source: examples/python_tests/acme_multi_rt0/query.py @ 09496b3

mei_rt2mei_rt2_fix_1
Last change on this file since 09496b3 was abf8d5d, checked in by Mei <mei@…>, 12 years ago

1) add backtrack/multiple solutions proof code changes and new

examples.

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