Wed, 31 Dec 2014 06:55:50 +0100
Added tag UPSTREAM_283F7C6 for changeset ca08bd8f51b2
michael@0 | 1 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | |
michael@0 | 5 | #include "nssrenam.h" |
michael@0 | 6 | #include "pkcs12.h" |
michael@0 | 7 | #include "secpkcs7.h" |
michael@0 | 8 | #include "secasn1.h" |
michael@0 | 9 | #include "seccomon.h" |
michael@0 | 10 | #include "secoid.h" |
michael@0 | 11 | #include "sechash.h" |
michael@0 | 12 | #include "secitem.h" |
michael@0 | 13 | #include "secerr.h" |
michael@0 | 14 | #include "pk11func.h" |
michael@0 | 15 | #include "p12local.h" |
michael@0 | 16 | #include "p12.h" |
michael@0 | 17 | |
michael@0 | 18 | #define SALT_LENGTH 16 |
michael@0 | 19 | |
michael@0 | 20 | SEC_ASN1_MKSUB(SECKEY_PrivateKeyInfoTemplate) |
michael@0 | 21 | SEC_ASN1_MKSUB(sgn_DigestInfoTemplate) |
michael@0 | 22 | |
michael@0 | 23 | CK_MECHANISM_TYPE |
michael@0 | 24 | sec_pkcs12_algtag_to_mech(SECOidTag algtag) |
michael@0 | 25 | { |
michael@0 | 26 | switch (algtag) { |
michael@0 | 27 | case SEC_OID_MD2: |
michael@0 | 28 | return CKM_MD2_HMAC; |
michael@0 | 29 | case SEC_OID_MD5: |
michael@0 | 30 | return CKM_MD5_HMAC; |
michael@0 | 31 | case SEC_OID_SHA1: |
michael@0 | 32 | return CKM_SHA_1_HMAC; |
michael@0 | 33 | case SEC_OID_SHA224: |
michael@0 | 34 | return CKM_SHA224_HMAC; |
michael@0 | 35 | case SEC_OID_SHA256: |
michael@0 | 36 | return CKM_SHA256_HMAC; |
michael@0 | 37 | case SEC_OID_SHA384: |
michael@0 | 38 | return CKM_SHA384_HMAC; |
michael@0 | 39 | case SEC_OID_SHA512: |
michael@0 | 40 | return CKM_SHA512_HMAC; |
michael@0 | 41 | default: |
michael@0 | 42 | break; |
michael@0 | 43 | } |
michael@0 | 44 | return CKM_INVALID_MECHANISM; |
michael@0 | 45 | } |
michael@0 | 46 | |
michael@0 | 47 | /* helper functions */ |
michael@0 | 48 | /* returns proper bag type template based upon object type tag */ |
michael@0 | 49 | const SEC_ASN1Template * |
michael@0 | 50 | sec_pkcs12_choose_bag_type_old(void *src_or_dest, PRBool encoding) |
michael@0 | 51 | { |
michael@0 | 52 | const SEC_ASN1Template *theTemplate; |
michael@0 | 53 | SEC_PKCS12SafeBag *safebag; |
michael@0 | 54 | SECOidData *oiddata; |
michael@0 | 55 | |
michael@0 | 56 | if (src_or_dest == NULL) { |
michael@0 | 57 | return NULL; |
michael@0 | 58 | } |
michael@0 | 59 | |
michael@0 | 60 | safebag = (SEC_PKCS12SafeBag*)src_or_dest; |
michael@0 | 61 | |
michael@0 | 62 | oiddata = safebag->safeBagTypeTag; |
michael@0 | 63 | if (oiddata == NULL) { |
michael@0 | 64 | oiddata = SECOID_FindOID(&safebag->safeBagType); |
michael@0 | 65 | safebag->safeBagTypeTag = oiddata; |
michael@0 | 66 | } |
michael@0 | 67 | |
michael@0 | 68 | switch (oiddata->offset) { |
michael@0 | 69 | default: |
michael@0 | 70 | theTemplate = SEC_ASN1_GET(SEC_PointerToAnyTemplate); |
michael@0 | 71 | break; |
michael@0 | 72 | case SEC_OID_PKCS12_KEY_BAG_ID: |
michael@0 | 73 | theTemplate = SEC_PointerToPKCS12KeyBagTemplate; |
michael@0 | 74 | break; |
michael@0 | 75 | case SEC_OID_PKCS12_CERT_AND_CRL_BAG_ID: |
michael@0 | 76 | theTemplate = SEC_PointerToPKCS12CertAndCRLBagTemplate_OLD; |
michael@0 | 77 | break; |
michael@0 | 78 | case SEC_OID_PKCS12_SECRET_BAG_ID: |
michael@0 | 79 | theTemplate = SEC_PointerToPKCS12SecretBagTemplate; |
michael@0 | 80 | break; |
michael@0 | 81 | } |
michael@0 | 82 | return theTemplate; |
michael@0 | 83 | } |
michael@0 | 84 | |
michael@0 | 85 | const SEC_ASN1Template * |
michael@0 | 86 | sec_pkcs12_choose_bag_type(void *src_or_dest, PRBool encoding) |
michael@0 | 87 | { |
michael@0 | 88 | const SEC_ASN1Template *theTemplate; |
michael@0 | 89 | SEC_PKCS12SafeBag *safebag; |
michael@0 | 90 | SECOidData *oiddata; |
michael@0 | 91 | |
michael@0 | 92 | if (src_or_dest == NULL) { |
michael@0 | 93 | return NULL; |
michael@0 | 94 | } |
michael@0 | 95 | |
michael@0 | 96 | safebag = (SEC_PKCS12SafeBag*)src_or_dest; |
michael@0 | 97 | |
michael@0 | 98 | oiddata = safebag->safeBagTypeTag; |
michael@0 | 99 | if (oiddata == NULL) { |
michael@0 | 100 | oiddata = SECOID_FindOID(&safebag->safeBagType); |
michael@0 | 101 | safebag->safeBagTypeTag = oiddata; |
michael@0 | 102 | } |
michael@0 | 103 | |
michael@0 | 104 | switch (oiddata->offset) { |
michael@0 | 105 | default: |
michael@0 | 106 | theTemplate = SEC_ASN1_GET(SEC_AnyTemplate); |
michael@0 | 107 | break; |
michael@0 | 108 | case SEC_OID_PKCS12_KEY_BAG_ID: |
michael@0 | 109 | theTemplate = SEC_PKCS12PrivateKeyBagTemplate; |
michael@0 | 110 | break; |
michael@0 | 111 | case SEC_OID_PKCS12_CERT_AND_CRL_BAG_ID: |
michael@0 | 112 | theTemplate = SEC_PKCS12CertAndCRLBagTemplate; |
michael@0 | 113 | break; |
michael@0 | 114 | case SEC_OID_PKCS12_SECRET_BAG_ID: |
michael@0 | 115 | theTemplate = SEC_PKCS12SecretBagTemplate; |
michael@0 | 116 | break; |
michael@0 | 117 | } |
michael@0 | 118 | return theTemplate; |
michael@0 | 119 | } |
michael@0 | 120 | |
michael@0 | 121 | /* returns proper cert crl template based upon type tag */ |
michael@0 | 122 | const SEC_ASN1Template * |
michael@0 | 123 | sec_pkcs12_choose_cert_crl_type_old(void *src_or_dest, PRBool encoding) |
michael@0 | 124 | { |
michael@0 | 125 | const SEC_ASN1Template *theTemplate; |
michael@0 | 126 | SEC_PKCS12CertAndCRL *certbag; |
michael@0 | 127 | SECOidData *oiddata; |
michael@0 | 128 | |
michael@0 | 129 | if (src_or_dest == NULL) { |
michael@0 | 130 | return NULL; |
michael@0 | 131 | } |
michael@0 | 132 | |
michael@0 | 133 | certbag = (SEC_PKCS12CertAndCRL*)src_or_dest; |
michael@0 | 134 | oiddata = certbag->BagTypeTag; |
michael@0 | 135 | if (oiddata == NULL) { |
michael@0 | 136 | oiddata = SECOID_FindOID(&certbag->BagID); |
michael@0 | 137 | certbag->BagTypeTag = oiddata; |
michael@0 | 138 | } |
michael@0 | 139 | |
michael@0 | 140 | switch (oiddata->offset) { |
michael@0 | 141 | default: |
michael@0 | 142 | theTemplate = SEC_ASN1_GET(SEC_PointerToAnyTemplate); |
michael@0 | 143 | break; |
michael@0 | 144 | case SEC_OID_PKCS12_X509_CERT_CRL_BAG: |
michael@0 | 145 | theTemplate = SEC_PointerToPKCS12X509CertCRLTemplate_OLD; |
michael@0 | 146 | break; |
michael@0 | 147 | case SEC_OID_PKCS12_SDSI_CERT_BAG: |
michael@0 | 148 | theTemplate = SEC_PointerToPKCS12SDSICertTemplate; |
michael@0 | 149 | break; |
michael@0 | 150 | } |
michael@0 | 151 | return theTemplate; |
michael@0 | 152 | } |
michael@0 | 153 | |
michael@0 | 154 | const SEC_ASN1Template * |
michael@0 | 155 | sec_pkcs12_choose_cert_crl_type(void *src_or_dest, PRBool encoding) |
michael@0 | 156 | { |
michael@0 | 157 | const SEC_ASN1Template *theTemplate; |
michael@0 | 158 | SEC_PKCS12CertAndCRL *certbag; |
michael@0 | 159 | SECOidData *oiddata; |
michael@0 | 160 | |
michael@0 | 161 | if (src_or_dest == NULL) { |
michael@0 | 162 | return NULL; |
michael@0 | 163 | } |
michael@0 | 164 | |
michael@0 | 165 | certbag = (SEC_PKCS12CertAndCRL*)src_or_dest; |
michael@0 | 166 | oiddata = certbag->BagTypeTag; |
michael@0 | 167 | if (oiddata == NULL) { |
michael@0 | 168 | oiddata = SECOID_FindOID(&certbag->BagID); |
michael@0 | 169 | certbag->BagTypeTag = oiddata; |
michael@0 | 170 | } |
michael@0 | 171 | |
michael@0 | 172 | switch (oiddata->offset) { |
michael@0 | 173 | default: |
michael@0 | 174 | theTemplate = SEC_ASN1_GET(SEC_PointerToAnyTemplate); |
michael@0 | 175 | break; |
michael@0 | 176 | case SEC_OID_PKCS12_X509_CERT_CRL_BAG: |
michael@0 | 177 | theTemplate = SEC_PointerToPKCS12X509CertCRLTemplate; |
michael@0 | 178 | break; |
michael@0 | 179 | case SEC_OID_PKCS12_SDSI_CERT_BAG: |
michael@0 | 180 | theTemplate = SEC_PointerToPKCS12SDSICertTemplate; |
michael@0 | 181 | break; |
michael@0 | 182 | } |
michael@0 | 183 | return theTemplate; |
michael@0 | 184 | } |
michael@0 | 185 | |
michael@0 | 186 | /* returns appropriate shroud template based on object type tag */ |
michael@0 | 187 | const SEC_ASN1Template * |
michael@0 | 188 | sec_pkcs12_choose_shroud_type(void *src_or_dest, PRBool encoding) |
michael@0 | 189 | { |
michael@0 | 190 | const SEC_ASN1Template *theTemplate; |
michael@0 | 191 | SEC_PKCS12ESPVKItem *espvk; |
michael@0 | 192 | SECOidData *oiddata; |
michael@0 | 193 | |
michael@0 | 194 | if (src_or_dest == NULL) { |
michael@0 | 195 | return NULL; |
michael@0 | 196 | } |
michael@0 | 197 | |
michael@0 | 198 | espvk = (SEC_PKCS12ESPVKItem*)src_or_dest; |
michael@0 | 199 | oiddata = espvk->espvkTag; |
michael@0 | 200 | if (oiddata == NULL) { |
michael@0 | 201 | oiddata = SECOID_FindOID(&espvk->espvkOID); |
michael@0 | 202 | espvk->espvkTag = oiddata; |
michael@0 | 203 | } |
michael@0 | 204 | |
michael@0 | 205 | switch (oiddata->offset) { |
michael@0 | 206 | default: |
michael@0 | 207 | theTemplate = SEC_ASN1_GET(SEC_PointerToAnyTemplate); |
michael@0 | 208 | break; |
michael@0 | 209 | case SEC_OID_PKCS12_PKCS8_KEY_SHROUDING: |
michael@0 | 210 | theTemplate = |
michael@0 | 211 | SEC_ASN1_GET(SECKEY_PointerToEncryptedPrivateKeyInfoTemplate); |
michael@0 | 212 | break; |
michael@0 | 213 | } |
michael@0 | 214 | return theTemplate; |
michael@0 | 215 | } |
michael@0 | 216 | |
michael@0 | 217 | /* generate SALT placing it into the character array passed in. |
michael@0 | 218 | * it is assumed that salt_dest is an array of appropriate size |
michael@0 | 219 | * XXX We might want to generate our own random context |
michael@0 | 220 | */ |
michael@0 | 221 | SECItem * |
michael@0 | 222 | sec_pkcs12_generate_salt(void) |
michael@0 | 223 | { |
michael@0 | 224 | SECItem *salt; |
michael@0 | 225 | |
michael@0 | 226 | salt = (SECItem *)PORT_ZAlloc(sizeof(SECItem)); |
michael@0 | 227 | if(salt == NULL) { |
michael@0 | 228 | PORT_SetError(SEC_ERROR_NO_MEMORY); |
michael@0 | 229 | return NULL; |
michael@0 | 230 | } |
michael@0 | 231 | salt->data = (unsigned char *)PORT_ZAlloc(sizeof(unsigned char) * |
michael@0 | 232 | SALT_LENGTH); |
michael@0 | 233 | salt->len = SALT_LENGTH; |
michael@0 | 234 | if(salt->data == NULL) { |
michael@0 | 235 | PORT_SetError(SEC_ERROR_NO_MEMORY); |
michael@0 | 236 | SECITEM_ZfreeItem(salt, PR_TRUE); |
michael@0 | 237 | return NULL; |
michael@0 | 238 | } |
michael@0 | 239 | |
michael@0 | 240 | PK11_GenerateRandom(salt->data, salt->len); |
michael@0 | 241 | |
michael@0 | 242 | return salt; |
michael@0 | 243 | } |
michael@0 | 244 | |
michael@0 | 245 | /* generate KEYS -- as per PKCS12 section 7. |
michael@0 | 246 | * only used for MAC |
michael@0 | 247 | */ |
michael@0 | 248 | SECItem * |
michael@0 | 249 | sec_pkcs12_generate_key_from_password(SECOidTag algorithm, |
michael@0 | 250 | SECItem *salt, |
michael@0 | 251 | SECItem *password) |
michael@0 | 252 | { |
michael@0 | 253 | unsigned char *pre_hash=NULL; |
michael@0 | 254 | unsigned char *hash_dest=NULL; |
michael@0 | 255 | SECStatus res; |
michael@0 | 256 | PLArenaPool *poolp; |
michael@0 | 257 | SECItem *key = NULL; |
michael@0 | 258 | int key_len = 0; |
michael@0 | 259 | |
michael@0 | 260 | if((salt == NULL) || (password == NULL)) { |
michael@0 | 261 | return NULL; |
michael@0 | 262 | } |
michael@0 | 263 | |
michael@0 | 264 | poolp = PORT_NewArena(DER_DEFAULT_CHUNKSIZE); |
michael@0 | 265 | if(poolp == NULL) { |
michael@0 | 266 | PORT_SetError(SEC_ERROR_NO_MEMORY); |
michael@0 | 267 | return NULL; |
michael@0 | 268 | } |
michael@0 | 269 | |
michael@0 | 270 | pre_hash = (unsigned char *)PORT_ArenaZAlloc(poolp, sizeof(char) * |
michael@0 | 271 | (salt->len+password->len)); |
michael@0 | 272 | if(pre_hash == NULL) { |
michael@0 | 273 | PORT_SetError(SEC_ERROR_NO_MEMORY); |
michael@0 | 274 | goto loser; |
michael@0 | 275 | } |
michael@0 | 276 | |
michael@0 | 277 | hash_dest = (unsigned char *)PORT_ArenaZAlloc(poolp, |
michael@0 | 278 | sizeof(unsigned char) * SHA1_LENGTH); |
michael@0 | 279 | if(hash_dest == NULL) { |
michael@0 | 280 | PORT_SetError(SEC_ERROR_NO_MEMORY); |
michael@0 | 281 | goto loser; |
michael@0 | 282 | } |
michael@0 | 283 | |
michael@0 | 284 | PORT_Memcpy(pre_hash, salt->data, salt->len); |
michael@0 | 285 | /* handle password of 0 length case */ |
michael@0 | 286 | if(password->len > 0) { |
michael@0 | 287 | PORT_Memcpy(&(pre_hash[salt->len]), password->data, password->len); |
michael@0 | 288 | } |
michael@0 | 289 | |
michael@0 | 290 | res = PK11_HashBuf(SEC_OID_SHA1, hash_dest, pre_hash, |
michael@0 | 291 | (salt->len+password->len)); |
michael@0 | 292 | if(res == SECFailure) { |
michael@0 | 293 | PORT_SetError(SEC_ERROR_NO_MEMORY); |
michael@0 | 294 | goto loser; |
michael@0 | 295 | } |
michael@0 | 296 | |
michael@0 | 297 | switch(algorithm) { |
michael@0 | 298 | case SEC_OID_SHA1: |
michael@0 | 299 | if(key_len == 0) |
michael@0 | 300 | key_len = 16; |
michael@0 | 301 | key = (SECItem *)PORT_ZAlloc(sizeof(SECItem)); |
michael@0 | 302 | if(key == NULL) { |
michael@0 | 303 | PORT_SetError(SEC_ERROR_NO_MEMORY); |
michael@0 | 304 | goto loser; |
michael@0 | 305 | } |
michael@0 | 306 | key->data = (unsigned char *)PORT_ZAlloc(sizeof(unsigned char) |
michael@0 | 307 | * key_len); |
michael@0 | 308 | if(key->data == NULL) { |
michael@0 | 309 | PORT_SetError(SEC_ERROR_NO_MEMORY); |
michael@0 | 310 | goto loser; |
michael@0 | 311 | } |
michael@0 | 312 | key->len = key_len; |
michael@0 | 313 | PORT_Memcpy(key->data, &hash_dest[SHA1_LENGTH-key->len], key->len); |
michael@0 | 314 | break; |
michael@0 | 315 | default: |
michael@0 | 316 | goto loser; |
michael@0 | 317 | break; |
michael@0 | 318 | } |
michael@0 | 319 | |
michael@0 | 320 | PORT_FreeArena(poolp, PR_TRUE); |
michael@0 | 321 | return key; |
michael@0 | 322 | |
michael@0 | 323 | loser: |
michael@0 | 324 | PORT_FreeArena(poolp, PR_TRUE); |
michael@0 | 325 | if(key != NULL) { |
michael@0 | 326 | SECITEM_ZfreeItem(key, PR_TRUE); |
michael@0 | 327 | } |
michael@0 | 328 | return NULL; |
michael@0 | 329 | } |
michael@0 | 330 | |
michael@0 | 331 | /* MAC is generated per PKCS 12 section 6. It is expected that key, msg |
michael@0 | 332 | * and mac_dest are pre allocated, non-NULL arrays. msg_len is passed in |
michael@0 | 333 | * because it is not known how long the message actually is. String |
michael@0 | 334 | * manipulation routines will not necessarily work because msg may have |
michael@0 | 335 | * imbedded NULLs |
michael@0 | 336 | */ |
michael@0 | 337 | static SECItem * |
michael@0 | 338 | sec_pkcs12_generate_old_mac(SECItem *key, |
michael@0 | 339 | SECItem *msg) |
michael@0 | 340 | { |
michael@0 | 341 | SECStatus res; |
michael@0 | 342 | PLArenaPool *temparena = NULL; |
michael@0 | 343 | unsigned char *hash_dest=NULL, *hash_src1=NULL, *hash_src2 = NULL; |
michael@0 | 344 | int i; |
michael@0 | 345 | SECItem *mac = NULL; |
michael@0 | 346 | |
michael@0 | 347 | if((key == NULL) || (msg == NULL)) |
michael@0 | 348 | goto loser; |
michael@0 | 349 | |
michael@0 | 350 | /* allocate return item */ |
michael@0 | 351 | mac = (SECItem *)PORT_ZAlloc(sizeof(SECItem)); |
michael@0 | 352 | if(mac == NULL) |
michael@0 | 353 | return NULL; |
michael@0 | 354 | mac->data = (unsigned char *)PORT_ZAlloc(sizeof(unsigned char) |
michael@0 | 355 | * SHA1_LENGTH); |
michael@0 | 356 | mac->len = SHA1_LENGTH; |
michael@0 | 357 | if(mac->data == NULL) |
michael@0 | 358 | goto loser; |
michael@0 | 359 | |
michael@0 | 360 | /* allocate temporary items */ |
michael@0 | 361 | temparena = PORT_NewArena(DER_DEFAULT_CHUNKSIZE); |
michael@0 | 362 | if(temparena == NULL) |
michael@0 | 363 | goto loser; |
michael@0 | 364 | |
michael@0 | 365 | hash_src1 = (unsigned char *)PORT_ArenaZAlloc(temparena, |
michael@0 | 366 | sizeof(unsigned char) * (16+msg->len)); |
michael@0 | 367 | if(hash_src1 == NULL) |
michael@0 | 368 | goto loser; |
michael@0 | 369 | |
michael@0 | 370 | hash_src2 = (unsigned char *)PORT_ArenaZAlloc(temparena, |
michael@0 | 371 | sizeof(unsigned char) * (SHA1_LENGTH+16)); |
michael@0 | 372 | if(hash_src2 == NULL) |
michael@0 | 373 | goto loser; |
michael@0 | 374 | |
michael@0 | 375 | hash_dest = (unsigned char *)PORT_ArenaZAlloc(temparena, |
michael@0 | 376 | sizeof(unsigned char) * SHA1_LENGTH); |
michael@0 | 377 | if(hash_dest == NULL) |
michael@0 | 378 | goto loser; |
michael@0 | 379 | |
michael@0 | 380 | /* perform mac'ing as per PKCS 12 */ |
michael@0 | 381 | |
michael@0 | 382 | /* first round of hashing */ |
michael@0 | 383 | for(i = 0; i < 16; i++) |
michael@0 | 384 | hash_src1[i] = key->data[i] ^ 0x36; |
michael@0 | 385 | PORT_Memcpy(&(hash_src1[16]), msg->data, msg->len); |
michael@0 | 386 | res = PK11_HashBuf(SEC_OID_SHA1, hash_dest, hash_src1, (16+msg->len)); |
michael@0 | 387 | if(res == SECFailure) |
michael@0 | 388 | goto loser; |
michael@0 | 389 | |
michael@0 | 390 | /* second round of hashing */ |
michael@0 | 391 | for(i = 0; i < 16; i++) |
michael@0 | 392 | hash_src2[i] = key->data[i] ^ 0x5c; |
michael@0 | 393 | PORT_Memcpy(&(hash_src2[16]), hash_dest, SHA1_LENGTH); |
michael@0 | 394 | res = PK11_HashBuf(SEC_OID_SHA1, mac->data, hash_src2, SHA1_LENGTH+16); |
michael@0 | 395 | if(res == SECFailure) |
michael@0 | 396 | goto loser; |
michael@0 | 397 | |
michael@0 | 398 | PORT_FreeArena(temparena, PR_TRUE); |
michael@0 | 399 | return mac; |
michael@0 | 400 | |
michael@0 | 401 | loser: |
michael@0 | 402 | if(temparena != NULL) |
michael@0 | 403 | PORT_FreeArena(temparena, PR_TRUE); |
michael@0 | 404 | if(mac != NULL) |
michael@0 | 405 | SECITEM_ZfreeItem(mac, PR_TRUE); |
michael@0 | 406 | return NULL; |
michael@0 | 407 | } |
michael@0 | 408 | |
michael@0 | 409 | /* MAC is generated per PKCS 12 section 6. It is expected that key, msg |
michael@0 | 410 | * and mac_dest are pre allocated, non-NULL arrays. msg_len is passed in |
michael@0 | 411 | * because it is not known how long the message actually is. String |
michael@0 | 412 | * manipulation routines will not necessarily work because msg may have |
michael@0 | 413 | * imbedded NULLs |
michael@0 | 414 | */ |
michael@0 | 415 | SECItem * |
michael@0 | 416 | sec_pkcs12_generate_mac(SECItem *key, |
michael@0 | 417 | SECItem *msg, |
michael@0 | 418 | PRBool old_method) |
michael@0 | 419 | { |
michael@0 | 420 | SECStatus res = SECFailure; |
michael@0 | 421 | SECItem *mac = NULL; |
michael@0 | 422 | PK11Context *pk11cx = NULL; |
michael@0 | 423 | SECItem ignore = {0}; |
michael@0 | 424 | |
michael@0 | 425 | if((key == NULL) || (msg == NULL)) { |
michael@0 | 426 | return NULL; |
michael@0 | 427 | } |
michael@0 | 428 | |
michael@0 | 429 | if(old_method == PR_TRUE) { |
michael@0 | 430 | return sec_pkcs12_generate_old_mac(key, msg); |
michael@0 | 431 | } |
michael@0 | 432 | |
michael@0 | 433 | /* allocate return item */ |
michael@0 | 434 | mac = SECITEM_AllocItem(NULL, NULL, SHA1_LENGTH); |
michael@0 | 435 | if (mac == NULL) { |
michael@0 | 436 | return NULL; |
michael@0 | 437 | } |
michael@0 | 438 | |
michael@0 | 439 | pk11cx = PK11_CreateContextByRawKey(NULL, CKM_SHA_1_HMAC, PK11_OriginDerive, |
michael@0 | 440 | CKA_SIGN, key, &ignore, NULL); |
michael@0 | 441 | if (pk11cx == NULL) { |
michael@0 | 442 | goto loser; |
michael@0 | 443 | } |
michael@0 | 444 | |
michael@0 | 445 | res = PK11_DigestBegin(pk11cx); |
michael@0 | 446 | if (res == SECFailure) { |
michael@0 | 447 | goto loser; |
michael@0 | 448 | } |
michael@0 | 449 | |
michael@0 | 450 | res = PK11_DigestOp(pk11cx, msg->data, msg->len); |
michael@0 | 451 | if (res == SECFailure) { |
michael@0 | 452 | goto loser; |
michael@0 | 453 | } |
michael@0 | 454 | |
michael@0 | 455 | res = PK11_DigestFinal(pk11cx, mac->data, &mac->len, SHA1_LENGTH); |
michael@0 | 456 | if (res == SECFailure) { |
michael@0 | 457 | goto loser; |
michael@0 | 458 | } |
michael@0 | 459 | |
michael@0 | 460 | PK11_DestroyContext(pk11cx, PR_TRUE); |
michael@0 | 461 | pk11cx = NULL; |
michael@0 | 462 | |
michael@0 | 463 | loser: |
michael@0 | 464 | |
michael@0 | 465 | if(res != SECSuccess) { |
michael@0 | 466 | SECITEM_ZfreeItem(mac, PR_TRUE); |
michael@0 | 467 | mac = NULL; |
michael@0 | 468 | if (pk11cx) { |
michael@0 | 469 | PK11_DestroyContext(pk11cx, PR_TRUE); |
michael@0 | 470 | } |
michael@0 | 471 | } |
michael@0 | 472 | |
michael@0 | 473 | return mac; |
michael@0 | 474 | } |
michael@0 | 475 | |
michael@0 | 476 | /* compute the thumbprint of the DER cert and create a digest info |
michael@0 | 477 | * to store it in and return the digest info. |
michael@0 | 478 | * a return of NULL indicates an error. |
michael@0 | 479 | */ |
michael@0 | 480 | SGNDigestInfo * |
michael@0 | 481 | sec_pkcs12_compute_thumbprint(SECItem *der_cert) |
michael@0 | 482 | { |
michael@0 | 483 | SGNDigestInfo *thumb = NULL; |
michael@0 | 484 | SECItem digest; |
michael@0 | 485 | PLArenaPool *temparena = NULL; |
michael@0 | 486 | SECStatus rv = SECFailure; |
michael@0 | 487 | |
michael@0 | 488 | if(der_cert == NULL) |
michael@0 | 489 | return NULL; |
michael@0 | 490 | |
michael@0 | 491 | temparena = PORT_NewArena(SEC_ASN1_DEFAULT_ARENA_SIZE); |
michael@0 | 492 | if(temparena == NULL) { |
michael@0 | 493 | return NULL; |
michael@0 | 494 | } |
michael@0 | 495 | |
michael@0 | 496 | digest.data = (unsigned char *)PORT_ArenaZAlloc(temparena, |
michael@0 | 497 | sizeof(unsigned char) * |
michael@0 | 498 | SHA1_LENGTH); |
michael@0 | 499 | /* digest data and create digest info */ |
michael@0 | 500 | if(digest.data != NULL) { |
michael@0 | 501 | digest.len = SHA1_LENGTH; |
michael@0 | 502 | rv = PK11_HashBuf(SEC_OID_SHA1, digest.data, der_cert->data, |
michael@0 | 503 | der_cert->len); |
michael@0 | 504 | if(rv == SECSuccess) { |
michael@0 | 505 | thumb = SGN_CreateDigestInfo(SEC_OID_SHA1, |
michael@0 | 506 | digest.data, |
michael@0 | 507 | digest.len); |
michael@0 | 508 | } else { |
michael@0 | 509 | PORT_SetError(SEC_ERROR_NO_MEMORY); |
michael@0 | 510 | } |
michael@0 | 511 | } else { |
michael@0 | 512 | PORT_SetError(SEC_ERROR_NO_MEMORY); |
michael@0 | 513 | } |
michael@0 | 514 | |
michael@0 | 515 | PORT_FreeArena(temparena, PR_TRUE); |
michael@0 | 516 | |
michael@0 | 517 | return thumb; |
michael@0 | 518 | } |
michael@0 | 519 | |
michael@0 | 520 | /* create a virtual password per PKCS 12, the password is converted |
michael@0 | 521 | * to unicode, the salt is prepended to it, and then the whole thing |
michael@0 | 522 | * is returned */ |
michael@0 | 523 | SECItem * |
michael@0 | 524 | sec_pkcs12_create_virtual_password(SECItem *password, SECItem *salt, |
michael@0 | 525 | PRBool swap) |
michael@0 | 526 | { |
michael@0 | 527 | SECItem uniPwd = {siBuffer, NULL,0}, *retPwd = NULL; |
michael@0 | 528 | |
michael@0 | 529 | if((password == NULL) || (salt == NULL)) { |
michael@0 | 530 | return NULL; |
michael@0 | 531 | } |
michael@0 | 532 | |
michael@0 | 533 | if(password->len == 0) { |
michael@0 | 534 | uniPwd.data = (unsigned char*)PORT_ZAlloc(2); |
michael@0 | 535 | uniPwd.len = 2; |
michael@0 | 536 | if(!uniPwd.data) { |
michael@0 | 537 | return NULL; |
michael@0 | 538 | } |
michael@0 | 539 | } else { |
michael@0 | 540 | uniPwd.data = (unsigned char*)PORT_ZAlloc(password->len * 3); |
michael@0 | 541 | uniPwd.len = password->len * 3; |
michael@0 | 542 | if(!PORT_UCS2_ASCIIConversion(PR_TRUE, password->data, password->len, |
michael@0 | 543 | uniPwd.data, uniPwd.len, &uniPwd.len, swap)) { |
michael@0 | 544 | SECITEM_ZfreeItem(&uniPwd, PR_FALSE); |
michael@0 | 545 | return NULL; |
michael@0 | 546 | } |
michael@0 | 547 | } |
michael@0 | 548 | |
michael@0 | 549 | retPwd = (SECItem *)PORT_ZAlloc(sizeof(SECItem)); |
michael@0 | 550 | if(retPwd == NULL) { |
michael@0 | 551 | goto loser; |
michael@0 | 552 | } |
michael@0 | 553 | |
michael@0 | 554 | /* allocate space and copy proper data */ |
michael@0 | 555 | retPwd->len = uniPwd.len + salt->len; |
michael@0 | 556 | retPwd->data = (unsigned char *)PORT_Alloc(retPwd->len); |
michael@0 | 557 | if(retPwd->data == NULL) { |
michael@0 | 558 | PORT_Free(retPwd); |
michael@0 | 559 | goto loser; |
michael@0 | 560 | } |
michael@0 | 561 | |
michael@0 | 562 | PORT_Memcpy(retPwd->data, salt->data, salt->len); |
michael@0 | 563 | PORT_Memcpy((retPwd->data + salt->len), uniPwd.data, uniPwd.len); |
michael@0 | 564 | |
michael@0 | 565 | SECITEM_ZfreeItem(&uniPwd, PR_FALSE); |
michael@0 | 566 | |
michael@0 | 567 | return retPwd; |
michael@0 | 568 | |
michael@0 | 569 | loser: |
michael@0 | 570 | PORT_SetError(SEC_ERROR_NO_MEMORY); |
michael@0 | 571 | SECITEM_ZfreeItem(&uniPwd, PR_FALSE); |
michael@0 | 572 | return NULL; |
michael@0 | 573 | } |
michael@0 | 574 | |
michael@0 | 575 | /* appends a shrouded key to a key bag. this is used for exporting |
michael@0 | 576 | * to store externally wrapped keys. it is used when importing to convert |
michael@0 | 577 | * old items to new |
michael@0 | 578 | */ |
michael@0 | 579 | SECStatus |
michael@0 | 580 | sec_pkcs12_append_shrouded_key(SEC_PKCS12BaggageItem *bag, |
michael@0 | 581 | SEC_PKCS12ESPVKItem *espvk) |
michael@0 | 582 | { |
michael@0 | 583 | int size; |
michael@0 | 584 | void *mark = NULL, *dummy = NULL; |
michael@0 | 585 | |
michael@0 | 586 | if((bag == NULL) || (espvk == NULL)) |
michael@0 | 587 | return SECFailure; |
michael@0 | 588 | |
michael@0 | 589 | mark = PORT_ArenaMark(bag->poolp); |
michael@0 | 590 | |
michael@0 | 591 | /* grow the list */ |
michael@0 | 592 | size = (bag->nEspvks + 1) * sizeof(SEC_PKCS12ESPVKItem *); |
michael@0 | 593 | dummy = (SEC_PKCS12ESPVKItem **)PORT_ArenaGrow(bag->poolp, |
michael@0 | 594 | bag->espvks, size, |
michael@0 | 595 | size + sizeof(SEC_PKCS12ESPVKItem *)); |
michael@0 | 596 | bag->espvks = (SEC_PKCS12ESPVKItem**)dummy; |
michael@0 | 597 | if(dummy == NULL) { |
michael@0 | 598 | PORT_SetError(SEC_ERROR_NO_MEMORY); |
michael@0 | 599 | goto loser; |
michael@0 | 600 | } |
michael@0 | 601 | |
michael@0 | 602 | bag->espvks[bag->nEspvks] = espvk; |
michael@0 | 603 | bag->nEspvks++; |
michael@0 | 604 | bag->espvks[bag->nEspvks] = NULL; |
michael@0 | 605 | |
michael@0 | 606 | PORT_ArenaUnmark(bag->poolp, mark); |
michael@0 | 607 | return SECSuccess; |
michael@0 | 608 | |
michael@0 | 609 | loser: |
michael@0 | 610 | PORT_ArenaRelease(bag->poolp, mark); |
michael@0 | 611 | return SECFailure; |
michael@0 | 612 | } |
michael@0 | 613 | |
michael@0 | 614 | /* search a certificate list for a nickname, a thumbprint, or both |
michael@0 | 615 | * within a certificate bag. if the certificate could not be |
michael@0 | 616 | * found or an error occurs, NULL is returned; |
michael@0 | 617 | */ |
michael@0 | 618 | static SEC_PKCS12CertAndCRL * |
michael@0 | 619 | sec_pkcs12_find_cert_in_certbag(SEC_PKCS12CertAndCRLBag *certbag, |
michael@0 | 620 | SECItem *nickname, SGNDigestInfo *thumbprint) |
michael@0 | 621 | { |
michael@0 | 622 | PRBool search_both = PR_FALSE, search_nickname = PR_FALSE; |
michael@0 | 623 | int i, j; |
michael@0 | 624 | |
michael@0 | 625 | if((certbag == NULL) || ((nickname == NULL) && (thumbprint == NULL))) { |
michael@0 | 626 | return NULL; |
michael@0 | 627 | } |
michael@0 | 628 | |
michael@0 | 629 | if(thumbprint && nickname) { |
michael@0 | 630 | search_both = PR_TRUE; |
michael@0 | 631 | } |
michael@0 | 632 | |
michael@0 | 633 | if(nickname) { |
michael@0 | 634 | search_nickname = PR_TRUE; |
michael@0 | 635 | } |
michael@0 | 636 | |
michael@0 | 637 | search_again: |
michael@0 | 638 | i = 0; |
michael@0 | 639 | while(certbag->certAndCRLs[i] != NULL) { |
michael@0 | 640 | SEC_PKCS12CertAndCRL *cert = certbag->certAndCRLs[i]; |
michael@0 | 641 | |
michael@0 | 642 | if(SECOID_FindOIDTag(&cert->BagID) == SEC_OID_PKCS12_X509_CERT_CRL_BAG) { |
michael@0 | 643 | |
michael@0 | 644 | /* check nicknames */ |
michael@0 | 645 | if(search_nickname) { |
michael@0 | 646 | if(SECITEM_CompareItem(nickname, &cert->nickname) == SECEqual) { |
michael@0 | 647 | return cert; |
michael@0 | 648 | } |
michael@0 | 649 | } else { |
michael@0 | 650 | /* check thumbprints */ |
michael@0 | 651 | SECItem **derCertList; |
michael@0 | 652 | |
michael@0 | 653 | /* get pointer to certificate list, does not need to |
michael@0 | 654 | * be freed since it is within the arena which will |
michael@0 | 655 | * be freed later. |
michael@0 | 656 | */ |
michael@0 | 657 | derCertList = SEC_PKCS7GetCertificateList(&cert->value.x509->certOrCRL); |
michael@0 | 658 | j = 0; |
michael@0 | 659 | if(derCertList != NULL) { |
michael@0 | 660 | while(derCertList[j] != NULL) { |
michael@0 | 661 | SECComparison eq; |
michael@0 | 662 | SGNDigestInfo *di; |
michael@0 | 663 | di = sec_pkcs12_compute_thumbprint(derCertList[j]); |
michael@0 | 664 | if(di) { |
michael@0 | 665 | eq = SGN_CompareDigestInfo(thumbprint, di); |
michael@0 | 666 | SGN_DestroyDigestInfo(di); |
michael@0 | 667 | if(eq == SECEqual) { |
michael@0 | 668 | /* copy the derCert for later reference */ |
michael@0 | 669 | cert->value.x509->derLeafCert = derCertList[j]; |
michael@0 | 670 | return cert; |
michael@0 | 671 | } |
michael@0 | 672 | } else { |
michael@0 | 673 | /* an error occurred */ |
michael@0 | 674 | return NULL; |
michael@0 | 675 | } |
michael@0 | 676 | j++; |
michael@0 | 677 | } |
michael@0 | 678 | } |
michael@0 | 679 | } |
michael@0 | 680 | } |
michael@0 | 681 | |
michael@0 | 682 | i++; |
michael@0 | 683 | } |
michael@0 | 684 | |
michael@0 | 685 | if(search_both) { |
michael@0 | 686 | search_both = PR_FALSE; |
michael@0 | 687 | search_nickname = PR_FALSE; |
michael@0 | 688 | goto search_again; |
michael@0 | 689 | } |
michael@0 | 690 | |
michael@0 | 691 | return NULL; |
michael@0 | 692 | } |
michael@0 | 693 | |
michael@0 | 694 | /* search a key list for a nickname, a thumbprint, or both |
michael@0 | 695 | * within a key bag. if the key could not be |
michael@0 | 696 | * found or an error occurs, NULL is returned; |
michael@0 | 697 | */ |
michael@0 | 698 | static SEC_PKCS12PrivateKey * |
michael@0 | 699 | sec_pkcs12_find_key_in_keybag(SEC_PKCS12PrivateKeyBag *keybag, |
michael@0 | 700 | SECItem *nickname, SGNDigestInfo *thumbprint) |
michael@0 | 701 | { |
michael@0 | 702 | PRBool search_both = PR_FALSE, search_nickname = PR_FALSE; |
michael@0 | 703 | int i, j; |
michael@0 | 704 | |
michael@0 | 705 | if((keybag == NULL) || ((nickname == NULL) && (thumbprint == NULL))) { |
michael@0 | 706 | return NULL; |
michael@0 | 707 | } |
michael@0 | 708 | |
michael@0 | 709 | if(keybag->privateKeys == NULL) { |
michael@0 | 710 | return NULL; |
michael@0 | 711 | } |
michael@0 | 712 | |
michael@0 | 713 | if(thumbprint && nickname) { |
michael@0 | 714 | search_both = PR_TRUE; |
michael@0 | 715 | } |
michael@0 | 716 | |
michael@0 | 717 | if(nickname) { |
michael@0 | 718 | search_nickname = PR_TRUE; |
michael@0 | 719 | } |
michael@0 | 720 | |
michael@0 | 721 | search_again: |
michael@0 | 722 | i = 0; |
michael@0 | 723 | while(keybag->privateKeys[i] != NULL) { |
michael@0 | 724 | SEC_PKCS12PrivateKey *key = keybag->privateKeys[i]; |
michael@0 | 725 | |
michael@0 | 726 | /* check nicknames */ |
michael@0 | 727 | if(search_nickname) { |
michael@0 | 728 | if(SECITEM_CompareItem(nickname, &key->pvkData.nickname) == SECEqual) { |
michael@0 | 729 | return key; |
michael@0 | 730 | } |
michael@0 | 731 | } else { |
michael@0 | 732 | /* check digests */ |
michael@0 | 733 | SGNDigestInfo **assocCerts = key->pvkData.assocCerts; |
michael@0 | 734 | if((assocCerts == NULL) || (assocCerts[0] == NULL)) { |
michael@0 | 735 | return NULL; |
michael@0 | 736 | } |
michael@0 | 737 | |
michael@0 | 738 | j = 0; |
michael@0 | 739 | while(assocCerts[j] != NULL) { |
michael@0 | 740 | SECComparison eq; |
michael@0 | 741 | eq = SGN_CompareDigestInfo(thumbprint, assocCerts[j]); |
michael@0 | 742 | if(eq == SECEqual) { |
michael@0 | 743 | return key; |
michael@0 | 744 | } |
michael@0 | 745 | j++; |
michael@0 | 746 | } |
michael@0 | 747 | } |
michael@0 | 748 | i++; |
michael@0 | 749 | } |
michael@0 | 750 | |
michael@0 | 751 | if(search_both) { |
michael@0 | 752 | search_both = PR_FALSE; |
michael@0 | 753 | search_nickname = PR_FALSE; |
michael@0 | 754 | goto search_again; |
michael@0 | 755 | } |
michael@0 | 756 | |
michael@0 | 757 | return NULL; |
michael@0 | 758 | } |
michael@0 | 759 | |
michael@0 | 760 | /* seach the safe first then try the baggage bag |
michael@0 | 761 | * safe and bag contain certs and keys to search |
michael@0 | 762 | * objType is the object type to look for |
michael@0 | 763 | * bagType is the type of bag that was found by sec_pkcs12_find_object |
michael@0 | 764 | * index is the entity in safe->safeContents or bag->unencSecrets which |
michael@0 | 765 | * is being searched |
michael@0 | 766 | * nickname and thumbprint are the search criteria |
michael@0 | 767 | * |
michael@0 | 768 | * a return of null indicates no match |
michael@0 | 769 | */ |
michael@0 | 770 | static void * |
michael@0 | 771 | sec_pkcs12_try_find(SEC_PKCS12SafeContents *safe, |
michael@0 | 772 | SEC_PKCS12BaggageItem *bag, |
michael@0 | 773 | SECOidTag objType, SECOidTag bagType, int index, |
michael@0 | 774 | SECItem *nickname, SGNDigestInfo *thumbprint) |
michael@0 | 775 | { |
michael@0 | 776 | PRBool searchSafe; |
michael@0 | 777 | int i = index; |
michael@0 | 778 | |
michael@0 | 779 | if((safe == NULL) && (bag == NULL)) { |
michael@0 | 780 | return NULL; |
michael@0 | 781 | } |
michael@0 | 782 | |
michael@0 | 783 | searchSafe = (safe == NULL ? PR_FALSE : PR_TRUE); |
michael@0 | 784 | switch(objType) { |
michael@0 | 785 | case SEC_OID_PKCS12_CERT_AND_CRL_BAG_ID: |
michael@0 | 786 | if(objType == bagType) { |
michael@0 | 787 | SEC_PKCS12CertAndCRLBag *certBag; |
michael@0 | 788 | |
michael@0 | 789 | if(searchSafe) { |
michael@0 | 790 | certBag = safe->contents[i]->safeContent.certAndCRLBag; |
michael@0 | 791 | } else { |
michael@0 | 792 | certBag = bag->unencSecrets[i]->safeContent.certAndCRLBag; |
michael@0 | 793 | } |
michael@0 | 794 | return sec_pkcs12_find_cert_in_certbag(certBag, nickname, |
michael@0 | 795 | thumbprint); |
michael@0 | 796 | } |
michael@0 | 797 | break; |
michael@0 | 798 | case SEC_OID_PKCS12_KEY_BAG_ID: |
michael@0 | 799 | if(objType == bagType) { |
michael@0 | 800 | SEC_PKCS12PrivateKeyBag *keyBag; |
michael@0 | 801 | |
michael@0 | 802 | if(searchSafe) { |
michael@0 | 803 | keyBag = safe->contents[i]->safeContent.keyBag; |
michael@0 | 804 | } else { |
michael@0 | 805 | keyBag = bag->unencSecrets[i]->safeContent.keyBag; |
michael@0 | 806 | } |
michael@0 | 807 | return sec_pkcs12_find_key_in_keybag(keyBag, nickname, |
michael@0 | 808 | thumbprint); |
michael@0 | 809 | } |
michael@0 | 810 | break; |
michael@0 | 811 | default: |
michael@0 | 812 | break; |
michael@0 | 813 | } |
michael@0 | 814 | |
michael@0 | 815 | return NULL; |
michael@0 | 816 | } |
michael@0 | 817 | |
michael@0 | 818 | /* searches both the baggage and the safe areas looking for |
michael@0 | 819 | * object of specified type matching either the nickname or the |
michael@0 | 820 | * thumbprint specified. |
michael@0 | 821 | * |
michael@0 | 822 | * safe and baggage store certs and keys |
michael@0 | 823 | * objType is the OID for the bag type to be searched: |
michael@0 | 824 | * SEC_OID_PKCS12_KEY_BAG_ID, or |
michael@0 | 825 | * SEC_OID_PKCS12_CERT_AND_CRL_BAG_ID |
michael@0 | 826 | * nickname and thumbprint are the search criteria |
michael@0 | 827 | * |
michael@0 | 828 | * if no match found, NULL returned and error set |
michael@0 | 829 | */ |
michael@0 | 830 | void * |
michael@0 | 831 | sec_pkcs12_find_object(SEC_PKCS12SafeContents *safe, |
michael@0 | 832 | SEC_PKCS12Baggage *baggage, |
michael@0 | 833 | SECOidTag objType, |
michael@0 | 834 | SECItem *nickname, |
michael@0 | 835 | SGNDigestInfo *thumbprint) |
michael@0 | 836 | { |
michael@0 | 837 | int i, j; |
michael@0 | 838 | void *retItem; |
michael@0 | 839 | |
michael@0 | 840 | if(((safe == NULL) && (thumbprint == NULL)) || |
michael@0 | 841 | ((nickname == NULL) && (thumbprint == NULL))) { |
michael@0 | 842 | return NULL; |
michael@0 | 843 | } |
michael@0 | 844 | |
michael@0 | 845 | i = 0; |
michael@0 | 846 | if((safe != NULL) && (safe->contents != NULL)) { |
michael@0 | 847 | while(safe->contents[i] != NULL) { |
michael@0 | 848 | SECOidTag bagType = SECOID_FindOIDTag(&safe->contents[i]->safeBagType); |
michael@0 | 849 | retItem = sec_pkcs12_try_find(safe, NULL, objType, bagType, i, |
michael@0 | 850 | nickname, thumbprint); |
michael@0 | 851 | if(retItem != NULL) { |
michael@0 | 852 | return retItem; |
michael@0 | 853 | } |
michael@0 | 854 | i++; |
michael@0 | 855 | } |
michael@0 | 856 | } |
michael@0 | 857 | |
michael@0 | 858 | if((baggage != NULL) && (baggage->bags != NULL)) { |
michael@0 | 859 | i = 0; |
michael@0 | 860 | while(baggage->bags[i] != NULL) { |
michael@0 | 861 | SEC_PKCS12BaggageItem *xbag = baggage->bags[i]; |
michael@0 | 862 | j = 0; |
michael@0 | 863 | if(xbag->unencSecrets != NULL) { |
michael@0 | 864 | while(xbag->unencSecrets[j] != NULL) { |
michael@0 | 865 | SECOidTag bagType; |
michael@0 | 866 | bagType = SECOID_FindOIDTag(&xbag->unencSecrets[j]->safeBagType); |
michael@0 | 867 | retItem = sec_pkcs12_try_find(NULL, xbag, objType, bagType, |
michael@0 | 868 | j, nickname, thumbprint); |
michael@0 | 869 | if(retItem != NULL) { |
michael@0 | 870 | return retItem; |
michael@0 | 871 | } |
michael@0 | 872 | j++; |
michael@0 | 873 | } |
michael@0 | 874 | } |
michael@0 | 875 | i++; |
michael@0 | 876 | } |
michael@0 | 877 | } |
michael@0 | 878 | |
michael@0 | 879 | PORT_SetError(SEC_ERROR_PKCS12_UNABLE_TO_LOCATE_OBJECT_BY_NAME); |
michael@0 | 880 | return NULL; |
michael@0 | 881 | } |
michael@0 | 882 | |
michael@0 | 883 | /* this function converts a password to unicode and encures that the |
michael@0 | 884 | * required double 0 byte be placed at the end of the string |
michael@0 | 885 | */ |
michael@0 | 886 | PRBool |
michael@0 | 887 | sec_pkcs12_convert_item_to_unicode(PLArenaPool *arena, SECItem *dest, |
michael@0 | 888 | SECItem *src, PRBool zeroTerm, |
michael@0 | 889 | PRBool asciiConvert, PRBool toUnicode) |
michael@0 | 890 | { |
michael@0 | 891 | PRBool success = PR_FALSE; |
michael@0 | 892 | if(!src || !dest) { |
michael@0 | 893 | PORT_SetError(SEC_ERROR_INVALID_ARGS); |
michael@0 | 894 | return PR_FALSE; |
michael@0 | 895 | } |
michael@0 | 896 | |
michael@0 | 897 | dest->len = src->len * 3 + 2; |
michael@0 | 898 | if(arena) { |
michael@0 | 899 | dest->data = (unsigned char*)PORT_ArenaZAlloc(arena, dest->len); |
michael@0 | 900 | } else { |
michael@0 | 901 | dest->data = (unsigned char*)PORT_ZAlloc(dest->len); |
michael@0 | 902 | } |
michael@0 | 903 | |
michael@0 | 904 | if(!dest->data) { |
michael@0 | 905 | dest->len = 0; |
michael@0 | 906 | return PR_FALSE; |
michael@0 | 907 | } |
michael@0 | 908 | |
michael@0 | 909 | if(!asciiConvert) { |
michael@0 | 910 | success = PORT_UCS2_UTF8Conversion(toUnicode, src->data, src->len, dest->data, |
michael@0 | 911 | dest->len, &dest->len); |
michael@0 | 912 | } else { |
michael@0 | 913 | #ifndef IS_LITTLE_ENDIAN |
michael@0 | 914 | PRBool swapUnicode = PR_FALSE; |
michael@0 | 915 | #else |
michael@0 | 916 | PRBool swapUnicode = PR_TRUE; |
michael@0 | 917 | #endif |
michael@0 | 918 | success = PORT_UCS2_ASCIIConversion(toUnicode, src->data, src->len, dest->data, |
michael@0 | 919 | dest->len, &dest->len, swapUnicode); |
michael@0 | 920 | } |
michael@0 | 921 | |
michael@0 | 922 | if(!success) { |
michael@0 | 923 | if(!arena) { |
michael@0 | 924 | PORT_Free(dest->data); |
michael@0 | 925 | dest->data = NULL; |
michael@0 | 926 | dest->len = 0; |
michael@0 | 927 | } |
michael@0 | 928 | return PR_FALSE; |
michael@0 | 929 | } |
michael@0 | 930 | |
michael@0 | 931 | if((dest->data[dest->len-1] || dest->data[dest->len-2]) && zeroTerm) { |
michael@0 | 932 | if(dest->len + 2 > 3 * src->len) { |
michael@0 | 933 | if(arena) { |
michael@0 | 934 | dest->data = (unsigned char*)PORT_ArenaGrow(arena, |
michael@0 | 935 | dest->data, dest->len, |
michael@0 | 936 | dest->len + 2); |
michael@0 | 937 | } else { |
michael@0 | 938 | dest->data = (unsigned char*)PORT_Realloc(dest->data, |
michael@0 | 939 | dest->len + 2); |
michael@0 | 940 | } |
michael@0 | 941 | |
michael@0 | 942 | if(!dest->data) { |
michael@0 | 943 | return PR_FALSE; |
michael@0 | 944 | } |
michael@0 | 945 | } |
michael@0 | 946 | dest->len += 2; |
michael@0 | 947 | dest->data[dest->len-1] = dest->data[dest->len-2] = 0; |
michael@0 | 948 | } |
michael@0 | 949 | |
michael@0 | 950 | return PR_TRUE; |
michael@0 | 951 | } |
michael@0 | 952 | |
michael@0 | 953 | /* pkcs 12 templates */ |
michael@0 | 954 | static const SEC_ASN1TemplateChooserPtr sec_pkcs12_shroud_chooser = |
michael@0 | 955 | sec_pkcs12_choose_shroud_type; |
michael@0 | 956 | |
michael@0 | 957 | const SEC_ASN1Template SEC_PKCS12CodedSafeBagTemplate[] = |
michael@0 | 958 | { |
michael@0 | 959 | { SEC_ASN1_SEQUENCE, 0, NULL, sizeof(SEC_PKCS12SafeBag) }, |
michael@0 | 960 | { SEC_ASN1_OBJECT_ID, offsetof(SEC_PKCS12SafeBag, safeBagType) }, |
michael@0 | 961 | { SEC_ASN1_ANY, offsetof(SEC_PKCS12SafeBag, derSafeContent) }, |
michael@0 | 962 | { 0 } |
michael@0 | 963 | }; |
michael@0 | 964 | |
michael@0 | 965 | const SEC_ASN1Template SEC_PKCS12CodedCertBagTemplate[] = |
michael@0 | 966 | { |
michael@0 | 967 | { SEC_ASN1_SEQUENCE, 0, NULL, sizeof(SEC_PKCS12CertAndCRL) }, |
michael@0 | 968 | { SEC_ASN1_OBJECT_ID, offsetof(SEC_PKCS12CertAndCRL, BagID) }, |
michael@0 | 969 | { SEC_ASN1_ANY, offsetof(SEC_PKCS12CertAndCRL, derValue) }, |
michael@0 | 970 | { 0 } |
michael@0 | 971 | }; |
michael@0 | 972 | |
michael@0 | 973 | const SEC_ASN1Template SEC_PKCS12CodedCertAndCRLBagTemplate[] = |
michael@0 | 974 | { |
michael@0 | 975 | { SEC_ASN1_SET_OF, offsetof(SEC_PKCS12CertAndCRLBag, certAndCRLs), |
michael@0 | 976 | SEC_PKCS12CodedCertBagTemplate }, |
michael@0 | 977 | }; |
michael@0 | 978 | |
michael@0 | 979 | const SEC_ASN1Template SEC_PKCS12ESPVKItemTemplate_OLD[] = |
michael@0 | 980 | { |
michael@0 | 981 | { SEC_ASN1_SEQUENCE, 0, NULL, sizeof(SEC_PKCS12ESPVKItem) }, |
michael@0 | 982 | { SEC_ASN1_OBJECT_ID, offsetof(SEC_PKCS12ESPVKItem, espvkOID) }, |
michael@0 | 983 | { SEC_ASN1_INLINE, offsetof(SEC_PKCS12ESPVKItem, espvkData), |
michael@0 | 984 | SEC_PKCS12PVKSupportingDataTemplate_OLD }, |
michael@0 | 985 | { SEC_ASN1_EXPLICIT | SEC_ASN1_CONSTRUCTED | SEC_ASN1_CONTEXT_SPECIFIC | |
michael@0 | 986 | SEC_ASN1_DYNAMIC | 0, offsetof(SEC_PKCS12ESPVKItem, espvkCipherText), |
michael@0 | 987 | &sec_pkcs12_shroud_chooser }, |
michael@0 | 988 | { 0 } |
michael@0 | 989 | }; |
michael@0 | 990 | |
michael@0 | 991 | const SEC_ASN1Template SEC_PKCS12ESPVKItemTemplate[] = |
michael@0 | 992 | { |
michael@0 | 993 | { SEC_ASN1_SEQUENCE, 0, NULL, sizeof(SEC_PKCS12ESPVKItem) }, |
michael@0 | 994 | { SEC_ASN1_OBJECT_ID, offsetof(SEC_PKCS12ESPVKItem, espvkOID) }, |
michael@0 | 995 | { SEC_ASN1_INLINE, offsetof(SEC_PKCS12ESPVKItem, espvkData), |
michael@0 | 996 | SEC_PKCS12PVKSupportingDataTemplate }, |
michael@0 | 997 | { SEC_ASN1_EXPLICIT | SEC_ASN1_CONSTRUCTED | SEC_ASN1_CONTEXT_SPECIFIC | |
michael@0 | 998 | SEC_ASN1_DYNAMIC | 0, offsetof(SEC_PKCS12ESPVKItem, espvkCipherText), |
michael@0 | 999 | &sec_pkcs12_shroud_chooser }, |
michael@0 | 1000 | { 0 } |
michael@0 | 1001 | }; |
michael@0 | 1002 | |
michael@0 | 1003 | const SEC_ASN1Template SEC_PKCS12PVKAdditionalDataTemplate[] = |
michael@0 | 1004 | { |
michael@0 | 1005 | { SEC_ASN1_SEQUENCE, 0, NULL, sizeof(SEC_PKCS12PVKAdditionalData) }, |
michael@0 | 1006 | { SEC_ASN1_OBJECT_ID, |
michael@0 | 1007 | offsetof(SEC_PKCS12PVKAdditionalData, pvkAdditionalType) }, |
michael@0 | 1008 | { SEC_ASN1_CONSTRUCTED | SEC_ASN1_CONTEXT_SPECIFIC | 0, |
michael@0 | 1009 | offsetof(SEC_PKCS12PVKAdditionalData, pvkAdditionalContent) }, |
michael@0 | 1010 | { 0 } |
michael@0 | 1011 | }; |
michael@0 | 1012 | |
michael@0 | 1013 | const SEC_ASN1Template SEC_PKCS12PVKSupportingDataTemplate_OLD[] = |
michael@0 | 1014 | { |
michael@0 | 1015 | { SEC_ASN1_SEQUENCE, 0, NULL, sizeof(SEC_PKCS12PVKSupportingData) }, |
michael@0 | 1016 | { SEC_ASN1_SET_OF | SEC_ASN1_XTRN , |
michael@0 | 1017 | offsetof(SEC_PKCS12PVKSupportingData, assocCerts), |
michael@0 | 1018 | SEC_ASN1_SUB(sgn_DigestInfoTemplate) }, |
michael@0 | 1019 | { SEC_ASN1_OPTIONAL | SEC_ASN1_BOOLEAN, |
michael@0 | 1020 | offsetof(SEC_PKCS12PVKSupportingData, regenerable) }, |
michael@0 | 1021 | { SEC_ASN1_PRINTABLE_STRING, |
michael@0 | 1022 | offsetof(SEC_PKCS12PVKSupportingData, nickname) }, |
michael@0 | 1023 | { SEC_ASN1_ANY | SEC_ASN1_OPTIONAL, |
michael@0 | 1024 | offsetof(SEC_PKCS12PVKSupportingData, pvkAdditionalDER) }, |
michael@0 | 1025 | { 0 } |
michael@0 | 1026 | }; |
michael@0 | 1027 | |
michael@0 | 1028 | const SEC_ASN1Template SEC_PKCS12PVKSupportingDataTemplate[] = |
michael@0 | 1029 | { |
michael@0 | 1030 | { SEC_ASN1_SEQUENCE, 0, NULL, sizeof(SEC_PKCS12PVKSupportingData) }, |
michael@0 | 1031 | { SEC_ASN1_SET_OF | SEC_ASN1_XTRN , |
michael@0 | 1032 | offsetof(SEC_PKCS12PVKSupportingData, assocCerts), |
michael@0 | 1033 | SEC_ASN1_SUB(sgn_DigestInfoTemplate) }, |
michael@0 | 1034 | { SEC_ASN1_OPTIONAL | SEC_ASN1_BOOLEAN, |
michael@0 | 1035 | offsetof(SEC_PKCS12PVKSupportingData, regenerable) }, |
michael@0 | 1036 | { SEC_ASN1_BMP_STRING, |
michael@0 | 1037 | offsetof(SEC_PKCS12PVKSupportingData, uniNickName) }, |
michael@0 | 1038 | { SEC_ASN1_ANY | SEC_ASN1_OPTIONAL, |
michael@0 | 1039 | offsetof(SEC_PKCS12PVKSupportingData, pvkAdditionalDER) }, |
michael@0 | 1040 | { 0 } |
michael@0 | 1041 | }; |
michael@0 | 1042 | |
michael@0 | 1043 | const SEC_ASN1Template SEC_PKCS12BaggageItemTemplate[] = |
michael@0 | 1044 | { |
michael@0 | 1045 | { SEC_ASN1_SEQUENCE, 0, NULL, sizeof(SEC_PKCS12BaggageItem) }, |
michael@0 | 1046 | { SEC_ASN1_SET_OF, offsetof(SEC_PKCS12BaggageItem, espvks), |
michael@0 | 1047 | SEC_PKCS12ESPVKItemTemplate }, |
michael@0 | 1048 | { SEC_ASN1_SET_OF, offsetof(SEC_PKCS12BaggageItem, unencSecrets), |
michael@0 | 1049 | SEC_PKCS12SafeBagTemplate }, |
michael@0 | 1050 | /*{ SEC_ASN1_SET_OF, offsetof(SEC_PKCS12BaggageItem, unencSecrets), |
michael@0 | 1051 | SEC_PKCS12CodedSafeBagTemplate }, */ |
michael@0 | 1052 | { 0 } |
michael@0 | 1053 | }; |
michael@0 | 1054 | |
michael@0 | 1055 | const SEC_ASN1Template SEC_PKCS12BaggageTemplate[] = |
michael@0 | 1056 | { |
michael@0 | 1057 | { SEC_ASN1_SET_OF, offsetof(SEC_PKCS12Baggage, bags), |
michael@0 | 1058 | SEC_PKCS12BaggageItemTemplate }, |
michael@0 | 1059 | }; |
michael@0 | 1060 | |
michael@0 | 1061 | const SEC_ASN1Template SEC_PKCS12BaggageTemplate_OLD[] = |
michael@0 | 1062 | { |
michael@0 | 1063 | { SEC_ASN1_SET_OF, offsetof(SEC_PKCS12Baggage_OLD, espvks), |
michael@0 | 1064 | SEC_PKCS12ESPVKItemTemplate_OLD }, |
michael@0 | 1065 | }; |
michael@0 | 1066 | |
michael@0 | 1067 | static const SEC_ASN1TemplateChooserPtr sec_pkcs12_bag_chooser = |
michael@0 | 1068 | sec_pkcs12_choose_bag_type; |
michael@0 | 1069 | |
michael@0 | 1070 | static const SEC_ASN1TemplateChooserPtr sec_pkcs12_bag_chooser_old = |
michael@0 | 1071 | sec_pkcs12_choose_bag_type_old; |
michael@0 | 1072 | |
michael@0 | 1073 | const SEC_ASN1Template SEC_PKCS12SafeBagTemplate_OLD[] = |
michael@0 | 1074 | { |
michael@0 | 1075 | { SEC_ASN1_SEQUENCE, 0, NULL, sizeof(SEC_PKCS12SafeBag) }, |
michael@0 | 1076 | { SEC_ASN1_OBJECT_ID, offsetof(SEC_PKCS12SafeBag, safeBagType) }, |
michael@0 | 1077 | { SEC_ASN1_DYNAMIC | SEC_ASN1_CONSTRUCTED | SEC_ASN1_EXPLICIT | |
michael@0 | 1078 | SEC_ASN1_CONTEXT_SPECIFIC | 0, |
michael@0 | 1079 | offsetof(SEC_PKCS12SafeBag, safeContent), |
michael@0 | 1080 | &sec_pkcs12_bag_chooser_old }, |
michael@0 | 1081 | { 0 } |
michael@0 | 1082 | }; |
michael@0 | 1083 | |
michael@0 | 1084 | const SEC_ASN1Template SEC_PKCS12SafeBagTemplate[] = |
michael@0 | 1085 | { |
michael@0 | 1086 | { SEC_ASN1_SEQUENCE, 0, NULL, sizeof(SEC_PKCS12SafeBag) }, |
michael@0 | 1087 | { SEC_ASN1_OBJECT_ID, offsetof(SEC_PKCS12SafeBag, safeBagType) }, |
michael@0 | 1088 | { SEC_ASN1_DYNAMIC | SEC_ASN1_POINTER, |
michael@0 | 1089 | offsetof(SEC_PKCS12SafeBag, safeContent), |
michael@0 | 1090 | &sec_pkcs12_bag_chooser }, |
michael@0 | 1091 | { SEC_ASN1_OPTIONAL | SEC_ASN1_BMP_STRING, |
michael@0 | 1092 | offsetof(SEC_PKCS12SafeBag, uniSafeBagName) }, |
michael@0 | 1093 | { 0 } |
michael@0 | 1094 | }; |
michael@0 | 1095 | |
michael@0 | 1096 | const SEC_ASN1Template SEC_PKCS12SafeContentsTemplate_OLD[] = |
michael@0 | 1097 | { |
michael@0 | 1098 | { SEC_ASN1_SET_OF, |
michael@0 | 1099 | offsetof(SEC_PKCS12SafeContents, contents), |
michael@0 | 1100 | SEC_PKCS12SafeBagTemplate_OLD } |
michael@0 | 1101 | }; |
michael@0 | 1102 | |
michael@0 | 1103 | const SEC_ASN1Template SEC_PKCS12SafeContentsTemplate[] = |
michael@0 | 1104 | { |
michael@0 | 1105 | { SEC_ASN1_SET_OF, |
michael@0 | 1106 | offsetof(SEC_PKCS12SafeContents, contents), |
michael@0 | 1107 | SEC_PKCS12SafeBagTemplate } /* here */ |
michael@0 | 1108 | }; |
michael@0 | 1109 | |
michael@0 | 1110 | const SEC_ASN1Template SEC_PKCS12PrivateKeyTemplate[] = |
michael@0 | 1111 | { |
michael@0 | 1112 | { SEC_ASN1_SEQUENCE, 0, NULL, sizeof(SEC_PKCS12PrivateKey) }, |
michael@0 | 1113 | { SEC_ASN1_INLINE, offsetof(SEC_PKCS12PrivateKey, pvkData), |
michael@0 | 1114 | SEC_PKCS12PVKSupportingDataTemplate }, |
michael@0 | 1115 | { SEC_ASN1_INLINE | SEC_ASN1_XTRN, |
michael@0 | 1116 | offsetof(SEC_PKCS12PrivateKey, pkcs8data), |
michael@0 | 1117 | SEC_ASN1_SUB(SECKEY_PrivateKeyInfoTemplate) }, |
michael@0 | 1118 | { 0 } |
michael@0 | 1119 | }; |
michael@0 | 1120 | |
michael@0 | 1121 | const SEC_ASN1Template SEC_PKCS12PrivateKeyBagTemplate[] = |
michael@0 | 1122 | { |
michael@0 | 1123 | { SEC_ASN1_SEQUENCE, 0, NULL, sizeof(SEC_PKCS12PrivateKeyBag) }, |
michael@0 | 1124 | { SEC_ASN1_SET_OF, offsetof(SEC_PKCS12PrivateKeyBag, privateKeys), |
michael@0 | 1125 | SEC_PKCS12PrivateKeyTemplate }, |
michael@0 | 1126 | { 0 } |
michael@0 | 1127 | }; |
michael@0 | 1128 | |
michael@0 | 1129 | const SEC_ASN1Template SEC_PKCS12X509CertCRLTemplate_OLD[] = |
michael@0 | 1130 | { |
michael@0 | 1131 | { SEC_ASN1_SEQUENCE, 0, NULL, sizeof(SEC_PKCS12X509CertCRL) }, |
michael@0 | 1132 | { SEC_ASN1_INLINE, offsetof(SEC_PKCS12X509CertCRL, certOrCRL), |
michael@0 | 1133 | sec_PKCS7ContentInfoTemplate }, |
michael@0 | 1134 | { SEC_ASN1_INLINE | SEC_ASN1_XTRN , |
michael@0 | 1135 | offsetof(SEC_PKCS12X509CertCRL, thumbprint), |
michael@0 | 1136 | SEC_ASN1_SUB(sgn_DigestInfoTemplate) }, |
michael@0 | 1137 | { 0 } |
michael@0 | 1138 | }; |
michael@0 | 1139 | |
michael@0 | 1140 | const SEC_ASN1Template SEC_PKCS12X509CertCRLTemplate[] = |
michael@0 | 1141 | { |
michael@0 | 1142 | { SEC_ASN1_SEQUENCE, 0, NULL, sizeof(SEC_PKCS12X509CertCRL) }, |
michael@0 | 1143 | { SEC_ASN1_INLINE, offsetof(SEC_PKCS12X509CertCRL, certOrCRL), |
michael@0 | 1144 | sec_PKCS7ContentInfoTemplate }, |
michael@0 | 1145 | { 0 } |
michael@0 | 1146 | }; |
michael@0 | 1147 | |
michael@0 | 1148 | const SEC_ASN1Template SEC_PKCS12SDSICertTemplate[] = |
michael@0 | 1149 | { |
michael@0 | 1150 | { SEC_ASN1_SEQUENCE, 0, NULL, sizeof(SEC_PKCS12X509CertCRL) }, |
michael@0 | 1151 | { SEC_ASN1_IA5_STRING, offsetof(SEC_PKCS12SDSICert, value) }, |
michael@0 | 1152 | { 0 } |
michael@0 | 1153 | }; |
michael@0 | 1154 | |
michael@0 | 1155 | static const SEC_ASN1TemplateChooserPtr sec_pkcs12_cert_crl_chooser_old = |
michael@0 | 1156 | sec_pkcs12_choose_cert_crl_type_old; |
michael@0 | 1157 | |
michael@0 | 1158 | static const SEC_ASN1TemplateChooserPtr sec_pkcs12_cert_crl_chooser = |
michael@0 | 1159 | sec_pkcs12_choose_cert_crl_type; |
michael@0 | 1160 | |
michael@0 | 1161 | const SEC_ASN1Template SEC_PKCS12CertAndCRLTemplate_OLD[] = |
michael@0 | 1162 | { |
michael@0 | 1163 | { SEC_ASN1_SEQUENCE, 0, NULL, sizeof(SEC_PKCS12CertAndCRL) }, |
michael@0 | 1164 | { SEC_ASN1_OBJECT_ID, offsetof(SEC_PKCS12CertAndCRL, BagID) }, |
michael@0 | 1165 | { SEC_ASN1_CONTEXT_SPECIFIC | SEC_ASN1_EXPLICIT | |
michael@0 | 1166 | SEC_ASN1_DYNAMIC | SEC_ASN1_CONSTRUCTED | 0, |
michael@0 | 1167 | offsetof(SEC_PKCS12CertAndCRL, value), |
michael@0 | 1168 | &sec_pkcs12_cert_crl_chooser_old }, |
michael@0 | 1169 | { 0 } |
michael@0 | 1170 | }; |
michael@0 | 1171 | |
michael@0 | 1172 | const SEC_ASN1Template SEC_PKCS12CertAndCRLTemplate[] = |
michael@0 | 1173 | { |
michael@0 | 1174 | { SEC_ASN1_SEQUENCE, 0, NULL, sizeof(SEC_PKCS12CertAndCRL) }, |
michael@0 | 1175 | { SEC_ASN1_OBJECT_ID, offsetof(SEC_PKCS12CertAndCRL, BagID) }, |
michael@0 | 1176 | { SEC_ASN1_DYNAMIC | SEC_ASN1_CONSTRUCTED | SEC_ASN1_EXPLICIT | |
michael@0 | 1177 | SEC_ASN1_CONTEXT_SPECIFIC | 0, |
michael@0 | 1178 | offsetof(SEC_PKCS12CertAndCRL, value), |
michael@0 | 1179 | &sec_pkcs12_cert_crl_chooser }, |
michael@0 | 1180 | { 0 } |
michael@0 | 1181 | }; |
michael@0 | 1182 | |
michael@0 | 1183 | const SEC_ASN1Template SEC_PKCS12CertAndCRLBagTemplate[] = |
michael@0 | 1184 | { |
michael@0 | 1185 | { SEC_ASN1_SET_OF, offsetof(SEC_PKCS12CertAndCRLBag, certAndCRLs), |
michael@0 | 1186 | SEC_PKCS12CertAndCRLTemplate }, |
michael@0 | 1187 | }; |
michael@0 | 1188 | |
michael@0 | 1189 | const SEC_ASN1Template SEC_PKCS12CertAndCRLBagTemplate_OLD[] = |
michael@0 | 1190 | { |
michael@0 | 1191 | { SEC_ASN1_SEQUENCE, 0, NULL, sizeof(SEC_PKCS12CertAndCRLBag) }, |
michael@0 | 1192 | { SEC_ASN1_SET_OF, offsetof(SEC_PKCS12CertAndCRLBag, certAndCRLs), |
michael@0 | 1193 | SEC_PKCS12CertAndCRLTemplate_OLD }, |
michael@0 | 1194 | { 0 } |
michael@0 | 1195 | }; |
michael@0 | 1196 | |
michael@0 | 1197 | const SEC_ASN1Template SEC_PKCS12SecretAdditionalTemplate[] = |
michael@0 | 1198 | { |
michael@0 | 1199 | { SEC_ASN1_SEQUENCE, 0, NULL, sizeof(SEC_PKCS12SecretAdditional) }, |
michael@0 | 1200 | { SEC_ASN1_OBJECT_ID, |
michael@0 | 1201 | offsetof(SEC_PKCS12SecretAdditional, secretAdditionalType) }, |
michael@0 | 1202 | { SEC_ASN1_CONTEXT_SPECIFIC | SEC_ASN1_EXPLICIT, |
michael@0 | 1203 | offsetof(SEC_PKCS12SecretAdditional, secretAdditionalContent) }, |
michael@0 | 1204 | { 0 } |
michael@0 | 1205 | }; |
michael@0 | 1206 | |
michael@0 | 1207 | const SEC_ASN1Template SEC_PKCS12SecretTemplate[] = |
michael@0 | 1208 | { |
michael@0 | 1209 | { SEC_ASN1_SEQUENCE, 0, NULL, sizeof(SEC_PKCS12Secret) }, |
michael@0 | 1210 | { SEC_ASN1_BMP_STRING, offsetof(SEC_PKCS12Secret, uniSecretName) }, |
michael@0 | 1211 | { SEC_ASN1_ANY, offsetof(SEC_PKCS12Secret, value) }, |
michael@0 | 1212 | { SEC_ASN1_INLINE | SEC_ASN1_OPTIONAL, |
michael@0 | 1213 | offsetof(SEC_PKCS12Secret, secretAdditional), |
michael@0 | 1214 | SEC_PKCS12SecretAdditionalTemplate }, |
michael@0 | 1215 | { 0 } |
michael@0 | 1216 | }; |
michael@0 | 1217 | |
michael@0 | 1218 | const SEC_ASN1Template SEC_PKCS12SecretItemTemplate[] = |
michael@0 | 1219 | { |
michael@0 | 1220 | { SEC_ASN1_SEQUENCE, 0, NULL, sizeof(SEC_PKCS12Secret) }, |
michael@0 | 1221 | { SEC_ASN1_INLINE | SEC_ASN1_CONTEXT_SPECIFIC | 0, |
michael@0 | 1222 | offsetof(SEC_PKCS12SecretItem, secret), SEC_PKCS12SecretTemplate }, |
michael@0 | 1223 | { SEC_ASN1_INLINE | SEC_ASN1_CONTEXT_SPECIFIC | 1, |
michael@0 | 1224 | offsetof(SEC_PKCS12SecretItem, subFolder), SEC_PKCS12SafeBagTemplate }, |
michael@0 | 1225 | { 0 } |
michael@0 | 1226 | }; |
michael@0 | 1227 | |
michael@0 | 1228 | const SEC_ASN1Template SEC_PKCS12SecretBagTemplate[] = |
michael@0 | 1229 | { |
michael@0 | 1230 | { SEC_ASN1_SET_OF, offsetof(SEC_PKCS12SecretBag, secrets), |
michael@0 | 1231 | SEC_PKCS12SecretItemTemplate }, |
michael@0 | 1232 | }; |
michael@0 | 1233 | |
michael@0 | 1234 | const SEC_ASN1Template SEC_PKCS12MacDataTemplate[] = |
michael@0 | 1235 | { |
michael@0 | 1236 | { SEC_ASN1_SEQUENCE, 0, NULL, sizeof(SEC_PKCS12PFXItem) }, |
michael@0 | 1237 | { SEC_ASN1_INLINE | SEC_ASN1_XTRN , offsetof(SEC_PKCS12MacData, safeMac), |
michael@0 | 1238 | SEC_ASN1_SUB(sgn_DigestInfoTemplate) }, |
michael@0 | 1239 | { SEC_ASN1_BIT_STRING, offsetof(SEC_PKCS12MacData, macSalt) }, |
michael@0 | 1240 | { 0 } |
michael@0 | 1241 | }; |
michael@0 | 1242 | |
michael@0 | 1243 | const SEC_ASN1Template SEC_PKCS12PFXItemTemplate[] = |
michael@0 | 1244 | { |
michael@0 | 1245 | { SEC_ASN1_SEQUENCE, 0, NULL, sizeof(SEC_PKCS12PFXItem) }, |
michael@0 | 1246 | { SEC_ASN1_OPTIONAL | |
michael@0 | 1247 | SEC_ASN1_CONSTRUCTED | SEC_ASN1_CONTEXT_SPECIFIC | 0, |
michael@0 | 1248 | offsetof(SEC_PKCS12PFXItem, macData), SEC_PKCS12MacDataTemplate }, |
michael@0 | 1249 | { SEC_ASN1_CONSTRUCTED | SEC_ASN1_CONTEXT_SPECIFIC | 1, |
michael@0 | 1250 | offsetof(SEC_PKCS12PFXItem, authSafe), |
michael@0 | 1251 | sec_PKCS7ContentInfoTemplate }, |
michael@0 | 1252 | { 0 } |
michael@0 | 1253 | }; |
michael@0 | 1254 | |
michael@0 | 1255 | const SEC_ASN1Template SEC_PKCS12PFXItemTemplate_OLD[] = |
michael@0 | 1256 | { |
michael@0 | 1257 | { SEC_ASN1_SEQUENCE, 0, NULL, sizeof(SEC_PKCS12PFXItem) }, |
michael@0 | 1258 | { SEC_ASN1_OPTIONAL | |
michael@0 | 1259 | SEC_ASN1_CONSTRUCTED | SEC_ASN1_CONTEXT_SPECIFIC | SEC_ASN1_XTRN | 0, |
michael@0 | 1260 | offsetof(SEC_PKCS12PFXItem, old_safeMac), |
michael@0 | 1261 | SEC_ASN1_SUB(sgn_DigestInfoTemplate) }, |
michael@0 | 1262 | { SEC_ASN1_OPTIONAL | SEC_ASN1_BIT_STRING, |
michael@0 | 1263 | offsetof(SEC_PKCS12PFXItem, old_macSalt) }, |
michael@0 | 1264 | { SEC_ASN1_CONSTRUCTED | SEC_ASN1_CONTEXT_SPECIFIC | 1, |
michael@0 | 1265 | offsetof(SEC_PKCS12PFXItem, authSafe), |
michael@0 | 1266 | sec_PKCS7ContentInfoTemplate }, |
michael@0 | 1267 | { 0 } |
michael@0 | 1268 | }; |
michael@0 | 1269 | |
michael@0 | 1270 | const SEC_ASN1Template SEC_PKCS12AuthenticatedSafeTemplate[] = |
michael@0 | 1271 | { |
michael@0 | 1272 | { SEC_ASN1_SEQUENCE, 0, NULL, sizeof(SEC_PKCS12AuthenticatedSafe) }, |
michael@0 | 1273 | { SEC_ASN1_OPTIONAL | SEC_ASN1_INTEGER, |
michael@0 | 1274 | offsetof(SEC_PKCS12AuthenticatedSafe, version) }, |
michael@0 | 1275 | { SEC_ASN1_OPTIONAL | SEC_ASN1_OBJECT_ID, |
michael@0 | 1276 | offsetof(SEC_PKCS12AuthenticatedSafe, transportMode) }, |
michael@0 | 1277 | { SEC_ASN1_BIT_STRING | SEC_ASN1_OPTIONAL, |
michael@0 | 1278 | offsetof(SEC_PKCS12AuthenticatedSafe, privacySalt) }, |
michael@0 | 1279 | { SEC_ASN1_OPTIONAL | SEC_ASN1_SET_OF, |
michael@0 | 1280 | offsetof(SEC_PKCS12AuthenticatedSafe, baggage.bags), |
michael@0 | 1281 | SEC_PKCS12BaggageItemTemplate }, |
michael@0 | 1282 | { SEC_ASN1_POINTER, |
michael@0 | 1283 | offsetof(SEC_PKCS12AuthenticatedSafe, safe), |
michael@0 | 1284 | sec_PKCS7ContentInfoTemplate }, |
michael@0 | 1285 | { 0 } |
michael@0 | 1286 | }; |
michael@0 | 1287 | |
michael@0 | 1288 | const SEC_ASN1Template SEC_PKCS12AuthenticatedSafeTemplate_OLD[] = |
michael@0 | 1289 | { |
michael@0 | 1290 | { SEC_ASN1_SEQUENCE, 0, NULL, sizeof(SEC_PKCS12AuthenticatedSafe) }, |
michael@0 | 1291 | { SEC_ASN1_OPTIONAL | SEC_ASN1_INTEGER, |
michael@0 | 1292 | offsetof(SEC_PKCS12AuthenticatedSafe, version) }, |
michael@0 | 1293 | { SEC_ASN1_OPTIONAL | SEC_ASN1_INTEGER, |
michael@0 | 1294 | offsetof(SEC_PKCS12AuthenticatedSafe, transportMode) }, |
michael@0 | 1295 | { SEC_ASN1_BIT_STRING, |
michael@0 | 1296 | offsetof(SEC_PKCS12AuthenticatedSafe, privacySalt) }, |
michael@0 | 1297 | { SEC_ASN1_OPTIONAL | SEC_ASN1_CONSTRUCTED | |
michael@0 | 1298 | SEC_ASN1_CONTEXT_SPECIFIC | 0, |
michael@0 | 1299 | offsetof(SEC_PKCS12AuthenticatedSafe, old_baggage), |
michael@0 | 1300 | SEC_PKCS12BaggageTemplate_OLD }, |
michael@0 | 1301 | { SEC_ASN1_CONSTRUCTED | SEC_ASN1_CONTEXT_SPECIFIC | 1, |
michael@0 | 1302 | offsetof(SEC_PKCS12AuthenticatedSafe, old_safe), |
michael@0 | 1303 | sec_PKCS7ContentInfoTemplate }, |
michael@0 | 1304 | { 0 } |
michael@0 | 1305 | }; |
michael@0 | 1306 | |
michael@0 | 1307 | const SEC_ASN1Template SEC_PointerToPKCS12KeyBagTemplate[] = |
michael@0 | 1308 | { |
michael@0 | 1309 | { SEC_ASN1_POINTER, 0, SEC_PKCS12PrivateKeyBagTemplate } |
michael@0 | 1310 | }; |
michael@0 | 1311 | |
michael@0 | 1312 | const SEC_ASN1Template SEC_PointerToPKCS12CertAndCRLBagTemplate_OLD[] = |
michael@0 | 1313 | { |
michael@0 | 1314 | { SEC_ASN1_POINTER, 0, SEC_PKCS12CertAndCRLBagTemplate_OLD } |
michael@0 | 1315 | }; |
michael@0 | 1316 | |
michael@0 | 1317 | const SEC_ASN1Template SEC_PointerToPKCS12CertAndCRLBagTemplate[] = |
michael@0 | 1318 | { |
michael@0 | 1319 | { SEC_ASN1_POINTER, 0, SEC_PKCS12CertAndCRLBagTemplate } |
michael@0 | 1320 | }; |
michael@0 | 1321 | |
michael@0 | 1322 | const SEC_ASN1Template SEC_PointerToPKCS12SecretBagTemplate[] = |
michael@0 | 1323 | { |
michael@0 | 1324 | { SEC_ASN1_POINTER, 0, SEC_PKCS12SecretBagTemplate } |
michael@0 | 1325 | }; |
michael@0 | 1326 | |
michael@0 | 1327 | const SEC_ASN1Template SEC_PointerToPKCS12X509CertCRLTemplate_OLD[] = |
michael@0 | 1328 | { |
michael@0 | 1329 | { SEC_ASN1_POINTER, 0, SEC_PKCS12X509CertCRLTemplate_OLD } |
michael@0 | 1330 | }; |
michael@0 | 1331 | |
michael@0 | 1332 | const SEC_ASN1Template SEC_PointerToPKCS12X509CertCRLTemplate[] = |
michael@0 | 1333 | { |
michael@0 | 1334 | { SEC_ASN1_POINTER, 0, SEC_PKCS12X509CertCRLTemplate } |
michael@0 | 1335 | }; |
michael@0 | 1336 | |
michael@0 | 1337 | const SEC_ASN1Template SEC_PointerToPKCS12SDSICertTemplate[] = |
michael@0 | 1338 | { |
michael@0 | 1339 | { SEC_ASN1_POINTER, 0, SEC_PKCS12SDSICertTemplate } |
michael@0 | 1340 | }; |
michael@0 | 1341 | |
michael@0 | 1342 |