Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8227651: Tests fail with SSLProtocolException: Input record too big #1448

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion test/jdk/ProblemList.txt
Expand Up @@ -616,7 +616,6 @@ sun/security/tools/keytool/ListKeychainStore.sh 8156889 macosx-a
sun/security/tools/jarsigner/compatibility/SignTwice.java 8217375 windows-all
sun/security/tools/jarsigner/warnings/BadKeyUsageTest.java 8026393 generic-all

javax/net/ssl/ServerName/SSLEngineExplorerMatchedSNI.java 8212096 generic-all
javax/net/ssl/DTLS/PacketLossRetransmission.java 8169086 macosx-x64
javax/net/ssl/DTLS/RespondToRetransmit.java 8169086 macosx-x64
javax/net/ssl/DTLS/CipherSuite.java 8202059 macosx-x64
Expand Down
9 changes: 5 additions & 4 deletions test/jdk/javax/net/ssl/SSLEngine/LargePacket.java
Expand Up @@ -38,6 +38,7 @@
*/

import javax.net.ssl.*;
import java.nio.ByteBuffer;
import java.nio.channels.*;
import java.net.*;

Expand Down Expand Up @@ -93,10 +94,10 @@ void doServerSide() throws Exception {
}

// handshaking
handshaking(ssle, sc, null);
ByteBuffer peerNetData = handshaking(ssle, sc, null);

// receive application data
receive(ssle, sc);
receive(ssle, sc, peerNetData);

// send out application data
deliver(ssle, sc);
Expand Down Expand Up @@ -136,13 +137,13 @@ void doClientSide() throws Exception {
}

// handshaking
handshaking(ssle, sc, null);
ByteBuffer peerNetData = handshaking(ssle, sc, null);

// send out application data
deliver(ssle, sc);

// receive application data
receive(ssle, sc);
receive(ssle, sc, peerNetData);

// close the socket channel.
sc.close();
Expand Down
42 changes: 21 additions & 21 deletions test/jdk/javax/net/ssl/SSLEngine/SSLEngineService.java
Expand Up @@ -70,7 +70,7 @@ private void init(String pathToStores) {
protected static void deliver(SSLEngine ssle, SocketChannel sc)
throws Exception {

// create buufer.
// create buffer.
int appBufferMax = ssle.getSession().getApplicationBufferSize();
int netBufferMax = ssle.getSession().getPacketBufferSize();
int length = appBufferMax * (Integer.SIZE / 8);
Expand Down Expand Up @@ -128,7 +128,7 @@ protected static void deliver(SSLEngine ssle, SocketChannel sc)
// maybe need to enlarge the local network packet buffer.
int size = ssle.getSession().getPacketBufferSize();
if (size > localNetData.capacity()) {
System.out.println("resize destination buffer upto " +
System.out.println("send: resize destination buffer upto " +
size + " bytes for BUFFER_OVERFLOW");
localNetData = enlargeBuffer(localNetData, size);
}
Expand All @@ -143,16 +143,14 @@ protected static void deliver(SSLEngine ssle, SocketChannel sc)


// receive peer application data.
protected static void receive(SSLEngine ssle, SocketChannel sc)
throws Exception {
protected static void receive(SSLEngine ssle, SocketChannel sc,
ByteBuffer peerNetData) throws Exception {

// create buufers.
// create buffer.
int appBufferMax = ssle.getSession().getApplicationBufferSize();
int netBufferMax = ssle.getSession().getPacketBufferSize();

// allocate less in order to check BUFFER_OVERFLOW/BUFFER_UNDERFLOW
// allocate less in order to check BUFFER_OVERFLOW
ByteBuffer peerAppData = ByteBuffer.allocate(appBufferMax/2);
ByteBuffer peerNetData = ByteBuffer.allocate(netBufferMax/2);
int received = -1;

boolean needToReadMore = true;
Expand Down Expand Up @@ -189,8 +187,8 @@ protected static void receive(SSLEngine ssle, SocketChannel sc)

System.out.println("received " + peerAppData.position() +
" bytes client application data");
System.out.println("\tcomsumed " + res.bytesConsumed() +
" byes network data");
System.out.println("\tconsumed " + res.bytesConsumed() +
" bytes network data");
peerAppData.clear();

received -= res.bytesProduced();
Expand All @@ -209,7 +207,7 @@ protected static void receive(SSLEngine ssle, SocketChannel sc)
// maybe need to enlarge the peer application data buffer.
int size = ssle.getSession().getApplicationBufferSize();
if (size > peerAppData.capacity()) {
System.out.println("resize destination buffer upto " +
System.out.println("recv: resize destination buffer upto " +
size + " bytes for BUFFER_OVERFLOW");
peerAppData = enlargeBuffer(peerAppData, size);
}
Expand All @@ -219,8 +217,8 @@ protected static void receive(SSLEngine ssle, SocketChannel sc)
// maybe need to enlarge the peer network packet data buffer.
size = ssle.getSession().getPacketBufferSize();
if (size > peerNetData.capacity()) {
System.out.println("resize source buffer upto " + size +
" bytes for BUFFER_UNDERFLOW");
System.out.println("recv: resize source buffer upto " +
size + " bytes for BUFFER_UNDERFLOW");
peerNetData = enlargeBuffer(peerNetData, size);
}

Expand All @@ -234,15 +232,16 @@ protected static void receive(SSLEngine ssle, SocketChannel sc)
}
}

protected static void handshaking(SSLEngine ssle, SocketChannel sc,
protected static ByteBuffer handshaking(SSLEngine ssle, SocketChannel sc,
ByteBuffer additional) throws Exception {

int appBufferMax = ssle.getSession().getApplicationBufferSize();
int netBufferMax = ssle.getSession().getPacketBufferSize();

// zero-byte app buffers - we do not want to exchange app data here
ByteBuffer localAppData = ByteBuffer.allocate(0);
ByteBuffer peerAppData = ByteBuffer.allocate(0);
// allocate less in order to check BUFFER_OVERFLOW/BUFFER_UNDERFLOW
ByteBuffer localAppData = ByteBuffer.allocate(appBufferMax/10);
ByteBuffer peerAppData = ByteBuffer.allocate(appBufferMax/10);
ByteBuffer localNetData = ByteBuffer.allocate(netBufferMax/10);
ByteBuffer peerNetData = ByteBuffer.allocate(netBufferMax/10);

Expand Down Expand Up @@ -272,15 +271,15 @@ protected static void handshaking(SSLEngine ssle, SocketChannel sc,
} else {
if (sc.read(peerNetData) < 0) {
ssle.closeInbound();
return;
throw new EOFException();
}
}
}

if (underflow) {
if (sc.read(peerNetData) < 0) {
ssle.closeInbound();
return;
throw new EOFException();
}

underflow = false;
Expand All @@ -298,7 +297,7 @@ protected static void handshaking(SSLEngine ssle, SocketChannel sc,
// maybe need to enlarge the peer network packet buffer.
int size = ssle.getSession().getPacketBufferSize();
if (size > peerNetData.capacity()) {
System.out.println("resize source buffer upto " +
System.out.println("hs recv: resize source buffer upto " +
size + " bytes for BUFFER_UNDERFLOW");
peerNetData = enlargeBuffer(peerNetData, size);
}
Expand All @@ -309,7 +308,7 @@ protected static void handshaking(SSLEngine ssle, SocketChannel sc,
// maybe need to enlarge the peer application data buffer.
size = ssle.getSession().getApplicationBufferSize();
if (size > peerAppData.capacity()) {
System.out.println("resize destination buffer upto " +
System.out.println("hs recv: resize destination buffer upto " +
size + " bytes for BUFFER_OVERFLOW");
peerAppData = enlargeBuffer(peerAppData, size);
}
Expand Down Expand Up @@ -346,7 +345,7 @@ protected static void handshaking(SSLEngine ssle, SocketChannel sc,
// maybe need to enlarge the local network packet buffer.
int size = ssle.getSession().getPacketBufferSize();
if (size > localNetData.capacity()) {
System.out.println("resize destination buffer upto " +
System.out.println("hs send: resize destination buffer upto " +
size + " bytes for BUFFER_OVERFLOW");
localNetData = enlargeBuffer(localNetData, size);
}
Expand All @@ -371,6 +370,7 @@ protected static void handshaking(SSLEngine ssle, SocketChannel sc,
}
} while (hs != SSLEngineResult.HandshakeStatus.FINISHED &&
hs != SSLEngineResult.HandshakeStatus.NOT_HANDSHAKING);
return peerNetData;
}

private static ByteBuffer enlargeBuffer(ByteBuffer buffer, int size) {
Expand Down
8 changes: 4 additions & 4 deletions test/jdk/javax/net/ssl/ServerName/SSLEngineExplorer.java
Expand Up @@ -142,10 +142,10 @@ void doServerSide() throws Exception {
}

// handshaking
handshaking(ssle, sc, buffer);
ByteBuffer peerNetData = handshaking(ssle, sc, buffer);

// receive application data
receive(ssle, sc);
receive(ssle, sc, peerNetData);

// send out application data
deliver(ssle, sc);
Expand Down Expand Up @@ -192,13 +192,13 @@ void doClientSide() throws Exception {
ssle.setEnabledProtocols(supportedProtocols);

// handshaking
handshaking(ssle, sc, null);
ByteBuffer peerNetData = handshaking(ssle, sc, null);

// send out application data
deliver(ssle, sc);

// receive application data
receive(ssle, sc);
receive(ssle, sc, peerNetData);

// close the socket channel.
sc.close();
Expand Down
Expand Up @@ -154,10 +154,10 @@ void doServerSide() throws Exception {
ssle.setSSLParameters(params);

// handshaking
handshaking(ssle, sc, buffer);
ByteBuffer peerNetData = handshaking(ssle, sc, buffer);

// receive application data
receive(ssle, sc);
receive(ssle, sc, peerNetData);

// send out application data
deliver(ssle, sc);
Expand Down Expand Up @@ -209,13 +209,13 @@ void doClientSide() throws Exception {
ssle.setSSLParameters(params);

// handshaking
handshaking(ssle, sc, null);
ByteBuffer peerNetData = handshaking(ssle, sc, null);

// send out application data
deliver(ssle, sc);

// receive application data
receive(ssle, sc);
receive(ssle, sc, peerNetData);

// check server name indication
ExtendedSSLSession session = (ExtendedSSLSession)ssle.getSession();
Expand Down
Expand Up @@ -148,10 +148,10 @@ void doServerSide() throws Exception {

try {
// handshaking
handshaking(ssle, sc, buffer);
ByteBuffer peerNetData = handshaking(ssle, sc, buffer);

// receive application data
receive(ssle, sc);
receive(ssle, sc, peerNetData);

// send out application data
deliver(ssle, sc);
Expand Down Expand Up @@ -213,13 +213,13 @@ void doClientSide() throws Exception {

try {
// handshaking
handshaking(ssle, sc, null);
ByteBuffer peerNetData = handshaking(ssle, sc, null);

// send out application data
deliver(ssle, sc);

// receive application data
receive(ssle, sc);
receive(ssle, sc, peerNetData);

// check server name indication
ExtendedSSLSession session = (ExtendedSSLSession)ssle.getSession();
Expand Down
Expand Up @@ -136,10 +136,10 @@ void doServerSide() throws Exception {
}

// handshaking
handshaking(ssle, sc, buffer);
ByteBuffer peerNetData = handshaking(ssle, sc, buffer);

// receive application data
receive(ssle, sc);
receive(ssle, sc, peerNetData);

// send out application data
deliver(ssle, sc);
Expand Down Expand Up @@ -190,13 +190,13 @@ void doClientSide() throws Exception {
ssle.setSSLParameters(params);

// handshaking
handshaking(ssle, sc, null);
ByteBuffer peerNetData = handshaking(ssle, sc, null);

// send out application data
deliver(ssle, sc);

// receive application data
receive(ssle, sc);
receive(ssle, sc, peerNetData);

// check server name indication
ExtendedSSLSession session = (ExtendedSSLSession)ssle.getSession();
Expand Down
Expand Up @@ -145,10 +145,10 @@ void doServerSide() throws Exception {
ssle.setSSLParameters(params);

// handshaking
handshaking(ssle, sc, buffer);
ByteBuffer peerNetData = handshaking(ssle, sc, buffer);

// receive application data
receive(ssle, sc);
receive(ssle, sc, peerNetData);

// send out application data
deliver(ssle, sc);
Expand Down Expand Up @@ -193,13 +193,13 @@ void doClientSide() throws Exception {
}

// handshaking
handshaking(ssle, sc, null);
ByteBuffer peerNetData = handshaking(ssle, sc, null);

// send out application data
deliver(ssle, sc);

// receive application data
receive(ssle, sc);
receive(ssle, sc, peerNetData);

// check server name indication
ExtendedSSLSession session = (ExtendedSSLSession)ssle.getSession();
Expand Down