From 3a26ebc8376f4ba91b4bea67a5ea8165956fa381 Mon Sep 17 00:00:00 2001 From: Daniel Kahn Gillmor Date: Mon, 20 Dec 2010 04:07:27 -0500 Subject: [PATCH] gpgkeys_hkpms: added support for --keyserver-options http-proxy=XXX and https_proxy environment variables --- Changelog | 4 +++- gpgkeys_hkpms | 23 ++++++++++++++++++++++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/Changelog b/Changelog index ef16495..06cd001 100644 --- a/Changelog +++ b/Changelog @@ -8,8 +8,10 @@ msva-perl (0.8) upstream; * Do not report self-sigs as other certifiers (but report valid, non-matching identities independently) (closes MS # 2569) * List certifiers only once (closes MS # 2573) + * Enable the use of --keyserver-options http-proxy for gpgkeys_hkpms + (includes support for socks proxies) (closes MS # 2677) - -- Daniel Kahn Gillmor Mon, 20 Dec 2010 02:35:54 -0500 + -- Daniel Kahn Gillmor Mon, 20 Dec 2010 04:04:15 -0500 msva-perl (0.7) upstream; diff --git a/gpgkeys_hkpms b/gpgkeys_hkpms index ad7a728..9d50554 100755 --- a/gpgkeys_hkpms +++ b/gpgkeys_hkpms @@ -19,6 +19,8 @@ use warnings; use POSIX; use Crypt::Monkeysphere::MSVA::Logger; use Crypt::Monkeysphere::MSVA::Client; + use Regexp::Common qw /net/; + use Module::Load::Conditional; sub parse_input { my $self = shift; @@ -45,6 +47,18 @@ use warnings; $self->{actually_check} = 0; } elsif ($opt eq 'check-cert') { $self->{actually_check} = 1; + } elsif ($opt =~ /^http-proxy=(.*)/) { + my $hp = $1; + if ($hp =~ /^(socks|http|https):\/\/($RE{net}{domain}|$RE{net}{IPv4}):([[:digit:]]+)$/) { + if ('socks' eq $1) { + if ( ! Module::Load::Conditional::check_install(module => 'LWP::Protocol::socks')) { + $self->{logger}->log('error', "Requesting a socks proxy for hkpms, but LWP::Protocol::socks is not installed.\nThis will likely fail.\n"); + } + } + $self->{proxy} = sprintf('%s://%s:%s', $1, $2, $3); + } else { + $self->{logger}->log('error', "Failed to make sense of this http-proxy address: '%s'; ignoring.\n", $hp); + } } else { $self->{logger}->log('error', "Received '%s' as an option, but gpgkeys_hkpms does not implement it. Ignoring...\n", $opt); } @@ -54,7 +68,6 @@ use warnings; # include-revoked # include-disabled # ca-cert-file - # http-proxy } } } else { @@ -142,6 +155,14 @@ use warnings; my $ua = LWP::UserAgent::->new(); + if (exists($self->{proxy})) { + $self->{logger}->log('verbose', "Using http-proxy: %s\n", $self->{proxy}); + $ua->proxy([qw(http https)] => $self->{proxy}); + } else { + # if no proxy was explicitly set, use the environment: + $ua->env_proxy(); + } + printf("VERSION 1\nPROGRAM %s gpgkeys_hkpms msva-perl/%s\n", $self->{config}->{program}, # this is kind of cheating :/ $Crypt::Monkeysphere::MSVA::VERSION); -- 2.26.2