andre@0: /* This Source Code Form is subject to the terms of the Mozilla Public
andre@0:  * License, v. 2.0. If a copy of the MPL was not distributed with this
andre@0:  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
andre@0: 
andre@0: /*
andre@0:  * Header file for routines specific to S/MIME.  Keep things that are pure
andre@0:  * pkcs7 out of here; this is for S/MIME policy, S/MIME interoperability, etc.
andre@0:  */
andre@0: 
andre@0: #ifndef _SECMIME_H_
andre@0: #define _SECMIME_H_ 1
andre@0: 
andre@0: #include "secpkcs7.h"
andre@0: 
andre@0: 
andre@0: /************************************************************************/
andre@0: SEC_BEGIN_PROTOS
andre@0: 
andre@0: /*
andre@0:  * Initialize the local recording of the user S/MIME cipher preferences.
andre@0:  * This function is called once for each cipher, the order being
andre@0:  * important (first call records greatest preference, and so on).
andre@0:  * When finished, it is called with a "which" of CIPHER_FAMILID_MASK.
andre@0:  * If the function is called again after that, it is assumed that
andre@0:  * the preferences are being reset, and the old preferences are
andre@0:  * discarded.
andre@0:  *
andre@0:  * XXX This is for a particular user, and right now the storage is
andre@0:  * XXX local, static.  The preference should be stored elsewhere to allow
andre@0:  * XXX for multiple uses of one library?  How does SSL handle this;
andre@0:  * XXX it has something similar?
andre@0:  *
andre@0:  *  - The "which" values are defined in ciferfam.h (the SMIME_* values,
andre@0:  *    for example SMIME_DES_CBC_56).
andre@0:  *  - If "on" is non-zero then the named cipher is enabled, otherwise
andre@0:  *    it is disabled.  (It is not necessary to call the function for
andre@0:  *    ciphers that are disabled, however, as that is the default.)
andre@0:  *
andre@0:  * If the cipher preference is successfully recorded, SECSuccess
andre@0:  * is returned.  Otherwise SECFailure is returned.  The only errors
andre@0:  * are due to failure allocating memory or bad parameters/calls:
andre@0:  *	SEC_ERROR_XXX ("which" is not in the S/MIME cipher family)
andre@0:  *	SEC_ERROR_XXX (function is being called more times than there
andre@0:  *		are known/expected ciphers)
andre@0:  */
andre@0: extern SECStatus SECMIME_EnableCipher(long which, int on);
andre@0: 
andre@0: /*
andre@0:  * Initialize the local recording of the S/MIME policy.
andre@0:  * This function is called to enable/disable a particular cipher.
andre@0:  * (S/MIME encryption or decryption using a particular cipher is only
andre@0:  * allowed if that cipher is currently enabled.)  At startup, all S/MIME
andre@0:  * ciphers are disabled.  From that point, this function can be called
andre@0:  * to enable a cipher -- it is not necessary to call this to disable
andre@0:  * a cipher unless that cipher was previously, explicitly enabled via
andre@0:  * this function.
andre@0:  *
andre@0:  * XXX This is for a the current module, I think, so local, static storage
andre@0:  * XXX is okay.  Is that correct, or could multiple uses of the same
andre@0:  * XXX library expect to operate under different policies?
andre@0:  *
andre@0:  *  - The "which" values are defined in ciferfam.h (the SMIME_* values,
andre@0:  *    for example SMIME_DES_CBC_56).
andre@0:  *  - If "on" is non-zero then the named cipher is enabled, otherwise
andre@0:  *    it is disabled.
andre@0:  *
andre@0:  * If the cipher is successfully enabled/disabled, SECSuccess is
andre@0:  * returned.  Otherwise SECFailure is returned.  The only errors
andre@0:  * are due to bad parameters:
andre@0:  *	SEC_ERROR_XXX ("which" is not in the S/MIME cipher family)
andre@0:  *	SEC_ERROR_XXX ("which" exceeds expected maximum cipher; this is
andre@0:  *		really an internal error)
andre@0:  */
andre@0: extern SECStatus SECMIME_SetPolicy(long which, int on);
andre@0: 
andre@0: /*
andre@0:  * Does the current policy allow S/MIME decryption of this particular
andre@0:  * algorithm and keysize?
andre@0:  */
andre@0: extern PRBool SECMIME_DecryptionAllowed(SECAlgorithmID *algid, PK11SymKey *key);
andre@0: 
andre@0: /*
andre@0:  * Does the current policy allow *any* S/MIME encryption (or decryption)?
andre@0:  *
andre@0:  * This tells whether or not *any* S/MIME encryption can be done,
andre@0:  * according to policy.  Callers may use this to do nicer user interface
andre@0:  * (say, greying out a checkbox so a user does not even try to encrypt
andre@0:  * a message when they are not allowed to) or for any reason they want
andre@0:  * to check whether S/MIME encryption (or decryption, for that matter)
andre@0:  * may be done.
andre@0:  *
andre@0:  * It takes no arguments.  The return value is a simple boolean:
andre@0:  *   PR_TRUE means encryption (or decryption) is *possible*
andre@0:  *	(but may still fail due to other reasons, like because we cannot
andre@0:  *	find all the necessary certs, etc.; PR_TRUE is *not* a guarantee)
andre@0:  *   PR_FALSE means encryption (or decryption) is not permitted
andre@0:  *
andre@0:  * There are no errors from this routine.
andre@0:  */
andre@0: extern PRBool SECMIME_EncryptionPossible(void);
andre@0: 
andre@0: /*
andre@0:  * Start an S/MIME encrypting context.
andre@0:  *
andre@0:  * "scert" is the cert for the sender.  It will be checked for validity.
andre@0:  * "rcerts" are the certs for the recipients.  They will also be checked.
andre@0:  *
andre@0:  * "certdb" is the cert database to use for verifying the certs.
andre@0:  * It can be NULL if a default database is available (like in the client).
andre@0:  *
andre@0:  * This function already does all of the stuff specific to S/MIME protocol
andre@0:  * and local policy; the return value just needs to be passed to
andre@0:  * SEC_PKCS7Encode() or to SEC_PKCS7EncoderStart() to create the encoded data,
andre@0:  * and finally to SEC_PKCS7DestroyContentInfo().
andre@0:  *
andre@0:  * An error results in a return value of NULL and an error set.
andre@0:  * (Retrieve specific errors via PORT_GetError()/XP_GetError().)
andre@0:  */
andre@0: extern SEC_PKCS7ContentInfo *SECMIME_CreateEncrypted(CERTCertificate *scert,
andre@0: 						     CERTCertificate **rcerts,
andre@0: 						     CERTCertDBHandle *certdb,
andre@0: 						     SECKEYGetPasswordKey pwfn,
andre@0: 						     void *pwfn_arg);
andre@0: 
andre@0: /*
andre@0:  * Start an S/MIME signing context.
andre@0:  *
andre@0:  * "scert" is the cert that will be used to sign the data.  It will be
andre@0:  * checked for validity.
andre@0:  *
andre@0:  * "certdb" is the cert database to use for verifying the cert.
andre@0:  * It can be NULL if a default database is available (like in the client).
andre@0:  * 
andre@0:  * "digestalg" names the digest algorithm.  (It should be SEC_OID_SHA1;
andre@0:  * XXX There should be SECMIME functions for hashing, or the hashing should
andre@0:  * be built into this interface, which we would like because we would
andre@0:  * support more smartcards that way, and then this argument should go away.)
andre@0:  *
andre@0:  * "digest" is the actual digest of the data.  It must be provided in
andre@0:  * the case of detached data or NULL if the content will be included.
andre@0:  *
andre@0:  * This function already does all of the stuff specific to S/MIME protocol
andre@0:  * and local policy; the return value just needs to be passed to
andre@0:  * SEC_PKCS7Encode() or to SEC_PKCS7EncoderStart() to create the encoded data,
andre@0:  * and finally to SEC_PKCS7DestroyContentInfo().
andre@0:  *
andre@0:  * An error results in a return value of NULL and an error set.
andre@0:  * (Retrieve specific errors via PORT_GetError()/XP_GetError().)
andre@0:  */
andre@0: extern SEC_PKCS7ContentInfo *SECMIME_CreateSigned(CERTCertificate *scert,
andre@0: 						  CERTCertificate *ecert,
andre@0: 						  CERTCertDBHandle *certdb,
andre@0: 						  SECOidTag digestalg,
andre@0: 						  SECItem *digest,
andre@0: 						  SECKEYGetPasswordKey pwfn,
andre@0: 						  void *pwfn_arg);
andre@0: 
andre@0: /************************************************************************/
andre@0: SEC_END_PROTOS
andre@0: 
andre@0: #endif /* _SECMIME_H_ */