Search in sources :

Example 1 with AnyServerX509TrustManager

use of org.opennms.core.utils.AnyServerX509TrustManager 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)

Example 2 with AnyServerX509TrustManager

use of org.opennms.core.utils.AnyServerX509TrustManager in project opennms by OpenNMS.

the class CustomHttpClientConfigurer method configureHttpClient.

@Override
public void configureHttpClient(final HttpClient client) {
    try {
        final SSLContext ctx = SSLContext.getInstance("SSL");
        ctx.init(EMPTY_KEYMANAGER_ARRAY, new TrustManager[] { new AnyServerX509TrustManager() }, new SecureRandom());
        SSLContext.setDefault(ctx);
        final UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(getUsername(), getPassword());
        client.getState().setCredentials(AuthScope.ANY, credentials);
        client.getParams().setAuthenticationPreemptive(true);
        LOG.debug("Configuring HTTP client with modified trust manager, username={}, password=xxxxxxxx", getUsername());
    } catch (final Exception e) {
        throw new CustomConfigurerException(e);
    }
}
Also used : SecureRandom(java.security.SecureRandom) AnyServerX509TrustManager(org.opennms.core.utils.AnyServerX509TrustManager) SSLContext(javax.net.ssl.SSLContext) UsernamePasswordCredentials(org.apache.commons.httpclient.UsernamePasswordCredentials)

Example 3 with AnyServerX509TrustManager

use of org.opennms.core.utils.AnyServerX509TrustManager in project opennms by OpenNMS.

the class TsrmTicketerPlugin method getService.

private SHSIMPINCPortType getService() {
    final SHSIMPINC service = new SHSIMPINC();
    port = service.getSHSIMPINCSOAP12Port();
    final Client cxfClient = ClientProxy.getClient(port);
    try {
        cxfClient.getRequestContext().put(Message.ENDPOINT_ADDRESS, getProperties().getProperty("tsrm.url"));
        final HTTPConduit http = (HTTPConduit) cxfClient.getConduit();
        String stictSSL = getProperties().getProperty("tsrm.ssl.strict");
        if (!Boolean.parseBoolean(stictSSL)) {
            LOG.debug("Disabling strict SSL checking.");
            // Accept all certificates
            final TrustManager[] simpleTrustManager = new TrustManager[] { new AnyServerX509TrustManager() };
            final TLSClientParameters tlsParams = new TLSClientParameters();
            tlsParams.setTrustManagers(simpleTrustManager);
            tlsParams.setDisableCNCheck(true);
            http.setTlsClientParameters(tlsParams);
        }
    } catch (IOException e) {
        LOG.error("Unable to load tsrm properties ", e);
    }
    // Log incoming and outgoing requests
    LoggingInInterceptor loggingInInterceptor = new LoggingInInterceptor();
    loggingInInterceptor.setPrettyLogging(true);
    cxfClient.getInInterceptors().add(loggingInInterceptor);
    LoggingOutInterceptor loggingOutInterceptor = new LoggingOutInterceptor();
    loggingOutInterceptor.setPrettyLogging(true);
    cxfClient.getOutInterceptors().add(loggingOutInterceptor);
    return port;
}
Also used : HTTPConduit(org.apache.cxf.transport.http.HTTPConduit) TLSClientParameters(org.apache.cxf.configuration.jsse.TLSClientParameters) LoggingOutInterceptor(org.apache.cxf.interceptor.LoggingOutInterceptor) LoggingInInterceptor(org.apache.cxf.interceptor.LoggingInInterceptor) AnyServerX509TrustManager(org.opennms.core.utils.AnyServerX509TrustManager) IOException(java.io.IOException) Client(org.apache.cxf.endpoint.Client) SHSIMPINC(com.ibm.maximo.wsdl.shsimpinc.SHSIMPINC) AnyServerX509TrustManager(org.opennms.core.utils.AnyServerX509TrustManager) TrustManager(javax.net.ssl.TrustManager)

Example 4 with AnyServerX509TrustManager

use of org.opennms.core.utils.AnyServerX509TrustManager 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) TrustManager(javax.net.ssl.TrustManager) AnyServerX509TrustManager(org.opennms.core.utils.AnyServerX509TrustManager) HostnameVerifier(javax.net.ssl.HostnameVerifier)

Aggregations

AnyServerX509TrustManager (org.opennms.core.utils.AnyServerX509TrustManager)4 IOException (java.io.IOException)3 SSLContext (javax.net.ssl.SSLContext)3 TrustManager (javax.net.ssl.TrustManager)3 SecureRandom (java.security.SecureRandom)2 HostnameVerifier (javax.net.ssl.HostnameVerifier)2 SSLSession (javax.net.ssl.SSLSession)2 SHSIMPINC (com.ibm.maximo.wsdl.shsimpinc.SHSIMPINC)1 ConnectException (java.net.ConnectException)1 MalformedURLException (java.net.MalformedURLException)1 RemoteException (java.rmi.RemoteException)1 KeyManagementException (java.security.KeyManagementException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 List (java.util.List)1 CommandLine (org.apache.commons.cli.CommandLine)1 CommandLineParser (org.apache.commons.cli.CommandLineParser)1 Options (org.apache.commons.cli.Options)1 ParseException (org.apache.commons.cli.ParseException)1 PosixParser (org.apache.commons.cli.PosixParser)1 UsernamePasswordCredentials (org.apache.commons.httpclient.UsernamePasswordCredentials)1