fuzz/nssfuzz/cert_target.cc
author Ted Mielczarek <ted@mielczarek.org>
Fri, 23 Sep 2016 15:12:59 -0400
changeset 12708 21dacf6b07fee05fd2ea3541d5e8899077c31325
parent 12706 920f90ee03a61ae7021607a232e560345e6a6412
permissions -rw-r--r--
bug 1237872 - Add gyp build system for NSS. r=fkiefer

/* -*- 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 <assert.h>
#include <stdint.h>
#include <memory>

#include "cert.h"

#include "registry.h"
#include "shared.h"

extern "C" int cert_fuzzing_target(const uint8_t *Data, size_t Size) {
  SECItem data = {siBuffer, (unsigned char *)Data, (unsigned int)Size};

  static std::unique_ptr<NSSDatabase> db(new NSSDatabase());
  assert(db != nullptr);

  static CERTCertDBHandle *certDB = CERT_GetDefaultCertDB();
  assert(certDB != NULL);

  CERTCertificate *cert =
      CERT_NewTempCertificate(certDB, &data, nullptr, false, true);

  if (cert) {
    CERT_DestroyCertificate(cert);
  }

  return 0;
}

REGISTER_FUZZING_TARGET("cert", cert_fuzzing_target, 3072, "Certificate Import")