NeoMutt  2024-04-25-89-g194907
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
lib.h File Reference

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

#include <sqlite3.h>
#include <stdbool.h>
#include <stdio.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

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 157 of file lib.h.

158{
164};
@ AUTOCRYPT_REC_DISCOURAGE
Prefer not to use Autocrypt.
Definition: lib.h:161
@ AUTOCRYPT_REC_NO
Do no use Autocrypt.
Definition: lib.h:160
@ AUTOCRYPT_REC_OFF
No recommendations.
Definition: lib.h:159
@ AUTOCRYPT_REC_AVAILABLE
Autocrypt is available.
Definition: lib.h:162
@ AUTOCRYPT_REC_YES
Autocrypt should be used.
Definition: lib.h:163

Function Documentation

◆ mutt_autocrypt_cleanup()

void mutt_autocrypt_cleanup ( void  )

Shutdown Autocrypt.

Definition at line 131 of file autocrypt.c.

132{
134}
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 825 of file autocrypt.c.

826{
827 int rc = -1;
828 struct AutocryptPeer *peer = NULL;
829 struct AutocryptAccount *account = NULL;
830 struct Address *recip = NULL;
831
832 const bool c_autocrypt = cs_subset_bool(NeoMutt->sub, "autocrypt");
833 if (!c_autocrypt || mutt_autocrypt_init(false) || !e)
834 return -1;
835
836 struct Envelope *mime_headers = e->body->mime_headers;
837 if (!mime_headers)
838 mime_headers = e->body->mime_headers = mutt_env_new();
840
841 struct AddressList recips = TAILQ_HEAD_INITIALIZER(recips);
842
843 mutt_addrlist_copy(&recips, &e->env->to, false);
844 mutt_addrlist_copy(&recips, &e->env->cc, false);
845
846 TAILQ_FOREACH(recip, &recips, entries)
847 {
848 /* At this point, we just accept missing keys and include what we can. */
849 if (mutt_autocrypt_db_peer_get(recip, &peer) <= 0)
850 continue;
851
852 const char *keydata = NULL;
854 keydata = peer->keydata;
856 keydata = peer->gossip_keydata;
857
858 if (keydata)
859 {
860 struct AutocryptHeader *gossip = mutt_autocrypthdr_new();
861 gossip->addr = mutt_str_dup(peer->email_addr);
862 gossip->keydata = mutt_str_dup(keydata);
863 gossip->next = mime_headers->autocrypt_gossip;
864 mime_headers->autocrypt_gossip = gossip;
865 }
866
868 }
869
870 TAILQ_FOREACH(recip, &e->env->reply_to, entries)
871 {
872 const char *addr = NULL;
873 const char *keydata = NULL;
874 if (mutt_autocrypt_db_account_get(recip, &account) > 0)
875 {
876 addr = account->email_addr;
877 keydata = account->keydata;
878 }
879 else if (mutt_autocrypt_db_peer_get(recip, &peer) > 0)
880 {
881 addr = peer->email_addr;
883 keydata = peer->keydata;
885 keydata = peer->gossip_keydata;
886 }
887
888 if (keydata)
889 {
890 struct AutocryptHeader *gossip = mutt_autocrypthdr_new();
891 gossip->addr = mutt_str_dup(addr);
892 gossip->keydata = mutt_str_dup(keydata);
893 gossip->next = mime_headers->autocrypt_gossip;
894 mime_headers->autocrypt_gossip = gossip;
895 }
898 }
899
900 mutt_addrlist_clear(&recips);
903 return rc;
904}
void mutt_addrlist_copy(struct AddressList *dst, const struct AddressList *src, bool prune)
Copy a list of addresses into another list.
Definition: address.c:765
void mutt_addrlist_clear(struct AddressList *al)
Unlink and free all Address in an AddressList.
Definition: address.c:1460
int mutt_autocrypt_db_account_get(struct Address *addr, struct AutocryptAccount **account)
Get Autocrypt Account data from the database.
Definition: db.c:266
int mutt_autocrypt_db_peer_get(struct Address *addr, struct AutocryptPeer **peer)
Get peer info from the Autocrypt database.
Definition: db.c:559
void mutt_autocrypt_db_account_free(struct AutocryptAccount **ptr)
Free an AutocryptAccount.
Definition: db.c:247
void mutt_autocrypt_db_peer_free(struct AutocryptPeer **ptr)
Free an AutocryptPeer.
Definition: db.c:537
int mutt_autocrypt_init(bool can_create)
Initialise Autocrypt.
Definition: autocrypt.c:99
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:46
struct AutocryptHeader * mutt_autocrypthdr_new(void)
Create a new AutocryptHeader.
Definition: envelope.c:95
void mutt_autocrypthdr_free(struct AutocryptHeader **ptr)
Free an AutocryptHeader.
Definition: envelope.c:104
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:253
#define TAILQ_FOREACH(var, head, field)
Definition: queue.h:725
#define TAILQ_HEAD_INITIALIZER(head)
Definition: queue.h:637
An email address.
Definition: address.h:36
Autocrypt account.
Definition: lib.h:107
char * email_addr
Email address.
Definition: lib.h:108
char * keydata
PGP Key data.
Definition: lib.h:110
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:119
char * gossip_keydata
Gossip Key data.
Definition: lib.h:128
char * keyid
PGP Key id.
Definition: lib.h:123
char * gossip_keyid
Gossip Key id.
Definition: lib.h:127
char * keydata
PGP Key data.
Definition: lib.h:124
char * email_addr
Email address.
Definition: lib.h:120
struct Envelope * mime_headers
Memory hole protected headers.
Definition: body.h:75
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:42
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:46
+ 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 99 of file autocrypt.c.

100{
101 if (AutocryptDB)
102 return 0;
103
104 const bool c_autocrypt = cs_subset_bool(NeoMutt->sub, "autocrypt");
105 const char *const c_autocrypt_dir = cs_subset_path(NeoMutt->sub, "autocrypt_dir");
106 if (!c_autocrypt || !c_autocrypt_dir)
107 return -1;
108
110
111 if (autocrypt_dir_init(can_create))
112 goto bail;
113
115 goto bail;
116
117 if (mutt_autocrypt_db_init(can_create))
118 goto bail;
119
120 return 0;
121
122bail:
123 cs_subset_str_native_set(NeoMutt->sub, "autocrypt", false, NULL);
125 return -1;
126}
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
void mutt_flushinp(void)
Empty all the keyboard buffers.
Definition: get.c:58
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:297
+ 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 258 of file autocrypt.c.

259{
260 struct AutocryptHeader *valid_ac_hdr = NULL;
261 struct AutocryptPeer *peer = NULL;
262 struct AutocryptPeerHistory *peerhist = NULL;
263 struct Buffer *keyid = NULL;
264 bool update_db = false, insert_db = false, insert_db_history = false, import_gpg = false;
265 int rc = -1;
266
267 const bool c_autocrypt = cs_subset_bool(NeoMutt->sub, "autocrypt");
268 if (!c_autocrypt)
269 return 0;
270
271 if (mutt_autocrypt_init(false))
272 return -1;
273
274 if (!e || !e->body || !env)
275 return 0;
276
277 /* 1.1 spec says to skip emails with more than one From header */
278 struct Address *from = TAILQ_FIRST(&env->from);
279 if (!from || TAILQ_NEXT(from, entries))
280 return 0;
281
282 /* 1.1 spec also says to skip multipart/report emails */
283 if ((e->body->type == TYPE_MULTIPART) && mutt_istr_equal(e->body->subtype, "report"))
284 {
285 return 0;
286 }
287
288 /* Ignore emails that appear to be more than a week in the future,
289 * since they can block all future updates during that time. */
290 if (e->date_sent > (mutt_date_now() + (7 * 24 * 60 * 60)))
291 return 0;
292
293 for (struct AutocryptHeader *ac_hdr = env->autocrypt; ac_hdr; ac_hdr = ac_hdr->next)
294 {
295 if (ac_hdr->invalid)
296 continue;
297
298 /* NOTE: this assumes the processing is occurring right after
299 * mutt_parse_rfc822_line() and the from ADDR is still in the same
300 * form (intl) as the autocrypt header addr field */
301 if (!mutt_istr_equal(buf_string(from->mailbox), ac_hdr->addr))
302 continue;
303
304 /* 1.1 spec says ignore all, if more than one valid header is found. */
305 if (valid_ac_hdr)
306 {
307 valid_ac_hdr = NULL;
308 break;
309 }
310 valid_ac_hdr = ac_hdr;
311 }
312
313 if (mutt_autocrypt_db_peer_get(from, &peer) < 0)
314 goto cleanup;
315
316 if (peer)
317 {
318 if (e->date_sent <= peer->autocrypt_timestamp)
319 {
320 rc = 0;
321 goto cleanup;
322 }
323
324 if (e->date_sent > peer->last_seen)
325 {
326 update_db = true;
327 peer->last_seen = e->date_sent;
328 }
329
330 if (valid_ac_hdr)
331 {
332 update_db = true;
334 peer->prefer_encrypt = valid_ac_hdr->prefer_encrypt;
335 if (!mutt_str_equal(peer->keydata, valid_ac_hdr->keydata))
336 {
337 import_gpg = true;
338 insert_db_history = true;
339 mutt_str_replace(&peer->keydata, valid_ac_hdr->keydata);
340 }
341 }
342 }
343 else if (valid_ac_hdr)
344 {
345 import_gpg = true;
346 insert_db = true;
347 insert_db_history = true;
348 }
349
350 if (!(import_gpg || insert_db || update_db))
351 {
352 rc = 0;
353 goto cleanup;
354 }
355
356 if (!peer)
357 {
359 peer->last_seen = e->date_sent;
361 peer->keydata = mutt_str_dup(valid_ac_hdr->keydata);
362 peer->prefer_encrypt = valid_ac_hdr->prefer_encrypt;
363 }
364
365 if (import_gpg)
366 {
367 keyid = buf_pool_get();
369 goto cleanup;
370 mutt_str_replace(&peer->keyid, buf_string(keyid));
371 }
372
373 if (insert_db && mutt_autocrypt_db_peer_insert(from, peer))
374 goto cleanup;
375
376 if (update_db && mutt_autocrypt_db_peer_update(peer))
377 goto cleanup;
378
379 if (insert_db_history)
380 {
382 peerhist->email_msgid = mutt_str_dup(env->message_id);
383 peerhist->timestamp = e->date_sent;
384 peerhist->keydata = mutt_str_dup(peer->keydata);
385 if (mutt_autocrypt_db_peer_history_insert(from, peerhist))
386 goto cleanup;
387 }
388
389 rc = 0;
390
391cleanup:
394 buf_pool_release(&keyid);
395
396 return rc;
397}
struct AutocryptPeer * mutt_autocrypt_db_peer_new(void)
Create a new AutocryptPeer.
Definition: db.c:528
int mutt_autocrypt_db_peer_insert(struct Address *addr, struct AutocryptPeer *peer)
Insert a peer into the Autocrypt database.
Definition: db.c:627
int mutt_autocrypt_db_peer_update(struct AutocryptPeer *peer)
Update the peer info in an Autocrypt database.
Definition: db.c:693
void mutt_autocrypt_db_peer_history_free(struct AutocryptPeerHistory **ptr)
Free an AutocryptPeerHistory.
Definition: db.c:758
struct AutocryptPeerHistory * mutt_autocrypt_db_peer_history_new(void)
Create a new AutocryptPeerHistory.
Definition: db.c:749
int mutt_autocrypt_db_peer_history_insert(struct Address *addr, struct AutocryptPeerHistory *peerhist)
Insert peer history into the Autocrypt database.
Definition: db.c:777
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:456
bool mutt_istr_equal(const char *a, const char *b)
Compare two strings, ignoring case.
Definition: string.c:672
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:660
char * mutt_str_replace(char **p, const char *s)
Replace one string with another.
Definition: string.c:280
struct Buffer * buf_pool_get(void)
Get a Buffer from the pool.
Definition: pool.c:81
void buf_pool_release(struct Buffer **ptr)
Return a Buffer to the pool.
Definition: pool.c:94
#define TAILQ_FIRST(head)
Definition: queue.h:723
#define TAILQ_NEXT(elm, field)
Definition: queue.h:832
struct Buffer * mailbox
Mailbox and host address.
Definition: address.h:38
bool prefer_encrypt
User prefers encryption.
Definition: envelope.h:47
Autocrypt peer history.
Definition: lib.h:135
char * email_msgid
Message id of the email.
Definition: lib.h:137
char * keydata
PGP Key data.
Definition: lib.h:139
sqlite3_int64 timestamp
Timestamp of email.
Definition: lib.h:138
sqlite3_int64 autocrypt_timestamp
When the email was sent.
Definition: lib.h:122
sqlite3_int64 last_seen
When was the peer last seen.
Definition: lib.h:121
bool prefer_encrypt
false = nopref, true = mutual
Definition: lib.h:125
char * subtype
content-type subtype
Definition: body.h:60
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 406 of file autocrypt.c.

407{
408 struct AutocryptPeer *peer = NULL;
409 struct AutocryptGossipHistory *gossip_hist = NULL;
410 struct Address *peer_addr = NULL;
411 struct Address ac_hdr_addr = { 0 };
412 bool update_db = false, insert_db = false, insert_db_history = false, import_gpg = false;
413 int rc = -1;
414
415 const bool c_autocrypt = cs_subset_bool(NeoMutt->sub, "autocrypt");
416 if (!c_autocrypt)
417 return 0;
418
419 if (mutt_autocrypt_init(false))
420 return -1;
421
422 if (!e || !e->env || !prot_headers)
423 return 0;
424
425 struct Envelope *env = e->env;
426
427 struct Address *from = TAILQ_FIRST(&env->from);
428 if (!from)
429 return 0;
430
431 /* Ignore emails that appear to be more than a week in the future,
432 * since they can block all future updates during that time. */
433 if (e->date_sent > (mutt_date_now() + (7 * 24 * 60 * 60)))
434 return 0;
435
436 struct Buffer *keyid = buf_pool_get();
437
438 struct AddressList recips = TAILQ_HEAD_INITIALIZER(recips);
439
440 /* Normalize the recipient list for comparison */
441 mutt_addrlist_copy(&recips, &env->to, false);
442 mutt_addrlist_copy(&recips, &env->cc, false);
443 mutt_addrlist_copy(&recips, &env->reply_to, false);
445
446 for (struct AutocryptHeader *ac_hdr = prot_headers->autocrypt_gossip; ac_hdr;
447 ac_hdr = ac_hdr->next)
448 {
449 if (ac_hdr->invalid)
450 continue;
451
452 /* normalize for comparison against recipient list */
453 buf_strcpy(ac_hdr_addr.mailbox, ac_hdr->addr);
454 ac_hdr_addr.is_intl = true;
455 ac_hdr_addr.intl_checked = true;
457
458 /* Check to make sure the address is in the recipient list. */
459 TAILQ_FOREACH(peer_addr, &recips, entries)
460 {
461 if (buf_str_equal(peer_addr->mailbox, ac_hdr_addr.mailbox))
462 break;
463 }
464
465 if (!peer_addr)
466 continue;
467
468 if (mutt_autocrypt_db_peer_get(peer_addr, &peer) < 0)
469 goto cleanup;
470
471 if (peer)
472 {
473 if (e->date_sent <= peer->gossip_timestamp)
474 {
476 continue;
477 }
478
479 update_db = true;
480 peer->gossip_timestamp = e->date_sent;
481 /* This is slightly different from the autocrypt 1.1 spec.
482 * Avoid setting an empty peer.gossip_keydata with a value that matches
483 * the current peer.keydata. */
484 if ((peer->gossip_keydata && !mutt_str_equal(peer->gossip_keydata, ac_hdr->keydata)) ||
485 (!peer->gossip_keydata && !mutt_str_equal(peer->keydata, ac_hdr->keydata)))
486 {
487 import_gpg = true;
488 insert_db_history = true;
489 mutt_str_replace(&peer->gossip_keydata, ac_hdr->keydata);
490 }
491 }
492 else
493 {
494 import_gpg = true;
495 insert_db = true;
496 insert_db_history = true;
497 }
498
499 if (!peer)
500 {
502 peer->gossip_timestamp = e->date_sent;
503 peer->gossip_keydata = mutt_str_dup(ac_hdr->keydata);
504 }
505
506 if (import_gpg)
507 {
509 goto cleanup;
511 }
512
513 if (insert_db && mutt_autocrypt_db_peer_insert(peer_addr, peer))
514 goto cleanup;
515
516 if (update_db && mutt_autocrypt_db_peer_update(peer))
517 goto cleanup;
518
519 if (insert_db_history)
520 {
522 gossip_hist->sender_email_addr = buf_strdup(from->mailbox);
523 gossip_hist->email_msgid = mutt_str_dup(env->message_id);
524 gossip_hist->timestamp = e->date_sent;
525 gossip_hist->gossip_keydata = mutt_str_dup(peer->gossip_keydata);
526 if (mutt_autocrypt_db_gossip_history_insert(peer_addr, gossip_hist))
527 goto cleanup;
528 }
529
532 buf_reset(keyid);
533 update_db = false;
534 insert_db = false;
535 insert_db_history = false;
536 import_gpg = false;
537 }
538
539 rc = 0;
540
541cleanup:
542 FREE(&ac_hdr_addr.mailbox);
543 mutt_addrlist_clear(&recips);
546 buf_pool_release(&keyid);
547
548 return rc;
549}
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:830
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:859
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:839
void buf_reset(struct Buffer *buf)
Reset an existing Buffer.
Definition: buffer.c:76
bool buf_str_equal(const struct Buffer *a, const struct Buffer *b)
Return if two buffers are equal.
Definition: buffer.c:685
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
#define FREE(x)
Definition: memory.h:45
bool intl_checked
Checked for IDN?
Definition: address.h:41
bool is_intl
International Domain Name.
Definition: address.h:40
Autocrypt gossip history.
Definition: lib.h:146
char * email_msgid
Sender's email's message id.
Definition: lib.h:149
char * sender_email_addr
Sender's email address.
Definition: lib.h:148
char * gossip_keydata
Gossip Key data.
Definition: lib.h:151
sqlite3_int64 timestamp
Timestamp of sender's email.
Definition: lib.h:150
sqlite3_int64 gossip_timestamp
Timestamp of Gossip header.
Definition: lib.h:126
+ 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 699 of file autocrypt.c.

700{
701 int rc = -1;
702 struct AutocryptAccount *account = NULL;
703
704 const bool c_autocrypt = cs_subset_bool(NeoMutt->sub, "autocrypt");
705 if (!c_autocrypt || mutt_autocrypt_init(false) || !e)
706 return -1;
707
708 struct Address *from = TAILQ_FIRST(&e->env->from);
709 if (!from || TAILQ_NEXT(from, entries))
710 return -1;
711
712 if (mutt_autocrypt_db_account_get(from, &account) <= 0)
713 goto cleanup;
714 if (!account->keyid)
715 goto cleanup;
716 if (!account->enabled)
717 goto cleanup;
718
721
722 rc = 0;
723
724cleanup:
726 return rc;
727}
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:109
bool enabled
Is this account enabled.
Definition: lib.h:112
+ 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 560 of file autocrypt.c.

561{
563 struct AutocryptAccount *account = NULL;
564 struct AutocryptPeer *peer = NULL;
565 struct Address *recip = NULL;
566 bool all_encrypt = true, has_discourage = false;
567 const char *matching_key = NULL;
568 struct AddressList recips = TAILQ_HEAD_INITIALIZER(recips);
569 struct Buffer *keylist_buf = NULL;
570
571 const bool c_autocrypt = cs_subset_bool(NeoMutt->sub, "autocrypt");
572 if (!c_autocrypt || mutt_autocrypt_init(false) || !e)
573 {
574 if (keylist)
575 {
576 /* L10N: Error displayed if the user tries to force sending an Autocrypt
577 email when the engine is not available. */
578 mutt_message(_("Autocrypt is not available"));
579 }
580 return AUTOCRYPT_REC_OFF;
581 }
582
583 struct Address *from = TAILQ_FIRST(&e->env->from);
584 if (!from || TAILQ_NEXT(from, entries))
585 {
586 if (keylist)
587 mutt_message(_("Autocrypt is not available"));
588 return AUTOCRYPT_REC_OFF;
589 }
590
592 {
593 if (keylist)
594 mutt_message(_("Autocrypt is not available"));
595 return AUTOCRYPT_REC_OFF;
596 }
597
598 if ((mutt_autocrypt_db_account_get(from, &account) <= 0) || !account->enabled)
599 {
600 if (keylist)
601 {
602 /* L10N: Error displayed if the user tries to force sending an Autocrypt
603 email when the account does not exist or is not enabled.
604 %s is the From email address used to look up the Autocrypt account.
605 */
606 mutt_message(_("Autocrypt is not enabled for %s"), buf_string(from->mailbox));
607 }
608 goto cleanup;
609 }
610
611 keylist_buf = buf_pool_get();
612 buf_addstr(keylist_buf, account->keyid);
613
614 mutt_addrlist_copy(&recips, &e->env->to, false);
615 mutt_addrlist_copy(&recips, &e->env->cc, false);
616 mutt_addrlist_copy(&recips, &e->env->bcc, false);
617
618 rc = AUTOCRYPT_REC_NO;
619 if (TAILQ_EMPTY(&recips))
620 goto cleanup;
621
622 TAILQ_FOREACH(recip, &recips, entries)
623 {
624 if (mutt_autocrypt_db_peer_get(recip, &peer) <= 0)
625 {
626 if (keylist)
627 {
628 /* L10N: s is an email address. Autocrypt is scanning for the keyids
629 to use to encrypt, but it can't find a valid keyid for this address.
630 The message is printed and they are returned to the compose menu. */
631 mutt_message(_("No (valid) autocrypt key found for %s"),
632 buf_string(recip->mailbox));
633 }
634 goto cleanup;
635 }
636
638 {
639 matching_key = peer->keyid;
640
641 if (!(peer->last_seen && peer->autocrypt_timestamp) ||
642 (peer->last_seen - peer->autocrypt_timestamp > (35 * 24 * 60 * 60)))
643 {
644 has_discourage = true;
645 all_encrypt = false;
646 }
647
648 if (!account->prefer_encrypt || !peer->prefer_encrypt)
649 all_encrypt = false;
650 }
652 {
653 matching_key = peer->gossip_keyid;
654
655 has_discourage = true;
656 all_encrypt = false;
657 }
658 else
659 {
660 if (keylist)
661 {
662 mutt_message(_("No (valid) autocrypt key found for %s"),
663 buf_string(recip->mailbox));
664 }
665 goto cleanup;
666 }
667
668 if (!buf_is_empty(keylist_buf))
669 buf_addch(keylist_buf, ' ');
670 buf_addstr(keylist_buf, matching_key);
671
673 }
674
675 if (all_encrypt)
677 else if (has_discourage)
679 else
681
682 if (keylist)
683 mutt_str_replace(keylist, buf_string(keylist_buf));
684
685cleanup:
687 mutt_addrlist_clear(&recips);
689 buf_pool_release(&keylist_buf);
690 return rc;
691}
AutocryptRec
Recommendation.
Definition: lib.h:158
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:91
#define _(a)
Definition: message.h:28
#define APPLICATION_SMIME
Use SMIME to encrypt/sign.
Definition: lib.h:91
#define TAILQ_EMPTY(head)
Definition: queue.h:721
bool prefer_encrypt
false = nopref, true = mutual
Definition: lib.h:111
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 765 of file autocrypt.c.

766{
767 int rc = -1;
768 struct AutocryptAccount *account = NULL;
769
770 const bool c_autocrypt = cs_subset_bool(NeoMutt->sub, "autocrypt");
771 if (!c_autocrypt || mutt_autocrypt_init(false) || !env)
772 return -1;
773
774 struct Address *from = TAILQ_FIRST(&env->from);
775 if (!from || TAILQ_NEXT(from, entries))
776 return -1;
777
778 if (mutt_autocrypt_db_account_get(from, &account) <= 0)
779 goto cleanup;
780 if (!account->keydata)
781 goto cleanup;
782 if (!account->enabled)
783 goto cleanup;
784
785 fputs("Autocrypt: ", fp);
787 account->keydata);
788
789 rc = 0;
790
791cleanup:
793 return rc;
794}
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:736
+ 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 803 of file autocrypt.c.

804{
805 const bool c_autocrypt = cs_subset_bool(NeoMutt->sub, "autocrypt");
806 if (!c_autocrypt || mutt_autocrypt_init(false) || !env)
807 return -1;
808
809 for (struct AutocryptHeader *gossip = env->autocrypt_gossip; gossip;
810 gossip = gossip->next)
811 {
812 fputs("Autocrypt-Gossip: ", fp);
813 write_autocrypt_header_line(fp, gossip->addr, 0, gossip->keydata);
814 }
815
816 return 0;
817}
+ 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.