source: preprover/abac_preprover_client.pl @ 6159c8d

abac0-leakabac0-meicompt_changesgec13mei-idmei-rt0-nmei_rt0mei_rt2mei_rt2_fix_1meiyap-rt1meiyap1rt2tvf-new-xml
Last change on this file since 6159c8d was 6159c8d, checked in by Mike Ryan <mikeryan@…>, 14 years ago

add options to preprover client/server, install into bin

  • Property mode set to 100755
File size: 2.0 KB
Line 
1#!/usr/bin/perl
2
3use strict;
4use Getopt::Long;
5use Data::Dumper;
6use RPC::XML qw(smart_encode);
7use RPC::XML::ParserFactory;
8use LWP::UserAgent;
9use HTTP::Request;
10# use IO::Socket::SSL;
11
12use ABAC;
13
14use constant {
15    USER_AGENT  => 'abac/0.1.0',
16};
17
18my ($keystore, $cert, $key, $role);
19my $url = 'localhost:8000';
20GetOptions(
21    'keystore=s'    => \$keystore,
22    'url=s'         => \$url,
23    'cert=s'        => \$cert,
24    'key=s'         => \$key,
25    'role=s'        => \$role,
26) || usage();
27
28usage() unless defined $keystore && defined $cert && defined $key && defined $role;
29
30# code starts here
31ABAC::libabac_init;
32
33# load the certificates
34my $context = ABAC::Context->new;
35$context->load_directory($keystore);
36
37# build the XML RPC request
38my $request = RPC::XML::request->new(
39    'abac.query',
40    smart_encode({
41        role => $role,
42        credentials => [
43            map {{
44                attribute_cert  => RPC::XML::base64->new($_->attribute_cert),
45                issuer_cert     => RPC::XML::base64->new($_->issuer_cert),
46            }} @{$context->credentials}
47        ],
48    }),
49);
50
51# encode and send the HTTP POST
52my $request_body = $request->as_string;
53
54$ENV{HTTPS_CERT_FILE} = $cert;
55$ENV{HTTPS_KEY_FILE} = $key;
56$ENV{HTTPS_DEBUG} = 1;
57
58my $ua = LWP::UserAgent->new;
59
60my $request = HTTP::Request->new(
61    'POST',
62    "https://$url/RPC2",
63);
64$request->header('User-Agent', USER_AGENT);
65$request->header('Content-Length', length $request_body);
66$request->content($request_body);
67
68my $response = $ua->request($request);
69if (!$response->is_success) {
70    die $response->status_line;
71}
72
73# decode the reply
74my $xmlrpc_response = RPC::XML::ParserFactory->new->parse($response->decoded_content);
75print Dumper $xmlrpc_response;
76
77sub usage {
78    print "Usage: $0 \\\n";
79    print "        --keystore <keystore> [ --url <host:port> ] \\\n";
80    print "        --cert <cert.pem> --key <key.pem> \\\n";
81    print "        --role <keyid.role>\n";
82    print "    url defaults to localhost:8000\n";
83    exit 1;
84}
Note: See TracBrowser for help on using the repository browser.