source: examples/python_tests/experiment_multi_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.1 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
31bobID=ABAC.ID("Bob_ID.pem");
32bobID.id_load_privkey_file("Bob_private.pem");
33bob=bobID.id_keyid()
34
35aliceID=ABAC.ID("Alice_ID.pem");
36aliceID.id_load_privkey_file("Alice_private.pem");
37alice=aliceID.id_keyid()
38
39globotronID=ABAC.ID("Globotron_ID.pem");
40globotronID.id_load_privkey_file("Globotron_private.pem");
41globotron=globotronID.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
55def get_next(ctxt) :
56    while( 1 ) :
57        print ("\nnext proof:")
58        (success, out) = ctxt.next_proof()
59        if(success) :
60            for c in out:
61                print "%s <- %s" % (c.head_string(), c.tail_string())
62        else:
63            print("no more..\n")
64            return
65
66##########################################################################
67# can bob create experiment at Acme ?
68# role=[keyid:Acme].role:experiment_create
69# p=[keyid:Bob]
70role = ABAC.Role(acme,"experiment_create")
71p = ABAC.Role(bob)
72print "\n===good=============== Acme.experiment_create <- Bob"
73out = ctxt.query(role, p)
74for c in out[1]:
75    print "%s <- %s" % (c.head_string(), c.tail_string())
76get_next(ctxt)
77
Note: See TracBrowser for help on using the repository browser.