source: examples/python_tests/leader_rt1/attr.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: 3.6 KB
Line 
1#!/usr/bin/env python
2
3"""
4See README in this directory for the semantics of the example.  This file
5constructs the credentials described and puts copies into this directory
6
7cmd1:env keystore=`pwd` ./attr.py
8"""
9
10import os
11import ABAC
12
13ctxt = ABAC.Context()
14print "ABAC version %s" % ctxt.version()
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
26out = ctxt.context_principals()
27print "...initial principal set..."
28for x in out[1]:
29    print "%s " % x.string()
30print "\n" 
31
32out = ctxt.context_credentials()
33print "...initial policy attribute set..."
34for c in out[1]:
35    print "%s <- %s" % (c.head_string(), c.tail_string())
36print "\n"
37
38# retrieve principals' keyid value from local credential files
39geniID=ABAC.ID("Geni_ID.pem");
40geniID.id_load_privkey_file("Geni_private.pem");
41geni=geniID.id_keyid()
42
43bobID=ABAC.ID("Bob_ID.pem");
44bobID.id_load_privkey_file("Bob_private.pem");
45bob=bobID.id_keyid()
46
47jackID=ABAC.ID("Jack_ID.pem");
48jackID.id_load_privkey_file("Jack_private.pem");
49jack=jackID.id_keyid()
50
51joeID=ABAC.ID("Joe_ID.pem");
52joeID.id_load_privkey_file("Joe_private.pem");
53joe=joeID.id_keyid()
54
55################################################
56# Credential 1,
57# [keyid:geni].role:leader
58#         <- [keyid:geni].role:equivalent([principal:?P[keyid:geni].role:leader])
59head=ABAC.Role(geni,"leader")
60
61# initialize the role constraint on a principlal
62condrole=ABAC.Role(geni,"leader")
63cond=ABAC.Constraint(condrole)
64
65# make the data term with the role constraint
66param=ABAC.DataTerm("principal","P", cond)
67tail = ABAC.Role(geni,"equivalent")
68tail.role_add_data_term(param)
69
70# build he attribute policy
71attr=ABAC.Attribute(head, 1800)
72attr.attribute_add_tail(tail)
73
74# finalize the policy
75attr.attribute_bake()
76
77# write the policy out to a credential file
78attr.attribute_write_cert("geni_leader__geni_leader_qP_attr.der")
79
80# load the policy into the context using the credential file
81ctxt.load_attribute_file("geni_leader__geni_leader_qP_attr.der")
82print attr.string() 
83print attr.typed_string()
84print "\n"
85
86#################################################
87# Credential 2
88# [keyid:geni].role:leader <- [keyid:bob]
89head=ABAC.Role(geni,"leader")
90tail = ABAC.Role(bob)
91attr=ABAC.Attribute(head, 1800)
92attr.attribute_add_tail(tail)
93attr.attribute_bake()
94attr.attribute_write_cert("geni_leader__Bob_attr.der")
95ctxt.load_attribute_file("geni_leader__Bob_attr.der")
96print attr.string() 
97print attr.typed_string()
98print "\n"
99
100#################################################
101# Credential 3
102# [keyid:geni].role:equivalent([keyid:bob]) <- [keyid:Joe]
103param=ABAC.DataTerm(bobID)
104head = ABAC.Role(geni,"equivalent")
105head.role_add_data_term(param)
106tail = ABAC.Role(joe)
107attr=ABAC.Attribute(head, 1800)
108attr.attribute_add_tail(tail)
109attr.attribute_bake()
110attr.attribute_write_cert("geni_equivalent_Bob__Joe_attr.der")
111ctxt.load_attribute_file("geni_equivalent_Bob__Joe_attr.der")
112print attr.string() 
113print attr.typed_string()
114print "\n"
115
116#################################################
117# Credential 4
118# [keyid:geni].role:equivalent([keyid:Joe]) <- [keyid:Bob]
119param=ABAC.DataTerm(joeID)
120head = ABAC.Role(geni,"equivalent")
121head.role_add_data_term(param)
122tail = ABAC.Role(bob)
123attr=ABAC.Attribute(head, 1800)
124attr.attribute_add_tail(tail)
125attr.attribute_bake()
126attr.attribute_write_cert("geni_equivalent_Joe__Bob_attr.der")
127ctxt.load_attribute_file("geni_equivalent_Joe__Bob_attr.der")
128print attr.string() 
129print attr.typed_string()
130print "\n"
Note: See TracBrowser for help on using the repository browser.