e : bucketList.entrySet()) {
119 |
120 | Element bucket = doc.createElement("Bucket");
121 |
122 | bucket.appendChild(createElement(doc, "Name", e.getKey()));
123 | bucket.appendChild(createElement(doc, "CreationDate", "1982-07-07T16:41:58.000Z"));
124 |
125 | buckets.appendChild(bucket);
126 | }
127 | rootElement.appendChild(buckets);
128 |
129 | return doc;
130 |
131 | }
132 |
133 | public String stringFromDoc(Document doc) {
134 | DOMImplementation impl = doc.getImplementation();
135 | DOMImplementationLS implLS = (DOMImplementationLS) impl.getFeature("LS", "3.0");
136 | LSSerializer lsSerializer = implLS.createLSSerializer();
137 | lsSerializer.getDomConfig().setParameter("format-pretty-print", true);
138 |
139 | LSOutput lsOutput = implLS.createLSOutput();
140 | lsOutput.setEncoding("UTF-8");
141 | Writer stringWriter = new StringWriter();
142 | lsOutput.setCharacterStream(stringWriter);
143 | lsSerializer.write(doc, lsOutput);
144 |
145 | return stringWriter.toString();
146 | }
147 |
148 | Document noSuchKey(String id) {
149 | Document doc = this.docBuilder.newDocument();
150 | doc.setXmlVersion("1.0");
151 |
152 | Element rootElement = doc.createElement("Error");
153 | rootElement.setAttribute("xmlns", "http://doc.s3.amazonaws.com/2006-03-01");
154 | doc.appendChild(rootElement);
155 |
156 | rootElement.appendChild(createElement(doc, "Message", "The resource you requested does not exist"));
157 | rootElement.appendChild(createElement(doc, "Code", "NoSuchKey"));
158 | rootElement.appendChild(createElement(doc, "Resource", id));
159 |
160 | return doc;
161 | }
162 | }
163 |
--------------------------------------------------------------------------------
/src/main/java/at/ac/ait/archistar/trustmanager/SSLContextFactory.java:
--------------------------------------------------------------------------------
1 | package at.ac.ait.archistar.trustmanager;
2 |
3 | import io.netty.handler.ssl.SslHandler;
4 | import java.io.IOException;
5 | import java.security.KeyManagementException;
6 |
7 | import java.security.KeyStore;
8 | import java.security.KeyStoreException;
9 | import java.security.NoSuchAlgorithmException;
10 | import java.security.SecureRandom;
11 | import java.security.Security;
12 | import java.security.UnrecoverableKeyException;
13 | import java.security.cert.CertificateException;
14 |
15 | import javax.net.ssl.KeyManager;
16 | import javax.net.ssl.KeyManagerFactory;
17 | import javax.net.ssl.SSLContext;
18 | import javax.net.ssl.SSLEngine;
19 | import javax.net.ssl.TrustManager;
20 |
21 | /**
22 | * Creates a bogus {@link SSLContext}. A client-side context created by this
23 | * factory accepts any certificate even if it is invalid. A server-side context
24 | * created by this factory sends a bogus certificate defined in
25 | * {@link SecureChatKeyStore}.
26 | *
27 | * You will have to create your context differently in a real world application.
28 | *
29 | *
Client Certificate Authentication
30 | *
31 | * To enable client certificate authentication:
32 | *
33 | * - Enable client authentication on the server side by calling
34 | * {@link SSLEngine#setNeedClientAuth(boolean)} before creating
35 | * {@link SslHandler}.
36 | * - When initializing an {@link SSLContext} on the client side, specify the
37 | * {@link KeyManager} that contains the client certificate as the first argument
38 | * of {@link SSLContext#init(KeyManager[], TrustManager[], SecureRandom)}.
39 | * - When initializing an {@link SSLContext} on the server side, specify the
40 | * proper {@link TrustManager} as the second argument of
41 | * {@link SSLContext#init(KeyManager[], TrustManager[], SecureRandom)} to
42 | * validate the client certificate.
43 | *
44 | */
45 | public final class SSLContextFactory {
46 |
47 | private static final String PROTOCOL = "TLS";
48 | private static final SSLContext SERVER_CONTEXT;
49 | private static final SSLContext CLIENT_CONTEXT;
50 |
51 | static {
52 | String algorithm = Security.getProperty("ssl.KeyManagerFactory.algorithm");
53 | if (algorithm == null) {
54 | algorithm = "SunX509";
55 | }
56 |
57 | SSLContext serverContext;
58 | SSLContext clientContext;
59 | try {
60 | KeyStore ks = KeyStore.getInstance("JKS");
61 | ks.load(SecureKeyStore.asInputStream(),
62 | SecureKeyStore.getKeyStorePassword());
63 |
64 | // Set up key manager factory to use our key store
65 | KeyManagerFactory kmf = KeyManagerFactory.getInstance(algorithm);
66 | kmf.init(ks, SecureKeyStore.getCertificatePassword());
67 |
68 | // Initialize the SSLContext to work with our key managers.
69 | serverContext = SSLContext.getInstance(PROTOCOL);
70 | serverContext.init(kmf.getKeyManagers(), null, null);
71 | } catch (KeyStoreException | IOException | NoSuchAlgorithmException | CertificateException | UnrecoverableKeyException | KeyManagementException e) {
72 | throw new Error(
73 | "Failed to initialize the server-side SSLContext", e);
74 | }
75 |
76 | try {
77 | clientContext = SSLContext.getInstance(PROTOCOL);
78 | clientContext.init(null, TrustManagerFactory.getTrustManagers(), null);
79 | } catch (NoSuchAlgorithmException | KeyManagementException e) {
80 | throw new Error(
81 | "Failed to initialize the client-side SSLContext", e);
82 | }
83 |
84 | SERVER_CONTEXT = serverContext;
85 | CLIENT_CONTEXT = clientContext;
86 | }
87 |
88 | public static SSLContext getServerContext() {
89 | return SERVER_CONTEXT;
90 | }
91 |
92 | public static SSLContext getClientContext() {
93 | return CLIENT_CONTEXT;
94 | }
95 |
96 | private SSLContextFactory() {
97 | // Unused
98 | }
99 | }
100 |
--------------------------------------------------------------------------------
/src/main/java/at/ac/ait/archistar/trustmanager/SecureKeyStore.java:
--------------------------------------------------------------------------------
1 | package at.ac.ait.archistar.trustmanager;
2 |
3 | import java.io.ByteArrayInputStream;
4 | import java.io.InputStream;
5 |
6 | /**
7 | * A bogus key store which provides all the required information to create an
8 | * example SSL connection.
9 | *
10 | * To generate a bogus key store:
11 | *
12 | * keytool -genkey -alias securechat -keysize 2048 -validity 36500
13 | * -keyalg RSA -dname "CN=securechat"
14 | * -keypass secret -storepass secret
15 | * -keystore cert.jks
16 | *
17 | */
18 | public final class SecureKeyStore {
19 |
20 | private static final short[] DATA = {
21 | 0xfe, 0xed, 0xfe, 0xed, 0x00, 0x00, 0x00, 0x02,
22 | 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x01,
23 | 0x00, 0x07, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c,
24 | 0x65, 0x00, 0x00, 0x01, 0x1a, 0x9f, 0x57, 0xa5,
25 | 0x27, 0x00, 0x00, 0x01, 0x9a, 0x30, 0x82, 0x01,
26 | 0x96, 0x30, 0x0e, 0x06, 0x0a, 0x2b, 0x06, 0x01,
27 | 0x04, 0x01, 0x2a, 0x02, 0x11, 0x01, 0x01, 0x05,
28 | 0x00, 0x04, 0x82, 0x01, 0x82, 0x48, 0x6d, 0xcf,
29 | 0x16, 0xb5, 0x50, 0x95, 0x36, 0xbf, 0x47, 0x27,
30 | 0x50, 0x58, 0x0d, 0xa2, 0x52, 0x7e, 0x25, 0xab,
31 | 0x14, 0x1a, 0x26, 0x5e, 0x2d, 0x8a, 0x23, 0x90,
32 | 0x60, 0x7f, 0x12, 0x20, 0x56, 0xd1, 0x43, 0xa2,
33 | 0x6b, 0x47, 0x5d, 0xed, 0x9d, 0xd4, 0xe5, 0x83,
34 | 0x28, 0x89, 0xc2, 0x16, 0x4c, 0x76, 0x06, 0xad,
35 | 0x8e, 0x8c, 0x29, 0x1a, 0x9b, 0x0f, 0xdd, 0x60,
36 | 0x4b, 0xb4, 0x62, 0x82, 0x9e, 0x4a, 0x63, 0x83,
37 | 0x2e, 0xd2, 0x43, 0x78, 0xc2, 0x32, 0x1f, 0x60,
38 | 0xa9, 0x8a, 0x7f, 0x0f, 0x7c, 0xa6, 0x1d, 0xe6,
39 | 0x92, 0x9e, 0x52, 0xc7, 0x7d, 0xbb, 0x35, 0x3b,
40 | 0xaa, 0x89, 0x73, 0x4c, 0xfb, 0x99, 0x54, 0x97,
41 | 0x99, 0x28, 0x6e, 0x66, 0x5b, 0xf7, 0x9b, 0x7e,
42 | 0x6d, 0x8a, 0x2f, 0xfa, 0xc3, 0x1e, 0x71, 0xb9,
43 | 0xbd, 0x8f, 0xc5, 0x63, 0x25, 0x31, 0x20, 0x02,
44 | 0xff, 0x02, 0xf0, 0xc9, 0x2c, 0xdd, 0x3a, 0x10,
45 | 0x30, 0xab, 0xe5, 0xad, 0x3d, 0x1a, 0x82, 0x77,
46 | 0x46, 0xed, 0x03, 0x38, 0xa4, 0x73, 0x6d, 0x36,
47 | 0x36, 0x33, 0x70, 0xb2, 0x63, 0x20, 0xca, 0x03,
48 | 0xbf, 0x5a, 0xf4, 0x7c, 0x35, 0xf0, 0x63, 0x1a,
49 | 0x12, 0x33, 0x12, 0x58, 0xd9, 0xa2, 0x63, 0x6b,
50 | 0x63, 0x82, 0x41, 0x65, 0x70, 0x37, 0x4b, 0x99,
51 | 0x04, 0x9f, 0xdd, 0x5e, 0x07, 0x01, 0x95, 0x9f,
52 | 0x36, 0xe8, 0xc3, 0x66, 0x2a, 0x21, 0x69, 0x68,
53 | 0x40, 0xe6, 0xbc, 0xbb, 0x85, 0x81, 0x21, 0x13,
54 | 0xe6, 0xa4, 0xcf, 0xd3, 0x67, 0xe3, 0xfd, 0x75,
55 | 0xf0, 0xdf, 0x83, 0xe0, 0xc5, 0x36, 0x09, 0xac,
56 | 0x1b, 0xd4, 0xf7, 0x2a, 0x23, 0x57, 0x1c, 0x5c,
57 | 0x0f, 0xf4, 0xcf, 0xa2, 0xcf, 0xf5, 0xbd, 0x9c,
58 | 0x69, 0x98, 0x78, 0x3a, 0x25, 0xe4, 0xfd, 0x85,
59 | 0x11, 0xcc, 0x7d, 0xef, 0xeb, 0x74, 0x60, 0xb1,
60 | 0xb7, 0xfb, 0x1f, 0x0e, 0x62, 0xff, 0xfe, 0x09,
61 | 0x0a, 0xc3, 0x80, 0x2f, 0x10, 0x49, 0x89, 0x78,
62 | 0xd2, 0x08, 0xfa, 0x89, 0x22, 0x45, 0x91, 0x21,
63 | 0xbc, 0x90, 0x3e, 0xad, 0xb3, 0x0a, 0xb4, 0x0e,
64 | 0x1c, 0xa1, 0x93, 0x92, 0xd8, 0x72, 0x07, 0x54,
65 | 0x60, 0xe7, 0x91, 0xfc, 0xd9, 0x3c, 0xe1, 0x6f,
66 | 0x08, 0xe4, 0x56, 0xf6, 0x0b, 0xb0, 0x3c, 0x39,
67 | 0x8a, 0x2d, 0x48, 0x44, 0x28, 0x13, 0xca, 0xe9,
68 | 0xf7, 0xa3, 0xb6, 0x8a, 0x5f, 0x31, 0xa9, 0x72,
69 | 0xf2, 0xde, 0x96, 0xf2, 0xb1, 0x53, 0xb1, 0x3e,
70 | 0x24, 0x57, 0xfd, 0x18, 0x45, 0x1f, 0xc5, 0x33,
71 | 0x1b, 0xa4, 0xe8, 0x21, 0xfa, 0x0e, 0xb2, 0xb9,
72 | 0xcb, 0xc7, 0x07, 0x41, 0xdd, 0x2f, 0xb6, 0x6a,
73 | 0x23, 0x18, 0xed, 0xc1, 0xef, 0xe2, 0x4b, 0xec,
74 | 0xc9, 0xba, 0xfb, 0x46, 0x43, 0x90, 0xd7, 0xb5,
75 | 0x68, 0x28, 0x31, 0x2b, 0x8d, 0xa8, 0x51, 0x63,
76 | 0xf7, 0x53, 0x99, 0x19, 0x68, 0x85, 0x66, 0x00,
77 | 0x00, 0x00, 0x01, 0x00, 0x05, 0x58, 0x2e, 0x35,
78 | 0x30, 0x39, 0x00, 0x00, 0x02, 0x3a, 0x30, 0x82,
79 | 0x02, 0x36, 0x30, 0x82, 0x01, 0xe0, 0xa0, 0x03,
80 | 0x02, 0x01, 0x02, 0x02, 0x04, 0x48, 0x59, 0xf1,
81 | 0x92, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48,
82 | 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x05, 0x05, 0x00,
83 | 0x30, 0x81, 0xa0, 0x31, 0x0b, 0x30, 0x09, 0x06,
84 | 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x4b, 0x52,
85 | 0x31, 0x13, 0x30, 0x11, 0x06, 0x03, 0x55, 0x04,
86 | 0x08, 0x13, 0x0a, 0x4b, 0x79, 0x75, 0x6e, 0x67,
87 | 0x67, 0x69, 0x2d, 0x64, 0x6f, 0x31, 0x14, 0x30,
88 | 0x12, 0x06, 0x03, 0x55, 0x04, 0x07, 0x13, 0x0b,
89 | 0x53, 0x65, 0x6f, 0x6e, 0x67, 0x6e, 0x61, 0x6d,
90 | 0x2d, 0x73, 0x69, 0x31, 0x1a, 0x30, 0x18, 0x06,
91 | 0x03, 0x55, 0x04, 0x0a, 0x13, 0x11, 0x54, 0x68,
92 | 0x65, 0x20, 0x4e, 0x65, 0x74, 0x74, 0x79, 0x20,
93 | 0x50, 0x72, 0x6f, 0x6a, 0x65, 0x63, 0x74, 0x31,
94 | 0x18, 0x30, 0x16, 0x06, 0x03, 0x55, 0x04, 0x0b,
95 | 0x13, 0x0f, 0x45, 0x78, 0x61, 0x6d, 0x70, 0x6c,
96 | 0x65, 0x20, 0x41, 0x75, 0x74, 0x68, 0x6f, 0x72,
97 | 0x73, 0x31, 0x30, 0x30, 0x2e, 0x06, 0x03, 0x55,
98 | 0x04, 0x03, 0x13, 0x27, 0x73, 0x65, 0x63, 0x75,
99 | 0x72, 0x65, 0x63, 0x68, 0x61, 0x74, 0x2e, 0x65,
100 | 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x2e, 0x6e,
101 | 0x65, 0x74, 0x74, 0x79, 0x2e, 0x67, 0x6c, 0x65,
102 | 0x61, 0x6d, 0x79, 0x6e, 0x6f, 0x64, 0x65, 0x2e,
103 | 0x6e, 0x65, 0x74, 0x30, 0x20, 0x17, 0x0d, 0x30,
104 | 0x38, 0x30, 0x36, 0x31, 0x39, 0x30, 0x35, 0x34,
105 | 0x31, 0x33, 0x38, 0x5a, 0x18, 0x0f, 0x32, 0x31,
106 | 0x38, 0x37, 0x31, 0x31, 0x32, 0x34, 0x30, 0x35,
107 | 0x34, 0x31, 0x33, 0x38, 0x5a, 0x30, 0x81, 0xa0,
108 | 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04,
109 | 0x06, 0x13, 0x02, 0x4b, 0x52, 0x31, 0x13, 0x30,
110 | 0x11, 0x06, 0x03, 0x55, 0x04, 0x08, 0x13, 0x0a,
111 | 0x4b, 0x79, 0x75, 0x6e, 0x67, 0x67, 0x69, 0x2d,
112 | 0x64, 0x6f, 0x31, 0x14, 0x30, 0x12, 0x06, 0x03,
113 | 0x55, 0x04, 0x07, 0x13, 0x0b, 0x53, 0x65, 0x6f,
114 | 0x6e, 0x67, 0x6e, 0x61, 0x6d, 0x2d, 0x73, 0x69,
115 | 0x31, 0x1a, 0x30, 0x18, 0x06, 0x03, 0x55, 0x04,
116 | 0x0a, 0x13, 0x11, 0x54, 0x68, 0x65, 0x20, 0x4e,
117 | 0x65, 0x74, 0x74, 0x79, 0x20, 0x50, 0x72, 0x6f,
118 | 0x6a, 0x65, 0x63, 0x74, 0x31, 0x18, 0x30, 0x16,
119 | 0x06, 0x03, 0x55, 0x04, 0x0b, 0x13, 0x0f, 0x45,
120 | 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x20, 0x41,
121 | 0x75, 0x74, 0x68, 0x6f, 0x72, 0x73, 0x31, 0x30,
122 | 0x30, 0x2e, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13,
123 | 0x27, 0x73, 0x65, 0x63, 0x75, 0x72, 0x65, 0x63,
124 | 0x68, 0x61, 0x74, 0x2e, 0x65, 0x78, 0x61, 0x6d,
125 | 0x70, 0x6c, 0x65, 0x2e, 0x6e, 0x65, 0x74, 0x74,
126 | 0x79, 0x2e, 0x67, 0x6c, 0x65, 0x61, 0x6d, 0x79,
127 | 0x6e, 0x6f, 0x64, 0x65, 0x2e, 0x6e, 0x65, 0x74,
128 | 0x30, 0x5c, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86,
129 | 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05,
130 | 0x00, 0x03, 0x4b, 0x00, 0x30, 0x48, 0x02, 0x41,
131 | 0x00, 0xc3, 0xe3, 0x5e, 0x41, 0xa7, 0x87, 0x11,
132 | 0x00, 0x42, 0x2a, 0xb0, 0x4b, 0xed, 0xb2, 0xe0,
133 | 0x23, 0xdb, 0xb1, 0x3d, 0x58, 0x97, 0x35, 0x60,
134 | 0x0b, 0x82, 0x59, 0xd3, 0x00, 0xea, 0xd4, 0x61,
135 | 0xb8, 0x79, 0x3f, 0xb6, 0x3c, 0x12, 0x05, 0x93,
136 | 0x2e, 0x9a, 0x59, 0x68, 0x14, 0x77, 0x3a, 0xc8,
137 | 0x50, 0x25, 0x57, 0xa4, 0x49, 0x18, 0x63, 0x41,
138 | 0xf0, 0x2d, 0x28, 0xec, 0x06, 0xfb, 0xb4, 0x9f,
139 | 0xbf, 0x02, 0x03, 0x01, 0x00, 0x01, 0x30, 0x0d,
140 | 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d,
141 | 0x01, 0x01, 0x05, 0x05, 0x00, 0x03, 0x41, 0x00,
142 | 0x65, 0x6c, 0x30, 0x01, 0xc2, 0x8e, 0x3e, 0xcb,
143 | 0xb3, 0x77, 0x48, 0xe9, 0x66, 0x61, 0x9a, 0x40,
144 | 0x86, 0xaf, 0xf6, 0x03, 0xeb, 0xba, 0x6a, 0xf2,
145 | 0xfd, 0xe2, 0xaf, 0x36, 0x5e, 0x7b, 0xaa, 0x22,
146 | 0x04, 0xdd, 0x2c, 0x20, 0xc4, 0xfc, 0xdd, 0xd0,
147 | 0x82, 0x20, 0x1c, 0x3d, 0xd7, 0x9e, 0x5e, 0x5c,
148 | 0x92, 0x5a, 0x76, 0x71, 0x28, 0xf5, 0x07, 0x7d,
149 | 0xa2, 0x81, 0xba, 0x77, 0x9f, 0x2a, 0xd9, 0x44,
150 | 0x00, 0x00, 0x00, 0x01, 0x00, 0x05, 0x6d, 0x79,
151 | 0x6b, 0x65, 0x79, 0x00, 0x00, 0x01, 0x1a, 0x9f,
152 | 0x5b, 0x56, 0xa0, 0x00, 0x00, 0x01, 0x99, 0x30,
153 | 0x82, 0x01, 0x95, 0x30, 0x0e, 0x06, 0x0a, 0x2b,
154 | 0x06, 0x01, 0x04, 0x01, 0x2a, 0x02, 0x11, 0x01,
155 | 0x01, 0x05, 0x00, 0x04, 0x82, 0x01, 0x81, 0x29,
156 | 0xa8, 0xb6, 0x08, 0x0c, 0x85, 0x75, 0x3e, 0xdd,
157 | 0xb5, 0xe5, 0x1a, 0x87, 0x68, 0xd1, 0x90, 0x4b,
158 | 0x29, 0x31, 0xee, 0x90, 0xbc, 0x9d, 0x73, 0xa0,
159 | 0x3f, 0xe9, 0x0b, 0xa4, 0xef, 0x30, 0x9b, 0x36,
160 | 0x9a, 0xb2, 0x54, 0x77, 0x81, 0x07, 0x4b, 0xaa,
161 | 0xa5, 0x77, 0x98, 0xe1, 0xeb, 0xb5, 0x7c, 0x4e,
162 | 0x48, 0xd5, 0x08, 0xfc, 0x2c, 0x36, 0xe2, 0x65,
163 | 0x03, 0xac, 0xe5, 0xf3, 0x96, 0xb7, 0xd0, 0xb5,
164 | 0x3b, 0x92, 0xe4, 0x14, 0x05, 0x7a, 0x6a, 0x92,
165 | 0x56, 0xfe, 0x4e, 0xab, 0xd3, 0x0e, 0x32, 0x04,
166 | 0x22, 0x22, 0x74, 0x47, 0x7d, 0xec, 0x21, 0x99,
167 | 0x30, 0x31, 0x64, 0x46, 0x64, 0x9b, 0xc7, 0x13,
168 | 0xbf, 0xbe, 0xd0, 0x31, 0x49, 0xe7, 0x3c, 0xbf,
169 | 0xba, 0xb1, 0x20, 0xf9, 0x42, 0xf4, 0xa9, 0xa9,
170 | 0xe5, 0x13, 0x65, 0x32, 0xbf, 0x7c, 0xcc, 0x91,
171 | 0xd3, 0xfd, 0x24, 0x47, 0x0b, 0xe5, 0x53, 0xad,
172 | 0x50, 0x30, 0x56, 0xd1, 0xfa, 0x9c, 0x37, 0xa8,
173 | 0xc1, 0xce, 0xf6, 0x0b, 0x18, 0xaa, 0x7c, 0xab,
174 | 0xbd, 0x1f, 0xdf, 0xe4, 0x80, 0xb8, 0xa7, 0xe0,
175 | 0xad, 0x7d, 0x50, 0x74, 0xf1, 0x98, 0x78, 0xbc,
176 | 0x58, 0xb9, 0xc2, 0x52, 0xbe, 0xd2, 0x5b, 0x81,
177 | 0x94, 0x83, 0x8f, 0xb9, 0x4c, 0xee, 0x01, 0x2b,
178 | 0x5e, 0xc9, 0x6e, 0x9b, 0xf5, 0x63, 0x69, 0xe4,
179 | 0xd8, 0x0b, 0x47, 0xd8, 0xfd, 0xd8, 0xe0, 0xed,
180 | 0xa8, 0x27, 0x03, 0x74, 0x1e, 0x5d, 0x32, 0xe6,
181 | 0x5c, 0x63, 0xc2, 0xfb, 0x3f, 0xee, 0xb4, 0x13,
182 | 0xc6, 0x0e, 0x6e, 0x74, 0xe0, 0x22, 0xac, 0xce,
183 | 0x79, 0xf9, 0x43, 0x68, 0xc1, 0x03, 0x74, 0x2b,
184 | 0xe1, 0x18, 0xf8, 0x7f, 0x76, 0x9a, 0xea, 0x82,
185 | 0x3f, 0xc2, 0xa6, 0xa7, 0x4c, 0xfe, 0xae, 0x29,
186 | 0x3b, 0xc1, 0x10, 0x7c, 0xd5, 0x77, 0x17, 0x79,
187 | 0x5f, 0xcb, 0xad, 0x1f, 0xd8, 0xa1, 0xfd, 0x90,
188 | 0xe1, 0x6b, 0xb2, 0xef, 0xb9, 0x41, 0x26, 0xa4,
189 | 0x0b, 0x4f, 0xc6, 0x83, 0x05, 0x6f, 0xf0, 0x64,
190 | 0x40, 0xe1, 0x44, 0xc4, 0xf9, 0x40, 0x2b, 0x3b,
191 | 0x40, 0xdb, 0xaf, 0x35, 0xa4, 0x9b, 0x9f, 0xc4,
192 | 0x74, 0x07, 0xe5, 0x18, 0x60, 0xc5, 0xfe, 0x15,
193 | 0x0e, 0x3a, 0x25, 0x2a, 0x11, 0xee, 0x78, 0x2f,
194 | 0xb8, 0xd1, 0x6e, 0x4e, 0x3c, 0x0a, 0xb5, 0xb9,
195 | 0x40, 0x86, 0x27, 0x6d, 0x8f, 0x53, 0xb7, 0x77,
196 | 0x36, 0xec, 0x5d, 0xed, 0x32, 0x40, 0x43, 0x82,
197 | 0xc3, 0x52, 0x58, 0xc4, 0x26, 0x39, 0xf3, 0xb3,
198 | 0xad, 0x58, 0xab, 0xb7, 0xf7, 0x8e, 0x0e, 0xba,
199 | 0x8e, 0x78, 0x9d, 0xbf, 0x58, 0x34, 0xbd, 0x77,
200 | 0x73, 0xa6, 0x50, 0x55, 0x00, 0x60, 0x26, 0xbf,
201 | 0x6d, 0xb4, 0x98, 0x8a, 0x18, 0x83, 0x89, 0xf8,
202 | 0xcd, 0x0d, 0x49, 0x06, 0xae, 0x51, 0x6e, 0xaf,
203 | 0xbd, 0xe2, 0x07, 0x13, 0xd8, 0x64, 0xcc, 0xbf,
204 | 0x00, 0x00, 0x00, 0x01, 0x00, 0x05, 0x58, 0x2e,
205 | 0x35, 0x30, 0x39, 0x00, 0x00, 0x02, 0x34, 0x30,
206 | 0x82, 0x02, 0x30, 0x30, 0x82, 0x01, 0xda, 0xa0,
207 | 0x03, 0x02, 0x01, 0x02, 0x02, 0x04, 0x48, 0x59,
208 | 0xf2, 0x84, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86,
209 | 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x05, 0x05,
210 | 0x00, 0x30, 0x81, 0x9d, 0x31, 0x0b, 0x30, 0x09,
211 | 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x4b,
212 | 0x52, 0x31, 0x13, 0x30, 0x11, 0x06, 0x03, 0x55,
213 | 0x04, 0x08, 0x13, 0x0a, 0x4b, 0x79, 0x75, 0x6e,
214 | 0x67, 0x67, 0x69, 0x2d, 0x64, 0x6f, 0x31, 0x14,
215 | 0x30, 0x12, 0x06, 0x03, 0x55, 0x04, 0x07, 0x13,
216 | 0x0b, 0x53, 0x65, 0x6f, 0x6e, 0x67, 0x6e, 0x61,
217 | 0x6d, 0x2d, 0x73, 0x69, 0x31, 0x1a, 0x30, 0x18,
218 | 0x06, 0x03, 0x55, 0x04, 0x0a, 0x13, 0x11, 0x54,
219 | 0x68, 0x65, 0x20, 0x4e, 0x65, 0x74, 0x74, 0x79,
220 | 0x20, 0x50, 0x72, 0x6f, 0x6a, 0x65, 0x63, 0x74,
221 | 0x31, 0x15, 0x30, 0x13, 0x06, 0x03, 0x55, 0x04,
222 | 0x0b, 0x13, 0x0c, 0x43, 0x6f, 0x6e, 0x74, 0x72,
223 | 0x69, 0x62, 0x75, 0x74, 0x6f, 0x72, 0x73, 0x31,
224 | 0x30, 0x30, 0x2e, 0x06, 0x03, 0x55, 0x04, 0x03,
225 | 0x13, 0x27, 0x73, 0x65, 0x63, 0x75, 0x72, 0x65,
226 | 0x63, 0x68, 0x61, 0x74, 0x2e, 0x65, 0x78, 0x61,
227 | 0x6d, 0x70, 0x6c, 0x65, 0x2e, 0x6e, 0x65, 0x74,
228 | 0x74, 0x79, 0x2e, 0x67, 0x6c, 0x65, 0x61, 0x6d,
229 | 0x79, 0x6e, 0x6f, 0x64, 0x65, 0x2e, 0x6e, 0x65,
230 | 0x74, 0x30, 0x20, 0x17, 0x0d, 0x30, 0x38, 0x30,
231 | 0x36, 0x31, 0x39, 0x30, 0x35, 0x34, 0x35, 0x34,
232 | 0x30, 0x5a, 0x18, 0x0f, 0x32, 0x31, 0x38, 0x37,
233 | 0x31, 0x31, 0x32, 0x33, 0x30, 0x35, 0x34, 0x35,
234 | 0x34, 0x30, 0x5a, 0x30, 0x81, 0x9d, 0x31, 0x0b,
235 | 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13,
236 | 0x02, 0x4b, 0x52, 0x31, 0x13, 0x30, 0x11, 0x06,
237 | 0x03, 0x55, 0x04, 0x08, 0x13, 0x0a, 0x4b, 0x79,
238 | 0x75, 0x6e, 0x67, 0x67, 0x69, 0x2d, 0x64, 0x6f,
239 | 0x31, 0x14, 0x30, 0x12, 0x06, 0x03, 0x55, 0x04,
240 | 0x07, 0x13, 0x0b, 0x53, 0x65, 0x6f, 0x6e, 0x67,
241 | 0x6e, 0x61, 0x6d, 0x2d, 0x73, 0x69, 0x31, 0x1a,
242 | 0x30, 0x18, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x13,
243 | 0x11, 0x54, 0x68, 0x65, 0x20, 0x4e, 0x65, 0x74,
244 | 0x74, 0x79, 0x20, 0x50, 0x72, 0x6f, 0x6a, 0x65,
245 | 0x63, 0x74, 0x31, 0x15, 0x30, 0x13, 0x06, 0x03,
246 | 0x55, 0x04, 0x0b, 0x13, 0x0c, 0x43, 0x6f, 0x6e,
247 | 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x6f, 0x72,
248 | 0x73, 0x31, 0x30, 0x30, 0x2e, 0x06, 0x03, 0x55,
249 | 0x04, 0x03, 0x13, 0x27, 0x73, 0x65, 0x63, 0x75,
250 | 0x72, 0x65, 0x63, 0x68, 0x61, 0x74, 0x2e, 0x65,
251 | 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x2e, 0x6e,
252 | 0x65, 0x74, 0x74, 0x79, 0x2e, 0x67, 0x6c, 0x65,
253 | 0x61, 0x6d, 0x79, 0x6e, 0x6f, 0x64, 0x65, 0x2e,
254 | 0x6e, 0x65, 0x74, 0x30, 0x5c, 0x30, 0x0d, 0x06,
255 | 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01,
256 | 0x01, 0x01, 0x05, 0x00, 0x03, 0x4b, 0x00, 0x30,
257 | 0x48, 0x02, 0x41, 0x00, 0x95, 0xb3, 0x47, 0x17,
258 | 0x95, 0x0f, 0x57, 0xcf, 0x66, 0x72, 0x0a, 0x7e,
259 | 0x5b, 0x54, 0xea, 0x8c, 0x6f, 0x79, 0xde, 0x94,
260 | 0xac, 0x0b, 0x5a, 0xd4, 0xd6, 0x1b, 0x58, 0x12,
261 | 0x1a, 0x16, 0x3d, 0xfe, 0xdf, 0xa5, 0x2b, 0x86,
262 | 0xbc, 0x64, 0xd4, 0x80, 0x1e, 0x3f, 0xf9, 0xe2,
263 | 0x04, 0x03, 0x79, 0x9b, 0xc1, 0x5c, 0xf0, 0xf1,
264 | 0xf3, 0xf1, 0xe3, 0xbf, 0x3f, 0xc0, 0x1f, 0xdd,
265 | 0xdb, 0xc0, 0x5b, 0x21, 0x02, 0x03, 0x01, 0x00,
266 | 0x01, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48,
267 | 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x05, 0x05, 0x00,
268 | 0x03, 0x41, 0x00, 0x02, 0xd7, 0xdd, 0xbd, 0x0c,
269 | 0x8e, 0x21, 0x20, 0xef, 0x9e, 0x4f, 0x1f, 0xf5,
270 | 0x49, 0xf1, 0xae, 0x58, 0x9b, 0x94, 0x3a, 0x1f,
271 | 0x70, 0x33, 0xf0, 0x9b, 0xbb, 0xe9, 0xc0, 0xf3,
272 | 0x72, 0xcb, 0xde, 0xb6, 0x56, 0x72, 0xcc, 0x1c,
273 | 0xf0, 0xd6, 0x5a, 0x2a, 0xbc, 0xa1, 0x7e, 0x23,
274 | 0x83, 0xe9, 0xe7, 0xcf, 0x9e, 0xa5, 0xf9, 0xcc,
275 | 0xc2, 0x61, 0xf4, 0xdb, 0x40, 0x93, 0x1d, 0x63,
276 | 0x8a, 0x50, 0x4c, 0x11, 0x39, 0xb1, 0x91, 0xc1,
277 | 0xe6, 0x9d, 0xd9, 0x1a, 0x62, 0x1b, 0xb8, 0xd3,
278 | 0xd6, 0x9a, 0x6d, 0xb9, 0x8e, 0x15, 0x51};
279 |
280 | public static InputStream asInputStream() {
281 | byte[] data = new byte[DATA.length];
282 | for (int i = 0; i < data.length; i++) {
283 | data[i] = (byte) DATA[i];
284 | }
285 | return new ByteArrayInputStream(data);
286 | }
287 |
288 | public static char[] getCertificatePassword() {
289 | return "secret".toCharArray();
290 | }
291 |
292 | public static char[] getKeyStorePassword() {
293 | return "secret".toCharArray();
294 | }
295 |
296 | private SecureKeyStore() {
297 | // Unused
298 | }
299 | }
300 |
--------------------------------------------------------------------------------
/src/main/java/at/ac/ait/archistar/trustmanager/TrustManagerFactory.java:
--------------------------------------------------------------------------------
1 | package at.ac.ait.archistar.trustmanager;
2 |
3 | import javax.net.ssl.ManagerFactoryParameters;
4 | import javax.net.ssl.TrustManager;
5 | import javax.net.ssl.TrustManagerFactorySpi;
6 | import javax.net.ssl.X509TrustManager;
7 | import java.security.InvalidAlgorithmParameterException;
8 | import java.security.KeyStore;
9 | import java.security.KeyStoreException;
10 | import java.security.cert.X509Certificate;
11 |
12 | /**
13 | * Bogus {@link TrustManagerFactorySpi} which accepts any certificate even if it
14 | * is invalid.
15 | */
16 | public class TrustManagerFactory extends TrustManagerFactorySpi {
17 |
18 | private static final TrustManager DUMMY_TRUST_MANAGER = new X509TrustManager() {
19 | @Override
20 | public X509Certificate[] getAcceptedIssuers() {
21 | return new X509Certificate[0];
22 | }
23 |
24 | @Override
25 | public void checkClientTrusted(X509Certificate[] chain, String authType) {
26 | // Always trust - it is an example.
27 | // You should do something in the real world.
28 | // You will reach here only if you enabled client certificate auth,
29 | // as described in SecureChatSslContextFactory.
30 | }
31 |
32 | @Override
33 | public void checkServerTrusted(X509Certificate[] chain, String authType) {
34 | // Always trust - it is an example.
35 | // You should do something in the real world.
36 | }
37 | };
38 |
39 | public static TrustManager[] getTrustManagers() {
40 | return new TrustManager[]{DUMMY_TRUST_MANAGER};
41 | }
42 |
43 | @Override
44 | protected TrustManager[] engineGetTrustManagers() {
45 | return getTrustManagers();
46 | }
47 |
48 | @Override
49 | protected void engineInit(KeyStore keystore) throws KeyStoreException {
50 | // Unused
51 | }
52 |
53 | @Override
54 | protected void engineInit(ManagerFactoryParameters managerFactoryParameters)
55 | throws InvalidAlgorithmParameterException {
56 | // Unused
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/src/test/java/at/ac/ait/archistar/cryptoengine/MirrorTest.java:
--------------------------------------------------------------------------------
1 | package at.ac.ait.archistar.cryptoengine;
2 |
3 | import static org.fest.assertions.api.Assertions.*;
4 |
5 | import org.junit.BeforeClass;
6 | import org.junit.Test;
7 |
8 | import at.ac.ait.archistar.engine.crypto.PseudoMirrorCryptoEngine;
9 | import at.archistar.crypto.CryptoEngine;
10 | import at.archistar.crypto.data.Share;
11 | import at.archistar.crypto.secretsharing.ReconstructionException;
12 | import at.archistar.crypto.secretsharing.WeakSecurityException;
13 |
14 | public class MirrorTest {
15 |
16 | private static CryptoEngine cryptoEngine;
17 | private final static byte[] mockSerializedData = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
18 |
19 | @BeforeClass
20 | public static void onceSetup() {
21 | // GIVEN some test data
22 | cryptoEngine = new PseudoMirrorCryptoEngine(2);
23 | }
24 |
25 | @Test
26 | public void testIfCryptoEngineProducesEnoughFragments() throws WeakSecurityException {
27 | // WHEN i encrypt some data
28 | Share shares[] = cryptoEngine.share(mockSerializedData);
29 | assertThat(shares).hasSize(2);
30 | }
31 |
32 | @Test
33 | public void testIfMirroringWorks() throws WeakSecurityException {
34 | // WHEN i encrypt data
35 | Share shares[] = cryptoEngine.share(mockSerializedData);
36 |
37 | for(Share s : shares) {
38 | assertThat(s.getYValues()).isEqualTo(mockSerializedData);
39 | }
40 | }
41 |
42 | @Test
43 | public void testIfDecryptionProducesOriginalData() throws ReconstructionException, WeakSecurityException {
44 | Share shares[] = cryptoEngine.share(mockSerializedData);
45 |
46 | byte[] result = cryptoEngine.reconstruct(shares);
47 | assertThat(result).isEqualTo(mockSerializedData);
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/src/test/java/at/ac/ait/archistar/cryptoengine/TestSecretSharingCryptoEngine.java:
--------------------------------------------------------------------------------
1 | package at.ac.ait.archistar.cryptoengine;
2 |
3 | import static org.fest.assertions.api.Assertions.*;
4 |
5 | import java.util.HashSet;
6 | import java.util.Set;
7 |
8 | import org.junit.BeforeClass;
9 | import org.junit.Test;
10 |
11 | import at.ac.ait.archistar.backendserver.fragments.Fragment;
12 | import at.ac.ait.archistar.backendserver.fragments.RemoteFragment;
13 | import at.ac.ait.archistar.engine.crypto.ArchistarSMCIntegrator;
14 | import at.archistar.crypto.CryptoEngine;
15 | import at.archistar.crypto.RabinBenOrEngine;
16 | import at.archistar.crypto.secretsharing.ReconstructionException;
17 | import at.archistar.crypto.secretsharing.WeakSecurityException;
18 | import at.archistar.crypto.random.FakeRandomSource;
19 | import java.security.NoSuchAlgorithmException;
20 |
21 | public class TestSecretSharingCryptoEngine {
22 |
23 | private static CryptoEngine cryptoEngine;
24 | private final static byte[] mockSerializedData = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
25 |
26 | @BeforeClass
27 | public static void onceSetup() throws WeakSecurityException, NoSuchAlgorithmException {
28 | cryptoEngine = new RabinBenOrEngine(4, 3, new FakeRandomSource());
29 | }
30 |
31 | @Test
32 | public void testIfDecryptionProducesOriginalData() throws ReconstructionException {
33 |
34 | Set distribution = new HashSet<>();
35 | distribution.add(new RemoteFragment("frag-1"));
36 | distribution.add(new RemoteFragment("frag-2"));
37 | distribution.add(new RemoteFragment("frag-3"));
38 | distribution.add(new RemoteFragment("frag-4"));
39 |
40 | Set encrypted = ArchistarSMCIntegrator.encrypt(cryptoEngine, mockSerializedData, distribution);
41 |
42 | assertThat(encrypted.size()).isEqualTo(4);
43 |
44 | for (Fragment f : encrypted) {
45 | assertThat(f.getData()).isNotNull();
46 | assertThat(f.getData()).isNotEmpty();
47 | }
48 |
49 | byte[] result = ArchistarSMCIntegrator.decrypt(cryptoEngine, encrypted);
50 | assertThat(result).isNotNull().isEqualTo(mockSerializedData);
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/src/test/java/at/ac/ait/archistar/data/CustomSerializerTest.java:
--------------------------------------------------------------------------------
1 | package at.ac.ait.archistar.data;
2 |
3 | import static org.fest.assertions.api.Assertions.*;
4 |
5 | import java.util.HashMap;
6 | import java.util.Map;
7 |
8 | import org.junit.Before;
9 | import org.junit.Test;
10 |
11 | import at.ac.ait.archistar.engine.dataobjects.CustomSerializer;
12 | import at.ac.ait.archistar.engine.dataobjects.FSObject;
13 | import at.ac.ait.archistar.engine.dataobjects.SimpleFile;
14 |
15 | public class CustomSerializerTest {
16 |
17 | private static final String testData = "datadatadata";
18 | private static final String testFilename = "testfilename.dat";
19 | private CustomSerializer serializer;
20 | byte[] serializedData;
21 |
22 | @Before
23 | public void prepareTestdata() {
24 | Map metadata = new HashMap<>();
25 | metadata.put("key0", "value0");
26 | metadata.put("key1", "value1");
27 |
28 | byte[] testString = testData.getBytes();
29 |
30 | SimpleFile fs = new SimpleFile(testFilename, testString, metadata);
31 | serializer = new CustomSerializer();
32 | serializedData = serializer.serialize(fs);
33 | }
34 |
35 | @Test
36 | public void testDataWasCreated() {
37 | assertThat(serializedData).isNotNull();
38 | }
39 |
40 | @Test
41 | public void testDeserializationOfObject() {
42 | FSObject des = serializer.deserialize(serializedData);
43 | assertThat(des).isNotNull();
44 | }
45 |
46 | @Test
47 | public void testPathAfterDeserialization() {
48 | FSObject des = serializer.deserialize(serializedData);
49 | assertThat(des.getPath()).isEqualTo(testFilename);
50 | }
51 |
52 | @Test
53 | public void testMetadataAfterDeserialization() {
54 | FSObject des = serializer.deserialize(serializedData);
55 | assertThat(des.getMetadata()).contains(entry("key0", "value0"), entry("key1", "value1"));
56 | }
57 |
58 | @Test
59 | public void testDataAfterDeserialization() {
60 | FSObject des = serializer.deserialize(serializedData);
61 | assertThat(des).isInstanceOf(SimpleFile.class);
62 | String decoded = new String(((SimpleFile) des).getData());
63 | assertThat(decoded).isEqualTo(testData);
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/src/test/java/at/ac/ait/archistar/integration/AbstractIntegrationTest.java:
--------------------------------------------------------------------------------
1 | package at.ac.ait.archistar.integration;
2 |
3 | import java.util.HashMap;
4 | import java.util.Map;
5 | import java.util.UUID;
6 |
7 | import static org.fest.assertions.api.Assertions.*;
8 |
9 | import org.junit.Test;
10 |
11 | import at.ac.ait.archistar.backendserver.storageinterface.DisconnectedException;
12 | import at.ac.ait.archistar.backendserver.storageinterface.StorageServer;
13 | import at.ac.ait.archistar.engine.TestEngine;
14 | import at.ac.ait.archistar.engine.dataobjects.FSObject;
15 | import at.ac.ait.archistar.engine.dataobjects.SimpleFile;
16 | import at.ac.ait.archistar.engine.distributor.TestServerConfiguration;
17 | import at.archistar.crypto.secretsharing.ReconstructionException;
18 |
19 | public abstract class AbstractIntegrationTest {
20 |
21 | protected final static byte[] testData = {65, 66, 67, 68, 69, 70, 71, 72, 73, 74};
22 |
23 | protected Map servers;
24 |
25 | protected static TestEngine engine;
26 |
27 | protected static TestServerConfiguration serverConfig;
28 |
29 | protected String randomTestFilename() {
30 | return UUID.randomUUID().toString();
31 | }
32 |
33 | @Test
34 | public void testConnect() {
35 | assertThat(engine.connect()).isEqualTo(engine.getNumberOfServers());
36 | }
37 |
38 | @Test
39 | public void testStoreOperation() {
40 | engine.connect();
41 |
42 | SimpleFile testObject = new SimpleFile(randomTestFilename(), testData, new HashMap());
43 |
44 | try {
45 | /* get initial fragment count */
46 | HashMap fragCount = serverConfig.getStorageFragmentCounts();
47 |
48 | /* add one fragment per storage server */
49 | assertThat(engine.putObject(testObject)).isEqualTo(true);
50 |
51 | /* expect the operation to be executed at (at least) f+1 nodes. The other (3f+1)-(f+1)
52 | * nodes might still need longer to perform the operation or might be in error
53 | *
54 | * TODO: shouldn't this be 2f+1?
55 | */
56 | int increaseCount = 0;
57 | for (Map.Entry m : serverConfig.getStorageFragmentCounts().entrySet()) {
58 | int oldValue = fragCount.get(m.getKey());
59 |
60 | /* if index was newly created count goes from 0 -> 2, otherweise from n to n+1 */
61 | if (m.getValue() == (oldValue + 1) || m.getValue() == 2) {
62 | increaseCount++;
63 | } else {
64 | if (m.getValue() != 0) {
65 | fail("count wasnt old_count+1 " + m.getValue() + " vs " + oldValue);
66 | }
67 | }
68 | }
69 | assertThat(increaseCount).isGreaterThanOrEqualTo(2);
70 | } catch (DisconnectedException e) {
71 | fail("error while retrieving storage fragment count", e);
72 | }
73 | }
74 |
75 | @Test
76 | public void testStoreAndRetrieveOperation() throws ReconstructionException {
77 | SimpleFile testObject = new SimpleFile(randomTestFilename(), testData, new HashMap());
78 | String path = testObject.getPath();
79 |
80 | engine.connect();
81 | assertThat(engine.putObject(testObject)).isEqualTo(true);
82 | assertThat(testObject.getPath()).isEqualTo(path);
83 |
84 | FSObject retrObject = engine.getObject(path);
85 | assertThat(retrObject).isNotNull().isInstanceOf(SimpleFile.class);
86 | assertThat(path).isEqualTo(retrObject.getPath());
87 | assertThat(((SimpleFile) retrObject).getData()).isEqualTo(testData);
88 | }
89 | }
90 |
--------------------------------------------------------------------------------
/src/test/java/at/ac/ait/archistar/integration/BftTest.java:
--------------------------------------------------------------------------------
1 | package at.ac.ait.archistar.integration;
2 |
3 | import io.netty.channel.nio.NioEventLoopGroup;
4 |
5 | import java.util.HashSet;
6 |
7 | import org.junit.AfterClass;
8 | import org.junit.BeforeClass;
9 |
10 | import at.ac.ait.archistar.backendserver.storageinterface.MemoryStorage;
11 | import at.ac.ait.archistar.backendserver.storageinterface.StorageServer;
12 | import at.ac.ait.archistar.engine.TestEngine;
13 | import at.ac.ait.archistar.engine.distributor.BFTDistributor;
14 | import at.ac.ait.archistar.engine.distributor.Distributor;
15 | import at.ac.ait.archistar.engine.distributor.TestServerConfiguration;
16 | import at.ac.ait.archistar.engine.metadata.MetadataService;
17 | import at.ac.ait.archistar.engine.metadata.SimpleMetadataService;
18 | import at.archistar.crypto.CryptoEngine;
19 | import at.archistar.crypto.RabinBenOrEngine;
20 | import at.archistar.crypto.secretsharing.WeakSecurityException;
21 | import at.archistar.crypto.random.FakeRandomSource;
22 | import java.security.NoSuchAlgorithmException;
23 |
24 | public class BftTest extends AbstractIntegrationTest {
25 |
26 | @BeforeClass
27 | public static void prepareBftNetwork() throws NoSuchAlgorithmException, WeakSecurityException {
28 | /* test configuration */
29 | HashSet servers = new HashSet<>();
30 | for (int i = 0; i < 4; i ++) {
31 | servers.add(new MemoryStorage(i));
32 | }
33 | serverConfig = new TestServerConfiguration(servers);
34 |
35 | serverConfig.setupTestServer(1);
36 |
37 | CryptoEngine crypto = new RabinBenOrEngine(4, 3, new FakeRandomSource());
38 | Distributor distributor = new BFTDistributor(serverConfig, new NioEventLoopGroup());
39 | MetadataService metadata = new SimpleMetadataService(serverConfig, distributor, crypto);
40 | engine = new TestEngine(serverConfig, metadata, distributor, crypto);
41 | }
42 |
43 | @AfterClass
44 | public static void shutdownServers() {
45 | serverConfig.teardownTestServer();
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/src/test/java/at/ac/ait/archistar/integration/EncryptedFileSystemTest.java:
--------------------------------------------------------------------------------
1 | package at.ac.ait.archistar.integration;
2 |
3 | import static org.fest.assertions.api.Assertions.assertThat;
4 | import static org.fest.assertions.api.Assertions.fail;
5 |
6 | import io.netty.channel.nio.NioEventLoopGroup;
7 |
8 | import java.io.File;
9 | import java.util.HashMap;
10 | import java.util.HashSet;
11 | import java.util.Set;
12 | import java.util.UUID;
13 |
14 | import org.junit.AfterClass;
15 | import org.junit.BeforeClass;
16 | import org.junit.Test;
17 |
18 | import at.ac.ait.archistar.backendserver.storageinterface.FilesystemStorage;
19 | import at.ac.ait.archistar.backendserver.storageinterface.StorageServer;
20 | import at.ac.ait.archistar.engine.TestEngine;
21 | import at.ac.ait.archistar.engine.dataobjects.FSObject;
22 | import at.ac.ait.archistar.engine.dataobjects.SimpleFile;
23 | import at.ac.ait.archistar.engine.distributor.BFTDistributor;
24 | import at.ac.ait.archistar.engine.distributor.Distributor;
25 | import at.ac.ait.archistar.engine.distributor.TestServerConfiguration;
26 | import at.ac.ait.archistar.engine.metadata.MetadataService;
27 | import at.ac.ait.archistar.engine.metadata.SimpleMetadataService;
28 | import at.archistar.crypto.CryptoEngine;
29 | import at.archistar.crypto.RabinBenOrEngine;
30 | import at.archistar.crypto.secretsharing.ReconstructionException;
31 | import at.archistar.crypto.secretsharing.WeakSecurityException;
32 | import at.archistar.crypto.random.FakeRandomSource;
33 | import at.archistar.crypto.random.RandomSource;
34 | import java.security.NoSuchAlgorithmException;
35 |
36 | public class EncryptedFileSystemTest extends AbstractIntegrationTest {
37 |
38 | private static Set createNewServers() {
39 | File baseDir = new File("/tmp/test-encrypted-filesystem/" + UUID.randomUUID() + "/");
40 | baseDir.mkdirs();
41 |
42 | File dir1 = new File(baseDir, "1");
43 | dir1.mkdir();
44 | File dir2 = new File(baseDir, "2");
45 | dir2.mkdir();
46 | File dir3 = new File(baseDir, "3");
47 | dir3.mkdir();
48 | File dir4 = new File(baseDir, "4");
49 | dir4.mkdir();
50 |
51 | HashSet servers = new HashSet<>();
52 | servers.add(new FilesystemStorage(0, dir1));
53 | servers.add(new FilesystemStorage(1, dir2));
54 | servers.add(new FilesystemStorage(2, dir3));
55 | servers.add(new FilesystemStorage(3, dir4));
56 | return servers;
57 | }
58 |
59 | @Test
60 | public void testPersistedStoreAndRetrieveOperation() throws ReconstructionException {
61 | SimpleFile testObject = new SimpleFile(randomTestFilename(), testData, new HashMap());
62 | String path = testObject.getPath();
63 |
64 | // WHEN I connect engine and store a fragment
65 | engine.connect();
66 | engine.putObject(testObject);
67 |
68 | // AND I disconnect and reconnect
69 | engine.disconnect();
70 |
71 | assertThat(engine.connect()).isEqualTo(engine.getNumberOfServers());
72 |
73 | // THEN the data should still be available
74 | FSObject retrObject = engine.getObject(path);
75 | assertThat(retrObject).isNotNull().isInstanceOf(SimpleFile.class);
76 | assertThat(path).isEqualTo(retrObject.getPath());
77 | assertThat(((SimpleFile) retrObject).getData()).isEqualTo(testData);
78 | }
79 |
80 | @BeforeClass
81 | public static void prepareServer() throws WeakSecurityException, NoSuchAlgorithmException {
82 | serverConfig = new TestServerConfiguration(createNewServers());
83 | serverConfig.setupTestServer(1);
84 |
85 | RandomSource rng = new FakeRandomSource();
86 | CryptoEngine crypto = new RabinBenOrEngine(4, 3, rng);
87 | Distributor distributor = new BFTDistributor(serverConfig, new NioEventLoopGroup());
88 | MetadataService metadata = new SimpleMetadataService(serverConfig, distributor, crypto);
89 | engine = new TestEngine(serverConfig, metadata, distributor, crypto);
90 | }
91 |
92 | @AfterClass
93 | public static void shutdownServers() {
94 | serverConfig.teardownTestServer();
95 | }
96 | }
97 |
--------------------------------------------------------------------------------
/src/test/java/at/ac/ait/archistar/integration/FileSystemTest.java:
--------------------------------------------------------------------------------
1 | package at.ac.ait.archistar.integration;
2 |
3 | import io.netty.channel.nio.NioEventLoopGroup;
4 |
5 | import java.io.File;
6 | import java.util.HashMap;
7 | import java.util.HashSet;
8 | import java.util.Set;
9 | import java.util.UUID;
10 |
11 | import org.junit.AfterClass;
12 | import org.junit.BeforeClass;
13 | import org.junit.Test;
14 | import org.slf4j.Logger;
15 | import org.slf4j.LoggerFactory;
16 |
17 | import static org.fest.assertions.api.Assertions.*;
18 | import at.ac.ait.archistar.backendserver.storageinterface.FilesystemStorage;
19 | import at.ac.ait.archistar.backendserver.storageinterface.StorageServer;
20 | import at.ac.ait.archistar.engine.TestEngine;
21 | import at.ac.ait.archistar.engine.crypto.PseudoMirrorCryptoEngine;
22 | import at.ac.ait.archistar.engine.dataobjects.FSObject;
23 | import at.ac.ait.archistar.engine.dataobjects.SimpleFile;
24 | import at.ac.ait.archistar.engine.distributor.BFTDistributor;
25 | import at.ac.ait.archistar.engine.distributor.Distributor;
26 | import at.ac.ait.archistar.engine.distributor.TestServerConfiguration;
27 | import at.ac.ait.archistar.engine.metadata.MetadataService;
28 | import at.ac.ait.archistar.engine.metadata.SimpleMetadataService;
29 | import at.archistar.crypto.CryptoEngine;
30 | import at.archistar.crypto.secretsharing.ReconstructionException;
31 |
32 | public class FileSystemTest extends AbstractIntegrationTest {
33 |
34 | private final Logger logger = LoggerFactory.getLogger(FileSystemTest.class);
35 |
36 | private static Set createNewServers() {
37 | File baseDir = new File("/tmp/test-filesystem/" + UUID.randomUUID() + "/");
38 | baseDir.mkdirs();
39 |
40 | File dir1 = new File(baseDir, "1");
41 | dir1.mkdir();
42 | File dir2 = new File(baseDir, "2");
43 | dir2.mkdir();
44 | File dir3 = new File(baseDir, "3");
45 | dir3.mkdir();
46 | File dir4 = new File(baseDir, "4");
47 | dir4.mkdir();
48 |
49 | HashSet servers = new HashSet<>();
50 | servers.add(new FilesystemStorage(0, dir1));
51 | servers.add(new FilesystemStorage(1, dir2));
52 | servers.add(new FilesystemStorage(2, dir3));
53 | servers.add(new FilesystemStorage(3, dir4));
54 | return servers;
55 | }
56 |
57 | @BeforeClass
58 | public static void prepareServer() {
59 | serverConfig = new TestServerConfiguration(createNewServers());
60 | serverConfig.setupTestServer(1);
61 |
62 | CryptoEngine crypto = new PseudoMirrorCryptoEngine(4);
63 | Distributor distributor = new BFTDistributor(serverConfig, new NioEventLoopGroup());
64 | MetadataService metadata = new SimpleMetadataService(serverConfig, distributor, crypto);
65 | engine = new TestEngine(serverConfig, metadata, distributor, crypto);
66 | }
67 |
68 | @Test
69 | public void testPersistedStoreAndRetrieveOperation() throws ReconstructionException {
70 |
71 | logger.info("starting test");
72 | SimpleFile testObject = new SimpleFile(randomTestFilename(), testData, new HashMap());
73 | String path = testObject.getPath();
74 |
75 | // WHEN I connect engine and store a fragment
76 | engine.connect();
77 | engine.putObject(testObject);
78 |
79 | // AND I disconnect and reconnect
80 | engine.disconnect();
81 |
82 | logger.info("reconnecting");
83 | assertThat(engine.connect()).isEqualTo(engine.getNumberOfServers());
84 |
85 | // THEN the data should still be available
86 | FSObject retrObject = engine.getObject(path);
87 | assertThat(retrObject).isNotNull().isInstanceOf(SimpleFile.class);
88 | assertThat(path).isEqualTo(retrObject.getPath());
89 | assertThat(((SimpleFile) retrObject).getData()).isEqualTo(testData);
90 | }
91 |
92 | @AfterClass
93 | public static void shutdownServers() {
94 | serverConfig.teardownTestServer();
95 | }
96 | }
97 |
--------------------------------------------------------------------------------
/src/test/java/at/ac/ait/archistar/integration/MemoryOnlyTest.java:
--------------------------------------------------------------------------------
1 | package at.ac.ait.archistar.integration;
2 |
3 | import io.netty.channel.nio.NioEventLoopGroup;
4 |
5 | import java.util.HashSet;
6 |
7 | import org.junit.AfterClass;
8 | import org.junit.BeforeClass;
9 |
10 | import at.ac.ait.archistar.backendserver.storageinterface.MemoryStorage;
11 | import at.ac.ait.archistar.backendserver.storageinterface.StorageServer;
12 | import at.ac.ait.archistar.engine.TestEngine;
13 | import at.ac.ait.archistar.engine.crypto.PseudoMirrorCryptoEngine;
14 | import at.ac.ait.archistar.engine.distributor.BFTDistributor;
15 | import at.ac.ait.archistar.engine.distributor.Distributor;
16 | import at.ac.ait.archistar.engine.distributor.TestServerConfiguration;
17 | import at.ac.ait.archistar.engine.metadata.MetadataService;
18 | import at.ac.ait.archistar.engine.metadata.SimpleMetadataService;
19 | import at.archistar.crypto.CryptoEngine;
20 |
21 | public class MemoryOnlyTest extends AbstractIntegrationTest {
22 |
23 | @BeforeClass
24 | public static void prepareServer() {
25 | /* test configuration */
26 | HashSet servers = new HashSet<>();
27 | for(int i = 0; i < 4; i++) {
28 | servers.add(new MemoryStorage(i));
29 | }
30 | serverConfig = new TestServerConfiguration(servers);
31 | serverConfig.setupTestServer(1);
32 |
33 | CryptoEngine crypto = new PseudoMirrorCryptoEngine(4);
34 | Distributor distributor = new BFTDistributor(serverConfig, new NioEventLoopGroup());
35 | MetadataService metadata = new SimpleMetadataService(serverConfig, distributor, crypto);
36 | engine = new TestEngine(serverConfig, metadata, distributor, crypto);
37 | }
38 |
39 | @AfterClass
40 | public static void shutdownServers() {
41 | serverConfig.teardownTestServer();
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/src/test/java/at/ac/ait/archistar/metadata/SimpleDirectoryServiceTest.java:
--------------------------------------------------------------------------------
1 | package at.ac.ait.archistar.metadata;
2 |
3 | import static org.fest.assertions.api.Assertions.*;
4 | import static org.mockito.Mockito.mock;
5 | import static org.mockito.Mockito.when;
6 |
7 | import java.util.Set;
8 | import java.util.HashSet;
9 |
10 | import org.junit.BeforeClass;
11 | import org.junit.Test;
12 |
13 | import at.ac.ait.archistar.backendserver.fragments.Fragment;
14 | import at.ac.ait.archistar.backendserver.storageinterface.StorageServer;
15 | import at.ac.ait.archistar.engine.crypto.PseudoMirrorCryptoEngine;
16 | import at.ac.ait.archistar.engine.distributor.Distributor;
17 | import at.ac.ait.archistar.engine.distributor.ServerConfiguration;
18 | import at.ac.ait.archistar.engine.metadata.MetadataService;
19 | import at.ac.ait.archistar.engine.metadata.SimpleMetadataService;
20 | import at.archistar.crypto.CryptoEngine;
21 |
22 | public class SimpleDirectoryServiceTest {
23 |
24 | private static Distributor distributor;
25 | private static MetadataService theService;
26 | private static StorageServer server1;
27 | private static StorageServer server2;
28 | private static ServerConfiguration config;
29 |
30 | @BeforeClass
31 | public static void prepareTestData() {
32 | distributor = mock(Distributor.class);
33 | config = mock(ServerConfiguration.class);
34 |
35 | Set servers = new HashSet<>();
36 |
37 | server1 = mock(StorageServer.class);
38 | when(server1.isConnected()).thenReturn(true);
39 | servers.add(server1);
40 |
41 | server2 = mock(StorageServer.class);
42 | when(server2.isConnected()).thenReturn(true);
43 | servers.add(server2);
44 |
45 | CryptoEngine crypto = new PseudoMirrorCryptoEngine(2);
46 |
47 | Set result = new HashSet<>();
48 | Fragment frag1 = mock(Fragment.class);
49 | when(frag1.getStorageServer()).thenReturn(server1);
50 | when(frag1.getFragmentId()).thenReturn("fragement-1");
51 | result.add(frag1);
52 | Fragment frag2 = mock(Fragment.class);
53 | when(frag2.getStorageServer()).thenReturn(server2);
54 | when(frag2.getFragmentId()).thenReturn("fragement-2");
55 | result.add(frag2);
56 |
57 | when(config.getOnlineStorageServerCount()).thenReturn(2);
58 | when(config.getOnlineStorageServers()).thenReturn(servers);
59 |
60 | theService = new SimpleMetadataService(config, distributor, crypto);
61 | theService.connect();
62 | }
63 |
64 | @Test
65 | public void testIfAllServersAreIncludedInResult() {
66 |
67 | Set result = theService.getDistributionFor("/some-test-path");
68 | assertThat(result).hasSize(config.getOnlineStorageServerCount());
69 |
70 | Set choosenServers = new HashSet<>();
71 | for (Fragment f : result) {
72 | choosenServers.add(f.getStorageServer());
73 | }
74 | assertThat(choosenServers).contains(server1, server2);
75 | }
76 |
77 | @Test
78 | public void testIfRepeatedCallsGenerateSameFragmentIds() {
79 |
80 | Set result1 = theService.getDistributionFor("/some-test-path");
81 | Set result2 = theService.getDistributionFor("/some-test-path");
82 |
83 | // equivalent to result1.map(&:getStorageServer()) == result2.map(&:getStorageServer())
84 | Set fragmentIds1 = new HashSet<>();
85 | for (Fragment f : result1) {
86 | fragmentIds1.add(f.getFragmentId());
87 | }
88 |
89 | Set fragmentIds2 = new HashSet<>();
90 |
91 | for (Fragment f : result2) {
92 | fragmentIds2.add(f.getFragmentId());
93 | }
94 |
95 | assertThat(fragmentIds1).containsAll(fragmentIds2);
96 | assertThat(fragmentIds2).containsAll(fragmentIds1);
97 | }
98 |
99 | @Test
100 | public void testIfRepeatedCallsGenerateSameServers() {
101 |
102 | Set result1 = theService.getDistributionFor("/some-test-path");
103 | Set result2 = theService.getDistributionFor("/some-test-path");
104 |
105 | // equivalent to result1.map(&:getStorageServer()) == result2.map(&:getStorageServer())
106 | Set servers1 = new HashSet<>();
107 | for (Fragment f : result1) {
108 | servers1.add(f.getStorageServer());
109 | }
110 |
111 | Set servers2 = new HashSet<>();
112 |
113 | for (Fragment f : result2) {
114 | servers2.add(f.getStorageServer());
115 | }
116 | assertThat(servers1).containsAll(servers2);
117 | assertThat(servers2).containsAll(servers1);
118 | }
119 | }
120 |
--------------------------------------------------------------------------------
/src/test/java/at/ac/ait/archistar/storage/AbstractStorageTest.java:
--------------------------------------------------------------------------------
1 | package at.ac.ait.archistar.storage;
2 |
3 | import static org.fest.assertions.api.Assertions.*;
4 |
5 | import org.junit.Test;
6 |
7 | import at.ac.ait.archistar.backendserver.storageinterface.DisconnectedException;
8 | import at.ac.ait.archistar.backendserver.storageinterface.InvalidFragmentNameException;
9 | import at.ac.ait.archistar.backendserver.storageinterface.StorageServer;
10 |
11 | public abstract class AbstractStorageTest {
12 |
13 | protected final static byte[] testData = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
14 |
15 | protected final String fragmentId = "blub";
16 |
17 | protected StorageServer store;
18 |
19 | @Test
20 | public void testConnect() {
21 | assertThat(store.connect()).isEqualTo(0);
22 | try {
23 | // WHEN I store stuff
24 | byte[] result = store.putBlob(fragmentId, testData);
25 | // THEN the same stuff should be the result of the operation
26 | assertThat(result).isEqualTo(testData);
27 | } catch (DisconnectedException e) {
28 | fail("storage server disconnected", e);
29 | }
30 | }
31 |
32 | @Test(expected = DisconnectedException.class)
33 | public void testPutBlobDisconnected() throws InvalidFragmentNameException, DisconnectedException {
34 | store.putBlob(fragmentId, testData);
35 | }
36 |
37 | @Test
38 | public void testPutBlob() {
39 | assertThat(store.connect()).isEqualTo(0);
40 |
41 | try {
42 | assertThat(store.putBlob(fragmentId, testData)).isEqualTo(testData);
43 | assertThat(store.getBlob(fragmentId)).isEqualTo(testData);
44 | } catch (DisconnectedException e) {
45 | fail("storage server disconnected", e);
46 | }
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/src/test/java/at/ac/ait/archistar/storage/FileSystemStorageTest.java:
--------------------------------------------------------------------------------
1 | package at.ac.ait.archistar.storage;
2 |
3 | import java.io.File;
4 | import java.util.UUID;
5 |
6 | import org.apache.commons.logging.Log;
7 | import org.apache.commons.logging.LogFactory;
8 | import org.junit.Before;
9 |
10 | import at.ac.ait.archistar.backendserver.storageinterface.FilesystemStorage;
11 | import at.ac.ait.archistar.cryptoengine.MirrorTest;
12 |
13 | public class FileSystemStorageTest extends AbstractStorageTest {
14 |
15 | @Before
16 | public void prepareData() {
17 | File tmp = new File("/tmp/storage/" + UUID.randomUUID());
18 | if (!tmp.exists()) {
19 | assert (tmp.mkdirs());
20 | }
21 | tmp.deleteOnExit();
22 |
23 | Log log = LogFactory.getLog(MirrorTest.class);
24 | log.info("storing file system fragments under " + tmp.getAbsolutePath());
25 |
26 | store = new FilesystemStorage(0, tmp);
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/src/test/java/at/ac/ait/archistar/storage/JetS3tStorageTest.java:
--------------------------------------------------------------------------------
1 | package at.ac.ait.archistar.storage;
2 |
3 | import org.junit.Before;
4 |
5 | import at.ac.ait.archistar.backendserver.storageinterface.JetS3tStorage;
6 |
7 | public class JetS3tStorageTest extends AbstractStorageTest {
8 |
9 | @Before
10 | public void prepareData() {
11 | store = new JetS3tStorage(0, "xxx", "yyy", "testme.snikt.net");
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/src/test/java/at/ac/ait/archistar/storage/MemoryStoreTest.java:
--------------------------------------------------------------------------------
1 | package at.ac.ait.archistar.storage;
2 |
3 | import org.junit.Before;
4 |
5 | import at.ac.ait.archistar.backendserver.storageinterface.MemoryStorage;
6 |
7 | public class MemoryStoreTest extends AbstractStorageTest {
8 |
9 | @Before
10 | public void prepareData() {
11 | store = new MemoryStorage(0);
12 | }
13 | }
14 |
--------------------------------------------------------------------------------