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

📄 cmtcert.c

📁 安全开发库。含客户端建立ssl连接、签名、证书验证、证书发布和撤销等。编译用到nss
💻 C
📖 第 1 页 / 共 3 页
字号:
    /* send the message and get the response */    if (CMT_SendMessage(control, &message) == CMTFailure) {        goto loser;    }    if (message.type != (SSM_REPLY_OK_MESSAGE | SSM_SEC_CFG_ACTION |         SSM_FIND_CERT_KEY | subtype)) {        goto loser;    }    if (CMT_DecodeMessage(SingleItemMessageTemplate, &reply, &message) !=        CMTSuccess) {        goto loser;    }    /* copy the cert lookup key */    certKey = (CMTItem*)malloc(sizeof(CMTItem));    if (certKey == NULL) {        goto loser;    }    certKey->len = reply.item.len;    certKey->data = reply.item.data;loser:    return certKey;}/* fetches cert key given nickname */CMTItem* CMT_SCFindCertKeyByNickname(PCMT_CONTROL control, char* name){    return CMT_SCFindCertKey(control, SSM_FIND_KEY_BY_NICKNAME, name);}/* fetches cert key given email address */CMTItem* CMT_SCFindCertKeyByEmailAddr(PCMT_CONTROL control, char* name){    return CMT_SCFindCertKey(control, SSM_FIND_KEY_BY_EMAIL_ADDR, name);}/* fetches cert key given DN */CMTItem* CMT_SCFindCertKeyByNameString(PCMT_CONTROL control, char* name){    return CMT_SCFindCertKey(control, SSM_FIND_KEY_BY_DN, name);}/* packs message that contains the cert key for CertGetProp messages */static CMTStatus cmt_sc_pack_cert_key(PCMT_CONTROL control, CMTItem* certKey,                                      SSMSecCfgGetCertPropType subtype,                                      CMTItem* message){    SingleItemMessage request;    CMTStatus rv = CMTFailure;    /* pack the request */    request.item.len = certKey->len;    request.item.data = certKey->data;    /* encode the request */    rv = CMT_EncodeMessage(SingleItemMessageTemplate, message, &request);    if (rv != CMTSuccess) {        return rv;    }    /* set the message type */    message->type = SSM_REQUEST_MESSAGE | SSM_SEC_CFG_ACTION |        SSM_GET_CERT_PROP_BY_KEY | subtype;    return CMTSuccess;}    /* fetches string property given cert key */static char* CMT_SCGetCertPropString(PCMT_CONTROL control,                                      CMTItem* certKey,                                      SSMSecCfgGetCertPropType subtype){    SingleStringMessage reply;    CMTItem message;    char* rv = NULL;    if (certKey == NULL) {        goto loser;    }    /* create the message */    if (cmt_sc_pack_cert_key(control, certKey, subtype, &message) !=         CMTSuccess) {        goto loser;    }    /* send the message and get the response */    if (CMT_SendMessage(control, &message) == CMTFailure) {        goto loser;    }    if (message.type != (SSM_REPLY_OK_MESSAGE | SSM_SEC_CFG_ACTION |        SSM_GET_CERT_PROP_BY_KEY)) {        goto loser;    }    /* decode the reply */    if (CMT_DecodeMessage(SingleStringMessageTemplate, &reply, &message) !=        CMTSuccess) {        goto loser;    }    rv = reply.string;loser:    return rv;}static CMTStatus CMT_SCGetCertPropTime(PCMT_CONTROL control,                                       CMTItem* certKey,                                       SSMSecCfgGetCertPropType subtype,                                       CMTime* time){    TimeMessage reply;    CMTItem message;    if (certKey == NULL) {        goto loser;    }    /* create the message */    if (cmt_sc_pack_cert_key(control, certKey, subtype, &message) !=        CMTSuccess) {        goto loser;    }    /* send the message and get the response */    if (CMT_SendMessage(control, &message) == CMTFailure) {        goto loser;    }    if (message.type != (SSM_REPLY_OK_MESSAGE | SSM_SEC_CFG_ACTION |        SSM_GET_CERT_PROP_BY_KEY)) {        goto loser;    }    /* decode the reply */    if (CMT_DecodeMessage(TimeMessageTemplate, &reply, &message) !=        CMTSuccess) {        goto loser;    }    time->year = reply.year;    time->month = reply.month;    time->day = reply.day;    time->hour = reply.hour;    time->minute = reply.minute;    time->second = reply.second;    return CMTSuccess;loser:    return CMTFailure;}/* fetches a related cert key given cert key */static CMTItem* CMT_SCGetCertPropCertKey(PCMT_CONTROL control,                                          CMTItem* certKey,                                         SSMSecCfgGetCertPropType subtype){    SingleItemMessage reply;    CMTItem message;    CMTItem* newKey = NULL;        if (certKey == NULL) {        goto loser;    }    /* create the message */    if (cmt_sc_pack_cert_key(control, certKey, subtype, &message) !=        CMTSuccess) {        goto loser;    }    /* send the message and get the response */    if (CMT_SendMessage(control, &message) == CMTFailure) {        goto loser;    }    if (message.type != (SSM_REPLY_OK_MESSAGE | SSM_SEC_CFG_ACTION |        SSM_GET_CERT_PROP_BY_KEY)) {        goto loser;    }    /* decode the reply */    if (CMT_DecodeMessage(SingleItemMessageTemplate, &reply, &message) !=        CMTSuccess) {        goto loser;    }    newKey = (CMTItem*)malloc(sizeof(CMTItem));    if (newKey == NULL) {        goto loser;    }    newKey->len = reply.item.len;    newKey->data = reply.item.data;loser:    return newKey;}/* fetches cert nickname given cert key */char* CMT_SCGetCertPropNickname(PCMT_CONTROL control, CMTItem* certKey){    return CMT_SCGetCertPropString(control, certKey, SSM_SECCFG_GET_NICKNAME);}/* fetches cert email address given cert key */char* CMT_SCGetCertPropEmailAddress(PCMT_CONTROL control, CMTItem* certKey){    return CMT_SCGetCertPropString(control, certKey,                                    SSM_SECCFG_GET_EMAIL_ADDR);}/* fetches cert DN given cert key */char* CMT_SCGetCertPropDN(PCMT_CONTROL control, CMTItem* certKey){    return CMT_SCGetCertPropString(control, certKey, SSM_SECCFG_GET_DN);}/* fetches cert trust given cert key */char* CMT_SCGetCertPropTrust(PCMT_CONTROL control, CMTItem* certKey){    return CMT_SCGetCertPropString(control, certKey, SSM_SECCFG_GET_TRUST);}/* fetches cert serial number given cert key */char* CMT_SCGetCertPropSerialNumber(PCMT_CONTROL control, CMTItem* certKey){    return CMT_SCGetCertPropString(control, certKey,                                    SSM_SECCFG_GET_SERIAL_NO);}/* fetches cert issuer name given cert key */char* CMT_SCGetCertPropIssuerName(PCMT_CONTROL control, CMTItem* certKey){    return CMT_SCGetCertPropString(control, certKey,                                    SSM_SECCFG_GET_ISSUER);}/* fetches validity periods as a string given cert key */CMTStatus CMT_SCGetCertPropTimeNotBefore(PCMT_CONTROL control,                                          CMTItem* certKey, CMTime* time){    return CMT_SCGetCertPropTime(control, certKey,                                  SSM_SECCFG_GET_NOT_BEFORE, time);}CMTStatus CMT_SCGetCertPropTimeNotAfter(PCMT_CONTROL control,                                         CMTItem* certKey, CMTime* time){    return CMT_SCGetCertPropTime(control, certKey,                                  SSM_SECCFG_GET_NOT_AFTER, time);}/* fetches issuer cert key given cert key */CMTItem* CMT_SCGetCertPropIssuerKey(PCMT_CONTROL control, CMTItem* certKey){    return CMT_SCGetCertPropCertKey(control, certKey,                                     SSM_SECCFG_GET_ISSUER_KEY);}/* fetches next subject key given cert key */CMTItem* CMT_SCGetCertPropSubjectNext(PCMT_CONTROL control, CMTItem* certKey){    return CMT_SCGetCertPropCertKey(control, certKey,                                    SSM_SECCFG_GET_SUBJECT_NEXT);}/* fetches previous subject key given cert key */CMTItem* CMT_SCGetCertPropSubjectPrev(PCMT_CONTROL control, CMTItem* certKey){    return CMT_SCGetCertPropCertKey(control, certKey,                                    SSM_SECCFG_GET_SUBJECT_PREV);}/* determines whether the cert is in perm db given cert key */CMTStatus CMT_SCGetCertPropIsPerm(PCMT_CONTROL control, CMTItem* certKey,                                  CMBool* isPerm){    CMTItem message;    SingleNumMessage reply;    if (certKey == NULL) {        goto loser;    }    /* create the message */    if (cmt_sc_pack_cert_key(control, certKey, SSM_SECCFG_CERT_IS_PERM,                             &message) != CMTSuccess) {        goto loser;    }    /* send the message and get the response */    if (CMT_SendMessage(control, &message) == CMTFailure) {        goto loser;    }    if (message.type != (SSM_REPLY_OK_MESSAGE | SSM_SEC_CFG_ACTION |        SSM_GET_CERT_PROP_BY_KEY)) {        goto loser;    }    /* decode the reply */    if (CMT_DecodeMessage(SingleNumMessageTemplate, &reply, &message) !=        CMTSuccess) {        goto loser;    }    if (reply.value) {        *isPerm = CM_TRUE;    }    else {        *isPerm = CM_FALSE;    }    return CMTSuccess;loser:    return CMTFailure;}CMTStatus CMT_SCCertIndexEnum(PCMT_CONTROL control, CMInt32 type,                               CMInt32* number, CMCertEnum** list){    SingleNumMessage request;    SCCertIndexEnumReply reply;    CMTItem message;    /* initialize these in case of failure */    *number = 0;    *list = NULL;    switch (type) {    case 0: /* nickname requested */        message.type = SSM_REQUEST_MESSAGE | SSM_SEC_CFG_ACTION |            SSM_CERT_INDEX_ENUM | SSM_FIND_KEY_BY_NICKNAME;        break;    case 1: /* email address requested */        message.type = SSM_REQUEST_MESSAGE | SSM_SEC_CFG_ACTION |            SSM_CERT_INDEX_ENUM | SSM_FIND_KEY_BY_EMAIL_ADDR;        break;    case 2: /* DN requested */        message.type = SSM_REQUEST_MESSAGE | SSM_SEC_CFG_ACTION |            SSM_CERT_INDEX_ENUM | SSM_FIND_KEY_BY_DN;        break;    default:        goto loser;        break;    }    /* pack the request */    request.value = 0; /* not important */    if (CMT_EncodeMessage(SingleNumMessageTemplate, &message, &request) !=        CMTSuccess) {        goto loser;    }    /* send the message and get the response */    if (CMT_SendMessage(control, &message) == CMTFailure) {        goto loser;    }    if (message.type != (SSM_REPLY_OK_MESSAGE | SSM_SEC_CFG_ACTION |        SSM_CERT_INDEX_ENUM)) {        goto loser;    }    /* decode the reply */    if (CMT_DecodeMessage(SCCertIndexEnumReplyTemplate, &reply, &message) !=        CMTSuccess) {        goto loser;    }    *number = reply.length;    *list = (CMCertEnum*)reply.list;    return CMTSuccess;loser:    return CMTFailure;}CMTStatus CMT_FindCertExtension(PCMT_CONTROL control, CMUint32 resID,                                 CMUint32 extension, CMTItem *extValue){    GetCertExtension request;    SingleItemMessage reply;    CMTItem message;    request.resID = resID;    request.extension = extension;    message.type = SSM_REQUEST_MESSAGE | SSM_CERT_ACTION | SSM_EXTENSION_VALUE;    if (CMT_EncodeMessage(GetCertExtensionTemplate,                           &message, &request) != CMTSuccess) {        goto loser;    }    if (CMT_SendMessage(control, &message) != CMTSuccess) {        goto loser;    }    if (message.type != (SSM_REPLY_OK_MESSAGE |                          SSM_CERT_ACTION      |                         SSM_EXTENSION_VALUE)) {        goto loser;    }    if (CMT_DecodeMessage(SingleItemMessageTemplate,                           &reply, &message) != CMTSuccess) {        goto loser;    }    extValue->type = 0;    extValue->data = reply.item.data;    extValue->len  = reply.item.len;    return CMTSuccess; loser:    return CMTFailure;}CMTStatus CMT_HTMLCertInfo(PCMT_CONTROL control, CMUint32 certID, CMBool showImages,                 CMBool showIssuer, char **retHtml){    HTMLCertInfoRequest request;    SingleStringMessage reply;    CMTItem message;    if (retHtml == NULL) {        return CMTFailure;    }    request.certID     = certID;    request.showImages = showImages;    request.showIssuer = showIssuer;    if (CMT_EncodeMessage(HTMLCertInfoRequestTemplate,                           &message, &request) != CMTSuccess) {        goto loser;    }    message.type = SSM_REQUEST_MESSAGE | SSM_CERT_ACTION | SSM_HTML_INFO;    if (CMT_SendMessage(control, &message) != CMTSuccess) {        goto loser;    }    if (message.type != (SSM_REPLY_OK_MESSAGE | SSM_CERT_ACTION |                          SSM_HTML_INFO)) {        goto loser;    }    if (CMT_DecodeMessage(SingleStringMessageTemplate,                           &reply, &message) != CMTSuccess) {        goto loser;    }    *retHtml = reply.string;    return CMTSuccess; loser:    return CMTFailure;}

⌨️ 快捷键说明

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