NeoMutt
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
crypt_gpgme.h File Reference

Wrapper for PGP/SMIME calls to GPGME. More...

#include <gpgme.h>
#include <stdbool.h>
#include <stdio.h>
#include "lib.h"
+ Include dependency graph for crypt_gpgme.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  CryptKeyInfo
 A stored PGP key. More...
 

Enumerations

enum  KeyInfo {
  KIP_NAME = 0 , KIP_AKA , KIP_VALID_FROM , KIP_VALID_TO ,
  KIP_KEY_TYPE , KIP_KEY_USAGE , KIP_FINGERPRINT , KIP_SERIAL_NO ,
  KIP_ISSUED_BY , KIP_SUBKEY , KIP_MAX
}
 PGP Key info. More...
 
enum  KeyCap { KEY_CAP_CAN_ENCRYPT , KEY_CAP_CAN_SIGN , KEY_CAP_CAN_CERTIFY }
 PGP/SMIME Key Capabilities. More...
 

Functions

void pgp_gpgme_set_sender (const char *sender)
 Implements CryptModuleSpecs::set_sender() -.
 
int pgp_gpgme_application_handler (struct Body *m, struct State *state)
 Implements CryptModuleSpecs::application_handler() -.
 
bool pgp_gpgme_check_traditional (FILE *fp, struct Body *b, bool just_one)
 Implements CryptModuleSpecs::pgp_check_traditional() -.
 
int pgp_gpgme_decrypt_mime (FILE *fp_in, FILE **fp_out, struct Body *b, struct Body **cur)
 Implements CryptModuleSpecs::decrypt_mime() -.
 
int pgp_gpgme_encrypted_handler (struct Body *a, struct State *state)
 Implements CryptModuleSpecs::encrypted_handler() -.
 
struct Bodypgp_gpgme_encrypt_message (struct Body *a, char *keylist, bool sign, const struct AddressList *from)
 Implements CryptModuleSpecs::pgp_encrypt_message() -.
 
char * pgp_gpgme_find_keys (const struct AddressList *addrlist, bool oppenc_mode)
 Implements CryptModuleSpecs::find_keys() -.
 
void pgp_gpgme_invoke_import (const char *fname)
 Implements CryptModuleSpecs::pgp_invoke_import() -.
 
struct Bodypgp_gpgme_make_key_attachment (void)
 Implements CryptModuleSpecs::pgp_make_key_attachment() -.
 
SecurityFlags pgp_gpgme_send_menu (struct Email *e)
 Implements CryptModuleSpecs::send_menu() -.
 
struct Bodypgp_gpgme_sign_message (struct Body *a, const struct AddressList *from)
 Implements CryptModuleSpecs::sign_message() -.
 
int pgp_gpgme_verify_one (struct Body *sigbdy, struct State *state, const char *tempfile)
 Implements CryptModuleSpecs::verify_one() -.
 
int smime_gpgme_application_handler (struct Body *a, struct State *state)
 Implements CryptModuleSpecs::application_handler() -.
 
struct Bodysmime_gpgme_build_smime_entity (struct Body *a, char *keylist)
 Implements CryptModuleSpecs::smime_build_smime_entity() -.
 
int smime_gpgme_decrypt_mime (FILE *fp_in, FILE **fp_out, struct Body *b, struct Body **cur)
 Implements CryptModuleSpecs::decrypt_mime() -.
 
char * smime_gpgme_find_keys (const struct AddressList *addrlist, bool oppenc_mode)
 Implements CryptModuleSpecs::find_keys() -.
 
void smime_gpgme_init (void)
 Implements CryptModuleSpecs::init() -.
 
SecurityFlags smime_gpgme_send_menu (struct Email *e)
 Implements CryptModuleSpecs::send_menu() -.
 
struct Bodysmime_gpgme_sign_message (struct Body *a, const struct AddressList *from)
 Implements CryptModuleSpecs::sign_message() -.
 
int smime_gpgme_verify_one (struct Body *sigbdy, struct State *state, const char *tempfile)
 Implements CryptModuleSpecs::verify_one() -.
 
int smime_gpgme_verify_sender (struct Email *e, struct Message *msg)
 Implements CryptModuleSpecs::smime_verify_sender() -.
 
gpgme_ctx_t create_gpgme_context (bool for_smime)
 Create a new GPGME context.
 
struct CryptKeyInfocrypt_copy_key (struct CryptKeyInfo *key)
 Return a copy of KEY.
 
const char * crypt_fpr_or_lkeyid (struct CryptKeyInfo *k)
 Find the fingerprint of a key.
 
bool crypt_id_is_strong (struct CryptKeyInfo *key)
 Is the key strong.
 
int crypt_id_is_valid (struct CryptKeyInfo *key)
 Is key ID valid.
 
const char * crypt_keyid (struct CryptKeyInfo *k)
 Find the ID for the key.
 
int digit (const char *s)
 
unsigned int key_check_cap (gpgme_key_t key, enum KeyCap cap)
 Check the capabilities of a key.
 

Detailed Description

Wrapper for PGP/SMIME calls to GPGME.

Authors
  • g10 Code GmbH
  • Pietro Cerutti

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 crypt_gpgme.h.

Enumeration Type Documentation

◆ KeyInfo

enum KeyInfo

PGP Key info.

Enumerator
KIP_NAME 

PGP Key field: Name.

KIP_AKA 

PGP Key field: aka (Also Known As)

KIP_VALID_FROM 

PGP Key field: Valid From date.

KIP_VALID_TO 

PGP Key field: Valid To date.

KIP_KEY_TYPE 

PGP Key field: Key Type.

KIP_KEY_USAGE 

PGP Key field: Key Usage.

KIP_FINGERPRINT 

PGP Key field: Fingerprint.

KIP_SERIAL_NO 

PGP Key field: Serial number.

KIP_ISSUED_BY 

PGP Key field: Issued By.

KIP_SUBKEY 

PGP Key field: Subkey.

KIP_MAX 

Definition at line 56 of file crypt_gpgme.h.

57{
58 KIP_NAME = 0,
59 KIP_AKA,
68 KIP_MAX,
69};
@ KIP_FINGERPRINT
PGP Key field: Fingerprint.
Definition: crypt_gpgme.h:64
@ KIP_SERIAL_NO
PGP Key field: Serial number.
Definition: crypt_gpgme.h:65
@ KIP_SUBKEY
PGP Key field: Subkey.
Definition: crypt_gpgme.h:67
@ KIP_AKA
PGP Key field: aka (Also Known As)
Definition: crypt_gpgme.h:59
@ KIP_VALID_FROM
PGP Key field: Valid From date.
Definition: crypt_gpgme.h:60
@ KIP_MAX
Definition: crypt_gpgme.h:68
@ KIP_KEY_TYPE
PGP Key field: Key Type.
Definition: crypt_gpgme.h:62
@ KIP_NAME
PGP Key field: Name.
Definition: crypt_gpgme.h:58
@ KIP_ISSUED_BY
PGP Key field: Issued By.
Definition: crypt_gpgme.h:66
@ KIP_KEY_USAGE
PGP Key field: Key Usage.
Definition: crypt_gpgme.h:63
@ KIP_VALID_TO
PGP Key field: Valid To date.
Definition: crypt_gpgme.h:61

◆ KeyCap

enum KeyCap

PGP/SMIME Key Capabilities.

Enumerator
KEY_CAP_CAN_ENCRYPT 

Key can be used for encryption.

KEY_CAP_CAN_SIGN 

Key can be used for signing.

KEY_CAP_CAN_CERTIFY 

Key can be used to certify.

Definition at line 74 of file crypt_gpgme.h.

75{
79};
@ KEY_CAP_CAN_CERTIFY
Key can be used to certify.
Definition: crypt_gpgme.h:78
@ KEY_CAP_CAN_ENCRYPT
Key can be used for encryption.
Definition: crypt_gpgme.h:76
@ KEY_CAP_CAN_SIGN
Key can be used for signing.
Definition: crypt_gpgme.h:77

Function Documentation

◆ create_gpgme_context()

gpgme_ctx_t create_gpgme_context ( bool  for_smime)

Create a new GPGME context.

Parameters
for_smimeIf true, protocol of the context is set to CMS
Return values
ptrNew GPGME context

Definition at line 360 of file crypt_gpgme.c.

361{
362 gpgme_ctx_t ctx = NULL;
363
364 gpgme_error_t err = gpgme_new(&ctx);
365
366#ifdef USE_AUTOCRYPT
367 const char *const c_autocrypt_dir = cs_subset_path(NeoMutt->sub, "autocrypt_dir");
368 if (!err && OptAutocryptGpgme)
369 err = gpgme_ctx_set_engine_info(ctx, GPGME_PROTOCOL_OpenPGP, NULL, c_autocrypt_dir);
370#endif
371
372 if (err != 0)
373 {
374 mutt_error(_("error creating GPGME context: %s"), gpgme_strerror(err));
375 mutt_exit(1);
376 }
377
378 if (for_smime)
379 {
380 err = gpgme_set_protocol(ctx, GPGME_PROTOCOL_CMS);
381 if (err != 0)
382 {
383 mutt_error(_("error enabling CMS protocol: %s"), gpgme_strerror(err));
384 mutt_exit(1);
385 }
386 }
387
388 return ctx;
389}
const char * cs_subset_path(const struct ConfigSubset *sub, const char *name)
Get a path config item by name.
Definition: helpers.c:169
bool OptAutocryptGpgme
(pseudo) use Autocrypt context inside ncrypt/crypt_gpgme.c
Definition: globals.c:67
#define mutt_error(...)
Definition: logging2.h:92
void mutt_exit(int code)
Leave NeoMutt NOW.
Definition: main.c:236
#define _(a)
Definition: message.h:28
Container for Accounts, Notifications.
Definition: neomutt.h:41
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:45
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ crypt_copy_key()

struct CryptKeyInfo * crypt_copy_key ( struct CryptKeyInfo key)

Return a copy of KEY.

Parameters
keyKey to copy
Return values
ptrCopy of key

Definition at line 233 of file crypt_gpgme.c.

234{
235 struct CryptKeyInfo *k = NULL;
236
237 k = mutt_mem_calloc(1, sizeof(*k));
238 k->kobj = key->kobj;
239 gpgme_key_ref(key->kobj);
240 k->idx = key->idx;
241 k->uid = key->uid;
242 k->flags = key->flags;
243 k->validity = key->validity;
244
245 return k;
246}
void * mutt_mem_calloc(size_t nmemb, size_t size)
Allocate zeroed memory on the heap.
Definition: memory.c:50
A stored PGP key.
Definition: crypt_gpgme.h:44
gpgme_validity_t validity
uid validity (cached for convenience)
Definition: crypt_gpgme.h:50
KeyFlags flags
global and per uid flags (for convenience)
Definition: crypt_gpgme.h:49
int idx
and the user ID at this index
Definition: crypt_gpgme.h:47
const char * uid
and for convenience point to this user ID
Definition: crypt_gpgme.h:48
gpgme_key_t kobj
Definition: crypt_gpgme.h:46
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ crypt_fpr_or_lkeyid()

const char * crypt_fpr_or_lkeyid ( struct CryptKeyInfo k)

Find the fingerprint of a key.

Parameters
kKey to examine
Return values
ptrFingerprint if available, otherwise the long keyid

Definition at line 213 of file crypt_gpgme.c.

214{
215 const char *s = "????????????????";
216
217 if (k->kobj && k->kobj->subkeys)
218 {
219 if (k->kobj->subkeys->fpr)
220 s = k->kobj->subkeys->fpr;
221 else
222 s = k->kobj->subkeys->keyid;
223 }
224
225 return s;
226}
+ Here is the caller graph for this function:

◆ crypt_id_is_strong()

bool crypt_id_is_strong ( struct CryptKeyInfo key)

Is the key strong.

Parameters
keyKey to test
Return values
trueValidity of key is sufficient

Definition at line 274 of file crypt_gpgme.c.

275{
276 if (!key)
277 return false;
278
279 bool is_strong = false;
280
281 if ((key->flags & KEYFLAG_ISX509))
282 return true;
283
284 switch (key->validity)
285 {
286 case GPGME_VALIDITY_MARGINAL:
287 case GPGME_VALIDITY_NEVER:
288 case GPGME_VALIDITY_UNDEFINED:
289 case GPGME_VALIDITY_UNKNOWN:
290 is_strong = false;
291 break;
292
293 case GPGME_VALIDITY_FULL:
294 case GPGME_VALIDITY_ULTIMATE:
295 is_strong = true;
296 break;
297 }
298
299 return is_strong;
300}
#define KEYFLAG_ISX509
Key is an X.509 key.
Definition: lib.h:130
+ Here is the caller graph for this function:

◆ crypt_id_is_valid()

int crypt_id_is_valid ( struct CryptKeyInfo key)

Is key ID valid.

Parameters
keyKey to test
Return values
trueKey is valid

When the key is not marked as unusable

Definition at line 309 of file crypt_gpgme.c.

310{
311 if (!key)
312 return 0;
313
314 return !(key->flags & KEYFLAG_CANTUSE);
315}
#define KEYFLAG_CANTUSE
Definition: lib.h:140
+ Here is the caller graph for this function:

◆ crypt_keyid()

const char * crypt_keyid ( struct CryptKeyInfo k)

Find the ID for the key.

Parameters
kKey to use
Return values
ptrID string for the key

Return the keyID for the key K. Note that this string is valid as long as K is valid

Definition at line 137 of file crypt_gpgme.c.

138{
139 const char *s = "????????";
140
141 if (k->kobj && k->kobj->subkeys)
142 {
143 s = k->kobj->subkeys->keyid;
144 const bool c_pgp_long_ids = cs_subset_bool(NeoMutt->sub, "pgp_long_ids");
145 if ((!c_pgp_long_ids) && (strlen(s) == 16))
146 {
147 /* Return only the short keyID. */
148 s += 8;
149 }
150 }
151
152 return s;
153}
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Definition: helpers.c:48
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ digit()

int digit ( const char *  s)
+ Here is the caller graph for this function:

◆ key_check_cap()

unsigned int key_check_cap ( gpgme_key_t  key,
enum KeyCap  cap 
)

Check the capabilities of a key.

Parameters
keyGPGME key
capFlags, e.g. KEY_CAP_CAN_ENCRYPT
Return values
>0Key has the capabilities

Definition at line 2845 of file crypt_gpgme.c.

2846{
2847 unsigned int rc = 0;
2848
2849 switch (cap)
2850 {
2852 rc = key->can_encrypt;
2853 if (rc == 0)
2854 {
2855 for (gpgme_subkey_t subkey = key->subkeys; subkey; subkey = subkey->next)
2856 {
2857 rc = subkey->can_encrypt;
2858 if (rc != 0)
2859 break;
2860 }
2861 }
2862 break;
2863 case KEY_CAP_CAN_SIGN:
2864 rc = key->can_sign;
2865 if (rc == 0)
2866 {
2867 for (gpgme_subkey_t subkey = key->subkeys; subkey; subkey = subkey->next)
2868 {
2869 rc = subkey->can_sign;
2870 if (rc != 0)
2871 break;
2872 }
2873 }
2874 break;
2876 rc = key->can_certify;
2877 if (rc == 0)
2878 {
2879 for (gpgme_subkey_t subkey = key->subkeys; subkey; subkey = subkey->next)
2880 {
2881 rc = subkey->can_certify;
2882 if (rc != 0)
2883 break;
2884 }
2885 }
2886 break;
2887 }
2888
2889 return rc;
2890}
+ Here is the caller graph for this function: