#include <stdbool.h>
#include <time.h>
#include "mutt/mutt.h"
+#include "ncrypt/ncrypt.h"
#include "tags.h"
/**
*/
struct Email
{
- unsigned int security : 12; /**< bit 0-8: flags, bit 9,10: application.
+ SecurityFlags security; /**< bit 0-8: flags, bit 9,10: application.
see: ncrypt/ncrypt.h pgplib.h, smime.h */
bool mime : 1; /**< has a MIME-Version email? */
/**
* crypt_valid_passphrase - Check that we have a usable passphrase, ask if not
- * @param flags Flags, e.g. #APPLICATION_PGP
+ * @param flags Flags, see #SecurityFlags
* @retval 0 Success
* @retval -1 Failure
*/
-int crypt_valid_passphrase(int flags)
+int crypt_valid_passphrase(SecurityFlags flags)
{
int rc = 0;
* mutt_is_application_pgp - Does the message use PGP?
* @param m Body of email
* @retval >0 Message uses PGP, e.g. #PGP_ENCRYPT
- * @retval 0 Message doesn't use PGP
+ * @retval 0 Message doesn't use PGP, (#SEC_NO_FLAGS)
*/
-int mutt_is_application_pgp(struct Body *m)
+SecurityFlags mutt_is_application_pgp(struct Body *m)
{
- int t = 0;
+ SecurityFlags t = SEC_NO_FLAGS;
char *p = NULL;
if (m->type == TYPE_APPLICATION)
* mutt_is_application_smime - Does the message use S/MIME?
* @param m Body of email
* @retval >0 Message uses S/MIME, e.g. #SMIME_ENCRYPT
- * @retval 0 Message doesn't use S/MIME
+ * @retval 0 Message doesn't use S/MIME, (#SEC_NO_FLAGS)
*/
-int mutt_is_application_smime(struct Body *m)
+SecurityFlags mutt_is_application_smime(struct Body *m)
{
if (!m)
- return 0;
+ return SEC_NO_FLAGS;
if (((m->type & TYPE_APPLICATION) == 0) || !m->subtype)
- return 0;
+ return SEC_NO_FLAGS;
char *t = NULL;
bool complain = false;
else if (mutt_str_strcasecmp(t, "signed-data") == 0)
return SMIME_SIGN | SMIME_OPAQUE;
else
- return 0;
+ return SEC_NO_FLAGS;
}
/* Netscape 4.7 uses
* Content-Description: S/MIME Encrypted Message
complain = true;
}
else if (mutt_str_strcasecmp(m->subtype, "octet-stream") != 0)
- return 0;
+ return SEC_NO_FLAGS;
t = mutt_param_get(&m->parameter, "name");
mutt_message(
_("S/MIME messages with no hints on content are unsupported"));
}
- return 0;
+ return SEC_NO_FLAGS;
}
/* no .p7c, .p10 support yet. */
return SMIME_SIGN | SMIME_OPAQUE;
}
- return 0;
+ return SEC_NO_FLAGS;
}
/**
* crypt_query - Check out the type of encryption used
* @param m Body of email
* @retval num Flags, e.g. #SEC_GOODSIGN
- * @retval 0 Error
+ * @retval 0 Error (#SEC_NO_FLAGS)
*
* Set the cached status values if there are any.
*/
int crypt_query(struct Body *m)
{
- int t = 0;
+ SecurityFlags t = SEC_NO_FLAGS;
if (!WithCrypto)
- return 0;
+ return SEC_NO_FLAGS;
if (!m)
- return 0;
+ return SEC_NO_FLAGS;
if (m->type == TYPE_APPLICATION)
{
int pgp_gpgme_check_traditional(FILE *fp, struct Body *b, bool just_one)
{
int rc = 0;
- int r;
for (; b; b = b->next)
{
if (!just_one && is_multipart(b))
rc = (pgp_gpgme_check_traditional(fp, b->parts, false) || rc);
else if (b->type == TYPE_TEXT)
{
- r = mutt_is_application_pgp(b);
+ SecurityFlags r = mutt_is_application_pgp(b);
if (r != 0)
rc = (rc || r);
else
*
* Select by looking at the HINTS list.
*/
-static struct CryptKeyInfo *get_candidates(struct ListHead *hints, unsigned int app, int secret)
+static struct CryptKeyInfo *get_candidates(struct ListHead *hints, SecurityFlags app, int secret)
{
struct CryptKeyInfo *db = NULL, *k = NULL, **kend = NULL;
gpgme_error_t err;
#include <stdbool.h>
#include <stdio.h>
+#include "ncrypt.h"
struct Address;
struct Body;
/**
* pgp_traditional_encryptsign - Create an inline PGP encrypted, signed email
* @param a Body of the email
- * @param flags Flags, e.g. #SEC_ENCRYPT
+ * @param flags Flags, see #SecurityFlags
* @param keylist List of keys to encrypt to (space-separated)
* @retval ptr New encrypted/siged Body
* @retval NULL Error
*/
- struct Body *(*pgp_traditional_encryptsign)(struct Body *a, int flags, char *keylist);
+ struct Body *(*pgp_traditional_encryptsign)(struct Body *a, SecurityFlags flags, char *keylist);
/**
* pgp_invoke_getkeys - Run a command to download a PGP key
* @param addr Address to search for
/**
* crypt_invoke_message - Display an informative message
- * @param type Crypto type, e.g. #APPLICATION_PGP
+ * @param type Crypto type, see #SecurityFlags
*
* Show a message that a backend will be invoked.
*/
-void crypt_invoke_message(int type)
+void crypt_invoke_message(SecurityFlags type)
{
if (((WithCrypto & APPLICATION_PGP) != 0) && (type & APPLICATION_PGP))
mutt_message(_("Invoking PGP..."));
/**
* crypt_has_module_backend - Is there a crypto backend for a given type?
- * @param type Crypto type, e.g. #APPLICATION_PGP
+ * @param type Crypto type, see #SecurityFlags
* @retval true Backend is present
* @retval false Backend is not present
*/
-bool crypt_has_module_backend(int type)
+bool crypt_has_module_backend(SecurityFlags type)
{
if (((WithCrypto & APPLICATION_PGP) != 0) && (type & APPLICATION_PGP) &&
crypto_module_lookup(APPLICATION_PGP))
extern char *C_SmimeVerifyCommand;
extern char *C_SmimeVerifyOpaqueCommand;
+typedef uint16_t SecurityFlags; ///< Flags, e.g. #SEC_ENCRYPT
+#define SEC_NO_FLAGS 0 ///< No flags are set
#define SEC_ENCRYPT (1 << 0) ///< Email is encrypted
#define SEC_SIGN (1 << 1) ///< Email is signed
#define SEC_GOODSIGN (1 << 2) ///< Email has a valid signature
int crypt_get_keys(struct Email *msg, char **keylist, bool oppenc_mode);
void crypt_opportunistic_encrypt(struct Email *msg);
int crypt_query(struct Body *m);
-int crypt_valid_passphrase(int flags);
-int mutt_is_application_pgp(struct Body *m);
-int mutt_is_application_smime(struct Body *m);
+int crypt_valid_passphrase(SecurityFlags flags);
+SecurityFlags mutt_is_application_pgp(struct Body *m);
+SecurityFlags mutt_is_application_smime(struct Body *m);
int mutt_is_malformed_multipart_pgp_encrypted(struct Body *b);
int mutt_is_multipart_encrypted(struct Body *b);
int mutt_is_multipart_signed(struct Body *b);
int mutt_signed_handler(struct Body *a, struct State *s);
/* cryptglue.c */
-bool crypt_has_module_backend(int type);
+bool crypt_has_module_backend(SecurityFlags type);
void crypt_init(void);
-void crypt_invoke_message(int type);
+void crypt_invoke_message(SecurityFlags type);
int crypt_pgp_application_handler(struct Body *m, struct State *s);
int crypt_pgp_check_traditional(FILE *fp, struct Body *b, bool just_one);
int crypt_pgp_decrypt_mime(FILE *a, FILE **b, struct Body *c, struct Body **d);
/**
* pgp_class_traditional_encryptsign - Implements CryptModuleSpecs::pgp_traditional_encryptsign()
*/
-struct Body *pgp_class_traditional_encryptsign(struct Body *a, int flags, char *keylist)
+struct Body *pgp_class_traditional_encryptsign(struct Body *a, SecurityFlags flags, char *keylist)
{
struct Body *b = NULL;
int pgp_class_valid_passphrase(void);
int pgp_class_verify_one(struct Body *sigbdy, struct State *s, const char *tempfile);
-struct Body *pgp_class_traditional_encryptsign(struct Body *a, int flags, char *keylist);
+struct Body *pgp_class_traditional_encryptsign(struct Body *a, SecurityFlags flags, char *keylist);
struct Body *pgp_class_encrypt_message(struct Body *a, char *keylist, bool sign);
struct Body *pgp_class_sign_message(struct Body *a);
* @param[in] pgperrfd stderr for the command, or -1 (OPTIONAL)
* @param[in] fname Filename to pass to the command
* @param[in] uids List of IDs/fingerprints, space separated
- * @param[in] flags Flags, e.g. #SEC_SIGN, #SEC_ENCRYPT
+ * @param[in] flags Flags, see #SecurityFlags
* @retval num PID of the created process
* @retval -1 Error creating pipes or forking
*
* @note `pgpin` has priority over `pgpinfd`.
* Likewise `pgpout` and `pgperr`.
*/
-pid_t pgp_invoke_traditional(FILE **pgpin, FILE **pgpout, FILE **pgperr,
- int pgpinfd, int pgpoutfd, int pgperrfd,
- const char *fname, const char *uids, int flags)
+pid_t pgp_invoke_traditional(FILE **pgpin, FILE **pgpout, FILE **pgperr, int pgpinfd,
+ int pgpoutfd, int pgperrfd, const char *fname,
+ const char *uids, SecurityFlags flags)
{
if (flags & SEC_ENCRYPT)
{
struct stat info;
struct Body *p = NULL;
pid_t thepid = -1;
- unsigned int type = mutt_is_application_smime(m);
+ SecurityFlags type = mutt_is_application_smime(m);
if (!(type & APPLICATION_SMIME))
return NULL;
* @param p Header string to parse
* @param set_empty_signas Allow an empty "Sign as"
* @param crypt_app App, e.g. #APPLICATION_PGP
- * @retval num Flags, e.g. #SEC_ENCRYPT
+ * @retval num SecurityFlags, see #SecurityFlags
*/
-int mutt_parse_crypt_hdr(const char *p, int set_empty_signas, int crypt_app)
+SecurityFlags mutt_parse_crypt_hdr(const char *p, int set_empty_signas, SecurityFlags crypt_app)
{
char smime_cryptalg[1024] = "\0";
char sign_as[1024] = "\0", *q = NULL;
- int flags = 0;
+ SecurityFlags flags = SEC_NO_FLAGS;
if (!WithCrypto)
- return 0;
+ return SEC_NO_FLAGS;
p = mutt_str_skip_email_wsp(p);
for (; *p; p++)
if (*p != '>')
{
mutt_error(_("Illegal S/MIME header"));
- return 0;
+ return SEC_NO_FLAGS;
}
}
if (*p != '>')
{
mutt_error(_("Illegal crypto header"));
- return 0;
+ return SEC_NO_FLAGS;
}
}
if (*p != '>')
{
mutt_error(_("Illegal crypto header"));
- return 0;
+ return SEC_NO_FLAGS;
}
}
default:
mutt_error(_("Illegal crypto header"));
- return 0;
+ return SEC_NO_FLAGS;
}
}
FILE *bfp = NULL;
int rc = -1;
struct State s = { 0 };
- int sec_type;
+ SecurityFlags sec_type;
struct Envelope *protected_headers = NULL;
if (!fp && !(msg = mx_msg_open(m, e->msgno)))
#include <time.h>
#include "config/lib.h"
#include "mutt.h"
+#include "ncrypt/ncrypt.h"
struct Context;
struct EnterState;
int mutt_enter_string_full(char *buf, size_t buflen, int col, CompletionFlags flags, bool multiple,
char ***files, int *numfiles, struct EnterState *state);
int mutt_get_postponed(struct Context *ctx, struct Email *e, struct Email **cur, char *fcc, size_t fcclen);
-int mutt_parse_crypt_hdr(const char *p, int set_empty_signas, int crypt_app);
+SecurityFlags mutt_parse_crypt_hdr(const char *p, int set_empty_signas, SecurityFlags crypt_app);
int mutt_num_postponed(struct Mailbox *m, bool force);
int mutt_thread_set_flag(struct Email *e, int flag, bool bf, bool subthread);
void mutt_update_num_postponed(void);
struct Body *m = NULL;
struct Body *new_body = NULL;
FILE *new_fp = NULL;
- int type, need_secured, secured;
+ SecurityFlags type;
+ int need_secured, secured;
for (m = parts; m; m = m->next)
{