51 gpgme_error_t err = gpgme_new(ctx);
53 err = gpgme_ctx_set_engine_info(*ctx, GPGME_PROTOCOL_OpenPGP, NULL, c_autocrypt_dir);
56 mutt_error(
_(
"error creating GPGME context: %s"), gpgme_strerror(err));
84 gpgme_data_t dh = NULL;
85 gpgme_key_t export_keys[2] = { 0 };
86 size_t export_data_len;
88 if (gpgme_data_new(&dh))
93 if (gpgme_data_set_encoding (dh, GPGME_DATA_ENCODING_BASE64))
98 export_keys[1] = NULL;
99 if (gpgme_op_export_keys(ctx, export_keys, GPGME_EXPORT_MODE_MINIMAL, dh))
102 char *export_data = gpgme_data_release_and_get_mem(dh, &export_data_len);
106 gpgme_free(export_data);
112 gpgme_data_release(dh);
124int mutt_autocrypt_gpgme_export_key(
const char *keyid,
struct Buffer *keydata)
127 gpgme_ctx_t ctx = NULL;
128 gpgme_key_t key = NULL;
133 if (gpgme_get_key(ctx, keyid, &key, 0))
141 gpgme_key_unref(key);
159 gpgme_ctx_t ctx = NULL;
160 gpgme_genkey_result_t keyresult = NULL;
161 gpgme_key_t primary_key = NULL;
178 gpgme_error_t err = gpgme_op_createkey(ctx,
buf_string(buf),
"ed25519", 0, 0, NULL,
179 GPGME_CREATE_NOPASSWD | GPGME_CREATE_FORCE |
180 GPGME_CREATE_NOEXPIRE);
185 mutt_error(
_(
"Error creating autocrypt key: %s"), gpgme_strerror(err));
188 keyresult = gpgme_op_genkey_result(ctx);
195 err = gpgme_get_key(ctx,
buf_string(keyid), &primary_key, 0);
200 err = gpgme_op_createsubkey(ctx, primary_key,
"cv25519", 0, 0,
201 GPGME_CREATE_NOPASSWD | GPGME_CREATE_NOEXPIRE);
204 mutt_error(
_(
"Error creating autocrypt key: %s"), gpgme_strerror(err));
216 gpgme_key_unref(primary_key);
232 gpgme_ctx_t ctx = NULL;
233 gpgme_key_t key = NULL;
242 if (gpgme_get_key(ctx,
buf_string(keyid), &key, 0))
245 if (key->revoked || key->expired || key->disabled || key->invalid ||
246 !key->can_encrypt || !key->can_sign)
263 gpgme_key_unref(key);
284 const char *prompt =
_(
"(c)reate new, or (s)elect existing GPG key?");
287 const char *letters =
_(
"cs");
320 gpgme_ctx_t ctx = NULL;
321 gpgme_data_t dh = NULL;
330 if (gpgme_data_new_from_mem(&dh,
buf_string(raw_keydata),
buf_len(raw_keydata), 0))
335 if (gpgme_op_import(ctx, dh))
338 gpgme_import_result_t result = gpgme_op_import_result(ctx);
339 if (!result->imports || !result->imports->fpr)
346 gpgme_data_release(dh);
360 gpgme_ctx_t ctx = NULL;
361 gpgme_key_t key = NULL;
369 if (gpgme_get_key(ctx, keyid, &key, 0))
373 if (key->revoked || key->expired || key->disabled || key->invalid || !key->can_encrypt)
377 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)
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.