source: examples/python_tests/alumni2_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: 4.4 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
38stateUID=ABAC.ID("StateU_ID.pem")
39stateUID.id_load_privkey_file("StateU_private.pem")
40stateU=stateUID.id_keyid()
41
42bobID=ABAC.ID("Bob_ID.pem")
43bobID.id_load_privkey_file("Bob_private.pem")
44bob=bobID.id_keyid()
45
46joeID=ABAC.ID("Joe_ID.pem")
47joeID.id_load_privkey_file("Joe_private.pem")
48joe=joeID.id_keyid()
49
50maryannID=ABAC.ID("Maryann_ID.pem")
51maryannID.id_load_privkey_file("Maryann_private.pem")
52maryann=maryannID.id_keyid()
53
54
55################################################
56# Credential 1, Any alumni of stateU is a member of foundingAlumni if
57# they have diploma from those specific years
58# [keyid:stateU].role:foundingAlumni
59#       <- [keyid:stateU].role:diploma([?], [integer:?Year:[1960,1961,1963]])
60head = ABAC.Role(stateU,"foundingAlumni")
61
62# constructing an anonymous parameter
63param1=ABAC.DataTerm("anonymous", "_")
64
65# initialize a integer range constraint
66cond=ABAC.Constraint("integer")
67
68# add specific target value for the integer range constraint
69cond.constraint_add_integer_target(1963)
70cond.constraint_add_integer_target(1961)
71cond.constraint_add_integer_target(1960)
72
73# create a paramter term that has a range constraint on it,
74# the variable name supplied has to start with a capitalized alphabet character
75param2=ABAC.DataTerm("integer", "Year", cond)
76tail = ABAC.Role(stateU,"diploma")
77tail.role_add_data_term(param1)
78tail.role_add_data_term(param2)
79attr=ABAC.Attribute(head, 1800)
80
81# construct the attribute
82attr.attribute_add_tail(tail)
83
84# finalize the attribute
85attr.attribute_bake()
86attr.attribute_write_cert("StateU_foundingAlumni__stateU_diploma_q_qY_attr.der")
87ctxt.load_attribute_file("StateU_foundingAlumni__stateU_diploma_q_qY_attr.der")
88print attr.string() 
89print attr.typed_string()
90print "\n"
91
92#################################################
93# Credential 2
94# [keyid:stateU].role:diploma([string:'mathmatics'],[integer:1961]) <- [keyid:bob]
95param1=ABAC.DataTerm("string", "'mathmatics'")
96param2=ABAC.DataTerm("integer", "1961")
97head = ABAC.Role(stateU,"diploma")
98head.role_add_data_term(param1)
99head.role_add_data_term(param2)
100tail = ABAC.Role(bob)
101attr=ABAC.Attribute(head, 1800)
102attr.attribute_add_tail(tail)
103attr.attribute_bake()
104attr.attribute_write_cert("StateU_diploma_m__Bob_attr.der")
105ctxt.load_attribute_file("StateU_diploma_m__Bob_attr.der")
106print attr.string() 
107print attr.typed_string()
108print "\n"
109
110#################################################
111# Credential 3
112# [keyid:stateU].role:diploma([string:'zoology'],[integer:1955]) <- [keyid:joe]
113param1=ABAC.DataTerm("string", "'zoology'")
114param2=ABAC.DataTerm("integer", "1955")
115head = ABAC.Role(stateU,"diploma")
116head.role_add_data_term(param1)
117head.role_add_data_term(param2)
118tail = ABAC.Role(joe)
119attr=ABAC.Attribute(head, 1800)
120attr.attribute_add_tail(tail)
121attr.attribute_bake()
122attr.attribute_write_cert("StateU_diploma_z__Joe_attr.der")
123ctxt.load_attribute_file("StateU_diploma_z__Joe_attr.der")
124print attr.string() 
125print attr.typed_string()
126print "\n"
127
128#################################################
129# Credential 4
130# [keyid:stateU].role:diploma([string:'psychology'],[integer:1962]) <- [keyid:maryann]
131param1=ABAC.DataTerm("string", "'psychology'")
132param2=ABAC.DataTerm("integer", "1962")
133head = ABAC.Role(stateU,"diploma")
134head.role_add_data_term(param1)
135head.role_add_data_term(param2)
136tail = ABAC.Role(maryann)
137attr=ABAC.Attribute(head, 1800)
138attr.attribute_add_tail(tail)
139attr.attribute_bake()
140attr.attribute_write_cert("StateU_diploma_p__Maryann_attr.der")
141ctxt.load_attribute_file("StateU_diploma_p__Maryann_attr.der")
142print attr.string() 
143print attr.typed_string()
144print "\n"
145
Note: See TracBrowser for help on using the repository browser.