通过 JDBC 连接到 postgres 服务器时 sslmode 参数的默认值?

default for sslmode argument while connection to postgres server through JDBC?

我们正在通过 jdbc 和 psql (libpq) 连接到 postgres 服务器。我已将 ssl 设置为在 postgres 服务器上。它可以采用 ssl 和非 ssl 连接。 我通过 psql 客户端建立了到 postgres 服务器的连接,并且可以确认默认的 sslmode(在建立连接时没有提供 sslmode 参数时)是“prefer”。请注意我没有在 psql 的连接字符串中提供 sslmode 参数。仍然连接安全

psql "postgresql://$POSTGRES_HOST:$PG_PORT/postgres" -U postgres
psql (9.6.18, server 9.6.12)
SSL connection (protocol: TLSv1.2, cipher: ECDHE-RSA-AES256-GCM-SHA384, bits: 256, compression: off)
Type "help" for help

。 这意味着 prefer 是 psql 的默认 ssl 模式。 我已在 AWS 文档中阅读 jdbc 到服务器的连接,默认模式是“完全验证”。我通过不向连接字符串提供 sslmode 创建了到 postgres 服务器的 jdbc 连接。传递“verify-ca”和“verify-full”无法连接到 postgres 服务器,没有发现证书异常。连接成功。我只想确认在服务器上打开 ssl 时 jdbc 连接到 postgres 服务器的默认 sslmode 是什么。我觉得应该是require or below.

JDBC 驱动程序的默认设置是使用 verify-fullsslmode

The documentation 说:

There are a number of connection parameters for configuring the client for SSL. See SSL Connection parameters

The simplest being ssl=true, passing this into the driver will cause the driver to validate both the SSL certificate and verify the hostname (same as verify-full). Note this is different than libpq which defaults to a non-validating SSL connection.