All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.quotemedia.streamer.client.util.SSLUtils Maven / Gradle / Ivy

Go to download

Java streaming client that provides easy-to-use client APIs to connect and subscribe to QuoteMedia's market data streaming services. https://quotemedia.com/

The newest version!
package com.quotemedia.streamer.client.util;

import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSession;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;

public final class SSLUtils {
    private SSLUtils() {
    }

    public static final void disablesslverification() {
        try {
            SSLContext sslctx = SSLContext.getInstance("SSL");
            sslctx.init(null, new TrustManager[]{new AllTrustingManager()}, new SecureRandom());
            HttpsURLConnection.setDefaultSSLSocketFactory(sslctx.getSocketFactory());
            HttpsURLConnection.setDefaultHostnameVerifier(new AllTrustingHostnameVerifier());
        } catch (final NoSuchAlgorithmException e) {
            // TODO log
        } catch (final KeyManagementException e) {
            // TODO log
        }
    }

    /**
     *
     */
    private static final class AllTrustingManager implements X509TrustManager {
        @Override
        public final void checkClientTrusted(final X509Certificate[] certs, final String s) throws CertificateException {
        }

        @Override
        public final void checkServerTrusted(final X509Certificate[] certs, final String s) throws CertificateException {
        }

        @Override
        public final X509Certificate[] getAcceptedIssuers() {
            return null;
        }
    }

    /**
     *
     */
    private static final class AllTrustingHostnameVerifier implements HostnameVerifier {
        @Override
        public final boolean verify(final String s, final SSLSession sslSession) {
            return true;
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy