| OLD | NEW |
| 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/core/crypto/channel_id.h" | 5 #include "net/quic/core/crypto/channel_id.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "net/quic/platform/api/quic_test.h" |
| 9 #include "net/quic/test_tools/crypto_test_utils.h" | 10 #include "net/quic/test_tools/crypto_test_utils.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | |
| 11 | 11 |
| 12 using std::string; | 12 using std::string; |
| 13 | 13 |
| 14 namespace net { | 14 namespace net { |
| 15 namespace test { | 15 namespace test { |
| 16 | 16 |
| 17 namespace { | 17 namespace { |
| 18 | 18 |
| 19 // The following ECDSA signature verification test vectors for P-256,SHA-256 | 19 // The following ECDSA signature verification test vectors for P-256,SHA-256 |
| 20 // come from the SigVer.rsp file in | 20 // come from the SigVer.rsp file in |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 236 } | 236 } |
| 237 out[*out_len] = HexDigitToInt(*in) * 16 + HexDigitToInt(*(in + 1)); | 237 out[*out_len] = HexDigitToInt(*in) * 16 + HexDigitToInt(*(in + 1)); |
| 238 (*out_len)++; | 238 (*out_len)++; |
| 239 in += 2; | 239 in += 2; |
| 240 } | 240 } |
| 241 return true; | 241 return true; |
| 242 } | 242 } |
| 243 | 243 |
| 244 } // namespace | 244 } // namespace |
| 245 | 245 |
| 246 class ChannelIDTest : public QuicTest {}; |
| 247 |
| 246 // A known answer test for ChannelIDVerifier. | 248 // A known answer test for ChannelIDVerifier. |
| 247 TEST(ChannelIDTest, VerifyKnownAnswerTest) { | 249 TEST_F(ChannelIDTest, VerifyKnownAnswerTest) { |
| 248 char msg[1024]; | 250 char msg[1024]; |
| 249 size_t msg_len; | 251 size_t msg_len; |
| 250 char key[64]; | 252 char key[64]; |
| 251 size_t qx_len; | 253 size_t qx_len; |
| 252 size_t qy_len; | 254 size_t qy_len; |
| 253 char signature[64]; | 255 char signature[64]; |
| 254 size_t r_len; | 256 size_t r_len; |
| 255 size_t s_len; | 257 size_t s_len; |
| 256 | 258 |
| 257 for (size_t i = 0; test_vector[i].msg != nullptr; i++) { | 259 for (size_t i = 0; test_vector[i].msg != nullptr; i++) { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 274 EXPECT_EQ(sizeof(signature) / 2, s_len); | 276 EXPECT_EQ(sizeof(signature) / 2, s_len); |
| 275 | 277 |
| 276 EXPECT_EQ( | 278 EXPECT_EQ( |
| 277 test_vector[i].result, | 279 test_vector[i].result, |
| 278 ChannelIDVerifier::VerifyRaw( | 280 ChannelIDVerifier::VerifyRaw( |
| 279 QuicStringPiece(key, sizeof(key)), QuicStringPiece(msg, msg_len), | 281 QuicStringPiece(key, sizeof(key)), QuicStringPiece(msg, msg_len), |
| 280 QuicStringPiece(signature, sizeof(signature)), false)); | 282 QuicStringPiece(signature, sizeof(signature)), false)); |
| 281 } | 283 } |
| 282 } | 284 } |
| 283 | 285 |
| 284 TEST(ChannelIDTest, SignAndVerify) { | 286 TEST_F(ChannelIDTest, SignAndVerify) { |
| 285 std::unique_ptr<ChannelIDSource> source( | 287 std::unique_ptr<ChannelIDSource> source( |
| 286 crypto_test_utils::ChannelIDSourceForTesting()); | 288 crypto_test_utils::ChannelIDSourceForTesting()); |
| 287 | 289 |
| 288 const string signed_data = "signed data"; | 290 const string signed_data = "signed data"; |
| 289 const string hostname = "foo.example.com"; | 291 const string hostname = "foo.example.com"; |
| 290 std::unique_ptr<ChannelIDKey> channel_id_key; | 292 std::unique_ptr<ChannelIDKey> channel_id_key; |
| 291 QuicAsyncStatus status = | 293 QuicAsyncStatus status = |
| 292 source->GetChannelIDKey(hostname, &channel_id_key, nullptr); | 294 source->GetChannelIDKey(hostname, &channel_id_key, nullptr); |
| 293 ASSERT_EQ(QUIC_SUCCESS, status); | 295 ASSERT_EQ(QUIC_SUCCESS, status); |
| 294 | 296 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 311 memcpy(bad_signature.get(), signature.data(), signature.size()); | 313 memcpy(bad_signature.get(), signature.data(), signature.size()); |
| 312 bad_signature[1] ^= 0x80; | 314 bad_signature[1] ^= 0x80; |
| 313 EXPECT_FALSE(ChannelIDVerifier::Verify( | 315 EXPECT_FALSE(ChannelIDVerifier::Verify( |
| 314 key, signed_data, string(bad_signature.get(), signature.size()))); | 316 key, signed_data, string(bad_signature.get(), signature.size()))); |
| 315 | 317 |
| 316 EXPECT_FALSE(ChannelIDVerifier::Verify(key, "wrong signed data", signature)); | 318 EXPECT_FALSE(ChannelIDVerifier::Verify(key, "wrong signed data", signature)); |
| 317 } | 319 } |
| 318 | 320 |
| 319 } // namespace test | 321 } // namespace test |
| 320 } // namespace net | 322 } // namespace net |
| OLD | NEW |