source: examples/python_tests/alumni_rt1/attr.py @ 47d5cf9

mei_rt2mei_rt2_fix_1
Last change on this file since 47d5cf9 was 669b481, checked in by Mei <mei@…>, 12 years ago

1) finish test conversion from creddy-prover to python
2) update the abac.hh/API doc more, adding more intermediate calls

to make abac.hh more uniform

3) found out why a very long attribute rule can not survive in/out of

ietf_attribute_t call (m64 en/decoding - abac_verifier, alice_rt1)

  • Property mode set to 100755
File size: 3.5 KB
Line 
1#!/usr/bin/env python
2
3"""
4  Setup access policy attribute rules
5
6cmd1:env keystore=`pwd` ./attr.py
7
8"""
9
10import os
11import ABAC
12
13keystore=os.environ["keystore"]
14
15ctxt = ABAC.Context()
16print "ABAC version %s" % ctxt.version()
17
18ctxt.load_directory(keystore)
19
20out = ctxt.context_principals()
21print "...initial principal set..."
22for x in out[1]:
23    print "%s " % x.string()
24print "\n" 
25
26out = ctxt.context_credentials()
27print "...initial policy attribute set..."
28for c in out[1]:
29    print "%s <- %s" % (c.head_string(), c.tail_string())
30print "\n"
31
32stateUID=ABAC.ID("StateU_ID.pem")
33stateUID.id_load_privkey_file("StateU_private.pem")
34stateU=stateUID.id_keyid()
35
36bobID=ABAC.ID("Bob_ID.pem")
37bobID.id_load_privkey_file("Bob_private.pem")
38bob=bobID.id_keyid()
39
40joeID=ABAC.ID("Joe_ID.pem")
41joeID.id_load_privkey_file("Joe_private.pem")
42joe=joeID.id_keyid()
43
44maryannID=ABAC.ID("Maryann_ID.pem")
45maryannID.id_load_privkey_file("Maryann_private.pem")
46maryann=maryannID.id_keyid()
47
48
49################################################
50# [keyid:stateU].role:foundingAlumni
51#                   <- [keyid:stateU].role:diploma([?], [integer:?Year:[1955 .. 1958]])
52head = ABAC.Role(stateU,"foundingAlumni")
53param1=ABAC.DataTerm("anonymous", "_")
54cond=ABAC.Constraint("integer")
55cond.constraint_add_integer_min(1955)
56cond.constraint_add_integer_max(1958)
57param2=ABAC.DataTerm("integer", "Year", cond)
58tail = ABAC.Role(stateU,"diploma")
59tail.role_add_data_term(param1)
60tail.role_add_data_term(param2)
61attr=ABAC.Attribute(head, 1800)
62attr.attribute_add_tail(tail)
63attr.attribute_bake()
64attr.attribute_write_cert("StateU_foundingAlumni__stateU_diploma_q_qY_attr.der")
65ctxt.load_attribute_file("StateU_foundingAlumni__stateU_diploma_q_qY_attr.der")
66print attr.string() 
67print attr.typed_string()
68print "\n"
69
70#################################################
71# [keyid:stateU].role:diploma([string:'mathmatics'],[integer:1960]) <- [keyid:bob]
72param1=ABAC.DataTerm("string", "'mathmatics'")
73param2=ABAC.DataTerm("integer", "1960")
74head = ABAC.Role(stateU,"diploma")
75head.role_add_data_term(param1)
76head.role_add_data_term(param2)
77tail = ABAC.Role(bob)
78attr=ABAC.Attribute(head, 1800)
79attr.attribute_add_tail(tail)
80attr.attribute_bake()
81attr.attribute_write_cert("StateU_diploma_m__Bob_attr.der")
82ctxt.load_attribute_file("StateU_diploma_m__Bob_attr.der")
83print attr.string() 
84print attr.typed_string()
85print "\n"
86
87#################################################
88# [keyid:stateU].role:diploma([string:'zoology'],[integer:1955]) <- [keyid:joe]
89param1=ABAC.DataTerm("string", "'zoology'")
90param2=ABAC.DataTerm("integer", "1955")
91head = ABAC.Role(stateU,"diploma")
92head.role_add_data_term(param1)
93head.role_add_data_term(param2)
94tail = ABAC.Role(joe)
95attr=ABAC.Attribute(head, 1800)
96attr.attribute_add_tail(tail)
97attr.attribute_bake()
98attr.attribute_write_cert("StateU_diploma_z__Joe_attr.der")
99ctxt.load_attribute_file("StateU_diploma_z__Joe_attr.der")
100print attr.string() 
101print attr.typed_string()
102print "\n"
103
104#################################################
105# [keyid:stateU].role:diploma([string:'psychology'],[integer:1956]) <- [keyid:maryann]
106param1=ABAC.DataTerm("string", "'psychology'")
107param2=ABAC.DataTerm("integer", "1956")
108head = ABAC.Role(stateU,"diploma")
109head.role_add_data_term(param1)
110head.role_add_data_term(param2)
111tail = ABAC.Role(maryann)
112attr=ABAC.Attribute(head, 1800)
113attr.attribute_add_tail(tail)
114attr.attribute_bake()
115attr.attribute_write_cert("StateU_diploma_p__Maryann_attr.der")
116ctxt.load_attribute_file("StateU_diploma_p__Maryann_attr.der")
117print attr.string() 
118print attr.typed_string()
119print "\n"
120
121ctxt.dump_yap_db()
122##
Note: See TracBrowser for help on using the repository browser.