source: examples/scaling_tests/haystack/fruit_python/base/ATTR.py @ f30b1e9

abac0-leakabac0-meimei-idmei-rt0-nmei_rt0tvf-new-xml
Last change on this file since f30b1e9 was 7e3f5e2, checked in by Mei <mei@…>, 12 years ago

1) converted daisychain scaling tests

  • 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
25# retrieve principals' keyid value from local credential files
26ralphsID=ABAC.ID("Ralphs_ID.pem");
27ralphsID.id_load_privkey_file("Ralphs_private.pem");
28ralphs=ralphsID.id_keyid()
29
30bobID=ABAC.ID("Bob_ID.pem");
31bobID.id_load_privkey_file("Bob_private.pem");
32bob=bobID.id_keyid()
33
34maryID=ABAC.ID("Mary_ID.pem");
35maryID.id_load_privkey_file("Mary_private.pem");
36mary=maryID.id_keyid()
37
38################################################
39# Credential 1, what kind of fruit Mary would eat. Anything not costing more
40#               than 2 dollars
41# [keyid:mary].oset:what2eat
42#      <- [keyid:ralphs].oset:fruitprice([float:?P:[..2.00]])
43head = ABAC.Oset(mary,"what2eat")
44
45# initialize a float range constraint
46cond=ABAC.Constraint("float")
47
48# add the upper max to the range, and only the max
49cond.constraint_add_float_max(2.00)
50
51# create the data term with the constraint
52param=ABAC.DataTerm("float", "P", cond)
53tail = ABAC.Oset(ralphs,"fruitprice")
54tail.oset_add_data_term(param)
55
56# compose the attribute policy
57attr=ABAC.Attribute(head, 1800)
58attr.attribute_add_tail(tail)
59
60#finalize the policy
61attr.attribute_bake()
62
63#write out the policy to a credential file
64attr.attribute_write_cert("mary_what2eat__ralphs_fruitprice_qP_attr.der")
65
66
67################################################
68# Credential 2,
69# [keyid:bob].oset:what2eat
70#      <- [keyid:ralphs].oset:fruitprice([float:?P:[1.00..5.00]])
71head = ABAC.Oset(bob,"what2eat")
72
73# initialze a float range constraint
74cond=ABAC.Constraint("float")
75
76# add the min and max value to the range
77cond.constraint_add_float_min(1.00)
78cond.constraint_add_float_max(5.00)
79param=ABAC.DataTerm("float", "P", cond)
80tail = ABAC.Oset(ralphs,"fruitprice")
81tail.oset_add_data_term(param)
82
83#create attribute policy
84attr=ABAC.Attribute(head, 1800)
85attr.attribute_add_tail(tail)
86
87#finalize the policy
88attr.attribute_bake()
89attr.attribute_write_cert("bob_what2eat__ralphs_fruitprice_qP_attr.der")
90
91#################################################
92# Credential 3
93# [keyid:ralphs].oset:fruitprice([float:1.50]) <- [string:'apple']
94param=ABAC.DataTerm("float", "1.50")
95head = ABAC.Oset(ralphs,"fruitprice")
96head.oset_add_data_term(param)
97param=ABAC.DataTerm("string", "'apple'")
98tail = ABAC.Oset(param)
99attr=ABAC.Attribute(head, 1800)
100attr.attribute_add_tail(tail)
101attr.attribute_bake()
102attr.attribute_write_cert("Ralphs_fruitprice__apple_attr.der")
103
104#################################################
105# Credential 4
106# [keyid:ralphs].oset:fruitprice([float:1.50]) <- [string:'kiwi']
107param=ABAC.DataTerm("float", "1.50")
108head = ABAC.Oset(ralphs,"fruitprice")
109head.oset_add_data_term(param)
110param=ABAC.DataTerm("string", "'kiwi'")
111tail = ABAC.Oset(param)
112attr=ABAC.Attribute(head, 1800)
113attr.attribute_add_tail(tail)
114attr.attribute_bake()
115attr.attribute_write_cert("Ralphs_fruitprice__kiwi_attr.der")
116
117#################################################
118# Credential 5
119# [keyid:ralphs].oset:fruitprice([float:2.50]) <- [string:'black berry']
120param=ABAC.DataTerm("float", "2.50")
121head = ABAC.Oset(ralphs,"fruitprice")
122head.oset_add_data_term(param)
123param=ABAC.DataTerm("string", "'black berry'")
124tail = ABAC.Oset(param)
125attr=ABAC.Attribute(head, 1800)
126attr.attribute_add_tail(tail)
127attr.attribute_bake()
128attr.attribute_write_cert("Ralphs_fruitprice__blackberry_attr.der")
129
130#################################################
131# Credential 6
132# [keyid:ralphs].oset:fruitprice([float:0.50]) <- [string:'navel orange']
133param=ABAC.DataTerm("float", "0.50")
134head = ABAC.Oset(ralphs,"fruitprice")
135head.oset_add_data_term(param)
136param=ABAC.DataTerm("string", "'navel orange'")
137tail = ABAC.Oset(param)
138attr=ABAC.Attribute(head, 1800)
139attr.attribute_add_tail(tail)
140attr.attribute_bake()
141attr.attribute_write_cert("Ralphs_fruitprice__navelorange_attr.der")
142
143
144########### NOISE #######################################
145# [keyid:Ralphs].oset:fruitprice([float:X.00])  <- [string:bananaY]
146i=1
147while i <= #VAL#:
148    p="%s.00"%i
149    n="'banana%s'"%i
150    nn="banana%s"%i
151    f="Ralphs_fruitprice__%s_attr.der"%nn
152    param=ABAC.DataTerm("float", p)
153    head = ABAC.Oset(ralphs,"fruitprice")
154    head.oset_add_data_term(param)
155    param=ABAC.DataTerm("string", n)
156    tail = ABAC.Oset(param)
157    attr=ABAC.Attribute(head, 1800)
158    attr.attribute_add_tail(tail)
159    attr.attribute_bake()
160    attr.attribute_write_cert(f)
161    i=i+1
162
163# [keyid:johnX].oset:what2eat
164#        <- [keyid:ralphs].oset:fruitprice([float:?P:[1.00..5.00]])
165i=1
166while i <= #VAL#:
167    j="john%s"%i
168    jid="%s_ID.pem"%j
169    jp="%s_private.pem"%j
170    f="%s_what2eat__ralphs_fruitprice_qP_attr.der"%j
171
172    jID=ABAC.ID(jid);
173    jID.id_load_privkey_file(jp);
174    john=jID.id_keyid()
175
176    head = ABAC.Oset(john,"what2eat")
177    cond=ABAC.Constraint("float")
178    cond.constraint_add_float_min(1.00)
179    cond.constraint_add_float_max(5.00)
180    param=ABAC.DataTerm("float", "P", cond)
181    tail = ABAC.Oset(ralphs,"fruitprice")
182    tail.oset_add_data_term(param)
183
184    attr=ABAC.Attribute(head, 1800)
185    attr.attribute_add_tail(tail)
186    attr.attribute_bake()
187    attr.attribute_write_cert(f)
188    i=i+1
189
190
Note: See TracBrowser for help on using the repository browser.