Skip to content

Commit cfa80b6

Browse files
authored
bpontarelli/tls fixes (#17)
Fixing TLS issues with a rewrite of the SSLEngine code. This now breaks apart handshaking and body processing into separate steps and using different buffers for consistency and clarity. This still doesn't handle mid-stream cipher renegotiations, but it works for most request/response transactions that are not large.
1 parent a8fb48b commit cfa80b6

File tree

12 files changed

+571
-267
lines changed

12 files changed

+571
-267
lines changed

build.savant

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,9 @@ release = loadPlugin(id: "org.savantbuild.plugin:release-git:2.0.0-RC.6")
6262
pom = loadPlugin(id: "org.savantbuild.plugin:pom:2.0.0-RC.6")
6363

6464
java.settings.javaVersion = "17"
65-
java
66-
.settings
67-
.compilerArguments = "--add-exports java.base/sun.security.x509=ALL-UNNAMED --add-exports java.base/sun.security.util=ALL-UNNAMED -XDignore.symbol.file"
65+
java.settings.compilerArguments = "--add-exports java.base/sun.security.x509=ALL-UNNAMED --add-exports java.base/sun.security.util=ALL-UNNAMED -XDignore.symbol.file"
6866
javaTestNG.settings.javaVersion = "17"
69-
javaTestNG
70-
.settings.jvmArguments = "--add-exports java.base/sun.security.x509=ALL-UNNAMED --add-exports java.base/sun.security.util=ALL-UNNAMED"
67+
javaTestNG.settings.jvmArguments = "--add-exports java.base/sun.security.x509=ALL-UNNAMED --add-exports java.base/sun.security.util=ALL-UNNAMED"
7168
javaTestNG.settings.testngArguments = "-listener io.fusionauth.http.BaseTest\$TestListener"
7269

7370
target(name: "clean", description: "Cleans the build directory") {

java-http.ipr

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1385,6 +1385,31 @@
13851385
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="Java 17" project-jdk-type="JavaSDK">
13861386
<output url="file://$PROJECT_DIR$/out" />
13871387
</component>
1388+
<component name="ProjectRunConfigurationManager">
1389+
<configuration default="true" type="TestNG">
1390+
<shortenClasspath name="NONE" />
1391+
<useClassPathOnly />
1392+
<option name="SUITE_NAME" value="" />
1393+
<option name="PACKAGE_NAME" value="" />
1394+
<option name="MAIN_CLASS_NAME" value="" />
1395+
<option name="GROUP_NAME" value="" />
1396+
<option name="TEST_OBJECT" value="CLASS" />
1397+
<option name="VM_PARAMETERS" value="-ea --add-exports java.base/sun.security.x509=ALL-UNNAMED --add-exports java.base/sun.security.util=ALL-UNNAMED" />
1398+
<option name="PARAMETERS" value="" />
1399+
<option name="OUTPUT_DIRECTORY" value="" />
1400+
<option name="TEST_SEARCH_SCOPE">
1401+
<value defaultName="moduleWithDependencies" />
1402+
</option>
1403+
<option name="PROPERTIES_FILE" value="" />
1404+
<properties />
1405+
<listeners>
1406+
<listener class="io.fusionauth.http.BaseTest$TestListener" />
1407+
</listeners>
1408+
<method v="2">
1409+
<option name="Make" enabled="true" />
1410+
</method>
1411+
</configuration>
1412+
</component>
13881413
<component name="VcsDirectoryMappings">
13891414
<mapping directory="$PROJECT_DIR$" vcs="Git" />
13901415
</component>

src/main/java/io/fusionauth/http/log/AccumulatingLogger.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
public class AccumulatingLogger extends BaseLogger {
2828
private final List<String> messages = new ArrayList<>();
2929

30-
public void reset() {
30+
public synchronized void reset() {
3131
messages.clear();
3232
}
3333

@@ -37,7 +37,7 @@ public String toString() {
3737
}
3838

3939
@Override
40-
protected void handleMessage(String message) {
40+
protected synchronized void handleMessage(String message) {
4141
messages.add(message);
4242
}
4343
}

src/main/java/io/fusionauth/http/server/HTTP11Processor.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ public ProcessorState read(ByteBuffer buffer) throws IOException {
181181
state = ProcessorState.Write;
182182
}
183183

184+
logger.trace("(RR)");
184185
return state;
185186
}
186187

src/main/java/io/fusionauth/http/server/HTTPRequestProcessor.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ public ByteBuffer bodyBuffer() {
6666

6767
public RequestState processBodyBytes() {
6868
bodyProcessor.processBuffer(inputStream);
69+
logger.trace("(BODY) {} {}", bodyProcessor.currentBuffer(), bodyProcessor.totalBytesProcessed());
6970

7071
if (bodyProcessor.isComplete()) {
7172
inputStream.signalDone();
@@ -115,7 +116,7 @@ public RequestState processPreambleBytes(ByteBuffer buffer) {
115116

116117
int size = Math.max(buffer.remaining(), bufferSize);
117118
if (contentLength != null) {
118-
logger.debug("Handling body using Content-Length header");
119+
logger.debug("Handling body using Content-Length header {}", contentLength);
119120
bodyProcessor = new ContentLengthBodyProcessor(size, contentLength);
120121
} else {
121122
logger.debug("Handling body using Chunked data");

src/main/java/io/fusionauth/http/server/HTTPResponseProcessor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public synchronized ByteBuffer[] currentBuffer() {
7070

7171
// Construct the preamble if needed and return it if there is any bytes left
7272
if (preambleBuffers == null) {
73-
logger.debug("The worker thread has bytes to write or has closed the stream, but the preamble hasn't been sent yet. Generating preamble");
73+
logger.debug("The server (via a worker thread or the server due to an Expect request) has bytes to write or has closed the stream, but the preamble hasn't been sent yet. Generating preamble");
7474
int maxHeadLength = configuration.getMaxHeadLength();
7575
if (state == ResponseState.Preamble) {
7676
fillInHeaders();

0 commit comments

Comments
 (0)