Skip to content

Accept concatenated PEM files for trustStore (aka make it easy to use SSL with Amazon RDS) #2459

Open
@eirikbakke

Description

@eirikbakke

Is your feature request related to a problem? If so, please give a short summary of the problem and how the feature would resolve it

To connect securely to a SQL Server instance, the trustStore connection property must point to a file that contains any necessary root certificate(s) and intermediate certificates. Currently, this file must be in the Java KeyStore (jks) or PKCS-12 (pk8/pfx) format. For databases hosted on Amazon RDS, however, these certificates are provided in a concatenated PEM format (global-bundle.pem which can be downloaded here).

The problem is that there is no straightforward way to convert from PEM to an acceptable JKS or PKCS12 format when the original PEM file contains many concatenated certificates. One ends up needing a script or custom tool (referenced in this StackOverflow question) that splits up the individual certificates in the PEM file and inserts them into the keystore.

Describe the preferred solution

The MSSQL JDBC driver should accept a concatenated PEM file for the trustStore parameter (in addition to any previously supported formats).

Describe alternatives you've considered

For me, the working approach was the aforementioned script, which after fixing one bug, produced a JKS file that allowed me to connect to MSSQL on RDS with JDBC without trustServerCertificate=true. This is not an approach I can easily document to other users, however.

The "easier" approach which did not work was the following command:

openssl pkcs12 -export -in global-bundle.pem -nokeys -out global-bundle.pfx

The resulting PFX file, while it does contain certificate data, was not in a form that worked as a keystore for the SQL Server JDBC driver. (Curiously, though, I was able to convert the working JKS file to a working PFX file with keytool.)

Additional context

I came upon this problem while writing documentation for Ultorg, a graphical database tool. I need simple steps to get SSL working that works on MacOS, Linux, and Windows. So I can't provide scripts that won't work on Windows etc., and I can't depend on certificates living in the Windows-native certificate stores etc.

Reference Documentations/Specifications

https://learn.microsoft.com/en-us/sql/connect/jdbc/connecting-with-ssl-encryption?view=sql-server-ver16

Reference Implementation

The PostgreSQL JDBC driver does accept concatenated PEM files for the sslrootcert property (I successfully tried it with global-bundle.pem from Amazon RDS). It looks like only a few lines of JDBC driver code would be needed to support it in the MSSQL JDBC driver. Basically:

KeyStore ks = KeyStore.getInstance("jks");
CertificateFactory cf = CertificateFactory.getInstance("X.509");
Object[] certs = cf.generateCertificates(new FileInputStream(TRUST_STORE_FILE_PATH)).toArray(new Certificate[]{});
ks.load(null, null);
for (int i = 0; i < certs.length; i++)
    ks.setCertificateEntry("cert" + i, (Certificate) certs[i]);

For comparison, the relevant code in the MSSQL JDBC driver is here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BacklogThe topic in question has been recognized and added to development backlogEnhancementAn enhancement to the driver. Lower priority than bugs.

    Type

    No type

    Projects

    Status

    Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions