| Top |
GMimeAutocryptHeaderGMimeAutocryptHeader — A header containing cryptographic information about the sending address |
A GMimeAutocryptHeader is an object containing information derived from a message about the sender's cryptographic keys and preferences. It can be used in conjunction with local storage and business logic to make a better user experience for encrypted e-mail.
GMimeAutocryptHeader * g_mime_autocrypt_header_parse (const char *raw_value,gsize length,GMimeAutocryptHeaderKind kind,GError **error);
Parses one complete raw field value, without RFC 2047 decoding. Requires addr and a final, nonempty, canonical Base64 keydata. Unknown critical and duplicate attributes invalidate the field; unknown underscore attributes are ignored. Gossip cannot establish an encryption preference. The field name, colon and raw value together may not exceed 10 KiB. This validates the representation, not the OpenPGP key or its owner.
raw_value |
bytes following the colon. |
[array length=length][element-type guint8] |
length |
byte length, including folding whitespace and the final LF or CRLF |
|
kind |
the field being parsed |
|
error |
return location for a GError. |
[nullable] |
GBytes * g_mime_autocrypt_header_format (GMimeAutocryptHeader *ah,GMimeAutocryptHeaderKind kind,GError **error);
Produces a raw field value suitable for g_mime_header_set_raw_value(),
with a leading space, CRLF folds and a final CRLF. Counts all these
bytes and the field name and colon against the 10 KiB wire limit.
The preference is omitted for gossip.
ah |
an Autocrypt advertisement |
|
kind |
the field to produce |
|
error |
return location for a GError. |
[nullable] |
GMimeAutocryptPeerState *
g_mime_autocrypt_peer_state_new (const char *address);
GMimeAutocryptPeerState * g_mime_autocrypt_peer_state_new_from_fields (const char *address,GDateTime *last_seen,GDateTime *autocrypt_timestamp,GBytes *public_key,GMimeAutocryptPreferEncrypt prefer_encrypt,GDateTime *gossip_timestamp,GBytes *gossip_key);
Restores the fields exposed by the snapshot getters. Key and timestamp must be present together for each source; last_seen must be at least as recent as the direct key, but is independent of gossip.
address |
a mailbox addr-spec |
|
last_seen |
most recent direct message. |
[nullable] |
autocrypt_timestamp |
date of accepted direct key. |
[nullable] |
public_key |
direct key bytes. |
[nullable] |
prefer_encrypt |
preference from the direct advertisement, or NONE if absent |
|
gossip_timestamp |
date of accepted gossip key. |
[nullable] |
gossip_key |
gossip key bytes. |
[nullable] |
const char *
g_mime_autocrypt_peer_state_get_address
(GMimeAutocryptPeerState *state);
GDateTime *
g_mime_autocrypt_peer_state_get_last_seen
(GMimeAutocryptPeerState *state);
GDateTime *
g_mime_autocrypt_peer_state_get_autocrypt_timestamp
(GMimeAutocryptPeerState *state);
GBytes *
g_mime_autocrypt_peer_state_get_public_key
(GMimeAutocryptPeerState *state);
GMimeAutocryptPreferEncrypt
g_mime_autocrypt_peer_state_get_prefer_encrypt
(GMimeAutocryptPeerState *state);
GDateTime *
g_mime_autocrypt_peer_state_get_gossip_timestamp
(GMimeAutocryptPeerState *state);
GBytes *
g_mime_autocrypt_peer_state_get_gossip_key
(GMimeAutocryptPeerState *state);
GMimeAutocryptPeerState * g_mime_autocrypt_peer_state_apply_observation (GMimeAutocryptPeerState *state,GMimeAutocryptObservation *observation,gboolean key_usable);
Ignores ineligible messages, other addresses, and dates strictly older than the direct key timestamp (not last_seen). At equal timestamps the last usable advertisement applied wins, as in Level 1. Seen-only messages and unusable keys can advance last_seen but never replace a key or preference.
GMimeAutocryptPeerState * g_mime_autocrypt_peer_state_apply_gossip (GMimeAutocryptPeerState *state,GMimeAutocryptHeader *header);
Call only after checking the gossip source and key usability. Incomplete headers, other addresses and timestamps no newer than the gossip timestamp are ignored (first gossip at an equal timestamp wins). Gossip never updates last_seen, the direct key, or the peer's preference.
GMimeAutocryptObservation * g_mime_message_observe_autocrypt (GMimeMessage *message,GDateTime *received_at);
Observe a single sender without importing a key or modifying peer state. The application should exclude spam before calling. Reports and messages without exactly one From mailbox are ignored. A malformed, missing or ambiguous advertisement does not erase the sender observation.
Prefer a delivery timestamp recorded by your mail store, such as IMAP
INTERNALDATE for a message delivered by SMTP. If your application handles
delivery itself, record the time once at delivery and reuse it on rescans.
Do not pass the sender's Date header: this function already compares it
with received_at
.
A Received field prepended by your own receiving server can also supply
the timestamp. In this example, message
came directly from that server
and the application knows it prepended the topmost Received field:
1 2 3 4 5 6 7 8 |
const char *value = g_mime_entity_get_header (GMIME_ENTITY (message), "Received"); GMimeReceived *hop = value ? g_mime_received_parse (NULL, value, -1, NULL) : NULL; GDateTime *received_at = hop ? g_mime_received_get_date_time (hop) : NULL; if (received_at) { observation = g_mime_message_observe_autocrypt (message, received_at); } g_clear_object (&hop); |
Header position alone does not establish trust in an imported message. If the trusted field is missing or undated, use recorded delivery metadata or skip the observation; do not search older hops or use the rescan time.
GMimeAutocryptObservationStatus
g_mime_autocrypt_observation_get_status
(GMimeAutocryptObservation *observation);
const char *
g_mime_autocrypt_observation_get_address
(GMimeAutocryptObservation *observation);
GDateTime *
g_mime_autocrypt_observation_get_effective_date
(GMimeAutocryptObservation *observation);
GBytes *
g_mime_autocrypt_observation_get_keydata
(GMimeAutocryptObservation *observation);
GMimeAutocryptPreferEncrypt
g_mime_autocrypt_observation_get_prefer_encrypt
(GMimeAutocryptObservation *observation);
GMimeAutocryptHeader *
g_mime_autocrypt_header_new (void);
Creates a new GMimeAutocryptHeader object.
GMimeMailboxAddress *
g_mime_autocrypt_header_get_address (GMimeAutocryptHeader *ah);
Gets the internal address of the Autocrypt header, or NULL if not set.
void g_mime_autocrypt_header_set_address (GMimeAutocryptHeader *ah,GMimeMailboxAddress *address);
Set the address associated with the autocrypt_header.
gboolean g_mime_autocrypt_header_set_address_from_string (GMimeAutocryptHeader *ah,const char *address,GError **error);
Set the address associated with the autocrypt_header. Invalid input leaves the existing address unchanged.
ah |
a GMimeAutocryptHeader object |
|
address |
a |
|
error |
return location for a GError. |
[nullable] |
const char *
g_mime_autocrypt_header_get_address_as_string
(GMimeAutocryptHeader *ah);
Gets the internal address of the Autocrypt header as a C string, or NULL if not set.
GMimeAutocryptPreferEncrypt
g_mime_autocrypt_header_get_prefer_encrypt
(GMimeAutocryptHeader *ah);
Gets the encryption preference stated by the Autocrypt header.
void g_mime_autocrypt_header_set_prefer_encrypt (GMimeAutocryptHeader *ah,GMimeAutocryptPreferEncrypt pref);
Set the encryption preference associated with the Autocrypt header.
GBytes *
g_mime_autocrypt_header_get_keydata (GMimeAutocryptHeader *ah);
Gets the raw keydata of the Autocrypt header, or NULL if not set.
void g_mime_autocrypt_header_set_keydata (GMimeAutocryptHeader *ah,GBytes *keydata);
Set the raw key data associated with the Autocrypt header.
GDateTime *
g_mime_autocrypt_header_get_effective_date
(GMimeAutocryptHeader *ah);
Gets the effective date of the Autocrypt header, or NULL if not set.
void g_mime_autocrypt_header_set_effective_date (GMimeAutocryptHeader *ah,GDateTime *effective_date);
Set the effective date associated with the Autocrypt header.
gboolean
g_mime_autocrypt_header_is_complete (GMimeAutocryptHeader *ah);
When dealing with Autocrypt headers derived from a message, some sender addresses will not have a legitimate/complete header associated with them. When a given sender address has no complete header of a specific type, it should "reset" the state of the associated address.
char * g_mime_autocrypt_header_to_string (GMimeAutocryptHeader *ah,gboolean gossip);
Gets the string representation of the Autocrypt header, or NULL on
error. For example, it might return:
prefer-encrypt=mutual; addr=bob@example.com; keydata=AAAB15BE...
If you are using this object to populate an Autocrypt-Gossip
header, you should set gossip
to TRUE (this will suppress
inclusion of prefer-encrypt).
ah |
a GMimeAutocryptHeader object |
|
gossip |
a gboolean, indicating whether this header is for use with gossip |
int g_mime_autocrypt_header_compare (GMimeAutocryptHeader *ah1,GMimeAutocryptHeader *ah2);
Compare two Autocrypt Headers. This is useful for comparison, as well as for sorting headers by:
address
effective_date
keydata
prefer_encrypt
void g_mime_autocrypt_header_clone (GMimeAutocryptHeader *dst,GMimeAutocryptHeader *src);
If address and type already match between src
and dst
, copy
keydata, prefer_encrypt, effective_date from src
to dst
.
GMimeAutocryptHeaderList *
g_mime_autocrypt_header_list_new (void);
Creates a new GMimeAutocryptHeaderList object.
guint g_mime_autocrypt_header_list_add_missing_addresses (GMimeAutocryptHeaderList *list,GMimeInternetAddressList *addresses);
Adds a new incomplete GMimeAutocryptHeader object for each GMimeMailboxAddress found in addresses.
void g_mime_autocrypt_header_list_add (GMimeAutocryptHeaderList *list,GMimeAutocryptHeader *header);
Adds a the passed GMimeAutocryptHeader to the list.
guint
g_mime_autocrypt_header_list_get_count
(GMimeAutocryptHeaderList *list);
See how many Autocrypt headers are in the list.
GMimeAutocryptHeader * g_mime_autocrypt_header_list_get_header_at (GMimeAutocryptHeaderList *list,guint index);
Get the Nth header in the list (returns NULL on error, or if index
is out of bounds)
GMimeAutocryptHeader * g_mime_autocrypt_header_list_get_header_for_address (GMimeAutocryptHeaderList *list,GMimeMailboxAddress *mailbox);
Gets the Autocrypt header corresponding to the given mailbox
.
void
g_mime_autocrypt_header_list_remove_incomplete
(GMimeAutocryptHeaderList *list);
Remove all incomplete Autocrypt headers from the list.
typedef struct _GMimeAutocryptPeerState GMimeAutocryptPeerState;
An immutable snapshot of the direct and gossiped advertisements for one mailbox. Keys are opaque bytes, not authenticated identities. No operation imports keys, changes trust, or performs I/O.
typedef struct _GMimeAutocryptHeader GMimeAutocryptHeader;
An object containing Autocrypt information about a given e-mail address, as derived from a message header.
See https://autocrypt.org/ for details and motivation.