NeoMutt  2025-12-11-694-ga89709
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
lib.h File Reference

Autocrypt end-to-end encryption. More...

#include "config.h"
#include <sqlite3.h>
#include <stdbool.h>
#include <stdio.h>
#include "mutt/lib.h"
+ Include dependency graph for lib.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  AutocryptAccount
 Autocrypt account. More...
 
struct  AutocryptPeer
 Autocrypt peer. More...
 
struct  AutocryptPeerHistory
 Autocrypt peer history. More...
 
struct  AutocryptGossipHistory
 Autocrypt gossip history. More...
 

Enumerations

enum  AutocryptRec {
  AUTOCRYPT_REC_OFF , AUTOCRYPT_REC_NO , AUTOCRYPT_REC_DISCOURAGE , AUTOCRYPT_REC_AVAILABLE ,
  AUTOCRYPT_REC_YES
}
 Recommendation. More...
 

Functions

 ARRAY_HEAD (AutocryptAccountArray, struct AutocryptAccount *)
 
void autocrypt_init_keys (struct SubMenu *sm_generic)
 Initialise the Autocrypt Keybindings - Implements ::init_keys_api.
 
void dlg_autocrypt (void)
 Display the Autocrypt account Menu -.
 
void mutt_autocrypt_cleanup (void)
 Shutdown Autocrypt.
 
int mutt_autocrypt_generate_gossip_list (struct Email *e)
 Create the gossip list headers.
 
int mutt_autocrypt_init (bool can_create)
 Initialise Autocrypt.
 
int mutt_autocrypt_process_autocrypt_header (struct Email *e, struct Envelope *env)
 Parse an Autocrypt email header.
 
int mutt_autocrypt_process_gossip_header (struct Email *e, struct Envelope *prot_headers)
 Parse an Autocrypt email gossip header.
 
int mutt_autocrypt_set_sign_as_default_key (struct Email *e)
 Set the Autocrypt default key for signing.
 
enum AutocryptRec mutt_autocrypt_ui_recommendation (const struct Email *e, char **keylist)
 Get the recommended action for an Email.
 
int mutt_autocrypt_write_autocrypt_header (struct Envelope *env, FILE *fp)
 Write the Autocrypt header to a file.
 
int mutt_autocrypt_write_gossip_headers (struct Envelope *env, FILE *fp)
 Write the Autocrypt gossip headers to a file.
 

Variables

char * AutocryptSignAs
 Autocrypt Key id to sign as.
 
char * AutocryptDefaultKey
 Autocrypt default key id (used for postponing messages)
 

Detailed Description

Autocrypt end-to-end encryption.

Authors
  • Kevin J. McCarthy
  • 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 lib.h.

Enumeration Type Documentation

◆ AutocryptRec

Recommendation.

Enumerator
AUTOCRYPT_REC_OFF 

No recommendations.

AUTOCRYPT_REC_NO 

Do no use Autocrypt.

AUTOCRYPT_REC_DISCOURAGE 

Prefer not to use Autocrypt.

AUTOCRYPT_REC_AVAILABLE 

Autocrypt is available.

AUTOCRYPT_REC_YES 

Autocrypt should be used.

Definition at line 164 of file lib.h.

165{
171};
@ AUTOCRYPT_REC_DISCOURAGE
Prefer not to use Autocrypt.
Definition lib.h:168
@ AUTOCRYPT_REC_NO
Do no use Autocrypt.
Definition lib.h:167
@ AUTOCRYPT_REC_OFF
No recommendations.
Definition lib.h:166
@ AUTOCRYPT_REC_AVAILABLE
Autocrypt is available.
Definition lib.h:169
@ AUTOCRYPT_REC_YES
Autocrypt should be used.
Definition lib.h:170

Function Documentation

◆ ARRAY_HEAD()

ARRAY_HEAD ( AutocryptAccountArray ,
struct AutocryptAccount *  )

◆ autocrypt_init_keys()

void autocrypt_init_keys ( struct SubMenu * sm_generic)

Initialise the Autocrypt Keybindings - Implements ::init_keys_api.

Definition at line 77 of file functions.c.

78{
79 struct MenuDefinition *md = NULL;
80 struct SubMenu *sm = NULL;
81
83 md = km_register_menu(MENU_AUTOCRYPT, "autocrypt");
84 km_menu_add_submenu(md, sm);
85 km_menu_add_submenu(md, sm_generic);
87
88 MdAutocrypt = md;
89}
static const struct MenuFuncOp OpAutocrypt[]
Functions for the Autocrypt Account.
Definition functions.c:52
struct MenuDefinition * MdAutocrypt
Autocrypt Menu Definition.
Definition functions.c:46
static const struct MenuOpSeq AutocryptDefaultBindings[]
Key bindings for the Autocrypt Account.
Definition functions.c:64
void km_menu_add_submenu(struct MenuDefinition *md, struct SubMenu *sm)
Add a SubMenu to a Menu Definition.
Definition init.c:123
struct SubMenu * km_register_submenu(const struct MenuFuncOp functions[])
Register a submenu.
Definition init.c:91
struct MenuDefinition * km_register_menu(int menu, const char *name)
Register a menu.
Definition init.c:107
void km_menu_add_bindings(struct MenuDefinition *md, const struct MenuOpSeq bindings[])
Add Keybindings to a Menu.
Definition init.c:136
Functions for a Dialog or Window.
Definition menu.h:80
Collection of related functions.
Definition menu.h:68
@ MENU_AUTOCRYPT
Autocrypt Account menu.
Definition type.h:37
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_autocrypt_cleanup()

void mutt_autocrypt_cleanup ( void )

Shutdown Autocrypt.

Definition at line 133 of file autocrypt.c.

134{
136}
void mutt_autocrypt_db_close(void)
Close the Autocrypt SQLite database connection.
Definition db.c:133
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_autocrypt_generate_gossip_list()

int mutt_autocrypt_generate_gossip_list ( struct Email * e)

Create the gossip list headers.

Parameters
eEmail
Return values
0Success
-1Error

Definition at line 840 of file autocrypt.c.

841{
842 int rc = -1;
843 struct AutocryptPeer *peer = NULL;
844 struct AutocryptAccount *account = NULL;
845 struct Address *recip = NULL;
846
847 const bool c_autocrypt = cs_subset_bool(NeoMutt->sub, "autocrypt");
848 if (!c_autocrypt || mutt_autocrypt_init(false) || !e)
849 return -1;
850
851 struct Envelope *mime_headers = e->body->mime_headers;
852 if (!mime_headers)
853 mime_headers = e->body->mime_headers = mutt_env_new();
855
856 struct AddressList recips = TAILQ_HEAD_INITIALIZER(recips);
857
858 mutt_addrlist_copy(&recips, &e->env->to, false);
859 mutt_addrlist_copy(&recips, &e->env->cc, false);
860
861 TAILQ_FOREACH(recip, &recips, entries)
862 {
863 /* At this point, we just accept missing keys and include what we can. */
864 if (mutt_autocrypt_db_peer_get(recip, &peer) <= 0)
865 continue;
866
867 const char *keydata = NULL;
869 keydata = peer->keydata;
871 keydata = peer->gossip_keydata;
872
873 if (keydata)
874 {
875 struct AutocryptHeader *gossip = mutt_autocrypthdr_new();
876 gossip->addr = mutt_str_dup(peer->email_addr);
877 gossip->keydata = mutt_str_dup(keydata);
878 gossip->next = mime_headers->autocrypt_gossip;
879 mime_headers->autocrypt_gossip = gossip;
880 }
881
883 }
884
885 TAILQ_FOREACH(recip, &e->env->reply_to, entries)
886 {
887 const char *addr = NULL;
888 const char *keydata = NULL;
889 if (mutt_autocrypt_db_account_get(recip, &account) > 0)
890 {
891 addr = account->email_addr;
892 keydata = account->keydata;
893 }
894 else if (mutt_autocrypt_db_peer_get(recip, &peer) > 0)
895 {
896 addr = peer->email_addr;
898 keydata = peer->keydata;
900 keydata = peer->gossip_keydata;
901 }
902
903 if (keydata)
904 {
905 struct AutocryptHeader *gossip = mutt_autocrypthdr_new();
906 gossip->addr = mutt_str_dup(addr);
907 gossip->keydata = mutt_str_dup(keydata);
908 gossip->next = mime_headers->autocrypt_gossip;
909 mime_headers->autocrypt_gossip = gossip;
910 }
913 }
914
915 rc = 0;
916
917 mutt_addrlist_clear(&recips);
920 return rc;
921}
void mutt_addrlist_copy(struct AddressList *dst, const struct AddressList *src, bool prune)
Copy a list of addresses into another list.
Definition address.c:774
void mutt_addrlist_clear(struct AddressList *al)
Unlink and free all Address in an AddressList.
Definition address.c:1469
int mutt_autocrypt_db_account_get(struct Address *addr, struct AutocryptAccount **account)
Get Autocrypt Account data from the database.
Definition db.c:265
int mutt_autocrypt_db_peer_get(struct Address *addr, struct AutocryptPeer **peer)
Get peer info from the Autocrypt database.
Definition db.c:553
void mutt_autocrypt_db_account_free(struct AutocryptAccount **ptr)
Free an AutocryptAccount.
Definition db.c:246
void mutt_autocrypt_db_peer_free(struct AutocryptPeer **ptr)
Free an AutocryptPeer.
Definition db.c:531
int mutt_autocrypt_init(bool can_create)
Initialise Autocrypt.
Definition autocrypt.c:103
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Definition helpers.c:47
struct Envelope * mutt_env_new(void)
Create a new Envelope.
Definition envelope.c:45
struct AutocryptHeader * mutt_autocrypthdr_new(void)
Create a new AutocryptHeader.
Definition envelope.c:94
void mutt_autocrypthdr_free(struct AutocryptHeader **ptr)
Free an AutocryptHeader.
Definition envelope.c:103
bool mutt_autocrypt_gpgme_is_valid_key(const char *keyid)
Is a key id valid?
Definition gpgme.c:361
char * mutt_str_dup(const char *str)
Copy a string, safely.
Definition string.c:257
#define TAILQ_FOREACH(var, head, field)
Definition queue.h:782
#define TAILQ_HEAD_INITIALIZER(head)
Definition queue.h:694
An email address.
Definition address.h:35
Autocrypt account.
Definition lib.h:113
char * email_addr
Email address.
Definition lib.h:114
char * keydata
PGP Key data.
Definition lib.h:116
Parse Autocrypt header info.
Definition envelope.h:44
struct AutocryptHeader * next
Linked list.
Definition envelope.h:49
char * keydata
PGP Key data.
Definition envelope.h:46
char * addr
Email address.
Definition envelope.h:45
Autocrypt peer.
Definition lib.h:126
char * gossip_keydata
Gossip Key data.
Definition lib.h:135
char * keyid
PGP Key id.
Definition lib.h:130
char * gossip_keyid
Gossip Key id.
Definition lib.h:134
char * keydata
PGP Key data.
Definition lib.h:131
char * email_addr
Email address.
Definition lib.h:127
struct Envelope * mime_headers
Memory hole protected headers.
Definition body.h:76
struct Envelope * env
Envelope information.
Definition email.h:68
struct Body * body
List of MIME parts.
Definition email.h:69
The header of an Email.
Definition envelope.h:57
struct AddressList to
Email's 'To' list.
Definition envelope.h:60
struct AddressList reply_to
Email's 'reply-to'.
Definition envelope.h:64
struct AutocryptHeader * autocrypt_gossip
Autocrypt Gossip header.
Definition envelope.h:88
struct AddressList cc
Email's 'Cc' list.
Definition envelope.h:61
Container for Accounts, Notifications.
Definition neomutt.h:41
struct ConfigSubset * sub
Inherited config items.
Definition neomutt.h:49
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_autocrypt_init()

int mutt_autocrypt_init ( bool can_create)

Initialise Autocrypt.

Parameters
can_createIf true, directories may be created
Return values
0Success
-1Error

Definition at line 103 of file autocrypt.c.

104{
105 if (AutocryptDB)
106 return 0;
107
108 const bool c_autocrypt = cs_subset_bool(NeoMutt->sub, "autocrypt");
109 const char *const c_autocrypt_dir = cs_subset_path(NeoMutt->sub, "autocrypt_dir");
110 if (!c_autocrypt || !c_autocrypt_dir)
111 return -1;
112
113 if (autocrypt_dir_init(can_create))
114 goto bail;
115
117 goto bail;
118
119 if (mutt_autocrypt_db_init(can_create))
120 goto bail;
121
122 return 0;
123
124bail:
125 cs_subset_str_native_set(NeoMutt->sub, "autocrypt", false, NULL);
127 return -1;
128}
sqlite3 * AutocryptDB
Handle to the open Autocrypt database.
Definition db.c:56
int mutt_autocrypt_db_init(bool can_create)
Initialise the Autocrypt SQLite database.
Definition db.c:83
static int autocrypt_dir_init(bool can_create)
Initialise an Autocrypt directory.
Definition autocrypt.c:61
const char * cs_subset_path(const struct ConfigSubset *sub, const char *name)
Get a path config item by name.
Definition helpers.c:168
int mutt_autocrypt_gpgme_init(void)
Initialise GPGME.
Definition gpgme.c:70
int cs_subset_str_native_set(const struct ConfigSubset *sub, const char *name, intptr_t value, struct Buffer *err)
Natively set the value of a string config item.
Definition subset.c:303
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_autocrypt_process_autocrypt_header()

int mutt_autocrypt_process_autocrypt_header ( struct Email * e,
struct Envelope * env )

Parse an Autocrypt email header.

Parameters
eEmail
envEnvelope
Return values
0Success
-1Error

Definition at line 260 of file autocrypt.c.

261{
262 struct AutocryptHeader *valid_ac_hdr = NULL;
263 struct AutocryptPeer *peer = NULL;
264 struct AutocryptPeerHistory *peerhist = NULL;
265 struct Buffer *keyid = NULL;
266 bool update_db = false, insert_db = false, insert_db_history = false, import_gpg = false;
267 int rc = -1;
268
269 const bool c_autocrypt = cs_subset_bool(NeoMutt->sub, "autocrypt");
270 if (!c_autocrypt)
271 return 0;
272
273 if (mutt_autocrypt_init(false))
274 return -1;
275
276 if (!e || !e->body || !env)
277 return 0;
278
279 /* 1.1 spec says to skip emails with more than one From header */
280 struct Address *from = TAILQ_FIRST(&env->from);
281 if (!from || TAILQ_NEXT(from, entries))
282 return 0;
283
284 /* 1.1 spec also says to skip multipart/report emails */
285 if ((e->body->type == TYPE_MULTIPART) && mutt_istr_equal(e->body->subtype, "report"))
286 {
287 return 0;
288 }
289
290 /* Ignore emails that appear to be more than a week in the future,
291 * since they can block all future updates during that time. */
292 if (e->date_sent > (mutt_date_now() + (7 * 24 * 60 * 60)))
293 return 0;
294
295 for (struct AutocryptHeader *ac_hdr = env->autocrypt; ac_hdr; ac_hdr = ac_hdr->next)
296 {
297 if (ac_hdr->invalid)
298 continue;
299
300 /* NOTE: this assumes the processing is occurring right after
301 * mutt_parse_rfc822_line() and the from ADDR is still in the same
302 * form (intl) as the autocrypt header addr field */
303 if (!mutt_istr_equal(buf_string(from->mailbox), ac_hdr->addr))
304 continue;
305
306 /* 1.1 spec says ignore all, if more than one valid header is found. */
307 if (valid_ac_hdr)
308 {
309 valid_ac_hdr = NULL;
310 break;
311 }
312 valid_ac_hdr = ac_hdr;
313 }
314
315 if (mutt_autocrypt_db_peer_get(from, &peer) < 0)
316 goto cleanup;
317
318 if (peer)
319 {
320 if (e->date_sent <= peer->autocrypt_timestamp)
321 {
322 rc = 0;
323 goto cleanup;
324 }
325
326 if (e->date_sent > peer->last_seen)
327 {
328 update_db = true;
329 peer->last_seen = e->date_sent;
330 }
331
332 if (valid_ac_hdr)
333 {
334 update_db = true;
336 peer->prefer_encrypt = valid_ac_hdr->prefer_encrypt;
337 if (!mutt_str_equal(peer->keydata, valid_ac_hdr->keydata))
338 {
339 import_gpg = true;
340 insert_db_history = true;
341 mutt_str_replace(&peer->keydata, valid_ac_hdr->keydata);
342 }
343 }
344 }
345 else if (valid_ac_hdr)
346 {
347 import_gpg = true;
348 insert_db = true;
349 insert_db_history = true;
350 }
351
352 if (!(import_gpg || insert_db || update_db))
353 {
354 rc = 0;
355 goto cleanup;
356 }
357
358 if (!peer)
359 {
361 peer->last_seen = e->date_sent;
363 peer->keydata = mutt_str_dup(valid_ac_hdr->keydata);
364 peer->prefer_encrypt = valid_ac_hdr->prefer_encrypt;
365 }
366
367 if (import_gpg)
368 {
369 keyid = buf_pool_get();
371 goto cleanup;
372 mutt_str_replace(&peer->keyid, buf_string(keyid));
373 }
374
375 if (insert_db && mutt_autocrypt_db_peer_insert(from, peer))
376 goto cleanup;
377
378 if (update_db && mutt_autocrypt_db_peer_update(peer))
379 goto cleanup;
380
381 if (insert_db_history)
382 {
384 peerhist->email_msgid = mutt_str_dup(env->message_id);
385 peerhist->timestamp = e->date_sent;
386 peerhist->keydata = mutt_str_dup(peer->keydata);
387 if (mutt_autocrypt_db_peer_history_insert(from, peerhist))
388 goto cleanup;
389 }
390
391 rc = 0;
392
393cleanup:
396 buf_pool_release(&keyid);
397
398 return rc;
399}
struct AutocryptPeer * mutt_autocrypt_db_peer_new(void)
Create a new AutocryptPeer.
Definition db.c:522
int mutt_autocrypt_db_peer_insert(struct Address *addr, struct AutocryptPeer *peer)
Insert a peer into the Autocrypt database.
Definition db.c:621
int mutt_autocrypt_db_peer_update(struct AutocryptPeer *peer)
Update the peer info in an Autocrypt database.
Definition db.c:687
void mutt_autocrypt_db_peer_history_free(struct AutocryptPeerHistory **ptr)
Free an AutocryptPeerHistory.
Definition db.c:752
struct AutocryptPeerHistory * mutt_autocrypt_db_peer_history_new(void)
Create a new AutocryptPeerHistory.
Definition db.c:743
int mutt_autocrypt_db_peer_history_insert(struct Address *addr, struct AutocryptPeerHistory *peerhist)
Insert peer history into the Autocrypt database.
Definition db.c:771
static const char * buf_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition buffer.h:96
int mutt_autocrypt_gpgme_import_key(const char *keydata, struct Buffer *keyid)
Read a key from GPGME.
Definition gpgme.c:320
@ TYPE_MULTIPART
Type: 'multipart/*'.
Definition mime.h:37
time_t mutt_date_now(void)
Return the number of seconds since the Unix epoch.
Definition date.c:457
bool mutt_istr_equal(const char *a, const char *b)
Compare two strings, ignoring case.
Definition string.c:677
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition string.c:665
char * mutt_str_replace(char **p, const char *s)
Replace one string with another.
Definition string.c:284
struct Buffer * buf_pool_get(void)
Get a Buffer from the pool.
Definition pool.c:91
void buf_pool_release(struct Buffer **ptr)
Return a Buffer to the pool.
Definition pool.c:111
#define TAILQ_FIRST(head)
Definition queue.h:780
#define TAILQ_NEXT(elm, field)
Definition queue.h:889
struct Buffer * mailbox
Mailbox and host address.
Definition address.h:37
bool prefer_encrypt
User prefers encryption.
Definition envelope.h:47
Autocrypt peer history.
Definition lib.h:142
char * email_msgid
Message id of the email.
Definition lib.h:144
char * keydata
PGP Key data.
Definition lib.h:146
sqlite3_int64 timestamp
Timestamp of email.
Definition lib.h:145
sqlite3_int64 autocrypt_timestamp
When the email was sent.
Definition lib.h:129
sqlite3_int64 last_seen
When was the peer last seen.
Definition lib.h:128
bool prefer_encrypt
false = nopref, true = mutual
Definition lib.h:132
char * subtype
content-type subtype
Definition body.h:61
unsigned int type
content-type primary type, ContentType
Definition body.h:40
String manipulation buffer.
Definition buffer.h:36
time_t date_sent
Time when the message was sent (UTC)
Definition email.h:60
char * message_id
Message ID.
Definition envelope.h:73
struct AutocryptHeader * autocrypt
Autocrypt header.
Definition envelope.h:87
struct AddressList from
Email's 'From' list.
Definition envelope.h:59
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_autocrypt_process_gossip_header()

int mutt_autocrypt_process_gossip_header ( struct Email * e,
struct Envelope * prot_headers )

Parse an Autocrypt email gossip header.

Parameters
eEmail
prot_headersEnvelope with protected headers
Return values
0Success
-1Error

Definition at line 408 of file autocrypt.c.

409{
410 struct AutocryptPeer *peer = NULL;
411 struct AutocryptGossipHistory *gossip_hist = NULL;
412 struct Buffer *keyid = NULL;
413 struct Address *peer_addr = NULL;
414 struct Address ac_hdr_addr = { 0 };
415 ac_hdr_addr.mailbox = buf_new(NULL);
416 struct AddressList recips = TAILQ_HEAD_INITIALIZER(recips);
417 bool update_db = false, insert_db = false, insert_db_history = false, import_gpg = false;
418 int rc = -1;
419
420 const bool c_autocrypt = cs_subset_bool(NeoMutt->sub, "autocrypt");
421 if (!c_autocrypt)
422 {
423 rc = 0;
424 goto cleanup;
425 }
426
427 if (mutt_autocrypt_init(false))
428 goto cleanup;
429
430 if (!e || !e->env || !prot_headers)
431 {
432 rc = 0;
433 goto cleanup;
434 }
435
436 struct Envelope *env = e->env;
437
438 struct Address *from = TAILQ_FIRST(&env->from);
439 if (!from)
440 {
441 rc = 0;
442 goto cleanup;
443 }
444
445 /* Ignore emails that appear to be more than a week in the future,
446 * since they can block all future updates during that time. */
447 if (e->date_sent > (mutt_date_now() + (7 * 24 * 60 * 60)))
448 {
449 rc = 0;
450 goto cleanup;
451 }
452
453 keyid = buf_pool_get();
454
455 /* Normalize the recipient list for comparison */
456 mutt_addrlist_copy(&recips, &env->to, false);
457 mutt_addrlist_copy(&recips, &env->cc, false);
458 mutt_addrlist_copy(&recips, &env->reply_to, false);
460
461 for (struct AutocryptHeader *ac_hdr = prot_headers->autocrypt_gossip; ac_hdr;
462 ac_hdr = ac_hdr->next)
463 {
464 if (ac_hdr->invalid)
465 continue;
466
467 /* normalize for comparison against recipient list */
468 buf_strcpy(ac_hdr_addr.mailbox, ac_hdr->addr);
469 ac_hdr_addr.is_intl = true;
470 ac_hdr_addr.intl_checked = true;
472
473 /* Check to make sure the address is in the recipient list. */
474 TAILQ_FOREACH(peer_addr, &recips, entries)
475 {
476 if (buf_str_equal(peer_addr->mailbox, ac_hdr_addr.mailbox))
477 break;
478 }
479
480 if (!peer_addr)
481 continue;
482
483 if (mutt_autocrypt_db_peer_get(peer_addr, &peer) < 0)
484 goto cleanup;
485
486 if (peer)
487 {
488 if (e->date_sent <= peer->gossip_timestamp)
489 {
491 continue;
492 }
493
494 update_db = true;
495 peer->gossip_timestamp = e->date_sent;
496 /* This is slightly different from the autocrypt 1.1 spec.
497 * Avoid setting an empty peer.gossip_keydata with a value that matches
498 * the current peer.keydata. */
499 if ((peer->gossip_keydata && !mutt_str_equal(peer->gossip_keydata, ac_hdr->keydata)) ||
500 (!peer->gossip_keydata && !mutt_str_equal(peer->keydata, ac_hdr->keydata)))
501 {
502 import_gpg = true;
503 insert_db_history = true;
504 mutt_str_replace(&peer->gossip_keydata, ac_hdr->keydata);
505 }
506 }
507 else
508 {
509 import_gpg = true;
510 insert_db = true;
511 insert_db_history = true;
512 }
513
514 if (!peer)
515 {
517 peer->gossip_timestamp = e->date_sent;
518 peer->gossip_keydata = mutt_str_dup(ac_hdr->keydata);
519 }
520
521 if (import_gpg)
522 {
524 goto cleanup;
526 }
527
528 if (insert_db && mutt_autocrypt_db_peer_insert(peer_addr, peer))
529 goto cleanup;
530
531 if (update_db && mutt_autocrypt_db_peer_update(peer))
532 goto cleanup;
533
534 if (insert_db_history)
535 {
537 gossip_hist->sender_email_addr = buf_strdup(from->mailbox);
538 gossip_hist->email_msgid = mutt_str_dup(env->message_id);
539 gossip_hist->timestamp = e->date_sent;
540 gossip_hist->gossip_keydata = mutt_str_dup(peer->gossip_keydata);
541 if (mutt_autocrypt_db_gossip_history_insert(peer_addr, gossip_hist))
542 goto cleanup;
543 }
544
547 buf_reset(keyid);
548 update_db = false;
549 insert_db = false;
550 insert_db_history = false;
551 import_gpg = false;
552 }
553
554 rc = 0;
555
556cleanup:
557 buf_free(&ac_hdr_addr.mailbox);
558 mutt_addrlist_clear(&recips);
561 buf_pool_release(&keyid);
562
563 return rc;
564}
void mutt_autocrypt_db_normalize_addrlist(struct AddressList *al)
Normalise a list of Email Addresses.
Definition db.c:179
struct AutocryptGossipHistory * mutt_autocrypt_db_gossip_history_new(void)
Create a new AutocryptGossipHistory.
Definition db.c:824
int mutt_autocrypt_db_gossip_history_insert(struct Address *addr, struct AutocryptGossipHistory *gossip_hist)
Insert a gossip history into the Autocrypt database.
Definition db.c:853
void mutt_autocrypt_db_normalize_addr(struct Address *a)
Normalise an Email Address.
Definition db.c:168
void mutt_autocrypt_db_gossip_history_free(struct AutocryptGossipHistory **ptr)
Free an AutocryptGossipHistory.
Definition db.c:833
void buf_reset(struct Buffer *buf)
Reset an existing Buffer.
Definition buffer.c:76
void buf_free(struct Buffer **ptr)
Deallocates a buffer.
Definition buffer.c:319
struct Buffer * buf_new(const char *str)
Allocate a new Buffer.
Definition buffer.c:304
bool buf_str_equal(const struct Buffer *a, const struct Buffer *b)
Return if two buffers are equal.
Definition buffer.c:683
size_t buf_strcpy(struct Buffer *buf, const char *s)
Copy a string into a Buffer.
Definition buffer.c:395
char * buf_strdup(const struct Buffer *buf)
Copy a Buffer's string.
Definition buffer.c:571
bool intl_checked
Checked for IDN?
Definition address.h:40
bool is_intl
International Domain Name.
Definition address.h:39
Autocrypt gossip history.
Definition lib.h:153
char * email_msgid
Sender's email's message id.
Definition lib.h:156
char * sender_email_addr
Sender's email address.
Definition lib.h:155
char * gossip_keydata
Gossip Key data.
Definition lib.h:158
sqlite3_int64 timestamp
Timestamp of sender's email.
Definition lib.h:157
sqlite3_int64 gossip_timestamp
Timestamp of Gossip header.
Definition lib.h:133
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_autocrypt_set_sign_as_default_key()

int mutt_autocrypt_set_sign_as_default_key ( struct Email * e)

Set the Autocrypt default key for signing.

Parameters
eEmail
Return values
0Success
-1Error

Definition at line 714 of file autocrypt.c.

715{
716 int rc = -1;
717 struct AutocryptAccount *account = NULL;
718
719 const bool c_autocrypt = cs_subset_bool(NeoMutt->sub, "autocrypt");
720 if (!c_autocrypt || mutt_autocrypt_init(false) || !e)
721 return -1;
722
723 struct Address *from = TAILQ_FIRST(&e->env->from);
724 if (!from || TAILQ_NEXT(from, entries))
725 return -1;
726
727 if (mutt_autocrypt_db_account_get(from, &account) <= 0)
728 goto cleanup;
729 if (!account->keyid)
730 goto cleanup;
731 if (!account->enabled)
732 goto cleanup;
733
736
737 rc = 0;
738
739cleanup:
741 return rc;
742}
char * AutocryptSignAs
Autocrypt Key id to sign as.
Definition config.c:37
char * AutocryptDefaultKey
Autocrypt default key id (used for postponing messages)
Definition config.c:38
char * keyid
PGP Key id.
Definition lib.h:115
bool enabled
Is this account enabled.
Definition lib.h:118
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_autocrypt_ui_recommendation()

enum AutocryptRec mutt_autocrypt_ui_recommendation ( const struct Email * e,
char ** keylist )

Get the recommended action for an Email.

Parameters
[in]eEmail
[out]keylistList of Autocrypt key ids
Return values
enumAutocryptRec Recommendation, e.g. AUTOCRYPT_REC_AVAILABLE

If the recommendataion is > NO and keylist is not NULL, keylist will be populated with the autocrypt keyids.

Definition at line 575 of file autocrypt.c.

576{
578 struct AutocryptAccount *account = NULL;
579 struct AutocryptPeer *peer = NULL;
580 struct Address *recip = NULL;
581 bool all_encrypt = true, has_discourage = false;
582 const char *matching_key = NULL;
583 struct AddressList recips = TAILQ_HEAD_INITIALIZER(recips);
584 struct Buffer *keylist_buf = NULL;
585
586 const bool c_autocrypt = cs_subset_bool(NeoMutt->sub, "autocrypt");
587 if (!c_autocrypt || mutt_autocrypt_init(false) || !e)
588 {
589 if (keylist)
590 {
591 /* L10N: Error displayed if the user tries to force sending an Autocrypt
592 email when the engine is not available. */
593 mutt_message(_("Autocrypt is not available"));
594 }
595 return AUTOCRYPT_REC_OFF;
596 }
597
598 struct Address *from = TAILQ_FIRST(&e->env->from);
599 if (!from || TAILQ_NEXT(from, entries))
600 {
601 if (keylist)
602 mutt_message(_("Autocrypt is not available"));
603 return AUTOCRYPT_REC_OFF;
604 }
605
607 {
608 if (keylist)
609 mutt_message(_("Autocrypt is not available"));
610 return AUTOCRYPT_REC_OFF;
611 }
612
613 if ((mutt_autocrypt_db_account_get(from, &account) <= 0) || !account->enabled)
614 {
615 if (keylist)
616 {
617 /* L10N: Error displayed if the user tries to force sending an Autocrypt
618 email when the account does not exist or is not enabled.
619 %s is the From email address used to look up the Autocrypt account.
620 */
621 mutt_message(_("Autocrypt is not enabled for %s"), buf_string(from->mailbox));
622 }
623 goto cleanup;
624 }
625
626 keylist_buf = buf_pool_get();
627 buf_addstr(keylist_buf, account->keyid);
628
629 mutt_addrlist_copy(&recips, &e->env->to, false);
630 mutt_addrlist_copy(&recips, &e->env->cc, false);
631 mutt_addrlist_copy(&recips, &e->env->bcc, false);
632
633 rc = AUTOCRYPT_REC_NO;
634 if (TAILQ_EMPTY(&recips))
635 goto cleanup;
636
637 TAILQ_FOREACH(recip, &recips, entries)
638 {
639 if (mutt_autocrypt_db_peer_get(recip, &peer) <= 0)
640 {
641 if (keylist)
642 {
643 /* L10N: s is an email address. Autocrypt is scanning for the keyids
644 to use to encrypt, but it can't find a valid keyid for this address.
645 The message is printed and they are returned to the compose menu. */
646 mutt_message(_("No (valid) autocrypt key found for %s"),
647 buf_string(recip->mailbox));
648 }
649 goto cleanup;
650 }
651
653 {
654 matching_key = peer->keyid;
655
656 if (!(peer->last_seen && peer->autocrypt_timestamp) ||
657 (peer->last_seen - peer->autocrypt_timestamp > (35 * 24 * 60 * 60)))
658 {
659 has_discourage = true;
660 all_encrypt = false;
661 }
662
663 if (!account->prefer_encrypt || !peer->prefer_encrypt)
664 all_encrypt = false;
665 }
667 {
668 matching_key = peer->gossip_keyid;
669
670 has_discourage = true;
671 all_encrypt = false;
672 }
673 else
674 {
675 if (keylist)
676 {
677 mutt_message(_("No (valid) autocrypt key found for %s"),
678 buf_string(recip->mailbox));
679 }
680 goto cleanup;
681 }
682
683 if (!buf_is_empty(keylist_buf))
684 buf_addch(keylist_buf, ' ');
685 buf_addstr(keylist_buf, matching_key);
686
688 }
689
690 if (all_encrypt)
692 else if (has_discourage)
694 else
696
697 if (keylist)
698 mutt_str_replace(keylist, buf_string(keylist_buf));
699
700cleanup:
702 mutt_addrlist_clear(&recips);
704 buf_pool_release(&keylist_buf);
705 return rc;
706}
AutocryptRec
Recommendation.
Definition lib.h:165
bool buf_is_empty(const struct Buffer *buf)
Is the Buffer empty?
Definition buffer.c:291
size_t buf_addch(struct Buffer *buf, char c)
Add a single character to a Buffer.
Definition buffer.c:241
size_t buf_addstr(struct Buffer *buf, const char *s)
Add a string to a Buffer.
Definition buffer.c:226
#define mutt_message(...)
Definition logging2.h:93
#define _(a)
Definition message.h:28
#define APPLICATION_SMIME
Use SMIME to encrypt/sign.
Definition lib.h:99
#define TAILQ_EMPTY(head)
Definition queue.h:778
bool prefer_encrypt
false = nopref, true = mutual
Definition lib.h:117
SecurityFlags security
bit 0-10: flags, bit 11,12: application, bit 13: traditional pgp See: ncrypt/lib.h pgplib....
Definition email.h:43
struct AddressList bcc
Email's 'Bcc' list.
Definition envelope.h:62
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_autocrypt_write_autocrypt_header()

int mutt_autocrypt_write_autocrypt_header ( struct Envelope * env,
FILE * fp )

Write the Autocrypt header to a file.

Parameters
envEnvelope
fpFile to write to
Return values
0Success
-1Error

Definition at line 780 of file autocrypt.c.

781{
782 int rc = -1;
783 struct AutocryptAccount *account = NULL;
784
785 const bool c_autocrypt = cs_subset_bool(NeoMutt->sub, "autocrypt");
786 if (!c_autocrypt || mutt_autocrypt_init(false) || !env)
787 return -1;
788
789 struct Address *from = TAILQ_FIRST(&env->from);
790 if (!from || TAILQ_NEXT(from, entries))
791 return -1;
792
793 if (mutt_autocrypt_db_account_get(from, &account) <= 0)
794 goto cleanup;
795 if (!account->keydata)
796 goto cleanup;
797 if (!account->enabled)
798 goto cleanup;
799
800 fputs("Autocrypt: ", fp);
802 account->keydata);
803
804 rc = 0;
805
806cleanup:
808 return rc;
809}
static void write_autocrypt_header_line(FILE *fp, const char *addr, bool prefer_encrypt, const char *keydata)
Write an Autocrypt header to a file.
Definition autocrypt.c:751
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_autocrypt_write_gossip_headers()

int mutt_autocrypt_write_gossip_headers ( struct Envelope * env,
FILE * fp )

Write the Autocrypt gossip headers to a file.

Parameters
envEnvelope
fpFile to write to
Return values
0Success
-1Error

Definition at line 818 of file autocrypt.c.

819{
820 const bool c_autocrypt = cs_subset_bool(NeoMutt->sub, "autocrypt");
821 if (!c_autocrypt || mutt_autocrypt_init(false) || !env)
822 return -1;
823
824 for (struct AutocryptHeader *gossip = env->autocrypt_gossip; gossip;
825 gossip = gossip->next)
826 {
827 fputs("Autocrypt-Gossip: ", fp);
828 write_autocrypt_header_line(fp, gossip->addr, 0, gossip->keydata);
829 }
830
831 return 0;
832}
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ AutocryptSignAs

char* AutocryptSignAs
extern

Autocrypt Key id to sign as.

Definition at line 37 of file config.c.

◆ AutocryptDefaultKey

char* AutocryptDefaultKey
extern

Autocrypt default key id (used for postponing messages)

Definition at line 38 of file config.c.