[7211a95] | 1 | #!/usr/bin/env python |
---|
| 2 | |
---|
| 3 | """ |
---|
| 4 | to test with python |
---|
| 5 | |
---|
| 6 | cmd1:env keystore=`pwd` ./attr.py |
---|
| 7 | """ |
---|
| 8 | |
---|
| 9 | import os |
---|
| 10 | import ABAC |
---|
| 11 | |
---|
| 12 | keystore=os.environ["keystore"] |
---|
| 13 | |
---|
| 14 | ctxt = ABAC.Context() |
---|
| 15 | print "ABAC version %s" % ctxt.version() |
---|
| 16 | |
---|
| 17 | ctxt.load_directory(keystore) |
---|
| 18 | |
---|
| 19 | out = ctxt.context_principals() |
---|
| 20 | print "...initial principal set..." |
---|
| 21 | for x in out[1]: |
---|
| 22 | print "%s " % x.string() |
---|
| 23 | print "\n" |
---|
| 24 | |
---|
| 25 | out = ctxt.context_credentials() |
---|
| 26 | print "...initial policy attribute set..." |
---|
| 27 | for c in out[1]: |
---|
| 28 | print "%s <- %s" % (c.head_string(), c.tail_string()) |
---|
| 29 | print "\n" |
---|
| 30 | |
---|
| 31 | alphaID=ABAC.ID("Alpha_ID.pem"); |
---|
| 32 | alphaID.id_load_privkey_file("Alpha_private.pem"); |
---|
| 33 | alpha=alphaID.id_keyid() |
---|
| 34 | |
---|
| 35 | bobID=ABAC.ID("Bob_ID.pem"); |
---|
| 36 | bobID.id_load_privkey_file("Bob_private.pem"); |
---|
| 37 | bob=bobID.id_keyid() |
---|
| 38 | |
---|
| 39 | maryannID=ABAC.ID("Maryann_ID.pem"); |
---|
| 40 | maryannID.id_load_privkey_file("Maryann_private.pem"); |
---|
| 41 | maryann=maryannID.id_keyid() |
---|
| 42 | |
---|
| 43 | joeID=ABAC.ID("Joe_ID.pem"); |
---|
| 44 | joeID.id_load_privkey_file("Joe_private.pem"); |
---|
| 45 | joe=joeID.id_keyid() |
---|
| 46 | |
---|
| 47 | ################################################ |
---|
| 48 | # [keyid:alpha].role:payRaise <- |
---|
| 49 | # [keyid:alpha].role:evaluatorOf([principal:?this]).role:goodPerformance & |
---|
| 50 | # [keyid:alpha].role:managerOf([principal:?this]).role:niceCoworker |
---|
| 51 | |
---|
| 52 | # [keyid:alpha].role:access([string:'Read'],[urn:'file//fileB']) <- [keyid:bob] |
---|
| 53 | head=ABAC.Role(alpha,"payRaise") |
---|
| 54 | param=ABAC.DataTerm("principal", "This") |
---|
| 55 | tail1 = ABAC.Role(alpha,"evaluatorOf","goodPerformance") |
---|
| 56 | tail1.role_add_linked_data_term(param) |
---|
| 57 | param=ABAC.DataTerm("principal", "This") |
---|
| 58 | tail2 = ABAC.Role(alpha,"managerOf","niceCoworker") |
---|
| 59 | tail2.role_add_linked_data_term(param) |
---|
| 60 | attr=ABAC.Attribute(head, 1800) |
---|
| 61 | attr.attribute_add_tail(tail1) |
---|
| 62 | attr.attribute_add_tail(tail2) |
---|
| 63 | attr.attribute_bake() |
---|
| 64 | attr.attribute_write_cert("Alpha_payraise__Alpha_performance_qT_niceguy_qT_attr.der") |
---|
| 65 | ctxt.load_attribute_file("Alpha_payraise__Alpha_performance_qT_niceguy_qT_attr.der") |
---|
| 66 | print attr.string() |
---|
| 67 | print attr.typed_string() |
---|
| 68 | print "\n" |
---|
| 69 | |
---|
| 70 | ################################################# |
---|
| 71 | # [keyid:alpha].role:managerOf([principal:?Z])<- |
---|
| 72 | # [keyid:alpha].role:evaluatorOf([principal:?Z]) |
---|
| 73 | param=ABAC.DataTerm("principal", "Z") |
---|
| 74 | head=ABAC.Role(alpha,"managerOf") |
---|
| 75 | head.role_add_data_term(param) |
---|
| 76 | param=ABAC.DataTerm("principal", "Z") |
---|
| 77 | tail = ABAC.Role(alpha,"evaluatorOf") |
---|
| 78 | tail.role_add_data_term(param) |
---|
| 79 | attr=ABAC.Attribute(head, 1800) |
---|
| 80 | attr.attribute_add_tail(tail) |
---|
| 81 | attr.attribute_bake() |
---|
| 82 | attr.attribute_write_cert("Alpha_manager_qZ__Alpha_evaluator_qZ_attr.der") |
---|
| 83 | ctxt.load_attribute_file("Alpha_manager_qZ__Alpha_evaluator_qZ_attr.der") |
---|
| 84 | print attr.string() |
---|
| 85 | print attr.typed_string() |
---|
| 86 | print "\n" |
---|
| 87 | |
---|
| 88 | ################################################# |
---|
| 89 | # [keyid:alpha].role:evaluatorOf([keyid:Maryann]) <-[keyid:Bob] |
---|
| 90 | param=ABAC.DataTerm(maryannID) |
---|
| 91 | head = ABAC.Role(alpha,"evaluatorOf") |
---|
| 92 | head.role_add_data_term(param) |
---|
| 93 | tail = ABAC.Role(bob) |
---|
| 94 | attr=ABAC.Attribute(head, 1800) |
---|
| 95 | attr.attribute_add_tail(tail) |
---|
| 96 | attr.attribute_bake() |
---|
| 97 | attr.attribute_write_cert("Alpha_evaluator_m__Bob_attr.der") |
---|
| 98 | ctxt.load_attribute_file("Alpha_evaluator_m__Bob_attr.der") |
---|
| 99 | print attr.string() |
---|
| 100 | print attr.typed_string() |
---|
| 101 | print "\n" |
---|
| 102 | |
---|
| 103 | ################################################# |
---|
| 104 | # [keyid:Bob].role:goodPerformance <- [keyid:Maryann]) |
---|
| 105 | head = ABAC.Role(bob,"goodPerformance") |
---|
| 106 | tail = ABAC.Role(maryann) |
---|
| 107 | attr=ABAC.Attribute(head, 1800) |
---|
| 108 | attr.attribute_add_tail(tail) |
---|
| 109 | attr.attribute_bake() |
---|
| 110 | attr.attribute_write_cert("Bob_goodperformance__Maryann_attr.der") |
---|
| 111 | ctxt.load_attribute_file("Bob_goodperformance__Maryann_attr.der") |
---|
| 112 | print attr.string() |
---|
| 113 | print attr.typed_string() |
---|
| 114 | print "\n" |
---|
| 115 | |
---|
| 116 | ################################################# |
---|
| 117 | # [keyid:Bob].role:niceCoworker <- [keyid:Maryann]) |
---|
| 118 | head = ABAC.Role(bob,"niceCoworker") |
---|
| 119 | tail = ABAC.Role(maryann) |
---|
| 120 | attr=ABAC.Attribute(head, 1800) |
---|
| 121 | attr.attribute_add_tail(tail) |
---|
| 122 | attr.attribute_bake() |
---|
| 123 | attr.attribute_write_cert("Bob_nicecoworker__Maryann_attr.der") |
---|
| 124 | ctxt.load_attribute_file("Bob_nicecoworker__Maryann_attr.der") |
---|
| 125 | print attr.string() |
---|
| 126 | print attr.typed_string() |
---|
| 127 | print "\n" |
---|
| 128 | |
---|
| 129 | ################################################# |
---|
| 130 | # [keyid:alpha].role:evaluatorOf([keyid:Joe]) <-[keyid:Bob] |
---|
| 131 | param=ABAC.DataTerm(joeID) |
---|
| 132 | head = ABAC.Role(alpha,"evaluatorOf") |
---|
| 133 | head.role_add_data_term(param) |
---|
| 134 | tail = ABAC.Role(bob) |
---|
| 135 | attr=ABAC.Attribute(head, 1800) |
---|
| 136 | attr.attribute_add_tail(tail) |
---|
| 137 | attr.attribute_bake() |
---|
| 138 | attr.attribute_write_cert("Alpha_evaluator_j__Bob_attr.der") |
---|
| 139 | ctxt.load_attribute_file("Alpha_evaluator_j__Bob_attr.der") |
---|
| 140 | print attr.string() |
---|
| 141 | print attr.typed_string() |
---|
| 142 | print "\n" |
---|
| 143 | |
---|
| 144 | ################################################# |
---|
| 145 | # [keyid:Bob].role:goodPerformance <- [keyid:Joe]) |
---|
| 146 | head = ABAC.Role(bob,"goodPerformance") |
---|
| 147 | tail = ABAC.Role(joe) |
---|
| 148 | attr=ABAC.Attribute(head, 1800) |
---|
| 149 | attr.attribute_add_tail(tail) |
---|
| 150 | attr.attribute_bake() |
---|
| 151 | attr.attribute_write_cert("Bob_goodperformance__Joe_attr.der") |
---|
| 152 | ctxt.load_attribute_file("Bob_goodperformance__Joe_attr.der") |
---|
| 153 | print attr.string() |
---|
| 154 | print attr.typed_string() |
---|
| 155 | print "\n" |
---|
| 156 | |
---|
| 157 | |
---|
| 158 | ctxt.dump_yap_db() |
---|
| 159 | ## |
---|