| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/ssl/ssl_cipher_suite_names.h" | 5 #include "net/ssl/ssl_cipher_suite_names.h" |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/macros.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 | 9 |
| 10 namespace net { | 10 namespace net { |
| 11 | 11 |
| 12 namespace { | 12 namespace { |
| 13 | 13 |
| 14 TEST(CipherSuiteNamesTest, Basic) { | 14 TEST(CipherSuiteNamesTest, Basic) { |
| 15 const char *key_exchange, *cipher, *mac; | 15 const char *key_exchange, *cipher, *mac; |
| 16 bool is_aead; | 16 bool is_aead; |
| 17 | 17 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 41 EXPECT_EQ(NULL, mac); | 41 EXPECT_EQ(NULL, mac); |
| 42 | 42 |
| 43 SSLCipherSuiteToStrings(&key_exchange, &cipher, &mac, &is_aead, 0xff31); | 43 SSLCipherSuiteToStrings(&key_exchange, &cipher, &mac, &is_aead, 0xff31); |
| 44 EXPECT_STREQ("???", key_exchange); | 44 EXPECT_STREQ("???", key_exchange); |
| 45 EXPECT_STREQ("???", cipher); | 45 EXPECT_STREQ("???", cipher); |
| 46 EXPECT_STREQ("???", mac); | 46 EXPECT_STREQ("???", mac); |
| 47 EXPECT_FALSE(is_aead); | 47 EXPECT_FALSE(is_aead); |
| 48 } | 48 } |
| 49 | 49 |
| 50 TEST(CipherSuiteNamesTest, ParseSSLCipherString) { | 50 TEST(CipherSuiteNamesTest, ParseSSLCipherString) { |
| 51 uint16 cipher_suite = 0; | 51 uint16_t cipher_suite = 0; |
| 52 EXPECT_TRUE(ParseSSLCipherString("0x0004", &cipher_suite)); | 52 EXPECT_TRUE(ParseSSLCipherString("0x0004", &cipher_suite)); |
| 53 EXPECT_EQ(0x00004u, cipher_suite); | 53 EXPECT_EQ(0x00004u, cipher_suite); |
| 54 | 54 |
| 55 EXPECT_TRUE(ParseSSLCipherString("0xBEEF", &cipher_suite)); | 55 EXPECT_TRUE(ParseSSLCipherString("0xBEEF", &cipher_suite)); |
| 56 EXPECT_EQ(0xBEEFu, cipher_suite); | 56 EXPECT_EQ(0xBEEFu, cipher_suite); |
| 57 } | 57 } |
| 58 | 58 |
| 59 TEST(CipherSuiteNamesTest, ParseSSLCipherStringFails) { | 59 TEST(CipherSuiteNamesTest, ParseSSLCipherStringFails) { |
| 60 const char* const cipher_strings[] = { | 60 const char* const cipher_strings[] = { |
| 61 "0004", | 61 "0004", |
| 62 "0x004", | 62 "0x004", |
| 63 "0xBEEFY", | 63 "0xBEEFY", |
| 64 }; | 64 }; |
| 65 | 65 |
| 66 for (size_t i = 0; i < arraysize(cipher_strings); ++i) { | 66 for (size_t i = 0; i < arraysize(cipher_strings); ++i) { |
| 67 uint16 cipher_suite = 0; | 67 uint16_t cipher_suite = 0; |
| 68 EXPECT_FALSE(ParseSSLCipherString(cipher_strings[i], &cipher_suite)); | 68 EXPECT_FALSE(ParseSSLCipherString(cipher_strings[i], &cipher_suite)); |
| 69 } | 69 } |
| 70 } | 70 } |
| 71 | 71 |
| 72 TEST(CipherSuiteNamesTest, SecureCipherSuites) { | 72 TEST(CipherSuiteNamesTest, SecureCipherSuites) { |
| 73 // Picked some random cipher suites. | 73 // Picked some random cipher suites. |
| 74 EXPECT_FALSE(IsSecureTLSCipherSuite(0x0 /* TLS_NULL_WITH_NULL_NULL */)); | 74 EXPECT_FALSE(IsSecureTLSCipherSuite(0x0 /* TLS_NULL_WITH_NULL_NULL */)); |
| 75 EXPECT_FALSE( | 75 EXPECT_FALSE( |
| 76 IsSecureTLSCipherSuite(0x39 /* TLS_DHE_RSA_WITH_AES_256_CBC_SHA */)); | 76 IsSecureTLSCipherSuite(0x39 /* TLS_DHE_RSA_WITH_AES_256_CBC_SHA */)); |
| 77 EXPECT_FALSE(IsSecureTLSCipherSuite( | 77 EXPECT_FALSE(IsSecureTLSCipherSuite( |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 0xcc14 /* ECDHE_ECDSA_WITH_CHACHA20_POLY1305 (non-standard) */)); | 134 0xcc14 /* ECDHE_ECDSA_WITH_CHACHA20_POLY1305 (non-standard) */)); |
| 135 EXPECT_TRUE(IsTLSCipherSuiteAllowedByHTTP2( | 135 EXPECT_TRUE(IsTLSCipherSuiteAllowedByHTTP2( |
| 136 0xcca8 /* ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256 */)); | 136 0xcca8 /* ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256 */)); |
| 137 EXPECT_TRUE(IsTLSCipherSuiteAllowedByHTTP2( | 137 EXPECT_TRUE(IsTLSCipherSuiteAllowedByHTTP2( |
| 138 0xcca9 /* ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256 */)); | 138 0xcca9 /* ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256 */)); |
| 139 } | 139 } |
| 140 | 140 |
| 141 } // anonymous namespace | 141 } // anonymous namespace |
| 142 | 142 |
| 143 } // namespace net | 143 } // namespace net |
| OLD | NEW |