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/cert/x509_certificate.h" | 5 #include "net/cert/x509_certificate.h" |
6 | 6 |
7 #include <CommonCrypto/CommonDigest.h> | 7 #include <CommonCrypto/CommonDigest.h> |
8 #include <CoreServices/CoreServices.h> | 8 #include <CoreServices/CoreServices.h> |
9 #include <Security/Security.h> | 9 #include <Security/Security.h> |
10 | 10 |
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
367 | 367 |
368 DCHECK(cert_data.Data); | 368 DCHECK(cert_data.Data); |
369 DCHECK_NE(cert_data.Length, 0U); | 369 DCHECK_NE(cert_data.Length, 0U); |
370 | 370 |
371 CC_SHA1(cert_data.Data, cert_data.Length, sha1.data); | 371 CC_SHA1(cert_data.Data, cert_data.Length, sha1.data); |
372 | 372 |
373 return sha1; | 373 return sha1; |
374 } | 374 } |
375 | 375 |
376 // static | 376 // static |
| 377 SHA256HashValue X509Certificate::CalculateFingerprint256(OSCertHandle cert) { |
| 378 SHA256HashValue sha256; |
| 379 memset(sha256.data, 0, sizeof(sha256.data)); |
| 380 |
| 381 CSSM_DATA cert_data; |
| 382 OSStatus status = SecCertificateGetData(cert, &cert_data); |
| 383 if (status) |
| 384 return sha256; |
| 385 |
| 386 DCHECK(cert_data.Data); |
| 387 DCHECK_NE(cert_data.Length, 0U); |
| 388 |
| 389 CC_SHA256(cert_data.Data, cert_data.Length, sha256.data); |
| 390 |
| 391 return sha256; |
| 392 } |
| 393 |
| 394 // static |
377 SHA1HashValue X509Certificate::CalculateCAFingerprint( | 395 SHA1HashValue X509Certificate::CalculateCAFingerprint( |
378 const OSCertHandles& intermediates) { | 396 const OSCertHandles& intermediates) { |
379 SHA1HashValue sha1; | 397 SHA1HashValue sha1; |
380 memset(sha1.data, 0, sizeof(sha1.data)); | 398 memset(sha1.data, 0, sizeof(sha1.data)); |
381 | 399 |
382 // The CC_SHA(3cc) man page says all CC_SHA1_xxx routines return 1, so | 400 // The CC_SHA(3cc) man page says all CC_SHA1_xxx routines return 1, so |
383 // we don't check their return values. | 401 // we don't check their return values. |
384 CC_SHA1_CTX sha1_ctx; | 402 CC_SHA1_CTX sha1_ctx; |
385 CC_SHA1_Init(&sha1_ctx); | 403 CC_SHA1_Init(&sha1_ctx); |
386 CSSM_DATA cert_data; | 404 CSSM_DATA cert_data; |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
507 *type = kPublicKeyTypeDH; | 525 *type = kPublicKeyTypeDH; |
508 break; | 526 break; |
509 default: | 527 default: |
510 *type = kPublicKeyTypeUnknown; | 528 *type = kPublicKeyTypeUnknown; |
511 *size_bits = 0; | 529 *size_bits = 0; |
512 break; | 530 break; |
513 } | 531 } |
514 } | 532 } |
515 | 533 |
516 } // namespace net | 534 } // namespace net |
OLD | NEW |