OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "net/cert/internal/verify_certificate_chain.h" | 5 #include "net/cert/internal/verify_certificate_chain.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "net/cert/internal/parse_certificate.h" | 8 #include "net/cert/internal/parse_certificate.h" |
9 #include "net/cert/internal/signature_algorithm.h" | 9 #include "net/cert/internal/signature_algorithm.h" |
10 #include "net/cert/internal/signature_policy.h" | 10 #include "net/cert/internal/signature_policy.h" |
11 #include "net/cert/internal/verify_name_match.h" | 11 #include "net/cert/internal/verify_name_match.h" |
12 #include "net/cert/internal/verify_signed_data.h" | 12 #include "net/cert/internal/verify_signed_data.h" |
13 #include "net/der/input.h" | 13 #include "net/der/input.h" |
14 #include "net/der/parser.h" | 14 #include "net/der/parser.h" |
15 | 15 |
16 namespace net { | 16 namespace net { |
17 | 17 |
18 namespace { | 18 namespace { |
19 | 19 |
20 // TODO(eroman): Move into net/der (duplicated from test_helpers.cc). | |
21 static der::Input InputFromString(const std::string* s) { | |
22 return der::Input(reinterpret_cast<const uint8_t*>(s->data()), s->size()); | |
23 } | |
24 | |
25 // Map from OID to ParsedExtension. | 20 // Map from OID to ParsedExtension. |
26 using ExtensionsMap = std::map<der::Input, ParsedExtension>; | 21 using ExtensionsMap = std::map<der::Input, ParsedExtension>; |
27 | 22 |
28 // Describes all parsed properties of a certificate that are relevant for | 23 // Describes all parsed properties of a certificate that are relevant for |
29 // certificate verification. | 24 // certificate verification. |
30 struct FullyParsedCert { | 25 struct FullyParsedCert { |
31 ParsedCertificate cert; | 26 ParsedCertificate cert; |
32 ParsedTbsCertificate tbs; | 27 ParsedTbsCertificate tbs; |
33 | 28 |
34 scoped_ptr<SignatureAlgorithm> signature_algorithm; | 29 scoped_ptr<SignatureAlgorithm> signature_algorithm; |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 // | 165 // |
171 // TODO(eroman): This implementation is linear in the size of the trust store, | 166 // TODO(eroman): This implementation is linear in the size of the trust store, |
172 // and also presumes that all names are unique. In practice it is possible to | 167 // and also presumes that all names are unique. In practice it is possible to |
173 // have multiple SPKIs with the same name. Also this mechanism of | 168 // have multiple SPKIs with the same name. Also this mechanism of |
174 // searching is fairly primitive, and does not take advantage of other | 169 // searching is fairly primitive, and does not take advantage of other |
175 // properties like the authority key id. | 170 // properties like the authority key id. |
176 WARN_UNUSED_RESULT const TrustAnchor* FindTrustAnchorByName( | 171 WARN_UNUSED_RESULT const TrustAnchor* FindTrustAnchorByName( |
177 const TrustStore& trust_store, | 172 const TrustStore& trust_store, |
178 const der::Input& name) { | 173 const der::Input& name) { |
179 for (const auto& anchor : trust_store.anchors) { | 174 for (const auto& anchor : trust_store.anchors) { |
180 if (NameMatches(name, InputFromString(&anchor.name))) | 175 if (NameMatches(name, der::Input(&anchor.name))) |
181 return &anchor; | 176 return &anchor; |
182 } | 177 } |
183 return nullptr; | 178 return nullptr; |
184 } | 179 } |
185 | 180 |
186 // Returns true if |cert| is valid at time |time|. | 181 // Returns true if |cert| is valid at time |time|. |
187 // | 182 // |
188 // The certificate's validity requirements are described by RFC 5280 section | 183 // The certificate's validity requirements are described by RFC 5280 section |
189 // 4.1.2.5: | 184 // 4.1.2.5: |
190 // | 185 // |
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
512 | 507 |
513 // When processing the first certificate, initialize |working_spki| | 508 // When processing the first certificate, initialize |working_spki| |
514 // and |working_issuer_name| to the trust anchor per RFC 5280 section 6.1.2. | 509 // and |working_issuer_name| to the trust anchor per RFC 5280 section 6.1.2. |
515 // This is done inside the loop in order to have access to the parsed | 510 // This is done inside the loop in order to have access to the parsed |
516 // certificate. | 511 // certificate. |
517 if (i == 0) { | 512 if (i == 0) { |
518 const TrustAnchor* trust_anchor = | 513 const TrustAnchor* trust_anchor = |
519 FindTrustAnchorByName(trust_store, cert.tbs.issuer_tlv); | 514 FindTrustAnchorByName(trust_store, cert.tbs.issuer_tlv); |
520 if (!trust_anchor) | 515 if (!trust_anchor) |
521 return false; | 516 return false; |
522 working_spki = InputFromString(&trust_anchor->spki); | 517 working_spki = der::Input(&trust_anchor->spki); |
523 working_issuer_name = InputFromString(&trust_anchor->name); | 518 working_issuer_name = der::Input(&trust_anchor->name); |
524 } | 519 } |
525 | 520 |
526 // Per RFC 5280 section 6.1: | 521 // Per RFC 5280 section 6.1: |
527 // * Do basic processing for each certificate | 522 // * Do basic processing for each certificate |
528 // * If it is the last certificate in the path (target certificate) | 523 // * If it is the last certificate in the path (target certificate) |
529 // - Then run "Wrap up" | 524 // - Then run "Wrap up" |
530 // - Otherwise run "Prepare for Next cert" | 525 // - Otherwise run "Prepare for Next cert" |
531 if (!BasicCertificateProcessing(cert, signature_policy, time, working_spki, | 526 if (!BasicCertificateProcessing(cert, signature_policy, time, working_spki, |
532 working_issuer_name)) { | 527 working_issuer_name)) { |
533 return false; | 528 return false; |
(...skipping 11 matching lines...) Expand all Loading... |
545 | 540 |
546 // TODO(eroman): RFC 5280 forbids duplicate certificates per section 6.1: | 541 // TODO(eroman): RFC 5280 forbids duplicate certificates per section 6.1: |
547 // | 542 // |
548 // A certificate MUST NOT appear more than once in a prospective | 543 // A certificate MUST NOT appear more than once in a prospective |
549 // certification path. | 544 // certification path. |
550 | 545 |
551 return true; | 546 return true; |
552 } | 547 } |
553 | 548 |
554 } // namespace net | 549 } // namespace net |
OLD | NEW |