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;
29 use Crypt::Monkeysphere::MSVA::Logger;
32 use Module::Load::Conditional;
36 $self->{logger}->log(@_);
41 my $requesturl = $self->{socket} . '/';
42 my $request = HTTP::Request->new('GET', $requesturl);
43 $self->log('debug', "Contacting MSVA at %s\n", $requesturl);
44 my $response = $self->{ua}->request($request);
45 my $status = $response->status_line;
47 if ($status eq '200 OK') {
48 $ret = from_json($response->content);
60 my $keyserverpolicy = shift;
62 my $apd = $self->create_apd($context, $peer, $peertype, $pkctype, $pkcdata, $keyserverpolicy);
64 my $apdjson = to_json($apd);
66 my $headers = HTTP::Headers->new(
67 'Content-Type' => 'application/json',
68 'Content-Length' => length($apdjson),
69 'Connection' => 'close',
70 'Accept' => 'application/json',
73 my $requesturl = $self->{socket} . '/reviewcert';
75 my $request = HTTP::Request->new(
82 $self->log('debug', "Contacting MSVA at %s\n", $requesturl);
83 my $response = $self->{ua}->request($request);
85 my $status = $response->status_line;
87 if ($status eq '200 OK') {
88 $ret = from_json($response->content);
101 my $keyserverpolicy = shift;
103 $self->log('debug', "context: %s\n", $context);
104 $self->log('debug', "peer: %s\n", $peer);
105 $self->log('debug', "pkctype: %s\n", $pkctype);
107 my $transformed_data;
108 if ($pkctype eq 'x509der') {
109 # remap raw der data into numeric array
110 $transformed_data = [map(ord, split(//,$pkcdata))];
112 $transformed_data = $pkcdata;
117 peer => { name => $peer},
120 data => $transformed_data,
123 $ret->{peer}->{type} = $peertype
124 if (defined $peertype);
125 $ret->{keyserverpolicy} = $keyserverpolicy
126 if (defined $keyserverpolicy);
137 $self->{logger} = Crypt::Monkeysphere::MSVA::Logger->new($args{log_level});
138 $self->{socket} = $args{socket};
139 $self->{socket} = 'http://localhost:8901'
140 if (! defined $self->{socket} or $self->{socket} eq '');
142 # create the user agent
143 $self->{ua} = LWP::UserAgent->new;
145 bless ($self,$class);