I'm trying to connect to Cassandra with SSL authentication using Spring Boot.
When I tried to connect to Cassandra using the cqlsh terminal with .crt and .key file it connected, but when I tried in Spring Boot(.crt and .key will be converted into keystore and truststore) I received the following exception:
Caused by: javax.net.ssl.SSLHandshakeException: Received fatal alert: bad_certificate
at java.base/sun.security.ssl.Alert.createSSLException(Alert.java:131) ~[?:?]
This is the method I used to create the SSLContext object with the keystore and truststore:
public SSLContext getSSLCertificate5() {
log.info("getSSLCertificate5---- ");
SSLContext sslContext = null;
try {
String key = usageServiceProperties.getCassandraKeyStorePassword();
//Load keystore
KeyStore keyStore = KeyStore.getInstance("JKS");
keyStore.load(usageServiceProperties.getKeyStorePath().getInputStream(), key.toCharArray());
KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance("SunX509");
keyManagerFactory.init(keyStore, key.toCharArray());
TrustManagerFactory tmf = TrustManagerFactory.getInstance("SunX509");
KeyStore trustStore = KeyStore.getInstance("JKS");
trustStore.load(usageServiceProperties.getTrustStorePath().getInputStream(), key.toCharArray());
tmf.init(trustStore);
sslContext = SSLContext.getInstance("TLS");
sslContext.init(keyManagerFactory.getKeyManagers(), tmf.getTrustManagers() , null);
} catch (Exception e) {
log.error("Error occured-- ",e);
}
return sslContext;
}
I tried all possibilities, but I haven't been able to connect, can anyone help on this? Cassandra should connect with SSL auth using Spring Boot.