security/nss/lib/pkcs7/secmime.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/security/nss/lib/pkcs7/secmime.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,161 @@
     1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.7 +
     1.8 +/*
     1.9 + * Header file for routines specific to S/MIME.  Keep things that are pure
    1.10 + * pkcs7 out of here; this is for S/MIME policy, S/MIME interoperability, etc.
    1.11 + */
    1.12 +
    1.13 +#ifndef _SECMIME_H_
    1.14 +#define _SECMIME_H_ 1
    1.15 +
    1.16 +#include "secpkcs7.h"
    1.17 +
    1.18 +
    1.19 +/************************************************************************/
    1.20 +SEC_BEGIN_PROTOS
    1.21 +
    1.22 +/*
    1.23 + * Initialize the local recording of the user S/MIME cipher preferences.
    1.24 + * This function is called once for each cipher, the order being
    1.25 + * important (first call records greatest preference, and so on).
    1.26 + * When finished, it is called with a "which" of CIPHER_FAMILID_MASK.
    1.27 + * If the function is called again after that, it is assumed that
    1.28 + * the preferences are being reset, and the old preferences are
    1.29 + * discarded.
    1.30 + *
    1.31 + * XXX This is for a particular user, and right now the storage is
    1.32 + * XXX local, static.  The preference should be stored elsewhere to allow
    1.33 + * XXX for multiple uses of one library?  How does SSL handle this;
    1.34 + * XXX it has something similar?
    1.35 + *
    1.36 + *  - The "which" values are defined in ciferfam.h (the SMIME_* values,
    1.37 + *    for example SMIME_DES_CBC_56).
    1.38 + *  - If "on" is non-zero then the named cipher is enabled, otherwise
    1.39 + *    it is disabled.  (It is not necessary to call the function for
    1.40 + *    ciphers that are disabled, however, as that is the default.)
    1.41 + *
    1.42 + * If the cipher preference is successfully recorded, SECSuccess
    1.43 + * is returned.  Otherwise SECFailure is returned.  The only errors
    1.44 + * are due to failure allocating memory or bad parameters/calls:
    1.45 + *	SEC_ERROR_XXX ("which" is not in the S/MIME cipher family)
    1.46 + *	SEC_ERROR_XXX (function is being called more times than there
    1.47 + *		are known/expected ciphers)
    1.48 + */
    1.49 +extern SECStatus SECMIME_EnableCipher(long which, int on);
    1.50 +
    1.51 +/*
    1.52 + * Initialize the local recording of the S/MIME policy.
    1.53 + * This function is called to enable/disable a particular cipher.
    1.54 + * (S/MIME encryption or decryption using a particular cipher is only
    1.55 + * allowed if that cipher is currently enabled.)  At startup, all S/MIME
    1.56 + * ciphers are disabled.  From that point, this function can be called
    1.57 + * to enable a cipher -- it is not necessary to call this to disable
    1.58 + * a cipher unless that cipher was previously, explicitly enabled via
    1.59 + * this function.
    1.60 + *
    1.61 + * XXX This is for a the current module, I think, so local, static storage
    1.62 + * XXX is okay.  Is that correct, or could multiple uses of the same
    1.63 + * XXX library expect to operate under different policies?
    1.64 + *
    1.65 + *  - The "which" values are defined in ciferfam.h (the SMIME_* values,
    1.66 + *    for example SMIME_DES_CBC_56).
    1.67 + *  - If "on" is non-zero then the named cipher is enabled, otherwise
    1.68 + *    it is disabled.
    1.69 + *
    1.70 + * If the cipher is successfully enabled/disabled, SECSuccess is
    1.71 + * returned.  Otherwise SECFailure is returned.  The only errors
    1.72 + * are due to bad parameters:
    1.73 + *	SEC_ERROR_XXX ("which" is not in the S/MIME cipher family)
    1.74 + *	SEC_ERROR_XXX ("which" exceeds expected maximum cipher; this is
    1.75 + *		really an internal error)
    1.76 + */
    1.77 +extern SECStatus SECMIME_SetPolicy(long which, int on);
    1.78 +
    1.79 +/*
    1.80 + * Does the current policy allow S/MIME decryption of this particular
    1.81 + * algorithm and keysize?
    1.82 + */
    1.83 +extern PRBool SECMIME_DecryptionAllowed(SECAlgorithmID *algid, PK11SymKey *key);
    1.84 +
    1.85 +/*
    1.86 + * Does the current policy allow *any* S/MIME encryption (or decryption)?
    1.87 + *
    1.88 + * This tells whether or not *any* S/MIME encryption can be done,
    1.89 + * according to policy.  Callers may use this to do nicer user interface
    1.90 + * (say, greying out a checkbox so a user does not even try to encrypt
    1.91 + * a message when they are not allowed to) or for any reason they want
    1.92 + * to check whether S/MIME encryption (or decryption, for that matter)
    1.93 + * may be done.
    1.94 + *
    1.95 + * It takes no arguments.  The return value is a simple boolean:
    1.96 + *   PR_TRUE means encryption (or decryption) is *possible*
    1.97 + *	(but may still fail due to other reasons, like because we cannot
    1.98 + *	find all the necessary certs, etc.; PR_TRUE is *not* a guarantee)
    1.99 + *   PR_FALSE means encryption (or decryption) is not permitted
   1.100 + *
   1.101 + * There are no errors from this routine.
   1.102 + */
   1.103 +extern PRBool SECMIME_EncryptionPossible(void);
   1.104 +
   1.105 +/*
   1.106 + * Start an S/MIME encrypting context.
   1.107 + *
   1.108 + * "scert" is the cert for the sender.  It will be checked for validity.
   1.109 + * "rcerts" are the certs for the recipients.  They will also be checked.
   1.110 + *
   1.111 + * "certdb" is the cert database to use for verifying the certs.
   1.112 + * It can be NULL if a default database is available (like in the client).
   1.113 + *
   1.114 + * This function already does all of the stuff specific to S/MIME protocol
   1.115 + * and local policy; the return value just needs to be passed to
   1.116 + * SEC_PKCS7Encode() or to SEC_PKCS7EncoderStart() to create the encoded data,
   1.117 + * and finally to SEC_PKCS7DestroyContentInfo().
   1.118 + *
   1.119 + * An error results in a return value of NULL and an error set.
   1.120 + * (Retrieve specific errors via PORT_GetError()/XP_GetError().)
   1.121 + */
   1.122 +extern SEC_PKCS7ContentInfo *SECMIME_CreateEncrypted(CERTCertificate *scert,
   1.123 +						     CERTCertificate **rcerts,
   1.124 +						     CERTCertDBHandle *certdb,
   1.125 +						     SECKEYGetPasswordKey pwfn,
   1.126 +						     void *pwfn_arg);
   1.127 +
   1.128 +/*
   1.129 + * Start an S/MIME signing context.
   1.130 + *
   1.131 + * "scert" is the cert that will be used to sign the data.  It will be
   1.132 + * checked for validity.
   1.133 + *
   1.134 + * "certdb" is the cert database to use for verifying the cert.
   1.135 + * It can be NULL if a default database is available (like in the client).
   1.136 + * 
   1.137 + * "digestalg" names the digest algorithm.  (It should be SEC_OID_SHA1;
   1.138 + * XXX There should be SECMIME functions for hashing, or the hashing should
   1.139 + * be built into this interface, which we would like because we would
   1.140 + * support more smartcards that way, and then this argument should go away.)
   1.141 + *
   1.142 + * "digest" is the actual digest of the data.  It must be provided in
   1.143 + * the case of detached data or NULL if the content will be included.
   1.144 + *
   1.145 + * This function already does all of the stuff specific to S/MIME protocol
   1.146 + * and local policy; the return value just needs to be passed to
   1.147 + * SEC_PKCS7Encode() or to SEC_PKCS7EncoderStart() to create the encoded data,
   1.148 + * and finally to SEC_PKCS7DestroyContentInfo().
   1.149 + *
   1.150 + * An error results in a return value of NULL and an error set.
   1.151 + * (Retrieve specific errors via PORT_GetError()/XP_GetError().)
   1.152 + */
   1.153 +extern SEC_PKCS7ContentInfo *SECMIME_CreateSigned(CERTCertificate *scert,
   1.154 +						  CERTCertificate *ecert,
   1.155 +						  CERTCertDBHandle *certdb,
   1.156 +						  SECOidTag digestalg,
   1.157 +						  SECItem *digest,
   1.158 +						  SECKEYGetPasswordKey pwfn,
   1.159 +						  void *pwfn_arg);
   1.160 +
   1.161 +/************************************************************************/
   1.162 +SEC_END_PROTOS
   1.163 +
   1.164 +#endif /* _SECMIME_H_ */

mercurial