| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 <pk11pub.h> | 8 #include <pk11pub.h> |
| 9 #include <prerror.h> | 9 #include <prerror.h> |
| 10 #include <prtime.h> | 10 #include <prtime.h> |
| (...skipping 599 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 610 return false; | 610 return false; |
| 611 | 611 |
| 612 return true; | 612 return true; |
| 613 } | 613 } |
| 614 | 614 |
| 615 // static | 615 // static |
| 616 X509Certificate::OSCertHandle X509Certificate::CreateOSCertHandleFromBytes( | 616 X509Certificate::OSCertHandle X509Certificate::CreateOSCertHandleFromBytes( |
| 617 const char* data, int length) { | 617 const char* data, int length) { |
| 618 base::EnsureNSSInit(); | 618 base::EnsureNSSInit(); |
| 619 | 619 |
| 620 SECItem der_cert; | 620 // Make a copy of |data| since CERT_DecodeCertPackage might modify it. |
| 621 der_cert.data = reinterpret_cast<unsigned char*>(const_cast<char*>(data)); | 621 char* data_copy = new char[length]; |
| 622 der_cert.len = length; | 622 memcpy(data_copy, data, length); |
| 623 return CERT_NewTempCertificate(CERT_GetDefaultCertDB(), &der_cert, | 623 |
| 624 NULL, PR_FALSE, PR_TRUE); | 624 // Parse into a certificate structure. |
| 625 CERTCertificate* cert = CERT_DecodeCertFromPackage(data_copy, length); |
| 626 delete [] data_copy; |
| 627 if (!cert) |
| 628 LOG(ERROR) << "Couldn't parse a certificate from " << length << " bytes"; |
| 629 return cert; |
| 625 } | 630 } |
| 626 | 631 |
| 627 // static | 632 // static |
| 628 void X509Certificate::FreeOSCertHandle(OSCertHandle cert_handle) { | 633 void X509Certificate::FreeOSCertHandle(OSCertHandle cert_handle) { |
| 629 CERT_DestroyCertificate(cert_handle); | 634 CERT_DestroyCertificate(cert_handle); |
| 630 } | 635 } |
| 631 | 636 |
| 632 // static | 637 // static |
| 633 X509Certificate::Fingerprint X509Certificate::CalculateFingerprint( | 638 X509Certificate::Fingerprint X509Certificate::CalculateFingerprint( |
| 634 OSCertHandle cert) { | 639 OSCertHandle cert) { |
| 635 Fingerprint sha1; | 640 Fingerprint sha1; |
| 636 memset(sha1.data, 0, sizeof(sha1.data)); | 641 memset(sha1.data, 0, sizeof(sha1.data)); |
| 637 | 642 |
| 638 DCHECK(NULL != cert->derCert.data); | 643 DCHECK(NULL != cert->derCert.data); |
| 639 DCHECK(0 != cert->derCert.len); | 644 DCHECK(0 != cert->derCert.len); |
| 640 | 645 |
| 641 SECStatus rv = HASH_HashBuf(HASH_AlgSHA1, sha1.data, | 646 SECStatus rv = HASH_HashBuf(HASH_AlgSHA1, sha1.data, |
| 642 cert->derCert.data, cert->derCert.len); | 647 cert->derCert.data, cert->derCert.len); |
| 643 DCHECK(rv == SECSuccess); | 648 DCHECK(rv == SECSuccess); |
| 644 | 649 |
| 645 return sha1; | 650 return sha1; |
| 646 } | 651 } |
| 647 | 652 |
| 648 } // namespace net | 653 } // namespace net |
| OLD | NEW |