* crypto: implement 'mu verify' command -- WIP

This commit is contained in:
djcb 2012-07-17 19:17:49 +03:00
parent 9e59b1f29b
commit bf2585b50e
5 changed files with 118 additions and 8 deletions

View File

@ -452,8 +452,8 @@ include_attachments (MuMsg *msg)
GString *gstr;
attlist = NULL;
mu_msg_part_foreach (msg, FALSE, (MuMsgPartForeachFunc)each_part,
&attlist);
mu_msg_part_foreach (msg, (MuMsgPartForeachFunc)each_part,
&attlist, MU_MSG_PART_OPTION_NONE);
gstr = g_string_sized_new (512);
gstr = g_string_append_c (gstr, '(');

View File

@ -40,6 +40,10 @@
#include "mu-flags.h"
#include "mu-store.h"
#ifdef BUILD_CRYPTO
#include "mu-msg-crypto.h"
#endif /*BUILD_CRYPTO*/
#define VIEW_TERMINATOR '\f' /* form-feed */
@ -79,8 +83,8 @@ get_attach_str (MuMsg *msg)
gchar *attach;
attach = NULL;
mu_msg_part_foreach (msg, FALSE,
(MuMsgPartForeachFunc)each_part, &attach);
mu_msg_part_foreach (msg, (MuMsgPartForeachFunc)each_part, &attach,
MU_MSG_PART_OPTION_NONE);
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
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_MKDIR: return mu_cmd_mkdir (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_FIND:

View File

@ -148,7 +148,19 @@ MuError mu_cmd_remove (MuStore *store, MuConfig *opts, GError **err);
* @return MU_OK (0) if the command succeeds,
* 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'

View File

@ -103,6 +103,8 @@ config_options_group_mu (void)
"log to standard error (false)", NULL},
{"nocolor", 0, 0, G_OPTION_ARG_NONE, &MU_CONFIG.nocolor,
"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,
&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*
config_options_group_server (void)
{
@ -372,15 +396,16 @@ parse_cmd (int *argcp, char ***argvp)
const gchar* _name;
MuConfigCmd _cmd;
} cmd_map[] = {
{ "add", MU_CONFIG_CMD_ADD },
{ "cfind", MU_CONFIG_CMD_CFIND },
{ "extract", MU_CONFIG_CMD_EXTRACT },
{ "find", MU_CONFIG_CMD_FIND },
{ "index", MU_CONFIG_CMD_INDEX },
{ "mkdir", MU_CONFIG_CMD_MKDIR },
{ "view", MU_CONFIG_CMD_VIEW },
{ "add", MU_CONFIG_CMD_ADD },
{ "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;
@ -426,6 +451,9 @@ add_context_group (GOptionContext *context)
case MU_CONFIG_CMD_CFIND:
group = config_options_group_cfind();
break;
case MU_CONFIG_CMD_VERIFY:
group = config_options_group_verify ();
break;
case MU_CONFIG_CMD_VIEW:
group = config_options_group_view();
break;

View File

@ -72,6 +72,7 @@ enum _MuConfigCmd {
MU_CONFIG_CMD_ADD,
MU_CONFIG_CMD_REMOVE,
MU_CONFIG_CMD_SERVER,
MU_CONFIG_CMD_VERIFY,
MU_CONFIG_CMD_NONE
};
@ -97,6 +98,7 @@ struct _MuConfig {
gchar** params; /* parameters (for querying) */
gboolean nocolor; /* don't use use ansi-colors
* in some output */
gboolean verbose; /* verbose output */
/* options for indexing */
char *maildir; /* where the mails are */
@ -135,6 +137,10 @@ struct _MuConfig {
time_t after; /* only show messages or
* adresses last seen after
* T */
/* options for verify */
gboolean auto_retrieve; /* assume we're online */
gboolean use_agent; /* attempt to use the gpg-agent */
/* options for view */
gboolean terminator; /* add separator \f between