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

Unified Diff: net/base/x509_certificate.cc

Issue 18836: Work around our not caching the intermediate CA... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 11 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/base/x509_certificate.h ('k') | net/base/x509_certificate_mac.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/base/x509_certificate.cc
===================================================================
--- net/base/x509_certificate.cc (revision 8670)
+++ net/base/x509_certificate.cc (working copy)
@@ -4,6 +4,7 @@
#include "net/base/x509_certificate.h"
+#include "base/histogram.h"
#include "base/logging.h"
namespace net {
@@ -122,5 +123,66 @@
denied_.insert(cert->fingerprint());
}
+// static
+X509Certificate* X509Certificate::CreateFromHandle(OSCertHandle cert_handle,
+ Source source) {
+ DCHECK(cert_handle);
+ DCHECK(source != SOURCE_UNUSED);
+
+ // Check if we already have this certificate in memory.
+ X509Certificate::Cache* cache = X509Certificate::Cache::GetInstance();
+ X509Certificate* cached_cert =
+ cache->Find(CalculateFingerprint(cert_handle));
+ if (cached_cert) {
+ DCHECK(cached_cert->source_ != SOURCE_UNUSED);
+ if (cached_cert->source_ >= source) {
+ // We've found a certificate with the same fingerprint in our cache. We
+ // own the |cert_handle|, which makes it our job to free it.
+ FreeOSCertHandle(cert_handle);
+ DHISTOGRAM_COUNTS(L"X509CertificateReuseCount", 1);
+ return cached_cert;
+ }
+ // Kick out the old certificate from our cache. The new one is better.
+ cache->Remove(cached_cert);
+ }
+ // Otherwise, allocate a new object.
+ return new X509Certificate(cert_handle, source);
+}
+
+// static
+X509Certificate* X509Certificate::CreateFromBytes(const char* data,
+ int length) {
+ OSCertHandle cert_handle = CreateOSCertHandleFromBytes(data, length);
+ if (!cert_handle)
+ return NULL;
+
+ return CreateFromHandle(cert_handle, SOURCE_LONE_CERT_IMPORT);
+}
+
+X509Certificate::X509Certificate(OSCertHandle cert_handle, Source source)
+ : cert_handle_(cert_handle), source_(source) {
+ Initialize();
+}
+
+X509Certificate::X509Certificate(const std::string& subject,
+ const std::string& issuer,
+ base::Time start_date,
+ base::Time expiration_date)
+ : subject_(subject),
+ issuer_(issuer),
+ valid_start_(start_date),
+ valid_expiry_(expiration_date),
+ cert_handle_(NULL),
+ source_(SOURCE_UNUSED) {
+ memset(fingerprint_.data, 0, sizeof(fingerprint_.data));
+}
+
+X509Certificate::~X509Certificate() {
+ // We might not be in the cache, but it is safe to remove ourselves anyway.
+ X509Certificate::Cache::GetInstance()->Remove(this);
+ if (cert_handle_)
+ FreeOSCertHandle(cert_handle_);
+}
+
} // namespace net
« no previous file with comments | « net/base/x509_certificate.h ('k') | net/base/x509_certificate_mac.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698