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

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

Issue 320663002: Change the prototype of ChannelIDSource::GetChannelIDKey() to allow an (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Remove unrelated changes 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 | Annotate | Revision Log
« no previous file with comments | « net/quic/crypto/channel_id.h ('k') | net/quic/crypto/proof_verifier.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 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 } 219 }
220 } 220 }
221 221
222 TEST(ChannelIDTest, SignAndVerify) { 222 TEST(ChannelIDTest, SignAndVerify) {
223 scoped_ptr<ChannelIDSource> source( 223 scoped_ptr<ChannelIDSource> source(
224 CryptoTestUtils::ChannelIDSourceForTesting()); 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 scoped_ptr<ChannelIDKey> channel_id_key; 228 scoped_ptr<ChannelIDKey> channel_id_key;
229 ASSERT_TRUE(source->GetChannelIDKey(hostname, &channel_id_key)); 229 QuicAsyncStatus status =
230 source->GetChannelIDKey(hostname, &channel_id_key, NULL);
231 ASSERT_EQ(QUIC_SUCCESS, status);
230 232
231 string signature; 233 string signature;
232 ASSERT_TRUE(channel_id_key->Sign(signed_data, &signature)); 234 ASSERT_TRUE(channel_id_key->Sign(signed_data, &signature));
233 235
234 string key = channel_id_key->SerializeKey(); 236 string key = channel_id_key->SerializeKey();
235 EXPECT_TRUE(ChannelIDVerifier::Verify(key, signed_data, signature)); 237 EXPECT_TRUE(ChannelIDVerifier::Verify(key, signed_data, signature));
236 238
237 EXPECT_FALSE(ChannelIDVerifier::Verify("a" + key, signed_data, signature)); 239 EXPECT_FALSE(ChannelIDVerifier::Verify("a" + key, signed_data, signature));
238 EXPECT_FALSE(ChannelIDVerifier::Verify(key, "a" + signed_data, signature)); 240 EXPECT_FALSE(ChannelIDVerifier::Verify(key, "a" + signed_data, signature));
239 241
240 scoped_ptr<char[]> bad_key(new char[key.size()]); 242 scoped_ptr<char[]> bad_key(new char[key.size()]);
241 memcpy(bad_key.get(), key.data(), key.size()); 243 memcpy(bad_key.get(), key.data(), key.size());
242 bad_key[1] ^= 0x80; 244 bad_key[1] ^= 0x80;
243 EXPECT_FALSE(ChannelIDVerifier::Verify( 245 EXPECT_FALSE(ChannelIDVerifier::Verify(
244 string(bad_key.get(), key.size()), signed_data, signature)); 246 string(bad_key.get(), key.size()), signed_data, signature));
245 247
246 scoped_ptr<char[]> bad_signature(new char[signature.size()]); 248 scoped_ptr<char[]> bad_signature(new char[signature.size()]);
247 memcpy(bad_signature.get(), signature.data(), signature.size()); 249 memcpy(bad_signature.get(), signature.data(), signature.size());
248 bad_signature[1] ^= 0x80; 250 bad_signature[1] ^= 0x80;
249 EXPECT_FALSE(ChannelIDVerifier::Verify( 251 EXPECT_FALSE(ChannelIDVerifier::Verify(
250 key, signed_data, string(bad_signature.get(), signature.size()))); 252 key, signed_data, string(bad_signature.get(), signature.size())));
251 253
252 EXPECT_FALSE(ChannelIDVerifier::Verify( 254 EXPECT_FALSE(ChannelIDVerifier::Verify(
253 key, "wrong signed data", signature)); 255 key, "wrong signed data", signature));
254 } 256 }
255 257
256 } // namespace test 258 } // namespace test
257 } // namespace net 259 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/crypto/channel_id.h ('k') | net/quic/crypto/proof_verifier.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698