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 24 matching lines...) Expand all Loading... |
35 void VerifyCertificateSignature(const std::string& der_cert, | 35 void VerifyCertificateSignature(const std::string& der_cert, |
36 const std::vector<uint8>& der_spki) { | 36 const std::vector<uint8>& der_spki) { |
37 crypto::ScopedPLArenaPool arena(PORT_NewArena(DER_DEFAULT_CHUNKSIZE)); | 37 crypto::ScopedPLArenaPool arena(PORT_NewArena(DER_DEFAULT_CHUNKSIZE)); |
38 | 38 |
39 CERTSignedData sd; | 39 CERTSignedData sd; |
40 memset(&sd, 0, sizeof(sd)); | 40 memset(&sd, 0, sizeof(sd)); |
41 | 41 |
42 SECItem der_cert_item = { | 42 SECItem der_cert_item = { |
43 siDERCertBuffer, | 43 siDERCertBuffer, |
44 reinterpret_cast<unsigned char*>(const_cast<char*>(der_cert.data())), | 44 reinterpret_cast<unsigned char*>(const_cast<char*>(der_cert.data())), |
45 der_cert.size() | 45 static_cast<unsigned int>(der_cert.size()) |
46 }; | 46 }; |
47 SECStatus rv = SEC_ASN1DecodeItem(arena.get(), &sd, | 47 SECStatus rv = SEC_ASN1DecodeItem(arena.get(), &sd, |
48 SEC_ASN1_GET(CERT_SignedDataTemplate), | 48 SEC_ASN1_GET(CERT_SignedDataTemplate), |
49 &der_cert_item); | 49 &der_cert_item); |
50 ASSERT_EQ(SECSuccess, rv); | 50 ASSERT_EQ(SECSuccess, rv); |
51 | 51 |
52 // The CERTSignedData.signatureAlgorithm is decoded, but SignatureVerifier | 52 // The CERTSignedData.signatureAlgorithm is decoded, but SignatureVerifier |
53 // wants the DER encoded form, so re-encode it again. | 53 // wants the DER encoded form, so re-encode it again. |
54 SECItem* signature_algorithm = SEC_ASN1EncodeItem( | 54 SECItem* signature_algorithm = SEC_ASN1EncodeItem( |
55 arena.get(), | 55 arena.get(), |
(...skipping 22 matching lines...) Expand all Loading... |
78 | 78 |
79 void VerifyDomainBoundCert(const std::string& domain, | 79 void VerifyDomainBoundCert(const std::string& domain, |
80 const std::string& der_cert) { | 80 const std::string& der_cert) { |
81 // Origin Bound Cert OID. | 81 // Origin Bound Cert OID. |
82 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"; |
83 | 83 |
84 // Create object neccessary for extension lookup call. | 84 // Create object neccessary for extension lookup call. |
85 SECItem extension_object = { | 85 SECItem extension_object = { |
86 siAsciiString, | 86 siAsciiString, |
87 (unsigned char*)domain.data(), | 87 (unsigned char*)domain.data(), |
88 domain.size() | 88 static_cast<unsigned int>(domain.size()) |
89 }; | 89 }; |
90 | 90 |
91 // IA5Encode and arena allocate SECItem. | 91 // IA5Encode and arena allocate SECItem. |
92 PLArenaPool* arena = PORT_NewArena(DER_DEFAULT_CHUNKSIZE); | 92 PLArenaPool* arena = PORT_NewArena(DER_DEFAULT_CHUNKSIZE); |
93 SECItem* expected = SEC_ASN1EncodeItem(arena, | 93 SECItem* expected = SEC_ASN1EncodeItem(arena, |
94 NULL, | 94 NULL, |
95 &extension_object, | 95 &extension_object, |
96 SEC_ASN1_GET(SEC_IA5StringTemplate)); | 96 SEC_ASN1_GET(SEC_IA5StringTemplate)); |
97 | 97 |
98 ASSERT_NE(static_cast<SECItem*>(NULL), expected); | 98 ASSERT_NE(static_cast<SECItem*>(NULL), expected); |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 | 162 |
163 #if !defined(OS_WIN) && !defined(OS_MACOSX) | 163 #if !defined(OS_WIN) && !defined(OS_MACOSX) |
164 // 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. |
165 std::vector<uint8> spki; | 165 std::vector<uint8> spki; |
166 ASSERT_TRUE(private_key->ExportPublicKey(&spki)); | 166 ASSERT_TRUE(private_key->ExportPublicKey(&spki)); |
167 VerifyCertificateSignature(der_cert, spki); | 167 VerifyCertificateSignature(der_cert, spki); |
168 #endif | 168 #endif |
169 } | 169 } |
170 | 170 |
171 } // namespace net | 171 } // namespace net |
OLD | NEW |