OLD | NEW |
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 <cert.h> | 7 #include <cert.h> |
8 #include <cryptohi.h> | 8 #include <cryptohi.h> |
9 #include <nss.h> | 9 #include <nss.h> |
10 #include <pk11pub.h> | 10 #include <pk11pub.h> |
(...skipping 659 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
670 } // namespace | 670 } // namespace |
671 | 671 |
672 void X509Certificate::Initialize() { | 672 void X509Certificate::Initialize() { |
673 ParsePrincipal(&cert_handle_->subject, &subject_); | 673 ParsePrincipal(&cert_handle_->subject, &subject_); |
674 ParsePrincipal(&cert_handle_->issuer, &issuer_); | 674 ParsePrincipal(&cert_handle_->issuer, &issuer_); |
675 | 675 |
676 ParseDate(&cert_handle_->validity.notBefore, &valid_start_); | 676 ParseDate(&cert_handle_->validity.notBefore, &valid_start_); |
677 ParseDate(&cert_handle_->validity.notAfter, &valid_expiry_); | 677 ParseDate(&cert_handle_->validity.notAfter, &valid_expiry_); |
678 | 678 |
679 fingerprint_ = CalculateFingerprint(cert_handle_); | 679 fingerprint_ = CalculateFingerprint(cert_handle_); |
| 680 chain_fingerprint_ = CalculateChainFingerprint(); |
680 | 681 |
681 serial_number_ = std::string( | 682 serial_number_ = std::string( |
682 reinterpret_cast<char*>(cert_handle_->serialNumber.data), | 683 reinterpret_cast<char*>(cert_handle_->serialNumber.data), |
683 cert_handle_->serialNumber.len); | 684 cert_handle_->serialNumber.len); |
684 // Remove leading zeros. | 685 // Remove leading zeros. |
685 while (serial_number_.size() > 1 && serial_number_[0] == 0) | 686 while (serial_number_.size() > 1 && serial_number_[0] == 0) |
686 serial_number_ = serial_number_.substr(1, serial_number_.size() - 1); | 687 serial_number_ = serial_number_.substr(1, serial_number_.size() - 1); |
687 } | 688 } |
688 | 689 |
689 // static | 690 // static |
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
998 DCHECK(NULL != cert->derCert.data); | 999 DCHECK(NULL != cert->derCert.data); |
999 DCHECK_NE(0U, cert->derCert.len); | 1000 DCHECK_NE(0U, cert->derCert.len); |
1000 | 1001 |
1001 SECStatus rv = HASH_HashBuf(HASH_AlgSHA1, sha1.data, | 1002 SECStatus rv = HASH_HashBuf(HASH_AlgSHA1, sha1.data, |
1002 cert->derCert.data, cert->derCert.len); | 1003 cert->derCert.data, cert->derCert.len); |
1003 DCHECK_EQ(SECSuccess, rv); | 1004 DCHECK_EQ(SECSuccess, rv); |
1004 | 1005 |
1005 return sha1; | 1006 return sha1; |
1006 } | 1007 } |
1007 | 1008 |
| 1009 SHA1Fingerprint X509Certificate::CalculateChainFingerprint() const { |
| 1010 SHA1Fingerprint sha1; |
| 1011 memset(sha1.data, 0, sizeof(sha1.data)); |
| 1012 |
| 1013 HASHContext* sha1_ctx = HASH_Create(HASH_AlgSHA1); |
| 1014 if (!sha1_ctx) |
| 1015 return sha1; |
| 1016 HASH_Begin(sha1_ctx); |
| 1017 HASH_Update(sha1_ctx, cert_handle_->derCert.data, cert_handle_->derCert.len); |
| 1018 for (size_t i = 0; i < intermediate_ca_certs_.size(); ++i) { |
| 1019 CERTCertificate* ca_cert = intermediate_ca_certs_[i]; |
| 1020 HASH_Update(sha1_ctx, ca_cert->derCert.data, ca_cert->derCert.len); |
| 1021 } |
| 1022 unsigned int result_len; |
| 1023 HASH_End(sha1_ctx, sha1.data, &result_len, HASH_ResultLenContext(sha1_ctx)); |
| 1024 HASH_Destroy(sha1_ctx); |
| 1025 |
| 1026 return sha1; |
| 1027 } |
| 1028 |
1008 // static | 1029 // static |
1009 X509Certificate::OSCertHandle | 1030 X509Certificate::OSCertHandle |
1010 X509Certificate::ReadOSCertHandleFromPickle(const Pickle& pickle, | 1031 X509Certificate::ReadOSCertHandleFromPickle(const Pickle& pickle, |
1011 void** pickle_iter) { | 1032 void** pickle_iter) { |
1012 const char* data; | 1033 const char* data; |
1013 int length; | 1034 int length; |
1014 if (!pickle.ReadData(pickle_iter, &data, &length)) | 1035 if (!pickle.ReadData(pickle_iter, &data, &length)) |
1015 return NULL; | 1036 return NULL; |
1016 | 1037 |
1017 return CreateOSCertHandleFromBytes(data, length); | 1038 return CreateOSCertHandleFromBytes(data, length); |
1018 } | 1039 } |
1019 | 1040 |
1020 // static | 1041 // static |
1021 bool X509Certificate::WriteOSCertHandleToPickle(OSCertHandle cert_handle, | 1042 bool X509Certificate::WriteOSCertHandleToPickle(OSCertHandle cert_handle, |
1022 Pickle* pickle) { | 1043 Pickle* pickle) { |
1023 return pickle->WriteData( | 1044 return pickle->WriteData( |
1024 reinterpret_cast<const char*>(cert_handle->derCert.data), | 1045 reinterpret_cast<const char*>(cert_handle->derCert.data), |
1025 cert_handle->derCert.len); | 1046 cert_handle->derCert.len); |
1026 } | 1047 } |
1027 | 1048 |
1028 } // namespace net | 1049 } // namespace net |
OLD | NEW |