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/base/x509_certificate.h" | 5 #include "net/base/x509_certificate.h" |
6 | 6 |
7 #include <blapi.h> // Implement CalculateChainFingerprint() with NSS. | 7 #include <blapi.h> // Implement CalculateChainFingerprint() with NSS. |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
421 Pickle* pickle) { | 421 Pickle* pickle) { |
422 return pickle->WriteData( | 422 return pickle->WriteData( |
423 reinterpret_cast<char*>(cert_handle->pbCertEncoded), | 423 reinterpret_cast<char*>(cert_handle->pbCertEncoded), |
424 cert_handle->cbCertEncoded); | 424 cert_handle->cbCertEncoded); |
425 } | 425 } |
426 | 426 |
427 // static | 427 // static |
428 void X509Certificate::GetPublicKeyInfo(OSCertHandle cert_handle, | 428 void X509Certificate::GetPublicKeyInfo(OSCertHandle cert_handle, |
429 size_t* size_bits, | 429 size_t* size_bits, |
430 PublicKeyType* type) { | 430 PublicKeyType* type) { |
| 431 *type = kPublicKeyTypeUnknown; |
| 432 *size_bits = 0; |
| 433 |
431 PCCRYPT_OID_INFO oid_info = CryptFindOIDInfo( | 434 PCCRYPT_OID_INFO oid_info = CryptFindOIDInfo( |
432 CRYPT_OID_INFO_OID_KEY, | 435 CRYPT_OID_INFO_OID_KEY, |
433 cert_handle->pCertInfo->SubjectPublicKeyInfo.Algorithm.pszObjId, | 436 cert_handle->pCertInfo->SubjectPublicKeyInfo.Algorithm.pszObjId, |
434 CRYPT_PUBKEY_ALG_OID_GROUP_ID); | 437 CRYPT_PUBKEY_ALG_OID_GROUP_ID); |
435 PCHECK(oid_info); | 438 if (!oid_info) |
436 CHECK(oid_info->dwGroupId == CRYPT_PUBKEY_ALG_OID_GROUP_ID); | 439 return; |
| 440 |
| 441 CHECK_EQ(oid_info->dwGroupId, |
| 442 static_cast<DWORD>(CRYPT_PUBKEY_ALG_OID_GROUP_ID)); |
437 | 443 |
438 *size_bits = CertGetPublicKeyLength( | 444 *size_bits = CertGetPublicKeyLength( |
439 X509_ASN_ENCODING | PKCS_7_ASN_ENCODING, | 445 X509_ASN_ENCODING | PKCS_7_ASN_ENCODING, |
440 &cert_handle->pCertInfo->SubjectPublicKeyInfo); | 446 &cert_handle->pCertInfo->SubjectPublicKeyInfo); |
441 | 447 |
442 switch (oid_info->Algid) { | 448 switch (oid_info->Algid) { |
443 case CALG_RSA_SIGN: | 449 case CALG_RSA_SIGN: |
444 case CALG_RSA_KEYX: | 450 case CALG_RSA_KEYX: |
445 *type = kPublicKeyTypeRSA; | 451 *type = kPublicKeyTypeRSA; |
446 break; | 452 break; |
447 case CALG_DSS_SIGN: | 453 case CALG_DSS_SIGN: |
448 *type = kPublicKeyTypeDSA; | 454 *type = kPublicKeyTypeDSA; |
449 break; | 455 break; |
450 case CALG_ECDSA: | 456 case CALG_ECDSA: |
451 *type = kPublicKeyTypeECDSA; | 457 *type = kPublicKeyTypeECDSA; |
452 break; | 458 break; |
453 case CALG_ECDH: | 459 case CALG_ECDH: |
454 *type = kPublicKeyTypeECDH; | 460 *type = kPublicKeyTypeECDH; |
455 break; | 461 break; |
456 default: | |
457 *type = kPublicKeyTypeUnknown; | |
458 *size_bits = 0; | |
459 break; | |
460 } | 462 } |
461 } | 463 } |
462 | 464 |
463 } // namespace net | 465 } // namespace net |
OLD | NEW |