source: examples/python_tests/alice_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: 13.3 KB
RevLine 
[669b481]1#!/usr/bin/env python
2
3"""
[f824a9e]4See README in this directory for the semantics of the example.  This file
5constructs the credentials described and puts copies into this directory
[669b481]6
7cmd1:env keystore=`pwd` ./attr.py
8"""
9
10import os
11import ABAC
12
13ctxt = ABAC.Context()
14print "ABAC version %s" % ctxt.version()
15
[f824a9e]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)
[646e57e]21else:
22    print("keystore is not set...")
23    exit(1)
24
[669b481]25
[f824a9e]26# retrieve principals' keyid value from local credential files
[669b481]27out = ctxt.context_principals()
28print "...initial principal set..."
29for x in out[1]:
30    print "%s " % x.string()
31print "\n" 
32
33out = ctxt.context_credentials()
34print "...initial policy attribute set..."
35for c in out[1]:
36    print "%s <- %s" % (c.head_string(), c.tail_string())
37print "\n"
38
39aliceID=ABAC.ID("Alice_ID.pem")
40aliceID.id_load_privkey_file("Alice_private.pem")
41alice=aliceID.id_keyid()
42
43partyID=ABAC.ID("Party_ID.pem")
44partyID.id_load_privkey_file("Party_private.pem")
45party=partyID.id_keyid()
46
47teaID=ABAC.ID("Tea_ID.pem")
48teaID.id_load_privkey_file("Tea_private.pem")
49tea=teaID.id_keyid()
50
51hatterID=ABAC.ID("Hatter_ID.pem")
52hatterID.id_load_privkey_file("Hatter_private.pem")
53hatter=hatterID.id_keyid()
54
55marchhareID=ABAC.ID("Marchhare_ID.pem")
56marchhareID.id_load_privkey_file("Marchhare_private.pem")
57marchhare=marchhareID.id_keyid()
58
59dormouseID=ABAC.ID("Dormouse_ID.pem")
60dormouseID.id_load_privkey_file("Dormouse_private.pem")
61dormouse=dormouseID.id_keyid()
62
63
64# can not have attribute string more than 382 characters or so
65# that would cause encoded attribute string more than 511 in length
66# and could not push/pull out of ietf_attribute_t properly
67###############################################
[f824a9e]68# NOTE: space and '~' in string value
69#       time value's optional ending
[669b481]70# [keyid:Party].role: about([keyid:tea],[time:20101010T],[boolean:true],
71#                           [integer:4],[float:-200.0],[float:8],[time:20120205T182930],
[f824a9e]72#                           [string:'a list'],[urn:'file://usr/party/~teaparty'])
[669b481]73#                <- [keyid:Party].role:guestOf([keyid:MarchHare])
74head=ABAC.Role(party,"about")
75param=ABAC.DataTerm(teaID)
76head.role_add_data_term(param)
77param=ABAC.DataTerm("time","20101010T")
78head.role_add_data_term(param)
79param=ABAC.DataTerm("boolean","true")
80head.role_add_data_term(param)
81param=ABAC.DataTerm("integer","4")
82head.role_add_data_term(param)
83param=ABAC.DataTerm("float","-200.0")
84head.role_add_data_term(param)
85param=ABAC.DataTerm("float","8")
86head.role_add_data_term(param)
87param=ABAC.DataTerm("time","20120205T182930")
88head.role_add_data_term(param)
[f824a9e]89param=ABAC.DataTerm("string","'a list'")
[669b481]90head.role_add_data_term(param)
91param=ABAC.DataTerm("urn","'file://usr/party/~teaparty'")
92head.role_add_data_term(param)
93tail=ABAC.Role(party,"guestOf")
94param=ABAC.DataTerm(marchhareID)
95tail.role_add_data_term(param)
96attr=ABAC.Attribute(head, 1800)
97attr.attribute_add_tail(tail)
98attr.attribute_bake()
99attr.attribute_write_cert("party_about_party__guestof_marchhare_attr.der")
100ctxt.load_attribute_file("party_about_party__guestof_marchhare_attr.der")
101print attr.string() 
102print attr.typed_string()
103print "\n"
104
105###############################################
[f824a9e]106# NOTE: anonymous parameter
107#       Variable value for different parameter types
[669b481]108# [keyid:Party].role:about_other_party([keyid:tea],[?],
109#                         [integer:99],[time:?AAA],[integer:?BBB],
110#                         [boolean:true],[integer:?])
111#                 <- [keyid:MarchHare]
112head=ABAC.Role(party,"about_other_party")
113param=ABAC.DataTerm(teaID)
114head.role_add_data_term(param)
115param=ABAC.DataTerm("anonymous","_")
116head.role_add_data_term(param)
117param=ABAC.DataTerm("integer","99")
118head.role_add_data_term(param)
119param=ABAC.DataTerm("time","AAA")
120head.role_add_data_term(param)
121param=ABAC.DataTerm("integer","BBB")
122head.role_add_data_term(param)
123param=ABAC.DataTerm("boolean","true")
124head.role_add_data_term(param)
125param=ABAC.DataTerm("integer","?")
126head.role_add_data_term(param)
127tail=ABAC.Role(marchhare)
128attr=ABAC.Attribute(head, 1800)
129attr.attribute_add_tail(tail)
130attr.attribute_bake()
131attr.attribute_write_cert("party_about_other_party__marchhare_attr.der")
132ctxt.load_attribute_file("party_about_other_party__marchhare_attr.der")
133print attr.string()
134print attr.typed_string()
135print "\n"
136
137###############################################
138# [keyid:Party].role:about_string([string:'a confused party'])
139#                 <- [keyid:MarchHare]
140head=ABAC.Role(party,"about_string")
141param=ABAC.DataTerm("string","'a confused party'")
142head.role_add_data_term(param)
143tail=ABAC.Role(marchhare)
144attr=ABAC.Attribute(head, 1800)
145attr.attribute_add_tail(tail)
146attr.attribute_bake()
147attr.attribute_write_cert("party_about_string__marchhare_attr.der")
148ctxt.load_attribute_file("party_about_string__marchhare_attr.der")
149print attr.string()
150print attr.typed_string()
151print "\n"
152
153###############################################
[f824a9e]154# NOTE: how to escape within a string value
[669b481]155# [keyid:Party].role:about_string2([string:'a mangled \\'string\\''])
156#                 <- [keyid:MarchHare]
157head=ABAC.Role(party,"about_string2")
158param=ABAC.DataTerm("string","'a mangled \\'string\\''")
159head.role_add_data_term(param)
160tail=ABAC.Role(marchhare)
161attr=ABAC.Attribute(head, 1800)
162attr.attribute_add_tail(tail)
163attr.attribute_bake()
164attr.attribute_write_cert("party_about_string2__marchhare_attr.der")
165ctxt.load_attribute_file("party_about_string2__marchhare_attr.der")
166print attr.string()
167print attr.typed_string()
168print "\n"
169
170###############################################
171# [keyid:Party].role:about_urn([urn:'file://user/local/party/~sillyparty'])
172#                 <- [keyid:MarchHare]
173head=ABAC.Role(party,"about_urn")
174param=ABAC.DataTerm("urn","'file://user/local/party/~sillyparty'")
175head.role_add_data_term(param)
176tail=ABAC.Role(marchhare)
177attr=ABAC.Attribute(head, 1800)
178attr.attribute_add_tail(tail)
179attr.attribute_bake()
180attr.attribute_write_cert("party_about_urn__marchhare_attr.der")
181ctxt.load_attribute_file("party_about_urn__marchhare_attr.der")
182print attr.string()
183print attr.typed_string()
184print "\n"
185
186###############################################
187# [keyid:Party].role:about_another_float([float:0.22])
188#                 <- [keyid:MarchHare]
189head=ABAC.Role(party,"about_another_float")
190param=ABAC.DataTerm("float","0.22")
191head.role_add_data_term(param)
192tail=ABAC.Role(marchhare)
193attr=ABAC.Attribute(head, 1800)
194attr.attribute_add_tail(tail)
195attr.attribute_bake()
196attr.attribute_write_cert("party_about_third_float__marchhare_attr.der")
197ctxt.load_attribute_file("party_about_third_float__marchhare_attr.der")
198print attr.string()
199print attr.typed_string()
200print "\n"
201
202###############################################
203# [keyid:Party].role:about_another_float([float:8])
204#                 <- [keyid:MarchHare]
205head=ABAC.Role(party,"about_another_float")
206param=ABAC.DataTerm("float","8")
207head.role_add_data_term(param)
208tail=ABAC.Role(marchhare)
209attr=ABAC.Attribute(head, 1800)
210attr.attribute_add_tail(tail)
211attr.attribute_bake()
212attr.attribute_write_cert("party_about_another_float__marchhare_attr.der")
213ctxt.load_attribute_file("party_about_another_float__marchhare_attr.der")
214print attr.string()
215print attr.typed_string()
216print "\n"
217
218###############################################
219# [keyid:Party].role:about_float([float:-200.0])
220#                 <- [keyid:MarchHare]
221head=ABAC.Role(party,"about_float")
222param=ABAC.DataTerm("float","-200.0")
223head.role_add_data_term(param)
224tail=ABAC.Role(marchhare)
225attr=ABAC.Attribute(head, 1800)
226attr.attribute_add_tail(tail)
227attr.attribute_bake()
228attr.attribute_write_cert("party_about_float__marchhare_attr.der")
229ctxt.load_attribute_file("party_about_float__marchhare_attr.der")
230print attr.string()
231print attr.typed_string()
232print "\n"
233
234###############################################
235# [keyid:Party].role:about_another_integer([integer:-7])
236#                 <- [keyid:MarchHare]
237head=ABAC.Role(party,"about_another_integer")
238param=ABAC.DataTerm("integer","-7")
239head.role_add_data_term(param)
240tail=ABAC.Role(marchhare)
241attr=ABAC.Attribute(head, 1800)
242attr.attribute_add_tail(tail)
243attr.attribute_bake()
244attr.attribute_write_cert("party_about_another_integer__marchhare_attr.der")
245ctxt.load_attribute_file("party_about_another_integer__marchhare_attr.der")
246print attr.string()
247print attr.typed_string()
248print "\n"
249
250###############################################
251# [keyid:Party].role:about_integer([integer:4])
252#                 <- [keyid:MarchHare]
253head=ABAC.Role(party,"about_integer")
254param=ABAC.DataTerm("integer","4")
255head.role_add_data_term(param)
256tail=ABAC.Role(marchhare)
257attr=ABAC.Attribute(head, 1800)
258attr.attribute_add_tail(tail)
259attr.attribute_bake()
260attr.attribute_write_cert("party_about_integer__marchhare_attr.der")
261ctxt.load_attribute_file("party_about_integer__marchhare_attr.der")
262print attr.string()
263print attr.typed_string()
264print "\n"
265
266###############################################
267# [keyid:Party].role:about_boolean([boolean:true])
268#                 <- [keyid:MarchHare]
269head=ABAC.Role(party,"about_boolean")
270param=ABAC.DataTerm("boolean","true")
271head.role_add_data_term(param)
272tail=ABAC.Role(marchhare)
273attr=ABAC.Attribute(head, 1800)
274attr.attribute_add_tail(tail)
275attr.attribute_bake()
276attr.attribute_write_cert("party_about_boolean__marchhare_attr.der")
277ctxt.load_attribute_file("party_about_boolean__marchhare_attr.der")
278print attr.string()
279print attr.typed_string()
280print "\n"
281
282###############################################
283# [keyid:Party].role:about_key([keyid:tea])
284#                 <- [keyid:MarchHare]
285head=ABAC.Role(party,"about_key")
286param=ABAC.DataTerm(teaID)
287head.role_add_data_term(param)
288tail=ABAC.Role(marchhare)
289attr=ABAC.Attribute(head, 1800)
290attr.attribute_add_tail(tail)
291attr.attribute_bake()
292attr.attribute_write_cert("party_about_key__marchhare_attr.der")
293ctxt.load_attribute_file("party_about_key__marchhare_attr.der")
294print attr.string()
295print attr.typed_string()
296print "\n"
297
298###############################################
299# [keyid:Party].role:about_another_time([time:20201101T182930])
300#                 <- [keyid:MarchHare]
301head=ABAC.Role(party,"about_another_time")
302param=ABAC.DataTerm("time","20201101T182930")
303head.role_add_data_term(param)
304tail=ABAC.Role(marchhare)
305attr=ABAC.Attribute(head, 1800)
306attr.attribute_add_tail(tail)
307attr.attribute_bake()
308attr.attribute_write_cert("party_about_another_time__marchhare_attr.der")
309ctxt.load_attribute_file("party_about_another_time__marchhare_attr.der")
310print attr.string()
311print attr.typed_string()
312print "\n"
313
314###############################################
315# [keyid:Party].role:about_time([time:20201101T])
316#                 <- [keyid:MarchHare]
317head=ABAC.Role(party,"about_time")
318param=ABAC.DataTerm("time","20201101T")
319head.role_add_data_term(param)
320tail=ABAC.Role(marchhare)
321attr=ABAC.Attribute(head, 1800)
322attr.attribute_add_tail(tail)
323attr.attribute_bake()
324attr.attribute_write_cert("party_about_time__marchhare_attr.der")
325ctxt.load_attribute_file("party_about_time__marchhare_attr.der")
326print attr.string()
327print attr.typed_string()
328print "\n"
329
330###############################################
[f824a9e]331# NOTE: principal parameter type
[669b481]332# [keyid:Party].role:guestof([principal:?V])
333#           <- [keyid:Party].role:friendOf([principal:?V])
334#
335head=ABAC.Role(party,"guestOf")
336param=ABAC.DataTerm("principal","V")
337head.role_add_data_term(param)
338tail=ABAC.Role(party,"friendOf")
339param=ABAC.DataTerm("principal","V")
340tail.role_add_data_term(param)
341attr=ABAC.Attribute(head, 1800)
342attr.attribute_add_tail(tail)
343attr.attribute_bake()
344attr.attribute_write_cert("party_guestof_qV__party_friendof_qV_attr.der")
345ctxt.load_attribute_file("party_guestof_qV__party_friendof_qV_attr.der")
346print attr.string()
347print attr.typed_string()
348print "\n"
349
350###############################################
351# [keyid:Party].role:guests
352#        <- [keyid:Party].role:friendOf([keyid:MarchHare])
353#
354head=ABAC.Role(party,"guests")
355tail=ABAC.Role(party,"friendOf")
356param=ABAC.DataTerm(marchhareID)
357tail.role_add_data_term(param)
358attr=ABAC.Attribute(head, 1800)
359attr.attribute_add_tail(tail)
360attr.attribute_bake()
361attr.attribute_write_cert("party_guests__party_friendof_marchhare_attr.der")
362ctxt.load_attribute_file("party_guests__party_friendof_marchhare_attr.der")
363print attr.string()
364print attr.typed_string()
365print "\n"
366
367###############################################
368# [keyid:Party].role:friendOf([keyid:MarchHare])
369#                               <- [keyid:Dormouse]
370#
371head=ABAC.Role(party,"friendOf")
372param=ABAC.DataTerm(marchhareID)
373head.role_add_data_term(param)
374tail=ABAC.Role(dormouse)
375attr=ABAC.Attribute(head, 1800)
376attr.attribute_add_tail(tail)
377attr.attribute_bake()
378attr.attribute_write_cert("party_friendof_marchhare__dormouse_attr.der")
379ctxt.load_attribute_file("party_friendof_marchhare__dormouse_attr.der")
380print attr.string()
381print attr.typed_string()
382print "\n"
383
384###############################################
[f824a9e]385# NOTE: named principal tail
[669b481]386# [keyid:Party].role:friendOf([keyid:Alice])
387#                               <- [keyid:Hatter]
388#
389head=ABAC.Role(party,"friendOf")
390param=ABAC.DataTerm(aliceID)
391head.role_add_data_term(param)
392tail=ABAC.Role(hatter)
393attr=ABAC.Attribute(head, 1800)
394attr.attribute_add_tail(tail)
395attr.attribute_bake()
396attr.attribute_write_cert("party_friendof_alice__hatter_attr.der")
397ctxt.load_attribute_file("party_friendof_alice__hatter_attr.der")
398print attr.string()
399print attr.typed_string()
400print "\n"
401
Note: See TracBrowser for help on using the repository browser.