NeoMutt  2025-12-11-1009-ga75d9e
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
verify_one()

Check a signed MIME part against a signature. More...

Collaboration diagram for verify_one():

Functions

int pgp_gpgme_verify_one (struct Body *b, struct State *state, const char *tempfile)
 Check a signed MIME part against a signature - Implements CryptModuleSpecs::verify_one() -.
int smime_gpgme_verify_one (struct Body *b, struct State *state, const char *tempfile)
 Check a signed MIME part against a signature - Implements CryptModuleSpecs::verify_one() -.
int pgp_class_verify_one (struct Body *b, struct State *state, const char *tempfile)
 Check a signed MIME part against a signature - Implements CryptModuleSpecs::verify_one() -.
int smime_class_verify_one (struct Body *b, struct State *state, const char *tempfile)
 Check a signed MIME part against a signature - Implements CryptModuleSpecs::verify_one() -.

Detailed Description

Check a signed MIME part against a signature.

Parameters
bBody of the signed mail
stateState of text being processed
tempfFile containing the key
Return values
0Success
-1Error

Function Documentation

◆ pgp_gpgme_verify_one()

int pgp_gpgme_verify_one ( struct Body * b,
struct State * state,
const char * tempfile )

Check a signed MIME part against a signature - Implements CryptModuleSpecs::verify_one() -.

Definition at line 1718 of file crypt_gpgme.c.

1719{
1720 return verify_one(b, state, tempfile, false);
1721}
static int verify_one(struct Body *b, struct State *state, const char *tempfile, bool is_smime)
Do the actual verification step.
Here is the call graph for this function:

◆ smime_gpgme_verify_one()

int smime_gpgme_verify_one ( struct Body * b,
struct State * state,
const char * tempfile )

Check a signed MIME part against a signature - Implements CryptModuleSpecs::verify_one() -.

Definition at line 1726 of file crypt_gpgme.c.

1727{
1728 return verify_one(b, state, tempfile, true);
1729}
Here is the call graph for this function:

◆ pgp_class_verify_one()

int pgp_class_verify_one ( struct Body * b,
struct State * state,
const char * tempfile )

Check a signed MIME part against a signature - Implements CryptModuleSpecs::verify_one() -.

Definition at line 899 of file pgp.c.

900{
901 FILE *fp_pgp_out = NULL;
902 pid_t pid;
903 int badsig = -1;
904 struct Buffer *sigfile = buf_pool_get();
905
906 buf_printf(sigfile, "%s.asc", tempfile);
907
908 FILE *fp_sig = mutt_file_fopen(buf_string(sigfile), "w");
909 if (!fp_sig)
910 {
911 mutt_perror("%s", buf_string(sigfile));
912 goto cleanup;
913 }
914
915 if (!mutt_file_seek(state->fp_in, b->offset, SEEK_SET))
916 {
917 mutt_file_fclose(&fp_sig);
918 goto cleanup;
919 }
920 mutt_file_copy_bytes(state->fp_in, fp_sig, b->length);
921 mutt_file_fclose(&fp_sig);
922
923 FILE *fp_pgp_err = mutt_file_mkstemp();
924 if (!fp_pgp_err)
925 {
926 mutt_perror(_("Can't create temporary file"));
927 unlink(buf_string(sigfile));
928 goto cleanup;
929 }
930
931 crypt_current_time(state, "PGP");
932
933 pid = pgp_invoke_verify(NULL, &fp_pgp_out, NULL, -1, -1, fileno(fp_pgp_err),
934 tempfile, buf_string(sigfile));
935 if (pid != -1)
936 {
937 if (pgp_copy_checksig(fp_pgp_out, state->fp_out) >= 0)
938 badsig = 0;
939
940 mutt_file_fclose(&fp_pgp_out);
941 fflush(fp_pgp_err);
942 rewind(fp_pgp_err);
943
944 if (pgp_copy_checksig(fp_pgp_err, state->fp_out) >= 0)
945 badsig = 0;
946
947 const int rv = filter_wait(pid);
948 if (rv)
949 badsig = -1;
950
951 mutt_debug(LL_DEBUG1, "filter_wait returned %d\n", rv);
952 }
953
954 mutt_file_fclose(&fp_pgp_err);
955
956 state_attach_puts(state, _("[-- End of PGP output --]\n\n"));
957
959
960cleanup:
961 buf_pool_release(&sigfile);
962
963 mutt_debug(LL_DEBUG1, "returning %d\n", badsig);
964 return badsig;
965}
int buf_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition buffer.c:168
static const char * buf_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition buffer.h:96
void crypt_current_time(struct State *state, const char *app_name)
Print the current time.
Definition crypt.c:64
int mutt_file_copy_bytes(FILE *fp_in, FILE *fp_out, size_t size)
Copy some content from one file to another.
Definition file.c:192
bool mutt_file_seek(FILE *fp, LOFF_T offset, int whence)
Wrapper for fseeko with error handling.
Definition file.c:648
void mutt_file_unlink(const char *s)
Delete a file, carefully.
Definition file.c:156
#define mutt_file_fclose(FP)
Definition file.h:144
#define mutt_file_fopen(PATH, MODE)
Definition file.h:143
#define mutt_debug(LEVEL,...)
Definition logging2.h:91
#define mutt_perror(...)
Definition logging2.h:95
@ LL_DEBUG1
Log at debug level 1.
Definition logging2.h:45
int filter_wait(pid_t pid)
Wait for the exit of a process and return its status.
Definition filter.c:231
#define _(a)
Definition message.h:28
void state_attach_puts(struct State *state, const char *t)
Write a string to the state.
Definition state.c:104
static int pgp_copy_checksig(FILE *fp_in, FILE *fp_out)
Copy PGP output and look for signs of a good signature.
Definition pgp.c:248
pid_t pgp_invoke_verify(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 *fname, const char *sig_fname)
Use PGP to verify a message.
Definition pgpinvoke.c:157
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
LOFF_T offset
offset where the actual data begins
Definition body.h:52
LOFF_T length
length (in bytes) of attachment
Definition body.h:53
String manipulation buffer.
Definition buffer.h:36
FILE * fp_out
File to write to.
Definition state.h:56
FILE * fp_in
File to read from.
Definition state.h:55
#define mutt_file_mkstemp()
Definition tmp.h:36
Here is the call graph for this function:

◆ smime_class_verify_one()

int smime_class_verify_one ( struct Body * b,
struct State * state,
const char * tempfile )

Check a signed MIME part against a signature - Implements CryptModuleSpecs::verify_one() -.

Definition at line 1585 of file smime.c.

1586{
1587 FILE *fp = NULL;
1588 FILE *fp_smime_out = NULL;
1589 FILE *fp_smime_err = NULL;
1590 pid_t pid;
1591 int badsig = -1;
1592
1593 LOFF_T tmpoffset = 0;
1594 size_t tmplength = 0;
1595 int orig_type = b->type;
1596
1597 struct Buffer *signedfile = buf_pool_get();
1598
1599 buf_printf(signedfile, "%s.sig", tempfile);
1600
1601 /* decode to a tempfile, saving the original destination */
1602 fp = state->fp_out;
1603 state->fp_out = mutt_file_fopen(buf_string(signedfile), "w");
1604 if (!state->fp_out)
1605 {
1606 mutt_perror("%s", buf_string(signedfile));
1607 goto cleanup;
1608 }
1609 /* decoding the attachment changes the size and offset, so save a copy
1610 * of the "real" values now, and restore them after processing */
1611 tmplength = b->length;
1612 tmpoffset = b->offset;
1613
1614 /* if we are decoding binary bodies, we don't want to prefix each
1615 * line with the prefix or else the data will get corrupted. */
1616 const char *save_prefix = state->prefix;
1617 state->prefix = NULL;
1618
1619 mutt_decode_attachment(b, state);
1620
1621 b->length = ftello(state->fp_out);
1622 b->offset = 0;
1623 mutt_file_fclose(&state->fp_out);
1624
1625 /* restore final destination and substitute the tempfile for input */
1626 state->fp_out = fp;
1627 fp = state->fp_in;
1628 state->fp_in = mutt_file_fopen(buf_string(signedfile), "r");
1629
1630 /* restore the prefix */
1631 state->prefix = save_prefix;
1632
1633 b->type = orig_type;
1634
1635 fp_smime_err = mutt_file_mkstemp();
1636 if (!fp_smime_err)
1637 {
1638 mutt_perror(_("Can't create temporary file"));
1639 goto cleanup;
1640 }
1641
1642 crypt_current_time(state, "OpenSSL");
1643
1644 pid = smime_invoke_verify(NULL, &fp_smime_out, NULL, -1, -1, fileno(fp_smime_err),
1645 tempfile, buf_string(signedfile), 0);
1646 if (pid != -1)
1647 {
1648 fflush(fp_smime_out);
1649 mutt_file_fclose(&fp_smime_out);
1650
1651 if (filter_wait(pid))
1652 {
1653 badsig = -1;
1654 }
1655 else
1656 {
1657 char *line = NULL;
1658 size_t linelen = 0;
1659
1660 fflush(fp_smime_err);
1661 rewind(fp_smime_err);
1662
1663 line = mutt_file_read_line(line, &linelen, fp_smime_err, NULL, MUTT_RL_NONE);
1664 if (linelen && mutt_istr_equal(line, "verification successful"))
1665 badsig = 0;
1666
1667 FREE(&line);
1668 }
1669 }
1670
1671 fflush(fp_smime_err);
1672 rewind(fp_smime_err);
1673 mutt_file_copy_stream(fp_smime_err, state->fp_out);
1674 mutt_file_fclose(&fp_smime_err);
1675
1676 state_attach_puts(state, _("[-- End of OpenSSL output --]\n\n"));
1677
1678 mutt_file_unlink(buf_string(signedfile));
1679
1680 b->length = tmplength;
1681 b->offset = tmpoffset;
1682
1683 /* restore the original source stream */
1684 mutt_file_fclose(&state->fp_in);
1685 state->fp_in = fp;
1686
1687cleanup:
1688 buf_pool_release(&signedfile);
1689 return badsig;
1690}
int mutt_file_copy_stream(FILE *fp_in, FILE *fp_out)
Copy the contents of one file into another.
Definition file.c:224
char * mutt_file_read_line(char *line, size_t *size, FILE *fp, int *line_num, ReadLineFlags flags)
Read a line from a file.
Definition file.c:678
@ MUTT_RL_NONE
No flags are set.
Definition file.h:43
void mutt_decode_attachment(const struct Body *b, struct State *state)
Decode an email's attachment.
Definition handler.c:1943
#define FREE(x)
Free memory and set the pointer to NULL.
Definition memory.h:68
bool mutt_istr_equal(const char *a, const char *b)
Compare two strings, ignoring case.
Definition string.c:678
static pid_t smime_invoke_verify(FILE **fp_smime_in, FILE **fp_smime_out, FILE **fp_smime_err, int fp_smime_infd, int fp_smime_outfd, int fp_smime_errfd, const char *fname, const char *sig_fname, int opaque)
Use SMIME to verify a file.
Definition smime.c:1541
unsigned int type
content-type primary type, ContentType
Definition body.h:40
const char * prefix
String to add to the beginning of each output line.
Definition state.h:57
Here is the call graph for this function: