Fix for extended length Le in decipher
[gnupg.git] / g10 / gpgv.c
blob747b05ff2004d92c70a7b790b409e2b3cc28f62a
1 /* gpgv.c - The GnuPG signature verify utility
2 * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2005,
3 * 2006, 2008 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/>.
21 #include <config.h>
22 #include <errno.h>
23 #include <stdio.h>
24 #include <stdlib.h>
25 #include <string.h>
26 #include <ctype.h>
27 #include <unistd.h>
28 #ifdef HAVE_DOSISH_SYSTEM
29 #include <fcntl.h> /* for setmode() */
30 #endif
31 #ifdef HAVE_LIBREADLINE
32 #define GNUPG_LIBREADLINE_H_INCLUDED
33 #include <readline/readline.h>
34 #endif
36 #define INCLUDED_BY_MAIN_MODULE 1
37 #include "gpg.h"
38 #include "packet.h"
39 #include "iobuf.h"
40 #include "util.h"
41 #include "main.h"
42 #include "options.h"
43 #include "keydb.h"
44 #include "trustdb.h"
45 #include "cipher.h"
46 #include "filter.h"
47 #include "ttyio.h"
48 #include "i18n.h"
49 #include "sysutils.h"
50 #include "status.h"
51 #include "call-agent.h"
54 enum cmd_and_opt_values {
55 aNull = 0,
56 oQuiet = 'q',
57 oVerbose = 'v',
58 oBatch = 500,
59 oKeyring,
60 oIgnoreTimeConflict,
61 oStatusFD,
62 oLoggerFD,
63 oHomedir,
64 aTest
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", "@"),
82 ARGPARSE_end ()
87 int g10_errors_seen = 0;
90 static char *
91 make_libversion (const char *libname, const char *(*getfnc)(const char*))
93 const char *s;
94 char *result;
96 s = getfnc (NULL);
97 result = xmalloc (strlen (libname) + 1 + strlen (s) + 1);
98 strcpy (stpcpy (stpcpy (result, libname), " "), s);
99 return result;
102 static const char *
103 my_strusage( int level )
105 static char *ver_gcry;
106 const char *p;
108 switch (level)
110 case 11: p = "gpgv (GnuPG)";
111 break;
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;
116 case 1:
117 case 40: p = _("Usage: gpgv [options] [files] (-h for help)");
118 break;
119 case 41: p = _("Syntax: gpgv [options] [files]\n"
120 "Check signatures against known trusted keys\n");
121 break;
123 case 20:
124 if (!ver_gcry)
125 ver_gcry = make_libversion ("libgcrypt", gcry_check_version);
126 p = ver_gcry;
127 break;
130 default: p = NULL;
132 return p;
138 main( int argc, char **argv )
140 ARGPARSE_ARGS pargs;
141 int rc=0;
142 strlist_t sl;
143 strlist_t nrings=NULL;
144 unsigned configlineno;
146 set_strusage (my_strusage);
147 log_set_prefix ("gpgv", 1);
149 /* Make sure that our subsystems are ready. */
150 i18n_init();
151 init_common_subsystems ();
153 gnupg_init_signals (0, NULL);
155 opt.command_fd = -1; /* no command fd */
156 opt.pgp2_workarounds = 1;
157 opt.keyserver_options.options|=KEYSERVER_AUTO_KEY_RETRIEVE;
158 opt.trust_model = TM_ALWAYS;
159 opt.batch = 1;
161 opt.homedir = default_homedir ();
163 tty_no_terminal(1);
164 tty_batchmode(1);
165 disable_dotlock();
167 pargs.argc = &argc;
168 pargs.argv = &argv;
169 pargs.flags= 1; /* do not remove the args */
170 while (optfile_parse( NULL, NULL, &configlineno, &pargs, opts))
172 switch (pargs.r_opt)
174 case oQuiet: opt.quiet = 1; break;
175 case oVerbose:
176 opt.verbose++;
177 opt.list_sigs=1;
178 gcry_control (GCRYCTL_SET_VERBOSITY, (int)opt.verbose);
179 break;
180 case oKeyring: append_to_strlist( &nrings, pargs.r.ret_str); break;
181 case oStatusFD: set_status_fd( pargs.r.ret_int ); break;
182 case oLoggerFD:
183 log_set_fd (translate_sys2libc_fd_int (pargs.r.ret_int, 1));
184 break;
185 case oHomedir: opt.homedir = pargs.r.ret_str; break;
186 case oIgnoreTimeConflict: opt.ignore_time_conflict = 1; break;
187 default : pargs.err = ARGPARSE_PRINT_ERROR; break;
191 if (log_get_errorcount (0))
192 g10_exit(2);
194 if (opt.verbose > 1)
195 set_packet_list_mode(1);
197 /* Note: We open all keyrings in read-only mode (flag value: 8). */
198 if (!nrings) /* No keyring given: use default one. */
199 keydb_add_resource ("trustedkeys" EXTSEP_S "gpg", 8, 0);
200 for (sl = nrings; sl; sl = sl->next)
201 keydb_add_resource (sl->d, 8, 0 );
203 FREE_STRLIST (nrings);
205 if ( (rc = verify_signatures( argc, argv ) ))
206 log_error("verify signatures failed: %s\n", g10_errstr(rc) );
208 /* cleanup */
209 g10_exit (0);
210 return 8; /*NOTREACHED*/
214 void
215 g10_exit( int rc )
217 rc = rc? rc : log_get_errorcount(0)? 2 : g10_errors_seen? 1 : 0;
218 exit(rc );
222 /* Stub:
223 * We have to override the trustcheck from pkclist.c becuase
224 * this utility assumes that all keys in the keyring are trustworthy
227 check_signatures_trust( PKT_signature *sig )
229 (void)sig;
230 return 0;
233 void
234 read_trust_options(byte *trust_model, ulong *created, ulong *nextcheck,
235 byte *marginals, byte *completes, byte *cert_depth)
237 (void)trust_model;
238 (void)created;
239 (void)nextcheck;
240 (void)marginals;
241 (void)completes;
242 (void)cert_depth;
245 /* Stub:
246 * We don't have the trustdb , so we have to provide some stub functions
247 * instead
251 cache_disabled_value(PKT_public_key *pk)
253 (void)pk;
254 return 0;
257 void
258 check_trustdb_stale(void)
263 get_validity_info (PKT_public_key *pk, PKT_user_id *uid)
265 (void)pk;
266 (void)uid;
267 return '?';
270 unsigned int
271 get_validity (PKT_public_key *pk, PKT_user_id *uid)
273 (void)pk;
274 (void)uid;
275 return 0;
278 const char *
279 trust_value_to_string (unsigned int value)
281 (void)value;
282 return "err";
285 const char *
286 uid_trust_string_fixed (PKT_public_key *key, PKT_user_id *uid)
288 (void)key;
289 (void)uid;
290 return "err";
294 get_ownertrust_info (PKT_public_key *pk)
296 (void)pk;
297 return '?';
300 unsigned int
301 get_ownertrust (PKT_public_key *pk)
303 (void)pk;
304 return TRUST_UNKNOWN;
308 /* Stubs:
309 * Because we only work with trusted keys, it does not make sense to
310 * get them from a keyserver
313 struct keyserver_spec *
314 keyserver_match (struct keyserver_spec *spec)
316 (void)spec;
317 return NULL;
321 keyserver_import_keyid (u32 *keyid, void *dummy)
323 (void)keyid;
324 (void)dummy;
325 return -1;
329 keyserver_import_cert (const char *name)
331 (void)name;
332 return -1;
336 keyserver_import_pka (const char *name,unsigned char *fpr)
338 (void)name;
339 (void)fpr;
340 return -1;
344 keyserver_import_name (const char *name,struct keyserver_spec *spec)
346 (void)name;
347 (void)spec;
348 return -1;
352 keyserver_import_ldap (const char *name)
354 (void)name;
355 return -1;
358 /* Stub:
359 * No encryption here but mainproc links to these functions.
362 get_session_key (PKT_pubkey_enc *k, DEK *dek)
364 (void)k;
365 (void)dek;
366 return G10ERR_GENERAL;
369 /* Stub: */
371 get_override_session_key (DEK *dek, const char *string)
373 (void)dek;
374 (void)string;
375 return G10ERR_GENERAL;
378 /* Stub: */
380 decrypt_data (void *procctx, PKT_encrypted *ed, DEK *dek)
382 (void)procctx;
383 (void)ed;
384 (void)dek;
385 return G10ERR_GENERAL;
389 /* Stub:
390 * No interactive commands, so we don't need the helptexts
392 void
393 display_online_help (const char *keyword)
395 (void)keyword;
398 /* Stub:
399 * We don't use secret keys, but getkey.c links to this
402 check_secret_key (PKT_secret_key *sk, int n)
404 (void)sk;
405 (void)n;
406 return G10ERR_GENERAL;
409 /* Stub:
410 * No secret key, so no passphrase needed
412 DEK *
413 passphrase_to_dek (u32 *keyid, int pubkey_algo,
414 int cipher_algo, STRING2KEY *s2k, int mode,
415 const char *tmp, int *canceled)
417 (void)keyid;
418 (void)pubkey_algo;
419 (void)cipher_algo;
420 (void)s2k;
421 (void)mode;
422 (void)tmp;
424 if (canceled)
425 *canceled = 0;
426 return NULL;
429 void
430 passphrase_clear_cache (u32 *keyid, const char *cacheid, int algo)
432 (void)keyid;
433 (void)cacheid;
434 (void)algo;
437 struct keyserver_spec *
438 parse_preferred_keyserver(PKT_signature *sig)
440 (void)sig;
441 return NULL;
444 struct keyserver_spec *
445 parse_keyserver_uri (const char *uri, int require_scheme,
446 const char *configname, unsigned int configlineno)
448 (void)uri;
449 (void)require_scheme;
450 (void)configname;
451 (void)configlineno;
452 return NULL;
455 void
456 free_keyserver_spec (struct keyserver_spec *keyserver)
458 (void)keyserver;
461 /* Stubs to avoid linking to photoid.c */
462 void
463 show_photos (const struct user_attribute *attrs, int count, PKT_public_key *pk)
465 (void)attrs;
466 (void)count;
467 (void)pk;
470 int
471 parse_image_header (const struct user_attribute *attr, byte *type, u32 *len)
473 (void)attr;
474 (void)type;
475 (void)len;
476 return 0;
479 char *
480 image_type_to_string (byte type, int string)
482 (void)type;
483 (void)string;
484 return NULL;
487 #ifdef ENABLE_CARD_SUPPORT
488 int
489 agent_scd_getattr (const char *name, struct agent_card_info_s *info)
491 (void)name;
492 (void)info;
493 return 0;
495 #endif /* ENABLE_CARD_SUPPORT */
497 /* We do not do any locking, so use these stubs here */
498 void
499 disable_dotlock (void)
503 DOTLOCK
504 create_dotlock (const char *file_to_lock)
506 (void)file_to_lock;
507 return NULL;
510 void
511 destroy_dotlock (DOTLOCK h)
513 (void)h;
517 make_dotlock (DOTLOCK h, long timeout)
519 (void)h;
520 (void)timeout;
521 return 0;
525 release_dotlock (DOTLOCK h)
527 (void)h;
528 return 0;
531 void
532 remove_lockfiles (void)