/* This Source Code Form is subject to the terms of the Mozilla Public *License,v.2.0.IfacopyoftheMPLwasnotdistributedwiththis
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/* A SafeInfo is used for each ContentInfo which makes up the *sequenceofsafesintheAuthenticatedSafeportionofthe *PFXstructure.
*/ struct SEC_PKCS12SafeInfoStr {
PLArenaPool *arena;
/* information for setting up password encryption */
SECItem pwitem;
SECOidTag algorithm;
PK11SymKey *encryptionKey;
/* how many items have been stored in this safe, *wewillskipanysafewhichdoesnotcontainany *items
*/ unsignedint itemCount;
/* the content info for the safe */
SEC_PKCS7ContentInfo *cinfo;
sec_PKCS12SafeContents *safe;
};
/* An opaque structure which contains information needed for exporting *certificatesandkeysthroughPKCS12.
*/ struct SEC_PKCS12ExportContextStr {
PLArenaPool *arena;
PK11SlotInfo *slot; void *wincx;
/* integrity information */
PRBool integrityEnabled;
PRBool pwdIntegrity; union { struct sec_PKCS12PasswordModeInfo pwdInfo; struct sec_PKCS12PublicKeyModeInfo pubkeyInfo;
} integrityInfo;
/* helper functions */ /* retrieve the password call back */
SECKEYGetPasswordKey pwfn; void *pwfnarg;
/* the sequence of safes */
sec_PKCS12AuthenticatedSafe authSafe;
/* information needing deletion */
CERTCertificate **certList;
};
/* structures for passing information to encoder callbacks when processing *datathroughtheASN1engine.
*/ struct sec_pkcs12_encoder_output {
SEC_PKCS12EncoderOutputCallback outputfn; void *outputarg;
};
/* An encoder context which is used for the actual encoding *portionofPKCS12.
*/ typedefstruct sec_PKCS12EncoderContextStr {
PLArenaPool *arena;
SEC_PKCS12ExportContext *p12exp;
/* encoder information - this is set up based on whether *passwordbasedorpublickeypasedprivacyisbeingused
*/
SEC_ASN1EncoderContext *outerA1ecx; union { struct sec_pkcs12_hmac_and_output_info hmacAndOutputInfo; struct sec_pkcs12_encoder_output encOutput;
} output;
/* structures for encoding of PFX and MAC */
sec_PKCS12PFXItem pfx;
sec_PKCS12MacData mac;
/* append the newly created safeInfo to list of safeInfos in the export *context.
*/ static SECStatus
sec_pkcs12_append_safe_info(SEC_PKCS12ExportContext *p12ctxt, SEC_PKCS12SafeInfo *info)
{ void *mark = NULL, *dummy1 = NULL, *dummy2 = NULL;
/* allocate the safe info */
mark = PORT_ArenaMark(p12ctxt->arena);
safeInfo = (SEC_PKCS12SafeInfo *)PORT_ArenaZAlloc(p12ctxt->arena, sizeof(SEC_PKCS12SafeInfo)); if (!safeInfo) {
PORT_SetError(SEC_ERROR_NO_MEMORY); goto loser;
}
safeInfo->itemCount = 0;
/* create the encrypted safe */ if (!SEC_PKCS5IsAlgorithmPBEAlgTag(privAlg)) {
SECOidTag prfAlg = SEC_OID_UNKNOWN; /* if we have password integrity set, use that to set the integrity *hashalgorithmtosetourpasswordPRF.Ifwehaven'tsetit,just
* let the low level code pick it */ if (p12ctxt->integrityEnabled && p12ctxt->pwdIntegrity) {
SECOidTag integrityAlg = p12ctxt->integrityInfo.pwdInfo.algorithm;
prfAlg = integrityAlg; /* verify that integrityAlg is an HMAC */ if (HASH_GetHashOidTagByHMACOidTag(integrityAlg) == SEC_OID_UNKNOWN) { /* it's not, find the hmac */
prfAlg = HASH_GetHMACOidTagByHashOidTag(integrityAlg); /* if prfAlg is SEC_OID_UNKNOWN at this point we'll
* default to SEC_OID_HMAC_SHA1 in the low level pbe code. */
}
} if (!SEC_PKCS12CipherAllowed(privAlg, prfAlg)) {
PORT_SetError(SEC_ERROR_BAD_EXPORT_ALGORITHM); goto loser;
}
safeInfo->cinfo = SEC_PKCS7CreateEncryptedDataWithPBEV2(SEC_OID_PKCS5_PBES2,
privAlg,
prfAlg, 0,
p12ctxt->pwfn,
p12ctxt->pwfnarg);
} else { if (!SEC_PKCS12CipherAllowed(privAlg, SEC_OID_UNKNOWN)) {
PORT_SetError(SEC_ERROR_BAD_EXPORT_ALGORITHM); goto loser;
}
safeInfo->cinfo = SEC_PKCS7CreateEncryptedData(privAlg, 0, p12ctxt->pwfn,
p12ctxt->pwfnarg);
} if (!safeInfo->cinfo) {
PORT_SetError(SEC_ERROR_NO_MEMORY); goto loser;
}
safeInfo->arena = p12ctxt->arena;
/* creates a safe contents which safeBags will be appended to */
sec_PKCS12SafeContents *
sec_PKCS12CreateSafeContents(PLArenaPool *arena)
{
sec_PKCS12SafeContents *safeContents;
if (arena == NULL) { return NULL;
}
/* create the safe contents */
safeContents = (sec_PKCS12SafeContents *)PORT_ArenaZAlloc(arena, sizeof(sec_PKCS12SafeContents)); if (!safeContents) {
PORT_SetError(SEC_ERROR_NO_MEMORY); goto loser;
}
/* set up the internal contents info */
safeContents->safeBags = NULL;
safeContents->arena = arena;
safeContents->bagCount = 0;
return safeContents;
loser: return NULL;
}
/* appends a safe bag to a safeContents using the specified arena.
*/
SECStatus
sec_pkcs12_append_bag_to_safe_contents(PLArenaPool *arena,
sec_PKCS12SafeContents *safeContents,
sec_PKCS12SafeBag *safeBag)
{ void *mark = NULL, *dummy = NULL;
if (!arena || !safeBag || !safeContents) { return SECFailure;
}
mark = PORT_ArenaMark(arena); if (!mark) {
PORT_SetError(SEC_ERROR_NO_MEMORY); return SECFailure;
}
/* allocate space for the list, or reallocate to increase space */ if (!safeContents->safeBags) {
safeContents->safeBags = (sec_PKCS12SafeBag **)PORT_ArenaZAlloc(arena,
(2 * sizeof(sec_PKCS12SafeBag *)));
dummy = safeContents->safeBags;
safeContents->bagCount = 0;
} else {
dummy = PORT_ArenaGrow(arena, safeContents->safeBags,
(safeContents->bagCount + 1) * sizeof(sec_PKCS12SafeBag *),
(safeContents->bagCount + 2) * sizeof(sec_PKCS12SafeBag *));
safeContents->safeBags = (sec_PKCS12SafeBag **)dummy;
}
if (!dummy) {
PORT_ArenaRelease(arena, mark);
PORT_SetError(SEC_ERROR_NO_MEMORY); return SECFailure;
}
/* append the bag at the end and null terminate the list */
safeContents->safeBags[safeContents->bagCount++] = safeBag;
safeContents->safeBags[safeContents->bagCount] = NULL;
PORT_ArenaUnmark(arena, mark);
return SECSuccess;
}
/* appends a safeBag to a specific safeInfo.
*/
SECStatus
sec_pkcs12_append_bag(SEC_PKCS12ExportContext *p12ctxt,
SEC_PKCS12SafeInfo *safeInfo, sec_PKCS12SafeBag *safeBag)
{
sec_PKCS12SafeContents *dest;
SECStatus rv = SECFailure;
if (!p12ctxt || !safeBag || !safeInfo) { return SECFailure;
}
if (!safeInfo->safe) {
safeInfo->safe = sec_PKCS12CreateSafeContents(p12ctxt->arena); if (!safeInfo->safe) { return SECFailure;
}
}
dest = safeInfo->safe;
rv = sec_pkcs12_append_bag_to_safe_contents(p12ctxt->arena, dest, safeBag); if (rv == SECSuccess) {
safeInfo->itemCount++;
}
return rv;
}
/* Creates a safeBag of the specified type, and if bagData is specified, *thecontentsareset.Thecontentscouldbesetlaterbythecalling *routine.
*/
sec_PKCS12SafeBag *
sec_PKCS12CreateSafeBag(SEC_PKCS12ExportContext *p12ctxt, SECOidTag bagType, void *bagData)
{
sec_PKCS12SafeBag *safeBag; void *mark = NULL;
SECStatus rv = SECSuccess;
SECOidData *oidData = NULL;
if (!p12ctxt) { return NULL;
}
mark = PORT_ArenaMark(p12ctxt->arena); if (!mark) {
PORT_SetError(SEC_ERROR_NO_MEMORY); return NULL;
}
/* set the bags content based upon bag type */ switch (bagType) { case SEC_OID_PKCS12_V1_KEY_BAG_ID:
safeBag->safeBagContent.pkcs8KeyBag =
(SECKEYPrivateKeyInfo *)bagData; break; case SEC_OID_PKCS12_V1_CERT_BAG_ID:
safeBag->safeBagContent.certBag = (sec_PKCS12CertBag *)bagData; break; case SEC_OID_PKCS12_V1_CRL_BAG_ID:
safeBag->safeBagContent.crlBag = (sec_PKCS12CRLBag *)bagData; break; case SEC_OID_PKCS12_V1_SECRET_BAG_ID:
safeBag->safeBagContent.secretBag = (sec_PKCS12SecretBag *)bagData; break; case SEC_OID_PKCS12_V1_PKCS8_SHROUDED_KEY_BAG_ID:
safeBag->safeBagContent.pkcs8ShroudedKeyBag =
(SECKEYEncryptedPrivateKeyInfo *)bagData; break; case SEC_OID_PKCS12_V1_SAFE_CONTENTS_BAG_ID:
safeBag->safeBagContent.safeContents =
(sec_PKCS12SafeContents *)bagData; break; default: goto loser;
}
loser: if (mark) {
PORT_ArenaRelease(p12ctxt->arena, mark);
}
return NULL;
}
/* Creates a new certificate bag and returns a pointer to it. If an error *occursNULLisreturned.
*/
sec_PKCS12CertBag *
sec_PKCS12NewCertBag(PLArenaPool *arena, SECOidTag certType)
{
sec_PKCS12CertBag *certBag = NULL;
SECOidData *bagType = NULL;
SECStatus rv; void *mark = NULL;
if (!arena) { return NULL;
}
mark = PORT_ArenaMark(arena);
certBag = (sec_PKCS12CertBag *)PORT_ArenaZAlloc(arena, sizeof(sec_PKCS12CertBag)); if (!certBag) {
PORT_ArenaRelease(arena, mark);
PORT_SetError(SEC_ERROR_NO_MEMORY); return NULL;
}
bagType = SECOID_FindOIDByTag(certType); if (!bagType) {
PORT_SetError(SEC_ERROR_NO_MEMORY); goto loser;
}
/* Creates a new CRL bag and returns a pointer to it. If an error *occursNULLisreturned.
*/
sec_PKCS12CRLBag *
sec_PKCS12NewCRLBag(PLArenaPool *arena, SECOidTag crlType)
{
sec_PKCS12CRLBag *crlBag = NULL;
SECOidData *bagType = NULL;
SECStatus rv; void *mark = NULL;
if (!arena) { return NULL;
}
mark = PORT_ArenaMark(arena);
crlBag = (sec_PKCS12CRLBag *)PORT_ArenaZAlloc(arena, sizeof(sec_PKCS12CRLBag)); if (!crlBag) {
PORT_ArenaRelease(arena, mark);
PORT_SetError(SEC_ERROR_NO_MEMORY); return NULL;
}
bagType = SECOID_FindOIDByTag(crlType); if (!bagType) {
PORT_SetError(SEC_ERROR_NO_MEMORY); goto loser;
}
/* append the attribute to the attribute value list */
attribute->attrValue = (SECItem **)PORT_ArenaZAlloc(p12ctxt->arena,
((nItems + 1) * sizeof(SECItem *))); if (!attribute->attrValue) {
PORT_SetError(SEC_ERROR_NO_MEMORY); goto loser;
}
/* XXX this will need to be changed if attributes requiring more than *oneelementareeverused.
*/
attribute->attrValue[0] = (SECItem *)PORT_ArenaZAlloc(p12ctxt->arena, sizeof(SECItem)); if (!attribute->attrValue[0]) {
PORT_SetError(SEC_ERROR_NO_MEMORY); goto loser;
}
attribute->attrValue[1] = NULL;
/* if the cert chain is to be included, we should only be exporting *thecertfromourinternaldatabase.
*/ if (includeCertChain) {
CERTCertificateList *certList = CERT_CertChainFromCert(cert,
certUsageSSLClient,
PR_TRUE); unsignedint count = 0; if (!certList) {
PORT_SetError(SEC_ERROR_NO_MEMORY); goto loser;
}
/* if the certificate has a nickname, we will set the friendly name *tothat.
*/ if (cert->nickname) { if (cert->slot && !PK11_IsInternal(cert->slot)) { /* *Thecertiscomingoffofanexternaltoken, *let'sstripthetokennamefromthenickname *andonlyaddwhatcomesafterthecolonasthe *nickname.-javi
*/ char *delimit;
/* add the friendly name and keyId attributes, if necessary */ if (nick.data) { if (sec_PKCS12AddAttributeToBag(p12ctxt, safeBag,
SEC_OID_PKCS9_FRIENDLY_NAME, &nick) != SECSuccess) { goto loser;
}
}
if (keyId) { if (sec_PKCS12AddAttributeToBag(p12ctxt, safeBag, SEC_OID_PKCS9_LOCAL_KEY_ID,
keyId) != SECSuccess) { goto loser;
}
}
if (!sec_pkcs12_encode_password(p12ctxt->arena, &uniPwitem, algorithm,
pwitem)) {
PORT_SetError(SEC_ERROR_NO_MEMORY); goto loser;
}
/* if we have password integrity set, use that to set the integrity *hashalgorithmtosetourpasswordPRF.Ifwehaven'tsetit,just
* let the low level code pick it */ if (p12ctxt->integrityEnabled && p12ctxt->pwdIntegrity) {
SECOidTag integrityAlg = p12ctxt->integrityInfo.pwdInfo.algorithm;
prfAlg = integrityAlg; /* verify that integrityAlg is an HMAC */ if (HASH_GetHashOidTagByHMACOidTag(integrityAlg) == SEC_OID_UNKNOWN) { /* it's not, find the hmac */
prfAlg = HASH_GetHMACOidTagByHashOidTag(integrityAlg); /* if prfAlg is SEC_OID_UNKNOWN at this point we'll
* default to SEC_OID_HMAC_SHA1 in the low level pbe code. */
}
}
if (!SEC_PKCS12CipherAllowed(algorithm, prfAlg)) {
PORT_SetError(SEC_ERROR_BAD_EXPORT_ALGORITHM); goto loser;
}
/* we want to make sure to take the key out of the key slot */ if (PK11_IsInternal(p12ctxt->slot)) {
slot = PK11_GetInternalKeySlot();
} else {
slot = PK11_ReferenceSlot(p12ctxt->slot);
}
/* passing algorithm as the pbe will force the PBE code to *automaticallyhandletheselectionbetweenusingthealgorithm *asathepbealgorithm,orusingthealgorithmasacipher
* and building a pkcs5 pbe */
epki = PK11_ExportEncryptedPrivateKeyInfoV2(slot, algorithm,
SEC_OID_UNKNOWN, prfAlg,
&uniPwitem, cert,
NSS_PBE_DEFAULT_ITERATION_COUNT,
p12ctxt->wincx);
PK11_FreeSlot(slot); if (!epki) {
PORT_SetError(SEC_ERROR_PKCS12_UNABLE_TO_EXPORT_KEY); goto loser;
}
/* if no nickname specified, let's see if the certificate has a *nickname.
*/ if (!nickName) { if (cert->nickname) {
nickname.data = (unsignedchar *)cert->nickname;
nickname.len = PORT_Strlen(cert->nickname);
nickName = &nickname;
}
}
/* create the safe bag and set any attributes */
returnBag = sec_PKCS12CreateSafeBag(p12ctxt, keyType, keyItem); if (!returnBag) {
rv = SECFailure; goto loser;
}
if (nickName) { if (sec_PKCS12AddAttributeToBag(p12ctxt, returnBag,
SEC_OID_PKCS9_FRIENDLY_NAME, nickName) != SECSuccess) { goto loser;
}
}
if (keyId) { if (sec_PKCS12AddAttributeToBag(p12ctxt, returnBag, SEC_OID_PKCS9_LOCAL_KEY_ID,
keyId) != SECSuccess) { goto loser;
}
}
/* generate the thumbprint of the cert to use as a keyId */
digest = sec_pkcs12_compute_thumbprint(&cert->derCert); if (!digest) {
PORT_ArenaRelease(p12ctxt->arena, mark); return SECFailure;
}
/* Clean up the resources allocated by a sec_PKCS12EncoderContext. */ staticvoid
sec_pkcs12_encoder_destroy_context(sec_PKCS12EncoderContext *p12enc)
{ if (p12enc) { if (p12enc->outerA1ecx) {
SEC_ASN1EncoderFinish(p12enc->outerA1ecx);
p12enc->outerA1ecx = NULL;
} if (p12enc->aSafeCinfo) {
SEC_PKCS7DestroyContentInfo(p12enc->aSafeCinfo);
p12enc->aSafeCinfo = NULL;
} if (p12enc->middleP7ecx) {
SEC_PKCS7EncoderFinish(p12enc->middleP7ecx, p12enc->p12exp->pwfn,
p12enc->p12exp->pwfnarg);
p12enc->middleP7ecx = NULL;
} if (p12enc->middleA1ecx) {
SEC_ASN1EncoderFinish(p12enc->middleA1ecx);
p12enc->middleA1ecx = NULL;
} if (p12enc->hmacCx) {
PK11_DestroyContext(p12enc->hmacCx, PR_TRUE);
p12enc->hmacCx = NULL;
}
}
}
/* set up the encoder context based on information in the export context *andreturnthenewlyallocatedenocodercontext.AreturnofNULL *indicatesanerroroccurred.
*/ static sec_PKCS12EncoderContext *
sec_pkcs12_encoder_start_context(SEC_PKCS12ExportContext *p12exp)
{
sec_PKCS12EncoderContext *p12enc = NULL; unsignedint i, nonEmptyCnt;
SECStatus rv;
SECItem ignore = { 0 }; void *mark;
SECItem *salt = NULL;
SECItem pwd = { siBuffer, NULL, 0 };
if (!p12exp || !p12exp->safeInfos) { return NULL;
}
/* check for any empty safes and skip them */
i = nonEmptyCnt = 0; while (p12exp->safeInfos[i]) { if (p12exp->safeInfos[i]->itemCount) {
nonEmptyCnt++;
}
i++;
} if (nonEmptyCnt == 0) { return NULL;
}
p12exp->authSafe.encodedSafes[nonEmptyCnt] = NULL;
/* allocate the encoder context */
mark = PORT_ArenaMark(p12exp->arena);
p12enc = PORT_ArenaZNew(p12exp->arena, sec_PKCS12EncoderContext); if (!p12enc) {
PORT_SetError(SEC_ERROR_NO_MEMORY); return NULL;
}
/* set up the PFX version and information */
PORT_Memset(&p12enc->pfx, 0, sizeof(sec_PKCS12PFXItem)); if (!SEC_ASN1EncodeInteger(p12exp->arena, &(p12enc->pfx.version),
SEC_PKCS12_VERSION)) {
PORT_SetError(SEC_ERROR_NO_MEMORY); goto loser;
}
/* set up the authenticated safe content info based on the *typeofintegritybeingused.thisshouldbechangedto *enforceintegritymode,butwillnotbeimplementeduntil *itisconfirmedthatintegritymustbeinplace
*/ if (p12exp->integrityEnabled && !p12exp->pwdIntegrity) { /* create public key integrity mode */
p12enc->aSafeCinfo = SEC_PKCS7CreateSignedData(
p12exp->integrityInfo.pubkeyInfo.cert,
certUsageEmailSigner,
p12exp->integrityInfo.pubkeyInfo.certDb,
p12exp->integrityInfo.pubkeyInfo.algorithm,
NULL,
p12exp->pwfn,
p12exp->pwfnarg); if (!p12enc->aSafeCinfo) { goto loser;
} if (SEC_PKCS7IncludeCertChain(p12enc->aSafeCinfo, NULL) != SECSuccess) { goto loser;
}
PORT_CheckSuccess(SEC_PKCS7AddSigningTime(p12enc->aSafeCinfo));
} else {
p12enc->aSafeCinfo = SEC_PKCS7CreateData();
/* create the digest info */
hmacAlgTag = p12exp->integrityInfo.pwdInfo.algorithm;
hashAlgTag = HASH_GetHashOidTagByHMACOidTag(hmacAlgTag); if (hashAlgTag != SEC_OID_UNKNOWN) { /* if the application asks for hmac explicitly, then use
* pkcs5v2 mac1 encoding */
SECAlgorithmID *algID; int keyLength;
keyLength = HASH_ResultLenByOidTag(hashAlgTag); if (keyLength == 0) {
PORT_SetError(SEC_ERROR_INVALID_ALGORITHM); return NULL;
} /* create PB_MAC1 params */
algID = PK11_CreatePBEV2AlgorithmID(SEC_OID_PKCS5_PBMAC1,
hmacAlgTag,
hmacAlgTag, keyLength,
NSS_PBE_DEFAULT_ITERATION_COUNT,
&p12enc->mac.macSalt); if (algID == NULL) { goto loser;
}
rv = SECOID_CopyAlgorithmID(p12enc->arena,
&p12enc->mac.safeMac.digestAlgorithm,
algID);
SECOID_DestroyAlgorithmID(algID, PR_TRUE); if (rv != SECSuccess) {
PORT_SetError(SEC_ERROR_NO_MEMORY); goto loser;
}
} elseif (HASH_GetHashTypeByOidTag(hmacAlgTag) != HASH_AlgNULL) { /* encode the algid now for sec_pkcs12_integrity_key to use */ /* this must be a valid hash function, SECOID_SetAlgorithmID *knowstoencodethehashalgidwithanexplicit
* null parameter */
rv = SECOID_SetAlgorithmID(p12enc->arena,
&p12enc->mac.safeMac.digestAlgorithm,
hmacAlgTag, NULL); if (rv != SECSuccess) { goto loser;
}
} else {
PORT_SetError(SEC_ERROR_INVALID_ALGORITHM); goto loser;
}
/* Feeds the output of a PKCS7 encoder into the next outward ASN.1 encoder. **ThisfunctionisusedbyboththeinnerandmiddlePCS7encoders.
*/ staticvoid
sec_P12P7OutputCB_CallA1Update(void *arg, constchar *buf, unsignedlong len)
{
SEC_ASN1EncoderContext *cx = (SEC_ASN1EncoderContext *)arg;
if (!buf || !len) return;
SEC_ASN1EncoderUpdate(cx, buf, len);
}
/* this function encodes content infos which are part of the *sequenceofcontentinfoslabeledAuthenticatedSafes
*/ static SECStatus
sec_pkcs12_encoder_asafe_process(sec_PKCS12EncoderContext *p12ecx)
{
SEC_PKCS7EncoderContext *innerP7ecx;
SEC_PKCS7ContentInfo *cinfo;
PK11SymKey *bulkKey = NULL;
SEC_ASN1EncoderContext *innerA1ecx = NULL;
SECStatus rv = SECSuccess;
if (p12ecx->currentSafe < p12ecx->p12exp->authSafe.safeCount) {
SEC_PKCS12SafeInfo *safeInfo;
SECOidTag cinfoType;
/* determine the safe type and set the appropriate argument */ switch (cinfoType) { case SEC_OID_PKCS7_DATA: case SEC_OID_PKCS7_ENVELOPED_DATA: break; case SEC_OID_PKCS7_ENCRYPTED_DATA:
bulkKey = safeInfo->encryptionKey;
PK11_SetSymKeyUserData(bulkKey, &safeInfo->pwitem, NULL); break; default: return SECFailure;
}
/* start the PKCS7 encoder */
innerP7ecx = SEC_PKCS7EncoderStart(cinfo,
sec_P12P7OutputCB_CallA1Update,
p12ecx->middleA1ecx, bulkKey); if (!innerP7ecx) { goto loser;
}
/* finish the HMAC and encode the macData so that it can be *encoded.
*/ static SECStatus
sec_Pkcs12FinishMac(sec_PKCS12EncoderContext *p12ecx)
{ unsignedchar hmacData[HASH_LENGTH_MAX]; unsignedint hmacLen;
SECStatus rv;
SGNDigestInfo *di = NULL; void *dummy;
if (!p12ecx) { return SECFailure;
}
/* make sure we are using password integrity mode */ if (!p12ecx->p12exp->integrityEnabled) { return SECSuccess;
}
if (!p12ecx->p12exp->pwdIntegrity) { return SECSuccess;
}
if (rv != SECSuccess) {
PORT_SetError(SEC_ERROR_NO_MEMORY); goto loser;
}
/* finish the digest info, algorithm ID is already set */
rv = SECITEM_MakeItem(p12ecx->arena, &p12ecx->mac.safeMac.digest,
hmacData, hmacLen); if (rv != SECSuccess) { goto loser;
}
/* encode the mac data */
dummy = SEC_ASN1EncodeItem(p12ecx->arena, &p12ecx->pfx.encodedMacData,
&p12ecx->mac, sec_PKCS12MacDataTemplate); if (!dummy) {
PORT_SetError(SEC_ERROR_NO_MEMORY);
rv = SECFailure;
}
/* set up PFX encoder, the "outer" encoder. Set it for streaming */
p12enc->outerA1ecx = SEC_ASN1EncoderStart(&p12enc->pfx,
sec_PKCS12PFXItemTemplate,
sec_P12A1OutputCB_Outer,
&outInfo); if (!p12enc->outerA1ecx) {
PORT_SetError(SEC_ERROR_NO_MEMORY);
rv = SECFailure; goto loser;
}
SEC_ASN1EncoderSetStreaming(p12enc->outerA1ecx);
SEC_ASN1EncoderSetNotifyProc(p12enc->outerA1ecx,
sec_pkcs12_encoder_pfx_notify, p12enc);
rv = SEC_ASN1EncoderUpdate(p12enc->outerA1ecx, NULL, 0); if (rv != SECSuccess) {
rv = SECFailure; goto loser;
}
/* set up asafe cinfo - the output of the encoder feeds the PFX encoder */
p12enc->middleP7ecx = SEC_PKCS7EncoderStart(p12enc->aSafeCinfo,
sec_P12P7OutputCB_CallA1Update,
p12enc->outerA1ecx, NULL); if (!p12enc->middleP7ecx) {
rv = SECFailure; goto loser;
}
void
SEC_PKCS12DestroyExportContext(SEC_PKCS12ExportContext *p12ecx)
{ int i = 0;
if (!p12ecx) { return;
}
if (p12ecx->safeInfos) {
i = 0; while (p12ecx->safeInfos[i] != NULL) { if (p12ecx->safeInfos[i]->encryptionKey) {
PK11_FreeSymKey(p12ecx->safeInfos[i]->encryptionKey);
} if (p12ecx->safeInfos[i]->cinfo) {
SEC_PKCS7DestroyContentInfo(p12ecx->safeInfos[i]->cinfo);
}
i++;
}
}
PK11_FreeSlot(p12ecx->slot);
PORT_FreeArena(p12ecx->arena, PR_TRUE);
}
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.31 Sekunden
(vorverarbeitet am 2026-09-28)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.