| OLD | NEW |
| 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 #ifndef NET_CERT_INTERNAL_TRUST_STORE_H_ | 5 #ifndef NET_CERT_INTERNAL_TRUST_STORE_H_ |
| 6 #define NET_CERT_INTERNAL_TRUST_STORE_H_ | 6 #define NET_CERT_INTERNAL_TRUST_STORE_H_ |
| 7 | 7 |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
| 11 #include "net/base/net_export.h" | 11 #include "net/base/net_export.h" |
| 12 #include "net/cert/internal/cert_issuer_source.h" |
| 12 #include "net/cert/internal/parsed_certificate.h" | 13 #include "net/cert/internal/parsed_certificate.h" |
| 13 | 14 |
| 14 namespace net { | 15 namespace net { |
| 15 | 16 |
| 16 namespace der { | 17 enum class CertificateTrustType { |
| 17 class Input; | 18 // This certificate is explicitly blacklisted (distrusted). |
| 18 } | 19 DISTRUSTED, |
| 19 | 20 |
| 20 // A TrustAnchor represents a trust anchor used during RFC 5280 path validation. | 21 // The trustedness of this certificate is unknown (inherits trust from |
| 21 // | 22 // its issuer). |
| 22 // At its core, each trust anchor has two parts: | 23 UNSPECIFIED, |
| 23 // * Name | |
| 24 // * Public Key | |
| 25 // | |
| 26 // Optionally a trust anchor may contain: | |
| 27 // * An associated certificate (used when pretty-printing) | |
| 28 // * Mandatory trust anchor constraints | |
| 29 // | |
| 30 // Relationship between ParsedCertificate and TrustAnchor: | |
| 31 // | |
| 32 // For convenience trust anchors are often described using a | |
| 33 // (self-signed) certificate. TrustAnchor facilitates this by allowing | |
| 34 // construction of a TrustAnchor given a ParsedCertificate. | |
| 35 // | |
| 36 // When constructing a TrustAnchor from a certificate there are different | |
| 37 // interpretations for the meaning of properties other than the Subject and | |
| 38 // SPKI in the certificate. | |
| 39 // | |
| 40 // * CreateFromCertificateNoConstraints() -- Extracts the Subject and SPKI from | |
| 41 // the source certificate. ALL other information in the certificate is | |
| 42 // considered irrelevant during path validation. | |
| 43 // | |
| 44 // * CreateFromCertificateWithConstraints() -- Extracts the Subject and SPKI | |
| 45 // from the source certificate, and additionally interprets some properties of | |
| 46 // the source certificate as mandatory anchor constraints. | |
| 47 // | |
| 48 // Trust anchor constraints are described in more detail by RFC 5937. This | |
| 49 // implementation follows that description, and fixes | |
| 50 // "enforceTrustAnchorConstraints" to true. | |
| 51 class NET_EXPORT TrustAnchor : public base::RefCountedThreadSafe<TrustAnchor> { | |
| 52 public: | |
| 53 // Creates a TrustAnchor given a certificate. The ONLY parts of the | |
| 54 // certificate that are relevant to the resulting trust anchor are: | |
| 55 // | |
| 56 // * Subject | |
| 57 // * SPKI | |
| 58 // | |
| 59 // Everything else, including the source certiticate's expiration, basic | |
| 60 // constraints, policy constraints, etc is not used. | |
| 61 // | |
| 62 // This is the common interpretation for a trust anchor when given as a | |
| 63 // certificate. | |
| 64 static scoped_refptr<TrustAnchor> CreateFromCertificateNoConstraints( | |
| 65 scoped_refptr<ParsedCertificate> cert); | |
| 66 | 24 |
| 67 // Creates a TrustAnchor given a certificate. The resulting trust anchor is | 25 // This certificate is a trust anchor (as defined by RFC 5280). The only |
| 68 // initialized using the source certificate's subject and SPKI as usual, | 26 // fields in the certificate that are meaningful are its name and SPKI. |
| 69 // however other parts of the certificate are applied as anchor constraints. | 27 TRUSTED_ANCHOR, |
| 70 // | |
| 71 // The implementation matches the properties identified by RFC 5937, | |
| 72 // resulting in the following hodgepodge of enforcement on the source | |
| 73 // certificate: | |
| 74 // | |
| 75 // * Signature: No | |
| 76 // * Validity (expiration): No | |
| 77 // * Key usage: No | |
| 78 // * Extended key usage: Yes (not part of RFC 5937) | |
| 79 // * Basic constraints: Yes, but only the pathlen (CA=false is accepted) | |
| 80 // * Name constraints: Yes | |
| 81 // * Certificate policies: Not currently, TODO(crbug.com/634453) | |
| 82 // * inhibitAnyPolicy: Not currently, TODO(crbug.com/634453) | |
| 83 // * PolicyConstraints: Not currently, TODO(crbug.com/634452) | |
| 84 // | |
| 85 // The presence of any other unrecognized extension marked as critical fails | |
| 86 // validation. | |
| 87 static scoped_refptr<TrustAnchor> CreateFromCertificateWithConstraints( | |
| 88 scoped_refptr<ParsedCertificate> cert); | |
| 89 | 28 |
| 90 der::Input spki() const; | 29 // This certificate is a trust anchor, and additionally some of the fields in |
| 91 der::Input normalized_subject() const; | 30 // the certificate (other than name and SPKI) should be used during the |
| 92 | 31 // verification process. See VerifyCertificateChain() for details on how |
| 93 // Returns the optional certificate representing this trust anchor. | 32 // constraints are applied. |
| 94 // In the current implementation it will never return nullptr... | 33 TRUSTED_ANCHOR_WITH_CONSTRAINTS, |
| 95 // however clients should be prepared to handle this case. | |
| 96 const scoped_refptr<ParsedCertificate>& cert() const; | |
| 97 | |
| 98 // Returns true if the trust anchor has attached (mandatory) trust anchor | |
| 99 // constraints. This returns true when the anchor was constructed using | |
| 100 // CreateFromCertificateWithConstraints. | |
| 101 bool enforces_constraints() const { return enforces_constraints_; } | |
| 102 | |
| 103 private: | |
| 104 friend class base::RefCountedThreadSafe<TrustAnchor>; | |
| 105 TrustAnchor(scoped_refptr<ParsedCertificate>, bool enforces_constraints); | |
| 106 ~TrustAnchor(); | |
| 107 | |
| 108 scoped_refptr<ParsedCertificate> cert_; | |
| 109 bool enforces_constraints_ = false; | |
| 110 }; | 34 }; |
| 111 | 35 |
| 112 using TrustAnchors = std::vector<scoped_refptr<TrustAnchor>>; | 36 // Describes the level of trust in a certificate. See CertificateTrustType for |
| 37 // details. |
| 38 // |
| 39 // TODO(eroman): Right now this is just a glorified wrapper around an enum... |
| 40 struct NET_EXPORT CertificateTrust { |
| 41 static CertificateTrust ForTrustAnchor(); |
| 42 static CertificateTrust ForTrustAnchorEnforcingConstraints(); |
| 43 static CertificateTrust ForUnspecified(); |
| 44 static CertificateTrust ForDistrusted(); |
| 113 | 45 |
| 114 // Interface for finding trust anchors. | 46 bool IsTrustAnchor() const; |
| 115 class NET_EXPORT TrustStore { | 47 bool IsDistrusted() const; |
| 48 bool HasUnspecifiedTrust() const; |
| 49 |
| 50 CertificateTrustType type = CertificateTrustType::UNSPECIFIED; |
| 51 }; |
| 52 |
| 53 // Interface for finding intermediates / trust anchors, and testing the |
| 54 // trustedness of certificates. |
| 55 class NET_EXPORT TrustStore : public CertIssuerSource { |
| 116 public: | 56 public: |
| 117 TrustStore(); | 57 TrustStore(); |
| 118 virtual ~TrustStore(); | |
| 119 | 58 |
| 120 // Appends the trust anchors that match |cert|'s issuer name to |*matches|. | 59 virtual void GetTrust(const scoped_refptr<ParsedCertificate>& cert, |
| 121 // |cert| and |matches| must not be null. | 60 CertificateTrust* trust) const = 0; |
| 122 virtual void FindTrustAnchorsForCert( | 61 |
| 123 const scoped_refptr<ParsedCertificate>& cert, | 62 // Disable async issuers for TrustStore, as it isn't needed. |
| 124 TrustAnchors* matches) const = 0; | 63 void AsyncGetIssuersOf(const ParsedCertificate* cert, |
| 64 std::unique_ptr<Request>* out_req) final; |
| 125 | 65 |
| 126 private: | 66 private: |
| 127 DISALLOW_COPY_AND_ASSIGN(TrustStore); | 67 DISALLOW_COPY_AND_ASSIGN(TrustStore); |
| 128 }; | 68 }; |
| 129 | 69 |
| 130 } // namespace net | 70 } // namespace net |
| 131 | 71 |
| 132 #endif // NET_CERT_INTERNAL_TRUST_STORE_H_ | 72 #endif // NET_CERT_INTERNAL_TRUST_STORE_H_ |
| OLD | NEW |