PageRenderTime 56ms CodeModel.GetById 27ms RepoModel.GetById 1ms app.codeStats 0ms

/gecko_api/include/pkcs12t.h

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