ignatenkobrain / rpms / nginx

Forked from rpms/nginx 2 years ago
Clone
d64139
diff --git a/src/event/ngx_event_openssl.c b/src/event/ngx_event_openssl.c
d64139
index 345914f..d23967f 100644
d64139
--- a/src/event/ngx_event_openssl.c
d64139
+++ b/src/event/ngx_event_openssl.c
d64139
@@ -252,6 +252,8 @@ ngx_ssl_init(ngx_log_t *log)
d64139
 ngx_int_t
d64139
 ngx_ssl_create(ngx_ssl_t *ssl, ngx_uint_t protocols, void *data)
d64139
 {
d64139
+    ngx_uint_t prot = NGX_SSL_NO_PROT;
d64139
+
d64139
     ssl->ctx = SSL_CTX_new(SSLv23_method());
d64139
 
d64139
     if (ssl->ctx == NULL) {
d64139
@@ -316,49 +318,54 @@ ngx_ssl_create(ngx_ssl_t *ssl, ngx_uint_t protocols, void *data)
d64139
 
d64139
     SSL_CTX_set_options(ssl->ctx, SSL_OP_SINGLE_DH_USE);
d64139
 
d64139
-#if OPENSSL_VERSION_NUMBER >= 0x009080dfL
d64139
-    /* only in 0.9.8m+ */
d64139
-    SSL_CTX_clear_options(ssl->ctx,
d64139
-                          SSL_OP_NO_SSLv2|SSL_OP_NO_SSLv3|SSL_OP_NO_TLSv1);
d64139
-#endif
d64139
-
d64139
-    if (!(protocols & NGX_SSL_SSLv2)) {
d64139
-        SSL_CTX_set_options(ssl->ctx, SSL_OP_NO_SSLv2);
d64139
-    }
d64139
-    if (!(protocols & NGX_SSL_SSLv3)) {
d64139
-        SSL_CTX_set_options(ssl->ctx, SSL_OP_NO_SSLv3);
d64139
-    }
d64139
-    if (!(protocols & NGX_SSL_TLSv1)) {
d64139
-        SSL_CTX_set_options(ssl->ctx, SSL_OP_NO_TLSv1);
d64139
-    }
d64139
-#ifdef SSL_OP_NO_TLSv1_1
d64139
-    SSL_CTX_clear_options(ssl->ctx, SSL_OP_NO_TLSv1_1);
d64139
-    if (!(protocols & NGX_SSL_TLSv1_1)) {
d64139
-        SSL_CTX_set_options(ssl->ctx, SSL_OP_NO_TLSv1_1);
d64139
-    }
d64139
+    if (protocols){
d64139
+#ifdef SSL_OP_NO_TLSv1_3
d64139
+        if (protocols & NGX_SSL_TLSv1_3) {
d64139
+            prot = TLS1_3_VERSION;
d64139
+        } else
d64139
 #endif
d64139
 #ifdef SSL_OP_NO_TLSv1_2
d64139
-    SSL_CTX_clear_options(ssl->ctx, SSL_OP_NO_TLSv1_2);
d64139
-    if (!(protocols & NGX_SSL_TLSv1_2)) {
d64139
-        SSL_CTX_set_options(ssl->ctx, SSL_OP_NO_TLSv1_2);
d64139
-    }
d64139
+        if (protocols & NGX_SSL_TLSv1_2) {
d64139
+            prot =  TLS1_2_VERSION;
d64139
+        } else
d64139
 #endif
d64139
-#ifdef SSL_OP_NO_TLSv1_3
d64139
-    SSL_CTX_clear_options(ssl->ctx, SSL_OP_NO_TLSv1_3);
d64139
-    if (!(protocols & NGX_SSL_TLSv1_3)) {
d64139
-        SSL_CTX_set_options(ssl->ctx, SSL_OP_NO_TLSv1_3);
d64139
-    }
d64139
+#ifdef SSL_OP_NO_TLSv1_1
d64139
+        if (protocols & NGX_SSL_TLSv1_1) {
d64139
+            prot = TLS1_1_VERSION;
d64139
+        } else
d64139
 #endif
d64139
+        if (protocols & NGX_SSL_TLSv1) {
d64139
+            prot = TLS1_VERSION;
d64139
+        }
d64139
+
d64139
+        if (prot == NGX_SSL_NO_PROT) {
d64139
+                    ngx_ssl_error(NGX_LOG_EMERG, ssl->log, 0,
d64139
+                      "No SSL protocols available [hint: ssl_protocols]");
d64139
+            return NGX_ERROR;
d64139
+        }
d64139
 
d64139
-#ifdef SSL_CTX_set_min_proto_version
d64139
-    SSL_CTX_set_min_proto_version(ssl->ctx, 0);
d64139
-    SSL_CTX_set_max_proto_version(ssl->ctx, TLS1_2_VERSION);
d64139
+        SSL_CTX_set_max_proto_version(ssl->ctx, prot);
d64139
+
d64139
+        /* Now, we have to scan for minimal protocol version,
d64139
+         *without allowing holes between min and max*/
d64139
+#if SSL_OP_NO_TLSv1_3
d64139
+        if ((prot == TLS1_3_VERSION) && (protocols & NGX_SSL_TLSv1_2)) {
d64139
+            prot = TLS1_2_VERSION;
d64139
+        }
d64139
 #endif
d64139
 
d64139
-#ifdef TLS1_3_VERSION
d64139
-    SSL_CTX_set_min_proto_version(ssl->ctx, 0);
d64139
-    SSL_CTX_set_max_proto_version(ssl->ctx, TLS1_3_VERSION);
d64139
+#ifdef SSL_OP_NO_TLSv1_1
d64139
+        if ((prot == TLS1_2_VERSION) && (protocols & NGX_SSL_TLSv1_1)) {
d64139
+            prot = TLS1_1_VERSION;
d64139
+        }
d64139
+#endif
d64139
+#ifdef SSL_OP_NO_TLSv1_2
d64139
+        if ((prot == TLS1_1_VERSION) && (protocols & NGX_SSL_TLSv1)) {
d64139
+            prot = TLS1_VERSION;
d64139
+        }
d64139
 #endif
d64139
+        SSL_CTX_set_min_proto_version(ssl->ctx, prot);
d64139
+    }
d64139
 
d64139
 #ifdef SSL_OP_NO_COMPRESSION
d64139
     SSL_CTX_set_options(ssl->ctx, SSL_OP_NO_COMPRESSION);
d64139
diff --git a/src/event/ngx_event_openssl.h b/src/event/ngx_event_openssl.h
d64139
index 61da0c5..fa7ac41 100644
d64139
--- a/src/event/ngx_event_openssl.h
d64139
+++ b/src/event/ngx_event_openssl.h
d64139
@@ -145,6 +145,7 @@ typedef struct {
d64139
 #endif
d64139
 
d64139
 
d64139
+#define NGX_SSL_NO_PROT  0x0000
d64139
 #define NGX_SSL_SSLv2    0x0002
d64139
 #define NGX_SSL_SSLv3    0x0004
d64139
 #define NGX_SSL_TLSv1    0x0008
d64139
diff --git a/src/http/modules/ngx_http_ssl_module.c b/src/http/modules/ngx_http_ssl_module.c
d64139
index b3f8f47..8340a12 100644
d64139
--- a/src/http/modules/ngx_http_ssl_module.c
d64139
+++ b/src/http/modules/ngx_http_ssl_module.c
d64139
@@ -613,8 +613,7 @@ ngx_http_ssl_merge_srv_conf(ngx_conf_t *cf, void *parent, void *child)
d64139
     ngx_conf_merge_value(conf->early_data, prev->early_data, 0);
d64139
 
d64139
     ngx_conf_merge_bitmask_value(conf->protocols, prev->protocols,
d64139
-                         (NGX_CONF_BITMASK_SET|NGX_SSL_TLSv1
d64139
-                          |NGX_SSL_TLSv1_1|NGX_SSL_TLSv1_2));
d64139
+                         0)
d64139
 
d64139
     ngx_conf_merge_size_value(conf->buffer_size, prev->buffer_size,
d64139
                          NGX_SSL_BUFSIZE);
d64139
diff --git a/src/mail/ngx_mail_ssl_module.c b/src/mail/ngx_mail_ssl_module.c
d64139
index 5544f75..3316a4b 100644
d64139
--- a/src/mail/ngx_mail_ssl_module.c
d64139
+++ b/src/mail/ngx_mail_ssl_module.c
d64139
@@ -291,8 +291,7 @@ ngx_mail_ssl_merge_conf(ngx_conf_t *cf, void *parent, void *child)
d64139
                          prev->prefer_server_ciphers, 0);
d64139
 
d64139
     ngx_conf_merge_bitmask_value(conf->protocols, prev->protocols,
d64139
-                         (NGX_CONF_BITMASK_SET|NGX_SSL_TLSv1
d64139
-                          |NGX_SSL_TLSv1_1|NGX_SSL_TLSv1_2));
d64139
+                         0);
d64139
 
d64139
     ngx_conf_merge_uint_value(conf->verify, prev->verify, 0);
d64139
     ngx_conf_merge_uint_value(conf->verify_depth, prev->verify_depth, 1);
d64139
diff --git a/src/stream/ngx_stream_ssl_module.c b/src/stream/ngx_stream_ssl_module.c
d64139
index ec9524e..37af046 100644
d64139
--- a/src/stream/ngx_stream_ssl_module.c
d64139
+++ b/src/stream/ngx_stream_ssl_module.c
d64139
@@ -625,8 +625,7 @@ ngx_stream_ssl_merge_conf(ngx_conf_t *cf, void *parent, void *child)
d64139
                          prev->prefer_server_ciphers, 0);
d64139
 
d64139
     ngx_conf_merge_bitmask_value(conf->protocols, prev->protocols,
d64139
-                         (NGX_CONF_BITMASK_SET|NGX_SSL_TLSv1
d64139
-                          |NGX_SSL_TLSv1_1|NGX_SSL_TLSv1_2));
d64139
+                         0);
d64139
 
d64139
     ngx_conf_merge_uint_value(conf->verify, prev->verify, 0);
d64139
     ngx_conf_merge_uint_value(conf->verify_depth, prev->verify_depth, 1);