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

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:194
bool OptAutocryptGpgme
(pseudo) use Autocrypt context inside ncrypt/crypt_gpgme.c
Definition: globals.c:68
#define mutt_error(...)
Definition: logging2.h:87
void mutt_exit(int code)
Leave NeoMutt NOW.
Definition: main.c:241
#define _(a)
Definition: message.h:28
Container for Accounts, Notifications.
Definition: neomutt.h:37
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:39
+ 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 232 of file crypt_gpgme.c.

233{
234 struct CryptKeyInfo *k = NULL;
235
236 k = mutt_mem_calloc(1, sizeof(*k));
237 k->kobj = key->kobj;
238 gpgme_key_ref(key->kobj);
239 k->idx = key->idx;
240 k->uid = key->uid;
241 k->flags = key->flags;
242 k->validity = key->validity;
243
244 return k;
245}
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 212 of file crypt_gpgme.c.

213{
214 const char *s = "????????????????";
215
216 if (k->kobj && k->kobj->subkeys)
217 {
218 if (k->kobj->subkeys->fpr)
219 s = k->kobj->subkeys->fpr;
220 else
221 s = k->kobj->subkeys->keyid;
222 }
223
224 return s;
225}
+ 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 273 of file crypt_gpgme.c.

274{
275 if (!key)
276 return false;
277
278 bool is_strong = false;
279
280 if ((key->flags & KEYFLAG_ISX509))
281 return true;
282
283 switch (key->validity)
284 {
285 case GPGME_VALIDITY_MARGINAL:
286 case GPGME_VALIDITY_NEVER:
287 case GPGME_VALIDITY_UNDEFINED:
288 case GPGME_VALIDITY_UNKNOWN:
289 is_strong = false;
290 break;
291
292 case GPGME_VALIDITY_FULL:
293 case GPGME_VALIDITY_ULTIMATE:
294 is_strong = true;
295 break;
296 }
297
298 return is_strong;
299}
#define KEYFLAG_ISX509
Key is an X.509 key.
Definition: lib.h:129
+ 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 308 of file crypt_gpgme.c.

309{
310 if (!key)
311 return 0;
312
313 return !(key->flags & KEYFLAG_CANTUSE);
314}
#define KEYFLAG_CANTUSE
Definition: lib.h:139
+ 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 136 of file crypt_gpgme.c.

137{
138 const char *s = "????????";
139
140 if (k->kobj && k->kobj->subkeys)
141 {
142 s = k->kobj->subkeys->keyid;
143 const bool c_pgp_long_ids = cs_subset_bool(NeoMutt->sub, "pgp_long_ids");
144 if ((!c_pgp_long_ids) && (strlen(s) == 16))
145 {
146 /* Return only the short keyID. */
147 s += 8;
148 }
149 }
150
151 return s;
152}
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Definition: helpers.c:73
+ 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 2852 of file crypt_gpgme.c.

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