 Chromium Code Reviews
 Chromium Code Reviews Issue 1696563002:
  Blimp: add support for SSL connections.  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@master
    
  
    Issue 1696563002:
  Blimp: add support for SSL connections.  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@master| OLD | NEW | 
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "blimp/client/session/assignment_source.h" | 5 #include "blimp/client/session/assignment_source.h" | 
| 6 | 6 | 
| 7 #include "base/bind.h" | 7 #include "base/bind.h" | 
| 8 #include "base/callback_helpers.h" | 8 #include "base/callback_helpers.h" | 
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" | 
| 10 #include "base/files/file_util.h" | |
| 10 #include "base/json/json_reader.h" | 11 #include "base/json/json_reader.h" | 
| 11 #include "base/json/json_writer.h" | 12 #include "base/json/json_writer.h" | 
| 12 #include "base/location.h" | 13 #include "base/location.h" | 
| 14 #include "base/memory/ref_counted.h" | |
| 13 #include "base/numerics/safe_conversions.h" | 15 #include "base/numerics/safe_conversions.h" | 
| 14 #include "base/strings/string_number_conversions.h" | 16 #include "base/strings/string_number_conversions.h" | 
| 17 #include "base/task_runner_util.h" | |
| 15 #include "base/values.h" | 18 #include "base/values.h" | 
| 16 #include "blimp/client/app/blimp_client_switches.h" | 19 #include "blimp/client/app/blimp_client_switches.h" | 
| 17 #include "blimp/common/protocol_version.h" | 20 #include "blimp/common/protocol_version.h" | 
| 18 #include "net/base/ip_address.h" | 21 #include "net/base/ip_address.h" | 
| 19 #include "net/base/ip_endpoint.h" | 22 #include "net/base/ip_endpoint.h" | 
| 20 #include "net/base/load_flags.h" | 23 #include "net/base/load_flags.h" | 
| 21 #include "net/base/net_errors.h" | 24 #include "net/base/net_errors.h" | 
| 22 #include "net/base/url_util.h" | 25 #include "net/base/url_util.h" | 
| 23 #include "net/http/http_status_code.h" | 26 #include "net/http/http_status_code.h" | 
| 24 #include "net/proxy/proxy_config_service.h" | 27 #include "net/proxy/proxy_config_service.h" | 
| 25 #include "net/proxy/proxy_service.h" | 28 #include "net/proxy/proxy_service.h" | 
| 26 #include "net/url_request/url_fetcher.h" | 29 #include "net/url_request/url_fetcher.h" | 
| 27 #include "net/url_request/url_request_context.h" | 30 #include "net/url_request/url_request_context.h" | 
| 28 #include "net/url_request/url_request_context_builder.h" | 31 #include "net/url_request/url_request_context_builder.h" | 
| 29 #include "net/url_request/url_request_context_getter.h" | 32 #include "net/url_request/url_request_context_getter.h" | 
| 30 | 33 | 
| 31 namespace blimp { | 34 namespace blimp { | 
| 32 namespace client { | 35 namespace client { | 
| 33 | 36 | 
| 34 namespace { | 37 namespace { | 
| 35 | 38 | 
| 36 // Assignment request JSON keys. | 39 // Assignment request JSON keys. | 
| 37 const char kProtocolVersionKey[] = "protocol_version"; | 40 const char kProtocolVersionKey[] = "protocol_version"; | 
| 38 | 41 | 
| 39 // Assignment response JSON keys. | 42 // Assignment response JSON keys. | 
| 40 const char kClientTokenKey[] = "clientToken"; | 43 const char kClientTokenKey[] = "clientToken"; | 
| 41 const char kHostKey[] = "host"; | 44 const char kHostKey[] = "host"; | 
| 42 const char kPortKey[] = "port"; | 45 const char kPortKey[] = "port"; | 
| 43 const char kCertificateFingerprintKey[] = "certificateFingerprint"; | |
| 44 const char kCertificateKey[] = "certificate"; | 46 const char kCertificateKey[] = "certificate"; | 
| 45 | 47 | 
| 46 // URL scheme constants for custom assignments. See the '--blimplet-endpoint' | 48 // URL scheme constants for custom assignments. See the '--blimplet-endpoint' | 
| 47 // documentation in blimp_client_switches.cc for details. | 49 // documentation in blimp_client_switches.cc for details. | 
| 48 const char kCustomSSLScheme[] = "ssl"; | 50 const char kCustomSSLScheme[] = "ssl"; | 
| 49 const char kCustomTCPScheme[] = "tcp"; | 51 const char kCustomTCPScheme[] = "tcp"; | 
| 50 const char kCustomQUICScheme[] = "quic"; | 52 const char kCustomQUICScheme[] = "quic"; | 
| 51 | 53 | 
| 52 Assignment GetCustomBlimpletAssignment() { | |
| 53 GURL url(base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | |
| 54 switches::kBlimpletEndpoint)); | |
| 55 | |
| 56 std::string host; | |
| 57 int port; | |
| 58 if (url.is_empty() || !url.is_valid() || !url.has_scheme() || | |
| 59 !net::ParseHostAndPort(url.path(), &host, &port)) { | |
| 60 return Assignment(); | |
| 61 } | |
| 62 | |
| 63 net::IPAddress ip_address; | |
| 64 if (!ip_address.AssignFromIPLiteral(host)) { | |
| 65 CHECK(false) << "Invalid BlimpletAssignment host " << host; | |
| 66 } | |
| 67 | |
| 68 if (!base::IsValueInRangeForNumericType<uint16_t>(port)) { | |
| 69 CHECK(false) << "Invalid BlimpletAssignment port " << port; | |
| 70 } | |
| 71 | |
| 72 Assignment::TransportProtocol protocol = | |
| 73 Assignment::TransportProtocol::UNKNOWN; | |
| 74 if (url.has_scheme()) { | |
| 75 if (url.SchemeIs(kCustomSSLScheme)) { | |
| 76 protocol = Assignment::TransportProtocol::SSL; | |
| 77 } else if (url.SchemeIs(kCustomTCPScheme)) { | |
| 78 protocol = Assignment::TransportProtocol::TCP; | |
| 79 } else if (url.SchemeIs(kCustomQUICScheme)) { | |
| 80 protocol = Assignment::TransportProtocol::QUIC; | |
| 81 } else { | |
| 82 CHECK(false) << "Invalid BlimpletAssignment scheme " << url.scheme(); | |
| 83 } | |
| 84 } | |
| 85 | |
| 86 Assignment assignment; | |
| 87 assignment.transport_protocol = protocol; | |
| 88 assignment.ip_endpoint = net::IPEndPoint(ip_address, port); | |
| 89 assignment.client_token = kDummyClientToken; | |
| 90 return assignment; | |
| 91 } | |
| 92 | |
| 93 GURL GetBlimpAssignerURL() { | 54 GURL GetBlimpAssignerURL() { | 
| 94 // TODO(dtrainor): Add a way to specify another assigner. | 55 // TODO(dtrainor): Add a way to specify another assigner. | 
| 95 return GURL(kDefaultAssignerURL); | 56 return GURL(kDefaultAssignerURL); | 
| 96 } | 57 } | 
| 97 | 58 | 
| 98 class SimpleURLRequestContextGetter : public net::URLRequestContextGetter { | 59 class SimpleURLRequestContextGetter : public net::URLRequestContextGetter { | 
| 99 public: | 60 public: | 
| 100 SimpleURLRequestContextGetter( | 61 SimpleURLRequestContextGetter( | 
| 101 const scoped_refptr<base::SingleThreadTaskRunner>& io_loop_task_runner) | 62 const scoped_refptr<base::SingleThreadTaskRunner>& io_loop_task_runner) | 
| 102 : io_loop_task_runner_(io_loop_task_runner), | 63 : io_loop_task_runner_(io_loop_task_runner), | 
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 141 Assignment::Assignment() : transport_protocol(TransportProtocol::UNKNOWN) {} | 102 Assignment::Assignment() : transport_protocol(TransportProtocol::UNKNOWN) {} | 
| 142 | 103 | 
| 143 Assignment::~Assignment() {} | 104 Assignment::~Assignment() {} | 
| 144 | 105 | 
| 145 bool Assignment::is_null() const { | 106 bool Assignment::is_null() const { | 
| 146 return ip_endpoint.address().empty() || ip_endpoint.port() == 0 || | 107 return ip_endpoint.address().empty() || ip_endpoint.port() == 0 || | 
| 147 transport_protocol == TransportProtocol::UNKNOWN; | 108 transport_protocol == TransportProtocol::UNKNOWN; | 
| 148 } | 109 } | 
| 149 | 110 | 
| 150 AssignmentSource::AssignmentSource( | 111 AssignmentSource::AssignmentSource( | 
| 151 const scoped_refptr<base::SingleThreadTaskRunner>& main_task_runner, | |
| 152 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner) | 112 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner) | 
| 153 : main_task_runner_(main_task_runner), | 113 : io_task_runner_(io_task_runner), | 
| 154 url_request_context_(new SimpleURLRequestContextGetter(io_task_runner)) {} | 114 url_request_context_(new SimpleURLRequestContextGetter(io_task_runner)), | 
| 115 file_reader_(new FileReader) {} | |
| 155 | 116 | 
| 156 AssignmentSource::~AssignmentSource() {} | 117 AssignmentSource::~AssignmentSource() {} | 
| 157 | 118 | 
| 158 void AssignmentSource::GetAssignment(const std::string& client_auth_token, | 119 void AssignmentSource::GetAssignment(const std::string& client_auth_token, | 
| 159 const AssignmentCallback& callback) { | 120 const AssignmentCallback& callback) { | 
| 160 DCHECK(main_task_runner_->BelongsToCurrentThread()); | |
| 161 | |
| 162 // Cancel any outstanding callback. | 121 // Cancel any outstanding callback. | 
| 163 if (!callback_.is_null()) { | 122 if (!callback_.is_null()) { | 
| 164 base::ResetAndReturn(&callback_) | 123 base::ResetAndReturn(&callback_) | 
| 165 .Run(AssignmentSource::Result::RESULT_SERVER_INTERRUPTED, Assignment()); | 124 .Run(AssignmentSource::Result::RESULT_SERVER_INTERRUPTED, Assignment()); | 
| 166 } | 125 } | 
| 167 callback_ = AssignmentCallback(callback); | 126 callback_ = AssignmentCallback(callback); | 
| 168 | 127 | 
| 169 Assignment assignment = GetCustomBlimpletAssignment(); | 128 // Try to get a custom assignment on the IO thread first. | 
| 170 if (!assignment.is_null()) { | 129 PostTaskAndReplyWithResult( | 
| 171 // Post the result so that the behavior of this function is consistent. | 130 io_task_runner_.get(), FROM_HERE, | 
| 172 main_task_runner_->PostTask( | 131 base::Bind(&AssignmentSource::GetCustomAssignment, | 
| 173 FROM_HERE, base::Bind(base::ResetAndReturn(&callback_), | 132 base::Unretained(this)), | 
| 174 AssignmentSource::Result::RESULT_OK, assignment)); | 133 base::Bind(&AssignmentSource::OnGetCustomAssignmentDone, | 
| 134 base::Unretained(this), client_auth_token)); | |
| 135 } | |
| 136 | |
| 137 scoped_ptr<Assignment> AssignmentSource::GetCustomAssignment() { | |
| 138 DCHECK(io_task_runner_->RunsTasksOnCurrentThread()); | |
| 
Ryan Sleevi
2016/02/23 00:49:45
It makes me deeply nervous to have an object that
 
Kevin M
2016/02/23 01:58:25
Made it an anonymous namespaced function and added
 | |
| 139 scoped_ptr<Assignment> assignment(new Assignment); | |
| 140 GURL url(base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | |
| 141 switches::kEngineEndpoint)); | |
| 142 | |
| 143 std::string host; | |
| 144 int port; | |
| 145 if (url.is_empty() || !url.is_valid() || !url.has_scheme() || | |
| 146 !net::ParseHostAndPort(url.path(), &host, &port)) { | |
| 147 return nullptr; | |
| 148 } | |
| 149 | |
| 150 net::IPAddress ip_address; | |
| 151 CHECK(ip_address.AssignFromIPLiteral(host)) << "Invalid Assignment host " | |
| 152 << host; | |
| 153 CHECK(port > 0 && port < 65535) << "Invalid IP port number: " << port; | |
| 
Ryan Sleevi
2016/02/23 00:49:45
Why do you check this, given url.is_valid()?
 
Kevin M
2016/02/23 01:58:25
Done.
 | |
| 154 | |
| 155 Assignment::TransportProtocol protocol = | |
| 156 Assignment::TransportProtocol::UNKNOWN; | |
| 157 if (url.has_scheme()) { | |
| 
Ryan Sleevi
2016/02/23 00:49:45
Why do you check this, given line 145?
 
Kevin M
2016/02/23 01:58:25
Done.
 | |
| 158 if (url.SchemeIs(kCustomSSLScheme)) { | |
| 159 protocol = Assignment::TransportProtocol::SSL; | |
| 160 } else if (url.SchemeIs(kCustomTCPScheme)) { | |
| 161 protocol = Assignment::TransportProtocol::TCP; | |
| 162 } else if (url.SchemeIs(kCustomQUICScheme)) { | |
| 163 protocol = Assignment::TransportProtocol::QUIC; | |
| 164 } else { | |
| 165 CHECK(false) << "Invalid engine protocol scheme " << url.scheme(); | |
| 166 } | |
| 167 } | |
| 168 | |
| 169 scoped_refptr<net::X509Certificate> cert; | |
| 170 if (protocol == Assignment::TransportProtocol::SSL || | |
| 171 protocol == Assignment::TransportProtocol::QUIC) { | |
| 172 base::FilePath cert_path = | |
| 173 base::CommandLine::ForCurrentProcess()->GetSwitchValuePath( | |
| 174 switches::kEngineCertPath); | |
| 175 CHECK(!cert_path.empty()) << "Missing required parameter --" | |
| 176 << switches::kEngineCertPath << "."; | |
| 177 std::string cert_str; | |
| 178 CHECK(file_reader_->ReadFileToString(cert_path, &cert_str)) | |
| 179 << "Couldn't read from file: " << cert_path.LossyDisplayName(); | |
| 180 net::CertificateList cert_list = | |
| 181 net::X509Certificate::CreateCertificateListFromBytes( | |
| 182 cert_str.data(), cert_str.size(), | |
| 183 net::X509Certificate::FORMAT_PEM_CERT_SEQUENCE); | |
| 184 CHECK_EQ(1u, cert_list.size()) | |
| 185 << "Only one cert is allowed in PEM cert list."; | |
| 186 cert = cert_list[0]; | |
| 187 } | |
| 188 | |
| 189 assignment->transport_protocol = protocol; | |
| 190 assignment->ip_endpoint = | |
| 191 net::IPEndPoint(ip_address, base::checked_cast<uint16_t>(port)); | |
| 
Ryan Sleevi
2016/02/23 00:49:45
Why do you do this, given line 153?
 
Kevin M
2016/02/23 01:58:25
In the previous patch you recommended using checke
 | |
| 192 assignment->client_token = kDummyClientToken; | |
| 193 assignment->cert = cert; | |
| 194 return assignment; | |
| 195 } | |
| 196 | |
| 197 void AssignmentSource::OnGetCustomAssignmentDone( | |
| 198 const std::string& client_auth_token, | |
| 199 scoped_ptr<Assignment> custom_assignment) { | |
| 200 // If GetCustomAssignment succeeded, then return the custom assignment | |
| 201 // directly. | |
| 202 if (custom_assignment && !custom_assignment->is_null()) { | |
| 203 base::ResetAndReturn(&callback_) | |
| 204 .Run(AssignmentSource::RESULT_OK, *custom_assignment); | |
| 
Ryan Sleevi
2016/02/23 00:49:45
The API contract for using a heap-allocated custom
 
Kevin M
2016/02/23 01:58:25
Done.
 | |
| 175 return; | 205 return; | 
| 176 } | 206 } | 
| 177 | 207 | 
| 178 // Call out to the network for a real assignment. Build the network request | 208 // Call out to the network for a real assignment. Build the network request | 
| 179 // to hit the assigner. | 209 // to hit the assigner. | 
| 180 url_fetcher_ = net::URLFetcher::Create(GetBlimpAssignerURL(), | 210 url_fetcher_ = net::URLFetcher::Create(GetBlimpAssignerURL(), | 
| 181 net::URLFetcher::POST, this); | 211 net::URLFetcher::POST, this); | 
| 182 url_fetcher_->SetRequestContext(url_request_context_.get()); | 212 url_fetcher_->SetRequestContext(url_request_context_.get()); | 
| 183 url_fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SAVE_COOKIES | | 213 url_fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SAVE_COOKIES | | 
| 184 net::LOAD_DO_NOT_SEND_COOKIES); | 214 net::LOAD_DO_NOT_SEND_COOKIES); | 
| 185 url_fetcher_->AddExtraRequestHeader("Authorization: Bearer " + | 215 url_fetcher_->AddExtraRequestHeader("Authorization: Bearer " + | 
| 186 client_auth_token); | 216 client_auth_token); | 
| 187 | 217 | 
| 188 // Write the JSON for the request data. | 218 // Write the JSON for the request data. | 
| 189 base::DictionaryValue dictionary; | 219 base::DictionaryValue dictionary; | 
| 190 dictionary.SetString(kProtocolVersionKey, blimp::kEngineVersion); | 220 dictionary.SetString(kProtocolVersionKey, blimp::kEngineVersion); | 
| 191 std::string json; | 221 std::string json; | 
| 192 base::JSONWriter::Write(dictionary, &json); | 222 base::JSONWriter::Write(dictionary, &json); | 
| 193 url_fetcher_->SetUploadData("application/json", json); | 223 url_fetcher_->SetUploadData("application/json", json); | 
| 194 | |
| 195 url_fetcher_->Start(); | 224 url_fetcher_->Start(); | 
| 196 } | 225 } | 
| 197 | 226 | 
| 227 void AssignmentSource::SetFileReaderForTest(scoped_ptr<FileReader> reader) { | |
| 228 file_reader_ = std::move(reader); | |
| 229 } | |
| 230 | |
| 198 void AssignmentSource::OnURLFetchComplete(const net::URLFetcher* source) { | 231 void AssignmentSource::OnURLFetchComplete(const net::URLFetcher* source) { | 
| 199 DCHECK(main_task_runner_->BelongsToCurrentThread()); | |
| 200 DCHECK(!callback_.is_null()); | 232 DCHECK(!callback_.is_null()); | 
| 201 DCHECK_EQ(url_fetcher_.get(), source); | 233 DCHECK_EQ(url_fetcher_.get(), source); | 
| 202 | 234 | 
| 203 if (!source->GetStatus().is_success()) { | 235 if (!source->GetStatus().is_success()) { | 
| 204 DVLOG(1) << "Assignment request failed due to network error: " | 236 DVLOG(1) << "Assignment request failed due to network error: " | 
| 205 << net::ErrorToString(source->GetStatus().error()); | 237 << net::ErrorToString(source->GetStatus().error()); | 
| 206 base::ResetAndReturn(&callback_) | 238 base::ResetAndReturn(&callback_) | 
| 207 .Run(AssignmentSource::Result::RESULT_NETWORK_FAILURE, Assignment()); | 239 .Run(AssignmentSource::Result::RESULT_NETWORK_FAILURE, Assignment()); | 
| 208 return; | 240 return; | 
| 209 } | 241 } | 
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 247 | 279 | 
| 248 // Grab the response from the assigner request. | 280 // Grab the response from the assigner request. | 
| 249 std::string response; | 281 std::string response; | 
| 250 if (!url_fetcher_->GetResponseAsString(&response)) { | 282 if (!url_fetcher_->GetResponseAsString(&response)) { | 
| 251 base::ResetAndReturn(&callback_) | 283 base::ResetAndReturn(&callback_) | 
| 252 .Run(AssignmentSource::Result::RESULT_BAD_RESPONSE, Assignment()); | 284 .Run(AssignmentSource::Result::RESULT_BAD_RESPONSE, Assignment()); | 
| 253 return; | 285 return; | 
| 254 } | 286 } | 
| 255 | 287 | 
| 256 // Attempt to interpret the response as JSON and treat it as a dictionary. | 288 // Attempt to interpret the response as JSON and treat it as a dictionary. | 
| 257 scoped_ptr<base::Value> json = base::JSONReader::Read(response); | 289 scoped_ptr<base::Value> json = base::JSONReader::Read(response); | 
| 
Ryan Sleevi
2016/02/23 00:49:45
SECURITY: In Chrome code, we never process JSON in
 
Kevin M
2016/02/23 01:58:25
Interesting. Is there a Codesearch link or a doc t
 
Kevin M
2016/02/23 20:38:15
Filed bug https://bugs.chromium.org/p/chromium/iss
 
David Trainor- moved to gerrit
2016/02/23 21:34:29
Hmm it looks like there are multiple instances of
 
Kevin M
2016/02/23 22:01:49
Issue is resolved. I modified the JSON parsing cod
 
Bernhard Bauer
2016/02/26 16:26:30
So, uh, I hate to be the bearer of bad news here,
 
Kevin M
2016/02/26 19:57:22
Is output from googleapis.com, as in this case, co
 | |
| 258 if (!json) { | 290 if (!json) { | 
| 259 base::ResetAndReturn(&callback_) | 291 base::ResetAndReturn(&callback_) | 
| 260 .Run(AssignmentSource::Result::RESULT_BAD_RESPONSE, Assignment()); | 292 .Run(AssignmentSource::Result::RESULT_BAD_RESPONSE, Assignment()); | 
| 261 return; | 293 return; | 
| 262 } | 294 } | 
| 263 | 295 | 
| 264 const base::DictionaryValue* dict; | 296 const base::DictionaryValue* dict; | 
| 265 if (!json->GetAsDictionary(&dict)) { | 297 if (!json->GetAsDictionary(&dict)) { | 
| 266 base::ResetAndReturn(&callback_) | 298 base::ResetAndReturn(&callback_) | 
| 267 .Run(AssignmentSource::Result::RESULT_BAD_RESPONSE, Assignment()); | 299 .Run(AssignmentSource::Result::RESULT_BAD_RESPONSE, Assignment()); | 
| 268 return; | 300 return; | 
| 269 } | 301 } | 
| 270 | 302 | 
| 271 // Validate that all the expected fields are present. | 303 // Validate that all the expected fields are present. | 
| 272 std::string client_token; | 304 std::string client_token; | 
| 273 std::string host; | 305 std::string host; | 
| 274 int port; | 306 int port; | 
| 275 std::string cert_fingerprint; | 307 std::string cert_str; | 
| 276 std::string cert; | |
| 277 if (!(dict->GetString(kClientTokenKey, &client_token) && | 308 if (!(dict->GetString(kClientTokenKey, &client_token) && | 
| 278 dict->GetString(kHostKey, &host) && dict->GetInteger(kPortKey, &port) && | 309 dict->GetString(kHostKey, &host) && dict->GetInteger(kPortKey, &port) && | 
| 279 dict->GetString(kCertificateFingerprintKey, &cert_fingerprint) && | 310 dict->GetString(kCertificateKey, &cert_str))) { | 
| 280 dict->GetString(kCertificateKey, &cert))) { | |
| 281 base::ResetAndReturn(&callback_) | 311 base::ResetAndReturn(&callback_) | 
| 282 .Run(AssignmentSource::Result::RESULT_BAD_RESPONSE, Assignment()); | 312 .Run(AssignmentSource::Result::RESULT_BAD_RESPONSE, Assignment()); | 
| 283 return; | 313 return; | 
| 284 } | 314 } | 
| 285 | 315 | 
| 286 net::IPAddress ip_address; | 316 net::IPAddress ip_address; | 
| 287 if (!ip_address.AssignFromIPLiteral(host)) { | 317 if (!ip_address.AssignFromIPLiteral(host)) { | 
| 288 base::ResetAndReturn(&callback_) | 318 base::ResetAndReturn(&callback_) | 
| 289 .Run(AssignmentSource::Result::RESULT_BAD_RESPONSE, Assignment()); | 319 .Run(AssignmentSource::Result::RESULT_BAD_RESPONSE, Assignment()); | 
| 290 return; | 320 return; | 
| 291 } | 321 } | 
| 292 | 322 | 
| 293 if (!base::IsValueInRangeForNumericType<uint16_t>(port)) { | 323 if (!base::IsValueInRangeForNumericType<uint16_t>(port)) { | 
| 
Ryan Sleevi
2016/02/23 00:49:45
Why do you soft-fail these errors, but CHECK on th
 
Kevin M
2016/02/23 01:58:25
This code handles responses received over the netw
 | |
| 294 base::ResetAndReturn(&callback_) | 324 base::ResetAndReturn(&callback_) | 
| 295 .Run(AssignmentSource::Result::RESULT_BAD_RESPONSE, Assignment()); | 325 .Run(AssignmentSource::Result::RESULT_BAD_RESPONSE, Assignment()); | 
| 296 return; | 326 return; | 
| 297 } | 327 } | 
| 298 | 328 | 
| 299 Assignment assignment; | 329 net::CertificateList cert_list = | 
| 330 net::X509Certificate::CreateCertificateListFromBytes( | |
| 331 cert_str.data(), cert_str.size(), | |
| 332 net::X509Certificate::FORMAT_PEM_CERT_SEQUENCE); | |
| 333 if (cert_list.size() != 1) { | |
| 334 base::ResetAndReturn(&callback_) | |
| 
Ryan Sleevi
2016/02/23 00:49:44
The heavy use of base::ResetAndReturn(...) makes m
 
Kevin M
2016/02/23 01:58:25
No, it's a safety practice my team has been using
 | |
| 335 .Run(AssignmentSource::Result::RESULT_INVALID_CERT, Assignment()); | |
| 336 return; | |
| 337 } | |
| 338 scoped_refptr<net::X509Certificate> cert = std::move(cert_list[0]); | |
| 
Ryan Sleevi
2016/02/23 00:49:45
Why do you std::move() here, only to copy-assign o
 
Kevin M
2016/02/23 01:58:25
:P Good point.
 | |
| 339 | |
| 300 // The assigner assumes SSL-only and all engines it assigns only communicate | 340 // The assigner assumes SSL-only and all engines it assigns only communicate | 
| 301 // over SSL. | 341 // over SSL. | 
| 342 Assignment assignment; | |
| 302 assignment.transport_protocol = Assignment::TransportProtocol::SSL; | 343 assignment.transport_protocol = Assignment::TransportProtocol::SSL; | 
| 303 assignment.ip_endpoint = net::IPEndPoint(ip_address, port); | 344 assignment.ip_endpoint = net::IPEndPoint(ip_address, port); | 
| 304 assignment.client_token = client_token; | 345 assignment.client_token = client_token; | 
| 305 assignment.certificate = cert; | 346 assignment.cert = cert; | 
| 306 assignment.certificate_fingerprint = cert_fingerprint; | |
| 307 | 347 | 
| 308 base::ResetAndReturn(&callback_) | 348 base::ResetAndReturn(&callback_) | 
| 309 .Run(AssignmentSource::Result::RESULT_OK, assignment); | 349 .Run(AssignmentSource::Result::RESULT_OK, assignment); | 
| 310 } | 350 } | 
| 311 | 351 | 
| 352 FileReader::FileReader() {} | |
| 353 | |
| 354 FileReader::~FileReader() {} | |
| 355 | |
| 356 bool FileReader::ReadFileToString(const base::FilePath& path, | |
| 357 std::string* output) { | |
| 358 return base::ReadFileToString(path, output); | |
| 359 } | |
| 360 | |
| 312 } // namespace client | 361 } // namespace client | 
| 313 } // namespace blimp | 362 } // namespace blimp | 
| OLD | NEW |