gpt4 book ai didi

java - 在 TLS1.2 上创建 ActiveMQ 连接

转载 作者:行者123 更新时间:2023-11-30 02:57:19 25 4
gpt4 key购买 nike

我们必须删除 SSLV3 支持。所以我们改变了activemq配置。我们添加了transportConnector并设置enabledProtocol='TLS1.1,TLS1.2'。所以它应该支持 TLS1.1 或 TLS1.2但我不知道在创建连接时应该如何指定协议(protocol)。现在它给我错误 SSLV2Hello 已禁用。所以我的问题是我应该如何在创建连接时提供协议(protocol)列表。我尝试了SSLSocket但无法通过。有人可以给我线索吗..

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);

最佳答案

终于对我有用了。

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();

关于java - 在 TLS1.2 上创建 ActiveMQ 连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36870380/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com