[669b481] | 1 | #!/usr/bin/env python |
---|
| 2 | |
---|
| 3 | """ |
---|
[f824a9e] | 4 | Run the queries described in README |
---|
[669b481] | 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() |
---|
| 15 | |
---|
[f824a9e] | 16 | # Keystore is the directory containing the principal credentials. |
---|
| 17 | # Load existing principals and/or policy credentials |
---|
| 18 | if (os.environ.has_key("keystore")) : |
---|
| 19 | keystore=os.environ["keystore"] |
---|
| 20 | ctxt.load_directory(keystore) |
---|
| 21 | else: |
---|
| 22 | print("keystore is not set...") |
---|
| 23 | exit(1) |
---|
[669b481] | 24 | |
---|
[f824a9e] | 25 | # retrieve principals' keyid value from local credential files |
---|
[669b481] | 26 | aliceID=ABAC.ID("Alice_ID.pem") |
---|
| 27 | aliceID.id_load_privkey_file("Alice_private.pem") |
---|
| 28 | alice=aliceID.id_keyid() |
---|
| 29 | |
---|
| 30 | partyID=ABAC.ID("Party_ID.pem") |
---|
| 31 | partyID.id_load_privkey_file("Party_private.pem") |
---|
| 32 | party=partyID.id_keyid() |
---|
| 33 | |
---|
| 34 | teaID=ABAC.ID("Tea_ID.pem") |
---|
| 35 | teaID.id_load_privkey_file("Tea_private.pem") |
---|
| 36 | tea=teaID.id_keyid() |
---|
| 37 | |
---|
| 38 | hatterID=ABAC.ID("Hatter_ID.pem") |
---|
| 39 | hatterID.id_load_privkey_file("Hatter_private.pem") |
---|
| 40 | hatter=hatterID.id_keyid() |
---|
| 41 | |
---|
| 42 | marchhareID=ABAC.ID("Marchhare_ID.pem") |
---|
| 43 | marchhareID.id_load_privkey_file("Marchhare_private.pem") |
---|
| 44 | marchhare=marchhareID.id_keyid() |
---|
| 45 | |
---|
| 46 | dormouseID=ABAC.ID("Dormouse_ID.pem") |
---|
| 47 | dormouseID.id_load_privkey_file("Dormouse_private.pem") |
---|
| 48 | dormouse=dormouseID.id_keyid() |
---|
| 49 | |
---|
[f824a9e] | 50 | ########################################################################## |
---|
| 51 | # dump the loaded principals/policies |
---|
| 52 | # |
---|
| 53 | out = ctxt.context_principals() |
---|
| 54 | print "\n...final principal set..." |
---|
| 55 | for x in out[1]: |
---|
| 56 | print "%s " % x.string() |
---|
| 57 | out = ctxt.context_credentials() |
---|
| 58 | print "\n...final policy attribute set..." |
---|
| 59 | for c in out[1]: |
---|
| 60 | print "%s <- %s" % (c.head_string(), c.tail_string()) |
---|
[669b481] | 61 | |
---|
| 62 | ########################################################################## |
---|
[f824a9e] | 63 | # can dormouse be a guest at the party ? |
---|
[669b481] | 64 | # role=[keyid:Party].role:guests |
---|
| 65 | # p=[keyid:dormouse] |
---|
| 66 | role = ABAC.Role(party,"guests") |
---|
| 67 | p = ABAC.Role(dormouse) |
---|
| 68 | print "\n===good============ Party.guests <- dourmouse" |
---|
| 69 | out = ctxt.query(role, p) |
---|
| 70 | for c in out[1]: |
---|
| 71 | print "%s <- %s" % (c.head_string(), c.tail_string()) |
---|
| 72 | |
---|
| 73 | ########################################################################## |
---|
[f824a9e] | 74 | # can hatter be a guest at the party ? |
---|
[669b481] | 75 | # role=[keyid:Party].role:guests |
---|
| 76 | # p=[keyid:hatter] |
---|
| 77 | role = ABAC.Role(party,"guests") |
---|
| 78 | p = ABAC.Role(hatter) |
---|
| 79 | print "\n===bad============ Party.guests <- hatter" |
---|
| 80 | out = ctxt.query(role, p) |
---|
| 81 | for c in out[1]: |
---|
| 82 | print "%s <- %s" % (c.head_string(), c.tail_string()) |
---|
| 83 | |
---|