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

Side by Side 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, 10 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 | Annotate | Revision Log
« no previous file with comments | « net/base/x509_certificate.h ('k') | net/base/x509_certificate_mac.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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/base/x509_certificate.h" 5 #include "net/base/x509_certificate.h"
6 6
7 #include "base/histogram.h"
7 #include "base/logging.h" 8 #include "base/logging.h"
8 9
9 namespace net { 10 namespace net {
10 11
11 namespace { 12 namespace {
12 13
13 // Returns true if this cert fingerprint is the null (all zero) fingerprint. 14 // Returns true if this cert fingerprint is the null (all zero) fingerprint.
14 // We use this as a bogus fingerprint value. 15 // We use this as a bogus fingerprint value.
15 bool IsNullFingerprint(const X509Certificate::Fingerprint& fingerprint) { 16 bool IsNullFingerprint(const X509Certificate::Fingerprint& fingerprint) {
16 for (size_t i = 0; i < arraysize(fingerprint.data); ++i) { 17 for (size_t i = 0; i < arraysize(fingerprint.data); ++i) {
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 denied_.erase(cert->fingerprint()); 116 denied_.erase(cert->fingerprint());
116 allowed_.insert(cert->fingerprint()); 117 allowed_.insert(cert->fingerprint());
117 } 118 }
118 119
119 void X509Certificate::Policy::Deny(X509Certificate* cert) { 120 void X509Certificate::Policy::Deny(X509Certificate* cert) {
120 // Put the cert in the denied set and (maybe) remove it from the allowed set. 121 // Put the cert in the denied set and (maybe) remove it from the allowed set.
121 allowed_.erase(cert->fingerprint()); 122 allowed_.erase(cert->fingerprint());
122 denied_.insert(cert->fingerprint()); 123 denied_.insert(cert->fingerprint());
123 } 124 }
124 125
126 // static
127 X509Certificate* X509Certificate::CreateFromHandle(OSCertHandle cert_handle,
128 Source source) {
129 DCHECK(cert_handle);
130 DCHECK(source != SOURCE_UNUSED);
131
132 // Check if we already have this certificate in memory.
133 X509Certificate::Cache* cache = X509Certificate::Cache::GetInstance();
134 X509Certificate* cached_cert =
135 cache->Find(CalculateFingerprint(cert_handle));
136 if (cached_cert) {
137 DCHECK(cached_cert->source_ != SOURCE_UNUSED);
138 if (cached_cert->source_ >= source) {
139 // We've found a certificate with the same fingerprint in our cache. We
140 // own the |cert_handle|, which makes it our job to free it.
141 FreeOSCertHandle(cert_handle);
142 DHISTOGRAM_COUNTS(L"X509CertificateReuseCount", 1);
143 return cached_cert;
144 }
145 // Kick out the old certificate from our cache. The new one is better.
146 cache->Remove(cached_cert);
147 }
148 // Otherwise, allocate a new object.
149 return new X509Certificate(cert_handle, source);
150 }
151
152 // static
153 X509Certificate* X509Certificate::CreateFromBytes(const char* data,
154 int length) {
155 OSCertHandle cert_handle = CreateOSCertHandleFromBytes(data, length);
156 if (!cert_handle)
157 return NULL;
158
159 return CreateFromHandle(cert_handle, SOURCE_LONE_CERT_IMPORT);
160 }
161
162 X509Certificate::X509Certificate(OSCertHandle cert_handle, Source source)
163 : cert_handle_(cert_handle), source_(source) {
164 Initialize();
165 }
166
167 X509Certificate::X509Certificate(const std::string& subject,
168 const std::string& issuer,
169 base::Time start_date,
170 base::Time expiration_date)
171 : subject_(subject),
172 issuer_(issuer),
173 valid_start_(start_date),
174 valid_expiry_(expiration_date),
175 cert_handle_(NULL),
176 source_(SOURCE_UNUSED) {
177 memset(fingerprint_.data, 0, sizeof(fingerprint_.data));
178 }
179
180 X509Certificate::~X509Certificate() {
181 // We might not be in the cache, but it is safe to remove ourselves anyway.
182 X509Certificate::Cache::GetInstance()->Remove(this);
183 if (cert_handle_)
184 FreeOSCertHandle(cert_handle_);
185 }
186
125 } // namespace net 187 } // namespace net
126 188
OLDNEW
« 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