| | |
| | | * The connected socket. |
| | | * @param soTimeout |
| | | * The socket timeout option to use for the protocol session. |
| | | * @return The new protocol session. |
| | | * @return The new protocol session, or {@code null} if TLS negotiation raised an {@link SSLException}. |
| | | * @throws ConfigException |
| | | * If the protocol session could not be established due to a |
| | | * configuration problem. |
| | |
| | | public Session createServerSession(final Socket socket, |
| | | final int soTimeout) throws ConfigException, IOException |
| | | { |
| | | try |
| | | { |
| | | return createServerSessionOrThrow(socket, soTimeout); |
| | | } |
| | | catch (SSLException e) |
| | | { |
| | | // The TLS failure was logged before the socket was closed. |
| | | return null; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * Creates a server session and propagates TLS failures to the caller. |
| | | * |
| | | * @param socket the connected socket |
| | | * @param soTimeout the socket read timeout in milliseconds |
| | | * @return the new protocol session |
| | | * @throws ConfigException if the session configuration is invalid |
| | | * @throws IOException if the session cannot be established, including an {@link SSLException} from TLS negotiation |
| | | */ |
| | | public Session createServerSessionOrThrow(final Socket socket, final int soTimeout) throws ConfigException, IOException |
| | | { |
| | | boolean hasCompleted = false; |
| | | SSLSocket secureSocket = null; |
| | | |
| | |
| | | |
| | | // Force TLS negotiation now. |
| | | secureSocket.startHandshake(); |
| | | final Session session = new Session(socket, secureSocket); |
| | | hasCompleted = true; |
| | | return new Session(socket, secureSocket); |
| | | return session; |
| | | } |
| | | catch (final SSLException e) |
| | | { |
| | |
| | | // also how a certificate misconfiguration shows up, so warn the |
| | | // administrator instead of failing silently. |
| | | logHandshakeFailure(socket, e); |
| | | return null; |
| | | throw e; |
| | | } |
| | | finally |
| | | { |