summaryrefslogtreecommitdiffstats
path: root/support/src/test/java/tests
diff options
context:
space:
mode:
authorBrian Carlstrom <bdc@google.com>2010-07-22 16:33:48 -0700
committerBrian Carlstrom <bdc@google.com>2010-08-02 17:56:01 -0700
commit4559b1d37edcb5d7f1da086cf2e3290388d74f46 (patch)
tree133c420e10d86b8d0501243e5fd60a4916476041 /support/src/test/java/tests
parent4fe378672d700aaae3a50db956b693b3ed599c7d (diff)
downloadlibcore-4559b1d37edcb5d7f1da086cf2e3290388d74f46.zip
libcore-4559b1d37edcb5d7f1da086cf2e3290388d74f46.tar.gz
libcore-4559b1d37edcb5d7f1da086cf2e3290388d74f46.tar.bz2
Support for TLS Extensions enabled SSLSockets with fallback to vanila SSL
See also b/1569612 Summary: - OpenSSlSocket support for SNI, session tickets, compression - URLConnection mimics Chrome behavior of trying connection with these enabled, falling back to SSL w/o encryption on failure Details: libcore URLConnection https retry Change HttpConnection.getSecureSocket to enable non-standard features on first connection attempt. On second attempt, we back off to SSLv3 from TLSv1, mimicking Chrome's behavior. luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/http/HttpConnection.java Change HttpsEngine.connect to implement SSL reconnect luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/https/HttpsURLConnectionImpl.java OpenSSL SSLSocket implementation OpenSSLSocketImpl and OpenSSLServerSocketImpl now have an array of enabled compression methods interface and implementation to parallel that of procotols and ciphersuites. luni/src/main/java/org/apache/harmony/xnet/provider/jsse/OpenSSLSocketImpl.java luni/src/main/java/org/apache/harmony/xnet/provider/jsse/OpenSSLServerSocketImpl.java OpenSSLSessionImpl now has a cache of the native compressionMethod. Also replaced "gives" javadoc working with "returns". luni/src/main/java/org/apache/harmony/xnet/provider/jsse/OpenSSLSessionImpl.java OpenSSLSocketImpl session caching now needs to skip cached sessions with mismatched compression requirements. luni/src/main/java/org/apache/harmony/xnet/provider/jsse/OpenSSLSocketImpl.java OpenSSLSocketImpl.startHandshake now uses NativeCrypto to support our non-standard extensions. luni/src/main/java/org/apache/harmony/xnet/provider/jsse/OpenSSLSocketImpl.java NativeCrypto changes - Added declaration of SSL options for tickets and compression. - Added general "compression methods" interface paralleling "cipher suites" and "protocols" interfaces. - Added SSL_set_tlsext_host_name to set SNI (Server Name Indication) value - Added SSL_get_servername to read SNI (Server Name Indication) value - Added SSL_SESSION_compress_meth read negotiated compression method - SSL_new makes sure to default compression to off for compatibility luni/src/main/java/org/apache/harmony/xnet/provider/jsse/NativeCrypto.java luni/src/main/native/NativeCrypto.cpp Testing Added URLConnectionTest.testConnectViaHttpsWithSSLFallback to make sure we properly retry an https connection if the server terminates unexpectedly. Fixed up URLConnectionTest.testHttpsWithCustomTrustManager with new expected certificate chain. Fixed a few mistaken TestSSLContext.serverContext uses to clientContext luni/src/test/java/java/net/URLConnectionTest.java Added test_SSL_set_tlsext_host_name, test_SSL_get_servername, test_SSL_SESSION_compress_meth. Added a number of missing fail() calls in expected exception cases which caught one test with mistaken expectations. Removed some unnecessary scopes. Fixed some badly scoped catch blocks. luni/src/test/java/org/apache/harmony/xnet/provider/jsse/NativeCryptoTest.java Changed MockWebServer to support a new MockResponse propery of disconnectAtStart, which immediately terminates the connection support/src/test/java/tests/http/MockResponse.java support/src/test/java/tests/http/MockWebServer.java external/openssl Restore -ZLIB to OpenSSL build. Note that NativeCrypto.SSL_new disables compression by for default SSLSocket for compatibility. android-config.mk Force clean build with new CFLAGS CleanSpec.mk Change-Id: Iba6268f9096f2be43f0d30de151dd3fd0aea4a81
Diffstat (limited to 'support/src/test/java/tests')
-rw-r--r--support/src/test/java/tests/http/MockResponse.java23
-rw-r--r--support/src/test/java/tests/http/MockWebServer.java7
2 files changed, 29 insertions, 1 deletions
diff --git a/support/src/test/java/tests/http/MockResponse.java b/support/src/test/java/tests/http/MockResponse.java
index 734253b..b6f6f66 100644
--- a/support/src/test/java/tests/http/MockResponse.java
+++ b/support/src/test/java/tests/http/MockResponse.java
@@ -35,6 +35,7 @@ public class MockResponse {
private String status = "HTTP/1.1 200 OK";
private List<String> headers = new ArrayList<String>();
private byte[] body = EMPTY_BODY;
+ private boolean disconnectAtStart;
private boolean disconnectAtEnd;
public MockResponse() {
@@ -122,6 +123,28 @@ public class MockResponse {
return setChunkedBody(body.getBytes(ASCII), maxChunkSize);
}
+ /**
+ * Request immediate close of connection without even reading the
+ * request.
+ * <p>
+ * Use to simulate the real life case of losing connection
+ * because of bugger SSL server close connection when it seems
+ * something like a compression method or TLS extension it doesn't
+ * understand, instead of simply ignoring it like it should.
+ */
+ public MockResponse setDisconnectAtStart(boolean disconnectAtStart) {
+ this.disconnectAtStart = disconnectAtStart;
+ return this;
+ }
+
+ public boolean getDisconnectAtStart() {
+ return disconnectAtStart;
+ }
+
+ /**
+ * Request close of connection after the response. This is the
+ * default HTTP/1.0 behavior.
+ */
public MockResponse setDisconnectAtEnd(boolean disconnectAtEnd) {
this.disconnectAtEnd = disconnectAtEnd;
return this;
diff --git a/support/src/test/java/tests/http/MockWebServer.java b/support/src/test/java/tests/http/MockWebServer.java
index fe35bf4..0e965b2 100644
--- a/support/src/test/java/tests/http/MockWebServer.java
+++ b/support/src/test/java/tests/http/MockWebServer.java
@@ -196,7 +196,7 @@ public final class MockWebServer {
}
}
- public void acceptConnections() throws IOException {
+ public void acceptConnections() throws Exception {
int count = 0;
while (true) {
if (count > 0 && responseQueue.isEmpty()) {
@@ -204,6 +204,11 @@ public final class MockWebServer {
}
Socket socket = serverSocket.accept();
+ if (responseQueue.peek().getDisconnectAtStart()) {
+ responseQueue.take();
+ socket.close();
+ continue;
+ }
openClientSockets.add(socket);
serveConnection(socket);
count++;