Search in sources :

Example 1 with SSLNegotiateException

use of ch.cyberduck.core.exception.SSLNegotiateException in project cyberduck by iterate-ch.

the class SSLExceptionMappingService method map.

/**
 * close_notify(0),
 * unexpected_message(10),
 * bad_record_mac(20),
 * decryption_failed_RESERVED(21),
 * record_overflow(22),
 * decompression_failure(30),
 * handshake_failure(40),
 * no_certificate_RESERVED(41),
 * bad_certificate(42),
 * unsupported_certificate(43),
 * certificate_revoked(44),
 * certificate_expired(45),
 * certificate_unknown(46),
 * illegal_parameter(47),
 * unknown_ca(48),
 * access_denied(49),
 * decode_error(50),
 * decrypt_error(51),
 * export_restriction_RESERVED(60),
 * protocol_version(70),
 * insufficient_security(71),
 * internal_error(80),
 * user_canceled(90),
 * no_renegotiation(100),
 * unsupported_extension(110),
 */
@Override
public BackgroundException map(final SSLException failure) {
    final StringBuilder buffer = new StringBuilder();
    for (Throwable cause : ExceptionUtils.getThrowableList(failure)) {
        if (cause instanceof SocketException) {
            // Connection has been shutdown: javax.net.ssl.SSLException: java.net.SocketException: Broken pipe
            return new DefaultSocketExceptionMappingService().map((SocketException) cause);
        }
    }
    final String message = failure.getMessage();
    for (Alert alert : Alert.values()) {
        if (StringUtils.containsIgnoreCase(message, alert.name())) {
            this.append(buffer, alert.getDescription());
            break;
        }
    }
    if (failure instanceof SSLHandshakeException) {
        if (ExceptionUtils.getRootCause(failure) instanceof CertificateException) {
            log.warn(String.format("Ignore certificate failure %s and drop connection", failure.getMessage()));
            // Server certificate not accepted
            return new ConnectionCanceledException(failure);
        }
        if (ExceptionUtils.getRootCause(failure) instanceof EOFException) {
            // SSL peer shut down incorrectly
            return this.wrap(failure, buffer);
        }
        return new SSLNegotiateException(buffer.toString(), failure);
    }
    if (ExceptionUtils.getRootCause(failure) instanceof GeneralSecurityException) {
        this.append(buffer, ExceptionUtils.getRootCause(failure).getMessage());
        return new InteroperabilityException(buffer.toString(), failure);
    }
    this.append(buffer, message);
    return new InteroperabilityException(buffer.toString(), failure);
}
Also used : SocketException(java.net.SocketException) InteroperabilityException(ch.cyberduck.core.exception.InteroperabilityException) SSLNegotiateException(ch.cyberduck.core.exception.SSLNegotiateException) ConnectionCanceledException(ch.cyberduck.core.exception.ConnectionCanceledException) GeneralSecurityException(java.security.GeneralSecurityException) CertificateException(java.security.cert.CertificateException) SSLHandshakeException(javax.net.ssl.SSLHandshakeException) DefaultSocketExceptionMappingService(ch.cyberduck.core.DefaultSocketExceptionMappingService) EOFException(java.io.EOFException)

Aggregations

DefaultSocketExceptionMappingService (ch.cyberduck.core.DefaultSocketExceptionMappingService)1 ConnectionCanceledException (ch.cyberduck.core.exception.ConnectionCanceledException)1 InteroperabilityException (ch.cyberduck.core.exception.InteroperabilityException)1 SSLNegotiateException (ch.cyberduck.core.exception.SSLNegotiateException)1 EOFException (java.io.EOFException)1 SocketException (java.net.SocketException)1 GeneralSecurityException (java.security.GeneralSecurityException)1 CertificateException (java.security.cert.CertificateException)1 SSLHandshakeException (javax.net.ssl.SSLHandshakeException)1