summaryrefslogtreecommitdiffstats
path: root/bcprov/src/main/java/org/bouncycastle/crypto/tls/test/TlsSRPProtocolTest.java
diff options
context:
space:
mode:
authorSergio Giro <sgiro@google.com>2016-02-01 14:37:23 +0000
committerSergio Giro <sgiro@google.com>2016-02-01 15:16:12 +0000
commit397d32894b89b506dc318e0f83446187c9b76ebe (patch)
tree8229ff72c8cbb06f49dce3a8382930919fa6fc2b /bcprov/src/main/java/org/bouncycastle/crypto/tls/test/TlsSRPProtocolTest.java
parent9b30eb05e5be69d51881a0d1b31e503e97acd784 (diff)
parent6d876f3f0ae553704a1dcf7e89003fcf14717037 (diff)
downloadandroid_external_bouncycastle-397d32894b89b506dc318e0f83446187c9b76ebe.tar.gz
android_external_bouncycastle-397d32894b89b506dc318e0f83446187c9b76ebe.tar.bz2
android_external_bouncycastle-397d32894b89b506dc318e0f83446187c9b76ebe.zip
Merge remote-tracking branch 'aosp/upstream-master' into merge-152-from-upstream
As to set a common ancestor for future merges from aosp/upstream-master (when updating to new versions of bouncycastle). We'll override all the changes of this commit with patch https://android-review.googlesource.com/#/c/199872 Change-Id: I53a7f797b520a6e119878dbae53246cdcc585ddf
Diffstat (limited to 'bcprov/src/main/java/org/bouncycastle/crypto/tls/test/TlsSRPProtocolTest.java')
-rw-r--r--bcprov/src/main/java/org/bouncycastle/crypto/tls/test/TlsSRPProtocolTest.java81
1 files changed, 81 insertions, 0 deletions
diff --git a/bcprov/src/main/java/org/bouncycastle/crypto/tls/test/TlsSRPProtocolTest.java b/bcprov/src/main/java/org/bouncycastle/crypto/tls/test/TlsSRPProtocolTest.java
new file mode 100644
index 0000000..b0c3c92
--- /dev/null
+++ b/bcprov/src/main/java/org/bouncycastle/crypto/tls/test/TlsSRPProtocolTest.java
@@ -0,0 +1,81 @@
+package org.bouncycastle.crypto.tls.test;
+
+import java.io.OutputStream;
+import java.io.PipedInputStream;
+import java.io.PipedOutputStream;
+import java.security.SecureRandom;
+
+import junit.framework.TestCase;
+
+import org.bouncycastle.crypto.tls.TlsClientProtocol;
+import org.bouncycastle.crypto.tls.TlsServerProtocol;
+import org.bouncycastle.util.Arrays;
+import org.bouncycastle.util.io.Streams;
+
+public class TlsSRPProtocolTest
+ extends TestCase
+{
+ public void testClientServer() throws Exception
+ {
+ SecureRandom secureRandom = new SecureRandom();
+
+ PipedInputStream clientRead = new PipedInputStream();
+ PipedInputStream serverRead = new PipedInputStream();
+ PipedOutputStream clientWrite = new PipedOutputStream(serverRead);
+ PipedOutputStream serverWrite = new PipedOutputStream(clientRead);
+
+ TlsClientProtocol clientProtocol = new TlsClientProtocol(clientRead, clientWrite, secureRandom);
+ TlsServerProtocol serverProtocol = new TlsServerProtocol(serverRead, serverWrite, secureRandom);
+
+ ServerThread serverThread = new ServerThread(serverProtocol);
+ serverThread.start();
+
+ MockSRPTlsClient client = new MockSRPTlsClient(null, MockSRPTlsServer.TEST_IDENTITY, MockSRPTlsServer.TEST_PASSWORD);
+ clientProtocol.connect(client);
+
+ // NOTE: Because we write-all before we read-any, this length can't be more than the pipe capacity
+ int length = 1000;
+
+ byte[] data = new byte[length];
+ secureRandom.nextBytes(data);
+
+ OutputStream output = clientProtocol.getOutputStream();
+ output.write(data);
+
+ byte[] echo = new byte[data.length];
+ int count = Streams.readFully(clientProtocol.getInputStream(), echo);
+
+ assertEquals(count, data.length);
+ assertTrue(Arrays.areEqual(data, echo));
+
+ output.close();
+
+ serverThread.join();
+ }
+
+ static class ServerThread
+ extends Thread
+ {
+ private final TlsServerProtocol serverProtocol;
+
+ ServerThread(TlsServerProtocol serverProtocol)
+ {
+ this.serverProtocol = serverProtocol;
+ }
+
+ public void run()
+ {
+ try
+ {
+ MockSRPTlsServer server = new MockSRPTlsServer();
+ serverProtocol.accept(server);
+ Streams.pipeAll(serverProtocol.getInputStream(), serverProtocol.getOutputStream());
+ serverProtocol.close();
+ }
+ catch (Exception e)
+ {
+ //throw new RuntimeException(e);
+ }
+ }
+ }
+}