]> git.ipfire.org Git - thirdparty/gnutls.git/commitdiff
fuzz: introduced psk.h common header
authorNikos Mavrogiannopoulos <nmav@gnutls.org>
Sun, 30 Jul 2017 01:01:08 +0000 (03:01 +0200)
committerNikos Mavrogiannopoulos <nmav@gnutls.org>
Thu, 3 Aug 2017 05:55:06 +0000 (07:55 +0200)
Signed-off-by: Nikos Mavrogiannopoulos <nmav@gnutls.org>
devel/fuzz/gnutls_psk_client_fuzzer.cc
devel/fuzz/gnutls_psk_server_fuzzer.cc
devel/fuzz/psk.h [new file with mode: 0644]

index 9d8e2ef10a54a97d4bb2f5cb10657b3b9aa98195..35b85f64c57babbf08e303f3fd9d695b9e631f75 100644 (file)
@@ -31,6 +31,8 @@
 
 #include <gnutls/gnutls.h>
 
+#include "psk.h"
+
 struct mem_st {
        const uint8_t *data;
        size_t size;
@@ -79,10 +81,10 @@ int LLVMFuzzerTestOneInput(const uint8_t * data, size_t size)
        gnutls_session_t session;
        gnutls_psk_client_credentials_t pcred;
        struct mem_st memdata;
-       gnutls_datum_t pskkey;
+       gnutls_datum_t psk_key;
 
-       pskkey.data = (unsigned char*)"\x8a\x77\x59\xb3\xf2\x69\x83\xc4\x53\xe4\x48\x06\x0b\xde\x89\x81";
-       pskkey.size = 16;
+       psk_key.data = (unsigned char*)psk_key16;
+       psk_key.size = 16;
 
        res = gnutls_init(&session, GNUTLS_CLIENT);
        assert(res >= 0);
@@ -90,7 +92,7 @@ int LLVMFuzzerTestOneInput(const uint8_t * data, size_t size)
        res = gnutls_psk_allocate_client_credentials(&pcred);
        assert(res >= 0);
 
-       res = gnutls_psk_set_client_credentials(pcred, "test", &pskkey, GNUTLS_PSK_KEY_RAW);
+       res = gnutls_psk_set_client_credentials(pcred, "test", &psk_key, GNUTLS_PSK_KEY_RAW);
        assert(res >= 0);
 
        res = gnutls_credentials_set(session, GNUTLS_CRD_PSK, pcred);
index a9708261afae7c75d551a8c589dba02f146ec5cd..60b8a94710514351751ed2479494539224df3a16 100644 (file)
@@ -30,6 +30,7 @@
 #include <gnutls/gnutls.h>
 
 #include "certs.h"
+#include "psk.h"
 
 struct mem_st {
        const uint8_t *data;
@@ -77,9 +78,7 @@ psk_cb(gnutls_session_t session, const char *username,
        key->data = (unsigned char*)gnutls_malloc(16);
        assert(key->data != NULL);
 
-       memcpy(key->data,
-              "\x8a\x77\x59\xb3\xf2\x69\x83\xc4\x53\xe4\x48\x06\x0b\xde\x89\x81",
-              16);
+       memcpy(key->data, psk_key16, 16);
        key->size = 16;
 
        return 0;
diff --git a/devel/fuzz/psk.h b/devel/fuzz/psk.h
new file mode 100644 (file)
index 0000000..fe4a8af
--- /dev/null
@@ -0,0 +1,32 @@
+/*
+ * Copyright (C) 2017 Nikos Mavrogiannopoulos
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ */
+
+#ifndef PSK_H
+# define PSK_H
+
+static const uint8_t psk_key16[] = {
+       0x8a, 0x77, 0x59, 0xb3, 0xf2, 0x69, 0x83, 0xc4,
+       0x53, 0xe4, 0x48, 0x06, 0x0b, 0xde, 0x89, 0x81
+};
+
+#endif