NeoMutt  2020-11-20
Teaching an old dog new tricks
DOXYGEN
dlgpgp.c File Reference

PGP key selection dialog. More...

#include "config.h"
#include <locale.h>
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
#include "private.h"
#include "mutt/lib.h"
#include "address/lib.h"
#include "gui/lib.h"
#include "format_flags.h"
#include "mutt_logging.h"
#include "mutt_menu.h"
#include "muttlib.h"
#include "opcodes.h"
#include "options.h"
#include "pgp.h"
#include "pgpinvoke.h"
#include "pgpkey.h"
#include "pgplib.h"
#include "protos.h"
+ Include dependency graph for dlgpgp.c:

Go to the source code of this file.

Data Structures

struct  PgpEntry
 An entry in a PGP key menu. More...
 

Functions

static int pgp_compare_key_address (const void *a, const void *b)
 Compare Key addresses and IDs for sorting. More...
 
static int pgp_compare_address_qsort (const void *a, const void *b)
 Compare the addresses of two PGP keys. More...
 
static int pgp_compare_key_date (const void *a, const void *b)
 Compare Key dates for sorting. More...
 
static int pgp_compare_date_qsort (const void *a, const void *b)
 Compare the dates of two PGP keys. More...
 
static int pgp_compare_keyid (const void *a, const void *b)
 Compare Key IDs and addresses for sorting. More...
 
static int pgp_compare_keyid_qsort (const void *a, const void *b)
 Compare key IDs. More...
 
static int pgp_compare_key_trust (const void *a, const void *b)
 Compare the trust of keys for sorting. More...
 
static int pgp_compare_trust_qsort (const void *a, const void *b)
 Compare the trust levels of two PGP keys. More...
 
static char * pgp_key_abilities (KeyFlags flags)
 Turn PGP key abilities into a string. More...
 
static char pgp_flags (KeyFlags flags)
 Turn PGP key flags into a string. More...
 
static const char * pgp_entry_format_str (char *buf, size_t buflen, size_t col, int cols, char op, const char *src, const char *prec, const char *if_str, const char *else_str, intptr_t data, MuttFormatFlags flags)
 Format an entry on the PGP key selection menu - Implements format_t. More...
 
static void pgp_make_entry (char *buf, size_t buflen, struct Menu *menu, int line)
 Format a menu item for the pgp key list - Implements Menu::make_entry() More...
 
struct PgpKeyInfodlg_select_pgp_key (struct PgpKeyInfo *keys, struct Address *p, const char *s)
 Let the user select a key to use. More...
 

Variables

static const struct Mapping PgpHelp []
 Help Bar for the PGP key selection dialog. More...
 
static const char trust_flags [] = "?- +"
 

Detailed Description

PGP key selection dialog.

Authors
  • Richard Russon

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 dlgpgp.c.

Function Documentation

◆ pgp_compare_key_address()

static int pgp_compare_key_address ( const void *  a,
const void *  b 
)
static

Compare Key addresses and IDs for sorting.

Parameters
aFirst key
bSecond key
Return values
-1a precedes b
0a and b are identical
1b precedes a

Definition at line 80 of file dlgpgp.c.

81 {
82  struct PgpUid const *const *s = (struct PgpUid const *const *) a;
83  struct PgpUid const *const *t = (struct PgpUid const *const *) b;
84 
85  int r = mutt_istr_cmp((*s)->addr, (*t)->addr);
86  if (r != 0)
87  return (r > 0);
88 
89  return mutt_istr_cmp(pgp_fpr_or_lkeyid((*s)->parent), pgp_fpr_or_lkeyid((*t)->parent)) > 0;
90 }
int mutt_istr_cmp(const char *a, const char *b)
Compare two strings ignoring case, safely.
Definition: string.c:580
PGP User ID.
Definition: pgplib.h:34
char * pgp_fpr_or_lkeyid(struct PgpKeyInfo *k)
Get the fingerprint or long keyid.
Definition: pgp.c:221
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ pgp_compare_address_qsort()

static int pgp_compare_address_qsort ( const void *  a,
const void *  b 
)
static

Compare the addresses of two PGP keys.

Parameters
aFirst address
bSecond address
Return values
-1a precedes b
0a and b are identical
1b precedes a

Definition at line 100 of file dlgpgp.c.

101 {
104 }
short C_PgpSortKeys
Config: Sort order for PGP keys.
Definition: config.c:104
static int pgp_compare_key_address(const void *a, const void *b)
Compare Key addresses and IDs for sorting.
Definition: dlgpgp.c:80
#define SORT_REVERSE
Reverse the order of the sort.
Definition: sort2.h:81
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ pgp_compare_key_date()

static int pgp_compare_key_date ( const void *  a,
const void *  b 
)
static

Compare Key dates for sorting.

Parameters
aFirst key ID
bSecond key ID
Return values
-1a precedes b
0a and b are identical
1b precedes a

Definition at line 114 of file dlgpgp.c.

115 {
116  struct PgpUid const *const *s = (struct PgpUid const *const *) a;
117  struct PgpUid const *const *t = (struct PgpUid const *const *) b;
118 
119  int r = ((*s)->parent->gen_time - (*t)->parent->gen_time);
120  if (r != 0)
121  return r > 0;
122  return mutt_istr_cmp((*s)->addr, (*t)->addr) > 0;
123 }
int mutt_istr_cmp(const char *a, const char *b)
Compare two strings ignoring case, safely.
Definition: string.c:580
PGP User ID.
Definition: pgplib.h:34
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ pgp_compare_date_qsort()

static int pgp_compare_date_qsort ( const void *  a,
const void *  b 
)
static

Compare the dates of two PGP keys.

Parameters
aFirst key
bSecond key
Return values
-1a precedes b
0a and b are identical
1b precedes a

Definition at line 133 of file dlgpgp.c.

134 {
135  return (C_PgpSortKeys & SORT_REVERSE) ? !pgp_compare_key_date(a, b) :
136  pgp_compare_key_date(a, b);
137 }
short C_PgpSortKeys
Config: Sort order for PGP keys.
Definition: config.c:104
static int pgp_compare_key_date(const void *a, const void *b)
Compare Key dates for sorting.
Definition: dlgpgp.c:114
#define SORT_REVERSE
Reverse the order of the sort.
Definition: sort2.h:81
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ pgp_compare_keyid()

static int pgp_compare_keyid ( const void *  a,
const void *  b 
)
static

Compare Key IDs and addresses for sorting.

Parameters
aFirst key ID
bSecond key ID
Return values
-1a precedes b
0a and b are identical
1b precedes a

Definition at line 147 of file dlgpgp.c.

148 {
149  struct PgpUid const *const *s = (struct PgpUid const *const *) a;
150  struct PgpUid const *const *t = (struct PgpUid const *const *) b;
151 
152  int r = mutt_istr_cmp(pgp_fpr_or_lkeyid((*s)->parent), pgp_fpr_or_lkeyid((*t)->parent));
153  if (r != 0)
154  return (r > 0);
155  return mutt_istr_cmp((*s)->addr, (*t)->addr) > 0;
156 }
int mutt_istr_cmp(const char *a, const char *b)
Compare two strings ignoring case, safely.
Definition: string.c:580
PGP User ID.
Definition: pgplib.h:34
char * pgp_fpr_or_lkeyid(struct PgpKeyInfo *k)
Get the fingerprint or long keyid.
Definition: pgp.c:221
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ pgp_compare_keyid_qsort()

static int pgp_compare_keyid_qsort ( const void *  a,
const void *  b 
)
static

Compare key IDs.

Parameters
aFirst key ID
bSecond key ID
Return values
-1a precedes b
0a and b are identical
1b precedes a

Definition at line 166 of file dlgpgp.c.

167 {
168  return (C_PgpSortKeys & SORT_REVERSE) ? !pgp_compare_keyid(a, b) :
169  pgp_compare_keyid(a, b);
170 }
static int pgp_compare_keyid(const void *a, const void *b)
Compare Key IDs and addresses for sorting.
Definition: dlgpgp.c:147
short C_PgpSortKeys
Config: Sort order for PGP keys.
Definition: config.c:104
#define SORT_REVERSE
Reverse the order of the sort.
Definition: sort2.h:81
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ pgp_compare_key_trust()

static int pgp_compare_key_trust ( const void *  a,
const void *  b 
)
static

Compare the trust of keys for sorting.

Parameters
aFirst key
bSecond key
Return values
-1a precedes b
0a and b are identical
1b precedes a

Compare two trust values, the key length, the creation dates. the addresses and the key IDs.

Definition at line 183 of file dlgpgp.c.

184 {
185  struct PgpUid const *const *s = (struct PgpUid const *const *) a;
186  struct PgpUid const *const *t = (struct PgpUid const *const *) b;
187 
188  int r = (((*s)->parent->flags & KEYFLAG_RESTRICTIONS) -
189  ((*t)->parent->flags & KEYFLAG_RESTRICTIONS));
190  if (r != 0)
191  return r > 0;
192  r = ((*s)->trust - (*t)->trust);
193  if (r != 0)
194  return r < 0;
195  r = ((*s)->parent->keylen - (*t)->parent->keylen);
196  if (r != 0)
197  return r < 0;
198  r = ((*s)->parent->gen_time - (*t)->parent->gen_time);
199  if (r != 0)
200  return r < 0;
201  r = mutt_istr_cmp((*s)->addr, (*t)->addr);
202  if (r != 0)
203  return r > 0;
204  return mutt_istr_cmp(pgp_fpr_or_lkeyid((*s)->parent), pgp_fpr_or_lkeyid((*t)->parent)) > 0;
205 }
int mutt_istr_cmp(const char *a, const char *b)
Compare two strings ignoring case, safely.
Definition: string.c:580
PGP User ID.
Definition: pgplib.h:34
#define KEYFLAG_RESTRICTIONS
Definition: lib.h:147
char * pgp_fpr_or_lkeyid(struct PgpKeyInfo *k)
Get the fingerprint or long keyid.
Definition: pgp.c:221
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ pgp_compare_trust_qsort()

static int pgp_compare_trust_qsort ( const void *  a,
const void *  b 
)
static

Compare the trust levels of two PGP keys.

Parameters
aFirst key
bSecond key
Return values
-1a precedes b
0a and b are identical
1b precedes a

Definition at line 215 of file dlgpgp.c.

216 {
217  return (C_PgpSortKeys & SORT_REVERSE) ? !pgp_compare_key_trust(a, b) :
218  pgp_compare_key_trust(a, b);
219 }
static int pgp_compare_key_trust(const void *a, const void *b)
Compare the trust of keys for sorting.
Definition: dlgpgp.c:183
short C_PgpSortKeys
Config: Sort order for PGP keys.
Definition: config.c:104
#define SORT_REVERSE
Reverse the order of the sort.
Definition: sort2.h:81
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ pgp_key_abilities()

static char* pgp_key_abilities ( KeyFlags  flags)
static

Turn PGP key abilities into a string.

Parameters
flagsFlags, see KeyFlags
Return values
ptrAbilities string
Note
This returns a pointer to a static buffer

Definition at line 228 of file dlgpgp.c.

229 {
230  static char buf[3];
231 
232  if (!(flags & KEYFLAG_CANENCRYPT))
233  buf[0] = '-';
234  else if (flags & KEYFLAG_PREFER_SIGNING)
235  buf[0] = '.';
236  else
237  buf[0] = 'e';
238 
239  if (!(flags & KEYFLAG_CANSIGN))
240  buf[1] = '-';
241  else if (flags & KEYFLAG_PREFER_ENCRYPTION)
242  buf[1] = '.';
243  else
244  buf[1] = 's';
245 
246  buf[2] = '\0';
247 
248  return buf;
249 }
#define KEYFLAG_PREFER_ENCRYPTION
Key&#39;s owner prefers encryption.
Definition: lib.h:143
#define KEYFLAG_CANENCRYPT
Key is suitable for encryption.
Definition: lib.h:135
#define KEYFLAG_PREFER_SIGNING
Key&#39;s owner prefers signing.
Definition: lib.h:144
#define KEYFLAG_CANSIGN
Key is suitable for signing.
Definition: lib.h:134
int flags
Definition: pgplib.h:38
+ Here is the caller graph for this function:

◆ pgp_flags()

static char pgp_flags ( KeyFlags  flags)
static

Turn PGP key flags into a string.

Parameters
flagsFlags, see KeyFlags
Return values
charFlag character

Definition at line 256 of file dlgpgp.c.

257 {
258  if (flags & KEYFLAG_REVOKED)
259  return 'R';
260  if (flags & KEYFLAG_EXPIRED)
261  return 'X';
262  if (flags & KEYFLAG_DISABLED)
263  return 'd';
264  if (flags & KEYFLAG_CRITICAL)
265  return 'c';
266 
267  return ' ';
268 }
#define KEYFLAG_EXPIRED
Key is expired.
Definition: lib.h:138
#define KEYFLAG_DISABLED
Key is marked disabled.
Definition: lib.h:140
#define KEYFLAG_CRITICAL
Key is marked critical.
Definition: lib.h:142
#define KEYFLAG_REVOKED
Key is revoked.
Definition: lib.h:139
int flags
Definition: pgplib.h:38
+ Here is the caller graph for this function:

◆ pgp_entry_format_str()

static const char* pgp_entry_format_str ( char *  buf,
size_t  buflen,
size_t  col,
int  cols,
char  op,
const char *  src,
const char *  prec,
const char *  if_str,
const char *  else_str,
intptr_t  data,
MuttFormatFlags  flags 
)
static

Format an entry on the PGP key selection menu - Implements format_t.

Expando Description
%n Number
%t Trust/validity of the key-uid association
%u User id
%[fmt] Date of key using strftime(3)

| | | %a | Algorithm | %c | Capabilities | %f | Flags | %k | Key id | %l | Length | | | %A | Algorithm of the principal key | %C | Capabilities of the principal key | %F | Flags of the principal key | %K | Key id of the principal key | %L | Length of the principal key

Definition at line 292 of file dlgpgp.c.

296 {
297  char fmt[128];
298  bool optional = (flags & MUTT_FORMAT_OPTIONAL);
299 
300  struct PgpEntry *entry = (struct PgpEntry *) data;
301  struct PgpUid *uid = entry->uid;
302  struct PgpKeyInfo *key = uid->parent;
303  struct PgpKeyInfo *pkey = pgp_principal_key(key);
304 
305  if (isupper((unsigned char) op))
306  key = pkey;
307 
308  KeyFlags kflags = key->flags | (pkey->flags & KEYFLAG_RESTRICTIONS) | uid->flags;
309 
310  switch (tolower(op))
311  {
312  case 'a':
313  if (!optional)
314  {
315  snprintf(fmt, sizeof(fmt), "%%%ss", prec);
316  snprintf(buf, buflen, fmt, key->algorithm);
317  }
318  break;
319  case 'c':
320  if (!optional)
321  {
322  snprintf(fmt, sizeof(fmt), "%%%ss", prec);
323  snprintf(buf, buflen, fmt, pgp_key_abilities(kflags));
324  }
325  else if (!(kflags & KEYFLAG_ABILITIES))
326  optional = false;
327  break;
328  case 'f':
329  if (!optional)
330  {
331  snprintf(fmt, sizeof(fmt), "%%%sc", prec);
332  snprintf(buf, buflen, fmt, pgp_flags(kflags));
333  }
334  else if (!(kflags & KEYFLAG_RESTRICTIONS))
335  optional = false;
336  break;
337  case 'k':
338  if (!optional)
339  {
340  snprintf(fmt, sizeof(fmt), "%%%ss", prec);
341  snprintf(buf, buflen, fmt, pgp_this_keyid(key));
342  }
343  break;
344  case 'l':
345  if (!optional)
346  {
347  snprintf(fmt, sizeof(fmt), "%%%sd", prec);
348  snprintf(buf, buflen, fmt, key->keylen);
349  }
350  break;
351  case 'n':
352  if (!optional)
353  {
354  snprintf(fmt, sizeof(fmt), "%%%sd", prec);
355  snprintf(buf, buflen, fmt, entry->num);
356  }
357  break;
358  case 't':
359  if (!optional)
360  {
361  snprintf(fmt, sizeof(fmt), "%%%sc", prec);
362  snprintf(buf, buflen, fmt, trust_flags[uid->trust & 0x03]);
363  }
364  else if (!(uid->trust & 0x03))
365  {
366  /* undefined trust */
367  optional = false;
368  }
369  break;
370  case 'u':
371  if (!optional)
372  {
373  snprintf(fmt, sizeof(fmt), "%%%ss", prec);
374  snprintf(buf, buflen, fmt, NONULL(uid->addr));
375  }
376  break;
377  case '[':
378 
379  {
380  char buf2[128];
381  bool do_locales = true;
382  size_t len;
383 
384  char *p = buf;
385 
386  const char *cp = src;
387  if (*cp == '!')
388  {
389  do_locales = false;
390  cp++;
391  }
392 
393  len = buflen - 1;
394  while ((len > 0) && (*cp != ']'))
395  {
396  if (*cp == '%')
397  {
398  cp++;
399  if (len >= 2)
400  {
401  *p++ = '%';
402  *p++ = *cp;
403  len -= 2;
404  }
405  else
406  break; /* not enough space */
407  cp++;
408  }
409  else
410  {
411  *p++ = *cp++;
412  len--;
413  }
414  }
415  *p = '\0';
416 
417  if (!do_locales)
418  setlocale(LC_TIME, "C");
419  mutt_date_localtime_format(buf2, sizeof(buf2), buf, key->gen_time);
420  if (!do_locales)
421  setlocale(LC_TIME, "");
422 
423  snprintf(fmt, sizeof(fmt), "%%%ss", prec);
424  snprintf(buf, buflen, fmt, buf2);
425  if (len > 0)
426  src = cp + 1;
427  break;
428  }
429  default:
430  *buf = '\0';
431  }
432 
433  if (optional)
434  {
435  mutt_expando_format(buf, buflen, col, cols, if_str, pgp_entry_format_str,
436  data, MUTT_FORMAT_NO_FLAGS);
437  }
438  else if (flags & MUTT_FORMAT_OPTIONAL)
439  {
440  mutt_expando_format(buf, buflen, col, cols, else_str, pgp_entry_format_str,
441  data, MUTT_FORMAT_NO_FLAGS);
442  }
443  return src;
444 }
#define NONULL(x)
Definition: string2.h:37
size_t mutt_date_localtime_format(char *buf, size_t buflen, const char *format, time_t t)
Format localtime.
Definition: date.c:680
static const char * pgp_entry_format_str(char *buf, size_t buflen, size_t col, int cols, char op, const char *src, const char *prec, const char *if_str, const char *else_str, intptr_t data, MuttFormatFlags flags)
Format an entry on the PGP key selection menu - Implements format_t.
Definition: dlgpgp.c:292
static char * pgp_key_abilities(KeyFlags flags)
Turn PGP key abilities into a string.
Definition: dlgpgp.c:228
size_t num
Definition: dlgpgp.c:66
static const char trust_flags[]
Definition: dlgpgp.c:70
static char pgp_flags(KeyFlags flags)
Turn PGP key flags into a string.
Definition: dlgpgp.c:256
PGP User ID.
Definition: pgplib.h:34
KeyFlags flags
Definition: pgplib.h:51
#define KEYFLAG_ABILITIES
Definition: lib.h:149
struct PgpKeyInfo * pgp_principal_key(struct PgpKeyInfo *key)
Get the main (parent) PGP key.
Definition: pgpkey.c:98
#define MUTT_FORMAT_NO_FLAGS
No flags are set.
Definition: format_flags.h:30
char * addr
Definition: pgplib.h:36
Information about a PGP key.
Definition: pgplib.h:46
short trust
Definition: pgplib.h:37
An entry in a PGP key menu.
Definition: dlgpgp.c:64
short keylen
Definition: pgplib.h:52
uint16_t KeyFlags
Flags describing PGP/SMIME keys, e.g. KEYFLAG_CANSIGN.
Definition: lib.h:132
struct PgpKeyInfo * parent
Definition: pgplib.h:39
struct PgpUid * uid
Definition: dlgpgp.c:67
#define KEYFLAG_RESTRICTIONS
Definition: lib.h:147
const char * algorithm
Definition: pgplib.h:55
void mutt_expando_format(char *buf, size_t buflen, size_t col, int cols, const char *src, format_t callback, intptr_t data, MuttFormatFlags flags)
Expand expandos (x) in a string.
Definition: muttlib.c:772
char * pgp_this_keyid(struct PgpKeyInfo *k)
Get the ID of this key.
Definition: pgp.c:179
#define MUTT_FORMAT_OPTIONAL
Allow optional field processing.
Definition: format_flags.h:33
int flags
Definition: pgplib.h:38
time_t gen_time
Definition: pgplib.h:53
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ pgp_make_entry()

static void pgp_make_entry ( char *  buf,
size_t  buflen,
struct Menu menu,
int  line 
)
static

Format a menu item for the pgp key list - Implements Menu::make_entry()

Definition at line 449 of file dlgpgp.c.

450 {
451  struct PgpUid **key_table = menu->mdata;
452  struct PgpEntry entry;
453 
454  entry.uid = key_table[line];
455  entry.num = line + 1;
456 
457  mutt_expando_format(buf, buflen, 0, menu->win_index->state.cols,
459  (intptr_t) &entry, MUTT_FORMAT_ARROWCURSOR);
460 }
#define NONULL(x)
Definition: string2.h:37
static const char * pgp_entry_format_str(char *buf, size_t buflen, size_t col, int cols, char op, const char *src, const char *prec, const char *if_str, const char *else_str, intptr_t data, MuttFormatFlags flags)
Format an entry on the PGP key selection menu - Implements format_t.
Definition: dlgpgp.c:292
#define MUTT_FORMAT_ARROWCURSOR
Reserve space for arrow_cursor.
Definition: format_flags.h:35
PGP User ID.
Definition: pgplib.h:34
An entry in a PGP key menu.
Definition: dlgpgp.c:64
short cols
Number of columns, can be MUTT_WIN_SIZE_UNLIMITED.
Definition: mutt_window.h:57
struct WindowState state
Current state of the Window.
Definition: mutt_window.h:120
void * mdata
Extra data for the current menu.
Definition: mutt_menu.h:55
struct PgpUid * uid
Definition: dlgpgp.c:67
char * C_PgpEntryFormat
Config: printf-like format string for the PGP key selection menu.
Definition: config.c:68
void mutt_expando_format(char *buf, size_t buflen, size_t col, int cols, const char *src, format_t callback, intptr_t data, MuttFormatFlags flags)
Expand expandos (x) in a string.
Definition: muttlib.c:772
struct MuttWindow * win_index
Definition: mutt_menu.h:63
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ dlg_select_pgp_key()

struct PgpKeyInfo* dlg_select_pgp_key ( struct PgpKeyInfo keys,
struct Address p,
const char *  s 
)

Let the user select a key to use.

Parameters
keysList of PGP keys
pAddress to match
sString to match
Return values
ptrSelected PGP key

Definition at line 469 of file dlgpgp.c.

471 {
472  struct PgpUid **key_table = NULL;
473  struct Menu *menu = NULL;
474  int i;
475  bool done = false;
476  char buf[1024], tmpbuf[256];
477  struct PgpKeyInfo *kp = NULL;
478  struct PgpUid *a = NULL;
479  struct Buffer *tempfile = NULL;
480 
481  bool unusable = false;
482 
483  int keymax = 0;
484 
485  for (i = 0, kp = keys; kp; kp = kp->next)
486  {
487  if (!C_PgpShowUnusable && (kp->flags & KEYFLAG_CANTUSE))
488  {
489  unusable = true;
490  continue;
491  }
492 
493  for (a = kp->address; a; a = a->next)
494  {
495  if (!C_PgpShowUnusable && (a->flags & KEYFLAG_CANTUSE))
496  {
497  unusable = true;
498  continue;
499  }
500 
501  if (i == keymax)
502  {
503  keymax += 5;
504  mutt_mem_realloc(&key_table, sizeof(struct PgpUid *) * keymax);
505  }
506 
507  key_table[i++] = a;
508  }
509  }
510 
511  if ((i == 0) && unusable)
512  {
513  mutt_error(_("All matching keys are expired, revoked, or disabled"));
514  return NULL;
515  }
516 
517  int (*f)(const void *, const void *);
518  switch (C_PgpSortKeys & SORT_MASK)
519  {
520  case SORT_ADDRESS:
522  break;
523  case SORT_DATE:
525  break;
526  case SORT_KEYID:
528  break;
529  case SORT_TRUST:
530  default:
532  break;
533  }
534  qsort(key_table, i, sizeof(struct PgpUid *), f);
535 
536  menu = mutt_menu_new(MENU_PGP);
537  struct MuttWindow *dlg = dialog_create_simple_index(menu, WT_DLG_PGP);
538  dlg->help_data = PgpHelp;
539  dlg->help_menu = MENU_PGP;
540 
541  menu->max = i;
542  menu->make_entry = pgp_make_entry;
543  menu->mdata = key_table;
545 
546  if (p)
547  snprintf(buf, sizeof(buf), _("PGP keys matching <%s>"), p->mailbox);
548  else
549  snprintf(buf, sizeof(buf), _("PGP keys matching \"%s\""), s);
550 
551  menu->title = buf;
552 
553  kp = NULL;
554 
556 
557  while (!done)
558  {
559  switch (mutt_menu_loop(menu))
560  {
561  case OP_VERIFY_KEY:
562  {
563  FILE *fp_null = fopen("/dev/null", "w");
564  if (!fp_null)
565  {
566  mutt_perror(_("Can't open /dev/null"));
567  break;
568  }
569  tempfile = mutt_buffer_pool_get();
570  mutt_buffer_mktemp(tempfile);
571  FILE *fp_tmp = mutt_file_fopen(mutt_b2s(tempfile), "w");
572  if (!fp_tmp)
573  {
574  mutt_perror(_("Can't create temporary file"));
575  mutt_file_fclose(&fp_null);
576  mutt_buffer_pool_release(&tempfile);
577  break;
578  }
579 
580  mutt_message(_("Invoking PGP..."));
581 
582  snprintf(tmpbuf, sizeof(tmpbuf), "0x%s",
583  pgp_fpr_or_lkeyid(pgp_principal_key(key_table[menu->current]->parent)));
584 
585  pid_t pid = pgp_invoke_verify_key(NULL, NULL, NULL, -1, fileno(fp_tmp),
586  fileno(fp_null), tmpbuf);
587  if (pid == -1)
588  {
589  mutt_perror(_("Can't create filter"));
590  unlink(mutt_b2s(tempfile));
591  mutt_file_fclose(&fp_tmp);
592  mutt_file_fclose(&fp_null);
593  }
594 
595  filter_wait(pid);
596  mutt_file_fclose(&fp_tmp);
597  mutt_file_fclose(&fp_null);
599  char title[1024];
600  snprintf(title, sizeof(title), _("Key ID: 0x%s"),
601  pgp_keyid(pgp_principal_key(key_table[menu->current]->parent)));
602  mutt_do_pager(title, mutt_b2s(tempfile), MUTT_PAGER_NO_FLAGS, NULL);
603  mutt_buffer_pool_release(&tempfile);
604  menu->redraw = REDRAW_FULL;
605  break;
606  }
607 
608  case OP_VIEW_ID:
609 
610  mutt_message("%s", NONULL(key_table[menu->current]->addr));
611  break;
612 
613  case OP_GENERIC_SELECT_ENTRY:
614 
615  /* XXX make error reporting more verbose */
616 
617  if (OptPgpCheckTrust)
618  {
619  if (!pgp_key_is_valid(key_table[menu->current]->parent))
620  {
621  mutt_error(_("This key can't be used: expired/disabled/revoked"));
622  break;
623  }
624  }
625 
626  if (OptPgpCheckTrust && (!pgp_id_is_valid(key_table[menu->current]) ||
627  !pgp_id_is_strong(key_table[menu->current])))
628  {
629  const char *str = "";
630  char buf2[1024];
631 
632  if (key_table[menu->current]->flags & KEYFLAG_CANTUSE)
633  {
634  str = _("ID is expired/disabled/revoked. Do you really want to use "
635  "the key?");
636  }
637  else
638  {
639  switch (key_table[menu->current]->trust & 0x03)
640  {
641  case 0:
642  str = _("ID has undefined validity. Do you really want to use "
643  "the key?");
644  break;
645  case 1:
646  str = _("ID is not valid. Do you really want to use the key?");
647  break;
648  case 2:
649  str = _("ID is only marginally valid. Do you really want to "
650  "use the key?");
651  break;
652  }
653  }
654 
655  snprintf(buf2, sizeof(buf2), "%s", str);
656 
657  if (mutt_yesorno(buf2, MUTT_NO) != MUTT_YES)
658  {
660  break;
661  }
662  }
663 
664  kp = key_table[menu->current]->parent;
665  done = true;
666  break;
667 
668  case OP_EXIT:
669 
670  kp = NULL;
671  done = true;
672  break;
673  }
674  }
675 
676  mutt_menu_pop_current(menu);
677  mutt_menu_free(&menu);
679  FREE(&key_table);
680 
681  return kp;
682 }
struct PgpKeyInfo * next
Definition: pgplib.h:57
PGP encryption menu.
Definition: keymap.h:84
#define mutt_buffer_mktemp(buf)
Definition: muttlib.h:77
#define REDRAW_FULL
Redraw everything.
Definition: mutt_menu.h:45
#define NONULL(x)
Definition: string2.h:37
struct Buffer * mutt_buffer_pool_get(void)
Get a Buffer from the pool.
Definition: pool.c:101
#define mutt_perror(...)
Definition: logging.h:85
GUI selectable list of items.
Definition: mutt_menu.h:52
struct PgpUid * next
Definition: pgplib.h:40
#define mutt_message(...)
Definition: logging.h:83
int help_menu
Menu for key bindings, e.g. MENU_PAGER.
Definition: mutt_window.h:134
char * pgp_keyid(struct PgpKeyInfo *k)
Get the ID of the main (parent) key.
Definition: pgp.c:191
void mutt_buffer_pool_release(struct Buffer **pbuf)
Free a Buffer from the pool.
Definition: pool.c:112
Pgp Dialog, dlg_select_pgp_key()
Definition: mutt_window.h:85
String manipulation buffer.
Definition: buffer.h:33
static int pgp_compare_address_qsort(const void *a, const void *b)
Compare the addresses of two PGP keys.
Definition: dlgpgp.c:100
#define _(a)
Definition: message.h:28
Sort by email address.
Definition: sort2.h:56
PGP User ID.
Definition: pgplib.h:34
char * mailbox
Mailbox and host address.
Definition: address.h:37
A division of the screen.
Definition: mutt_window.h:115
KeyFlags flags
Definition: pgplib.h:51
bool pgp_key_is_valid(struct PgpKeyInfo *k)
Is a PGP key valid?
Definition: pgpkey.c:110
static int pgp_compare_date_qsort(const void *a, const void *b)
Compare the dates of two PGP keys.
Definition: dlgpgp.c:133
static void pgp_make_entry(char *buf, size_t buflen, struct Menu *menu, int line)
Format a menu item for the pgp key list - Implements Menu::make_entry()
Definition: dlgpgp.c:449
struct PgpKeyInfo * pgp_principal_key(struct PgpKeyInfo *key)
Get the main (parent) PGP key.
Definition: pgpkey.c:98
struct MuttWindow * dialog_create_simple_index(struct Menu *menu, enum WindowType type)
Create a simple index Dialog.
Definition: dialog.c:165
char * addr
Definition: pgplib.h:36
Information about a PGP key.
Definition: pgplib.h:46
enum QuadOption mutt_yesorno(const char *msg, enum QuadOption def)
Ask the user a Yes/No question.
Definition: curs_lib.c:379
short trust
Definition: pgplib.h:37
const char * title
Title of this menu.
Definition: mutt_menu.h:54
int mutt_file_fclose(FILE **fp)
Close a FILE handle (and NULL the pointer)
Definition: file.c:153
void mutt_clear_error(void)
Clear the message line (bottom line of screen)
Definition: mutt_logging.c:113
static int pgp_compare_trust_qsort(const void *a, const void *b)
Compare the trust levels of two PGP keys.
Definition: dlgpgp.c:215
bool C_PgpShowUnusable
Config: Show non-usable keys in the key selection.
Definition: config.c:64
#define KEYFLAG_CANTUSE
Definition: lib.h:146
void mutt_mem_realloc(void *ptr, size_t size)
Resize a block of memory on the heap.
Definition: memory.c:114
#define mutt_b2s(buf)
Definition: buffer.h:41
Sort by encryption key&#39;s trust level.
Definition: sort2.h:58
void * mdata
Extra data for the current menu.
Definition: mutt_menu.h:55
const struct Mapping * help_data
Data for the Help Bar.
Definition: mutt_window.h:135
void dialog_destroy_simple_index(struct MuttWindow **ptr)
Destroy a simple index Dialog.
Definition: dialog.c:209
struct PgpUid * address
Definition: pgplib.h:50
pid_t pgp_invoke_verify_key(FILE **fp_pgp_in, FILE **fp_pgp_out, FILE **fp_pgp_err, int fd_pgp_in, int fd_pgp_out, int fd_pgp_err, const char *uids)
Use PGP to verify a key.
Definition: pgpinvoke.c:497
WHERE bool OptPgpCheckTrust
(pseudo) used by dlg_select_pgp_key()
Definition: options.h:49
struct PgpKeyInfo * parent
Definition: pgplib.h:39
short C_PgpSortKeys
Config: Sort order for PGP keys.
Definition: config.c:104
int max
Number of entries in the menu.
Definition: mutt_menu.h:57
MuttRedrawFlags redraw
When to redraw the screen.
Definition: mutt_menu.h:58
char * pgp_fpr_or_lkeyid(struct PgpKeyInfo *k)
Get the fingerprint or long keyid.
Definition: pgp.c:221
static const struct Mapping PgpHelp[]
Help Bar for the PGP key selection dialog.
Definition: dlgpgp.c:51
int mutt_do_pager(const char *banner, const char *tempfile, PagerFlags do_color, struct Pager *info)
Display some page-able text to the user.
Definition: curs_lib.c:690
bool pgp_id_is_valid(struct PgpUid *uid)
Is a PGP key valid.
Definition: pgpkey.c:139
#define mutt_error(...)
Definition: logging.h:84
#define FREE(x)
Definition: memory.h:40
static int pgp_compare_keyid_qsort(const void *a, const void *b)
Compare key IDs.
Definition: dlgpgp.c:166
User answered &#39;No&#39;, or assume &#39;No&#39;.
Definition: quad.h:39
bool pgp_id_is_strong(struct PgpUid *uid)
Is a PGP key strong?
Definition: pgpkey.c:126
Sort by the encryption key&#39;s ID.
Definition: sort2.h:57
int current
Current entry.
Definition: mutt_menu.h:56
Sort by the date the email was sent.
Definition: sort2.h:45
FILE * mutt_file_fopen(const char *path, const char *mode)
Call fopen() safely.
Definition: file.c:588
int filter_wait(pid_t pid)
Wait for the exit of a process and return its status.
Definition: filter.c:217
void(* make_entry)(char *buf, size_t buflen, struct Menu *menu, int line)
Format a item for a menu.
Definition: mutt_menu.h:88
#define SORT_MASK
Mask for the sort id.
Definition: sort2.h:80
#define MUTT_PAGER_NO_FLAGS
No flags are set.
Definition: pager.h:43
int flags
Definition: pgplib.h:38
User answered &#39;Yes&#39;, or assume &#39;Yes&#39;.
Definition: quad.h:40
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ PgpHelp

const struct Mapping PgpHelp[]
static
Initial value:
= {
{ N_("Exit"), OP_EXIT },
{ N_("Select"), OP_GENERIC_SELECT_ENTRY },
{ N_("Check key"), OP_VERIFY_KEY },
{ N_("Help"), OP_HELP },
{ NULL, 0 },
}
#define N_(a)
Definition: message.h:32

Help Bar for the PGP key selection dialog.

Definition at line 51 of file dlgpgp.c.

◆ trust_flags

const char trust_flags[] = "?- +"
static

Definition at line 70 of file dlgpgp.c.