OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <openssl/asn1.h> | 7 #include <openssl/asn1.h> |
8 #include <openssl/crypto.h> | 8 #include <openssl/crypto.h> |
9 #include <openssl/obj_mac.h> | 9 #include <openssl/obj_mac.h> |
10 #include <openssl/pem.h> | 10 #include <openssl/pem.h> |
11 #include <openssl/pkcs7.h> | 11 #include <openssl/pkcs7.h> |
12 #include <openssl/sha.h> | 12 #include <openssl/sha.h> |
13 #include <openssl/ssl.h> | 13 #include <openssl/ssl.h> |
14 #include <openssl/x509v3.h> | 14 #include <openssl/x509v3.h> |
15 | 15 |
16 #include "base/memory/singleton.h" | 16 #include "base/memory/singleton.h" |
17 #include "base/pickle.h" | 17 #include "base/pickle.h" |
18 #include "base/sha1.h" | 18 #include "base/sha1.h" |
19 #include "base/string_number_conversions.h" | 19 #include "base/string_number_conversions.h" |
20 #include "crypto/openssl_util.h" | 20 #include "crypto/openssl_util.h" |
21 #include "net/base/asn1_util.h" | 21 #include "net/base/asn1_util.h" |
22 #include "net/base/cert_status_flags.h" | 22 #include "net/base/cert_status_flags.h" |
23 #include "net/base/cert_verify_result.h" | 23 #include "net/base/cert_verify_result.h" |
24 #include "net/base/net_errors.h" | 24 #include "net/base/net_errors.h" |
25 #include "net/base/x509_util_openssl.h" | 25 #include "net/base/x509_util_openssl.h" |
26 | 26 |
27 namespace net { | 27 namespace net { |
28 | 28 |
29 namespace { | |
michaelbai
2011/11/01 16:37:59
Why did you remove the this?
Jing Zhao
2011/11/02 16:22:55
Methods in this anonymous namespace were only used
| |
30 | |
31 void CreateOSCertHandlesFromPKCS7Bytes( | 29 void CreateOSCertHandlesFromPKCS7Bytes( |
32 const char* data, int length, | 30 const char* data, int length, |
33 X509Certificate::OSCertHandles* handles) { | 31 X509Certificate::OSCertHandles* handles) { |
34 crypto::EnsureOpenSSLInit(); | 32 crypto::EnsureOpenSSLInit(); |
35 const unsigned char* der_data = reinterpret_cast<const unsigned char*>(data); | 33 const unsigned char* der_data = reinterpret_cast<const unsigned char*>(data); |
36 crypto::ScopedOpenSSL<PKCS7, PKCS7_free> pkcs7_cert( | 34 crypto::ScopedOpenSSL<PKCS7, PKCS7_free> pkcs7_cert( |
37 d2i_PKCS7(NULL, &der_data, length)); | 35 d2i_PKCS7(NULL, &der_data, length)); |
38 if (!pkcs7_cert.get()) | 36 if (!pkcs7_cert.get()) |
39 return; | 37 return; |
40 | 38 |
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
292 if (data_length <= 0 || !data) | 290 if (data_length <= 0 || !data) |
293 return false; | 291 return false; |
294 internal_cache = SetDERCache(cert, x509_der_cache_index, data, data_length); | 292 internal_cache = SetDERCache(cert, x509_der_cache_index, data, data_length); |
295 if (!internal_cache) | 293 if (!internal_cache) |
296 return false; | 294 return false; |
297 } | 295 } |
298 *der_cache = *internal_cache; | 296 *der_cache = *internal_cache; |
299 return true; | 297 return true; |
300 } | 298 } |
301 | 299 |
302 } // namespace | |
303 | |
304 // static | 300 // static |
305 X509Certificate::OSCertHandle X509Certificate::DupOSCertHandle( | 301 X509Certificate::OSCertHandle X509Certificate::DupOSCertHandle( |
306 OSCertHandle cert_handle) { | 302 OSCertHandle cert_handle) { |
307 DCHECK(cert_handle); | 303 DCHECK(cert_handle); |
308 // Using X509_dup causes the entire certificate to be reparsed. This | 304 // Using X509_dup causes the entire certificate to be reparsed. This |
309 // conversion, besides being non-trivial, drops any associated | 305 // conversion, besides being non-trivial, drops any associated |
310 // application-specific data set by X509_set_ex_data. Using CRYPTO_add | 306 // application-specific data set by X509_set_ex_data. Using CRYPTO_add |
311 // just bumps up the ref-count for the cert, without causing any allocations | 307 // just bumps up the ref-count for the cert, without causing any allocations |
312 // or deallocations. | 308 // or deallocations. |
313 CRYPTO_add(&cert_handle->references, 1, CRYPTO_LOCK_X509); | 309 CRYPTO_add(&cert_handle->references, 1, CRYPTO_LOCK_X509); |
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
572 DERCache der_cache; | 568 DERCache der_cache; |
573 if (!GetDERAndCacheIfNeeded(cert_handle, &der_cache)) | 569 if (!GetDERAndCacheIfNeeded(cert_handle, &der_cache)) |
574 return false; | 570 return false; |
575 | 571 |
576 return pickle->WriteData( | 572 return pickle->WriteData( |
577 reinterpret_cast<const char*>(der_cache.data), | 573 reinterpret_cast<const char*>(der_cache.data), |
578 der_cache.data_length); | 574 der_cache.data_length); |
579 } | 575 } |
580 | 576 |
581 } // namespace net | 577 } // namespace net |
OLD | NEW |