/* * Parse a ContentInfo in the context of (i.e., as an element of) * an AuthenticatedSafe. */ static int authSafeElementParse(pkcs12_context * context, const NSS_P7_DecodedContentInfo *info) { p12DecodeLog("authSafeElementParse"); switch(info->type) { case CT_Data: /* unencrypted SafeContents */ require_noerr(safeContentsParse(context, info->content.data), out); break; case CT_EncryptedData: { /* * Decrypt contents to get a SafeContents and * then parse that. */ SecAsn1Item ptext = {0, NULL}; NSS_P7_EncryptedData *edata = info->content.encryptData; require_noerr_quiet(p12Decrypt(context, &edata->contentInfo.encrAlg, &edata->contentInfo.encrContent, &ptext), out); require_noerr(safeContentsParse(context, &ptext), out); break; } default: break; } return 0; out: return -1; }
/* * Parse a ContentInfo in the context of (i.e., as an element of) * an AuthenticatedSafe. */ void P12Coder::authSafeElementParse( const NSS_P7_DecodedContentInfo *info, SecNssCoder &localCdr) { p12DecodeLog("authSafeElementParse"); switch(info->type) { case CT_Data: /* unencrypted SafeContents */ safeContentsParse(*info->content.data, localCdr); break; case CT_EncryptedData: { NSS_P12_PBE_Params pbep; encryptedDataParse(*info->content.encryptData, localCdr, &pbep); /* * Decrypt contents to get a SafeContents and * then parse that. */ CSSM_DATA ptext = {0, NULL}; encryptedDataDecrypt(*info->content.encryptData, localCdr, &pbep, ptext); safeContentsParse(ptext, localCdr); break; } default: p12ErrorLog("authSafeElementParse: unknown sage type (%u)\n", (unsigned)info->type); /* well, save it as an opaque bag for now */ P12OpaqueBag *opaque = new P12OpaqueBag( info->contentType, *info->content.data, NULL, // no attrs localCdr); addOpaque(opaque); break; } }
/* * Parse a ContentInfo in the context of (i.e., as an element of) * an element in a AuthenticatedSafe */ static int authSafeElementParse( const NSS_P7_DecodedContentInfo *info, P12ParseInfo &pinfo, unsigned depth) // print indent depth { char oidStr[OID_PARSER_STRING_SIZE]; pinfo.mParser.oidParse(info->contentType.Data, info->contentType.Length, oidStr); doIndent(depth); printf("contentType = %s\n", oidStr); doIndent(depth); printf("type = %s\n", p7ContentInfoTypeStr(info->type)); int rtn = 0; switch(info->type) { case CT_Data: /* unencrypted SafeContents */ doIndent(depth); printf("raw size: %u\n", (unsigned)info->content.data->Length); doIndent(depth); printf("Plaintext SafeContents:\n"); rtn = safeContentsParse(*info->content.data, pinfo, depth+3); break; case CT_EncryptedData: { doIndent(depth); printf("EncryptedData:\n"); NSS_P12_PBE_Params pbep; rtn = encryptedDataParse(*info->content.encryptData, pinfo, &pbep, depth+3); if(rtn) { break; } if(pinfo.mPwd.Data == NULL) { doIndent(depth+3); printf("=== Contents not decrypted (no passphrase)===\n"); } else { /* * Decrypt contents to get a SafeContents and * then parse that. */ CSSM_DATA ptext = {0, NULL}; rtn = encryptedDataDecrypt(*info->content.encryptData, pinfo, &pbep, ptext); doIndent(depth); if(rtn) { printf("***Error decrypting CT_EncryptedData\n"); break; } printf("Decrypted SafeContents {\n"); rtn = safeContentsParse(ptext, pinfo, depth+3); doIndent(depth); printf("}\n"); } break; } default: /* the rest map to an ASN_ANY/CSSM_DATA for now */ doIndent(depth+3); printf("size of %u is all we know today\n", (unsigned)info->content.data->Length); rtn = 0; break; } return rtn; }