NeoMutt  2023-05-17-33-gce4425
Teaching an old dog new tricks
DOXYGEN
verify_one()

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

+ Collaboration diagram for verify_one():

Functions

int pgp_gpgme_verify_one (struct Body *sigbdy, struct State *state, const char *tempfile)
 Implements CryptModuleSpecs::verify_one() -. More...
 
int smime_gpgme_verify_one (struct Body *sigbdy, struct State *state, const char *tempfile)
 Implements CryptModuleSpecs::verify_one() -. More...
 
int pgp_class_verify_one (struct Body *sigbdy, struct State *state, const char *tempfile)
 Implements CryptModuleSpecs::verify_one() -. More...
 
int smime_class_verify_one (struct Body *sigbdy, struct State *state, const char *tempfile)
 Implements CryptModuleSpecs::verify_one() -. More...
 

Detailed Description

Check a signed MIME part against a signature.

Parameters
sigbdyBody 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 sigbdy,
struct State state,
const char *  tempfile 
)

Implements CryptModuleSpecs::verify_one() -.

Definition at line 1668 of file crypt_gpgme.c.

1669{
1670 return verify_one(sigbdy, state, tempfile, false);
1671}
static int verify_one(struct Body *sigbdy, struct State *state, const char *tempfile, bool is_smime)
Do the actual verification step.
Definition: crypt_gpgme.c:1541
+ Here is the call graph for this function:

◆ smime_gpgme_verify_one()

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

Implements CryptModuleSpecs::verify_one() -.

Definition at line 1676 of file crypt_gpgme.c.

1677{
1678 return verify_one(sigbdy, state, tempfile, true);
1679}
+ Here is the call graph for this function:

◆ pgp_class_verify_one()

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

Implements CryptModuleSpecs::verify_one() -.

Definition at line 900 of file pgp.c.

901{
902 FILE *fp_pgp_out = NULL;
903 pid_t pid;
904 int badsig = -1;
905 struct Buffer *sigfile = buf_pool_get();
906
907 buf_printf(sigfile, "%s.asc", tempfile);
908
909 FILE *fp_sig = mutt_file_fopen(buf_string(sigfile), "w");
910 if (!fp_sig)
911 {
912 mutt_perror(buf_string(sigfile));
913 goto cleanup;
914 }
915
916 if (!mutt_file_seek(state->fp_in, sigbdy->offset, SEEK_SET))
917 {
918 mutt_file_fclose(&fp_sig);
919 goto cleanup;
920 }
921 mutt_file_copy_bytes(state->fp_in, fp_sig, sigbdy->length);
922 mutt_file_fclose(&fp_sig);
923
924 FILE *fp_pgp_err = mutt_file_mkstemp();
925 if (!fp_pgp_err)
926 {
927 mutt_perror(_("Can't create temporary file"));
928 unlink(buf_string(sigfile));
929 goto cleanup;
930 }
931
932 crypt_current_time(state, "PGP");
933
934 pid = pgp_invoke_verify(NULL, &fp_pgp_out, NULL, -1, -1, fileno(fp_pgp_err),
935 tempfile, buf_string(sigfile));
936 if (pid != -1)
937 {
938 if (pgp_copy_checksig(fp_pgp_out, state->fp_out) >= 0)
939 badsig = 0;
940
941 mutt_file_fclose(&fp_pgp_out);
942 fflush(fp_pgp_err);
943 rewind(fp_pgp_err);
944
945 if (pgp_copy_checksig(fp_pgp_err, state->fp_out) >= 0)
946 badsig = 0;
947
948 const int rv = filter_wait(pid);
949 if (rv)
950 badsig = -1;
951
952 mutt_debug(LL_DEBUG1, "filter_wait returned %d\n", rv);
953 }
954
955 mutt_file_fclose(&fp_pgp_err);
956
957 state_attach_puts(state, _("[-- End of PGP output --]\n\n"));
958
960
961cleanup:
962 buf_pool_release(&sigfile);
963
964 mutt_debug(LL_DEBUG1, "returning %d\n", badsig);
965 return badsig;
966}
int buf_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:171
static const char * buf_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition: buffer.h:78
void crypt_current_time(struct State *state, const char *app_name)
Print the current time.
Definition: crypt.c:69
FILE * mutt_file_fopen(const char *path, const char *mode)
Call fopen() safely.
Definition: file.c:634
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:230
int mutt_file_fclose(FILE **fp)
Close a FILE handle (and NULL the pointer)
Definition: file.c:150
bool mutt_file_seek(FILE *fp, LOFF_T offset, int whence)
Wrapper for fseeko with error handling.
Definition: file.c:708
void mutt_file_unlink(const char *s)
Delete a file, carefully.
Definition: file.c:194
int filter_wait(pid_t pid)
Wait for the exit of a process and return its status.
Definition: filter.c:217
#define mutt_debug(LEVEL,...)
Definition: logging2.h:84
#define mutt_perror(...)
Definition: logging2.h:88
@ LL_DEBUG1
Log at debug level 1.
Definition: logging2.h:40
#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:102
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:252
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:288
struct Buffer * buf_pool_get(void)
Get a Buffer from the pool.
Definition: pool.c:106
void buf_pool_release(struct Buffer **ptr)
Return a Buffer to the pool.
Definition: pool.c:119
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:34
FILE * fp_out
File to write to.
Definition: state.h:49
FILE * fp_in
File to read from.
Definition: state.h:48
#define mutt_file_mkstemp()
Definition: tmp.h:40
+ Here is the call graph for this function:

◆ smime_class_verify_one()

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

Implements CryptModuleSpecs::verify_one() -.

Definition at line 1756 of file smime.c.

1757{
1758 FILE *fp = NULL, *fp_smime_out = NULL, *fp_smime_err = NULL;
1759 pid_t pid;
1760 int badsig = -1;
1761
1762 LOFF_T tmpoffset = 0;
1763 size_t tmplength = 0;
1764 int orig_type = sigbdy->type;
1765
1766 struct Buffer *signedfile = buf_pool_get();
1767
1768 buf_printf(signedfile, "%s.sig", tempfile);
1769
1770 /* decode to a tempfile, saving the original destination */
1771 fp = state->fp_out;
1772 state->fp_out = mutt_file_fopen(buf_string(signedfile), "w");
1773 if (!state->fp_out)
1774 {
1775 mutt_perror(buf_string(signedfile));
1776 goto cleanup;
1777 }
1778 /* decoding the attachment changes the size and offset, so save a copy
1779 * of the "real" values now, and restore them after processing */
1780 tmplength = sigbdy->length;
1781 tmpoffset = sigbdy->offset;
1782
1783 /* if we are decoding binary bodies, we don't want to prefix each
1784 * line with the prefix or else the data will get corrupted. */
1785 char *save_prefix = state->prefix;
1786 state->prefix = NULL;
1787
1788 mutt_decode_attachment(sigbdy, state);
1789
1790 sigbdy->length = ftello(state->fp_out);
1791 sigbdy->offset = 0;
1792 mutt_file_fclose(&state->fp_out);
1793
1794 /* restore final destination and substitute the tempfile for input */
1795 state->fp_out = fp;
1796 fp = state->fp_in;
1797 state->fp_in = fopen(buf_string(signedfile), "r");
1798
1799 /* restore the prefix */
1800 state->prefix = save_prefix;
1801
1802 sigbdy->type = orig_type;
1803
1804 fp_smime_err = mutt_file_mkstemp();
1805 if (!fp_smime_err)
1806 {
1807 mutt_perror(_("Can't create temporary file"));
1808 goto cleanup;
1809 }
1810
1811 crypt_current_time(state, "OpenSSL");
1812
1813 pid = smime_invoke_verify(NULL, &fp_smime_out, NULL, -1, -1, fileno(fp_smime_err),
1814 tempfile, buf_string(signedfile), 0);
1815 if (pid != -1)
1816 {
1817 fflush(fp_smime_out);
1818 mutt_file_fclose(&fp_smime_out);
1819
1820 if (filter_wait(pid))
1821 {
1822 badsig = -1;
1823 }
1824 else
1825 {
1826 char *line = NULL;
1827 size_t linelen;
1828
1829 fflush(fp_smime_err);
1830 rewind(fp_smime_err);
1831
1832 line = mutt_file_read_line(line, &linelen, fp_smime_err, NULL, MUTT_RL_NO_FLAGS);
1833 if (linelen && mutt_istr_equal(line, "verification successful"))
1834 badsig = 0;
1835
1836 FREE(&line);
1837 }
1838 }
1839
1840 fflush(fp_smime_err);
1841 rewind(fp_smime_err);
1842 mutt_file_copy_stream(fp_smime_err, state->fp_out);
1843 mutt_file_fclose(&fp_smime_err);
1844
1845 state_attach_puts(state, _("[-- End of OpenSSL output --]\n\n"));
1846
1847 mutt_file_unlink(buf_string(signedfile));
1848
1849 sigbdy->length = tmplength;
1850 sigbdy->offset = tmpoffset;
1851
1852 /* restore the original source stream */
1853 mutt_file_fclose(&state->fp_in);
1854 state->fp_in = fp;
1855
1856cleanup:
1857 buf_pool_release(&signedfile);
1858 return badsig;
1859}
int mutt_file_copy_stream(FILE *fp_in, FILE *fp_out)
Copy the contents of one file into another.
Definition: file.c:260
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:738
#define MUTT_RL_NO_FLAGS
No flags are set.
Definition: file.h:39
void mutt_decode_attachment(struct Body *b, struct State *state)
Decode an email's attachment.
Definition: handler.c:1892
#define FREE(x)
Definition: memory.h:43
bool mutt_istr_equal(const char *a, const char *b)
Compare two strings, ignoring case.
Definition: string.c:810
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:1715
unsigned int type
content-type primary type, ContentType
Definition: body.h:40
char * prefix
String to add to the beginning of each output line.
Definition: state.h:50
+ Here is the call graph for this function: