summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNikos Mavrogiannopoulos <nmav@gnutls.org>2016-12-15 14:47:25 +0000
committerNikos Mavrogiannopoulos <nmav@gnutls.org>2016-12-15 14:47:25 +0000
commita71f69f2a2dcbc3d095c1b0613de675ff58076db (patch)
tree29d660577a7ba09c76d64906afd88a20a012b15d
parent83e659a2a4ea9a9cf540e3bdcde7afaf15334f66 (diff)
parentf27a842a1c4cd4067152b7a62a7da1d021bc4d27 (diff)
downloadgnutls-a71f69f2a2dcbc3d095c1b0613de675ff58076db.tar.gz
Merge branch 'fuzzers' into 'master'
Migrated fuzzers from the oss-repo to here. Also added a new private_key_parser fuzzer. See merge request !184
-rw-r--r--devel/fuzz/README.md7
-rw-r--r--devel/fuzz/gnutls_client_fuzzer.cc73
-rw-r--r--devel/fuzz/gnutls_private_key_parser_fuzzer.cc41
-rw-r--r--devel/fuzz/gnutls_server_fuzzer.cc250
-rw-r--r--devel/fuzz/gnutls_x509_parser_fuzzer.cc47
5 files changed, 418 insertions, 0 deletions
diff --git a/devel/fuzz/README.md b/devel/fuzz/README.md
new file mode 100644
index 0000000000..f648dcab8d
--- /dev/null
+++ b/devel/fuzz/README.md
@@ -0,0 +1,7 @@
+# Fuzzers
+
+These are fuzzers designed for use with `libFuzzer`. Currently they are
+primarily run on Google's OSS-Fuzz (https://github.com/google/oss-fuzz/).
+
+OSS-Fuzz will automatically locate and compile any `*_fuzzer.cc` files and
+assume they are fuzzers it should run.
diff --git a/devel/fuzz/gnutls_client_fuzzer.cc b/devel/fuzz/gnutls_client_fuzzer.cc
new file mode 100644
index 0000000000..b155ca5edf
--- /dev/null
+++ b/devel/fuzz/gnutls_client_fuzzer.cc
@@ -0,0 +1,73 @@
+/*
+# Copyright 2016 Google Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+################################################################################
+*/
+
+#include <assert.h>
+#include <fcntl.h>
+#include <stdint.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <unistd.h>
+
+#include <gnutls/gnutls.h>
+
+
+extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
+ int res;
+ gnutls_session_t session;
+ gnutls_certificate_credentials_t xcred;
+
+ int socket_fds[2];
+ res = socketpair(AF_UNIX, SOCK_STREAM, 0, socket_fds);
+ assert(res >= 0);
+ ssize_t send_res = send(socket_fds[1], data, size, 0);
+ assert(send_res == size);
+ res = shutdown(socket_fds[1], SHUT_WR);
+ assert(res == 0);
+
+ res = gnutls_init(&session, GNUTLS_CLIENT);
+ assert(res >= 0);
+
+ res = gnutls_certificate_allocate_credentials(&xcred);
+ assert(res >= 0);
+ res = gnutls_credentials_set(session, GNUTLS_CRD_CERTIFICATE, xcred);
+ assert(res >= 0);
+
+ res = gnutls_set_default_priority(session);
+ assert(res >= 0);
+
+ gnutls_transport_set_int(session, socket_fds[0]);
+
+ 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;
+ }
+ }
+ }
+
+ close(socket_fds[0]);
+ close(socket_fds[1]);
+ gnutls_deinit(session);
+ gnutls_certificate_free_credentials(xcred);
+ return 0;
+}
diff --git a/devel/fuzz/gnutls_private_key_parser_fuzzer.cc b/devel/fuzz/gnutls_private_key_parser_fuzzer.cc
new file mode 100644
index 0000000000..63d8163fa7
--- /dev/null
+++ b/devel/fuzz/gnutls_private_key_parser_fuzzer.cc
@@ -0,0 +1,41 @@
+/*
+# Copyright 2016 Google Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+################################################################################
+*/
+
+#include <assert.h>
+#include <stdint.h>
+
+#include <gnutls/gnutls.h>
+#include <gnutls/x509.h>
+
+
+extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
+ gnutls_datum_t raw;
+ gnutls_x509_privkey_t key;
+ int ret;
+
+ raw.data = (unsigned char *)data;
+ raw.size = size;
+
+ ret = gnutls_x509_privkey_init(&key);
+ assert(ret >= 0);
+
+ ret = gnutls_x509_privkey_import(key, &raw, GNUTLS_X509_FMT_DER);
+
+ gnutls_x509_privkey_deinit(key);
+ return 0;
+}
diff --git a/devel/fuzz/gnutls_server_fuzzer.cc b/devel/fuzz/gnutls_server_fuzzer.cc
new file mode 100644
index 0000000000..e864f10354
--- /dev/null
+++ b/devel/fuzz/gnutls_server_fuzzer.cc
@@ -0,0 +1,250 @@
+/*
+# Copyright 2016 Google Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+################################################################################
+*/
+
+#include <assert.h>
+#include <stdint.h>
+#include <sys/socket.h>
+#include <unistd.h>
+
+#include <gnutls/gnutls.h>
+
+static const uint8_t kCertificateDER[] = {
+ 0x30, 0x82, 0x02, 0xff, 0x30, 0x82, 0x01, 0xe7, 0xa0, 0x03, 0x02, 0x01,
+ 0x02, 0x02, 0x11, 0x00, 0xb1, 0x84, 0xee, 0x34, 0x99, 0x98, 0x76, 0xfb,
+ 0x6f, 0xb2, 0x15, 0xc8, 0x47, 0x79, 0x05, 0x9b, 0x30, 0x0d, 0x06, 0x09,
+ 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00, 0x30,
+ 0x12, 0x31, 0x10, 0x30, 0x0e, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x13, 0x07,
+ 0x41, 0x63, 0x6d, 0x65, 0x20, 0x43, 0x6f, 0x30, 0x1e, 0x17, 0x0d, 0x31,
+ 0x35, 0x31, 0x31, 0x30, 0x37, 0x30, 0x30, 0x32, 0x34, 0x35, 0x36, 0x5a,
+ 0x17, 0x0d, 0x31, 0x36, 0x31, 0x31, 0x30, 0x36, 0x30, 0x30, 0x32, 0x34,
+ 0x35, 0x36, 0x5a, 0x30, 0x12, 0x31, 0x10, 0x30, 0x0e, 0x06, 0x03, 0x55,
+ 0x04, 0x0a, 0x13, 0x07, 0x41, 0x63, 0x6d, 0x65, 0x20, 0x43, 0x6f, 0x30,
+ 0x82, 0x01, 0x22, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7,
+ 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, 0x82, 0x01, 0x0f, 0x00, 0x30,
+ 0x82, 0x01, 0x0a, 0x02, 0x82, 0x01, 0x01, 0x00, 0xce, 0x47, 0xcb, 0x11,
+ 0xbb, 0xd2, 0x9d, 0x8e, 0x9e, 0xd2, 0x1e, 0x14, 0xaf, 0xc7, 0xea, 0xb6,
+ 0xc9, 0x38, 0x2a, 0x6f, 0xb3, 0x7e, 0xfb, 0xbc, 0xfc, 0x59, 0x42, 0xb9,
+ 0x56, 0xf0, 0x4c, 0x3f, 0xf7, 0x31, 0x84, 0xbe, 0xac, 0x03, 0x9e, 0x71,
+ 0x91, 0x85, 0xd8, 0x32, 0xbd, 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, size_t size) {
+ int res;
+ gnutls_datum_t cert, key;
+ gnutls_session_t session;
+ gnutls_certificate_credentials_t xcred;
+
+ int socket_fds[2];
+ res = socketpair(AF_UNIX, SOCK_STREAM, 0, socket_fds);
+ assert(res >= 0);
+ ssize_t send_res = send(socket_fds[1], data, size, 0);
+ assert(send_res == size);
+ res = shutdown(socket_fds[1], SHUT_WR);
+ assert(res == 0);
+
+ res = gnutls_init(&session, GNUTLS_SERVER);
+ assert(res >= 0);
+
+ res = gnutls_certificate_allocate_credentials(&xcred);
+ assert(res >= 0);
+
+ cert.data = (unsigned char *)kCertificateDER;
+ cert.size = sizeof(kCertificateDER);
+ key.data = (unsigned char *)kRSAPrivateKeyDER;
+ key.size = sizeof(kRSAPrivateKeyDER);
+ res = gnutls_certificate_set_x509_key_mem(
+ xcred, &cert, &key, GNUTLS_X509_FMT_DER);
+ assert(res >= 0);
+ res = gnutls_credentials_set(session, GNUTLS_CRD_CERTIFICATE, xcred);
+ assert(res >= 0);
+
+ res = gnutls_set_default_priority(session);
+ assert(res >= 0);
+
+ gnutls_transport_set_int(session, socket_fds[0]);
+
+ 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;
+ }
+ }
+ }
+
+ close(socket_fds[0]);
+ close(socket_fds[1]);
+ gnutls_deinit(session);
+ gnutls_certificate_free_credentials(xcred);
+ return 0;
+}
diff --git a/devel/fuzz/gnutls_x509_parser_fuzzer.cc b/devel/fuzz/gnutls_x509_parser_fuzzer.cc
new file mode 100644
index 0000000000..28dc3397fc
--- /dev/null
+++ b/devel/fuzz/gnutls_x509_parser_fuzzer.cc
@@ -0,0 +1,47 @@
+/*
+# Copyright 2016 Google Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+################################################################################
+*/
+
+#include <assert.h>
+#include <stdint.h>
+
+#include <gnutls/gnutls.h>
+#include <gnutls/x509.h>
+
+
+extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
+ gnutls_datum_t raw;
+ gnutls_datum_t out;
+ gnutls_x509_crt_t crt;
+ int ret;
+
+ raw.data = (unsigned char *)data;
+ raw.size = size;
+
+ ret = gnutls_x509_crt_init(&crt);
+ assert(ret >= 0);
+
+ ret = gnutls_x509_crt_import(crt, &raw, GNUTLS_X509_FMT_DER);
+ if (ret >= 0) {
+ ret = gnutls_x509_crt_print(crt, GNUTLS_CRT_PRINT_FULL, &out);
+ assert(ret >= 0);
+ gnutls_free(out.data);
+ }
+
+ gnutls_x509_crt_deinit(crt);
+ return 0;
+}