rethinkdb / rethinkdb-java

Official RethinkDB Java client
https://rethinkdb.com/api/java/
Apache License 2.0
21 stars 10 forks source link

Unable to connect with TLS enabled starting from version 2.4.2 #72

Open HeikoMueller opened 9 months ago

HeikoMueller commented 9 months ago

Describe the bug A clear and concise description of what the bug is. I am unable to estabish a TLS connection, neither with .certpath nor .sslContext, starting from version 2.4.2. Version 2.4.1 works without problems

To Reproduce Steps to reproduce the behavior:

  1. TODO
    • Create a self-signed certificate on RethinkDB server, add it to client's trust store, then

private SSLContext initializeSSLContext(RethinkSinkConfig config) throws KeyStoreException,NoSuchAlgorithmException, CertificateException, IOException, KeyManagementException { KeyStore keyStore = loadCertificate(config.getCertpath()); TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm()); tmf.init(keyStore); SSLContext sslContext = SSLContext.getInstance("TLS"); sslContext.init(null, tmf.getTrustManagers(), null); return sslContext; } private KeyStore loadCertificate(String certPath) throws KeyStoreException, NoSuchAlgorithmException, CertificateException, IOException { KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType()); keyStore.load(null, null); // Initialize KeyStore

    try (FileInputStream certInputStream = new FileInputStream(certPath)) {
        CertificateFactory cf = CertificateFactory.getInstance("X.509");
        X509Certificate caCert = (X509Certificate) cf.generateCertificate(certInputStream);
        keyStore.setCertificateEntry("caCert", caCert);
    } catch (FileNotFoundException e) {
        log.log(Level.SEVERE, "Certificate file not found at " + certPath, e);
        throw e;
    } catch (CertificateException | IOException e) {
        log.log(Level.SEVERE, "Error loading certificate from " + certPath, e);
        throw e;
    }
    return keyStore;

}

SSLContext sslContext = initializeSSLContext(config); Connection connection = r.connection() .hostname(config.getHost()) .port(config.getPort()) .db(config.getDb()) .user(config.getUsername(), config.getPassword()) .sslContext(sslContext) // .certFile(certStream) .connect();

Expected behavior A clear and concise description of what you expected to happen. Java client shall connect. It does not. No exceptions are thrown. Same with .certFile(certStream) option. Code works as expected up to 2.4.1

System info RethinkDB Version: 2.4.3 openjdk 17.0.7 2023-04-18 OpenJDK Runtime Environment (build 17.0.7+7-Ubuntu-0ubuntu118.04) OpenJDK 64-Bit Server VM (build 17.0.7+7-Ubuntu-0ubuntu118.04, mixed mode, sharing)