source: examples/python_tests/acme_multi_rt0/query.py @ c3c73bd

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

1) add partial proof

  • Property mode set to 100755
File size: 2.6 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
27acmeID=ABAC.ID("Acme_ID.pem");
28acmeID.id_load_privkey_file("Acme_private.pem");
29acme=acmeID.id_keyid()
30
31coyoteID=ABAC.ID("Coyote_ID.pem");
32coyoteID.id_load_privkey_file("Coyote_private.pem");
33coyote=coyoteID.id_keyid()
34
35##########################################################################
36# dump the loaded principals/policies
37#
38out = ctxt.context_principals()
39print "\n...final principal set..."
40for x in out[1]:
41    print "%s " % x.string()
42out = ctxt.context_credentials()
43print "\n...final policy attribute set..."
44for c in out[1]:
45    print "%s <- %s" % (c.head_string(), c.tail_string())
46
47def get_next(ctxt) :
48    while(1) :
49        print ("\nnext proof:")
50        (success, out) = ctxt.next_proof()
51        if(success) :
52            for c in out:
53                print "%s <- %s" % (c.head_string(), c.tail_string())
54        else:
55            print("no more..\n")
56            return
57
58##########################################################################
59# can coyote buy rockets from Acme ?
60# role=[keyid:Acme].role:buy_rockets
61# p =[keyid:coyote]
62role = ABAC.Role(acme,"buy_rockets")
63p = ABAC.Role(coyote)
64print "\n===good============ Acme.buy_rockets <- Coyote"
65out = ctxt.query(role, p)
66for c in out[1]:
67    print "%s <- %s" % (c.head_string(), c.tail_string())
68get_next(ctxt)
69
70##########################################################################
71# is coyote a preferred_customer of Acme ?
72# role=[keyid:Acme].role:preferred_customer
73# p =[keyid:coyote]
74role = ABAC.Role(acme,"preferred_customer")
75p = ABAC.Role(coyote)
76print "\n===good============ Acme.preferred_customer <- Coyote"
77out = ctxt.query(role, p)
78for c in out[1]:
79    print "%s <- %s" % (c.head_string(), c.tail_string())
80get_next(ctxt)
81
82##########################################################################
83# is Acme a friend of coyote ?
84# role=[keyid:Coyote].role:friend
85# p=[keyid:Acme]
86role = ABAC.Role(coyote,"friend")
87p = ABAC.Role(acme)
88print "\n===bad=============== Coyote.friend <- Acme"
89out = ctxt.query(role, p)
90for c in out[1]:
91    print "%s <- %s" % (c.head_string(), c.tail_string())
92get_next(ctxt)
Note: See TracBrowser for help on using the repository browser.