Add enterprise policy for SSL error overriding
[chromium-blink-merge.git] / chrome / browser / ssl / ssl_blocking_page.h
blob36026b50a8d4104de64e43d768d936476891acc5
1 // Copyright (c) 2012 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.
5 #ifndef CHROME_BROWSER_SSL_SSL_BLOCKING_PAGE_H_
6 #define CHROME_BROWSER_SSL_SSL_BLOCKING_PAGE_H_
8 #include <string>
9 #include <vector>
11 #include "base/callback.h"
12 #include "base/strings/string16.h"
13 #include "base/task/cancelable_task_tracker.h"
14 #include "base/time/time.h"
15 #include "chrome/browser/interstitials/security_interstitial_page.h"
16 #include "chrome/browser/profiles/profile.h"
17 #include "chrome/browser/ssl/ssl_cert_reporter.h"
18 #include "net/ssl/ssl_info.h"
19 #include "url/gurl.h"
21 // Constants for the HTTPSErrorReporter Finch experiment
22 extern const char kHTTPSErrorReporterFinchExperimentName[];
23 extern const char kHTTPSErrorReporterFinchGroupShowPossiblySend[];
24 extern const char kHTTPSErrorReporterFinchGroupDontShowDontSend[];
25 extern const char kHTTPSErrorReporterFinchParamName[];
27 #if defined(ENABLE_EXTENSIONS)
28 namespace extensions {
29 class ExperienceSamplingEvent;
31 #endif
33 class SSLErrorClassification;
35 // This class is responsible for showing/hiding the interstitial page that is
36 // shown when a certificate error happens.
37 // It deletes itself when the interstitial page is closed.
38 class SSLBlockingPage : public SecurityInterstitialPage {
39 public:
40 enum SSLBlockingPageOptionsMask {
41 // Indicates whether or not the user could (assuming perfect knowledge)
42 // successfully override the error and still get the security guarantees
43 // of TLS.
44 OVERRIDABLE = 1 << 0,
45 // Indicates whether or not the site the user is trying to connect to has
46 // requested strict enforcement of certificate validation (e.g. with HTTP
47 // Strict-Transport-Security).
48 STRICT_ENFORCEMENT = 1 << 1,
49 // Indicates whether a user decision had been previously made but the
50 // decision has expired.
51 EXPIRED_BUT_PREVIOUSLY_ALLOWED = 1 << 2
54 // Interstitial type, used in tests.
55 static InterstitialPageDelegate::TypeID kTypeForTesting;
57 ~SSLBlockingPage() override;
59 // Creates an SSL blocking page. If the blocking page isn't shown, the caller
60 // is responsible for cleaning up the blocking page, otherwise the
61 // interstitial takes ownership when shown. |options_mask| must be a bitwise
62 // mask of SSLBlockingPageOptionsMask values.
63 SSLBlockingPage(content::WebContents* web_contents,
64 int cert_error,
65 const net::SSLInfo& ssl_info,
66 const GURL& request_url,
67 int options_mask,
68 const base::Time& time_triggered,
69 scoped_ptr<SSLCertReporter> ssl_cert_reporter,
70 const base::Callback<void(bool)>& callback);
72 // InterstitialPageDelegate method:
73 InterstitialPageDelegate::TypeID GetTypeForTesting() const override;
75 // Returns true if |options_mask| refers to an overridable SSL error and
76 // if SSL error overriding is allowed by policy.
77 static bool IsOverridable(int options_mask, const Profile* const profile);
79 void SetSSLCertReporterForTesting(
80 scoped_ptr<SSLCertReporter> ssl_cert_reporter);
82 protected:
83 // InterstitialPageDelegate implementation.
84 void CommandReceived(const std::string& command) override;
85 void OverrideEntry(content::NavigationEntry* entry) override;
86 void OverrideRendererPrefs(content::RendererPreferences* prefs) override;
87 void OnProceed() override;
88 void OnDontProceed() override;
90 // SecurityInterstitialPage implementation:
91 bool ShouldCreateNewNavigation() const override;
92 void PopulateInterstitialStrings(
93 base::DictionaryValue* load_time_data) override;
95 void PopulateExtendedReportingOption(base::DictionaryValue* load_time_data);
97 private:
98 void NotifyDenyCertificate();
99 void NotifyAllowCertificate();
101 std::string GetUmaHistogramPrefix() const;
102 std::string GetSamplingEventName() const;
104 // Send a report about an invalid certificate to the server.
105 void FinishCertCollection();
107 // Check whether a checkbox should be shown on the page that allows
108 // the user to opt in to Safe Browsing extended reporting.
109 bool ShouldShowCertificateReporterCheckbox();
111 // Returns true if an certificate report should be sent for the SSL
112 // error for this page.
113 bool ShouldReportCertificateError();
115 base::Callback<void(bool)> callback_;
117 const int cert_error_;
118 const net::SSLInfo ssl_info_;
119 // There are two ways for the user to override an interstitial:
121 // overridable_) By clicking on "Advanced" and then "Proceed".
122 // - This corresponds to "the user can override using the UI".
123 // danger_overridable_) By typing the word "danger".
124 // - This is an undocumented workaround.
125 // - This can be set to "false" dynamically to prevent the behaviour.
126 const bool overridable_;
127 bool danger_overridable_;
128 // Has the site requested strict enforcement of certificate errors?
129 const bool strict_enforcement_;
130 // Did the user previously allow a bad certificate but the decision has now
131 // expired?
132 const bool expired_but_previously_allowed_;
133 scoped_ptr<SSLErrorClassification> ssl_error_classification_;
135 // The time at which the interstitial was triggered. The interstitial
136 // calculates all times relative to this.
137 const base::Time time_triggered_;
139 // Handles reports of invalid SSL certificates.
140 scoped_ptr<SSLCertReporter> ssl_cert_reporter_;
142 // Which type of interstitial this is.
143 enum SSLInterstitialReason {
144 SSL_REASON_SSL,
145 SSL_REASON_BAD_CLOCK
146 } interstitial_reason_;
148 DISALLOW_COPY_AND_ASSIGN(SSLBlockingPage);
151 #endif // CHROME_BROWSER_SSL_SSL_BLOCKING_PAGE_H_