ConnectionFactory factory = new ConnectionFactory();
factory.setHost(AppSettings.rabbitmq_host);
factory.setPort(5671);
factory.setUsername(AppSettings.rabbitmq_username);
factory.setPassword(AppSettings.rabbitmq_password);
factory.setVirtualHost(AppSettings.rabbitmq_virtual_host);
try {
factory.useSslProtocol("TLSv1.2");
connection = factory.newConnection();
log.info("Connected to RabbitMQ!");
} catch (NoSuchAlgorithmException e) {
log.error("Unsupported algorithm: " + e.getMessage());
return false;
} catch (Exception e) {
log.error("Error establishing RabbitMQ connection: " + e.getMessage());
return false;
}
Thanks in advance,
Jim
sun.security.validator.ValidatorException: PKIX path building failed
From what I have read, it looks like the client does not like the cert I generated using my certificate authority. Unfortunately, I haven't discovered how to deal with this yet.
Jim
factory.useSslProtocol();
// Tells the library to setup the default Key and Trust managers for you
// which do not do any form of remote server trust verificationSSLContext sslContext = SSLContext.getInstance("TLSv1.2", "SunJSSE");
sslContext.init(null, null, null);
factory.useSslProtocol(sslContext);
Probably because it's doing the "remote server trust verification?"
Jim
ConnectionFactory factory = new ConnectionFactory();
factory.setUsername(AppSettings.rabbitmq_username);
factory.setPassword(AppSettings.rabbitmq_password);
factory.setVirtualHost(AppSettings.rabbitmq_virtual_host);
// Creates a Trust Manager that accepts any certificate
TrustManager[] trustAllCerts = new TrustManager[] {
new X509TrustManager() {
public java.security.cert.X509Certificate[] getAcceptedIssuers() {
return null;
}
public void checkClientTrusted(X509Certificate[] certs, String authType) {
}
public void checkServerTrusted(X509Certificate[] certs, String authType) {
}
}
};
try {
// Get the SSL Context and initialize it with our custom Trust Manager
SSLContext sslContext = SSLContext.getInstance("TLSv1.2", "SunJSSE");
sslContext.init(null, trustAllCerts, null);
SSLParameters params = sslContext.getDefaultSSLParameters();
ArrayList<String> protocols = new ArrayList<String>(Arrays.asList(params.getProtocols()));
ArrayList<String> ciphers = new ArrayList<String>(Arrays.asList(params.getCipherSuites()));
// Adjust the list of acceptable protocols
protocols.remove("SSLv3");
params.setProtocols(protocols.toArray(new String[protocols.size()]));
// Adjust the list of acceptable ciphers
ciphers.retainAll(Arrays.asList("TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA",
"TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA",
"TLS_RSA_WITH_AES_128_CBC_SHA",
"TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA",
"TLS_ECDH_RSA_WITH_AES_128_CBC_SHA",
"TLS_DHE_RSA_WITH_AES_128_CBC_SHA",
"TLS_DHE_DSS_WITH_AES_128_CBC_SHA"));
params.setCipherSuites(ciphers.toArray(new String[ciphers.size()]));
// Create the socket for the ConnectionFactory and set it to use the adjusted SSL Parameters
SSLSocket socket = (SSLSocket) sslContext.getSocketFactory().createSocket(AppSettings.rabbitmq_host, 5671);
socket.setTcpNoDelay(true);
socket.setSSLParameters(params);
socket.startHandshake();
connection = factory.newConnection();
log.info("Connected to RabbitMQ!");
} catch (Exception e){
log.error("Error establishing RabbitMQ connection: " + e.toString());
return false;