Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(761)

Side by Side Diff: net/quic/crypto/proof_test.cc

Issue 17385010: OpenSSL/NSS implementation of ProofVerfifier. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix compiler error Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 "net/base/net_errors.h"
6 #include "net/base/test_completion_callback.h"
5 #include "net/quic/crypto/proof_source.h" 7 #include "net/quic/crypto/proof_source.h"
6 #include "net/quic/crypto/proof_verifier.h" 8 #include "net/quic/crypto/proof_verifier.h"
7 #include "net/quic/test_tools/crypto_test_utils.h" 9 #include "net/quic/test_tools/crypto_test_utils.h"
8 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
9 11
10 using std::string; 12 using std::string;
11 using std::vector; 13 using std::vector;
12 14
13 namespace net { 15 namespace net {
14 namespace test { 16 namespace test {
(...skipping 12 matching lines...) Expand all
27 string error_details, signature, first_signature; 29 string error_details, signature, first_signature;
28 30
29 ASSERT_TRUE(source->GetProof(hostname, server_config, &first_certs, 31 ASSERT_TRUE(source->GetProof(hostname, server_config, &first_certs,
30 &first_signature)); 32 &first_signature));
31 ASSERT_TRUE(source->GetProof(hostname, server_config, &certs, &signature)); 33 ASSERT_TRUE(source->GetProof(hostname, server_config, &certs, &signature));
32 34
33 // Check that the proof source is caching correctly: 35 // Check that the proof source is caching correctly:
34 ASSERT_EQ(first_certs, certs); 36 ASSERT_EQ(first_certs, certs);
35 ASSERT_EQ(signature, first_signature); 37 ASSERT_EQ(signature, first_signature);
36 38
37 ASSERT_TRUE(verifier->VerifyProof(hostname, server_config, *certs, signature, 39 int rv;
38 &error_details)); 40 TestCompletionCallback callback;
39 ASSERT_FALSE(verifier->VerifyProof("foo.com", server_config, *certs, 41 rv = verifier->VerifyProof(hostname, server_config, *certs, signature,
40 signature, &error_details)); 42 callback.callback(), &error_details);
41 ASSERT_FALSE( 43 if (rv == ERR_IO_PENDING)
42 verifier->VerifyProof(hostname, server_config.substr(1, string::npos), 44 rv = callback.WaitForResult();
43 *certs, signature, &error_details)); 45 ASSERT_EQ(OK, rv);
46
47 rv = verifier->VerifyProof("foo.com", server_config, *certs,
48 signature, callback.callback(), &error_details);
49 if (rv == ERR_IO_PENDING)
50 rv = callback.WaitForResult();
51 ASSERT_EQ(ERR_FAILED, rv);
52
53 rv = verifier->VerifyProof(hostname, server_config.substr(1, string::npos),
54 *certs, signature, callback.callback(),
55 &error_details);
56 if (rv == ERR_IO_PENDING)
57 rv = callback.WaitForResult();
58 ASSERT_EQ(ERR_FAILED, rv);
59
44 const string corrupt_signature = "1" + signature; 60 const string corrupt_signature = "1" + signature;
45 ASSERT_FALSE(verifier->VerifyProof(hostname, server_config, *certs, 61 rv = verifier->VerifyProof(hostname, server_config, *certs,
46 corrupt_signature, &error_details)); 62 corrupt_signature, callback.callback(),
63 &error_details);
64 if (rv == ERR_IO_PENDING)
65 rv = callback.WaitForResult();
66 ASSERT_EQ(ERR_FAILED, rv);
47 67
48 vector<string> wrong_certs; 68 vector<string> wrong_certs;
49 for (size_t i = 1; i < certs->size(); i++) { 69 for (size_t i = 1; i < certs->size(); i++) {
50 wrong_certs.push_back((*certs)[i]); 70 wrong_certs.push_back((*certs)[i]);
51 } 71 }
52 ASSERT_FALSE(verifier->VerifyProof("foo.com", server_config, wrong_certs, 72 rv = verifier->VerifyProof("foo.com", server_config, wrong_certs,
53 signature, &error_details)); 73 signature, callback.callback(), &error_details);
74 if (rv == ERR_IO_PENDING)
75 rv = callback.WaitForResult();
76 ASSERT_EQ(ERR_FAILED, rv);
54 #endif // 0 77 #endif // 0
55 } 78 }
56 79
80 static const unsigned char cert_data_0[] = {
81 0x30, 0x82, 0x01, 0xdc, 0x30, 0x82, 0x01, 0x47, 0xa0, 0x03,
82 0x02, 0x01, 0x02, 0x02, 0x01, 0x04, 0x30, 0x0b, 0x06, 0x09,
83 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x05, 0x30,
84 0x2c, 0x31, 0x10, 0x30, 0x0e, 0x06, 0x03, 0x55, 0x04, 0x0a,
85 0x13, 0x07, 0x41, 0x63, 0x6d, 0x65, 0x20, 0x43, 0x6f, 0x31,
86 0x18, 0x30, 0x16, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x0f,
87 0x49, 0x6e, 0x74, 0x65, 0x72, 0x6d, 0x65, 0x64, 0x69, 0x61,
88 0x74, 0x65, 0x20, 0x43, 0x41, 0x30, 0x1e, 0x17, 0x0d, 0x31,
89 0x33, 0x30, 0x31, 0x30, 0x31, 0x31, 0x30, 0x30, 0x30, 0x30,
90 0x30, 0x5a, 0x17, 0x0d, 0x32, 0x33, 0x31, 0x32, 0x33, 0x31,
91 0x31, 0x30, 0x30, 0x30, 0x30, 0x30, 0x5a, 0x30, 0x33, 0x31,
92 0x10, 0x30, 0x0e, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x13, 0x07,
93 0x41, 0x63, 0x6d, 0x65, 0x20, 0x43, 0x6f, 0x31, 0x1f, 0x30,
94 0x1d, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x16, 0x45, 0x43,
95 0x44, 0x53, 0x41, 0x20, 0x4c, 0x65, 0x61, 0x66, 0x20, 0x63,
96 0x65, 0x72, 0x74, 0x69, 0x66, 0x69, 0x63, 0x61, 0x74, 0x65,
97 0x30, 0x59, 0x30, 0x13, 0x06, 0x07, 0x2a, 0x86, 0x48, 0xce,
98 0x3d, 0x02, 0x01, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d,
99 0x03, 0x01, 0x07, 0x03, 0x42, 0x00, 0x04, 0x6d, 0x48, 0xd0,
100 0x30, 0x76, 0xbb, 0xbf, 0x91, 0xb1, 0xd7, 0x03, 0xc2, 0xfc,
101 0x95, 0x9b, 0xe0, 0xea, 0x42, 0xed, 0x43, 0x2c, 0xa6, 0xb2,
102 0x23, 0xc4, 0x52, 0x33, 0x93, 0x95, 0x25, 0xfc, 0x16, 0x75,
103 0x83, 0x9e, 0x0f, 0x0f, 0x91, 0xa5, 0x47, 0xb1, 0x21, 0x91,
104 0xd4, 0x94, 0x94, 0x30, 0xb8, 0x00, 0xdc, 0x1c, 0x79, 0x2c,
105 0xfa, 0x72, 0x99, 0x62, 0xb2, 0xfa, 0xaf, 0xb0, 0xca, 0xf2,
106 0x42, 0xa3, 0x52, 0x30, 0x50, 0x30, 0x0e, 0x06, 0x03, 0x55,
107 0x1d, 0x0f, 0x01, 0x01, 0xff, 0x04, 0x04, 0x03, 0x02, 0x00,
108 0x80, 0x30, 0x13, 0x06, 0x03, 0x55, 0x1d, 0x25, 0x04, 0x0c,
109 0x30, 0x0a, 0x06, 0x08, 0x2b, 0x06, 0x01, 0x05, 0x05, 0x07,
110 0x03, 0x01, 0x30, 0x0c, 0x06, 0x03, 0x55, 0x1d, 0x13, 0x01,
111 0x01, 0xff, 0x04, 0x02, 0x30, 0x00, 0x30, 0x1b, 0x06, 0x03,
112 0x55, 0x1d, 0x11, 0x04, 0x14, 0x30, 0x12, 0x82, 0x10, 0x74,
113 0x65, 0x73, 0x74, 0x2e, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c,
114 0x65, 0x2e, 0x63, 0x6f, 0x6d, 0x30, 0x0b, 0x06, 0x09, 0x2a,
115 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x05, 0x03, 0x81,
116 0x81, 0x00, 0x5d, 0x23, 0x47, 0xb4, 0xb5, 0x0f, 0x38, 0x18,
117 0xcd, 0x63, 0x90, 0x24, 0x37, 0xf1, 0xda, 0x67, 0x66, 0xa4,
118 0xfe, 0x8d, 0x53, 0x3f, 0xc5, 0xa7, 0x10, 0xe6, 0x21, 0xa3,
119 0x1d, 0xb7, 0x42, 0xb0, 0x1a, 0xe7, 0xd7, 0x83, 0x3d, 0xea,
120 0x7b, 0x6b, 0x89, 0x85, 0xbb, 0x13, 0x77, 0x4d, 0x45, 0xab,
121 0xb2, 0xe7, 0x1e, 0xac, 0x6e, 0x74, 0xb6, 0x9f, 0xc4, 0xe0,
122 0x76, 0x1c, 0xe4, 0x13, 0xe9, 0x6c, 0xb1, 0x20, 0xa3, 0x34,
123 0xe8, 0x1e, 0x8a, 0x71, 0x51, 0xcb, 0x00, 0x44, 0x71, 0x64,
124 0xf6, 0x4b, 0x9e, 0x9a, 0x2d, 0xd9, 0x9a, 0x44, 0x62, 0xf5,
125 0x8c, 0x3c, 0xc5, 0xec, 0xc1, 0x1c, 0xd5, 0xbb, 0x05, 0x53,
126 0x33, 0xaf, 0x70, 0x44, 0x1d, 0x5b, 0xaa, 0x23, 0x67, 0x30,
127 0x3e, 0xd3, 0xa9, 0x5e, 0xa2, 0x57, 0x84, 0x86, 0xaa, 0xbe,
128 0xbd, 0x7b, 0x4f, 0x74, 0xd9, 0x3b, 0xcd, 0x2e, 0x7e, 0xd1,
129 };
130
131 static const unsigned char cert_data_1[] = {
132 0x30, 0x82, 0x01, 0xf8, 0x30, 0x82, 0x01, 0x63, 0xa0, 0x03,
133 0x02, 0x01, 0x02, 0x02, 0x01, 0x02, 0x30, 0x0b, 0x06, 0x09,
134 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x05, 0x30,
135 0x24, 0x31, 0x10, 0x30, 0x0e, 0x06, 0x03, 0x55, 0x04, 0x0a,
136 0x13, 0x07, 0x41, 0x63, 0x6d, 0x65, 0x20, 0x43, 0x6f, 0x31,
137 0x10, 0x30, 0x0e, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x07,
138 0x52, 0x6f, 0x6f, 0x74, 0x20, 0x43, 0x41, 0x30, 0x1e, 0x17,
139 0x0d, 0x31, 0x33, 0x30, 0x31, 0x30, 0x31, 0x31, 0x30, 0x30,
140 0x30, 0x30, 0x30, 0x5a, 0x17, 0x0d, 0x32, 0x33, 0x31, 0x32,
141 0x33, 0x31, 0x31, 0x30, 0x30, 0x30, 0x30, 0x30, 0x5a, 0x30,
142 0x2c, 0x31, 0x10, 0x30, 0x0e, 0x06, 0x03, 0x55, 0x04, 0x0a,
143 0x13, 0x07, 0x41, 0x63, 0x6d, 0x65, 0x20, 0x43, 0x6f, 0x31,
144 0x18, 0x30, 0x16, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x0f,
145 0x49, 0x6e, 0x74, 0x65, 0x72, 0x6d, 0x65, 0x64, 0x69, 0x61,
146 0x74, 0x65, 0x20, 0x43, 0x41, 0x30, 0x81, 0x9d, 0x30, 0x0b,
147 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01,
148 0x01, 0x03, 0x81, 0x8d, 0x00, 0x30, 0x81, 0x89, 0x02, 0x81,
149 0x81, 0x00, 0xaf, 0x95, 0xdd, 0xa0, 0xeb, 0xd7, 0xc3, 0xba,
150 0xa6, 0xae, 0xdb, 0x6e, 0x05, 0x68, 0xa0, 0x00, 0x15, 0xa1,
151 0x85, 0xd1, 0x89, 0xba, 0xbe, 0x3a, 0x7a, 0x3b, 0x8c, 0x3b,
152 0x41, 0x07, 0x76, 0x63, 0x71, 0x28, 0xf7, 0xbf, 0xa5, 0xfb,
153 0xb3, 0x28, 0x94, 0xf9, 0x9a, 0xde, 0x1d, 0x03, 0x00, 0xce,
154 0x5e, 0x25, 0x06, 0x6a, 0xe6, 0xc7, 0x0a, 0x6b, 0x6d, 0xd3,
155 0x76, 0x95, 0x57, 0xf5, 0x16, 0xf8, 0xf0, 0x43, 0xde, 0xb7,
156 0xc7, 0x1b, 0x0b, 0x83, 0xf4, 0x70, 0xe6, 0x29, 0xa1, 0x8d,
157 0x22, 0x12, 0x9a, 0xdf, 0x4b, 0x31, 0xe8, 0x9b, 0x86, 0x7d,
158 0x95, 0x29, 0x97, 0x18, 0xc1, 0x34, 0x2f, 0xb6, 0xa7, 0xc1,
159 0xc7, 0x46, 0xd6, 0x9c, 0xc6, 0xa6, 0xae, 0x6e, 0xdd, 0x8f,
160 0xbe, 0xc2, 0xec, 0x02, 0x00, 0xd2, 0x54, 0xf6, 0x0f, 0xa0,
161 0xcc, 0xaf, 0x04, 0x85, 0x65, 0x98, 0xa1, 0xea, 0x73, 0xf1,
162 0x02, 0x03, 0x01, 0x00, 0x01, 0xa3, 0x38, 0x30, 0x36, 0x30,
163 0x0e, 0x06, 0x03, 0x55, 0x1d, 0x0f, 0x01, 0x01, 0xff, 0x04,
164 0x04, 0x03, 0x02, 0x00, 0x04, 0x30, 0x13, 0x06, 0x03, 0x55,
165 0x1d, 0x25, 0x04, 0x0c, 0x30, 0x0a, 0x06, 0x08, 0x2b, 0x06,
166 0x01, 0x05, 0x05, 0x07, 0x03, 0x01, 0x30, 0x0f, 0x06, 0x03,
167 0x55, 0x1d, 0x13, 0x01, 0x01, 0xff, 0x04, 0x05, 0x30, 0x03,
168 0x01, 0x01, 0xff, 0x30, 0x0b, 0x06, 0x09, 0x2a, 0x86, 0x48,
169 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x05, 0x03, 0x81, 0x81, 0x00,
170 0x9a, 0x68, 0x79, 0x17, 0x6c, 0x13, 0x20, 0xb3, 0x5f, 0x01,
171 0xca, 0xae, 0xc0, 0xbf, 0xd2, 0x7b, 0x98, 0xbf, 0xdd, 0x4d,
172 0xd1, 0xc3, 0xa5, 0xab, 0x01, 0x47, 0x2e, 0xc8, 0x61, 0xb4,
173 0xf5, 0x1d, 0x55, 0x04, 0xf0, 0xeb, 0x5d, 0x84, 0x5a, 0x78,
174 0x09, 0xb0, 0xf1, 0x42, 0x64, 0x14, 0xe8, 0x9e, 0xba, 0xc3,
175 0x38, 0x32, 0xd3, 0x16, 0xfe, 0xe1, 0x65, 0x1f, 0x76, 0xda,
176 0xe4, 0xc0, 0x83, 0x62, 0x4a, 0xae, 0xd0, 0x4e, 0x00, 0x2e,
177 0x38, 0x52, 0x91, 0x81, 0x62, 0x94, 0xb0, 0x3d, 0x69, 0xb3,
178 0x87, 0x72, 0x39, 0x55, 0x94, 0x9e, 0xca, 0x2c, 0xca, 0x51,
179 0x3c, 0xd3, 0x3f, 0xd2, 0x1c, 0x92, 0xd3, 0xde, 0xdf, 0xba,
180 0xbc, 0x45, 0x9b, 0x30, 0x99, 0xb4, 0x39, 0xf8, 0x17, 0x55,
181 0x94, 0x7d, 0x3a, 0xba, 0x0e, 0xe9, 0x3f, 0x2d, 0xbc, 0xf0,
182 0xea, 0x6d, 0x17, 0x85, 0x23, 0xe4, 0xca, 0x94,
183 };
184
185 static const unsigned char signature_data_0[] = {
186 0x30, 0x45, 0x02, 0x20, 0x15, 0xb7, 0x9f, 0xe3, 0xd9, 0x7a,
187 0x3c, 0x3b, 0x18, 0xb0, 0xdb, 0x60, 0x23, 0x56, 0xa0, 0x06,
188 0x4e, 0x70, 0xa3, 0xf7, 0x4b, 0xe5, 0x0d, 0x69, 0xf0, 0x35,
189 0x8c, 0xae, 0xb5, 0x54, 0x32, 0xe9, 0x02, 0x21, 0x00, 0xf7,
190 0xe3, 0x06, 0x99, 0x16, 0x56, 0x7e, 0xab, 0x33, 0x53, 0x0d,
191 0xde, 0xbe, 0xef, 0x6d, 0xb0, 0xc7, 0xa6, 0x63, 0xaf, 0x8d,
192 0xab, 0x34, 0xa9, 0xc0, 0x63, 0x88, 0x47, 0x17, 0x4c, 0x4c,
193 0x04,
194 };
195
196 static const unsigned char signature_data_1[] = {
197 0x30, 0x44, 0x02, 0x20, 0x69, 0x60, 0x55, 0xbb, 0x11, 0x93,
198 0x6a, 0xdc, 0x9b, 0x61, 0x2c, 0x60, 0x19, 0xbc, 0x15, 0x55,
199 0xcf, 0xf2, 0x8e, 0x2e, 0x27, 0x0b, 0x69, 0xef, 0x33, 0x25,
200 0x1e, 0x5d, 0x8c, 0x00, 0x11, 0xef, 0x02, 0x20, 0x0c, 0x26,
201 0xfe, 0x0b, 0x06, 0x8f, 0xe8, 0xe2, 0x02, 0x63, 0xe5, 0x43,
202 0x0d, 0xc9, 0x80, 0x4d, 0xe9, 0x6f, 0x6e, 0x18, 0xdb, 0xb0,
203 0x04, 0x2a, 0x45, 0x37, 0x1a, 0x60, 0x0e, 0xc6, 0xc4, 0x8f,
204 };
205
206 static const unsigned char signature_data_2[] = {
207 0x30, 0x45, 0x02, 0x21, 0x00, 0xd5, 0x43, 0x36, 0x60, 0x50,
208 0xce, 0xe0, 0x00, 0x51, 0x02, 0x84, 0x95, 0x51, 0x47, 0xaf,
209 0xe4, 0xf9, 0xe1, 0x23, 0xae, 0x21, 0xb4, 0x98, 0xd1, 0xa3,
210 0x5f, 0x3b, 0xf3, 0x6a, 0x65, 0x44, 0x6b, 0x02, 0x20, 0x30,
211 0x7e, 0xb4, 0xea, 0xf0, 0xda, 0xdb, 0xbd, 0x38, 0xb9, 0x7a,
212 0x5d, 0x12, 0x04, 0x0e, 0xc2, 0xf0, 0xb1, 0x0e, 0x25, 0xf8,
213 0x0a, 0x27, 0xa3, 0x16, 0x94, 0xac, 0x1e, 0xb8, 0x6e, 0x00,
214 0x05,
215 };
216
217 TEST(Proof, VerifyECDSAKnownAnswerTest) {
218 TestCompletionCallback callback;
219 scoped_ptr<ProofVerifier> verifier(
220 CryptoTestUtils::ProofVerifierForTesting());
221
222 const string server_config = "server config bytes";
223 const string hostname = "test.example.com";
224
225 vector<string> certs(2);
226 certs[0].assign(reinterpret_cast<const char*>(cert_data_0),
227 sizeof(cert_data_0));
228 certs[1].assign(reinterpret_cast<const char*>(cert_data_1),
229 sizeof(cert_data_1));
230
231 // Signatures are nondeterministic, so we test multiple signatures
232 // on the same server_config.
233 vector<string> signatures(3);
234 signatures[0].assign(reinterpret_cast<const char*>(signature_data_0),
235 sizeof(signature_data_0));
236 signatures[1].assign(reinterpret_cast<const char*>(signature_data_1),
237 sizeof(signature_data_1));
238 signatures[2].assign(reinterpret_cast<const char*>(signature_data_2),
239 sizeof(signature_data_2));
240
241 int rv;
242 for (size_t i = 0; i < signatures.size(); i++) {
243 const string& signature = signatures[i];
244 string error_details;
245 rv = verifier->VerifyProof(hostname, server_config, certs, signature,
246 callback.callback(), &error_details);
247 if (rv == ERR_IO_PENDING)
248 rv = callback.WaitForResult();
249 EXPECT_EQ(OK, rv);
250
251 rv = verifier->VerifyProof("foo.com", server_config, certs, signature,
252 callback.callback(), &error_details);
253 if (rv == ERR_IO_PENDING)
254 rv = callback.WaitForResult();
255 EXPECT_EQ(ERR_FAILED, rv);
256
257 rv = verifier->VerifyProof(hostname, server_config.substr(1, string::npos),
258 certs, signature, callback.callback(),
259 &error_details);
260 if (rv == ERR_IO_PENDING)
261 rv = callback.WaitForResult();
262 EXPECT_EQ(ERR_FAILED, rv);
263
264 const string corrupt_signature = "1" + signature;
265 rv = verifier->VerifyProof(hostname, server_config, certs,
266 corrupt_signature, callback.callback(),
267 &error_details);
268 if (rv == ERR_IO_PENDING)
269 rv = callback.WaitForResult();
270 EXPECT_EQ(ERR_FAILED, rv);
271
272 vector<string> wrong_certs;
273 for (size_t i = 1; i < certs.size(); i++) {
274 wrong_certs.push_back(certs[i]);
275 }
276 rv = verifier->VerifyProof("foo.com", server_config, wrong_certs, signature,
277 callback.callback(), &error_details);
278 if (rv == ERR_IO_PENDING)
279 rv = callback.WaitForResult();
280 EXPECT_EQ(ERR_FAILED, rv);
281 }
282 }
wtc 2013/06/24 22:36:56 Please use the following code for this new unit te
ramant (doing other things) 2013/06/28 19:16:56 I have used the latest code from you for the above
283
57 } // namespace test 284 } // namespace test
58 } // namespace net 285 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698