NeoMutt  2024-10-02-37-gfa9146
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 129 of file autocrypt.c.

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

824{
825 int rc = -1;
826 struct AutocryptPeer *peer = NULL;
827 struct AutocryptAccount *account = NULL;
828 struct Address *recip = NULL;
829
830 const bool c_autocrypt = cs_subset_bool(NeoMutt->sub, "autocrypt");
831 if (!c_autocrypt || mutt_autocrypt_init(false) || !e)
832 return -1;
833
834 struct Envelope *mime_headers = e->body->mime_headers;
835 if (!mime_headers)
836 mime_headers = e->body->mime_headers = mutt_env_new();
838
839 struct AddressList recips = TAILQ_HEAD_INITIALIZER(recips);
840
841 mutt_addrlist_copy(&recips, &e->env->to, false);
842 mutt_addrlist_copy(&recips, &e->env->cc, false);
843
844 TAILQ_FOREACH(recip, &recips, entries)
845 {
846 /* At this point, we just accept missing keys and include what we can. */
847 if (mutt_autocrypt_db_peer_get(recip, &peer) <= 0)
848 continue;
849
850 const char *keydata = NULL;
852 keydata = peer->keydata;
854 keydata = peer->gossip_keydata;
855
856 if (keydata)
857 {
858 struct AutocryptHeader *gossip = mutt_autocrypthdr_new();
859 gossip->addr = mutt_str_dup(peer->email_addr);
860 gossip->keydata = mutt_str_dup(keydata);
861 gossip->next = mime_headers->autocrypt_gossip;
862 mime_headers->autocrypt_gossip = gossip;
863 }
864
866 }
867
868 TAILQ_FOREACH(recip, &e->env->reply_to, entries)
869 {
870 const char *addr = NULL;
871 const char *keydata = NULL;
872 if (mutt_autocrypt_db_account_get(recip, &account) > 0)
873 {
874 addr = account->email_addr;
875 keydata = account->keydata;
876 }
877 else if (mutt_autocrypt_db_peer_get(recip, &peer) > 0)
878 {
879 addr = peer->email_addr;
881 keydata = peer->keydata;
883 keydata = peer->gossip_keydata;
884 }
885
886 if (keydata)
887 {
888 struct AutocryptHeader *gossip = mutt_autocrypthdr_new();
889 gossip->addr = mutt_str_dup(addr);
890 gossip->keydata = mutt_str_dup(keydata);
891 gossip->next = mime_headers->autocrypt_gossip;
892 mime_headers->autocrypt_gossip = gossip;
893 }
896 }
897
898 mutt_addrlist_clear(&recips);
901 return rc;
902}
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: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: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
109 if (autocrypt_dir_init(can_create))
110 goto bail;
111
113 goto bail;
114
115 if (mutt_autocrypt_db_init(can_create))
116 goto bail;
117
118 return 0;
119
120bail:
121 cs_subset_str_native_set(NeoMutt->sub, "autocrypt", false, NULL);
123 return -1;
124}
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: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 256 of file autocrypt.c.

257{
258 struct AutocryptHeader *valid_ac_hdr = NULL;
259 struct AutocryptPeer *peer = NULL;
260 struct AutocryptPeerHistory *peerhist = NULL;
261 struct Buffer *keyid = NULL;
262 bool update_db = false, insert_db = false, insert_db_history = false, import_gpg = false;
263 int rc = -1;
264
265 const bool c_autocrypt = cs_subset_bool(NeoMutt->sub, "autocrypt");
266 if (!c_autocrypt)
267 return 0;
268
269 if (mutt_autocrypt_init(false))
270 return -1;
271
272 if (!e || !e->body || !env)
273 return 0;
274
275 /* 1.1 spec says to skip emails with more than one From header */
276 struct Address *from = TAILQ_FIRST(&env->from);
277 if (!from || TAILQ_NEXT(from, entries))
278 return 0;
279
280 /* 1.1 spec also says to skip multipart/report emails */
281 if ((e->body->type == TYPE_MULTIPART) && mutt_istr_equal(e->body->subtype, "report"))
282 {
283 return 0;
284 }
285
286 /* Ignore emails that appear to be more than a week in the future,
287 * since they can block all future updates during that time. */
288 if (e->date_sent > (mutt_date_now() + (7 * 24 * 60 * 60)))
289 return 0;
290
291 for (struct AutocryptHeader *ac_hdr = env->autocrypt; ac_hdr; ac_hdr = ac_hdr->next)
292 {
293 if (ac_hdr->invalid)
294 continue;
295
296 /* NOTE: this assumes the processing is occurring right after
297 * mutt_parse_rfc822_line() and the from ADDR is still in the same
298 * form (intl) as the autocrypt header addr field */
299 if (!mutt_istr_equal(buf_string(from->mailbox), ac_hdr->addr))
300 continue;
301
302 /* 1.1 spec says ignore all, if more than one valid header is found. */
303 if (valid_ac_hdr)
304 {
305 valid_ac_hdr = NULL;
306 break;
307 }
308 valid_ac_hdr = ac_hdr;
309 }
310
311 if (mutt_autocrypt_db_peer_get(from, &peer) < 0)
312 goto cleanup;
313
314 if (peer)
315 {
316 if (e->date_sent <= peer->autocrypt_timestamp)
317 {
318 rc = 0;
319 goto cleanup;
320 }
321
322 if (e->date_sent > peer->last_seen)
323 {
324 update_db = true;
325 peer->last_seen = e->date_sent;
326 }
327
328 if (valid_ac_hdr)
329 {
330 update_db = true;
332 peer->prefer_encrypt = valid_ac_hdr->prefer_encrypt;
333 if (!mutt_str_equal(peer->keydata, valid_ac_hdr->keydata))
334 {
335 import_gpg = true;
336 insert_db_history = true;
337 mutt_str_replace(&peer->keydata, valid_ac_hdr->keydata);
338 }
339 }
340 }
341 else if (valid_ac_hdr)
342 {
343 import_gpg = true;
344 insert_db = true;
345 insert_db_history = true;
346 }
347
348 if (!(import_gpg || insert_db || update_db))
349 {
350 rc = 0;
351 goto cleanup;
352 }
353
354 if (!peer)
355 {
357 peer->last_seen = e->date_sent;
359 peer->keydata = mutt_str_dup(valid_ac_hdr->keydata);
360 peer->prefer_encrypt = valid_ac_hdr->prefer_encrypt;
361 }
362
363 if (import_gpg)
364 {
365 keyid = buf_pool_get();
367 goto cleanup;
368 mutt_str_replace(&peer->keyid, buf_string(keyid));
369 }
370
371 if (insert_db && mutt_autocrypt_db_peer_insert(from, peer))
372 goto cleanup;
373
374 if (update_db && mutt_autocrypt_db_peer_update(peer))
375 goto cleanup;
376
377 if (insert_db_history)
378 {
380 peerhist->email_msgid = mutt_str_dup(env->message_id);
381 peerhist->timestamp = e->date_sent;
382 peerhist->keydata = mutt_str_dup(peer->keydata);
383 if (mutt_autocrypt_db_peer_history_insert(from, peerhist))
384 goto cleanup;
385 }
386
387 rc = 0;
388
389cleanup:
392 buf_pool_release(&keyid);
393
394 return rc;
395}
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: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 404 of file autocrypt.c.

405{
406 struct AutocryptPeer *peer = NULL;
407 struct AutocryptGossipHistory *gossip_hist = NULL;
408 struct Address *peer_addr = NULL;
409 struct Address ac_hdr_addr = { 0 };
410 bool update_db = false, insert_db = false, insert_db_history = false, import_gpg = false;
411 int rc = -1;
412
413 const bool c_autocrypt = cs_subset_bool(NeoMutt->sub, "autocrypt");
414 if (!c_autocrypt)
415 return 0;
416
417 if (mutt_autocrypt_init(false))
418 return -1;
419
420 if (!e || !e->env || !prot_headers)
421 return 0;
422
423 struct Envelope *env = e->env;
424
425 struct Address *from = TAILQ_FIRST(&env->from);
426 if (!from)
427 return 0;
428
429 /* Ignore emails that appear to be more than a week in the future,
430 * since they can block all future updates during that time. */
431 if (e->date_sent > (mutt_date_now() + (7 * 24 * 60 * 60)))
432 return 0;
433
434 struct Buffer *keyid = buf_pool_get();
435
436 struct AddressList recips = TAILQ_HEAD_INITIALIZER(recips);
437
438 /* Normalize the recipient list for comparison */
439 mutt_addrlist_copy(&recips, &env->to, false);
440 mutt_addrlist_copy(&recips, &env->cc, false);
441 mutt_addrlist_copy(&recips, &env->reply_to, false);
443
444 for (struct AutocryptHeader *ac_hdr = prot_headers->autocrypt_gossip; ac_hdr;
445 ac_hdr = ac_hdr->next)
446 {
447 if (ac_hdr->invalid)
448 continue;
449
450 /* normalize for comparison against recipient list */
451 buf_strcpy(ac_hdr_addr.mailbox, ac_hdr->addr);
452 ac_hdr_addr.is_intl = true;
453 ac_hdr_addr.intl_checked = true;
455
456 /* Check to make sure the address is in the recipient list. */
457 TAILQ_FOREACH(peer_addr, &recips, entries)
458 {
459 if (buf_str_equal(peer_addr->mailbox, ac_hdr_addr.mailbox))
460 break;
461 }
462
463 if (!peer_addr)
464 continue;
465
466 if (mutt_autocrypt_db_peer_get(peer_addr, &peer) < 0)
467 goto cleanup;
468
469 if (peer)
470 {
471 if (e->date_sent <= peer->gossip_timestamp)
472 {
474 continue;
475 }
476
477 update_db = true;
478 peer->gossip_timestamp = e->date_sent;
479 /* This is slightly different from the autocrypt 1.1 spec.
480 * Avoid setting an empty peer.gossip_keydata with a value that matches
481 * the current peer.keydata. */
482 if ((peer->gossip_keydata && !mutt_str_equal(peer->gossip_keydata, ac_hdr->keydata)) ||
483 (!peer->gossip_keydata && !mutt_str_equal(peer->keydata, ac_hdr->keydata)))
484 {
485 import_gpg = true;
486 insert_db_history = true;
487 mutt_str_replace(&peer->gossip_keydata, ac_hdr->keydata);
488 }
489 }
490 else
491 {
492 import_gpg = true;
493 insert_db = true;
494 insert_db_history = true;
495 }
496
497 if (!peer)
498 {
500 peer->gossip_timestamp = e->date_sent;
501 peer->gossip_keydata = mutt_str_dup(ac_hdr->keydata);
502 }
503
504 if (import_gpg)
505 {
507 goto cleanup;
509 }
510
511 if (insert_db && mutt_autocrypt_db_peer_insert(peer_addr, peer))
512 goto cleanup;
513
514 if (update_db && mutt_autocrypt_db_peer_update(peer))
515 goto cleanup;
516
517 if (insert_db_history)
518 {
520 gossip_hist->sender_email_addr = buf_strdup(from->mailbox);
521 gossip_hist->email_msgid = mutt_str_dup(env->message_id);
522 gossip_hist->timestamp = e->date_sent;
523 gossip_hist->gossip_keydata = mutt_str_dup(peer->gossip_keydata);
524 if (mutt_autocrypt_db_gossip_history_insert(peer_addr, gossip_hist))
525 goto cleanup;
526 }
527
530 buf_reset(keyid);
531 update_db = false;
532 insert_db = false;
533 insert_db_history = false;
534 import_gpg = false;
535 }
536
537 rc = 0;
538
539cleanup:
540 FREE(&ac_hdr_addr.mailbox);
541 mutt_addrlist_clear(&recips);
544 buf_pool_release(&keyid);
545
546 return rc;
547}
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 697 of file autocrypt.c.

698{
699 int rc = -1;
700 struct AutocryptAccount *account = NULL;
701
702 const bool c_autocrypt = cs_subset_bool(NeoMutt->sub, "autocrypt");
703 if (!c_autocrypt || mutt_autocrypt_init(false) || !e)
704 return -1;
705
706 struct Address *from = TAILQ_FIRST(&e->env->from);
707 if (!from || TAILQ_NEXT(from, entries))
708 return -1;
709
710 if (mutt_autocrypt_db_account_get(from, &account) <= 0)
711 goto cleanup;
712 if (!account->keyid)
713 goto cleanup;
714 if (!account->enabled)
715 goto cleanup;
716
719
720 rc = 0;
721
722cleanup:
724 return rc;
725}
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 558 of file autocrypt.c.

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

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

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