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

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

Issue 10883012: net: don't crash when processing a certificate with an unknown public key. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: ... Created 8 years, 4 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/cert_verify_proc_unittest.cc ('k') | net/base/x509_certificate_win.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) 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/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>
(...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after
433 433
434 return pickle->WriteData( 434 return pickle->WriteData(
435 reinterpret_cast<const char*>(der_cache.data), 435 reinterpret_cast<const char*>(der_cache.data),
436 der_cache.data_length); 436 der_cache.data_length);
437 } 437 }
438 438
439 // static 439 // static
440 void X509Certificate::GetPublicKeyInfo(OSCertHandle cert_handle, 440 void X509Certificate::GetPublicKeyInfo(OSCertHandle cert_handle,
441 size_t* size_bits, 441 size_t* size_bits,
442 PublicKeyType* type) { 442 PublicKeyType* type) {
443 *type = kPublicKeyTypeUnknown;
444 *size_bits = 0;
445
443 crypto::ScopedOpenSSL<EVP_PKEY, EVP_PKEY_free> scoped_key( 446 crypto::ScopedOpenSSL<EVP_PKEY, EVP_PKEY_free> scoped_key(
444 X509_get_pubkey(cert_handle)); 447 X509_get_pubkey(cert_handle));
448 if (!scoped_key.get())
449 return;
450
445 CHECK(scoped_key.get()); 451 CHECK(scoped_key.get());
446 EVP_PKEY* key = scoped_key.get(); 452 EVP_PKEY* key = scoped_key.get();
447 453
448 switch (key->type) { 454 switch (key->type) {
449 case EVP_PKEY_RSA: 455 case EVP_PKEY_RSA:
450 *type = kPublicKeyTypeRSA; 456 *type = kPublicKeyTypeRSA;
451 *size_bits = EVP_PKEY_size(key) * 8; 457 *size_bits = EVP_PKEY_size(key) * 8;
452 break; 458 break;
453 case EVP_PKEY_DSA: 459 case EVP_PKEY_DSA:
454 *type = kPublicKeyTypeDSA; 460 *type = kPublicKeyTypeDSA;
455 *size_bits = EVP_PKEY_size(key) * 8; 461 *size_bits = EVP_PKEY_size(key) * 8;
456 break; 462 break;
457 case EVP_PKEY_EC: 463 case EVP_PKEY_EC:
458 *type = kPublicKeyTypeECDSA; 464 *type = kPublicKeyTypeECDSA;
459 *size_bits = EVP_PKEY_size(key); 465 *size_bits = EVP_PKEY_size(key);
460 break; 466 break;
461 case EVP_PKEY_DH: 467 case EVP_PKEY_DH:
462 *type = kPublicKeyTypeDH; 468 *type = kPublicKeyTypeDH;
463 *size_bits = EVP_PKEY_size(key) * 8; 469 *size_bits = EVP_PKEY_size(key) * 8;
464 break; 470 break;
465 default:
466 *type = kPublicKeyTypeUnknown;
467 *size_bits = 0;
468 break;
469 } 471 }
470 } 472 }
471 473
472 } // namespace net 474 } // namespace net
OLDNEW
« no previous file with comments | « net/base/cert_verify_proc_unittest.cc ('k') | net/base/x509_certificate_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698