tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

pkcs12.cc (1820B)


      1 /* This Source Code Form is subject to the terms of the Mozilla Public
      2 * License, v. 2.0. If a copy of the MPL was not distributed with this
      3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      4 
      5 #include <cassert>
      6 #include <cstddef>
      7 #include <cstdint>
      8 
      9 #include "nss_scoped_ptrs.h"
     10 #include "p12.h"
     11 #include "pk11pub.h"
     12 #include "seccomon.h"
     13 
     14 #include "asn1/mutators.h"
     15 #include "base/database.h"
     16 #include "base/mutate.h"
     17 
     18 static SECItem* nicknameCollision(SECItem* oldNick, PRBool* cancel,
     19                                  void* wincx) {
     20  *cancel = true;
     21  return nullptr;
     22 }
     23 
     24 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
     25  static NSSDatabase db = NSSDatabase();
     26 
     27  ScopedPK11SlotInfo slot(PK11_GetInternalSlot());
     28  assert(slot);
     29 
     30  // Initialize the decoder.
     31  SECItem pwItem = {siBuffer, nullptr, 0};
     32  ScopedSEC_PKCS12DecoderContext dcx(
     33      SEC_PKCS12DecoderStart(&pwItem, slot.get(), nullptr, nullptr, nullptr,
     34                             nullptr, nullptr, nullptr));
     35  assert(dcx);
     36 
     37  SECStatus rv = SEC_PKCS12DecoderUpdate(dcx.get(), (unsigned char*)data, size);
     38  if (rv != SECSuccess) {
     39    return 0;
     40  }
     41 
     42  // Verify the blob.
     43  rv = SEC_PKCS12DecoderVerify(dcx.get());
     44  if (rv != SECSuccess) {
     45    return 0;
     46  }
     47 
     48  // Validate bags.
     49  rv = SEC_PKCS12DecoderValidateBags(dcx.get(), nicknameCollision);
     50  if (rv != SECSuccess) {
     51    return 0;
     52  }
     53 
     54  // Import cert and key.
     55  rv = SEC_PKCS12DecoderImportBags(dcx.get());
     56  if (rv != SECSuccess) {
     57    return 0;
     58  }
     59 
     60  return 0;
     61 }
     62 
     63 extern "C" size_t LLVMFuzzerCustomMutator(uint8_t* data, size_t size,
     64                                          size_t maxSize, unsigned int seed) {
     65  return CustomMutate(
     66      Mutators({ASN1Mutators::FlipConstructed, ASN1Mutators::ChangeType}), data,
     67      size, maxSize, seed);
     68 }