source: examples/python_tests/evaluator_rt1/attr.py @ 5f551d3

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

1) add more python examples

  • Property mode set to 100755
File size: 4.0 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
31isiID=ABAC.ID("ISI_ID.pem")
32isiID.id_load_privkey_file("ISI_private.pem");
33isi=isiID.id_keyid()
34
35uscID=ABAC.ID("USC_ID.pem")
36uscID.id_load_privkey_file("USC_private.pem");
37usc=uscID.id_keyid()
38
39maryannID=ABAC.ID("Maryann_ID.pem")
40maryannID.id_load_privkey_file("Maryann_private.pem");
41maryann=maryannID.id_keyid()
42
43johnID=ABAC.ID("John_ID.pem")
44johnID.id_load_privkey_file("John_private.pem");
45john=johnID.id_keyid()
46
47################################################
48#[keyid:USC].role:evaluatorOf([principal:?K])
49#           <-[keyid:USC].role:managerOf([principal:?K])
50param=ABAC.DataTerm("principal", "K")
51head = ABAC.Role(usc,"evaluatorOf")
52head.role_add_data_term(param)
53param=ABAC.DataTerm("principal","K")
54tail = ABAC.Role(usc,"managerOf")
55tail.role_add_data_term(param)
56attr=ABAC.Attribute(head, 1800)
57attr.attribute_add_tail(tail)
58attr.attribute_bake()
59attr.attribute_write_cert("USC_evaluatorof_qK__USC_managerof_qK_attr.der")
60ctxt.load_attribute_file("USC_evaluatorof_qK__USC_managerof_qK_attr.der")
61print attr.string() 
62print attr.typed_string()
63print "\n"
64
65#################################################
66# [keyid:USC].role:managerOf([principal:?K])
67#            <-[keyid:ISI].role:managerOf([principal:?K])
68#
69param=ABAC.DataTerm("principal", "K")
70head = ABAC.Role(usc,"managerOf")
71head.role_add_data_term(param)
72param=ABAC.DataTerm("principal", "K")
73tail = ABAC.Role(isi,"managerOf")
74tail.role_add_data_term(param)
75attr=ABAC.Attribute(head, 1800)
76attr.attribute_add_tail(tail)
77attr.attribute_bake()
78attr.attribute_write_cert("USC_managerof_qK__USC_employee_attr.der")
79ctxt.load_attribute_file("USC_managerof_qK__USC_employee_attr.der")
80print attr.string() 
81print attr.typed_string()
82print "\n"
83
84#################################################
85# [keyid:ISI].role:managerOf([keyid:Maryann])
86#                        <- [keyid:John]
87param=ABAC.DataTerm(maryannID)
88head = ABAC.Role(isi,"managerOf")
89head.role_add_data_term(param)
90tail = ABAC.Role(john)
91attr=ABAC.Attribute(head, 1800)
92attr.attribute_add_tail(tail)
93attr.attribute_bake()
94attr.attribute_write_cert("ISI_manageof_Maryann__John_attr.der")
95ctxt.load_attribute_file("ISI_manageof_Maryann__John_attr.der")
96print attr.string() 
97print attr.typed_string()
98print "\n"
99
100################################################
101# [keyid:USC].role:employee <- [keyid:ISI].role:employee
102head=ABAC.Role(usc,"employee")
103tail = ABAC.Role(isi,"employee")
104attr=ABAC.Attribute(head, 1800)
105attr.attribute_add_tail(tail)
106attr.attribute_bake()
107attr.attribute_write_cert("USC_employee__ISI_employee_attr.der")
108#ctxt.load_attribute_file("USC_employee__ISI_employee_attr.der")
109ctxt.load_attribute(attr)
110#print attr.string()
111#print attr.typed_string()
112#print "\n"
113
114
115#################################################
116# [keyid:ISI].role:employee  <- [keyid:Maryann]
117head = ABAC.Role(isi,"employee")
118tail= ABAC.Role(maryann)
119attr=ABAC.Attribute(head, 1800)
120attr.attribute_add_tail(tail)
121attr.attribute_bake()
122attr.attribute_write_cert("ISI_employee__Maryann_attr.der")
123#ctxt.load_attribute_file("ISI_employee__Maryann_attr.der")
124ctxt.load_attribute(attr)
125print attr.string() 
126print attr.typed_string()
127print "\n"
128
129#################################################
130# [keyid:ISI].role:employee  <- [keyid:John]
131head = ABAC.Role(isi,"employee")
132tail= ABAC.Role(john)
133attr=ABAC.Attribute(head, 1800)
134attr.attribute_add_tail(tail)
135attr.attribute_bake()
136attr.attribute_write_cert("ISI_employee__John_attr.der")
137#ctxt.load_attribute_file("ISI_employee__John_attr.der")
138ctxt.load_attribute(attr)
139print attr.string() 
140print attr.typed_string()
141print "\n"
142
143ctxt.dump_yap_db()
144##
Note: See TracBrowser for help on using the repository browser.