NeoMutt  2024-11-14-34-g5aaf0d
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 1706 of file crypt_gpgme.c.

1707{
1708 return verify_one(b, state, tempfile, false);
1709}
static int verify_one(struct Body *b, struct State *state, const char *tempfile, bool is_smime)
Do the actual verification step.
Definition: crypt_gpgme.c:1581
+ 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 1714 of file crypt_gpgme.c.

1715{
1716 return verify_one(b, state, tempfile, true);
1717}
+ 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 898 of file pgp.c.

899{
900 FILE *fp_pgp_out = NULL;
901 pid_t pid;
902 int badsig = -1;
903 struct Buffer *sigfile = buf_pool_get();
904
905 buf_printf(sigfile, "%s.asc", tempfile);
906
907 FILE *fp_sig = mutt_file_fopen(buf_string(sigfile), "w");
908 if (!fp_sig)
909 {
910 mutt_perror("%s", buf_string(sigfile));
911 goto cleanup;
912 }
913
914 if (!mutt_file_seek(state->fp_in, b->offset, SEEK_SET))
915 {
916 mutt_file_fclose(&fp_sig);
917 goto cleanup;
918 }
919 mutt_file_copy_bytes(state->fp_in, fp_sig, b->length);
920 mutt_file_fclose(&fp_sig);
921
922 FILE *fp_pgp_err = mutt_file_mkstemp();
923 if (!fp_pgp_err)
924 {
925 mutt_perror(_("Can't create temporary file"));
926 unlink(buf_string(sigfile));
927 goto cleanup;
928 }
929
930 crypt_current_time(state, "PGP");
931
932 pid = pgp_invoke_verify(NULL, &fp_pgp_out, NULL, -1, -1, fileno(fp_pgp_err),
933 tempfile, buf_string(sigfile));
934 if (pid != -1)
935 {
936 if (pgp_copy_checksig(fp_pgp_out, state->fp_out) >= 0)
937 badsig = 0;
938
939 mutt_file_fclose(&fp_pgp_out);
940 fflush(fp_pgp_err);
941 rewind(fp_pgp_err);
942
943 if (pgp_copy_checksig(fp_pgp_err, state->fp_out) >= 0)
944 badsig = 0;
945
946 const int rv = filter_wait(pid);
947 if (rv)
948 badsig = -1;
949
950 mutt_debug(LL_DEBUG1, "filter_wait returned %d\n", rv);
951 }
952
953 mutt_file_fclose(&fp_pgp_err);
954
955 state_attach_puts(state, _("[-- End of PGP output --]\n\n"));
956
958
959cleanup:
960 buf_pool_release(&sigfile);
961
962 mutt_debug(LL_DEBUG1, "returning %d\n", badsig);
963 return badsig;
964}
int buf_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:161
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:65
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:257
bool mutt_file_seek(FILE *fp, LOFF_T offset, int whence)
Wrapper for fseeko with error handling.
Definition: file.c:778
void mutt_file_unlink(const char *s)
Delete a file, carefully.
Definition: file.c:221
#define mutt_file_fclose(FP)
Definition: file.h:138
#define mutt_file_fopen(PATH, MODE)
Definition: file.h:137
#define mutt_debug(LEVEL,...)
Definition: logging2.h:89
#define mutt_perror(...)
Definition: logging2.h:93
@ LL_DEBUG1
Log at debug level 1.
Definition: logging2.h:43
int filter_wait(pid_t pid)
Wait for the exit of a process and return its status.
Definition: filter.c:220
#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:103
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:251
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:225
struct Buffer * buf_pool_get(void)
Get a Buffer from the pool.
Definition: pool.c:81
void buf_pool_release(struct Buffer **ptr)
Return a Buffer to the pool.
Definition: pool.c:94
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:50
FILE * fp_in
File to read from.
Definition: state.h:49
#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 1708 of file smime.c.

1709{
1710 FILE *fp = NULL, *fp_smime_out = NULL, *fp_smime_err = NULL;
1711 pid_t pid;
1712 int badsig = -1;
1713
1714 LOFF_T tmpoffset = 0;
1715 size_t tmplength = 0;
1716 int orig_type = b->type;
1717
1718 struct Buffer *signedfile = buf_pool_get();
1719
1720 buf_printf(signedfile, "%s.sig", tempfile);
1721
1722 /* decode to a tempfile, saving the original destination */
1723 fp = state->fp_out;
1724 state->fp_out = mutt_file_fopen(buf_string(signedfile), "w");
1725 if (!state->fp_out)
1726 {
1727 mutt_perror("%s", buf_string(signedfile));
1728 goto cleanup;
1729 }
1730 /* decoding the attachment changes the size and offset, so save a copy
1731 * of the "real" values now, and restore them after processing */
1732 tmplength = b->length;
1733 tmpoffset = b->offset;
1734
1735 /* if we are decoding binary bodies, we don't want to prefix each
1736 * line with the prefix or else the data will get corrupted. */
1737 const char *save_prefix = state->prefix;
1738 state->prefix = NULL;
1739
1740 mutt_decode_attachment(b, state);
1741
1742 b->length = ftello(state->fp_out);
1743 b->offset = 0;
1744 mutt_file_fclose(&state->fp_out);
1745
1746 /* restore final destination and substitute the tempfile for input */
1747 state->fp_out = fp;
1748 fp = state->fp_in;
1749 state->fp_in = mutt_file_fopen(buf_string(signedfile), "r");
1750
1751 /* restore the prefix */
1752 state->prefix = save_prefix;
1753
1754 b->type = orig_type;
1755
1756 fp_smime_err = mutt_file_mkstemp();
1757 if (!fp_smime_err)
1758 {
1759 mutt_perror(_("Can't create temporary file"));
1760 goto cleanup;
1761 }
1762
1763 crypt_current_time(state, "OpenSSL");
1764
1765 pid = smime_invoke_verify(NULL, &fp_smime_out, NULL, -1, -1, fileno(fp_smime_err),
1766 tempfile, buf_string(signedfile), 0);
1767 if (pid != -1)
1768 {
1769 fflush(fp_smime_out);
1770 mutt_file_fclose(&fp_smime_out);
1771
1772 if (filter_wait(pid))
1773 {
1774 badsig = -1;
1775 }
1776 else
1777 {
1778 char *line = NULL;
1779 size_t linelen;
1780
1781 fflush(fp_smime_err);
1782 rewind(fp_smime_err);
1783
1784 line = mutt_file_read_line(line, &linelen, fp_smime_err, NULL, MUTT_RL_NO_FLAGS);
1785 if (linelen && mutt_istr_equal(line, "verification successful"))
1786 badsig = 0;
1787
1788 FREE(&line);
1789 }
1790 }
1791
1792 fflush(fp_smime_err);
1793 rewind(fp_smime_err);
1794 mutt_file_copy_stream(fp_smime_err, state->fp_out);
1795 mutt_file_fclose(&fp_smime_err);
1796
1797 state_attach_puts(state, _("[-- End of OpenSSL output --]\n\n"));
1798
1799 mutt_file_unlink(buf_string(signedfile));
1800
1801 b->length = tmplength;
1802 b->offset = tmpoffset;
1803
1804 /* restore the original source stream */
1805 mutt_file_fclose(&state->fp_in);
1806 state->fp_in = fp;
1807
1808cleanup:
1809 buf_pool_release(&signedfile);
1810 return badsig;
1811}
int mutt_file_copy_stream(FILE *fp_in, FILE *fp_out)
Copy the contents of one file into another.
Definition: file.c:287
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:808
#define MUTT_RL_NO_FLAGS
No flags are set.
Definition: file.h:40
void mutt_decode_attachment(const struct Body *b, struct State *state)
Decode an email's attachment.
Definition: handler.c:1905
#define FREE(x)
Definition: memory.h:55
bool mutt_istr_equal(const char *a, const char *b)
Compare two strings, ignoring case.
Definition: string.c:672
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:1666
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:51
+ Here is the call graph for this function: