ignatenkobrain / rpms / nginx

Forked from rpms/nginx 2 years ago
Clone
daa24a
diff --git a/src/event/ngx_event_openssl.c b/src/event/ngx_event_openssl.c
daa24a
index 570abd7..ac37936 100644
daa24a
--- a/src/event/ngx_event_openssl.c
daa24a
+++ b/src/event/ngx_event_openssl.c
daa24a
@@ -232,6 +232,8 @@ ngx_ssl_init(ngx_log_t *log)
daa24a
 ngx_int_t
daa24a
 ngx_ssl_create(ngx_ssl_t *ssl, ngx_uint_t protocols, void *data)
daa24a
 {
daa24a
+    ngx_uint_t prot = NGX_SSL_NO_PROT;
daa24a
+
daa24a
     ssl->ctx = SSL_CTX_new(SSLv23_method());
daa24a
 
daa24a
     if (ssl->ctx == NULL) {
daa24a
@@ -296,39 +298,53 @@ ngx_ssl_create(ngx_ssl_t *ssl, ngx_uint_t protocols, void *data)
daa24a
 
daa24a
     SSL_CTX_set_options(ssl->ctx, SSL_OP_SINGLE_DH_USE);
daa24a
 
daa24a
-#ifdef SSL_CTRL_CLEAR_OPTIONS
daa24a
-    /* only in 0.9.8m+ */
daa24a
-    SSL_CTX_clear_options(ssl->ctx,
daa24a
-                          SSL_OP_NO_SSLv2|SSL_OP_NO_SSLv3|SSL_OP_NO_TLSv1);
daa24a
+    if (protocols){
daa24a
+#ifdef SSL_OP_NO_TLSv1_3
daa24a
+        if (protocols & NGX_SSL_TLSv1_3) {
daa24a
+            prot = TLS1_3_VERSION;
daa24a
+        } else
daa24a
+#endif
daa24a
+#ifdef SSL_OP_NO_TLSv1_2
daa24a
+        if (protocols & NGX_SSL_TLSv1_2) {
daa24a
+            prot =  TLS1_2_VERSION;
daa24a
+        } else
daa24a
+#endif
daa24a
+#ifdef SSL_OP_NO_TLSv1_1
daa24a
+        if (protocols & NGX_SSL_TLSv1_1) {
daa24a
+            prot = TLS1_1_VERSION;
daa24a
+        } else
daa24a
 #endif
daa24a
+        if (protocols & NGX_SSL_TLSv1) {
daa24a
+            prot = TLS1_VERSION;
daa24a
+        }
daa24a
 
daa24a
-    if (!(protocols & NGX_SSL_SSLv2)) {
daa24a
-        SSL_CTX_set_options(ssl->ctx, SSL_OP_NO_SSLv2);
daa24a
-    }
daa24a
-    if (!(protocols & NGX_SSL_SSLv3)) {
daa24a
-        SSL_CTX_set_options(ssl->ctx, SSL_OP_NO_SSLv3);
daa24a
-    }
daa24a
-    if (!(protocols & NGX_SSL_TLSv1)) {
daa24a
-        SSL_CTX_set_options(ssl->ctx, SSL_OP_NO_TLSv1);
daa24a
-    }
daa24a
+        if (prot == NGX_SSL_NO_PROT) {
daa24a
+                    ngx_ssl_error(NGX_LOG_EMERG, ssl->log, 0,
daa24a
+                      "No SSL protocols available [hint: ssl_protocols]");
daa24a
+            return NGX_ERROR;
daa24a
+        }
daa24a
+
daa24a
+        SSL_CTX_set_max_proto_version(ssl->ctx, prot);
daa24a
+
daa24a
+        /* Now, we have to scan for minimal protocol version,
daa24a
+         *without allowing holes between min and max*/
daa24a
+#if SSL_OP_NO_TLSv1_3
daa24a
+        if ((prot == TLS1_3_VERSION) && (protocols & NGX_SSL_TLSv1_2)) {
daa24a
+            prot = TLS1_2_VERSION;
daa24a
+        }
daa24a
+#endif
daa24a
 #ifdef SSL_OP_NO_TLSv1_1
daa24a
-    SSL_CTX_clear_options(ssl->ctx, SSL_OP_NO_TLSv1_1);
daa24a
-    if (!(protocols & NGX_SSL_TLSv1_1)) {
daa24a
-        SSL_CTX_set_options(ssl->ctx, SSL_OP_NO_TLSv1_1);
daa24a
-    }
daa24a
+        if ((prot == TLS1_2_VERSION) && (protocols & NGX_SSL_TLSv1_1)) {
daa24a
+            prot = TLS1_1_VERSION;
daa24a
+        }
daa24a
 #endif
daa24a
 #ifdef SSL_OP_NO_TLSv1_2
daa24a
-    SSL_CTX_clear_options(ssl->ctx, SSL_OP_NO_TLSv1_2);
daa24a
-    if (!(protocols & NGX_SSL_TLSv1_2)) {
daa24a
-        SSL_CTX_set_options(ssl->ctx, SSL_OP_NO_TLSv1_2);
daa24a
-    }
daa24a
+        if ((prot == TLS1_1_VERSION) && (protocols & NGX_SSL_TLSv1)) {
daa24a
+            prot = TLS1_VERSION;
daa24a
+        }
daa24a
 #endif
daa24a
-#ifdef SSL_OP_NO_TLSv1_3
daa24a
-    SSL_CTX_clear_options(ssl->ctx, SSL_OP_NO_TLSv1_3);
daa24a
-    if (!(protocols & NGX_SSL_TLSv1_3)) {
daa24a
-        SSL_CTX_set_options(ssl->ctx, SSL_OP_NO_TLSv1_3);
daa24a
+        SSL_CTX_set_min_proto_version(ssl->ctx, prot);
daa24a
     }
daa24a
-#endif
daa24a
 
daa24a
 #ifdef SSL_OP_NO_COMPRESSION
daa24a
     SSL_CTX_set_options(ssl->ctx, SSL_OP_NO_COMPRESSION);
daa24a
diff --git a/src/event/ngx_event_openssl.h b/src/event/ngx_event_openssl.h
daa24a
index 623d851..6f3d7ee 100644
daa24a
--- a/src/event/ngx_event_openssl.h
daa24a
+++ b/src/event/ngx_event_openssl.h
daa24a
@@ -132,6 +132,7 @@ typedef struct {
daa24a
 #endif
daa24a
 
daa24a
 
daa24a
+#define NGX_SSL_NO_PROT  0x0000
daa24a
 #define NGX_SSL_SSLv2    0x0002
daa24a
 #define NGX_SSL_SSLv3    0x0004
daa24a
 #define NGX_SSL_TLSv1    0x0008
daa24a
diff --git a/src/http/modules/ngx_http_ssl_module.c b/src/http/modules/ngx_http_ssl_module.c
daa24a
index 7d62176..f9ef07d 100644
daa24a
--- a/src/http/modules/ngx_http_ssl_module.c
daa24a
+++ b/src/http/modules/ngx_http_ssl_module.c
daa24a
@@ -590,8 +588,7 @@ ngx_http_ssl_merge_srv_conf(ngx_conf_t *cf, void *parent, void *child)
daa24a
                          prev->prefer_server_ciphers, 0);
daa24a
 
daa24a
     ngx_conf_merge_bitmask_value(conf->protocols, prev->protocols,
daa24a
-                         (NGX_CONF_BITMASK_SET|NGX_SSL_TLSv1
daa24a
-                          |NGX_SSL_TLSv1_1|NGX_SSL_TLSv1_2));
daa24a
+                         0)
daa24a
 
daa24a
     ngx_conf_merge_size_value(conf->buffer_size, prev->buffer_size,
daa24a
                          NGX_SSL_BUFSIZE);
daa24a
diff --git a/src/mail/ngx_mail_ssl_module.c b/src/mail/ngx_mail_ssl_module.c
daa24a
index aebd179..50c7023 100644
daa24a
--- a/src/mail/ngx_mail_ssl_module.c
daa24a
+++ b/src/mail/ngx_mail_ssl_module.c
daa24a
@@ -285,8 +283,7 @@ ngx_mail_ssl_merge_conf(ngx_conf_t *cf, void *parent, void *child)
daa24a
                          prev->prefer_server_ciphers, 0);
daa24a
 
daa24a
     ngx_conf_merge_bitmask_value(conf->protocols, prev->protocols,
daa24a
-                         (NGX_CONF_BITMASK_SET|NGX_SSL_TLSv1
daa24a
-                          |NGX_SSL_TLSv1_1|NGX_SSL_TLSv1_2));
daa24a
+                         0);
daa24a
 
daa24a
     ngx_conf_merge_uint_value(conf->verify, prev->verify, 0);
daa24a
     ngx_conf_merge_uint_value(conf->verify_depth, prev->verify_depth, 1);
daa24a
diff --git a/src/stream/ngx_stream_ssl_module.c b/src/stream/ngx_stream_ssl_module.c
daa24a
index 3e5a1f2..c8fce57 100644
daa24a
--- a/src/stream/ngx_stream_ssl_module.c
daa24a
+++ b/src/stream/ngx_stream_ssl_module.c
daa24a
@@ -554,8 +552,7 @@ ngx_stream_ssl_merge_conf(ngx_conf_t *cf, void *parent, void *child)
daa24a
                          prev->prefer_server_ciphers, 0);
daa24a
 
daa24a
     ngx_conf_merge_bitmask_value(conf->protocols, prev->protocols,
daa24a
-                         (NGX_CONF_BITMASK_SET|NGX_SSL_TLSv1
daa24a
-                          |NGX_SSL_TLSv1_1|NGX_SSL_TLSv1_2));
daa24a
+                         0);
daa24a
 
daa24a
     ngx_conf_merge_uint_value(conf->verify, prev->verify, 0);
daa24a
     ngx_conf_merge_uint_value(conf->verify_depth, prev->verify_depth, 1);