Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6529)

Unified Diff: chrome/browser/ssl/common_name_mismatch_handler.h

Issue 1223233002: Common Name Mismatch Handler For WWW Subdomain Mismatch case (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Resolving Comments Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ssl/common_name_mismatch_handler.h
diff --git a/chrome/browser/ssl/common_name_mismatch_handler.h b/chrome/browser/ssl/common_name_mismatch_handler.h
new file mode 100644
index 0000000000000000000000000000000000000000..01128efb44e6f9bb4c6c066cfb24b9efbc610c0a
--- /dev/null
+++ b/chrome/browser/ssl/common_name_mismatch_handler.h
@@ -0,0 +1,84 @@
+// Copyright (c) 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_SSL_COMMON_NAME_MISMATCH_HANDLER_H_
+#define CHROME_BROWSER_SSL_COMMON_NAME_MISMATCH_HANDLER_H_
+
+#include "base/basictypes.h"
+#include "base/callback.h"
+#include "base/compiler_specific.h"
+#include "base/memory/ref_counted.h"
+#include "base/memory/scoped_ptr.h"
+#include "base/threading/non_thread_safe.h"
+#include "base/time/time.h"
+#include "net/url_request/url_fetcher.h"
+#include "net/url_request/url_fetcher_delegate.h"
+#include "net/url_request/url_request_context_getter.h"
+#include "url/gurl.h"
+
+// This class contains methods to get a suggested URL when certificate
+// validation fails due to |ERR_CERT_COMMON_NAME_INVALID| and has methods to
+// perform a network request to check the validity of new URL.
+class CommonNameMismatchHandler : public net::URLFetcherDelegate,
+ public base::NonThreadSafe {
+ public:
+ enum SuggestedUrlCheckResult {
+ // The request succeeds with good response code i.e. URL exists and its
+ // certificate is valid.
+ RESULT_SUGGESTED_URL_VALID,
+ // Suggested URL is invalid
+ RESULT_SUGGESTED_URL_INVALID
+ };
+
+ struct Results {
+ Results() : result(RESULT_SUGGESTED_URL_INVALID) {}
+
+ SuggestedUrlCheckResult result;
+ GURL new_url;
+ };
+
+ typedef base::Callback<void(const Results& results)> CheckUrlCallback;
+
+ explicit CommonNameMismatchHandler(
+ const GURL request_url,
+ const scoped_refptr<net::URLRequestContextGetter>& request_context);
+ ~CommonNameMismatchHandler() override;
+
+ // Triggers a check to validate suggested URL. After completion, runs the
+ // |callback|.
+ void CheckSuggestedUrl(const GURL& url,
+ const CheckUrlCallback& callback);
+
+ // Returns true if any other DNS names in the certificate's subject
+ // alternative names list closely match the original request hostname.
+ // If such a domain name exists, writes a suggestion for a new URL
+ // to try into |suggested_url|.
+ static bool GetSuggestedUrl(const GURL& request_url,
+ const std::vector<std::string>& dns_names,
+ GURL* suggested_url);
+
+ private:
+ // net::URLFetcherDelegate:
+ void OnURLFetchComplete(const net::URLFetcher* source) override;
+
+ // Takes a |net::URLFetcher| that has finished trying to retrieve the
+ // suggested URL, and fills a |Results| struct based on its result.
+ void GetSuggestedUrlCheckResult(const net::URLFetcher* url_fetcher,
+ Results* results) const;
+
+ const GURL request_url_;
+
+ // Returns true if the check is currently running.
+ bool CheckingSuggestedUrl() const;
+
+ scoped_refptr<net::URLRequestContextGetter> request_context_;
+
+ CheckUrlCallback check_url_callback_;
+
+ scoped_ptr<net::URLFetcher> url_fetcher_;
+
+ DISALLOW_COPY_AND_ASSIGN(CommonNameMismatchHandler);
+};
+
+#endif // CHROME_BROWSER_SSL_COMMON_NAME_MISMATCH_HANDLER_H_

Powered by Google App Engine
This is Rietveld 408576698