| OLD | NEW |
| (Empty) |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/ssl/chrome_security_state_model_client.h" | |
| 6 | |
| 7 #include "components/security_state/security_state_model.h" | |
| 8 #include "content/public/browser/security_style_explanation.h" | |
| 9 #include "content/public/browser/security_style_explanations.h" | |
| 10 #include "net/cert/cert_status_flags.h" | |
| 11 #include "net/ssl/ssl_cipher_suite_names.h" | |
| 12 #include "net/ssl/ssl_connection_status_flags.h" | |
| 13 #include "testing/gtest/include/gtest/gtest.h" | |
| 14 | |
| 15 namespace { | |
| 16 | |
| 17 // Tests that SecurityInfo flags for subresources with certificate | |
| 18 // errors are reflected in the SecurityStyleExplanations produced by | |
| 19 // ChromeSecurityStateModelClient. | |
| 20 TEST(ChromeSecurityStateModelClientTest, | |
| 21 GetSecurityStyleForContentWithCertErrors) { | |
| 22 content::SecurityStyleExplanations explanations; | |
| 23 security_state::SecurityStateModel::SecurityInfo security_info; | |
| 24 security_info.cert_status = 0; | |
| 25 security_info.scheme_is_cryptographic = true; | |
| 26 | |
| 27 security_info.content_with_cert_errors_status = | |
| 28 security_state::SecurityStateModel::CONTENT_STATUS_DISPLAYED_AND_RAN; | |
| 29 ChromeSecurityStateModelClient::GetSecurityStyle(security_info, | |
| 30 &explanations); | |
| 31 EXPECT_TRUE(explanations.ran_content_with_cert_errors); | |
| 32 EXPECT_TRUE(explanations.displayed_content_with_cert_errors); | |
| 33 | |
| 34 security_info.content_with_cert_errors_status = | |
| 35 security_state::SecurityStateModel::CONTENT_STATUS_RAN; | |
| 36 ChromeSecurityStateModelClient::GetSecurityStyle(security_info, | |
| 37 &explanations); | |
| 38 EXPECT_TRUE(explanations.ran_content_with_cert_errors); | |
| 39 EXPECT_FALSE(explanations.displayed_content_with_cert_errors); | |
| 40 | |
| 41 security_info.content_with_cert_errors_status = | |
| 42 security_state::SecurityStateModel::CONTENT_STATUS_DISPLAYED; | |
| 43 ChromeSecurityStateModelClient::GetSecurityStyle(security_info, | |
| 44 &explanations); | |
| 45 EXPECT_FALSE(explanations.ran_content_with_cert_errors); | |
| 46 EXPECT_TRUE(explanations.displayed_content_with_cert_errors); | |
| 47 | |
| 48 security_info.content_with_cert_errors_status = | |
| 49 security_state::SecurityStateModel::CONTENT_STATUS_NONE; | |
| 50 ChromeSecurityStateModelClient::GetSecurityStyle(security_info, | |
| 51 &explanations); | |
| 52 EXPECT_FALSE(explanations.ran_content_with_cert_errors); | |
| 53 EXPECT_FALSE(explanations.displayed_content_with_cert_errors); | |
| 54 } | |
| 55 | |
| 56 // Tests that SecurityStyleExplanations for subresources with cert | |
| 57 // errors are *not* set when the main resource has major certificate | |
| 58 // errors. If the main resource has certificate errors, it would be | |
| 59 // duplicative/confusing to also report subresources with cert errors. | |
| 60 TEST(ChromeSecurityStateModelClientTest, | |
| 61 SubresourcesAndMainResourceWithMajorCertErrors) { | |
| 62 content::SecurityStyleExplanations explanations; | |
| 63 security_state::SecurityStateModel::SecurityInfo security_info; | |
| 64 security_info.cert_status = net::CERT_STATUS_DATE_INVALID; | |
| 65 security_info.scheme_is_cryptographic = true; | |
| 66 | |
| 67 security_info.content_with_cert_errors_status = | |
| 68 security_state::SecurityStateModel::CONTENT_STATUS_DISPLAYED_AND_RAN; | |
| 69 ChromeSecurityStateModelClient::GetSecurityStyle(security_info, | |
| 70 &explanations); | |
| 71 EXPECT_FALSE(explanations.ran_content_with_cert_errors); | |
| 72 EXPECT_FALSE(explanations.displayed_content_with_cert_errors); | |
| 73 | |
| 74 security_info.content_with_cert_errors_status = | |
| 75 security_state::SecurityStateModel::CONTENT_STATUS_RAN; | |
| 76 ChromeSecurityStateModelClient::GetSecurityStyle(security_info, | |
| 77 &explanations); | |
| 78 EXPECT_FALSE(explanations.ran_content_with_cert_errors); | |
| 79 EXPECT_FALSE(explanations.displayed_content_with_cert_errors); | |
| 80 | |
| 81 security_info.content_with_cert_errors_status = | |
| 82 security_state::SecurityStateModel::CONTENT_STATUS_DISPLAYED; | |
| 83 ChromeSecurityStateModelClient::GetSecurityStyle(security_info, | |
| 84 &explanations); | |
| 85 EXPECT_FALSE(explanations.ran_content_with_cert_errors); | |
| 86 EXPECT_FALSE(explanations.displayed_content_with_cert_errors); | |
| 87 | |
| 88 security_info.content_with_cert_errors_status = | |
| 89 security_state::SecurityStateModel::CONTENT_STATUS_NONE; | |
| 90 ChromeSecurityStateModelClient::GetSecurityStyle(security_info, | |
| 91 &explanations); | |
| 92 EXPECT_FALSE(explanations.ran_content_with_cert_errors); | |
| 93 EXPECT_FALSE(explanations.displayed_content_with_cert_errors); | |
| 94 } | |
| 95 | |
| 96 // Tests that SecurityStyleExplanations for subresources with cert | |
| 97 // errors are set when the main resource has only minor certificate | |
| 98 // errors. Minor errors on the main resource should not hide major | |
| 99 // errors on subresources. | |
| 100 TEST(ChromeSecurityStateModelClientTest, | |
| 101 SubresourcesAndMainResourceWithMinorCertErrors) { | |
| 102 content::SecurityStyleExplanations explanations; | |
| 103 security_state::SecurityStateModel::SecurityInfo security_info; | |
| 104 security_info.cert_status = net::CERT_STATUS_UNABLE_TO_CHECK_REVOCATION; | |
| 105 security_info.scheme_is_cryptographic = true; | |
| 106 | |
| 107 security_info.content_with_cert_errors_status = | |
| 108 security_state::SecurityStateModel::CONTENT_STATUS_DISPLAYED_AND_RAN; | |
| 109 ChromeSecurityStateModelClient::GetSecurityStyle(security_info, | |
| 110 &explanations); | |
| 111 EXPECT_TRUE(explanations.ran_content_with_cert_errors); | |
| 112 EXPECT_TRUE(explanations.displayed_content_with_cert_errors); | |
| 113 | |
| 114 security_info.content_with_cert_errors_status = | |
| 115 security_state::SecurityStateModel::CONTENT_STATUS_RAN; | |
| 116 ChromeSecurityStateModelClient::GetSecurityStyle(security_info, | |
| 117 &explanations); | |
| 118 EXPECT_TRUE(explanations.ran_content_with_cert_errors); | |
| 119 EXPECT_FALSE(explanations.displayed_content_with_cert_errors); | |
| 120 | |
| 121 security_info.content_with_cert_errors_status = | |
| 122 security_state::SecurityStateModel::CONTENT_STATUS_DISPLAYED; | |
| 123 ChromeSecurityStateModelClient::GetSecurityStyle(security_info, | |
| 124 &explanations); | |
| 125 EXPECT_FALSE(explanations.ran_content_with_cert_errors); | |
| 126 EXPECT_TRUE(explanations.displayed_content_with_cert_errors); | |
| 127 | |
| 128 security_info.content_with_cert_errors_status = | |
| 129 security_state::SecurityStateModel::CONTENT_STATUS_NONE; | |
| 130 ChromeSecurityStateModelClient::GetSecurityStyle(security_info, | |
| 131 &explanations); | |
| 132 EXPECT_FALSE(explanations.ran_content_with_cert_errors); | |
| 133 EXPECT_FALSE(explanations.displayed_content_with_cert_errors); | |
| 134 } | |
| 135 | |
| 136 bool FindSecurityStyleExplanation( | |
| 137 const std::vector<content::SecurityStyleExplanation>& explanations, | |
| 138 const char* summary, | |
| 139 content::SecurityStyleExplanation* explanation) { | |
| 140 for (const auto& entry : explanations) { | |
| 141 if (entry.summary == summary) { | |
| 142 *explanation = entry; | |
| 143 return true; | |
| 144 } | |
| 145 } | |
| 146 | |
| 147 return false; | |
| 148 } | |
| 149 | |
| 150 // Test that connection explanations are formated as expected. Note the strings | |
| 151 // are not translated and so will be the same in any locale. | |
| 152 TEST(ChromeSecurityStateModelClientTest, ConnectionExplanation) { | |
| 153 // Test a modern configuration with a key exchange group. | |
| 154 security_state::SecurityStateModel::SecurityInfo security_info; | |
| 155 security_info.cert_status = net::CERT_STATUS_UNABLE_TO_CHECK_REVOCATION; | |
| 156 security_info.scheme_is_cryptographic = true; | |
| 157 net::SSLConnectionStatusSetCipherSuite( | |
| 158 0xcca8 /* TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256 */, | |
| 159 &security_info.connection_status); | |
| 160 net::SSLConnectionStatusSetVersion(net::SSL_CONNECTION_VERSION_TLS1_2, | |
| 161 &security_info.connection_status); | |
| 162 security_info.key_exchange_group = 29; // X25519 | |
| 163 | |
| 164 { | |
| 165 content::SecurityStyleExplanations explanations; | |
| 166 ChromeSecurityStateModelClient::GetSecurityStyle(security_info, | |
| 167 &explanations); | |
| 168 content::SecurityStyleExplanation explanation; | |
| 169 ASSERT_TRUE(FindSecurityStyleExplanation( | |
| 170 explanations.secure_explanations, "Secure Connection", &explanation)); | |
| 171 EXPECT_EQ( | |
| 172 "The connection to this site is encrypted and authenticated using a " | |
| 173 "strong protocol (TLS 1.2), a strong key exchange (ECDHE_RSA with " | |
| 174 "X25519), and a strong cipher (CHACHA20_POLY1305).", | |
| 175 explanation.description); | |
| 176 } | |
| 177 | |
| 178 // Some older cache entries may be missing the key exchange group, despite | |
| 179 // having a cipher which should supply one. | |
| 180 security_info.key_exchange_group = 0; | |
| 181 { | |
| 182 content::SecurityStyleExplanations explanations; | |
| 183 ChromeSecurityStateModelClient::GetSecurityStyle(security_info, | |
| 184 &explanations); | |
| 185 content::SecurityStyleExplanation explanation; | |
| 186 ASSERT_TRUE(FindSecurityStyleExplanation( | |
| 187 explanations.secure_explanations, "Secure Connection", &explanation)); | |
| 188 EXPECT_EQ( | |
| 189 "The connection to this site is encrypted and authenticated using a " | |
| 190 "strong protocol (TLS 1.2), a strong key exchange (ECDHE_RSA), and a " | |
| 191 "strong cipher (CHACHA20_POLY1305).", | |
| 192 explanation.description); | |
| 193 } | |
| 194 | |
| 195 // TLS 1.3 ciphers use the key exchange group exclusively. | |
| 196 net::SSLConnectionStatusSetCipherSuite(0x1301 /* TLS_AES_128_GCM_SHA256 */, | |
| 197 &security_info.connection_status); | |
| 198 net::SSLConnectionStatusSetVersion(net::SSL_CONNECTION_VERSION_TLS1_3, | |
| 199 &security_info.connection_status); | |
| 200 security_info.key_exchange_group = 29; // X25519 | |
| 201 { | |
| 202 content::SecurityStyleExplanations explanations; | |
| 203 ChromeSecurityStateModelClient::GetSecurityStyle(security_info, | |
| 204 &explanations); | |
| 205 content::SecurityStyleExplanation explanation; | |
| 206 ASSERT_TRUE(FindSecurityStyleExplanation( | |
| 207 explanations.secure_explanations, "Secure Connection", &explanation)); | |
| 208 EXPECT_EQ( | |
| 209 "The connection to this site is encrypted and authenticated using a " | |
| 210 "strong protocol (TLS 1.3), a strong key exchange (X25519), and a " | |
| 211 "strong cipher (AES_128_GCM).", | |
| 212 explanation.description); | |
| 213 } | |
| 214 } | |
| 215 | |
| 216 // Tests that a security level of HTTP_SHOW_WARNING produces a | |
| 217 // content::SecurityStyle of UNAUTHENTICATED, with an explanation. | |
| 218 TEST(ChromeSecurityStateModelClientTest, HTTPWarning) { | |
| 219 security_state::SecurityStateModel::SecurityInfo security_info; | |
| 220 content::SecurityStyleExplanations explanations; | |
| 221 security_info.security_level = | |
| 222 security_state::SecurityStateModel::HTTP_SHOW_WARNING; | |
| 223 blink::WebSecurityStyle security_style = | |
| 224 ChromeSecurityStateModelClient::GetSecurityStyle(security_info, | |
| 225 &explanations); | |
| 226 EXPECT_EQ(blink::WebSecurityStyleUnauthenticated, security_style); | |
| 227 EXPECT_EQ(1u, explanations.unauthenticated_explanations.size()); | |
| 228 } | |
| 229 | |
| 230 // Tests that a security level of NONE when there is a password or | |
| 231 // credit card field on HTTP produces a content::SecurityStyle of | |
| 232 // UNAUTHENTICATED, with an info explanation. | |
| 233 TEST(ChromeSecurityStateModelClientTest, HTTPWarningInFuture) { | |
| 234 security_state::SecurityStateModel::SecurityInfo security_info; | |
| 235 content::SecurityStyleExplanations explanations; | |
| 236 security_info.security_level = security_state::SecurityStateModel::NONE; | |
| 237 security_info.displayed_private_user_data_input_on_http = true; | |
| 238 blink::WebSecurityStyle security_style = | |
| 239 ChromeSecurityStateModelClient::GetSecurityStyle(security_info, | |
| 240 &explanations); | |
| 241 EXPECT_EQ(blink::WebSecurityStyleUnauthenticated, security_style); | |
| 242 EXPECT_EQ(1u, explanations.info_explanations.size()); | |
| 243 } | |
| 244 | |
| 245 } // namespace | |
| OLD | NEW |