[5f551d3] | 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 | ################################################ |
---|
| 49 | # [keyid:alpha].role:read([urn:?F])<- |
---|
| 50 | # [keyid:alpha].role:managerOf([principal:?E[keyid:alpha].role:ownerOf([urn:?F])] |
---|
| 51 | param=ABAC.DataTerm("urn", "F") |
---|
| 52 | head = ABAC.Role(alpha,"read") |
---|
| 53 | head.role_add_data_term(param) |
---|
| 54 | param=ABAC.DataTerm("urn", "F") |
---|
| 55 | condoset=ABAC.Role(alpha,"ownerOf") |
---|
| 56 | condoset.role_add_data_term(param) |
---|
| 57 | cond=ABAC.Constraint(condoset) |
---|
| 58 | param=ABAC.DataTerm("principal", "E", cond) |
---|
| 59 | tail = ABAC.Role(alpha,"managerOf") |
---|
| 60 | tail.role_add_data_term(param) |
---|
| 61 | attr=ABAC.Attribute(head, 1800) |
---|
| 62 | attr.attribute_add_tail(tail) |
---|
| 63 | attr.attribute_bake() |
---|
| 64 | attr.attribute_write_cert("Alpha_read_qF__alpha_managerof_qE_attr.der") |
---|
| 65 | ctxt.load_attribute_file("Alpha_read_qF__alpha_managerof_qE_attr.der") |
---|
| 66 | print attr.string() |
---|
| 67 | print attr.typed_string() |
---|
| 68 | print "\n" |
---|
| 69 | |
---|
| 70 | ################################################# |
---|
| 71 | # [keyid:Alpha].role:managerOf([Keyid:Joe]) <- [keyid:Bob] |
---|
| 72 | # |
---|
| 73 | param=ABAC.DataTerm(joeID) |
---|
| 74 | role = ABAC.Role(alpha,"managerOf") |
---|
| 75 | role.role_add_data_term(param) |
---|
| 76 | tail = ABAC.Role(bob) |
---|
| 77 | attr=ABAC.Attribute(role, 1800) |
---|
| 78 | attr.attribute_add_tail(tail) |
---|
| 79 | attr.attribute_bake() |
---|
| 80 | attr.attribute_write_cert("Alpha_managerof_Joe__Bob_attr.der") |
---|
| 81 | ctxt.load_attribute_file("Alpha_managerof_Joe__Bob_attr.der") |
---|
| 82 | print attr.string() |
---|
| 83 | print attr.typed_string() |
---|
| 84 | print "\n" |
---|
| 85 | |
---|
| 86 | ################################################# |
---|
| 87 | #[keyid:Alpha].role:ownerOf([urn:'file://fileA']) <- [keyid:Joe] |
---|
| 88 | # |
---|
| 89 | param=ABAC.DataTerm("urn", "'file://fileA'") |
---|
| 90 | role = ABAC.Role(alpha,"ownerOf") |
---|
| 91 | role.role_add_data_term(param) |
---|
| 92 | tail = ABAC.Role(joe) |
---|
| 93 | attr=ABAC.Attribute(role, 1800) |
---|
| 94 | attr.attribute_add_tail(tail) |
---|
| 95 | attr.attribute_bake() |
---|
| 96 | attr.attribute_write_cert("Alpha_ownerof_fileA__Joe_attr.der") |
---|
| 97 | ctxt.load_attribute_file("Alpha_ownerof_fileA__Joe_attr.der") |
---|
| 98 | print attr.string() |
---|
| 99 | print attr.typed_string() |
---|
| 100 | print "\n" |
---|
| 101 | |
---|
| 102 | |
---|
| 103 | ctxt.dump_yap_db() |
---|
| 104 | ## |
---|