Coverage Report

Created: 2026-07-26 06:24

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/phosphor-certificate-manager/fuzzing/parse_cert_fuzzer.cpp
Line
Count
Source
1
// Copyright 2026 Google LLC
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
//      http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14
//
15
//##############################################################################
16
17
#include "x509_utils.hpp"
18
#include <cstdint>
19
#include <cstddef>
20
#include <string>
21
#include <memory>
22
#include <openssl/x509.h>
23
#include <openssl/x509_vfy.h>
24
25
1.12k
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
26
1.12k
    std::string pem(reinterpret_cast<const char*>(data), size);
27
1.12k
    try {
28
1.12k
        auto cert = phosphor::certs::parseCert(pem);
29
1.12k
        if (cert) {
30
            // Validate start date
31
107
            phosphor::certs::validateCertificateStartDate(*cert);
32
33
            // Validate in SSL context
34
107
            phosphor::certs::validateCertificateInSSLContext(*cert);
35
36
            // Validate against an empty store.
37
            // Since validateCertificateAgainstStore allows trust chain errors,
38
            // this should not throw for typical untrusted certs, but will
39
            // exercise the verification logic.
40
107
            std::unique_ptr<X509_STORE, decltype(&::X509_STORE_free)> x509Store(
41
107
                X509_STORE_new(), &X509_STORE_free);
42
107
            if (x509Store) {
43
33
                phosphor::certs::validateCertificateAgainstStore(*x509Store, *cert);
44
33
            }
45
107
        }
46
1.12k
    } catch (const std::exception& e) {
47
        // Catch expected exceptions to prevent the fuzzer from treating them as crashes.
48
1.09k
    } catch (...) {
49
        // Catch any other unexpected exceptions.
50
0
    }
51
1.12k
    return 0;
52
1.12k
}