source: examples/python_tests/alice_rt1/query.py @ 446b3ce

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

1) add partial proof

  • Property mode set to 100755
File size: 2.3 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
27aliceID=ABAC.ID("Alice_ID.pem")
28aliceID.id_load_privkey_file("Alice_private.pem")
29alice=aliceID.id_keyid()
30
31partyID=ABAC.ID("Party_ID.pem")
32partyID.id_load_privkey_file("Party_private.pem")
33party=partyID.id_keyid()
34
35teaID=ABAC.ID("Tea_ID.pem")
36teaID.id_load_privkey_file("Tea_private.pem")
37tea=teaID.id_keyid()
38
39hatterID=ABAC.ID("Hatter_ID.pem")
40hatterID.id_load_privkey_file("Hatter_private.pem")
41hatter=hatterID.id_keyid()
42
43marchhareID=ABAC.ID("Marchhare_ID.pem")
44marchhareID.id_load_privkey_file("Marchhare_private.pem")
45marchhare=marchhareID.id_keyid()
46
47dormouseID=ABAC.ID("Dormouse_ID.pem")
48dormouseID.id_load_privkey_file("Dormouse_private.pem")
49dormouse=dormouseID.id_keyid()
50
51##########################################################################
52# dump the loaded principals/policies
53#
54out = ctxt.context_principals()
55print "\n...final principal set..."
56for x in out[1]:
57    print "%s " % x.string()
58out = ctxt.context_credentials()
59print "\n...final policy attribute set..."
60for c in out[1]:
61    print "%s <- %s" % (c.head_string(), c.tail_string())
62
63##########################################################################
64# can dormouse be a guest at the party ?
65# role=[keyid:Party].role:guests
66# p=[keyid:dormouse]
67role = ABAC.Role(party,"guests")
68p = ABAC.Role(dormouse)
69print "\n===good============ Party.guests <- dourmouse"
70out = ctxt.query(role, p)
71for c in out[1]:
72    print "%s <- %s" % (c.head_string(), c.tail_string())
73
74##########################################################################
75# can hatter be a guest at the party ?
76# role=[keyid:Party].role:guests
77# p=[keyid:hatter]
78role = ABAC.Role(party,"guests")
79p = ABAC.Role(hatter)
80print "\n===bad============ Party.guests <- hatter"
81out = ctxt.query(role, p)
82for c in out[1]:
83    print "%s <- %s" % (c.head_string(), c.tail_string())
84
Note: See TracBrowser for help on using the repository browser.