Welcome! Log In Create A New Profile

Advanced

[nginx] SSL: a new macro to set default protocol versions.

Anonymous User
November 22, 2024 04:50AM
details: https://github.com/nginx/nginx/commit/476d6526b2e8297025c608425f4cad07b4f65990
branches: master
commit: 476d6526b2e8297025c608425f4cad07b4f65990
user: Sergey Kandaurov <pluknet@nginx.com>
date: Mon, 18 Nov 2024 13:39:13 +0400
description:
SSL: a new macro to set default protocol versions.

This simplifies merging protocol values after ea15896 and ebd18ec.

Further, as outlined in ebd18ec18, for libraries preceeding TLSv1.2+
support, only meaningful versions TLSv1 and TLSv1.1 are set by default.

While here, fixed indentation.

---
src/event/ngx_event_openssl.h | 7 +++++++
src/http/modules/ngx_http_grpc_module.c | 10 +---------
src/http/modules/ngx_http_proxy_module.c | 10 +---------
src/http/modules/ngx_http_ssl_module.c | 10 +---------
src/http/modules/ngx_http_uwsgi_module.c | 10 +---------
src/mail/ngx_mail_ssl_module.c | 10 +---------
src/stream/ngx_stream_proxy_module.c | 10 +---------
src/stream/ngx_stream_ssl_module.c | 10 +---------
8 files changed, 14 insertions(+), 63 deletions(-)

diff --git a/src/event/ngx_event_openssl.h b/src/event/ngx_event_openssl.h
index 6d171229c..2147205d6 100644
--- a/src/event/ngx_event_openssl.h
+++ b/src/event/ngx_event_openssl.h
@@ -187,6 +187,13 @@ typedef struct {
#define NGX_SSL_TLSv1_3 0x0040


+#if (defined SSL_OP_NO_TLSv1_2 || defined SSL_OP_NO_TLSv1_3)
+#define NGX_SSL_DEFAULT_PROTOCOLS (NGX_SSL_TLSv1_2|NGX_SSL_TLSv1_3)
+#else
+#define NGX_SSL_DEFAULT_PROTOCOLS (NGX_SSL_TLSv1|NGX_SSL_TLSv1_1)
+#endif
+
+
#define NGX_SSL_BUFFER 1
#define NGX_SSL_CLIENT 2

diff --git a/src/http/modules/ngx_http_grpc_module.c b/src/http/modules/ngx_http_grpc_module.c
index 0a103ac66..326720447 100644
--- a/src/http/modules/ngx_http_grpc_module.c
+++ b/src/http/modules/ngx_http_grpc_module.c
@@ -4475,16 +4475,8 @@ ngx_http_grpc_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
ngx_conf_merge_value(conf->upstream.ssl_session_reuse,
prev->upstream.ssl_session_reuse, 1);

-#ifndef SSL_OP_NO_TLSv1_2
ngx_conf_merge_bitmask_value(conf->ssl_protocols, prev->ssl_protocols,
- (NGX_CONF_BITMASK_SET
- |NGX_SSL_TLSv1|NGX_SSL_TLSv1_1
- |NGX_SSL_TLSv1_2|NGX_SSL_TLSv1_3));
-#else
- ngx_conf_merge_bitmask_value(conf->ssl_protocols, prev->ssl_protocols,
- (NGX_CONF_BITMASK_SET
- |NGX_SSL_TLSv1_2|NGX_SSL_TLSv1_3));
-#endif
+ (NGX_CONF_BITMASK_SET|NGX_SSL_DEFAULT_PROTOCOLS));

ngx_conf_merge_str_value(conf->ssl_ciphers, prev->ssl_ciphers,
"DEFAULT");
diff --git a/src/http/modules/ngx_http_proxy_module.c b/src/http/modules/ngx_http_proxy_module.c
index 73d8ce2a8..25fa92bae 100644
--- a/src/http/modules/ngx_http_proxy_module.c
+++ b/src/http/modules/ngx_http_proxy_module.c
@@ -3942,16 +3942,8 @@ ngx_http_proxy_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
ngx_conf_merge_value(conf->upstream.ssl_session_reuse,
prev->upstream.ssl_session_reuse, 1);

-#ifndef SSL_OP_NO_TLSv1_2
ngx_conf_merge_bitmask_value(conf->ssl_protocols, prev->ssl_protocols,
- (NGX_CONF_BITMASK_SET
- |NGX_SSL_TLSv1|NGX_SSL_TLSv1_1
- |NGX_SSL_TLSv1_2|NGX_SSL_TLSv1_3));
-#else
- ngx_conf_merge_bitmask_value(conf->ssl_protocols, prev->ssl_protocols,
- (NGX_CONF_BITMASK_SET
- |NGX_SSL_TLSv1_2|NGX_SSL_TLSv1_3));
-#endif
+ (NGX_CONF_BITMASK_SET|NGX_SSL_DEFAULT_PROTOCOLS));

ngx_conf_merge_str_value(conf->ssl_ciphers, prev->ssl_ciphers,
"DEFAULT");
diff --git a/src/http/modules/ngx_http_ssl_module.c b/src/http/modules/ngx_http_ssl_module.c
index 2ab9b84b7..0e892b04d 100644
--- a/src/http/modules/ngx_http_ssl_module.c
+++ b/src/http/modules/ngx_http_ssl_module.c
@@ -651,16 +651,8 @@ ngx_http_ssl_merge_srv_conf(ngx_conf_t *cf, void *parent, void *child)
ngx_conf_merge_value(conf->early_data, prev->early_data, 0);
ngx_conf_merge_value(conf->reject_handshake, prev->reject_handshake, 0);

-#ifndef SSL_OP_NO_TLSv1_2
ngx_conf_merge_bitmask_value(conf->protocols, prev->protocols,
- (NGX_CONF_BITMASK_SET
- |NGX_SSL_TLSv1|NGX_SSL_TLSv1_1
- |NGX_SSL_TLSv1_2|NGX_SSL_TLSv1_3));
-#else
- ngx_conf_merge_bitmask_value(conf->protocols, prev->protocols,
- (NGX_CONF_BITMASK_SET
- |NGX_SSL_TLSv1_2|NGX_SSL_TLSv1_3));
-#endif
+ (NGX_CONF_BITMASK_SET|NGX_SSL_DEFAULT_PROTOCOLS));

ngx_conf_merge_size_value(conf->buffer_size, prev->buffer_size,
NGX_SSL_BUFSIZE);
diff --git a/src/http/modules/ngx_http_uwsgi_module.c b/src/http/modules/ngx_http_uwsgi_module.c
index 9e9682bc3..f42ae706a 100644
--- a/src/http/modules/ngx_http_uwsgi_module.c
+++ b/src/http/modules/ngx_http_uwsgi_module.c
@@ -1899,16 +1899,8 @@ ngx_http_uwsgi_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
ngx_conf_merge_value(conf->upstream.ssl_session_reuse,
prev->upstream.ssl_session_reuse, 1);

-#ifndef SSL_OP_NO_TLSv1_2
ngx_conf_merge_bitmask_value(conf->ssl_protocols, prev->ssl_protocols,
- (NGX_CONF_BITMASK_SET
- |NGX_SSL_TLSv1|NGX_SSL_TLSv1_1
- |NGX_SSL_TLSv1_2|NGX_SSL_TLSv1_3));
-#else
- ngx_conf_merge_bitmask_value(conf->ssl_protocols, prev->ssl_protocols,
- (NGX_CONF_BITMASK_SET
- |NGX_SSL_TLSv1_2|NGX_SSL_TLSv1_3));
-#endif
+ (NGX_CONF_BITMASK_SET|NGX_SSL_DEFAULT_PROTOCOLS));

ngx_conf_merge_str_value(conf->ssl_ciphers, prev->ssl_ciphers,
"DEFAULT");
diff --git a/src/mail/ngx_mail_ssl_module.c b/src/mail/ngx_mail_ssl_module.c
index 4c3f41a58..176e9c624 100644
--- a/src/mail/ngx_mail_ssl_module.c
+++ b/src/mail/ngx_mail_ssl_module.c
@@ -343,16 +343,8 @@ ngx_mail_ssl_merge_conf(ngx_conf_t *cf, void *parent, void *child)
ngx_conf_merge_value(conf->prefer_server_ciphers,
prev->prefer_server_ciphers, 0);

-#ifndef SSL_OP_NO_TLSv1_2
ngx_conf_merge_bitmask_value(conf->protocols, prev->protocols,
- (NGX_CONF_BITMASK_SET
- |NGX_SSL_TLSv1|NGX_SSL_TLSv1_1
- |NGX_SSL_TLSv1_2|NGX_SSL_TLSv1_3));
-#else
- ngx_conf_merge_bitmask_value(conf->protocols, prev->protocols,
- (NGX_CONF_BITMASK_SET
- |NGX_SSL_TLSv1_2|NGX_SSL_TLSv1_3));
-#endif
+ (NGX_CONF_BITMASK_SET|NGX_SSL_DEFAULT_PROTOCOLS));

ngx_conf_merge_uint_value(conf->verify, prev->verify, 0);
ngx_conf_merge_uint_value(conf->verify_depth, prev->verify_depth, 1);
diff --git a/src/stream/ngx_stream_proxy_module.c b/src/stream/ngx_stream_proxy_module.c
index 2b6f9baaf..e978056ef 100644
--- a/src/stream/ngx_stream_proxy_module.c
+++ b/src/stream/ngx_stream_proxy_module.c
@@ -2181,16 +2181,8 @@ ngx_stream_proxy_merge_srv_conf(ngx_conf_t *cf, void *parent, void *child)
ngx_conf_merge_value(conf->ssl_session_reuse,
prev->ssl_session_reuse, 1);

-#ifndef SSL_OP_NO_TLSv1_2
ngx_conf_merge_bitmask_value(conf->ssl_protocols, prev->ssl_protocols,
- (NGX_CONF_BITMASK_SET
- |NGX_SSL_TLSv1|NGX_SSL_TLSv1_1
- |NGX_SSL_TLSv1_2|NGX_SSL_TLSv1_3));
-#else
- ngx_conf_merge_bitmask_value(conf->ssl_protocols, prev->ssl_protocols,
- (NGX_CONF_BITMASK_SET
- |NGX_SSL_TLSv1_2|NGX_SSL_TLSv1_3));
-#endif
+ (NGX_CONF_BITMASK_SET|NGX_SSL_DEFAULT_PROTOCOLS));

ngx_conf_merge_str_value(conf->ssl_ciphers, prev->ssl_ciphers, "DEFAULT");

diff --git a/src/stream/ngx_stream_ssl_module.c b/src/stream/ngx_stream_ssl_module.c
index 8177d580f..dfbaa0e2f 100644
--- a/src/stream/ngx_stream_ssl_module.c
+++ b/src/stream/ngx_stream_ssl_module.c
@@ -882,16 +882,8 @@ ngx_stream_ssl_merge_srv_conf(ngx_conf_t *cf, void *parent, void *child)

ngx_conf_merge_value(conf->reject_handshake, prev->reject_handshake, 0);

-#ifndef SSL_OP_NO_TLSv1_2
ngx_conf_merge_bitmask_value(conf->protocols, prev->protocols,
- (NGX_CONF_BITMASK_SET
- |NGX_SSL_TLSv1|NGX_SSL_TLSv1_1
- |NGX_SSL_TLSv1_2|NGX_SSL_TLSv1_3));
-#else
- ngx_conf_merge_bitmask_value(conf->protocols, prev->protocols,
- (NGX_CONF_BITMASK_SET
- |NGX_SSL_TLSv1_2|NGX_SSL_TLSv1_3));
-#endif
+ (NGX_CONF_BITMASK_SET|NGX_SSL_DEFAULT_PROTOCOLS));

ngx_conf_merge_uint_value(conf->verify, prev->verify, 0);
ngx_conf_merge_uint_value(conf->verify_depth, prev->verify_depth, 1);
_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
https://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

[nginx] SSL: a new macro to set default protocol versions.

Anonymous User 131 November 22, 2024 04:50AM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 200
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 500 on July 15, 2024
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready