andre@0: /* This Source Code Form is subject to the terms of the Mozilla Public andre@0: * License, v. 2.0. If a copy of the MPL was not distributed with this andre@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ andre@0: andre@0: /* andre@0: * PKCS7 implementation -- the exported parts that are used whether andre@0: * creating or decoding. andre@0: */ andre@0: andre@0: #include "p7local.h" andre@0: andre@0: #include "cert.h" andre@0: #include "secitem.h" andre@0: #include "secoid.h" andre@0: #include "pk11func.h" andre@0: andre@0: /* andre@0: * Find out (saving pointer to lookup result for future reference) andre@0: * and return the inner content type. andre@0: */ andre@0: SECOidTag andre@0: SEC_PKCS7ContentType (SEC_PKCS7ContentInfo *cinfo) andre@0: { andre@0: if (cinfo->contentTypeTag == NULL) andre@0: cinfo->contentTypeTag = SECOID_FindOID(&(cinfo->contentType)); andre@0: andre@0: if (cinfo->contentTypeTag == NULL) andre@0: return SEC_OID_UNKNOWN; andre@0: andre@0: return cinfo->contentTypeTag->offset; andre@0: } andre@0: andre@0: andre@0: /* andre@0: * Destroy a PKCS7 contentInfo and all of its sub-pieces. andre@0: */ andre@0: void andre@0: SEC_PKCS7DestroyContentInfo(SEC_PKCS7ContentInfo *cinfo) andre@0: { andre@0: SECOidTag kind; andre@0: CERTCertificate **certs; andre@0: CERTCertificateList **certlists; andre@0: SEC_PKCS7SignerInfo **signerinfos; andre@0: SEC_PKCS7RecipientInfo **recipientinfos; andre@0: andre@0: PORT_Assert (cinfo->refCount > 0); andre@0: if (cinfo->refCount <= 0) andre@0: return; andre@0: andre@0: cinfo->refCount--; andre@0: if (cinfo->refCount > 0) andre@0: return; andre@0: andre@0: certs = NULL; andre@0: certlists = NULL; andre@0: recipientinfos = NULL; andre@0: signerinfos = NULL; andre@0: andre@0: kind = SEC_PKCS7ContentType (cinfo); andre@0: switch (kind) { andre@0: case SEC_OID_PKCS7_ENVELOPED_DATA: andre@0: { andre@0: SEC_PKCS7EnvelopedData *edp; andre@0: andre@0: edp = cinfo->content.envelopedData; andre@0: if (edp != NULL) { andre@0: recipientinfos = edp->recipientInfos; andre@0: } andre@0: } andre@0: break; andre@0: case SEC_OID_PKCS7_SIGNED_DATA: andre@0: { andre@0: SEC_PKCS7SignedData *sdp; andre@0: andre@0: sdp = cinfo->content.signedData; andre@0: if (sdp != NULL) { andre@0: certs = sdp->certs; andre@0: certlists = sdp->certLists; andre@0: signerinfos = sdp->signerInfos; andre@0: } andre@0: } andre@0: break; andre@0: case SEC_OID_PKCS7_SIGNED_ENVELOPED_DATA: andre@0: { andre@0: SEC_PKCS7SignedAndEnvelopedData *saedp; andre@0: andre@0: saedp = cinfo->content.signedAndEnvelopedData; andre@0: if (saedp != NULL) { andre@0: certs = saedp->certs; andre@0: certlists = saedp->certLists; andre@0: recipientinfos = saedp->recipientInfos; andre@0: signerinfos = saedp->signerInfos; andre@0: if (saedp->sigKey != NULL) andre@0: PK11_FreeSymKey (saedp->sigKey); andre@0: } andre@0: } andre@0: break; andre@0: default: andre@0: /* XXX Anything else that needs to be "manually" freed/destroyed? */ andre@0: break; andre@0: } andre@0: andre@0: if (certs != NULL) { andre@0: CERTCertificate *cert; andre@0: andre@0: while ((cert = *certs++) != NULL) { andre@0: CERT_DestroyCertificate (cert); andre@0: } andre@0: } andre@0: andre@0: if (certlists != NULL) { andre@0: CERTCertificateList *certlist; andre@0: andre@0: while ((certlist = *certlists++) != NULL) { andre@0: CERT_DestroyCertificateList (certlist); andre@0: } andre@0: } andre@0: andre@0: if (recipientinfos != NULL) { andre@0: SEC_PKCS7RecipientInfo *ri; andre@0: andre@0: while ((ri = *recipientinfos++) != NULL) { andre@0: if (ri->cert != NULL) andre@0: CERT_DestroyCertificate (ri->cert); andre@0: } andre@0: } andre@0: andre@0: if (signerinfos != NULL) { andre@0: SEC_PKCS7SignerInfo *si; andre@0: andre@0: while ((si = *signerinfos++) != NULL) { andre@0: if (si->cert != NULL) andre@0: CERT_DestroyCertificate (si->cert); andre@0: if (si->certList != NULL) andre@0: CERT_DestroyCertificateList (si->certList); andre@0: } andre@0: } andre@0: andre@0: if (cinfo->poolp != NULL) { andre@0: PORT_FreeArena (cinfo->poolp, PR_FALSE); /* XXX clear it? */ andre@0: } andre@0: } andre@0: andre@0: andre@0: /* andre@0: * Return a copy of the given contentInfo. The copy may be virtual andre@0: * or may be real -- either way, the result needs to be passed to andre@0: * SEC_PKCS7DestroyContentInfo later (as does the original). andre@0: */ andre@0: SEC_PKCS7ContentInfo * andre@0: SEC_PKCS7CopyContentInfo(SEC_PKCS7ContentInfo *cinfo) andre@0: { andre@0: if (cinfo == NULL) andre@0: return NULL; andre@0: andre@0: PORT_Assert (cinfo->refCount > 0); andre@0: andre@0: if (cinfo->created) { andre@0: /* andre@0: * Want to do a real copy of these; otherwise subsequent andre@0: * changes made to either copy are likely to be a surprise. andre@0: * XXX I suspect that this will not actually be called for yet, andre@0: * which is why the assert, so to notice if it is... andre@0: */ andre@0: PORT_Assert (0); andre@0: /* andre@0: * XXX Create a new pool here, and copy everything from andre@0: * within. For cert stuff, need to call the appropriate andre@0: * copy functions, etc. andre@0: */ andre@0: } andre@0: andre@0: cinfo->refCount++; andre@0: return cinfo; andre@0: } andre@0: andre@0: andre@0: /* andre@0: * Return a pointer to the actual content. In the case of those types andre@0: * which are encrypted, this returns the *plain* content. andre@0: * XXX Needs revisiting if/when we handle nested encrypted types. andre@0: */ andre@0: SECItem * andre@0: SEC_PKCS7GetContent(SEC_PKCS7ContentInfo *cinfo) andre@0: { andre@0: SECOidTag kind; andre@0: andre@0: kind = SEC_PKCS7ContentType (cinfo); andre@0: switch (kind) { andre@0: case SEC_OID_PKCS7_DATA: andre@0: return cinfo->content.data; andre@0: case SEC_OID_PKCS7_DIGESTED_DATA: andre@0: { andre@0: SEC_PKCS7DigestedData *digd; andre@0: andre@0: digd = cinfo->content.digestedData; andre@0: if (digd == NULL) andre@0: break; andre@0: return SEC_PKCS7GetContent (&(digd->contentInfo)); andre@0: } andre@0: case SEC_OID_PKCS7_ENCRYPTED_DATA: andre@0: { andre@0: SEC_PKCS7EncryptedData *encd; andre@0: andre@0: encd = cinfo->content.encryptedData; andre@0: if (encd == NULL) andre@0: break; andre@0: return &(encd->encContentInfo.plainContent); andre@0: } andre@0: case SEC_OID_PKCS7_ENVELOPED_DATA: andre@0: { andre@0: SEC_PKCS7EnvelopedData *envd; andre@0: andre@0: envd = cinfo->content.envelopedData; andre@0: if (envd == NULL) andre@0: break; andre@0: return &(envd->encContentInfo.plainContent); andre@0: } andre@0: case SEC_OID_PKCS7_SIGNED_DATA: andre@0: { andre@0: SEC_PKCS7SignedData *sigd; andre@0: andre@0: sigd = cinfo->content.signedData; andre@0: if (sigd == NULL) andre@0: break; andre@0: return SEC_PKCS7GetContent (&(sigd->contentInfo)); andre@0: } andre@0: case SEC_OID_PKCS7_SIGNED_ENVELOPED_DATA: andre@0: { andre@0: SEC_PKCS7SignedAndEnvelopedData *saed; andre@0: andre@0: saed = cinfo->content.signedAndEnvelopedData; andre@0: if (saed == NULL) andre@0: break; andre@0: return &(saed->encContentInfo.plainContent); andre@0: } andre@0: default: andre@0: PORT_Assert(0); andre@0: break; andre@0: } andre@0: andre@0: return NULL; andre@0: } andre@0: andre@0: andre@0: /* andre@0: * XXX Fix the placement and formatting of the andre@0: * following routines (i.e. make them consistent with the rest of andre@0: * the pkcs7 code -- I think some/many belong in other files and andre@0: * they all need a formatting/style rehaul) andre@0: */ andre@0: andre@0: /* retrieve the algorithm identifier for encrypted data. andre@0: * the identifier returned is a copy of the algorithm identifier andre@0: * in the content info and needs to be freed after being used. andre@0: * andre@0: * cinfo is the content info for which to retrieve the andre@0: * encryption algorithm. andre@0: * andre@0: * if the content info is not encrypted data or an error andre@0: * occurs NULL is returned. andre@0: */ andre@0: SECAlgorithmID * andre@0: SEC_PKCS7GetEncryptionAlgorithm(SEC_PKCS7ContentInfo *cinfo) andre@0: { andre@0: SECAlgorithmID *alg = 0; andre@0: switch (SEC_PKCS7ContentType(cinfo)) andre@0: { andre@0: case SEC_OID_PKCS7_ENCRYPTED_DATA: andre@0: alg = &cinfo->content.encryptedData->encContentInfo.contentEncAlg; andre@0: break; andre@0: case SEC_OID_PKCS7_ENVELOPED_DATA: andre@0: alg = &cinfo->content.envelopedData->encContentInfo.contentEncAlg; andre@0: break; andre@0: case SEC_OID_PKCS7_SIGNED_ENVELOPED_DATA: andre@0: alg = &cinfo->content.signedAndEnvelopedData andre@0: ->encContentInfo.contentEncAlg; andre@0: break; andre@0: default: andre@0: alg = 0; andre@0: break; andre@0: } andre@0: andre@0: return alg; andre@0: } andre@0: andre@0: /* set the content of the content info. For data content infos, andre@0: * the data is set. For encrytped content infos, the plainContent andre@0: * is set, and is expected to be encrypted later. andre@0: * andre@0: * cinfo is the content info where the data will be set andre@0: * andre@0: * buf is a buffer of the data to set andre@0: * andre@0: * len is the length of the data being set. andre@0: * andre@0: * in the event of an error, SECFailure is returned. SECSuccess andre@0: * indicates the content was successfully set. andre@0: */ andre@0: SECStatus andre@0: SEC_PKCS7SetContent(SEC_PKCS7ContentInfo *cinfo, andre@0: const char *buf, andre@0: unsigned long len) andre@0: { andre@0: SECOidTag cinfo_type; andre@0: SECStatus rv; andre@0: SECItem content; andre@0: SECOidData *contentTypeTag = NULL; andre@0: andre@0: content.type = siBuffer; andre@0: content.data = (unsigned char *)buf; andre@0: content.len = len; andre@0: andre@0: cinfo_type = SEC_PKCS7ContentType(cinfo); andre@0: andre@0: /* set inner content */ andre@0: switch(cinfo_type) andre@0: { andre@0: case SEC_OID_PKCS7_SIGNED_DATA: andre@0: if(content.len > 0) { andre@0: /* we "leak" the old content here, but as it's all in the pool */ andre@0: /* it does not really matter */ andre@0: andre@0: /* create content item if necessary */ andre@0: if (cinfo->content.signedData->contentInfo.content.data == NULL) andre@0: cinfo->content.signedData->contentInfo.content.data = SECITEM_AllocItem(cinfo->poolp, NULL, 0); andre@0: rv = SECITEM_CopyItem(cinfo->poolp, andre@0: cinfo->content.signedData->contentInfo.content.data, andre@0: &content); andre@0: } else { andre@0: cinfo->content.signedData->contentInfo.content.data->data = NULL; andre@0: cinfo->content.signedData->contentInfo.content.data->len = 0; andre@0: rv = SECSuccess; andre@0: } andre@0: if(rv == SECFailure) andre@0: goto loser; andre@0: andre@0: break; andre@0: case SEC_OID_PKCS7_ENCRYPTED_DATA: andre@0: /* XXX this forces the inner content type to be "data" */ andre@0: /* do we really want to override without asking or reason? */ andre@0: contentTypeTag = SECOID_FindOIDByTag(SEC_OID_PKCS7_DATA); andre@0: if(contentTypeTag == NULL) andre@0: goto loser; andre@0: rv = SECITEM_CopyItem(cinfo->poolp, andre@0: &(cinfo->content.encryptedData->encContentInfo.contentType), andre@0: &(contentTypeTag->oid)); andre@0: if(rv == SECFailure) andre@0: goto loser; andre@0: if(content.len > 0) { andre@0: rv = SECITEM_CopyItem(cinfo->poolp, andre@0: &(cinfo->content.encryptedData->encContentInfo.plainContent), andre@0: &content); andre@0: } else { andre@0: cinfo->content.encryptedData->encContentInfo.plainContent.data = NULL; andre@0: cinfo->content.encryptedData->encContentInfo.encContent.data = NULL; andre@0: cinfo->content.encryptedData->encContentInfo.plainContent.len = 0; andre@0: cinfo->content.encryptedData->encContentInfo.encContent.len = 0; andre@0: rv = SECSuccess; andre@0: } andre@0: if(rv == SECFailure) andre@0: goto loser; andre@0: break; andre@0: case SEC_OID_PKCS7_DATA: andre@0: cinfo->content.data = (SECItem *)PORT_ArenaZAlloc(cinfo->poolp, andre@0: sizeof(SECItem)); andre@0: if(cinfo->content.data == NULL) andre@0: goto loser; andre@0: if(content.len > 0) { andre@0: rv = SECITEM_CopyItem(cinfo->poolp, andre@0: cinfo->content.data, &content); andre@0: } else { andre@0: /* handle case with NULL content */ andre@0: rv = SECSuccess; andre@0: } andre@0: if(rv == SECFailure) andre@0: goto loser; andre@0: break; andre@0: default: andre@0: goto loser; andre@0: } andre@0: andre@0: return SECSuccess; andre@0: andre@0: loser: andre@0: andre@0: return SECFailure; andre@0: } andre@0: andre@0: /* the content of an encrypted data content info is encrypted. andre@0: * it is assumed that for encrypted data, that the data has already andre@0: * been set and is in the "plainContent" field of the content info. andre@0: * andre@0: * cinfo is the content info to encrypt andre@0: * andre@0: * key is the key with which to perform the encryption. if the andre@0: * algorithm is a password based encryption algorithm, the andre@0: * key is actually a password which will be processed per andre@0: * PKCS #5. andre@0: * andre@0: * in the event of an error, SECFailure is returned. SECSuccess andre@0: * indicates a success. andre@0: */ andre@0: SECStatus andre@0: SEC_PKCS7EncryptContents(PLArenaPool *poolp, andre@0: SEC_PKCS7ContentInfo *cinfo, andre@0: SECItem *key, andre@0: void *wincx) andre@0: { andre@0: SECAlgorithmID *algid = NULL; andre@0: SECItem * result = NULL; andre@0: SECItem * src; andre@0: SECItem * dest; andre@0: SECItem * blocked_data = NULL; andre@0: void * mark; andre@0: void * cx; andre@0: PK11SymKey * eKey = NULL; andre@0: PK11SlotInfo * slot = NULL; andre@0: andre@0: CK_MECHANISM_TYPE cryptoMechType; andre@0: int bs; andre@0: SECStatus rv = SECFailure; andre@0: SECItem *c_param = NULL; andre@0: andre@0: if((cinfo == NULL) || (key == NULL)) andre@0: return SECFailure; andre@0: andre@0: if(SEC_PKCS7ContentType(cinfo) != SEC_OID_PKCS7_ENCRYPTED_DATA) andre@0: return SECFailure; andre@0: andre@0: algid = SEC_PKCS7GetEncryptionAlgorithm(cinfo); andre@0: if(algid == NULL) andre@0: return SECFailure; andre@0: andre@0: if(poolp == NULL) andre@0: poolp = cinfo->poolp; andre@0: andre@0: mark = PORT_ArenaMark(poolp); andre@0: andre@0: src = &cinfo->content.encryptedData->encContentInfo.plainContent; andre@0: dest = &cinfo->content.encryptedData->encContentInfo.encContent; andre@0: dest->data = (unsigned char*)PORT_ArenaZAlloc(poolp, (src->len + 64)); andre@0: dest->len = (src->len + 64); andre@0: if(dest->data == NULL) { andre@0: rv = SECFailure; andre@0: goto loser; andre@0: } andre@0: andre@0: slot = PK11_GetInternalKeySlot(); andre@0: if(slot == NULL) { andre@0: rv = SECFailure; andre@0: goto loser; andre@0: } andre@0: andre@0: eKey = PK11_PBEKeyGen(slot, algid, key, PR_FALSE, wincx); andre@0: if(eKey == NULL) { andre@0: rv = SECFailure; andre@0: goto loser; andre@0: } andre@0: andre@0: cryptoMechType = PK11_GetPBECryptoMechanism(algid, &c_param, key); andre@0: if (cryptoMechType == CKM_INVALID_MECHANISM) { andre@0: rv = SECFailure; andre@0: goto loser; andre@0: } andre@0: andre@0: /* block according to PKCS 8 */ andre@0: bs = PK11_GetBlockSize(cryptoMechType, c_param); andre@0: rv = SECSuccess; andre@0: if(bs) { andre@0: char pad_char; andre@0: pad_char = (char)(bs - (src->len % bs)); andre@0: if(src->len % bs) { andre@0: rv = SECSuccess; andre@0: blocked_data = PK11_BlockData(src, bs); andre@0: if(blocked_data) { andre@0: PORT_Memset((blocked_data->data + blocked_data->len andre@0: - (int)pad_char), andre@0: pad_char, (int)pad_char); andre@0: } else { andre@0: rv = SECFailure; andre@0: goto loser; andre@0: } andre@0: } else { andre@0: blocked_data = SECITEM_DupItem(src); andre@0: if(blocked_data) { andre@0: blocked_data->data = (unsigned char*)PORT_Realloc( andre@0: blocked_data->data, andre@0: blocked_data->len + bs); andre@0: if(blocked_data->data) { andre@0: blocked_data->len += bs; andre@0: PORT_Memset((blocked_data->data + src->len), (char)bs, bs); andre@0: } else { andre@0: rv = SECFailure; andre@0: goto loser; andre@0: } andre@0: } else { andre@0: rv = SECFailure; andre@0: goto loser; andre@0: } andre@0: } andre@0: } else { andre@0: blocked_data = SECITEM_DupItem(src); andre@0: if(!blocked_data) { andre@0: rv = SECFailure; andre@0: goto loser; andre@0: } andre@0: } andre@0: andre@0: cx = PK11_CreateContextBySymKey(cryptoMechType, CKA_ENCRYPT, andre@0: eKey, c_param); andre@0: if(cx == NULL) { andre@0: rv = SECFailure; andre@0: goto loser; andre@0: } andre@0: andre@0: rv = PK11_CipherOp((PK11Context*)cx, dest->data, (int *)(&dest->len), andre@0: (int)(src->len + 64), blocked_data->data, andre@0: (int)blocked_data->len); andre@0: PK11_DestroyContext((PK11Context*)cx, PR_TRUE); andre@0: andre@0: loser: andre@0: /* let success fall through */ andre@0: if(blocked_data != NULL) andre@0: SECITEM_ZfreeItem(blocked_data, PR_TRUE); andre@0: andre@0: if(result != NULL) andre@0: SECITEM_ZfreeItem(result, PR_TRUE); andre@0: andre@0: if(rv == SECFailure) andre@0: PORT_ArenaRelease(poolp, mark); andre@0: else andre@0: PORT_ArenaUnmark(poolp, mark); andre@0: andre@0: if(eKey != NULL) andre@0: PK11_FreeSymKey(eKey); andre@0: andre@0: if(slot != NULL) andre@0: PK11_FreeSlot(slot); andre@0: andre@0: if(c_param != NULL) andre@0: SECITEM_ZfreeItem(c_param, PR_TRUE); andre@0: andre@0: return rv; andre@0: } andre@0: andre@0: /* the content of an encrypted data content info is decrypted. andre@0: * it is assumed that for encrypted data, that the data has already andre@0: * been set and is in the "encContent" field of the content info. andre@0: * andre@0: * cinfo is the content info to decrypt andre@0: * andre@0: * key is the key with which to perform the decryption. if the andre@0: * algorithm is a password based encryption algorithm, the andre@0: * key is actually a password which will be processed per andre@0: * PKCS #5. andre@0: * andre@0: * in the event of an error, SECFailure is returned. SECSuccess andre@0: * indicates a success. andre@0: */ andre@0: SECStatus andre@0: SEC_PKCS7DecryptContents(PLArenaPool *poolp, andre@0: SEC_PKCS7ContentInfo *cinfo, andre@0: SECItem *key, andre@0: void *wincx) andre@0: { andre@0: SECAlgorithmID *algid = NULL; andre@0: SECStatus rv = SECFailure; andre@0: SECItem *result = NULL, *dest, *src; andre@0: void *mark; andre@0: andre@0: PK11SymKey *eKey = NULL; andre@0: PK11SlotInfo *slot = NULL; andre@0: CK_MECHANISM_TYPE cryptoMechType; andre@0: void *cx; andre@0: SECItem *c_param = NULL; andre@0: int bs; andre@0: andre@0: if((cinfo == NULL) || (key == NULL)) andre@0: return SECFailure; andre@0: andre@0: if(SEC_PKCS7ContentType(cinfo) != SEC_OID_PKCS7_ENCRYPTED_DATA) andre@0: return SECFailure; andre@0: andre@0: algid = SEC_PKCS7GetEncryptionAlgorithm(cinfo); andre@0: if(algid == NULL) andre@0: return SECFailure; andre@0: andre@0: if(poolp == NULL) andre@0: poolp = cinfo->poolp; andre@0: andre@0: mark = PORT_ArenaMark(poolp); andre@0: andre@0: src = &cinfo->content.encryptedData->encContentInfo.encContent; andre@0: dest = &cinfo->content.encryptedData->encContentInfo.plainContent; andre@0: dest->data = (unsigned char*)PORT_ArenaZAlloc(poolp, (src->len + 64)); andre@0: dest->len = (src->len + 64); andre@0: if(dest->data == NULL) { andre@0: rv = SECFailure; andre@0: goto loser; andre@0: } andre@0: andre@0: slot = PK11_GetInternalKeySlot(); andre@0: if(slot == NULL) { andre@0: rv = SECFailure; andre@0: goto loser; andre@0: } andre@0: andre@0: eKey = PK11_PBEKeyGen(slot, algid, key, PR_FALSE, wincx); andre@0: if(eKey == NULL) { andre@0: rv = SECFailure; andre@0: goto loser; andre@0: } andre@0: andre@0: cryptoMechType = PK11_GetPBECryptoMechanism(algid, &c_param, key); andre@0: if (cryptoMechType == CKM_INVALID_MECHANISM) { andre@0: rv = SECFailure; andre@0: goto loser; andre@0: } andre@0: andre@0: cx = PK11_CreateContextBySymKey(cryptoMechType, CKA_DECRYPT, andre@0: eKey, c_param); andre@0: if(cx == NULL) { andre@0: rv = SECFailure; andre@0: goto loser; andre@0: } andre@0: andre@0: rv = PK11_CipherOp((PK11Context*)cx, dest->data, (int *)(&dest->len), andre@0: (int)(src->len + 64), src->data, (int)src->len); andre@0: PK11_DestroyContext((PK11Context *)cx, PR_TRUE); andre@0: andre@0: bs = PK11_GetBlockSize(cryptoMechType, c_param); andre@0: if(bs) { andre@0: /* check for proper badding in block algorithms. this assumes andre@0: * RC2 cbc or a DES cbc variant. and the padding is thus defined andre@0: */ andre@0: if(((int)dest->data[dest->len-1] <= bs) && andre@0: ((int)dest->data[dest->len-1] > 0)) { andre@0: dest->len -= (int)dest->data[dest->len-1]; andre@0: } else { andre@0: rv = SECFailure; andre@0: /* set an error ? */ andre@0: } andre@0: } andre@0: andre@0: loser: andre@0: /* let success fall through */ andre@0: if(result != NULL) andre@0: SECITEM_ZfreeItem(result, PR_TRUE); andre@0: andre@0: if(rv == SECFailure) andre@0: PORT_ArenaRelease(poolp, mark); andre@0: else andre@0: PORT_ArenaUnmark(poolp, mark); andre@0: andre@0: if(eKey != NULL) andre@0: PK11_FreeSymKey(eKey); andre@0: andre@0: if(slot != NULL) andre@0: PK11_FreeSlot(slot); andre@0: andre@0: if(c_param != NULL) andre@0: SECITEM_ZfreeItem(c_param, PR_TRUE); andre@0: andre@0: return rv; andre@0: } andre@0: andre@0: SECItem ** andre@0: SEC_PKCS7GetCertificateList(SEC_PKCS7ContentInfo *cinfo) andre@0: { andre@0: switch(SEC_PKCS7ContentType(cinfo)) andre@0: { andre@0: case SEC_OID_PKCS7_SIGNED_DATA: andre@0: return cinfo->content.signedData->rawCerts; andre@0: break; andre@0: default: andre@0: return NULL; andre@0: break; andre@0: } andre@0: } andre@0: andre@0: andre@0: int andre@0: SEC_PKCS7GetKeyLength(SEC_PKCS7ContentInfo *cinfo) andre@0: { andre@0: if (cinfo->contentTypeTag->offset == SEC_OID_PKCS7_ENVELOPED_DATA) andre@0: return cinfo->content.envelopedData->encContentInfo.keysize; andre@0: else andre@0: return 0; andre@0: } andre@0: