| 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. |
| 23 // |
| 24 // At its core, a trust anchor has three parts: |
| 25 // * Name |
| 26 // * Public Key |
| 27 // * Constraints |
| 28 // |
| 29 // For convenience trust anchors are often described using a self-signed |
| 30 // certificate, and this class mirrors that representation. |
| 31 // |
| 32 // However note that a TrustAnchor is NOT the same thing as a certificate. |
| 33 // Properties of a certificate like expiration and signature are not considered |
| 34 // for trust anchors during path validation. Trust anchors can have equivalent |
| 35 // constraints for extensions like name constraints, policy, basic constraints |
| 36 // path len, however those anchor constraints need to be specified explicitly. |
| 37 // See RFC 5937. |
| 38 // |
| 39 // TODO(crbug.com/635200): Support anchor constraints. |
| 40 class NET_EXPORT TrustAnchor : public base::RefCountedThreadSafe<TrustAnchor> { |
| 41 public: |
| 42 // Creates a TrustAnchor given a certificate. The only parts of the |
| 43 // certificate that will be used are the subject and SPKI. Any extensions in |
| 44 // the certificate that might limit its use (like name constraints or policy) |
| 45 // are disregarded during validation. In other words, the resulting trust |
| 46 // anchor has no anchor constraints. |
| 47 static scoped_refptr<TrustAnchor> CreateFromCertificateNoConstraints( |
| 48 scoped_refptr<ParsedCertificate> cert); |
| 49 |
| 50 der::Input spki() const; |
| 51 der::Input normalized_subject() const; |
| 52 |
| 53 // Returns the certificate representing this trust anchor. |
| 54 const scoped_refptr<ParsedCertificate>& cert() const; |
| 55 |
| 56 private: |
| 57 friend class base::RefCountedThreadSafe<TrustAnchor>; |
| 58 explicit TrustAnchor(scoped_refptr<ParsedCertificate>); |
| 59 ~TrustAnchor(); |
| 60 |
| 61 scoped_refptr<ParsedCertificate> cert_; |
| 62 }; |
| 63 |
| 64 using TrustAnchors = std::vector<scoped_refptr<TrustAnchor>>; |
| 65 |
| 22 // A very simple implementation of a TrustStore, which contains a set of | 66 // A very simple implementation of a TrustStore, which contains a set of |
| 23 // trusted certificates. | 67 // trust anchors. |
| 68 // |
| 24 // TODO(mattm): convert this into an interface, provide implementations that | 69 // TODO(mattm): convert this into an interface, provide implementations that |
| 25 // interface with OS trust store. | 70 // interface with OS trust store. |
| 26 class NET_EXPORT TrustStore { | 71 class NET_EXPORT TrustStore { |
| 27 public: | 72 public: |
| 28 TrustStore(); | 73 TrustStore(); |
| 29 ~TrustStore(); | 74 ~TrustStore(); |
| 30 | 75 |
| 31 // Empties the trust store, resetting it to original state. | 76 // Empties the trust store, resetting it to original state. |
| 32 void Clear(); | 77 void Clear(); |
| 33 | 78 |
| 34 // Adds a trusted certificate to the store. | 79 void AddTrustAnchor(scoped_refptr<TrustAnchor> anchor); |
| 35 void AddTrustedCertificate(scoped_refptr<ParsedCertificate> anchor); | |
| 36 | 80 |
| 37 // Returns the trust anchors that match |name| in |*matches|, if any. | 81 // Returns the trust anchors that match |name| in |*matches|, if any. |
| 38 void FindTrustAnchorsByNormalizedName(const der::Input& normalized_name, | 82 void FindTrustAnchorsByNormalizedName(const der::Input& normalized_name, |
| 39 ParsedCertificateList* matches) const; | 83 TrustAnchors* matches) const; |
| 40 | |
| 41 // Returns true if |cert| matches a certificate in the TrustStore. | |
| 42 bool IsTrustedCertificate(const ParsedCertificate* cert) const | |
| 43 WARN_UNUSED_RESULT; | |
| 44 | 84 |
| 45 private: | 85 private: |
| 46 // Multimap from normalized subject -> ParsedCertificate. | 86 // Multimap from normalized subject -> TrustAnchor. |
| 47 std::unordered_multimap<base::StringPiece, | 87 std::unordered_multimap<base::StringPiece, |
| 48 scoped_refptr<ParsedCertificate>, | 88 scoped_refptr<TrustAnchor>, |
| 49 base::StringPieceHash> | 89 base::StringPieceHash> |
| 50 anchors_; | 90 anchors_; |
| 51 | 91 |
| 52 DISALLOW_COPY_AND_ASSIGN(TrustStore); | 92 DISALLOW_COPY_AND_ASSIGN(TrustStore); |
| 53 }; | 93 }; |
| 54 | 94 |
| 55 } // namespace net | 95 } // namespace net |
| 56 | 96 |
| 57 #endif // NET_CERT_INTERNAL_TRUST_STORE_H_ | 97 #endif // NET_CERT_INTERNAL_TRUST_STORE_H_ |
| OLD | NEW |