Back to index

lightning-sunbird  0.9+nobinonly
secmime.h
Go to the documentation of this file.
00001 /* ***** BEGIN LICENSE BLOCK *****
00002  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00003  *
00004  * The contents of this file are subject to the Mozilla Public License Version
00005  * 1.1 (the "License"); you may not use this file except in compliance with
00006  * the License. You may obtain a copy of the License at
00007  * http://www.mozilla.org/MPL/
00008  *
00009  * Software distributed under the License is distributed on an "AS IS" basis,
00010  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00011  * for the specific language governing rights and limitations under the
00012  * License.
00013  *
00014  * The Original Code is the Netscape security libraries.
00015  *
00016  * The Initial Developer of the Original Code is
00017  * Netscape Communications Corporation.
00018  * Portions created by the Initial Developer are Copyright (C) 1994-2000
00019  * the Initial Developer. All Rights Reserved.
00020  *
00021  * Contributor(s):
00022  *
00023  * Alternatively, the contents of this file may be used under the terms of
00024  * either the GNU General Public License Version 2 or later (the "GPL"), or
00025  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00026  * in which case the provisions of the GPL or the LGPL are applicable instead
00027  * of those above. If you wish to allow use of your version of this file only
00028  * under the terms of either the GPL or the LGPL, and not to allow others to
00029  * use your version of this file under the terms of the MPL, indicate your
00030  * decision by deleting the provisions above and replace them with the notice
00031  * and other provisions required by the GPL or the LGPL. If you do not delete
00032  * the provisions above, a recipient may use your version of this file under
00033  * the terms of any one of the MPL, the GPL or the LGPL.
00034  *
00035  * ***** END LICENSE BLOCK ***** */
00036 
00037 /*
00038  * Header file for routines specific to S/MIME.  Keep things that are pure
00039  * pkcs7 out of here; this is for S/MIME policy, S/MIME interoperability, etc.
00040  *
00041  * $Id: secmime.h,v 1.2 2004/04/25 15:03:13 gerv%gerv.net Exp $
00042  */
00043 
00044 #ifndef _SECMIME_H_
00045 #define _SECMIME_H_ 1
00046 
00047 #include "secpkcs7.h"
00048 
00049 
00050 /************************************************************************/
00051 SEC_BEGIN_PROTOS
00052 
00053 /*
00054  * Initialize the local recording of the user S/MIME cipher preferences.
00055  * This function is called once for each cipher, the order being
00056  * important (first call records greatest preference, and so on).
00057  * When finished, it is called with a "which" of CIPHER_FAMILID_MASK.
00058  * If the function is called again after that, it is assumed that
00059  * the preferences are being reset, and the old preferences are
00060  * discarded.
00061  *
00062  * XXX This is for a particular user, and right now the storage is
00063  * XXX local, static.  The preference should be stored elsewhere to allow
00064  * XXX for multiple uses of one library?  How does SSL handle this;
00065  * XXX it has something similar?
00066  *
00067  *  - The "which" values are defined in ciferfam.h (the SMIME_* values,
00068  *    for example SMIME_DES_CBC_56).
00069  *  - If "on" is non-zero then the named cipher is enabled, otherwise
00070  *    it is disabled.  (It is not necessary to call the function for
00071  *    ciphers that are disabled, however, as that is the default.)
00072  *
00073  * If the cipher preference is successfully recorded, SECSuccess
00074  * is returned.  Otherwise SECFailure is returned.  The only errors
00075  * are due to failure allocating memory or bad parameters/calls:
00076  *     SEC_ERROR_XXX ("which" is not in the S/MIME cipher family)
00077  *     SEC_ERROR_XXX (function is being called more times than there
00078  *            are known/expected ciphers)
00079  */
00080 extern SECStatus SECMIME_EnableCipher(long which, int on);
00081 
00082 /*
00083  * Initialize the local recording of the S/MIME policy.
00084  * This function is called to enable/disable a particular cipher.
00085  * (S/MIME encryption or decryption using a particular cipher is only
00086  * allowed if that cipher is currently enabled.)  At startup, all S/MIME
00087  * ciphers are disabled.  From that point, this function can be called
00088  * to enable a cipher -- it is not necessary to call this to disable
00089  * a cipher unless that cipher was previously, explicitly enabled via
00090  * this function.
00091  *
00092  * XXX This is for a the current module, I think, so local, static storage
00093  * XXX is okay.  Is that correct, or could multiple uses of the same
00094  * XXX library expect to operate under different policies?
00095  *
00096  *  - The "which" values are defined in ciferfam.h (the SMIME_* values,
00097  *    for example SMIME_DES_CBC_56).
00098  *  - If "on" is non-zero then the named cipher is enabled, otherwise
00099  *    it is disabled.
00100  *
00101  * If the cipher is successfully enabled/disabled, SECSuccess is
00102  * returned.  Otherwise SECFailure is returned.  The only errors
00103  * are due to bad parameters:
00104  *     SEC_ERROR_XXX ("which" is not in the S/MIME cipher family)
00105  *     SEC_ERROR_XXX ("which" exceeds expected maximum cipher; this is
00106  *            really an internal error)
00107  */
00108 extern SECStatus SECMIME_SetPolicy(long which, int on);
00109 
00110 /*
00111  * Does the current policy allow S/MIME decryption of this particular
00112  * algorithm and keysize?
00113  */
00114 extern PRBool SECMIME_DecryptionAllowed(SECAlgorithmID *algid, PK11SymKey *key);
00115 
00116 /*
00117  * Does the current policy allow *any* S/MIME encryption (or decryption)?
00118  *
00119  * This tells whether or not *any* S/MIME encryption can be done,
00120  * according to policy.  Callers may use this to do nicer user interface
00121  * (say, greying out a checkbox so a user does not even try to encrypt
00122  * a message when they are not allowed to) or for any reason they want
00123  * to check whether S/MIME encryption (or decryption, for that matter)
00124  * may be done.
00125  *
00126  * It takes no arguments.  The return value is a simple boolean:
00127  *   PR_TRUE means encryption (or decryption) is *possible*
00128  *     (but may still fail due to other reasons, like because we cannot
00129  *     find all the necessary certs, etc.; PR_TRUE is *not* a guarantee)
00130  *   PR_FALSE means encryption (or decryption) is not permitted
00131  *
00132  * There are no errors from this routine.
00133  */
00134 extern PRBool SECMIME_EncryptionPossible(void);
00135 
00136 /*
00137  * Start an S/MIME encrypting context.
00138  *
00139  * "scert" is the cert for the sender.  It will be checked for validity.
00140  * "rcerts" are the certs for the recipients.  They will also be checked.
00141  *
00142  * "certdb" is the cert database to use for verifying the certs.
00143  * It can be NULL if a default database is available (like in the client).
00144  *
00145  * This function already does all of the stuff specific to S/MIME protocol
00146  * and local policy; the return value just needs to be passed to
00147  * SEC_PKCS7Encode() or to SEC_PKCS7EncoderStart() to create the encoded data,
00148  * and finally to SEC_PKCS7DestroyContentInfo().
00149  *
00150  * An error results in a return value of NULL and an error set.
00151  * (Retrieve specific errors via PORT_GetError()/XP_GetError().)
00152  */
00153 extern SEC_PKCS7ContentInfo *SECMIME_CreateEncrypted(CERTCertificate *scert,
00154                                                CERTCertificate **rcerts,
00155                                                CERTCertDBHandle *certdb,
00156                                                SECKEYGetPasswordKey pwfn,
00157                                                void *pwfn_arg);
00158 
00159 /*
00160  * Start an S/MIME signing context.
00161  *
00162  * "scert" is the cert that will be used to sign the data.  It will be
00163  * checked for validity.
00164  *
00165  * "certdb" is the cert database to use for verifying the cert.
00166  * It can be NULL if a default database is available (like in the client).
00167  * 
00168  * "digestalg" names the digest algorithm.  (It should be SEC_OID_SHA1;
00169  * XXX There should be SECMIME functions for hashing, or the hashing should
00170  * be built into this interface, which we would like because we would
00171  * support more smartcards that way, and then this argument should go away.)
00172  *
00173  * "digest" is the actual digest of the data.  It must be provided in
00174  * the case of detached data or NULL if the content will be included.
00175  *
00176  * This function already does all of the stuff specific to S/MIME protocol
00177  * and local policy; the return value just needs to be passed to
00178  * SEC_PKCS7Encode() or to SEC_PKCS7EncoderStart() to create the encoded data,
00179  * and finally to SEC_PKCS7DestroyContentInfo().
00180  *
00181  * An error results in a return value of NULL and an error set.
00182  * (Retrieve specific errors via PORT_GetError()/XP_GetError().)
00183  */
00184 extern SEC_PKCS7ContentInfo *SECMIME_CreateSigned(CERTCertificate *scert,
00185                                             CERTCertificate *ecert,
00186                                             CERTCertDBHandle *certdb,
00187                                             SECOidTag digestalg,
00188                                             SECItem *digest,
00189                                             SECKEYGetPasswordKey pwfn,
00190                                             void *pwfn_arg);
00191 
00192 /************************************************************************/
00193 SEC_END_PROTOS
00194 
00195 #endif /* _SECMIME_H_ */