54 gpgme_error_t err = gpgme_new(ctx);
55 if (err == GPG_ERR_NO_ERROR)
56 err = gpgme_ctx_set_engine_info(*ctx, GPGME_PROTOCOL_OpenPGP, NULL, c_autocrypt_dir);
57 if (err != GPG_ERR_NO_ERROR)
59 mutt_error(
_(
"error creating GPGME context: %s"), gpgme_strerror(err));
87 gpgme_data_t dh = NULL;
88 gpgme_key_t export_keys[2] = { 0 };
89 size_t export_data_len;
91 if (gpgme_data_new(&dh))
96 if (gpgme_data_set_encoding (dh, GPGME_DATA_ENCODING_BASE64))
100 export_keys[0] = key;
101 export_keys[1] = NULL;
102 if (gpgme_op_export_keys(ctx, export_keys, GPGME_EXPORT_MODE_MINIMAL, dh))
105 char *export_data = gpgme_data_release_and_get_mem(dh, &export_data_len);
109 gpgme_free(export_data);
115 gpgme_data_release(dh);
127int mutt_autocrypt_gpgme_export_key(
const char *keyid,
struct Buffer *keydata)
130 gpgme_ctx_t ctx = NULL;
131 gpgme_key_t key = NULL;
136 if (gpgme_get_key(ctx, keyid, &key, 0))
144 gpgme_key_unref(key);
162 gpgme_ctx_t ctx = NULL;
163 gpgme_genkey_result_t keyresult = NULL;
164 gpgme_key_t primary_key = NULL;
181 gpgme_error_t err = gpgme_op_createkey(ctx,
buf_string(buf),
"ed25519", 0, 0, NULL,
182 GPGME_CREATE_NOPASSWD | GPGME_CREATE_FORCE |
183 GPGME_CREATE_NOEXPIRE);
184 if (err != GPG_ERR_NO_ERROR)
188 mutt_error(
_(
"Error creating autocrypt key: %s"), gpgme_strerror(err));
191 keyresult = gpgme_op_genkey_result(ctx);
198 err = gpgme_get_key(ctx,
buf_string(keyid), &primary_key, 0);
203 err = gpgme_op_createsubkey(ctx, primary_key,
"cv25519", 0, 0,
204 GPGME_CREATE_NOPASSWD | GPGME_CREATE_NOEXPIRE);
205 if (err != GPG_ERR_NO_ERROR)
207 mutt_error(
_(
"Error creating autocrypt key: %s"), gpgme_strerror(err));
219 gpgme_key_unref(primary_key);
235 gpgme_ctx_t ctx = NULL;
236 gpgme_key_t key = NULL;
245 if (gpgme_get_key(ctx,
buf_string(keyid), &key, 0))
248 if (key->revoked || key->expired || key->disabled || key->invalid ||
249 !key->can_encrypt || !key->can_sign)
266 gpgme_key_unref(key);
287 const char *prompt =
_(
"(c)reate new, or (s)elect existing GPG key?");
290 const char *letters =
_(
"cs");
323 gpgme_ctx_t ctx = NULL;
324 gpgme_data_t dh = NULL;
325 struct Buffer *raw_keydata = NULL;
334 if (gpgme_data_new_from_mem(&dh,
buf_string(raw_keydata),
buf_len(raw_keydata), 0))
339 if (gpgme_op_import(ctx, dh))
342 gpgme_import_result_t result = gpgme_op_import_result(ctx);
343 if (!result->imports || !result->imports->fpr)
350 gpgme_data_release(dh);
364 gpgme_ctx_t ctx = NULL;
365 gpgme_key_t key = NULL;
373 if (gpgme_get_key(ctx, keyid, &key, 0))
377 if (key->revoked || key->expired || key->disabled || key->invalid || !key->can_encrypt)
381 gpgme_key_unref(key);
void mutt_addr_free(struct Address **ptr)
Free a single Address.
size_t mutt_addr_write(struct Buffer *buf, struct Address *addr, bool display)
Write a single Address to a buffer.
struct Address * mutt_addr_copy(const struct Address *addr)
Copy the real address.
bool mutt_addr_to_local(struct Address *a)
Convert an Address from Punycode.
size_t mutt_b64_buffer_encode(struct Buffer *buf, const char *in, size_t len)
Convert raw bytes to null-terminated base64 string.
int mutt_b64_buffer_decode(struct Buffer *buf, const char *in)
Convert null-terminated base64 string to raw bytes.
size_t buf_len(const struct Buffer *buf)
Calculate the length of a Buffer.
size_t buf_strcpy(struct Buffer *buf, const char *s)
Copy a string into a Buffer.
static const char * buf_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
const char * cs_subset_path(const struct ConfigSubset *sub, const char *name)
Get a path config item by name.
Convenience wrapper for the config headers.
Convenience wrapper for the core headers.
int mutt_gpgme_select_secret_key(struct Buffer *keyid)
Select a private Autocrypt key for a new account.
bool OptAutocryptGpgme
(pseudo) use Autocrypt context inside ncrypt/crypt_gpgme.c
bool mutt_autocrypt_gpgme_is_valid_key(const char *keyid)
Is a key id valid?
int mutt_autocrypt_gpgme_create_key(struct Address *addr, struct Buffer *keyid, struct Buffer *keydata)
Create a GPGME key.
int mutt_autocrypt_gpgme_select_key(struct Buffer *keyid, struct Buffer *keydata)
Select a Autocrypt key.
int mutt_autocrypt_gpgme_init(void)
Initialise GPGME.
static int create_gpgme_context(gpgme_ctx_t *ctx)
Create a GPGME context.
int mutt_autocrypt_gpgme_import_key(const char *keydata, struct Buffer *keyid)
Read a key from GPGME.
static int export_keydata(gpgme_ctx_t ctx, gpgme_key_t key, struct Buffer *keydata)
Export Key data from GPGME into a Buffer.
int mutt_autocrypt_gpgme_select_or_create_key(struct Address *addr, struct Buffer *keyid, struct Buffer *keydata)
Ask the user to select or create an Autocrypt key.
void pgp_gpgme_init(void)
Initialise the crypto module - Implements CryptModuleSpecs::init() -.
int mw_multi_choice(const char *prompt, const char *letters)
Offer the user a multiple choice question -.
#define mutt_message(...)
#define mutt_debug(LEVEL,...)
@ LL_DEBUG1
Log at debug level 1.
Convenience wrapper for the library headers.
API for encryption/signing of emails.
struct Buffer * buf_pool_get(void)
Get a Buffer from the pool.
void buf_pool_release(struct Buffer **ptr)
Return a Buffer to the pool.
@ MUTT_YES
User answered 'Yes', or assume 'Yes'.
enum QuadOption query_yesorno(const char *prompt, enum QuadOption def)
Ask the user a Yes/No question.
String manipulation buffer.
Container for Accounts, Notifications.
struct ConfigSubset * sub
Inherited config items.