Search code examples
springpostgresqlsslibm-cloudubuntu-18.04

Loading the SSL Root Certificate into a TrustManager failed


I'm trying to start a spring application on a IBM cloud VM (Ubuntu 18). The command I'm using is java -jar application.jar. It uses spring data and a SSL certificate to connect to an IBM PostGres service. It works fine on my local machine, but when I try running it the vm, it gives the following error:

org.postgresql.util.PSQLException: Loading the SSL root certificate /home/*******/.postgresql/root.crt into a TrustManager failed.
        at org.postgresql.ssl.jdbc4.LibPQFactory.<init>(LibPQFactory.java:151) ~[postgresql-42.2.2.jar!/:42.2.2]
        at org.postgresql.ssl.MakeSSL.convert(MakeSSL.java:42) ~[postgresql-42.2.2.jar!/:42.2.2]
        at org.postgresql.core.v3.ConnectionFactoryImpl.enableSSL(ConnectionFactoryImpl.java:389) ~[postgresql-42.2.2.jar!/:42.2.2]
        at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:160) ~[postgresql-42.2.2.jar!/:42.2.2]
        at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:49) [postgresql-42.2.2.jar!/:42.2.2]
        at org.postgresql.jdbc.PgConnection.<init>(PgConnection.java:195) [postgresql-42.2.2.jar!/:42.2.2]
        at org.postgresql.Driver.makeConnection(Driver.java:452) [postgresql-42.2.2.jar!/:42.2.2]
        at org.postgresql.Driver.connect(Driver.java:254) [postgresql-42.2.2.jar!/:42.2.2]
        at com.zaxxer.hikari.util.DriverDataSource.getConnection(DriverDataSource.java:136) [HikariCP-3.2.0.jar!/:na]
        at com.zaxxer.hikari.pool.PoolBase.newConnection(PoolBase.java:369) [HikariCP-3.2.0.jar!/:na]
        at com.zaxxer.hikari.pool.PoolBase.newPoolEntry(PoolBase.java:198) [HikariCP-3.2.0.jar!/:na]
        at com.zaxxer.hikari.pool.HikariPool.createPoolEntry(HikariPool.java:467) [HikariCP-3.2.0.jar!/:na]
        at com.zaxxer.hikari.pool.HikariPool.checkFailFast(HikariPool.java:541) [HikariCP-3.2.0.jar!/:na]
        at com.zaxxer.hikari.pool.HikariPool.<init>(HikariPool.java:115) [HikariCP-3.2.0.jar!/:na]

I'm scratching my head because I'm using the exact same SSL cert and jar on my local as on the VM, but it's not working. Any help would be appreciated. Thanks.


Solution

  • Fixed by putting the root.cert into

    /root/.postgresql/root.crt
    

    and running the jar w/ sudo.