mirror of
https://github.com/postgres/postgres.git
synced 2025-07-27 12:41:57 +03:00
Allow to use system CA pool for certificate verification
This adds a new option to libpq's sslrootcert, "system", which will load the system trusted CA roots for certificate verification. This is a more convenient way to achieve this than pointing to the system CA roots manually since the location can differ by installation and be locally adjusted by env vars in OpenSSL. When sslrootcert is set to system, sslmode is forced to be verify-full as weaker modes aren't providing much security for public CAs. Changing the location of the system roots by setting environment vars is not supported by LibreSSL so the tests will use a heuristic to determine if the system being tested is LibreSSL or OpenSSL. The workaround in .cirrus.yml is required to handle a strange interaction between homebrew and the openssl@3 formula; hopefully this can be removed in the near future. The original patch was written by Thomas Habets, which was later revived by Jacob Champion. Author: Jacob Champion <jchampion@timescale.com> Author: Thomas Habets <thomas@habets.se> Reviewed-by: Jelte Fennema <postgres@jeltef.nl> Reviewed-by: Andrew Dunstan <andrew@dunslane.net> Reviewed-by: Magnus Hagander <magnus@hagander.net> Discussion: https://www.postgresql.org/message-id/flat/CA%2BkHd%2BcJwCUxVb-Gj_0ptr3_KZPwi3%2B67vK6HnLFBK9MzuYrLA%40mail.gmail.com
This commit is contained in:
@ -1060,8 +1060,29 @@ initialize_SSL(PGconn *conn)
|
||||
else
|
||||
fnbuf[0] = '\0';
|
||||
|
||||
if (fnbuf[0] != '\0' &&
|
||||
stat(fnbuf, &buf) == 0)
|
||||
if (strcmp(fnbuf, "system") == 0)
|
||||
{
|
||||
/*
|
||||
* The "system" sentinel value indicates that we should load whatever
|
||||
* root certificates are installed for use by OpenSSL; these locations
|
||||
* differ by platform. Note that the default system locations may be
|
||||
* further overridden by the SSL_CERT_DIR and SSL_CERT_FILE
|
||||
* environment variables.
|
||||
*/
|
||||
if (SSL_CTX_set_default_verify_paths(SSL_context) != 1)
|
||||
{
|
||||
char *err = SSLerrmessage(ERR_get_error());
|
||||
|
||||
libpq_append_conn_error(conn, "could not load system root certificate paths: %s",
|
||||
err);
|
||||
SSLerrfree(err);
|
||||
SSL_CTX_free(SSL_context);
|
||||
return -1;
|
||||
}
|
||||
have_rootcert = true;
|
||||
}
|
||||
else if (fnbuf[0] != '\0' &&
|
||||
stat(fnbuf, &buf) == 0)
|
||||
{
|
||||
X509_STORE *cvstore;
|
||||
|
||||
@ -1122,10 +1143,10 @@ initialize_SSL(PGconn *conn)
|
||||
*/
|
||||
if (fnbuf[0] == '\0')
|
||||
libpq_append_conn_error(conn, "could not get home directory to locate root certificate file\n"
|
||||
"Either provide the file or change sslmode to disable server certificate verification.");
|
||||
"Either provide the file, use the system's trusted roots with sslrootcert=system, or change sslmode to disable server certificate verification.");
|
||||
else
|
||||
libpq_append_conn_error(conn, "root certificate file \"%s\" does not exist\n"
|
||||
"Either provide the file or change sslmode to disable server certificate verification.", fnbuf);
|
||||
"Either provide the file, use the system's trusted roots with sslrootcert=system, or change sslmode to disable server certificate verification.", fnbuf);
|
||||
SSL_CTX_free(SSL_context);
|
||||
return -1;
|
||||
}
|
||||
|
Reference in New Issue
Block a user