Answer the question
In order to leave comments, you need to log in
How to connect to postgresql using TLS certificate from java application?
Hello, there is a java spring boot application that should connect via a private network using a tls certificate to a postgresql database on another server.
Certificates are all self-signed which are made by these commands:
openssl req -sha256 -new -x509 -days 5475 -nodes -out server-ca.crt -keyout server-ca.key
openssl req -sha256 -new -nodes -subj "/CN=10.0.0.3" -out server.csr -keyout server.key
openssl x509 -req -sha256 -days 5475 -in server.csr -CA server-ca.crt -CAkey server-ca.key -CAcreateserial -out server.crt
openssl req -sha256 -new -x509 -days 5475 -nodes -out client-ca.crt -keyout client-ca.key
openssl req -sha256 -new -nodes -subj "/CN=application" -out client.csr -keyout client.key
openssl x509 -req -sha256 -days 5475 -in client.csr -CA client-ca.crt -CAkey client-ca.key -CAcreateserial -out client.crt
cat client-ca.key client.crt > client.full.crt
keytool -keystore cacerts -alias client-full-crt -import -file client.full.crt
keytool -keystore cacerts -alias postgresql-server-crt -import -file server-ca.crt
openssl pkcs8 -topk8 -inform PEM -in client.key -outform DER -out client.pk8 -v1 PBE-MD5-DES
spring.datasource.url=jdbc:postgresql://10.0.0.3:5432/application?ssl=true&sslfactory=org.postgresql.ssl.DefaultJavaSSLFactory&sslmode=verify-full&sslcert=/etc/ssl/postgres-client/client.crt&sslkey=/etc/ssl/postgres-client/client.pk8&sslrootcert=/etc/ssl/postgres-client/server-ca.crt
spring.datasource.username=application
java -Djavax.net.ssl.trustStore=cacerts -Djavax.net.ssl.trustStorePassword=changeit -jar backend.jar --spring.config.location=application.properties
2022-01-22 19:25:34.344 UTC [324199] [unknown]@[unknown] LOG: could not accept SSL connection: sslv3 alert certificate unknown
psql "host=10.0.0.3 \
user=application \
dbname=application \
sslmode=verify-full \
sslrootcert=/etc/ssl/postgres-client/server-ca.crt \
sslcert=/etc/ssl/postgres-client/client.crt \
sslkey=/etc/ssl/postgres-client/client.key"
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question