diff options
author | Werner Koch <[email protected]> | 2014-08-14 13:20:53 +0000 |
---|---|---|
committer | Werner Koch <[email protected]> | 2014-08-14 13:21:21 +0000 |
commit | c23c18c1543d1ff58f0f78baaa6a8e319c659ecb (patch) | |
tree | 49a00478985e5c73ce00642f6820cc2a718d4134 /g10/import.c | |
parent | scd: Minor changes to app-sc-hsm. (diff) | |
download | gnupg-c23c18c1543d1ff58f0f78baaa6a8e319c659ecb.tar.gz gnupg-c23c18c1543d1ff58f0f78baaa6a8e319c659ecb.zip |
gpg: Screen keyserver responses.
* g10/main.h (import_screener_t): New.
* g10/import.c (import): Add screener callbacks to param list.
(import_one): Ditto.
(import_secret_one): Ditto.
(import_keys_internal): Ditto.
(import_keys_stream): Ditto.
* g10/keyserver.c (struct ks_retrieval_screener_arg_s): New.
(keyserver_retrieval_screener): New.
(keyserver_get): Pass screener to import_keys_es_stream().
--
These changes introduces import functions that apply a constraining
filter to imported keys. These filters can verify the fingerprints of
the keys returned before importing them into the keyring, ensuring
that the keys fetched from the keyserver are in fact those selected by
the user beforehand.
Signed-off-by: Stefan Tomanek <[email protected]>
This is an extended and fixed versions of Stefan's patch. In addition
to the changes done in gnupg 2.0, namely the commits
5e933008beffbeae7255ece02383606481f9c169
044847a0e2013a2833605c1a9f80cfa6ef353309
088f82c0b5e39687f70e44d3ab719854e808eeb6
the symbol names have been changed to "screener" to void mixing them
up with the iobuf filter feature and it has been changed to be used
with the dirmngr based keyserver lookup.
Signed-off-by: Werner Koch <[email protected]>
Diffstat (limited to 'g10/import.c')
-rw-r--r-- | g10/import.c | 69 |
1 files changed, 49 insertions, 20 deletions
diff --git a/g10/import.c b/g10/import.c index 774a727da..ca35ce1b9 100644 --- a/g10/import.c +++ b/g10/import.c @@ -63,16 +63,19 @@ struct stats_s { static int import (ctrl_t ctrl, IOBUF inp, const char* fname, struct stats_s *stats, - unsigned char **fpr, size_t *fpr_len, unsigned int options); + unsigned char **fpr, size_t *fpr_len, unsigned int options, + import_screener_t screener, void *screener_arg); static int read_block( IOBUF a, PACKET **pending_pkt, KBNODE *ret_root ); static void revocation_present (ctrl_t ctrl, kbnode_t keyblock); static int import_one (ctrl_t ctrl, const char *fname, KBNODE keyblock,struct stats_s *stats, - unsigned char **fpr,size_t *fpr_len, - unsigned int options,int from_sk, int silent); + unsigned char **fpr, size_t *fpr_len, + unsigned int options, int from_sk, int silent, + import_screener_t screener, void *screener_arg); static int import_secret_one (ctrl_t ctrl, const char *fname, KBNODE keyblock, struct stats_s *stats, int batch, - unsigned int options, int for_migration); + unsigned int options, int for_migration, + import_screener_t screener, void *screener_arg); static int import_revoke_cert( const char *fname, KBNODE node, struct stats_s *stats); static int chk_self_sigs( const char *fname, KBNODE keyblock, @@ -169,7 +172,8 @@ import_release_stats_handle (void *p) static int import_keys_internal (ctrl_t ctrl, iobuf_t inp, char **fnames, int nnames, void *stats_handle, unsigned char **fpr, size_t *fpr_len, - unsigned int options ) + unsigned int options, + import_screener_t screener, void *screener_arg) { int i, rc = 0; struct stats_s *stats = stats_handle; @@ -178,7 +182,8 @@ import_keys_internal (ctrl_t ctrl, iobuf_t inp, char **fnames, int nnames, stats = import_new_stats_handle (); if (inp) { - rc = import (ctrl, inp, "[stream]", stats, fpr, fpr_len, options); + rc = import (ctrl, inp, "[stream]", stats, fpr, fpr_len, options, + screener, screener_arg); } else { if( !fnames && !nnames ) @@ -199,7 +204,8 @@ import_keys_internal (ctrl_t ctrl, iobuf_t inp, char **fnames, int nnames, log_error(_("can't open '%s': %s\n"), fname, strerror(errno) ); else { - rc = import (ctrl, inp2, fname, stats, fpr, fpr_len, options); + rc = import (ctrl, inp2, fname, stats, fpr, fpr_len, options, + screener, screener_arg); iobuf_close(inp2); /* Must invalidate that ugly cache to actually close it. */ iobuf_ioctl (NULL, IOBUF_IOCTL_INVALIDATE_CACHE, @@ -235,15 +241,15 @@ import_keys (ctrl_t ctrl, char **fnames, int nnames, void *stats_handle, unsigned int options ) { import_keys_internal (ctrl, NULL, fnames, nnames, stats_handle, - NULL, NULL, options); + NULL, NULL, options, NULL, NULL); } int import_keys_stream (ctrl_t ctrl, IOBUF inp, void *stats_handle, - unsigned char **fpr, size_t *fpr_len,unsigned int options) + unsigned char **fpr, size_t *fpr_len, unsigned int options) { return import_keys_internal (ctrl, inp, NULL, 0, stats_handle, - fpr, fpr_len, options); + fpr, fpr_len, options, NULL, NULL); } @@ -251,7 +257,8 @@ import_keys_stream (ctrl_t ctrl, IOBUF inp, void *stats_handle, int import_keys_es_stream (ctrl_t ctrl, estream_t fp, void *stats_handle, unsigned char **fpr, size_t *fpr_len, - unsigned int options) + unsigned int options, + import_screener_t screener, void *screener_arg) { int rc; iobuf_t inp; @@ -265,7 +272,8 @@ import_keys_es_stream (ctrl_t ctrl, estream_t fp, void *stats_handle, } rc = import_keys_internal (ctrl, inp, NULL, 0, stats_handle, - fpr, fpr_len, options); + fpr, fpr_len, options, + screener, screener_arg); iobuf_close (inp); return rc; @@ -274,7 +282,8 @@ import_keys_es_stream (ctrl_t ctrl, estream_t fp, void *stats_handle, static int import (ctrl_t ctrl, IOBUF inp, const char* fname,struct stats_s *stats, - unsigned char **fpr,size_t *fpr_len,unsigned int options ) + unsigned char **fpr,size_t *fpr_len, unsigned int options, + import_screener_t screener, void *screener_arg) { PACKET *pending_pkt = NULL; KBNODE keyblock = NULL; /* Need to initialize because gcc can't @@ -296,10 +305,12 @@ import (ctrl_t ctrl, IOBUF inp, const char* fname,struct stats_s *stats, while( !(rc = read_block( inp, &pending_pkt, &keyblock) )) { if( keyblock->pkt->pkttype == PKT_PUBLIC_KEY ) rc = import_one (ctrl, fname, keyblock, - stats, fpr, fpr_len, options, 0, 0); + stats, fpr, fpr_len, options, 0, 0, + screener, screener_arg); else if( keyblock->pkt->pkttype == PKT_SECRET_KEY ) rc = import_secret_one (ctrl, fname, keyblock, stats, - opt.batch, options, 0); + opt.batch, options, 0, + screener, screener_arg); else if( keyblock->pkt->pkttype == PKT_SIGNATURE && keyblock->pkt->pkt.signature->sig_class == 0x20 ) rc = import_revoke_cert( fname, keyblock, stats ); @@ -355,7 +366,8 @@ import_old_secring (ctrl_t ctrl, const char *fname) while (!(err = read_block (inp, &pending_pkt, &keyblock))) { if (keyblock->pkt->pkttype == PKT_SECRET_KEY) - err = import_secret_one (ctrl, fname, keyblock, stats, 1, 0, 1); + err = import_secret_one (ctrl, fname, keyblock, stats, 1, 0, 1, + NULL, NULL); release_kbnode (keyblock); if (err) break; @@ -835,8 +847,9 @@ check_prefs (ctrl_t ctrl, kbnode_t keyblock) static int import_one (ctrl_t ctrl, const char *fname, KBNODE keyblock, struct stats_s *stats, - unsigned char **fpr,size_t *fpr_len,unsigned int options, - int from_sk, int silent) + unsigned char **fpr, size_t *fpr_len, unsigned int options, + int from_sk, int silent, + import_screener_t screener, void *screener_arg) { PKT_public_key *pk; PKT_public_key *pk_orig; @@ -880,6 +893,13 @@ import_one (ctrl_t ctrl, return 0; } + if (screener && screener (keyblock, screener_arg)) + { + log_error (_("key %s: %s\n"), keystr_from_pk (pk), + _("rejected by import screener")); + return 0; + } + if (opt.interactive && !silent) { if(is_status_enabled()) print_import_check (pk, uidnode->pkt->pkt.user_id); @@ -1519,7 +1539,8 @@ sec_to_pub_keyblock (kbnode_t sec_keyblock) static int import_secret_one (ctrl_t ctrl, const char *fname, KBNODE keyblock, struct stats_s *stats, int batch, unsigned int options, - int for_migration) + int for_migration, + import_screener_t screener, void *screener_arg) { PKT_public_key *pk; struct seckey_info *ski; @@ -1540,6 +1561,13 @@ import_secret_one (ctrl_t ctrl, const char *fname, KBNODE keyblock, keyid_from_pk (pk, keyid); uidnode = find_next_kbnode (keyblock, PKT_USER_ID); + if (screener && screener (keyblock, screener_arg)) + { + log_error (_("secret key %s: %s\n"), keystr_from_pk (pk), + _("rejected by import screener")); + return 0; + } + if (opt.verbose && !for_migration) { log_info ("sec %s/%s %s ", @@ -1610,7 +1638,8 @@ import_secret_one (ctrl_t ctrl, const char *fname, KBNODE keyblock, public key block, and below we will output another one for the secret keys. FIXME? */ import_one (ctrl, fname, pub_keyblock, stats, - NULL, NULL, options, 1, for_migration); + NULL, NULL, options, 1, for_migration, + screener, screener_arg); /* Fixme: We should check for an invalid keyblock and cancel the secret key import in this case. */ |