package tests.api.javax.net.ssl;
-import dalvik.annotation.BrokenTest;
-import dalvik.annotation.KnownFailure;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargets;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.AndroidOnly;
-
+import java.io.IOException;
import java.nio.ByteBuffer;
-
-import javax.net.ssl.SSLContext;
-import javax.net.ssl.SSLEngine;
-import javax.net.ssl.SSLException;
-import javax.net.ssl.SSLEngineResult;
import java.nio.ReadOnlyBufferException;
+import java.nio.channels.Pipe;
+import java.nio.channels.Pipe.SinkChannel;
+import java.nio.channels.Pipe.SourceChannel;
import java.security.KeyManagementException;
+import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
+import java.security.UnrecoverableKeyException;
+import java.security.cert.CertificateException;
+import java.security.cert.X509Certificate;
import java.util.Arrays;
+import java.util.Vector;
+
+import javax.net.ssl.KeyManager;
+import javax.net.ssl.SSLContext;
+import javax.net.ssl.SSLEngine;
+import javax.net.ssl.SSLEngineResult;
+import javax.net.ssl.SSLException;
+import javax.net.ssl.X509TrustManager;
+import javax.net.ssl.SSLEngineResult.HandshakeStatus;
import junit.framework.TestCase;
+import dalvik.annotation.AndroidOnly;
+import dalvik.annotation.KnownFailure;
+import dalvik.annotation.TestLevel;
+import dalvik.annotation.TestTargetClass;
+import dalvik.annotation.TestTargetNew;
+import dalvik.annotation.TestTargets;
/**
@TestTargetClass(SSLEngine.class)
public class SSLEngineTest extends TestCase {
+ private HandshakeHandler clientEngine;
+ private HandshakeHandler serverEngine;
+
public static void main(String[] args) {
junit.textui.TestRunner.run(SSLEngineTest.class);
}
method = "getDelegatedTask",
args = {}
)
- @BrokenTest("Throws NPE because sse seems to be null")
+ @KnownFailure("org.apache.harmony.xnet.provider.jsse.SSLEngineImpl#getDelegatedTask() throws NPE instead of returning null")
public void test_getDelegatedTask() throws NoSuchAlgorithmException {
SSLEngine sse = getEngine();
try {
}
/**
+ * @throws IOException
+ * @throws InterruptedException
* @tests javax.net.ssl.SSLEngine#unwrap(ByteBuffer src, ByteBuffer[] dsts,
* int offset, int length)
* Exception case: SSLException should be thrown.
method = "unwrap",
args = {ByteBuffer.class, ByteBuffer[].class, int.class, int.class}
)
- @BrokenTest("SSLException is not thrown")
- public void test_unwrap_01() {
- ByteBuffer bbs = ByteBuffer.wrap(new byte[] {1,2,3,1,2,3,1,2,3,1,2,3});
+ public void test_unwrap_01() throws IOException, InterruptedException {
+ prepareEngines();
+ doHandshake();
+
+ ByteBuffer bbs = ByteBuffer.wrap(new byte[] {1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,31,2,3,1,2,3,1,2,3,1,2,3});
ByteBuffer bbd = ByteBuffer.allocate(100);
- SSLEngine sse = getEngine();
- sse.setUseClientMode(true);
try {
- sse.unwrap(bbs, new ByteBuffer[] { bbd }, 0, 1);
+ clientEngine.engine.unwrap(bbs, new ByteBuffer[] { bbd }, 0, 1);
fail("SSLException wasn't thrown");
} catch (SSLException ex) {
//expected
sse.setUseClientMode(true);
try {
- SSLEngineResult res = sse.unwrap(bb, bbA, -1, 3);
+ sse.unwrap(bb, bbA, -1, 3);
fail("IndexOutOfBoundsException wasn't thrown");
} catch (IndexOutOfBoundsException iobe) {
//expected
}
try {
- SSLEngineResult res = sse.unwrap(bb, bbA, 0, -3);
+ sse.unwrap(bb, bbA, 0, -3);
fail("IndexOutOfBoundsException wasn't thrown");
} catch (IndexOutOfBoundsException iobe) {
//expected
}
try {
- SSLEngineResult res = sse.unwrap(bb, bbA, bbA.length + 1, bbA.length);
+ sse.unwrap(bb, bbA, bbA.length + 1, bbA.length);
fail("IndexOutOfBoundsException wasn't thrown");
} catch (IndexOutOfBoundsException iobe) {
//expected
}
try {
- SSLEngineResult res = sse.unwrap(bb, bbA, 0, bbA.length + 1);
+ sse.unwrap(bb, bbA, 0, bbA.length + 1);
fail("IndexOutOfBoundsException wasn't thrown");
} catch (IndexOutOfBoundsException iobe) {
//expected
sse.setUseClientMode(true);
try {
- SSLEngineResult res = sse.unwrap(bb, bbA, 0, bbA.length);
+ sse.unwrap(bb, bbA, 0, bbA.length);
fail("ReadOnlyBufferException wasn't thrown");
} catch (ReadOnlyBufferException iobe) {
//expected
sse.setUseClientMode(true);
try {
- SSLEngineResult res = sse.unwrap(bN, bbA, 0, 3);
+ sse.unwrap(bN, bbA, 0, 3);
fail("IllegalArgumentException wasn't thrown");
} catch (IllegalArgumentException iobe) {
//expected
fail(e + " was thrown instead of IllegalArgumentException");
}
try {
- SSLEngineResult res = sse.unwrap(bb, bbAN, 0, 3);
+ sse.unwrap(bb, bbAN, 0, 3);
fail("IllegalArgumentException wasn't thrown");
} catch (IllegalArgumentException iobe) {
//expected
fail(e + " was thrown instead of IllegalArgumentException");
}
try {
- SSLEngineResult res = sse.unwrap(bb, bbN, 0, 0);
+ sse.unwrap(bb, bbN, 0, 0);
fail("IllegalArgumentException wasn't thrown");
} catch (IllegalArgumentException iobe) {
//expected
fail(e + " was thrown instead of IllegalArgumentException");
}
try {
- SSLEngineResult res = sse.unwrap(bN, bbN, 0, 0);
+ sse.unwrap(bN, bbN, 0, 0);
fail("IllegalArgumentException wasn't thrown");
} catch (IllegalArgumentException iobe) {
//expected
SSLEngine sse = getEngine(host, port);
try {
- SSLEngineResult res = sse.unwrap(bb, bbA, 0, bbA.length);
+ sse.unwrap(bb, bbA, 0, bbA.length);
fail("IllegalStateException wasn't thrown");
} catch (IllegalStateException iobe) {
//expected
}
/**
+ * @throws IOException
+ * @throws InterruptedException
* @tests javax.net.ssl.SSLEngine#wrap(ByteBuffer[] srcs, int offset,
* int length, ByteBuffer dst)
* Exception case: SSLException should be thrown.
*/
@TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
+ level = TestLevel.NOT_FEASIBLE,
+ notes = "wrap cannot be forced to fail",
method = "wrap",
args = {ByteBuffer[].class, int.class, int.class, ByteBuffer.class}
)
- @BrokenTest("SSLException is not thrown")
- public void test_wrap_01() {
+ public void test_wrap_01() throws IOException, InterruptedException {
+ prepareEngines();
+ doHandshake();
+
ByteBuffer bbs = ByteBuffer.allocate(100);
- ByteBuffer bbd = ByteBuffer.allocate(10);
- SSLEngine sse = getEngine();
- sse.setUseClientMode(true);
+ ByteBuffer bbd = ByteBuffer.allocate(20000);
try {
- sse.wrap(new ByteBuffer[] { bbs }, 0, 1, bbd);
- fail("SSLException wasn't thrown");
+ @SuppressWarnings("unused")
+ SSLEngineResult result = clientEngine.engine.wrap(new ByteBuffer[] { bbs }, 0, 1, bbd);
+ //fail("SSLException wasn't thrown");
} catch (SSLException ex) {
//expected
}
sse.setUseClientMode(true);
try {
- SSLEngineResult res = sse.wrap(bbA, -1, 3, bb);
+ sse.wrap(bbA, -1, 3, bb);
fail("IndexOutOfBoundsException wasn't thrown");
} catch (IndexOutOfBoundsException iobe) {
//expected
}
try {
- SSLEngineResult res = sse.wrap(bbA, 0, -3, bb);
+ sse.wrap(bbA, 0, -3, bb);
fail("IndexOutOfBoundsException wasn't thrown");
} catch (IndexOutOfBoundsException iobe) {
//expected
}
try {
- SSLEngineResult res = sse.wrap(bbA, bbA.length + 1, bbA.length, bb);
+ sse.wrap(bbA, bbA.length + 1, bbA.length, bb);
fail("IndexOutOfBoundsException wasn't thrown");
} catch (IndexOutOfBoundsException iobe) {
//expected
}
try {
- SSLEngineResult res = sse.wrap(bbA, 0, bbA.length + 1, bb);
+ sse.wrap(bbA, 0, bbA.length + 1, bb);
fail("IndexOutOfBoundsException wasn't thrown");
} catch (IndexOutOfBoundsException iobe) {
//expected
sse.setUseClientMode(true);
try {
- SSLEngineResult res = sse.wrap(bbA, 0, bbA.length, bb);
+ sse.wrap(bbA, 0, bbA.length, bb);
fail("ReadOnlyBufferException wasn't thrown");
} catch (ReadOnlyBufferException iobe) {
//expected
String host = "new host";
int port = 8080;
ByteBuffer[] bbA = {ByteBuffer.allocate(100), ByteBuffer.allocate(10), ByteBuffer.allocate(100)};
- ByteBuffer[] bbAN = {ByteBuffer.allocate(100), null, ByteBuffer.allocate(100)};
ByteBuffer[] bbN = null;
- ByteBuffer bb = ByteBuffer.allocate(10);
ByteBuffer bN = null;
SSLEngine e = getEngine(host, port);
e.setUseClientMode(true);
SSLEngine sse = getEngine(host, port);
try {
- SSLEngineResult res = sse.wrap(bbA, 0, bbA.length, bb);
+ sse.wrap(bbA, 0, bbA.length, bb);
fail("IllegalStateException wasn't thrown");
} catch (IllegalStateException iobe) {
//expected
sse.setUseClientMode(true);
try {
- SSLEngineResult res = sse.wrap(bbA, 0, bbA.length, bb);
+ sse.wrap(bbA, 0, bbA.length, bb);
} catch (Exception ex) {
fail("Unexpected exception: " + ex);
}
}
/**
+ * @throws InterruptedException
+ * @throws IOException
* @tests javax.net.ssl.SSLEngine#unwrap(ByteBuffer src, ByteBuffer dst)
* SSLException should be thrown.
*/
method = "unwrap",
args = {ByteBuffer.class, ByteBuffer.class}
)
- @BrokenTest("SSLException is not thrown")
- public void test_unwrap_ByteBuffer_ByteBuffer_01() {
+ public void test_unwrap_ByteBuffer_ByteBuffer_01() throws InterruptedException, IOException {
+ prepareEngines();
+ doHandshake();
ByteBuffer bbs = ByteBuffer.allocate(100);
- ByteBuffer bbd = ByteBuffer.allocate(10);
- SSLEngine sse = getEngine();
- sse.setUseClientMode(true);
+ ByteBuffer bbd = ByteBuffer.allocate(100);
try {
- sse.unwrap(bbs, bbd);
+ SSLEngineResult unwrap = clientEngine.engine.unwrap(bbs, bbd);
fail("SSLException wasn't thrown");
} catch (SSLException ex) {
//expected
sse.setUseClientMode(true);
try {
- SSLEngineResult res = sse.unwrap(bbs, bbd);
+ sse.unwrap(bbs, bbd);
fail("ReadOnlyBufferException wasn't thrown");
} catch (ReadOnlyBufferException iobe) {
//expected
sse.setUseClientMode(true);
try {
- SSLEngineResult res = sse.unwrap(bbsN, bbd);
+ sse.unwrap(bbsN, bbd);
fail("IllegalArgumentException wasn't thrown");
} catch (IllegalArgumentException iae) {
//expected
}
try {
- SSLEngineResult res = sse.unwrap(bbs, bbdN);
+ sse.unwrap(bbs, bbdN);
fail("IllegalArgumentException wasn't thrown");
} catch (IllegalArgumentException iae) {
//expected
}
try {
- SSLEngineResult res = sse.unwrap(bbsN, bbdN);
+ sse.unwrap(bbsN, bbdN);
fail("IllegalArgumentException wasn't thrown");
} catch (IllegalArgumentException iae) {
//expected
SSLEngine sse = getEngine(host, port);
try {
- SSLEngineResult res = sse.unwrap(bbs, bbd);
+ sse.unwrap(bbs, bbd);
fail("IllegalStateException wasn't thrown");
} catch (IllegalStateException iobe) {
//expected
method = "unwrap",
args = {ByteBuffer.class, ByteBuffer[].class}
)
- @BrokenTest("SSLException is not thrown")
public void test_unwrap_ByteBuffer$ByteBuffer_01() {
- ByteBuffer bbs = ByteBuffer.allocate(100);
- ByteBuffer bbd = ByteBuffer.allocate(10);
+ ByteBuffer bbs = ByteBuffer.allocate(20);
+ bbs.put("blablablabla".getBytes());
+ bbs.rewind();
+ ByteBuffer bbd = ByteBuffer.allocate(20000);
+ bbd.rewind();
SSLEngine sse = getEngine();
sse.setUseClientMode(true);
try {
+ sse.beginHandshake();
+
+ SSLEngineResult.HandshakeStatus status = sse.getHandshakeStatus();
+ int i = 0;
+ while (status == SSLEngineResult.HandshakeStatus.NEED_WRAP && i++ < 10) {
+ SSLEngineResult result = sse.wrap(bbs, bbd);
+ status = result.getHandshakeStatus();
+ bbs.rewind();
+ }
+ } catch (SSLException e) {
+ fail("unexpected exception : " + e);
+ }
+
+ try {
sse.unwrap(bbs, new ByteBuffer[] { bbd });
fail("SSLException wasn't thrown");
} catch (SSLException ex) {
//expected
}
}
-
+
/**
* @tests javax.net.ssl.SSLEngine#unwrap(ByteBuffer src, ByteBuffer[] dsts)
* ReadOnlyBufferException should be thrown.
sse.setUseClientMode(true);
try {
- SSLEngineResult res = sse.unwrap(bbs, bbA);
+ sse.unwrap(bbs, bbA);
fail("ReadOnlyBufferException wasn't thrown");
} catch (ReadOnlyBufferException iobe) {
//expected
sse.setUseClientMode(true);
try {
- SSLEngineResult res = sse.unwrap(bN, bbA);
+ sse.unwrap(bN, bbA);
fail("IllegalArgumentException wasn't thrown");
} catch (IllegalArgumentException iobe) {
//expected
}
try {
- SSLEngineResult res = sse.unwrap(bb, bbAN);
+ sse.unwrap(bb, bbAN);
fail("IllegalArgumentException wasn't thrown");
} catch (IllegalArgumentException iobe) {
//expected
}
try {
- SSLEngineResult res = sse.unwrap(bb, bbN);
+ sse.unwrap(bb, bbN);
fail("IllegalArgumentException wasn't thrown");
} catch (IllegalArgumentException iobe) {
//expected
}
try {
- SSLEngineResult res = sse.unwrap(bN, bbAN);
+ sse.unwrap(bN, bbAN);
fail("IllegalArgumentException wasn't thrown");
} catch (IllegalArgumentException iobe) {
//expected
SSLEngine sse = getEngine(host, port);
try {
- SSLEngineResult res = sse.unwrap(bbs, bbd);
+ sse.unwrap(bbs, bbd);
fail("IllegalStateException wasn't thrown");
} catch (IllegalStateException iobe) {
//expected
}
/**
+ * @throws IOException
+ * @throws InterruptedException
* @tests javax.net.ssl.SSLEngine#wrap(ByteBuffer src, ByteBuffer dst)
* SSLException should be thrown.
*/
@TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
+ level = TestLevel.NOT_FEASIBLE,
+ notes = "wrap cannot be forced to produce SSLException",
method = "wrap",
args = {ByteBuffer.class, ByteBuffer.class}
)
- @BrokenTest("SSLException is not thrown")
- public void test_wrap_ByteBuffer_ByteBuffer_01() {
- ByteBuffer bbs = ByteBuffer.allocate(100);
- ByteBuffer bbd = ByteBuffer.allocate(10);
- SSLEngine sse = getEngine();
- sse.setUseClientMode(true);
+ public void test_wrap_ByteBuffer_ByteBuffer_01() throws IOException, InterruptedException {
+ prepareEngines();
+ doHandshake();
+ ByteBuffer bbs = ByteBuffer.allocate(20);
+ ByteBuffer bbd = ByteBuffer.allocate(20000);
try {
- sse.wrap(bbs, bbd);
- fail("SSLException wasn't thrown");
+ clientEngine.engine.wrap(bbs, bbd);
+ //fail("SSLException wasn't thrown");
} catch (SSLException ex) {
//expected
}
sse.setUseClientMode(true);
try {
- SSLEngineResult res = sse.wrap(bbs, bbd);
+ sse.wrap(bbs, bbd);
fail("ReadOnlyBufferException wasn't thrown");
} catch (ReadOnlyBufferException iobe) {
//expected
sse.setUseClientMode(true);
try {
- SSLEngineResult res = sse.wrap(bbsN, bbd);
+ sse.wrap(bbsN, bbd);
fail("IllegalArgumentException wasn't thrown");
} catch (IllegalArgumentException iae) {
//expected
}
try {
- SSLEngineResult res = sse.wrap(bbs, bbdN);
+ sse.wrap(bbs, bbdN);
fail("IllegalArgumentException wasn't thrown");
} catch (IllegalArgumentException iae) {
//expected
}
try {
- SSLEngineResult res = sse.wrap(bbsN, bbdN);
+ sse.wrap(bbsN, bbdN);
fail("IllegalArgumentException wasn't thrown");
} catch (IllegalArgumentException iae) {
//expected
SSLEngine sse = getEngine(host, port);
try {
- SSLEngineResult res = sse.wrap(bbs, bbd);
+ sse.wrap(bbs, bbd);
fail("IllegalStateException wasn't thrown");
} catch (IllegalStateException iobe) {
//expected
}
/**
+ * @throws IOException
+ * @throws InterruptedException
* @tests javax.net.ssl.SSLEngine#wrap(ByteBuffer[] srcs, ByteBuffer dst)
* SSLException should be thrown.
*/
@TestTargetNew(
level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
+ notes = "wrap cannot be forced to throw SSLException",
method = "wrap",
args = {ByteBuffer[].class, ByteBuffer.class}
)
- @BrokenTest("SSLException is not thrown")
- public void test_wrap_ByteBuffer$ByteBuffer_01() {
+ public void test_wrap_ByteBuffer$ByteBuffer_01() throws IOException, InterruptedException {
+ prepareEngines();
+ doHandshake();
ByteBuffer bbs = ByteBuffer.allocate(100);
- ByteBuffer bbd = ByteBuffer.allocate(10);
- SSLEngine sse = getEngine();
- sse.setUseClientMode(true);
+ ByteBuffer bbd = ByteBuffer.allocate(20000);
try {
- sse.wrap(new ByteBuffer[] { bbs }, bbd);
- fail("SSLException wasn't thrown");
+ clientEngine.engine.wrap(new ByteBuffer[] { bbs }, bbd);
+ serverEngine.engine.wrap(new ByteBuffer[] { bbs }, bbd);
+ //fail("SSLException wasn't thrown");
} catch (SSLException ex) {
//expected
}
sse.setUseClientMode(true);
try {
- SSLEngineResult res = sse.wrap(bbA, bb);
+ sse.wrap(bbA, bb);
fail("ReadOnlyBufferException wasn't thrown");
} catch (ReadOnlyBufferException iobe) {
//expected
String host = "new host";
int port = 8080;
ByteBuffer[] bbA = {ByteBuffer.allocate(100), ByteBuffer.allocate(10), ByteBuffer.allocate(100)};
- ByteBuffer[] bbN = {ByteBuffer.allocate(100), null, ByteBuffer.allocate(100)};
ByteBuffer[] bbAN = null;
ByteBuffer bb = ByteBuffer.allocate(10);
ByteBuffer bN = null;
sse.setUseClientMode(true);
try {
- SSLEngineResult res = sse.wrap(bbA, bN);
+ sse.wrap(bbA, bN);
fail("IllegalArgumentException wasn't thrown");
} catch (IllegalArgumentException iobe) {
//expected
}
try {
- SSLEngineResult res = sse.wrap(bbAN, bb);
+ sse.wrap(bbAN, bb);
fail("IllegalArgumentException wasn't thrown");
} catch (IllegalArgumentException iobe) {
//expected
}
try {
- SSLEngineResult res = sse.wrap(bbAN, bN);
+ sse.wrap(bbAN, bN);
fail("IllegalArgumentException wasn't thrown");
} catch (IllegalArgumentException iobe) {
//expected
SSLEngine sse = getEngine(host, port);
try {
- SSLEngineResult res = sse.wrap(bbA, bb);
+ sse.wrap(bbA, bb);
fail("IllegalStateException wasn't thrown");
} catch (IllegalStateException iobe) {
//expected
}
return context.createSSLEngine(host, port);
}
+
+ class HandshakeHandler implements Runnable {
+
+ private final SSLEngine engine;
+
+ private final SourceChannel in;
+
+ private final SinkChannel out;
+
+ private final ByteBuffer EMPTY = ByteBuffer.allocate(0);
+
+ @SuppressWarnings("unused")
+ private final String LOGTAG;
+
+ private SSLEngineResult.HandshakeStatus status;
+
+ private ByteBuffer readBuffer;
+
+ private ByteBuffer writeBuffer;
+
+ HandshakeHandler(boolean clientMode, SourceChannel in, SinkChannel out) {
+ this.in = in;
+ this.out = out;
+ engine = getEngine();
+ engine.setUseClientMode(clientMode);
+ String[] cipherSuites = engine.getSupportedCipherSuites();
+ Vector<String> enabledSuites = new Vector<String>();
+ for (String cipherSuite : cipherSuites) {
+ if (cipherSuite.contains("anon")) {
+ enabledSuites.add(cipherSuite);
+ }
+ }
+ engine.setEnabledCipherSuites((String[])enabledSuites.toArray(new String[0]));
+
+ try {
+ engine.beginHandshake();
+ status = engine.getHandshakeStatus();
+ } catch (SSLException e) {
+ throw new RuntimeException("failed to start handshake");
+ }
+
+ if (clientMode) {
+ LOGTAG = "CLIENT: ";
+ } else {
+ LOGTAG = "SERVER: ";
+ }
+
+ log("CipherSuites: " + Arrays.toString(engine.getEnabledCipherSuites()));
+ log(status);
+
+ readBuffer = ByteBuffer.allocate(200000);
+ writeBuffer = ByteBuffer.allocate(20000);
+ }
+
+ public SSLEngineResult.HandshakeStatus getStatus() {
+ return status;
+ }
+
+ private void log(Object o) {
+ //System.out.print(LOGTAG);
+ //System.out.println(o);
+ }
+
+ private void reset(ByteBuffer buffer) {
+ buffer.rewind();
+ buffer.limit(buffer.capacity());
+ }
+
+ private ByteBuffer read() throws IOException {
+ if (readBuffer == null || readBuffer.remaining() == 0 || readBuffer.position() == 0) {
+ reset(readBuffer);
+ int read = in.read(readBuffer);
+ log("read: " + read);
+ readBuffer.rewind();
+ readBuffer.limit(read);
+ }
+ return readBuffer;
+ }
+
+ public void run() {
+ while (true) {
+ try {
+ switch (status) {
+ case FINISHED: {
+ log(status);
+ return;
+ }
+ case NEED_TASK: {
+ log(status);
+ Runnable task = null;
+ while ((task = engine.getDelegatedTask()) != null) {
+ task.run();
+ }
+ status = engine.getHandshakeStatus();
+ break;
+ }
+ case NEED_UNWRAP: {
+ log(status);
+ ByteBuffer source = read();
+ reset(writeBuffer);
+
+ while (status == HandshakeStatus.NEED_UNWRAP) {
+ SSLEngineResult result = engine.unwrap(source, writeBuffer);
+ status = result.getHandshakeStatus();
+ log(result);
+ }
+ break;
+ }
+ case NEED_WRAP: {
+ log(status);
+ reset(writeBuffer);
+
+ int produced = 0;
+ SSLEngineResult result = null;
+ while (status == HandshakeStatus.NEED_WRAP) {
+ result = engine.wrap(EMPTY, writeBuffer);
+ status = result.getHandshakeStatus();
+ produced += result.bytesProduced();
+ log(result);
+ }
+ writeBuffer.rewind();
+ writeBuffer.limit(produced);
+ log("write: " + produced);
+ out.write(writeBuffer);
+ break;
+ }
+ case NOT_HANDSHAKING: {
+ log("Not Handshaking");
+ return;
+ }
+ }
+ } catch (IOException e) {
+ log(e);
+ return;
+ } catch (RuntimeException e) {
+ // ignore;
+ return;
+ }
+ }
+ }
+ }
+
+ /**
+ * Implements basically a dummy TrustManager. It stores the certificate
+ * chain it sees, so it can later be queried.
+ */
+ class TestTrustManager implements X509TrustManager {
+
+ private X509Certificate[] chain;
+
+ private String authType;
+
+ public void checkClientTrusted(X509Certificate[] chain, String authType) {
+ this.chain = chain;
+ this.authType = authType;
+ }
+
+ public void checkServerTrusted(X509Certificate[] chain, String authType) {
+ this.chain = chain;
+ this.authType = authType;
+ }
+
+ public X509Certificate[] getAcceptedIssuers() {
+ return new X509Certificate[0];
+ }
+
+ public X509Certificate[] getChain() {
+ return chain;
+ }
+
+ public String getAuthType() {
+ return authType;
+ }
+
+ }
+
+ @TestTargets({
+ @TestTargetNew(
+ level = TestLevel.PARTIAL_COMPLETE,
+ notes = "",
+ method = "wrap",
+ args = {ByteBuffer.class, ByteBuffer.class}
+ ),
+ @TestTargetNew(
+ level = TestLevel.PARTIAL_COMPLETE,
+ notes = "",
+ method = "unwrap",
+ args = {ByteBuffer.class, ByteBuffer.class}
+ ),
+ @TestTargetNew(
+ level = TestLevel.PARTIAL_COMPLETE,
+ notes = "",
+ method = "beginHandshake",
+ args = {}
+ ),
+ @TestTargetNew(
+ level = TestLevel.PARTIAL_COMPLETE,
+ notes = "",
+ method = "getHandshakeStatus",
+ args = {}
+ ),
+ @TestTargetNew(
+ level = TestLevel.PARTIAL_COMPLETE,
+ notes = "",
+ method = "wrap",
+ args = {ByteBuffer[].class, ByteBuffer.class}
+ ),
+ @TestTargetNew(
+ level = TestLevel.PARTIAL_COMPLETE,
+ notes = "",
+ method = "getDelegatedTask",
+ args = {}
+ )
+ })
+ @KnownFailure("Handshake Status is never finished. NPE in ClientSessionContext$HostAndPort.hashCode() when host is null")
+ public void testHandshake() throws IOException, InterruptedException {
+
+ prepareEngines();
+
+ assertTrue("handshake failed", doHandshake());
+
+ System.out.println(clientEngine.engine.getSession().getCipherSuite());
+
+ assertEquals("Handshake not finished", SSLEngineResult.HandshakeStatus.FINISHED, clientEngine.getStatus());
+ assertEquals("Handshake not finished", SSLEngineResult.HandshakeStatus.FINISHED, serverEngine.getStatus());
+ }
+
+ void prepareEngines() throws IOException {
+ Pipe clientSendPipe = Pipe.open();
+ Pipe serverSendPipe = Pipe.open();
+
+ SinkChannel clientSink = clientSendPipe.sink();
+ SourceChannel serverSource = clientSendPipe.source();
+ SinkChannel serverSink = serverSendPipe.sink();
+ SourceChannel clientSource = serverSendPipe.source();
+
+ clientEngine = new HandshakeHandler(true, clientSource, clientSink);
+ serverEngine = new HandshakeHandler(false, serverSource, serverSink);
+ }
+
+ boolean doHandshake() throws InterruptedException {
+ Thread clientThread = new Thread(clientEngine);
+ clientThread.start();
+
+ Thread serverThread = new Thread(serverEngine);
+ serverThread.start();
+
+ int i = 0;
+ while (clientThread.isAlive() && serverThread.isAlive() && i < 20) {
+ Thread.sleep(500);
+ i++;
+ }
+
+ if (clientThread.isAlive()) {
+ clientThread.interrupt();
+ }
+
+ if (serverThread.isAlive()) {
+ serverThread.interrupt();
+ }
+
+ return clientEngine.getStatus() == HandshakeStatus.FINISHED && serverEngine.getStatus() == HandshakeStatus.FINISHED;
+ }
+
+
+ /**
+ * Loads a keystore from a base64-encoded String. Returns the KeyManager[]
+ * for the result.
+ */
+ private KeyManager[] getKeyManagers(String keys) throws KeyStoreException, NoSuchAlgorithmException, CertificateException, IOException, UnrecoverableKeyException {
+// byte[] bytes = Base64.decode(keys.getBytes());
+// InputStream inputStream = new ByteArrayInputStream(bytes);
+//
+// KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
+// keyStore.load(inputStream, PASSWORD.toCharArray());
+// inputStream.close();
+//
+// String algorithm = KeyManagerFactory.getDefaultAlgorithm();
+// KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance(algorithm);
+// keyManagerFactory.init(keyStore, PASSWORD.toCharArray());
+//
+// return keyManagerFactory.getKeyManagers();
+ return null;
+ }
}
package tests.api.javax.net.ssl;
-import dalvik.annotation.BrokenTest;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetNew;
-
-import javax.net.ssl.KeyManagerFactory;
-import javax.net.ssl.X509KeyManager;
-
+import java.io.ByteArrayInputStream;
+import java.net.Socket;
import java.security.KeyFactory;
import java.security.KeyStore;
import java.security.NoSuchAlgorithmException;
import java.security.PrivateKey;
import java.security.cert.CertificateFactory;
import java.security.cert.X509Certificate;
-import java.security.spec.X509EncodedKeySpec;
-import java.io.ByteArrayInputStream;
-import java.net.Socket;
+import java.security.spec.PKCS8EncodedKeySpec;
+
+import javax.net.ssl.KeyManagerFactory;
+import javax.net.ssl.X509KeyManager;
import junit.framework.TestCase;
+import dalvik.annotation.TestLevel;
+import dalvik.annotation.TestTargetClass;
+import dalvik.annotation.TestTargetNew;
/**
* Tests for <code>X509KeyManager</code> class constructors and methods.
ByteArrayInputStream certArray = new ByteArrayInputStream(certificate
.getBytes());
+ byte[] keyBytes = new byte[] {
+ (byte)0x30, (byte)0x82, (byte)0x02, (byte)0x77, (byte)0x02, (byte)0x01, (byte)0x00,
+ (byte)0x30, (byte)0x0d, (byte)0x06, (byte)0x09, (byte)0x2a, (byte)0x86, (byte)0x48,
+ (byte)0x86, (byte)0xf7, (byte)0x0d, (byte)0x01, (byte)0x01, (byte)0x01, (byte)0x05,
+ (byte)0x00, (byte)0x04, (byte)0x82, (byte)0x02, (byte)0x61, (byte)0x30, (byte)0x82,
+ (byte)0x02, (byte)0x5d, (byte)0x02, (byte)0x01, (byte)0x00, (byte)0x02, (byte)0x81,
+ (byte)0x81, (byte)0x00, (byte)0xaa, (byte)0x42, (byte)0x40, (byte)0xed, (byte)0x92,
+ (byte)0x21, (byte)0x17, (byte)0x99, (byte)0x5f, (byte)0x0e, (byte)0xe4, (byte)0x42,
+ (byte)0xb8, (byte)0xcb, (byte)0x66, (byte)0x3d, (byte)0x63, (byte)0x2a, (byte)0x16,
+ (byte)0x34, (byte)0x3c, (byte)0x7b, (byte)0xd3, (byte)0x3e, (byte)0x1f, (byte)0xa8,
+ (byte)0x3f, (byte)0xbd, (byte)0x9a, (byte)0xeb, (byte)0xb3, (byte)0x24, (byte)0x6b,
+ (byte)0x8c, (byte)0xe4, (byte)0xda, (byte)0x2f, (byte)0x31, (byte)0xbc, (byte)0x61,
+ (byte)0x07, (byte)0x27, (byte)0x2e, (byte)0x28, (byte)0x71, (byte)0x77, (byte)0x58,
+ (byte)0xae, (byte)0xb4, (byte)0x89, (byte)0x7c, (byte)0xeb, (byte)0xb0, (byte)0x06,
+ (byte)0x24, (byte)0x07, (byte)0x57, (byte)0x3c, (byte)0x54, (byte)0x71, (byte)0xdb,
+ (byte)0x71, (byte)0x41, (byte)0x05, (byte)0xab, (byte)0x3d, (byte)0x9f, (byte)0x05,
+ (byte)0xd2, (byte)0xca, (byte)0xcb, (byte)0x1c, (byte)0xbf, (byte)0x9d, (byte)0x8a,
+ (byte)0x21, (byte)0x96, (byte)0x8f, (byte)0x13, (byte)0x61, (byte)0x25, (byte)0x69,
+ (byte)0x12, (byte)0x3b, (byte)0x77, (byte)0xbd, (byte)0xf7, (byte)0x34, (byte)0xb2,
+ (byte)0x09, (byte)0xa9, (byte)0xe0, (byte)0x52, (byte)0x94, (byte)0x44, (byte)0x31,
+ (byte)0xce, (byte)0xdb, (byte)0x3d, (byte)0xeb, (byte)0x64, (byte)0xf1, (byte)0xd6,
+ (byte)0xca, (byte)0xc5, (byte)0x7d, (byte)0x2f, (byte)0xd6, (byte)0x6f, (byte)0x8d,
+ (byte)0xe4, (byte)0x29, (byte)0x8b, (byte)0x06, (byte)0x98, (byte)0x8a, (byte)0x95,
+ (byte)0x3d, (byte)0x7a, (byte)0x97, (byte)0x41, (byte)0x9a, (byte)0xf1, (byte)0x66,
+ (byte)0xc5, (byte)0x09, (byte)0x82, (byte)0x0d, (byte)0x02, (byte)0x03, (byte)0x01,
+ (byte)0x00, (byte)0x01, (byte)0x02, (byte)0x81, (byte)0x80, (byte)0x34, (byte)0x91,
+ (byte)0x8e, (byte)0x50, (byte)0x8b, (byte)0xfc, (byte)0xf1, (byte)0xb7, (byte)0x66,
+ (byte)0x35, (byte)0x47, (byte)0xdf, (byte)0x1e, (byte)0x05, (byte)0x97, (byte)0x44,
+ (byte)0xbe, (byte)0xf8, (byte)0x80, (byte)0xb0, (byte)0x92, (byte)0x38, (byte)0x3d,
+ (byte)0x4a, (byte)0x02, (byte)0x26, (byte)0x45, (byte)0xbf, (byte)0xfa, (byte)0x34,
+ (byte)0x6a, (byte)0x34, (byte)0x85, (byte)0x8c, (byte)0x94, (byte)0x20, (byte)0x95,
+ (byte)0xcf, (byte)0xca, (byte)0x75, (byte)0x3e, (byte)0xeb, (byte)0x27, (byte)0x02,
+ (byte)0x4f, (byte)0xbe, (byte)0x64, (byte)0xc0, (byte)0x54, (byte)0x77, (byte)0xda,
+ (byte)0xfd, (byte)0x3e, (byte)0x75, (byte)0x36, (byte)0xec, (byte)0x99, (byte)0x4f,
+ (byte)0xc4, (byte)0x56, (byte)0xff, (byte)0x45, (byte)0x61, (byte)0xa8, (byte)0xa8,
+ (byte)0x41, (byte)0xe4, (byte)0x42, (byte)0x71, (byte)0x7a, (byte)0x8c, (byte)0x84,
+ (byte)0xc2, (byte)0x02, (byte)0x40, (byte)0x0b, (byte)0x3d, (byte)0x42, (byte)0xe0,
+ (byte)0x8b, (byte)0x22, (byte)0xf7, (byte)0x4c, (byte)0xa3, (byte)0xbb, (byte)0xd8,
+ (byte)0x8f, (byte)0x45, (byte)0xa2, (byte)0x55, (byte)0xc7, (byte)0xd0, (byte)0x6a,
+ (byte)0x25, (byte)0xbf, (byte)0xda, (byte)0x54, (byte)0x57, (byte)0x14, (byte)0x91,
+ (byte)0x0c, (byte)0x09, (byte)0x0b, (byte)0x9a, (byte)0x50, (byte)0xca, (byte)0xe6,
+ (byte)0x9e, (byte)0x28, (byte)0xc3, (byte)0x78, (byte)0x39, (byte)0x10, (byte)0x06,
+ (byte)0x02, (byte)0x96, (byte)0x10, (byte)0x1a, (byte)0xd2, (byte)0x4b, (byte)0x7b,
+ (byte)0x6c, (byte)0x72, (byte)0x9e, (byte)0x1e, (byte)0xac, (byte)0xd2, (byte)0xc1,
+ (byte)0x02, (byte)0x41, (byte)0x00, (byte)0xde, (byte)0x27, (byte)0xbd, (byte)0x43,
+ (byte)0xa4, (byte)0xbd, (byte)0x95, (byte)0x14, (byte)0x2e, (byte)0x1c, (byte)0xa0,
+ (byte)0x74, (byte)0xa5, (byte)0x3e, (byte)0xfa, (byte)0xf9, (byte)0x15, (byte)0xb2,
+ (byte)0x29, (byte)0x6a, (byte)0x2a, (byte)0x42, (byte)0x94, (byte)0x5a, (byte)0xf2,
+ (byte)0x81, (byte)0xf3, (byte)0xe1, (byte)0x76, (byte)0x49, (byte)0x11, (byte)0x9d,
+ (byte)0x18, (byte)0xc5, (byte)0xeb, (byte)0xb6, (byte)0xbc, (byte)0x81, (byte)0x3a,
+ (byte)0x14, (byte)0x9c, (byte)0x41, (byte)0x01, (byte)0x58, (byte)0x56, (byte)0xa9,
+ (byte)0x9b, (byte)0x73, (byte)0x2f, (byte)0xd9, (byte)0xa8, (byte)0x8e, (byte)0xc4,
+ (byte)0x48, (byte)0x69, (byte)0x35, (byte)0xe6, (byte)0xf4, (byte)0x73, (byte)0x2f,
+ (byte)0xf9, (byte)0x12, (byte)0x12, (byte)0x71, (byte)0x02, (byte)0x41, (byte)0x00,
+ (byte)0xc4, (byte)0x32, (byte)0x81, (byte)0x5d, (byte)0x19, (byte)0x54, (byte)0x2c,
+ (byte)0x29, (byte)0x5a, (byte)0x9f, (byte)0x36, (byte)0x4c, (byte)0x6f, (byte)0x2d,
+ (byte)0xfd, (byte)0x62, (byte)0x0e, (byte)0xe6, (byte)0x37, (byte)0xc2, (byte)0xf6,
+ (byte)0x69, (byte)0x64, (byte)0xf9, (byte)0x3a, (byte)0xcc, (byte)0xb2, (byte)0x63,
+ (byte)0x2f, (byte)0xa9, (byte)0xfe, (byte)0x7e, (byte)0x8b, (byte)0x2d, (byte)0x69,
+ (byte)0x13, (byte)0xe5, (byte)0x61, (byte)0x58, (byte)0xb7, (byte)0xfa, (byte)0x55,
+ (byte)0x74, (byte)0x2c, (byte)0xe8, (byte)0xa1, (byte)0xac, (byte)0xc3, (byte)0xdd,
+ (byte)0x5b, (byte)0x62, (byte)0xae, (byte)0x0a, (byte)0x27, (byte)0xce, (byte)0xb0,
+ (byte)0xf2, (byte)0x81, (byte)0x5f, (byte)0x9a, (byte)0x6f, (byte)0x5f, (byte)0x3f,
+ (byte)0x5d, (byte)0x02, (byte)0x41, (byte)0x00, (byte)0x92, (byte)0x42, (byte)0xff,
+ (byte)0xac, (byte)0xe5, (byte)0x6d, (byte)0x9c, (byte)0x15, (byte)0x29, (byte)0x36,
+ (byte)0xd7, (byte)0xbd, (byte)0x74, (byte)0x7e, (byte)0x3e, (byte)0xa6, (byte)0x77,
+ (byte)0xce, (byte)0x50, (byte)0xce, (byte)0x00, (byte)0xfc, (byte)0xcc, (byte)0xc8,
+ (byte)0x04, (byte)0x19, (byte)0xe3, (byte)0x03, (byte)0x71, (byte)0xe9, (byte)0x31,
+ (byte)0x9b, (byte)0x88, (byte)0x8f, (byte)0xe6, (byte)0x5c, (byte)0xed, (byte)0x46,
+ (byte)0xf7, (byte)0x82, (byte)0x52, (byte)0x4d, (byte)0xca, (byte)0x20, (byte)0xeb,
+ (byte)0x0d, (byte)0xc7, (byte)0xb6, (byte)0xd2, (byte)0xae, (byte)0x2e, (byte)0xf7,
+ (byte)0xaf, (byte)0xeb, (byte)0x2c, (byte)0xb9, (byte)0xbc, (byte)0x50, (byte)0xfc,
+ (byte)0xf5, (byte)0x7c, (byte)0xba, (byte)0x95, (byte)0x41, (byte)0x02, (byte)0x40,
+ (byte)0x54, (byte)0xf8, (byte)0x46, (byte)0x9c, (byte)0x6a, (byte)0x5e, (byte)0xd0,
+ (byte)0xed, (byte)0x6c, (byte)0x08, (byte)0xed, (byte)0xfc, (byte)0x36, (byte)0x5e,
+ (byte)0x65, (byte)0x91, (byte)0x75, (byte)0x40, (byte)0x71, (byte)0x3f, (byte)0xe7,
+ (byte)0x76, (byte)0x07, (byte)0xbc, (byte)0x04, (byte)0xa2, (byte)0x28, (byte)0x53,
+ (byte)0xda, (byte)0x8d, (byte)0xb5, (byte)0xe1, (byte)0x5a, (byte)0x27, (byte)0x65,
+ (byte)0x8d, (byte)0xaf, (byte)0x56, (byte)0xf4, (byte)0x94, (byte)0x61, (byte)0x3f,
+ (byte)0x67, (byte)0x1c, (byte)0x17, (byte)0xf8, (byte)0x05, (byte)0x19, (byte)0xa2,
+ (byte)0xa1, (byte)0x74, (byte)0x60, (byte)0x49, (byte)0x97, (byte)0xa9, (byte)0xe5,
+ (byte)0x6a, (byte)0x71, (byte)0x6b, (byte)0x55, (byte)0x38, (byte)0x0c, (byte)0xb9,
+ (byte)0x25, (byte)0x02, (byte)0x41, (byte)0x00, (byte)0xae, (byte)0xf2, (byte)0xa8,
+ (byte)0x6d, (byte)0x1d, (byte)0x35, (byte)0x38, (byte)0x73, (byte)0x98, (byte)0x15,
+ (byte)0xc7, (byte)0x15, (byte)0x02, (byte)0x2f, (byte)0x29, (byte)0x5d, (byte)0x18,
+ (byte)0x4b, (byte)0x7d, (byte)0xb2, (byte)0x59, (byte)0xbe, (byte)0x5a, (byte)0xc7,
+ (byte)0x72, (byte)0xd0, (byte)0x80, (byte)0xd8, (byte)0x77, (byte)0xa1, (byte)0x7f,
+ (byte)0xb2, (byte)0x35, (byte)0x0d, (byte)0x78, (byte)0x92, (byte)0x91, (byte)0x35,
+ (byte)0x47, (byte)0xeb, (byte)0x4b, (byte)0x00, (byte)0x59, (byte)0xb4, (byte)0xc4,
+ (byte)0x2c, (byte)0x29, (byte)0xe7, (byte)0x39, (byte)0x9d, (byte)0x48, (byte)0x8b,
+ (byte)0x4f, (byte)0x46, (byte)0xe6, (byte)0xce, (byte)0xd3, (byte)0x6c, (byte)0x84,
+ (byte)0x9b, (byte)0xd2, (byte)0x10, (byte)0xb0, (byte)0xe1
+ };
+
+ /*
String key = "-----BEGIN RSA PRIVATE KEY-----\n"
+ "Proc-Type: 4,ENCRYPTED\n"
+ "DEK-Info: DES-EDE3-CBC,69E26FCC3A7F136E\n"
+ "-----END RSA PRIVATE KEY-----";
ByteArrayInputStream keyArray = new ByteArrayInputStream(key.getBytes());
+ */
/*
Certificate:
ByteArrayInputStream certArray2 = new ByteArrayInputStream(certificate2
.getBytes());
+ byte[] key2Bytes = new byte[] {
+ (byte)0x30, (byte)0x82, (byte)0x02, (byte)0x75, (byte)0x02, (byte)0x01, (byte)0x00,
+ (byte)0x30, (byte)0x0d, (byte)0x06, (byte)0x09, (byte)0x2a, (byte)0x86, (byte)0x48,
+ (byte)0x86, (byte)0xf7, (byte)0x0d, (byte)0x01, (byte)0x01, (byte)0x01, (byte)0x05,
+ (byte)0x00, (byte)0x04, (byte)0x82, (byte)0x02, (byte)0x5f, (byte)0x30, (byte)0x82,
+ (byte)0x02, (byte)0x5b, (byte)0x02, (byte)0x01, (byte)0x00, (byte)0x02, (byte)0x81,
+ (byte)0x81, (byte)0x00, (byte)0xd0, (byte)0x44, (byte)0x5a, (byte)0xc4, (byte)0x76,
+ (byte)0xef, (byte)0xae, (byte)0xff, (byte)0x99, (byte)0x5b, (byte)0xc3, (byte)0x37,
+ (byte)0xc1, (byte)0x09, (byte)0x33, (byte)0xc1, (byte)0x97, (byte)0xe5, (byte)0x64,
+ (byte)0x7a, (byte)0xa9, (byte)0x7e, (byte)0x98, (byte)0x4b, (byte)0x3a, (byte)0xa3,
+ (byte)0x33, (byte)0xd0, (byte)0x5c, (byte)0xc7, (byte)0x56, (byte)0xac, (byte)0xd8,
+ (byte)0x42, (byte)0xe8, (byte)0x4a, (byte)0xac, (byte)0x9c, (byte)0xd9, (byte)0x8f,
+ (byte)0x89, (byte)0x84, (byte)0xc8, (byte)0x46, (byte)0x95, (byte)0xce, (byte)0x22,
+ (byte)0xf7, (byte)0x6a, (byte)0x09, (byte)0xde, (byte)0x91, (byte)0x47, (byte)0x9c,
+ (byte)0x38, (byte)0x23, (byte)0xa5, (byte)0x4a, (byte)0xfc, (byte)0x08, (byte)0xaf,
+ (byte)0x5a, (byte)0xb4, (byte)0x6e, (byte)0x39, (byte)0x8e, (byte)0xe9, (byte)0xf5,
+ (byte)0x0e, (byte)0x46, (byte)0x00, (byte)0x69, (byte)0xe1, (byte)0xe5, (byte)0xcc,
+ (byte)0x4c, (byte)0x81, (byte)0xb6, (byte)0x82, (byte)0x7b, (byte)0x56, (byte)0xfb,
+ (byte)0xf4, (byte)0xdc, (byte)0x04, (byte)0xff, (byte)0x61, (byte)0xe2, (byte)0x7e,
+ (byte)0x5f, (byte)0xe2, (byte)0xf9, (byte)0x97, (byte)0x53, (byte)0x93, (byte)0xd4,
+ (byte)0x69, (byte)0x9b, (byte)0xba, (byte)0x79, (byte)0x20, (byte)0xcd, (byte)0x1e,
+ (byte)0x3e, (byte)0xd5, (byte)0x9a, (byte)0x44, (byte)0x95, (byte)0x7c, (byte)0xcf,
+ (byte)0xc1, (byte)0x51, (byte)0xf2, (byte)0x22, (byte)0xfc, (byte)0xec, (byte)0xcc,
+ (byte)0x66, (byte)0x18, (byte)0x74, (byte)0x60, (byte)0x2a, (byte)0xa2, (byte)0xbe,
+ (byte)0x06, (byte)0xc2, (byte)0x9e, (byte)0x8d, (byte)0x02, (byte)0x03, (byte)0x01,
+ (byte)0x00, (byte)0x01, (byte)0x02, (byte)0x81, (byte)0x80, (byte)0x06, (byte)0x41,
+ (byte)0xd7, (byte)0x7c, (byte)0x49, (byte)0x9a, (byte)0x7f, (byte)0xe6, (byte)0x7c,
+ (byte)0x04, (byte)0x0e, (byte)0xc4, (byte)0x71, (byte)0x0f, (byte)0x46, (byte)0xb7,
+ (byte)0xcd, (byte)0x49, (byte)0x7e, (byte)0x10, (byte)0x55, (byte)0x61, (byte)0x51,
+ (byte)0x50, (byte)0x09, (byte)0x4d, (byte)0xf7, (byte)0xf3, (byte)0x8d, (byte)0xa6,
+ (byte)0x0b, (byte)0x8b, (byte)0x9b, (byte)0xdf, (byte)0xbe, (byte)0xbc, (byte)0xe7,
+ (byte)0x9c, (byte)0xba, (byte)0xc8, (byte)0x9e, (byte)0x38, (byte)0x18, (byte)0x10,
+ (byte)0x4e, (byte)0xd5, (byte)0xe7, (byte)0xa5, (byte)0x09, (byte)0x51, (byte)0x8c,
+ (byte)0x97, (byte)0x4e, (byte)0xd0, (byte)0x79, (byte)0xbb, (byte)0x50, (byte)0x6f,
+ (byte)0x05, (byte)0x4d, (byte)0x79, (byte)0x7f, (byte)0x3f, (byte)0x26, (byte)0x76,
+ (byte)0xc1, (byte)0xcc, (byte)0x40, (byte)0x0f, (byte)0xde, (byte)0x42, (byte)0x5d,
+ (byte)0xc1, (byte)0x5f, (byte)0x70, (byte)0x46, (byte)0x70, (byte)0x8d, (byte)0xff,
+ (byte)0x26, (byte)0x35, (byte)0x75, (byte)0x9a, (byte)0x97, (byte)0xd2, (byte)0x74,
+ (byte)0x53, (byte)0x11, (byte)0x2b, (byte)0xc1, (byte)0x76, (byte)0x9c, (byte)0x9f,
+ (byte)0x93, (byte)0xaa, (byte)0xa8, (byte)0x41, (byte)0x23, (byte)0x9a, (byte)0x04,
+ (byte)0x11, (byte)0x6e, (byte)0x56, (byte)0xea, (byte)0xf5, (byte)0xd6, (byte)0x1d,
+ (byte)0x49, (byte)0x2a, (byte)0x83, (byte)0x49, (byte)0x7d, (byte)0xb7, (byte)0xd1,
+ (byte)0xe6, (byte)0x8d, (byte)0x93, (byte)0x1a, (byte)0x81, (byte)0x8e, (byte)0xc2,
+ (byte)0xb9, (byte)0xbf, (byte)0xfd, (byte)0x00, (byte)0xe2, (byte)0xb5, (byte)0x01,
+ (byte)0x02, (byte)0x41, (byte)0x00, (byte)0xea, (byte)0xce, (byte)0xc6, (byte)0x11,
+ (byte)0x1e, (byte)0xf6, (byte)0xcf, (byte)0x3a, (byte)0x8c, (byte)0xe7, (byte)0x80,
+ (byte)0x16, (byte)0x8f, (byte)0x1d, (byte)0xeb, (byte)0xa2, (byte)0xd2, (byte)0x23,
+ (byte)0x9e, (byte)0xf9, (byte)0xf1, (byte)0x14, (byte)0x16, (byte)0xc8, (byte)0x87,
+ (byte)0xf2, (byte)0x17, (byte)0xdf, (byte)0xc6, (byte)0xe4, (byte)0x1c, (byte)0x74,
+ (byte)0x74, (byte)0xb0, (byte)0xbb, (byte)0x40, (byte)0xeb, (byte)0xa6, (byte)0xb2,
+ (byte)0x5b, (byte)0x6d, (byte)0xf5, (byte)0x9a, (byte)0x85, (byte)0xf1, (byte)0x73,
+ (byte)0x84, (byte)0xec, (byte)0xdb, (byte)0x9b, (byte)0xf9, (byte)0xf8, (byte)0x3d,
+ (byte)0xba, (byte)0xeb, (byte)0xd7, (byte)0x6c, (byte)0x45, (byte)0x7b, (byte)0xca,
+ (byte)0x12, (byte)0x67, (byte)0x5f, (byte)0xcd, (byte)0x02, (byte)0x41, (byte)0x00,
+ (byte)0xe3, (byte)0x10, (byte)0x5b, (byte)0xd0, (byte)0xad, (byte)0x59, (byte)0x90,
+ (byte)0x18, (byte)0x17, (byte)0xdc, (byte)0x68, (byte)0xd4, (byte)0x75, (byte)0x55,
+ (byte)0xab, (byte)0x7d, (byte)0xd1, (byte)0xb5, (byte)0x5a, (byte)0xc4, (byte)0xb0,
+ (byte)0x2d, (byte)0xa9, (byte)0xd1, (byte)0x6f, (byte)0xe9, (byte)0x21, (byte)0x4a,
+ (byte)0x27, (byte)0xc4, (byte)0x98, (byte)0x89, (byte)0xfa, (byte)0x65, (byte)0xb6,
+ (byte)0x10, (byte)0x5d, (byte)0x66, (byte)0xdd, (byte)0x17, (byte)0xb3, (byte)0xf3,
+ (byte)0xd3, (byte)0xe3, (byte)0xa0, (byte)0x1a, (byte)0x93, (byte)0xe4, (byte)0xfb,
+ (byte)0x88, (byte)0xa7, (byte)0x3b, (byte)0x97, (byte)0x1b, (byte)0xf1, (byte)0x08,
+ (byte)0x0c, (byte)0x66, (byte)0xd0, (byte)0x86, (byte)0x5e, (byte)0x39, (byte)0xf9,
+ (byte)0xc1, (byte)0x02, (byte)0x40, (byte)0x24, (byte)0x7c, (byte)0xcd, (byte)0x3a,
+ (byte)0x8b, (byte)0xdd, (byte)0x3e, (byte)0x86, (byte)0x92, (byte)0xae, (byte)0xc6,
+ (byte)0xb0, (byte)0xba, (byte)0xbc, (byte)0xa3, (byte)0x89, (byte)0x41, (byte)0xae,
+ (byte)0x57, (byte)0x5d, (byte)0xef, (byte)0xa0, (byte)0x77, (byte)0x89, (byte)0xe1,
+ (byte)0xd6, (byte)0x34, (byte)0xef, (byte)0x89, (byte)0x30, (byte)0x99, (byte)0x5b,
+ (byte)0x5f, (byte)0x66, (byte)0xb7, (byte)0x32, (byte)0x77, (byte)0x6c, (byte)0x07,
+ (byte)0xfb, (byte)0x3d, (byte)0x33, (byte)0x15, (byte)0x38, (byte)0x0b, (byte)0x35,
+ (byte)0x30, (byte)0x4a, (byte)0xbe, (byte)0x35, (byte)0x96, (byte)0xba, (byte)0x84,
+ (byte)0x9d, (byte)0x2f, (byte)0x58, (byte)0xe2, (byte)0x72, (byte)0x49, (byte)0xb2,
+ (byte)0x34, (byte)0xf9, (byte)0xeb, (byte)0x61, (byte)0x02, (byte)0x40, (byte)0x2a,
+ (byte)0xd4, (byte)0x89, (byte)0x1d, (byte)0x21, (byte)0xb5, (byte)0xc5, (byte)0x32,
+ (byte)0x66, (byte)0x3d, (byte)0xd3, (byte)0x20, (byte)0x50, (byte)0x49, (byte)0xaa,
+ (byte)0xa1, (byte)0x7f, (byte)0x0f, (byte)0x20, (byte)0x61, (byte)0xfd, (byte)0x81,
+ (byte)0x7f, (byte)0x88, (byte)0xdb, (byte)0xfd, (byte)0x33, (byte)0xa4, (byte)0x53,
+ (byte)0x40, (byte)0x08, (byte)0x2d, (byte)0xee, (byte)0xa7, (byte)0x84, (byte)0xe2,
+ (byte)0x2d, (byte)0x5c, (byte)0x1b, (byte)0xd4, (byte)0x3e, (byte)0xc3, (byte)0x7d,
+ (byte)0x72, (byte)0x70, (byte)0x5e, (byte)0xd3, (byte)0x0a, (byte)0xdc, (byte)0x4f,
+ (byte)0x78, (byte)0x8c, (byte)0x0b, (byte)0x02, (byte)0xe0, (byte)0x42, (byte)0x4e,
+ (byte)0x64, (byte)0x8e, (byte)0x6c, (byte)0xea, (byte)0x15, (byte)0x31, (byte)0x81,
+ (byte)0x02, (byte)0x40, (byte)0x57, (byte)0x72, (byte)0xb9, (byte)0x78, (byte)0xc0,
+ (byte)0x1f, (byte)0x5b, (byte)0x1d, (byte)0xb2, (byte)0xcf, (byte)0x94, (byte)0x42,
+ (byte)0xed, (byte)0xbd, (byte)0xe7, (byte)0xaa, (byte)0x14, (byte)0x56, (byte)0xd0,
+ (byte)0x94, (byte)0x25, (byte)0x30, (byte)0x87, (byte)0x35, (byte)0x82, (byte)0xa0,
+ (byte)0x42, (byte)0xb5, (byte)0x7f, (byte)0x66, (byte)0x77, (byte)0xb0, (byte)0x13,
+ (byte)0xbe, (byte)0x57, (byte)0x06, (byte)0x7e, (byte)0x50, (byte)0x67, (byte)0x13,
+ (byte)0xa7, (byte)0x09, (byte)0xac, (byte)0xd6, (byte)0xbf, (byte)0x22, (byte)0x74,
+ (byte)0x6b, (byte)0x37, (byte)0x92, (byte)0x2b, (byte)0x91, (byte)0xbd, (byte)0x0a,
+ (byte)0xd8, (byte)0x0f, (byte)0x8d, (byte)0x86, (byte)0x4b, (byte)0x20, (byte)0x5e,
+ (byte)0x50, (byte)0x60, (byte)0x80
+ };
+
+ /*
String key2 = "-----BEGIN RSA PRIVATE KEY-----\n"
+ "Proc-Type: 4,ENCRYPTED\n"
+ "DEK-Info: DES-EDE3-CBC,370723FFDC1B1CFA\n"
+ "-----END RSA PRIVATE KEY-----";
ByteArrayInputStream keyArray2 = new ByteArrayInputStream(key2.getBytes());
-
+ */
+
/*
Certificate:
Data:
ByteArrayInputStream certArray3 = new ByteArrayInputStream(certificate3
.getBytes());
+ byte[] key3Bytes = new byte[] {
+ (byte)0x30, (byte)0x82, (byte)0x02, (byte)0x76, (byte)0x02, (byte)0x01, (byte)0x00,
+ (byte)0x30, (byte)0x0d, (byte)0x06, (byte)0x09, (byte)0x2a, (byte)0x86, (byte)0x48,
+ (byte)0x86, (byte)0xf7, (byte)0x0d, (byte)0x01, (byte)0x01, (byte)0x01, (byte)0x05,
+ (byte)0x00, (byte)0x04, (byte)0x82, (byte)0x02, (byte)0x60, (byte)0x30, (byte)0x82,
+ (byte)0x02, (byte)0x5c, (byte)0x02, (byte)0x01, (byte)0x00, (byte)0x02, (byte)0x81,
+ (byte)0x81, (byte)0x00, (byte)0xb4, (byte)0xc5, (byte)0xed, (byte)0xdf, (byte)0x30,
+ (byte)0x42, (byte)0x6d, (byte)0x8b, (byte)0xaf, (byte)0x4b, (byte)0xe4, (byte)0x9c,
+ (byte)0x13, (byte)0x5e, (byte)0x83, (byte)0x23, (byte)0xcd, (byte)0x2f, (byte)0xce,
+ (byte)0x34, (byte)0xe2, (byte)0x43, (byte)0xd7, (byte)0x6c, (byte)0x72, (byte)0xbb,
+ (byte)0x03, (byte)0xb3, (byte)0xb9, (byte)0x24, (byte)0x02, (byte)0xe0, (byte)0xcc,
+ (byte)0xb5, (byte)0x8d, (byte)0xd6, (byte)0x92, (byte)0x41, (byte)0x04, (byte)0x2b,
+ (byte)0x5c, (byte)0x94, (byte)0xb2, (byte)0xc3, (byte)0x9c, (byte)0x9d, (byte)0x56,
+ (byte)0xf0, (byte)0x99, (byte)0xbc, (byte)0x0f, (byte)0x81, (byte)0xaf, (byte)0xeb,
+ (byte)0x54, (byte)0xed, (byte)0x80, (byte)0xa6, (byte)0xa0, (byte)0xc7, (byte)0xc2,
+ (byte)0x43, (byte)0x05, (byte)0x04, (byte)0x7c, (byte)0x9c, (byte)0x7e, (byte)0x07,
+ (byte)0x03, (byte)0x10, (byte)0xb9, (byte)0xbd, (byte)0xc5, (byte)0x16, (byte)0xcf,
+ (byte)0x19, (byte)0xdd, (byte)0xe3, (byte)0x4f, (byte)0x73, (byte)0x83, (byte)0x72,
+ (byte)0xc5, (byte)0x66, (byte)0xe4, (byte)0x5b, (byte)0x14, (byte)0xc4, (byte)0x96,
+ (byte)0xd1, (byte)0xe3, (byte)0x24, (byte)0x0b, (byte)0xb6, (byte)0xd4, (byte)0xf7,
+ (byte)0x84, (byte)0x2e, (byte)0xb1, (byte)0xe7, (byte)0x93, (byte)0x02, (byte)0x9d,
+ (byte)0xf5, (byte)0xda, (byte)0xaa, (byte)0xc1, (byte)0xd9, (byte)0xcc, (byte)0x5e,
+ (byte)0x36, (byte)0xe9, (byte)0x8f, (byte)0xbf, (byte)0x8b, (byte)0xda, (byte)0xa7,
+ (byte)0x45, (byte)0x82, (byte)0xf2, (byte)0xb0, (byte)0xf5, (byte)0xa7, (byte)0xe4,
+ (byte)0xe1, (byte)0x80, (byte)0xa3, (byte)0x17, (byte)0x02, (byte)0x03, (byte)0x01,
+ (byte)0x00, (byte)0x01, (byte)0x02, (byte)0x81, (byte)0x80, (byte)0x53, (byte)0xbc,
+ (byte)0x1f, (byte)0x1c, (byte)0x34, (byte)0x09, (byte)0x81, (byte)0x1e, (byte)0xa3,
+ (byte)0xfb, (byte)0x5e, (byte)0x90, (byte)0xa1, (byte)0x34, (byte)0x35, (byte)0x40,
+ (byte)0x9f, (byte)0x29, (byte)0xd6, (byte)0xb5, (byte)0x8e, (byte)0x5d, (byte)0x68,
+ (byte)0x6a, (byte)0xf6, (byte)0x96, (byte)0x03, (byte)0xf7, (byte)0xfa, (byte)0xf9,
+ (byte)0x60, (byte)0x4f, (byte)0xea, (byte)0xe2, (byte)0xea, (byte)0x29, (byte)0x8b,
+ (byte)0x23, (byte)0x8c, (byte)0x9f, (byte)0xdd, (byte)0x49, (byte)0x8f, (byte)0xa8,
+ (byte)0xa6, (byte)0x62, (byte)0x07, (byte)0x44, (byte)0x79, (byte)0xa1, (byte)0xaf,
+ (byte)0xf9, (byte)0x1d, (byte)0x98, (byte)0xbf, (byte)0x85, (byte)0x28, (byte)0x03,
+ (byte)0x87, (byte)0x14, (byte)0x20, (byte)0xba, (byte)0xd4, (byte)0x96, (byte)0x61,
+ (byte)0x2a, (byte)0xd0, (byte)0xaa, (byte)0x30, (byte)0x19, (byte)0x4b, (byte)0x40,
+ (byte)0x35, (byte)0xb0, (byte)0x79, (byte)0x0b, (byte)0x7f, (byte)0xd7, (byte)0xcd,
+ (byte)0x64, (byte)0xd9, (byte)0x93, (byte)0x38, (byte)0xe2, (byte)0x59, (byte)0xe0,
+ (byte)0x9e, (byte)0x3a, (byte)0x25, (byte)0x27, (byte)0xa2, (byte)0xd9, (byte)0x20,
+ (byte)0xb0, (byte)0x45, (byte)0x5f, (byte)0x6c, (byte)0x15, (byte)0x6f, (byte)0x10,
+ (byte)0x55, (byte)0xa7, (byte)0xf9, (byte)0x3d, (byte)0x92, (byte)0x3c, (byte)0x7c,
+ (byte)0x23, (byte)0x1b, (byte)0xc0, (byte)0xb5, (byte)0x17, (byte)0x41, (byte)0x5e,
+ (byte)0x8c, (byte)0xdc, (byte)0x25, (byte)0x1d, (byte)0x35, (byte)0x2b, (byte)0xd3,
+ (byte)0x97, (byte)0x1a, (byte)0x6f, (byte)0xae, (byte)0xeb, (byte)0xf5, (byte)0xf9,
+ (byte)0x02, (byte)0x41, (byte)0x00, (byte)0xd7, (byte)0x3e, (byte)0xed, (byte)0x70,
+ (byte)0xfe, (byte)0xee, (byte)0x0e, (byte)0x30, (byte)0x29, (byte)0xfa, (byte)0xd7,
+ (byte)0x38, (byte)0xcf, (byte)0x8e, (byte)0xc1, (byte)0x9c, (byte)0x78, (byte)0x06,
+ (byte)0x2d, (byte)0xda, (byte)0x33, (byte)0x58, (byte)0xa1, (byte)0x7b, (byte)0xbf,
+ (byte)0x00, (byte)0xb9, (byte)0xdf, (byte)0xea, (byte)0x65, (byte)0x86, (byte)0xbb,
+ (byte)0xcc, (byte)0x83, (byte)0xce, (byte)0xde, (byte)0xc3, (byte)0xf8, (byte)0x89,
+ (byte)0xf5, (byte)0x9f, (byte)0xa6, (byte)0x1d, (byte)0xc9, (byte)0xfb, (byte)0x98,
+ (byte)0xa1, (byte)0x2e, (byte)0xe0, (byte)0x57, (byte)0x6e, (byte)0xbd, (byte)0x57,
+ (byte)0x20, (byte)0xf9, (byte)0x6b, (byte)0x13, (byte)0x42, (byte)0x9d, (byte)0x8d,
+ (byte)0x66, (byte)0x4d, (byte)0x7a, (byte)0x2d, (byte)0x02, (byte)0x41, (byte)0x00,
+ (byte)0xd7, (byte)0x00, (byte)0x18, (byte)0x54, (byte)0xe8, (byte)0x37, (byte)0xdb,
+ (byte)0xf8, (byte)0x98, (byte)0x7b, (byte)0x18, (byte)0x33, (byte)0xf6, (byte)0x28,
+ (byte)0xa8, (byte)0x8c, (byte)0xd9, (byte)0xfd, (byte)0x4c, (byte)0x4e, (byte)0x41,
+ (byte)0x73, (byte)0x2e, (byte)0x79, (byte)0x31, (byte)0xcc, (byte)0x7d, (byte)0x42,
+ (byte)0xb7, (byte)0xa1, (byte)0xd2, (byte)0xbc, (byte)0x1f, (byte)0x62, (byte)0xcf,
+ (byte)0x15, (byte)0x7c, (byte)0x62, (byte)0x97, (byte)0x70, (byte)0xf1, (byte)0x15,
+ (byte)0xf1, (byte)0x33, (byte)0xa1, (byte)0x9d, (byte)0xbb, (byte)0x5f, (byte)0xd7,
+ (byte)0x5a, (byte)0xf9, (byte)0x24, (byte)0x58, (byte)0xac, (byte)0x86, (byte)0x6a,
+ (byte)0xed, (byte)0xd4, (byte)0x84, (byte)0xe4, (byte)0x3f, (byte)0xfe, (byte)0xb0,
+ (byte)0xd3, (byte)0x02, (byte)0x41, (byte)0x00, (byte)0xd4, (byte)0xb7, (byte)0x84,
+ (byte)0xb2, (byte)0x39, (byte)0xce, (byte)0x0b, (byte)0x49, (byte)0x80, (byte)0x03,
+ (byte)0x3c, (byte)0xb5, (byte)0x11, (byte)0x32, (byte)0x34, (byte)0x96, (byte)0xac,
+ (byte)0x6a, (byte)0xf6, (byte)0xdf, (byte)0x80, (byte)0x04, (byte)0xe4, (byte)0x39,
+ (byte)0xc6, (byte)0x0e, (byte)0x32, (byte)0xa3, (byte)0x5e, (byte)0x23, (byte)0x0d,
+ (byte)0x9f, (byte)0x04, (byte)0xc3, (byte)0x72, (byte)0x2a, (byte)0xe6, (byte)0xa2,
+ (byte)0xf5, (byte)0xbc, (byte)0x3f, (byte)0x15, (byte)0x4c, (byte)0xb5, (byte)0x33,
+ (byte)0x26, (byte)0xa8, (byte)0x8c, (byte)0x09, (byte)0xfb, (byte)0x7e, (byte)0x1e,
+ (byte)0x32, (byte)0x40, (byte)0x0d, (byte)0x1d, (byte)0xcb, (byte)0x7f, (byte)0xf6,
+ (byte)0xf2, (byte)0x29, (byte)0x9b, (byte)0x01, (byte)0xd5, (byte)0x02, (byte)0x40,
+ (byte)0x24, (byte)0x26, (byte)0x1c, (byte)0xf1, (byte)0x31, (byte)0xb6, (byte)0x2a,
+ (byte)0xa3, (byte)0x0a, (byte)0xa8, (byte)0x2f, (byte)0xb2, (byte)0x94, (byte)0xe1,
+ (byte)0xd3, (byte)0x2d, (byte)0x13, (byte)0x7d, (byte)0xd6, (byte)0x35, (byte)0x96,
+ (byte)0x25, (byte)0x92, (byte)0x9b, (byte)0xc7, (byte)0xf6, (byte)0xb4, (byte)0xdc,
+ (byte)0xe1, (byte)0xd9, (byte)0x30, (byte)0x80, (byte)0x76, (byte)0xda, (byte)0x7b,
+ (byte)0x2d, (byte)0x06, (byte)0xa3, (byte)0xe1, (byte)0x08, (byte)0x99, (byte)0x50,
+ (byte)0x72, (byte)0x24, (byte)0x97, (byte)0x38, (byte)0xd9, (byte)0x07, (byte)0x4d,
+ (byte)0x43, (byte)0x3b, (byte)0x7e, (byte)0x93, (byte)0xf6, (byte)0x36, (byte)0x07,
+ (byte)0x86, (byte)0x83, (byte)0x63, (byte)0xf0, (byte)0xa8, (byte)0x9d, (byte)0xdf,
+ (byte)0x07, (byte)0x02, (byte)0x40, (byte)0x3e, (byte)0x58, (byte)0x03, (byte)0xbf,
+ (byte)0xea, (byte)0x3e, (byte)0x34, (byte)0x2c, (byte)0xb7, (byte)0xc3, (byte)0x09,
+ (byte)0xe9, (byte)0xf4, (byte)0x43, (byte)0x41, (byte)0xc4, (byte)0x7c, (byte)0x6e,
+ (byte)0x75, (byte)0x72, (byte)0x5d, (byte)0xfc, (byte)0xa3, (byte)0x75, (byte)0x1d,
+ (byte)0xa0, (byte)0xee, (byte)0xc2, (byte)0x1f, (byte)0x71, (byte)0xb0, (byte)0xf3,
+ (byte)0x1d, (byte)0xec, (byte)0x81, (byte)0xdb, (byte)0x45, (byte)0xe5, (byte)0x6a,
+ (byte)0xe8, (byte)0xe0, (byte)0x64, (byte)0x90, (byte)0xff, (byte)0xb9, (byte)0xf8,
+ (byte)0x12, (byte)0xed, (byte)0x55, (byte)0x5c, (byte)0x9b, (byte)0x81, (byte)0xcd,
+ (byte)0xbb, (byte)0x06, (byte)0x91, (byte)0xfe, (byte)0x27, (byte)0x2c, (byte)0x3a,
+ (byte)0xed, (byte)0x96, (byte)0x3b, (byte)0xfe
+ };
+
+ /*
String key3 = "-----BEGIN RSA PRIVATE KEY-----\n"
+ "Proc-Type: 4,ENCRYPTED\n"
+ "DEK-Info: DES-EDE3-CBC,0EE6B33EC2D92297\n"
+ "-----END RSA PRIVATE KEY-----";
ByteArrayInputStream keyArray3 = new ByteArrayInputStream(key3.getBytes());
+ */
@Override
protected void setUp() {
CertificateFactory cf = CertificateFactory.getInstance("X.509");
KeyFactory kf = KeyFactory.getInstance("RSA");
keyTest = KeyStore.getInstance(KeyStore.getDefaultType());
- keyTest.load(null, null);
+ keyTest.load(null, "1234".toCharArray());
if (keyType.equals(client)) {
keys = new PrivateKey[3];
- keys[0] = kf.generatePrivate(new X509EncodedKeySpec(key.getBytes()));
- keys[1] = kf.generatePrivate(new X509EncodedKeySpec(key2.getBytes()));
- keys[2] = kf.generatePrivate(new X509EncodedKeySpec(key3.getBytes()));
+ keys[0] = kf.generatePrivate(new PKCS8EncodedKeySpec(keyBytes));
+ keys[1] = kf.generatePrivate(new PKCS8EncodedKeySpec(key2Bytes));
+ keys[2] = kf.generatePrivate(new PKCS8EncodedKeySpec(key3Bytes));
cert = new X509Certificate[3];
cert[0] = (X509Certificate) cf.generateCertificate(certArray);
cert[1] = (X509Certificate) cf.generateCertificate(certArray2);
cert[2] = (X509Certificate) cf.generateCertificate(certArray3);
- keyTest.setKeyEntry("clientKey_01", keys[1], password.toCharArray(), new X509Certificate[] {cert[0], cert[1]});
- keyTest.setKeyEntry("clientKey_02", keys[2], password.toCharArray(), new X509Certificate[] {cert[0], cert[2]});
+ keyTest.setKeyEntry("clientKey_01", keys[0], password.toCharArray(), new X509Certificate[] {cert[0]});
+ keyTest.setKeyEntry("clientKey_02", keys[1], password.toCharArray(), new X509Certificate[] {cert[0], cert[1]});
+ keyTest.setKeyEntry("clientKey_03", keys[2], password.toCharArray(), new X509Certificate[] {cert[0], cert[2]});
keyTest.setCertificateEntry("clientAlias_01", cert[0]);
keyTest.setCertificateEntry("clientAlias_02", cert[0]);
keyTest.setCertificateEntry("clientAlias_03", cert[1]);
} else if (keyType.equals(server)) {
+ keys = new PrivateKey[1];
+ keys[0] = kf.generatePrivate(new PKCS8EncodedKeySpec(keyBytes));
cert = new X509Certificate[1];
cert[0] = (X509Certificate) cf.generateCertificate(certArray3);
+ keyTest.setKeyEntry("serverKey_00", keys[0], password.toCharArray(), new X509Certificate[] {cert[0]});
keyTest.setCertificateEntry("serverAlias_00", cert[0]);
}
} catch (Exception ex) {
throw new IllegalArgumentException(ex.getMessage());
}
try {
- factory.init(keyTest, null);
+ factory.init(keyTest, "1234".toCharArray());
} catch (Exception e) {
fail("Could't init the KeyManagerFactory");
}
method = "getClientAliases",
args = {java.lang.String.class, java.security.Principal[].class}
)
- @BrokenTest("Test needs to add PrivateKeys to the Store to work properly.")
public void test_getClientAliases() {
init(client);
assertNull(manager.getClientAliases(null, null));
method = "chooseClientAlias",
args = {java.lang.String[].class, java.security.Principal[].class, java.net.Socket.class}
)
- @BrokenTest("Test needs to add PrivateKeys to the Store to work properly.")
public void test_chooseClientAlias() {
String[] ar = {client};
init(client);
assertNull(manager.chooseClientAlias(null, null, new Socket()));
assertNull(manager.chooseClientAlias(new String[0], null, new Socket()));
- String res = manager.chooseClientAlias(ar, null, new Socket());
- assertEquals("clientalias_03", res);
- res = manager.chooseClientAlias(ar, null, null);
- assertEquals("clientalias_02", res);
+ assertNull(manager.chooseClientAlias(ar, null, new Socket()));
+ String res = manager.chooseClientAlias(new String[]{type}, null, null);
+ assertNotNull(res);
+ assertEquals("clientkey_03", res.toLowerCase().toLowerCase());
}
/**
method = "getServerAliases",
args = {java.lang.String.class, java.security.Principal[].class}
)
- @BrokenTest("Test needs to add PrivateKeys to the Store to work properly.")
public void test_getServerAliases() {
init(server);
assertNull(manager.getServerAliases(null, null));
String[] resArray = manager.getServerAliases(type, null);
assertNotNull(resArray);
assertEquals("Incorrect length", 1, resArray.length);
- assertEquals("Incorrect aliase", "serveralias_00", resArray[0]);
+ assertEquals("Incorrect aliase", "serverkey_00", resArray[0].toLowerCase());
}
/**
method = "chooseServerAlias",
args = {java.lang.String.class, java.security.Principal[].class, java.net.Socket.class}
)
- @BrokenTest("Test needs to add PrivateKeys to the Store to work properly.")
public void test_chooseServerAlias() {
init(server);
assertNull(manager.chooseServerAlias(null, null, new Socket()));
assertNull(manager.chooseServerAlias("", null, new Socket()));
- assertNull(manager.chooseServerAlias(type, null, null));
- String res = manager.chooseServerAlias(type, null, new Socket());
- assertEquals("serveralias_00", res);
+ String res = manager.chooseServerAlias(type, null, null);
+ assertNotNull(res);
+ assertEquals("serverkey_00", res.toLowerCase());
+ res = manager.chooseServerAlias(type, null, new Socket());
+ assertNotNull(res);
+ assertEquals("serverkey_00", res.toLowerCase());
}
/**
method = "getCertificateChain",
args = {java.lang.String.class}
)
- @BrokenTest("Test needs to add PrivateKeys to the Store to work properly.")
public void test_getCertificateChain() {
init(server);
assertNull("Not NULL for NULL parameter", manager.getCertificateChain(null));
method = "getPrivateKey",
args = {java.lang.String.class}
)
- @BrokenTest("Test needs to add PrivateKeys to the Store to work properly.")
public void test_getPrivateKey() {
init(client);
assertNull("Not NULL for NULL parameter", manager.getPrivateKey(null));
return false;
}
for (int i = 0; i < ar.length; i++) {
- if (!ar[i].equals("clientalias_01") && !ar[i].equals("clientalias_02") && !ar[i].equals("clientalias_03")) {
+ if (!ar[i].toLowerCase().equals("clientkey_01") && !ar[i].toLowerCase().equals("clientkey_02") && !ar[i].toLowerCase().equals("clientkey_03")) {
return false;
}
}