[5348b6c] | 1 | package net.deterlab.abac.regression; |
---|
| 2 | |
---|
| 3 | import java.io.*; |
---|
| 4 | import java.util.*; |
---|
| 5 | |
---|
| 6 | import net.deterlab.abac.*; |
---|
| 7 | |
---|
| 8 | public class RocketsTest extends RegressionTest { |
---|
| 9 | /** |
---|
| 10 | * Put out an identity and key into dir named by the name of the Identity |
---|
| 11 | * @param i the Identity to write |
---|
| 12 | * @param dir a File holding the destination directory |
---|
| 13 | * @throws IOException if the file writing fails |
---|
| 14 | */ |
---|
| 15 | public void writeCombinedIdentity(Identity i, File dir) |
---|
| 16 | throws IOException { |
---|
| 17 | FileOutputStream f = new FileOutputStream( |
---|
| 18 | new File(dir, i.getName() + ".pem")); |
---|
| 19 | |
---|
| 20 | i.write(f); |
---|
| 21 | i.writePrivateKey(f); |
---|
| 22 | } |
---|
| 23 | /** |
---|
| 24 | * Create a new Credential/Identity writing test for the given class of |
---|
| 25 | * credentials. |
---|
| 26 | * @param cn a String containing the binary name of the class to test |
---|
| 27 | */ |
---|
| 28 | public RocketsTest(String name) { |
---|
| 29 | super(name); |
---|
| 30 | } |
---|
| 31 | |
---|
| 32 | /** |
---|
| 33 | * Carry out the test. Create credentials for the create_experiment |
---|
| 34 | * example, run the proof and make sure the correct proof is generated. |
---|
| 35 | * @param data a File pointing to a directory that contains files the test |
---|
| 36 | * may need |
---|
| 37 | * @param scratch a File pointing to a directory that the test can use to |
---|
| 38 | * store data |
---|
| 39 | * @return a boolean, true if the test is passed |
---|
| 40 | */ |
---|
| 41 | public boolean runTest(File data, File scratch) { |
---|
| 42 | try { |
---|
| 43 | Context ctxt = new Context(); |
---|
| 44 | Identity acme = new Identity("Acme"); |
---|
| 45 | Identity warnerBros = new Identity("WarnerBros"); |
---|
| 46 | Identity batman = new Identity("Batman"); |
---|
| 47 | Identity coyote = new Identity("Coyote"); |
---|
| 48 | ArrayList<Credential> inProof = new ArrayList<Credential>(); |
---|
| 49 | |
---|
| 50 | ctxt.load_id_chunk(acme); |
---|
| 51 | ctxt.load_id_chunk(warnerBros); |
---|
| 52 | ctxt.load_id_chunk(batman); |
---|
| 53 | ctxt.load_id_chunk(coyote); |
---|
| 54 | |
---|
| 55 | Credential c = ctxt.newCredential( |
---|
| 56 | new Role(acme.getKeyID() + ".buy_rockets"), |
---|
| 57 | new Role(acme.getKeyID() + ".preferred_customer & " + |
---|
| 58 | warnerBros.getKeyID() + ".character")); |
---|
| 59 | c.make_cert(acme); |
---|
| 60 | ctxt.load_attribute_chunk(c); |
---|
| 61 | inProof.add(c); |
---|
| 62 | c = ctxt.newCredential( |
---|
| 63 | new Role(acme.getKeyID() + ".preferred_customer"), |
---|
| 64 | new Role(coyote.getKeyID())); |
---|
| 65 | c.make_cert(acme); |
---|
| 66 | ctxt.load_attribute_chunk(c); |
---|
| 67 | inProof.add(c); |
---|
| 68 | c = ctxt.newCredential( |
---|
| 69 | new Role(acme.getKeyID() + ".preferred_customer"), |
---|
| 70 | new Role(batman.getKeyID())); |
---|
| 71 | c.make_cert(acme); |
---|
| 72 | ctxt.load_attribute_chunk(c); |
---|
| 73 | c = ctxt.newCredential( |
---|
| 74 | new Role(warnerBros.getKeyID() + ".character"), |
---|
| 75 | new Role(coyote.getKeyID())); |
---|
| 76 | c.make_cert(warnerBros); |
---|
| 77 | ctxt.load_attribute_chunk(c); |
---|
| 78 | inProof.add(c); |
---|
| 79 | |
---|
[736a573] | 80 | /* For checking only. An internal credential of this form will |
---|
| 81 | * come out of the Context in the proof. */ |
---|
| 82 | c = new InternalCredential( |
---|
| 83 | new Role(acme.getKeyID() + ".preferred_customer & " + |
---|
| 84 | warnerBros.getKeyID() + ".character"), |
---|
| 85 | new Role(coyote.getKeyID())); |
---|
| 86 | inProof.add(c); |
---|
| 87 | |
---|
[5348b6c] | 88 | Context.QueryResult q = ctxt.query( |
---|
| 89 | acme.getKeyID() + ".buy_rockets", |
---|
| 90 | coyote.getKeyID()); |
---|
| 91 | |
---|
| 92 | if ( !q.getSuccess()) { |
---|
| 93 | setReason("Coyote can buy rockets proof failed?"); |
---|
| 94 | return false; |
---|
| 95 | } |
---|
| 96 | if ( inProof.size() != q.getCredentials().size()) { |
---|
| 97 | setReason("Coyote can buy rockets proof is the wrong size"); |
---|
| 98 | return false; |
---|
| 99 | } |
---|
| 100 | |
---|
| 101 | for (Credential cc: inProof) |
---|
| 102 | if ( !q.getCredentials().contains(cc)) { |
---|
| 103 | setReason("Coyote can buy rockets proof missing cred "+cc); |
---|
| 104 | return false; |
---|
| 105 | } |
---|
| 106 | |
---|
| 107 | q = ctxt.query(acme.getKeyID() + ".buy_rockets", |
---|
| 108 | batman.getKeyID()); |
---|
| 109 | if ( q.getSuccess()) { |
---|
| 110 | setReason("Batman can buy rockets ?"); |
---|
| 111 | return false; |
---|
| 112 | } |
---|
| 113 | } |
---|
| 114 | catch (Exception e) { |
---|
| 115 | setReason(e.getMessage()); |
---|
| 116 | return false; |
---|
| 117 | } |
---|
| 118 | return true; |
---|
| 119 | } |
---|
| 120 | } |
---|