OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "chrome/browser/ssl/security_state_model.h" | 5 #include "chrome/browser/ssl/security_state_model.h" |
6 | 6 |
| 7 #include <stdint.h> |
| 8 |
7 #include "chrome/browser/ssl/security_state_model_client.h" | 9 #include "chrome/browser/ssl/security_state_model_client.h" |
8 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 10 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
9 #include "chrome/test/base/testing_profile.h" | 11 #include "chrome/test/base/testing_profile.h" |
10 #include "content/public/browser/cert_store.h" | 12 #include "content/public/browser/cert_store.h" |
11 #include "content/public/common/origin_util.h" | 13 #include "content/public/common/origin_util.h" |
12 #include "content/public/test/mock_render_process_host.h" | 14 #include "content/public/test/mock_render_process_host.h" |
13 #include "content/public/test/test_browser_thread_bundle.h" | 15 #include "content/public/test/test_browser_thread_bundle.h" |
14 #include "net/base/test_data_directory.h" | 16 #include "net/base/test_data_directory.h" |
15 #include "net/cert/x509_certificate.h" | 17 #include "net/cert/x509_certificate.h" |
16 #include "net/ssl/ssl_connection_status_flags.h" | 18 #include "net/ssl/ssl_connection_status_flags.h" |
(...skipping 15 matching lines...) Expand all Loading... |
32 displayed_mixed_content_(false), | 34 displayed_mixed_content_(false), |
33 ran_mixed_content_(false) { | 35 ran_mixed_content_(false) { |
34 cert_ = | 36 cert_ = |
35 net::ImportCertFromFile(net::GetTestCertsDirectory(), "sha1_2016.pem"); | 37 net::ImportCertFromFile(net::GetTestCertsDirectory(), "sha1_2016.pem"); |
36 } | 38 } |
37 ~TestSecurityStateModelClient() override {} | 39 ~TestSecurityStateModelClient() override {} |
38 | 40 |
39 void set_connection_status(int connection_status) { | 41 void set_connection_status(int connection_status) { |
40 connection_status_ = connection_status; | 42 connection_status_ = connection_status; |
41 } | 43 } |
42 void SetCipherSuite(uint16 ciphersuite) { | 44 void SetCipherSuite(uint16_t ciphersuite) { |
43 net::SSLConnectionStatusSetCipherSuite(ciphersuite, &connection_status_); | 45 net::SSLConnectionStatusSetCipherSuite(ciphersuite, &connection_status_); |
44 } | 46 } |
45 void AddCertStatus(net::CertStatus cert_status) { | 47 void AddCertStatus(net::CertStatus cert_status) { |
46 cert_status_ |= cert_status; | 48 cert_status_ |= cert_status; |
47 } | 49 } |
48 void SetDisplayedMixedContent(bool displayed_mixed_content) { | 50 void SetDisplayedMixedContent(bool displayed_mixed_content) { |
49 displayed_mixed_content_ = displayed_mixed_content; | 51 displayed_mixed_content_ = displayed_mixed_content; |
50 } | 52 } |
51 void SetRanMixedContent(bool ran_mixed_content) { | 53 void SetRanMixedContent(bool ran_mixed_content) { |
52 ran_mixed_content_ = ran_mixed_content; | 54 ran_mixed_content_ = ran_mixed_content; |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 } | 150 } |
149 | 151 |
150 // Tests that |security_info.is_secure_protocol_and_ciphersuite| is | 152 // Tests that |security_info.is_secure_protocol_and_ciphersuite| is |
151 // computed correctly. | 153 // computed correctly. |
152 TEST_F(SecurityStateModelTest, SecureProtocolAndCiphersuite) { | 154 TEST_F(SecurityStateModelTest, SecureProtocolAndCiphersuite) { |
153 TestSecurityStateModelClient client; | 155 TestSecurityStateModelClient client; |
154 SecurityStateModel model; | 156 SecurityStateModel model; |
155 model.SetClient(&client); | 157 model.SetClient(&client); |
156 // TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 from | 158 // TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 from |
157 // http://www.iana.org/assignments/tls-parameters/tls-parameters.xml#tls-param
eters-4 | 159 // http://www.iana.org/assignments/tls-parameters/tls-parameters.xml#tls-param
eters-4 |
158 const uint16 ciphersuite = 0xc02f; | 160 const uint16_t ciphersuite = 0xc02f; |
159 client.set_connection_status(net::SSL_CONNECTION_VERSION_TLS1_2 | 161 client.set_connection_status(net::SSL_CONNECTION_VERSION_TLS1_2 |
160 << net::SSL_CONNECTION_VERSION_SHIFT); | 162 << net::SSL_CONNECTION_VERSION_SHIFT); |
161 client.SetCipherSuite(ciphersuite); | 163 client.SetCipherSuite(ciphersuite); |
162 const SecurityStateModel::SecurityInfo& security_info = | 164 const SecurityStateModel::SecurityInfo& security_info = |
163 model.GetSecurityInfo(); | 165 model.GetSecurityInfo(); |
164 EXPECT_TRUE(security_info.is_secure_protocol_and_ciphersuite); | 166 EXPECT_TRUE(security_info.is_secure_protocol_and_ciphersuite); |
165 } | 167 } |
166 | 168 |
167 TEST_F(SecurityStateModelTest, NonsecureProtocol) { | 169 TEST_F(SecurityStateModelTest, NonsecureProtocol) { |
168 TestSecurityStateModelClient client; | 170 TestSecurityStateModelClient client; |
169 SecurityStateModel model; | 171 SecurityStateModel model; |
170 model.SetClient(&client); | 172 model.SetClient(&client); |
171 // TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 from | 173 // TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 from |
172 // http://www.iana.org/assignments/tls-parameters/tls-parameters.xml#tls-param
eters-4 | 174 // http://www.iana.org/assignments/tls-parameters/tls-parameters.xml#tls-param
eters-4 |
173 const uint16 ciphersuite = 0xc02f; | 175 const uint16_t ciphersuite = 0xc02f; |
174 client.set_connection_status(net::SSL_CONNECTION_VERSION_TLS1_1 | 176 client.set_connection_status(net::SSL_CONNECTION_VERSION_TLS1_1 |
175 << net::SSL_CONNECTION_VERSION_SHIFT); | 177 << net::SSL_CONNECTION_VERSION_SHIFT); |
176 client.SetCipherSuite(ciphersuite); | 178 client.SetCipherSuite(ciphersuite); |
177 const SecurityStateModel::SecurityInfo& security_info = | 179 const SecurityStateModel::SecurityInfo& security_info = |
178 model.GetSecurityInfo(); | 180 model.GetSecurityInfo(); |
179 EXPECT_FALSE(security_info.is_secure_protocol_and_ciphersuite); | 181 EXPECT_FALSE(security_info.is_secure_protocol_and_ciphersuite); |
180 } | 182 } |
181 | 183 |
182 TEST_F(SecurityStateModelTest, NonsecureCiphersuite) { | 184 TEST_F(SecurityStateModelTest, NonsecureCiphersuite) { |
183 TestSecurityStateModelClient client; | 185 TestSecurityStateModelClient client; |
184 SecurityStateModel model; | 186 SecurityStateModel model; |
185 model.SetClient(&client); | 187 model.SetClient(&client); |
186 // TLS_RSA_WITH_AES_128_CCM_8 from | 188 // TLS_RSA_WITH_AES_128_CCM_8 from |
187 // http://www.iana.org/assignments/tls-parameters/tls-parameters.xml#tls-param
eters-4 | 189 // http://www.iana.org/assignments/tls-parameters/tls-parameters.xml#tls-param
eters-4 |
188 const uint16 ciphersuite = 0xc0a0; | 190 const uint16_t ciphersuite = 0xc0a0; |
189 client.set_connection_status(net::SSL_CONNECTION_VERSION_TLS1_2 | 191 client.set_connection_status(net::SSL_CONNECTION_VERSION_TLS1_2 |
190 << net::SSL_CONNECTION_VERSION_SHIFT); | 192 << net::SSL_CONNECTION_VERSION_SHIFT); |
191 client.SetCipherSuite(ciphersuite); | 193 client.SetCipherSuite(ciphersuite); |
192 const SecurityStateModel::SecurityInfo& security_info = | 194 const SecurityStateModel::SecurityInfo& security_info = |
193 model.GetSecurityInfo(); | 195 model.GetSecurityInfo(); |
194 EXPECT_FALSE(security_info.is_secure_protocol_and_ciphersuite); | 196 EXPECT_FALSE(security_info.is_secure_protocol_and_ciphersuite); |
195 } | 197 } |
196 | 198 |
197 } // namespace | 199 } // namespace |
OLD | NEW |