SMIME helper routines. More...
#include "config.h"
#include <limits.h>
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include "private.h"
#include "mutt/lib.h"
#include "address/lib.h"
#include "config/lib.h"
#include "email/lib.h"
#include "core/lib.h"
#include "alias/lib.h"
#include "gui/lib.h"
#include "mutt.h"
#include "lib.h"
#include "editor/lib.h"
#include "expando/lib.h"
#include "history/lib.h"
#include "question/lib.h"
#include "send/lib.h"
#include "copy.h"
#include "crypt.h"
#include "cryptglue.h"
#include "globals.h"
#include "handler.h"
#include "mutt_logging.h"
#include "muttlib.h"
#include "smime.h"
Go to the source code of this file.
Functions | |
void | smime_init (void) |
Initialise smime globals. | |
void | smime_cleanup (void) |
Clean up smime globals. | |
static void | smime_key_free (struct SmimeKey **keylist) |
Free a list of SMIME keys. | |
static struct SmimeKey * | smime_copy_key (struct SmimeKey *key) |
Copy an SMIME key. | |
void | smime_class_void_passphrase (void) |
Forget the cached passphrase - Implements CryptModuleSpecs::void_passphrase() -. | |
bool | smime_class_valid_passphrase (void) |
Ensure we have a valid passphrase - Implements CryptModuleSpecs::valid_passphrase() -. | |
void | smime_command_a (const struct ExpandoNode *node, void *data, MuttFormatFlags flags, struct Buffer *buf) |
Smime Command: algorithm - Implements ExpandoRenderData::get_string() -. | |
void | smime_command_c (const struct ExpandoNode *node, void *data, MuttFormatFlags flags, struct Buffer *buf) |
Smime Command: certificate IDs - Implements ExpandoRenderData::get_string() -. | |
void | smime_command_C (const struct ExpandoNode *node, void *data, MuttFormatFlags flags, struct Buffer *buf) |
Smime Command: CA location - Implements ExpandoRenderData::get_string() -. | |
void | smime_command_d (const struct ExpandoNode *node, void *data, MuttFormatFlags flags, struct Buffer *buf) |
Smime Command: Message digest algorithm - Implements ExpandoRenderData::get_string() -. | |
void | smime_command_f (const struct ExpandoNode *node, void *data, MuttFormatFlags flags, struct Buffer *buf) |
Smime Command: Filename of message - Implements ExpandoRenderData::get_string() -. | |
void | smime_command_i (const struct ExpandoNode *node, void *data, MuttFormatFlags flags, struct Buffer *buf) |
Smime Command: Intermediate certificates - Implements ExpandoRenderData::get_string() -. | |
void | smime_command_k (const struct ExpandoNode *node, void *data, MuttFormatFlags flags, struct Buffer *buf) |
Smime Command: Key-pair - Implements ExpandoRenderData::get_string() -. | |
void | smime_command_s (const struct ExpandoNode *node, void *data, MuttFormatFlags flags, struct Buffer *buf) |
Smime Command: Filename of signature - Implements ExpandoRenderData::get_string() -. | |
static void | smime_command (struct Buffer *buf, struct SmimeCommandContext *cctx, const struct Expando *exp) |
Format an SMIME command string. | |
static pid_t | smime_invoke (FILE **fp_smime_in, FILE **fp_smime_out, FILE **fp_smime_err, int fp_smime_infd, int fp_smime_outfd, int fp_smime_errfd, const char *fname, const char *sig_fname, const char *cryptalg, const char *digestalg, const char *key, const char *certificates, const char *intermediates, const struct Expando *exp) |
Run an SMIME command. | |
static struct SmimeKey * | smime_parse_key (char *buf) |
Parse an SMIME key block. | |
static struct SmimeKey * | smime_get_candidates (const char *search, bool only_public_key) |
Find keys matching a string. | |
static struct SmimeKey * | smime_get_key_by_hash (const char *hash, bool only_public_key) |
Find a key by its hash. | |
static struct SmimeKey * | smime_get_key_by_addr (const char *mailbox, KeyFlags abilities, bool only_public_key, bool oppenc_mode) |
Find an SIME key by address. | |
static struct SmimeKey * | smime_get_key_by_str (const char *str, KeyFlags abilities, bool only_public_key) |
Find an SMIME key by string. | |
static struct SmimeKey * | smime_ask_for_key (char *prompt, KeyFlags abilities, bool only_public_key) |
Ask the user to select a key. | |
static void | getkeys (const char *mailbox) |
Get the keys for a mailbox. | |
void | smime_class_getkeys (struct Envelope *env) |
Get the S/MIME keys required to encrypt this email - Implements CryptModuleSpecs::smime_getkeys() -. | |
char * | smime_class_find_keys (const struct AddressList *al, bool oppenc_mode) |
Find the keyids of the recipients of a message - Implements CryptModuleSpecs::find_keys() -. | |
static int | smime_handle_cert_email (const char *certificate, const char *mailbox, bool copy, char ***buffer, int *num) |
Process an email containing certificates. | |
static char * | smime_extract_certificate (const char *infile) |
Extract an SMIME certificate from a file. | |
static char * | smime_extract_signer_certificate (const char *infile) |
Extract the signer's certificate. | |
void | smime_class_invoke_import (const char *infile, const char *mailbox) |
Add a certificate and update index file (externally) - Implements CryptModuleSpecs::smime_invoke_import() -. | |
int | smime_class_verify_sender (struct Email *e, struct Message *msg) |
Does the sender match the certificate? - Implements CryptModuleSpecs::smime_verify_sender() -. | |
static pid_t | smime_invoke_encrypt (FILE **fp_smime_in, FILE **fp_smime_out, FILE **fp_smime_err, int fp_smime_infd, int fp_smime_outfd, int fp_smime_errfd, const char *fname, const char *uids) |
Use SMIME to encrypt a file. | |
static pid_t | smime_invoke_sign (FILE **fp_smime_in, FILE **fp_smime_out, FILE **fp_smime_err, int fp_smime_infd, int fp_smime_outfd, int fp_smime_errfd, const char *fname) |
Use SMIME to sign a file. | |
struct Body * | smime_class_build_smime_entity (struct Body *b, char *certlist) |
Encrypt the email body to all recipients - Implements CryptModuleSpecs::smime_build_smime_entity() -. | |
static char * | openssl_md_to_smime_micalg (const char *md) |
Change the algorithm names. | |
struct Body * | smime_class_sign_message (struct Body *b, const struct AddressList *from) |
Cryptographically sign the Body of a message - Implements CryptModuleSpecs::sign_message() -. | |
static pid_t | smime_invoke_verify (FILE **fp_smime_in, FILE **fp_smime_out, FILE **fp_smime_err, int fp_smime_infd, int fp_smime_outfd, int fp_smime_errfd, const char *fname, const char *sig_fname, int opaque) |
Use SMIME to verify a file. | |
static pid_t | smime_invoke_decrypt (FILE **fp_smime_in, FILE **fp_smime_out, FILE **fp_smime_err, int fp_smime_infd, int fp_smime_outfd, int fp_smime_errfd, const char *fname) |
Use SMIME to decrypt a file. | |
int | smime_class_verify_one (struct Body *b, struct State *state, const char *tempfile) |
Check a signed MIME part against a signature - Implements CryptModuleSpecs::verify_one() -. | |
static struct Body * | smime_handle_entity (struct Body *b, struct State *state, FILE *fp_out_file) |
Handle type application/pkcs7-mime. | |
int | smime_class_decrypt_mime (FILE *fp_in, FILE **fp_out, struct Body *b, struct Body **b_dec) |
Decrypt an encrypted MIME part - Implements CryptModuleSpecs::decrypt_mime() -. | |
int | smime_class_application_handler (struct Body *b, struct State *state) |
Manage the MIME type "application/pgp" or "application/smime" - Implements CryptModuleSpecs::application_handler() -. | |
SecurityFlags | smime_class_send_menu (struct Email *e) |
Ask the user whether to sign and/or encrypt the email - Implements CryptModuleSpecs::send_menu() -. | |
Variables | |
const struct ExpandoRenderData | SmimeCommandRenderData [] |
Callbacks for Smime Command Expandos. | |
static char | SmimePass [256] |
Cached Smime Passphrase. | |
static time_t | SmimeExpTime = 0 |
Unix time when SmimePass expires. | |
static struct Buffer | SmimeKeyToUse = { 0 } |
Smime key to use. | |
static struct Buffer | SmimeCertToUse = { 0 } |
Smime certificate to use. | |
static struct Buffer | SmimeIntermediateToUse = { 0 } |
Smime intermediate certificate to use. | |
SMIME helper routines.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.
Definition in file smime.c.
void smime_init | ( | void | ) |
Initialise smime globals.
Definition at line 85 of file smime.c.
void smime_cleanup | ( | void | ) |
Clean up smime globals.
Definition at line 95 of file smime.c.
|
static |
Free a list of SMIME keys.
[out] | keylist | List of keys to free |
Definition at line 106 of file smime.c.
Copy an SMIME key.
key | Key to copy |
ptr | Newly allocated SMIME key |
Definition at line 131 of file smime.c.
|
static |
Format an SMIME command string.
Definition at line 339 of file smime.c.
|
static |
Run an SMIME command.
[out] | fp_smime_in | stdin for the command, or NULL (OPTIONAL) |
[out] | fp_smime_out | stdout for the command, or NULL (OPTIONAL) |
[out] | fp_smime_err | stderr for the command, or NULL (OPTIONAL) |
[in] | fp_smime_infd | stdin for the command, or -1 (OPTIONAL) |
[in] | fp_smime_outfd | stdout for the command, or -1 (OPTIONAL) |
[in] | fp_smime_errfd | stderr for the command, or -1 (OPTIONAL) |
[in] | fname | Filename to pass to the command |
[in] | sig_fname | Signature filename to pass to the command |
[in] | cryptalg | Encryption algorithm |
[in] | digestalg | Hashing algorithm |
[in] | key | SMIME key |
[in] | certificates | Public certificates |
[in] | intermediates | Intermediate certificates |
[in] | exp | Expando format string |
num | PID of the created process |
-1 | Error creating pipes or forking |
fp_smime_in
has priority over fp_smime_infd
. Likewise fp_smime_out
and fp_smime_err
. Definition at line 368 of file smime.c.
|
static |
Parse an SMIME key block.
buf | String to parse |
ptr | SMIME key |
NULL | Error |
Definition at line 402 of file smime.c.
|
static |
Find keys matching a string.
search | String to match |
only_public_key | If true, only get the public keys |
ptr | Matching key |
Definition at line 485 of file smime.c.
|
static |
Find a key by its hash.
hash | Hash to find |
only_public_key | If true, only get the public keys |
ptr | Matching key |
Returns the first matching key record, without prompting or checking of abilities or trust.
Definition at line 533 of file smime.c.
|
static |
Find an SIME key by address.
mailbox | Email address to match |
abilities | Abilities to match, see KeyFlags |
only_public_key | If true, only get the public keys |
oppenc_mode | If true, use opportunistic encryption |
ptr | Matching key |
Definition at line 559 of file smime.c.
|
static |
Find an SMIME key by string.
str | String to match |
abilities | Abilities to match, see KeyFlags |
only_public_key | If true, only get the public keys |
ptr | Matching key |
Definition at line 640 of file smime.c.
|
static |
Ask the user to select a key.
prompt | Prompt to show the user |
abilities | Abilities to match, see KeyFlags |
only_public_key | If true, only get the public keys |
ptr | Selected SMIME key |
Definition at line 686 of file smime.c.
|
static |
Get the keys for a mailbox.
mailbox | Email address |
This sets the '*ToUse' variables for an upcoming decryption, where the required key is different from $smime_default_key
.
Definition at line 723 of file smime.c.
|
static |
Process an email containing certificates.
[in] | certificate | Email with certificates |
[in] | mailbox | Email address |
[in] | copy | If true, save the certificates to buffer |
[out] | buffer | Buffer allocated to hold certificates |
[out] | num | Number of certificates in buffer |
0 | Success |
-1 | Error |
-2 | Error |
Definition at line 845 of file smime.c.
|
static |
Extract an SMIME certificate from a file.
infile | File to read |
ptr | Filename of temporary file containing certificate |
Definition at line 947 of file smime.c.
|
static |
Extract the signer's certificate.
infile | File to read |
ptr | Name of temporary file containing certificate |
Definition at line 1062 of file smime.c.
|
static |
Use SMIME to encrypt a file.
[out] | fp_smime_in | stdin for the command, or NULL (OPTIONAL) |
[out] | fp_smime_out | stdout for the command, or NULL (OPTIONAL) |
[out] | fp_smime_err | stderr for the command, or NULL (OPTIONAL) |
[in] | fp_smime_infd | stdin for the command, or -1 (OPTIONAL) |
[in] | fp_smime_outfd | stdout for the command, or -1 (OPTIONAL) |
[in] | fp_smime_errfd | stderr for the command, or -1 (OPTIONAL) |
[in] | fname | Filename to pass to the command |
[in] | uids | List of IDs/fingerprints, space separated |
num | PID of the created process |
-1 | Error creating pipes or forking |
fp_smime_in
has priority over fp_smime_infd
. Likewise fp_smime_out
and fp_smime_err
. Definition at line 1290 of file smime.c.
|
static |
Use SMIME to sign a file.
[out] | fp_smime_in | stdin for the command, or NULL (OPTIONAL) |
[out] | fp_smime_out | stdout for the command, or NULL (OPTIONAL) |
[out] | fp_smime_err | stderr for the command, or NULL (OPTIONAL) |
[in] | fp_smime_infd | stdin for the command, or -1 (OPTIONAL) |
[in] | fp_smime_outfd | stdout for the command, or -1 (OPTIONAL) |
[in] | fp_smime_errfd | stderr for the command, or -1 (OPTIONAL) |
[in] | fname | Filename to pass to the command |
num | PID of the created process |
-1 | Error creating pipes or forking |
fp_smime_in
has priority over fp_smime_infd
. Likewise fp_smime_out
and fp_smime_err
. Definition at line 1317 of file smime.c.
|
static |
Change the algorithm names.
md | OpenSSL message digest name |
ptr | SMIME Message Integrity Check algorithm |
The openssl -md doesn't want hyphens: md5, sha1, sha224, sha256, sha384, sha512 However, the micalg does: md5, sha-1, sha-224, sha-256, sha-384, sha-512
Definition at line 1476 of file smime.c.
|
static |
Use SMIME to verify a file.
[out] | fp_smime_in | stdin for the command, or NULL (OPTIONAL) |
[out] | fp_smime_out | stdout for the command, or NULL (OPTIONAL) |
[out] | fp_smime_err | stderr for the command, or NULL (OPTIONAL) |
[in] | fp_smime_infd | stdin for the command, or -1 (OPTIONAL) |
[in] | fp_smime_outfd | stdout for the command, or -1 (OPTIONAL) |
[in] | fp_smime_errfd | stderr for the command, or -1 (OPTIONAL) |
[in] | fname | Filename to pass to the command |
[in] | sig_fname | Signature filename to pass to the command |
[in] | opaque | If true, use $smime_verify_opaque_command else $smime_verify_command |
num | PID of the created process |
-1 | Error creating pipes or forking |
fp_smime_in
has priority over fp_smime_infd
. Likewise fp_smime_out
and fp_smime_err
. Definition at line 1664 of file smime.c.
|
static |
Use SMIME to decrypt a file.
[out] | fp_smime_in | stdin for the command, or NULL (OPTIONAL) |
[out] | fp_smime_out | stdout for the command, or NULL (OPTIONAL) |
[out] | fp_smime_err | stderr for the command, or NULL (OPTIONAL) |
[in] | fp_smime_infd | stdin for the command, or -1 (OPTIONAL) |
[in] | fp_smime_outfd | stdout for the command, or -1 (OPTIONAL) |
[in] | fp_smime_errfd | stderr for the command, or -1 (OPTIONAL) |
[in] | fname | Filename to pass to the command |
num | PID of the created process |
-1 | Error creating pipes or forking |
fp_smime_in
has priority over fp_smime_infd
. Likewise fp_smime_out
and fp_smime_err
. Definition at line 1692 of file smime.c.
|
static |
Handle type application/pkcs7-mime.
ptr | Body for parsed MIME part |
This can either be a signed or an encrypted message.
Definition at line 1820 of file smime.c.
const struct ExpandoRenderData SmimeCommandRenderData |
Callbacks for Smime Command Expandos.
|
static |
|
static |