1 /* gpgv.c - The GnuPG signature verify utility
2 * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2005, 2006,
3 * 2008, 2009, 2012 Free Software Foundation, Inc.
5 * This file is part of GnuPG.
7 * GnuPG is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
12 * GnuPG is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, see <http://www.gnu.org/licenses/>.
28 #ifdef HAVE_DOSISH_SYSTEM
29 #include <fcntl.h> /* for setmode() */
31 #ifdef HAVE_LIBREADLINE
32 #define GNUPG_LIBREADLINE_H_INCLUDED
33 #include <readline/readline.h>
36 #define INCLUDED_BY_MAIN_MODULE 1
50 #include "call-agent.h"
51 #include "../common/init.h"
54 enum cmd_and_opt_values {
68 static ARGPARSE_OPTS opts[] = {
69 ARGPARSE_group (300, N_("@\nOptions:\n ")),
71 ARGPARSE_s_n (oVerbose, "verbose", N_("verbose")),
72 ARGPARSE_s_n (oQuiet, "quiet", N_("be somewhat more quiet")),
73 ARGPARSE_s_s (oKeyring, "keyring",
74 N_("|FILE|take the keys from the keyring FILE")),
75 ARGPARSE_s_n (oIgnoreTimeConflict, "ignore-time-conflict",
76 N_("make timestamp conflicts only a warning")),
77 ARGPARSE_s_i (oStatusFD, "status-fd",
78 N_("|FD|write status info to this FD")),
79 ARGPARSE_s_i (oLoggerFD, "logger-fd", "@"),
80 ARGPARSE_s_s (oHomedir, "homedir", "@"),
87 int g10_errors_seen = 0;
91 make_libversion (const char *libname, const char *(*getfnc)(const char*))
97 result = xmalloc (strlen (libname) + 1 + strlen (s) + 1);
98 strcpy (stpcpy (stpcpy (result, libname), " "), s);
103 my_strusage( int level )
105 static char *ver_gcry;
110 case 11: p = "@GPG@v (GnuPG)";
112 case 13: p = VERSION; break;
113 case 17: p = PRINTABLE_OS_NAME; break;
114 case 19: p = _("Please report bugs to <@EMAIL@>.\n"); break;
117 case 40: p = _("Usage: gpgv [options] [files] (-h for help)");
119 case 41: p = _("Syntax: gpgv [options] [files]\n"
120 "Check signatures against known trusted keys\n");
125 ver_gcry = make_libversion ("libgcrypt", gcry_check_version);
138 main( int argc, char **argv )
143 strlist_t nrings = NULL;
144 unsigned configlineno;
147 set_strusage (my_strusage);
148 log_set_prefix ("gpgv", 1);
150 /* Make sure that our subsystems are ready. */
152 init_common_subsystems (&argc, &argv);
154 if (!gcry_check_version (NEED_LIBGCRYPT_VERSION) )
156 log_fatal ( _("%s is too old (need %s, have %s)\n"), "libgcrypt",
157 NEED_LIBGCRYPT_VERSION, gcry_check_version (NULL) );
159 gcry_control (GCRYCTL_DISABLE_SECMEM, 0);
161 gnupg_init_signals (0, NULL);
163 opt.command_fd = -1; /* no command fd */
164 opt.pgp2_workarounds = 1;
165 opt.keyserver_options.options |= KEYSERVER_AUTO_KEY_RETRIEVE;
166 opt.trust_model = TM_ALWAYS;
169 opt.homedir = default_homedir ();
174 gcry_control (GCRYCTL_INITIALIZATION_FINISHED, 0);
178 pargs.flags= 1; /* do not remove the args */
179 while (optfile_parse( NULL, NULL, &configlineno, &pargs, opts))
183 case oQuiet: opt.quiet = 1; break;
187 gcry_control (GCRYCTL_SET_VERBOSITY, (int)opt.verbose);
189 case oKeyring: append_to_strlist( &nrings, pargs.r.ret_str); break;
190 case oStatusFD: set_status_fd( pargs.r.ret_int ); break;
192 log_set_fd (translate_sys2libc_fd_int (pargs.r.ret_int, 1));
194 case oHomedir: opt.homedir = pargs.r.ret_str; break;
195 case oIgnoreTimeConflict: opt.ignore_time_conflict = 1; break;
196 default : pargs.err = ARGPARSE_PRINT_ERROR; break;
200 if (log_get_errorcount (0))
204 set_packet_list_mode(1);
206 /* Note: We open all keyrings in read-only mode. */
207 if (!nrings) /* No keyring given: use default one. */
208 keydb_add_resource ("trustedkeys" EXTSEP_S GPGEXT_GPG,
209 KEYDB_RESOURCE_FLAG_READONLY);
210 for (sl = nrings; sl; sl = sl->next)
211 keydb_add_resource (sl->d, KEYDB_RESOURCE_FLAG_READONLY);
213 FREE_STRLIST (nrings);
215 ctrl = xcalloc (1, sizeof *ctrl);
217 if ((rc = verify_signatures (ctrl, argc, argv)))
218 log_error("verify signatures failed: %s\n", g10_errstr(rc) );
224 return 8; /*NOTREACHED*/
231 rc = rc? rc : log_get_errorcount(0)? 2 : g10_errors_seen? 1 : 0;
237 * We have to override the trustcheck from pkclist.c becuase
238 * this utility assumes that all keys in the keyring are trustworthy
241 check_signatures_trust( PKT_signature *sig )
248 read_trust_options(byte *trust_model, ulong *created, ulong *nextcheck,
249 byte *marginals, byte *completes, byte *cert_depth,
250 byte *min_cert_level)
258 (void)min_cert_level;
262 * We don't have the trustdb , so we have to provide some stub functions
267 cache_disabled_value(PKT_public_key *pk)
274 check_trustdb_stale(void)
279 get_validity_info (PKT_public_key *pk, PKT_user_id *uid)
287 get_validity (PKT_public_key *pk, PKT_user_id *uid)
295 trust_value_to_string (unsigned int value)
302 uid_trust_string_fixed (PKT_public_key *key, PKT_user_id *uid)
310 get_ownertrust_info (PKT_public_key *pk)
317 get_ownertrust (PKT_public_key *pk)
320 return TRUST_UNKNOWN;
325 * Because we only work with trusted keys, it does not make sense to
326 * get them from a keyserver
329 struct keyserver_spec *
330 keyserver_match (struct keyserver_spec *spec)
337 keyserver_import_keyid (u32 *keyid, void *dummy)
345 keyserver_import_cert (const char *name)
352 keyserver_import_pka (const char *name,unsigned char *fpr)
360 keyserver_import_name (const char *name,struct keyserver_spec *spec)
368 keyserver_import_ldap (const char *name)
375 * No encryption here but mainproc links to these functions.
378 get_session_key (PKT_pubkey_enc *k, DEK *dek)
382 return G10ERR_GENERAL;
387 get_override_session_key (DEK *dek, const char *string)
391 return G10ERR_GENERAL;
396 decrypt_data (ctrl_t ctrl, void *procctx, PKT_encrypted *ed, DEK *dek)
402 return G10ERR_GENERAL;
407 * No interactive commands, so we don't need the helptexts
410 display_online_help (const char *keyword)
416 * We don't use secret keys, but getkey.c links to this
419 check_secret_key (PKT_public_key *pk, int n)
423 return G10ERR_GENERAL;
427 * No secret key, so no passphrase needed
430 passphrase_to_dek (u32 *keyid, int pubkey_algo,
431 int cipher_algo, STRING2KEY *s2k, int mode,
432 const char *tmp, int *canceled)
447 passphrase_clear_cache (u32 *keyid, const char *cacheid, int algo)
454 struct keyserver_spec *
455 parse_preferred_keyserver(PKT_signature *sig)
461 struct keyserver_spec *
462 parse_keyserver_uri (const char *uri, int require_scheme,
463 const char *configname, unsigned int configlineno)
466 (void)require_scheme;
473 free_keyserver_spec (struct keyserver_spec *keyserver)
478 /* Stubs to avoid linking to photoid.c */
480 show_photos (const struct user_attribute *attrs, int count, PKT_public_key *pk)
488 parse_image_header (const struct user_attribute *attr, byte *type, u32 *len)
497 image_type_to_string (byte type, int string)
504 #ifdef ENABLE_CARD_SUPPORT
506 agent_scd_getattr (const char *name, struct agent_card_info_s *info)
512 #endif /* ENABLE_CARD_SUPPORT */
514 /* We do not do any locking, so use these stubs here */
516 dotlock_disable (void)
521 dotlock_create (const char *file_to_lock, unsigned int flags)
529 dotlock_destroy (dotlock_t h)
535 dotlock_take (dotlock_t h, long timeout)
543 dotlock_release (dotlock_t h)
550 dotlock_remove_lockfiles (void)
555 agent_probe_secret_key (ctrl_t ctrl, PKT_public_key *pk)
559 return gpg_error (GPG_ERR_NO_SECKEY);
563 agent_probe_any_secret_key (ctrl_t ctrl, kbnode_t keyblock)
567 return gpg_error (GPG_ERR_NO_SECKEY);
571 agent_get_keyinfo (ctrl_t ctrl, const char *hexkeygrip, char **r_serialno)
576 return gpg_error (GPG_ERR_NO_SECKEY);