tor-browser

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

pkcs8.cc (1801B)


      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 "keyhi.h"
     10 #include "nss_scoped_ptrs.h"
     11 #include "pk11pub.h"
     12 #include "seccomon.h"
     13 #include "utilrename.h"
     14 
     15 #include "asn1/mutators.h"
     16 #include "base/database.h"
     17 #include "base/mutate.h"
     18 
     19 extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
     20  static NSSDatabase db = NSSDatabase();
     21 
     22  SECItem derPki = {siBuffer, (unsigned char *)data, (unsigned int)size};
     23 
     24  ScopedPK11SlotInfo slot(PK11_GetInternalSlot());
     25  assert(slot);
     26 
     27  SECKEYPrivateKey *privKey = nullptr;
     28  if (PK11_ImportDERPrivateKeyInfoAndReturnKey(
     29          slot.get(), &derPki, nullptr, nullptr, false, false, KU_ALL, &privKey,
     30          nullptr) != SECSuccess) {
     31    return 0;
     32  }
     33 
     34  (void)SECKEY_PrivateKeyStrengthInBits(privKey);
     35  (void)SECKEY_GetPrivateKeyType(privKey);
     36  (void)PK11_SignatureLen(privKey);
     37  (void)PK11_GetPrivateModulusLen(privKey);
     38 
     39  ScopedSECKEYPublicKey pubKey(SECKEY_ConvertToPublicKey(privKey));
     40  ScopedCERTCertificate cert(PK11_GetCertFromPrivateKey(privKey));
     41 
     42  char *nickname = PK11_GetPrivateKeyNickname(privKey);
     43  PORT_Free(nickname);
     44 
     45  SECKEYPQGParams *params = PK11_GetPQGParamsFromPrivateKey(privKey);
     46  PORT_FreeArena(params ? params->arena : nullptr, PR_FALSE);
     47 
     48  SECKEY_DestroyPrivateKey(privKey);
     49 
     50  return 0;
     51 }
     52 
     53 extern "C" size_t LLVMFuzzerCustomMutator(uint8_t *data, size_t size,
     54                                          size_t maxSize, unsigned int seed) {
     55  return CustomMutate(
     56      Mutators({ASN1Mutators::FlipConstructed, ASN1Mutators::ChangeType}), data,
     57      size, maxSize, seed);
     58 }