security/nss/lib/pkcs7/secmime.h

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

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

mercurial