Latest update.
This commit is contained in:
+27
-12
@@ -12,14 +12,14 @@ With `clang` from a package manager
|
||||
Install `clang`, which [ships with `libfuzzer`](http://llvm.org/docs/LibFuzzer.html#fuzzer-usage)
|
||||
since version 6.0:
|
||||
|
||||
$ sudo apt-get install clang
|
||||
sudo apt-get install clang
|
||||
|
||||
Configure `openssl` for fuzzing. For now, you'll still need to pass in the path
|
||||
to the `libFuzzer` library file while configuring; this is represented as
|
||||
`$PATH_TO_LIBFUZZER` below. A typical value would be
|
||||
`/usr/lib/llvm-6.0/lib/clang/6.0.0/lib/linux/libclang_rt.fuzzer-x86_64.a`.
|
||||
`/usr/lib/llvm-7/lib/clang/7.0.1/lib/linux/libclang_rt.fuzzer-x86_64.a`.
|
||||
|
||||
$ CC=clang ./config enable-fuzz-libfuzzer \
|
||||
CC=clang ./config enable-fuzz-libfuzzer \
|
||||
--with-fuzzer-lib=$PATH_TO_LIBFUZZER \
|
||||
-DPEDANTIC enable-asan enable-ubsan no-shared \
|
||||
-DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION \
|
||||
@@ -31,14 +31,16 @@ to the `libFuzzer` library file while configuring; this is represented as
|
||||
|
||||
Compile:
|
||||
|
||||
$ sudo apt-get install make
|
||||
$ LDCMD=clang++ make -j
|
||||
sudo apt-get install make
|
||||
make clean
|
||||
LDCMD=clang++ make -j4
|
||||
|
||||
Finally, perform the actual fuzzing:
|
||||
|
||||
$ fuzz/helper.py $FUZZER
|
||||
fuzz/helper.py $FUZZER
|
||||
|
||||
where $FUZZER is one of the executables in `fuzz/`.
|
||||
It will run until you stop it.
|
||||
|
||||
If you get a crash, you should find a corresponding input file in
|
||||
`fuzz/corpora/$FUZZER-crash/`.
|
||||
@@ -54,7 +56,7 @@ fuzzing is the same, except that you also need to specify
|
||||
a `--with-fuzzer-include` option, which should be the parent directory of the
|
||||
prebuilt fuzzer library. This is represented as `$PATH_TO_LIBFUZZER_DIR` below.
|
||||
|
||||
$ CC=clang ./config enable-fuzz-libfuzzer \
|
||||
CC=clang ./config enable-fuzz-libfuzzer \
|
||||
--with-fuzzer-include=$PATH_TO_LIBFUZZER_DIR \
|
||||
--with-fuzzer-lib=$PATH_TO_LIBFUZZER \
|
||||
-DPEDANTIC enable-asan enable-ubsan no-shared \
|
||||
@@ -68,21 +70,24 @@ prebuilt fuzzer library. This is represented as `$PATH_TO_LIBFUZZER_DIR` below.
|
||||
AFL
|
||||
===
|
||||
|
||||
This is an alternative to using LibFuzzer.
|
||||
|
||||
Configure for fuzzing:
|
||||
|
||||
$ sudo apt-get install afl-clang
|
||||
$ CC=afl-clang-fast ./config enable-fuzz-afl no-shared no-module \
|
||||
sudo apt-get install afl-clang
|
||||
CC=afl-clang-fast ./config enable-fuzz-afl no-shared no-module \
|
||||
-DPEDANTIC enable-tls1_3 enable-weak-ssl-ciphers enable-rc5 \
|
||||
enable-md2 enable-ssl3 enable-ssl3-method enable-nextprotoneg \
|
||||
enable-ec_nistp_64_gcc_128 -fno-sanitize=alignment \
|
||||
--debug
|
||||
$ make
|
||||
make clean
|
||||
make
|
||||
|
||||
The following options can also be enabled: enable-asan, enable-ubsan, enable-msan
|
||||
|
||||
Run one of the fuzzers:
|
||||
|
||||
$ afl-fuzz -i fuzz/corpora/$FUZZER -o fuzz/corpora/$FUZZER/out fuzz/$FUZZER
|
||||
afl-fuzz -i fuzz/corpora/$FUZZER -o fuzz/corpora/$FUZZER/out fuzz/$FUZZER
|
||||
|
||||
Where $FUZZER is one of the executables in `fuzz/`.
|
||||
|
||||
@@ -100,7 +105,7 @@ reproduce the generated random numbers.
|
||||
|
||||
To reproduce the crash you can run:
|
||||
|
||||
$ fuzz/$FUZZER-test $file
|
||||
fuzz/$FUZZER-test $file
|
||||
|
||||
Random numbers
|
||||
==============
|
||||
@@ -140,3 +145,13 @@ The client and server corpus is generated with multiple config options:
|
||||
|
||||
The libfuzzer merge option is used to add the additional coverage
|
||||
from each config to the minimal set.
|
||||
|
||||
Minimizing the corpus
|
||||
=====================
|
||||
|
||||
When you have gathered corpus data from more than one fuzzer run
|
||||
or for any other reason want to to minimize the data
|
||||
in some corpus subdirectory `fuzz/corpora/DIR` this can be done as follows:
|
||||
|
||||
mkdir fuzz/corpora/NEWDIR
|
||||
fuzz/$FUZZER -merge=1 fuzz/corpora/NEWDIR fuzz/corpora/DIR
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2016-2019 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 2016-2020 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the Apache License 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
||||
@@ -11,6 +11,10 @@
|
||||
IF[{- !$disabled{"fuzz-afl"} || !$disabled{"fuzz-libfuzzer"} -}]
|
||||
PROGRAMS{noinst}=asn1 asn1parse bignum bndiv client conf crl server x509
|
||||
|
||||
IF[{- !$disabled{"cmp"} -}]
|
||||
PROGRAMS{noinst}=cmp
|
||||
ENDIF
|
||||
|
||||
IF[{- !$disabled{"cms"} -}]
|
||||
PROGRAMS{noinst}=cms
|
||||
ENDIF
|
||||
@@ -39,6 +43,10 @@ IF[{- !$disabled{"fuzz-afl"} || !$disabled{"fuzz-libfuzzer"} -}]
|
||||
INCLUDE[client]=../include {- $ex_inc -}
|
||||
DEPEND[client]=../libcrypto ../libssl {- $ex_lib -}
|
||||
|
||||
SOURCE[cmp]=cmp.c driver.c
|
||||
INCLUDE[cmp]=../include {- $ex_inc -}
|
||||
DEPEND[cmp]=../libcrypto {- $ex_lib -}
|
||||
|
||||
SOURCE[cms]=cms.c driver.c
|
||||
INCLUDE[cms]=../include {- $ex_inc -}
|
||||
DEPEND[cms]=../libcrypto {- $ex_lib -}
|
||||
@@ -67,6 +75,10 @@ ENDIF
|
||||
IF[{- !$disabled{tests} -}]
|
||||
PROGRAMS{noinst}=asn1-test asn1parse-test bignum-test bndiv-test client-test conf-test crl-test server-test x509-test
|
||||
|
||||
IF[{- !$disabled{"cmp"} -}]
|
||||
PROGRAMS{noinst}=cmp-test
|
||||
ENDIF
|
||||
|
||||
IF[{- !$disabled{"cms"} -}]
|
||||
PROGRAMS{noinst}=cms-test
|
||||
ENDIF
|
||||
@@ -95,6 +107,11 @@ IF[{- !$disabled{tests} -}]
|
||||
INCLUDE[client-test]=../include
|
||||
DEPEND[client-test]=../libcrypto ../libssl
|
||||
|
||||
SOURCE[cmp-test]=cmp.c test-corpus.c
|
||||
INCLUDE[cmp-test]=../include
|
||||
DEPEND[cmp-test]=../libcrypto.a
|
||||
# referring to static lib allows using non-exported functions
|
||||
|
||||
SOURCE[cms-test]=cms.c test-corpus.c
|
||||
INCLUDE[cms-test]=../include
|
||||
DEPEND[cms-test]=../libcrypto
|
||||
|
||||
@@ -20,6 +20,8 @@
|
||||
|
||||
#include "rand.inc"
|
||||
|
||||
DEFINE_STACK_OF(SSL_COMP)
|
||||
|
||||
/* unused, to avoid warning. */
|
||||
static int idx;
|
||||
|
||||
|
||||
+205
@@ -0,0 +1,205 @@
|
||||
/*
|
||||
* Copyright 2007-2020 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the Apache License 2.0 (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
* in the file LICENSE in the source distribution or at
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
/*
|
||||
* Test CMP DER parsing.
|
||||
*/
|
||||
|
||||
#include <openssl/bio.h>
|
||||
#include <openssl/cmp.h>
|
||||
#include "../crypto/cmp/cmp_local.h"
|
||||
#include <openssl/err.h>
|
||||
#include "fuzzer.h"
|
||||
#include "rand.inc"
|
||||
|
||||
DEFINE_STACK_OF(OSSL_CMP_ITAV)
|
||||
|
||||
int FuzzerInitialize(int *argc, char ***argv)
|
||||
{
|
||||
OPENSSL_init_crypto(OPENSSL_INIT_LOAD_CRYPTO_STRINGS, NULL);
|
||||
ERR_clear_error();
|
||||
CRYPTO_free_ex_index(0, -1);
|
||||
FuzzerSetRand();
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int num_responses;
|
||||
|
||||
static OSSL_CMP_MSG *transfer_cb(OSSL_CMP_CTX *ctx, const OSSL_CMP_MSG *req)
|
||||
{
|
||||
if (num_responses++ > 2)
|
||||
return NULL; /* prevent loops due to repeated pollRep */
|
||||
return OSSL_CMP_MSG_dup((OSSL_CMP_MSG *)
|
||||
OSSL_CMP_CTX_get_transfer_cb_arg(ctx));
|
||||
}
|
||||
|
||||
static int print_noop(const char *func, const char *file, int line,
|
||||
OSSL_CMP_severity level, const char *msg)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int allow_unprotected(const OSSL_CMP_CTX *ctx, const OSSL_CMP_MSG *rep,
|
||||
int invalid_protection, int expected_type)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void cmp_client_process_response(OSSL_CMP_CTX *ctx, OSSL_CMP_MSG *msg)
|
||||
{
|
||||
X509_NAME *name = X509_NAME_new();
|
||||
ASN1_INTEGER *serial = ASN1_INTEGER_new();
|
||||
|
||||
ctx->unprotectedSend = 1; /* satisfy ossl_cmp_msg_protect() */
|
||||
ctx->disableConfirm = 1; /* check just one response message */
|
||||
ctx->popoMethod = OSSL_CRMF_POPO_NONE; /* satisfy ossl_cmp_certReq_new() */
|
||||
ctx->oldCert = X509_new(); /* satisfy crm_new() and ossl_cmp_rr_new() */
|
||||
if (!OSSL_CMP_CTX_set1_secretValue(ctx, (unsigned char *)"",
|
||||
0) /* prevent too unspecific error */
|
||||
|| ctx->oldCert == NULL
|
||||
|| name == NULL || !X509_set_issuer_name(ctx->oldCert, name)
|
||||
|| serial == NULL || !X509_set_serialNumber(ctx->oldCert, serial))
|
||||
goto err;
|
||||
|
||||
(void)OSSL_CMP_CTX_set_transfer_cb(ctx, transfer_cb);
|
||||
(void)OSSL_CMP_CTX_set_transfer_cb_arg(ctx, msg);
|
||||
(void)OSSL_CMP_CTX_set_log_cb(ctx, print_noop);
|
||||
num_responses = 0;
|
||||
switch (msg->body != NULL ? msg->body->type : -1) {
|
||||
case OSSL_CMP_PKIBODY_IP:
|
||||
(void)OSSL_CMP_exec_IR_ses(ctx);
|
||||
break;
|
||||
case OSSL_CMP_PKIBODY_CP:
|
||||
(void)OSSL_CMP_exec_CR_ses(ctx);
|
||||
(void)OSSL_CMP_exec_P10CR_ses(ctx);
|
||||
break;
|
||||
case OSSL_CMP_PKIBODY_KUP:
|
||||
(void)OSSL_CMP_exec_KUR_ses(ctx);
|
||||
break;
|
||||
case OSSL_CMP_PKIBODY_POLLREP:
|
||||
ctx->status = OSSL_CMP_PKISTATUS_waiting;
|
||||
(void)OSSL_CMP_try_certreq(ctx, OSSL_CMP_PKIBODY_CR, NULL);
|
||||
break;
|
||||
case OSSL_CMP_PKIBODY_RP:
|
||||
(void)OSSL_CMP_exec_RR_ses(ctx);
|
||||
break;
|
||||
case OSSL_CMP_PKIBODY_GENP:
|
||||
sk_OSSL_CMP_ITAV_pop_free(OSSL_CMP_exec_GENM_ses(ctx),
|
||||
OSSL_CMP_ITAV_free);
|
||||
break;
|
||||
default:
|
||||
(void)ossl_cmp_msg_check_received(ctx, msg, allow_unprotected, 0);
|
||||
break;
|
||||
}
|
||||
err:
|
||||
X509_NAME_free(name);
|
||||
ASN1_INTEGER_free(serial);
|
||||
}
|
||||
|
||||
static OSSL_CMP_PKISI *process_cert_request(OSSL_CMP_SRV_CTX *srv_ctx,
|
||||
const OSSL_CMP_MSG *cert_req,
|
||||
int certReqId,
|
||||
const OSSL_CRMF_MSG *crm,
|
||||
const X509_REQ *p10cr,
|
||||
X509 **certOut,
|
||||
STACK_OF(X509) **chainOut,
|
||||
STACK_OF(X509) **caPubs)
|
||||
{
|
||||
CMPerr(0, CMP_R_ERROR_PROCESSING_MESSAGE);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static OSSL_CMP_PKISI *process_rr(OSSL_CMP_SRV_CTX *srv_ctx,
|
||||
const OSSL_CMP_MSG *rr,
|
||||
const X509_NAME *issuer,
|
||||
const ASN1_INTEGER *serial)
|
||||
{
|
||||
CMPerr(0, CMP_R_ERROR_PROCESSING_MESSAGE);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int process_genm(OSSL_CMP_SRV_CTX *srv_ctx,
|
||||
const OSSL_CMP_MSG *genm,
|
||||
const STACK_OF(OSSL_CMP_ITAV) *in,
|
||||
STACK_OF(OSSL_CMP_ITAV) **out)
|
||||
{
|
||||
CMPerr(0, CMP_R_ERROR_PROCESSING_MESSAGE);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void process_error(OSSL_CMP_SRV_CTX *srv_ctx, const OSSL_CMP_MSG *error,
|
||||
const OSSL_CMP_PKISI *statusInfo,
|
||||
const ASN1_INTEGER *errorCode,
|
||||
const OSSL_CMP_PKIFREETEXT *errorDetails)
|
||||
{
|
||||
CMPerr(0, CMP_R_ERROR_PROCESSING_MESSAGE);
|
||||
}
|
||||
|
||||
static int process_certConf(OSSL_CMP_SRV_CTX *srv_ctx,
|
||||
const OSSL_CMP_MSG *certConf, int certReqId,
|
||||
const ASN1_OCTET_STRING *certHash,
|
||||
const OSSL_CMP_PKISI *si)
|
||||
{
|
||||
CMPerr(0, CMP_R_ERROR_PROCESSING_MESSAGE);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int process_pollReq(OSSL_CMP_SRV_CTX *srv_ctx,
|
||||
const OSSL_CMP_MSG *pollReq, int certReqId,
|
||||
OSSL_CMP_MSG **certReq, int64_t *check_after)
|
||||
{
|
||||
CMPerr(0, CMP_R_ERROR_PROCESSING_MESSAGE);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int FuzzerTestOneInput(const uint8_t *buf, size_t len)
|
||||
{
|
||||
OSSL_CMP_MSG *msg;
|
||||
BIO *in;
|
||||
|
||||
if (len == 0)
|
||||
return 0;
|
||||
|
||||
in = BIO_new(BIO_s_mem());
|
||||
OPENSSL_assert((size_t)BIO_write(in, buf, len) == len);
|
||||
msg = d2i_OSSL_CMP_MSG_bio(in, NULL);
|
||||
if (msg != NULL) {
|
||||
BIO *out = BIO_new(BIO_s_null());
|
||||
OSSL_CMP_SRV_CTX *srv_ctx = OSSL_CMP_SRV_CTX_new();
|
||||
OSSL_CMP_CTX *client_ctx = OSSL_CMP_CTX_new();
|
||||
|
||||
i2d_OSSL_CMP_MSG_bio(out, msg);
|
||||
ASN1_item_print(out, (ASN1_VALUE *)msg, 4,
|
||||
ASN1_ITEM_rptr(OSSL_CMP_MSG), NULL);
|
||||
BIO_free(out);
|
||||
|
||||
if (client_ctx != NULL)
|
||||
cmp_client_process_response(client_ctx, msg);
|
||||
if (srv_ctx != NULL
|
||||
&& OSSL_CMP_CTX_set_log_cb(OSSL_CMP_SRV_CTX_get0_cmp_ctx(srv_ctx),
|
||||
print_noop)
|
||||
&& OSSL_CMP_SRV_CTX_init(srv_ctx, NULL, process_cert_request,
|
||||
process_rr, process_genm, process_error,
|
||||
process_certConf, process_pollReq))
|
||||
OSSL_CMP_MSG_free(OSSL_CMP_SRV_process_request(srv_ctx, msg));
|
||||
|
||||
OSSL_CMP_CTX_free(client_ctx);
|
||||
OSSL_CMP_SRV_CTX_free(srv_ctx);
|
||||
OSSL_CMP_MSG_free(msg);
|
||||
}
|
||||
|
||||
BIO_free(in);
|
||||
ERR_clear_error();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void FuzzerCleanup(void)
|
||||
{
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user