我正在尝试将我的Openliberty连接到一个PostgreDB,它的sslMode比"require“要高。这是server.xml
<featureManager>
<feature>jaxrs-2.1</feature>
<feature>mpHealth-2.1</feature>
<feature>ejbLite-3.2</feature>
<feature>beanValidation-2.0</feature>
<feature>concurrent-1.0</feature>
<feature>mpConfig-1.3</feature>
<feature>jpa-2.2</feature>
<feature>transportSecurity-1.0</feature>
<feature>jdbc-4.2</feature>
</featureManager>
...
<sslDefault sslRef="defaultSsl"/>
<ssl id="defaultSsl" trustStoreRef="defaultTrustStore"/>
<keyStore id="defaultTrustStore" location="postgre_store.jks" password="changeit"/>
<library id="postgresql-driver-library">
<fileset dir="${shared.resource.dir}/postgresql" id="postgresql-driver-fileset" includes="*.jar"/>
</library>
<jdbcDriver id="postgresql-driver" javax.sql.XADataSource="org.postgresql.xa.PGXADataSource"
javax.sql.ConnectionPoolDataSource="org.postgresql.ds.PGConnectionPoolDataSource"
libraryRef="postgresql-driver-library"/>
<dataSource id="some-db" jndiName="jdbc/mydb" jdbcDriverRef="postgresql-driver"
type="javax.sql.ConnectionPoolDataSource" transactional="true">
<properties serverName="${datasource.servername}"
portNumber="${datasource.port}"
databaseName="${datasource.database}"
user="${datasource.username}"
password="${datasource.password}"
ssl="true"
loggerLevel="DEBUG"
sslMode="verify-ca"
sslFactory="org.postgresql.ssl.DefaultJavaSSLFactory"/>
</dataSource>
信任库与server.xml
位于同一个文件夹中。在服务器启动时,一旦Flyway试图连接到PostgreDB,我就会收到以下错误:
[INFO] SQL State : 08006
[INFO] Error Code : 0
[INFO] Message : SSL error: PKIX path building failed:
sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path
to requested target DSRA0010E: SQL-Status = 08006, Errorcode = 0
[INFO]
[INFO] at org.flywaydb.core.internal.jdbc.JdbcUtils.openConnection(JdbcUtils.java:60)
[INFO] at
org.flywaydb.core.internal.database.DatabaseFactory.createDatabase(DatabaseFactory.java:72)
[INFO] at org.flywaydb.core.Flyway.execute(Flyway.java:1670)
[INFO] at org.flywaydb.core.Flyway.info(Flyway.java:1521)
我将根证书(它是自签名的)添加到一个新创建的信任库中,如下面所描述的:https://jdbc.postgresql.org/documentation/head/ssl-client.html,并将其从.cer
转换为.crt.der
(我也不确定这是否重要)。如何确保所提供的信任库被jdbc识别和使用?我的假设是,sslRootCert
标记中的<properties>
属性也应该指向在Postgre服务器端(我想连接到的服务器)上用于证书生成的公共可信根证书吗?
Openliberty版本为: 21.0.0.3
postgre司机手工艺品是:
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.2.14</version>
对于为什么这种联系不起作用,有什么想法吗?
发布于 2021-07-21 07:04:05
连接设置是正确的,本例中的问题是配置不正确的PostgreSQL服务器。
发布于 2021-06-09 05:39:59
我认为这里的问题是,您试图同时使用驱动程序SSL工厂和本机java SSL工厂。
当您设置sslFactory="org.postgresql.ssl.DefaultJavaSSLFactory"
时,您告诉驱动程序忽略sslRootCert
,而是希望在本机java信任库中找到证书。
您可以执行以下操作之一来修复此问题:
将根证书添加到truststore.
。
要调试这一点,您应该使用以下JVM属性-Djavax.net.debug=all
运行并查看输出。驱动程序试图对其进行验证的受信任证书将在下面列出:
javax.net.ssl|DEBUG|35|Default Executor-thread-3|X509TrustManagerImpl.java:79|adding as trusted certificates (
"certificate" : {
"version" : "v3",
"serial number" : "1C 3D 0F 3E",
"signature algorithm": "SHA256withRSA",
这里有一个有用的博客,可以更深入地了解SSL配置:https://openliberty.io/blog/2021/06/04/database-ssl-primer.html。
https://stackoverflow.com/questions/67743239
复制相似问题