Parse the 'pub' line from the pgp output.
137{
138 struct PgpUid *uid = NULL;
139 int field = 0;
140 bool is_uid = false;
141 bool is_pub = false;
142 bool is_fpr = false;
143 char *pend = NULL, *p = NULL;
146 char tstr[11] = { 0 };
147
148 *is_subkey = false;
149 if (*buf == '\0')
150 return NULL;
151
152
153
154
156 if (k)
157 memcpy(&tmp, k, sizeof(tmp));
158
160
162 for (p = buf; p; p = pend)
163 {
164 pend = strchr(p, ':');
165 if (pend)
166 *pend++ = 0;
167 field++;
168 if ((*p == '\0') && (field != 1) && (field != 10))
169 continue;
170
171 if (is_fpr && (field != 10))
172 continue;
173
174 switch (field)
175 {
176 case 1:
177 {
179
181 is_pub = true;
183 *is_subkey = true;
185 ;
187 *is_subkey = true;
189 is_uid = true;
191 is_fpr = true;
192 else
193 return NULL;
194
195 if (!(is_uid || is_fpr || (*is_subkey && c_pgp_ignore_subkeys)))
196 memset(&tmp, 0, sizeof(tmp));
197
198 break;
199 }
200 case 2:
201 {
203
204 switch (*p)
205 {
206 case 'd':
208 break;
209 case 'e':
211 break;
212 case 'f':
213 trust = 3;
214 break;
215 case 'm':
216 trust = 2;
217 break;
218 case 'n':
219 trust = 1;
220 break;
221 case 'r':
223 break;
224 case 'u':
225 trust = 3;
226 break;
227 }
228
229 if (!is_uid && !(*is_subkey && c_pgp_ignore_subkeys))
231
232 break;
233 }
234 case 3:
235 {
237
238 if (!(*is_subkey && c_pgp_ignore_subkeys) && !mutt_str_atos_full(p, &tmp.
keylen))
239 {
240 goto bail;
241 }
242 break;
243 }
244 case 4:
245 {
247
248 if (!(*is_subkey && c_pgp_ignore_subkeys))
249 {
250 int x = 0;
251 if (!mutt_str_atoi_full(p, &x))
252 goto bail;
255 }
256 break;
257 }
258 case 5:
259 {
261
262 if (!(*is_subkey && c_pgp_ignore_subkeys))
264 break;
265 }
266 case 6:
267 {
269
270 if (strchr(p, '-'))
271 {
272 struct tm time = { 0 };
273
274 time.tm_sec = 0;
275 time.tm_min = 0;
276 time.tm_hour = 12;
277 strncpy(tstr, p, 11);
278 tstr[4] = '\0';
279 tstr[7] = '\0';
280 if (!mutt_str_atoi_full(tstr, &time.tm_year))
281 {
282 p = tstr;
283 goto bail;
284 }
285 time.tm_year -= 1900;
286 if (!mutt_str_atoi_full(tstr + 5, &time.tm_mon))
287 {
288 p = tstr + 5;
289 goto bail;
290 }
291 time.tm_mon -= 1;
292 if (!mutt_str_atoi_full(tstr + 8, &time.tm_mday))
293 {
294 p = tstr + 8;
295 goto bail;
296 }
298 }
299 else
300 {
301 unsigned long long secs;
302
304 goto bail;
306 }
307 break;
308 }
309 case 7:
310 break;
311 case 8:
312 break;
313 case 9:
314 break;
315 case 10:
316 {
317
318
319
320
321
322 if (!(pend && (*p || is_pub)))
323 break;
324
325 if (is_fpr)
326 {
327
330 break;
331 }
332
333
334 if (!is_uid && (*is_subkey && c_pgp_ignore_subkeys))
335 break;
336
338
346
347 if (strstr(p, "ENCR"))
349 if (strstr(p, "SIGN"))
351
352 break;
353 }
354 case 11:
355 break;
356 case 12:
358
359 while (*p)
360 {
361 switch (*p++)
362 {
363 case 'D':
365 break;
366
367 case 'e':
369 break;
370
371 case 's':
373 break;
374 }
375 }
376
377 if (!is_uid && (!*is_subkey || !c_pgp_ignore_subkeys ||
380 {
382 }
383
384 break;
385
386 default:
387 break;
388 }
389 }
390
391
392 if (!(is_uid || is_fpr || (*is_subkey && c_pgp_ignore_subkeys)))
394 if (!k)
395 return NULL;
396 memcpy(k, &tmp, sizeof(*k));
397
398
400 {
403 }
404
405 return k;
406
407bail:
409 return NULL;
410}
const char * mutt_str_atoull(const char *str, unsigned long long *dst)
Convert ASCII string to an unsigned long long.
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
static void fix_uid(char *uid)
Decode backslash-escaped user ids (in place)
#define mutt_debug(LEVEL,...)
@ LL_DEBUG2
Log at debug level 2.
@ LL_DEBUG1
Log at debug level 1.
#define MUTT_MEM_CALLOC(n, type)
time_t mutt_date_make_time(struct tm *t, bool local)
Convert struct tm to time_t
char * mutt_str_dup(const char *str)
Copy a string, safely.
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
char * mutt_str_replace(char **p, const char *s)
Replace one string with another.
#define KEYFLAG_EXPIRED
Key is expired.
uint16_t KeyFlags
Flags describing PGP/SMIME keys, e.g. KEYFLAG_CANSIGN.
#define KEYFLAG_CANENCRYPT
Key is suitable for encryption.
#define KEYFLAG_NO_FLAGS
No flags are set.
#define KEYFLAG_PREFER_SIGNING
Key's owner prefers signing.
#define KEYFLAG_DISABLED
Key is marked disabled.
#define KEYFLAG_REVOKED
Key is revoked.
#define KEYFLAG_PREFER_ENCRYPTION
Key's owner prefers encryption.
#define KEYFLAG_CANSIGN
Key is suitable for signing.
const char * pgp_pkalgbytype(unsigned char type)
Get the name of the algorithm from its ID.
Container for Accounts, Notifications.
struct ConfigSubset * sub
Inherited config items.
Information about a PGP key.
struct PgpKeyInfo * parent
Parent key.
struct PgpUid * next
Linked list.