mirror of
https://github.com/postgres/postgres.git
synced 2025-11-22 12:22:45 +03:00
Support configuring TLSv1.3 cipher suites
The ssl_ciphers GUC can only set cipher suites for TLSv1.2, and lower, connections. For TLSv1.3 connections a different OpenSSL API must be used. This adds a new GUC, ssl_tls13_ciphers, which can be used to configure a colon separated list of cipher suites to support when performing a TLSv1.3 handshake. Original patch by Erica Zhang with additional hacking by me. Author: Erica Zhang <ericazhangy2021@qq.com> Author: Daniel Gustafsson <daniel@yesql.se> Reviewed-by: Jacob Champion <jacob.champion@enterprisedb.com> Reviewed-by: Andres Freund <andres@anarazel.de> Reviewed-by: Peter Eisentraut <peter@eisentraut.org> Reviewed-by: Jelte Fennema-Nio <postgres@jeltef.nl> Discussion: https://postgr.es/m/tencent_063F89FA72CCF2E48A0DF5338841988E9809@qq.com
This commit is contained in:
@@ -288,15 +288,31 @@ be_tls_init(bool isServerStart)
|
||||
if (!initialize_ecdh(context, isServerStart))
|
||||
goto error;
|
||||
|
||||
/* set up the allowed cipher list */
|
||||
if (SSL_CTX_set_cipher_list(context, SSLCipherSuites) != 1)
|
||||
/* set up the allowed cipher list for TLSv1.2 and below */
|
||||
if (SSL_CTX_set_cipher_list(context, SSLCipherList) != 1)
|
||||
{
|
||||
ereport(isServerStart ? FATAL : LOG,
|
||||
(errcode(ERRCODE_CONFIG_FILE_ERROR),
|
||||
errmsg("could not set the cipher list (no valid ciphers available)")));
|
||||
errmsg("could not set the TLSv1.2 cipher list (no valid ciphers available)")));
|
||||
goto error;
|
||||
}
|
||||
|
||||
/*
|
||||
* Set up the allowed cipher suites for TLSv1.3. If the GUC is an empty
|
||||
* string we leave the allowed suites to be the OpenSSL default value.
|
||||
*/
|
||||
if (SSLCipherSuites[0])
|
||||
{
|
||||
/* set up the allowed cipher suites */
|
||||
if (SSL_CTX_set_ciphersuites(context, SSLCipherSuites) != 1)
|
||||
{
|
||||
ereport(isServerStart ? FATAL : LOG,
|
||||
(errcode(ERRCODE_CONFIG_FILE_ERROR),
|
||||
errmsg("could not set the TLSv1.3 cipher suites (no valid ciphers available)")));
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
|
||||
/* Let server choose order */
|
||||
if (SSLPreferServerCiphers)
|
||||
SSL_CTX_set_options(context, SSL_OP_CIPHER_SERVER_PREFERENCE);
|
||||
|
||||
@@ -49,6 +49,7 @@ bool ssl_loaded_verify_locations = false;
|
||||
|
||||
/* GUC variable controlling SSL cipher list */
|
||||
char *SSLCipherSuites = NULL;
|
||||
char *SSLCipherList = NULL;
|
||||
|
||||
/* GUC variable for default ECHD curve. */
|
||||
char *SSLECDHCurve;
|
||||
|
||||
@@ -4641,12 +4641,23 @@ struct config_string ConfigureNamesString[] =
|
||||
},
|
||||
|
||||
{
|
||||
{"ssl_ciphers", PGC_SIGHUP, CONN_AUTH_SSL,
|
||||
gettext_noop("Sets the list of allowed SSL ciphers."),
|
||||
{"ssl_tls13_ciphers", PGC_SIGHUP, CONN_AUTH_SSL,
|
||||
gettext_noop("Sets the list of allowed TLSv1.3 cipher suites (leave blank for default)."),
|
||||
NULL,
|
||||
GUC_SUPERUSER_ONLY
|
||||
},
|
||||
&SSLCipherSuites,
|
||||
"",
|
||||
NULL, NULL, NULL
|
||||
},
|
||||
|
||||
{
|
||||
{"ssl_ciphers", PGC_SIGHUP, CONN_AUTH_SSL,
|
||||
gettext_noop("Sets the list of allowed TLSv1.2 (and lower) ciphers."),
|
||||
NULL,
|
||||
GUC_SUPERUSER_ONLY
|
||||
},
|
||||
&SSLCipherList,
|
||||
#ifdef USE_OPENSSL
|
||||
"HIGH:MEDIUM:+3DES:!aNULL",
|
||||
#else
|
||||
|
||||
@@ -110,7 +110,8 @@
|
||||
#ssl_crl_file = ''
|
||||
#ssl_crl_dir = ''
|
||||
#ssl_key_file = 'server.key'
|
||||
#ssl_ciphers = 'HIGH:MEDIUM:+3DES:!aNULL' # allowed SSL ciphers
|
||||
#ssl_ciphers = 'HIGH:MEDIUM:+3DES:!aNULL' # allowed TLSv1.2 ciphers
|
||||
#ssl_tls13_ciphers = '' # allowed TLSv1.3 cipher suites, blank for default
|
||||
#ssl_prefer_server_ciphers = on
|
||||
#ssl_groups = 'prime256v1'
|
||||
#ssl_min_protocol_version = 'TLSv1.2'
|
||||
|
||||
Reference in New Issue
Block a user