summaryrefslogtreecommitdiff
path: root/fuzz
diff options
context:
space:
mode:
authorTom Vrancken <dev@tomvrancken.nl>2019-09-01 13:49:40 +0200
committerTom Vrancken <dev@tomvrancken.nl>2019-09-02 20:39:04 +0200
commitb1da7d4aa9ab8b821101287c3587bad70ffe77b5 (patch)
tree560b57668db864d4c870a7e266504b647922c593 /fuzz
parent28c5912c0445ab66ed4229e05bc7ed64f5fbcba3 (diff)
downloadgnutls-b1da7d4aa9ab8b821101287c3587bad70ffe77b5.tar.gz
Implemented client rawpk fuzzer.
Signed-off-by: Tom Vrancken <dev@tomvrancken.nl>
Diffstat (limited to 'fuzz')
-rw-r--r--fuzz/Makefile.am2
-rw-r--r--fuzz/certs.h65
-rw-r--r--fuzz/gnutls_client_rawpk_fuzzer.c108
3 files changed, 175 insertions, 0 deletions
diff --git a/fuzz/Makefile.am b/fuzz/Makefile.am
index 32d64d6abc..5e32b0009f 100644
--- a/fuzz/Makefile.am
+++ b/fuzz/Makefile.am
@@ -13,6 +13,7 @@ FUZZERS = \
gnutls_base64_decoder_fuzzer$(EXEEXT) \
gnutls_base64_encoder_fuzzer$(EXEEXT) \
gnutls_client_fuzzer$(EXEEXT) \
+ gnutls_client_rawpk_fuzzer$(EXEEXT) \
gnutls_dn_parser_fuzzer$(EXEEXT) \
gnutls_idna_parser_fuzzer$(EXEEXT) \
gnutls_ocsp_req_parser_fuzzer$(EXEEXT) \
@@ -36,6 +37,7 @@ gnutls_x509_verify_fuzzer_SOURCES = gnutls_x509_verify_fuzzer.c main.c fuzzer.h
gnutls_base64_decoder_fuzzer_SOURCES = gnutls_base64_decoder_fuzzer.c main.c fuzzer.h
gnutls_base64_encoder_fuzzer_SOURCES = gnutls_base64_encoder_fuzzer.c main.c fuzzer.h
gnutls_client_fuzzer_SOURCES = gnutls_client_fuzzer.c main.c fuzzer.h mem.h certs.h
+gnutls_client_rawpk_fuzzer_SOURCES = gnutls_client_rawpk_fuzzer.c main.c fuzzer.h mem.h certs.h
gnutls_dn_parser_fuzzer_SOURCES = gnutls_dn_parser_fuzzer.c main.c fuzzer.h
gnutls_idna_parser_fuzzer_SOURCES = gnutls_idna_parser_fuzzer.c main.c fuzzer.h
gnutls_ocsp_req_parser_fuzzer_SOURCES = gnutls_ocsp_req_parser_fuzzer.c main.c fuzzer.h
diff --git a/fuzz/certs.h b/fuzz/certs.h
index 6843714fe0..c95f63b5dd 100644
--- a/fuzz/certs.h
+++ b/fuzz/certs.h
@@ -300,4 +300,69 @@ static const uint8_t kEd25519PrivateKeyDER[] = {
0xe5, 0xb4, 0x5f, 0x9b, 0xd7, 0xa6, 0xf8, 0x36, 0x0c, 0x92, 0x59, 0x70
};
+/* Raw public-key key material for testing */
+static char rawpk_public_key_pem1[] =
+ "-----BEGIN PUBLIC KEY-----\n"
+ "MIIBojANBgkqhkiG9w0BAQEFAAOCAY8AMIIBigKCAYEAyAeBq7Ti7oVExeVT1PqH\n"
+ "GBXzC+johdeVnZgZRLhDTIaIGODV5F5JhE4NNb1O/DYLlAy5IIO8tfAE2KIxlarN\n"
+ "H/+AcfV6ZJQSG4SSmhoIGzfdcdjuBmFfdfhO+z/cgqiewh53/fFCQlaJweHhpmim\n"
+ "/LVL/M/1Rd6Urskv/5jXGG4FVUNfhXKQag0uzWsqcztCPX7Lrqr2BSOmkA1nWzdo\n"
+ "h5oBuxdooaH9/kwphqJAp03LwtaSStX/yz6Mh+ZqEbBuM4mWw/xKzbEbs7zA+d8s\n"
+ "ryHXkC8nsdA+h+IRd8bPa/KuWQNfjxXKNPzgmsZddHmHtYtWvAcoIMvtyO23Y2Nh\n"
+ "N4V0/7fwFLbZtfUBg4pqUl2ktkdwsNguTT1qzJCsYhsHXaqqvHy+5HR2D0w07y2X\n"
+ "1qCVmfHzBZCM5OhxoeoauE+xu+5nvYrgsgPE0y5Nty0y2MrApg3digaiKUXrI+mE\n"
+ "VKn9vsQeaVvw9D6PgNQM99HkbGhRMGPOzcHjS/ZeLd1zAgMBAAE=\n"
+ "-----END PUBLIC KEY-----";
+
+const gnutls_datum_t rawpk_public_key1 = {
+ (unsigned char*)rawpk_public_key_pem1,
+ sizeof(rawpk_public_key_pem1) - 1
+};
+
+static char rawpk_private_key_pem1[] =
+ "-----BEGIN RSA PRIVATE KEY-----\n"
+ "MIIG4wIBAAKCAYEAyAeBq7Ti7oVExeVT1PqHGBXzC+johdeVnZgZRLhDTIaIGODV\n"
+ "5F5JhE4NNb1O/DYLlAy5IIO8tfAE2KIxlarNH/+AcfV6ZJQSG4SSmhoIGzfdcdju\n"
+ "BmFfdfhO+z/cgqiewh53/fFCQlaJweHhpmim/LVL/M/1Rd6Urskv/5jXGG4FVUNf\n"
+ "hXKQag0uzWsqcztCPX7Lrqr2BSOmkA1nWzdoh5oBuxdooaH9/kwphqJAp03LwtaS\n"
+ "StX/yz6Mh+ZqEbBuM4mWw/xKzbEbs7zA+d8sryHXkC8nsdA+h+IRd8bPa/KuWQNf\n"
+ "jxXKNPzgmsZddHmHtYtWvAcoIMvtyO23Y2NhN4V0/7fwFLbZtfUBg4pqUl2ktkdw\n"
+ "sNguTT1qzJCsYhsHXaqqvHy+5HR2D0w07y2X1qCVmfHzBZCM5OhxoeoauE+xu+5n\n"
+ "vYrgsgPE0y5Nty0y2MrApg3digaiKUXrI+mEVKn9vsQeaVvw9D6PgNQM99HkbGhR\n"
+ "MGPOzcHjS/ZeLd1zAgMBAAECggGBALHiAw3Yscqd11gJpbCMDqF7u4VG3alQ26un\n"
+ "PClhl++w380H/Q62TriK1LKKpHgj8834NpXUsXg2d4jTTDcmCn6/L9GoFOzmxOeV\n"
+ "0O2b4sOZvaNl397qrwLxDAPhec7z9yL4B4tcBqmJ3b3+izX6cS3gaC/uG9fDpgN9\n"
+ "xOKPYBFInhOB86twAz9cc9eXysto0nJvlODDBj/xwUjvso9qydl1Or7PhWvf7Ek+\n"
+ "H9ur5MUjqOWe/b/xaSWsfTrJzF/ovbRnGbXLIpozIx609TZS4wYSqU5FUjkL0zTB\n"
+ "bTdb3jgFm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/q/nHL6CjC0+6uiwjBWpRt9o7djFoxAoHAJzK/e1wJVGIXtVQa\n"
+ "N6Nlj7yhgD1ju1B4mTXQGuUMCkz3KtePFHU8tGExK5I2ySlZR3wobAXWx/cQLzbH\n"
+ "3nL0RkKGcgPAFyjl0Q7LBulsAllHrZJC7whVQ4E0wLBNkUDeIlNwUE6Go5qjopbD\n"
+ "q4KpNxUwaXYahNvEkzcNgWQ+XA7p8LDELX4K8tJi39ybHgbwiqdW2ags2xyD4ooD\n"
+ "HMCeKnEMuwWfd/0GaJdcCMdsGNl9D49eg2OZQTc8fkLwoA6BAoHATQdk3VZwGGn/\n"
+ "93p9vu189alkshTmir+SOo/ufH5U+j7t8cPeT7psuYAPZWS+Z6KEzvHxj54pAvcp\n"
+ "mlAngD3+AfHDn/VAtYv5HVcpZ+K2K0X4v8N5HGIubgaebs2oVNz+RAWnd8K2drDG\n"
+ "NcJV3C+zLziTCwvpGCIy3T/lHjKe+YczjGfhg2e6PgfwhTqPAjuhUZ8wScYo7l7V\n"
+ "zAhlSL0665IXJ32zX+3LyQFDbkB6pbKy5TU+rX3DmDyj3MSbc3kR\n"
+ "-----END RSA PRIVATE KEY-----\n";
+
+const gnutls_datum_t rawpk_private_key1 = {
+ (unsigned char*)rawpk_private_key_pem1,
+ sizeof(rawpk_private_key_pem1) - 1
+};
+
#endif
diff --git a/fuzz/gnutls_client_rawpk_fuzzer.c b/fuzz/gnutls_client_rawpk_fuzzer.c
new file mode 100644
index 0000000000..c7208b0d1c
--- /dev/null
+++ b/fuzz/gnutls_client_rawpk_fuzzer.c
@@ -0,0 +1,108 @@
+/*
+ * Copyright (C) 2017 Nikos Mavrogiannopoulos
+ * Copyright (C) 2019 Tom Vrancken (dev@tomvrancken.nl)
+ *
+ * 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.
+ *
+ */
+
+
+/***
+ * This fuzzer tests the behavior of the GnuTLS library in client mode,
+ * specifically dealing with raw public keys during the handshake.
+ *
+ * The fuzzer corpus generated as first input was generated with the
+ * following parameters for gnutls-serv and gnutls-cli:
+ *
+ * gnutls-serv --priority NORMAL:+CTYPE-CLI-RAWPK:+CTYPE-SRV-RAWPK
+ * gnutls-cli localhost:5556 --priority NORMAL:-CTYPE-ALL:+CTYPE-CLI-RAWPK:+CTYPE-SRV-RAWPK --no-ca-verification
+ *
+ * The above yields a handshake where both the client and server present
+ * a raw public-key to eachother.
+ */
+
+#include <assert.h>
+#include <fcntl.h>
+#include <stdint.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include <string.h>
+#include <stdlib.h>
+#include <stdbool.h>
+
+#include <gnutls/gnutls.h>
+
+#include "certs.h"
+#include "mem.h"
+#include "fuzzer.h"
+
+int LLVMFuzzerTestOneInput(const uint8_t * data, size_t size)
+{
+ int res;
+ gnutls_session_t session;
+ gnutls_certificate_credentials_t rawpk_cred;
+ struct mem_st memdata;
+
+ res = gnutls_init(&session, GNUTLS_CLIENT | GNUTLS_ENABLE_RAWPK);
+ assert(res >= 0);
+
+ res = gnutls_certificate_allocate_credentials(&rawpk_cred);
+ assert(res >= 0);
+
+ res =
+ gnutls_certificate_set_rawpk_key_mem(rawpk_cred,
+ &rawpk_public_key1,
+ &rawpk_private_key1,
+ GNUTLS_X509_FMT_PEM,
+ NULL, 0, NULL, 0, 0);
+ assert(res >= 0);
+
+ gnutls_certificate_set_known_dh_params(rawpk_cred, GNUTLS_SEC_PARAM_MEDIUM);
+
+ res = gnutls_credentials_set(session, GNUTLS_CRD_CERTIFICATE, rawpk_cred);
+ assert(res >= 0);
+
+ res = gnutls_priority_set_direct(session, "NORMAL:"VERS_STR":-CTYPE-ALL:+CTYPE-CLI-RAWPK:+CTYPE-SRV-RAWPK", NULL);
+ assert(res >= 0);
+
+ memdata.data = data;
+ memdata.size = size;
+
+ gnutls_transport_set_push_function(session, mem_push);
+ gnutls_transport_set_pull_function(session, mem_pull);
+ gnutls_transport_set_pull_timeout_function(session, mem_pull_timeout);
+ gnutls_transport_set_ptr(session, &memdata);
+
+ do {
+ res = gnutls_handshake(session);
+ } while (res < 0 && gnutls_error_is_fatal(res) == 0);
+ if (res >= 0) {
+ while (true) {
+ char buf[16384];
+ res = gnutls_record_recv(session, buf, sizeof(buf));
+ if (res <= 0) {
+ break;
+ }
+ }
+ }
+
+ gnutls_deinit(session);
+ gnutls_certificate_free_credentials(rawpk_cred);
+ return 0;
+}