source: examples/example_scripts/python/abac_prover.py @ 4e10a0f

abac0-leakabac0-meimei-idmei-rt0-nmei_rt0tvf-new-xml
Last change on this file since 4e10a0f 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
Line 
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
17import getopt
18import sys
19from ABAC import Context
20
21
22def 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
29keystore = ''
30role = ''
31principal = ''
32
33try:
34    opts, args = getopt.getopt(sys.argv[1:], '', ['keystore=', 'role=', 'principal='])
35except getopt.GetoptError, err:
36    print str(err)
37    sys.exit(1)
38
39for 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
49if keystore == '' or role == '' or principal == '':
50    usage()
51
52# code begins here! sorry about that
53
54print keystore
55print role
56print principal
57
58ctx = Context()
59ctx.load_directory(keystore)
60
61(success, credentials) = ctx.query(role, principal)
62
63if success:
64    print "success"
65
66for 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.