1 /* gpgv.c - The GnuPG signature verify utility
2 * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2005,
3 * 2006 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 2 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, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
30 #ifdef HAVE_DOSISH_SYSTEM
31 #include <fcntl.h> /* for setmode() */
33 #ifdef HAVE_LIBREADLINE
35 #include <readline/readline.h>
38 #define INCLUDED_BY_MAIN_MODULE 1
54 enum cmd_and_opt_values
{ aNull
= 0,
66 static ARGPARSE_OPTS opts
[] = {
68 { 301, NULL
, 0, N_("@\nOptions:\n ") },
70 { oVerbose
, "verbose", 0, N_("verbose") },
71 { oQuiet
, "quiet", 0, N_("be somewhat more quiet") },
72 { oKeyring
, "keyring" ,2, N_("take the keys from this keyring")},
73 { oIgnoreTimeConflict
, "ignore-time-conflict", 0,
74 N_("make timestamp conflicts only a warning") },
75 { oStatusFD
, "status-fd" ,1, N_("|FD|write status info to this FD") },
76 { oLoggerFD
, "logger-fd",1, "@" },
77 { oHomedir
, "homedir", 2, "@" }, /* defaults to "~/.gnupg" */
83 int g10_errors_seen
= 0;
86 my_strusage( int level
)
90 case 11: p
= "gpgv (GnuPG)";
92 case 13: p
= VERSION
; break;
93 case 17: p
= PRINTABLE_OS_NAME
; break;
95 _("Please report bugs to <gnupg-bugs@gnu.org>.\n");
99 _("Usage: gpgv [options] [files] (-h for help)");
102 _("Syntax: gpg [options] [files]\n"
103 "Check signatures against known trusted keys\n");
115 #ifdef USE_SIMPLE_GETTEXT
116 set_gettext_file (PACKAGE_GT
, "Software\\GNU\\GnuPG");
119 setlocale (LC_ALL
, "");
120 bindtextdomain (PACKAGE_GT
, LOCALEDIR
);
121 textdomain (PACKAGE_GT
);
129 main( int argc
, char **argv
)
135 unsigned configlineno
;
137 set_strusage (my_strusage
);
138 log_set_prefix ("gpgv", 1);
139 gnupg_init_signals (0, NULL
);
141 opt
.command_fd
= -1; /* no command fd */
142 opt
.pgp2_workarounds
= 1;
143 opt
.keyserver_options
.options
|=KEYSERVER_AUTO_KEY_RETRIEVE
;
144 opt
.trust_model
= TM_ALWAYS
;
147 opt
.homedir
= default_homedir ();
153 set_native_charset (NULL
); /* Try to auto set the character set */
157 pargs
.flags
= 1; /* do not remove the args */
158 while( optfile_parse( NULL
, NULL
, &configlineno
, &pargs
, opts
) ) {
159 switch( pargs
.r_opt
) {
160 case oQuiet
: opt
.quiet
= 1; break;
164 gcry_control (GCRYCTL_SET_VERBOSITY
, (int)opt
.verbose
);
166 case oKeyring
: append_to_strlist( &nrings
, pargs
.r
.ret_str
); break;
167 case oStatusFD
: set_status_fd( pargs
.r
.ret_int
); break;
169 log_set_fd (iobuf_translate_file_handle (pargs
.r
.ret_int
, 1));
171 case oHomedir
: opt
.homedir
= pargs
.r
.ret_str
; break;
172 case oIgnoreTimeConflict
: opt
.ignore_time_conflict
= 1; break;
173 default : pargs
.err
= 2; break;
177 if( log_get_errorcount(0) )
180 if( opt
.verbose
> 1 )
181 set_packet_list_mode(1);
183 if( !nrings
) /* no keyring given: use default one */
184 keydb_add_resource ("trustedkeys" EXTSEP_S
"gpg", 0, 0);
185 for(sl
= nrings
; sl
; sl
= sl
->next
)
186 keydb_add_resource (sl
->d
, 0, 0 );
188 FREE_STRLIST(nrings
);
190 if( (rc
= verify_signatures( argc
, argv
) ))
191 log_error("verify signatures failed: %s\n", g10_errstr(rc
) );
195 return 8; /*NEVER REACHED*/
202 rc
= rc
? rc
: log_get_errorcount(0)? 2 :
203 g10_errors_seen
? 1 : 0;
209 * We have to override the trustcheck from pkclist.c becuase
210 * this utility assumes that all keys in the keyring are trustworthy
213 check_signatures_trust( PKT_signature
*sig
)
219 read_trust_options(byte
*trust_model
,ulong
*created
,ulong
*nextcheck
,
220 byte
*marginals
,byte
*completes
,byte
*cert_depth
) {}
223 * We don't have the trustdb , so we have to provide some stub functions
228 cache_disabled_value(PKT_public_key
*pk
)
234 check_trustdb_stale(void) {}
237 get_validity_info (PKT_public_key
*pk
, PKT_user_id
*uid
)
243 get_validity (PKT_public_key
*pk
, PKT_user_id
*uid
)
249 trust_value_to_string (unsigned int value
)
255 uid_trust_string_fixed(PKT_public_key
*key
,PKT_user_id
*uid
)
261 get_ownertrust_info (PKT_public_key
*pk
)
267 get_ownertrust (PKT_public_key
*pk
)
269 return TRUST_UNKNOWN
;
274 * Because we only work with trusted keys, it does not make sense to
275 * get them from a keyserver
278 struct keyserver_spec
*
279 keyserver_match(struct keyserver_spec
*spec
) { return NULL
; }
282 keyserver_import_keyid( u32
*keyid
, void *dummy
)
288 keyserver_import_cert(const char *name
) { return -1; }
291 keyserver_import_pka(const char *name
,unsigned char *fpr
) { return -1; }
294 keyserver_import_name(const char *name
,struct keyserver_spec
*spec
)
300 keyserver_import_ldap(const char *name
) { return -1; }
303 * No encryption here but mainproc links to these functions.
306 get_session_key( PKT_pubkey_enc
*k
, DEK
*dek
)
308 return G10ERR_GENERAL
;
312 get_override_session_key( DEK
*dek
, const char *string
)
314 return G10ERR_GENERAL
;
318 decrypt_data( void *procctx
, PKT_encrypted
*ed
, DEK
*dek
)
320 return G10ERR_GENERAL
;
325 * No interactive commnds, so we don't need the helptexts
328 display_online_help( const char *keyword
)
333 * We don't use secret keys, but getkey.c links to this
336 check_secret_key( PKT_secret_key
*sk
, int n
)
338 return G10ERR_GENERAL
;
342 * No secret key, so no passphrase needed
345 passphrase_to_dek( u32
*keyid
, int pubkey_algo
,
346 int cipher_algo
, STRING2KEY
*s2k
, int mode
,
347 const char *tmp
, int *canceled
)
354 struct keyserver_spec
*parse_preferred_keyserver(PKT_signature
*sig
) {return NULL
;}
355 struct keyserver_spec
*parse_keyserver_uri(const char *uri
,int require_scheme
,
356 const char *configname
,
357 unsigned int configlineno
)
362 void free_keyserver_spec(struct keyserver_spec
*keyserver
) {}
364 /* Stubs to avoid linking to photoid.c */
365 void show_photos(const struct user_attribute
*attrs
,int count
,PKT_public_key
*pk
) {}
366 int parse_image_header(const struct user_attribute
*attr
,byte
*type
,u32
*len
) {return 0;}
367 char *image_type_to_string(byte type
,int string
) {return NULL
;}
369 #ifdef ENABLE_CARD_SUPPORT
370 int agent_scd_getattr (const char *name
, struct agent_card_info_s
*info
) {return 0;}
371 #endif /* ENABLE_CARD_SUPPORT */
373 /* Stubs to void linking to ../cipher/cipher.c */
374 const char *cipher_algo_to_string( int algo
) { return "?";}
375 void disable_cipher_algo( int algo
) {}
376 int check_cipher_algo( int algo
) { return -1;}
377 unsigned int cipher_get_keylen( int algo
) { return 0; }
378 unsigned int cipher_get_blocksize( int algo
) {return 0;}
379 gcry_cipher_hd_t
cipher_open( int algo
, int mode
, int secure
) { return NULL
;}
380 void cipher_close( gcry_cipher_hd_t c
) {}
381 int cipher_setkey( gcry_cipher_hd_t c
, byte
*key
, unsigned keylen
) { return -1;}
382 void cipher_setiv( gcry_cipher_hd_t c
, const byte
*iv
, unsigned ivlen
){}
383 void cipher_encrypt( gcry_cipher_hd_t c
, byte
*outbuf
,
384 byte
*inbuf
, unsigned nbytes
) {}
385 void cipher_decrypt( gcry_cipher_hd_t c
, byte
*outbuf
,
386 byte
*inbuf
, unsigned nbytes
) {}
387 void cipher_sync( gcry_cipher_hd_t c
) {}
390 /* Stubs to avoid linking to ../util/ttyio.c */
391 int tty_batchmode( int onoff
) { return 0; }
392 void tty_printf( const char *fmt
, ... ) { }
393 void tty_fprintf (FILE *fp
, const char *fmt
, ... ) { }
394 void tty_print_string( const byte
*p
, size_t n
) { }
395 void tty_print_utf8_string( const byte
*p
, size_t n
) {}
396 void tty_print_utf8_string2( const byte
*p
, size_t n
, size_t max_n
) {}
397 char *tty_get( const char *prompt
) { return NULL
;}
398 char *tty_get_hidden( const char *prompt
) {return NULL
; }
399 void tty_kill_prompt(void) {}
400 int tty_get_answer_is_yes( const char *prompt
) {return 0;}
401 int tty_no_terminal(int onoff
) {return 0;}
402 #ifdef HAVE_LIBREADLINE
403 void tty_enable_completion(rl_completion_func_t
*completer
) {}
404 void tty_disable_completion(void) {}
407 /* We do not do any locking, so use these stubs here */
408 void disable_dotlock(void) {}
409 DOTLOCK
create_dotlock( const char *file_to_lock
) { return NULL
; }
410 void destroy_dotlock (DOTLOCK h
) {}
411 int make_dotlock( DOTLOCK h
, long timeout
) { return 0;}
412 int release_dotlock( DOTLOCK h
) {return 0;}
413 void remove_lockfiles(void) {}