[openssl-commits] [openssl] master update

Matt Caswell matt at openssl.org
Wed Aug 10 11:53:59 UTC 2016


The branch master has been updated
       via  eb633d03fe2db3666840dee8d0a2dbe491672dfc (commit)
       via  c14e790d6c46907ad0974f0ba7f640aafb2bdedf (commit)
      from  eea8723cd0d56398fc40d0337e9e730961c9c2fa (commit)


- Log -----------------------------------------------------------------
commit eb633d03fe2db3666840dee8d0a2dbe491672dfc
Author: David Woodhouse <David.Woodhouse at intel.com>
Date:   Sat Aug 6 11:25:46 2016 +0100

    Kill PACKET_starts() from bad_dtls_test
    
    As discussed in PR#1409 it can be done differently.
    
    Reviewed-by: Rich Salz <rsalz at openssl.org>
    Reviewed-by: Matt Caswell <matt at openssl.org>

commit c14e790d6c46907ad0974f0ba7f640aafb2bdedf
Author: David Woodhouse <David.Woodhouse at intel.com>
Date:   Fri Aug 5 14:58:32 2016 +0100

    Fix clienthellotest to use PACKET functions
    
    Reviewed-by: Rich Salz <rsalz at openssl.org>
    Reviewed-by: Matt Caswell <matt at openssl.org>

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

Summary of changes:
 test/bad_dtls_test.c   | 28 +++++------------------
 test/clienthellotest.c | 60 ++++++++++++++++++++------------------------------
 2 files changed, 30 insertions(+), 58 deletions(-)

diff --git a/test/bad_dtls_test.c b/test/bad_dtls_test.c
index 9c478f4..4ee155f 100644
--- a/test/bad_dtls_test.c
+++ b/test/bad_dtls_test.c
@@ -111,25 +111,10 @@ static SSL_SESSION *client_session(void)
     return d2i_SSL_SESSION(NULL, &p, sizeof(session_asn1));
 }
 
-/* PACKET_equal() doesn't quite do what we need. Provide a version that
- * does, in a form that can easily be moved to ssl_locl.h if anyone else
- * cares to come up with a better name and use it too... */
-__owur static ossl_inline int PACKET_starts(PACKET *pkt, const void *ptr,
-                                            size_t num)
-{
-    if (PACKET_remaining(pkt) < num)
-        return 0;
-    if (CRYPTO_memcmp(pkt->curr, ptr, num) != 0)
-        return 0;
-
-    packet_forward(pkt, num);
-    return 1;
-}
-
 /* Returns 1 for initial ClientHello, 2 for ClientHello with cookie */
 static int validate_client_hello(BIO *wbio)
 {
-    PACKET pkt;
+    PACKET pkt, pkt2;
     long len;
     unsigned char *data;
     int cookie_found = 0;
@@ -165,16 +150,15 @@ static int validate_client_hello(BIO *wbio)
         return 0;
 
     /* Check session id length and content */
-    if (!PACKET_get_1(&pkt, &u))
-        return 0;
-    if (u != sizeof(session_id) || !PACKET_starts(&pkt, session_id, u))
+    if (!PACKET_get_length_prefixed_1(&pkt, &pkt2) ||
+        !PACKET_equal(&pkt2, session_id, sizeof(session_id)))
         return 0;
 
     /* Check cookie */
-    if (!PACKET_get_1(&pkt, &u))
+    if (!PACKET_get_length_prefixed_1(&pkt, &pkt2))
         return 0;
-    if (u) {
-        if (u != sizeof(cookie) || !PACKET_starts(&pkt, cookie, u))
+    if (PACKET_remaining(&pkt2)) {
+        if (!PACKET_equal(&pkt2, cookie, sizeof(cookie)))
             return 0;
         cookie_found = 1;
     }
diff --git a/test/clienthellotest.c b/test/clienthellotest.c
index 1f1d44c..b8157f2 100644
--- a/test/clienthellotest.c
+++ b/test/clienthellotest.c
@@ -16,14 +16,9 @@
 #include <openssl/ssl.h>
 #include <openssl/err.h>
 
+#include "../ssl/packet_locl.h"
 
 #define CLIENT_VERSION_LEN      2
-#define SESSION_ID_LEN_LEN      1
-#define CIPHERS_LEN_LEN         2
-#define COMPRESSION_LEN_LEN     1
-#define EXTENSIONS_LEN_LEN      2
-#define EXTENSION_TYPE_LEN      2
-#define EXTENSION_SIZE_LEN      2
 
 
 #define TOTAL_NUM_TESTS                         1
@@ -43,11 +38,9 @@ int main(int argc, char *argv[])
     BIO *err;
     long len;
     unsigned char *data;
-    unsigned char *dataend;
+    PACKET pkt, pkt2, pkt3;
     char *dummytick = "Hello World!";
-    unsigned int tmplen;
     unsigned int type;
-    unsigned int size;
     int testresult = 0;
     int currtest = 0;
 
@@ -81,50 +74,47 @@ int main(int argc, char *argv[])
         }
 
         len = BIO_get_mem_data(wbio, (char **)&data);
-        dataend = data + len;
+        if (!PACKET_buf_init(&pkt, data, len))
+            goto end;
 
         /* Skip the record header */
-        data += SSL3_RT_HEADER_LENGTH;
+        if (!PACKET_forward(&pkt, SSL3_RT_HEADER_LENGTH))
+            goto end;
+
         /* Skip the handshake message header */
-        data += SSL3_HM_HEADER_LENGTH;
+        if (!PACKET_forward(&pkt, SSL3_HM_HEADER_LENGTH))
+            goto end;
+
         /* Skip client version and random */
-        data += CLIENT_VERSION_LEN + SSL3_RANDOM_SIZE;
-        if (data + SESSION_ID_LEN_LEN > dataend)
+        if (!PACKET_forward(&pkt, CLIENT_VERSION_LEN + SSL3_RANDOM_SIZE))
             goto end;
+
         /* Skip session id */
-        tmplen = *data;
-        data += SESSION_ID_LEN_LEN + tmplen;
-        if (data + CIPHERS_LEN_LEN > dataend)
+        if (!PACKET_get_length_prefixed_1(&pkt, &pkt2))
             goto end;
+
         /* Skip ciphers */
-        tmplen = ((*data) << 8) | *(data + 1);
-        data += CIPHERS_LEN_LEN + tmplen;
-        if (data + COMPRESSION_LEN_LEN > dataend)
+        if (!PACKET_get_length_prefixed_2(&pkt, &pkt2))
             goto end;
+
         /* Skip compression */
-        tmplen = *data;
-        data += COMPRESSION_LEN_LEN + tmplen;
-        if (data + EXTENSIONS_LEN_LEN > dataend)
+        if (!PACKET_get_length_prefixed_1(&pkt, &pkt2))
             goto end;
+
         /* Extensions len */
-        tmplen = ((*data) << 8) | *(data + 1);
-        data += EXTENSIONS_LEN_LEN;
-        if (data + tmplen > dataend)
+        if (!PACKET_as_length_prefixed_2(&pkt, &pkt2))
             goto end;
 
         /* Loop through all extensions */
-        while (tmplen > EXTENSION_TYPE_LEN + EXTENSION_SIZE_LEN) {
-            type = ((*data) << 8) | *(data + 1);
-            data += EXTENSION_TYPE_LEN;
-            size = ((*data) << 8) | *(data + 1);
-            data += EXTENSION_SIZE_LEN;
-            if (data + size > dataend)
+        while (PACKET_remaining(&pkt2)) {
+
+            if (!PACKET_get_net_2(&pkt2, &type) ||
+                !PACKET_get_length_prefixed_2(&pkt2, &pkt3))
                 goto end;
 
             if (type == TLSEXT_TYPE_session_ticket) {
                 if (currtest == TEST_SET_SESSION_TICK_DATA_VER_NEG) {
-                    if (size == strlen(dummytick)
-                            && memcmp(data, dummytick, size) == 0) {
+                    if (PACKET_equal(&pkt3, dummytick, strlen(dummytick))) {
                         /* Ticket data is as we expected */
                         testresult = 1;
                     } else {
@@ -134,8 +124,6 @@ int main(int argc, char *argv[])
                 }
             }
 
-            tmplen -= EXTENSION_TYPE_LEN + EXTENSION_SIZE_LEN + size;
-            data += size;
         }
 
  end:


More information about the openssl-commits mailing list