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() |
---|
15 | ctxt.set_no_partial_proof() |
---|
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 | #ctxt.dump_yap_db() |
---|
27 | |
---|
28 | # retrieve principals' keyid value from local credential files |
---|
29 | acmeID=ABAC.ID("Acme_ID.pem"); |
---|
30 | acmeID.id_load_privkey_file("Acme_private.pem"); |
---|
31 | acme=acmeID.id_keyid() |
---|
32 | |
---|
33 | bobID=ABAC.ID("Bob_ID.pem"); |
---|
34 | bobID.id_load_privkey_file("Bob_private.pem"); |
---|
35 | bob=bobID.id_keyid() |
---|
36 | |
---|
37 | aliceID=ABAC.ID("Alice_ID.pem"); |
---|
38 | aliceID.id_load_privkey_file("Alice_private.pem"); |
---|
39 | alice=aliceID.id_keyid() |
---|
40 | |
---|
41 | globotronID=ABAC.ID("Globotron_ID.pem"); |
---|
42 | globotronID.id_load_privkey_file("Globotron_private.pem"); |
---|
43 | globotron=globotronID.id_keyid() |
---|
44 | |
---|
45 | ########################################################################## |
---|
46 | # dump the loaded principals/policies |
---|
47 | # |
---|
48 | out = ctxt.context_principals() |
---|
49 | print "\n...final principal set..." |
---|
50 | for x in out[1]: |
---|
51 | print "%s " % x.string() |
---|
52 | out = ctxt.context_credentials() |
---|
53 | print "\n...final policy attribute set..." |
---|
54 | for c in out[1]: |
---|
55 | print "%s <- %s" % (c.head_string(), c.tail_string()) |
---|
56 | |
---|
57 | ########################################################################## |
---|
58 | # is alice a admin at Globotron ? |
---|
59 | # role=[keyid:Globotron].role:admin |
---|
60 | # p=[keyid:Alice] |
---|
61 | role = ABAC.Role(globotron,"admin") |
---|
62 | p = ABAC.Role(alice) |
---|
63 | print "\n===good=============== Globotron.admin <- Alice" |
---|
64 | out = ctxt.query(role, p) |
---|
65 | for c in out[1]: |
---|
66 | print "%s <- %s" % (c.head_string(), c.tail_string()) |
---|
67 | |
---|
68 | ########################################################################## |
---|
69 | # is bob a admin at Globotron ? |
---|
70 | # role=[keyid:Globotron].role:admin |
---|
71 | # p=[keyid:Bob] |
---|
72 | role = ABAC.Role(globotron,"admin") |
---|
73 | p = ABAC.Role(bob) |
---|
74 | print "\n===bad=============== Globotron.admin <- Bob" |
---|
75 | out = ctxt.query(role, p) |
---|
76 | for c in out[1]: |
---|
77 | print "%s <- %s" % (c.head_string(), c.tail_string()) |
---|
78 | |
---|
79 | |
---|
80 | ########################################################################## |
---|
81 | # can bob create experiment at Acme ? |
---|
82 | # role=[keyid:Acme].role:experiment_create |
---|
83 | # p=[keyid:Bob] |
---|
84 | role = ABAC.Role(acme,"experiment_create") |
---|
85 | p = ABAC.Role(bob) |
---|
86 | print "\n===good=============== Acme.experiment_create <- Bob" |
---|
87 | out = ctxt.query(role, p) |
---|
88 | for c in out[1]: |
---|
89 | print "%s <- %s" % (c.head_string(), c.tail_string()) |
---|