PageRenderTime 39ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

/gecko_api/include/pkcs7t.h

http://firefox-mac-pdf.googlecode.com/
C Header | 299 lines | 142 code | 26 blank | 131 comment | 0 complexity | 647f7b722af26c181e0f02915789f289 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. /*
  37. * Header for pkcs7 types.
  38. *
  39. * $Id: pkcs7t.h,v 1.5 2004/04/25 15:03:13 gerv%gerv.net Exp $
  40. */
  41. #ifndef _PKCS7T_H_
  42. #define _PKCS7T_H_
  43. #include "plarena.h"
  44. #include "seccomon.h"
  45. #include "secoidt.h"
  46. #include "certt.h"
  47. #include "secmodt.h"
  48. /* Opaque objects */
  49. typedef struct SEC_PKCS7DecoderContextStr SEC_PKCS7DecoderContext;
  50. typedef struct SEC_PKCS7EncoderContextStr SEC_PKCS7EncoderContext;
  51. /* legacy defines that haven't been active for years */
  52. typedef void *(*SECKEYGetPasswordKey)(void *arg, void *handle);
  53. /* Non-opaque objects. NOTE, though: I want them to be treated as
  54. * opaque as much as possible. If I could hide them completely,
  55. * I would. (I tried, but ran into trouble that was taking me too
  56. * much time to get out of.) I still intend to try to do so.
  57. * In fact, the only type that "outsiders" should even *name* is
  58. * SEC_PKCS7ContentInfo, and they should not reference its fields.
  59. */
  60. /* rjr: PKCS #11 cert handling (pk11cert.c) does use SEC_PKCS7RecipientInfo's.
  61. * This is because when we search the recipient list for the cert and key we
  62. * want, we need to invert the order of the loops we used to have. The old
  63. * loops were:
  64. *
  65. * For each recipient {
  66. * find_cert = PK11_Find_AllCert(recipient->issuerSN);
  67. * [which unrolls to... ]
  68. * For each slot {
  69. * Log into slot;
  70. * search slot for cert;
  71. * }
  72. * }
  73. *
  74. * the new loop searchs all the recipients at once on a slot. this allows
  75. * PKCS #11 to order slots in such a way that logout slots don't get checked
  76. * if we can find the cert on a logged in slot. This eliminates lots of
  77. * spurious password prompts when smart cards are installed... so why this
  78. * comment? If you make SEC_PKCS7RecipientInfo completely opaque, you need
  79. * to provide a non-opaque list of issuerSN's (the only field PKCS#11 needs
  80. * and fix up pk11cert.c first. NOTE: Only S/MIME calls this special PKCS #11
  81. * function.
  82. */
  83. typedef struct SEC_PKCS7ContentInfoStr SEC_PKCS7ContentInfo;
  84. typedef struct SEC_PKCS7SignedDataStr SEC_PKCS7SignedData;
  85. typedef struct SEC_PKCS7EncryptedContentInfoStr SEC_PKCS7EncryptedContentInfo;
  86. typedef struct SEC_PKCS7EnvelopedDataStr SEC_PKCS7EnvelopedData;
  87. typedef struct SEC_PKCS7SignedAndEnvelopedDataStr
  88. SEC_PKCS7SignedAndEnvelopedData;
  89. typedef struct SEC_PKCS7SignerInfoStr SEC_PKCS7SignerInfo;
  90. typedef struct SEC_PKCS7RecipientInfoStr SEC_PKCS7RecipientInfo;
  91. typedef struct SEC_PKCS7DigestedDataStr SEC_PKCS7DigestedData;
  92. typedef struct SEC_PKCS7EncryptedDataStr SEC_PKCS7EncryptedData;
  93. typedef struct SEC_PKCS7SMIMEKEAParametersStr SEC_PKCS7SMIMEKEAParameters;
  94. /*
  95. * The following is not actually a PKCS7 type, but for now it is only
  96. * used by PKCS7, so we have adopted it. If someone else *ever* needs
  97. * it, its name should be changed and it should be moved out of here.
  98. * Do not dare to use it without doing so!
  99. */
  100. typedef struct SEC_PKCS7AttributeStr SEC_PKCS7Attribute;
  101. struct SEC_PKCS7ContentInfoStr {
  102. PRArenaPool *poolp; /* local; not part of encoding */
  103. PRBool created; /* local; not part of encoding */
  104. int refCount; /* local; not part of encoding */
  105. SECOidData *contentTypeTag; /* local; not part of encoding */
  106. SECKEYGetPasswordKey pwfn; /* local; not part of encoding */
  107. void *pwfn_arg; /* local; not part of encoding */
  108. SECItem contentType;
  109. union {
  110. SECItem *data;
  111. SEC_PKCS7DigestedData *digestedData;
  112. SEC_PKCS7EncryptedData *encryptedData;
  113. SEC_PKCS7EnvelopedData *envelopedData;
  114. SEC_PKCS7SignedData *signedData;
  115. SEC_PKCS7SignedAndEnvelopedData *signedAndEnvelopedData;
  116. } content;
  117. };
  118. struct SEC_PKCS7SignedDataStr {
  119. SECItem version;
  120. SECAlgorithmID **digestAlgorithms;
  121. SEC_PKCS7ContentInfo contentInfo;
  122. SECItem **rawCerts;
  123. CERTSignedCrl **crls;
  124. SEC_PKCS7SignerInfo **signerInfos;
  125. SECItem **digests; /* local; not part of encoding */
  126. CERTCertificate **certs; /* local; not part of encoding */
  127. CERTCertificateList **certLists; /* local; not part of encoding */
  128. };
  129. #define SEC_PKCS7_SIGNED_DATA_VERSION 1 /* what we *create* */
  130. struct SEC_PKCS7EncryptedContentInfoStr {
  131. SECOidData *contentTypeTag; /* local; not part of encoding */
  132. SECItem contentType;
  133. SECAlgorithmID contentEncAlg;
  134. SECItem encContent;
  135. SECItem plainContent; /* local; not part of encoding */
  136. /* bytes not encrypted, but encoded */
  137. int keysize; /* local; not part of encoding */
  138. /* size of bulk encryption key
  139. * (only used by creation code) */
  140. SECOidTag encalg; /* local; not part of encoding */
  141. /* oid tag of encryption algorithm
  142. * (only used by creation code) */
  143. };
  144. struct SEC_PKCS7EnvelopedDataStr {
  145. SECItem version;
  146. SEC_PKCS7RecipientInfo **recipientInfos;
  147. SEC_PKCS7EncryptedContentInfo encContentInfo;
  148. };
  149. #define SEC_PKCS7_ENVELOPED_DATA_VERSION 0 /* what we *create* */
  150. struct SEC_PKCS7SignedAndEnvelopedDataStr {
  151. SECItem version;
  152. SEC_PKCS7RecipientInfo **recipientInfos;
  153. SECAlgorithmID **digestAlgorithms;
  154. SEC_PKCS7EncryptedContentInfo encContentInfo;
  155. SECItem **rawCerts;
  156. CERTSignedCrl **crls;
  157. SEC_PKCS7SignerInfo **signerInfos;
  158. SECItem **digests; /* local; not part of encoding */
  159. CERTCertificate **certs; /* local; not part of encoding */
  160. CERTCertificateList **certLists; /* local; not part of encoding */
  161. PK11SymKey *sigKey; /* local; not part of encoding */
  162. };
  163. #define SEC_PKCS7_SIGNED_AND_ENVELOPED_DATA_VERSION 1 /* what we *create* */
  164. struct SEC_PKCS7SignerInfoStr {
  165. SECItem version;
  166. CERTIssuerAndSN *issuerAndSN;
  167. SECAlgorithmID digestAlg;
  168. SEC_PKCS7Attribute **authAttr;
  169. SECAlgorithmID digestEncAlg;
  170. SECItem encDigest;
  171. SEC_PKCS7Attribute **unAuthAttr;
  172. CERTCertificate *cert; /* local; not part of encoding */
  173. CERTCertificateList *certList; /* local; not part of encoding */
  174. };
  175. #define SEC_PKCS7_SIGNER_INFO_VERSION 1 /* what we *create* */
  176. struct SEC_PKCS7RecipientInfoStr {
  177. SECItem version;
  178. CERTIssuerAndSN *issuerAndSN;
  179. SECAlgorithmID keyEncAlg;
  180. SECItem encKey;
  181. CERTCertificate *cert; /* local; not part of encoding */
  182. };
  183. #define SEC_PKCS7_RECIPIENT_INFO_VERSION 0 /* what we *create* */
  184. struct SEC_PKCS7DigestedDataStr {
  185. SECItem version;
  186. SECAlgorithmID digestAlg;
  187. SEC_PKCS7ContentInfo contentInfo;
  188. SECItem digest;
  189. };
  190. #define SEC_PKCS7_DIGESTED_DATA_VERSION 0 /* what we *create* */
  191. struct SEC_PKCS7EncryptedDataStr {
  192. SECItem version;
  193. SEC_PKCS7EncryptedContentInfo encContentInfo;
  194. };
  195. #define SEC_PKCS7_ENCRYPTED_DATA_VERSION 0 /* what we *create* */
  196. /*
  197. * See comment above about this type not really belonging to PKCS7.
  198. */
  199. struct SEC_PKCS7AttributeStr {
  200. /* The following fields make up an encoded Attribute: */
  201. SECItem type;
  202. SECItem **values; /* data may or may not be encoded */
  203. /* The following fields are not part of an encoded Attribute: */
  204. SECOidData *typeTag;
  205. PRBool encoded; /* when true, values are encoded */
  206. };
  207. /* An enumerated type used to select templates based on the encryption
  208. scenario and data specifics. */
  209. typedef enum
  210. {
  211. SECKEAInvalid = -1,
  212. SECKEAUsesSkipjack = 0,
  213. SECKEAUsesNonSkipjack = 1,
  214. SECKEAUsesNonSkipjackWithPaddedEncKey = 2
  215. } SECKEATemplateSelector;
  216. /* ### mwelch - S/MIME KEA parameters. These don't really fit here,
  217. but I cannot think of a more appropriate place at this time. */
  218. struct SEC_PKCS7SMIMEKEAParametersStr {
  219. SECItem originatorKEAKey; /* sender KEA key (encrypted?) */
  220. SECItem originatorRA; /* random number generated by sender */
  221. SECItem nonSkipjackIV; /* init'n vector for SkipjackCBC64
  222. decryption of KEA key if Skipjack
  223. is not the bulk algorithm used on
  224. the message */
  225. SECItem bulkKeySize; /* if Skipjack is not the bulk
  226. algorithm used on the message,
  227. and the size of the bulk encryption
  228. key is not the same as that of
  229. originatorKEAKey (due to padding
  230. perhaps), this field will contain
  231. the real size of the bulk encryption
  232. key. */
  233. };
  234. /*
  235. * Type of function passed to SEC_PKCS7Decode or SEC_PKCS7DecoderStart.
  236. * If specified, this is where the content bytes (only) will be "sent"
  237. * as they are recovered during the decoding.
  238. *
  239. * XXX Should just combine this with SEC_PKCS7EncoderContentCallback type
  240. * and use a simpler, common name.
  241. */
  242. typedef void (* SEC_PKCS7DecoderContentCallback)(void *arg,
  243. const char *buf,
  244. unsigned long len);
  245. /*
  246. * Type of function passed to SEC_PKCS7Encode or SEC_PKCS7EncoderStart.
  247. * This is where the encoded bytes will be "sent".
  248. *
  249. * XXX Should just combine this with SEC_PKCS7DecoderContentCallback type
  250. * and use a simpler, common name.
  251. */
  252. typedef void (* SEC_PKCS7EncoderOutputCallback)(void *arg,
  253. const char *buf,
  254. unsigned long len);
  255. /*
  256. * Type of function passed to SEC_PKCS7Decode or SEC_PKCS7DecoderStart
  257. * to retrieve the decryption key. This function is inteded to be
  258. * used for EncryptedData content info's which do not have a key available
  259. * in a certificate, etc.
  260. */
  261. typedef PK11SymKey * (* SEC_PKCS7GetDecryptKeyCallback)(void *arg,
  262. SECAlgorithmID *algid);
  263. /*
  264. * Type of function passed to SEC_PKCS7Decode or SEC_PKCS7DecoderStart.
  265. * This function in intended to be used to verify that decrypting a
  266. * particular crypto algorithm is allowed. Content types which do not
  267. * require decryption will not need the callback. If the callback
  268. * is not specified for content types which require decryption, the
  269. * decryption will be disallowed.
  270. */
  271. typedef PRBool (* SEC_PKCS7DecryptionAllowedCallback)(SECAlgorithmID *algid,
  272. PK11SymKey *bulkkey);
  273. #endif /* _PKCS7T_H_ */