GMimeAutocryptHeader

GMimeAutocryptHeader — A header containing cryptographic information about the sending address

Functions

GMimeAutocryptHeader * g_mime_autocrypt_header_parse ()
GBytes * g_mime_autocrypt_header_format ()
GMimeAutocryptPeerState * g_mime_autocrypt_peer_state_new ()
GMimeAutocryptPeerState * g_mime_autocrypt_peer_state_new_from_fields ()
const char * g_mime_autocrypt_peer_state_get_address ()
GDateTime * g_mime_autocrypt_peer_state_get_last_seen ()
GDateTime * g_mime_autocrypt_peer_state_get_autocrypt_timestamp ()
GBytes * g_mime_autocrypt_peer_state_get_public_key ()
GMimeAutocryptPreferEncrypt g_mime_autocrypt_peer_state_get_prefer_encrypt ()
GDateTime * g_mime_autocrypt_peer_state_get_gossip_timestamp ()
GBytes * g_mime_autocrypt_peer_state_get_gossip_key ()
GMimeAutocryptPeerState * g_mime_autocrypt_peer_state_apply_observation ()
GMimeAutocryptPeerState * g_mime_autocrypt_peer_state_apply_gossip ()
GMimeAutocryptObservation * g_mime_message_observe_autocrypt ()
GMimeAutocryptObservationStatus g_mime_autocrypt_observation_get_status ()
const char * g_mime_autocrypt_observation_get_address ()
GDateTime * g_mime_autocrypt_observation_get_effective_date ()
GBytes * g_mime_autocrypt_observation_get_keydata ()
GMimeAutocryptPreferEncrypt g_mime_autocrypt_observation_get_prefer_encrypt ()
GMimeAutocryptHeader * g_mime_autocrypt_header_new ()
GMimeMailboxAddress * g_mime_autocrypt_header_get_address ()
void g_mime_autocrypt_header_set_address ()
gboolean g_mime_autocrypt_header_set_address_from_string ()
const char * g_mime_autocrypt_header_get_address_as_string ()
GMimeAutocryptPreferEncrypt g_mime_autocrypt_header_get_prefer_encrypt ()
void g_mime_autocrypt_header_set_prefer_encrypt ()
GBytes * g_mime_autocrypt_header_get_keydata ()
void g_mime_autocrypt_header_set_keydata ()
GDateTime * g_mime_autocrypt_header_get_effective_date ()
void g_mime_autocrypt_header_set_effective_date ()
gboolean g_mime_autocrypt_header_is_complete ()
char * g_mime_autocrypt_header_to_string ()
int g_mime_autocrypt_header_compare ()
void g_mime_autocrypt_header_clone ()
GMimeAutocryptHeaderList * g_mime_autocrypt_header_list_new ()
guint g_mime_autocrypt_header_list_add_missing_addresses ()
void g_mime_autocrypt_header_list_add ()
guint g_mime_autocrypt_header_list_get_count ()
GMimeAutocryptHeader * g_mime_autocrypt_header_list_get_header_at ()
GMimeAutocryptHeader * g_mime_autocrypt_header_list_get_header_for_address ()
void g_mime_autocrypt_header_list_remove_incomplete ()

Types and Values

Description

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.

Functions

g_mime_autocrypt_header_parse ()

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.

Parameters

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]

Returns

the advertisement, or NULL on error.

[transfer full][nullable]


g_mime_autocrypt_header_format ()

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.

Parameters

ah

an Autocrypt advertisement

 

kind

the field to produce

 

error

return location for a GError.

[nullable]

Returns

the raw value, or NULL on error.

[transfer full][nullable]


g_mime_autocrypt_peer_state_new ()

GMimeAutocryptPeerState *
g_mime_autocrypt_peer_state_new (const char *address);

Parameters

address

a mailbox addr-spec

 

Returns

an empty snapshot, or NULL for an invalid address.

[transfer full][nullable]


g_mime_autocrypt_peer_state_new_from_fields ()

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.

Parameters

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]

Returns

a snapshot, or NULL for invalid fields.

[transfer full][nullable]


g_mime_autocrypt_peer_state_get_address ()

const char *
g_mime_autocrypt_peer_state_get_address
                               (GMimeAutocryptPeerState *state);

Parameters

state

a peer snapshot

 

Returns

the canonical lowercase, IDN-encoded address.

[transfer none]


g_mime_autocrypt_peer_state_get_last_seen ()

GDateTime *
g_mime_autocrypt_peer_state_get_last_seen
                               (GMimeAutocryptPeerState *state);

Parameters

state

a peer snapshot

 

Returns

most recent eligible direct message date.

[transfer none][nullable]


g_mime_autocrypt_peer_state_get_autocrypt_timestamp ()

GDateTime *
g_mime_autocrypt_peer_state_get_autocrypt_timestamp
                               (GMimeAutocryptPeerState *state);

Parameters

state

a peer snapshot

 

Returns

date of the current direct key.

[transfer none][nullable]


g_mime_autocrypt_peer_state_get_public_key ()

GBytes *
g_mime_autocrypt_peer_state_get_public_key
                               (GMimeAutocryptPeerState *state);

Parameters

state

a peer snapshot

 

Returns

the directly advertised key.

[transfer none][nullable]


g_mime_autocrypt_peer_state_get_prefer_encrypt ()

GMimeAutocryptPreferEncrypt
g_mime_autocrypt_peer_state_get_prefer_encrypt
                               (GMimeAutocryptPeerState *state);

Parameters

state

a peer snapshot

 

Returns

the directly advertised encryption preference.


g_mime_autocrypt_peer_state_get_gossip_timestamp ()

GDateTime *
g_mime_autocrypt_peer_state_get_gossip_timestamp
                               (GMimeAutocryptPeerState *state);

Parameters

state

a peer snapshot

 

Returns

date of the current gossip key.

[transfer none][nullable]


g_mime_autocrypt_peer_state_get_gossip_key ()

GBytes *
g_mime_autocrypt_peer_state_get_gossip_key
                               (GMimeAutocryptPeerState *state);

Parameters

state

a peer snapshot

 

Returns

the key obtained through gossip.

[transfer none][nullable]


g_mime_autocrypt_peer_state_apply_observation ()

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.

Parameters

state

a peer snapshot

 

observation

a direct message observation

 

key_usable

whether the caller accepts the advertised key bytes

 

Returns

the resulting snapshot, possibly a new reference to state .

[transfer full]


g_mime_autocrypt_peer_state_apply_gossip ()

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.

Parameters

state

a peer snapshot

 

header

a recipient-matched gossip header from a decrypted inner part

 

Returns

the resulting snapshot, possibly a new reference to state .

[transfer full]


g_mime_message_observe_autocrypt ()

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.

Parameters

message

message to examine

 

received_at

original receipt time, including on subsequent rescans

 

Returns

an immutable observation.

[transfer full]


g_mime_autocrypt_observation_get_status ()

GMimeAutocryptObservationStatus
g_mime_autocrypt_observation_get_status
                               (GMimeAutocryptObservation *observation);

Parameters

observation

an observation

 

Returns

the eligibility and advertisement status.


g_mime_autocrypt_observation_get_address ()

const char *
g_mime_autocrypt_observation_get_address
                               (GMimeAutocryptObservation *observation);

Parameters

observation

an observation

 

Returns

sender address, or NULL if ignored.

[nullable]


g_mime_autocrypt_observation_get_effective_date ()

GDateTime *
g_mime_autocrypt_observation_get_effective_date
                               (GMimeAutocryptObservation *observation);

Parameters

observation

an observation

 

Returns

the earlier of message date and receipt time, or receipt time when undated; NULL if ignored.

[transfer none][nullable]


g_mime_autocrypt_observation_get_keydata ()

GBytes *
g_mime_autocrypt_observation_get_keydata
                               (GMimeAutocryptObservation *observation);

Parameters

observation

an observation

 

Returns

advertised bytes, not a validated or trusted key.

[transfer none][nullable]


g_mime_autocrypt_observation_get_prefer_encrypt ()

GMimeAutocryptPreferEncrypt
g_mime_autocrypt_observation_get_prefer_encrypt
                               (GMimeAutocryptObservation *observation);

Parameters

observation

an observation

 

Returns

advertised preference, or GMIME_AUTOCRYPT_PREFER_ENCRYPT_NONE if absent.


g_mime_autocrypt_header_new ()

GMimeAutocryptHeader *
g_mime_autocrypt_header_new (void);

Creates a new GMimeAutocryptHeader object.

Returns

a new GMimeAutocryptHeader object.

[transfer full]


g_mime_autocrypt_header_get_address ()

GMimeMailboxAddress *
g_mime_autocrypt_header_get_address (GMimeAutocryptHeader *ah);

Gets the internal address of the Autocrypt header, or NULL if not set.

Parameters

ah

a GMimeAutocryptHeader object

 

Returns

the address associated with the Autocrypt header.

[transfer none]


g_mime_autocrypt_header_set_address ()

void
g_mime_autocrypt_header_set_address (GMimeAutocryptHeader *ah,
                                     GMimeMailboxAddress *address);

Set the address associated with the autocrypt_header.

Parameters

ah

a GMimeAutocryptHeader object

 

address

a GMimeMailboxAddress value

 

g_mime_autocrypt_header_set_address_from_string ()

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.

Parameters

ah

a GMimeAutocryptHeader object

 

address

a NULL-terminated string that is a raw e-mail address

 

error

return location for a GError.

[nullable]

Returns

whether the address was valid.


g_mime_autocrypt_header_get_address_as_string ()

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.

Parameters

ah

a GMimeAutocryptHeader object

 

Returns

the address associated with the Autocrypt header.

[transfer none]


g_mime_autocrypt_header_get_prefer_encrypt ()

GMimeAutocryptPreferEncrypt
g_mime_autocrypt_header_get_prefer_encrypt
                               (GMimeAutocryptHeader *ah);

Gets the encryption preference stated by the Autocrypt header.

Parameters

ah

a GMimeAutocryptHeader object

 

Returns

the encryption preference associated with the Autocrypt header


g_mime_autocrypt_header_set_prefer_encrypt ()

void
g_mime_autocrypt_header_set_prefer_encrypt
                               (GMimeAutocryptHeader *ah,
                                GMimeAutocryptPreferEncrypt pref);

Set the encryption preference associated with the Autocrypt header.

Parameters

ah

a GMimeAutocryptHeader object

 

pref

a GMimeAutocryptPreferEncrypt value

 

g_mime_autocrypt_header_get_keydata ()

GBytes *
g_mime_autocrypt_header_get_keydata (GMimeAutocryptHeader *ah);

Gets the raw keydata of the Autocrypt header, or NULL if not set.

Parameters

ah

a GMimeAutocryptHeader object

 

Returns

the raw key data associated with the Autocrypt header.

[transfer none]


g_mime_autocrypt_header_set_keydata ()

void
g_mime_autocrypt_header_set_keydata (GMimeAutocryptHeader *ah,
                                     GBytes *keydata);

Set the raw key data associated with the Autocrypt header.

Parameters

ah

a GMimeAutocryptHeader object

 

keydata

a GBytes object

 

g_mime_autocrypt_header_get_effective_date ()

GDateTime *
g_mime_autocrypt_header_get_effective_date
                               (GMimeAutocryptHeader *ah);

Gets the effective date of the Autocrypt header, or NULL if not set.

Parameters

ah

a GMimeAutocryptHeader object

 

Returns

the effective date associated with the Autocrypt header.

[transfer none]


g_mime_autocrypt_header_set_effective_date ()

void
g_mime_autocrypt_header_set_effective_date
                               (GMimeAutocryptHeader *ah,
                                GDateTime *effective_date);

Set the effective date associated with the Autocrypt header.

Parameters

ah

a GMimeAutocryptHeader object

 

effective_date

a GDateTime object

 

g_mime_autocrypt_header_is_complete ()

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.

Parameters

ah

a GMimeAutocryptHeader object

 

Returns

TRUE if the header is complete, or FALSE if it is incomplete.


g_mime_autocrypt_header_to_string ()

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).

Parameters

ah

a GMimeAutocryptHeader object

 

gossip

a gboolean, indicating whether this header is for use with gossip

 

Returns

the string representation of the Autocrypt header.

[transfer full]


g_mime_autocrypt_header_compare ()

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

Parameters

ah1

a GMimeAutocryptHeader object

 

ah2

a GMimeAutocryptHeader object

 

Returns

-1, 0, or 1 when ah1 is less than, equal to, or greater than ah2 .


g_mime_autocrypt_header_clone ()

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 .

Parameters

dst

a GMimeAutocryptHeader object

 

src

a GMimeAutocryptHeader object

 

g_mime_autocrypt_header_list_new ()

GMimeAutocryptHeaderList *
g_mime_autocrypt_header_list_new (void);

Creates a new GMimeAutocryptHeaderList object.

Returns

a new GMimeAutocryptHeaderList object.

[transfer full]


g_mime_autocrypt_header_list_add_missing_addresses ()

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.

Parameters

list

a GMimeAutocryptHeaderList object

 

addresses

an GMimeInternetAddressList object

 

Returns

the number of addresses added


g_mime_autocrypt_header_list_add ()

void
g_mime_autocrypt_header_list_add (GMimeAutocryptHeaderList *list,
                                  GMimeAutocryptHeader *header);

Adds a the passed GMimeAutocryptHeader to the list.

Parameters

list

a GMimeAutocryptHeaderList object

 

header

a GMimeAutocryptHeader object

 

g_mime_autocrypt_header_list_get_count ()

guint
g_mime_autocrypt_header_list_get_count
                               (GMimeAutocryptHeaderList *list);

See how many Autocrypt headers are in the list.

Parameters

list

a GMimeAutocryptHeaderList object

 

Returns

the number of available Autocrypt headers


g_mime_autocrypt_header_list_get_header_at ()

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)

Parameters

list

a GMimeAutocryptHeaderList object

 

index

an index into the list

 

Returns

a pointer to the Nth header in the list.

[transfer none]


g_mime_autocrypt_header_list_get_header_for_address ()

GMimeAutocryptHeader *
g_mime_autocrypt_header_list_get_header_for_address
                               (GMimeAutocryptHeaderList *list,
                                GMimeMailboxAddress *mailbox);

Gets the Autocrypt header corresponding to the given mailbox .

Parameters

list

a GMimeAutocryptHeaderList object

 

mailbox

an GMimeMailboxAddress object

 

Returns

a pointer to the header in the list which matches the requested address, or NULL if no such header exists in the list.

[transfer none]


g_mime_autocrypt_header_list_remove_incomplete ()

void
g_mime_autocrypt_header_list_remove_incomplete
                               (GMimeAutocryptHeaderList *list);

Remove all incomplete Autocrypt headers from the list.

Parameters

list

a GMimeAutocryptHeaderList object

 

Types and Values

enum GMimeAutocryptHeaderKind

Members

GMIME_AUTOCRYPT_HEADER_DIRECT

An Autocrypt field.

 

GMIME_AUTOCRYPT_HEADER_GOSSIP

An Autocrypt-Gossip field.

 

GMimeAutocryptPeerState

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.


GMimeAutocryptObservation

typedef struct _GMimeAutocryptObservation GMimeAutocryptObservation;

enum GMimeAutocryptObservationStatus

Members

GMIME_AUTOCRYPT_OBSERVATION_IGNORED

No eligible sender observation.

 

GMIME_AUTOCRYPT_OBSERVATION_SEEN

Eligible sender, but no unique matching advertisement.

 

GMIME_AUTOCRYPT_OBSERVATION_ADVERTISED

One matching, syntactically valid advertisement.

 

enum GMimeAutocryptPreferEncrypt

A description of the user's preference for encrypted messaging.

Members

GMIME_AUTOCRYPT_PREFER_ENCRYPT_NONE

No preference stated.

 

GMIME_AUTOCRYPT_PREFER_ENCRYPT_MUTUAL

Please encrypt, if you also have this preference

 

GMimeAutocryptHeader

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.


GMimeAutocryptHeaderList

typedef struct _GMimeAutocryptHeaderList GMimeAutocryptHeaderList;

A list of Autocrypt headers, typically extracted from a GMimeMessage.

See Also

https://autocrypt.org