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

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

Issue 300223007: Break ChannelIDSigner into two classes: ChannelIDKey and ChannelIDSource. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixes build on C++03 Created 6 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
« no previous file with comments | « net/quic/crypto/channel_id.h ('k') | net/quic/crypto/quic_crypto_client_config.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 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/quic/crypto/channel_id.h" 5 #include "net/quic/crypto/channel_id.h"
6 6
7 #include "net/quic/test_tools/crypto_test_utils.h" 7 #include "net/quic/test_tools/crypto_test_utils.h"
8 #include "net/quic/test_tools/quic_test_utils.h" 8 #include "net/quic/test_tools/quic_test_utils.h"
9 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 10
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 EXPECT_EQ(32u, qy.size()); 213 EXPECT_EQ(32u, qy.size());
214 EXPECT_EQ(32u, r.size()); 214 EXPECT_EQ(32u, r.size());
215 EXPECT_EQ(32u, s.size()); 215 EXPECT_EQ(32u, s.size());
216 216
217 EXPECT_EQ(test_vector[i].result, 217 EXPECT_EQ(test_vector[i].result,
218 ChannelIDVerifier::VerifyRaw(key, msg, signature, false)); 218 ChannelIDVerifier::VerifyRaw(key, msg, signature, false));
219 } 219 }
220 } 220 }
221 221
222 TEST(ChannelIDTest, SignAndVerify) { 222 TEST(ChannelIDTest, SignAndVerify) {
223 scoped_ptr<ChannelIDSigner> signer( 223 scoped_ptr<ChannelIDSource> source(
224 CryptoTestUtils::ChannelIDSignerForTesting()); 224 CryptoTestUtils::ChannelIDSourceForTesting());
225 225
226 const string signed_data = "signed data"; 226 const string signed_data = "signed data";
227 const string hostname = "foo.example.com"; 227 const string hostname = "foo.example.com";
228 string key, signature; 228 scoped_ptr<ChannelIDKey> channel_id_key;
229 ASSERT_TRUE(signer->Sign(hostname, signed_data, &key, &signature)); 229 ASSERT_TRUE(source->GetChannelIDKey(hostname, &channel_id_key));
230 230
231 EXPECT_EQ(key, signer->GetKeyForHostname(hostname)); 231 string signature;
232 ASSERT_TRUE(channel_id_key->Sign(signed_data, &signature));
232 233
234 string key = channel_id_key->SerializeKey();
233 EXPECT_TRUE(ChannelIDVerifier::Verify(key, signed_data, signature)); 235 EXPECT_TRUE(ChannelIDVerifier::Verify(key, signed_data, signature));
234 236
235 EXPECT_FALSE(ChannelIDVerifier::Verify("a" + key, signed_data, signature)); 237 EXPECT_FALSE(ChannelIDVerifier::Verify("a" + key, signed_data, signature));
236 EXPECT_FALSE(ChannelIDVerifier::Verify(key, "a" + signed_data, signature)); 238 EXPECT_FALSE(ChannelIDVerifier::Verify(key, "a" + signed_data, signature));
237 239
238 scoped_ptr<char[]> bad_key(new char[key.size()]); 240 scoped_ptr<char[]> bad_key(new char[key.size()]);
239 memcpy(bad_key.get(), key.data(), key.size()); 241 memcpy(bad_key.get(), key.data(), key.size());
240 bad_key[1] ^= 0x80; 242 bad_key[1] ^= 0x80;
241 EXPECT_FALSE(ChannelIDVerifier::Verify( 243 EXPECT_FALSE(ChannelIDVerifier::Verify(
242 string(bad_key.get(), key.size()), signed_data, signature)); 244 string(bad_key.get(), key.size()), signed_data, signature));
243 245
244 scoped_ptr<char[]> bad_signature(new char[signature.size()]); 246 scoped_ptr<char[]> bad_signature(new char[signature.size()]);
245 memcpy(bad_signature.get(), signature.data(), signature.size()); 247 memcpy(bad_signature.get(), signature.data(), signature.size());
246 bad_signature[1] ^= 0x80; 248 bad_signature[1] ^= 0x80;
247 EXPECT_FALSE(ChannelIDVerifier::Verify( 249 EXPECT_FALSE(ChannelIDVerifier::Verify(
248 key, signed_data, string(bad_signature.get(), signature.size()))); 250 key, signed_data, string(bad_signature.get(), signature.size())));
249 251
250 EXPECT_FALSE(ChannelIDVerifier::Verify( 252 EXPECT_FALSE(ChannelIDVerifier::Verify(
251 key, "wrong signed data", signature)); 253 key, "wrong signed data", signature));
252 } 254 }
253 255
254 } // namespace test 256 } // namespace test
255 } // namespace net 257 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/crypto/channel_id.h ('k') | net/quic/crypto/quic_crypto_client_config.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698