source: examples/python_tests/payraise_rt1/attr.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: 5.5 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
25out = ctxt.context_principals()
26print "...initial principal set..."
27for x in out[1]:
28    print "%s " % x.string()
29print "\n" 
30
31out = ctxt.context_credentials()
32print "...initial policy attribute set..."
33for c in out[1]:
34    print "%s <- %s" % (c.head_string(), c.tail_string())
35print "\n"
36
37# retrieve principals' keyid value from local credential files
38alphaID=ABAC.ID("Alpha_ID.pem");
39alphaID.id_load_privkey_file("Alpha_private.pem");
40alpha=alphaID.id_keyid()
41
42bobID=ABAC.ID("Bob_ID.pem");
43bobID.id_load_privkey_file("Bob_private.pem");
44bob=bobID.id_keyid()
45
46maryannID=ABAC.ID("Maryann_ID.pem");
47maryannID.id_load_privkey_file("Maryann_private.pem");
48maryann=maryannID.id_keyid()
49
50joeID=ABAC.ID("Joe_ID.pem");
51joeID.id_load_privkey_file("Joe_private.pem");
52joe=joeID.id_keyid()
53
54################################################
55# Credential 1, intersecting linking roles with This principal param for the
56#               linked role
57# [keyid:alpha].role:payRaise <-
58#      [keyid:alpha].role:evaluatorOf([principal:?this]).role:goodPerformance &
59#      [keyid:alpha].role:managerOf([principal:?this]).role:niceCoworker
60head=ABAC.Role(alpha,"payRaise")
61
62# build a data term with ?This
63param=ABAC.DataTerm("principal", "This")
64tail1 = ABAC.Role(alpha,"evaluatorOf","goodPerformance")
65
66# add the param to the linked role
67tail1.role_add_linked_data_term(param)
68
69# build another data term with ?This
70param=ABAC.DataTerm("principal", "This")
71tail2 = ABAC.Role(alpha,"managerOf","niceCoworker")
72
73# add the param to the linked role
74tail2.role_add_linked_data_term(param)
75
76# compose the intersecting role attribute policy
77attr=ABAC.Attribute(head, 1800)
78attr.attribute_add_tail(tail1)
79attr.attribute_add_tail(tail2)
80
81# finalize the attribute policy
82attr.attribute_bake()
83
84# write out the attribute credential file
85attr.attribute_write_cert("Alpha_payraise__Alpha_performance_qT_niceguy_qT_attr.der")
86ctxt.load_attribute_file("Alpha_payraise__Alpha_performance_qT_niceguy_qT_attr.der")
87print attr.string() 
88print attr.typed_string()
89print "\n"
90
91#################################################
92# Credential 2,
93# [keyid:alpha].role:managerOf([principal:?Z])<-
94#           [keyid:alpha].role:evaluatorOf([principal:?Z])
95param=ABAC.DataTerm("principal", "Z")
96head=ABAC.Role(alpha,"managerOf")
97head.role_add_data_term(param)
98param=ABAC.DataTerm("principal", "Z")
99tail = ABAC.Role(alpha,"evaluatorOf")
100tail.role_add_data_term(param)
101attr=ABAC.Attribute(head, 1800)
102attr.attribute_add_tail(tail)
103attr.attribute_bake()
104attr.attribute_write_cert("Alpha_manager_qZ__Alpha_evaluator_qZ_attr.der")
105ctxt.load_attribute_file("Alpha_manager_qZ__Alpha_evaluator_qZ_attr.der")
106print attr.string() 
107print attr.typed_string()
108print "\n"
109
110#################################################
111# Credential 3
112# [keyid:alpha].role:evaluatorOf([keyid:Maryann]) <-[keyid:Bob]
113param=ABAC.DataTerm(maryannID)
114head = ABAC.Role(alpha,"evaluatorOf")
115head.role_add_data_term(param)
116tail = ABAC.Role(bob)
117attr=ABAC.Attribute(head, 1800)
118attr.attribute_add_tail(tail)
119attr.attribute_bake()
120attr.attribute_write_cert("Alpha_evaluator_m__Bob_attr.der")
121ctxt.load_attribute_file("Alpha_evaluator_m__Bob_attr.der")
122print attr.string() 
123print attr.typed_string()
124print "\n"
125
126#################################################
127# Credential 4
128# [keyid:Bob].role:goodPerformance <- [keyid:Maryann])
129head = ABAC.Role(bob,"goodPerformance")
130tail = ABAC.Role(maryann)
131attr=ABAC.Attribute(head, 1800)
132attr.attribute_add_tail(tail)
133attr.attribute_bake()
134attr.attribute_write_cert("Bob_goodperformance__Maryann_attr.der")
135ctxt.load_attribute_file("Bob_goodperformance__Maryann_attr.der")
136print attr.string() 
137print attr.typed_string()
138print "\n"
139
140#################################################
141# Credential 5
142# [keyid:Bob].role:niceCoworker <- [keyid:Maryann])
143head = ABAC.Role(bob,"niceCoworker")
144tail = ABAC.Role(maryann)
145attr=ABAC.Attribute(head, 1800)
146attr.attribute_add_tail(tail)
147attr.attribute_bake()
148attr.attribute_write_cert("Bob_nicecoworker__Maryann_attr.der")
149ctxt.load_attribute_file("Bob_nicecoworker__Maryann_attr.der")
150print attr.string() 
151print attr.typed_string()
152print "\n"
153
154#################################################
155# Credential 6
156# [keyid:alpha].role:evaluatorOf([keyid:Joe]) <-[keyid:Bob]
157param=ABAC.DataTerm(joeID)
158head = ABAC.Role(alpha,"evaluatorOf")
159head.role_add_data_term(param)
160tail = ABAC.Role(bob)
161attr=ABAC.Attribute(head, 1800)
162attr.attribute_add_tail(tail)
163attr.attribute_bake()
164attr.attribute_write_cert("Alpha_evaluator_j__Bob_attr.der")
165ctxt.load_attribute_file("Alpha_evaluator_j__Bob_attr.der")
166print attr.string() 
167print attr.typed_string()
168print "\n"
169
170#################################################
171# Credential 7
172# [keyid:Bob].role:goodPerformance <- [keyid:Joe])
173head = ABAC.Role(bob,"goodPerformance")
174tail = ABAC.Role(joe)
175attr=ABAC.Attribute(head, 1800)
176attr.attribute_add_tail(tail)
177attr.attribute_bake()
178attr.attribute_write_cert("Bob_goodperformance__Joe_attr.der")
179ctxt.load_attribute_file("Bob_goodperformance__Joe_attr.der")
180print attr.string() 
181print attr.typed_string()
182print "\n"
183
Note: See TracBrowser for help on using the repository browser.