/* gpgv.c - The GnuPG signature verify utility
- * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2005,
- * 2006, 2008 Free Software Foundation, Inc.
+ * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2005, 2006,
+ * 2008, 2009, 2012 Free Software Foundation, Inc.
*
* This file is part of GnuPG.
*
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
- * along with this program; if not, see <http://www.gnu.org/licenses/>.
+ * along with this program; if not, see <https://www.gnu.org/licenses/>.
*/
#include <config.h>
#define INCLUDED_BY_MAIN_MODULE 1
#include "gpg.h"
-#include "util.h"
+#include "../common/util.h"
#include "packet.h"
-#include "iobuf.h"
+#include "../common/iobuf.h"
#include "main.h"
#include "options.h"
#include "keydb.h"
#include "trustdb.h"
-#include "cipher.h"
#include "filter.h"
-#include "ttyio.h"
-#include "i18n.h"
-#include "sysutils.h"
-#include "status.h"
+#include "../common/ttyio.h"
+#include "../common/i18n.h"
+#include "../common/sysutils.h"
+#include "../common/status.h"
#include "call-agent.h"
+#include "../common/init.h"
enum cmd_and_opt_values {
aNull = 0,
oQuiet = 'q',
oVerbose = 'v',
+ oOutput = 'o',
oBatch = 500,
oKeyring,
- oIgnoreTimeConflict,
+ oIgnoreTimeConflict,
oStatusFD,
oLoggerFD,
+ oLoggerFile,
oHomedir,
+ oWeakDigest,
+ oEnableSpecialFilenames,
+ oDebug,
aTest
};
static ARGPARSE_OPTS opts[] = {
ARGPARSE_group (300, N_("@\nOptions:\n ")),
-
+
ARGPARSE_s_n (oVerbose, "verbose", N_("verbose")),
ARGPARSE_s_n (oQuiet, "quiet", N_("be somewhat more quiet")),
- ARGPARSE_s_s (oKeyring, "keyring",
+ ARGPARSE_s_s (oKeyring, "keyring",
N_("|FILE|take the keys from the keyring FILE")),
+ ARGPARSE_s_s (oOutput, "output", N_("|FILE|write output to FILE")),
ARGPARSE_s_n (oIgnoreTimeConflict, "ignore-time-conflict",
N_("make timestamp conflicts only a warning")),
ARGPARSE_s_i (oStatusFD, "status-fd",
N_("|FD|write status info to this FD")),
ARGPARSE_s_i (oLoggerFD, "logger-fd", "@"),
+ ARGPARSE_s_s (oLoggerFile, "log-file", "@"),
ARGPARSE_s_s (oHomedir, "homedir", "@"),
+ ARGPARSE_s_s (oWeakDigest, "weak-digest",
+ N_("|ALGO|reject signatures made with ALGO")),
+ ARGPARSE_s_n (oEnableSpecialFilenames, "enable-special-filenames", "@"),
+ ARGPARSE_s_s (oDebug, "debug", "@"),
ARGPARSE_end ()
};
+/* The list of supported debug flags. */
+static struct debug_flags_s debug_flags [] =
+ {
+ { DBG_PACKET_VALUE , "packet" },
+ { DBG_MPI_VALUE , "mpi" },
+ { DBG_CRYPTO_VALUE , "crypto" },
+ { DBG_FILTER_VALUE , "filter" },
+ { DBG_IOBUF_VALUE , "iobuf" },
+ { DBG_MEMORY_VALUE , "memory" },
+ { DBG_CACHE_VALUE , "cache" },
+ { DBG_MEMSTAT_VALUE, "memstat" },
+ { DBG_TRUST_VALUE , "trust" },
+ { DBG_HASHING_VALUE, "hashing" },
+ { DBG_IPC_VALUE , "ipc" },
+ { DBG_CLOCK_VALUE , "clock" },
+ { DBG_LOOKUP_VALUE , "lookup" },
+ { DBG_EXTPROG_VALUE, "extprog" },
+ { 0, NULL }
+ };
+
int g10_errors_seen = 0;
{
const char *s;
char *result;
-
+
s = getfnc (NULL);
result = xmalloc (strlen (libname) + 1 + strlen (s) + 1);
strcpy (stpcpy (stpcpy (result, libname), " "), s);
switch (level)
{
- case 11: p = "gpgv (GnuPG)";
+ case 11: p = "@GPG@v (GnuPG)";
break;
case 13: p = VERSION; break;
case 17: p = PRINTABLE_OS_NAME; break;
strlist_t nrings = NULL;
unsigned configlineno;
ctrl_t ctrl;
-
+
+ early_system_init ();
set_strusage (my_strusage);
- log_set_prefix ("gpgv", 1);
-
+ log_set_prefix ("gpgv", GPGRT_LOG_WITH_PREFIX);
+
/* Make sure that our subsystems are ready. */
i18n_init();
init_common_subsystems (&argc, &argv);
-
+
+ gcry_control (GCRYCTL_DISABLE_SECMEM, 0);
+
gnupg_init_signals (0, NULL);
opt.command_fd = -1; /* no command fd */
- opt.pgp2_workarounds = 1;
- opt.keyserver_options.options|=KEYSERVER_AUTO_KEY_RETRIEVE;
+ opt.keyserver_options.options |= KEYSERVER_AUTO_KEY_RETRIEVE;
opt.trust_model = TM_ALWAYS;
+ opt.no_sig_cache = 1;
+ opt.flags.require_cross_cert = 1;
opt.batch = 1;
+ opt.answer_yes = 1;
- opt.homedir = default_homedir ();
+ opt.weak_digests = NULL;
tty_no_terminal(1);
tty_batchmode(1);
- disable_dotlock();
-
+ dotlock_disable ();
+ gcry_control (GCRYCTL_INITIALIZATION_FINISHED, 0);
+ additional_weak_digest("MD5");
+ gnupg_initialize_compliance (GNUPG_MODULE_NAME_GPG);
+
pargs.argc = &argc;
pargs.argv = &argv;
pargs.flags= 1; /* do not remove the args */
switch (pargs.r_opt)
{
case oQuiet: opt.quiet = 1; break;
- case oVerbose:
- opt.verbose++;
+ case oVerbose:
+ opt.verbose++;
opt.list_sigs=1;
gcry_control (GCRYCTL_SET_VERBOSITY, (int)opt.verbose);
break;
+ case oDebug:
+ if (parse_debug_flag (pargs.r.ret_str, &opt.debug, debug_flags))
+ {
+ pargs.r_opt = ARGPARSE_INVALID_ARG;
+ pargs.err = ARGPARSE_PRINT_ERROR;
+ }
+ break;
case oKeyring: append_to_strlist( &nrings, pargs.r.ret_str); break;
- case oStatusFD: set_status_fd( pargs.r.ret_int ); break;
- case oLoggerFD:
+ case oOutput: opt.outfile = pargs.r.ret_str; break;
+ case oStatusFD:
+ set_status_fd (translate_sys2libc_fd_int (pargs.r.ret_int, 1));
+ break;
+ case oLoggerFD:
log_set_fd (translate_sys2libc_fd_int (pargs.r.ret_int, 1));
break;
- case oHomedir: opt.homedir = pargs.r.ret_str; break;
+ case oLoggerFile:
+ log_set_file (pargs.r.ret_str);
+ log_set_prefix (NULL, (GPGRT_LOG_WITH_PREFIX
+ | GPGRT_LOG_WITH_TIME
+ | GPGRT_LOG_WITH_PID) );
+ break;
+ case oHomedir: gnupg_set_homedir (pargs.r.ret_str); break;
+ case oWeakDigest:
+ additional_weak_digest(pargs.r.ret_str);
+ break;
case oIgnoreTimeConflict: opt.ignore_time_conflict = 1; break;
+ case oEnableSpecialFilenames:
+ enable_special_filenames ();
+ break;
default : pargs.err = ARGPARSE_PRINT_ERROR; break;
}
}
-
+
if (log_get_errorcount (0))
g10_exit(2);
if (opt.verbose > 1)
set_packet_list_mode(1);
- /* Note: We open all keyrings in read-only mode (flag value: 8). */
+ /* Note: We open all keyrings in read-only mode. */
if (!nrings) /* No keyring given: use default one. */
- keydb_add_resource ("trustedkeys" EXTSEP_S "gpg", 8);
+ keydb_add_resource ("trustedkeys" EXTSEP_S "kbx",
+ (KEYDB_RESOURCE_FLAG_READONLY
+ |KEYDB_RESOURCE_FLAG_GPGVDEF));
for (sl = nrings; sl; sl = sl->next)
- keydb_add_resource (sl->d, 8);
-
+ keydb_add_resource (sl->d, KEYDB_RESOURCE_FLAG_READONLY);
+
FREE_STRLIST (nrings);
ctrl = xcalloc (1, sizeof *ctrl);
-
+
if ((rc = verify_signatures (ctrl, argc, argv)))
- log_error("verify signatures failed: %s\n", g10_errstr(rc) );
-
+ log_error("verify signatures failed: %s\n", gpg_strerror (rc) );
+
+ keydb_release (ctrl->cached_getkey_kdb);
xfree (ctrl);
/* cleanup */
/* Stub:
- * We have to override the trustcheck from pkclist.c becuase
+ * We have to override the trustcheck from pkclist.c because
* this utility assumes that all keys in the keyring are trustworthy
*/
int
-check_signatures_trust( PKT_signature *sig )
+check_signatures_trust (ctrl_t ctrl, PKT_signature *sig)
{
+ (void)ctrl;
(void)sig;
return 0;
}
void
-read_trust_options(byte *trust_model, ulong *created, ulong *nextcheck,
- byte *marginals, byte *completes, byte *cert_depth)
+read_trust_options (ctrl_t ctrl,
+ byte *trust_model, ulong *created, ulong *nextcheck,
+ byte *marginals, byte *completes, byte *cert_depth,
+ byte *min_cert_level)
{
+ (void)ctrl;
(void)trust_model;
(void)created;
(void)nextcheck;
(void)marginals;
(void)completes;
(void)cert_depth;
+ (void)min_cert_level;
}
-/* Stub:
+/* Stub:
* We don't have the trustdb , so we have to provide some stub functions
* instead
*/
int
-cache_disabled_value(PKT_public_key *pk)
+cache_disabled_value (ctrl_t ctrl, PKT_public_key *pk)
{
+ (void)ctrl;
(void)pk;
return 0;
}
void
-check_trustdb_stale(void)
+check_trustdb_stale (ctrl_t ctrl)
{
+ (void)ctrl;
}
int
-get_validity_info (PKT_public_key *pk, PKT_user_id *uid)
+get_validity_info (ctrl_t ctrl, kbnode_t kb, PKT_public_key *pk,
+ PKT_user_id *uid)
{
+ (void)ctrl;
+ (void)kb;
(void)pk;
(void)uid;
return '?';
}
unsigned int
-get_validity (PKT_public_key *pk, PKT_user_id *uid)
+get_validity (ctrl_t ctrl, kbnode_t kb, PKT_public_key *pk, PKT_user_id *uid,
+ PKT_signature *sig, int may_ask)
{
+ (void)ctrl;
+ (void)kb;
(void)pk;
(void)uid;
+ (void)sig;
+ (void)may_ask;
return 0;
}
}
const char *
-uid_trust_string_fixed (PKT_public_key *key, PKT_user_id *uid)
+uid_trust_string_fixed (ctrl_t ctrl, PKT_public_key *key, PKT_user_id *uid)
{
+ (void)ctrl;
(void)key;
(void)uid;
return "err";
}
int
-get_ownertrust_info (PKT_public_key *pk)
+get_ownertrust_info (ctrl_t ctrl, PKT_public_key *pk, int no_create)
{
+ (void)ctrl;
(void)pk;
+ (void)no_create;
return '?';
}
unsigned int
-get_ownertrust (PKT_public_key *pk)
+get_ownertrust (ctrl_t ctrl, PKT_public_key *pk)
{
+ (void)ctrl;
(void)pk;
return TRUST_UNKNOWN;
}
keyserver_match (struct keyserver_spec *spec)
{
(void)spec;
- return NULL;
+ return NULL;
+}
+
+int
+keyserver_any_configured (ctrl_t ctrl)
+{
+ (void)ctrl;
+ return 0;
}
int
-keyserver_import_keyid (u32 *keyid, void *dummy)
+keyserver_import_keyid (u32 *keyid, void *dummy, int quick)
{
(void)keyid;
(void)dummy;
+ (void)quick;
+ return -1;
+}
+
+int
+keyserver_import_fprint (ctrl_t ctrl, const byte *fprint,size_t fprint_len,
+ struct keyserver_spec *keyserver, int quick)
+{
+ (void)ctrl;
+ (void)fprint;
+ (void)fprint_len;
+ (void)keyserver;
+ (void)quick;
return -1;
}
keyserver_import_cert (const char *name)
{
(void)name;
- return -1;
+ return -1;
}
int
return -1;
}
+gpg_error_t
+keyserver_import_wkd (ctrl_t ctrl, const char *name, int quick,
+ unsigned char **fpr, size_t *fpr_len)
+{
+ (void)ctrl;
+ (void)name;
+ (void)quick;
+ (void)fpr;
+ (void)fpr_len;
+ return GPG_ERR_BUG;
+}
+
int
keyserver_import_name (const char *name,struct keyserver_spec *spec)
{
return -1;
}
+
+gpg_error_t
+read_key_from_file (ctrl_t ctrl, const char *fname, kbnode_t *r_keyblock)
+{
+ (void)ctrl;
+ (void)fname;
+ (void)r_keyblock;
+ return -1;
+}
+
+
/* Stub:
* No encryption here but mainproc links to these functions.
*/
gpg_error_t
-get_session_key (PKT_pubkey_enc *k, DEK *dek)
+get_session_key (ctrl_t ctrl, struct pubkey_enc_list *k, DEK *dek)
{
+ (void)ctrl;
(void)k;
(void)dek;
- return G10ERR_GENERAL;
+ return GPG_ERR_GENERAL;
}
/* Stub: */
{
(void)dek;
(void)string;
- return G10ERR_GENERAL;
+ return GPG_ERR_GENERAL;
}
/* Stub: */
(void)procctx;
(void)ed;
(void)dek;
- return G10ERR_GENERAL;
+ return GPG_ERR_GENERAL;
}
{
(void)pk;
(void)n;
- return G10ERR_GENERAL;
+ return GPG_ERR_GENERAL;
}
/* Stub:
- * No secret key, so no passphrase needed
+ * No secret key, so no passphrase needed
*/
DEK *
-passphrase_to_dek (u32 *keyid, int pubkey_algo,
- int cipher_algo, STRING2KEY *s2k, int mode,
+passphrase_to_dek (int cipher_algo, STRING2KEY *s2k, int create, int nocache,
const char *tmp, int *canceled)
{
- (void)keyid;
- (void)pubkey_algo;
(void)cipher_algo;
(void)s2k;
- (void)mode;
+ (void)create;
+ (void)nocache;
(void)tmp;
if (canceled)
}
void
-passphrase_clear_cache (u32 *keyid, const char *cacheid, int algo)
+passphrase_clear_cache (const char *cacheid)
{
- (void)keyid;
(void)cacheid;
- (void)algo;
}
struct keyserver_spec *
-parse_preferred_keyserver(PKT_signature *sig)
+parse_preferred_keyserver(PKT_signature *sig)
{
(void)sig;
return NULL;
return NULL;
}
-void
+void
free_keyserver_spec (struct keyserver_spec *keyserver)
{
(void)keyserver;
}
/* Stubs to avoid linking to photoid.c */
-void
+void
show_photos (const struct user_attribute *attrs, int count, PKT_public_key *pk)
{
(void)attrs;
(void)pk;
}
-int
+int
parse_image_header (const struct user_attribute *attr, byte *type, u32 *len)
{
(void)attr;
}
#ifdef ENABLE_CARD_SUPPORT
-int
+int
agent_scd_getattr (const char *name, struct agent_card_info_s *info)
{
(void)name;
#endif /* ENABLE_CARD_SUPPORT */
/* We do not do any locking, so use these stubs here */
-void
-disable_dotlock (void)
+void
+dotlock_disable (void)
{
}
-dotlock_t
-create_dotlock (const char *file_to_lock)
+dotlock_t
+dotlock_create (const char *file_to_lock, unsigned int flags)
{
(void)file_to_lock;
+ (void)flags;
return NULL;
}
-void
-destroy_dotlock (dotlock_t h)
+void
+dotlock_destroy (dotlock_t h)
{
(void)h;
}
int
-make_dotlock (dotlock_t h, long timeout)
+dotlock_take (dotlock_t h, long timeout)
{
(void)h;
(void)timeout;
}
int
-release_dotlock (dotlock_t h)
+dotlock_release (dotlock_t h)
{
(void)h;
return 0;
}
-void
-remove_lockfiles (void)
+void
+dotlock_remove_lockfiles (void)
{
}
}
gpg_error_t
-agent_get_keyinfo (ctrl_t ctrl, const char *hexkeygrip, char **r_serialno)
+agent_get_keyinfo (ctrl_t ctrl, const char *hexkeygrip,
+ char **r_serialno, int *r_cleartext)
{
(void)ctrl;
(void)hexkeygrip;
+ (void)r_cleartext;
*r_serialno = NULL;
return gpg_error (GPG_ERR_NO_SECKEY);
}
-
+
+gpg_error_t
+gpg_dirmngr_get_pka (ctrl_t ctrl, const char *userid,
+ unsigned char **r_fpr, size_t *r_fprlen,
+ char **r_url)
+{
+ (void)ctrl;
+ (void)userid;
+ if (r_fpr)
+ *r_fpr = NULL;
+ if (r_fprlen)
+ *r_fprlen = 0;
+ if (r_url)
+ *r_url = NULL;
+ return gpg_error (GPG_ERR_NOT_FOUND);
+}
+
+gpg_error_t
+export_pubkey_buffer (ctrl_t ctrl, const char *keyspec, unsigned int options,
+ export_stats_t stats,
+ kbnode_t *r_keyblock, void **r_data, size_t *r_datalen)
+{
+ (void)ctrl;
+ (void)keyspec;
+ (void)options;
+ (void)stats;
+
+ *r_keyblock = NULL;
+ *r_data = NULL;
+ *r_datalen = 0;
+ return gpg_error (GPG_ERR_NOT_IMPLEMENTED);
+}
+
+gpg_error_t
+tofu_write_tfs_record (ctrl_t ctrl, estream_t fp,
+ PKT_public_key *pk, const char *user_id)
+{
+ (void)ctrl;
+ (void)fp;
+ (void)pk;
+ (void)user_id;
+ return gpg_error (GPG_ERR_GENERAL);
+}
+
+gpg_error_t
+tofu_get_policy (ctrl_t ctrl, PKT_public_key *pk, PKT_user_id *user_id,
+ enum tofu_policy *policy)
+{
+ (void)ctrl;
+ (void)pk;
+ (void)user_id;
+ (void)policy;
+ return gpg_error (GPG_ERR_GENERAL);
+}
+
+const char *
+tofu_policy_str (enum tofu_policy policy)
+{
+ (void)policy;
+
+ return "unknown";
+}
+
+void
+tofu_begin_batch_update (ctrl_t ctrl)
+{
+ (void)ctrl;
+}
+
+void
+tofu_end_batch_update (ctrl_t ctrl)
+{
+ (void)ctrl;
+}
+
+gpg_error_t
+tofu_notice_key_changed (ctrl_t ctrl, kbnode_t kb)
+{
+ (void) ctrl;
+ (void) kb;
+
+ return 0;
+}
+
+
+int
+get_revocation_reason (PKT_signature *sig, char **r_reason,
+ char **r_comment, size_t *r_commentlen)
+{
+ (void)sig;
+ (void)r_commentlen;
+
+ if (r_reason)
+ *r_reason = NULL;
+ if (r_comment)
+ *r_comment = NULL;
+ return 0;
+}