tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

secmime.h (7163B)


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