#include "config.h"
#include <stdbool.h>
#include <stdio.h>
#include "lib.h"
Go to the source code of this file.
|
void | smime_init (void) |
| Initialise smime globals. More...
|
|
void | smime_cleanup (void) |
| Clean up smime globals. More...
|
|
int | smime_class_application_handler (struct Body *m, struct State *s) |
| Implements CryptModuleSpecs::application_handler() More...
|
|
struct Body * | smime_class_build_smime_entity (struct Body *a, char *certlist) |
| Implements CryptModuleSpecs::smime_build_smime_entity() More...
|
|
int | smime_class_decrypt_mime (FILE *fp_in, FILE **fp_out, struct Body *b, struct Body **cur) |
| Implements CryptModuleSpecs::decrypt_mime() More...
|
|
char * | smime_class_find_keys (struct AddressList *addrlist, bool oppenc_mode) |
| Implements CryptModuleSpecs::find_keys() More...
|
|
void | smime_class_getkeys (struct Envelope *env) |
| Implements CryptModuleSpecs::smime_getkeys() More...
|
|
void | smime_class_invoke_import (const char *infile, const char *mailbox) |
| Implements CryptModuleSpecs::smime_invoke_import() More...
|
|
SecurityFlags | smime_class_send_menu (struct Email *e) |
| Implements CryptModuleSpecs::send_menu() More...
|
|
struct Body * | smime_class_sign_message (struct Body *a, const struct AddressList *from) |
| Implements CryptModuleSpecs::sign_message() More...
|
|
bool | smime_class_valid_passphrase (void) |
| Implements CryptModuleSpecs::valid_passphrase() More...
|
|
int | smime_class_verify_one (struct Body *sigbdy, struct State *s, const char *tempfile) |
| Implements CryptModuleSpecs::verify_one() More...
|
|
int | smime_class_verify_sender (struct Mailbox *m, struct Email *e) |
| Implements CryptModuleSpecs::smime_verify_sender() More...
|
|
void | smime_class_void_passphrase (void) |
| Implements CryptModuleSpecs::void_passphrase() More...
|
|
SMIME helper routines
- Authors
- Oliver Ehli
- g10 Code GmbH
- Pietro Cerutti
- Copyright
- This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 2 of the License, or (at your option) any later version.
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.h.
◆ smime_init()
Initialise smime globals.
Definition at line 87 of file smime.c.
◆ smime_cleanup()
void smime_cleanup |
( |
void |
| ) |
|
Clean up smime globals.
Definition at line 97 of file smime.c.
◆ smime_class_application_handler()
int smime_class_application_handler |
( |
struct Body * |
m, |
|
|
struct State * |
s |
|
) |
| |
◆ smime_class_build_smime_entity()
struct Body* smime_class_build_smime_entity |
( |
struct Body * |
a, |
|
|
char * |
certlist |
|
) |
| |
Implements CryptModuleSpecs::smime_build_smime_entity()
Definition at line 1317 of file smime.c.
1319 char buf[1024], certfile[
PATH_MAX];
1320 char *cert_end = NULL;
1321 FILE *fp_smime_in = NULL, *fp_smime_err = NULL, *fp_out = NULL, *fp_tmp = NULL;
1322 struct Body *t = NULL;
1323 int err = 0, empty, off;
1353 for (
char *cert_start = certlist; cert_start; cert_start = cert_end)
1355 cert_end = strchr(cert_start,
' ');
1361 snprintf(certfile + off,
sizeof(certfile) - off,
"%s%s/%s",
1370 fputc(
'\n', fp_tmp);
1375 fileno(fp_smime_err),
1390 empty = (fgetc(fp_out) == EOF);
1393 fflush(fp_smime_err);
1394 rewind(fp_smime_err);
1395 while (fgets(buf,
sizeof(buf) - 1, fp_smime_err))
◆ smime_class_decrypt_mime()
int smime_class_decrypt_mime |
( |
FILE * |
fp_in, |
|
|
FILE ** |
fp_out, |
|
|
struct Body * |
b, |
|
|
struct Body ** |
cur |
|
) |
| |
◆ smime_class_find_keys()
char* smime_class_find_keys |
( |
struct AddressList * |
addrlist, |
|
|
bool |
oppenc_mode |
|
) |
| |
Implements CryptModuleSpecs::find_keys()
Definition at line 803 of file smime.c.
806 char *keyid = NULL, *keylist = NULL;
807 size_t keylist_size = 0;
808 size_t keylist_used = 0;
814 if (!key && !oppenc_mode)
817 snprintf(buf,
sizeof(buf),
_(
"Enter keyID for %s: "), a->
mailbox);
831 sprintf(keylist + keylist_used,
"%s%s", keylist_used ?
" " :
"", keyid);
◆ smime_class_getkeys()
void smime_class_getkeys |
( |
struct Envelope * |
env | ) |
|
◆ smime_class_invoke_import()
void smime_class_invoke_import |
( |
const char * |
infile, |
|
|
const char * |
mailbox |
|
) |
| |
Implements CryptModuleSpecs::smime_invoke_import()
Definition at line 1124 of file smime.c.
1126 char *certfile = NULL;
1128 FILE *fp_smime_in = NULL;
1164 pid_t pid =
smime_invoke(&fp_smime_in, NULL, NULL, -1, fileno(fp_out),
1165 fileno(fp_err), certfile, NULL, NULL, NULL, NULL,
1169 mutt_message(
_(
"Error: unable to create OpenSSL subprocess"));
1172 fputs(buf, fp_smime_in);
1173 fputc(
'\n', fp_smime_in);
◆ smime_class_send_menu()
Implements CryptModuleSpecs::send_menu()
Definition at line 2108 of file smime.c.
2111 const char *prompt = NULL;
2112 const char *letters = NULL;
2113 const char *choices = NULL;
2127 prompt =
_(
"S/MIME (s)ign, encrypt (w)ith, sign (a)s, (c)lear, or (o)ppenc "
2130 letters =
_(
"swaco");
2138 prompt =
_(
"S/MIME (e)ncrypt, (s)ign, encrypt (w)ith, sign (a)s, (b)oth, "
2139 "(c)lear, or (o)ppenc mode?");
2141 letters =
_(
"eswabco");
2142 choices =
"eswabcO";
2148 prompt =
_(
"S/MIME (e)ncrypt, (s)ign, encrypt (w)ith, sign (a)s, (b)oth, "
2151 letters =
_(
"eswabc");
2158 switch (choices[choice - 1])
2218 "RC2, (3) AES, or (c)lear?"),
2240 _(
"(1) RC2-40, (2) RC2-64, (3) RC2-128?"),
2254 "rc2-128", &errmsg);
2261 _(
"(1) AES128, (2) AES192, (3) AES256?"),
2294 }
while (choice == -1);
◆ smime_class_sign_message()
struct Body* smime_class_sign_message |
( |
struct Body * |
a, |
|
|
const struct AddressList * |
from |
|
) |
| |
Implements CryptModuleSpecs::sign_message()
Definition at line 1482 of file smime.c.
1484 struct Body *t = NULL;
1485 struct Body *retval = NULL;
1487 struct Buffer *filetosign = NULL, *signedfile = NULL;
1488 FILE *fp_smime_in = NULL, *fp_smime_out = NULL, *fp_smime_err = NULL, *fp_sign = NULL;
1492 char *intermediates = NULL;
1495 if (!signas || (*signas ==
'\0'))
1497 mutt_error(
_(
"Can't sign: No key specified. Use Sign As."));
1523 fputc(
'\n', fp_sign);
1532 intermediates = signas;
1534 intermediates = signas_key->
issuer;
1550 fputc(
'\n', fp_smime_in);
1557 fflush(fp_smime_err);
1558 rewind(fp_smime_err);
1559 while (fgets(buf,
sizeof(buf) - 1, fp_smime_err))
1566 fflush(fp_smime_out);
1567 rewind(fp_smime_out);
1568 empty = (fgetc(fp_smime_out) == EOF);
◆ smime_class_valid_passphrase()
bool smime_class_valid_passphrase |
( |
void |
| ) |
|
◆ smime_class_verify_one()
int smime_class_verify_one |
( |
struct Body * |
sigbdy, |
|
|
struct State * |
s, |
|
|
const char * |
tempfile |
|
) |
| |
Implements CryptModuleSpecs::verify_one()
Definition at line 1683 of file smime.c.
1685 FILE *fp = NULL, *fp_smime_out = NULL, *fp_smime_err = NULL;
1689 LOFF_T tmpoffset = 0;
1690 size_t tmplength = 0;
1691 int orig_type = sigbdy->
type;
1707 tmplength = sigbdy->
length;
1708 tmpoffset = sigbdy->
offset;
1712 char *save_prefix = s->
prefix;
1729 sigbdy->
type = orig_type;
1744 fflush(fp_smime_out);
1754 fflush(fp_smime_err);
1755 rewind(fp_smime_err);
1765 fflush(fp_smime_err);
1766 rewind(fp_smime_err);
1774 sigbdy->
length = tmplength;
1775 sigbdy->
offset = tmpoffset;
◆ smime_class_verify_sender()
int smime_class_verify_sender |
( |
struct Mailbox * |
m, |
|
|
struct Email * |
e |
|
) |
| |
◆ smime_class_void_passphrase()
void smime_class_void_passphrase |
( |
void |
| ) |
|
void mutt_endwin(void)
Shutdown curses/slang.
char * C_SmimeImportCertCommand
Config: (smime) External command to import a certificate.
void mutt_generate_boundary(struct ParameterList *pl)
Create a unique boundary id for a MIME part.
static struct Buffer SmimeCertToUse
FILE * fp_in
File to read from.
char * C_SmimeKeys
Config: File containing user's private certificates.
static struct Buffer SmimeKeyToUse
#define APPLICATION_SMIME
Use SMIME to encrypt/sign.
#define CH_NONEWLINE
Don't output terminating newline after the header.
String manipulation buffer.
LOFF_T offset
offset where the actual data begins
#define SEC_OPPENCRYPT
Opportunistic encrypt mode.
void crypt_smime_void_passphrase(void)
Wrapper for CryptModuleSpecs::void_passphrase()
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.
int mutt_file_fclose(FILE **fp)
Close a FILE handle (and NULL the pointer)
struct Body * next
next attachment in the list
bool mutt_buffer_is_empty(const struct Buffer *buf)
Is the Buffer empty?
void mutt_buffer_dealloc(struct Buffer *buf)
Release the memory allocated by a buffer.
#define MUTT_CM_DECODE_CRYPT
#define SEC_ENCRYPT
Email is encrypted.
#define CSR_SUCCESS
Action completed successfully.
#define SEC_SIGN
Email is signed.
long C_SmimeTimeout
Config: Time in seconds to cache a passphrase.
#define mutt_buffer_mktemp(buf)
int mutt_multi_choice(const char *prompt, const char *letters)
Offer the user a multiple choice question.
static struct SmimeKey * smime_get_key_by_hash(char *hash, bool only_public_key)
Find a key by its hash.
#define TAILQ_EMPTY(head)
#define CH_WEED
Weed the headers?
#define TAILQ_FOREACH(var, head, field)
void mutt_expand_aliases(struct AddressList *al)
Expand aliases in a List of Addresses.
char * mutt_str_dup(const char *str)
Copy a string, safely.
FILE * mutt_file_fopen(const char *path, const char *mode)
Call fopen() safely.
void mutt_file_unlink(const char *s)
Delete a file, carefully.
void crypt_convert_to_7bit(struct Body *a)
Convert an email to 7bit encoding.
char * C_SmimeCertificates
Config: File containing user's public certificates.
void smime_class_void_passphrase(void)
Implements CryptModuleSpecs::void_passphrase()
unsigned int disposition
content-disposition, ContentDisposition
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.
unsigned int encoding
content-transfer-encoding, ContentEncoding
@ DISP_ATTACH
Content is attached.
#define KEYFLAG_CANENCRYPT
Key is suitable for encryption.
static int smime_handle_cert_email(char *certificate, char *mailbox, bool copy, char ***buffer, int *num)
Process an email containing certificates.
void mutt_buffer_pool_release(struct Buffer **pbuf)
Free a Buffer from the pool.
void mutt_body_free(struct Body **ptr)
Free a Body.
char * subtype
content-type subtype
void mutt_buffer_alloc(struct Buffer *buf, size_t new_size)
Make sure a buffer can store at least new_size bytes.
FILE * fp_out
File to write to.
void state_attach_puts(struct State *s, const char *t)
Write a string to the state.
char * prefix
String to add to the beginning of each output line.
bool mutt_istr_equal(const char *a, const char *b)
Compare two strings, ignoring case.
#define MUTT_CM_DECODE_SMIME
Used for decoding S/MIME messages.
bool badsig
Bad cryptographic signature (needed to check encrypted s/mime-signatures)
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
char * C_SmimeSignAs
Config: Use this alternative key for signing messages.
#define MUTT_RL_NO_FLAGS
No flags are set.
#define TAILQ_FIRST(head)
int mutt_any_key_to_continue(const char *s)
Prompt the user to 'press any key' and wait.
struct AddressList cc
Email's 'Cc' list.
struct Body * mutt_body_new(void)
Create a new Body.
void mutt_env_free(struct Envelope **ptr)
Free an Envelope.
struct Buffer * mutt_buffer_pool_get(void)
Get a Buffer from the pool.
static char * smime_extract_signer_certificate(const char *infile)
Extract the signer's certificate.
bool C_SmimeAskCertLabel
Config: Prompt the user for a label for SMIME certificates.
bool goodsig
Good cryptographic signature.
int mutt_file_copy_stream(FILE *fp_in, FILE *fp_out)
Copy the contents of one file into another.
int mutt_write_mime_body(struct Body *a, FILE *fp, struct ConfigSubset *sub)
Write a MIME part.
LOFF_T length
length (in bytes) of attachment
#define KEYFLAG_CANSIGN
Key is suitable for signing.
#define MUTT_CM_NO_FLAGS
No flags are set.
bool C_CryptOpportunisticEncrypt
Config: Enable encryption when the recipient's key is available.
static char * openssl_md_to_smime_micalg(char *md)
Change the algorithm names.
#define CH_NO_FLAGS
No flags are set.
int cs_subset_str_string_set(const struct ConfigSubset *sub, const char *name, const char *value, struct Buffer *err)
Set a config item by string.
static void smime_key_free(struct SmimeKey **keylist)
Free a list of SMIME keys.
void mutt_param_set(struct ParameterList *pl, const char *attribute, const char *value)
Set a Parameter.
struct AddressList to
Email's 'To' list.
struct Body * parts
parts of a multipart or message/rfc822
static void getkeys(char *mailbox)
Get the keys for a mailbox.
void mutt_mem_realloc(void *ptr, size_t size)
Resize a block of memory on the heap.
struct Envelope * env
Envelope information.
static struct Body * smime_handle_entity(struct Body *m, struct State *s, FILE *fp_out_file)
Handle type application/pkcs7-mime.
static struct SmimeKey * smime_ask_for_key(char *prompt, KeyFlags abilities, bool only_public_key)
Ask the user to select a key.
void mutt_addr_free(struct Address **ptr)
Free a single Address.
size_t mutt_str_len(const char *a)
Calculate the length of a string, safely.
static const char * mutt_buffer_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
SecurityFlags security
bit 0-10: flags, bit 11,12: application, bit 13: traditional pgp See: ncrypt/lib.h pgplib....
time_t mutt_date_epoch(void)
Return the number of seconds since the Unix epoch.
void crypt_current_time(struct State *s, const char *app_name)
Print the current time.
char * mutt_str_replace(char **p, const char *s)
Replace one string with another.
int filter_wait(pid_t pid)
Wait for the exit of a process and return its status.
char * mailbox
Mailbox and host address.
bool C_SmimeDecryptUseDefaultKey
Config: Use the default key for decryption.
#define MUTT_PASS
Password mode (no echo)
char * C_SmimeSignDigestAlg
Config: Digest algorithm.
struct AddressList from
Email's 'From' list.
Keep track when processing files.
@ TYPE_APPLICATION
Type: 'application/*'.
char * d_filename
filename to be used for the content-disposition header.
@ ENC_BASE64
Base-64 encoded text.
static struct Buffer SmimeIntermediateToUse
Container for Accounts, Notifications.
@ DISP_INLINE
Content is inline.
void crypt_opportunistic_encrypt(struct Email *e)
Can all recipients be determined.
unsigned int type
content-type primary type, ContentType
char * C_SmimeDefaultKey
Config: Default key for SMIME operations.
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 char *format)
Run an SMIME command.
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.
struct Address * mutt_default_from(struct ConfigSubset *sub)
Get a default 'from' Address.
struct ConfigSubset * sub
Inherited config items.
static struct SmimeKey * smime_get_key_by_addr(char *mailbox, KeyFlags abilities, bool only_public_key, bool oppenc_mode)
Find an SIME key by address.
bool use_disp
Content-Disposition uses filename= ?
#define CH_MIME
Ignore MIME fields.
int mutt_get_field(const char *field, char *buf, size_t buflen, CompletionFlags complete, bool multiple, char ***files, int *numfiles)
Ask the user for a string.
char * mutt_buffer_strdup(const struct Buffer *buf)
Copy a Buffer's string.
bool unlink
If true, filename should be unlink()ed before free()ing this structure.
time_t mutt_date_add_timeout(time_t now, time_t timeout)
Safely add a timeout to a given time_t value.
struct ParameterList parameter
parameters of the content-type
void mutt_decode_attachment(struct Body *b, struct State *s)
Decode an email's attachment.
@ TYPE_MULTIPART
Type: 'multipart/*'.
#define mutt_message(...)
int mutt_buffer_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
#define mutt_file_mkstemp()
int mutt_copy_message(FILE *fp_out, struct Mailbox *m, struct Email *e, CopyMessageFlags cmflags, CopyHeaderFlags chflags, int wraplen)
Copy a message from a Mailbox.
struct Buffer mutt_buffer_make(size_t size)
Make a new buffer on the stack.
struct AddressList sender
Email's sender.
SecurityFlags mutt_is_application_smime(struct Body *m)
Does the message use S/MIME?
bool mutt_addr_is_user(const struct Address *addr)
Does the address belong to the user.
struct Envelope * mime_headers
Memory hole protected headers.
char * filename
when sending a message, this is the file to which this structure refers
static char * smime_extract_certificate(const char *infile)
Extract an SMIME certificate from a file.
char * mutt_file_read_line(char *line, size_t *size, FILE *fp, int *line_num, ReadLineFlags flags)
Read a line from a file.
int mutt_get_field_unbuffered(const char *msg, char *buf, size_t buflen, CompletionFlags flags)
Ask the user for a string (ignoring macro buffer)
#define MUTT_COMP_NO_FLAGS
No flags are set.