NeoMutt  2025-12-11-911-gd8d604
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
pgp_make_key_attachment()

Generate a public key attachment. More...

+ Collaboration diagram for pgp_make_key_attachment():

Functions

struct Bodypgp_gpgme_make_key_attachment (void)
 Generate a public key attachment - Implements CryptModuleSpecs::pgp_make_key_attachment() -.
 
struct Bodypgp_class_make_key_attachment (void)
 Generate a public key attachment - Implements CryptModuleSpecs::pgp_make_key_attachment() -.
 

Detailed Description

Generate a public key attachment.

Return values
ptrNew Body containing the attachment
NULLError

Function Documentation

◆ pgp_gpgme_make_key_attachment()

struct Body * pgp_gpgme_make_key_attachment ( void )

Generate a public key attachment - Implements CryptModuleSpecs::pgp_make_key_attachment() -.

Definition at line 3781 of file crypt_gpgme.c.

3782{
3783 gpgme_ctx_t ctx = NULL;
3784 gpgme_key_t export_keys[2] = { 0 };
3785 gpgme_data_t keydata = NULL;
3786 struct Body *att = NULL;
3787 char buf[1024] = { 0 };
3788
3789 OptPgpCheckTrust = false;
3790
3791 struct CryptKeyInfo *key = crypt_ask_for_key(_("Please enter the key ID: "), NULL,
3793 if (!key)
3794 goto bail;
3795 export_keys[0] = key->kobj;
3796 export_keys[1] = NULL;
3797
3798 ctx = create_gpgme_context(false);
3799 gpgme_set_armor(ctx, 1);
3800 keydata = create_gpgme_data();
3801 gpgme_error_t err = gpgme_op_export_keys(ctx, export_keys, 0, keydata);
3802 if (err != GPG_ERR_NO_ERROR)
3803 {
3804 mutt_error(_("Error exporting key: %s"), gpgme_strerror(err));
3805 goto bail;
3806 }
3807
3808 char *tempf = data_object_to_tempfile(keydata, NULL);
3809 if (!tempf)
3810 goto bail;
3811
3812 att = mutt_body_new();
3813 /* tempf is a newly allocated string, so this is correct: */
3814 att->filename = tempf;
3815 att->unlink = true;
3816 att->use_disp = false;
3817 att->type = TYPE_APPLICATION;
3818 att->subtype = mutt_str_dup("pgp-keys");
3819 /* L10N: MIME description for exported (attached) keys.
3820 You can translate this entry to a non-ASCII string (it will be encoded),
3821 but it may be safer to keep it untranslated. */
3822 snprintf(buf, sizeof(buf), _("PGP Key 0x%s"), crypt_keyid(key));
3823 att->description = mutt_str_dup(buf);
3825
3826 att->length = mutt_file_get_size(tempf);
3827
3828bail:
3829 crypt_key_free(&key);
3830 gpgme_data_release(keydata);
3831 gpgme_release(ctx);
3832
3833 return att;
3834}
static gpgme_data_t create_gpgme_data(void)
Create a new GPGME data object.
gpgme_ctx_t create_gpgme_context(bool for_smime)
Create a new GPGME context.
static char * data_object_to_tempfile(gpgme_data_t data, FILE **fp_ret)
Copy a data object to a temporary file.
static struct CryptKeyInfo * crypt_ask_for_key(const char *tag, const char *whatfor, KeyFlags abilities, unsigned int app, bool *forced_valid)
Ask the user for a key.
const char * crypt_keyid(struct CryptKeyInfo *k)
Find the ID for the key.
static void crypt_key_free(struct CryptKeyInfo **keylist)
Release all the keys in a list.
struct Body * mutt_body_new(void)
Create a new Body.
Definition body.c:44
long mutt_file_get_size(const char *path)
Get the size of a file.
Definition file.c:1414
bool OptPgpCheckTrust
(pseudo) used by dlg_pgp()
Definition globals.c:55
#define mutt_error(...)
Definition logging2.h:94
@ TYPE_APPLICATION
Type: 'application/*'.
Definition mime.h:33
#define _(a)
Definition message.h:28
char * mutt_str_dup(const char *str)
Copy a string, safely.
Definition string.c:257
#define APPLICATION_PGP
Use PGP to encrypt/sign.
Definition lib.h:106
@ KEYFLAG_NONE
No flags are set.
Definition lib.h:146
void mutt_update_encoding(struct Body *b, struct ConfigSubset *sub)
Update the encoding type.
Definition sendlib.c:421
The body of an email.
Definition body.h:36
bool unlink
If true, filename should be unlink()ed before free()ing this structure.
Definition body.h:68
LOFF_T length
length (in bytes) of attachment
Definition body.h:53
bool use_disp
Content-Disposition uses filename= ?
Definition body.h:47
char * description
content-description
Definition body.h:55
char * subtype
content-type subtype
Definition body.h:61
unsigned int type
content-type primary type, ContentType
Definition body.h:40
char * filename
When sending a message, this is the file to which this structure refers.
Definition body.h:59
A stored PGP key.
Definition crypt_gpgme.h:44
gpgme_key_t kobj
GPGME key object.
Definition crypt_gpgme.h:46
Container for Accounts, Notifications.
Definition neomutt.h:41
struct ConfigSubset * sub
Inherited config items.
Definition neomutt.h:49
+ Here is the call graph for this function:

◆ pgp_class_make_key_attachment()

struct Body * pgp_class_make_key_attachment ( void )

Generate a public key attachment - Implements CryptModuleSpecs::pgp_make_key_attachment() -.

Definition at line 263 of file pgpkey.c.

264{
265 struct Body *att = NULL;
266 char buf[1024] = { 0 };
267 char tmp[256] = { 0 };
268 struct stat st = { 0 };
269 pid_t pid;
270 OptPgpCheckTrust = false;
271
272 struct PgpKeyInfo *key = pgp_ask_for_key(_("Please enter the key ID: "), NULL,
274
275 if (!key)
276 return NULL;
277
278 snprintf(tmp, sizeof(tmp), "0x%s", pgp_fpr_or_lkeyid(pgp_principal_key(key)));
279 pgp_key_free(&key);
280
281 struct Buffer *tempfile = buf_pool_get();
282 buf_mktemp(tempfile);
283 FILE *fp_tmp = mutt_file_fopen(buf_string(tempfile), "w");
284 if (!fp_tmp)
285 {
286 mutt_perror(_("Can't create temporary file"));
287 goto cleanup;
288 }
289
290 FILE *fp_null = mutt_file_fopen("/dev/null", "w");
291 if (!fp_null)
292 {
293 mutt_perror(_("Can't open /dev/null"));
294 mutt_file_fclose(&fp_tmp);
295 unlink(buf_string(tempfile));
296 goto cleanup;
297 }
298
299 mutt_message(_("Invoking PGP..."));
300
301 pid = pgp_invoke_export(NULL, NULL, NULL, -1, fileno(fp_tmp), fileno(fp_null), tmp);
302 if (pid == -1)
303 {
304 mutt_perror(_("Can't create filter"));
305 unlink(buf_string(tempfile));
306 mutt_file_fclose(&fp_tmp);
307 mutt_file_fclose(&fp_null);
308 goto cleanup;
309 }
310
311 filter_wait(pid);
312
313 mutt_file_fclose(&fp_tmp);
314 mutt_file_fclose(&fp_null);
315
316 att = mutt_body_new();
317 att->filename = buf_strdup(tempfile);
318 att->unlink = true;
319 att->use_disp = false;
320 att->type = TYPE_APPLICATION;
321 att->subtype = mutt_str_dup("pgp-keys");
322 snprintf(buf, sizeof(buf), _("PGP Key %s"), tmp);
323 att->description = mutt_str_dup(buf);
325
326 stat(buf_string(tempfile), &st);
327 att->length = st.st_size;
328
329cleanup:
330 buf_pool_release(&tempfile);
331 return att;
332}
char * buf_strdup(const struct Buffer *buf)
Copy a Buffer's string.
Definition buffer.c:571
static const char * buf_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition buffer.h:96
#define mutt_file_fclose(FP)
Definition file.h:144
#define mutt_file_fopen(PATH, MODE)
Definition file.h:143
#define mutt_message(...)
Definition logging2.h:93
#define mutt_perror(...)
Definition logging2.h:95
int filter_wait(pid_t pid)
Wait for the exit of a process and return its status.
Definition filter.c:228
char * pgp_fpr_or_lkeyid(struct PgpKeyInfo *k)
Get the fingerprint or long keyid.
Definition pgp.c:231
pid_t pgp_invoke_export(FILE **fp_pgp_in, FILE **fp_pgp_out, FILE **fp_pgp_err, int fd_pgp_in, int fd_pgp_out, int fd_pgp_err, const char *uids)
Use PGP to export a key from the user's keyring.
Definition pgpinvoke.c:374
struct PgpKeyInfo * pgp_ask_for_key(char *tag, const char *whatfor, KeyFlags abilities, enum PgpRing keyring)
Ask the user for a PGP key.
Definition pgpkey.c:202
struct PgpKeyInfo * pgp_principal_key(struct PgpKeyInfo *key)
Get the main (parent) PGP key.
Definition pgpkey.c:95
@ PGP_PUBRING
Public keys.
Definition pgpkey.h:40
void pgp_key_free(struct PgpKeyInfo **kpp)
Free a PGP key info.
Definition pgplib.c:201
struct Buffer * buf_pool_get(void)
Get a Buffer from the pool.
Definition pool.c:91
void buf_pool_release(struct Buffer **ptr)
Return a Buffer to the pool.
Definition pool.c:111
String manipulation buffer.
Definition buffer.h:36
Information about a PGP key.
Definition pgplib.h:49
#define buf_mktemp(buf)
Definition tmp.h:33
+ Here is the call graph for this function: