source: examples/python_tests/evaluator_rt1/attr.py @ 4b46680

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

1) add more doc to python_tests

  • Property mode set to 100755
File size: 4.4 KB
RevLine 
[5f551d3]1#!/usr/bin/env python
2
3"""
[f824a9e]4See README in this directory for the semantics of the example.  This file
5constructs the credentials described and puts copies into this directory
[5f551d3]6
7cmd1:env keystore=`pwd` ./attr.py
8"""
9
10import os
11import ABAC
12
13ctxt = ABAC.Context()
14print "ABAC version %s" % ctxt.version()
15
[f824a9e]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)
[5f551d3]21
22out = ctxt.context_principals()
23print "...initial principal set..."
24for x in out[1]:
25    print "%s " % x.string()
26print "\n" 
27
28out = ctxt.context_credentials()
29print "...initial policy attribute set..."
30for c in out[1]:
31    print "%s <- %s" % (c.head_string(), c.tail_string())
32print "\n"
33
[f824a9e]34# retrieve principals' keyid value from local credential files
[5f551d3]35isiID=ABAC.ID("ISI_ID.pem")
36isiID.id_load_privkey_file("ISI_private.pem");
37isi=isiID.id_keyid()
38
39uscID=ABAC.ID("USC_ID.pem")
40uscID.id_load_privkey_file("USC_private.pem");
41usc=uscID.id_keyid()
42
43maryannID=ABAC.ID("Maryann_ID.pem")
44maryannID.id_load_privkey_file("Maryann_private.pem");
45maryann=maryannID.id_keyid()
46
47johnID=ABAC.ID("John_ID.pem")
48johnID.id_load_privkey_file("John_private.pem");
49john=johnID.id_keyid()
50
51################################################
52#[keyid:USC].role:evaluatorOf([principal:?K])
53#           <-[keyid:USC].role:managerOf([principal:?K])
54param=ABAC.DataTerm("principal", "K")
55head = ABAC.Role(usc,"evaluatorOf")
56head.role_add_data_term(param)
57param=ABAC.DataTerm("principal","K")
58tail = ABAC.Role(usc,"managerOf")
59tail.role_add_data_term(param)
60attr=ABAC.Attribute(head, 1800)
61attr.attribute_add_tail(tail)
62attr.attribute_bake()
63attr.attribute_write_cert("USC_evaluatorof_qK__USC_managerof_qK_attr.der")
64ctxt.load_attribute_file("USC_evaluatorof_qK__USC_managerof_qK_attr.der")
65print attr.string() 
66print attr.typed_string()
67print "\n"
68
69#################################################
[f824a9e]70# Credential 1, double uninstantiated parameters
[5f551d3]71# [keyid:USC].role:managerOf([principal:?K])
72#            <-[keyid:ISI].role:managerOf([principal:?K])
73#
74param=ABAC.DataTerm("principal", "K")
75head = ABAC.Role(usc,"managerOf")
76head.role_add_data_term(param)
[f824a9e]77
78# create variable princpal parameter
[5f551d3]79param=ABAC.DataTerm("principal", "K")
80tail = ABAC.Role(isi,"managerOf")
81tail.role_add_data_term(param)
82attr=ABAC.Attribute(head, 1800)
[f824a9e]83
84# compose the attribute for the policy
[5f551d3]85attr.attribute_add_tail(tail)
[f824a9e]86
87# finalize the policy
[5f551d3]88attr.attribute_bake()
[f824a9e]89
90# write the policy to a file
[5f551d3]91attr.attribute_write_cert("USC_managerof_qK__USC_employee_attr.der")
92ctxt.load_attribute_file("USC_managerof_qK__USC_employee_attr.der")
93print attr.string() 
94print attr.typed_string()
95print "\n"
96
97#################################################
[f824a9e]98# Credential 2
[5f551d3]99# [keyid:ISI].role:managerOf([keyid:Maryann])
100#                        <- [keyid:John]
101param=ABAC.DataTerm(maryannID)
102head = ABAC.Role(isi,"managerOf")
103head.role_add_data_term(param)
104tail = ABAC.Role(john)
105attr=ABAC.Attribute(head, 1800)
106attr.attribute_add_tail(tail)
107attr.attribute_bake()
108attr.attribute_write_cert("ISI_manageof_Maryann__John_attr.der")
109ctxt.load_attribute_file("ISI_manageof_Maryann__John_attr.der")
110print attr.string() 
111print attr.typed_string()
112print "\n"
113
114################################################
[f824a9e]115# Credential 3
[5f551d3]116# [keyid:USC].role:employee <- [keyid:ISI].role:employee
117head=ABAC.Role(usc,"employee")
118tail = ABAC.Role(isi,"employee")
119attr=ABAC.Attribute(head, 1800)
120attr.attribute_add_tail(tail)
121attr.attribute_bake()
122attr.attribute_write_cert("USC_employee__ISI_employee_attr.der")
123ctxt.load_attribute(attr)
[f824a9e]124print attr.string() 
125print attr.typed_string()
126print "\n"
[5f551d3]127
128
129#################################################
[f824a9e]130# Credential 4
[5f551d3]131# [keyid:ISI].role:employee  <- [keyid:Maryann]
132head = ABAC.Role(isi,"employee")
133tail= ABAC.Role(maryann)
134attr=ABAC.Attribute(head, 1800)
135attr.attribute_add_tail(tail)
136attr.attribute_bake()
137attr.attribute_write_cert("ISI_employee__Maryann_attr.der")
138ctxt.load_attribute(attr)
139print attr.string() 
140print attr.typed_string()
141print "\n"
142
143#################################################
[f824a9e]144# Credential 4
[5f551d3]145# [keyid:ISI].role:employee  <- [keyid:John]
146head = ABAC.Role(isi,"employee")
147tail= ABAC.Role(john)
148attr=ABAC.Attribute(head, 1800)
149attr.attribute_add_tail(tail)
150attr.attribute_bake()
151attr.attribute_write_cert("ISI_employee__John_attr.der")
152ctxt.load_attribute(attr)
153print attr.string() 
154print attr.typed_string()
155print "\n"
156
Note: See TracBrowser for help on using the repository browser.