abac0-leakabac0-meimei-idmei-rt0-nmei_rt0tvf-new-xml
Last change
on this file since bc7133b was
4721618,
checked in by Mei <mei@…>, 12 years ago
|
1) tested out python and perl test scripts along with
abac_chunk_t calls in libabac's abac.hh
|
-
Property mode set to
100755
|
File size:
1.4 KB
|
Rev | Line | |
---|
[4721618] | 1 | #!/usr/bin/env python |
---|
| 2 | |
---|
| 3 | """ |
---|
| 4 | abac_prover.py |
---|
| 5 | |
---|
| 6 | To demonstrate how to use ABAC's api in python to make a query |
---|
| 7 | |
---|
| 8 | call: abac_prover "keystorestring" "rolestring" "principalstring" |
---|
| 9 | |
---|
| 10 | pre-condition: run make attr_abac generate IceCream_ID.pem and IceCream_private.pem with |
---|
| 11 | |
---|
| 12 | This program will make a prover call using |
---|
| 13 | rolestring <- principalstring |
---|
| 14 | |
---|
| 15 | """ |
---|
| 16 | |
---|
| 17 | import getopt |
---|
| 18 | import sys |
---|
| 19 | from ABAC import Context |
---|
| 20 | |
---|
| 21 | |
---|
| 22 | def usage(): |
---|
| 23 | print "Usage: abac_prover.py \\" |
---|
| 24 | print " --keystore <keystore> \\" |
---|
| 25 | print " --role <role> --principal <principal> " |
---|
| 26 | print " loads the keystore and runs the query role <-?- principal" |
---|
| 27 | sys.exit(1) |
---|
| 28 | |
---|
| 29 | keystore = '' |
---|
| 30 | role = '' |
---|
| 31 | principal = '' |
---|
| 32 | |
---|
| 33 | try: |
---|
| 34 | opts, args = getopt.getopt(sys.argv[1:], '', ['keystore=', 'role=', 'principal=']) |
---|
| 35 | except getopt.GetoptError, err: |
---|
| 36 | print str(err) |
---|
| 37 | sys.exit(1) |
---|
| 38 | |
---|
| 39 | for o, a in opts: |
---|
| 40 | if o == '--keystore': |
---|
| 41 | keystore = a |
---|
| 42 | elif o == '--role': |
---|
| 43 | role = a |
---|
| 44 | elif o == '--principal': |
---|
| 45 | principal = a |
---|
| 46 | else: |
---|
| 47 | assert False, "WAT" |
---|
| 48 | |
---|
| 49 | if keystore == '' or role == '' or principal == '': |
---|
| 50 | usage() |
---|
| 51 | |
---|
| 52 | # code begins here! sorry about that |
---|
| 53 | |
---|
| 54 | print keystore |
---|
| 55 | print role |
---|
| 56 | print principal |
---|
| 57 | |
---|
| 58 | ctx = Context() |
---|
| 59 | ctx.load_directory(keystore) |
---|
| 60 | |
---|
| 61 | (success, credentials) = ctx.query(role, principal) |
---|
| 62 | |
---|
| 63 | if success: |
---|
| 64 | print "success" |
---|
| 65 | |
---|
| 66 | for credential in credentials: |
---|
| 67 | print "credential %s <- %s" % (credential.head().string(), credential.tail().string()) |
---|
| 68 | |
---|
Note: See
TracBrowser
for help on using the repository browser.