summaryrefslogtreecommitdiff
path: root/security/nss/lib/pkcs12/pkcs12t.h
blob: ad00d7b5b550bc0faaf299e873a7c0179c8398bf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef _PKCS12T_H_
#define _PKCS12T_H_

#include "seccomon.h"
#include "secoid.h"
#include "cert.h"
#include "key.h"
#include "plarena.h"
#include "secpkcs7.h"
#include "secdig.h" /* for SGNDigestInfo */

typedef enum {
    SECPKCS12TargetTokenNoCAs,           /* CA get loaded intothe fixed token,
                                          * User certs go to target token */
    SECPKCS12TargetTokenIntermediateCAs, /* User certs and intermediates go to
                                          * target token, root certs got to
                                          * fixed token */
    SECPKCS12TargetTokenAllCAs           /* All certs go to target token */
} SECPKCS12TargetTokenCAs;

/* PKCS12 Structures */
typedef struct SEC_PKCS12PFXItemStr SEC_PKCS12PFXItem;
typedef struct SEC_PKCS12MacDataStr SEC_PKCS12MacData;
typedef struct SEC_PKCS12AuthenticatedSafeStr SEC_PKCS12AuthenticatedSafe;
typedef struct SEC_PKCS12BaggageItemStr SEC_PKCS12BaggageItem;
typedef struct SEC_PKCS12BaggageStr SEC_PKCS12Baggage;
typedef struct SEC_PKCS12Baggage_OLDStr SEC_PKCS12Baggage_OLD;
typedef struct SEC_PKCS12ESPVKItemStr SEC_PKCS12ESPVKItem;
typedef struct SEC_PKCS12PVKSupportingDataStr SEC_PKCS12PVKSupportingData;
typedef struct SEC_PKCS12PVKAdditionalDataStr SEC_PKCS12PVKAdditionalData;
typedef struct SEC_PKCS12SafeContentsStr SEC_PKCS12SafeContents;
typedef struct SEC_PKCS12SafeBagStr SEC_PKCS12SafeBag;
typedef struct SEC_PKCS12PrivateKeyStr SEC_PKCS12PrivateKey;
typedef struct SEC_PKCS12PrivateKeyBagStr SEC_PKCS12PrivateKeyBag;
typedef struct SEC_PKCS12CertAndCRLBagStr SEC_PKCS12CertAndCRLBag;
typedef struct SEC_PKCS12CertAndCRLStr SEC_PKCS12CertAndCRL;
typedef struct SEC_PKCS12X509CertCRLStr SEC_PKCS12X509CertCRL;
typedef struct SEC_PKCS12SDSICertStr SEC_PKCS12SDSICert;
typedef struct SEC_PKCS12SecretStr SEC_PKCS12Secret;
typedef struct SEC_PKCS12SecretAdditionalStr SEC_PKCS12SecretAdditional;
typedef struct SEC_PKCS12SecretItemStr SEC_PKCS12SecretItem;
typedef struct SEC_PKCS12SecretBagStr SEC_PKCS12SecretBag;

typedef SECItem *(*SEC_PKCS12PasswordFunc)(SECItem *args);

/* PKCS12 types */

/* stores shrouded keys */
struct SEC_PKCS12BaggageStr {
    PLArenaPool *poolp;
    SEC_PKCS12BaggageItem **bags;

    int luggage_size; /* used locally */
};

/* additional data to be associated with keys.  currently there
 * is nothing defined to be stored here.  allows future expansion.
 */
struct SEC_PKCS12PVKAdditionalDataStr {
    PLArenaPool *poolp;
    SECOidData *pvkAdditionalTypeTag; /* used locally */
    SECItem pvkAdditionalType;
    SECItem pvkAdditionalContent;
};

/* cert and other supporting data for private keys.  used
 * for both shrouded and non-shrouded keys.
 */
struct SEC_PKCS12PVKSupportingDataStr {
    PLArenaPool *poolp;
    SGNDigestInfo **assocCerts;
    SECItem regenerable;
    SECItem nickname;
    SEC_PKCS12PVKAdditionalData pvkAdditional;
    SECItem pvkAdditionalDER;

    SECItem uniNickName;
    /* used locally */
    int nThumbs;
};

/* shrouded key structure.  supports only pkcs8 shrouding
 * currently.
 */
struct SEC_PKCS12ESPVKItemStr {
    PLArenaPool *poolp;   /* used locally */
    SECOidData *espvkTag; /* used locally */
    SECItem espvkOID;
    SEC_PKCS12PVKSupportingData espvkData;
    union {
        SECKEYEncryptedPrivateKeyInfo *pkcs8KeyShroud;
    } espvkCipherText;

    PRBool duplicate;    /* used locally */
    PRBool problem_cert; /* used locally */
    PRBool single_cert;  /* used locally */
    int nCerts;          /* used locally */
    SECItem derCert;     /* used locally */
};

/* generic bag store for the safe.  safeBagType identifies
 * the type of bag stored.
 */
struct SEC_PKCS12SafeBagStr {
    PLArenaPool *poolp;
    SECOidData *safeBagTypeTag; /* used locally */
    SECItem safeBagType;
    union {
        SEC_PKCS12PrivateKeyBag *keyBag;
        SEC_PKCS12CertAndCRLBag *certAndCRLBag;
        SEC_PKCS12SecretBag *secretBag;
    } safeContent;

    SECItem derSafeContent;
    SECItem safeBagName;

    SECItem uniSafeBagName;
};

/* stores private keys and certificates in a list.  each safebag
 * has an ID identifying the type of content stored.
 */
struct SEC_PKCS12SafeContentsStr {
    PLArenaPool *poolp;
    SEC_PKCS12SafeBag **contents;

    /* used for tracking purposes */
    int safe_size;
    PRBool old;
    PRBool swapUnicode;
    PRBool possibleSwapUnicode;
};

/* private key structure which holds encrypted private key and
 * supporting data including nickname and certificate thumbprint.
 */
struct SEC_PKCS12PrivateKeyStr {
    PLArenaPool *poolp;
    SEC_PKCS12PVKSupportingData pvkData;
    SECKEYPrivateKeyInfo pkcs8data; /* borrowed from PKCS 8 */

    PRBool duplicate;    /* used locally */
    PRBool problem_cert; /* used locally */
    PRBool single_cert;  /* used locally */
    int nCerts;          /* used locally */
    SECItem derCert;     /* used locally */
};

/* private key bag, holds a (null terminated) list of private key
 * structures.
 */
struct SEC_PKCS12PrivateKeyBagStr {
    PLArenaPool *poolp;
    SEC_PKCS12PrivateKey **privateKeys;

    int bag_size; /* used locally */
};

/* container to hold certificates.  currently supports x509
 * and sdsi certificates
 */
struct SEC_PKCS12CertAndCRLStr {
    PLArenaPool *poolp;
    SECOidData *BagTypeTag; /* used locally */
    SECItem BagID;
    union {
        SEC_PKCS12X509CertCRL *x509;
        SEC_PKCS12SDSICert *sdsi;
    } value;

    SECItem derValue;
    SECItem nickname; /* used locally */
    PRBool duplicate; /* used locally */
};

/* x509 certificate structure.  typically holds the der encoding
 * of the x509 certificate.  thumbprint contains a digest of the
 * certificate
 */
struct SEC_PKCS12X509CertCRLStr {
    PLArenaPool *poolp;
    SEC_PKCS7ContentInfo certOrCRL;
    SGNDigestInfo thumbprint;

    SECItem *derLeafCert; /* used locally */
};

/* sdsi certificate structure.  typically holds the der encoding
 * of the sdsi certificate.  thumbprint contains a digest of the
 * certificate
 */
struct SEC_PKCS12SDSICertStr {
    PLArenaPool *poolp;
    SECItem value;
    SGNDigestInfo thumbprint;
};

/* contains a null terminated list of certs and crls */
struct SEC_PKCS12CertAndCRLBagStr {
    PLArenaPool *poolp;
    SEC_PKCS12CertAndCRL **certAndCRLs;

    int bag_size; /* used locally */
};

/* additional secret information.  currently no information
 * stored in this structure.
 */
struct SEC_PKCS12SecretAdditionalStr {
    PLArenaPool *poolp;
    SECOidData *secretTypeTag; /* used locally */
    SECItem secretAdditionalType;
    SECItem secretAdditionalContent;
};

/* secrets container.  this will be used to contain currently
 * unspecified secrets.  (it's a secret)
 */
struct SEC_PKCS12SecretStr {
    PLArenaPool *poolp;
    SECItem secretName;
    SECItem value;
    SEC_PKCS12SecretAdditional secretAdditional;

    SECItem uniSecretName;
};

struct SEC_PKCS12SecretItemStr {
    PLArenaPool *poolp;
    SEC_PKCS12Secret secret;
    SEC_PKCS12SafeBag subFolder;
};

/* a bag of secrets.  holds a null terminated list of secrets.
 */
struct SEC_PKCS12SecretBagStr {
    PLArenaPool *poolp;
    SEC_PKCS12SecretItem **secrets;

    int bag_size; /* used locally */
};

struct SEC_PKCS12MacDataStr {
    SGNDigestInfo safeMac;
    SECItem macSalt;
};

/* outer transfer unit */
struct SEC_PKCS12PFXItemStr {
    PLArenaPool *poolp;
    SEC_PKCS12MacData macData;
    SEC_PKCS7ContentInfo authSafe;

    /* for compatibility with beta */
    PRBool old;
    SGNDigestInfo old_safeMac;
    SECItem old_macSalt;

    /* compatibility between platforms for unicode swapping */
    PRBool swapUnicode;
};

struct SEC_PKCS12BaggageItemStr {
    PLArenaPool *poolp;
    SEC_PKCS12ESPVKItem **espvks;
    SEC_PKCS12SafeBag **unencSecrets;

    int nEspvks;
    int nSecrets;
};

/* stores shrouded keys */
struct SEC_PKCS12Baggage_OLDStr {
    PLArenaPool *poolp;
    SEC_PKCS12ESPVKItem **espvks;

    int luggage_size; /* used locally */
};

/* authenticated safe, stores certs, keys, and shrouded keys */
struct SEC_PKCS12AuthenticatedSafeStr {
    PLArenaPool *poolp;
    SECItem version;
    SECOidData *transportTypeTag; /* local not part of encoding*/
    SECItem transportMode;
    SECItem privacySalt;
    SEC_PKCS12Baggage baggage;
    SEC_PKCS7ContentInfo *safe;

    /* used for beta compatibility */
    PRBool old;
    PRBool emptySafe;
    SEC_PKCS12Baggage_OLD old_baggage;
    SEC_PKCS7ContentInfo old_safe;
    PRBool swapUnicode;
};
#define SEC_PKCS12_PFX_VERSION 1 /* what we create */

/* PKCS 12 Templates */
extern const SEC_ASN1Template SEC_PKCS12PFXItemTemplate_OLD[];
extern const SEC_ASN1Template SEC_PKCS12AuthenticatedSafeTemplate_OLD[];
extern const SEC_ASN1Template SEC_PKCS12BaggageTemplate_OLD[];
extern const SEC_ASN1Template SEC_PKCS12PFXItemTemplate[];
extern const SEC_ASN1Template SEC_PKCS12MacDataTemplate[];
extern const SEC_ASN1Template SEC_PKCS12AuthenticatedSafeTemplate[];
extern const SEC_ASN1Template SEC_PKCS12BaggageTemplate[];
extern const SEC_ASN1Template SEC_PKCS12ESPVKItemTemplate[];
extern const SEC_ASN1Template SEC_PKCS12PVKSupportingDataTemplate[];
extern const SEC_ASN1Template SEC_PKCS12PVKAdditionalTemplate[];
extern const SEC_ASN1Template SEC_PKCS12SafeContentsTemplate_OLD[];
extern const SEC_ASN1Template SEC_PKCS12SafeContentsTemplate[];
extern const SEC_ASN1Template SEC_PKCS12SafeBagTemplate[];
extern const SEC_ASN1Template SEC_PKCS12PrivateKeyTemplate[];
extern const SEC_ASN1Template SEC_PKCS12PrivateKeyBagTemplate[];
extern const SEC_ASN1Template SEC_PKCS12CertAndCRLTemplate[];
extern const SEC_ASN1Template SEC_PKCS12CertAndCRLBagTemplate[];
extern const SEC_ASN1Template SEC_PKCS12X509CertCRLTemplate_OLD[];
extern const SEC_ASN1Template SEC_PKCS12X509CertCRLTemplate[];
extern const SEC_ASN1Template SEC_PKCS12SDSICertTemplate[];
extern const SEC_ASN1Template SEC_PKCS12SecretBagTemplate[];
extern const SEC_ASN1Template SEC_PKCS12SecretTemplate[];
extern const SEC_ASN1Template SEC_PKCS12SecretItemTemplate[];
extern const SEC_ASN1Template SEC_PKCS12SecretAdditionalTemplate[];
extern const SEC_ASN1Template SGN_DigestInfoTemplate[];
extern const SEC_ASN1Template SEC_PointerToPKCS12KeyBagTemplate[];
extern const SEC_ASN1Template SEC_PointerToPKCS12CertAndCRLBagTemplate[];
extern const SEC_ASN1Template SEC_PointerToPKCS12CertAndCRLBagTemplate_OLD[];
extern const SEC_ASN1Template SEC_PointerToPKCS12SecretBagTemplate[];
extern const SEC_ASN1Template SEC_PointerToPKCS12X509CertCRLTemplate_OLD[];
extern const SEC_ASN1Template SEC_PointerToPKCS12X509CertCRLTemplate[];
extern const SEC_ASN1Template SEC_PointerToPKCS12SDSICertTemplate[];
extern const SEC_ASN1Template SEC_PKCS12CodedSafeBagTemplate[];
extern const SEC_ASN1Template SEC_PKCS12CodedCertBagTemplate[];
extern const SEC_ASN1Template SEC_PKCS12CodedCertAndCRLBagTemplate[];
extern const SEC_ASN1Template SEC_PKCS12PVKSupportingDataTemplate_OLD[];
extern const SEC_ASN1Template SEC_PKCS12ESPVKItemTemplate_OLD[];
#endif