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

Side by Side Diff: net/ssl/ssl_cipher_suite_names_unittest.cc

Issue 2418113002: Revert "Roll src/third_party/boringssl/src 0d81373f9..1991af690" (https://codereview.chromium.org/2… (Closed)
Patch Set: Created 4 years, 2 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
OLDNEW
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/macros.h" 7 #include "base/macros.h"
8 #include "base/strings/stringprintf.h" 8 #include "base/strings/stringprintf.h"
9 #include "net/ssl/ssl_connection_status_flags.h" 9 #include "net/ssl/ssl_connection_status_flags.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 21 matching lines...) Expand all
32 int connection_status = 0; 32 int connection_status = 0;
33 33
34 SSLConnectionStatusSetVersion(version, &connection_status); 34 SSLConnectionStatusSetVersion(version, &connection_status);
35 SSLConnectionStatusSetCipherSuite(cipher_suite, &connection_status); 35 SSLConnectionStatusSetCipherSuite(cipher_suite, &connection_status);
36 36
37 return connection_status; 37 return connection_status;
38 } 38 }
39 39
40 TEST(CipherSuiteNamesTest, Basic) { 40 TEST(CipherSuiteNamesTest, Basic) {
41 const char *key_exchange, *cipher, *mac; 41 const char *key_exchange, *cipher, *mac;
42 bool is_aead, is_tls13; 42 bool is_aead;
43 43
44 SSLCipherSuiteToStrings(&key_exchange, &cipher, &mac, &is_aead, &is_tls13, 44 SSLCipherSuiteToStrings(&key_exchange, &cipher, &mac, &is_aead, 0xc001);
45 0xc001);
46 EXPECT_STREQ("ECDH_ECDSA", key_exchange); 45 EXPECT_STREQ("ECDH_ECDSA", key_exchange);
47 EXPECT_STREQ("NULL", cipher); 46 EXPECT_STREQ("NULL", cipher);
48 EXPECT_STREQ("HMAC-SHA1", mac); 47 EXPECT_STREQ("HMAC-SHA1", mac);
49 EXPECT_FALSE(is_aead); 48 EXPECT_FALSE(is_aead);
50 EXPECT_FALSE(is_tls13);
51 49
52 SSLCipherSuiteToStrings(&key_exchange, &cipher, &mac, &is_aead, &is_tls13, 50 SSLCipherSuiteToStrings(&key_exchange, &cipher, &mac, &is_aead, 0x009f);
53 0x009f);
54 EXPECT_STREQ("DHE_RSA", key_exchange); 51 EXPECT_STREQ("DHE_RSA", key_exchange);
55 EXPECT_STREQ("AES_256_GCM", cipher); 52 EXPECT_STREQ("AES_256_GCM", cipher);
56 EXPECT_TRUE(is_aead); 53 EXPECT_TRUE(is_aead);
57 EXPECT_FALSE(is_tls13); 54 EXPECT_EQ(NULL, mac);
58 EXPECT_EQ(nullptr, mac);
59 55
60 SSLCipherSuiteToStrings(&key_exchange, &cipher, &mac, &is_aead, &is_tls13, 56 SSLCipherSuiteToStrings(&key_exchange, &cipher, &mac, &is_aead, 0xcca9);
61 0xcca9);
62 EXPECT_STREQ("ECDHE_ECDSA", key_exchange); 57 EXPECT_STREQ("ECDHE_ECDSA", key_exchange);
63 EXPECT_STREQ("CHACHA20_POLY1305", cipher); 58 EXPECT_STREQ("CHACHA20_POLY1305", cipher);
64 EXPECT_TRUE(is_aead); 59 EXPECT_TRUE(is_aead);
65 EXPECT_FALSE(is_tls13); 60 EXPECT_EQ(NULL, mac);
66 EXPECT_EQ(nullptr, mac);
67 61
68 // Non-standard variant. 62 // Non-standard variant.
69 SSLCipherSuiteToStrings(&key_exchange, &cipher, &mac, &is_aead, &is_tls13, 63 SSLCipherSuiteToStrings(&key_exchange, &cipher, &mac, &is_aead, 0xcc14);
70 0xcc14);
71 EXPECT_STREQ("ECDHE_ECDSA", key_exchange); 64 EXPECT_STREQ("ECDHE_ECDSA", key_exchange);
72 EXPECT_STREQ("CHACHA20_POLY1305", cipher); 65 EXPECT_STREQ("CHACHA20_POLY1305", cipher);
73 EXPECT_TRUE(is_aead); 66 EXPECT_TRUE(is_aead);
74 EXPECT_FALSE(is_tls13); 67 EXPECT_EQ(NULL, mac);
75 EXPECT_EQ(nullptr, mac);
76 68
77 SSLCipherSuiteToStrings(&key_exchange, &cipher, &mac, &is_aead, &is_tls13, 69 SSLCipherSuiteToStrings(&key_exchange, &cipher, &mac, &is_aead, 0xff31);
78 0xff31);
79 EXPECT_STREQ("???", key_exchange); 70 EXPECT_STREQ("???", key_exchange);
80 EXPECT_STREQ("???", cipher); 71 EXPECT_STREQ("???", cipher);
81 EXPECT_STREQ("???", mac); 72 EXPECT_STREQ("???", mac);
82 EXPECT_FALSE(is_aead); 73 EXPECT_FALSE(is_aead);
83 EXPECT_FALSE(is_tls13);
84
85 SSLCipherSuiteToStrings(&key_exchange, &cipher, &mac, &is_aead, &is_tls13,
86 0x1301);
87 EXPECT_STREQ("AES_128_GCM", cipher);
88 EXPECT_TRUE(is_aead);
89 EXPECT_TRUE(is_tls13);
90 EXPECT_EQ(nullptr, mac);
91 EXPECT_EQ(nullptr, key_exchange);
92
93 SSLCipherSuiteToStrings(&key_exchange, &cipher, &mac, &is_aead, &is_tls13,
94 0x1302);
95 EXPECT_STREQ("AES_256_GCM", cipher);
96 EXPECT_TRUE(is_aead);
97 EXPECT_TRUE(is_tls13);
98 EXPECT_EQ(nullptr, mac);
99 EXPECT_EQ(nullptr, key_exchange);
100
101 SSLCipherSuiteToStrings(&key_exchange, &cipher, &mac, &is_aead, &is_tls13,
102 0x1303);
103 EXPECT_STREQ("CHACHA20_POLY1305", cipher);
104 EXPECT_TRUE(is_aead);
105 EXPECT_TRUE(is_tls13);
106 EXPECT_EQ(nullptr, mac);
107 EXPECT_EQ(nullptr, key_exchange);
108 } 74 }
109 75
110 TEST(CipherSuiteNamesTest, ParseSSLCipherString) { 76 TEST(CipherSuiteNamesTest, ParseSSLCipherString) {
111 uint16_t cipher_suite = 0; 77 uint16_t cipher_suite = 0;
112 EXPECT_TRUE(ParseSSLCipherString("0x0004", &cipher_suite)); 78 EXPECT_TRUE(ParseSSLCipherString("0x0004", &cipher_suite));
113 EXPECT_EQ(0x00004u, cipher_suite); 79 EXPECT_EQ(0x00004u, cipher_suite);
114 80
115 EXPECT_TRUE(ParseSSLCipherString("0xBEEF", &cipher_suite)); 81 EXPECT_TRUE(ParseSSLCipherString("0xBEEF", &cipher_suite));
116 EXPECT_EQ(0xBEEFu, cipher_suite); 82 EXPECT_EQ(0xBEEFu, cipher_suite);
117 } 83 }
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 kModernVersion, kObsoleteCipherObsoleteKeyExchange))); 140 kModernVersion, kObsoleteCipherObsoleteKeyExchange)));
175 EXPECT_EQ(OBSOLETE_SSL_MASK_KEY_EXCHANGE, 141 EXPECT_EQ(OBSOLETE_SSL_MASK_KEY_EXCHANGE,
176 ObsoleteSSLStatus(MakeConnectionStatus( 142 ObsoleteSSLStatus(MakeConnectionStatus(
177 kModernVersion, kObsoleteCipherModernKeyExchange))); 143 kModernVersion, kObsoleteCipherModernKeyExchange)));
178 EXPECT_EQ(OBSOLETE_SSL_MASK_CIPHER, 144 EXPECT_EQ(OBSOLETE_SSL_MASK_CIPHER,
179 ObsoleteSSLStatus(MakeConnectionStatus( 145 ObsoleteSSLStatus(MakeConnectionStatus(
180 kModernVersion, kModernCipherObsoleteKeyExchange))); 146 kModernVersion, kModernCipherObsoleteKeyExchange)));
181 EXPECT_EQ(OBSOLETE_SSL_NONE, 147 EXPECT_EQ(OBSOLETE_SSL_NONE,
182 ObsoleteSSLStatus(MakeConnectionStatus( 148 ObsoleteSSLStatus(MakeConnectionStatus(
183 kModernVersion, kModernCipherModernKeyExchange))); 149 kModernVersion, kModernCipherModernKeyExchange)));
184 EXPECT_EQ(OBSOLETE_SSL_NONE, ObsoleteSSLStatus(MakeConnectionStatus(
185 SSL_CONNECTION_VERSION_TLS1_3,
186 0x1301 /* AES_128_GCM_SHA256 */)));
187 } 150 }
188 151
189 TEST(CipherSuiteNamesTest, HTTP2CipherSuites) { 152 TEST(CipherSuiteNamesTest, HTTP2CipherSuites) {
190 // Picked some random cipher suites. 153 // Picked some random cipher suites.
191 EXPECT_FALSE( 154 EXPECT_FALSE(
192 IsTLSCipherSuiteAllowedByHTTP2(0x0 /* TLS_NULL_WITH_NULL_NULL */)); 155 IsTLSCipherSuiteAllowedByHTTP2(0x0 /* TLS_NULL_WITH_NULL_NULL */));
193 EXPECT_FALSE(IsTLSCipherSuiteAllowedByHTTP2( 156 EXPECT_FALSE(IsTLSCipherSuiteAllowedByHTTP2(
194 0x39 /* TLS_DHE_RSA_WITH_AES_256_CBC_SHA */)); 157 0x39 /* TLS_DHE_RSA_WITH_AES_256_CBC_SHA */));
195 EXPECT_FALSE(IsTLSCipherSuiteAllowedByHTTP2( 158 EXPECT_FALSE(IsTLSCipherSuiteAllowedByHTTP2(
196 0xc5 /* TLS_DH_anon_WITH_CAMELLIA_256_CBC_SHA256 */)); 159 0xc5 /* TLS_DH_anon_WITH_CAMELLIA_256_CBC_SHA256 */));
(...skipping 15 matching lines...) Expand all
212 EXPECT_TRUE(IsTLSCipherSuiteAllowedByHTTP2( 175 EXPECT_TRUE(IsTLSCipherSuiteAllowedByHTTP2(
213 0xc02f /* TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 */)); 176 0xc02f /* TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 */));
214 EXPECT_TRUE(IsTLSCipherSuiteAllowedByHTTP2( 177 EXPECT_TRUE(IsTLSCipherSuiteAllowedByHTTP2(
215 0xcc13 /* ECDHE_RSA_WITH_CHACHA20_POLY1305 (non-standard) */)); 178 0xcc13 /* ECDHE_RSA_WITH_CHACHA20_POLY1305 (non-standard) */));
216 EXPECT_TRUE(IsTLSCipherSuiteAllowedByHTTP2( 179 EXPECT_TRUE(IsTLSCipherSuiteAllowedByHTTP2(
217 0xcc14 /* ECDHE_ECDSA_WITH_CHACHA20_POLY1305 (non-standard) */)); 180 0xcc14 /* ECDHE_ECDSA_WITH_CHACHA20_POLY1305 (non-standard) */));
218 EXPECT_TRUE(IsTLSCipherSuiteAllowedByHTTP2( 181 EXPECT_TRUE(IsTLSCipherSuiteAllowedByHTTP2(
219 0xcca8 /* ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256 */)); 182 0xcca8 /* ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256 */));
220 EXPECT_TRUE(IsTLSCipherSuiteAllowedByHTTP2( 183 EXPECT_TRUE(IsTLSCipherSuiteAllowedByHTTP2(
221 0xcca9 /* ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256 */)); 184 0xcca9 /* ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256 */));
222 EXPECT_TRUE(IsTLSCipherSuiteAllowedByHTTP2(0x1301 /* AES_128_GCM_SHA256 */));
223 EXPECT_TRUE(IsTLSCipherSuiteAllowedByHTTP2(0x1302 /* AES_256_GCM_SHA384 */));
224 EXPECT_TRUE(IsTLSCipherSuiteAllowedByHTTP2(0x1303 /* CHACHA20_POLY1305 */));
225 } 185 }
226 186
227 TEST(CipherSuiteNamesTest, CECPQ1) { 187 TEST(CipherSuiteNamesTest, CECPQ1) {
228 const std::vector<uint16_t> kCECPQ1CipherSuites = { 188 const std::vector<uint16_t> kCECPQ1CipherSuites = {
229 0x16b7, // TLS_CECPQ1_RSA_WITH_CHACHA20_POLY1305_SHA256 (non-standard) 189 0x16b7, // TLS_CECPQ1_RSA_WITH_CHACHA20_POLY1305_SHA256 (non-standard)
230 0x16b8, // TLS_CECPQ1_ECDSA_WITH_CHACHA20_POLY1305_SHA256 (non-standard) 190 0x16b8, // TLS_CECPQ1_ECDSA_WITH_CHACHA20_POLY1305_SHA256 (non-standard)
231 0x16b9, // TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384 (non-standard) 191 0x16b9, // TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384 (non-standard)
232 0x16ba, // TLS_CECPQ1_ECDSA_WITH_AES_256_GCM_SHA384 (non-standard) 192 0x16ba, // TLS_CECPQ1_ECDSA_WITH_AES_256_GCM_SHA384 (non-standard)
233 }; 193 };
234 const char *key_exchange, *cipher, *mac; 194 const char *key_exchange, *cipher, *mac;
235 bool is_aead, is_tls13; 195 bool is_aead;
236 196
237 for (const uint16_t cipher_suite_id : kCECPQ1CipherSuites) { 197 for (const uint16_t cipher_suite_id : kCECPQ1CipherSuites) {
238 SCOPED_TRACE(base::StringPrintf("cipher suite %x", cipher_suite_id)); 198 SCOPED_TRACE(base::StringPrintf("cipher suite %x", cipher_suite_id));
239 EXPECT_TRUE(IsTLSCipherSuiteAllowedByHTTP2(cipher_suite_id)); 199 EXPECT_TRUE(IsTLSCipherSuiteAllowedByHTTP2(cipher_suite_id));
240 200
241 int connection_status = 201 int connection_status =
242 MakeConnectionStatus(kModernVersion, cipher_suite_id); 202 MakeConnectionStatus(kModernVersion, cipher_suite_id);
243 EXPECT_EQ(OBSOLETE_SSL_NONE, ObsoleteSSLStatus(connection_status)); 203 EXPECT_EQ(OBSOLETE_SSL_NONE, ObsoleteSSLStatus(connection_status));
244 EXPECT_TRUE(IsTLSCipherSuiteAllowedByHTTP2(cipher_suite_id)); 204 SSLCipherSuiteToStrings(&key_exchange, &cipher, &mac, &is_aead,
245 SSLCipherSuiteToStrings(&key_exchange, &cipher, &mac, &is_aead, &is_tls13,
246 cipher_suite_id); 205 cipher_suite_id);
247 EXPECT_TRUE(is_aead); 206 EXPECT_TRUE(is_aead);
248 EXPECT_FALSE(is_tls13);
249 EXPECT_EQ(nullptr, mac); 207 EXPECT_EQ(nullptr, mac);
250 } 208 }
251 209
252 SSLCipherSuiteToStrings(&key_exchange, &cipher, &mac, &is_aead, &is_tls13, 210 SSLCipherSuiteToStrings(&key_exchange, &cipher, &mac, &is_aead, 0x16b7);
253 0x16b7);
254 EXPECT_STREQ("CECPQ1_RSA", key_exchange); 211 EXPECT_STREQ("CECPQ1_RSA", key_exchange);
255 EXPECT_STREQ("CHACHA20_POLY1305", cipher); 212 EXPECT_STREQ("CHACHA20_POLY1305", cipher);
256 213
257 SSLCipherSuiteToStrings(&key_exchange, &cipher, &mac, &is_aead, &is_tls13, 214 SSLCipherSuiteToStrings(&key_exchange, &cipher, &mac, &is_aead, 0x16b8);
258 0x16b8);
259 EXPECT_STREQ("CECPQ1_ECDSA", key_exchange); 215 EXPECT_STREQ("CECPQ1_ECDSA", key_exchange);
260 EXPECT_STREQ("CHACHA20_POLY1305", cipher); 216 EXPECT_STREQ("CHACHA20_POLY1305", cipher);
261 217
262 SSLCipherSuiteToStrings(&key_exchange, &cipher, &mac, &is_aead, &is_tls13, 218 SSLCipherSuiteToStrings(&key_exchange, &cipher, &mac, &is_aead, 0x16b9);
263 0x16b9);
264 EXPECT_STREQ("CECPQ1_RSA", key_exchange); 219 EXPECT_STREQ("CECPQ1_RSA", key_exchange);
265 EXPECT_STREQ("AES_256_GCM", cipher); 220 EXPECT_STREQ("AES_256_GCM", cipher);
266 221
267 SSLCipherSuiteToStrings(&key_exchange, &cipher, &mac, &is_aead, &is_tls13, 222 SSLCipherSuiteToStrings(&key_exchange, &cipher, &mac, &is_aead, 0x16ba);
268 0x16ba);
269 EXPECT_STREQ("CECPQ1_ECDSA", key_exchange); 223 EXPECT_STREQ("CECPQ1_ECDSA", key_exchange);
270 EXPECT_STREQ("AES_256_GCM", cipher); 224 EXPECT_STREQ("AES_256_GCM", cipher);
271 } 225 }
272 226
273 } // anonymous namespace 227 } // anonymous namespace
274 228
275 } // namespace net 229 } // namespace net
OLDNEW
« no previous file with comments | « net/ssl/ssl_cipher_suite_names.cc ('k') | third_party/WebKit/Source/core/inspector/browser_protocol.json » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698