[c987819] | 1 | #!/usr/bin/perl |
---|
| 2 | |
---|
| 3 | use strict; |
---|
| 4 | use ABAC; |
---|
| 5 | use Data::Dumper; |
---|
| 6 | $Data::Dumper::Indent = 1; |
---|
| 7 | |
---|
| 8 | use constant { |
---|
| 9 | ROLE => '3f1aca4c5911b345d81c5f1a77675dce13249d0c.fed_create', |
---|
| 10 | PRINCIPAL => '5839d714b16bbe108642c5eb586c2173420bed19', |
---|
| 11 | }; |
---|
| 12 | |
---|
| 13 | my $keystore = shift || die "Usage: prover.pl <keystore> [-v]\n"; |
---|
| 14 | my $verbose = shift; |
---|
| 15 | |
---|
| 16 | ABAC::libabac_init(); |
---|
| 17 | |
---|
| 18 | my $ctx = ABAC::Context->new; |
---|
| 19 | $ctx->load_directory("$keystore/1"); |
---|
| 20 | |
---|
| 21 | my $ctx_add = ABAC::Context->new($ctx); |
---|
| 22 | |
---|
| 23 | my ($success, $credentials) = $ctx_add->query(ROLE, PRINCIPAL); |
---|
| 24 | my $result = $success ? 'FAIL' : 'PASS'; |
---|
| 25 | printf "%-60s %s\n", 'Unsuccessful query:', $result; |
---|
| 26 | dump_creds($credentials) if $verbose; |
---|
| 27 | |
---|
| 28 | $ctx_add->load_directory("$keystore/2"); |
---|
| 29 | my ($success, $credentials) = $ctx_add->query(ROLE, PRINCIPAL); |
---|
| 30 | my $result = $success ? 'PASS' : 'FAIL'; |
---|
| 31 | printf "%-60s %s\n", 'Added credentials, successful query:', $result; |
---|
| 32 | dump_creds($credentials) if $verbose; |
---|
| 33 | |
---|
| 34 | my ($success, $credentials) = $ctx->query(ROLE, PRINCIPAL); |
---|
| 35 | my $result = $success ? 'FAIL' : 'PASS'; |
---|
| 36 | printf "%-60s %s\n", 'Original context, failed query:', $result; |
---|
| 37 | dump_creds($credentials) if $verbose; |
---|
| 38 | |
---|
| 39 | ABAC::libabac_deinit(); |
---|
| 40 | |
---|
| 41 | sub dump_creds { |
---|
| 42 | my $credentials = shift; |
---|
| 43 | foreach my $credential (@$credentials) { |
---|
| 44 | printf "%s <- %s\n", |
---|
| 45 | $credential->head->string, |
---|
| 46 | $credential->tail->string; |
---|
| 47 | } |
---|
| 48 | } |
---|