OLD | NEW |
---|---|
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 "base/files/file_path.h" | |
6 #include "net/base/net_errors.h" | |
7 #include "net/base/test_completion_callback.h" | |
8 #include "net/base/test_data_directory.h" | |
9 #include "net/cert/x509_certificate.h" | |
5 #include "net/quic/crypto/proof_source.h" | 10 #include "net/quic/crypto/proof_source.h" |
6 #include "net/quic/crypto/proof_verifier.h" | 11 #include "net/quic/crypto/proof_verifier.h" |
7 #include "net/quic/test_tools/crypto_test_utils.h" | 12 #include "net/quic/test_tools/crypto_test_utils.h" |
13 #include "net/test/cert_test_util.h" | |
8 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
9 | 15 |
10 using std::string; | 16 using std::string; |
11 using std::vector; | 17 using std::vector; |
12 | 18 |
13 namespace net { | 19 namespace net { |
14 namespace test { | 20 namespace test { |
15 | 21 |
16 TEST(Proof, Verify) { | 22 TEST(Proof, Verify) { |
17 // TODO(rtenneti): Enable testing of ProofVerifier. | 23 // TODO(rtenneti): Enable testing of ProofVerifier. |
18 #if 0 | 24 #if 0 |
19 scoped_ptr<ProofSource> source(CryptoTestUtils::ProofSourceForTesting()); | 25 scoped_ptr<ProofSource> source(CryptoTestUtils::ProofSourceForTesting()); |
20 scoped_ptr<ProofVerifier> verifier( | 26 scoped_ptr<ProofVerifier> verifier( |
21 CryptoTestUtils::ProofVerifierForTesting()); | 27 CryptoTestUtils::ProofVerifierForTesting()); |
22 | 28 |
23 const string server_config = "server config bytes"; | 29 const string server_config = "server config bytes"; |
24 const string hostname = "test.example.com"; | 30 const string hostname = "test.example.com"; |
25 const vector<string>* certs; | 31 const vector<string>* certs; |
26 const vector<string>* first_certs; | 32 const vector<string>* first_certs; |
27 string error_details, signature, first_signature; | 33 string signature, first_signature; |
28 | 34 |
29 ASSERT_TRUE(source->GetProof(hostname, server_config, &first_certs, | 35 ASSERT_TRUE(source->GetProof(hostname, server_config, &first_certs, |
30 &first_signature)); | 36 &first_signature)); |
31 ASSERT_TRUE(source->GetProof(hostname, server_config, &certs, &signature)); | 37 ASSERT_TRUE(source->GetProof(hostname, server_config, &certs, &signature)); |
32 | 38 |
33 // Check that the proof source is caching correctly: | 39 // Check that the proof source is caching correctly: |
34 ASSERT_EQ(first_certs, certs); | 40 ASSERT_EQ(first_certs, certs); |
35 ASSERT_EQ(signature, first_signature); | 41 ASSERT_EQ(signature, first_signature); |
36 | 42 |
37 ASSERT_TRUE(verifier->VerifyProof(hostname, server_config, *certs, signature, | 43 int rv; |
38 &error_details)); | 44 TestCompletionCallback callback; |
39 ASSERT_FALSE(verifier->VerifyProof("foo.com", server_config, *certs, | 45 rv = verifier->VerifyProof(hostname, server_config, *certs, signature, |
40 signature, &error_details)); | 46 callback.callback()); |
41 ASSERT_FALSE( | 47 if (rv == ERR_IO_PENDING) |
42 verifier->VerifyProof(hostname, server_config.substr(1, string::npos), | 48 rv = callback.WaitForResult(); |
43 *certs, signature, &error_details)); | 49 ASSERT_EQ(OK, rv); |
50 ASSERT_EQ("", verifier->error_details()); | |
51 | |
52 rv = verifier->VerifyProof("foo.com", server_config, *certs, | |
53 signature, callback.callback()); | |
54 if (rv == ERR_IO_PENDING) | |
55 rv = callback.WaitForResult(); | |
56 ASSERT_EQ(ERR_FAILED, rv); | |
57 ASSERT_NE("", verifier->error_details()); | |
58 | |
59 rv = verifier->VerifyProof(hostname, server_config.substr(1, string::npos), | |
60 *certs, signature, callback.callback()); | |
61 if (rv == ERR_IO_PENDING) | |
62 rv = callback.WaitForResult(); | |
63 ASSERT_EQ(ERR_FAILED, rv); | |
64 ASSERT_NE("", verifier->error_details()); | |
65 | |
44 const string corrupt_signature = "1" + signature; | 66 const string corrupt_signature = "1" + signature; |
45 ASSERT_FALSE(verifier->VerifyProof(hostname, server_config, *certs, | 67 rv = verifier->VerifyProof(hostname, server_config, *certs, |
46 corrupt_signature, &error_details)); | 68 corrupt_signature, callback.callback()); |
69 if (rv == ERR_IO_PENDING) | |
70 rv = callback.WaitForResult(); | |
71 ASSERT_EQ(ERR_FAILED, rv); | |
72 ASSERT_NE("", verifier->error_details()); | |
47 | 73 |
48 vector<string> wrong_certs; | 74 vector<string> wrong_certs; |
49 for (size_t i = 1; i < certs->size(); i++) { | 75 for (size_t i = 1; i < certs->size(); i++) { |
50 wrong_certs.push_back((*certs)[i]); | 76 wrong_certs.push_back((*certs)[i]); |
51 } | 77 } |
52 ASSERT_FALSE(verifier->VerifyProof("foo.com", server_config, wrong_certs, | 78 rv = verifier->VerifyProof("foo.com", server_config, wrong_certs, |
53 signature, &error_details)); | 79 signature, callback.callback()); |
80 if (rv == ERR_IO_PENDING) | |
81 rv = callback.WaitForResult(); | |
82 ASSERT_EQ(ERR_FAILED, rv); | |
83 ASSERT_NE("", verifier->error_details()); | |
54 #endif // 0 | 84 #endif // 0 |
55 } | 85 } |
56 | 86 |
87 static string PEMCertFileToDER(const string& file_name) { | |
88 base::FilePath certs_dir = GetTestCertsDirectory(); | |
89 scoped_refptr<X509Certificate> cert = | |
90 ImportCertFromFile(certs_dir, file_name); | |
91 CHECK_NE(static_cast<X509Certificate*>(NULL), cert); | |
92 | |
93 string der_bytes; | |
94 CHECK(X509Certificate::GetDEREncoded(cert->os_cert_handle(), &der_bytes)); | |
95 return der_bytes; | |
96 } | |
97 | |
98 // A known answer test that allows us to test ProofVerifier without a working | |
99 // ProofSource. | |
100 TEST(Proof, VerifyRSAKnownAnswerTest) { | |
101 // These sample signatures were generated by running the Proof.Verify test | |
102 // and dumping the bytes of the |signature| output of ProofSource::GetProof(). | |
103 #if 0 | |
104 // sLen = hLen | |
agl
2013/07/01 16:23:18
The #if 0 block should probably either be removed,
wtc
2013/07/02 00:56:38
ramant: please feel free to just delete the #if 0
ramant (doing other things)
2013/07/02 14:19:50
Added a comment.
Done.
| |
105 static const unsigned char signature_data_0[] = { | |
106 0x9e, 0xe6, 0x74, 0x3b, 0x8f, 0xb8, 0x66, 0x77, 0x57, 0x09, | |
107 0x8a, 0x04, 0xe9, 0xf0, 0x7c, 0x91, 0xa9, 0x5c, 0xe9, 0xdf, | |
108 0x12, 0x4d, 0x23, 0x82, 0x8c, 0x29, 0x72, 0x7f, 0xc2, 0x20, | |
109 0xa7, 0xb3, 0xe5, 0xbc, 0xcf, 0x3c, 0x0d, 0x8f, 0xae, 0x46, | |
110 0x6a, 0xb9, 0xee, 0x0c, 0xe1, 0x13, 0x21, 0xc0, 0x7e, 0x45, | |
111 0x24, 0x24, 0x4b, 0x72, 0x43, 0x5e, 0xc4, 0x0d, 0xdf, 0x6c, | |
112 0xd8, 0xaa, 0x35, 0x97, 0x05, 0x40, 0x76, 0xd3, 0x2c, 0xee, | |
113 0x82, 0x16, 0x6a, 0x43, 0xf9, 0xa2, 0xd0, 0x41, 0x3c, 0xed, | |
114 0x3f, 0x40, 0x10, 0x95, 0xc7, 0xa9, 0x1f, 0x04, 0xdb, 0xd5, | |
115 0x98, 0x9f, 0xe2, 0xbf, 0x77, 0x3d, 0xc9, 0x9a, 0xaf, 0xf7, | |
116 0xef, 0x63, 0x0b, 0x7d, 0xc8, 0x37, 0xda, 0x37, 0x23, 0x88, | |
117 0x78, 0xc8, 0x8b, 0xf5, 0xb9, 0x36, 0x5d, 0x72, 0x1f, 0xfc, | |
118 0x14, 0xff, 0xa7, 0x81, 0x27, 0x49, 0xae, 0xe1, | |
119 }; | |
120 static const unsigned char signature_data_1[] = { | |
121 0x5e, 0xc2, 0xab, 0x6b, 0x16, 0xe6, 0x55, 0xf3, 0x16, 0x46, | |
122 0x35, 0xdc, 0xcc, 0xde, 0xd0, 0xbd, 0x6c, 0x66, 0xb2, 0x3d, | |
123 0xd3, 0x14, 0x78, 0xed, 0x47, 0x55, 0xfb, 0xdb, 0xe1, 0x7d, | |
124 0xbf, 0x31, 0xf6, 0xf4, 0x10, 0x4c, 0x8d, 0x22, 0x17, 0xaa, | |
125 0xe1, 0x85, 0xc7, 0x96, 0x4c, 0x42, 0xfb, 0xf4, 0x63, 0x53, | |
126 0x8a, 0x79, 0x01, 0x63, 0x48, 0xa8, 0x3a, 0xbc, 0xc9, 0xd2, | |
127 0xf5, 0xec, 0xe9, 0x09, 0x71, 0xaf, 0xce, 0x34, 0x56, 0xe5, | |
128 0x00, 0xbe, 0xee, 0x3c, 0x1c, 0xc4, 0xa0, 0x07, 0xd5, 0x77, | |
129 0xb8, 0x83, 0x57, 0x7d, 0x1a, 0xc9, 0xd0, 0xc0, 0x59, 0x9a, | |
130 0x88, 0x19, 0x3f, 0xb9, 0xf0, 0x45, 0x37, 0xc3, 0x00, 0x8b, | |
131 0xb3, 0x89, 0xf4, 0x89, 0x07, 0xa9, 0xc3, 0x26, 0xbf, 0x81, | |
132 0xaf, 0x6b, 0x47, 0xbc, 0x16, 0x55, 0x37, 0x0a, 0xbe, 0x0e, | |
133 0xc5, 0x75, 0x3f, 0x3d, 0x8e, 0xe8, 0x44, 0xe3, | |
134 }; | |
135 static const unsigned char signature_data_2[] = { | |
136 0x8e, 0x5c, 0x78, 0x63, 0x74, 0x99, 0x2e, 0x96, 0xc0, 0x14, | |
137 0x8d, 0xb5, 0x13, 0x74, 0xa3, 0xa4, 0xe0, 0x43, 0x3e, 0x85, | |
138 0xba, 0x8f, 0x3c, 0x5e, 0x14, 0x64, 0x0e, 0x5e, 0xff, 0x89, | |
139 0x88, 0x8a, 0x65, 0xe2, 0xa2, 0x79, 0xe4, 0xe9, 0x3a, 0x7f, | |
140 0xf6, 0x9d, 0x3d, 0xe2, 0xb0, 0x8a, 0x35, 0x55, 0xed, 0x21, | |
141 0xee, 0x20, 0xd8, 0x8a, 0x60, 0x47, 0xca, 0x52, 0x54, 0x91, | |
142 0x99, 0x69, 0x8d, 0x16, 0x34, 0x69, 0xe1, 0x46, 0x56, 0x67, | |
143 0x5f, 0x50, 0xf0, 0x94, 0xe7, 0x8b, 0xf2, 0x6a, 0x73, 0x0f, | |
144 0x30, 0x30, 0xde, 0x59, 0xdc, 0xc7, 0xfe, 0xb6, 0x83, 0xe1, | |
145 0x86, 0x1d, 0x88, 0xd3, 0x2f, 0x2f, 0x74, 0x68, 0xbd, 0x6c, | |
146 0xd1, 0x46, 0x76, 0x06, 0xa9, 0xd4, 0x03, 0x3f, 0xda, 0x7d, | |
147 0xa7, 0xff, 0x48, 0xe4, 0xb4, 0x42, 0x06, 0xac, 0x19, 0x12, | |
148 0xe6, 0x05, 0xae, 0xbe, 0x29, 0x94, 0x8f, 0x99, | |
149 }; | |
150 #else | |
151 // sLen = special value -2 used by OpenSSL. | |
152 static const unsigned char signature_data_0[] = { | |
153 0x4c, 0x68, 0x3c, 0xc2, 0x1f, 0x31, 0x73, 0xa5, 0x29, 0xd3, | |
154 0x56, 0x75, 0xb1, 0xbf, 0xbd, 0x31, 0x17, 0xfb, 0x2e, 0x24, | |
155 0xb3, 0xc4, 0x0d, 0xfa, 0x56, 0xb8, 0x65, 0x94, 0x12, 0x38, | |
156 0x6e, 0xff, 0xb3, 0x10, 0x2e, 0xf8, 0x5c, 0xc1, 0x21, 0x9d, | |
157 0x29, 0x0c, 0x3a, 0x0a, 0x1a, 0xbf, 0x6b, 0x1c, 0x63, 0x77, | |
158 0xf7, 0x86, 0xd3, 0xa4, 0x36, 0xf2, 0xb1, 0x6f, 0xac, 0xc3, | |
159 0x23, 0x8d, 0xda, 0xe6, 0xd5, 0x83, 0xba, 0xdf, 0x28, 0x3e, | |
160 0x7f, 0x4e, 0x79, 0xfc, 0xba, 0xdb, 0xf7, 0xd0, 0x4b, 0xad, | |
161 0x79, 0xd0, 0xeb, 0xcf, 0xfa, 0x6e, 0x84, 0x44, 0x7a, 0x26, | |
162 0xb1, 0x29, 0xa3, 0x08, 0xa8, 0x63, 0xfd, 0xed, 0x85, 0xff, | |
163 0x9a, 0xe6, 0x79, 0x8b, 0xb6, 0x81, 0x13, 0x2c, 0xde, 0xe2, | |
164 0xd8, 0x31, 0x29, 0xa4, 0xe0, 0x1b, 0x75, 0x2d, 0x8a, 0xf8, | |
165 0x27, 0x55, 0xbc, 0xc7, 0x3b, 0x1e, 0xc1, 0x42, | |
166 }; | |
167 static const unsigned char signature_data_1[] = { | |
168 0xbb, 0xd1, 0x17, 0x43, 0xf3, 0x42, 0x16, 0xe9, 0xf9, 0x76, | |
169 0xe6, 0xe3, 0xaa, 0x50, 0x47, 0x5f, 0x93, 0xb6, 0x7d, 0x35, | |
170 0x03, 0x49, 0x0a, 0x07, 0x61, 0xd5, 0xf1, 0x9c, 0x6b, 0xaf, | |
171 0xaa, 0xd7, 0x64, 0xe4, 0x0a, 0x0c, 0xab, 0x97, 0xfb, 0x4e, | |
172 0x5c, 0x14, 0x08, 0xf6, 0xb9, 0xa9, 0x1d, 0xa9, 0xf8, 0x6d, | |
173 0xb0, 0x2b, 0x2a, 0x0e, 0xc4, 0xd0, 0xd2, 0xe9, 0x96, 0x4f, | |
174 0x44, 0x70, 0x90, 0x46, 0xb9, 0xd5, 0x89, 0x72, 0xb9, 0xa8, | |
175 0xe4, 0xfb, 0x88, 0xbc, 0x69, 0x7f, 0xc9, 0xdc, 0x84, 0x87, | |
176 0x18, 0x21, 0x9b, 0xde, 0x22, 0x33, 0xde, 0x16, 0x3f, 0xe6, | |
177 0xfd, 0x27, 0x56, 0xd3, 0xa4, 0x97, 0x91, 0x65, 0x1a, 0xe7, | |
178 0x5e, 0x80, 0x9a, 0xbf, 0xbf, 0x1a, 0x29, 0x8a, 0xbe, 0xa2, | |
179 0x8c, 0x9c, 0x23, 0xf4, 0xcb, 0xba, 0x79, 0x31, 0x28, 0xab, | |
180 0x77, 0x94, 0x92, 0xb2, 0xc2, 0x35, 0xb2, 0xfa, | |
181 }; | |
182 static const unsigned char signature_data_2[] = { | |
183 0x7e, 0x17, 0x01, 0xcb, 0x76, 0x9e, 0x9f, 0xce, 0xeb, 0x66, | |
184 0x3e, 0xaa, 0xc9, 0x36, 0x5b, 0x7e, 0x48, 0x25, 0x99, 0xf8, | |
185 0x0d, 0xe1, 0xa8, 0x48, 0x93, 0x3c, 0xe8, 0x97, 0x2e, 0x98, | |
186 0xd6, 0x73, 0x0f, 0xd0, 0x74, 0x9c, 0x17, 0xef, 0xee, 0xf8, | |
187 0x0e, 0x2a, 0x27, 0x3f, 0xc6, 0x55, 0xc6, 0xb9, 0xfe, 0x17, | |
188 0xcc, 0xeb, 0x5d, 0xa1, 0xdc, 0xbd, 0x64, 0xd9, 0x5e, 0xec, | |
189 0x57, 0x9d, 0xc3, 0xdc, 0x11, 0xbf, 0x23, 0x02, 0x58, 0xc4, | |
190 0xf1, 0x18, 0xc1, 0x6f, 0x3f, 0xef, 0x18, 0x4d, 0xa6, 0x1e, | |
191 0xe8, 0x25, 0x32, 0x8f, 0x92, 0x1e, 0xad, 0xbc, 0xbe, 0xde, | |
192 0x83, 0x2a, 0x92, 0xd5, 0x59, 0x6f, 0xe4, 0x95, 0x6f, 0xe6, | |
193 0xb1, 0xf9, 0xaf, 0x3f, 0xdb, 0x69, 0x6f, 0xae, 0xa6, 0x36, | |
194 0xd2, 0x50, 0x81, 0x78, 0x41, 0x13, 0x2c, 0x65, 0x9c, 0x9e, | |
195 0xf4, 0xd2, 0xd5, 0x58, 0x5b, 0x8b, 0x87, 0xcf, | |
196 }; | |
197 #endif | |
198 | |
199 scoped_ptr<ProofVerifier> verifier( | |
200 CryptoTestUtils::ProofVerifierForTesting()); | |
201 | |
202 const string server_config = "server config bytes"; | |
203 const string hostname = "test.example.com"; | |
204 | |
205 vector<string> certs(2); | |
206 certs[0] = PEMCertFileToDER("test.example.com.crt"); | |
207 certs[1] = PEMCertFileToDER("intermediate.crt"); | |
208 | |
209 // Signatures are nondeterministic, so we test multiple signatures on the | |
210 // same server_config. | |
211 vector<string> signatures(3); | |
212 signatures[0].assign(reinterpret_cast<const char*>(signature_data_0), | |
213 sizeof(signature_data_0)); | |
214 signatures[1].assign(reinterpret_cast<const char*>(signature_data_1), | |
215 sizeof(signature_data_1)); | |
216 signatures[2].assign(reinterpret_cast<const char*>(signature_data_2), | |
217 sizeof(signature_data_2)); | |
218 | |
219 for (size_t i = 0; i < signatures.size(); i++) { | |
220 const string& signature = signatures[i]; | |
221 int rv; | |
222 TestCompletionCallback callback; | |
223 rv = verifier->VerifyProof(hostname, server_config, certs, signature, | |
224 callback.callback()); | |
225 if (rv == ERR_IO_PENDING) | |
226 rv = callback.WaitForResult(); | |
wtc
2013/07/02 00:56:38
Nit: this can be rewritten more compactly as
rv
ramant (doing other things)
2013/07/02 14:19:50
Done.
| |
227 ASSERT_EQ(OK, rv); | |
228 ASSERT_EQ("", verifier->error_details()); | |
wtc
2013/07/02 00:56:38
Nit: add blank lines between these tests. Specific
ramant (doing other things)
2013/07/02 14:19:50
Done.
| |
229 rv = verifier->VerifyProof("foo.com", server_config, certs, signature, | |
230 callback.callback()); | |
231 if (rv == ERR_IO_PENDING) | |
232 rv = callback.WaitForResult(); | |
233 ASSERT_EQ(ERR_FAILED, rv); | |
234 ASSERT_NE("", verifier->error_details()); | |
235 rv = verifier->VerifyProof(hostname, server_config.substr(1, string::npos), | |
236 certs, signature, callback.callback()); | |
237 if (rv == ERR_IO_PENDING) | |
238 rv = callback.WaitForResult(); | |
239 ASSERT_EQ(ERR_FAILED, rv); | |
240 ASSERT_NE("", verifier->error_details()); | |
241 | |
242 const string corrupt_signature = "1" + signature; | |
243 rv = verifier->VerifyProof(hostname, server_config, certs, | |
244 corrupt_signature, callback.callback()); | |
245 if (rv == ERR_IO_PENDING) | |
246 rv = callback.WaitForResult(); | |
247 ASSERT_EQ(ERR_FAILED, rv); | |
248 ASSERT_NE("", verifier->error_details()); | |
249 | |
250 vector<string> wrong_certs; | |
251 for (size_t i = 1; i < certs.size(); i++) { | |
252 wrong_certs.push_back(certs[i]); | |
253 } | |
254 rv = verifier->VerifyProof("foo.com", server_config, wrong_certs, signature, | |
255 callback.callback()); | |
256 if (rv == ERR_IO_PENDING) | |
257 rv = callback.WaitForResult(); | |
258 ASSERT_EQ(ERR_FAILED, rv); | |
259 ASSERT_NE("", verifier->error_details()); | |
260 } | |
261 } | |
262 | |
263 // A known answer test that allows us to test ProofVerifier without a working | |
264 // ProofSource. | |
265 TEST(Proof, VerifyECDSAKnownAnswerTest) { | |
266 // These sample signatures were generated by running the Proof.Verify test | |
267 // (modified to use ECDSA for signing proofs) and dumping the bytes of the | |
268 // |signature| output of ProofSource::GetProof(). | |
269 static const unsigned char signature_data_0[] = { | |
270 0x30, 0x45, 0x02, 0x20, 0x15, 0xb7, 0x9f, 0xe3, 0xd9, 0x7a, | |
271 0x3c, 0x3b, 0x18, 0xb0, 0xdb, 0x60, 0x23, 0x56, 0xa0, 0x06, | |
272 0x4e, 0x70, 0xa3, 0xf7, 0x4b, 0xe5, 0x0d, 0x69, 0xf0, 0x35, | |
273 0x8c, 0xae, 0xb5, 0x54, 0x32, 0xe9, 0x02, 0x21, 0x00, 0xf7, | |
274 0xe3, 0x06, 0x99, 0x16, 0x56, 0x7e, 0xab, 0x33, 0x53, 0x0d, | |
275 0xde, 0xbe, 0xef, 0x6d, 0xb0, 0xc7, 0xa6, 0x63, 0xaf, 0x8d, | |
276 0xab, 0x34, 0xa9, 0xc0, 0x63, 0x88, 0x47, 0x17, 0x4c, 0x4c, | |
277 0x04, | |
278 }; | |
279 static const unsigned char signature_data_1[] = { | |
280 0x30, 0x44, 0x02, 0x20, 0x69, 0x60, 0x55, 0xbb, 0x11, 0x93, | |
281 0x6a, 0xdc, 0x9b, 0x61, 0x2c, 0x60, 0x19, 0xbc, 0x15, 0x55, | |
282 0xcf, 0xf2, 0x8e, 0x2e, 0x27, 0x0b, 0x69, 0xef, 0x33, 0x25, | |
283 0x1e, 0x5d, 0x8c, 0x00, 0x11, 0xef, 0x02, 0x20, 0x0c, 0x26, | |
284 0xfe, 0x0b, 0x06, 0x8f, 0xe8, 0xe2, 0x02, 0x63, 0xe5, 0x43, | |
285 0x0d, 0xc9, 0x80, 0x4d, 0xe9, 0x6f, 0x6e, 0x18, 0xdb, 0xb0, | |
286 0x04, 0x2a, 0x45, 0x37, 0x1a, 0x60, 0x0e, 0xc6, 0xc4, 0x8f, | |
287 }; | |
288 static const unsigned char signature_data_2[] = { | |
289 0x30, 0x45, 0x02, 0x21, 0x00, 0xd5, 0x43, 0x36, 0x60, 0x50, | |
290 0xce, 0xe0, 0x00, 0x51, 0x02, 0x84, 0x95, 0x51, 0x47, 0xaf, | |
291 0xe4, 0xf9, 0xe1, 0x23, 0xae, 0x21, 0xb4, 0x98, 0xd1, 0xa3, | |
292 0x5f, 0x3b, 0xf3, 0x6a, 0x65, 0x44, 0x6b, 0x02, 0x20, 0x30, | |
293 0x7e, 0xb4, 0xea, 0xf0, 0xda, 0xdb, 0xbd, 0x38, 0xb9, 0x7a, | |
294 0x5d, 0x12, 0x04, 0x0e, 0xc2, 0xf0, 0xb1, 0x0e, 0x25, 0xf8, | |
295 0x0a, 0x27, 0xa3, 0x16, 0x94, 0xac, 0x1e, 0xb8, 0x6e, 0x00, | |
296 0x05, | |
297 }; | |
298 | |
299 scoped_ptr<ProofVerifier> verifier( | |
300 CryptoTestUtils::ProofVerifierForTesting()); | |
301 | |
302 const string server_config = "server config bytes"; | |
303 const string hostname = "test.example.com"; | |
304 | |
305 vector<string> certs(2); | |
306 certs[0] = PEMCertFileToDER("test_ecc.example.com.crt"); | |
307 certs[1] = PEMCertFileToDER("intermediate.crt"); | |
308 | |
309 // Signatures are nondeterministic, so we test multiple signatures on the | |
310 // same server_config. | |
311 vector<string> signatures(3); | |
312 signatures[0].assign(reinterpret_cast<const char*>(signature_data_0), | |
313 sizeof(signature_data_0)); | |
314 signatures[1].assign(reinterpret_cast<const char*>(signature_data_1), | |
315 sizeof(signature_data_1)); | |
316 signatures[2].assign(reinterpret_cast<const char*>(signature_data_2), | |
317 sizeof(signature_data_2)); | |
318 | |
319 for (size_t i = 0; i < signatures.size(); i++) { | |
320 const string& signature = signatures[i]; | |
321 int rv; | |
322 TestCompletionCallback callback; | |
323 rv = verifier->VerifyProof(hostname, server_config, certs, signature, | |
324 callback.callback()); | |
325 if (rv == ERR_IO_PENDING) | |
326 rv = callback.WaitForResult(); | |
327 ASSERT_EQ(OK, rv); | |
328 ASSERT_EQ("", verifier->error_details()); | |
329 | |
330 rv = verifier->VerifyProof("foo.com", server_config, certs, | |
331 signature, callback.callback()); | |
332 if (rv == ERR_IO_PENDING) | |
333 rv = callback.WaitForResult(); | |
334 ASSERT_EQ(ERR_FAILED, rv); | |
335 ASSERT_NE("", verifier->error_details()); | |
336 | |
337 rv = verifier->VerifyProof(hostname, server_config.substr(1, string::npos), | |
338 certs, signature, callback.callback()); | |
339 if (rv == ERR_IO_PENDING) | |
340 rv = callback.WaitForResult(); | |
341 ASSERT_EQ(ERR_FAILED, rv); | |
342 ASSERT_NE("", verifier->error_details()); | |
343 | |
344 // An ECDSA signature is DER-encoded. Corrupt the last byte so that the | |
345 // signature can still be DER-decoded correctly. | |
346 string corrupt_signature = signature; | |
347 corrupt_signature[corrupt_signature.size() - 1] += 1; | |
348 rv = verifier->VerifyProof(hostname, server_config, certs, | |
349 corrupt_signature, callback.callback()); | |
350 if (rv == ERR_IO_PENDING) | |
351 rv = callback.WaitForResult(); | |
352 ASSERT_EQ(ERR_FAILED, rv); | |
353 ASSERT_NE("", verifier->error_details()); | |
354 | |
355 // Prepending a "1" makes the DER invalid. | |
356 const string bad_der_signature1 = "1" + signature; | |
357 rv = verifier->VerifyProof(hostname, server_config, certs, | |
358 bad_der_signature1, callback.callback()); | |
359 if (rv == ERR_IO_PENDING) | |
360 rv = callback.WaitForResult(); | |
361 ASSERT_EQ(ERR_FAILED, rv); | |
362 ASSERT_NE("", verifier->error_details()); | |
363 | |
364 vector<string> wrong_certs; | |
365 for (size_t i = 1; i < certs.size(); i++) { | |
366 wrong_certs.push_back(certs[i]); | |
367 } | |
368 rv = verifier->VerifyProof("foo.com", server_config, wrong_certs, signature, | |
369 callback.callback()); | |
370 if (rv == ERR_IO_PENDING) | |
371 rv = callback.WaitForResult(); | |
372 ASSERT_EQ(ERR_FAILED, rv); | |
373 ASSERT_NE("", verifier->error_details()); | |
374 } | |
375 } | |
376 | |
57 } // namespace test | 377 } // namespace test |
58 } // namespace net | 378 } // namespace net |
OLD | NEW |