| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 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 "ios/chrome/browser/ssl/ios_chrome_security_state_model_client.h" | 5 #include "components/security_state/ios/ios_security_state_model.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/metrics/field_trial.h" | 8 #include "base/metrics/field_trial.h" |
| 9 #include "base/metrics/histogram_macros.h" | 9 #include "base/metrics/histogram_macros.h" |
| 10 #include "ios/web/public/navigation_item.h" | 10 #include "ios/web/public/navigation_item.h" |
| 11 #import "ios/web/public/navigation_manager.h" | 11 #import "ios/web/public/navigation_manager.h" |
| 12 #import "ios/web/public/origin_util.h" | 12 #import "ios/web/public/origin_util.h" |
| 13 #include "ios/web/public/security_style.h" | 13 #include "ios/web/public/security_style.h" |
| 14 #include "ios/web/public/ssl_status.h" | 14 #include "ios/web/public/ssl_status.h" |
| 15 #include "ios/web/public/web_state/web_state.h" | 15 #include "ios/web/public/web_state/web_state.h" |
| 16 #include "net/cert/x509_certificate.h" | 16 #include "net/cert/x509_certificate.h" |
| 17 | 17 |
| 18 DEFINE_WEB_STATE_USER_DATA_KEY(IOSChromeSecurityStateModelClient); | 18 DEFINE_WEB_STATE_USER_DATA_KEY(IOSSecurityStateModel); |
| 19 |
| 20 namespace security_state { |
| 19 | 21 |
| 20 namespace { | 22 namespace { |
| 21 | 23 |
| 22 // Converts a web::SecurityStyle (an indicator of a request's | 24 // Converts a web::SecurityStyle (an indicator of a request's |
| 23 // overall security level computed by //ios/web) into a | 25 // overall security level computed by //ios/web) into a |
| 24 // SecurityStateModel::SecurityLevel (a finer-grained SecurityStateModel | 26 // SecurityStateModel::SecurityLevel (a finer-grained SecurityStateModel |
| 25 // concept that can express all of SecurityStateModel's policies that | 27 // concept that can express all of SecurityStateModel's policies that |
| 26 // //ios/web doesn't necessarily know about). | 28 // //ios/web doesn't necessarily know about). |
| 27 security_state::SecurityStateModel::SecurityLevel | 29 SecurityStateModel::SecurityLevel |
| 28 GetSecurityLevelForSecurityStyle(web::SecurityStyle style) { | 30 GetSecurityLevelForSecurityStyle(web::SecurityStyle style) { |
| 29 switch (style) { | 31 switch (style) { |
| 30 case web::SECURITY_STYLE_UNKNOWN: | 32 case web::SECURITY_STYLE_UNKNOWN: |
| 31 NOTREACHED(); | 33 NOTREACHED(); |
| 32 return security_state::SecurityStateModel::NONE; | 34 return SecurityStateModel::NONE; |
| 33 case web::SECURITY_STYLE_UNAUTHENTICATED: | 35 case web::SECURITY_STYLE_UNAUTHENTICATED: |
| 34 return security_state::SecurityStateModel::NONE; | 36 return SecurityStateModel::NONE; |
| 35 case web::SECURITY_STYLE_AUTHENTICATION_BROKEN: | 37 case web::SECURITY_STYLE_AUTHENTICATION_BROKEN: |
| 36 return security_state::SecurityStateModel::DANGEROUS; | 38 return SecurityStateModel::DANGEROUS; |
| 37 case web::SECURITY_STYLE_WARNING: | 39 case web::SECURITY_STYLE_WARNING: |
| 38 // //ios/web currently doesn't use this style. | 40 // //ios/web currently doesn't use this style. |
| 39 NOTREACHED(); | 41 NOTREACHED(); |
| 40 return security_state::SecurityStateModel::SECURITY_WARNING; | 42 return SecurityStateModel::SECURITY_WARNING; |
| 41 case web::SECURITY_STYLE_AUTHENTICATED: | 43 case web::SECURITY_STYLE_AUTHENTICATED: |
| 42 return security_state::SecurityStateModel::SECURE; | 44 return SecurityStateModel::SECURE; |
| 43 } | 45 } |
| 44 return security_state::SecurityStateModel::NONE; | 46 return SecurityStateModel::NONE; |
| 45 } | 47 } |
| 46 | 48 |
| 47 } // namespace | 49 } // namespace |
| 48 | 50 |
| 49 IOSChromeSecurityStateModelClient::IOSChromeSecurityStateModelClient( | 51 bool IsOriginSecure(const GURL& url) { |
| 52 return web::IsOriginSecure(url); |
| 53 } |
| 54 |
| 55 IOSSecurityStateModel::IOSSecurityStateModel( |
| 50 web::WebState* web_state) | 56 web::WebState* web_state) |
| 51 : web_state_(web_state), | 57 : web_state_(web_state), |
| 52 security_state_model_(new security_state::SecurityStateModel()) { | 58 security_state_model_(new SecurityStateModel()) {} |
| 53 security_state_model_->SetClient(this); | 59 |
| 60 IOSSecurityStateModel::~IOSSecurityStateModel() {} |
| 61 |
| 62 void IOSSecurityStateModel::GetSecurityInfo( |
| 63 SecurityStateModel::SecurityInfo* result) const { |
| 64 security_state_model_->GetSecurityInfo( |
| 65 result, GetVisibleSecurityState(), UsedPolicyInstalledCertificate()); |
| 54 } | 66 } |
| 55 | 67 |
| 56 IOSChromeSecurityStateModelClient::~IOSChromeSecurityStateModelClient() {} | 68 bool IOSSecurityStateModel::UsedPolicyInstalledCertificate() const { |
| 57 | |
| 58 void IOSChromeSecurityStateModelClient::GetSecurityInfo( | |
| 59 security_state::SecurityStateModel::SecurityInfo* result) const { | |
| 60 return security_state_model_->GetSecurityInfo(result); | |
| 61 } | |
| 62 | |
| 63 bool IOSChromeSecurityStateModelClient::UsedPolicyInstalledCertificate() { | |
| 64 return false; | 69 return false; |
| 65 } | 70 } |
| 66 | 71 |
| 67 bool IOSChromeSecurityStateModelClient::IsOriginSecure(const GURL& url) { | 72 std::unique_ptr<SecurityStateModel::VisibleSecurityState> |
| 68 return web::IsOriginSecure(url); | 73 IOSSecurityStateModel::GetVisibleSecurityState() const { |
| 69 } | 74 auto state = base::MakeUnique<SecurityStateModel::VisibleSecurityState>(); |
| 70 | 75 |
| 71 void IOSChromeSecurityStateModelClient::GetVisibleSecurityState( | |
| 72 security_state::SecurityStateModel::VisibleSecurityState* state) { | |
| 73 web::NavigationItem* item = | 76 web::NavigationItem* item = |
| 74 web_state_->GetNavigationManager()->GetVisibleItem(); | 77 web_state_->GetNavigationManager()->GetVisibleItem(); |
| 75 if (!item || item->GetSSL().security_style == web::SECURITY_STYLE_UNKNOWN) { | 78 if (!item || item->GetSSL().security_style == web::SECURITY_STYLE_UNKNOWN) |
| 76 *state = security_state::SecurityStateModel::VisibleSecurityState(); | 79 return state; |
| 77 return; | |
| 78 } | |
| 79 | 80 |
| 80 state->connection_info_initialized = true; | 81 state->connection_info_initialized = true; |
| 81 state->url = item->GetURL(); | 82 state->url = item->GetURL(); |
| 82 const web::SSLStatus& ssl = item->GetSSL(); | 83 const web::SSLStatus& ssl = item->GetSSL(); |
| 83 state->certificate = ssl.certificate; | 84 state->certificate = ssl.certificate; |
| 84 state->cert_status = ssl.cert_status; | 85 state->cert_status = ssl.cert_status; |
| 85 state->connection_status = ssl.connection_status; | 86 state->connection_status = ssl.connection_status; |
| 86 state->security_bits = ssl.security_bits; | 87 state->security_bits = ssl.security_bits; |
| 87 state->displayed_mixed_content = | 88 state->displayed_mixed_content = |
| 88 (ssl.content_status & web::SSLStatus::DISPLAYED_INSECURE_CONTENT) ? true | 89 (ssl.content_status & web::SSLStatus::DISPLAYED_INSECURE_CONTENT) ? true |
| 89 : false; | 90 : false; |
| 91 return state; |
| 90 } | 92 } |
| 93 |
| 94 } // namespace security_state |
| OLD | NEW |