| 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 #include "net/cert/x509_certificate.h" | 5 #include "net/cert/x509_certificate.h" |
| 6 | 6 |
| 7 #include <limits.h> | 7 #include <limits.h> |
| 8 #include <stdlib.h> | 8 #include <stdlib.h> |
| 9 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| (...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 223 } | 223 } |
| 224 } | 224 } |
| 225 | 225 |
| 226 } // namespace | 226 } // namespace |
| 227 | 227 |
| 228 // static | 228 // static |
| 229 scoped_refptr<X509Certificate> X509Certificate::CreateFromHandle( | 229 scoped_refptr<X509Certificate> X509Certificate::CreateFromHandle( |
| 230 OSCertHandle cert_handle, | 230 OSCertHandle cert_handle, |
| 231 const OSCertHandles& intermediates) { | 231 const OSCertHandles& intermediates) { |
| 232 DCHECK(cert_handle); | 232 DCHECK(cert_handle); |
| 233 return new X509Certificate(cert_handle, intermediates); | 233 scoped_refptr<X509Certificate> cert( |
| 234 new X509Certificate(cert_handle, intermediates)); |
| 235 if (!cert->os_cert_handle()) |
| 236 return nullptr; // Initialize() failed. |
| 237 return cert; |
| 234 } | 238 } |
| 235 | 239 |
| 236 // static | 240 // static |
| 237 scoped_refptr<X509Certificate> X509Certificate::CreateFromDERCertChain( | 241 scoped_refptr<X509Certificate> X509Certificate::CreateFromDERCertChain( |
| 238 const std::vector<base::StringPiece>& der_certs) { | 242 const std::vector<base::StringPiece>& der_certs) { |
| 239 TRACE_EVENT0("io", "X509Certificate::CreateFromDERCertChain"); | 243 TRACE_EVENT0("io", "X509Certificate::CreateFromDERCertChain"); |
| 240 | 244 |
| 241 // TODO(cbentzel): Remove ScopedTracker below once crbug.com/424386 is fixed. | 245 // TODO(cbentzel): Remove ScopedTracker below once crbug.com/424386 is fixed. |
| 242 tracked_objects::ScopedTracker tracking_profile( | 246 tracked_objects::ScopedTracker tracking_profile( |
| 243 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 247 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| (...skipping 463 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 707 for (size_t i = 0; i < intermediates.size(); ++i) { | 711 for (size_t i = 0; i < intermediates.size(); ++i) { |
| 708 // Duplicate the incoming certificate, as the caller retains ownership | 712 // Duplicate the incoming certificate, as the caller retains ownership |
| 709 // of |intermediates|. | 713 // of |intermediates|. |
| 710 OSCertHandle intermediate = DupOSCertHandle(intermediates[i]); | 714 OSCertHandle intermediate = DupOSCertHandle(intermediates[i]); |
| 711 // Update the cache, which will assume ownership of the duplicated | 715 // Update the cache, which will assume ownership of the duplicated |
| 712 // handle and return a suitable equivalent, potentially from the cache. | 716 // handle and return a suitable equivalent, potentially from the cache. |
| 713 InsertOrUpdateCache(&intermediate); | 717 InsertOrUpdateCache(&intermediate); |
| 714 intermediate_ca_certs_.push_back(intermediate); | 718 intermediate_ca_certs_.push_back(intermediate); |
| 715 } | 719 } |
| 716 // Platform-specific initialization. | 720 // Platform-specific initialization. |
| 717 Initialize(); | 721 if (!Initialize() && cert_handle_) { |
| 722 // Signal initialization failure by clearing cert_handle_. |
| 723 RemoveFromCache(cert_handle_); |
| 724 FreeOSCertHandle(cert_handle_); |
| 725 cert_handle_ = nullptr; |
| 726 } |
| 718 } | 727 } |
| 719 | 728 |
| 720 X509Certificate::~X509Certificate() { | 729 X509Certificate::~X509Certificate() { |
| 721 if (cert_handle_) { | 730 if (cert_handle_) { |
| 722 RemoveFromCache(cert_handle_); | 731 RemoveFromCache(cert_handle_); |
| 723 FreeOSCertHandle(cert_handle_); | 732 FreeOSCertHandle(cert_handle_); |
| 724 } | 733 } |
| 725 for (size_t i = 0; i < intermediate_ca_certs_.size(); ++i) { | 734 for (size_t i = 0; i < intermediate_ca_certs_.size(); ++i) { |
| 726 RemoveFromCache(intermediate_ca_certs_[i]); | 735 RemoveFromCache(intermediate_ca_certs_[i]); |
| 727 FreeOSCertHandle(intermediate_ca_certs_[i]); | 736 FreeOSCertHandle(intermediate_ca_certs_[i]); |
| 728 } | 737 } |
| 729 } | 738 } |
| 730 | 739 |
| 731 } // namespace net | 740 } // namespace net |
| OLD | NEW |