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

Side by Side Diff: net/cert/internal/trust_store_in_memory.h

Issue 2832703002: Allow the TrustStore interface to return matching intermediates, and identify distrusted certs. (Closed)
Patch Set: address comments Created 3 years, 7 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
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 #ifndef NET_CERT_INTERNAL_TRUST_STORE_IN_MEMORY_H_ 5 #ifndef NET_CERT_INTERNAL_TRUST_STORE_IN_MEMORY_H_
6 #define NET_CERT_INTERNAL_TRUST_STORE_IN_MEMORY_H_ 6 #define NET_CERT_INTERNAL_TRUST_STORE_IN_MEMORY_H_
7 7
8 #include <unordered_map> 8 #include <unordered_map>
9 9
10 #include "base/memory/ref_counted.h" 10 #include "base/memory/ref_counted.h"
11 #include "base/strings/string_piece.h" 11 #include "base/strings/string_piece.h"
12 #include "net/base/net_export.h" 12 #include "net/base/net_export.h"
13 #include "net/cert/internal/trust_store.h" 13 #include "net/cert/internal/trust_store.h"
14 14
15 namespace net { 15 namespace net {
16 16
17 // A very simple implementation of a TrustStore, which contains a set of 17 // A very simple implementation of a TrustStore, which contains a set of
18 // trust anchors. 18 // certificates and their trustedness.
19 class NET_EXPORT TrustStoreInMemory : public TrustStore { 19 class NET_EXPORT TrustStoreInMemory : public TrustStore {
20 public: 20 public:
21 TrustStoreInMemory(); 21 TrustStoreInMemory();
22 ~TrustStoreInMemory() override; 22 ~TrustStoreInMemory() override;
23 23
24 // Empties the trust store, resetting it to original state. 24 // Empties the trust store, resetting it to original state.
25 void Clear(); 25 void Clear();
26 26
27 void AddTrustAnchor(scoped_refptr<TrustAnchor> anchor); 27 // Adds a certificate as a trust anchor (only the SPKI and subject will be
28 // used during verification).
29 void AddTrustAnchor(scoped_refptr<ParsedCertificate> cert);
30
31 // Adds a certificate as a trust achor and extracts anchor constraints from
32 // the certificate. See VerifyCertificateChain for details.
33 void AddTrustAnchorWithConstraints(scoped_refptr<ParsedCertificate> cert);
34
35 // TODO(eroman): This is marked "ForTest" as the current implementation
36 // requires an exact match on the certificate DER (a wider match by say
37 // issuer/serial is probably what we would want for a real implementation).
38 void AddDistrustedCertificateForTest(scoped_refptr<ParsedCertificate> cert);
28 39
29 // TrustStore implementation: 40 // TrustStore implementation:
30 void FindTrustAnchorsForCert(const scoped_refptr<ParsedCertificate>& cert, 41 void SyncGetIssuersOf(const ParsedCertificate* cert,
31 TrustAnchors* matches) const override; 42 ParsedCertificateList* issuers) override;
43 void GetTrust(const scoped_refptr<ParsedCertificate>& cert,
44 CertificateTrust* trust) const override;
32 45
33 // Returns true if the trust store contains the given TrustAnchor instance. 46 // Returns true if the trust store contains the given ParsedCertificate
34 // Note that this considers only pointer equality and not a more 47 // (matches by DER).
35 // broad notion of equivalence based on the object's content. 48 bool Contains(const ParsedCertificate* cert) const;
36 bool Contains(const TrustAnchor* anchor) const;
37 49
38 private: 50 private:
39 // Multimap from normalized subject -> TrustAnchor. 51 struct Entry {
40 std::unordered_multimap<base::StringPiece, 52 Entry();
41 scoped_refptr<TrustAnchor>, 53 Entry(const Entry& other);
42 base::StringPieceHash> 54 ~Entry();
43 anchors_; 55
56 scoped_refptr<ParsedCertificate> cert;
57 CertificateTrust trust;
58 };
59
60 // Multimap from normalized subject -> Entry.
61 std::unordered_multimap<base::StringPiece, Entry, base::StringPieceHash>
62 entries_;
63
64 // Adds a certificate with the specified trust settings. Both trusted and
65 // distrusted certificates require a full DER match.
66 void AddCertificate(scoped_refptr<ParsedCertificate> cert,
67 const CertificateTrust& trust);
44 68
45 DISALLOW_COPY_AND_ASSIGN(TrustStoreInMemory); 69 DISALLOW_COPY_AND_ASSIGN(TrustStoreInMemory);
46 }; 70 };
47 71
48 } // namespace net 72 } // namespace net
49 73
50 #endif // NET_CERT_INTERNAL_TRUST_STORE_IN_MEMORY_H_ 74 #endif // NET_CERT_INTERNAL_TRUST_STORE_IN_MEMORY_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698