corda - 无法使用 SSL 将 Corda 节点连接到 Postgres
问题描述
我在 GCP(谷歌云平台)中的 Postgres DB 只接受通过 SSL 的连接。
我在我的内部尝试了以下内容,node.conf
但没有成功:
dataSourceProperties {
dataSourceClassName = "org.postgresql.ds.PGSimpleDataSource"
dataSource.url = "jdbc:postgresql://db-private-ip:5432/my_node"
dataSource.ssl = true
dataSource.sslMode = verify-ca
dataSource.sslRootCert = "/opt/corda/db-certs/server-ca.pem"
dataSource.sslCert = "/opt/corda/db-certs/client-cert.pem"
dataSource.sslKey = "/opt/corda/db-certs/client-key.pem"
dataSource.user = my_node_db_user
dataSource.password = my_pass
}
我确定密钥(sslMode、sslRootCert、sslCert 和 sslKey)在node.conf
(即使在 Corda 文档中的任何地方都没有提到)是可以接受的,因为在日志中我没有收到任何错误表明这些密钥无法识别.
当我尝试启动节点时出现此错误:
[ERROR] 21:58:48+0000 [main] pool.HikariPool. - HikariPool-1 - Exception during pool initialization. [errorCode=zmhrwq, moreInformationAt=https://errors.corda.net/OS/4.3/zmhrwq]
[ERROR] 21:58:48+0000 [main] internal.NodeStartupLogging. - Could not connect to the database. Please check your JDBC connection URL, or the connectivity to the database.: Could not connect to the database. Please check your JDBC connection URL, or the connectivity to the database. [errorCode=18t70u2, moreInformationAt=https://errors.corda.net/OS/4.3/18t70u2]
我尝试按照( Azure Postgres 数据库需要 Corda 的 SSL 连接?ssl=true
)中的建议添加到数据源 URL 的末尾,但这并没有解决问题。
同样对于相同的值,我可以使用 psql 客户端将我的 VM 连接到数据库:
psql "sslmode=verify-ca sslrootcert=server-ca.pem sslcert=client-cert.pem sslkey=client-key.pem hostaddr=db-private-ip user=some-user dbname=some-pass"
解决方案
结果 JDBC 驱动程序无法从 PEM 文件中读取密钥,必须使用以下命令将其转换为 DER 文件:
openssl pkcs8 -topk8 -inform PEM -in client-key.pem -outform DER -nocrypt -out client-key.der
chmod 400 client-key.der
chown corda:corda client-key.der
更多细节在这里:https ://github.com/pgjdbc/pgjdbc/issues/1364
所以正确的配置应该是这样的:
dataSourceProperties {
dataSourceClassName = "org.postgresql.ds.PGSimpleDataSource"
dataSource.url = "jdbc:postgresql://db-private-ip:5432/db-name"
dataSource.ssl = true
dataSource.sslMode = verify-ca
dataSource.sslRootCert = "/opt/corda/db-certs/server-ca.pem"
dataSource.sslCert = "/opt/corda/db-certs/client-cert.pem"
dataSource.sslKey = "/opt/corda/db-certs/client-key.der"
dataSource.user = db-user-name
dataSource.password = db-user-pass
}
推荐阅读
- python - Shapely 点对象和 Geopandas 数据框产生空输出
- android - checkableBehavior="all" 不适用于菜单
- robotics - 位置控制器能够平移关节,但不能旋转
- django - 如何使用 Django 中的 OneToOne 字段创建多种类型的用户?
- api - Swagger - 从定义中检索“示例值”以构建测试
- safari - CAS v6.4:注册服务时不重定向 safari (macOS Catalina) 中的登录页面
- python - 如何在没有 Process 类的情况下从 C# 执行 Python 脚本
- flutter - 如何使状态栏颜色与颤动中的容器颜色相同
- ios - 无法连接到 iPhone se2 上的 React-Native 语音通话
- tensorflow - 框架暗网有多少模型?