[openssl-commits] [openssl] master update

Matt Caswell matt at openssl.org
Thu Mar 30 14:50:04 UTC 2017


The branch master has been updated
       via  9b5c865df0626d85065eacff714f20e2c721ca56 (commit)
       via  116d0da5e8bcbb79ac1bdd1ec6bb861d9830e3a5 (commit)
      from  1c7ae3dd9e04d6af40d162f10c607f90da48a6fc (commit)


- Log -----------------------------------------------------------------
commit 9b5c865df0626d85065eacff714f20e2c721ca56
Author: Matt Caswell <matt at openssl.org>
Date:   Thu Mar 30 15:26:23 2017 +0100

    Provide a test for pause between EoED and CF
    
    This tests the bug fixed in the previous commit. We introduce a synthetic
    delay between the server receiving EoED and CF and check that we can still
    send early data.
    
    Reviewed-by: Rich Salz <rsalz at openssl.org>
    (Merged from https://github.com/openssl/openssl/pull/3089)

commit 116d0da5e8bcbb79ac1bdd1ec6bb861d9830e3a5
Author: Matt Caswell <matt at openssl.org>
Date:   Thu Mar 30 15:24:07 2017 +0100

    Fix early data bug with pause between EoED and CF
    
    If the server received EoED then SSL_read_early_data() will return
    SSL_READ_EARLY_DATA_FINISH. However if the CF has not yet been processed
    then SSL_is_init_finished() will still return 0. Therefore we should still
    be able to write early data.
    
    Fixes #3041
    
    Reviewed-by: Rich Salz <rsalz at openssl.org>
    (Merged from https://github.com/openssl/openssl/pull/3089)

-----------------------------------------------------------------------

Summary of changes:
 ssl/ssl_lib.c     |  1 +
 test/sslapitest.c | 60 +++++++++++++++++++++++++++++++++++++++++++++++++------
 2 files changed, 55 insertions(+), 6 deletions(-)

diff --git a/ssl/ssl_lib.c b/ssl/ssl_lib.c
index f169611..a76ee40 100644
--- a/ssl/ssl_lib.c
+++ b/ssl/ssl_lib.c
@@ -1829,6 +1829,7 @@ int SSL_write_early_data(SSL *s, const void *buf, size_t num, size_t *written)
         s->early_data_state = SSL_EARLY_DATA_WRITE_RETRY;
         return ret;
 
+    case SSL_EARLY_DATA_FINISHED_READING:
     case SSL_EARLY_DATA_READ_RETRY:
         /* We are a server writing to an unauthenticated client */
         s->early_data_state = SSL_EARLY_DATA_UNAUTH_WRITING;
diff --git a/test/sslapitest.c b/test/sslapitest.c
index b4e99e8..ab1d6ff 100644
--- a/test/sslapitest.c
+++ b/test/sslapitest.c
@@ -1603,8 +1603,9 @@ static int test_early_data_read_write(int idx)
     SSL *clientssl = NULL, *serverssl = NULL;
     int testresult = 0;
     SSL_SESSION *sess = NULL;
-    unsigned char buf[20];
-    size_t readbytes, written;
+    unsigned char buf[20], data[1024];
+    size_t readbytes, written, eoedlen, rawread, rawwritten;
+    BIO *rbio;
 
     if (!setupearly_data_test(&cctx, &sctx, &clientssl, &serverssl, &sess, idx))
         goto end;
@@ -1691,6 +1692,27 @@ static int test_early_data_read_write(int idx)
         goto end;
     }
 
+    /*
+     * At this point the client has written EndOfEarlyData, ClientFinished and
+     * normal (fully protected) data. We are going to cause a delay between the
+     * arrival of EndOfEarlyData and ClientFinished. We read out all the data
+     * in the read BIO, and then just put back the EndOfEarlyData message.
+     */
+    rbio = SSL_get_rbio(serverssl);
+    if (!BIO_read_ex(rbio, data, sizeof(data), &rawread)
+            || rawread >= sizeof(data)
+            || rawread < SSL3_RT_HEADER_LENGTH) {
+        printf("Failed reading data from rbio\n");
+        goto end;
+    }
+    /* Record length is in the 4th and 5th bytes of the record header */
+    eoedlen = SSL3_RT_HEADER_LENGTH + (data[3] << 8 | data[4]);
+    if (!BIO_write_ex(rbio, data, eoedlen, &rawwritten)
+            || rawwritten != eoedlen) {
+        printf("Failed to write the EndOfEarlyData message to server rbio\n");
+        goto end;
+    }
+
     /* Server should be told that there is no more early data */
     if (SSL_read_early_data(serverssl, buf, sizeof(buf), &readbytes)
                 != SSL_READ_EARLY_DATA_FINISH
@@ -1699,6 +1721,23 @@ static int test_early_data_read_write(int idx)
         goto end;
     }
 
+    /* Push the ClientFinished and the normal data back into the server rbio */
+    if (!BIO_write_ex(rbio, data + eoedlen, rawread - eoedlen, &rawwritten)
+            || rawwritten != rawread - eoedlen) {
+        printf("Failed to write the ClientFinished and data to server rbio\n");
+        goto end;
+    }
+
+    /*
+     * Server has not finished init yet, so should still be able to write early
+     * data.
+     */
+    if (!SSL_write_early_data(serverssl, MSG6, strlen(MSG6), &written)
+            || written != strlen(MSG6)) {
+        printf("Failed writing early data message 6\n");
+        goto end;
+    }
+
     /* Server should be able to read normal data */
     if (!SSL_read_ex(serverssl, buf, sizeof(buf), &readbytes)
             || readbytes != strlen(MSG5)) {
@@ -1721,14 +1760,23 @@ static int test_early_data_read_write(int idx)
     ERR_clear_error();
 
     /*
-     * Make sure we process the NewSessionTicket. This arrives post-handshake
-     * so we must make sure we attempt a read - even though we don't expect to
-     * actually get any application data.
+     * Make sure we process the NewSessionTicket. This arrives post-handshake.
+     * We attempt a read which we do not expect to return any data.  Doesn't
+     * apply when read_ahead is in use - the ticket will get processed along
+     * with the application data in the second read below.
      */
-    if (SSL_read_ex(clientssl, buf, sizeof(buf), &readbytes)) {
+    if (idx == 0 && SSL_read_ex(clientssl, buf, sizeof(buf), &readbytes)) {
         printf("Unexpected success doing final client read\n");
         goto end;
     }
+    /* Client should be able to read the data sent by the server */
+    if (!SSL_read_ex(clientssl, buf, sizeof(buf), &readbytes)
+            || readbytes != strlen(MSG6)
+            || memcmp(MSG6, buf, strlen(MSG6))) {
+        printf("Failed reading message 6\n");
+        goto end;
+    }
+
 
     SSL_SESSION_free(sess);
     sess = SSL_get1_session(clientssl);


More information about the openssl-commits mailing list