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

Side by Side Diff: net/base/x509_certificate_openssl.cc

Issue 8429034: Upstream: Build net_unittests for Android. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: address comments Created 9 years, 1 month 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
OLDNEW
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 "base/string_util.h" 20 #include "base/string_util.h"
21 #include "crypto/openssl_util.h" 21 #include "crypto/openssl_util.h"
22 #include "net/base/asn1_util.h" 22 #include "net/base/asn1_util.h"
23 #include "net/base/cert_status_flags.h" 23 #include "net/base/cert_status_flags.h"
24 #include "net/base/cert_verify_result.h" 24 #include "net/base/cert_verify_result.h"
25 #include "net/base/net_errors.h" 25 #include "net/base/net_errors.h"
26 #include "net/base/x509_util_openssl.h" 26 #include "net/base/x509_util_openssl.h"
27 27
28 namespace net { 28 namespace net {
29 29
30 namespace {
31
32 void CreateOSCertHandlesFromPKCS7Bytes( 30 void CreateOSCertHandlesFromPKCS7Bytes(
33 const char* data, int length, 31 const char* data, int length,
34 X509Certificate::OSCertHandles* handles) { 32 X509Certificate::OSCertHandles* handles) {
35 crypto::EnsureOpenSSLInit(); 33 crypto::EnsureOpenSSLInit();
36 const unsigned char* der_data = reinterpret_cast<const unsigned char*>(data); 34 const unsigned char* der_data = reinterpret_cast<const unsigned char*>(data);
37 crypto::ScopedOpenSSL<PKCS7, PKCS7_free> pkcs7_cert( 35 crypto::ScopedOpenSSL<PKCS7, PKCS7_free> pkcs7_cert(
38 d2i_PKCS7(NULL, &der_data, length)); 36 d2i_PKCS7(NULL, &der_data, length));
39 if (!pkcs7_cert.get()) 37 if (!pkcs7_cert.get())
40 return; 38 return;
41 39
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 return CERT_STATUS_INVALID; 196 return CERT_STATUS_INVALID;
199 } 197 }
200 } 198 }
201 199
202 // sk_X509_free is a function-style macro, so can't be used as a template 200 // sk_X509_free is a function-style macro, so can't be used as a template
203 // param directly. 201 // param directly.
204 void sk_X509_free_fn(STACK_OF(X509)* st) { 202 void sk_X509_free_fn(STACK_OF(X509)* st) {
205 sk_X509_free(st); 203 sk_X509_free(st);
206 } 204 }
207 205
208 struct DERCache {
209 unsigned char* data;
210 int data_length;
211 };
212
213 void DERCache_free(void* parent, void* ptr, CRYPTO_EX_DATA* ad, int idx, 206 void DERCache_free(void* parent, void* ptr, CRYPTO_EX_DATA* ad, int idx,
214 long argl, void* argp) { 207 long argl, void* argp) {
215 DERCache* der_cache = static_cast<DERCache*>(ptr); 208 DERCache* der_cache = static_cast<DERCache*>(ptr);
216 if (!der_cache) 209 if (!der_cache)
217 return; 210 return;
218 if (der_cache->data) 211 if (der_cache->data)
219 OPENSSL_free(der_cache->data); 212 OPENSSL_free(der_cache->data);
220 OPENSSL_free(der_cache); 213 OPENSSL_free(der_cache);
221 } 214 }
222 215
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
293 if (data_length <= 0 || !data) 286 if (data_length <= 0 || !data)
294 return false; 287 return false;
295 internal_cache = SetDERCache(cert, x509_der_cache_index, data, data_length); 288 internal_cache = SetDERCache(cert, x509_der_cache_index, data, data_length);
296 if (!internal_cache) 289 if (!internal_cache)
297 return false; 290 return false;
298 } 291 }
299 *der_cache = *internal_cache; 292 *der_cache = *internal_cache;
300 return true; 293 return true;
301 } 294 }
302 295
303 } // namespace
joth 2011/11/02 18:57:05 shouldn't be any need for any of these edits
Jing Zhao 2011/11/03 17:49:08 Done.
304
305 // static 296 // static
306 X509Certificate::OSCertHandle X509Certificate::DupOSCertHandle( 297 X509Certificate::OSCertHandle X509Certificate::DupOSCertHandle(
307 OSCertHandle cert_handle) { 298 OSCertHandle cert_handle) {
308 DCHECK(cert_handle); 299 DCHECK(cert_handle);
309 // Using X509_dup causes the entire certificate to be reparsed. This 300 // Using X509_dup causes the entire certificate to be reparsed. This
310 // conversion, besides being non-trivial, drops any associated 301 // conversion, besides being non-trivial, drops any associated
311 // application-specific data set by X509_set_ex_data. Using CRYPTO_add 302 // application-specific data set by X509_set_ex_data. Using CRYPTO_add
312 // just bumps up the ref-count for the cert, without causing any allocations 303 // just bumps up the ref-count for the cert, without causing any allocations
313 // or deallocations. 304 // or deallocations.
314 CRYPTO_add(&cert_handle->references, 1, CRYPTO_LOCK_X509); 305 CRYPTO_add(&cert_handle->references, 1, CRYPTO_LOCK_X509);
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
583 DERCache der_cache; 574 DERCache der_cache;
584 if (!GetDERAndCacheIfNeeded(cert_handle, &der_cache)) 575 if (!GetDERAndCacheIfNeeded(cert_handle, &der_cache))
585 return false; 576 return false;
586 577
587 return pickle->WriteData( 578 return pickle->WriteData(
588 reinterpret_cast<const char*>(der_cache.data), 579 reinterpret_cast<const char*>(der_cache.data),
589 der_cache.data_length); 580 der_cache.data_length);
590 } 581 }
591 582
592 } // namespace net 583 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698