Search in sources :

Example 31 with HostnameVerifier

use of javax.net.ssl.HostnameVerifier in project ORCID-Source by ORCID.

the class DevJerseyClientConfig method init.

public void init() {
    SSLContext ctx = createSslContext();
    HttpsURLConnection.setDefaultSSLSocketFactory(ctx.getSocketFactory());
    getProperties().put(HTTPSProperties.PROPERTY_HTTPS_PROPERTIES, new HTTPSProperties(new HostnameVerifier() {

        @Override
        public boolean verify(String hostname, SSLSession sslSession) {
            if (hostname.equals("localhost")) {
                return true;
            }
            return false;
        }
    }, ctx));
}
Also used : SSLSession(javax.net.ssl.SSLSession) SSLContext(javax.net.ssl.SSLContext) HTTPSProperties(com.sun.jersey.client.urlconnection.HTTPSProperties) HostnameVerifier(javax.net.ssl.HostnameVerifier)

Example 32 with HostnameVerifier

use of javax.net.ssl.HostnameVerifier in project ORCID-Source by ORCID.

the class OrcidJerseyT2ClientConfig method afterPropertiesSet.

/**
     * Invoked by a BeanFactory after it has set all bean properties supplied
     * (and satisfied BeanFactoryAware and ApplicationContextAware).
     * <p>
     * This method allows the bean instance to perform initialization only
     * possible when all bean properties have been set and to throw an exception
     * in the event of misconfiguration.
     * 
     * @throws Exception
     *             in the event of misconfiguration (such as failure to set an
     *             essential property) or if initialization fails.
     */
@Override
public void afterPropertiesSet() throws Exception {
    SSLContext ctx = createSslContext();
    HttpsURLConnection.setDefaultSSLSocketFactory(ctx.getSocketFactory());
    getProperties().put(HTTPSProperties.PROPERTY_HTTPS_PROPERTIES, new HTTPSProperties(new HostnameVerifier() {

        @Override
        public boolean verify(String s, SSLSession sslSession) {
            return true;
        }
    }, ctx));
}
Also used : SSLSession(javax.net.ssl.SSLSession) SSLContext(javax.net.ssl.SSLContext) HTTPSProperties(com.sun.jersey.client.urlconnection.HTTPSProperties) HostnameVerifier(javax.net.ssl.HostnameVerifier)

Example 33 with HostnameVerifier

use of javax.net.ssl.HostnameVerifier in project ORCID-Source by ORCID.

the class OrcidJerseyT2ClientOAuthConfig method afterPropertiesSet.

@Override
public void afterPropertiesSet() throws Exception {
    SSLContext ctx = createSslContext();
    HttpsURLConnection.setDefaultSSLSocketFactory(ctx.getSocketFactory());
    getProperties().put(HTTPSProperties.PROPERTY_HTTPS_PROPERTIES, new HTTPSProperties(new HostnameVerifier() {

        @Override
        public boolean verify(String s, SSLSession sslSession) {
            return true;
        }
    }, ctx));
}
Also used : SSLSession(javax.net.ssl.SSLSession) SSLContext(javax.net.ssl.SSLContext) HTTPSProperties(com.sun.jersey.client.urlconnection.HTTPSProperties) HostnameVerifier(javax.net.ssl.HostnameVerifier)

Example 34 with HostnameVerifier

use of javax.net.ssl.HostnameVerifier in project opennms by OpenNMS.

the class VmwareViJavaAccess method relax.

/**
     * This method is used to "relax" the policies concerning self-signed certificates.
     */
protected void relax() {
    TrustManager[] trustAllCerts = new TrustManager[] { new AnyServerX509TrustManager() };
    try {
        SSLContext sslContext = SSLContext.getInstance("SSL");
        sslContext.init(null, trustAllCerts, new SecureRandom());
        HttpsURLConnection.setDefaultSSLSocketFactory(sslContext.getSocketFactory());
    } catch (Exception exception) {
        logger.warn("Error setting relaxed SSL policy", exception);
    }
    HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier() {

        @Override
        public boolean verify(String s, SSLSession sslSession) {
            return true;
        }
    });
}
Also used : SSLSession(javax.net.ssl.SSLSession) SecureRandom(java.security.SecureRandom) AnyServerX509TrustManager(org.opennms.core.utils.AnyServerX509TrustManager) SSLContext(javax.net.ssl.SSLContext) CIMException(org.sblim.wbem.cim.CIMException) RemoteException(java.rmi.RemoteException) ConnectException(java.net.ConnectException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) CertificateException(java.security.cert.CertificateException) TrustManager(javax.net.ssl.TrustManager) AnyServerX509TrustManager(org.opennms.core.utils.AnyServerX509TrustManager) X509TrustManager(javax.net.ssl.X509TrustManager) HostnameVerifier(javax.net.ssl.HostnameVerifier)

Example 35 with HostnameVerifier

use of javax.net.ssl.HostnameVerifier in project opennms by OpenNMS.

the class VmwareConfigBuilder method main.

public static void main(String[] args) throws ParseException {
    String hostname = null;
    String username = null;
    String password = null;
    String rrdRepository = null;
    final Options options = new Options();
    options.addOption("rrdRepository", true, "set rrdRepository path for generated config files, default: '/opt/opennms/share/rrd/snmp/'");
    final CommandLineParser parser = new PosixParser();
    final CommandLine cmd = parser.parse(options, args);
    @SuppressWarnings("unchecked") List<String> arguments = (List<String>) cmd.getArgList();
    if (arguments.size() < 3) {
        usage(options, cmd);
        System.exit(1);
    }
    hostname = arguments.remove(0);
    username = arguments.remove(0);
    password = arguments.remove(0);
    if (cmd.hasOption("rrdRepository")) {
        rrdRepository = cmd.getOptionValue("rrdRepository");
    } else {
        rrdRepository = "/opt/opennms/share/rrd/snmp/";
    }
    TrustManager[] trustAllCerts = new TrustManager[] { new AnyServerX509TrustManager() };
    SSLContext sc = null;
    try {
        sc = SSLContext.getInstance("SSL");
        sc.init(null, trustAllCerts, null);
    } catch (NoSuchAlgorithmException e) {
        e.printStackTrace();
    } catch (KeyManagementException e) {
        e.printStackTrace();
    }
    HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
    HostnameVerifier hv = new HostnameVerifier() {

        @Override
        public boolean verify(String urlHostName, SSLSession session) {
            return true;
        }
    };
    HttpsURLConnection.setDefaultHostnameVerifier(hv);
    VmwareConfigBuilder vmwareConfigBuilder;
    vmwareConfigBuilder = new VmwareConfigBuilder(hostname, username, password);
    try {
        vmwareConfigBuilder.generateData(rrdRepository);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : Options(org.apache.commons.cli.Options) PosixParser(org.apache.commons.cli.PosixParser) SSLSession(javax.net.ssl.SSLSession) SSLContext(javax.net.ssl.SSLContext) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) KeyManagementException(java.security.KeyManagementException) IOException(java.io.IOException) KeyManagementException(java.security.KeyManagementException) ParseException(org.apache.commons.cli.ParseException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) AnyServerX509TrustManager(org.opennms.core.utils.AnyServerX509TrustManager) TrustManager(javax.net.ssl.TrustManager) HostnameVerifier(javax.net.ssl.HostnameVerifier) CommandLine(org.apache.commons.cli.CommandLine) List(java.util.List) AnyServerX509TrustManager(org.opennms.core.utils.AnyServerX509TrustManager) CommandLineParser(org.apache.commons.cli.CommandLineParser)

Aggregations

HostnameVerifier (javax.net.ssl.HostnameVerifier)94 SSLSession (javax.net.ssl.SSLSession)41 SSLContext (javax.net.ssl.SSLContext)30 SSLSocketFactory (javax.net.ssl.SSLSocketFactory)27 HttpsURLConnection (javax.net.ssl.HttpsURLConnection)24 TrustManager (javax.net.ssl.TrustManager)19 IOException (java.io.IOException)18 URL (java.net.URL)18 X509Certificate (java.security.cert.X509Certificate)17 X509TrustManager (javax.net.ssl.X509TrustManager)17 Test (org.junit.Test)16 HttpURLConnection (java.net.HttpURLConnection)14 SecureRandom (java.security.SecureRandom)14 InputStream (java.io.InputStream)12 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)10 CertificateException (java.security.cert.CertificateException)10 SSLConnectionSocketFactory (org.apache.http.conn.ssl.SSLConnectionSocketFactory)10 KeyManagementException (java.security.KeyManagementException)9 ConnectionSocketFactory (org.apache.http.conn.socket.ConnectionSocketFactory)9 ByteArrayInputStream (java.io.ByteArrayInputStream)8