| 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_util.h" | 5 #include "net/base/x509_util.h" |
| 6 #include "net/base/x509_util_nss.h" | 6 #include "net/base/x509_util_nss.h" |
| 7 | 7 |
| 8 #include <cert.h> | 8 #include <cert.h> |
| 9 #include <secoid.h> | 9 #include <secoid.h> |
| 10 | 10 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 SECItem der_cert; | 24 SECItem der_cert; |
| 25 der_cert.data = reinterpret_cast<unsigned char*>(const_cast<char*>(data)); | 25 der_cert.data = reinterpret_cast<unsigned char*>(const_cast<char*>(data)); |
| 26 der_cert.len = length; | 26 der_cert.len = length; |
| 27 der_cert.type = siDERCertBuffer; | 27 der_cert.type = siDERCertBuffer; |
| 28 | 28 |
| 29 // Parse into a certificate structure. | 29 // Parse into a certificate structure. |
| 30 return CERT_NewTempCertificate(CERT_GetDefaultCertDB(), &der_cert, NULL, | 30 return CERT_NewTempCertificate(CERT_GetDefaultCertDB(), &der_cert, NULL, |
| 31 PR_FALSE, PR_TRUE); | 31 PR_FALSE, PR_TRUE); |
| 32 } | 32 } |
| 33 | 33 |
| 34 #if !defined(OS_WIN) && !defined(OS_MACOSX) |
| 34 void VerifyCertificateSignature(const std::string& der_cert, | 35 void VerifyCertificateSignature(const std::string& der_cert, |
| 35 const std::vector<uint8>& der_spki) { | 36 const std::vector<uint8>& der_spki) { |
| 36 crypto::ScopedPLArenaPool arena(PORT_NewArena(DER_DEFAULT_CHUNKSIZE)); | 37 crypto::ScopedPLArenaPool arena(PORT_NewArena(DER_DEFAULT_CHUNKSIZE)); |
| 37 | 38 |
| 38 CERTSignedData sd; | 39 CERTSignedData sd; |
| 39 memset(&sd, 0, sizeof(sd)); | 40 memset(&sd, 0, sizeof(sd)); |
| 40 | 41 |
| 41 SECItem der_cert_item = { | 42 SECItem der_cert_item = { |
| 42 siDERCertBuffer, | 43 siDERCertBuffer, |
| 43 reinterpret_cast<unsigned char*>(const_cast<char*>(der_cert.data())), | 44 reinterpret_cast<unsigned char*>(const_cast<char*>(der_cert.data())), |
| (...skipping 22 matching lines...) Expand all Loading... |
| 66 &der_spki[0], | 67 &der_spki[0], |
| 67 der_spki.size()); | 68 der_spki.size()); |
| 68 | 69 |
| 69 ASSERT_TRUE(ok); | 70 ASSERT_TRUE(ok); |
| 70 verifier.VerifyUpdate(sd.data.data, | 71 verifier.VerifyUpdate(sd.data.data, |
| 71 sd.data.len); | 72 sd.data.len); |
| 72 | 73 |
| 73 ok = verifier.VerifyFinal(); | 74 ok = verifier.VerifyFinal(); |
| 74 EXPECT_TRUE(ok); | 75 EXPECT_TRUE(ok); |
| 75 } | 76 } |
| 77 #endif // !defined(OS_WIN) && !defined(OS_MACOSX) |
| 76 | 78 |
| 77 void VerifyDomainBoundCert(const std::string& domain, | 79 void VerifyDomainBoundCert(const std::string& domain, |
| 78 const std::string& der_cert) { | 80 const std::string& der_cert) { |
| 79 // Origin Bound Cert OID. | 81 // Origin Bound Cert OID. |
| 80 static const char oid_string[] = "1.3.6.1.4.1.11129.2.1.6"; | 82 static const char oid_string[] = "1.3.6.1.4.1.11129.2.1.6"; |
| 81 | 83 |
| 82 // Create object neccessary for extension lookup call. | 84 // Create object neccessary for extension lookup call. |
| 83 SECItem extension_object = { | 85 SECItem extension_object = { |
| 84 siAsciiString, | 86 siAsciiString, |
| 85 (unsigned char*)domain.data(), | 87 (unsigned char*)domain.data(), |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 | 162 |
| 161 #if !defined(OS_WIN) && !defined(OS_MACOSX) | 163 #if !defined(OS_WIN) && !defined(OS_MACOSX) |
| 162 // signature_verifier_win and signature_verifier_mac can't handle EC certs. | 164 // signature_verifier_win and signature_verifier_mac can't handle EC certs. |
| 163 std::vector<uint8> spki; | 165 std::vector<uint8> spki; |
| 164 ASSERT_TRUE(private_key->ExportPublicKey(&spki)); | 166 ASSERT_TRUE(private_key->ExportPublicKey(&spki)); |
| 165 VerifyCertificateSignature(der_cert, spki); | 167 VerifyCertificateSignature(der_cert, spki); |
| 166 #endif | 168 #endif |
| 167 } | 169 } |
| 168 | 170 |
| 169 } // namespace net | 171 } // namespace net |
| OLD | NEW |