source: examples/python_tests/leader_rt1/attr.py @ 7211a95

mei_rt2mei_rt2_fix_1
Last change on this file since 7211a95 was 7211a95, checked in by Mei <mei@…>, 12 years ago

1) add more python examples
2) add the missing linking role and linking oset api calls
3) fix the output of time typed data term/oset obj in typed_string format

(transform back from yap time format to our ddddddddTdddddd format

  • Property mode set to 100755
File size: 4.2 KB
Line 
1#!/usr/bin/env python
2
3"""
4  to test with python
5
6cmd1:env keystore=`pwd` ./attr.py
7"""
8
9import os
10import ABAC
11
12keystore=os.environ["keystore"]
13
14ctxt = ABAC.Context()
15print "ABAC version %s" % ctxt.version()
16
17ctxt.load_directory(keystore)
18
19out = ctxt.context_principals()
20print "...initial principal set..."
21for x in out[1]:
22    print "%s " % x.string()
23print "\n" 
24
25out = ctxt.context_credentials()
26print "...initial policy attribute set..."
27for c in out[1]:
28    print "%s <- %s" % (c.head_string(), c.tail_string())
29print "\n"
30
31geniID=ABAC.ID("Geni_ID.pem");
32geniID.id_load_privkey_file("Geni_private.pem");
33geni=geniID.id_keyid()
34
35bobID=ABAC.ID("Bob_ID.pem");
36bobID.id_load_privkey_file("Bob_private.pem");
37bob=bobID.id_keyid()
38
39jackID=ABAC.ID("Jack_ID.pem");
40jackID.id_load_privkey_file("Jack_private.pem");
41jack=jackID.id_keyid()
42
43joeID=ABAC.ID("Joe_ID.pem");
44joeID.id_load_privkey_file("Joe_private.pem");
45joe=joeID.id_keyid()
46
47################################################
48# [keyid:geni].role:leader
49#         <- [keyid:geni].role:equivalent([principal:?P[keyid:geni].role:leader])
50head=ABAC.Role(geni,"leader")
51condoset=ABAC.Role(geni,"leader")
52cond=ABAC.Constraint(condoset)
53param=ABAC.DataTerm("principal","P", cond)
54tail = ABAC.Role(geni,"equivalent")
55tail.role_add_data_term(param)
56attr=ABAC.Attribute(head, 1800)
57attr.attribute_add_tail(tail)
58attr.attribute_bake()
59attr.attribute_write_cert("geni_leader__geni_leader_qP_attr.der")
60ctxt.load_attribute_file("geni_leader__geni_leader_qP_attr.der")
61print attr.string() 
62print attr.typed_string()
63print "\n"
64
65#################################################
66# [keyid:geni].role:leader <- [keyid:bob]
67head=ABAC.Role(geni,"leader")
68tail = ABAC.Role(bob)
69attr=ABAC.Attribute(head, 1800)
70attr.attribute_add_tail(tail)
71attr.attribute_bake()
72attr.attribute_write_cert("geni_leader__Bob_attr.der")
73ctxt.load_attribute_file("geni_leader__Bob_attr.der")
74print attr.string() 
75print attr.typed_string()
76print "\n"
77
78#################################################
79# [keyid:geni].role:equivalent([keyid:bob]) <- [keyid:Joe]
80param=ABAC.DataTerm(bobID)
81head = ABAC.Role(geni,"equivalent")
82head.role_add_data_term(param)
83tail = ABAC.Role(joe)
84attr=ABAC.Attribute(head, 1800)
85attr.attribute_add_tail(tail)
86attr.attribute_bake()
87attr.attribute_write_cert("geni_equivalent_Bob__Joe_attr.der")
88ctxt.load_attribute_file("geni_equivalent_Bob__Joe_attr.der")
89print attr.string() 
90print attr.typed_string()
91print "\n"
92
93#################################################
94# [keyid:geni].role:equivalent([keyid:Joe]) <- [keyid:Bob]
95param=ABAC.DataTerm(joeID)
96head = ABAC.Role(geni,"equivalent")
97head.role_add_data_term(param)
98tail = ABAC.Role(bob)
99attr=ABAC.Attribute(head, 1800)
100attr.attribute_add_tail(tail)
101attr.attribute_bake()
102attr.attribute_write_cert("geni_equivalent_Joe__Bob_attr.der")
103ctxt.load_attribute_file("geni_equivalent_Joe__Bob_attr.der")
104print attr.string() 
105print attr.typed_string()
106print "\n"
107
108#################################################
109# [keyid:Bob].role:niceCoworker <- [keyid:Maryann])
110head = ABAC.Role(bob,"niceCoworker")
111tail = ABAC.Role(jack)
112attr=ABAC.Attribute(head, 1800)
113attr.attribute_add_tail(tail)
114attr.attribute_bake()
115attr.attribute_write_cert("Bob_nicecoworker__Maryann_attr.der")
116ctxt.load_attribute_file("Bob_nicecoworker__Maryann_attr.der")
117print attr.string() 
118print attr.typed_string()
119print "\n"
120
121#################################################
122# [keyid:geni].role:evaluatorOf([keyid:Joe]) <-[keyid:Bob]
123param=ABAC.DataTerm(joeID)
124head = ABAC.Role(geni,"evaluatorOf")
125head.role_add_data_term(param)
126tail = ABAC.Role(bob)
127attr=ABAC.Attribute(head, 1800)
128attr.attribute_add_tail(tail)
129attr.attribute_bake()
130attr.attribute_write_cert("Alpha_evaluator_j__Bob_attr.der")
131ctxt.load_attribute_file("Alpha_evaluator_j__Bob_attr.der")
132print attr.string() 
133print attr.typed_string()
134print "\n"
135
136#################################################
137# [keyid:Bob].role:goodPerformance <- [keyid:Joe])
138head = ABAC.Role(bob,"goodPerformance")
139tail = ABAC.Role(joe)
140attr=ABAC.Attribute(head, 1800)
141attr.attribute_add_tail(tail)
142attr.attribute_bake()
143attr.attribute_write_cert("Bob_goodperformance__Joe_attr.der")
144ctxt.load_attribute_file("Bob_goodperformance__Joe_attr.der")
145print attr.string() 
146print attr.typed_string()
147print "\n"
148
149
150ctxt.dump_yap_db()
151##
Note: See TracBrowser for help on using the repository browser.