1 | #!/usr/bin/env python |
---|
2 | |
---|
3 | """ |
---|
4 | to test with python |
---|
5 | |
---|
6 | cmd:env keystore=`pwd` ./query.py |
---|
7 | |
---|
8 | No real query (originally id.py) |
---|
9 | """ |
---|
10 | |
---|
11 | import os |
---|
12 | import ABAC |
---|
13 | |
---|
14 | ctxt = ABAC.Context() |
---|
15 | |
---|
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) |
---|
21 | else: |
---|
22 | print("keystore is not set, using current directory...") |
---|
23 | ctxt.load_directory(".") |
---|
24 | |
---|
25 | ## case 1 |
---|
26 | ## creating and writing out using libabac ID |
---|
27 | id=ABAC.ID("Mary", 0) |
---|
28 | print "adding -> %s(Mary/good)" % id.keyid() |
---|
29 | id.write_cert_file("Mary_ID.pem") |
---|
30 | id.write_privkey_file("Mary_private.pem") |
---|
31 | ## load principal with id/key file pair |
---|
32 | ## note, with this, we do not have handle on the keyid |
---|
33 | ## to Mary but it will be in the db |
---|
34 | #XXX# ctxt.load_id_files("Mary_ID.pem","Mary_private.pem") |
---|
35 | |
---|
36 | ## case 2 |
---|
37 | ## creating principal using ID |
---|
38 | id2=ABAC.ID("Jack2", 0) |
---|
39 | print "adding -> %s(Jack2/good)" % id2.keyid() |
---|
40 | ## load principal directly with the ID, no external |
---|
41 | ## credential files were created |
---|
42 | #XXX# ctxt.load_id(id2) |
---|
43 | |
---|
44 | ## case 3 |
---|
45 | ## creating principal using ID |
---|
46 | id3=ABAC.ID("Mark", 0) |
---|
47 | print "adding -> %s(Mark/good)" % id3.keyid() |
---|
48 | ## write cert and key content to a combo file. One is appended |
---|
49 | ## after another |
---|
50 | id3.write_privkey_file("Mark_IDKEY.pem") |
---|
51 | id3.write_cert_file("Mark_IDKEY.pem") |
---|
52 | ## load principal in with the combo file with the tandem format |
---|
53 | ctxt.load_id_file("Mark_IDKEY.pem") |
---|
54 | |
---|
55 | ## case 4 |
---|
56 | ## creating principal using ID |
---|
57 | id4=ABAC.ID("John", 0) |
---|
58 | print "adding -> %s(John/good,invisible)" % id4.keyid() |
---|
59 | id4.write_cert_file("John_other.pem") |
---|
60 | ## load id without the key file |
---|
61 | ctxt.load_id_file("John_other.pem") |
---|
62 | |
---|
63 | ## case 5 |
---|
64 | ## creating principal using ID |
---|
65 | id5=ABAC.ID("Lori", 0) |
---|
66 | print "adding -> %s(Lori/good,nokey)" % id5.keyid() |
---|
67 | ## write just cert into the combo file |
---|
68 | id5.write_cert_file("Lori_IDKEY.pem") |
---|
69 | ##load principal from a combo file that only contains cert part |
---|
70 | ctxt.load_id_file("Lori2_IDKEY.pem") |
---|
71 | |
---|
72 | ## case 6 |
---|
73 | ## creating principal using ID |
---|
74 | id6=ABAC.ID("Tom", 0) |
---|
75 | print "adding -> %s(Tom/bad,nocert)" % id6.keyid() |
---|
76 | ## write just key into the combo file |
---|
77 | id6.write_privkey_file("Tom_IDKEY.pem") |
---|
78 | ## load principal from combo file that only contains key part |
---|
79 | ctxt.load_id_file("Tom_IDKEY.pem") |
---|
80 | |
---|
81 | ## case 7 |
---|
82 | ## creating ID using chunk |
---|
83 | ## this already created a Tim with private key and |
---|
84 | ## stored in the master list |
---|
85 | id7=ABAC.ID("Tim", 0) |
---|
86 | chunk=id7.cert_chunk() |
---|
87 | id77=ABAC.ID_chunk(chunk) |
---|
88 | ## load principal from new id |
---|
89 | ctxt.load_id_chunk(id77.cert_chunk()) |
---|
90 | |
---|
91 | ## case 8 |
---|
92 | ## load directly using chunk |
---|
93 | ## this already created a Stanley with private key |
---|
94 | ## and stored in the master list |
---|
95 | id8=ABAC.ID("Stanley", 0) |
---|
96 | chunk=id8.cert_chunk() |
---|
97 | ## load principal as chunk |
---|
98 | ctxt.load_id_chunk(chunk) |
---|
99 | |
---|
100 | ## case 9 |
---|
101 | ## failure case, loading a non-existing combo file |
---|
102 | print "adding -> Casper(bad,unknown file)" |
---|
103 | ctxt.load_id_file("Casper_IDKEY.pem") |
---|
104 | |
---|