Example usage for javax.net.ssl SSLException getMessage

List of usage examples for javax.net.ssl SSLException getMessage

Introduction

In this page you can find the example usage for javax.net.ssl SSLException getMessage.

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:org.apache.camel.component.file.remote.FtpsOperations.java

@Override
public boolean connect(RemoteFileConfiguration configuration) throws GenericFileOperationFailedException {
    boolean answer = super.connect(configuration);

    FtpsConfiguration config = (FtpsConfiguration) configuration;
    if (answer) {
        try {/*from  ww w .  java2s . c o  m*/
            String execProt = config.getExecProt();
            Long execPbsz = config.getExecPbsz();
            // use default values for prop and pbsz, unless told to not do so
            if (!config.isDisableSecureDataChannelDefaults()) {
                if (ObjectHelper.isEmpty(execProt)) {
                    execProt = "P";
                }
                if (ObjectHelper.isEmpty(execPbsz)) {
                    execPbsz = 0L;
                }
            }

            if (execPbsz != null) {
                log.debug("FTPClient initializing with execPbsz={}", execPbsz);
                getFtpClient().execPBSZ(execPbsz);
            }
            if (execProt != null) {
                log.debug("FTPClient initializing with execProt={}", execProt);
                getFtpClient().execPROT(execProt);
            }
        } catch (SSLException e) {
            throw new GenericFileOperationFailedException(client.getReplyCode(), client.getReplyString(),
                    e.getMessage(), e);
        } catch (IOException e) {
            throw new GenericFileOperationFailedException(client.getReplyCode(), client.getReplyString(),
                    e.getMessage(), e);
        }
    }

    return answer;
}

From source file:com.newrelic.agent.deps.org.apache.http.conn.ssl.DefaultHostnameVerifier.java

@Override
public final boolean verify(final String host, final SSLSession session) {
    try {/*from w ww .  j a  v  a  2 s.c  o m*/
        final Certificate[] certs = session.getPeerCertificates();
        final X509Certificate x509 = (X509Certificate) certs[0];
        verify(host, x509);
        return true;
    } catch (final SSLException ex) {
        if (log.isDebugEnabled()) {
            log.debug(ex.getMessage(), ex);
        }
        return false;
    }
}

From source file:net.lightbody.bmp.proxy.jetty.http.JsseListener.java

/**
 * @param p_serverSocket/*from   ww w  .  jav a2s . c  o  m*/
 * @return
 * @exception IOException
 */
protected Socket accept(ServerSocket p_serverSocket) throws IOException {
    try {
        SSLSocket s = (SSLSocket) p_serverSocket.accept();
        if (getMaxIdleTimeMs() > 0)
            s.setSoTimeout(getMaxIdleTimeMs());
        s.startHandshake(); // block until SSL handshaking is done
        return s;
    } catch (SSLException e) {
        log.warn(LogSupport.EXCEPTION, e);
        throw new IOException(e.getMessage());
    }
}

From source file:org.apache.http.HC4.conn.ssl.DefaultHostnameVerifier.java

@Override
public final boolean verify(final String host, final SSLSession session) {
    try {//from   ww  w. j av a 2s  .c om
        final Certificate[] certs = session.getPeerCertificates();
        final X509Certificate x509 = (X509Certificate) certs[0];
        return verify(host, x509);
    } catch (final SSLException ex) {
        if (log.isDebugEnabled()) {
            log.debug(ex.getMessage(), ex);
        }
        return false;
    }
}

From source file:client.ui.Container.java

private JSONObject getCert(SocketFactory factory, URL url) {
    JSONObject json = new JSONObject();
    json.put("host", url.getHost());
    json.put("port", url.getPort());

    try {//from  w  w  w.j  a va  2  s .  c o m
        log("Get Certs: " + url.getHost() + ":" + url.getPort());

        SSLSocket socket = (SSLSocket) factory.createSocket(url.getHost(), url.getPort());
        socket.startHandshake();

        Certificate[] certs = socket.getSession().getPeerCertificates();
        String result = "";

        for (Certificate cert : certs) {

            if (cert instanceof X509Certificate) {
                try {
                    ((X509Certificate) cert).checkValidity();
                    result += "OK ";

                } catch (CertificateExpiredException cee) {
                    result += "Expired ";
                } catch (CertificateNotYetValidException ex) {
                    result += "NotYetValid ";
                }
            }
        }

        log("Result: " + result.trim());
        json.put("result", result.trim());

    } catch (SSLException se) {
        log("Error: SSLException (" + se.getMessage() + ")");
        json.put("result", "SSLException: " + se.getMessage());
    } catch (ConnectException ce) {
        log("Error: ConnectException (" + ce.getMessage() + ")");
        json.put("result", "ConnectException: " + ce.getMessage());
    } catch (IOException ioe) {
        log("Error: IOException (" + ioe.getMessage() + ")");
        json.put("result", "IOException: " + ioe.getMessage());
    }

    return json;
}

From source file:org.parosproxy.paros.network.SSLConnector.java

/**
 * @see SecureProtocolSocketFactory#createSocket(java.net.Socket,java.lang.String,int,boolean)
 *//*w w  w .  ja va  2 s.c  om*/
@Override
public Socket createSocket(Socket socket, String host, int port, boolean autoClose)
        throws IOException, UnknownHostException {
    InetAddress inetAddress = getCachedMisconfiguredHost(host, port);
    if (inetAddress != null) {
        return clientSSLSockFactory.createSocket(socket, inetAddress.getHostAddress(), port, autoClose);
    }

    try {
        SSLSocket socketSSL = (SSLSocket) clientSSLSockFactory.createSocket(socket, host, port, autoClose);
        socketSSL.startHandshake();

        return socketSSL;
    } catch (SSLException e) {
        if (e.getMessage().contains(CONTENTS_UNRECOGNIZED_NAME_EXCEPTION)) {
            cacheMisconfiguredHost(host, port, InetAddress.getByName(host));
        }
        // Throw the exception anyway because the socket might no longer be usable (e.g. closed). The connection will be 
        // retried (see HttpMethodDirector#executeWithRetry(HttpMethod) for more information on the retry policy).
        throw e;
    }
}

From source file:org.zaproxy.zap.extension.websocket.client.ServerConnectionEstablisher.java

/**
 * Build a descriptive exception message about SSLException
 *
 * @param sslEx the ssl exception//from  w  w  w. ja  v a 2s.co  m
 * @param httpMessage message cause the exception
 * @return descriptive message
 */
private String sslExceptionBuilder(SSLException sslEx, HttpMessage httpMessage) {
    StringBuilder strBuilder = new StringBuilder();
    strBuilder.append(Constant.messages.getString("network.ssl.error.connect"));
    strBuilder.append(httpMessage.getRequestHeader().getURI().toString()).append('\n');
    strBuilder.append(Constant.messages.getString("network.ssl.error.exception")).append(sslEx.getMessage())
            .append('\n');
    strBuilder.append(Constant.messages.getString("network.ssl.error.exception.rootcause"))
            .append(ExceptionUtils.getRootCauseMessage(sslEx)).append('\n');
    strBuilder.append(Constant.messages.getString("network.ssl.error.help",
            Constant.messages.getString("network.ssl.error.help.url")));
    return strBuilder.toString();
}

From source file:ch.cyberduck.core.ssl.SSLExceptionMappingService.java

/**
 * close_notify(0),/*from   ww  w  .j  a v a 2  s.c  o  m*/
 * 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) {
            // Map 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.contains(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);
        }
        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);
}

From source file:org.parosproxy.paros.extension.manualrequest.ManualRequestEditorDialog.java

protected void send(final Message aMessage) {
    final Thread t = new Thread(new Runnable() {
        @Override/*from   w  w w  .j a va2  s.  c  o  m*/
        public void run() {
            try {
                getMessageSender().handleSendMessage(aMessage);
                postSend();
            } catch (SSLException sslEx) {
                StringBuilder strBuilder = new StringBuilder();

                strBuilder.append(Constant.messages.getString("network.ssl.error.connect"));
                strBuilder.append(((HttpMessage) aMessage).getRequestHeader().getURI().toString()).append('\n');
                strBuilder.append(Constant.messages.getString("network.ssl.error.exception"))
                        .append(sslEx.getMessage()).append('\n');
                strBuilder.append(Constant.messages.getString("network.ssl.error.exception.rootcause"))
                        .append(ExceptionUtils.getRootCauseMessage(sslEx)).append('\n');
                strBuilder.append(Constant.messages.getString("network.ssl.error.help",
                        Constant.messages.getString("network.ssl.error.help.url")));
                logger.warn(strBuilder.toString());
                if (logger.isDebugEnabled()) {
                    logger.debug(sslEx, sslEx);
                }
                View.getSingleton().showWarningDialog(strBuilder.toString());
            } catch (Exception e) {
                logger.warn(e.getMessage(), e);
                View.getSingleton().showWarningDialog(e.getMessage());
            } finally {
                btnSend.setEnabled(true);
            }
        }
    });
    t.setPriority(Thread.NORM_PRIORITY);
    t.start();
}

From source file:com.archivas.clienttools.arcutils.utils.net.GetCertsX509TrustManager.java

public String testHostname(String hostname, SSLCertChain certChain) {
    String result = null;/*  w  w w  .j  a  v  a  2  s. c o  m*/
    String testingCN = null;
    try {
        List<X509Certificate> certList = certChain.getCertificateList();
        String[] cnList = new String[certList.size()];
        Iterator<X509Certificate> i = certList.iterator();

        for (int count = 0; i.hasNext(); ++count) {
            String dn = ((X509Certificate) i.next()).getSubjectDN().getName();
            int cnIndex = dn.indexOf("CN=") + 3;
            if (cnIndex < 0) {
                LOG.log(Level.FINE, "Hostname not found in certificate " + dn);
                continue;
            }
            int cnEndIndex = dn.indexOf(',', cnIndex);
            String cn = (cnEndIndex < 0 ? dn.substring(cnIndex + 3) : dn.substring(cnIndex + 3, cnEndIndex));

            // Also remove the *.
            if (cn.startsWith("*.")) {
                cn = cn.substring(2);
            }

            cnList[count] = cn;

            // I think it is unlikely there are ever multiple certs coming in here.
            testingCN = cn;
        }
        BrowserCompatHostnameVerifier verifier = new BrowserCompatHostnameVerifier();
        verifier.verify(hostname, cnList, null);
    } catch (SSLException e) {
        if (testingCN != null) {
            result = "Host name " + hostname + " is not equal to the certificate issuer's \nhost name "
                    + testingCN;
        }
        LOG.log(Level.FINE, e.getMessage(), e);
    }
    return result;
}