1 | #!/usr/bin/perl |
---|
2 | |
---|
3 | use strict; |
---|
4 | use Data::Dumper; |
---|
5 | use RPC::XML qw(smart_encode); |
---|
6 | use RPC::XML::ParserFactory; |
---|
7 | use LWP::UserAgent; |
---|
8 | use HTTP::Request; |
---|
9 | # use IO::Socket::SSL; |
---|
10 | |
---|
11 | use lib '../swig/perl'; |
---|
12 | use ABAC; |
---|
13 | ABAC::libabac_init; |
---|
14 | |
---|
15 | use constant { |
---|
16 | USER_AGENT => 'libabac/0.1', |
---|
17 | }; |
---|
18 | |
---|
19 | my ($keystore, $url) = @ARGV; |
---|
20 | die "Usage: $0 <keystore> <url>\n" unless defined $keystore && defined $url; |
---|
21 | |
---|
22 | # load the certificates |
---|
23 | my $context = ABAC::Context->new; |
---|
24 | $context->load_directory($keystore); |
---|
25 | |
---|
26 | # build the XML RPC request |
---|
27 | my $request = RPC::XML::request->new( |
---|
28 | 'abac.query', |
---|
29 | smart_encode({ |
---|
30 | role => '3f1aca4c5911b345d81c5f1a77675dce13249d0c.fed_create', |
---|
31 | credentials => [ |
---|
32 | map {{ |
---|
33 | attribute_cert => RPC::XML::base64->new($_->attribute_cert), |
---|
34 | issuer_cert => RPC::XML::base64->new($_->issuer_cert), |
---|
35 | }} @{$context->credentials} |
---|
36 | ], |
---|
37 | }), |
---|
38 | ); |
---|
39 | |
---|
40 | # encode and send the HTTP POST |
---|
41 | my $request_body = $request->as_string; |
---|
42 | |
---|
43 | $ENV{HTTPS_CERT_FILE} = 'certs/mike-cert.pem'; |
---|
44 | $ENV{HTTPS_KEY_FILE} = 'certs/mike-key.pem'; |
---|
45 | |
---|
46 | my $ua = LWP::UserAgent->new; |
---|
47 | |
---|
48 | my $request = HTTP::Request->new( |
---|
49 | 'POST', |
---|
50 | "https://$url/RPC2", |
---|
51 | ); |
---|
52 | $request->header('User-Agent', USER_AGENT); |
---|
53 | $request->header('Content-Length', length $request_body); |
---|
54 | $request->content($request_body); |
---|
55 | |
---|
56 | my $response = $ua->request($request); |
---|
57 | if (!$response->is_success) { |
---|
58 | die $response->status_line; |
---|
59 | } |
---|
60 | |
---|
61 | # decode the reply |
---|
62 | my $xmlrpc_response = RPC::XML::ParserFactory->new->parse($response->decoded_content); |
---|
63 | print Dumper $xmlrpc_response; |
---|