Search in sources :

Example 31 with SSLProtocolException

use of javax.net.ssl.SSLProtocolException in project fabric8 by fabric8io.

the class KubernetesHelper method isServiceSsl.

public static boolean isServiceSsl(String host, int port, boolean trustAllCerts) {
    try {
        LOG.info("Checking if a service is SSL on " + host + ":" + port);
        SSLSocketFactory sslsocketfactory;
        if (trustAllCerts) {
            sslsocketfactory = TrustEverythingSSLTrustManager.getTrustingSSLSocketFactory();
        } else {
            sslsocketfactory = (SSLSocketFactory) SSLSocketFactory.getDefault();
        }
        Socket socket = sslsocketfactory.createSocket();
        // Connect, with an explicit timeout value
        socket.connect(new InetSocketAddress(host, port), 1 * 1000);
        try {
            InputStream in = socket.getInputStream();
            OutputStream out = socket.getOutputStream();
            // Write a test byte to get a reaction :)
            out.write(1);
            while (in.available() > 0) {
                System.out.print(in.read());
            }
            return true;
        } finally {
            LOG.info("Checked if a service is SSL on " + host + ":" + port);
            socket.close();
        }
    } catch (SSLHandshakeException e) {
        LOG.error("SSL handshake failed - this probably means that you need to trust the kubernetes root SSL certificate or set the environment variable " + Utils.convertSystemPropertyNameToEnvVar(io.fabric8.kubernetes.client.Config.KUBERNETES_TRUST_CERT_SYSTEM_PROPERTY), e);
    } catch (SSLProtocolException e) {
        LOG.error("SSL protocol error", e);
    } catch (SSLKeyException e) {
        LOG.error("Bad SSL key", e);
    } catch (SSLPeerUnverifiedException e) {
        LOG.error("Could not verify server", e);
    } catch (SSLException e) {
        LOG.debug("Address does not appear to be SSL-enabled - falling back to http", e);
    } catch (IOException e) {
        LOG.debug("Failed to validate service", e);
    }
    return false;
}
Also used : SSLProtocolException(javax.net.ssl.SSLProtocolException) InetSocketAddress(java.net.InetSocketAddress) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) SSLPeerUnverifiedException(javax.net.ssl.SSLPeerUnverifiedException) IOException(java.io.IOException) SSLSocketFactory(javax.net.ssl.SSLSocketFactory) SSLKeyException(javax.net.ssl.SSLKeyException) SSLException(javax.net.ssl.SSLException) Socket(java.net.Socket) SSLHandshakeException(javax.net.ssl.SSLHandshakeException)

Example 32 with SSLProtocolException

use of javax.net.ssl.SSLProtocolException in project fdroidclient by f-droid.

the class IndexV1Updater method update.

/**
 * @return whether this successfully found an index of this version
 * @throws IndexUpdater.UpdateException
 * @see org.fdroid.fdroid.net.DownloaderService#handleIntent(android.content.Intent)
 */
@Override
public boolean update() throws IndexUpdater.UpdateException {
    if (repo.isSwap) {
        // swap repos do not support index-v1
        return false;
    }
    Downloader downloader = null;
    try {
        // read file name from file
        downloader = DownloaderFactory.create(context, indexUrl);
        downloader.setCacheTag(repo.lastetag);
        downloader.setListener(downloadListener);
        downloader.download();
        if (downloader.isNotFound()) {
            return false;
        }
        hasChanged = downloader.hasChanged();
        if (!hasChanged) {
            return true;
        }
        processDownloadedIndex(downloader.outputFile, downloader.getCacheTag());
    } catch (ConnectException | HttpRetryException | NoRouteToHostException | SocketTimeoutException | SSLHandshakeException | SSLKeyException | SSLPeerUnverifiedException | SSLProtocolException | ProtocolException | UnknownHostException e) {
        // if the above list changes, also change below and in DownloaderService.handleIntent()
        Utils.debugLog(TAG, "Trying to download the index from a mirror: " + e.getMessage());
        // Mirror logic here, so that the default download code is untouched.
        String mirrorUrl;
        String prevMirrorUrl = indexUrl;
        FDroidApp.resetMirrorVars();
        // 3 is the number of timeouts we have. 10s, 30s & 60s
        int n = repo.getMirrorCount() * 3;
        for (int i = 0; i <= n; i++) {
            try {
                mirrorUrl = FDroidApp.getNewMirrorOnError(prevMirrorUrl, repo);
                prevMirrorUrl = mirrorUrl;
                downloader = DownloaderFactory.create(context, mirrorUrl);
                downloader.setCacheTag(repo.lastetag);
                downloader.setListener(downloadListener);
                downloader.setTimeout(FDroidApp.getTimeout());
                downloader.download();
                if (downloader.isNotFound()) {
                    return false;
                }
                hasChanged = downloader.hasChanged();
                if (!hasChanged) {
                    return true;
                }
                processDownloadedIndex(downloader.outputFile, downloader.getCacheTag());
                break;
            } catch (ConnectException | HttpRetryException | NoRouteToHostException | SocketTimeoutException | SSLHandshakeException | SSLKeyException | SSLPeerUnverifiedException | SSLProtocolException | ProtocolException | UnknownHostException e2) {
                // We'll just let this try the next mirror
                Utils.debugLog(TAG, "Trying next mirror");
            } catch (IOException e2) {
                if (downloader != null) {
                    FileUtils.deleteQuietly(downloader.outputFile);
                }
                throw new IndexUpdater.UpdateException(repo, "Error getting F-Droid index file", e2);
            } catch (InterruptedException e2) {
            // ignored if canceled, the local database just won't be updated
            }
        }
    } catch (IOException e) {
        if (downloader != null) {
            FileUtils.deleteQuietly(downloader.outputFile);
        }
        throw new IndexUpdater.UpdateException(repo, "Error getting F-Droid index file", e);
    } catch (InterruptedException e) {
    // ignored if canceled, the local database just won't be updated
    }
    return true;
}
Also used : SSLProtocolException(javax.net.ssl.SSLProtocolException) ProtocolException(java.net.ProtocolException) UnknownHostException(java.net.UnknownHostException) SSLPeerUnverifiedException(javax.net.ssl.SSLPeerUnverifiedException) Downloader(org.fdroid.fdroid.net.Downloader) IOException(java.io.IOException) SSLKeyException(javax.net.ssl.SSLKeyException) HttpRetryException(java.net.HttpRetryException) NoRouteToHostException(java.net.NoRouteToHostException) SSLHandshakeException(javax.net.ssl.SSLHandshakeException) SSLProtocolException(javax.net.ssl.SSLProtocolException) SocketTimeoutException(java.net.SocketTimeoutException) ConnectException(java.net.ConnectException)

Aggregations

SSLProtocolException (javax.net.ssl.SSLProtocolException)32 SSLHandshakeException (javax.net.ssl.SSLHandshakeException)9 IOException (java.io.IOException)6 SSLException (javax.net.ssl.SSLException)4 SSLKeyException (javax.net.ssl.SSLKeyException)4 SSLPeerUnverifiedException (javax.net.ssl.SSLPeerUnverifiedException)4 BufferUnderflowException (java.nio.BufferUnderflowException)3 CertificateException (java.security.cert.CertificateException)3 SSLSocketFactory (javax.net.ssl.SSLSocketFactory)3 Test (org.junit.Test)3 HandshakeState (sun.security.ssl.HandshakeStateManager.HandshakeState)3 InputStream (java.io.InputStream)2 OutputStream (java.io.OutputStream)2 ConnectException (java.net.ConnectException)2 HttpRetryException (java.net.HttpRetryException)2 InetSocketAddress (java.net.InetSocketAddress)2 NoRouteToHostException (java.net.NoRouteToHostException)2 ProtocolException (java.net.ProtocolException)2 Socket (java.net.Socket)2 SocketTimeoutException (java.net.SocketTimeoutException)2