source: examples/python_tests/acme_rockets_intersection_rt0/query.py @ a59bc06

mei_rt2mei_rt2_fix_1
Last change on this file since a59bc06 was 646e57e, checked in by Mei <mei@…>, 12 years ago

1) add partial proof

  • Property mode set to 100755
File size: 2.2 KB
Line 
1#!/usr/bin/env python
2
3"""
4Run the queries described in README
5
6cmd1:env keystore=`pwd` ./query.py
7cmd2: env ABAC_CN=1 keystore=`pwd` ./query.py
8"""
9
10import os
11import ABAC
12
13ctxt = ABAC.Context()
14ctxt.set_no_partial_proof()
15
16# Keystore is the directory containing the principal credentials.
17# Load existing principals and/or policy credentials
18if (os.environ.has_key("keystore")) :
19    keystore=os.environ["keystore"]
20    ctxt.load_directory(keystore)
21else:
22    print("keystore is not set...")
23    exit(1)
24
25# retrieve principals' keyid value from local credential files
26acmeID=ABAC.ID("Acme_ID.pem");
27acmeID.id_load_privkey_file("Acme_private.pem");
28acme=acmeID.id_keyid()
29
30coyoteID=ABAC.ID("Coyote_ID.pem");
31coyoteID.id_load_privkey_file("Coyote_private.pem");
32coyote=coyoteID.id_keyid()
33
34warnerbrosID=ABAC.ID("WarnerBros_ID.pem");
35warnerbrosID.id_load_privkey_file("WarnerBros_private.pem");
36warnerbros=warnerbrosID.id_keyid()
37
38batmanID=ABAC.ID("Batman_ID.pem");
39batmanID.id_load_privkey_file("Batman_private.pem");
40batman=batmanID.id_keyid()
41
42##########################################################################
43# dump the loaded principals/policies
44#
45out = ctxt.context_principals()
46print "\n...final principal set..."
47for x in out[1]:
48    print "%s " % x.string()
49out = ctxt.context_credentials()
50print "\n...final policy attribute set..."
51for c in out[1]:
52    print "%s <- %s" % (c.head_string(), c.tail_string())
53
54##########################################################################
55# can coyote buy rockets from Acme ?
56# role = "[keyid:Acme].role:buy_rockets"
57# p = "[keyid:coyote]"
58role = ABAC.Role(acme,"buy_rockets")
59p = ABAC.Role(coyote)
60
61print "\n===good============ Acme.buy_rockets <- Coyote"
62out = ctxt.query(role, p)
63
64for c in out[1]:
65    print "%s <- %s" % (c.head_string(), c.tail_string())
66
67
68##########################################################################
69# can batman buy rockets from Acme ?
70# role = "[keyid:Acme].role:buy_rockets"
71# p = "[keyid:batman]"
72role = ABAC.Role(acme,"buy_rockets")
73p = ABAC.Role(batman)
74
75print "\n===bad============ Acme.buy_rockets <- Batman"
76out = ctxt.query(role, p)
77
78for c in out[1]:
79    print "%s <- %s" % (c.head_string(), c.tail_string())
80
Note: See TracBrowser for help on using the repository browser.