NeoMutt  2022-04-29-323-g5fcc6c
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 *s)
 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 *s)
 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 *s, const char *tempfile)
 Implements CryptModuleSpecs::verify_one() -. More...
 
int smime_gpgme_application_handler (struct Body *a, struct State *s)
 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 *s, 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...
 
bool crypt_id_is_strong (struct CryptKeyInfo *key)
 Is the key strong. More...
 
int digit (const char *s)
 
const char * crypt_fpr_or_lkeyid (struct CryptKeyInfo *k)
 Find the fingerprint of a key. More...
 
unsigned int key_check_cap (gpgme_key_t key, enum KeyCap cap)
 Check the capabilities of a key. More...
 
gpgme_ctx_t create_gpgme_context (bool for_smime)
 Create a new GPGME context. More...
 
const char * crypt_keyid (struct CryptKeyInfo *k)
 Find the ID for the key. More...
 
int crypt_id_is_valid (struct CryptKeyInfo *key)
 Is key ID valid. More...
 
struct CryptKeyInfocrypt_copy_key (struct CryptKeyInfo *key)
 Return a copy of 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

◆ 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 271 of file crypt_gpgme.c.

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

◆ digit()

int digit ( const char *  s)
+ 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 210 of file crypt_gpgme.c.

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

2834{
2835 unsigned int rc = 0;
2836
2837 switch (cap)
2838 {
2840 rc = key->can_encrypt;
2841 if (rc == 0)
2842 {
2843 for (gpgme_subkey_t subkey = key->subkeys; subkey; subkey = subkey->next)
2844 {
2845 rc = subkey->can_encrypt;
2846 if (rc != 0)
2847 break;
2848 }
2849 }
2850 break;
2851 case KEY_CAP_CAN_SIGN:
2852 rc = key->can_sign;
2853 if (rc == 0)
2854 {
2855 for (gpgme_subkey_t subkey = key->subkeys; subkey; subkey = subkey->next)
2856 {
2857 rc = subkey->can_sign;
2858 if (rc != 0)
2859 break;
2860 }
2861 }
2862 break;
2864 rc = key->can_certify;
2865 if (rc == 0)
2866 {
2867 for (gpgme_subkey_t subkey = key->subkeys; subkey; subkey = subkey->next)
2868 {
2869 rc = subkey->can_certify;
2870 if (rc != 0)
2871 break;
2872 }
2873 }
2874 break;
2875 }
2876
2877 return rc;
2878}
+ Here is the caller graph for this function:

◆ 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 358 of file crypt_gpgme.c.

359{
360 gpgme_ctx_t ctx = NULL;
361
362 gpgme_error_t err = gpgme_new(&ctx);
363
364#ifdef USE_AUTOCRYPT
365 const char *const c_autocrypt_dir = cs_subset_path(NeoMutt->sub, "autocrypt_dir");
366 if (!err && OptAutocryptGpgme)
367 err = gpgme_ctx_set_engine_info(ctx, GPGME_PROTOCOL_OpenPGP, NULL, c_autocrypt_dir);
368#endif
369
370 if (err != 0)
371 {
372 mutt_error(_("error creating GPGME context: %s"), gpgme_strerror(err));
373 mutt_exit(1);
374 }
375
376 if (for_smime)
377 {
378 err = gpgme_set_protocol(ctx, GPGME_PROTOCOL_CMS);
379 if (err != 0)
380 {
381 mutt_error(_("error enabling CMS protocol: %s"), gpgme_strerror(err));
382 mutt_exit(1);
383 }
384 }
385
386 return ctx;
387}
const char * cs_subset_path(const struct ConfigSubset *sub, const char *name)
Get a path config item by name.
Definition: helpers.c:194
#define mutt_error(...)
Definition: logging.h:87
void mutt_exit(int code)
Leave NeoMutt NOW.
Definition: main.c:247
#define _(a)
Definition: message.h:28
bool OptAutocryptGpgme
(pseudo) use Autocrypt context inside ncrypt/crypt_gpgme.c
Definition: options.h:39
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_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 134 of file crypt_gpgme.c.

135{
136 const char *s = "????????";
137
138 if (k->kobj && k->kobj->subkeys)
139 {
140 s = k->kobj->subkeys->keyid;
141 const bool c_pgp_long_ids = cs_subset_bool(NeoMutt->sub, "pgp_long_ids");
142 if ((!c_pgp_long_ids) && (strlen(s) == 16))
143 {
144 /* Return only the short keyID. */
145 s += 8;
146 }
147 }
148
149 return s;
150}
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:

◆ 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 306 of file crypt_gpgme.c.

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

231{
232 struct CryptKeyInfo *k = NULL;
233
234 k = mutt_mem_calloc(1, sizeof(*k));
235 k->kobj = key->kobj;
236 gpgme_key_ref(key->kobj);
237 k->idx = key->idx;
238 k->uid = key->uid;
239 k->flags = key->flags;
240 k->validity = key->validity;
241
242 return k;
243}
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
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
+ Here is the call graph for this function:
+ Here is the caller graph for this function: