Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Bug 1295054 - Add support for Google's BoGo test harness. r=mt
This patch lets you run the test harness by hand. Next step is to
enable it in CI.
  • Loading branch information
ekr committed Aug 15, 2016
1 parent e88e8ee commit 7582395
Show file tree
Hide file tree
Showing 10 changed files with 676 additions and 0 deletions.
1 change: 1 addition & 0 deletions external_tests/manifest.mn
Expand Up @@ -12,4 +12,5 @@ DIRS = \
util_gtest \
pk11_gtest \
ssl_gtest \
nss_bogo_shim \
$(NULL)
52 changes: 52 additions & 0 deletions external_tests/nss_bogo_shim/Makefile
@@ -0,0 +1,52 @@
#! gmake
#
# 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/.

#######################################################################
# (1) Include initial platform-independent assignments (MANDATORY). #
#######################################################################

include manifest.mn

#######################################################################
# (2) Include "global" configuration information. (OPTIONAL) #
#######################################################################

include $(CORE_DEPTH)/coreconf/config.mk

#######################################################################
# (3) Include "component" configuration information. (OPTIONAL) #
#######################################################################

CXXFLAGS += -std=c++0x

#######################################################################
# (4) Include "local" platform-dependent assignments (OPTIONAL). #
#######################################################################

include ../common/gtest.mk

CFLAGS += -I$(CORE_DEPTH)/lib/ssl

ifdef NSS_SSL_ENABLE_ZLIB
include $(CORE_DEPTH)/coreconf/zlib.mk
endif

#######################################################################
# (5) Execute "global" rules. (OPTIONAL) #
#######################################################################

include $(CORE_DEPTH)/coreconf/rules.mk

#######################################################################
# (6) Execute "component" rules. (OPTIONAL) #
#######################################################################


#######################################################################
# (7) Execute "local" rules. (OPTIONAL). #
#######################################################################


58 changes: 58 additions & 0 deletions external_tests/nss_bogo_shim/config.cc
@@ -0,0 +1,58 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=2 et sw=2 tw=80: */
/* 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 "config.h"

#include <cstdlib>
#include <queue>
#include <string>

bool ConfigEntryBase::ParseInternal(std::queue<const char *> *args,
std::string *out) {
if (args->empty()) return false;
*out = args->front();
args->pop();
return true;
}

bool ConfigEntryBase::ParseInternal(std::queue<const char *> *args, int *out) {
if (args->empty()) return false;

char *endptr;
*out = strtol(args->front(), &endptr, 10);
args->pop();

return !*endptr;
}

bool ConfigEntryBase::ParseInternal(std::queue<const char *> *args, bool *out) {
*out = true;
return true;
}

std::string Config::XformFlag(const std::string &arg) {
if (arg.empty()) return "";

if (arg[0] != '-') return "";

return arg.substr(1);
}

Config::Status Config::ParseArgs(int argc, char **argv) {
std::queue<const char *> args;
for (int i = 1; i < argc; ++i) {
args.push(argv[i]);
}
while (!args.empty()) {
auto e = entries_.find(XformFlag(args.front()));
args.pop();
if (e == entries_.end()) {
return kUnknownFlag;
}
if (!e->second->Parse(&args)) return kMalformedArgument;
}

return kOK;
}
88 changes: 88 additions & 0 deletions external_tests/nss_bogo_shim/config.h
@@ -0,0 +1,88 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=2 et sw=2 tw=80: */
/* 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/. */

// Generic command line flags system for NSS BoGo shim. This class
// could actually in principle handle other programs. The flags are
// defined in the consumer code.

#ifndef config_h_
#define config_h_

#include <cassert>

#include <iostream>
#include <map>
#include <queue>
#include <string>

// Abstract base class for a given config flag.
class ConfigEntryBase {
public:
ConfigEntryBase(const std::string& name, const std::string& type)
: name_(name), type_(type) {}

const std::string& type() const { return type_; }
virtual bool Parse(std::queue<const char*>* args) = 0;

protected:
bool ParseInternal(std::queue<const char*>* args, std::string* out);
bool ParseInternal(std::queue<const char*>* args, int* out);
bool ParseInternal(std::queue<const char*>* args, bool* out);

const std::string name_;
const std::string type_;
};

// Template specializations for the concrete flag types.
template <typename T>
class ConfigEntry : public ConfigEntryBase {
public:
ConfigEntry(const std::string& name, T init)
: ConfigEntryBase(name, typeid(T).name()), value_(init) {}
T get() const { return value_; }

bool Parse(std::queue<const char*>* args) {
return ParseInternal(args, &value_);
}

private:
T value_;
};

// The overall configuration (I.e., the total set of flags).
class Config {
public:
enum Status { kOK, kUnknownFlag, kMalformedArgument, kMissingValue };

Config() : entries_() {}

template <typename T>
void AddEntry(const std::string& name, T init) {
entries_[name] = new ConfigEntry<T>(name, init);
}

Status ParseArgs(int argc, char** argv);

template <typename T>
T get(const std::string& key) const {
auto e = entry(key);
assert(e->type() == typeid(T).name());
return static_cast<const ConfigEntry<T>*>(e)->get();
}

private:
static std::string XformFlag(const std::string& arg);

std::map<std::string, ConfigEntryBase*> entries_;

const ConfigEntryBase* entry(const std::string& key) const {
auto e = entries_.find(key);
if (e == entries_.end()) return nullptr;
return e->second;
}
};

#endif // config_h_
38 changes: 38 additions & 0 deletions external_tests/nss_bogo_shim/config.json
@@ -0,0 +1,38 @@
{
"DisabledTests": {
"*TLS13*":"TLS 1.3: Draft version mismatch",
"*HelloRetryRequest*":"TLS 1.3: Draft version mismatch",
"SecondClientHelloWrongCurve":"TLS 1.3: Draft version mismatch",
"KeyUpdate":"TLS 1.3: Draft version mismatch",
"*KeyShare*":"TLS 1.3: Draft version mismatch",
"FragmentedClientVersion":"TLS 1.3: Draft version mismatch",
"*VersionTolerance":"TLS 1.3: Draft version mismatch",
"Downgrade-TLS12-*":"TLS 1.3: Draft version mismatch",
"ClientAuth-SHA1-Fallback":"TLS 1.3: Draft version mismatch",
"NoSupportedCurves":"TLS 1.3: Draft version mismatch",
"SendEmptyRecords-Pass":"TLS 1.3: Draft version mismatch",
"*SSL3*":"NSS disables SSLv3",
"*SSLv3*":"NSS disables SSLv3",
"*AES256*":"Inconsistent support for AES256",
"*AES128-SHA256*":"No support for Suite B ciphers",
"*CHACHA20-POLY1305-OLD*":"Old ChaCha/Poly",
"DuplicateExtension*":"NSS sends unexpected_extension alert",
"WeakDH":"NSS supports 768-bit DH",
"SillyDH":"NSS supports 4097-bit DH",
"SendWarningAlerts":"This appears to be Boring-specific",
"V2ClientHello-WarningAlertPrefix":"Bug 1292893",
"TLS12-AES128-GCM-client":"Bug 1292895",
"*TLS12-AES128-GCM-LargeRecord*":"Bug 1292895",
"Renegotiate-Client-Forbidden-1":"Bug 1292898",
"Renegotiate-Server-Forbidden":"NSS doesn't disable renegotiation by default",
"Renegotiate-Client-NoIgnore":"NSS doesn't disable renegotiation by default",
"StrayHelloRequest*":"NSS doesn't disable renegotiation by default"
},
"ErrorMap" : {
":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:":"SSL_ERROR_NO_CYPHER_OVERLAP",
":UNKNOWN_CIPHER_RETURNED:":"SSL_ERROR_NO_CYPHER_OVERLAP",
":OLD_SESSION_CIPHER_NOT_RETURNED:":"SSL_ERROR_NO_CYPHER_OVERLAP",
":NO_SHARED_CIPHER:":"SSL_ERROR_NO_CYPHER_OVERLAP"
}
}

20 changes: 20 additions & 0 deletions external_tests/nss_bogo_shim/manifest.mn
@@ -0,0 +1,20 @@
#
# 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/.
CORE_DEPTH = ../..
DEPTH = ../..
MODULE = nss

CPPSRCS = \
config.cc \
nsskeys.cc \
nss_bogo_shim.cc \
$(NULL)

REQUIRES = nspr nss libdbm

PROGRAM = nss_bogo_shim
#EXTRA_LIBS = $(DIST)/lib/$(LIB_PREFIX)softokn.$(LIB_SUFFIX)

USE_STATIC_LIBS = 1

0 comments on commit 7582395

Please sign in to comment.