| 1 |
#!/usr/bin/perl -wT |
| 2 |
|
| 3 |
# Monkeysphere Validation Agent Client, Perl version |
| 4 |
# Copyright © 2010 Jameson Greaf Rollins <[email protected]> |
| 5 |
# |
| 6 |
# This program is free software: you can redistribute it and/or modify |
| 7 |
# it under the terms of the GNU General Public License as published by |
| 8 |
# the Free Software Foundation, either version 3 of the License, or |
| 9 |
# (at your option) any later version. |
| 10 |
# |
| 11 |
# This program is distributed in the hope that it will be useful, |
| 12 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 |
# GNU General Public License for more details. |
| 15 |
# |
| 16 |
# You should have received a copy of the GNU General Public License |
| 17 |
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 18 |
|
| 19 |
use warnings; |
| 20 |
use strict; |
| 21 |
|
| 22 |
use Crypt::Monkeysphere::MSVA::Client; |
| 23 |
|
| 24 |
sub usage { |
| 25 |
my $name = shift; |
| 26 |
|
| 27 |
printf STDERR ("Usage: %s CONTEXT PEER PKC_TYPE [PEER_TYPE] < PKC_DATA |
| 28 |
%s CONTEXT PEER PKC_TYPE PEER_TYPE PKC_DATA |
| 29 |
%s --version |
| 30 |
", $name, $name, $name); |
| 31 |
} |
| 32 |
|
| 33 |
my $context = shift; |
| 34 |
if ((!defined($context)) || |
| 35 |
$context eq '--help') { |
| 36 |
usage($0); |
| 37 |
exit (defined($context) ? 0 : 1); |
| 38 |
} elsif ($context eq '--version') { |
| 39 |
my $client = Crypt::Monkeysphere::MSVA::Client->new( |
| 40 |
socket => $ENV{MONKEYSPHERE_VALIDATION_AGENT_SOCKET}, |
| 41 |
log_level => $ENV{MSVA_LOG_LEVEL}, |
| 42 |
); |
| 43 |
my ($status,$ret) = $client->agent_info(); |
| 44 |
$client->log('verbose', "status: %s\n", $status); |
| 45 |
if (defined $ret) { |
| 46 |
printf("%s\n", $ret->{server}); |
| 47 |
exit 0; |
| 48 |
} |
| 49 |
exit 1; |
| 50 |
} |
| 51 |
|
| 52 |
my $peer = shift; |
| 53 |
my $pkctype = shift; |
| 54 |
my $peertype = shift; |
| 55 |
my $pkcdata = shift; |
| 56 |
|
| 57 |
if (!defined $pkcdata) { |
| 58 |
# load raw pkc data from stdin |
| 59 |
$pkcdata = do { |
| 60 |
local $/; # slurp! |
| 61 |
<STDIN>; |
| 62 |
}; |
| 63 |
} |
| 64 |
|
| 65 |
my $client = Crypt::Monkeysphere::MSVA::Client->new( |
| 66 |
socket => $ENV{MONKEYSPHERE_VALIDATION_AGENT_SOCKET}, |
| 67 |
log_level => $ENV{MSVA_LOG_LEVEL}, |
| 68 |
); |
| 69 |
|
| 70 |
my ($status,$ret) = $client->query_agent($context,$peer,$peertype,$pkctype,$pkcdata); |
| 71 |
|
| 72 |
$client->log('verbose', "status: %s\n", $status); |
| 73 |
if (defined $ret) { |
| 74 |
$client->log('info', "valid: %s\n", $ret->{valid}); |
| 75 |
$client->log('info', "server: %s\n", $ret->{server}); |
| 76 |
printf("%s", $ret->{message}); |
| 77 |
if ($ret->{valid}) { |
| 78 |
exit 0 |
| 79 |
} else { |
| 80 |
exit 1; |
| 81 |
} |
| 82 |
} else { |
| 83 |
printf("%s\n", $status); |
| 84 |
exit 100; |
| 85 |
} |
| 86 |
|
| 87 |
__END__ |
| 88 |
|
| 89 |
=encoding utf8 |
| 90 |
|
| 91 |
=head1 NAME |
| 92 |
|
| 93 |
msva-query-agent - query a Monkeysphere Validation Agent |
| 94 |
|
| 95 |
=head1 SYNOPSIS |
| 96 |
|
| 97 |
msva-query-agent CONTEXT PEER PKC_TYPE [PEER_TYPE] < /path/to/public_key_carrier |
| 98 |
|
| 99 |
msva-query-agent CONTEXT PEER PKC_TYPE PEER_TYPE PKC_DATA |
| 100 |
|
| 101 |
msva-query-agent --version |
| 102 |
|
| 103 |
=head1 ABSTRACT |
| 104 |
|
| 105 |
msva-query-agent validates certificates for a given use by querying a |
| 106 |
running Monkeysphere Validation Agent. |
| 107 |
|
| 108 |
=head1 USAGE |
| 109 |
|
| 110 |
msva-query-agent reads a certificate from standard input, and posts it |
| 111 |
to the running Monkeysphere Validation Agent. The return code |
| 112 |
indicates the validity (as determined by the agent) of the certificate |
| 113 |
for the specified purpose. The agent's return message (if any) is |
| 114 |
emitted on stdout. |
| 115 |
|
| 116 |
The various arguments are: |
| 117 |
|
| 118 |
=over 4 |
| 119 |
|
| 120 |
=item CONTEXT |
| 121 |
|
| 122 |
Context in which the certificate is being validated (e.g. 'https', |
| 123 |
'ssh', 'ike') |
| 124 |
|
| 125 |
=item PEER |
| 126 |
|
| 127 |
The name of the intended peer. When validating a certificate for a |
| 128 |
service, supply the host's full DNS name (e.g. 'foo.example.net') |
| 129 |
|
| 130 |
=item PKC_TYPE |
| 131 |
|
| 132 |
The format of public key carrier data provided on standard input |
| 133 |
(e.g. 'x509der', 'x509pem', 'opensshpubkey', 'rfc4716', 'openpgp4fpr') |
| 134 |
|
| 135 |
=item PEER_TYPE |
| 136 |
|
| 137 |
The type of peer we are inquiring about (e.g. 'client', 'server', |
| 138 |
'peer'). This argument is optional and defaults will be used (based |
| 139 |
on CONTEXT) if it is not supplied. |
| 140 |
|
| 141 |
=item PKC_DATA |
| 142 |
|
| 143 |
This is the actual public key carrier data itself. If less than five |
| 144 |
arguments are given, then the PKC_DATA is expected on stdin. If five |
| 145 |
arguments are given, the fifth argument is interpreted as the |
| 146 |
PKC_DATA. This is likely only useful for supplying an OpenPGP |
| 147 |
fingerprint with the 'openpgp4fpr' type. |
| 148 |
|
| 149 |
=back |
| 150 |
|
| 151 |
=head1 RETURN CODE |
| 152 |
|
| 153 |
If the certificate is valid for the requested peer in the given |
| 154 |
context, the return code is 0. Otherwise, the return code is 1. |
| 155 |
|
| 156 |
=head1 ENVIRONMENT VARIABLES |
| 157 |
|
| 158 |
msva-query-agent's behavior is controlled by environment variables: |
| 159 |
|
| 160 |
=over 4 |
| 161 |
|
| 162 |
=item MONKEYSPHERE_VALIDATION_AGENT_SOCKET |
| 163 |
|
| 164 |
Socket over which to query the validation agent. If unset, the |
| 165 |
default value is 'http://127.0.0.1:8901'. |
| 166 |
|
| 167 |
=item MSVA_LOG_LEVEL |
| 168 |
|
| 169 |
Log messages about its operation to stderr. MSVA_LOG_LEVEL controls |
| 170 |
its verbosity, and should be one of (in increasing verbosity): silent, |
| 171 |
quiet, fatal, error, info, verbose, debug, debug1, debug2, debug3. |
| 172 |
Default is 'error'. |
| 173 |
|
| 174 |
=back |
| 175 |
|
| 176 |
=head1 COMMUNICATION PROTOCOL DETAILS |
| 177 |
|
| 178 |
Communications with the Monkeysphere Validation Agent are in the form |
| 179 |
of JSON requests over plain HTTP. Responses from the agent are also |
| 180 |
JSON objects. For details on the structure of the requests and |
| 181 |
responses, please see |
| 182 |
http://web.monkeysphere.info/validation-agent/protocol |
| 183 |
|
| 184 |
=head1 SEE ALSO |
| 185 |
|
| 186 |
msva-perl(1), monkeysphere(1), monkeysphere(7) |
| 187 |
|
| 188 |
=head1 BUGS AND FEEDBACK |
| 189 |
|
| 190 |
Bugs or feature requests for msva-perl and associated tools should be |
| 191 |
filed with the Monkeysphere project's bug tracker at |
| 192 |
https://labs.riseup.net/code/projects/monkeysphere/issues/ |
| 193 |
|
| 194 |
=head1 AUTHORS AND CONTRIBUTORS |
| 195 |
|
| 196 |
Jameson Graef Rollins E<lt>[email protected]<gt> |
| 197 |
Daniel Kahn Gillmor E<lt>[email protected]<gt> |
| 198 |
|
| 199 |
The Monkeysphere Team http://web.monkeysphere.info/ |
| 200 |
|
| 201 |
=head1 COPYRIGHT AND LICENSE |
| 202 |
|
| 203 |
Copyright © 2010, Jameson Graef Rollins and others from the Monkeysphere |
| 204 |
team. msva-query-agent is free software, distributed under the GNU |
| 205 |
Public License, version 3 or later. |