OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 // This file includes code SSLClientSocketNSS::DoVerifyCertComplete() derived | 5 // This file includes code SSLClientSocketNSS::DoVerifyCertComplete() derived |
6 // from AuthCertificateCallback() in | 6 // from AuthCertificateCallback() in |
7 // mozilla/security/manager/ssl/src/nsNSSCallbacks.cpp. | 7 // mozilla/security/manager/ssl/src/nsNSSCallbacks.cpp. |
8 | 8 |
9 /* ***** BEGIN LICENSE BLOCK ***** | 9 /* ***** BEGIN LICENSE BLOCK ***** |
10 * Version: MPL 1.1/GPL 2.0/LGPL 2.1 | 10 * Version: MPL 1.1/GPL 2.0/LGPL 2.1 |
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
275 | 275 |
276 #endif | 276 #endif |
277 | 277 |
278 void DestroyCertificates(CERTCertificate** certs, size_t len) { | 278 void DestroyCertificates(CERTCertificate** certs, size_t len) { |
279 for (size_t i = 0; i < len; i++) | 279 for (size_t i = 0; i < len; i++) |
280 CERT_DestroyCertificate(certs[i]); | 280 CERT_DestroyCertificate(certs[i]); |
281 } | 281 } |
282 | 282 |
283 // Helper functions to make it possible to log events from within the | 283 // Helper functions to make it possible to log events from within the |
284 // SSLClientSocketNSS::Core. | 284 // SSLClientSocketNSS::Core. |
285 void AddLogEvent(BoundNetLog* net_log, NetLog::EventType event_type) { | 285 void AddLogEvent(const base::WeakPtr<BoundNetLog>& net_log, |
286 if (!net_log) | 286 NetLog::EventType event_type) { |
| 287 if (!net_log.get()) |
287 return; | 288 return; |
288 net_log->AddEvent(event_type); | 289 net_log->AddEvent(event_type); |
289 } | 290 } |
290 | 291 |
291 // Helper function to make it possible to log events from within the | 292 // Helper function to make it possible to log events from within the |
292 // SSLClientSocketNSS::Core. | 293 // SSLClientSocketNSS::Core. |
293 void AddLogEventWithCallback(BoundNetLog* net_log, | 294 void AddLogEventWithCallback(const base::WeakPtr<BoundNetLog>& net_log, |
294 NetLog::EventType event_type, | 295 NetLog::EventType event_type, |
295 const NetLog::ParametersCallback& callback) { | 296 const NetLog::ParametersCallback& callback) { |
296 if (!net_log) | 297 if (!net_log.get()) |
297 return; | 298 return; |
298 net_log->AddEvent(event_type, callback); | 299 net_log->AddEvent(event_type, callback); |
299 } | 300 } |
300 | 301 |
301 // Helper function to make it easier to call BoundNetLog::AddByteTransferEvent | 302 // Helper function to make it easier to call BoundNetLog::AddByteTransferEvent |
302 // from within the SSLClientSocketNSS::Core. | 303 // from within the SSLClientSocketNSS::Core. |
303 // AddByteTransferEvent expects to receive a const char*, which within the | 304 // AddByteTransferEvent expects to receive a const char*, which within the |
304 // Core is backed by an IOBuffer. If the "const char*" is bound via | 305 // Core is backed by an IOBuffer. If the "const char*" is bound via |
305 // base::Bind and posted to another thread, and the IOBuffer that backs that | 306 // base::Bind and posted to another thread, and the IOBuffer that backs that |
306 // pointer then goes out of scope on the origin thread, this would result in | 307 // pointer then goes out of scope on the origin thread, this would result in |
307 // an invalid read of a stale pointer. | 308 // an invalid read of a stale pointer. |
308 // Instead, provide a signature that accepts an IOBuffer*, so that a reference | 309 // Instead, provide a signature that accepts an IOBuffer*, so that a reference |
309 // to the owning IOBuffer can be bound to the Callback. This ensures that the | 310 // to the owning IOBuffer can be bound to the Callback. This ensures that the |
310 // IOBuffer will stay alive long enough to cross threads if needed. | 311 // IOBuffer will stay alive long enough to cross threads if needed. |
311 void LogByteTransferEvent(BoundNetLog* net_log, NetLog::EventType event_type, | 312 void LogByteTransferEvent( |
312 int len, IOBuffer* buffer) { | 313 const base::WeakPtr<BoundNetLog>& net_log, NetLog::EventType event_type, |
313 if (!net_log) | 314 int len, IOBuffer* buffer) { |
| 315 if (!net_log.get()) |
314 return; | 316 return; |
315 net_log->AddByteTransferEvent(event_type, len, buffer->data()); | 317 net_log->AddByteTransferEvent(event_type, len, buffer->data()); |
316 } | 318 } |
317 | 319 |
318 // PeerCertificateChain is a helper object which extracts the certificate | 320 // PeerCertificateChain is a helper object which extracts the certificate |
319 // chain, as given by the server, from an NSS socket and performs the needed | 321 // chain, as given by the server, from an NSS socket and performs the needed |
320 // resource management. The first element of the chain is the leaf certificate | 322 // resource management. The first element of the chain is the leaf certificate |
321 // and the other elements are in the order given by the server. | 323 // and the other elements are in the order given by the server. |
322 class PeerCertificateChain { | 324 class PeerCertificateChain { |
323 public: | 325 public: |
(...skipping 3228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3552 EnsureThreadIdAssigned(); | 3554 EnsureThreadIdAssigned(); |
3553 base::AutoLock auto_lock(lock_); | 3555 base::AutoLock auto_lock(lock_); |
3554 return valid_thread_id_ == base::PlatformThread::CurrentId(); | 3556 return valid_thread_id_ == base::PlatformThread::CurrentId(); |
3555 } | 3557 } |
3556 | 3558 |
3557 ServerBoundCertService* SSLClientSocketNSS::GetServerBoundCertService() const { | 3559 ServerBoundCertService* SSLClientSocketNSS::GetServerBoundCertService() const { |
3558 return server_bound_cert_service_; | 3560 return server_bound_cert_service_; |
3559 } | 3561 } |
3560 | 3562 |
3561 } // namespace net | 3563 } // namespace net |
OLD | NEW |