Skip to content

Commit

Permalink
Introduce PreTlsHandshakeException to indicate the exception raised b…
Browse files Browse the repository at this point in the history
…efore TLS handshake starts (line#5344)

Motivation:
Got a report from @mauhiz that the current exception that is raised before TLS handshake starts, is not sufficiently clear and can cause confusion.

Modifications:
- Change the exception type from `IllegalStateException` to `PreTlsHandshakeException`.
- Refine the exception message to be more explicit.

Result:
- `PreTlsHandshakeException` is now used when an exception is raised before a TLS handshake starts.
  • Loading branch information
minwoox authored Jan 22, 2024
1 parent 3963f2a commit d2edfb0
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -295,12 +295,13 @@ public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws E
// A legacy HTTPS server such as Microsoft-IIS/8.5 may reset the connection
// if no cipher suites in common.
final String tlsVersion = sslHandler.engine().getSession().getProtocol();
final IllegalStateException maybeHandshakeException = new IllegalStateException(
"An unexpected exception during TLS handshake. " +
"Possible reasons: no cipher suites in common, unsupported TLS version, etc. " +
final PreTlsHandshakeException preTlsHandshakeException = new PreTlsHandshakeException(
"An unexpected exception before a TLS handshake starts. The possible reason could" +
" be one of: [connection forcefully closed by peer, unsupported TLS version, " +
"no cipher suites in common, etc.] " +
"(TLS version: " + tlsVersion + ", cipher suites: " + sslCtx.cipherSuites() + ')',
cause);
setPendingException(ctx, maybeHandshakeException);
setPendingException(ctx, preTlsHandshakeException);
return;
}
if (handshakeFailed &&
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* 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 javax.net.ssl.SSLException;

import com.linecorp.armeria.common.Flags;

/**
* An {@link SSLException} raised before starting a TLS handshake.
*/
public final class PreTlsHandshakeException extends SSLException {

private static final long serialVersionUID = -4425286273254997423L;

/**
* Creates a new instance.
*/
public PreTlsHandshakeException(String message, Throwable cause) {
super(message, cause);
}

@Override
public Throwable fillInStackTrace() {
if (Flags.verboseExceptionSampler().isSampled(getClass())) {
super.fillInStackTrace();
}
return this;
}
}

0 comments on commit d2edfb0

Please sign in to comment.