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