| 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 <unordered_map> | 8 #include <unordered_map> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
| 12 #include "base/strings/string_piece.h" | 12 #include "base/strings/string_piece.h" |
| 13 #include "net/base/net_export.h" | 13 #include "net/base/net_export.h" |
| 14 #include "net/cert/internal/parsed_certificate.h" | 14 #include "net/cert/internal/parsed_certificate.h" |
| 15 | 15 |
| 16 namespace net { | 16 namespace net { |
| 17 | 17 |
| 18 namespace der { | 18 namespace der { |
| 19 class Input; | 19 class Input; |
| 20 } | 20 } |
| 21 | 21 |
| 22 // A TrustAnchor represents a trust anchor used during RFC 5280 path validation. | 22 // A TrustAnchor represents a trust anchor used during RFC 5280 path validation. |
| 23 // | 23 // |
| 24 // At its core, each trust anchor has two parts: | 24 // At its core, each trust anchor has two parts: |
| 25 // * Name | 25 // * Name |
| 26 // * Public Key | 26 // * Public Key |
| 27 // | 27 // |
| 28 // Optionally a trust anchor may contain: | 28 // Optionally a trust anchor may contain: |
| 29 // * An associated certificate | 29 // * An associated certificate (used when pretty-printing) |
| 30 // * Trust anchor constraints | 30 // * Mandatory trust anchor constraints |
| 31 // | 31 // |
| 32 // Relationship between ParsedCertificate and TrustAnchor: | 32 // Relationship between ParsedCertificate and TrustAnchor: |
| 33 // | 33 // |
| 34 // For convenience trust anchors are often described using a | 34 // For convenience trust anchors are often described using a |
| 35 // (self-signed) certificate. TrustAnchor facilitates this by allowing | 35 // (self-signed) certificate. TrustAnchor facilitates this by allowing |
| 36 // construction of a TrustAnchor given a ParsedCertificate, however | 36 // construction of a TrustAnchor given a ParsedCertificate. |
| 37 // the concepts are NOT quite the same. | |
| 38 // | 37 // |
| 39 // Notably when constructed from a certificate, properties/constraints of | 38 // When constructing a TrustAnchor from a certificate there are different |
| 40 // the underlying certificate like expiration, signature, or basic | 39 // interpretations for the meaning of properties other than the Subject and |
| 41 // constraints are NOT processed and validated by path validation. | 40 // SPKI in the certificate. |
| 42 // Instead such properties need to be explicitly indicated via "trust | |
| 43 // anchor constraints". | |
| 44 // | 41 // |
| 45 // See RFC 5937 and RFC 5280 for more details. | 42 // * CreateFromCertificateNoConstraints() -- Extracts the Subject and SPKI from |
| 43 // the source certificate. ALL other information in the certificate is |
| 44 // considered irrelevant during path validation. |
| 45 // |
| 46 // * CreateFromCertificateWithConstraints() -- Extracts the Subject and SPKI |
| 47 // from the source certificate, and additionally interprets some properties of |
| 48 // the source certificate as mandatory anchor constraints. |
| 49 // |
| 50 // Trust anchor constraints are described in more detail by RFC 5937. This |
| 51 // implementation follows that description, and fixes |
| 52 // "enforceTrustAnchorConstraints" to true. |
| 46 class NET_EXPORT TrustAnchor : public base::RefCountedThreadSafe<TrustAnchor> { | 53 class NET_EXPORT TrustAnchor : public base::RefCountedThreadSafe<TrustAnchor> { |
| 47 public: | 54 public: |
| 48 // Creates a TrustAnchor given a certificate. The only parts of the | 55 // Creates a TrustAnchor given a certificate. The ONLY parts of the |
| 49 // certificate that will be used are the subject and SPKI. Any extensions in | 56 // certificate that are relevant to the resulting trust anchor are: |
| 50 // the certificate that might limit its use (like name constraints or policy) | 57 // |
| 51 // are disregarded during validation. In other words, the resulting trust | 58 // * Subject |
| 52 // anchor has no anchor constraints. | 59 // * SPKI |
| 60 // |
| 61 // Everything else, including the source certiticate's expiration, basic |
| 62 // constraints, policy constraints, etc is not used. |
| 63 // |
| 64 // This is the common interpretation for a trust anchor when given as a |
| 65 // certificate. |
| 53 static scoped_refptr<TrustAnchor> CreateFromCertificateNoConstraints( | 66 static scoped_refptr<TrustAnchor> CreateFromCertificateNoConstraints( |
| 54 scoped_refptr<ParsedCertificate> cert); | 67 scoped_refptr<ParsedCertificate> cert); |
| 55 | 68 |
| 56 // TODO(crbug.com/635200): Support anchor constraints. For instance | 69 // Creates a TrustAnchor given a certificate. The resulting trust anchor is |
| 57 // by adding factory method CreateFromCertificateWithConstraints() | 70 // initialized using the source certificate's subject and SPKI as usual, |
| 71 // however other parts of the certificate are applied as anchor constraints. |
| 72 // |
| 73 // The implementation matches the properties identified by RFC 5937, |
| 74 // resulting in the following hodgepodge of enforcement on the source |
| 75 // certificate: |
| 76 // |
| 77 // * Signature: No |
| 78 // * Validity (expiration): No |
| 79 // * Key usage: No |
| 80 // * Extended key usage: No |
| 81 // * Basic constraints: Yes, but only the pathlen (CA=false is accepted) |
| 82 // * Name constraints: Yes |
| 83 // * Certificate policies: Not currently, TODO(crbug.com/634453) |
| 84 // * inhibitAnyPolicy: Not currently, TODO(crbug.com/634453) |
| 85 // * PolicyConstraints: Not currently, TODO(crbug.com/634452) |
| 86 // |
| 87 // The presence of any other unrecognized extension marked as critical fails |
| 88 // validation. |
| 89 static scoped_refptr<TrustAnchor> CreateFromCertificateWithConstraints( |
| 90 scoped_refptr<ParsedCertificate> cert); |
| 58 | 91 |
| 59 der::Input spki() const; | 92 der::Input spki() const; |
| 60 der::Input normalized_subject() const; | 93 der::Input normalized_subject() const; |
| 61 | 94 |
| 62 // Returns the optional certificate representing this trust anchor. | 95 // Returns the optional certificate representing this trust anchor. |
| 63 // In the current implementation it will never return nullptr... | 96 // In the current implementation it will never return nullptr... |
| 64 // however clients should be prepared to handle this case. | 97 // however clients should be prepared to handle this case. |
| 65 const scoped_refptr<ParsedCertificate>& cert() const; | 98 const scoped_refptr<ParsedCertificate>& cert() const; |
| 66 | 99 |
| 100 // Returns true if the trust anchor has attached (mandatory) trust anchor |
| 101 // constraints. This returns true when the anchor was constructed using |
| 102 // CreateFromCertificateWithConstraints. |
| 103 bool enforces_constraints() const { return enforces_constraints_; } |
| 104 |
| 67 private: | 105 private: |
| 68 friend class base::RefCountedThreadSafe<TrustAnchor>; | 106 friend class base::RefCountedThreadSafe<TrustAnchor>; |
| 69 explicit TrustAnchor(scoped_refptr<ParsedCertificate>); | 107 TrustAnchor(scoped_refptr<ParsedCertificate>, bool enforces_constraints); |
| 70 ~TrustAnchor(); | 108 ~TrustAnchor(); |
| 71 | 109 |
| 72 scoped_refptr<ParsedCertificate> cert_; | 110 scoped_refptr<ParsedCertificate> cert_; |
| 111 bool enforces_constraints_ = false; |
| 73 }; | 112 }; |
| 74 | 113 |
| 75 using TrustAnchors = std::vector<scoped_refptr<TrustAnchor>>; | 114 using TrustAnchors = std::vector<scoped_refptr<TrustAnchor>>; |
| 76 | 115 |
| 77 // A very simple implementation of a TrustStore, which contains a set of | 116 // A very simple implementation of a TrustStore, which contains a set of |
| 78 // trust anchors. | 117 // trust anchors. |
| 79 // | 118 // |
| 80 // TODO(mattm): convert this into an interface, provide implementations that | 119 // TODO(mattm): convert this into an interface, provide implementations that |
| 81 // interface with OS trust store. | 120 // interface with OS trust store. |
| 82 class NET_EXPORT TrustStore { | 121 class NET_EXPORT TrustStore { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 99 scoped_refptr<TrustAnchor>, | 138 scoped_refptr<TrustAnchor>, |
| 100 base::StringPieceHash> | 139 base::StringPieceHash> |
| 101 anchors_; | 140 anchors_; |
| 102 | 141 |
| 103 DISALLOW_COPY_AND_ASSIGN(TrustStore); | 142 DISALLOW_COPY_AND_ASSIGN(TrustStore); |
| 104 }; | 143 }; |
| 105 | 144 |
| 106 } // namespace net | 145 } // namespace net |
| 107 | 146 |
| 108 #endif // NET_CERT_INTERNAL_TRUST_STORE_H_ | 147 #endif // NET_CERT_INTERNAL_TRUST_STORE_H_ |
| OLD | NEW |