source: preprover/abac_preprover_server.pl

Last change on this file was 55c272b, checked in by Mike Ryan <mikeryan@…>, 14 years ago

remove libabac_init and libabac_deinit

  • 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 IO::Socket::SSL;
7use XMLRPC;
8
9use lib '../swig/perl';
10use ABAC;
11
12use constant {
13    PORT    => 8000,
14};
15
16my ($keystore, $cert, $key);
17my $port = 8000;
18GetOptions(
19    'keystore=s'    => \$keystore,
20    'port=i'        => \$port,
21    'cert=s'        => \$cert,
22    'key=s'        => \$key,
23) || usage();
24
25usage() unless defined $keystore && defined $cert && defined $key;
26
27my $ctx = ABAC::Context->new;
28$ctx->load_directory($keystore);
29
30my $server = XMLRPC->new();
31$server->add_method({
32    name        => 'abac.query',
33    code        => \&abac_query,
34    signature   => [ 'struct struct' ],
35});
36$server->run($port, $cert, $key);
37
38sub abac_query {
39    my ($server, $request) = @_;
40
41    my $peer_cert = $server->{peer_cert};
42    my $peer_id = ABAC::SSL_keyid($peer_cert);
43
44    # clone the context so the state remains pure between requests
45    my $local_ctx = ABAC::Context->new($ctx);
46    foreach my $cred (@{$request->{credentials}}) {
47        my $ret = $local_ctx->load_id_chunk($cred->{issuer_cert});
48        warn "Invalid issuer certificate" unless $ret == $ABAC::ABAC_CERT_SUCCESS;
49
50        $ret = $local_ctx->load_attribute_chunk($cred->{attribute_cert});
51        warn "Invalid attribute certificate" unless $ret == $ABAC::ABAC_CERT_SUCCESS;
52    }
53
54    my $role = $request->{role};
55    print "$role <- $peer_id\n";
56    my ($success, $credentials) = $local_ctx->query($role, $peer_id);
57
58    return {
59        success => $success,
60        map {{
61            attribute_cert  => RPC::XML::base64->new($_->attribute_cert),
62            issuer_cert     => RPC::XML::base64->new($_->issuer_cert),
63        }} @$credentials,
64    };
65}
66
67sub usage {
68    print "Usage: $0 \\\n";
69    print "        --keystore <keystore> [ --port <port> ] \\\n";
70    print "        --cert <cert.pem> --key <key.pem>\n";
71    print "    port defaults to 8000\n";
72    print "\n";
73    print "    cert and key must be an OpenSSL cert and key\n";
74    print "    ABAC cert and key will not work\n";
75    exit 1;
76}
Note: See TracBrowser for help on using the repository browser.