NeoMutt  2024-11-14-138-ge5ca67
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
expando_pgp.c
Go to the documentation of this file.
1
29#include <stdbool.h>
30#include <stdio.h>
31#include "private.h"
32#include "mutt/lib.h"
33#include "core/lib.h"
34#include "expando_pgp.h"
35#include "lib.h"
36#include "expando/lib.h"
37#include "pgp.h"
38#include "pgpkey.h"
39#include "pgplib.h"
40
42static const char TrustFlags[] = "?- +";
43
49static char pgp_flags(KeyFlags flags)
50{
51 if (flags & KEYFLAG_REVOKED)
52 return 'R';
53 if (flags & KEYFLAG_EXPIRED)
54 return 'X';
55 if (flags & KEYFLAG_DISABLED)
56 return 'd';
57 if (flags & KEYFLAG_CRITICAL)
58 return 'c';
59
60 return ' ';
61}
62
66static void pgp_entry_ignore(const struct ExpandoNode *node, void *data,
67 MuttFormatFlags flags, struct Buffer *buf)
68{
69}
70
74static long pgp_entry_number_num(const struct ExpandoNode *node, void *data, MuttFormatFlags flags)
75{
76 const struct PgpEntry *entry = data;
77 return entry->num;
78}
79
83static void pgp_entry_trust(const struct ExpandoNode *node, void *data,
84 MuttFormatFlags flags, struct Buffer *buf)
85{
86 const struct PgpEntry *entry = data;
87 const struct PgpUid *uid = entry->uid;
88
89 buf_printf(buf, "%c", TrustFlags[uid->trust & 0x03]);
90}
91
95static void pgp_entry_user_id(const struct ExpandoNode *node, void *data,
96 MuttFormatFlags flags, struct Buffer *buf)
97{
98 const struct PgpEntry *entry = data;
99 const struct PgpUid *uid = entry->uid;
100
101 const char *s = uid->addr;
102 buf_strcpy(buf, s);
103}
104
113{
114 static char buf[3];
115
116 if (!(flags & KEYFLAG_CANENCRYPT))
117 buf[0] = '-';
118 else if (flags & KEYFLAG_PREFER_SIGNING)
119 buf[0] = '.';
120 else
121 buf[0] = 'e';
122
123 if (!(flags & KEYFLAG_CANSIGN))
124 buf[1] = '-';
126 buf[1] = '.';
127 else
128 buf[1] = 's';
129
130 buf[2] = '\0';
131
132 return buf;
133}
134
138static void pgp_key_algorithm(const struct ExpandoNode *node, void *data,
139 MuttFormatFlags flags, struct Buffer *buf)
140{
141 const struct PgpEntry *entry = data;
142 const struct PgpUid *uid = entry->uid;
143 const struct PgpKeyInfo *key = uid->parent;
144
145 const char *s = key->algorithm;
146 buf_strcpy(buf, s);
147}
148
152static void pgp_key_capabilities(const struct ExpandoNode *node, void *data,
153 MuttFormatFlags flags, struct Buffer *buf)
154{
155 const struct PgpEntry *entry = data;
156 const struct PgpUid *uid = entry->uid;
157 const struct PgpKeyInfo *key = uid->parent;
158
159 const KeyFlags kflags = key->flags | uid->flags;
160
161 const char *s = pgp_key_abilities(kflags);
162 buf_strcpy(buf, s);
163}
164
168static void pgp_key_date(const struct ExpandoNode *node, void *data,
169 MuttFormatFlags flags, struct Buffer *buf)
170{
171 const struct PgpEntry *entry = data;
172 const struct PgpUid *uid = entry->uid;
173 const struct PgpKeyInfo *key = uid->parent;
174
175 bool use_c_locale = false;
176 const char *text = node->text;
177 if (*text == '!')
178 {
179 use_c_locale = true;
180 text++;
181 }
182
183 char tmp[128] = { 0 };
184 if (use_c_locale)
185 {
186 mutt_date_localtime_format_locale(tmp, sizeof(tmp), text, key->gen_time,
188 }
189 else
190 {
191 mutt_date_localtime_format(tmp, sizeof(tmp), text, key->gen_time);
192 }
193
194 buf_strcpy(buf, tmp);
195}
196
200static long pgp_key_date_num(const struct ExpandoNode *node, void *data, MuttFormatFlags flags)
201{
202 const struct PgpEntry *entry = data;
203 const struct PgpUid *uid = entry->uid;
204 const struct PgpKeyInfo *key = uid->parent;
205
206 return key->gen_time;
207}
208
212static void pgp_key_flags(const struct ExpandoNode *node, void *data,
213 MuttFormatFlags flags, struct Buffer *buf)
214{
215 const struct PgpEntry *entry = data;
216 const struct PgpUid *uid = entry->uid;
217 const struct PgpKeyInfo *key = uid->parent;
218
219 const KeyFlags kflags = key->flags | uid->flags;
220
221 buf_printf(buf, "%c", pgp_flags(kflags));
222}
223
227static void pgp_key_id(const struct ExpandoNode *node, void *data,
228 MuttFormatFlags flags, struct Buffer *buf)
229{
230 const struct PgpEntry *entry = data;
231 const struct PgpUid *uid = entry->uid;
232 struct PgpKeyInfo *key = uid->parent;
233
234 const char *s = pgp_this_keyid(key);
235 buf_strcpy(buf, s);
236}
237
241static long pgp_key_length_num(const struct ExpandoNode *node, void *data, MuttFormatFlags flags)
242{
243 const struct PgpEntry *entry = data;
244 const struct PgpUid *uid = entry->uid;
245 const struct PgpKeyInfo *key = uid->parent;
246
247 return key->keylen;
248}
249
253static void pgp_pkey_algorithm(const struct ExpandoNode *node, void *data,
254 MuttFormatFlags flags, struct Buffer *buf)
255{
256 const struct PgpEntry *entry = data;
257 const struct PgpUid *uid = entry->uid;
258 struct PgpKeyInfo *key = uid->parent;
259 struct PgpKeyInfo *pkey = pgp_principal_key(key);
260
261 const char *s = pkey->algorithm;
262 buf_strcpy(buf, s);
263}
264
268static void pgp_pkey_capabilities(const struct ExpandoNode *node, void *data,
269 MuttFormatFlags flags, struct Buffer *buf)
270{
271 const struct PgpEntry *entry = data;
272 const struct PgpUid *uid = entry->uid;
273 struct PgpKeyInfo *key = uid->parent;
274 struct PgpKeyInfo *pkey = pgp_principal_key(key);
275
276 const KeyFlags kflags = (pkey->flags & KEYFLAG_RESTRICTIONS) | uid->flags;
277
278 const char *s = pgp_key_abilities(kflags);
279 buf_strcpy(buf, s);
280}
281
285static void pgp_pkey_flags(const struct ExpandoNode *node, void *data,
286 MuttFormatFlags flags, struct Buffer *buf)
287{
288 const struct PgpEntry *entry = data;
289 const struct PgpUid *uid = entry->uid;
290 struct PgpKeyInfo *key = uid->parent;
291 struct PgpKeyInfo *pkey = pgp_principal_key(key);
292
293 const KeyFlags kflags = (pkey->flags & KEYFLAG_RESTRICTIONS) | uid->flags;
294
295 buf_printf(buf, "%c", pgp_flags(kflags));
296}
297
301static void pgp_pkey_id(const struct ExpandoNode *node, void *data,
302 MuttFormatFlags flags, struct Buffer *buf)
303{
304 const struct PgpEntry *entry = data;
305 const struct PgpUid *uid = entry->uid;
306 struct PgpKeyInfo *key = uid->parent;
307 struct PgpKeyInfo *pkey = pgp_principal_key(key);
308
309 const char *s = pgp_this_keyid(pkey);
310 buf_strcpy(buf, s);
311}
312
316static long pgp_pkey_length_num(const struct ExpandoNode *node, void *data, MuttFormatFlags flags)
317{
318 const struct PgpEntry *entry = data;
319 const struct PgpUid *uid = entry->uid;
320 struct PgpKeyInfo *key = uid->parent;
321 struct PgpKeyInfo *pkey = pgp_principal_key(key);
322
323 return pkey->keylen;
324}
325
332 // clang-format off
350 { -1, -1, NULL, NULL },
351 // clang-format on
352};
int buf_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:161
size_t buf_strcpy(struct Buffer *buf, const char *s)
Copy a string into a Buffer.
Definition: buffer.c:395
Convenience wrapper for the core headers.
@ ED_PGP
Pgp ED_PGP_ ExpandoDataPgp.
Definition: domain.h:51
@ ED_PGP_KEY
Pgp_Key ED_PGK_ ExpandoDataPgpKey.
Definition: domain.h:53
Parse Expando string.
const struct ExpandoRenderCallback PgpEntryRenderCallbacks[]
PgpEntryRenderCallbacks- Callbacks for PGP Key Expandos.
Definition: expando_pgp.c:331
static char pgp_flags(KeyFlags flags)
Turn PGP key flags into a string.
Definition: expando_pgp.c:49
static const char TrustFlags[]
Characters used to show the trust level for PGP keys.
Definition: expando_pgp.c:42
static char * pgp_key_abilities(KeyFlags flags)
Turn PGP key abilities into a string.
Definition: expando_pgp.c:112
Ncrypt PGP Expando definitions.
static long pgp_key_length_num(const struct ExpandoNode *node, void *data, MuttFormatFlags flags)
PGP: Key length - Implements get_number_t -.
Definition: expando_pgp.c:241
static long pgp_entry_number_num(const struct ExpandoNode *node, void *data, MuttFormatFlags flags)
PGP: Index number - Implements get_number_t -.
Definition: expando_pgp.c:74
static long pgp_key_date_num(const struct ExpandoNode *node, void *data, MuttFormatFlags flags)
PGP: Date of the key - Implements get_number_t -.
Definition: expando_pgp.c:200
static long pgp_pkey_length_num(const struct ExpandoNode *node, void *data, MuttFormatFlags flags)
PGP: Principal Key length - Implements get_number_t -.
Definition: expando_pgp.c:316
static void pgp_entry_ignore(const struct ExpandoNode *node, void *data, MuttFormatFlags flags, struct Buffer *buf)
PGP: Field not supported - Implements get_string_t -.
Definition: expando_pgp.c:66
static void pgp_key_capabilities(const struct ExpandoNode *node, void *data, MuttFormatFlags flags, struct Buffer *buf)
PGP: Key Capabilities - Implements get_string_t -.
Definition: expando_pgp.c:152
static void pgp_pkey_algorithm(const struct ExpandoNode *node, void *data, MuttFormatFlags flags, struct Buffer *buf)
PGP: Principal Key Algorithm - Implements get_string_t -.
Definition: expando_pgp.c:253
static void pgp_key_flags(const struct ExpandoNode *node, void *data, MuttFormatFlags flags, struct Buffer *buf)
PGP: Key Flags - Implements get_string_t -.
Definition: expando_pgp.c:212
static void pgp_pkey_flags(const struct ExpandoNode *node, void *data, MuttFormatFlags flags, struct Buffer *buf)
PGP: Principal Key Flags - Implements get_string_t -.
Definition: expando_pgp.c:285
static void pgp_key_id(const struct ExpandoNode *node, void *data, MuttFormatFlags flags, struct Buffer *buf)
PGP: Key id - Implements get_string_t -.
Definition: expando_pgp.c:227
static void pgp_pkey_capabilities(const struct ExpandoNode *node, void *data, MuttFormatFlags flags, struct Buffer *buf)
PGP: Principal Key Capabilities - Implements get_string_t -.
Definition: expando_pgp.c:268
static void pgp_key_algorithm(const struct ExpandoNode *node, void *data, MuttFormatFlags flags, struct Buffer *buf)
PGP: Key Algorithm - Implements get_string_t -.
Definition: expando_pgp.c:138
static void pgp_entry_user_id(const struct ExpandoNode *node, void *data, MuttFormatFlags flags, struct Buffer *buf)
PGP: User id - Implements get_string_t -.
Definition: expando_pgp.c:95
static void pgp_key_date(const struct ExpandoNode *node, void *data, MuttFormatFlags flags, struct Buffer *buf)
PGP: Date of the key - Implements get_string_t -.
Definition: expando_pgp.c:168
static void pgp_pkey_id(const struct ExpandoNode *node, void *data, MuttFormatFlags flags, struct Buffer *buf)
PGP: Principal Key id - Implements get_string_t -.
Definition: expando_pgp.c:301
static void pgp_entry_trust(const struct ExpandoNode *node, void *data, MuttFormatFlags flags, struct Buffer *buf)
PGP: Trust/validity - Implements get_string_t -.
Definition: expando_pgp.c:83
size_t mutt_date_localtime_format(char *buf, size_t buflen, const char *format, time_t t)
Format localtime.
Definition: date.c:951
size_t mutt_date_localtime_format_locale(char *buf, size_t buflen, const char *format, time_t t, locale_t loc)
Format localtime using a given locale.
Definition: date.c:969
Convenience wrapper for the library headers.
#define KEYFLAG_EXPIRED
Key is expired.
Definition: lib.h:137
uint16_t KeyFlags
Flags describing PGP/SMIME keys, e.g. KEYFLAG_CANSIGN.
Definition: lib.h:131
#define KEYFLAG_RESTRICTIONS
Definition: lib.h:146
#define KEYFLAG_CANENCRYPT
Key is suitable for encryption.
Definition: lib.h:134
#define KEYFLAG_PREFER_SIGNING
Key's owner prefers signing.
Definition: lib.h:143
#define KEYFLAG_CRITICAL
Key is marked critical.
Definition: lib.h:141
#define KEYFLAG_DISABLED
Key is marked disabled.
Definition: lib.h:139
#define KEYFLAG_REVOKED
Key is revoked.
Definition: lib.h:138
#define KEYFLAG_PREFER_ENCRYPTION
Key's owner prefers encryption.
Definition: lib.h:142
#define KEYFLAG_CANSIGN
Key is suitable for signing.
Definition: lib.h:133
@ ED_PGP_NUMBER
PgpEntry.num.
Definition: private.h:51
@ ED_PGP_USER_ID
PgpUid.addr.
Definition: private.h:53
@ ED_PGP_TRUST
PgpUid, TrustFlags.
Definition: private.h:52
char * pgp_this_keyid(struct PgpKeyInfo *k)
Get the ID of this key.
Definition: pgp.c:191
PGP sign, encrypt, check routines.
struct PgpKeyInfo * pgp_principal_key(struct PgpKeyInfo *key)
Get the main (parent) PGP key.
Definition: pgpkey.c:92
PGP key management routines.
Misc PGP helper routines.
@ ED_PGK_KEY_CAPABILITIES
PgpKeyInfo.flags, pgp_key_abilities()
Definition: pgplib.h:71
@ ED_PGK_KEY_FINGERPRINT
PgpKeyInfo.fingerprint.
Definition: pgplib.h:72
@ ED_PGK_PKEY_LENGTH
pgp_principal_key(), PgpKeyInfo.keylen
Definition: pgplib.h:81
@ ED_PGK_PKEY_ALGORITHM
pgp_principal_key(), PgpKeyInfo.algorithm
Definition: pgplib.h:76
@ ED_PGK_DATE
PgpKeyInfo.gen_time.
Definition: pgplib.h:69
@ ED_PGK_PKEY_FINGERPRINT
pgp_principal_key(), PgpKeyInfo.fingerprint
Definition: pgplib.h:78
@ ED_PGK_KEY_ID
PgpKeyInfo, pgp_this_keyid()
Definition: pgplib.h:74
@ ED_PGK_PROTOCOL
PgpKeyInfo.
Definition: pgplib.h:82
@ ED_PGK_PKEY_CAPABILITIES
pgp_principal_key(), PgpKeyInfo.flags, pgp_key_abilities()
Definition: pgplib.h:77
@ ED_PGK_KEY_FLAGS
PgpKeyInfo.kflags, pgp_flags()
Definition: pgplib.h:73
@ ED_PGK_PKEY_ID
pgp_principal_key(), PgpKeyInfo, pgp_this_keyid()
Definition: pgplib.h:80
@ ED_PGK_KEY_ALGORITHM
PgpKeyInfo.algorithm.
Definition: pgplib.h:70
@ ED_PGK_KEY_LENGTH
PgpKeyInfo.keylen.
Definition: pgplib.h:75
@ ED_PGK_PKEY_FLAGS
pgp_principal_key(), PgpKeyInfo.kflags, pgp_flags()
Definition: pgplib.h:79
uint8_t MuttFormatFlags
Flags for expando_render(), e.g. MUTT_FORMAT_FORCESUBJ.
Definition: render.h:32
GUI display the mailboxes in a side panel.
Key value store.
String manipulation buffer.
Definition: buffer.h:36
Basic Expando Node.
Definition: node.h:67
const char * text
Node-specific text.
Definition: node.h:73
Container for Accounts, Notifications.
Definition: neomutt.h:42
locale_t time_c_locale
Current locale but LC_TIME=C.
Definition: neomutt.h:48
An entry in a PGP key menu.
Definition: private.h:39
struct PgpUid * uid
PGP Key info.
Definition: private.h:41
size_t num
Index number.
Definition: private.h:40
Information about a PGP key.
Definition: pgplib.h:49
KeyFlags flags
Definition: pgplib.h:53
short keylen
Definition: pgplib.h:54
time_t gen_time
Definition: pgplib.h:55
const char * algorithm
Definition: pgplib.h:57
PGP User ID.
Definition: pgplib.h:36
short trust
Definition: pgplib.h:38
struct PgpKeyInfo * parent
Parent key.
Definition: pgplib.h:40
int flags
Definition: pgplib.h:39
char * addr
Definition: pgplib.h:37