Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "chrome/browser/chromeos/login/test/https_forwarder.h" | 5 #include "chrome/browser/chromeos/login/test/https_forwarder.h" |
| 6 | 6 |
| 7 #include <cstring> | 7 #include <cstring> |
| 8 | 8 |
| 9 #include "base/base_paths.h" | 9 #include "base/base_paths.h" |
| 10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/path_service.h" | 13 #include "base/path_service.h" |
| 14 #include "base/values.h" | 14 #include "base/values.h" |
| 15 #include "net/cert/test_root_certs.h" | 15 #include "net/cert/test_root_certs.h" |
| 16 #include "net/cert/x509_certificate.h" | 16 #include "net/cert/x509_certificate.h" |
| 17 #include "net/test/cert_test_util.h" | |
| 17 #include "net/test/python_utils.h" | 18 #include "net/test/python_utils.h" |
| 18 #include "net/test/spawned_test_server/base_test_server.h" | 19 #include "net/test/spawned_test_server/base_test_server.h" |
| 19 #include "net/test/spawned_test_server/local_test_server.h" | 20 #include "net/test/spawned_test_server/local_test_server.h" |
| 21 #include "net/test/test_data_directory.h" | |
| 20 #include "url/third_party/mozilla/url_parse.h" | 22 #include "url/third_party/mozilla/url_parse.h" |
| 21 #include "url/url_canon.h" | 23 #include "url/url_canon.h" |
| 22 | 24 |
| 23 namespace chromeos { | 25 namespace chromeos { |
| 24 | 26 |
| 25 namespace { | |
| 26 | |
| 27 // The root certificate used by net/tools/testserver/minica.py. | |
| 28 const char kMinicaRootCert[] = | |
| 29 "-----BEGIN CERTIFICATE-----\n" | |
| 30 "MIIB0TCCATqgAwIBAgIBATANBgkqhkiG9w0BAQUFADAVMRMwEQYDVQQDEwpUZXN0aW5nIENBMB" | |
| 31 "4XDTEwMDEwMTA2MDAwMFoXDTMyMTIwMTA2MDAwMFowFTETMBEGA1UEAxMKVGVzdGluZyBDQTCB" | |
| 32 "nTANBgkqhkiG9w0BAQEFAAOBiwAwgYcCgYEApxmY8pML/nPQMah/Ez0vN47u7tUqd+RND8n/bw" | |
| 33 "f/Msvz2pmd5O1lgyr8sIB/mHh1BlOdJYoM48LHeWdlMJmpA0qbEVqHbDmoxOTtSs0MZAlZRvs5" | |
| 34 "7utHoHBNuwGKz0jDocS4lfxAn7SjQKmGsa/EVRmrnspHwwGFx3HGSqXs8H0CAQOjMzAxMBIGA1" | |
| 35 "UdEwEB/wQIMAYBAf8CAQAwGwYDVR0gAQEABBEwDzANBgsrBgEEAdZ5AgHODzANBgkqhkiG9w0B" | |
| 36 "AQUFAAOBgQA/STb40A6D+93jMfLGQzXc997IsaJZdoPt7tYa8PqGJBL62EiTj+erd/H5pDZx/2" | |
| 37 "/bcpOG4m9J56ygwOohbllw2TM+oeEd8syzV6X+1SIPnGI56JRrm3UXcHYx1Rq5loM9WKAiz/Wm" | |
| 38 "IWmskljsEQ7+542pq0pkHjs8nuXovSkUYA==\n" | |
| 39 "-----END CERTIFICATE-----"; | |
| 40 | |
| 41 } // namespace | |
| 42 | |
| 43 // A net::LocalTestServer that handles the actual forwarding to another server. | 27 // A net::LocalTestServer that handles the actual forwarding to another server. |
| 44 // Requires that the root certificate used by minica.py be marked as trusted | 28 // Requires that the root certificate used by minica.py be marked as trusted |
| 45 // before it is used. | 29 // before it is used. |
| 46 class ForwardingServer : public net::LocalTestServer { | 30 class ForwardingServer : public net::LocalTestServer { |
| 47 public: | 31 public: |
| 48 ForwardingServer(const std::string& ssl_host, const GURL& forward_target); | 32 ForwardingServer(const std::string& ssl_host, const GURL& forward_target); |
| 49 | 33 |
| 50 // net::LocalTestServer: | 34 // net::LocalTestServer: |
| 51 bool SetPythonPath() const override; | 35 bool SetPythonPath() const override; |
| 52 bool GetTestServerPath(base::FilePath* testserver_path) const override; | 36 bool GetTestServerPath(base::FilePath* testserver_path) const override; |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 117 | 101 |
| 118 GURL HTTPSForwarder::GetURLForSSLHost(const std::string& path) const { | 102 GURL HTTPSForwarder::GetURLForSSLHost(const std::string& path) const { |
| 119 CHECK(forwarding_server_); | 103 CHECK(forwarding_server_); |
| 120 url::Replacements<char> replacements; | 104 url::Replacements<char> replacements; |
| 121 replacements.SetHost(ssl_host_.c_str(), url::Component(0, ssl_host_.size())); | 105 replacements.SetHost(ssl_host_.c_str(), url::Component(0, ssl_host_.size())); |
| 122 return forwarding_server_->GetURL(path).ReplaceComponents(replacements); | 106 return forwarding_server_->GetURL(path).ReplaceComponents(replacements); |
| 123 } | 107 } |
| 124 | 108 |
| 125 bool HTTPSForwarder::Initialize(const std::string& ssl_host, | 109 bool HTTPSForwarder::Initialize(const std::string& ssl_host, |
| 126 const GURL& forward_target) { | 110 const GURL& forward_target) { |
| 127 // Mark the root certificate used by minica.py as trusted. This will be used | 111 // Mark the root certificate used by minica.py as trusted. This will be used |
|
achuithb
2016/11/28 09:09:49
Please update this comment.
mattm
2016/11/28 22:35:49
Done.
| |
| 128 // by the Python part of the HTTPSForwarder to generate a certificate for | 112 // by the Python part of the HTTPSForwarder to generate a certificate for |
| 129 // |ssl_host_|. | 113 // |ssl_host_|. |
| 130 net::TestRootCerts* root_certs = net::TestRootCerts::GetInstance(); | 114 scoped_refptr<net::X509Certificate> root_cert = net::ImportCertFromFile( |
| 131 if (!root_certs) | 115 net::GetTestCertsDirectory(), "ocsp-test-root.pem"); |
| 116 if (!root_cert) | |
| 132 return false; | 117 return false; |
| 133 net::CertificateList certs = | 118 test_root_.reset(new net::ScopedTestRoot(root_cert.get())); |
| 134 net::X509Certificate::CreateCertificateListFromBytes( | |
| 135 kMinicaRootCert, strlen(kMinicaRootCert), | |
| 136 net::X509Certificate::FORMAT_AUTO); | |
| 137 if (certs.size() != 1) | |
| 138 return false; | |
| 139 root_certs->Add(certs.front().get()); | |
| 140 | 119 |
| 141 ssl_host_ = ssl_host; | 120 ssl_host_ = ssl_host; |
| 142 forwarding_server_.reset(new ForwardingServer(ssl_host, forward_target)); | 121 forwarding_server_.reset(new ForwardingServer(ssl_host, forward_target)); |
| 143 return forwarding_server_->Start(); | 122 return forwarding_server_->Start(); |
| 144 } | 123 } |
| 145 | 124 |
| 146 } // namespace chromeos | 125 } // namespace chromeos |
| OLD | NEW |