diff options
author | nharper <nharper@chromium.org> | 2016-01-25 15:54:14 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-01-25 23:55:18 +0000 |
commit | b7441ef2effe86324798710a82d8a006f5eb1395 (patch) | |
tree | bbc0a66b978a7d10640509cc3eb91dc3e8662303 /net/url_request | |
parent | 65295cfea49ef91053171841767163db073df1da (diff) | |
download | chromium_src-b7441ef2effe86324798710a82d8a006f5eb1395.zip chromium_src-b7441ef2effe86324798710a82d8a006f5eb1395.tar.gz chromium_src-b7441ef2effe86324798710a82d8a006f5eb1395.tar.bz2 |
Set Token-Binding HTTP header
Adds a new method to SSLClientSocket to get the Token Binding from an SSL
connection where Token Binding was negotiated, and uses that to add the
Set-Token-Binding HTTP header (only when Token Binding was negotiated).
BUG=467312
Review URL: https://codereview.chromium.org/1378613004
Cr-Commit-Position: refs/heads/master@{#371347}
Diffstat (limited to 'net/url_request')
-rw-r--r-- | net/url_request/url_request_http_job_unittest.cc | 6 | ||||
-rw-r--r-- | net/url_request/url_request_test_util.cc | 1 | ||||
-rw-r--r-- | net/url_request/url_request_unittest.cc | 206 |
3 files changed, 143 insertions, 70 deletions
diff --git a/net/url_request/url_request_http_job_unittest.cc b/net/url_request/url_request_http_job_unittest.cc index 5958487..dddfd8d 100644 --- a/net/url_request/url_request_http_job_unittest.cc +++ b/net/url_request/url_request_http_job_unittest.cc @@ -809,6 +809,12 @@ class FakeWebSocketHandshakeStream : public WebSocketHandshakeStreamBase { bool GetRemoteEndpoint(IPEndPoint* endpoint) override { return false; } + Error GetSignedEKMForTokenBinding(crypto::ECPrivateKey* key, + std::vector<uint8_t>* out) override { + ADD_FAILURE(); + return ERR_NOT_IMPLEMENTED; + } + void Drain(HttpNetworkSession* session) override {} void PopulateNetErrorDetails(NetErrorDetails* details) override { return; } diff --git a/net/url_request/url_request_test_util.cc b/net/url_request/url_request_test_util.cc index b3c03c7..60f0f36 100644 --- a/net/url_request/url_request_test_util.cc +++ b/net/url_request/url_request_test_util.cc @@ -111,6 +111,7 @@ void TestURLRequestContext::Init() { params.network_delegate = network_delegate(); params.http_server_properties = http_server_properties(); params.net_log = net_log(); + params.channel_id_service = channel_id_service(); context_storage_.set_http_network_session( make_scoped_ptr(new HttpNetworkSession(params))); context_storage_.set_http_transaction_factory(make_scoped_ptr( diff --git a/net/url_request/url_request_unittest.cc b/net/url_request/url_request_unittest.cc index d0e5d25..78e4eb3 100644 --- a/net/url_request/url_request_unittest.cc +++ b/net/url_request/url_request_unittest.cc @@ -16,6 +16,7 @@ #include <algorithm> #include <limits> +#include "base/base64url.h" #include "base/bind.h" #include "base/compiler_specific.h" #include "base/files/file_path.h" @@ -79,9 +80,12 @@ #include "net/log/test_net_log_util.h" #include "net/proxy/proxy_service.h" #include "net/socket/ssl_client_socket.h" +#include "net/ssl/channel_id_service.h" +#include "net/ssl/default_channel_id_store.h" #include "net/ssl/ssl_cipher_suite_names.h" #include "net/ssl/ssl_connection_status_flags.h" #include "net/ssl/ssl_server_config.h" +#include "net/ssl/token_binding.h" #include "net/test/cert_test_util.h" #include "net/test/embedded_test_server/embedded_test_server.h" #include "net/test/embedded_test_server/http_request.h" @@ -3370,7 +3374,113 @@ scoped_ptr<test_server::HttpResponse> HandleRedirectConnect( } // namespace -// In this unit test, we're using the EmbeddedTestServer as a proxy server and +class TestSSLConfigService : public SSLConfigService { + public: + TestSSLConfigService(bool ev_enabled, + bool online_rev_checking, + bool rev_checking_required_local_anchors, + bool token_binding_enabled) + : ev_enabled_(ev_enabled), + online_rev_checking_(online_rev_checking), + rev_checking_required_local_anchors_( + rev_checking_required_local_anchors), + token_binding_enabled_(token_binding_enabled), + min_version_(kDefaultSSLVersionMin), + fallback_min_version_(kDefaultSSLVersionFallbackMin) {} + + void set_min_version(uint16_t version) { min_version_ = version; } + + void set_fallback_min_version(uint16_t version) { + fallback_min_version_ = version; + } + + // SSLConfigService: + void GetSSLConfig(SSLConfig* config) override { + *config = SSLConfig(); + config->rev_checking_enabled = online_rev_checking_; + config->verify_ev_cert = ev_enabled_; + config->rev_checking_required_local_anchors = + rev_checking_required_local_anchors_; + if (fallback_min_version_) { + config->version_fallback_min = fallback_min_version_; + } + if (min_version_) { + config->version_min = min_version_; + } + if (token_binding_enabled_) { + config->token_binding_params.push_back(TB_PARAM_ECDSAP256); + } + } + + protected: + ~TestSSLConfigService() override {} + + private: + const bool ev_enabled_; + const bool online_rev_checking_; + const bool rev_checking_required_local_anchors_; + const bool token_binding_enabled_; + uint16_t min_version_; + uint16_t fallback_min_version_; +}; + +// TODO(svaldez): Update tests to use EmbeddedTestServer. +#if !defined(OS_IOS) +class TokenBindingURLRequestTest : public URLRequestTestHTTP { + public: + void SetUp() override { + default_context_.set_ssl_config_service( + new TestSSLConfigService(false, false, false, true)); + channel_id_service_.reset(new ChannelIDService( + new DefaultChannelIDStore(NULL), base::ThreadTaskRunnerHandle::Get())); + default_context_.set_channel_id_service(channel_id_service_.get()); + URLRequestTestHTTP::SetUp(); + } + + protected: + scoped_ptr<ChannelIDService> channel_id_service_; +}; + +TEST_F(TokenBindingURLRequestTest, TokenBindingTest) { + SpawnedTestServer::SSLOptions ssl_options; + ssl_options.supported_token_binding_params.push_back(TB_PARAM_ECDSAP256); + SpawnedTestServer https_test_server(SpawnedTestServer::TYPE_HTTPS, + ssl_options, + base::FilePath(kTestFilePath)); + ASSERT_TRUE(https_test_server.Start()); + + TestDelegate d; + { + scoped_ptr<URLRequest> r(default_context_.CreateRequest( + https_test_server.GetURL("tokbind-ekm"), DEFAULT_PRIORITY, &d)); + r->Start(); + EXPECT_TRUE(r->is_pending()); + + base::RunLoop().Run(); + + EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status()); + + HttpRequestHeaders headers; + std::string token_binding_header, token_binding_message; + EXPECT_TRUE(r->GetFullRequestHeaders(&headers)); + EXPECT_TRUE(headers.GetHeader(HttpRequestHeaders::kTokenBinding, + &token_binding_header)); + EXPECT_TRUE(base::Base64UrlDecode( + token_binding_header, base::Base64UrlDecodePolicy::REQUIRE_PADDING, + &token_binding_message)); + base::StringPiece ec_point, signature; + EXPECT_TRUE( + ParseTokenBindingMessage(token_binding_message, &ec_point, &signature)); + + EXPECT_GT(d.bytes_received(), 0); + std::string ekm = d.data_received(); + + EXPECT_TRUE(VerifyEKMSignature(ec_point, signature, ekm)); + } +} +#endif // !defined(OS_IOS) + +// In this unit test, we're using the HTTPTestServer as a proxy server and // issuing a CONNECT request with the magic host name "www.redirect.com". // The EmbeddedTestServer will return a 302 response, which we should not // follow. @@ -8528,61 +8638,17 @@ TEST_F(HTTPSRequestTest, DisableECDSAOnXP) { #endif // OS_WIN -class TestSSLConfigService : public SSLConfigService { - public: - TestSSLConfigService(bool ev_enabled, - bool online_rev_checking, - bool rev_checking_required_local_anchors) - : ev_enabled_(ev_enabled), - online_rev_checking_(online_rev_checking), - rev_checking_required_local_anchors_( - rev_checking_required_local_anchors), - min_version_(kDefaultSSLVersionMin), - fallback_min_version_(kDefaultSSLVersionFallbackMin) {} - - void set_min_version(uint16_t version) { min_version_ = version; } - - void set_fallback_min_version(uint16_t version) { - fallback_min_version_ = version; - } - - // SSLConfigService: - void GetSSLConfig(SSLConfig* config) override { - *config = SSLConfig(); - config->rev_checking_enabled = online_rev_checking_; - config->verify_ev_cert = ev_enabled_; - config->rev_checking_required_local_anchors = - rev_checking_required_local_anchors_; - if (fallback_min_version_) { - config->version_fallback_min = fallback_min_version_; - } - if (min_version_) { - config->version_min = min_version_; - } - } - - protected: - ~TestSSLConfigService() override {} - - private: - const bool ev_enabled_; - const bool online_rev_checking_; - const bool rev_checking_required_local_anchors_; - uint16_t min_version_; - uint16_t fallback_min_version_; -}; - class FallbackTestURLRequestContext : public TestURLRequestContext { public: explicit FallbackTestURLRequestContext(bool delay_initialization) : TestURLRequestContext(delay_initialization) {} void set_fallback_min_version(uint16_t version) { - TestSSLConfigService *ssl_config_service = - new TestSSLConfigService(true /* check for EV */, - false /* online revocation checking */, - false /* require rev. checking for local - anchors */); + TestSSLConfigService* ssl_config_service = new TestSSLConfigService( + true /* check for EV */, false /* online revocation checking */, + false /* require rev. checking for local + anchors */, + false /* token binding enabled */); ssl_config_service->set_fallback_min_version(version); set_ssl_config_service(ssl_config_service); } @@ -8957,11 +9023,11 @@ class HTTPSOCSPTest : public HTTPSRequestTest { // connetions to testserver. This can be overridden in test subclasses for // different behaviour. virtual void SetupContext(URLRequestContext* context) { - context->set_ssl_config_service( - new TestSSLConfigService(true /* check for EV */, - true /* online revocation checking */, - false /* require rev. checking for local - anchors */)); + context->set_ssl_config_service(new TestSSLConfigService( + true /* check for EV */, true /* online revocation checking */, + false /* require rev. checking for local + anchors */, + false /* token binding enabled */)); } scoped_ptr<ScopedTestRoot> test_root_; @@ -9152,11 +9218,11 @@ TEST_F(HTTPSOCSPTest, MAYBE_RevokedStapled) { class HTTPSHardFailTest : public HTTPSOCSPTest { protected: void SetupContext(URLRequestContext* context) override { - context->set_ssl_config_service( - new TestSSLConfigService(false /* check for EV */, - false /* online revocation checking */, - true /* require rev. checking for local - anchors */)); + context->set_ssl_config_service(new TestSSLConfigService( + false /* check for EV */, false /* online revocation checking */, + true /* require rev. checking for local + anchors */, + false /* token binding enabled */)); } }; @@ -9189,11 +9255,11 @@ TEST_F(HTTPSHardFailTest, FailsOnOCSPInvalid) { class HTTPSEVCRLSetTest : public HTTPSOCSPTest { protected: void SetupContext(URLRequestContext* context) override { - context->set_ssl_config_service( - new TestSSLConfigService(true /* check for EV */, - false /* online revocation checking */, - false /* require rev. checking for local - anchors */)); + context->set_ssl_config_service(new TestSSLConfigService( + true /* check for EV */, false /* online revocation checking */, + false /* require rev. checking for local + anchors */, + false /* token binding enabled */)); } }; @@ -9374,11 +9440,11 @@ TEST_F(HTTPSEVCRLSetTest, ExpiredCRLSetAndRevokedNonEVCert) { class HTTPSCRLSetTest : public HTTPSOCSPTest { protected: void SetupContext(URLRequestContext* context) override { - context->set_ssl_config_service( - new TestSSLConfigService(false /* check for EV */, - false /* online revocation checking */, - false /* require rev. checking for local - anchors */)); + context->set_ssl_config_service(new TestSSLConfigService( + false /* check for EV */, false /* online revocation checking */, + false /* require rev. checking for local + anchors */, + false /* token binding enabled */)); } }; |