⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 protocolf.c

📁 安全开发库。含客户端建立ssl连接、签名、证书验证、证书发布和撤销等。编译用到nss
💻 C
📖 第 1 页 / 共 4 页
字号:
    SSMPORT_SetError(SSMPR_INVALID_ARGUMENT_ERROR);    return 0;  }    *verifyDetachedSigReply = NULL;  blobSize = sizeof(SSMPRInt32);  /* allocate space for the helloRequest "blob" */  curptr = (void *)SSMPORT_ZAlloc(blobSize);  if (!curptr) {     SSMPORT_SetError(SSMPR_OUT_OF_MEMORY_ERROR);    return 0;  }  *verifyDetachedSigReply = curptr;  *(SSMPRInt32 *)curptr = SSMPR_htonl(result);    return blobSize;}/* Messages for the resource management */SSMPRStatus SSM_ParseCreateSignedRequest(void *request,                                         SSMPRInt32 *scertRID,                                         SSMPRInt32 *ecertRID,                                         SSMPRUint32 *dig_alg,                                         SECItem **digest){    unsigned char *curPtr = (unsigned char *) request;    SSMPRStatus rv;    if (!request) {        SSMPORT_SetError(SSMPR_INVALID_ARGUMENT_ERROR);        return SSMPR_FAILURE;    }    *scertRID = SSMPR_ntohl(*(SSMPRInt32*)curPtr);    curPtr += sizeof(SSMPRInt32);    *ecertRID = SSMPR_ntohl(*(SSMPRInt32*)curPtr);    curPtr += sizeof(SSMPRInt32);    *dig_alg = SSMPR_ntohl(*(SSMPRUint32*)curPtr);    curPtr += sizeof(SSMPRUint32);    *digest = PR_NEWZAP(SECItem);    if (*digest == NULL)        goto loser;    rv = SSM_SSMStringToString(&(*digest)->data, &(*digest)->len,                               (SSMString *) curPtr);    if (rv != SSMPR_SUCCESS)        goto loser;    return PR_SUCCESS;loser:    return PR_FAILURE;}SSMPRInt32 SSM_PackCreateSignedReply(void **reply, SSMPRInt32 ciRID,                                     SSMPRUint32 result){    SSMPRInt32     blobSize;    unsigned char *curPtr;        blobSize = sizeof (SSMPRInt32) + sizeof(SSMPRUint32);    *reply = curPtr = PORT_ZAlloc(blobSize);    if (curPtr == NULL) {        SSMPORT_SetError(SSMPR_OUT_OF_MEMORY_ERROR);        return 0;    }    *((SSMPRInt32*)curPtr) = SSMPR_htonl(ciRID);    curPtr += sizeof(SSMPRInt32);    *((SSMPRInt32*)curPtr) = SSMPR_htonl(result);        return blobSize;}SSMPRStatus SSM_ParseCreateEncryptedRequest(void *request,                                            SSMPRInt32 *scertRID,                                            SSMPRInt32 *nrcerts,                                            SSMPRInt32 **rcertRIDs){    unsigned char *curPtr = (unsigned char *) request;    SSMPRStatus rv;    SSMPRInt32 ncerts;    int i;    if (!request) {        SSMPORT_SetError(SSMPR_INVALID_ARGUMENT_ERROR);        return SSMPR_FAILURE;    }    *scertRID = SSMPR_ntohl(*(SSMPRInt32*)curPtr);    curPtr += sizeof(SSMPRInt32);    ncerts = SSMPR_ntohl(*(SSMPRInt32*)curPtr);    *rcertRIDs = PR_Calloc(ncerts+1, sizeof(SSMPRInt32));    curPtr += sizeof(SSMPRInt32);    for (i = 0; i < ncerts; i++) {        (*rcertRIDs)[i] = SSMPR_ntohl(*(SSMPRInt32*)curPtr);        curPtr += sizeof(SSMPRInt32);    }    *nrcerts = ncerts;    return SSMPR_SUCCESS;}SSMPRInt32 SSM_PackCreateEncryptedReply(void **reply, SSMPRInt32 ciRID,                                        SSMPRUint32 result){    SSMPRInt32     blobSize;    unsigned char *curPtr;        blobSize = sizeof (SSMPRInt32) + sizeof(SSMPRUint32);    *reply = curPtr = PORT_ZAlloc(blobSize);    if (curPtr == NULL) {        SSMPORT_SetError(SSMPR_OUT_OF_MEMORY_ERROR);        return 0;    }    *((SSMPRInt32*)curPtr) = SSMPR_htonl(ciRID);    curPtr += sizeof(SSMPRInt32);    *((SSMPRInt32*)curPtr) = SSMPR_htonl(result);        return blobSize;}SSMPRStatus SSM_ParseCreateResourceRequest(void *request,                                           SSMPRUint32 *type,                                           unsigned char **params,                                           SSMPRUint32 *paramLen){    unsigned char *curPtr = (unsigned char*)request;    SSMPRStatus    rv     = SSMPR_SUCCESS;    if (!request)    {        SSMPORT_SetError(SSMPR_INVALID_ARGUMENT_ERROR);        return SSMPR_FAILURE;    }    /* Get stuff out. */    if (type)        *type = SSMPR_ntohl(*((SSMPRInt32*)curPtr));    curPtr += sizeof(SSMPRInt32);    if (params)        rv = SSM_SSMStringToString((char **) params, (int*) paramLen,                                   (SSMString *) curPtr);    return rv;}SSMPRStatus SSM_PackCreateResourceReply(void **reply, SSMPRStatus rv,                                        SSMPRUint32 resID){    SSMPRInt32     blobSize;    unsigned char *curPtr;        blobSize = sizeof (SSMPRInt32) + sizeof(SSMPRUint32);    *reply = curPtr = PORT_ZAlloc(blobSize);    if (curPtr == NULL) {        SSMPORT_SetError(SSMPR_OUT_OF_MEMORY_ERROR);        return 0;    }    *((SSMPRInt32*)curPtr) = SSMPR_htonl(rv);    curPtr += sizeof(SSMPRInt32);    *((SSMPRInt32*)curPtr) = SSMPR_htonl(resID);        return blobSize;}SSMPRStatus SSM_ParseDuplicateResourceRequest(void *request,					      SSMPRUint32 *resourceID){    return SSM_ParseSingleNumRequest(request, resourceID);} SSMPRInt32 SSM_PackDuplicateResourceReply(void ** reply, SSMPRInt32 result,					  SSMPRUint32 resID){    SSMPRInt32     blobSize;    unsigned char *curPtr;        blobSize = sizeof (SSMPRInt32) + sizeof(SSMPRUint32);    *reply = curPtr = PORT_ZAlloc(blobSize);    if (curPtr == NULL) {        SSMPORT_SetError(SSMPR_OUT_OF_MEMORY_ERROR);        return 0;    }    *((SSMPRInt32*)curPtr) = SSMPR_htonl(result);    curPtr += sizeof(SSMPRInt32);    *((SSMPRInt32*)curPtr) = SSMPR_htonl(resID);        return blobSize;}SSMPRStatus SSM_ParseGetAttribRequest(void * getAttribRequest, 				      SSMPRUint32 * resourceID, 				      SSMPRUint32 * fieldID){   void * curptr = getAttribRequest;   PRStatus rv = PR_SUCCESS;  if (!getAttribRequest) {     rv = PR_INVALID_ARGUMENT_ERROR;    goto loser;  }  if (resourceID) *resourceID = SSMPR_ntohl(*(SSMPRUint32 *)curptr);  curptr = (SSMPRUint32 *)curptr + 1;    if (fieldID) *fieldID = SSMPR_ntohl(*(SSMPRInt32 *)curptr);  curptr = (SSMPRInt32 *)curptr + 1;  loser:  if (getAttribRequest)     PR_Free(getAttribRequest);  return rv;}SSMPRInt32 SSM_PackGetAttribReply(void **getAttribReply,				  SSMPRInt32 result,				  SSMAttributeValue *value){  SSMPRInt32 blobSize, fieldlength;  void * curptr;  if (!getAttribReply) {    SSMPORT_SetError(SSMPR_INVALID_ARGUMENT_ERROR);    return 0;  }  *getAttribReply = NULL;    /* Calculate length of the field value. Binary length (fielddatalen)	takes precedence over using strlen(). */  fieldlength = (value->type == SSM_STRING_ATTRIBUTE) ? 	  PR_ntohl(SSMSTRING_PADDED_LENGTH(value->u.string->m_length)) : 0;  fieldlength += sizeof(SSMPRUint32);  blobSize = sizeof(SSMPRInt32) + fieldlength;  /* allocate space for the getAttribReply "blob" */  curptr = (void *)SSMPORT_ZAlloc(blobSize);  if (!curptr) {     SSMPORT_SetError(SSMPR_OUT_OF_MEMORY_ERROR);    return 0;  }  * getAttribReply = curptr;  *(SSMPRInt32 *)curptr = SSMPR_htonl(result);  curptr = (SSMPRInt32 *)curptr + 1;  switch(value->type) {   case SSM_STRING_ATTRIBUTE:      /* This value is stored in network byte order, no need to switch       * it back       */      *(SSMPRUint32 *)curptr = value->u.string->m_length;      curptr = (SSMPRInt32 *)curptr + 1;      memcpy(curptr, &value->u.string->m_data,              PR_ntohl(value->u.string->m_length));      break;   case SSM_RID_ATTRIBUTE:      *(SSMPRUint32 *)curptr = SSMPR_htonl(value->u.rid);      break;   case SSM_NUMERIC_ATTRIBUTE:      *(SSMPRUint32 *)curptr = SSMPR_htonl(value->u.numeric);      break;  }    return blobSize;}SSMPRStatusSSM_ParseSetAttribRequest(SECItem             *msg,			  SSMPRInt32          *resourceID,			  SSMPRInt32          *fieldID,			  SSMAttributeValue   *value){  unsigned char *curPtr;  SSMPRInt32 strLen;  if (!msg      || !msg->data || !resourceID || !fieldID || !value){    SSMPORT_SetError(SSMPR_INVALID_ARGUMENT_ERROR);    return SSMPR_FAILURE;  }  curPtr = msg->data;  value->type = msg->type & SSM_SPECIFIC_MASK;  switch (value->type) {  case SSM_NUMERIC_ATTRIBUTE:    *resourceID = SSMPR_ntohl(*(SSMPRInt32*)curPtr);    curPtr += sizeof(SSMPRInt32);    *fieldID = SSMPR_ntohl(*(SSMPRInt32*)curPtr);    curPtr += sizeof(SSMPRInt32);    value->u.numeric = SSMPR_ntohl(*(SSMPRInt32*)curPtr);    break;  case SSM_RID_ATTRIBUTE:    *resourceID = SSMPR_ntohl(*(SSMPRInt32*)curPtr);    curPtr += sizeof(SSMPRInt32);    *fieldID = SSMPR_ntohl(*(SSMPRInt32*)curPtr);    curPtr += sizeof(SSMPRInt32);    value->u.rid = SSMPR_ntohl(*(SSMPRInt32*)curPtr);    break;  case SSM_STRING_ATTRIBUTE:    *resourceID = SSMPR_ntohl(*(SSMPRInt32*)curPtr);    curPtr += sizeof(SSMPRInt32);    *fieldID = SSMPR_ntohl(*(SSMPRInt32*)curPtr);    curPtr += sizeof(SSMPRInt32);    strLen = msg->len - (curPtr - msg->data);    value->u.string = SSMPORT_ZAlloc(strLen);    memcpy (value->u.string, curPtr, strLen);    break;  default:    return SSMPR_FAILURE;  }    return SSMPR_SUCCESS;}/* Messages to pickle and unpickle a resource. */SSMPRStatus SSM_ParsePickleResourceRequest(void * pickleResourceRequest, 					  SSMPRUint32 * resourceID){   void * curptr = pickleResourceRequest;  PRStatus rv = PR_SUCCESS;  if (!pickleResourceRequest) {     rv = PR_INVALID_ARGUMENT_ERROR;    goto loser;  }  if (resourceID) *resourceID = SSMPR_ntohl(*(SSMPRUint32 *)curptr);  loser:  if (pickleResourceRequest)     SSMPORT_Free(pickleResourceRequest);  return rv;}SSMPRInt32 SSM_PackPickleResourceReply(void ** pickleResourceReply, 				       SSMPRInt32 result,				       SSMPRUint32 resourceLen, 				       void * resource){     SSMPRInt32 blobSize;    void * curptr, *tmpStr = NULL;    PRStatus rv;        if (!pickleResourceReply)       goto loser;        *pickleResourceReply = NULL;    blobSize = sizeof(SSMPRInt32) + sizeof(SSMPRUint32) + 	SSMSTRING_PADDED_LENGTH(resourceLen);         /* allocate space for the helloRequest "blob" */    curptr = (void *)SSMPORT_ZAlloc(blobSize);    if (!curptr)        goto loser;        *pickleResourceReply = curptr;    *(SSMPRInt32 *)curptr = SSMPR_htonl(result);    curptr = (SSMPRInt32 *)curptr + 1;        rv = SSM_StringToSSMString((SSMString **)&tmpStr, resourceLen, resource);    if (rv != SSMPR_SUCCESS)       goto loser;    memcpy(curptr, tmpStr, SSM_SIZEOF_STRING(*(SSMString *)tmpStr));    goto done;loser:    if (pickleResourceReply && *pickleResourceReply)       PR_Free(*pickleResourceReply);    if (tmpStr)       PR_Free(tmpStr);done:    return blobSize;}SSMPRStatus SSM_ParseUnpickleResourceRequest(void * unpickleResourceRequest, 					     SSMPRUint32 blobSize,					     SSMPRUint32 * resourceType,					     SSMPRUint32 * resourceLen, 					     void ** resource){    void * curptr = unpickleResourceRequest;    SSMPRStatus rv = PR_SUCCESS;        if (!unpickleResourceRequest) {         rv = PR_INVALID_ARGUMENT_ERROR;        goto loser;    }    if (resourceType)          *resourceType = PR_ntohl(*(SSMPRUint32 *)curptr);    curptr = (SSMPRUint32 *)curptr + 1;        if (resource) {        rv = SSM_SSMStringToString((char **)resource,  (SSMPRInt32 *)resourceLen,                                    (SSMString *)curptr);        if (rv != SSMPR_SUCCESS)              goto loser;     }    goto done;loser:    if (resource && *resource)      PR_Free(*resource);done:     if (unpickleResourceRequest)      PR_Free(unpickleResourceRequest);     return rv;}SSMPRInt32 SSM_PackUnpickleResourceReply(void ** unpickleResourceReply, 					 SSMPRInt32 result, 					 SSMPRUint32 resourceID){  SSMPRInt32 blobSize;  void * curptr;    if (!unpickleResourceReply) {    SSMPORT_SetError(SSMPR_INVALID_ARGUMENT_ERROR);    return 0;  }    *unpickleResourceReply = NULL;  blobSize = sizeof(SSMPRInt32) + sizeof(SSMPRUint32);  /* allocate space for the helloRequest "blob" */  curptr = (void *)SSMPORT_ZAlloc(blobSize);  if (!curptr) {     SSMPORT_SetError(SSMPR_OUT_OF_MEMORY_ERROR);    return 0;  }  *unpickleResourceReply = curptr;  *(SSMPRInt32 *)curptr = SSMPR_htonl(result);  curptr = (SSMPRInt32 *)curptr + 1;  *(SSMPRUint32 *)curptr = SSMPR_htonl(resourceID);  return blobSize;}/* Destroy resource messages */SSMPRStatus SSM_ParseDestroyResourceRequest(void * destroyResourceRequest, 					    SSMPRUint32 * resourceID, 					    SSMPRUint32 * resourceType){   void * curptr = destroyResourceRequest;  PRStatus rv = PR_SUCCESS;  if (!destroyResourceRequest) {     rv = PR_INVALID_ARGUMENT_ERROR;    goto loser;  }  if (resourceID) *resourceID = SSMPR_ntohl(*(SSMPRUint32 *)curptr);  curptr = (SSMPRUint32 *)curptr + 1;  if (resourceType) *resourceType = SSMPR_ntohl(*(SSMPRUint32 *)curptr);loser:  if (destroyResourceRequest)     SSMPORT_Free(destroyResourceRequest);  return rv;} SSMPRInt32 SSM_PackDestroyResourceReply(void ** destroyResourceReply, 					SSMPRInt32 result){    return SSM_PackSingleNumReply(destroyResourceReply, result);}SSMPRStatus SSM_ParseVerifyCertRequest(void * verifyCertRequest,                                        SSMPRUint32 * resourceID,                                        SSMPRInt32 * certUsage){  void * curptr = verifyCertRequest;  PRStatus rv = PR_SUCCESS;  if (!verifyCertRequest) {     rv = PR_INVALID_ARGUMENT_ERROR;    goto loser;  }  if (resourceID) *resourceID = SSMPR_ntohl(*(SSMPRUint32 *)curptr);  curptr = (SSMPRUint32 *)curptr + 1;  if (certUsage) *certUsage = SSMPR_ntohl(*(SSMPRInt32 *)curptr);loser:  if (verifyCertRequest)  SSMPORT_Free(verifyCertRequest);  return rv;}SSMPRInt32 SSM_PackVerifyCertReply(void ** verifyCertReply,                                    SSMPRInt32 result){  SSMPRInt32 blobSize;  void * curptr;    if (!verifyCertReply) {    SSMPORT_SetError(SSMPR_INVALID_ARGUMENT_ERROR);    return 0;  }  *verifyCertReply = NULL;  blobSize = sizeof(SSMPRInt32);  /* allocate space for the helloRequest "blob" */  curptr = (void *)SSMPORT_ZAlloc(blobSize);  if (!curptr) {     SSMPORT_SetError(SSMPR_OUT_OF_MEMORY_ERROR);    return 0;  }  *verifyCertReply = curptr;  *(SSMPRInt32 *)curptr = SSMPR_htonl(result);    return blobSize;}SSMPRStatus SSM_ParseImportCertRequest(void * importCertRequest, 			   SSMPRUint32 * blobLen, 			   void ** certBlob){  PRStatus rv;  void * curptr = importCertRequest;  PRUint32 length = 0;  if (!importCertRequest) {     rv = PR_INVALID_ARGUMENT_ERROR;     goto loser;  }    /* in case we fail */  if (certBlob) *certBlob = NULL;   if (blobLen)     *blobLen = 0;  if (certBlob) {    rv = SSM_SSMStringToString((char **)certBlob,  (SSMPRInt32 *)&length, 			       (SSMString *)curptr);    if (rv != SSMPR_SUCCESS)         goto loser;     }   if (blobLen)     *blobLen = length;  goto done;loser:   if (certBlob && *certBlob)	PR_Free(*certBlob);done:   if (importCertRequest)      SSMPORT_Free(importCertRequest);   return rv;}  SSMPRInt32 SSM_PackImportCertReply(void ** importCertReply, SSMPRInt32 result, 			SSMPRUint32 resourceID)  {    SSMPRInt32 blobSize;    void * curptr;        if (!importCertReply)       goto loser;        *importCertReply = NULL;    blobSize = sizeof(SSMPRInt32) + sizeof(SSMPRUint32);        /* allocate space for the "blob" */    curptr = (void *)SSMPORT_ZAlloc(blobSize);    if (!curptr)       goto loser;    *importCertReply = curptr;    *(SSMPRInt32 *)curptr = SSMPR_htonl(result);    curptr = (SSMPRInt32 *)curptr + 1;    *(SSMPRUint32 *)curptr = SSMPR_htonl(resourceID);        return blobSize;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -