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 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
331 OSCertHandle cert_handle) { | 331 OSCertHandle cert_handle) { |
332 return CertDuplicateCertificateContext(cert_handle); | 332 return CertDuplicateCertificateContext(cert_handle); |
333 } | 333 } |
334 | 334 |
335 // static | 335 // static |
336 void X509Certificate::FreeOSCertHandle(OSCertHandle cert_handle) { | 336 void X509Certificate::FreeOSCertHandle(OSCertHandle cert_handle) { |
337 CertFreeCertificateContext(cert_handle); | 337 CertFreeCertificateContext(cert_handle); |
338 } | 338 } |
339 | 339 |
340 // static | 340 // static |
341 SHA1HashValue X509Certificate::CalculateFingerprint( | 341 SHA1Fingerprint X509Certificate::CalculateFingerprint( |
342 OSCertHandle cert) { | 342 OSCertHandle cert) { |
343 DCHECK(NULL != cert->pbCertEncoded); | 343 DCHECK(NULL != cert->pbCertEncoded); |
344 DCHECK_NE(static_cast<DWORD>(0), cert->cbCertEncoded); | 344 DCHECK_NE(static_cast<DWORD>(0), cert->cbCertEncoded); |
345 | 345 |
346 BOOL rv; | 346 BOOL rv; |
347 SHA1HashValue sha1; | 347 SHA1Fingerprint sha1; |
348 DWORD sha1_size = sizeof(sha1.data); | 348 DWORD sha1_size = sizeof(sha1.data); |
349 rv = CryptHashCertificate(NULL, CALG_SHA1, 0, cert->pbCertEncoded, | 349 rv = CryptHashCertificate(NULL, CALG_SHA1, 0, cert->pbCertEncoded, |
350 cert->cbCertEncoded, sha1.data, &sha1_size); | 350 cert->cbCertEncoded, sha1.data, &sha1_size); |
351 DCHECK(rv && sha1_size == sizeof(sha1.data)); | 351 DCHECK(rv && sha1_size == sizeof(sha1.data)); |
352 if (!rv) | 352 if (!rv) |
353 memset(sha1.data, 0, sizeof(sha1.data)); | 353 memset(sha1.data, 0, sizeof(sha1.data)); |
354 return sha1; | 354 return sha1; |
355 } | 355 } |
356 | 356 |
357 // TODO(wtc): This function is implemented with NSS low-level hash | 357 // TODO(wtc): This function is implemented with NSS low-level hash |
358 // functions to ensure it is fast. Reimplement this function with | 358 // functions to ensure it is fast. Reimplement this function with |
359 // CryptoAPI. May need to cache the HCRYPTPROV to reduce the overhead. | 359 // CryptoAPI. May need to cache the HCRYPTPROV to reduce the overhead. |
360 // static | 360 // static |
361 SHA1HashValue X509Certificate::CalculateCAFingerprint( | 361 SHA1Fingerprint X509Certificate::CalculateCAFingerprint( |
362 const OSCertHandles& intermediates) { | 362 const OSCertHandles& intermediates) { |
363 SHA1HashValue sha1; | 363 SHA1Fingerprint sha1; |
364 memset(sha1.data, 0, sizeof(sha1.data)); | 364 memset(sha1.data, 0, sizeof(sha1.data)); |
365 | 365 |
366 SHA1Context* sha1_ctx = SHA1_NewContext(); | 366 SHA1Context* sha1_ctx = SHA1_NewContext(); |
367 if (!sha1_ctx) | 367 if (!sha1_ctx) |
368 return sha1; | 368 return sha1; |
369 SHA1_Begin(sha1_ctx); | 369 SHA1_Begin(sha1_ctx); |
370 for (size_t i = 0; i < intermediates.size(); ++i) { | 370 for (size_t i = 0; i < intermediates.size(); ++i) { |
371 PCCERT_CONTEXT ca_cert = intermediates[i]; | 371 PCCERT_CONTEXT ca_cert = intermediates[i]; |
372 SHA1_Update(sha1_ctx, ca_cert->pbCertEncoded, ca_cert->cbCertEncoded); | 372 SHA1_Update(sha1_ctx, ca_cert->pbCertEncoded, ca_cert->cbCertEncoded); |
373 } | 373 } |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
454 *type = kPublicKeyTypeECDH; | 454 *type = kPublicKeyTypeECDH; |
455 break; | 455 break; |
456 default: | 456 default: |
457 *type = kPublicKeyTypeUnknown; | 457 *type = kPublicKeyTypeUnknown; |
458 *size_bits = 0; | 458 *size_bits = 0; |
459 break; | 459 break; |
460 } | 460 } |
461 } | 461 } |
462 | 462 |
463 } // namespace net | 463 } // namespace net |
OLD | NEW |