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 "base/lazy_instance.h" | 7 #include "base/lazy_instance.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/pickle.h" | 9 #include "base/pickle.h" |
10 #include "base/sha1.h" | 10 #include "base/sha1.h" |
(...skipping 530 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
541 valid_expiry_ = Time::FromFileTime(cert_handle_->pCertInfo->NotAfter); | 541 valid_expiry_ = Time::FromFileTime(cert_handle_->pCertInfo->NotAfter); |
542 | 542 |
543 fingerprint_ = CalculateFingerprint(cert_handle_); | 543 fingerprint_ = CalculateFingerprint(cert_handle_); |
544 | 544 |
545 const CRYPT_INTEGER_BLOB* serial = &cert_handle_->pCertInfo->SerialNumber; | 545 const CRYPT_INTEGER_BLOB* serial = &cert_handle_->pCertInfo->SerialNumber; |
546 scoped_array<uint8> serial_bytes(new uint8[serial->cbData]); | 546 scoped_array<uint8> serial_bytes(new uint8[serial->cbData]); |
547 for (unsigned i = 0; i < serial->cbData; i++) | 547 for (unsigned i = 0; i < serial->cbData; i++) |
548 serial_bytes[i] = serial->pbData[serial->cbData - i - 1]; | 548 serial_bytes[i] = serial->pbData[serial->cbData - i - 1]; |
549 serial_number_ = std::string( | 549 serial_number_ = std::string( |
550 reinterpret_cast<char*>(serial_bytes.get()), serial->cbData); | 550 reinterpret_cast<char*>(serial_bytes.get()), serial->cbData); |
551 // Remove leading zeros. | |
552 while (serial_number_.size() > 1 && serial_number_[0] == 0) | |
553 serial_number_ = serial_number_.substr(1, serial_number_.size() - 1); | |
554 } | 551 } |
555 | 552 |
556 // IsIssuedByKnownRoot returns true if the given chain is rooted at a root CA | 553 // IsIssuedByKnownRoot returns true if the given chain is rooted at a root CA |
557 // which we recognise as a standard root. | 554 // which we recognise as a standard root. |
558 // static | 555 // static |
559 bool X509Certificate::IsIssuedByKnownRoot(PCCERT_CHAIN_CONTEXT chain_context) { | 556 bool X509Certificate::IsIssuedByKnownRoot(PCCERT_CHAIN_CONTEXT chain_context) { |
560 PCERT_SIMPLE_CHAIN first_chain = chain_context->rgpChain[0]; | 557 PCERT_SIMPLE_CHAIN first_chain = chain_context->rgpChain[0]; |
561 int num_elements = first_chain->cElement; | 558 int num_elements = first_chain->cElement; |
562 if (num_elements < 1) | 559 if (num_elements < 1) |
563 return false; | 560 return false; |
(...skipping 488 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1052 if (!CertSerializeCertificateStoreElement(cert_handle, 0, &buffer[0], | 1049 if (!CertSerializeCertificateStoreElement(cert_handle, 0, &buffer[0], |
1053 &length)) { | 1050 &length)) { |
1054 return false; | 1051 return false; |
1055 } | 1052 } |
1056 | 1053 |
1057 return pickle->WriteData(reinterpret_cast<const char*>(&buffer[0]), | 1054 return pickle->WriteData(reinterpret_cast<const char*>(&buffer[0]), |
1058 length); | 1055 length); |
1059 } | 1056 } |
1060 | 1057 |
1061 } // namespace net | 1058 } // namespace net |
OLD | NEW |