1 | import java.io.*; |
---|
2 | import java.util.*; |
---|
3 | |
---|
4 | import net.deterlab.abac.*; |
---|
5 | |
---|
6 | /** |
---|
7 | * Simple test of the swig generated JNI for libabac. Loads credentials |
---|
8 | * from keystore and runs a query against them. |
---|
9 | */ |
---|
10 | public class ProverTest { |
---|
11 | |
---|
12 | static { |
---|
13 | System.loadLibrary("jABAC"); |
---|
14 | } |
---|
15 | |
---|
16 | public static void main(String[] args) throws IOException { |
---|
17 | if (args.length < 4) { |
---|
18 | System.out.println("Usage: ProverTest <keystore> <issuer> <roletype> <principal>"); |
---|
19 | System.out.println(" runs the query issuer.roletype <-?- principal and prints the result" |
---|
20 | ); |
---|
21 | System.exit(1); |
---|
22 | } |
---|
23 | |
---|
24 | String keystore=args[0]; |
---|
25 | String iname=args[1]; |
---|
26 | String roletype=args[2]; |
---|
27 | String pname=args[3]; |
---|
28 | |
---|
29 | Context ctxt = new Context(); |
---|
30 | |
---|
31 | ctxt.load_directory(keystore); |
---|
32 | |
---|
33 | /* |
---|
34 | role="[keyid:${pID}].role:delicious" |
---|
35 | principal="[keyid:${cID}]" |
---|
36 | */ |
---|
37 | String ifname=iname+"_ID.pem"; |
---|
38 | String pfname=pname+"_ID.pem"; |
---|
39 | |
---|
40 | ID iID=new ID(ifname); |
---|
41 | ID pID=new ID(pfname); |
---|
42 | |
---|
43 | String ikeyid=iID.id_keyid(); |
---|
44 | String pkeyid=pID.id_keyid(); |
---|
45 | |
---|
46 | String role="[keyid:"+ikeyid+"].role:"+roletype; |
---|
47 | String principal="[keyid:"+pkeyid+"]"; |
---|
48 | |
---|
49 | AttributeVector credentials = ctxt.query(role, principal); |
---|
50 | |
---|
51 | long sz=credentials.size(); |
---|
52 | |
---|
53 | if(sz > 0) |
---|
54 | System.out.println("prover success!!"); |
---|
55 | else |
---|
56 | System.out.println("prover failed!!"); |
---|
57 | |
---|
58 | for(int i=0; i<sz; i++) { |
---|
59 | Attribute c=credentials.get(i); |
---|
60 | System.out.println(c.head_string()+"<- "+c.tail_string()); |
---|
61 | } |
---|
62 | |
---|
63 | ctxt.free_context_now(); |
---|
64 | System.out.println("ProverTest okay."); |
---|
65 | } |
---|
66 | } |
---|