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

📄 cmtpkcs7.c

📁 安全开发库。含客户端建立ssl连接、签名、证书验证、证书发布和撤销等。编译用到nss
💻 C
📖 第 1 页 / 共 2 页
字号:
    *result = reply.value;    return CMTSuccess;loser:	*result = reply.value;	return CMTFailure;}CMTStatus CMT_PKCS7VerifySignature(PCMT_CONTROL control, CMUint32 pubKeyAlgID,                                   CMTItem *pubKeyParams, CMTItem *signerPubKey,                                   CMTItem *computedHash, CMTItem *signature,                                   CMInt32 *result){	return CMTFailure;}CMTStatus CMT_CreateSigned(PCMT_CONTROL control, CMUint32 scertRID,                           CMUint32 ecertRID, CMUint32 dig_alg,                           CMTItem *digest, CMUint32 *ciRID, CMInt32 *errCode){    CMTItem message;    CreateSignedRequest request;    CreateContentInfoReply reply;    /* Do some parameter checking */    if (!control || !scertRID || !ecertRID || !digest || !ciRID) {        goto loser;    }    /* Set the request */    request.scertRID = scertRID;    request.ecertRID = ecertRID;    request.dig_alg = dig_alg;    request.digest = *digest;    /* Encode the request */    if (CMT_EncodeMessage(CreateSignedRequestTemplate, &message, &request) != CMTSuccess) {        goto loser;    }    /* Set the message request type */    message.type = SSM_REQUEST_MESSAGE | SSM_OBJECT_SIGNING | SSM_CREATE_SIGNED;    /* Send the message */    if (CMT_SendMessage(control, &message) == CMTFailure) {        goto loser;    }    /* Validate the message reply type */    if (message.type != (SSM_REPLY_OK_MESSAGE | SSM_OBJECT_SIGNING | SSM_CREATE_SIGNED)) {        goto loser;    }    /* Decode the reply */    if (CMT_DecodeMessage(CreateContentInfoReplyTemplate, &reply, &message) != CMTSuccess) {        goto loser;    }    *ciRID = reply.ciRID;    if (reply.result == 0) {		return CMTSuccess;	} loser:    if (CMT_DecodeMessage(CreateContentInfoReplyTemplate, &reply, &message) == CMTSuccess) {        *errCode = reply.errorCode;    } else {        *errCode = 0;    }	return CMTFailure;}CMTStatus CMT_CreateEncrypted(PCMT_CONTROL control, CMUint32 scertRID,                              CMUint32 *rcertRIDs, CMUint32 *ciRID){    CMTItem message;    CMInt32 nrcerts;    CreateEncryptedRequest request;    CreateContentInfoReply reply;    /* Do some parameter checking */    if (!control || !scertRID || !rcertRIDs || !ciRID) {        goto loser;    }    /* Calculate the number of certs */    for (nrcerts =0; rcertRIDs[nrcerts] != 0; nrcerts++) {        /* Nothing */        ;    }    /* Set up the request */    request.scertRID = scertRID;    request.nrcerts = nrcerts;    request.rcertRIDs = (long *) rcertRIDs;    /* Encode the request */    if (CMT_EncodeMessage(CreateEncryptedRequestTemplate, &message, &request) != CMTSuccess) {        goto loser;    }    /* Set the message request type */    message.type = SSM_REQUEST_MESSAGE | SSM_OBJECT_SIGNING | SSM_CREATE_ENCRYPTED;    /* Send the message */    if (CMT_SendMessage(control, &message) == CMTFailure) {        goto loser;    }    /* Validate the message response type */    if (message.type != (SSM_REPLY_OK_MESSAGE | SSM_OBJECT_SIGNING | SSM_CREATE_ENCRYPTED)) {        goto loser;    }    /* Decode the reply */    if (CMT_DecodeMessage(CreateContentInfoReplyTemplate, &reply, &message) != CMTSuccess) {        goto loser;    }    *ciRID = reply.ciRID;    if (reply.result == 0) {		return CMTSuccess;	} loser:	return CMTFailure;}CMTStatus CMT_PKCS7EncoderStart(PCMT_CONTROL control, CMUint32 ciRID,                                CMUint32 *connectionID, CMTP7ContentCallback cb,                                void *cb_arg){    CMTItem message;    CMTStatus rv;    CMTP7Private *priv;    PKCS7DataConnectionRequest request;    DataConnectionReply reply;    /* Check passed in parameters */    if (!control || !ciRID) {        goto loser;    }    /* Set up the request */    request.resID = ciRID;    request.clientContext.len = 0;    request.clientContext.data = NULL;    /* Encode the request */    if (CMT_EncodeMessage(PKCS7DataConnectionRequestTemplate, &message, &request) != CMTSuccess) {        goto loser;    }    /* Set the message request type */    message.type = SSM_REQUEST_MESSAGE | SSM_DATA_CONNECTION | SSM_PKCS7ENCODE_STREAM;    /* Send the message */    if (CMT_SendMessage(control, &message) == CMTFailure) {        goto loser;    }    /* Validate the message reply type */    if (message.type != (SSM_REPLY_OK_MESSAGE | SSM_DATA_CONNECTION | SSM_PKCS7ENCODE_STREAM)) {        goto loser;    }    /* Decode the reply */    if (CMT_DecodeMessage(DataConnectionReplyTemplate, &reply, &message) != CMTSuccess) {        goto loser;    }    /* Success */    if (reply.result == 0) {        CMTSocket sock;        priv = (CMTP7Private *)malloc(sizeof(CMTP7Private));        if (priv == NULL)            goto loser;        priv->priv.dest = (CMTReclaimFunc) free;        priv->cb = cb;        priv->cb_arg = cb_arg;        sock = control->sockFuncs.socket(0);        if (sock == NULL) {            goto loser;        }        if (control->sockFuncs.connect(sock, reply.port, NULL) != CMTSuccess) {            goto loser;        }        if (control->sockFuncs.send(sock, control->nonce.data,                                    control->nonce.len) != control->nonce.len) {            goto loser;        }        /* Save connection info */        if (CMT_AddDataConnection(control, sock, reply.connID)            != CMTSuccess) {            goto loser;        }        *connectionID = reply.connID;        rv = CMT_SetPrivate(control, reply.connID, &priv->priv);        if (rv != CMTSuccess)            goto loser;        return CMTSuccess;    } loser:    return CMTFailure;}CMTStatus CMT_PKCS7EncoderUpdate(PCMT_CONTROL control, CMUint32 connectionID,                                 const char *buf, CMUint32 len){    CMUint32 sent;    CMTP7Private *priv;    unsigned long nbytes;    char read_buf[128];    CMTSocket sock, ctrlsock, sockArr[2], selSock;    /* Do some parameter checking */    if (!control || !connectionID || !buf) {        goto loser;    }    /* Get the data socket */    if (CMT_GetDataSocket(control, connectionID, &sock) == CMTFailure) {        goto loser;    }    priv = (CMTP7Private *)CMT_GetPrivate(control, connectionID);    if (priv == NULL)        goto loser;    /* Write the data to the socket */    sent = CMT_WriteThisMany(control, sock, (void*)buf, len);    if (sent != len) {        goto loser;    }	ctrlsock = control->sock;	sockArr[0] = ctrlsock;	sockArr[1] = sock;#ifdef XP_MAC    while ((selSock = control->sockFuncs.select(sockArr, 2, 1)) != NULL) #else    while ((selSock = control->sockFuncs.select(&sockArr, 2, 1)) != NULL) #endif    {		if (selSock == ctrlsock) {			CMT_ProcessEvent(control);		} else {	        nbytes = control->sockFuncs.recv(sock, read_buf, sizeof(read_buf));		    if (nbytes == -1) {			    goto loser;			} else if (nbytes == 0) {	            break;		    } else {			    priv->cb(priv->cb_arg, read_buf, nbytes);			}		}    }    return CMTSuccess;loser:    return CMTFailure;}CMTStatus CMT_PKCS7EncoderFinish(PCMT_CONTROL control, CMUint32 connectionID){    CMTP7Private *priv;    unsigned long nbytes;    char buf[128];    CMTSocket sock, ctrlsock, sockArr[2], selSock;    /* Do some parameter checking */    if (!control) {        goto loser;    }    priv = (CMTP7Private *)CMT_GetPrivate(control, connectionID);    if (priv == NULL)        goto loser;    if (CMT_GetDataSocket(control, connectionID, &sock) == CMTFailure) {        goto loser;    }    ctrlsock = control->sock;    sockArr[0] = ctrlsock;    sockArr[1] = sock;    control->sockFuncs.shutdown(sock);    while (1) {        selSock = control->sockFuncs.select(sockArr, 2, 0);        if (selSock == ctrlsock) {            CMT_ProcessEvent(control);        } else if (selSock == sock) {            nbytes = control->sockFuncs.recv(sock, buf, sizeof(buf));            if (nbytes < 0) {                goto loser;            } else if (nbytes == 0) {                break;            } else {                priv->cb(priv->cb_arg, buf, nbytes);            }        }    }    if (CMT_CloseDataConnection(control, connectionID) == CMTFailure) {        goto loser;    }    return CMTSuccess;loser:    if (control) {        CMT_CloseDataConnection(control, connectionID);    }        return CMTFailure;}

⌨️ 快捷键说明

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