Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Bug 1330557 - Add basic TLS client fuzzer r=mt,franziskus
Differential Revision: https://nss-review.dev.mozaws.net/D145

--HG--
rename : gtests/common/scoped_ptrs.h => cpputil/scoped_ptrs.h
  • Loading branch information
Tim Taubert committed Feb 10, 2017
1 parent db98f6a commit f7bc3cb
Show file tree
Hide file tree
Showing 30 changed files with 735 additions and 335 deletions.
16 changes: 11 additions & 5 deletions automation/taskcluster/graph/src/extend.js
Expand Up @@ -326,16 +326,22 @@ async function scheduleFuzzing() {

// Schedule fuzzing runs.
let run_base = merge(base, {parent: task_build, kind: "test"});
let mpi_base = merge(run_base, {group: "MPI"});
scheduleFuzzingRun(run_base, "CertDN", "certDN", 4096);
scheduleFuzzingRun(run_base, "Hash", "hash", 4096);
scheduleFuzzingRun(run_base, "QuickDER", "quickder", 10000);
for (let mpi_name of ["add", "addmod", "div", "expmod", "mod", "mulmod",
"sqr", "sqrmod", "sub", "submod"]) {
scheduleFuzzingRun(mpi_base, `MPI (${mpi_name})`, `mpi-${mpi_name}`,
4096, mpi_name);

// Schedule MPI fuzzing runs.
let mpi_base = merge(run_base, {group: "MPI"});
let mpi_names = ["add", "addmod", "div", "expmod", "mod", "mulmod", "sqr",
"sqrmod", "sub", "submod"];
for (let name of mpi_names) {
scheduleFuzzingRun(mpi_base, `MPI (${name})`, `mpi-${name}`, 4096, name);
}

// Schedule TLS fuzzing runs.
let tls_base = merge(run_base, {group: "TLS"});
scheduleFuzzingRun(tls_base, "TLS Client", "tls-client", 20000, "client");

return queue.submit();
}

Expand Down
1 change: 1 addition & 0 deletions automation/taskcluster/scripts/run_clang_format.sh
Expand Up @@ -42,6 +42,7 @@ else
"$top/gtests/ssl_gtest" \
"$top/gtests/util_gtest" \
"$top/nss-tool" \
"$top/cpputil" \
)
fi

Expand Down
4 changes: 4 additions & 0 deletions cpputil/.clang-format
@@ -0,0 +1,4 @@
---
Language: Cpp
BasedOnStyle: Google
...
11 changes: 11 additions & 0 deletions cpputil/README
@@ -0,0 +1,11 @@
######################################
## PLEASE READ BEFORE USING CPPUTIL ##
######################################

This is a static library supposed to be mainly used by NSS internally. We use
it for testing, fuzzing, and a few new tools written in C++ that we're
experimenting with.

You might find it handy to use for your own projects but please be aware that
we will make no promises your application won't break in the future. We will
provide no support if you decide to link against it.
27 changes: 27 additions & 0 deletions cpputil/cpputil.gyp
@@ -0,0 +1,27 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
{
'includes': [
'../coreconf/config.gypi',
],
'targets': [
{
'target_name': 'cpputil',
'type': 'static_library',
'sources': [
'dummy_io.cc',
'dummy_io_fwd.cc',
],
'dependencies': [
'<(DEPTH)/exports.gyp:nss_exports',
],
'direct_dependent_settings': {
'include_dirs': [
'<(DEPTH)/cpputil',
],
},
},
],
}

221 changes: 221 additions & 0 deletions cpputil/dummy_io.cc
@@ -0,0 +1,221 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */

#include <assert.h>
#include <iostream>

#include "prerror.h"
#include "prio.h"

#include "dummy_io.h"

#define UNIMPLEMENTED() \
std::cerr << "Unimplemented: " << __FUNCTION__ << std::endl; \
assert(false);

extern const struct PRIOMethods DummyMethodsForward;

ScopedPRFileDesc DummyIOLayerMethods::CreateFD(PRDescIdentity id,
DummyIOLayerMethods *methods) {
ScopedPRFileDesc fd(PR_CreateIOLayerStub(id, &DummyMethodsForward));
fd->secret = reinterpret_cast<PRFilePrivate *>(methods);
return fd;
}

PRStatus DummyIOLayerMethods::Close(PRFileDesc *f) {
f->secret = nullptr;
f->dtor(f);
return PR_SUCCESS;
}

int32_t DummyIOLayerMethods::Read(PRFileDesc *f, void *buf, int32_t length) {
UNIMPLEMENTED();
return -1;
}

int32_t DummyIOLayerMethods::Write(PRFileDesc *f, const void *buf,
int32_t length) {
UNIMPLEMENTED();
return -1;
}

int32_t DummyIOLayerMethods::Available(PRFileDesc *f) {
UNIMPLEMENTED();
return -1;
}

int64_t DummyIOLayerMethods::Available64(PRFileDesc *f) {
UNIMPLEMENTED();
return -1;
}

PRStatus DummyIOLayerMethods::Sync(PRFileDesc *f) {
UNIMPLEMENTED();
return PR_FAILURE;
}

int32_t DummyIOLayerMethods::Seek(PRFileDesc *f, int32_t offset,
PRSeekWhence how) {
UNIMPLEMENTED();
return -1;
}

int64_t DummyIOLayerMethods::Seek64(PRFileDesc *f, int64_t offset,
PRSeekWhence how) {
UNIMPLEMENTED();
return -1;
}

PRStatus DummyIOLayerMethods::FileInfo(PRFileDesc *f, PRFileInfo *info) {
UNIMPLEMENTED();
return PR_FAILURE;
}

PRStatus DummyIOLayerMethods::FileInfo64(PRFileDesc *f, PRFileInfo64 *info) {
UNIMPLEMENTED();
return PR_FAILURE;
}

int32_t DummyIOLayerMethods::Writev(PRFileDesc *f, const PRIOVec *iov,
int32_t iov_size, PRIntervalTime to) {
UNIMPLEMENTED();
return -1;
}

PRStatus DummyIOLayerMethods::Connect(PRFileDesc *f, const PRNetAddr *addr,
PRIntervalTime to) {
UNIMPLEMENTED();
return PR_FAILURE;
}

PRFileDesc *DummyIOLayerMethods::Accept(PRFileDesc *sd, PRNetAddr *addr,
PRIntervalTime to) {
UNIMPLEMENTED();
return nullptr;
}

PRStatus DummyIOLayerMethods::Bind(PRFileDesc *f, const PRNetAddr *addr) {
UNIMPLEMENTED();
return PR_FAILURE;
}

PRStatus DummyIOLayerMethods::Listen(PRFileDesc *f, int32_t depth) {
UNIMPLEMENTED();
return PR_FAILURE;
}

PRStatus DummyIOLayerMethods::Shutdown(PRFileDesc *f, int32_t how) {
return PR_SUCCESS;
}

int32_t DummyIOLayerMethods::Recv(PRFileDesc *f, void *buf, int32_t buflen,
int32_t flags, PRIntervalTime to) {
UNIMPLEMENTED();
return -1;
}

// Note: this is always nonblocking and assumes a zero timeout.
int32_t DummyIOLayerMethods::Send(PRFileDesc *f, const void *buf,
int32_t amount, int32_t flags,
PRIntervalTime to) {
return Write(f, buf, amount);
}

int32_t DummyIOLayerMethods::Recvfrom(PRFileDesc *f, void *buf, int32_t amount,
int32_t flags, PRNetAddr *addr,
PRIntervalTime to) {
UNIMPLEMENTED();
return -1;
}

int32_t DummyIOLayerMethods::Sendto(PRFileDesc *f, const void *buf,
int32_t amount, int32_t flags,
const PRNetAddr *addr, PRIntervalTime to) {
UNIMPLEMENTED();
return -1;
}

int16_t DummyIOLayerMethods::Poll(PRFileDesc *f, int16_t in_flags,
int16_t *out_flags) {
UNIMPLEMENTED();
return -1;
}

int32_t DummyIOLayerMethods::AcceptRead(PRFileDesc *sd, PRFileDesc **nd,
PRNetAddr **raddr, void *buf,
int32_t amount, PRIntervalTime t) {
UNIMPLEMENTED();
return -1;
}

int32_t DummyIOLayerMethods::TransmitFile(PRFileDesc *sd, PRFileDesc *f,
const void *headers, int32_t hlen,
PRTransmitFileFlags flags,
PRIntervalTime t) {
UNIMPLEMENTED();
return -1;
}

// TODO: Modify to return unique names for each channel
// somehow, as opposed to always the same static address. The current
// implementation messes up the session cache, which is why it's off
// elsewhere
PRStatus DummyIOLayerMethods::Getpeername(PRFileDesc *f, PRNetAddr *addr) {
addr->inet.family = PR_AF_INET;
addr->inet.port = 0;
addr->inet.ip = 0;

return PR_SUCCESS;
}

PRStatus DummyIOLayerMethods::Getsockname(PRFileDesc *f, PRNetAddr *addr) {
UNIMPLEMENTED();
return PR_FAILURE;
}

PRStatus DummyIOLayerMethods::Getsockoption(PRFileDesc *f,
PRSocketOptionData *opt) {
switch (opt->option) {
case PR_SockOpt_Nonblocking:
opt->value.non_blocking = PR_TRUE;
return PR_SUCCESS;
default:
UNIMPLEMENTED();
break;
}

return PR_FAILURE;
}

PRStatus DummyIOLayerMethods::Setsockoption(PRFileDesc *f,
const PRSocketOptionData *opt) {
switch (opt->option) {
case PR_SockOpt_Nonblocking:
return PR_SUCCESS;
case PR_SockOpt_NoDelay:
return PR_SUCCESS;
default:
UNIMPLEMENTED();
break;
}

return PR_FAILURE;
}

int32_t DummyIOLayerMethods::Sendfile(PRFileDesc *out, PRSendFileData *in,
PRTransmitFileFlags flags,
PRIntervalTime to) {
UNIMPLEMENTED();
return -1;
}

PRStatus DummyIOLayerMethods::ConnectContinue(PRFileDesc *f, int16_t flags) {
UNIMPLEMENTED();
return PR_FAILURE;
}

int32_t DummyIOLayerMethods::Reserved(PRFileDesc *f) {
UNIMPLEMENTED();
return -1;
}
62 changes: 62 additions & 0 deletions cpputil/dummy_io.h
@@ -0,0 +1,62 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef dummy_io_h__
#define dummy_io_h__

#include "prerror.h"
#include "prio.h"

#include "scoped_ptrs.h"

class DummyIOLayerMethods {
public:
static ScopedPRFileDesc CreateFD(PRDescIdentity id,
DummyIOLayerMethods *methods);

virtual PRStatus Close(PRFileDesc *f);
virtual int32_t Read(PRFileDesc *f, void *buf, int32_t length);
virtual int32_t Write(PRFileDesc *f, const void *buf, int32_t length);
virtual int32_t Available(PRFileDesc *f);
virtual int64_t Available64(PRFileDesc *f);
virtual PRStatus Sync(PRFileDesc *f);
virtual int32_t Seek(PRFileDesc *f, int32_t offset, PRSeekWhence how);
virtual int64_t Seek64(PRFileDesc *f, int64_t offset, PRSeekWhence how);
virtual PRStatus FileInfo(PRFileDesc *f, PRFileInfo *info);
virtual PRStatus FileInfo64(PRFileDesc *f, PRFileInfo64 *info);
virtual int32_t Writev(PRFileDesc *f, const PRIOVec *iov, int32_t iov_size,
PRIntervalTime to);
virtual PRStatus Connect(PRFileDesc *f, const PRNetAddr *addr,
PRIntervalTime to);
virtual PRFileDesc *Accept(PRFileDesc *sd, PRNetAddr *addr,
PRIntervalTime to);
virtual PRStatus Bind(PRFileDesc *f, const PRNetAddr *addr);
virtual PRStatus Listen(PRFileDesc *f, int32_t depth);
virtual PRStatus Shutdown(PRFileDesc *f, int32_t how);
virtual int32_t Recv(PRFileDesc *f, void *buf, int32_t buflen, int32_t flags,
PRIntervalTime to);
virtual int32_t Send(PRFileDesc *f, const void *buf, int32_t amount,
int32_t flags, PRIntervalTime to);
virtual int32_t Recvfrom(PRFileDesc *f, void *buf, int32_t amount,
int32_t flags, PRNetAddr *addr, PRIntervalTime to);
virtual int32_t Sendto(PRFileDesc *f, const void *buf, int32_t amount,
int32_t flags, const PRNetAddr *addr,
PRIntervalTime to);
virtual int16_t Poll(PRFileDesc *f, int16_t in_flags, int16_t *out_flags);
virtual int32_t AcceptRead(PRFileDesc *sd, PRFileDesc **nd, PRNetAddr **raddr,
void *buf, int32_t amount, PRIntervalTime t);
virtual int32_t TransmitFile(PRFileDesc *sd, PRFileDesc *f,
const void *headers, int32_t hlen,
PRTransmitFileFlags flags, PRIntervalTime t);
virtual PRStatus Getpeername(PRFileDesc *f, PRNetAddr *addr);
virtual PRStatus Getsockname(PRFileDesc *f, PRNetAddr *addr);
virtual PRStatus Getsockoption(PRFileDesc *f, PRSocketOptionData *opt);
virtual PRStatus Setsockoption(PRFileDesc *f, const PRSocketOptionData *opt);
virtual int32_t Sendfile(PRFileDesc *out, PRSendFileData *in,
PRTransmitFileFlags flags, PRIntervalTime to);
virtual PRStatus ConnectContinue(PRFileDesc *f, int16_t flags);
virtual int32_t Reserved(PRFileDesc *f);
};

#endif // dummy_io_h__

0 comments on commit f7bc3cb

Please sign in to comment.