-
Notifications
You must be signed in to change notification settings - Fork 900
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Propagate TLS handshake exception in
SslCompletionEvent
(#4950)
Motivation: - `SslCompletionEvent` can have a cause if a TLS handshake is completed exceptionally. As the cause isn't taken into account, users could see the root cause of the failure. - A legacy HTTPS server such as Microsoft-IIS/8.5 resets the connection if no cipher suites in common without respecting the handshake process. No hint is given to the handshake failure, users don't know why Armeria can't communicate with the server. Modifications: - If `SslCompletionEvent` is not successful, propagate the cause to the session promise. - If an exception is raised during a handshake, create `IllegalStateException` with a hint and add it as a suppressed exception. Result: Exceptions that occurred during a TLS handshake are properly propagated to users.
- Loading branch information
Showing
3 changed files
with
121 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
core/src/test/java/com/linecorp/armeria/client/IisServerCompatibilityTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* | ||
* Copyright 2023 LINE Corporation | ||
* | ||
* LINE Corporation licenses this file to you under the Apache License, | ||
* version 2.0 (the "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at: | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package com.linecorp.armeria.client; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.assertj.core.api.AssertionsForClassTypes.catchThrowable; | ||
|
||
import java.nio.channels.ClosedChannelException; | ||
|
||
import javax.net.ssl.SSLHandshakeException; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.condition.DisabledOnOs; | ||
import org.junit.jupiter.api.condition.OS; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import com.linecorp.armeria.common.HttpResponse; | ||
import com.linecorp.armeria.server.ServerBuilder; | ||
import com.linecorp.armeria.testing.junit5.server.ServerExtension; | ||
|
||
@DisabledOnOs(value = OS.WINDOWS, disabledReason = "Windows may be a different order of closing events.") | ||
class IisServerCompatibilityTest { | ||
|
||
@RegisterExtension | ||
static ServerExtension server = new ServerExtension() { | ||
@Override | ||
protected void configure(ServerBuilder sb) { | ||
sb.https(0); | ||
sb.tlsSelfSigned(); | ||
sb.childChannelPipelineCustomizer(pipeline -> { | ||
// Simulate the behavior of IIS. | ||
pipeline.channel().close(); | ||
}); | ||
sb.service("/", (ctx, req) -> HttpResponse.of("OK")); | ||
} | ||
}; | ||
|
||
@Test | ||
void shouldRaiseSslHandleShakeExceptionWhenConnectionIsResetDuringTlsHandshake() { | ||
final BlockingWebClient client = WebClient.builder(server.httpsUri()) | ||
.factory(ClientFactory.insecure()) | ||
.build() | ||
.blocking(); | ||
final Throwable cause = catchThrowable(() -> client.get("/")); | ||
assertThat(cause).isInstanceOf(UnprocessedRequestException.class) | ||
.getCause().isInstanceOf(IllegalStateException.class) | ||
.hasMessageFindingMatch( | ||
"An unexpected exception during TLS handshake. " + | ||
"Possible reasons: no cipher suites in common, unsupported TLS version," + | ||
" etc. \\(TLS version: .*, cipher suites: .*\\)"); | ||
final Throwable suppressed0 = cause.getCause().getSuppressed()[0]; | ||
assertThat(suppressed0) | ||
.isInstanceOf(ClosedChannelException.class); | ||
assertThat(suppressed0.getSuppressed()[0]) | ||
.isInstanceOf(SSLHandshakeException.class) | ||
.hasMessageContaining("Connection closed while SSL/TLS handshake was in progress"); | ||
} | ||
} |