* crypto: implement 'mu verify' command -- WIP
This commit is contained in:
@ -452,8 +452,8 @@ include_attachments (MuMsg *msg)
|
|||||||
GString *gstr;
|
GString *gstr;
|
||||||
|
|
||||||
attlist = NULL;
|
attlist = NULL;
|
||||||
mu_msg_part_foreach (msg, FALSE, (MuMsgPartForeachFunc)each_part,
|
mu_msg_part_foreach (msg, (MuMsgPartForeachFunc)each_part,
|
||||||
&attlist);
|
&attlist, MU_MSG_PART_OPTION_NONE);
|
||||||
|
|
||||||
gstr = g_string_sized_new (512);
|
gstr = g_string_sized_new (512);
|
||||||
gstr = g_string_append_c (gstr, '(');
|
gstr = g_string_append_c (gstr, '(');
|
||||||
|
|||||||
68
mu/mu-cmd.c
68
mu/mu-cmd.c
@ -40,6 +40,10 @@
|
|||||||
#include "mu-flags.h"
|
#include "mu-flags.h"
|
||||||
#include "mu-store.h"
|
#include "mu-store.h"
|
||||||
|
|
||||||
|
#ifdef BUILD_CRYPTO
|
||||||
|
#include "mu-msg-crypto.h"
|
||||||
|
#endif /*BUILD_CRYPTO*/
|
||||||
|
|
||||||
#define VIEW_TERMINATOR '\f' /* form-feed */
|
#define VIEW_TERMINATOR '\f' /* form-feed */
|
||||||
|
|
||||||
|
|
||||||
@ -79,8 +83,8 @@ get_attach_str (MuMsg *msg)
|
|||||||
gchar *attach;
|
gchar *attach;
|
||||||
|
|
||||||
attach = NULL;
|
attach = NULL;
|
||||||
mu_msg_part_foreach (msg, FALSE,
|
mu_msg_part_foreach (msg, (MuMsgPartForeachFunc)each_part, &attach,
|
||||||
(MuMsgPartForeachFunc)each_part, &attach);
|
MU_MSG_PART_OPTION_NONE);
|
||||||
|
|
||||||
return attach;
|
return attach;
|
||||||
}
|
}
|
||||||
@ -391,6 +395,65 @@ mu_cmd_remove (MuStore *store, MuConfig *opts, GError **err)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef BUILD_CRYPTO
|
||||||
|
static void print_signatures (MuMsg *msg, MuMsgPart *part, MuConfig *opts)
|
||||||
|
{
|
||||||
|
GSList *cur;
|
||||||
|
|
||||||
|
if (!part->sig_infos)
|
||||||
|
return;
|
||||||
|
|
||||||
|
g_print ("MIME-part %u has %u signature(s): ",
|
||||||
|
part->index, g_slist_length (part->sig_infos));
|
||||||
|
|
||||||
|
for (cur = part->sig_infos; cur; cur = g_slist_next (cur)) {
|
||||||
|
char *descr;
|
||||||
|
descr = mu_msg_part_sig_info_to_string
|
||||||
|
((MuMsgPartSigInfo*)cur->data);
|
||||||
|
g_print ("%s\n", descr);
|
||||||
|
g_free (descr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
MuError
|
||||||
|
mu_cmd_verify (MuConfig *opts, GError **err)
|
||||||
|
{
|
||||||
|
MuMsg *msg;
|
||||||
|
MuMsgPartOptions partopts;
|
||||||
|
|
||||||
|
g_return_val_if_fail (opts, MU_ERROR_INTERNAL);
|
||||||
|
g_return_val_if_fail (opts->cmd == MU_CONFIG_CMD_VERIFY,
|
||||||
|
MU_ERROR_INTERNAL);
|
||||||
|
|
||||||
|
msg = mu_msg_new_from_file (opts->params[1], NULL, err);
|
||||||
|
if (!msg)
|
||||||
|
return MU_ERROR;
|
||||||
|
|
||||||
|
partopts = MU_MSG_PART_OPTION_CHECK_SIGNATURES;
|
||||||
|
if (opts->auto_retrieve)
|
||||||
|
partopts |= MU_MSG_PART_OPTION_AUTO_RETRIEVE_KEY;
|
||||||
|
if (opts->use_agent)
|
||||||
|
partopts |= MU_MSG_PART_OPTION_USE_AGENT;
|
||||||
|
|
||||||
|
mu_msg_part_foreach (msg,(MuMsgPartForeachFunc)print_signatures, opts,
|
||||||
|
partopts);
|
||||||
|
|
||||||
|
mu_msg_unref (msg);
|
||||||
|
|
||||||
|
return MU_OK;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
MuError
|
||||||
|
mu_cmd_verify (MuConfig *opts, GError **err)
|
||||||
|
{
|
||||||
|
g_warning ("Your version of mu does not support crypto");
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /*!BUILD_CRYPTO*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
show_usage (void)
|
show_usage (void)
|
||||||
{
|
{
|
||||||
@ -466,6 +529,7 @@ mu_cmd_execute (MuConfig *opts, GError **err)
|
|||||||
case MU_CONFIG_CMD_CFIND: return mu_cmd_cfind (opts, err);
|
case MU_CONFIG_CMD_CFIND: return mu_cmd_cfind (opts, err);
|
||||||
case MU_CONFIG_CMD_MKDIR: return mu_cmd_mkdir (opts, err);
|
case MU_CONFIG_CMD_MKDIR: return mu_cmd_mkdir (opts, err);
|
||||||
case MU_CONFIG_CMD_VIEW: return mu_cmd_view (opts, err);
|
case MU_CONFIG_CMD_VIEW: return mu_cmd_view (opts, err);
|
||||||
|
case MU_CONFIG_CMD_VERIFY: return mu_cmd_verify (opts, err);
|
||||||
case MU_CONFIG_CMD_EXTRACT: return mu_cmd_extract (opts, err);
|
case MU_CONFIG_CMD_EXTRACT: return mu_cmd_extract (opts, err);
|
||||||
|
|
||||||
case MU_CONFIG_CMD_FIND:
|
case MU_CONFIG_CMD_FIND:
|
||||||
|
|||||||
14
mu/mu-cmd.h
14
mu/mu-cmd.h
@ -148,7 +148,19 @@ MuError mu_cmd_remove (MuStore *store, MuConfig *opts, GError **err);
|
|||||||
* @return MU_OK (0) if the command succeeds,
|
* @return MU_OK (0) if the command succeeds,
|
||||||
* some error code otherwise
|
* some error code otherwise
|
||||||
*/
|
*/
|
||||||
MuError mu_cmd_server (MuStore *store, MuConfig *opts,GError**/*unused*/);
|
MuError mu_cmd_server (MuStore *store, MuConfig *opts, GError**/*unused*/);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* execute the verify command (to verify signatures)
|
||||||
|
* @param store store object to use
|
||||||
|
* @param opts configuration options
|
||||||
|
* @param err receives error information, or NULL
|
||||||
|
*
|
||||||
|
* @return MU_OK (0) if the command succeeds,
|
||||||
|
* some error code otherwise
|
||||||
|
*/
|
||||||
|
MuError mu_cmd_verify (MuConfig *opts, GError **err);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* execute some mu command, based on 'opts'
|
* execute some mu command, based on 'opts'
|
||||||
|
|||||||
@ -103,6 +103,8 @@ config_options_group_mu (void)
|
|||||||
"log to standard error (false)", NULL},
|
"log to standard error (false)", NULL},
|
||||||
{"nocolor", 0, 0, G_OPTION_ARG_NONE, &MU_CONFIG.nocolor,
|
{"nocolor", 0, 0, G_OPTION_ARG_NONE, &MU_CONFIG.nocolor,
|
||||||
"don't use ANSI-colors in some output (false)", NULL},
|
"don't use ANSI-colors in some output (false)", NULL},
|
||||||
|
{"verbose", 'v', 0, G_OPTION_ARG_NONE, &MU_CONFIG.verbose,
|
||||||
|
"verbose output (false)", NULL},
|
||||||
|
|
||||||
{G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_STRING_ARRAY,
|
{G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_STRING_ARRAY,
|
||||||
&MU_CONFIG.params, "parameters", NULL},
|
&MU_CONFIG.params, "parameters", NULL},
|
||||||
@ -344,6 +346,28 @@ config_options_group_extract (void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static GOptionGroup*
|
||||||
|
config_options_group_verify (void)
|
||||||
|
{
|
||||||
|
GOptionGroup *og;
|
||||||
|
GOptionEntry entries[] = {
|
||||||
|
{"auto-retrieve", 'r', 0, G_OPTION_ARG_NONE,
|
||||||
|
&MU_CONFIG.auto_retrieve,
|
||||||
|
"attempt to retrieve keys online (false)", NULL},
|
||||||
|
{"use-agent", 'a', 0, G_OPTION_ARG_NONE, &MU_CONFIG.use_agent,
|
||||||
|
"attempt to use the GPG agent (false)", NULL},
|
||||||
|
{NULL, 0, 0, 0, NULL, NULL, NULL}
|
||||||
|
};
|
||||||
|
|
||||||
|
og = g_option_group_new("verify",
|
||||||
|
"options for the 'verify' command",
|
||||||
|
"", NULL, NULL);
|
||||||
|
g_option_group_add_entries(og, entries);
|
||||||
|
|
||||||
|
return og;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static GOptionGroup*
|
static GOptionGroup*
|
||||||
config_options_group_server (void)
|
config_options_group_server (void)
|
||||||
{
|
{
|
||||||
@ -372,15 +396,16 @@ parse_cmd (int *argcp, char ***argvp)
|
|||||||
const gchar* _name;
|
const gchar* _name;
|
||||||
MuConfigCmd _cmd;
|
MuConfigCmd _cmd;
|
||||||
} cmd_map[] = {
|
} cmd_map[] = {
|
||||||
|
{ "add", MU_CONFIG_CMD_ADD },
|
||||||
{ "cfind", MU_CONFIG_CMD_CFIND },
|
{ "cfind", MU_CONFIG_CMD_CFIND },
|
||||||
{ "extract", MU_CONFIG_CMD_EXTRACT },
|
{ "extract", MU_CONFIG_CMD_EXTRACT },
|
||||||
{ "find", MU_CONFIG_CMD_FIND },
|
{ "find", MU_CONFIG_CMD_FIND },
|
||||||
{ "index", MU_CONFIG_CMD_INDEX },
|
{ "index", MU_CONFIG_CMD_INDEX },
|
||||||
{ "mkdir", MU_CONFIG_CMD_MKDIR },
|
{ "mkdir", MU_CONFIG_CMD_MKDIR },
|
||||||
{ "view", MU_CONFIG_CMD_VIEW },
|
|
||||||
{ "add", MU_CONFIG_CMD_ADD },
|
|
||||||
{ "remove", MU_CONFIG_CMD_REMOVE },
|
{ "remove", MU_CONFIG_CMD_REMOVE },
|
||||||
{ "server", MU_CONFIG_CMD_SERVER }
|
{ "server", MU_CONFIG_CMD_SERVER },
|
||||||
|
{ "verify", MU_CONFIG_CMD_VERIFY },
|
||||||
|
{ "view", MU_CONFIG_CMD_VIEW }
|
||||||
};
|
};
|
||||||
|
|
||||||
MU_CONFIG.cmd = MU_CONFIG_CMD_NONE;
|
MU_CONFIG.cmd = MU_CONFIG_CMD_NONE;
|
||||||
@ -426,6 +451,9 @@ add_context_group (GOptionContext *context)
|
|||||||
case MU_CONFIG_CMD_CFIND:
|
case MU_CONFIG_CMD_CFIND:
|
||||||
group = config_options_group_cfind();
|
group = config_options_group_cfind();
|
||||||
break;
|
break;
|
||||||
|
case MU_CONFIG_CMD_VERIFY:
|
||||||
|
group = config_options_group_verify ();
|
||||||
|
break;
|
||||||
case MU_CONFIG_CMD_VIEW:
|
case MU_CONFIG_CMD_VIEW:
|
||||||
group = config_options_group_view();
|
group = config_options_group_view();
|
||||||
break;
|
break;
|
||||||
|
|||||||
@ -72,6 +72,7 @@ enum _MuConfigCmd {
|
|||||||
MU_CONFIG_CMD_ADD,
|
MU_CONFIG_CMD_ADD,
|
||||||
MU_CONFIG_CMD_REMOVE,
|
MU_CONFIG_CMD_REMOVE,
|
||||||
MU_CONFIG_CMD_SERVER,
|
MU_CONFIG_CMD_SERVER,
|
||||||
|
MU_CONFIG_CMD_VERIFY,
|
||||||
|
|
||||||
MU_CONFIG_CMD_NONE
|
MU_CONFIG_CMD_NONE
|
||||||
};
|
};
|
||||||
@ -97,6 +98,7 @@ struct _MuConfig {
|
|||||||
gchar** params; /* parameters (for querying) */
|
gchar** params; /* parameters (for querying) */
|
||||||
gboolean nocolor; /* don't use use ansi-colors
|
gboolean nocolor; /* don't use use ansi-colors
|
||||||
* in some output */
|
* in some output */
|
||||||
|
gboolean verbose; /* verbose output */
|
||||||
|
|
||||||
/* options for indexing */
|
/* options for indexing */
|
||||||
char *maildir; /* where the mails are */
|
char *maildir; /* where the mails are */
|
||||||
@ -135,6 +137,10 @@ struct _MuConfig {
|
|||||||
time_t after; /* only show messages or
|
time_t after; /* only show messages or
|
||||||
* adresses last seen after
|
* adresses last seen after
|
||||||
* T */
|
* T */
|
||||||
|
/* options for verify */
|
||||||
|
gboolean auto_retrieve; /* assume we're online */
|
||||||
|
gboolean use_agent; /* attempt to use the gpg-agent */
|
||||||
|
|
||||||
|
|
||||||
/* options for view */
|
/* options for view */
|
||||||
gboolean terminator; /* add separator \f between
|
gboolean terminator; /* add separator \f between
|
||||||
|
|||||||
Reference in New Issue
Block a user