tiny bit of cleanup and commenting
[monkeysphere-validation-agent.git] / msva-query-agent
index 1c77282701e2cbda7eaa2101d71a12d7196688df..784c16f599113d516011ad8b31483e8e0de1e1b4 100755 (executable)
 use warnings;
 use strict;
 
-use Crypt::Monkeysphere::MSVA qw( msvalog );
 use Crypt::Monkeysphere::MSVA::Client;
 
 my $context = shift;
+if ($context eq '--help') {
+    printf("Usage: msva-query-agent CONTEXT PEER PKC_TYPE [PEER_TYPE] <PKC_DATA\n");
+    exit 0;
+}
 my $peer = shift;
-my $pkctype = shift || 'x509der';
+my $pkctype = shift;
+my $peertype = shift;
 
 # load raw pkc data from stdin
 my $pkcdata = do {
@@ -32,12 +36,18 @@ my $pkcdata = do {
   <STDIN>;
 };
 
-my ($status,$ret) = Crypt::Monkeysphere::MSVA::Client->query_agent($context,$peer,$pkctype, $pkcdata, $ENV{MONKEYSPHERE_VALIDATION_AGENT_SOCKET});
+my $client = Crypt::Monkeysphere::MSVA::Client->new(
+                                                    socket => $ENV{MONKEYSPHERE_VALIDATION_AGENT_SOCKET},
+                                                    log_level => $ENV{MSVA_LOG_LEVEL},
+                                                   );
+
+my ($status,$ret) = $client->query_agent($context,$peer,$peertype,$pkctype,$pkcdata);
 
-msvalog('info', "status: %s\n", $status);
+$client->log('info', "status: %s\n", $status);
 if (defined $ret) {
-  msvalog('info', "valid: %s\n", $ret->{valid});
-  msvalog('fatal', "message: %s\n", $ret->{message});
+  $client->log('info', "valid: %s\n", $ret->{valid});
+  $client->log('info', "server: %s\n", $ret->{server});
+  printf("%s\n", $ret->{message});
   exit 0
     if ($ret->{valid});
 }
@@ -51,7 +61,7 @@ msva-query-agent - query a Monkeysphere Validation Agent
 
 =head1 SYNOPSIS
 
-msva-query-agent CONTEXT PEER PKC_TYPE < /path/to/public_key_carrier
+msva-query-agent CONTEXT PEER PKC_TYPE [PEER_TYPE] < /path/to/public_key_carrier
 
 =head1 ABSTRACT
 
@@ -64,10 +74,10 @@ msva-query-agent reads a certificate from standard input, and posts it
 to the running Monkeysphere Validation Agent.  The return code
 indicates the validity (as determined by the agent) of the certificate
 for the specified purpose.  The agent's return message (if any) is
-emitted on stderr.
+emitted on stdout.
 
-Three command-line arguments are all required, supplied in order, as
-follows:
+The first three command-line arguments are all required, supplied in
+order, as follows:
 
 =over 4
 
@@ -84,7 +94,17 @@ service, supply the host's full DNS name (e.g.  'foo.example.net')
 =item PKC_TYPE
 
 The format of public key carrier data provided on standard input
-(e.g. 'x509der')
+(e.g. 'x509der', 'x509pem', 'opensshpubkey', 'rfc4716')
+
+=back
+
+The fourth argument is optional:
+
+=over 4
+
+=item PEER_TYPE
+
+The type of peer we are inquiring about (e.g. 'client', 'server')
 
 =back