/src/nss/fuzz/targets/pkcs7.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 <cstddef> |
6 | | #include <cstdint> |
7 | | |
8 | | #include "cert.h" |
9 | | #include "nss_scoped_ptrs.h" |
10 | | #include "prtime.h" |
11 | | #include "prtypes.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 | | ScopedCERTCertificate cert( |
23 | | CERT_DecodeCertFromPackage((char *)data, (int)size)); |
24 | | if (!cert) { |
25 | | return 0; |
26 | | } |
27 | | |
28 | | SECCertificateUsage usage; |
29 | | SECItem der; |
30 | | |
31 | | (void)CERT_VerifyCertificateNow(CERT_GetDefaultCertDB(), cert.get(), PR_TRUE, |
32 | | certificateUsageCheckAllUsages, nullptr, |
33 | | &usage); |
34 | | (void)CERT_VerifyCertName(cert.get(), "fuzz.host"); |
35 | | (void)CERT_GetCertificateDer(cert.get(), &der); |
36 | | |
37 | | ScopedSECKEYPublicKey pubk(CERT_ExtractPublicKey(cert.get())); |
38 | | ScopedCERTCertList chain( |
39 | | CERT_GetCertChainFromCert(cert.get(), PR_Now(), certUsageEmailSigner)); |
40 | | |
41 | | CERTCertNicknames *patterns = CERT_GetValidDNSPatternsFromCert(cert.get()); |
42 | | PORT_FreeArena(patterns ? patterns->arena : nullptr, PR_FALSE); |
43 | | |
44 | | return 0; |
45 | | } |
46 | | |
47 | | extern "C" size_t LLVMFuzzerCustomMutator(uint8_t *data, size_t size, |
48 | 0 | size_t maxSize, unsigned int seed) { |
49 | 0 | return CustomMutate( |
50 | 0 | Mutators({ASN1Mutators::FlipConstructed, ASN1Mutators::ChangeType}), data, |
51 | 0 | size, maxSize, seed); |
52 | 0 | } |