| // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| |
| #include "quic/core/crypto/crypto_utils.h" |
| |
| #include <string> |
| |
| #include "absl/base/macros.h" |
| #include "absl/strings/escaping.h" |
| #include "quic/core/quic_utils.h" |
| #include "quic/platform/api/quic_test.h" |
| #include "quic/test_tools/quic_test_utils.h" |
| #include "common/test_tools/quiche_test_utils.h" |
| |
| namespace quic { |
| namespace test { |
| namespace { |
| |
| class CryptoUtilsTest : public QuicTest {}; |
| |
| TEST_F(CryptoUtilsTest, HandshakeFailureReasonToString) { |
| EXPECT_STREQ("HANDSHAKE_OK", |
| CryptoUtils::HandshakeFailureReasonToString(HANDSHAKE_OK)); |
| EXPECT_STREQ("CLIENT_NONCE_UNKNOWN_FAILURE", |
| CryptoUtils::HandshakeFailureReasonToString( |
| CLIENT_NONCE_UNKNOWN_FAILURE)); |
| EXPECT_STREQ("CLIENT_NONCE_INVALID_FAILURE", |
| CryptoUtils::HandshakeFailureReasonToString( |
| CLIENT_NONCE_INVALID_FAILURE)); |
| EXPECT_STREQ("CLIENT_NONCE_NOT_UNIQUE_FAILURE", |
| CryptoUtils::HandshakeFailureReasonToString( |
| CLIENT_NONCE_NOT_UNIQUE_FAILURE)); |
| EXPECT_STREQ("CLIENT_NONCE_INVALID_ORBIT_FAILURE", |
| CryptoUtils::HandshakeFailureReasonToString( |
| CLIENT_NONCE_INVALID_ORBIT_FAILURE)); |
| EXPECT_STREQ("CLIENT_NONCE_INVALID_TIME_FAILURE", |
| CryptoUtils::HandshakeFailureReasonToString( |
| CLIENT_NONCE_INVALID_TIME_FAILURE)); |
| EXPECT_STREQ("CLIENT_NONCE_STRIKE_REGISTER_TIMEOUT", |
| CryptoUtils::HandshakeFailureReasonToString( |
| CLIENT_NONCE_STRIKE_REGISTER_TIMEOUT)); |
| EXPECT_STREQ("CLIENT_NONCE_STRIKE_REGISTER_FAILURE", |
| CryptoUtils::HandshakeFailureReasonToString( |
| CLIENT_NONCE_STRIKE_REGISTER_FAILURE)); |
| EXPECT_STREQ("SERVER_NONCE_DECRYPTION_FAILURE", |
| CryptoUtils::HandshakeFailureReasonToString( |
| SERVER_NONCE_DECRYPTION_FAILURE)); |
| EXPECT_STREQ("SERVER_NONCE_INVALID_FAILURE", |
| CryptoUtils::HandshakeFailureReasonToString( |
| SERVER_NONCE_INVALID_FAILURE)); |
| EXPECT_STREQ("SERVER_NONCE_NOT_UNIQUE_FAILURE", |
| CryptoUtils::HandshakeFailureReasonToString( |
| SERVER_NONCE_NOT_UNIQUE_FAILURE)); |
| EXPECT_STREQ("SERVER_NONCE_INVALID_TIME_FAILURE", |
| CryptoUtils::HandshakeFailureReasonToString( |
| SERVER_NONCE_INVALID_TIME_FAILURE)); |
| EXPECT_STREQ("SERVER_NONCE_REQUIRED_FAILURE", |
| CryptoUtils::HandshakeFailureReasonToString( |
| SERVER_NONCE_REQUIRED_FAILURE)); |
| EXPECT_STREQ("SERVER_CONFIG_INCHOATE_HELLO_FAILURE", |
| CryptoUtils::HandshakeFailureReasonToString( |
| SERVER_CONFIG_INCHOATE_HELLO_FAILURE)); |
| EXPECT_STREQ("SERVER_CONFIG_UNKNOWN_CONFIG_FAILURE", |
| CryptoUtils::HandshakeFailureReasonToString( |
| SERVER_CONFIG_UNKNOWN_CONFIG_FAILURE)); |
| EXPECT_STREQ("SOURCE_ADDRESS_TOKEN_INVALID_FAILURE", |
| CryptoUtils::HandshakeFailureReasonToString( |
| SOURCE_ADDRESS_TOKEN_INVALID_FAILURE)); |
| EXPECT_STREQ("SOURCE_ADDRESS_TOKEN_DECRYPTION_FAILURE", |
| CryptoUtils::HandshakeFailureReasonToString( |
| SOURCE_ADDRESS_TOKEN_DECRYPTION_FAILURE)); |
| EXPECT_STREQ("SOURCE_ADDRESS_TOKEN_PARSE_FAILURE", |
| CryptoUtils::HandshakeFailureReasonToString( |
| SOURCE_ADDRESS_TOKEN_PARSE_FAILURE)); |
| EXPECT_STREQ("SOURCE_ADDRESS_TOKEN_DIFFERENT_IP_ADDRESS_FAILURE", |
| CryptoUtils::HandshakeFailureReasonToString( |
| SOURCE_ADDRESS_TOKEN_DIFFERENT_IP_ADDRESS_FAILURE)); |
| EXPECT_STREQ("SOURCE_ADDRESS_TOKEN_CLOCK_SKEW_FAILURE", |
| CryptoUtils::HandshakeFailureReasonToString( |
| SOURCE_ADDRESS_TOKEN_CLOCK_SKEW_FAILURE)); |
| EXPECT_STREQ("SOURCE_ADDRESS_TOKEN_EXPIRED_FAILURE", |
| CryptoUtils::HandshakeFailureReasonToString( |
| SOURCE_ADDRESS_TOKEN_EXPIRED_FAILURE)); |
| EXPECT_STREQ("INVALID_EXPECTED_LEAF_CERTIFICATE", |
| CryptoUtils::HandshakeFailureReasonToString( |
| INVALID_EXPECTED_LEAF_CERTIFICATE)); |
| EXPECT_STREQ("MAX_FAILURE_REASON", |
| CryptoUtils::HandshakeFailureReasonToString(MAX_FAILURE_REASON)); |
| EXPECT_STREQ( |
| "INVALID_HANDSHAKE_FAILURE_REASON", |
| CryptoUtils::HandshakeFailureReasonToString( |
| static_cast<HandshakeFailureReason>(MAX_FAILURE_REASON + 1))); |
| } |
| |
| TEST_F(CryptoUtilsTest, AuthTagLengths) { |
| for (const auto& version : AllSupportedVersions()) { |
| for (QuicTag algo : {kAESG, kCC20}) { |
| SCOPED_TRACE(version); |
| std::unique_ptr<QuicEncrypter> encrypter( |
| QuicEncrypter::Create(version, algo)); |
| size_t auth_tag_size = 12; |
| if (version.UsesInitialObfuscators()) { |
| auth_tag_size = 16; |
| } |
| EXPECT_EQ(encrypter->GetCiphertextSize(0), auth_tag_size); |
| } |
| } |
| } |
| |
| } // namespace |
| } // namespace test |
| } // namespace quic |