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 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
51 #include "call-agent.h"
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");
114 main( int argc
, char **argv
)
119 strlist_t nrings
=NULL
;
120 unsigned configlineno
;
122 set_strusage (my_strusage
);
123 log_set_prefix ("gpgv", 1);
125 /* Make sure that our subsystems are ready. */
126 init_common_subsystems ();
128 gnupg_init_signals (0, NULL
);
131 opt
.command_fd
= -1; /* no command fd */
132 opt
.pgp2_workarounds
= 1;
133 opt
.keyserver_options
.options
|=KEYSERVER_AUTO_KEY_RETRIEVE
;
134 opt
.trust_model
= TM_ALWAYS
;
137 opt
.homedir
= default_homedir ();
145 pargs
.flags
= 1; /* do not remove the args */
146 while( optfile_parse( NULL
, NULL
, &configlineno
, &pargs
, opts
) ) {
147 switch( pargs
.r_opt
) {
148 case oQuiet
: opt
.quiet
= 1; break;
152 gcry_control (GCRYCTL_SET_VERBOSITY
, (int)opt
.verbose
);
154 case oKeyring
: append_to_strlist( &nrings
, pargs
.r
.ret_str
); break;
155 case oStatusFD
: set_status_fd( pargs
.r
.ret_int
); break;
157 log_set_fd (translate_sys2libc_fd (pargs
.r
.ret_int
, 1));
159 case oHomedir
: opt
.homedir
= pargs
.r
.ret_str
; break;
160 case oIgnoreTimeConflict
: opt
.ignore_time_conflict
= 1; break;
161 default : pargs
.err
= 2; break;
165 if( log_get_errorcount(0) )
168 if( opt
.verbose
> 1 )
169 set_packet_list_mode(1);
171 if( !nrings
) /* no keyring given: use default one */
172 keydb_add_resource ("trustedkeys" EXTSEP_S
"gpg", 0, 0);
173 for(sl
= nrings
; sl
; sl
= sl
->next
)
174 keydb_add_resource (sl
->d
, 0, 0 );
176 FREE_STRLIST (nrings
);
178 if( (rc
= verify_signatures( argc
, argv
) ))
179 log_error("verify signatures failed: %s\n", g10_errstr(rc
) );
183 return 8; /*NEVER REACHED*/
190 rc
= rc
? rc
: log_get_errorcount(0)? 2 :
191 g10_errors_seen
? 1 : 0;
197 * We have to override the trustcheck from pkclist.c becuase
198 * this utility assumes that all keys in the keyring are trustworthy
201 check_signatures_trust( PKT_signature
*sig
)
207 read_trust_options(byte
*trust_model
,ulong
*created
,ulong
*nextcheck
,
208 byte
*marginals
,byte
*completes
,byte
*cert_depth
) {}
211 * We don't have the trustdb , so we have to provide some stub functions
216 cache_disabled_value(PKT_public_key
*pk
)
222 check_trustdb_stale(void) {}
225 get_validity_info (PKT_public_key
*pk
, PKT_user_id
*uid
)
231 get_validity (PKT_public_key
*pk
, PKT_user_id
*uid
)
237 trust_value_to_string (unsigned int value
)
243 uid_trust_string_fixed(PKT_public_key
*key
,PKT_user_id
*uid
)
249 get_ownertrust_info (PKT_public_key
*pk
)
255 get_ownertrust (PKT_public_key
*pk
)
257 return TRUST_UNKNOWN
;
262 * Because we only work with trusted keys, it does not make sense to
263 * get them from a keyserver
266 struct keyserver_spec
*
267 keyserver_match(struct keyserver_spec
*spec
) { return NULL
; }
270 keyserver_import_keyid( u32
*keyid
, void *dummy
)
276 keyserver_import_cert(const char *name
) { return -1; }
279 keyserver_import_pka(const char *name
,unsigned char *fpr
) { return -1; }
282 keyserver_import_name(const char *name
,struct keyserver_spec
*spec
)
288 keyserver_import_ldap(const char *name
) { return -1; }
291 * No encryption here but mainproc links to these functions.
294 get_session_key( PKT_pubkey_enc
*k
, DEK
*dek
)
296 return G10ERR_GENERAL
;
300 get_override_session_key( DEK
*dek
, const char *string
)
302 return G10ERR_GENERAL
;
306 decrypt_data( void *procctx
, PKT_encrypted
*ed
, DEK
*dek
)
308 return G10ERR_GENERAL
;
313 * No interactive commnds, so we don't need the helptexts
316 display_online_help( const char *keyword
)
321 * We don't use secret keys, but getkey.c links to this
324 check_secret_key( PKT_secret_key
*sk
, int n
)
326 return G10ERR_GENERAL
;
330 * No secret key, so no passphrase needed
333 passphrase_to_dek( u32
*keyid
, int pubkey_algo
,
334 int cipher_algo
, STRING2KEY
*s2k
, int mode
,
335 const char *tmp
, int *canceled
)
342 struct keyserver_spec
*parse_preferred_keyserver(PKT_signature
*sig
) {return NULL
;}
343 struct keyserver_spec
*parse_keyserver_uri(const char *uri
,int require_scheme
,
344 const char *configname
,
345 unsigned int configlineno
)
350 void free_keyserver_spec(struct keyserver_spec
*keyserver
) {}
352 /* Stubs to avoid linking to photoid.c */
353 void show_photos(const struct user_attribute
*attrs
,int count
,PKT_public_key
*pk
) {}
354 int parse_image_header(const struct user_attribute
*attr
,byte
*type
,u32
*len
) {return 0;}
355 char *image_type_to_string(byte type
,int string
) {return NULL
;}
357 #ifdef ENABLE_CARD_SUPPORT
358 int agent_scd_getattr (const char *name
, struct agent_card_info_s
*info
) {return 0;}
359 #endif /* ENABLE_CARD_SUPPORT */
361 /* Stubs to void linking to ../cipher/cipher.c */
362 const char *cipher_algo_to_string( int algo
) { return "?";}
363 void disable_cipher_algo( int algo
) {}
364 int check_cipher_algo( int algo
) { return -1;}
365 unsigned int cipher_get_keylen( int algo
) { return 0; }
366 unsigned int cipher_get_blocksize( int algo
) {return 0;}
367 gcry_cipher_hd_t
cipher_open( int algo
, int mode
, int secure
) { return NULL
;}
368 void cipher_close( gcry_cipher_hd_t c
) {}
369 int cipher_setkey( gcry_cipher_hd_t c
, byte
*key
, unsigned keylen
) { return -1;}
370 void cipher_setiv( gcry_cipher_hd_t c
, const byte
*iv
, unsigned ivlen
){}
371 void cipher_encrypt( gcry_cipher_hd_t c
, byte
*outbuf
,
372 byte
*inbuf
, unsigned nbytes
) {}
373 void cipher_decrypt( gcry_cipher_hd_t c
, byte
*outbuf
,
374 byte
*inbuf
, unsigned nbytes
) {}
375 void cipher_sync( gcry_cipher_hd_t c
) {}
379 /* We do not do any locking, so use these stubs here */
380 void disable_dotlock(void) {}
381 DOTLOCK
create_dotlock( const char *file_to_lock
) { return NULL
; }
382 void destroy_dotlock (DOTLOCK h
) {}
383 int make_dotlock( DOTLOCK h
, long timeout
) { return 0;}
384 int release_dotlock( DOTLOCK h
) {return 0;}
385 void remove_lockfiles(void) {}