From 2e47cbcfd5aad2a525af42cbc93a919b96e2c62a Mon Sep 17 00:00:00 2001 From: Narayan Kamath Date: Tue, 2 Dec 2014 18:58:22 +0000 Subject: Add tests for issue 18554122. We assert that UNDERFLOW is returned on empty inputs both during and after a handshake. bug: 18554122 (cherry picked from commit 03365a863c7316325ff12bf88aa19dc33e34f19f) Change-Id: I41d7fbdbd0363aea84904b14a1e99116cebff0f5 --- .../java/libcore/javax/net/ssl/SSLEngineTest.java | 26 ++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'luni') diff --git a/luni/src/test/java/libcore/javax/net/ssl/SSLEngineTest.java b/luni/src/test/java/libcore/javax/net/ssl/SSLEngineTest.java index 5239977..fd24944 100644 --- a/luni/src/test/java/libcore/javax/net/ssl/SSLEngineTest.java +++ b/luni/src/test/java/libcore/javax/net/ssl/SSLEngineTest.java @@ -86,6 +86,32 @@ public class SSLEngineTest extends TestCase { test_SSLEngine_getSupportedCipherSuites_connect(testKeyStore, false); test_SSLEngine_getSupportedCipherSuites_connect(testKeyStore, true); } + + // http://b/18554122 + public void test_SSLEngine_underflowsOnEmptyBuffersDuringHandshake() throws Exception { + final SSLEngine sslEngine = SSLContext.getDefault().createSSLEngine(); + sslEngine.setUseClientMode(false); + ByteBuffer input = ByteBuffer.allocate(1024); + input.flip(); + ByteBuffer output = ByteBuffer.allocate(1024); + sslEngine.beginHandshake(); + assertEquals(SSLEngineResult.HandshakeStatus.NEED_UNWRAP, sslEngine.getHandshakeStatus()); + SSLEngineResult result = sslEngine.unwrap(input, output); + assertEquals(SSLEngineResult.Status.BUFFER_UNDERFLOW, result.getStatus()); + assertEquals(SSLEngineResult.HandshakeStatus.NEED_UNWRAP, result.getHandshakeStatus()); + } + + // http://b/18554122 + public void test_SSLEngine_underflowsOnEmptyBuffersAfterHandshake() throws Exception { + // Note that create performs the handshake. + final TestSSLEnginePair engines = TestSSLEnginePair.create(null /* hooks */); + ByteBuffer input = ByteBuffer.allocate(1024); + input.flip(); + ByteBuffer output = ByteBuffer.allocate(1024); + assertEquals(SSLEngineResult.Status.BUFFER_UNDERFLOW, + engines.client.unwrap(input, output).getStatus()); + } + private void test_SSLEngine_getSupportedCipherSuites_connect(TestKeyStore testKeyStore, boolean secureRenegotiation) throws Exception { -- cgit v1.1