PageRenderTime 18ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/gecko_api/include/secmime.h

http://firefox-mac-pdf.googlecode.com/
C Header | 195 lines | 22 code | 13 blank | 160 comment | 0 complexity | 52b98e37a9dd9d9fa16b5b0780c6ae7f 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 file for routines specific to S/MIME. Keep things that are pure
  38. * pkcs7 out of here; this is for S/MIME policy, S/MIME interoperability, etc.
  39. *
  40. * $Id: secmime.h,v 1.2 2004/04/25 15:03:13 gerv%gerv.net Exp $
  41. */
  42. #ifndef _SECMIME_H_
  43. #define _SECMIME_H_ 1
  44. #include "secpkcs7.h"
  45. /************************************************************************/
  46. SEC_BEGIN_PROTOS
  47. /*
  48. * Initialize the local recording of the user S/MIME cipher preferences.
  49. * This function is called once for each cipher, the order being
  50. * important (first call records greatest preference, and so on).
  51. * When finished, it is called with a "which" of CIPHER_FAMILID_MASK.
  52. * If the function is called again after that, it is assumed that
  53. * the preferences are being reset, and the old preferences are
  54. * discarded.
  55. *
  56. * XXX This is for a particular user, and right now the storage is
  57. * XXX local, static. The preference should be stored elsewhere to allow
  58. * XXX for multiple uses of one library? How does SSL handle this;
  59. * XXX it has something similar?
  60. *
  61. * - The "which" values are defined in ciferfam.h (the SMIME_* values,
  62. * for example SMIME_DES_CBC_56).
  63. * - If "on" is non-zero then the named cipher is enabled, otherwise
  64. * it is disabled. (It is not necessary to call the function for
  65. * ciphers that are disabled, however, as that is the default.)
  66. *
  67. * If the cipher preference is successfully recorded, SECSuccess
  68. * is returned. Otherwise SECFailure is returned. The only errors
  69. * are due to failure allocating memory or bad parameters/calls:
  70. * SEC_ERROR_XXX ("which" is not in the S/MIME cipher family)
  71. * SEC_ERROR_XXX (function is being called more times than there
  72. * are known/expected ciphers)
  73. */
  74. extern SECStatus SECMIME_EnableCipher(long which, int on);
  75. /*
  76. * Initialize the local recording of the S/MIME policy.
  77. * This function is called to enable/disable a particular cipher.
  78. * (S/MIME encryption or decryption using a particular cipher is only
  79. * allowed if that cipher is currently enabled.) At startup, all S/MIME
  80. * ciphers are disabled. From that point, this function can be called
  81. * to enable a cipher -- it is not necessary to call this to disable
  82. * a cipher unless that cipher was previously, explicitly enabled via
  83. * this function.
  84. *
  85. * XXX This is for a the current module, I think, so local, static storage
  86. * XXX is okay. Is that correct, or could multiple uses of the same
  87. * XXX library expect to operate under different policies?
  88. *
  89. * - The "which" values are defined in ciferfam.h (the SMIME_* values,
  90. * for example SMIME_DES_CBC_56).
  91. * - If "on" is non-zero then the named cipher is enabled, otherwise
  92. * it is disabled.
  93. *
  94. * If the cipher is successfully enabled/disabled, SECSuccess is
  95. * returned. Otherwise SECFailure is returned. The only errors
  96. * are due to bad parameters:
  97. * SEC_ERROR_XXX ("which" is not in the S/MIME cipher family)
  98. * SEC_ERROR_XXX ("which" exceeds expected maximum cipher; this is
  99. * really an internal error)
  100. */
  101. extern SECStatus SECMIME_SetPolicy(long which, int on);
  102. /*
  103. * Does the current policy allow S/MIME decryption of this particular
  104. * algorithm and keysize?
  105. */
  106. extern PRBool SECMIME_DecryptionAllowed(SECAlgorithmID *algid, PK11SymKey *key);
  107. /*
  108. * Does the current policy allow *any* S/MIME encryption (or decryption)?
  109. *
  110. * This tells whether or not *any* S/MIME encryption can be done,
  111. * according to policy. Callers may use this to do nicer user interface
  112. * (say, greying out a checkbox so a user does not even try to encrypt
  113. * a message when they are not allowed to) or for any reason they want
  114. * to check whether S/MIME encryption (or decryption, for that matter)
  115. * may be done.
  116. *
  117. * It takes no arguments. The return value is a simple boolean:
  118. * PR_TRUE means encryption (or decryption) is *possible*
  119. * (but may still fail due to other reasons, like because we cannot
  120. * find all the necessary certs, etc.; PR_TRUE is *not* a guarantee)
  121. * PR_FALSE means encryption (or decryption) is not permitted
  122. *
  123. * There are no errors from this routine.
  124. */
  125. extern PRBool SECMIME_EncryptionPossible(void);
  126. /*
  127. * Start an S/MIME encrypting context.
  128. *
  129. * "scert" is the cert for the sender. It will be checked for validity.
  130. * "rcerts" are the certs for the recipients. They will also be checked.
  131. *
  132. * "certdb" is the cert database to use for verifying the certs.
  133. * It can be NULL if a default database is available (like in the client).
  134. *
  135. * This function already does all of the stuff specific to S/MIME protocol
  136. * and local policy; the return value just needs to be passed to
  137. * SEC_PKCS7Encode() or to SEC_PKCS7EncoderStart() to create the encoded data,
  138. * and finally to SEC_PKCS7DestroyContentInfo().
  139. *
  140. * An error results in a return value of NULL and an error set.
  141. * (Retrieve specific errors via PORT_GetError()/XP_GetError().)
  142. */
  143. extern SEC_PKCS7ContentInfo *SECMIME_CreateEncrypted(CERTCertificate *scert,
  144. CERTCertificate **rcerts,
  145. CERTCertDBHandle *certdb,
  146. SECKEYGetPasswordKey pwfn,
  147. void *pwfn_arg);
  148. /*
  149. * Start an S/MIME signing context.
  150. *
  151. * "scert" is the cert that will be used to sign the data. It will be
  152. * checked for validity.
  153. *
  154. * "certdb" is the cert database to use for verifying the cert.
  155. * It can be NULL if a default database is available (like in the client).
  156. *
  157. * "digestalg" names the digest algorithm. (It should be SEC_OID_SHA1;
  158. * XXX There should be SECMIME functions for hashing, or the hashing should
  159. * be built into this interface, which we would like because we would
  160. * support more smartcards that way, and then this argument should go away.)
  161. *
  162. * "digest" is the actual digest of the data. It must be provided in
  163. * the case of detached data or NULL if the content will be included.
  164. *
  165. * This function already does all of the stuff specific to S/MIME protocol
  166. * and local policy; the return value just needs to be passed to
  167. * SEC_PKCS7Encode() or to SEC_PKCS7EncoderStart() to create the encoded data,
  168. * and finally to SEC_PKCS7DestroyContentInfo().
  169. *
  170. * An error results in a return value of NULL and an error set.
  171. * (Retrieve specific errors via PORT_GetError()/XP_GetError().)
  172. */
  173. extern SEC_PKCS7ContentInfo *SECMIME_CreateSigned(CERTCertificate *scert,
  174. CERTCertificate *ecert,
  175. CERTCertDBHandle *certdb,
  176. SECOidTag digestalg,
  177. SECItem *digest,
  178. SECKEYGetPasswordKey pwfn,
  179. void *pwfn_arg);
  180. /************************************************************************/
  181. SEC_END_PROTOS
  182. #endif /* _SECMIME_H_ */