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 #include "net/cert/internal/trust_store_in_memory.h" | 5 #include "net/cert/internal/trust_store_in_memory.h" |
6 | 6 |
7 namespace net { | 7 namespace net { |
8 | 8 |
9 TrustStoreInMemory::TrustStoreInMemory() = default; | 9 TrustStoreInMemory::TrustStoreInMemory() = default; |
10 TrustStoreInMemory::~TrustStoreInMemory() = default; | 10 TrustStoreInMemory::~TrustStoreInMemory() = default; |
11 | 11 |
12 void TrustStoreInMemory::Clear() { | 12 void TrustStoreInMemory::Clear() { |
13 anchors_.clear(); | 13 entries_.clear(); |
14 } | 14 } |
15 | 15 |
16 void TrustStoreInMemory::AddTrustAnchor(scoped_refptr<TrustAnchor> anchor) { | 16 void TrustStoreInMemory::AddTrustAnchor(scoped_refptr<ParsedCertificate> cert) { |
17 // TODO(mattm): should this check for duplicate anchors? | 17 AddCertificate(std::move(cert), CertificateTrust::ForTrustAnchor()); |
18 anchors_.insert(std::make_pair(anchor->normalized_subject().AsStringPiece(), | |
19 std::move(anchor))); | |
20 } | 18 } |
21 | 19 |
22 void TrustStoreInMemory::FindTrustAnchorsForCert( | 20 void TrustStoreInMemory::AddTrustAnchorWithConstraints( |
23 const scoped_refptr<ParsedCertificate>& cert, | 21 scoped_refptr<ParsedCertificate> cert) { |
24 TrustAnchors* matches) const { | 22 AddCertificate(std::move(cert), |
25 auto range = anchors_.equal_range(cert->normalized_issuer().AsStringPiece()); | 23 CertificateTrust::ForTrustAnchorEnforcingConstraints()); |
26 for (auto it = range.first; it != range.second; ++it) | |
27 matches->push_back(it->second); | |
28 } | 24 } |
29 | 25 |
30 bool TrustStoreInMemory::Contains(const TrustAnchor* anchor) const { | 26 void TrustStoreInMemory::AddCertificate(scoped_refptr<ParsedCertificate> cert, |
31 for (const auto& it : anchors_) { | 27 const CertificateTrust& trust) { |
32 if (anchor == it.second.get()) | 28 Entry entry; |
| 29 entry.cert = std::move(cert); |
| 30 entry.trust = trust; |
| 31 |
| 32 // TODO(mattm): should this check for duplicate certificates? |
| 33 entries_.insert( |
| 34 std::make_pair(entry.cert->normalized_subject().AsStringPiece(), entry)); |
| 35 } |
| 36 |
| 37 void TrustStoreInMemory::SyncGetIssuersOf(const ParsedCertificate* cert, |
| 38 ParsedCertificateList* issuers) { |
| 39 auto range = entries_.equal_range(cert->normalized_issuer().AsStringPiece()); |
| 40 for (auto it = range.first; it != range.second; ++it) |
| 41 issuers->push_back(it->second.cert); |
| 42 } |
| 43 |
| 44 void TrustStoreInMemory::GetTrust(const scoped_refptr<ParsedCertificate>& cert, |
| 45 CertificateTrust* trust) const { |
| 46 auto range = entries_.equal_range(cert->normalized_subject().AsStringPiece()); |
| 47 for (auto it = range.first; it != range.second; ++it) { |
| 48 if (cert.get() == it->second.cert.get() || |
| 49 cert->der_cert() == it->second.cert->der_cert()) { |
| 50 *trust = it->second.trust; |
| 51 // NOTE: ambiguity when there are duplicate entries. |
| 52 return; |
| 53 } |
| 54 } |
| 55 *trust = CertificateTrust::Unspecified(); |
| 56 } |
| 57 |
| 58 bool TrustStoreInMemory::Contains(const ParsedCertificate* cert) const { |
| 59 for (const auto& it : entries_) { |
| 60 if (cert->der_cert() == it.second.cert->der_cert()) |
33 return true; | 61 return true; |
34 } | 62 } |
35 return false; | 63 return false; |
36 } | 64 } |
37 | 65 |
| 66 TrustStoreInMemory::Entry::Entry() = default; |
| 67 TrustStoreInMemory::Entry::Entry(const Entry& other) = default; |
| 68 TrustStoreInMemory::Entry::~Entry() = default; |
| 69 |
38 } // namespace net | 70 } // namespace net |
OLD | NEW |