[5f551d3] | 1 | #!/usr/bin/env python |
---|
| 2 | |
---|
| 3 | """ |
---|
| 4 | Setup access policy attribute rules |
---|
| 5 | |
---|
| 6 | cmd1:env keystore=`pwd` ./attr.py |
---|
| 7 | |
---|
| 8 | """ |
---|
| 9 | |
---|
| 10 | import os |
---|
| 11 | import ABAC |
---|
| 12 | |
---|
| 13 | keystore=os.environ["keystore"] |
---|
| 14 | |
---|
| 15 | ctxt = ABAC.Context() |
---|
| 16 | print "ABAC version %s" % ctxt.version() |
---|
| 17 | |
---|
| 18 | ctxt.load_directory(keystore) |
---|
| 19 | |
---|
| 20 | out = ctxt.context_principals() |
---|
| 21 | print "...initial principal set..." |
---|
| 22 | for x in out[1]: |
---|
| 23 | print "%s " % x.string() |
---|
| 24 | print "\n" |
---|
| 25 | |
---|
| 26 | out = ctxt.context_credentials() |
---|
| 27 | print "...initial policy attribute set..." |
---|
| 28 | for c in out[1]: |
---|
| 29 | print "%s <- %s" % (c.head_string(), c.tail_string()) |
---|
| 30 | print "\n" |
---|
| 31 | |
---|
| 32 | stateUID=ABAC.ID("StateU_ID.pem") |
---|
| 33 | stateUID.id_load_privkey_file("StateU_private.pem") |
---|
| 34 | stateU=stateUID.id_keyid() |
---|
| 35 | |
---|
| 36 | bobID=ABAC.ID("Bob_ID.pem") |
---|
| 37 | bobID.id_load_privkey_file("Bob_private.pem") |
---|
| 38 | bob=bobID.id_keyid() |
---|
| 39 | |
---|
| 40 | joeID=ABAC.ID("Joe_ID.pem") |
---|
| 41 | joeID.id_load_privkey_file("Joe_private.pem") |
---|
| 42 | joe=joeID.id_keyid() |
---|
| 43 | |
---|
| 44 | maryannID=ABAC.ID("Maryann_ID.pem") |
---|
| 45 | maryannID.id_load_privkey_file("Maryann_private.pem") |
---|
| 46 | maryann=maryannID.id_keyid() |
---|
| 47 | |
---|
| 48 | |
---|
| 49 | ################################################ |
---|
| 50 | # [keyid:stateU].role:foundingAlumni |
---|
| 51 | # <- [keyid:stateU].role:diploma([?], [integer:?Year:[1960,1961,1963]]) |
---|
| 52 | head = ABAC.Role(stateU,"foundingAlumni") |
---|
| 53 | param1=ABAC.DataTerm("anonymous", "_") |
---|
| 54 | cond=ABAC.Constraint("integer") |
---|
| 55 | cond.constraint_add_integer_target(1960) |
---|
| 56 | cond.constraint_add_integer_target(1961) |
---|
| 57 | cond.constraint_add_integer_target(1963) |
---|
| 58 | param2=ABAC.DataTerm("integer", "Year", cond) |
---|
| 59 | tail = ABAC.Role(stateU,"diploma") |
---|
| 60 | tail.role_add_data_term(param1) |
---|
| 61 | tail.role_add_data_term(param2) |
---|
| 62 | attr=ABAC.Attribute(head, 1800) |
---|
| 63 | attr.attribute_add_tail(tail) |
---|
| 64 | attr.attribute_bake() |
---|
| 65 | attr.attribute_write_cert("StateU_foundingAlumni__stateU_diploma_q_qY_attr.der") |
---|
| 66 | ctxt.load_attribute_file("StateU_foundingAlumni__stateU_diploma_q_qY_attr.der") |
---|
| 67 | print attr.string() |
---|
| 68 | print attr.typed_string() |
---|
| 69 | print "\n" |
---|
| 70 | |
---|
| 71 | ################################################# |
---|
| 72 | # [keyid:stateU].role:diploma([string:'mathmatics'],[integer:1961]) <- [keyid:bob] |
---|
| 73 | param1=ABAC.DataTerm("string", "'mathmatics'") |
---|
| 74 | param2=ABAC.DataTerm("integer", "1961") |
---|
| 75 | head = ABAC.Role(stateU,"diploma") |
---|
| 76 | head.role_add_data_term(param1) |
---|
| 77 | head.role_add_data_term(param2) |
---|
| 78 | tail = ABAC.Role(bob) |
---|
| 79 | attr=ABAC.Attribute(head, 1800) |
---|
| 80 | attr.attribute_add_tail(tail) |
---|
| 81 | attr.attribute_bake() |
---|
| 82 | attr.attribute_write_cert("StateU_diploma_m__Bob_attr.der") |
---|
| 83 | ctxt.load_attribute_file("StateU_diploma_m__Bob_attr.der") |
---|
| 84 | print attr.string() |
---|
| 85 | print attr.typed_string() |
---|
| 86 | print "\n" |
---|
| 87 | |
---|
| 88 | ################################################# |
---|
| 89 | # [keyid:stateU].role:diploma([string:'zoology'],[integer:1955]) <- [keyid:joe] |
---|
| 90 | param1=ABAC.DataTerm("string", "'zoology'") |
---|
| 91 | param2=ABAC.DataTerm("integer", "1955") |
---|
| 92 | head = ABAC.Role(stateU,"diploma") |
---|
| 93 | head.role_add_data_term(param1) |
---|
| 94 | head.role_add_data_term(param2) |
---|
| 95 | tail = ABAC.Role(joe) |
---|
| 96 | attr=ABAC.Attribute(head, 1800) |
---|
| 97 | attr.attribute_add_tail(tail) |
---|
| 98 | attr.attribute_bake() |
---|
| 99 | attr.attribute_write_cert("StateU_diploma_z__Joe_attr.der") |
---|
| 100 | ctxt.load_attribute_file("StateU_diploma_z__Joe_attr.der") |
---|
| 101 | print attr.string() |
---|
| 102 | print attr.typed_string() |
---|
| 103 | print "\n" |
---|
| 104 | |
---|
| 105 | ################################################# |
---|
| 106 | # [keyid:stateU].role:diploma([string:'psychology'],[integer:1962]) <- [keyid:maryann] |
---|
| 107 | param1=ABAC.DataTerm("string", "'psychology'") |
---|
| 108 | param2=ABAC.DataTerm("integer", "1962") |
---|
| 109 | head = ABAC.Role(stateU,"diploma") |
---|
| 110 | head.role_add_data_term(param1) |
---|
| 111 | head.role_add_data_term(param2) |
---|
| 112 | tail = ABAC.Role(maryann) |
---|
| 113 | attr=ABAC.Attribute(head, 1800) |
---|
| 114 | attr.attribute_add_tail(tail) |
---|
| 115 | attr.attribute_bake() |
---|
| 116 | attr.attribute_write_cert("StateU_diploma_p__Maryann_attr.der") |
---|
| 117 | ctxt.load_attribute_file("StateU_diploma_p__Maryann_attr.der") |
---|
| 118 | print attr.string() |
---|
| 119 | print attr.typed_string() |
---|
| 120 | print "\n" |
---|
| 121 | |
---|
| 122 | ctxt.dump_yap_db() |
---|
| 123 | ## |
---|