]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
Move need_empty_fragments inside the record layer
authorMatt Caswell <matt@openssl.org>
Tue, 30 Aug 2022 15:26:33 +0000 (16:26 +0100)
committerMatt Caswell <matt@openssl.org>
Fri, 23 Sep 2022 13:54:49 +0000 (14:54 +0100)
This flag can now be managed entirely by the new record layer code so we
move it into ossl_record_layer_st.

Reviewed-by: Hugo Landau <hlandau@openssl.org>
Reviewed-by: Richard Levitte <levitte@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/19198)

ssl/record/methods/recmethod_local.h
ssl/record/methods/tls_common.c
ssl/s3_enc.c
ssl/ssl_local.h
ssl/t1_enc.c

index 289f2e83330dd6b5d9949f85869d5c816dc2a907..294bec3e0865e82df45274c1700e30ae704c3b66 100644 (file)
@@ -139,6 +139,13 @@ struct ossl_record_layer_st
     /* The number of consecutive empty records we have received */
     size_t empty_record_count;
 
+    /*
+     * Do we need to send a prefix empty record before application data as a
+     * countermeasure against known-IV weakness (necessary for SSLv3 and
+     * TLSv1.0)
+     */
+    int need_empty_fragments;
+
     /* cryptographic state */
     EVP_CIPHER_CTX *enc_ctx;
 
index 0f094abf7ffebcbbf9291a31a7be93bda4eb950c..2c480c0815e7f42ec4a74b3f453c0859d03257d7 100644 (file)
@@ -1238,6 +1238,17 @@ tls_int_new_record_layer(OSSL_LIB_CTX *libctx, const char *propq, int vers,
         goto err;
     }
 
+    if ((rl->options & SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS) == 0
+            && rl->version <= TLS1_VERSION
+            && !EVP_CIPHER_is_a(ciph, "NULL")
+            && !EVP_CIPHER_is_a(ciph, "RC4")) {
+        /*
+         * Enable vulnerability countermeasure for CBC ciphers with known-IV
+         * problem (http://www.openssl.org/~bodo/tls-cbc.txt)
+         */
+        rl->need_empty_fragments = 1;
+    }
+
     *retrl = rl;
     return OSSL_RECORD_RETURN_SUCCESS;
  err:
@@ -1440,7 +1451,7 @@ int tls_write_records(OSSL_RECORD_LAYER *rl, OSSL_RECORD_TEMPLATE *templates,
      * ourselves.
      * Do we need to do that recursion in order to add an empty record prefix?
      */
-    prefix = s->s3.need_empty_fragments
+    prefix = rl->need_empty_fragments
              && !clear
              && templates[0].type == SSL3_RT_APPLICATION_DATA;
 
index a1b91a0acb780a037a571b2844888214a6798527..e778a2a8607aee79d1f99c25267c466837ec0ee3 100644 (file)
@@ -259,22 +259,6 @@ int ssl3_setup_key_block(SSL_CONNECTION *s)
     /* Calls SSLfatal() as required */
     ret = ssl3_generate_key_block(s, p, num);
 
-    if (!(s->options & SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS)) {
-        /*
-         * enable vulnerability countermeasure for CBC ciphers with known-IV
-         * problem (http://www.openssl.org/~bodo/tls-cbc.txt)
-         */
-        s->s3.need_empty_fragments = 1;
-
-        if (s->session->cipher != NULL) {
-            if (s->session->cipher->algorithm_enc == SSL_eNULL)
-                s->s3.need_empty_fragments = 0;
-
-            if (s->session->cipher->algorithm_enc == SSL_RC4)
-                s->s3.need_empty_fragments = 0;
-        }
-    }
-
     return ret;
 }
 
index c8e8d9f4475f6e3e145152107818587e6c637cee..61b77602bac53d7f6e56ea29f4acf320f6b3c471 100644 (file)
@@ -1296,8 +1296,7 @@ struct ssl_connection_st {
         unsigned char write_mac_secret[EVP_MAX_MD_SIZE];
         unsigned char server_random[SSL3_RANDOM_SIZE];
         unsigned char client_random[SSL3_RANDOM_SIZE];
-        /* flags for countermeasure against known-IV weakness */
-        int need_empty_fragments;
+
         /* used during startup, digest all incoming/outgoing packets */
         BIO *handshake_buffer;
         /*
index 2ef0da41b58afac860d85bb29640824361a43786..88249c7951d05eca4c41bb969afdc21df2ab1e92 100644 (file)
@@ -523,23 +523,6 @@ int tls1_setup_key_block(SSL_CONNECTION *s)
         BIO_dump_indent(trc_out, p, num, 4);
     } OSSL_TRACE_END(TLS);
 
-    if (!(s->options & SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS)
-        && SSL_CONNECTION_GET_SSL(s)->method->version <= TLS1_VERSION) {
-        /*
-         * enable vulnerability countermeasure for CBC ciphers with known-IV
-         * problem (http://www.openssl.org/~bodo/tls-cbc.txt)
-         */
-        s->s3.need_empty_fragments = 1;
-
-        if (s->session->cipher != NULL) {
-            if (s->session->cipher->algorithm_enc == SSL_eNULL)
-                s->s3.need_empty_fragments = 0;
-
-            if (s->session->cipher->algorithm_enc == SSL_RC4)
-                s->s3.need_empty_fragments = 0;
-        }
-    }
-
     ret = 1;
  err:
     return ret;