source: examples/python_tests/access_rt2/attr.py @ 669b481

mei_rt2mei_rt2_fix_1
Last change on this file since 669b481 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.9 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
31joeID=ABAC.ID("Joe", 0)
32ctxt.load_id(joeID)
33#joeID.id_write_privkey("Joe_IDKEY.pem")
34#joeID.id_write_cert("Joe_IDKEY.pem")
35joeID.id_write_privkey("Joe_private.pem")
36joeID.id_write_cert("Joe_ID.pem")
37joe=joeID.id_keyid()
38
39alphaID=ABAC.ID("Alpha_ID.pem")
40alphaID.id_load_privkey_file("Alpha_private.pem");
41alpha=alphaID.id_keyid()
42
43bobID=ABAC.ID("Bob_ID.pem")
44bobID.id_load_privkey_file("Bob_private.pem");
45bob=bobID.id_keyid()
46
47################################################
48# [keyid:alpha].role:access([string:'Read'],[urn:'file//fileB']) <- [keyid:bob]
49param1=ABAC.DataTerm("string", "'Read'")
50param2=ABAC.DataTerm("urn","'file//fileB'")
51head = ABAC.Role(alpha,"access")
52head.role_add_data_term(param1)
53head.role_add_data_term(param2)
54tail = ABAC.Role(bob)
55attr=ABAC.Attribute(head, 1800)
56attr.attribute_add_tail(tail)
57attr.attribute_bake()
58attr.attribute_write_cert("Alpha_access_fileB__Bob_attr.der")
59ctxt.load_attribute_file("Alpha_access_fileB__Bob_attr.der")
60print attr.string() 
61print attr.typed_string()
62print "\n"
63
64#################################################
65## [keyid:alpha].role:team([string:'proj1'])<-[keyid:bob]
66param1=ABAC.DataTerm("string", "'proj1'")
67head = ABAC.Role(alpha,"team")
68head.role_add_data_term(param1)
69tail = ABAC.Role(bob)
70attr=ABAC.Attribute(head, 1800)
71attr.attribute_add_tail(tail)
72attr.attribute_bake()
73attr.attribute_write_cert("Alpha_team_proj1__Bob_attr.der")
74ctxt.load_attribute_file("Alpha_team_proj1__Bob_attr.der")
75print attr.string() 
76print attr.typed_string()
77print "\n"
78
79#################################################
80## [keyid:alpha].role:team([string:'proj2'])<-[keyid:Joe]
81param1=ABAC.DataTerm("string", "'proj2'")
82head = ABAC.Role(alpha,"team")
83head.role_add_data_term(param1)
84tail = ABAC.Role(joe)
85attr=ABAC.Attribute(head, 1800)
86attr.attribute_add_tail(tail)
87attr.attribute_bake()
88attr.attribute_write_cert("Alpha_team_proj2__Joe_attr.der")
89ctxt.load_attribute_file("Alpha_team_proj2__Joe_attr.der")
90print attr.string() 
91print attr.typed_string()
92print "\n"
93
94################################################
95# [keyid:alpha].role:access([string:'Read',
96#                [urn:?F[keyid:alpha].oset:documents([string:?P])])
97#                                 <- [keyid:alpha].role:team([string:?P])
98param=ABAC.DataTerm("string", "P")
99oset=ABAC.Oset(alpha,"documents")
100oset.oset_add_data_term(param)
101cond=ABAC.Constraint(oset)
102param2=ABAC.DataTerm("urn", "F", cond)
103param1=ABAC.DataTerm("string", "'Read'")
104head = ABAC.Role(alpha,"access")
105head.role_add_data_term(param1)
106head.role_add_data_term(param2)
107param3=ABAC.DataTerm("string", "P")
108tail = ABAC.Role(alpha,"team")
109tail.role_add_data_term(param3)
110attr=ABAC.Attribute(head, 1800)
111attr.attribute_add_tail(tail)
112attr.attribute_bake()
113attr.attribute_write_cert("Alpha_access_qFqP__alpha_team_qP_attr.der")
114ctxt.load_attribute(attr)
115#print attr.string()
116#print attr.typed_string()
117#print "\n"
118
119
120#################################################
121## [keyid:alpha].oset:documents([string:'proj1'])<-[urn:'file//fileA']
122param1=ABAC.DataTerm("string", "'proj1'")
123head = ABAC.Oset(alpha,"documents")
124head.oset_add_data_term(param1)
125obj = ABAC.DataTerm("urn", "'file//fileA'")
126tail= ABAC.Oset(obj)
127attr=ABAC.Attribute(head, 1800)
128attr.attribute_add_tail(tail)
129attr.attribute_bake()
130attr.attribute_write_cert("Alpha_team_proj1__fileA_attr.der")
131ctxt.load_attribute(attr)
132print attr.string() 
133print attr.typed_string()
134print "\n"
135
136ctxt.dump_yap_db()
137##
Note: See TracBrowser for help on using the repository browser.