Coverage Report

Created: 2025-08-18 06:34

/src/nss/fuzz/targets/pkcs8.cc
Line
Count
Source (jump to first uncovered line)
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
5.76k
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
20
5.76k
  static NSSDatabase db = NSSDatabase();
21
22
5.76k
  SECItem derPki = {siBuffer, (unsigned char *)data, (unsigned int)size};
23
24
5.76k
  ScopedPK11SlotInfo slot(PK11_GetInternalSlot());
25
5.76k
  assert(slot);
26
27
5.76k
  SECKEYPrivateKey *privKey = nullptr;
28
5.76k
  if (PK11_ImportDERPrivateKeyInfoAndReturnKey(
29
5.76k
          slot.get(), &derPki, nullptr, nullptr, false, false, KU_ALL, &privKey,
30
5.76k
          nullptr) != SECSuccess) {
31
5.64k
    return 0;
32
5.64k
  }
33
34
123
  (void)SECKEY_PrivateKeyStrengthInBits(privKey);
35
123
  (void)SECKEY_GetPrivateKeyType(privKey);
36
123
  (void)PK11_SignatureLen(privKey);
37
123
  (void)PK11_GetPrivateModulusLen(privKey);
38
39
123
  ScopedSECKEYPublicKey pubKey(SECKEY_ConvertToPublicKey(privKey));
40
123
  ScopedCERTCertificate cert(PK11_GetCertFromPrivateKey(privKey));
41
42
123
  char *nickname = PK11_GetPrivateKeyNickname(privKey);
43
123
  PORT_Free(nickname);
44
45
123
  SECKEYPQGParams *params = PK11_GetPQGParamsFromPrivateKey(privKey);
46
123
  PORT_FreeArena(params ? params->arena : nullptr, PR_FALSE);
47
48
123
  SECKEY_DestroyPrivateKey(privKey);
49
50
123
  return 0;
51
5.76k
}
52
53
extern "C" size_t LLVMFuzzerCustomMutator(uint8_t *data, size_t size,
54
0
                                          size_t maxSize, unsigned int seed) {
55
0
  return CustomMutate(
56
0
      Mutators({ASN1Mutators::FlipConstructed, ASN1Mutators::ChangeType}), data,
57
0
      size, maxSize, seed);
58
0
}