summaryrefslogtreecommitdiffstats
path: root/chrome/browser/ssl
diff options
context:
space:
mode:
authorabarth@chromium.org <abarth@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-03-17 18:56:42 +0000
committerabarth@chromium.org <abarth@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-03-17 18:56:42 +0000
commit425210cc4509d0339664eb142c3ae86500407bb1 (patch)
treeb04e954baa813d3cf40c11baa3642a44f4de8e30 /chrome/browser/ssl
parent93edf7352b4c0500d1561ab0a56034d226ead456 (diff)
downloadchromium_src-425210cc4509d0339664eb142c3ae86500407bb1.zip
chromium_src-425210cc4509d0339664eb142c3ae86500407bb1.tar.gz
chromium_src-425210cc4509d0339664eb142c3ae86500407bb1.tar.bz2
SSLPolicy Fix: Step 7.
Simplify SSLPolicy to prepare for changing its algorithm. This change should not change the SSLPolicy behavior at all. R=jcampan BUG=8706 Review URL: http://codereview.chromium.org/48060 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@11892 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/ssl')
-rw-r--r--chrome/browser/ssl/ssl_policy.cc333
-rw-r--r--chrome/browser/ssl/ssl_policy.h33
2 files changed, 103 insertions, 263 deletions
diff --git a/chrome/browser/ssl/ssl_policy.cc b/chrome/browser/ssl/ssl_policy.cc
index 599f45c..66e0ba2 100644
--- a/chrome/browser/ssl/ssl_policy.cc
+++ b/chrome/browser/ssl/ssl_policy.cc
@@ -38,8 +38,6 @@
// Wrap all these helper classes in an anonymous namespace.
namespace {
-static const char kDot = '.';
-
class ShowUnsafeContentTask : public Task {
public:
ShowUnsafeContentTask(const GURL& main_frame_url,
@@ -116,261 +114,108 @@ static void ShowBlockingPage(SSLPolicy* policy, SSLManager::CertError* error) {
blocking_page->Show();
}
-#if 0
-// See TODO(jcampan) below.
-static bool IsIntranetHost(const std::string& host) {
- const size_t dot = host.find(kDot);
- return dot == std::string::npos || dot == host.length() - 1;
-}
-#endif
-
-class CommonNameInvalidPolicy : public SSLPolicy {
- public:
- static SSLPolicy* GetInstance() {
- return Singleton<CommonNameInvalidPolicy>::get();
- }
-
- void OnCertError(const GURL& main_frame_url,
- SSLManager::CertError* error) {
- OnOverridableCertError(main_frame_url, error);
- }
-};
-
-class DateInvalidPolicy : public SSLPolicy {
- public:
- static SSLPolicy* GetInstance() {
- return Singleton<DateInvalidPolicy>::get();
- }
-
- void OnCertError(const GURL& main_frame_url,
- SSLManager::CertError* error) {
- OnOverridableCertError(main_frame_url, error);
- }
-};
-
-class AuthorityInvalidPolicy : public SSLPolicy {
- public:
- static SSLPolicy* GetInstance() {
- return Singleton<AuthorityInvalidPolicy>::get();
- }
-
- void OnCertError(const GURL& main_frame_url,
- SSLManager::CertError* error) {
- OnOverridableCertError(main_frame_url, error);
- }
-};
-
-class ContainsErrorsPolicy : public SSLPolicy {
- public:
- static SSLPolicy* GetInstance() {
- return Singleton<ContainsErrorsPolicy>::get();
- }
-
- void OnCertError(const GURL& main_frame_url,
- SSLManager::CertError* error) {
- OnFatalCertError(main_frame_url, error);
- }
-};
+} // namespace
-class NoRevocationMechanismPolicy : public SSLPolicy {
- public:
- static SSLPolicy* GetInstance() {
- return Singleton<NoRevocationMechanismPolicy>::get();
- }
+SSLPolicy::SSLPolicy() {
+}
- void OnCertError(const GURL& main_frame_url,
- SSLManager::CertError* error) {
- // Silently ignore this error.
- error->ContinueRequest();
- }
-};
+SSLPolicy* SSLPolicy::GetDefaultPolicy() {
+ return Singleton<SSLPolicy>::get();
+}
-class UnableToCheckRevocationPolicy : public SSLPolicy {
- public:
- static SSLPolicy* GetInstance() {
- return Singleton<UnableToCheckRevocationPolicy>::get();
- }
+void SSLPolicy::OnCertError(const GURL& main_frame_url,
+ SSLManager::CertError* error) {
+ // First we check if we know the policy for this error.
+ net::X509Certificate::Policy::Judgment judgment =
+ error->manager()->QueryPolicy(error->ssl_info().cert,
+ error->request_url().host());
- void OnCertError(const GURL& main_frame_url,
- SSLManager::CertError* error) {
- // We ignore this error and display an info-bar.
+ if (judgment == net::X509Certificate::Policy::ALLOWED) {
+ // We've been told to allow this certificate.
+ if (error->manager()->SetMaxSecurityStyle(
+ SECURITY_STYLE_AUTHENTICATION_BROKEN)) {
+ NotificationService::current()->Notify(
+ NotificationType::SSL_VISIBLE_STATE_CHANGED,
+ Source<NavigationController>(error->manager()->controller()),
+ Details<NavigationEntry>(
+ error->manager()->controller()->GetActiveEntry()));
+ }
error->ContinueRequest();
- error->manager()->ShowMessage(l10n_util::GetString(
- IDS_CERT_ERROR_UNABLE_TO_CHECK_REVOCATION_INFO_BAR));
- }
-};
-
-class RevokedPolicy : public SSLPolicy {
- public:
- static SSLPolicy* GetInstance() {
- return Singleton<RevokedPolicy>::get();
- }
-
- void OnCertError(const GURL& main_frame_url,
- SSLManager::CertError* error) {
- OnFatalCertError(main_frame_url, error);
- }
-};
-
-class InvalidPolicy : public SSLPolicy {
- public:
- static SSLPolicy* GetInstance() {
- return Singleton<InvalidPolicy>::get();
- }
-
- void OnCertError(const GURL& main_frame_url,
- SSLManager::CertError* error) {
- OnFatalCertError(main_frame_url, error);
- }
-};
-
-class DefaultPolicy : public SSLPolicy {
- public:
- DefaultPolicy() {
- // Load our helper classes to handle various cert errors.
- DCHECK(SubPolicyIndex(net::ERR_CERT_COMMON_NAME_INVALID) == 0);
- sub_policies_[0] = CommonNameInvalidPolicy::GetInstance();
- DCHECK(SubPolicyIndex(net::ERR_CERT_DATE_INVALID) == 1);
- sub_policies_[1] = DateInvalidPolicy::GetInstance();
- DCHECK(SubPolicyIndex(net::ERR_CERT_AUTHORITY_INVALID) == 2);
- sub_policies_[2] = AuthorityInvalidPolicy::GetInstance();
- DCHECK(SubPolicyIndex(net::ERR_CERT_CONTAINS_ERRORS) == 3);
- sub_policies_[3] = ContainsErrorsPolicy::GetInstance();
- DCHECK(SubPolicyIndex(net::ERR_CERT_NO_REVOCATION_MECHANISM) == 4);
- sub_policies_[4] = NoRevocationMechanismPolicy::GetInstance();
- DCHECK(SubPolicyIndex(net::ERR_CERT_UNABLE_TO_CHECK_REVOCATION) == 5);
- sub_policies_[5] = UnableToCheckRevocationPolicy::GetInstance();
- DCHECK(SubPolicyIndex(net::ERR_CERT_REVOKED) == 6);
- sub_policies_[6] = RevokedPolicy::GetInstance();
- DCHECK(SubPolicyIndex(net::ERR_CERT_INVALID) == 7);
- sub_policies_[7] = InvalidPolicy::GetInstance();
- DCHECK(SubPolicyIndex(net::ERR_CERT_END) == 8);
+ return;
}
- void OnCertError(const GURL& main_frame_url,
- SSLManager::CertError* error) {
- size_t index = SubPolicyIndex(error->cert_error());
- if (index < 0 || index >= arraysize(sub_policies_)) {
+ // The judgment is either DENIED or UNKNOWN.
+ // For now we handle the DENIED as the UNKNOWN, which means a blocking
+ // page is shown to the user every time he comes back to the page.
+
+ switch(error->cert_error()) {
+ case net::ERR_CERT_COMMON_NAME_INVALID:
+ case net::ERR_CERT_DATE_INVALID:
+ case net::ERR_CERT_AUTHORITY_INVALID:
+ OnOverridableCertError(main_frame_url, error);
+ break;
+ case net::ERR_CERT_NO_REVOCATION_MECHANISM:
+ // Ignore this error.
+ error->ContinueRequest();
+ break;
+ case net::ERR_CERT_UNABLE_TO_CHECK_REVOCATION:
+ // We ignore this error and display an infobar.
+ error->ContinueRequest();
+ error->manager()->ShowMessage(l10n_util::GetString(
+ IDS_CERT_ERROR_UNABLE_TO_CHECK_REVOCATION_INFO_BAR));
+ break;
+ case net::ERR_CERT_CONTAINS_ERRORS:
+ case net::ERR_CERT_REVOKED:
+ case net::ERR_CERT_INVALID:
+ OnFatalCertError(main_frame_url, error);
+ break;
+ default:
NOTREACHED();
error->CancelRequest();
- return;
- }
-
- // First we check if we know the policy for this error.
- net::X509Certificate::Policy::Judgment judgment =
- error->manager()->QueryPolicy(error->ssl_info().cert,
- error->request_url().host());
-
- switch (judgment) {
- case net::X509Certificate::Policy::ALLOWED:
- // We've been told to allow this certificate.
- if (error->manager()->SetMaxSecurityStyle(
- SECURITY_STYLE_AUTHENTICATION_BROKEN)) {
- NotificationService::current()->Notify(
- NotificationType::SSL_VISIBLE_STATE_CHANGED,
- Source<NavigationController>(error->manager()->controller()),
- Details<NavigationEntry>(
- error->manager()->controller()->GetActiveEntry()));
- }
- error->ContinueRequest();
- break;
- case net::X509Certificate::Policy::DENIED:
- // For now we handle the DENIED as the UNKNOWN, which means a blocking
- // page is shown to the user every time he comes back to the page.
- case net::X509Certificate::Policy::UNKNOWN:
- // We don't know how to handle this error. Ask our sub-policies.
- sub_policies_[index]->OnCertError(main_frame_url, error);
- break;
- default:
- NOTREACHED();
- }
- }
-
- void OnMixedContent(NavigationController* navigation_controller,
- const GURL& main_frame_url,
- SSLManager::MixedContentHandler* mixed_content_handler) {
- PrefService* prefs = navigation_controller->profile()->GetPrefs();
- FilterPolicy::Type filter_policy = FilterPolicy::DONT_FILTER;
- if (!mixed_content_handler->manager()->
- CanShowInsecureContent(main_frame_url)) {
- filter_policy = FilterPolicy::FromInt(
- prefs->GetInteger(prefs::kMixedContentFiltering));
- }
- if (filter_policy != FilterPolicy::DONT_FILTER) {
- mixed_content_handler->manager()->ShowMessageWithLink(
- l10n_util::GetString(IDS_SSL_INFO_BAR_FILTERED_CONTENT),
- l10n_util::GetString(IDS_SSL_INFO_BAR_SHOW_CONTENT),
- new ShowUnsafeContentTask(main_frame_url, mixed_content_handler));
- }
- mixed_content_handler->StartRequest(filter_policy);
-
- NavigationEntry* entry = navigation_controller->GetLastCommittedEntry();
- DCHECK(entry);
- // Even though we are loading the mixed-content resource, it will not be
- // included in the page when we set the policy to FILTER_ALL or
- // FILTER_ALL_EXCEPT_IMAGES (only images and they are stamped with warning
- // icons), so we don't set the mixed-content mode in these cases.
- if (filter_policy == FilterPolicy::DONT_FILTER)
- entry->ssl().set_has_mixed_content();
-
- // Print a message indicating the mixed-contents resource in the console.
- const std::wstring& msg = l10n_util::GetStringF(
- IDS_MIXED_CONTENT_LOG_MESSAGE,
- UTF8ToWide(entry->url().spec()),
- UTF8ToWide(mixed_content_handler->request_url().spec()));
- mixed_content_handler->manager()->
- AddMessageToConsole(msg, MESSAGE_LEVEL_WARNING);
-
- NotificationService::current()->Notify(
- NotificationType::SSL_VISIBLE_STATE_CHANGED,
- Source<NavigationController>(navigation_controller),
- Details<NavigationEntry>(entry));
- }
-
- void OnDenyCertificate(SSLManager::CertError* error) {
- size_t index = SubPolicyIndex(error->cert_error());
- if (index < 0 || index >= arraysize(sub_policies_)) {
- NOTREACHED();
- return;
- }
- sub_policies_[index]->OnDenyCertificate(error);
+ break;
}
+}
- void OnAllowCertificate(SSLManager::CertError* error) {
- size_t index = SubPolicyIndex(error->cert_error());
- if (index < 0 || index >= arraysize(sub_policies_)) {
- NOTREACHED();
- return;
- }
- sub_policies_[index]->OnAllowCertificate(error);
+void SSLPolicy::OnMixedContent(
+ NavigationController* navigation_controller,
+ const GURL& main_frame_url,
+ SSLManager::MixedContentHandler* mixed_content_handler) {
+ PrefService* prefs = navigation_controller->profile()->GetPrefs();
+ FilterPolicy::Type filter_policy = FilterPolicy::DONT_FILTER;
+ if (!mixed_content_handler->manager()->
+ CanShowInsecureContent(main_frame_url)) {
+ filter_policy = FilterPolicy::FromInt(
+ prefs->GetInteger(prefs::kMixedContentFiltering));
}
-
- private:
- // Returns the index of the sub-policy for |cert_error| in the
- // sub_policies_ array.
- int SubPolicyIndex(int cert_error) {
- // Certificate errors are negative integers from net::ERR_CERT_BEGIN
- // (inclusive) to net::ERR_CERT_END (exclusive) in *decreasing* order.
- return net::ERR_CERT_BEGIN - cert_error;
+ if (filter_policy != FilterPolicy::DONT_FILTER) {
+ mixed_content_handler->manager()->ShowMessageWithLink(
+ l10n_util::GetString(IDS_SSL_INFO_BAR_FILTERED_CONTENT),
+ l10n_util::GetString(IDS_SSL_INFO_BAR_SHOW_CONTENT),
+ new ShowUnsafeContentTask(main_frame_url, mixed_content_handler));
}
- SSLPolicy* sub_policies_[net::ERR_CERT_BEGIN - net::ERR_CERT_END];
-};
-
-} // namespace
-
-SSLPolicy* SSLPolicy::GetDefaultPolicy() {
- // Lazily initialize our default policy instance.
- static SSLPolicy* default_policy = new DefaultPolicy();
- return default_policy;
-}
-
-SSLPolicy::SSLPolicy() {
-}
-
-void SSLPolicy::OnCertError(const GURL& main_frame_url,
- SSLManager::CertError* error) {
- // Default to secure behavior.
- error->CancelRequest();
+ mixed_content_handler->StartRequest(filter_policy);
+
+ NavigationEntry* entry = navigation_controller->GetLastCommittedEntry();
+ DCHECK(entry);
+ // Even though we are loading the mixed-content resource, it will not be
+ // included in the page when we set the policy to FILTER_ALL or
+ // FILTER_ALL_EXCEPT_IMAGES (only images and they are stamped with warning
+ // icons), so we don't set the mixed-content mode in these cases.
+ if (filter_policy == FilterPolicy::DONT_FILTER)
+ entry->ssl().set_has_mixed_content();
+
+ // Print a message indicating the mixed-contents resource in the console.
+ const std::wstring& msg = l10n_util::GetStringF(
+ IDS_MIXED_CONTENT_LOG_MESSAGE,
+ UTF8ToWide(entry->url().spec()),
+ UTF8ToWide(mixed_content_handler->request_url().spec()));
+ mixed_content_handler->manager()->
+ AddMessageToConsole(msg, MESSAGE_LEVEL_WARNING);
+
+ NotificationService::current()->Notify(
+ NotificationType::SSL_VISIBLE_STATE_CHANGED,
+ Source<NavigationController>(navigation_controller),
+ Details<NavigationEntry>(entry));
}
void SSLPolicy::OnRequestStarted(SSLManager* manager, const GURL& url,
diff --git a/chrome/browser/ssl/ssl_policy.h b/chrome/browser/ssl/ssl_policy.h
index 9318143..b7edea5 100644
--- a/chrome/browser/ssl/ssl_policy.h
+++ b/chrome/browser/ssl/ssl_policy.h
@@ -2,24 +2,23 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef CHROME_BROWSER_SSL_POLICY_H__
-#define CHROME_BROWSER_SSL_POLICY_H__
+#ifndef CHROME_BROWSER_SSL_POLICY_H_
+#define CHROME_BROWSER_SSL_POLICY_H_
+#include "base/singleton.h"
#include "chrome/browser/ssl/ssl_blocking_page.h"
#include "chrome/browser/ssl/ssl_manager.h"
-// The basic SSLPolicy. This class contains default implementations of all
-// the SSLPolicy entry points. It is expected that subclasses will override
-// most of these methods to implement policy specific to certain errors or
-// situations.
+// SSLPolicy
+//
+// This class is responsible for making the security decisions that concern the
+// SSL trust indicators. It relies on the SSLManager to actually enact the
+// decisions it reaches.
+//
class SSLPolicy : public SSLManager::Delegate,
public SSLBlockingPage::Delegate {
public:
// Factory method to get the default policy.
- //
- // SSLPolicy is not meant to be instantiated itself. Only subclasses should
- // be instantiated. The default policy has more complex behavior than a
- // direct instance of SSLPolicy.
static SSLPolicy* GetDefaultPolicy();
// SSLManager::Delegate methods.
@@ -28,12 +27,7 @@ class SSLPolicy : public SSLManager::Delegate,
virtual void OnMixedContent(
NavigationController* navigation_controller,
const GURL& main_frame_url,
- SSLManager::MixedContentHandler* mixed_content_handler) {
- // So far only the default policy is expected to receive mixed-content
- // calls.
- NOTREACHED();
- }
-
+ SSLManager::MixedContentHandler* mixed_content_handler);
virtual void OnRequestStarted(SSLManager* manager,
const GURL& url,
ResourceType::Type resource_type,
@@ -53,8 +47,9 @@ class SSLPolicy : public SSLManager::Delegate,
virtual void OnAllowCertificate(SSLManager::CertError* error);
protected:
- // Allow our subclasses to construct us.
+ // Construct via |GetDefaultPolicy|.
SSLPolicy();
+ friend struct DefaultSingletonTraits<SSLPolicy>;
// Helper method for derived classes handling certificate errors that can be
// overridden by the user.
@@ -68,7 +63,7 @@ class SSLPolicy : public SSLManager::Delegate,
SSLManager::CertError* error);
private:
- DISALLOW_EVIL_CONSTRUCTORS(SSLPolicy);
+ DISALLOW_COPY_AND_ASSIGN(SSLPolicy);
};
-#endif // CHROME_BROWSER_SSL_POLICY_H__
+#endif // CHROME_BROWSER_SSL_POLICY_H_