Index: ios/web/net/cert_verification_cache.h |
diff --git a/ios/web/net/cert_verification_cache.h b/ios/web/net/cert_verification_cache.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..e992b35df7e758484ac9d8237741f3dfd0be9084 |
--- /dev/null |
+++ b/ios/web/net/cert_verification_cache.h |
@@ -0,0 +1,72 @@ |
+// Copyright 2015 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef IOS_WEB_NET_CERT_VERIFICATION_CACHE_H_ |
+#define IOS_WEB_NET_CERT_VERIFICATION_CACHE_H_ |
+ |
+#include <map> |
+#include <string> |
+ |
+#include "net/cert/x509_certificate.h" |
+ |
+namespace web { |
+ |
+// Allows caching cert verification data. Key is cert-host pair, value is |
+// a template param. |
Ryan Sleevi
2015/09/24 22:48:38
This second sentence is unclear. What is Key? Why
Eugene But (OOO till 7-30)
2015/09/25 21:24:23
Value is templated because it is very specific to
|
+template <typename ValueType> |
+class CertVerificationCache { |
+ public: |
+ CertVerificationCache() {} |
+ ~CertVerificationCache() {} |
+ |
+ // Retrieves |value| for the given cert-host pair. |cert| cannot be null. |
+ // Returns true on success. |
+ bool get(const scoped_refptr<net::X509Certificate>& cert, |
Ryan Sleevi
2015/09/24 22:48:39
http://google-styleguide.googlecode.com/svn/trunk/
Eugene But (OOO till 7-30)
2015/09/25 21:24:23
Done. Capitalized Set as well for consistency. Sty
Ryan Sleevi
2015/09/28 22:46:52
The problem is that this is actually quite a large
Eugene But (OOO till 7-30)
2015/09/29 18:29:07
Thanks for detailed explanation. Un-inlined.
|
+ const std::string& host, |
+ ValueType* value) const { |
+ auto it = map_.find(KeyType(cert, host)); |
+ if (it == map_.end()) |
+ return false; |
+ |
+ *value = it->second; |
+ return true; |
+ } |
+ |
+ // Adds |value| for the given cert-host pair. |cert| cannot be null. |
+ void set(const scoped_refptr<net::X509Certificate>& cert, |
+ const std::string& host, |
+ const ValueType& value) { |
+ DCHECK(cert); |
+ map_[KeyType(cert, host)] = value; |
Ryan Sleevi
2015/09/24 22:48:39
Why is the key type multi-value? This allows a sin
Eugene But (OOO till 7-30)
2015/09/25 21:24:23
This cache object will be used for transferring ne
Ryan Sleevi
2015/09/28 22:46:52
I guess I'm still rather confused here. Perhaps it
Eugene But (OOO till 7-30)
2015/09/29 18:29:07
Consider the following use case:
1. didReceiveAuth
Ryan Sleevi
2015/09/29 20:28:38
On 2015/09/29 18:29:07, eugenebut wrote:
https://c
Eugene But (OOO till 7-30)
2015/09/29 21:16:47
Or MITM attack. But I guess it's not a frequent ca
Ryan Sleevi
2015/09/29 21:25:28
Sure. But doing something battery expensive under
Eugene But (OOO till 7-30)
2015/10/09 16:32:36
Replaced bicycle with MRUCache. Thanks for suggest
|
+ } |
+ |
+ // Clears the cache. |
+ void reset() { map_.clear(); } |
+ |
+ private: |
+ // Holds cert-host pair and provides less-than comparator. |
Ryan Sleevi
2015/09/24 22:48:39
What does this comment add?
Eugene But (OOO till 7-30)
2015/09/25 21:24:23
Removed.
|
+ struct KeyType { |
+ KeyType(const scoped_refptr<net::X509Certificate>& cert, |
+ const std::string& host) |
+ : cert(cert), host(host) {} |
+ |
+ bool operator<(const KeyType& other) const { |
Ryan Sleevi
2015/09/24 22:48:38
Why is this inlined? It can be out-of-lined via a
Eugene But (OOO till 7-30)
2015/09/25 21:24:23
This operator is inlined, because it is 3 LOC. Is
|
+ if (host == other.host) |
Ryan Sleevi
2015/09/24 22:48:39
DANGEROUS DESIGN PATTERN:
When writing comparator
Eugene But (OOO till 7-30)
2015/09/25 21:24:23
Done.
|
+ return cert_comparator(cert, other.cert); |
+ return host < other.host; |
+ } |
+ |
+ scoped_refptr<net::X509Certificate> cert; |
+ std::string host; |
+ |
+ private: |
+ net::X509Certificate::LessThan cert_comparator; |
+ }; |
+ |
+ std::map<KeyType, ValueType> map_; |
+}; |
+ |
+} // namespace web |
+ |
+#endif // IOS_WEB_NET_CERT_VERIFICATION_CACHE_H_ |