PGP sign, encrypt, check routines. More...
#include "config.h"
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <unistd.h>
#include "mutt/lib.h"
#include "address/lib.h"
#include "config/lib.h"
#include "email/lib.h"
#include "core/lib.h"
#include "gui/lib.h"
#include "mutt.h"
#include "lib.h"
#include "attach/lib.h"
#include "editor/lib.h"
#include "history/lib.h"
#include "question/lib.h"
#include "send/lib.h"
#include "crypt.h"
#include "cryptglue.h"
#include "globals.h"
#include "handler.h"
#include "hook.h"
#include "pgpinvoke.h"
#include "pgpkey.h"
#include "pgpmicalg.h"
#include "pgp.h"
#include "pgplib.h"
Go to the source code of this file.
Functions | |
void | pgp_class_void_passphrase (void) |
Forget the cached passphrase - Implements CryptModuleSpecs::void_passphrase() -. | |
bool | pgp_class_valid_passphrase (void) |
Ensure we have a valid passphrase - Implements CryptModuleSpecs::valid_passphrase() -. | |
bool | pgp_use_gpg_agent (void) |
Does the user want to use the gpg agent? | |
static struct PgpKeyInfo * | key_parent (struct PgpKeyInfo *k) |
Find a key's parent (if it's a subkey) | |
char * | pgp_long_keyid (struct PgpKeyInfo *k) |
Get a key's long id. | |
char * | pgp_short_keyid (struct PgpKeyInfo *k) |
Get a key's short id. | |
char * | pgp_this_keyid (struct PgpKeyInfo *k) |
Get the ID of this key. | |
char * | pgp_keyid (struct PgpKeyInfo *k) |
Get the ID of the main (parent) key. | |
static char * | pgp_fingerprint (struct PgpKeyInfo *k) |
Get the key's fingerprint. | |
char * | pgp_fpr_or_lkeyid (struct PgpKeyInfo *k) |
Get the fingerprint or long keyid. | |
static int | pgp_copy_checksig (FILE *fp_in, FILE *fp_out) |
Copy PGP output and look for signs of a good signature. | |
static int | pgp_check_pgp_decryption_okay_regex (FILE *fp_in) |
Check PGP output to look for successful outcome. | |
static int | pgp_check_decryption_okay (FILE *fp_in) |
Check GPG output for status codes. | |
static void | pgp_copy_clearsigned (FILE *fp_in, struct State *state, char *charset) |
Copy a clearsigned message, stripping the signature. | |
int | pgp_class_application_handler (struct Body *b, struct State *state) |
Manage the MIME type "application/pgp" or "application/smime" - Implements CryptModuleSpecs::application_handler() -. | |
static bool | pgp_check_traditional_one_body (FILE *fp, struct Body *b) |
Check the body of an inline PGP message. | |
bool | pgp_class_check_traditional (FILE *fp, struct Body *b, bool just_one) |
Look for inline (non-MIME) PGP content - Implements CryptModuleSpecs::pgp_check_traditional() -. | |
int | pgp_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 void | pgp_extract_keys_from_attachment (FILE *fp, struct Body *b) |
Extract pgp keys from messages/attachments. | |
void | pgp_class_extract_key_from_attachment (FILE *fp, struct Body *b) |
Extract PGP key from an attachment - Implements CryptModuleSpecs::pgp_extract_key_from_attachment() -. | |
static struct Body * | pgp_decrypt_part (struct Body *a, struct State *state, FILE *fp_out, struct Body *p) |
Decrypt part of a PGP message. | |
int | pgp_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 | pgp_class_encrypted_handler (struct Body *b, struct State *state) |
Manage a PGP or S/MIME encrypted MIME part - Implements CryptModuleSpecs::encrypted_handler() -. | |
struct Body * | pgp_class_sign_message (struct Body *b, const struct AddressList *from) |
Cryptographically sign the Body of a message - Implements CryptModuleSpecs::sign_message() -. | |
char * | pgp_class_find_keys (const struct AddressList *addrlist, bool oppenc_mode) |
Find the keyids of the recipients of a message - Implements CryptModuleSpecs::find_keys() -. | |
struct Body * | pgp_class_encrypt_message (struct Body *b, char *keylist, bool sign, const struct AddressList *from) |
PGP encrypt an email - Implements CryptModuleSpecs::pgp_encrypt_message() -. | |
struct Body * | pgp_class_traditional_encryptsign (struct Body *b, SecurityFlags flags, char *keylist) |
Create an inline PGP encrypted, signed email - Implements CryptModuleSpecs::pgp_traditional_encryptsign() -. | |
SecurityFlags | pgp_class_send_menu (struct Email *e) |
Ask the user whether to sign and/or encrypt the email - Implements CryptModuleSpecs::send_menu() -. | |
Variables | |
static char | PgpPass [1024] |
Cached PGP Passphrase. | |
static time_t | PgpExptime = 0 |
Unix time when PgpPass expires. | |
PGP sign, encrypt, check 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 pgp.c.
bool pgp_use_gpg_agent | ( | void | ) |
Does the user want to use the gpg agent?
true | The user wants to use the gpg agent |
$GPG_TTY
Definition at line 127 of file pgp.c.
|
static |
char * pgp_long_keyid | ( | struct PgpKeyInfo * | k | ) |
Get a key's long id.
k | PGP key |
ptr | Long key id string |
Definition at line 165 of file pgp.c.
char * pgp_short_keyid | ( | struct PgpKeyInfo * | k | ) |
char * pgp_this_keyid | ( | struct PgpKeyInfo * | k | ) |
char * pgp_keyid | ( | struct PgpKeyInfo * | k | ) |
Get the ID of the main (parent) key.
k | PGP key |
ptr | Long/Short key id string |
Definition at line 204 of file pgp.c.
|
static |
Get the key's fingerprint.
k | PGP key |
ptr | Fingerprint string |
Definition at line 216 of file pgp.c.
char * pgp_fpr_or_lkeyid | ( | struct PgpKeyInfo * | k | ) |
Get the fingerprint or long keyid.
k | PGP key |
ptr | String fingerprint or long keyid |
Grab the longest key identifier available: fingerprint or else the long keyid.
The longest available should be used for internally identifying the key and for invoking pgp commands.
Definition at line 234 of file pgp.c.
|
static |
Copy PGP output and look for signs of a good signature.
fp_in | File to read from |
fp_out | File to write to |
0 | Success |
-1 | Error |
Definition at line 251 of file pgp.c.
|
static |
Check PGP output to look for successful outcome.
fp_in | File to read from |
0 | Success |
-1 | Error |
Checks PGP output messages to look for the $pgp_decryption_okay message. This protects against messages with multipart/encrypted headers but which aren't actually encrypted.
Definition at line 303 of file pgp.c.
|
static |
Check GPG output for status codes.
fp_in | File to read from |
1 | - no patterns were matched (if delegated to decryption_okay_regex) |
0 | - DECRYPTION_OKAY was seen, with no PLAINTEXT outside |
-1 | - No decryption status codes were encountered |
-2 | - PLAINTEXT was encountered outside of DECRYPTION delimiters |
-3 | - DECRYPTION_FAILED was encountered |
Checks GnuPGP status fd output for various status codes indicating an issue. If $pgp_check_gpg_decrypt_status_fd is unset, it falls back to the old behavior of just scanning for $pgp_decryption_okay.
pgp_decrypt_part() should fail if the part is not encrypted, so we return less than 0 to indicate part or all was NOT actually encrypted.
On the other hand, for pgp_application_pgp_handler(), a "BEGIN PGP MESSAGE" could indicate a signed and armored message. For that we allow -1 and -2 as "valid" (with a warning).
Definition at line 357 of file pgp.c.
|
static |
Copy a clearsigned message, stripping the signature.
fp_in | File to read from |
state | State to use |
charset | Charset of file |
XXX charset handling: We assume that it is safe to do character set decoding first, dash decoding second here, while we do it the other way around in the main handler.
(Note that we aren't worse than Outlook &c in this, and also note that we can successfully handle anything produced by any existing versions of neomutt.)
Definition at line 424 of file pgp.c.
|
static |
Check the body of an inline PGP message.
fp | File to read |
b | Body to populate |
true | Success |
false | Error |
Definition at line 801 of file pgp.c.
|
static |
Extract pgp keys from messages/attachments.
fp | File to read from |
b | Top Attachment |
Definition at line 971 of file pgp.c.
|
static |
Decrypt part of a PGP message.
a | Body of attachment |
state | State to use |
fp_out | File to write to |
p | Body of parent (main email) |
ptr | New Body for the attachment |
Definition at line 1026 of file pgp.c.