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

8266881: Enable debug log for SSLEngineExplorerMatchedSNI.java #567

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions jdk/test/javax/net/ssl/SSLEngine/LargePacket.java
Original file line number Diff line number Diff line change
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 jdk/test/javax/net/ssl/SSLEngine/SSLEngineService.java
Original file line number Diff line number Diff line change
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 jdk/test/javax/net/ssl/ServerName/SSLEngineExplorer.java
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -71,7 +71,7 @@ public class SSLEngineExplorerMatchedSNI extends SSLEngineService {
/*
* Turn on SSL debugging?
*/
static boolean debug = false;
static boolean debug = true;

/*
* Define the server side of the test.
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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