p12local.c

来自「支持SSL v2/v3, TLS, PKCS #5, PKCS #7, PKCS」· C语言 代码 · 共 1,326 行 · 第 1/3 页

C
1,326
字号
    dest->len = src->len * 3 + 2;    if(arena) {	dest->data = (unsigned char*)PORT_ArenaZAlloc(arena, dest->len);    } else {	dest->data = (unsigned char*)PORT_ZAlloc(dest->len);    }    if(!dest->data) {	dest->len = 0;	return PR_FALSE;    }    if(!asciiConvert) {	success = PORT_UCS2_UTF8Conversion(toUnicode, src->data, src->len, dest->data,					   dest->len, &dest->len);    } else {#ifndef IS_LITTLE_ENDIAN	PRBool swapUnicode = PR_FALSE;#else	PRBool swapUnicode = PR_TRUE;#endif	success = PORT_UCS2_ASCIIConversion(toUnicode, src->data, src->len, dest->data,					    dest->len, &dest->len, swapUnicode);    }    if(!success) {	if(!arena) {	    PORT_Free(dest->data);	    dest->data = NULL;	    dest->len = 0;	}	return PR_FALSE;    }    if((dest->data[dest->len-1] || dest->data[dest->len-2]) && zeroTerm) {	if(dest->len + 2 > 3 * src->len) {	    if(arena) {		dest->data = (unsigned char*)PORT_ArenaGrow(arena, 						     dest->data, dest->len,						     dest->len + 2);	    } else {		dest->data = (unsigned char*)PORT_Realloc(dest->data, 							  dest->len + 2);	    }	    if(!dest->data) {		return PR_FALSE;	    }	}	dest->len += 2;	dest->data[dest->len-1] = dest->data[dest->len-2] = 0;    }    return PR_TRUE;}/* pkcs 12 templates */static SEC_ChooseASN1TemplateFunc sec_pkcs12_shroud_chooser =    sec_pkcs12_choose_shroud_type;const SEC_ASN1Template SEC_PKCS12CodedSafeBagTemplate[] ={    { SEC_ASN1_SEQUENCE, 0, NULL, sizeof(SEC_PKCS12SafeBag) },    { SEC_ASN1_OBJECT_ID, offsetof(SEC_PKCS12SafeBag, safeBagType) },    { SEC_ASN1_ANY, offsetof(SEC_PKCS12SafeBag, derSafeContent) },    { 0 }};const SEC_ASN1Template SEC_PKCS12CodedCertBagTemplate[] ={    { SEC_ASN1_SEQUENCE, 0, NULL, sizeof(SEC_PKCS12CertAndCRL) },    { SEC_ASN1_OBJECT_ID, offsetof(SEC_PKCS12CertAndCRL, BagID) },    { SEC_ASN1_ANY, offsetof(SEC_PKCS12CertAndCRL, derValue) },    { 0 }};const SEC_ASN1Template SEC_PKCS12CodedCertAndCRLBagTemplate[] ={    { SEC_ASN1_SET_OF, offsetof(SEC_PKCS12CertAndCRLBag, certAndCRLs),	SEC_PKCS12CodedCertBagTemplate },};const SEC_ASN1Template SEC_PKCS12ESPVKItemTemplate_OLD[] = {    { SEC_ASN1_SEQUENCE, 0, NULL, sizeof(SEC_PKCS12ESPVKItem) },    { SEC_ASN1_OBJECT_ID, offsetof(SEC_PKCS12ESPVKItem, espvkOID) },    { SEC_ASN1_INLINE, offsetof(SEC_PKCS12ESPVKItem, espvkData),	SEC_PKCS12PVKSupportingDataTemplate_OLD },    { SEC_ASN1_EXPLICIT | SEC_ASN1_CONSTRUCTED | SEC_ASN1_CONTEXT_SPECIFIC |	SEC_ASN1_DYNAMIC | 0, offsetof(SEC_PKCS12ESPVKItem, espvkCipherText),	&sec_pkcs12_shroud_chooser },    { 0 }};const SEC_ASN1Template SEC_PKCS12ESPVKItemTemplate[] = {    { SEC_ASN1_SEQUENCE, 0, NULL, sizeof(SEC_PKCS12ESPVKItem) },    { SEC_ASN1_OBJECT_ID, offsetof(SEC_PKCS12ESPVKItem, espvkOID) },    { SEC_ASN1_INLINE, offsetof(SEC_PKCS12ESPVKItem, espvkData),	SEC_PKCS12PVKSupportingDataTemplate },    { SEC_ASN1_EXPLICIT | SEC_ASN1_CONSTRUCTED | SEC_ASN1_CONTEXT_SPECIFIC |	SEC_ASN1_DYNAMIC | 0, offsetof(SEC_PKCS12ESPVKItem, espvkCipherText),	&sec_pkcs12_shroud_chooser },    { 0 }};const SEC_ASN1Template SEC_PKCS12PVKAdditionalDataTemplate[] ={    { SEC_ASN1_SEQUENCE, 0, NULL, sizeof(SEC_PKCS12PVKAdditionalData) },    { SEC_ASN1_OBJECT_ID, 	offsetof(SEC_PKCS12PVKAdditionalData, pvkAdditionalType) },    { SEC_ASN1_CONSTRUCTED | SEC_ASN1_CONTEXT_SPECIFIC | 0,	offsetof(SEC_PKCS12PVKAdditionalData, pvkAdditionalContent) },    { 0 }};const SEC_ASN1Template SEC_PKCS12PVKSupportingDataTemplate_OLD[] ={    { SEC_ASN1_SEQUENCE, 0, NULL, sizeof(SEC_PKCS12PVKSupportingData) },    { SEC_ASN1_SET_OF, offsetof(SEC_PKCS12PVKSupportingData, assocCerts),	sgn_DigestInfoTemplate },    { SEC_ASN1_OPTIONAL | SEC_ASN1_BOOLEAN, 	offsetof(SEC_PKCS12PVKSupportingData, regenerable) },    { SEC_ASN1_PRINTABLE_STRING, 	offsetof(SEC_PKCS12PVKSupportingData, nickname) },    { SEC_ASN1_ANY | SEC_ASN1_OPTIONAL,	offsetof(SEC_PKCS12PVKSupportingData, pvkAdditionalDER) },    { 0 }};const SEC_ASN1Template SEC_PKCS12PVKSupportingDataTemplate[] ={    { SEC_ASN1_SEQUENCE, 0, NULL, sizeof(SEC_PKCS12PVKSupportingData) },    { SEC_ASN1_SET_OF, offsetof(SEC_PKCS12PVKSupportingData, assocCerts),	sgn_DigestInfoTemplate },    { SEC_ASN1_OPTIONAL | SEC_ASN1_BOOLEAN, 	offsetof(SEC_PKCS12PVKSupportingData, regenerable) },    { SEC_ASN1_BMP_STRING, 	offsetof(SEC_PKCS12PVKSupportingData, uniNickName) },    { SEC_ASN1_ANY | SEC_ASN1_OPTIONAL,	offsetof(SEC_PKCS12PVKSupportingData, pvkAdditionalDER) },    { 0 }};const SEC_ASN1Template SEC_PKCS12BaggageItemTemplate[] ={    { SEC_ASN1_SEQUENCE, 0, NULL, sizeof(SEC_PKCS12BaggageItem) },    { SEC_ASN1_SET_OF, offsetof(SEC_PKCS12BaggageItem, espvks),	SEC_PKCS12ESPVKItemTemplate },    { SEC_ASN1_SET_OF, offsetof(SEC_PKCS12BaggageItem, unencSecrets),	SEC_PKCS12SafeBagTemplate },    /*{ SEC_ASN1_SET_OF, offsetof(SEC_PKCS12BaggageItem, unencSecrets),	SEC_PKCS12CodedSafeBagTemplate }, */    { 0 }};const SEC_ASN1Template SEC_PKCS12BaggageTemplate[] ={    { SEC_ASN1_SET_OF, offsetof(SEC_PKCS12Baggage, bags),	SEC_PKCS12BaggageItemTemplate },};const SEC_ASN1Template SEC_PKCS12BaggageTemplate_OLD[] ={    { SEC_ASN1_SET_OF, offsetof(SEC_PKCS12Baggage_OLD, espvks),	SEC_PKCS12ESPVKItemTemplate_OLD },};static SEC_ChooseASN1TemplateFunc sec_pkcs12_bag_chooser =	sec_pkcs12_choose_bag_type;static SEC_ChooseASN1TemplateFunc sec_pkcs12_bag_chooser_old =	sec_pkcs12_choose_bag_type_old;const SEC_ASN1Template SEC_PKCS12SafeBagTemplate_OLD[] ={    { SEC_ASN1_SEQUENCE, 0, NULL, sizeof(SEC_PKCS12SafeBag) },    { SEC_ASN1_OBJECT_ID, offsetof(SEC_PKCS12SafeBag, safeBagType) },    { SEC_ASN1_DYNAMIC | SEC_ASN1_CONSTRUCTED | SEC_ASN1_EXPLICIT |	SEC_ASN1_CONTEXT_SPECIFIC | 0,        offsetof(SEC_PKCS12SafeBag, safeContent),	&sec_pkcs12_bag_chooser_old },    { 0 }};const SEC_ASN1Template SEC_PKCS12SafeBagTemplate[] ={    { SEC_ASN1_SEQUENCE, 0, NULL, sizeof(SEC_PKCS12SafeBag) },    { SEC_ASN1_OBJECT_ID, offsetof(SEC_PKCS12SafeBag, safeBagType) },    { SEC_ASN1_DYNAMIC | SEC_ASN1_POINTER,        offsetof(SEC_PKCS12SafeBag, safeContent),	&sec_pkcs12_bag_chooser },    { SEC_ASN1_OPTIONAL | SEC_ASN1_BMP_STRING,	offsetof(SEC_PKCS12SafeBag, uniSafeBagName) },    { 0 }};const SEC_ASN1Template SEC_PKCS12SafeContentsTemplate_OLD[] ={    { SEC_ASN1_SET_OF,	offsetof(SEC_PKCS12SafeContents, contents),	SEC_PKCS12SafeBagTemplate_OLD }};const SEC_ASN1Template SEC_PKCS12SafeContentsTemplate[] ={    { SEC_ASN1_SET_OF,	offsetof(SEC_PKCS12SafeContents, contents),	SEC_PKCS12SafeBagTemplate }  /* here */};const SEC_ASN1Template SEC_PKCS12PrivateKeyTemplate[] ={    { SEC_ASN1_SEQUENCE, 0, NULL, sizeof(SEC_PKCS12PrivateKey) },    { SEC_ASN1_INLINE, offsetof(SEC_PKCS12PrivateKey, pvkData),	SEC_PKCS12PVKSupportingDataTemplate },    { SEC_ASN1_INLINE, offsetof(SEC_PKCS12PrivateKey, pkcs8data),	SECKEY_PrivateKeyInfoTemplate },    { 0 }};const SEC_ASN1Template SEC_PKCS12PrivateKeyBagTemplate[] ={    { SEC_ASN1_SEQUENCE, 0, NULL, sizeof(SEC_PKCS12PrivateKeyBag) },    { SEC_ASN1_SET_OF, offsetof(SEC_PKCS12PrivateKeyBag, privateKeys),	SEC_PKCS12PrivateKeyTemplate },    { 0 }};const SEC_ASN1Template SEC_PKCS12X509CertCRLTemplate_OLD[] ={    { SEC_ASN1_SEQUENCE, 0, NULL, sizeof(SEC_PKCS12X509CertCRL) },    { SEC_ASN1_INLINE, offsetof(SEC_PKCS12X509CertCRL, certOrCRL),	sec_PKCS7ContentInfoTemplate },    { SEC_ASN1_INLINE, offsetof(SEC_PKCS12X509CertCRL, thumbprint),	sgn_DigestInfoTemplate },    { 0 }};const SEC_ASN1Template SEC_PKCS12X509CertCRLTemplate[] ={    { SEC_ASN1_SEQUENCE, 0, NULL, sizeof(SEC_PKCS12X509CertCRL) },    { SEC_ASN1_INLINE, offsetof(SEC_PKCS12X509CertCRL, certOrCRL),	sec_PKCS7ContentInfoTemplate },    { 0 }};const SEC_ASN1Template SEC_PKCS12SDSICertTemplate[] ={    { SEC_ASN1_SEQUENCE, 0, NULL, sizeof(SEC_PKCS12X509CertCRL) },    { SEC_ASN1_IA5_STRING, offsetof(SEC_PKCS12SDSICert, value) },    { 0 }};static SEC_ChooseASN1TemplateFunc sec_pkcs12_cert_crl_chooser_old =	sec_pkcs12_choose_cert_crl_type_old;static SEC_ChooseASN1TemplateFunc sec_pkcs12_cert_crl_chooser =	sec_pkcs12_choose_cert_crl_type;const SEC_ASN1Template SEC_PKCS12CertAndCRLTemplate_OLD[] ={    { SEC_ASN1_SEQUENCE, 0, NULL, sizeof(SEC_PKCS12CertAndCRL) },    { SEC_ASN1_OBJECT_ID, offsetof(SEC_PKCS12CertAndCRL, BagID) },    { SEC_ASN1_CONTEXT_SPECIFIC | SEC_ASN1_EXPLICIT |	SEC_ASN1_DYNAMIC | SEC_ASN1_CONSTRUCTED | 0,	offsetof(SEC_PKCS12CertAndCRL, value),	&sec_pkcs12_cert_crl_chooser_old },    { 0 }};const SEC_ASN1Template SEC_PKCS12CertAndCRLTemplate[] ={    { SEC_ASN1_SEQUENCE, 0, NULL, sizeof(SEC_PKCS12CertAndCRL) },    { SEC_ASN1_OBJECT_ID, offsetof(SEC_PKCS12CertAndCRL, BagID) },    { SEC_ASN1_DYNAMIC | SEC_ASN1_CONSTRUCTED | SEC_ASN1_EXPLICIT |	SEC_ASN1_CONTEXT_SPECIFIC | 0, 	offsetof(SEC_PKCS12CertAndCRL, value),	&sec_pkcs12_cert_crl_chooser },    { 0 }};const SEC_ASN1Template SEC_PKCS12CertAndCRLBagTemplate[] ={    { SEC_ASN1_SET_OF, offsetof(SEC_PKCS12CertAndCRLBag, certAndCRLs),	SEC_PKCS12CertAndCRLTemplate },};const SEC_ASN1Template SEC_PKCS12CertAndCRLBagTemplate_OLD[] ={    { SEC_ASN1_SEQUENCE, 0, NULL, sizeof(SEC_PKCS12CertAndCRLBag) },    { SEC_ASN1_SET_OF, offsetof(SEC_PKCS12CertAndCRLBag, certAndCRLs),	SEC_PKCS12CertAndCRLTemplate_OLD },    { 0 }};const SEC_ASN1Template SEC_PKCS12SecretAdditionalTemplate[] ={    { SEC_ASN1_SEQUENCE, 0, NULL, sizeof(SEC_PKCS12SecretAdditional) },    { SEC_ASN1_OBJECT_ID,	offsetof(SEC_PKCS12SecretAdditional, secretAdditionalType) },    { SEC_ASN1_CONTEXT_SPECIFIC | SEC_ASN1_EXPLICIT,	offsetof(SEC_PKCS12SecretAdditional, secretAdditionalContent) },    { 0 }};const SEC_ASN1Template SEC_PKCS12SecretTemplate[] ={    { SEC_ASN1_SEQUENCE, 0, NULL, sizeof(SEC_PKCS12Secret) },    { SEC_ASN1_BMP_STRING, offsetof(SEC_PKCS12Secret, uniSecretName) },    { SEC_ASN1_ANY, offsetof(SEC_PKCS12Secret, value) },    { SEC_ASN1_INLINE | SEC_ASN1_OPTIONAL,	offsetof(SEC_PKCS12Secret, secretAdditional),	SEC_PKCS12SecretAdditionalTemplate },    { 0 }};const SEC_ASN1Template SEC_PKCS12SecretItemTemplate[] = {    { SEC_ASN1_SEQUENCE, 0, NULL, sizeof(SEC_PKCS12Secret) },    { SEC_ASN1_INLINE | SEC_ASN1_CONTEXT_SPECIFIC | 0,	offsetof(SEC_PKCS12SecretItem, secret), SEC_PKCS12SecretTemplate },    { SEC_ASN1_INLINE | SEC_ASN1_CONTEXT_SPECIFIC | 1,	offsetof(SEC_PKCS12SecretItem, subFolder), SEC_PKCS12SafeBagTemplate },    { 0 }};const SEC_ASN1Template SEC_PKCS12SecretBagTemplate[] ={    { SEC_ASN1_SET_OF, offsetof(SEC_PKCS12SecretBag, secrets),	SEC_PKCS12SecretItemTemplate },};const SEC_ASN1Template SEC_PKCS12MacDataTemplate[] ={    { SEC_ASN1_SEQUENCE, 0, NULL, sizeof(SEC_PKCS12PFXItem) },    { SEC_ASN1_INLINE, offsetof(SEC_PKCS12MacData, safeMac),	sgn_DigestInfoTemplate },    { SEC_ASN1_BIT_STRING, offsetof(SEC_PKCS12MacData, macSalt) },    { 0 }};const SEC_ASN1Template SEC_PKCS12PFXItemTemplate[] ={    { SEC_ASN1_SEQUENCE, 0, NULL, sizeof(SEC_PKCS12PFXItem) },    { SEC_ASN1_OPTIONAL |	SEC_ASN1_CONSTRUCTED | SEC_ASN1_CONTEXT_SPECIFIC | 0, 	offsetof(SEC_PKCS12PFXItem, macData), SEC_PKCS12MacDataTemplate },    { SEC_ASN1_CONSTRUCTED | SEC_ASN1_CONTEXT_SPECIFIC | 1, 	offsetof(SEC_PKCS12PFXItem, authSafe), 	sec_PKCS7ContentInfoTemplate },    { 0 }};const SEC_ASN1Template SEC_PKCS12PFXItemTemplate_OLD[] ={    { SEC_ASN1_SEQUENCE, 0, NULL, sizeof(SEC_PKCS12PFXItem) },    { SEC_ASN1_OPTIONAL |	SEC_ASN1_CONSTRUCTED | SEC_ASN1_CONTEXT_SPECIFIC | 0, 	offsetof(SEC_PKCS12PFXItem, old_safeMac), sgn_DigestInfoTemplate },    { SEC_ASN1_OPTIONAL | SEC_ASN1_BIT_STRING,	offsetof(SEC_PKCS12PFXItem, old_macSalt) },    { SEC_ASN1_CONSTRUCTED | SEC_ASN1_CONTEXT_SPECIFIC | 1, 	offsetof(SEC_PKCS12PFXItem, authSafe), 	sec_PKCS7ContentInfoTemplate },    { 0 }};const SEC_ASN1Template SEC_PKCS12AuthenticatedSafeTemplate[] ={    { SEC_ASN1_SEQUENCE, 0, NULL, sizeof(SEC_PKCS12AuthenticatedSafe) },    { SEC_ASN1_OPTIONAL | SEC_ASN1_INTEGER, 	offsetof(SEC_PKCS12AuthenticatedSafe, version) },     { SEC_ASN1_OPTIONAL | SEC_ASN1_OBJECT_ID,	offsetof(SEC_PKCS12AuthenticatedSafe, transportMode) },    { SEC_ASN1_BIT_STRING | SEC_ASN1_OPTIONAL,	offsetof(SEC_PKCS12AuthenticatedSafe, privacySalt) },    { SEC_ASN1_OPTIONAL | SEC_ASN1_SET_OF, 	offsetof(SEC_PKCS12AuthenticatedSafe, baggage.bags), 	SEC_PKCS12BaggageItemTemplate },    { SEC_ASN1_POINTER,	offsetof(SEC_PKCS12AuthenticatedSafe, safe),	sec_PKCS7ContentInfoTemplate },    { 0 }};const SEC_ASN1Template SEC_PKCS12AuthenticatedSafeTemplate_OLD[] ={    { SEC_ASN1_SEQUENCE, 0, NULL, sizeof(SEC_PKCS12AuthenticatedSafe) },    { SEC_ASN1_OPTIONAL | SEC_ASN1_INTEGER, 	offsetof(SEC_PKCS12AuthenticatedSafe, version) },     { SEC_ASN1_OPTIONAL | SEC_ASN1_INTEGER,	offsetof(SEC_PKCS12AuthenticatedSafe, transportMode) },    { SEC_ASN1_BIT_STRING,	offsetof(SEC_PKCS12AuthenticatedSafe, privacySalt) },    { SEC_ASN1_OPTIONAL | SEC_ASN1_CONSTRUCTED |     	SEC_ASN1_CONTEXT_SPECIFIC | 0, 	offsetof(SEC_PKCS12AuthenticatedSafe, old_baggage), 	SEC_PKCS12BaggageTemplate_OLD },    { SEC_ASN1_CONSTRUCTED | SEC_ASN1_CONTEXT_SPECIFIC | 1,	offsetof(SEC_PKCS12AuthenticatedSafe, old_safe),	sec_PKCS7ContentInfoTemplate },    { 0 }};const SEC_ASN1Template SEC_PointerToPKCS12KeyBagTemplate[] ={    { SEC_ASN1_POINTER, 0, SEC_PKCS12PrivateKeyBagTemplate }};const SEC_ASN1Template SEC_PointerToPKCS12CertAndCRLBagTemplate_OLD[] ={    { SEC_ASN1_POINTER, 0, SEC_PKCS12CertAndCRLBagTemplate_OLD }};const SEC_ASN1Template SEC_PointerToPKCS12CertAndCRLBagTemplate[] ={    { SEC_ASN1_POINTER, 0, SEC_PKCS12CertAndCRLBagTemplate }};const SEC_ASN1Template SEC_PointerToPKCS12SecretBagTemplate[] ={    { SEC_ASN1_POINTER, 0, SEC_PKCS12SecretBagTemplate }};const SEC_ASN1Template SEC_PointerToPKCS12X509CertCRLTemplate_OLD[] ={    { SEC_ASN1_POINTER, 0, SEC_PKCS12X509CertCRLTemplate_OLD }};const SEC_ASN1Template SEC_PointerToPKCS12X509CertCRLTemplate[] ={    { SEC_ASN1_POINTER, 0, SEC_PKCS12X509CertCRLTemplate }};const SEC_ASN1Template SEC_PointerToPKCS12SDSICertTemplate[] ={    { SEC_ASN1_POINTER, 0, SEC_PKCS12SDSICertTemplate }};

⌨️ 快捷键说明

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