1 #----------------------------------------------------------------------
2 # Monkeysphere Validation Agent, Perl version
3 # Marginal User Interface for reasonable prompting
4 # Copyright © 2010 Daniel Kahn Gillmor <dkg@fifthhorseman.net>,
5 # Matthew James Goins <mjgoins@openflows.com>,
6 # Jameson Graef Rollins <jrollins@finestructure.net>,
7 # Elliot Winard <enw@caveteen.com>
9 # This program is free software: you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation, either version 3 of the License, or
12 # (at your option) any later version.
14 # This program is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with this program. If not, see <http://www.gnu.org/licenses/>.
22 #----------------------------------------------------------------------
24 { package Crypt::Monkeysphere::MSVA::Client;
31 our (@EXPORT_OK,@ISA);
33 @EXPORT_OK = qw( &create_apd );
38 use Crypt::Monkeysphere::MSVA qw( msvalog );
49 my $msvasocket = shift;
51 if (! defined $msvasocket or $msvasocket eq '') {
52 $msvasocket = 'http://localhost:8901';
55 my $apd = create_apd($context, $peer, $pkctype, $pkcdata);
57 my $apdjson = to_json($apd);
59 # create the user agent
60 my $ua = LWP::UserAgent->new;
62 my $headers = HTTP::Headers->new(
63 'Content-Type' => 'application/json',
64 'Content-Length' => length($apdjson),
65 'Connection' => 'close',
66 'Accept' => 'application/json',
69 my $requesturl = $msvasocket . '/reviewcert';
71 my $request = HTTP::Request->new(
78 msvalog('debug', "Contacting MSVA at %s\n", $requesturl);
79 my $response = $ua->request($request);
81 my $status = $response->status_line;
82 my $ret = from_json($response->content);
93 msvalog('debug', "context: %s\n", $context);
94 msvalog('debug', "peer: %s\n", $peer);
95 msvalog('debug', "pkctype: %s\n", $pkctype);
98 if ($pkctype eq 'x509der') {
99 my $cert = Crypt::X509->new(cert => $pkcdata);
103 msvalog('info', "x509der certificate loaded.\n");
104 msvalog('verbose', "cert subject: %s\n", $cert->subject_cn());
105 msvalog('verbose', "cert issuer: %s\n", $cert->issuer_cn());
106 msvalog('verbose', "cert pubkey algo: %s\n", $cert->PubKeyAlg());
107 msvalog('verbose', "cert pubkey: %s\n", unpack('H*', $cert->pubkey()));
109 msvalog('error', "unknown pkc type '%s'.\n", $pkctype);
117 # remap raw pkc data into numeric array
118 data => [map(ord, split(//,$pkcdata))],