Create ActiveMQ Connection on TLS1.2

扶醉桌前 提交于 2019-12-09 13:52:42

问题


We had to remove SSLV3 support. So we changed activemq configuration. we added transportConnector and set enabledProtocol='TLS1.1,TLS1.2'. So that it should support on TLS1.1 or TLS1.2 But i am not getting how should i specify protocol when i am creating connection. Now it is giving me error SSLV2Hello is disabled. So my question is how should i give protocol list while creating connection. I tried it SSLSocket but could not go through. Can somebody please give me clue..

String keyStorePath = "abc.ks";
String keyStorePassword = "XYZ";
String trustStore = "cks.ts";                     
java.lang.System.setProperty("javax.net.ssl.keyStore", keyStorePath);
java.lang.System.setProperty("javax.net.ssl.keyStorePassword", keyStorePassword);
java.lang.System.setProperty("javax.net.ssl.trustStore", trustStore);
String connectionURL = 'URL?initialReconnectDelay=10&maxReconnectDelay=10&maxReconnectAttempts=2&jms.watchTopicAdvisories=false&wireFormat.maxInactivityDuration=3600000';

ConnectionFactory factory = new ActiveMQSslConnectionFactory(connectionURL);
Connection connection = factory.createConnection(user, pwd);

回答1:


Finally it worked for me.

String keyStorePassword = "123456";   
String configPath = "C:\\ssl\\";  
String keyStorePath = configPath + "client.ks";  
KeyStore ks = KeyStore.getInstance("jks");  
String trustStore = configPath + "trust.ts";  
java.lang.System.setProperty("javax.net.ssl.trustStore", trustStore);
java.lang.System.setProperty("javax.net.ssl.trustStorePassword", keyStorePassword);

            InputStream ksIs = new FileInputStream(keyStorePath);
            try {
                ks.load(ksIs, keyStorePassword.toCharArray());
            } finally {
                if (ksIs != null) {
                    ksIs.close();
                }
            }
            KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
            kmf.init(ks, keyStorePassword.toCharArray());

            TrustManager[] trustAllCerts = new TrustManager[] {
                    new X509TrustManager() {
                        public void checkClientTrusted(java.security.cert.X509Certificate[] certs, String authType) {
                        }

                        public void checkServerTrusted(java.security.cert.X509Certificate[] certs, String authType) {
                        }

                        public java.security.cert.X509Certificate[] getAcceptedIssuers() {
                            return null;
                        }
                    }
            };

            final SSLContext sslContext = SSLContext.getInstance("TLSv1.2");
            ConnectionFactory factory = new ActiveMQSslConnectionFactory(URL);
            sslContext.init(kmf.getKeyManagers(), trustAllCerts, new SecureRandom());       
            SslContext context = new SslContext();
            context.setSSLContext(sslContext);
            SslContext.setCurrentSslContext(context);
            Connection connection = factory.createConnection(loginName, pwd);
            connection.start();         
            Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
            MessageProducer nonPersistentProducer = session.createProducer(null);
            session.close();
            connection.close();


来源:https://stackoverflow.com/questions/36870380/create-activemq-connection-on-tls1-2

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!