Line | Count | Source |
1 | | // Copyright 2020 Google Inc. |
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 | | // This fuzz target fuzzes the same API as |
18 | | // https://github.com/google/boringssl/blob/master/fuzz/pkcs12.cc, but it |
19 | | // employs libprotobuf-mutator for structure-aware fuzzing. |
20 | | |
21 | | #include <openssl/bytestring.h> |
22 | | #include <openssl/evp.h> |
23 | | #include <openssl/pkcs8.h> |
24 | | #include <openssl/x509.h> |
25 | | #include "asn1_pdu.pb.h" |
26 | | #include "asn1_pdu_to_der.h" |
27 | | #include "libprotobuf-mutator/src/libfuzzer/libfuzzer_macro.h" |
28 | | |
29 | 2.18k | DEFINE_PROTO_FUZZER(const asn1_pdu::PDU& asn1) { |
30 | 2.18k | asn1_pdu::ASN1PDUToDER converter; |
31 | 2.18k | std::vector<uint8_t> encoded = converter.PDUToDER(asn1); |
32 | 2.18k | const uint8_t* buf = encoded.data(); |
33 | 2.18k | size_t len = encoded.size(); |
34 | | |
35 | 2.18k | bssl::UniquePtr<STACK_OF(X509)> certs(sk_X509_new_null()); |
36 | 2.18k | EVP_PKEY* key = nullptr; |
37 | 2.18k | CBS cbs; |
38 | 2.18k | CBS_init(&cbs, buf, len); |
39 | 2.18k | PKCS12_get_key_and_certs(&key, certs.get(), &cbs, "foo"); |
40 | 2.18k | EVP_PKEY_free(key); |
41 | 2.18k | } |