Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
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 | #ifndef _PKCS12T_H_ |
michael@0 | 6 | #define _PKCS12T_H_ |
michael@0 | 7 | |
michael@0 | 8 | #include "seccomon.h" |
michael@0 | 9 | #include "secoid.h" |
michael@0 | 10 | #include "cert.h" |
michael@0 | 11 | #include "key.h" |
michael@0 | 12 | #include "plarena.h" |
michael@0 | 13 | #include "secpkcs7.h" |
michael@0 | 14 | #include "secdig.h" /* for SGNDigestInfo */ |
michael@0 | 15 | |
michael@0 | 16 | typedef enum { |
michael@0 | 17 | SECPKCS12TargetTokenNoCAs, /* CA get loaded intothe fixed token, |
michael@0 | 18 | * User certs go to target token */ |
michael@0 | 19 | SECPKCS12TargetTokenIntermediateCAs, /* User certs and intermediates go to |
michael@0 | 20 | * target token, root certs got to |
michael@0 | 21 | * fixed token */ |
michael@0 | 22 | SECPKCS12TargetTokenAllCAs /* All certs go to target token */ |
michael@0 | 23 | } SECPKCS12TargetTokenCAs; |
michael@0 | 24 | |
michael@0 | 25 | /* PKCS12 Structures */ |
michael@0 | 26 | typedef struct SEC_PKCS12PFXItemStr SEC_PKCS12PFXItem; |
michael@0 | 27 | typedef struct SEC_PKCS12MacDataStr SEC_PKCS12MacData; |
michael@0 | 28 | typedef struct SEC_PKCS12AuthenticatedSafeStr SEC_PKCS12AuthenticatedSafe; |
michael@0 | 29 | typedef struct SEC_PKCS12BaggageItemStr SEC_PKCS12BaggageItem; |
michael@0 | 30 | typedef struct SEC_PKCS12BaggageStr SEC_PKCS12Baggage; |
michael@0 | 31 | typedef struct SEC_PKCS12Baggage_OLDStr SEC_PKCS12Baggage_OLD; |
michael@0 | 32 | typedef struct SEC_PKCS12ESPVKItemStr SEC_PKCS12ESPVKItem; |
michael@0 | 33 | typedef struct SEC_PKCS12PVKSupportingDataStr SEC_PKCS12PVKSupportingData; |
michael@0 | 34 | typedef struct SEC_PKCS12PVKAdditionalDataStr SEC_PKCS12PVKAdditionalData; |
michael@0 | 35 | typedef struct SEC_PKCS12SafeContentsStr SEC_PKCS12SafeContents; |
michael@0 | 36 | typedef struct SEC_PKCS12SafeBagStr SEC_PKCS12SafeBag; |
michael@0 | 37 | typedef struct SEC_PKCS12PrivateKeyStr SEC_PKCS12PrivateKey; |
michael@0 | 38 | typedef struct SEC_PKCS12PrivateKeyBagStr SEC_PKCS12PrivateKeyBag; |
michael@0 | 39 | typedef struct SEC_PKCS12CertAndCRLBagStr SEC_PKCS12CertAndCRLBag; |
michael@0 | 40 | typedef struct SEC_PKCS12CertAndCRLStr SEC_PKCS12CertAndCRL; |
michael@0 | 41 | typedef struct SEC_PKCS12X509CertCRLStr SEC_PKCS12X509CertCRL; |
michael@0 | 42 | typedef struct SEC_PKCS12SDSICertStr SEC_PKCS12SDSICert; |
michael@0 | 43 | typedef struct SEC_PKCS12SecretStr SEC_PKCS12Secret; |
michael@0 | 44 | typedef struct SEC_PKCS12SecretAdditionalStr SEC_PKCS12SecretAdditional; |
michael@0 | 45 | typedef struct SEC_PKCS12SecretItemStr SEC_PKCS12SecretItem; |
michael@0 | 46 | typedef struct SEC_PKCS12SecretBagStr SEC_PKCS12SecretBag; |
michael@0 | 47 | |
michael@0 | 48 | typedef SECItem *(* SEC_PKCS12PasswordFunc)(SECItem *args); |
michael@0 | 49 | |
michael@0 | 50 | /* PKCS12 types */ |
michael@0 | 51 | |
michael@0 | 52 | /* stores shrouded keys */ |
michael@0 | 53 | struct SEC_PKCS12BaggageStr |
michael@0 | 54 | { |
michael@0 | 55 | PLArenaPool *poolp; |
michael@0 | 56 | SEC_PKCS12BaggageItem **bags; |
michael@0 | 57 | |
michael@0 | 58 | int luggage_size; /* used locally */ |
michael@0 | 59 | }; |
michael@0 | 60 | |
michael@0 | 61 | /* additional data to be associated with keys. currently there |
michael@0 | 62 | * is nothing defined to be stored here. allows future expansion. |
michael@0 | 63 | */ |
michael@0 | 64 | struct SEC_PKCS12PVKAdditionalDataStr |
michael@0 | 65 | { |
michael@0 | 66 | PLArenaPool *poolp; |
michael@0 | 67 | SECOidData *pvkAdditionalTypeTag; /* used locally */ |
michael@0 | 68 | SECItem pvkAdditionalType; |
michael@0 | 69 | SECItem pvkAdditionalContent; |
michael@0 | 70 | }; |
michael@0 | 71 | |
michael@0 | 72 | /* cert and other supporting data for private keys. used |
michael@0 | 73 | * for both shrouded and non-shrouded keys. |
michael@0 | 74 | */ |
michael@0 | 75 | struct SEC_PKCS12PVKSupportingDataStr |
michael@0 | 76 | { |
michael@0 | 77 | PLArenaPool *poolp; |
michael@0 | 78 | SGNDigestInfo **assocCerts; |
michael@0 | 79 | SECItem regenerable; |
michael@0 | 80 | SECItem nickname; |
michael@0 | 81 | SEC_PKCS12PVKAdditionalData pvkAdditional; |
michael@0 | 82 | SECItem pvkAdditionalDER; |
michael@0 | 83 | |
michael@0 | 84 | SECItem uniNickName; |
michael@0 | 85 | /* used locally */ |
michael@0 | 86 | int nThumbs; |
michael@0 | 87 | }; |
michael@0 | 88 | |
michael@0 | 89 | /* shrouded key structure. supports only pkcs8 shrouding |
michael@0 | 90 | * currently. |
michael@0 | 91 | */ |
michael@0 | 92 | struct SEC_PKCS12ESPVKItemStr |
michael@0 | 93 | { |
michael@0 | 94 | PLArenaPool *poolp; /* used locally */ |
michael@0 | 95 | SECOidData *espvkTag; /* used locally */ |
michael@0 | 96 | SECItem espvkOID; |
michael@0 | 97 | SEC_PKCS12PVKSupportingData espvkData; |
michael@0 | 98 | union |
michael@0 | 99 | { |
michael@0 | 100 | SECKEYEncryptedPrivateKeyInfo *pkcs8KeyShroud; |
michael@0 | 101 | } espvkCipherText; |
michael@0 | 102 | |
michael@0 | 103 | PRBool duplicate; /* used locally */ |
michael@0 | 104 | PRBool problem_cert; /* used locally */ |
michael@0 | 105 | PRBool single_cert; /* used locally */ |
michael@0 | 106 | int nCerts; /* used locally */ |
michael@0 | 107 | SECItem derCert; /* used locally */ |
michael@0 | 108 | }; |
michael@0 | 109 | |
michael@0 | 110 | /* generic bag store for the safe. safeBagType identifies |
michael@0 | 111 | * the type of bag stored. |
michael@0 | 112 | */ |
michael@0 | 113 | struct SEC_PKCS12SafeBagStr |
michael@0 | 114 | { |
michael@0 | 115 | PLArenaPool *poolp; |
michael@0 | 116 | SECOidData *safeBagTypeTag; /* used locally */ |
michael@0 | 117 | SECItem safeBagType; |
michael@0 | 118 | union |
michael@0 | 119 | { |
michael@0 | 120 | SEC_PKCS12PrivateKeyBag *keyBag; |
michael@0 | 121 | SEC_PKCS12CertAndCRLBag *certAndCRLBag; |
michael@0 | 122 | SEC_PKCS12SecretBag *secretBag; |
michael@0 | 123 | } safeContent; |
michael@0 | 124 | |
michael@0 | 125 | SECItem derSafeContent; |
michael@0 | 126 | SECItem safeBagName; |
michael@0 | 127 | |
michael@0 | 128 | SECItem uniSafeBagName; |
michael@0 | 129 | }; |
michael@0 | 130 | |
michael@0 | 131 | /* stores private keys and certificates in a list. each safebag |
michael@0 | 132 | * has an ID identifying the type of content stored. |
michael@0 | 133 | */ |
michael@0 | 134 | struct SEC_PKCS12SafeContentsStr |
michael@0 | 135 | { |
michael@0 | 136 | PLArenaPool *poolp; |
michael@0 | 137 | SEC_PKCS12SafeBag **contents; |
michael@0 | 138 | |
michael@0 | 139 | /* used for tracking purposes */ |
michael@0 | 140 | int safe_size; |
michael@0 | 141 | PRBool old; |
michael@0 | 142 | PRBool swapUnicode; |
michael@0 | 143 | PRBool possibleSwapUnicode; |
michael@0 | 144 | }; |
michael@0 | 145 | |
michael@0 | 146 | /* private key structure which holds encrypted private key and |
michael@0 | 147 | * supporting data including nickname and certificate thumbprint. |
michael@0 | 148 | */ |
michael@0 | 149 | struct SEC_PKCS12PrivateKeyStr |
michael@0 | 150 | { |
michael@0 | 151 | PLArenaPool *poolp; |
michael@0 | 152 | SEC_PKCS12PVKSupportingData pvkData; |
michael@0 | 153 | SECKEYPrivateKeyInfo pkcs8data; /* borrowed from PKCS 8 */ |
michael@0 | 154 | |
michael@0 | 155 | PRBool duplicate; /* used locally */ |
michael@0 | 156 | PRBool problem_cert;/* used locally */ |
michael@0 | 157 | PRBool single_cert; /* used locally */ |
michael@0 | 158 | int nCerts; /* used locally */ |
michael@0 | 159 | SECItem derCert; /* used locally */ |
michael@0 | 160 | }; |
michael@0 | 161 | |
michael@0 | 162 | /* private key bag, holds a (null terminated) list of private key |
michael@0 | 163 | * structures. |
michael@0 | 164 | */ |
michael@0 | 165 | struct SEC_PKCS12PrivateKeyBagStr |
michael@0 | 166 | { |
michael@0 | 167 | PLArenaPool *poolp; |
michael@0 | 168 | SEC_PKCS12PrivateKey **privateKeys; |
michael@0 | 169 | |
michael@0 | 170 | int bag_size; /* used locally */ |
michael@0 | 171 | }; |
michael@0 | 172 | |
michael@0 | 173 | /* container to hold certificates. currently supports x509 |
michael@0 | 174 | * and sdsi certificates |
michael@0 | 175 | */ |
michael@0 | 176 | struct SEC_PKCS12CertAndCRLStr |
michael@0 | 177 | { |
michael@0 | 178 | PLArenaPool *poolp; |
michael@0 | 179 | SECOidData *BagTypeTag; /* used locally */ |
michael@0 | 180 | SECItem BagID; |
michael@0 | 181 | union |
michael@0 | 182 | { |
michael@0 | 183 | SEC_PKCS12X509CertCRL *x509; |
michael@0 | 184 | SEC_PKCS12SDSICert *sdsi; |
michael@0 | 185 | } value; |
michael@0 | 186 | |
michael@0 | 187 | SECItem derValue; |
michael@0 | 188 | SECItem nickname; /* used locally */ |
michael@0 | 189 | PRBool duplicate; /* used locally */ |
michael@0 | 190 | }; |
michael@0 | 191 | |
michael@0 | 192 | /* x509 certificate structure. typically holds the der encoding |
michael@0 | 193 | * of the x509 certificate. thumbprint contains a digest of the |
michael@0 | 194 | * certificate |
michael@0 | 195 | */ |
michael@0 | 196 | struct SEC_PKCS12X509CertCRLStr |
michael@0 | 197 | { |
michael@0 | 198 | PLArenaPool *poolp; |
michael@0 | 199 | SEC_PKCS7ContentInfo certOrCRL; |
michael@0 | 200 | SGNDigestInfo thumbprint; |
michael@0 | 201 | |
michael@0 | 202 | SECItem *derLeafCert; /* used locally */ |
michael@0 | 203 | }; |
michael@0 | 204 | |
michael@0 | 205 | /* sdsi certificate structure. typically holds the der encoding |
michael@0 | 206 | * of the sdsi certificate. thumbprint contains a digest of the |
michael@0 | 207 | * certificate |
michael@0 | 208 | */ |
michael@0 | 209 | struct SEC_PKCS12SDSICertStr |
michael@0 | 210 | { |
michael@0 | 211 | PLArenaPool *poolp; |
michael@0 | 212 | SECItem value; |
michael@0 | 213 | SGNDigestInfo thumbprint; |
michael@0 | 214 | }; |
michael@0 | 215 | |
michael@0 | 216 | /* contains a null terminated list of certs and crls */ |
michael@0 | 217 | struct SEC_PKCS12CertAndCRLBagStr |
michael@0 | 218 | { |
michael@0 | 219 | PLArenaPool *poolp; |
michael@0 | 220 | SEC_PKCS12CertAndCRL **certAndCRLs; |
michael@0 | 221 | |
michael@0 | 222 | int bag_size; /* used locally */ |
michael@0 | 223 | }; |
michael@0 | 224 | |
michael@0 | 225 | /* additional secret information. currently no information |
michael@0 | 226 | * stored in this structure. |
michael@0 | 227 | */ |
michael@0 | 228 | struct SEC_PKCS12SecretAdditionalStr |
michael@0 | 229 | { |
michael@0 | 230 | PLArenaPool *poolp; |
michael@0 | 231 | SECOidData *secretTypeTag; /* used locally */ |
michael@0 | 232 | SECItem secretAdditionalType; |
michael@0 | 233 | SECItem secretAdditionalContent; |
michael@0 | 234 | }; |
michael@0 | 235 | |
michael@0 | 236 | /* secrets container. this will be used to contain currently |
michael@0 | 237 | * unspecified secrets. (it's a secret) |
michael@0 | 238 | */ |
michael@0 | 239 | struct SEC_PKCS12SecretStr |
michael@0 | 240 | { |
michael@0 | 241 | PLArenaPool *poolp; |
michael@0 | 242 | SECItem secretName; |
michael@0 | 243 | SECItem value; |
michael@0 | 244 | SEC_PKCS12SecretAdditional secretAdditional; |
michael@0 | 245 | |
michael@0 | 246 | SECItem uniSecretName; |
michael@0 | 247 | }; |
michael@0 | 248 | |
michael@0 | 249 | struct SEC_PKCS12SecretItemStr |
michael@0 | 250 | { |
michael@0 | 251 | PLArenaPool *poolp; |
michael@0 | 252 | SEC_PKCS12Secret secret; |
michael@0 | 253 | SEC_PKCS12SafeBag subFolder; |
michael@0 | 254 | }; |
michael@0 | 255 | |
michael@0 | 256 | /* a bag of secrets. holds a null terminated list of secrets. |
michael@0 | 257 | */ |
michael@0 | 258 | struct SEC_PKCS12SecretBagStr |
michael@0 | 259 | { |
michael@0 | 260 | PLArenaPool *poolp; |
michael@0 | 261 | SEC_PKCS12SecretItem **secrets; |
michael@0 | 262 | |
michael@0 | 263 | int bag_size; /* used locally */ |
michael@0 | 264 | }; |
michael@0 | 265 | |
michael@0 | 266 | struct SEC_PKCS12MacDataStr |
michael@0 | 267 | { |
michael@0 | 268 | SGNDigestInfo safeMac; |
michael@0 | 269 | SECItem macSalt; |
michael@0 | 270 | }; |
michael@0 | 271 | |
michael@0 | 272 | /* outer transfer unit */ |
michael@0 | 273 | struct SEC_PKCS12PFXItemStr |
michael@0 | 274 | { |
michael@0 | 275 | PLArenaPool *poolp; |
michael@0 | 276 | SEC_PKCS12MacData macData; |
michael@0 | 277 | SEC_PKCS7ContentInfo authSafe; |
michael@0 | 278 | |
michael@0 | 279 | /* for compatibility with beta */ |
michael@0 | 280 | PRBool old; |
michael@0 | 281 | SGNDigestInfo old_safeMac; |
michael@0 | 282 | SECItem old_macSalt; |
michael@0 | 283 | |
michael@0 | 284 | /* compatibility between platforms for unicode swapping */ |
michael@0 | 285 | PRBool swapUnicode; |
michael@0 | 286 | }; |
michael@0 | 287 | |
michael@0 | 288 | struct SEC_PKCS12BaggageItemStr { |
michael@0 | 289 | PLArenaPool *poolp; |
michael@0 | 290 | SEC_PKCS12ESPVKItem **espvks; |
michael@0 | 291 | SEC_PKCS12SafeBag **unencSecrets; |
michael@0 | 292 | |
michael@0 | 293 | int nEspvks; |
michael@0 | 294 | int nSecrets; |
michael@0 | 295 | }; |
michael@0 | 296 | |
michael@0 | 297 | /* stores shrouded keys */ |
michael@0 | 298 | struct SEC_PKCS12Baggage_OLDStr |
michael@0 | 299 | { |
michael@0 | 300 | PLArenaPool *poolp; |
michael@0 | 301 | SEC_PKCS12ESPVKItem **espvks; |
michael@0 | 302 | |
michael@0 | 303 | int luggage_size; /* used locally */ |
michael@0 | 304 | }; |
michael@0 | 305 | |
michael@0 | 306 | /* authenticated safe, stores certs, keys, and shrouded keys */ |
michael@0 | 307 | struct SEC_PKCS12AuthenticatedSafeStr |
michael@0 | 308 | { |
michael@0 | 309 | PLArenaPool *poolp; |
michael@0 | 310 | SECItem version; |
michael@0 | 311 | SECOidData *transportTypeTag; /* local not part of encoding*/ |
michael@0 | 312 | SECItem transportMode; |
michael@0 | 313 | SECItem privacySalt; |
michael@0 | 314 | SEC_PKCS12Baggage baggage; |
michael@0 | 315 | SEC_PKCS7ContentInfo *safe; |
michael@0 | 316 | |
michael@0 | 317 | /* used for beta compatibility */ |
michael@0 | 318 | PRBool old; |
michael@0 | 319 | PRBool emptySafe; |
michael@0 | 320 | SEC_PKCS12Baggage_OLD old_baggage; |
michael@0 | 321 | SEC_PKCS7ContentInfo old_safe; |
michael@0 | 322 | PRBool swapUnicode; |
michael@0 | 323 | }; |
michael@0 | 324 | #define SEC_PKCS12_PFX_VERSION 1 /* what we create */ |
michael@0 | 325 | |
michael@0 | 326 | |
michael@0 | 327 | |
michael@0 | 328 | /* PKCS 12 Templates */ |
michael@0 | 329 | extern const SEC_ASN1Template SEC_PKCS12PFXItemTemplate_OLD[]; |
michael@0 | 330 | extern const SEC_ASN1Template SEC_PKCS12AuthenticatedSafeTemplate_OLD[]; |
michael@0 | 331 | extern const SEC_ASN1Template SEC_PKCS12BaggageTemplate_OLD[]; |
michael@0 | 332 | extern const SEC_ASN1Template SEC_PKCS12PFXItemTemplate[]; |
michael@0 | 333 | extern const SEC_ASN1Template SEC_PKCS12MacDataTemplate[]; |
michael@0 | 334 | extern const SEC_ASN1Template SEC_PKCS12AuthenticatedSafeTemplate[]; |
michael@0 | 335 | extern const SEC_ASN1Template SEC_PKCS12BaggageTemplate[]; |
michael@0 | 336 | extern const SEC_ASN1Template SEC_PKCS12ESPVKItemTemplate[]; |
michael@0 | 337 | extern const SEC_ASN1Template SEC_PKCS12PVKSupportingDataTemplate[]; |
michael@0 | 338 | extern const SEC_ASN1Template SEC_PKCS12PVKAdditionalTemplate[]; |
michael@0 | 339 | extern const SEC_ASN1Template SEC_PKCS12SafeContentsTemplate_OLD[]; |
michael@0 | 340 | extern const SEC_ASN1Template SEC_PKCS12SafeContentsTemplate[]; |
michael@0 | 341 | extern const SEC_ASN1Template SEC_PKCS12SafeBagTemplate[]; |
michael@0 | 342 | extern const SEC_ASN1Template SEC_PKCS12PrivateKeyTemplate[]; |
michael@0 | 343 | extern const SEC_ASN1Template SEC_PKCS12PrivateKeyBagTemplate[]; |
michael@0 | 344 | extern const SEC_ASN1Template SEC_PKCS12CertAndCRLTemplate[]; |
michael@0 | 345 | extern const SEC_ASN1Template SEC_PKCS12CertAndCRLBagTemplate[]; |
michael@0 | 346 | extern const SEC_ASN1Template SEC_PKCS12X509CertCRLTemplate_OLD[]; |
michael@0 | 347 | extern const SEC_ASN1Template SEC_PKCS12X509CertCRLTemplate[]; |
michael@0 | 348 | extern const SEC_ASN1Template SEC_PKCS12SDSICertTemplate[]; |
michael@0 | 349 | extern const SEC_ASN1Template SEC_PKCS12SecretBagTemplate[]; |
michael@0 | 350 | extern const SEC_ASN1Template SEC_PKCS12SecretTemplate[]; |
michael@0 | 351 | extern const SEC_ASN1Template SEC_PKCS12SecretItemTemplate[]; |
michael@0 | 352 | extern const SEC_ASN1Template SEC_PKCS12SecretAdditionalTemplate[]; |
michael@0 | 353 | extern const SEC_ASN1Template SGN_DigestInfoTemplate[]; |
michael@0 | 354 | extern const SEC_ASN1Template SEC_PointerToPKCS12KeyBagTemplate[]; |
michael@0 | 355 | extern const SEC_ASN1Template SEC_PointerToPKCS12CertAndCRLBagTemplate[]; |
michael@0 | 356 | extern const SEC_ASN1Template SEC_PointerToPKCS12CertAndCRLBagTemplate_OLD[]; |
michael@0 | 357 | extern const SEC_ASN1Template SEC_PointerToPKCS12SecretBagTemplate[]; |
michael@0 | 358 | extern const SEC_ASN1Template SEC_PointerToPKCS12X509CertCRLTemplate_OLD[]; |
michael@0 | 359 | extern const SEC_ASN1Template SEC_PointerToPKCS12X509CertCRLTemplate[]; |
michael@0 | 360 | extern const SEC_ASN1Template SEC_PointerToPKCS12SDSICertTemplate[]; |
michael@0 | 361 | extern const SEC_ASN1Template SEC_PKCS12CodedSafeBagTemplate[]; |
michael@0 | 362 | extern const SEC_ASN1Template SEC_PKCS12CodedCertBagTemplate[]; |
michael@0 | 363 | extern const SEC_ASN1Template SEC_PKCS12CodedCertAndCRLBagTemplate[]; |
michael@0 | 364 | extern const SEC_ASN1Template SEC_PKCS12PVKSupportingDataTemplate_OLD[]; |
michael@0 | 365 | extern const SEC_ASN1Template SEC_PKCS12ESPVKItemTemplate_OLD[]; |
michael@0 | 366 | #endif |