source: examples/python_tests/leader_rt1/query.py @ 20eaefe

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

1) add partial proof

  • Property mode set to 100755
File size: 2.4 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"""
10
11import os
12import ABAC
13
14ctxt = ABAC.Context()
15ctxt.set_no_partial_proof()
16
17# Keystore is the directory containing the principal credentials.
18# Load existing principals and/or policy credentials
19if (os.environ.has_key("keystore")) :
20    keystore=os.environ["keystore"]
21    ctxt.load_directory(keystore)
22else:
23    print("keystore is not set...")
24    exit(1)
25
26# retrieve principals' keyid value from local credential files
27geniID=ABAC.ID("Geni_ID.pem");
28geniID.id_load_privkey_file("Geni_private.pem");
29geni=geniID.id_keyid()
30
31bobID=ABAC.ID("Bob_ID.pem");
32bobID.id_load_privkey_file("Bob_private.pem");
33bob=bobID.id_keyid()
34
35jackID=ABAC.ID("Jack_ID.pem");
36jackID.id_load_privkey_file("Jack_private.pem");
37jack=jackID.id_keyid()
38
39joeID=ABAC.ID("Joe_ID.pem");
40joeID.id_load_privkey_file("Joe_private.pem");
41joe=joeID.id_keyid()
42
43##########################################################################
44# dump the loaded principals/policies
45#
46out = ctxt.context_principals()
47print "\n...final principal set..."
48for x in out[1]:
49    print "%s " % x.string()
50out = ctxt.context_credentials()
51print "\n...final policy attribute set..."
52for c in out[1]:
53    print "%s <- %s" % (c.head_string(), c.tail_string())
54
55##########################################################################
56# is Bob a leader at Geni ?
57# role=[keyid:geni].role:leader
58# p=[keyid:Bob]
59role = ABAC.Role(geni,"leader")
60p = ABAC.Role(bob)
61print "\n===good============ geni.leader <- Bob"
62out = ctxt.query(role, p)
63for c in out[1]:
64    print "%s <- %s" % (c.head_string(), c.tail_string())
65
66##########################################################################
67# is Jack a leader at Geni ?
68# role=[keyid:geni].role:leader
69# p=[keyid:Jack]
70role = ABAC.Role(geni,"leader")
71p = ABAC.Role(jack)
72print "\n===bad============ geni.leader <- Jack"
73out = ctxt.query(role, p)
74for c in out[1]:
75    print "%s <- %s" % (c.head_string(), c.tail_string())
76
77##########################################################################
78# is Joe a leader at Geni ?
79# role=[keyid:geni].role:leader
80# p=[keyid:Joe]
81role = ABAC.Role(geni,"leader")
82p = ABAC.Role(joe)
83print "\n===good============ geni.leader <- Joe"
84out = ctxt.query(role, p)
85for c in out[1]:
86    print "%s <- %s" % (c.head_string(), c.tail_string())
87
Note: See TracBrowser for help on using the repository browser.