1 | |
---|
2 | import java.io.*; |
---|
3 | import java.security.*; |
---|
4 | import java.util.*; |
---|
5 | |
---|
6 | import edu.uci.ics.jung.graph.*; |
---|
7 | |
---|
8 | import net.deterlab.abac.Credential; |
---|
9 | import net.deterlab.abac.CredentialGraph; |
---|
10 | import net.deterlab.abac.Query; |
---|
11 | import net.deterlab.abac.Role; |
---|
12 | import net.deterlab.abac.Identity; |
---|
13 | |
---|
14 | import org.bouncycastle.openssl.PEMReader; |
---|
15 | import org.bouncycastle.jce.provider.X509CertificateObject; |
---|
16 | import java.security.KeyPair; |
---|
17 | import java.security.PublicKey; |
---|
18 | // import org.bouncycastle.util.io.pem.PemObject; |
---|
19 | |
---|
20 | |
---|
21 | /** |
---|
22 | * Simple test of the native Java implementation of ABAC. Loads credentials |
---|
23 | * from an rt0 file and runs a query against them. |
---|
24 | */ |
---|
25 | public class MakeTest { |
---|
26 | public static void main(String[] args) throws IOException { |
---|
27 | Identity id = null; |
---|
28 | Credential newCred = null; |
---|
29 | try { |
---|
30 | id = new Identity(args[0]); |
---|
31 | Credential.addIdentity(id); |
---|
32 | } |
---|
33 | catch (Exception e) { System.out.println(e); } |
---|
34 | System.err.println("ID " + id); |
---|
35 | PEMReader pr = new PEMReader(new FileReader(args[1])); |
---|
36 | Object o = pr.readObject(); |
---|
37 | System.err.println(o.getClass().getName()); |
---|
38 | |
---|
39 | if ( o instanceof KeyPair ) { |
---|
40 | KeyPair p = (KeyPair) o; |
---|
41 | |
---|
42 | System.err.println(p.getPrivate().getFormat()); |
---|
43 | Role role = new Role(args[args.length-2], true); |
---|
44 | Role prin = new Role(args[args.length-1], true); |
---|
45 | |
---|
46 | Credential c = new Credential(role, prin); |
---|
47 | c.make_cert(p.getPrivate()); |
---|
48 | c.write("./test.der"); |
---|
49 | try { |
---|
50 | newCred = new Credential("./test.der"); |
---|
51 | } |
---|
52 | catch (Exception e) { System.out.println(e); } |
---|
53 | System.err.println(newCred); |
---|
54 | } |
---|
55 | |
---|
56 | } |
---|
57 | } |
---|