Commit 36f1c15a authored by Brian Carlstrom's avatar Brian Carlstrom
Browse files

Fixed interruption of blocked SSLSocket via Socket.close()

Bug: 10599593

(cherry picked from commit 3f17b9a7)

Change-Id: I1bffa8189d64aa8ee0aa1ac414359aecb71934a5
parent c1b838f6
......@@ -95,11 +95,10 @@ LOCAL_CFLAGS += $(core_cflags)
LOCAL_CFLAGS += -DJNI_JARJAR_PREFIX="com/android/"
LOCAL_CPPFLAGS += $(core_cppflags)
LOCAL_SRC_FILES := \
crypto/src/main/native/org_conscrypt_NativeCrypto.cpp \
luni/src/main/native/AsynchronousSocketCloseMonitor.cpp
crypto/src/main/native/org_conscrypt_NativeCrypto.cpp
LOCAL_C_INCLUDES += $(core_c_includes) \
libcore/luni/src/main/native
LOCAL_SHARED_LIBRARIES += $(core_shared_libraries) libcrypto libssl libnativehelper libz
LOCAL_SHARED_LIBRARIES += $(core_shared_libraries) libcrypto libssl libnativehelper libz libjavacore
LOCAL_STATIC_LIBRARIES += $(core_static_libraries)
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE := libjavacrypto
......@@ -146,8 +145,7 @@ ifeq ($(WITH_HOST_DALVIK),true)
# Conscrypt native library for host
include $(CLEAR_VARS)
LOCAL_SRC_FILES += \
crypto/src/main/native/org_conscrypt_NativeCrypto.cpp \
luni/src/main/native/AsynchronousSocketCloseMonitor.cpp
crypto/src/main/native/org_conscrypt_NativeCrypto.cpp
LOCAL_C_INCLUDES += $(core_c_includes) \
libcore/luni/src/main/native
LOCAL_CPPFLAGS += $(core_cppflags)
......@@ -156,15 +154,14 @@ ifeq ($(WITH_HOST_DALVIK),true)
LOCAL_MODULE := libjavacrypto
LOCAL_CFLAGS += -DJNI_JARJAR_PREFIX="com/android/"
LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/NativeCode.mk
LOCAL_SHARED_LIBRARIES += $(core_shared_libraries) libssl-host libcrypto-host
LOCAL_SHARED_LIBRARIES += $(core_shared_libraries) libssl-host libcrypto-host libjavacore
LOCAL_STATIC_LIBRARIES += $(core_static_libraries)
include $(BUILD_HOST_SHARED_LIBRARY)
# Conscrypt native library for nojarjar'd version
include $(CLEAR_VARS)
LOCAL_SRC_FILES += \
crypto/src/main/native/org_conscrypt_NativeCrypto.cpp \
luni/src/main/native/AsynchronousSocketCloseMonitor.cpp
crypto/src/main/native/org_conscrypt_NativeCrypto.cpp
LOCAL_C_INCLUDES += $(core_c_includes) \
libcore/luni/src/main/native
LOCAL_CPPFLAGS += $(core_cppflags)
......@@ -172,7 +169,7 @@ ifeq ($(WITH_HOST_DALVIK),true)
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE := libconscrypt_jni
LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/NativeCode.mk
LOCAL_SHARED_LIBRARIES += $(core_shared_libraries) libssl-host libcrypto-host
LOCAL_SHARED_LIBRARIES += $(core_shared_libraries) libssl-host libcrypto-host libjavacore
LOCAL_STATIC_LIBRARIES += $(core_static_libraries)
include $(BUILD_HOST_SHARED_LIBRARY)
......
......@@ -1239,40 +1239,29 @@ public class SSLSocketTest extends TestCase {
}
public void test_SSLSocket_interrupt() throws Exception {
ServerSocket listening = new ServerSocket(0);
for (int i = 0; i < 3; i++) {
Socket underlying = new Socket(listening.getInetAddress(), listening.getLocalPort());
Socket server = listening.accept();
SSLSocketFactory sf = (SSLSocketFactory) SSLSocketFactory.getDefault();
Socket clientWrapping = sf.createSocket(underlying, null, -1, true);
switch (i) {
case 0:
test_SSLSocket_interrupt_case(underlying, underlying);
break;
case 1:
test_SSLSocket_interrupt_case(underlying, clientWrapping);
break;
case 2:
test_SSLSocket_interrupt_case(clientWrapping, underlying);
break;
case 3:
test_SSLSocket_interrupt_case(clientWrapping, clientWrapping);
break;
default:
fail();
}
server.close();
underlying.close();
test_SSLSocket_interrupt_case(true, true);
test_SSLSocket_interrupt_case(true, false);
test_SSLSocket_interrupt_case(false, true);
// Currently failing due to reader blocking closing thread http://b/10681815
if (StandardNames.IS_RI) {
test_SSLSocket_interrupt_case(false, false);
}
listening.close();
}
private void test_SSLSocket_interrupt_case(Socket toRead, final Socket toClose)
private void test_SSLSocket_interrupt_case(boolean readUnderlying, boolean closeUnderlying)
throws Exception {
ServerSocket listening = new ServerSocket(0);
Socket underlying = new Socket(listening.getInetAddress(), listening.getLocalPort());
Socket server = listening.accept();
SSLSocketFactory sf = (SSLSocketFactory) SSLSocketFactory.getDefault();
Socket clientWrapping = sf.createSocket(underlying, null, -1, true);
final Socket toRead = (readUnderlying) ? underlying : clientWrapping;
final Socket toClose = (closeUnderlying) ? underlying : clientWrapping;
ExecutorService executor = Executors.newSingleThreadExecutor();
Future<Void> future = executor.submit(new Callable<Void>() {
@Override public Void call() throws Exception {
......@@ -1283,7 +1272,7 @@ public class SSLSocketTest extends TestCase {
});
executor.shutdown();
try {
toRead.setSoTimeout(10 * 1000);
toRead.setSoTimeout(5 * 1000);
toRead.getInputStream().read();
fail();
} catch (SocketTimeoutException e) {
......@@ -1291,6 +1280,10 @@ public class SSLSocketTest extends TestCase {
} catch (SocketException expected) {
}
future.get();
server.close();
underlying.close();
listening.close();
}
/**
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment