Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(836)

Side by Side Diff: net/cert/internal/parse_certificate_fuzzer.cc

Issue 2366493003: Simplify parse_certificate_fuzzer. (Closed)
Patch Set: rebase Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <stddef.h> 5 #include <stddef.h>
6 #include <stdint.h> 6 #include <stdint.h>
7 7
8 #include "base/macros.h" 8 #include "base/macros.h"
9 #include "net/cert/internal/cert_errors.h" 9 #include "net/cert/internal/cert_errors.h"
10 #include "net/cert/internal/certificate_policies.h" 10 #include "net/cert/internal/parsed_certificate.h"
11 #include "net/cert/internal/extended_key_usage.h"
12 #include "net/cert/internal/name_constraints.h"
13 #include "net/cert/internal/parse_certificate.h"
14 #include "net/cert/internal/parse_name.h"
15 #include "net/cert/internal/signature_algorithm.h"
16 #include "net/cert/internal/signature_policy.h"
17 #include "net/cert/internal/verify_signed_data.h"
18
19 namespace net {
20 namespace {
21
22 bool FindExtension(const der::Input& oid,
23 std::map<der::Input, ParsedExtension>* extensions,
24 ParsedExtension* extension) {
25 auto it = extensions->find(oid);
26 if (it == extensions->end())
27 return false;
28 *extension = it->second;
29 return true;
30 }
31
32 void ParseCertificateForFuzzer(const der::Input& in) {
33 der::Input tbs_certificate_tlv;
34 der::Input signature_algorithm_tlv;
35 der::BitString signature_value;
36 CertErrors errors;
37 if (!ParseCertificate(in, &tbs_certificate_tlv, &signature_algorithm_tlv,
38 &signature_value, &errors))
39 return;
40 std::unique_ptr<SignatureAlgorithm> sig_alg(
41 SignatureAlgorithm::Create(signature_algorithm_tlv, &errors));
42
43 ParsedTbsCertificate tbs;
44 if (!ParseTbsCertificate(tbs_certificate_tlv, {}, &tbs, &errors))
45 return;
46
47 RDNSequence subject;
48 ignore_result(ParseName(tbs.subject_tlv, &subject));
49
50 std::map<der::Input, ParsedExtension> extensions;
51 if (tbs.has_extensions && ParseExtensions(tbs.extensions_tlv, &extensions)) {
52 ParsedExtension extension;
53 ParsedBasicConstraints basic_constraints;
54 der::BitString key_usage;
55 std::vector<der::Input> policies;
56 std::vector<der::Input> eku_oids;
57 std::vector<base::StringPiece> ca_issuers_uris;
58 std::vector<base::StringPiece> ocsp_uris;
59 if (FindExtension(BasicConstraintsOid(), &extensions, &extension))
60 ignore_result(ParseBasicConstraints(extension.value, &basic_constraints));
61 if (FindExtension(KeyUsageOid(), &extensions, &extension))
62 ignore_result(ParseKeyUsage(extension.value, &key_usage));
63 if (FindExtension(SubjectAltNameOid(), &extensions, &extension))
64 GeneralNames::Create(extension.value);
65 if (FindExtension(CertificatePoliciesOid(), &extensions, &extension))
66 ParseCertificatePoliciesExtension(extension.value, &policies);
67 if (FindExtension(ExtKeyUsageOid(), &extensions, &extension))
68 ParseEKUExtension(extension.value, &eku_oids);
69 if (FindExtension(AuthorityInfoAccessOid(), &extensions, &extension))
70 ignore_result(ParseAuthorityInfoAccess(extension.value, &ca_issuers_uris,
71 &ocsp_uris));
72 }
73 }
74
75 } // namespace
76 } // namespace net
77 11
78 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { 12 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
79 net::der::Input in(data, size); 13 net::CertErrors errors;
80 net::ParseCertificateForFuzzer(in); 14 scoped_refptr<net::ParsedCertificate> cert =
15 net::ParsedCertificate::Create(data, size, {}, &errors);
16
17 // TODO(crbug.com/634443): Ensure that !errors.empty() on parsing failure.
81 return 0; 18 return 0;
82 } 19 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698