Browse Source

add basic ConnectionID DTLS tests

Marco Oliverio 1 year ago
parent
commit
f3262005e4
6 changed files with 141 additions and 0 deletions
  1. 39 0
      scripts/dtlscid.test
  2. 1 0
      scripts/include.am
  3. 1 0
      tests/include.am
  4. 11 0
      tests/suites.c
  5. 80 0
      tests/test-dtls13-cid.conf
  6. 9 0
      wolfssl/test.h

+ 39 - 0
scripts/dtlscid.test

@@ -0,0 +1,39 @@
+#!/bin/bash
+
+set -e
+
+cleanup () {
+    echo "Cleaning up..."
+    if [ ! -z "$SERVER_PID" ];then
+        echo "Killing server $SERVER_PID"
+        kill $SERVER_PID
+    fi
+}
+
+trap cleanup err exit
+
+CCID="AA"
+SCID="BB"
+HEXCID=$(printf $CCID | od -An -tx1 | tr -d ' \n')
+HEXSCID=$(printf $SCID | od -An -tx1 | tr -d ' \n')
+WOLFSSL_ROOT=$(pwd)
+SERVER_PORT=11111
+
+(killall lt-server || true)
+(killall lt-client || true)
+
+test_cid () {
+    $WOLFSSL_ROOT/examples/server/server -v4 -u --cid $SCID 2>/tmp/serr 1>/tmp/sout &
+    SERVER_PID=$!
+    sleep 0.2
+    now=$(date +%s.%N)
+    $WOLFSSL_ROOT/examples/client/client -v4 -u --cid $CCID 2>/tmp/cerr 1>/tmp/cout
+    elapsed=$(echo $(date +%s.%N) - $now | bc)
+    echo "it took ${elapsed} sec(s)" >> /tmp/udp
+    wait $SERVER_PID
+    SERVER_PID=
+    grep "Sending CID is ${HEXSCID}" < /tmp/cout
+    grep "Sending CID is ${HEXCID}" < /tmp/sout
+}
+
+test_cid

+ 1 - 0
scripts/include.am

@@ -116,4 +116,5 @@ EXTRA_DIST += scripts/cleanup_testfiles.sh
 
 if BUILD_DTLS13
 EXTRA_DIST += scripts/dtls13.test
+EXTRA_DIST += scripts/dtlscid.test
 endif

+ 1 - 0
tests/include.am

@@ -45,6 +45,7 @@ EXTRA_DIST += tests/unit.h \
               tests/test-dtls13.conf \
               tests/test-dtls13-downgrade.conf \
               tests/test-dtls13-psk.conf \
+              tests/test-dtls13-cid.conf \
               tests/test-sctp.conf \
               tests/test-sctp-sha2.conf \
               tests/test-sig.conf \

+ 11 - 0
tests/suites.c

@@ -1153,6 +1153,17 @@ int SuiteTest(int argc, char** argv)
     }
 #endif /* NO_PSK */
 
+#ifdef WOLFSSL_DTLS_CID
+    XSTRLCPY(argv0[1], "tests/test-dtls13-cid.conf", sizeof(argv0[1]));
+    printf("starting DTLS 1.3 ConnectionID suite tests\n");
+    test_harness(&args);
+    if (args.return_code != 0) {
+        printf("error from script %d\n", args.return_code);
+        args.return_code = EXIT_FAILURE;
+        goto exit;
+    }
+#endif /* WOLFSSL_DTLS_CID */
+
 #endif /* WOLFSSL_DTLS13 */
 
 #endif

+ 80 - 0
tests/test-dtls13-cid.conf

@@ -0,0 +1,80 @@
+# server DTLSv1.3 empty CID
+-v 4
+-u
+-l TLS_AES_128_GCM_SHA256
+--cid
+
+# client DTLSv1.3 empty CID
+-v 4
+-u
+-l TLS_AES_128_GCM_SHA256
+--cid
+
+# server DTLSv1.3 A CID
+-v 4
+-u
+-l TLS_AES_128_GCM_SHA256
+--cid AA
+
+# client DTLSv1.3 empty CID
+-v 4
+-u
+-l TLS_AES_128_GCM_SHA256
+--cid
+
+# server DTLSv1.3 Empty CID
+-v 4
+-u
+-l TLS_AES_128_GCM_SHA256
+--cid
+
+# client DTLSv1.3 B CID
+-v 4
+-u
+-l TLS_AES_128_GCM_SHA256
+--cid BB
+
+# server DTLSv1.3 A CID
+-v 4
+-u
+-l TLS_AES_128_GCM_SHA256
+--cid AA
+
+# client DTLSv1.3 B CID
+-v 4
+-u
+-l TLS_AES_128_GCM_SHA256
+--cid BB
+
+# server DTLSv1.3 No CID support
+-v 4
+-u
+-l TLS_AES_128_GCM_SHA256
+
+# client DTLSv1.3 B CID
+-v 4
+-u
+-l TLS_AES_128_GCM_SHA256
+--cid B
+
+# server DTLSv1.3 CID A
+-v 4
+-u
+-l TLS_AES_128_GCM_SHA256
+
+# client DTLSv1.3 No CID support
+-v 4
+-u
+-l TLS_AES_128_GCM_SHA256
+
+# server DTLSv1.3 CID 2 bytes
+-v 4
+-u
+-l TLS_AES_128_GCM_SHA256
+--cid AA
+
+# client DTLSv1.3 CID 1 byte
+-v 4
+-u
+-l TLS_AES_128_GCM_SHA256
+--cid B

+ 9 - 0
wolfssl/test.h

@@ -5445,10 +5445,19 @@ static WC_INLINE int process_handshake_messages(WOLFSSL* ssl, int blocking,
 }
 #endif /* HAVE_SESSION_TICKET || WOLFSSL_DTLS13 */
 
+static WC_INLINE void printBuffer(const byte *buf, int size)
+{
+    int i;
+    for (i = 0; i < size; i++)
+        printf("%x", buf[i]);
+}
+
 #if !defined(NO_FILESYSTEM) && defined(OPENSSL_EXTRA) && \
     defined(DEBUG_UNIT_TEST_CERTS)
 void DEBUG_WRITE_CERT_X509(WOLFSSL_X509* x509, const char* fileName);
 void DEBUG_WRITE_DER(const byte* der, int derSz, const char* fileName);
 #endif
 
+#define DTLS_CID_BUFFER_SIZE 256
+
 #endif /* wolfSSL_TEST_H */