[abf8d5d] | 1 | #!/usr/bin/env python |
---|
| 2 | |
---|
| 3 | """ |
---|
| 4 | Run the queries described in README |
---|
| 5 | |
---|
| 6 | cmd1:env keystore=`pwd` ./query.py |
---|
| 7 | cmd2: env ABAC_CN=1 keystore=`pwd` ./query.py |
---|
| 8 | |
---|
| 9 | """ |
---|
| 10 | |
---|
| 11 | import os |
---|
| 12 | import ABAC |
---|
| 13 | |
---|
| 14 | ctxt = ABAC.Context() |
---|
[646e57e] | 15 | ctxt.set_no_partial_proof() |
---|
[abf8d5d] | 16 | |
---|
| 17 | # Keystore is the directory containing the principal credentials. |
---|
| 18 | # Load existing principals and/or policy credentials |
---|
| 19 | if (os.environ.has_key("keystore")) : |
---|
| 20 | keystore=os.environ["keystore"] |
---|
| 21 | ctxt.load_directory(keystore) |
---|
| 22 | else: |
---|
| 23 | print("keystore is not set...") |
---|
| 24 | exit(1) |
---|
| 25 | |
---|
| 26 | # retrieve principals' keyid value from local credential files |
---|
| 27 | acmeID=ABAC.ID("Acme_ID.pem"); |
---|
| 28 | acmeID.id_load_privkey_file("Acme_private.pem"); |
---|
| 29 | acme=acmeID.id_keyid() |
---|
| 30 | |
---|
| 31 | bobID=ABAC.ID("Bob_ID.pem"); |
---|
| 32 | bobID.id_load_privkey_file("Bob_private.pem"); |
---|
| 33 | bob=bobID.id_keyid() |
---|
| 34 | |
---|
| 35 | aliceID=ABAC.ID("Alice_ID.pem"); |
---|
| 36 | aliceID.id_load_privkey_file("Alice_private.pem"); |
---|
| 37 | alice=aliceID.id_keyid() |
---|
| 38 | |
---|
| 39 | globotronID=ABAC.ID("Globotron_ID.pem"); |
---|
| 40 | globotronID.id_load_privkey_file("Globotron_private.pem"); |
---|
| 41 | globotron=globotronID.id_keyid() |
---|
| 42 | |
---|
| 43 | ########################################################################## |
---|
| 44 | # dump the loaded principals/policies |
---|
| 45 | # |
---|
| 46 | out = ctxt.context_principals() |
---|
| 47 | print "\n...final principal set..." |
---|
| 48 | for x in out[1]: |
---|
| 49 | print "%s " % x.string() |
---|
| 50 | out = ctxt.context_credentials() |
---|
| 51 | print "\n...final policy attribute set..." |
---|
| 52 | for c in out[1]: |
---|
| 53 | print "%s <- %s" % (c.head_string(), c.tail_string()) |
---|
| 54 | |
---|
| 55 | def get_next(ctxt) : |
---|
[646e57e] | 56 | while( 1 ) : |
---|
[abf8d5d] | 57 | print ("\nnext proof:") |
---|
[646e57e] | 58 | (success, out) = ctxt.next_proof() |
---|
| 59 | if(success) : |
---|
| 60 | for c in out: |
---|
| 61 | print "%s <- %s" % (c.head_string(), c.tail_string()) |
---|
[abf8d5d] | 62 | else: |
---|
| 63 | print("no more..\n") |
---|
[646e57e] | 64 | return |
---|
[abf8d5d] | 65 | |
---|
| 66 | ########################################################################## |
---|
| 67 | # can bob create experiment at Acme ? |
---|
| 68 | # role=[keyid:Acme].role:experiment_create |
---|
| 69 | # p=[keyid:Bob] |
---|
| 70 | role = ABAC.Role(acme,"experiment_create") |
---|
| 71 | p = ABAC.Role(bob) |
---|
| 72 | print "\n===good=============== Acme.experiment_create <- Bob" |
---|
| 73 | out = ctxt.query(role, p) |
---|
| 74 | for c in out[1]: |
---|
| 75 | print "%s <- %s" % (c.head_string(), c.tail_string()) |
---|
| 76 | get_next(ctxt) |
---|
| 77 | |
---|