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" |
| 21 #include "components/safe_json/safe_json_parser.h" |
18 #include "net/base/ip_address.h" | 22 #include "net/base/ip_address.h" |
19 #include "net/base/ip_endpoint.h" | 23 #include "net/base/ip_endpoint.h" |
20 #include "net/base/load_flags.h" | 24 #include "net/base/load_flags.h" |
21 #include "net/base/net_errors.h" | 25 #include "net/base/net_errors.h" |
22 #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 // Possible arguments for the "--engine-transport" command line parameter. |
47 // documentation in blimp_client_switches.cc for details. | 49 const char kSSLTransportValue[] = "ssl"; |
48 const char kCustomSSLScheme[] = "ssl"; | 50 const char kTCPTransportValue[] = "tcp"; |
49 const char kCustomTCPScheme[] = "tcp"; | |
50 const char kCustomQUICScheme[] = "quic"; | |
51 | |
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 | 51 |
93 GURL GetBlimpAssignerURL() { | 52 GURL GetBlimpAssignerURL() { |
94 // TODO(dtrainor): Add a way to specify another assigner. | 53 // TODO(dtrainor): Add a way to specify another assigner. |
95 return GURL(kDefaultAssignerURL); | 54 return GURL(kDefaultAssignerURL); |
96 } | 55 } |
97 | 56 |
98 class SimpleURLRequestContextGetter : public net::URLRequestContextGetter { | 57 class SimpleURLRequestContextGetter : public net::URLRequestContextGetter { |
99 public: | 58 public: |
100 SimpleURLRequestContextGetter( | 59 SimpleURLRequestContextGetter( |
101 const scoped_refptr<base::SingleThreadTaskRunner>& io_loop_task_runner) | 60 scoped_refptr<base::SingleThreadTaskRunner> io_loop_task_runner) |
102 : io_loop_task_runner_(io_loop_task_runner), | 61 : io_loop_task_runner_(std::move(io_loop_task_runner)), |
103 proxy_config_service_(net::ProxyService::CreateSystemProxyConfigService( | 62 proxy_config_service_(net::ProxyService::CreateSystemProxyConfigService( |
104 io_loop_task_runner_, | 63 io_loop_task_runner_, |
105 io_loop_task_runner_)) {} | 64 io_loop_task_runner_)) {} |
106 | 65 |
107 // net::URLRequestContextGetter implementation. | 66 // net::URLRequestContextGetter implementation. |
108 net::URLRequestContext* GetURLRequestContext() override { | 67 net::URLRequestContext* GetURLRequestContext() override { |
109 if (!url_request_context_) { | 68 if (!url_request_context_) { |
110 net::URLRequestContextBuilder builder; | 69 net::URLRequestContextBuilder builder; |
111 builder.set_proxy_config_service(std::move(proxy_config_service_)); | 70 builder.set_proxy_config_service(std::move(proxy_config_service_)); |
112 builder.DisableHttpCache(); | 71 builder.DisableHttpCache(); |
(...skipping 16 matching lines...) Expand all Loading... |
129 | 88 |
130 // Temporary storage for the ProxyConfigService, which needs to be created on | 89 // Temporary storage for the ProxyConfigService, which needs to be created on |
131 // the main thread but cleared on the IO thread. This will be built in the | 90 // the main thread but cleared on the IO thread. This will be built in the |
132 // constructor and cleared on the IO thread. Due to the usage of this class | 91 // constructor and cleared on the IO thread. Due to the usage of this class |
133 // this is safe. | 92 // this is safe. |
134 scoped_ptr<net::ProxyConfigService> proxy_config_service_; | 93 scoped_ptr<net::ProxyConfigService> proxy_config_service_; |
135 | 94 |
136 DISALLOW_COPY_AND_ASSIGN(SimpleURLRequestContextGetter); | 95 DISALLOW_COPY_AND_ASSIGN(SimpleURLRequestContextGetter); |
137 }; | 96 }; |
138 | 97 |
| 98 bool IsValidIpPortNumber(unsigned port) { |
| 99 return port > 0 && port <= 65535; |
| 100 } |
| 101 |
| 102 // Populates an Assignment using command-line parameters, if provided. |
| 103 // Returns a null Assignment if no parameters were set. |
| 104 // Must be called on a thread suitable for file IO. |
| 105 Assignment GetAssignmentFromCommandLine() { |
| 106 Assignment assignment; |
| 107 assignment.client_token = kDummyClientToken; |
| 108 |
| 109 unsigned port_parsed = 0; |
| 110 if (!base::StringToUint( |
| 111 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| 112 switches::kEnginePort), |
| 113 &port_parsed) || |
| 114 !IsValidIpPortNumber(port_parsed)) { |
| 115 DLOG(FATAL) << "--engine-port must be a value between 1 and 65535."; |
| 116 return Assignment(); |
| 117 } |
| 118 |
| 119 net::IPAddress ip_address; |
| 120 std::string ip_str = |
| 121 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| 122 switches::kEngineIP); |
| 123 if (!ip_address.AssignFromIPLiteral(ip_str)) { |
| 124 DLOG(FATAL) << "Invalid engine IP " << ip_str; |
| 125 return Assignment(); |
| 126 } |
| 127 assignment.engine_endpoint = |
| 128 net::IPEndPoint(ip_address, base::checked_cast<uint16_t>(port_parsed)); |
| 129 |
| 130 std::string transport_str = |
| 131 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| 132 switches::kEngineTransport); |
| 133 if (transport_str == kSSLTransportValue) { |
| 134 assignment.transport_protocol = Assignment::TransportProtocol::SSL; |
| 135 } else if (transport_str == kTCPTransportValue) { |
| 136 assignment.transport_protocol = Assignment::TransportProtocol::TCP; |
| 137 } else { |
| 138 DLOG(FATAL) << "Invalid engine transport " << transport_str; |
| 139 return Assignment(); |
| 140 } |
| 141 |
| 142 scoped_refptr<net::X509Certificate> cert; |
| 143 if (assignment.transport_protocol == Assignment::TransportProtocol::SSL) { |
| 144 base::FilePath cert_path = |
| 145 base::CommandLine::ForCurrentProcess()->GetSwitchValuePath( |
| 146 switches::kEngineCertPath); |
| 147 if (cert_path.empty()) { |
| 148 DLOG(FATAL) << "Missing required parameter --" |
| 149 << switches::kEngineCertPath << "."; |
| 150 return Assignment(); |
| 151 } |
| 152 std::string cert_str; |
| 153 if (!base::ReadFileToString(cert_path, &cert_str)) { |
| 154 DLOG(FATAL) << "Couldn't read from file: " |
| 155 << cert_path.LossyDisplayName(); |
| 156 return Assignment(); |
| 157 } |
| 158 net::CertificateList cert_list = |
| 159 net::X509Certificate::CreateCertificateListFromBytes( |
| 160 cert_str.data(), cert_str.size(), |
| 161 net::X509Certificate::FORMAT_PEM_CERT_SEQUENCE); |
| 162 DLOG_IF(FATAL, (cert_list.size() != 1u)) |
| 163 << "Only one cert is allowed in PEM cert list."; |
| 164 assignment.cert = std::move(cert_list[0]); |
| 165 } |
| 166 |
| 167 if (!assignment.IsValid()) { |
| 168 DLOG(FATAL) << "Invalid command-line assignment."; |
| 169 return Assignment(); |
| 170 } |
| 171 |
| 172 return assignment; |
| 173 } |
| 174 |
139 } // namespace | 175 } // namespace |
140 | 176 |
141 Assignment::Assignment() : transport_protocol(TransportProtocol::UNKNOWN) {} | 177 Assignment::Assignment() : transport_protocol(TransportProtocol::UNKNOWN) {} |
142 | 178 |
143 Assignment::~Assignment() {} | 179 Assignment::~Assignment() {} |
144 | 180 |
145 bool Assignment::is_null() const { | 181 bool Assignment::IsValid() const { |
146 return ip_endpoint.address().empty() || ip_endpoint.port() == 0 || | 182 if (engine_endpoint.address().empty() || engine_endpoint.port() == 0 || |
147 transport_protocol == TransportProtocol::UNKNOWN; | 183 transport_protocol == TransportProtocol::UNKNOWN) { |
| 184 return false; |
| 185 } |
| 186 if (transport_protocol == TransportProtocol::SSL && !cert) { |
| 187 return false; |
| 188 } |
| 189 return true; |
148 } | 190 } |
149 | 191 |
150 AssignmentSource::AssignmentSource( | 192 AssignmentSource::AssignmentSource( |
151 const scoped_refptr<base::SingleThreadTaskRunner>& main_task_runner, | 193 const scoped_refptr<base::SingleThreadTaskRunner>& network_task_runner, |
152 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner) | 194 const scoped_refptr<base::SingleThreadTaskRunner>& file_task_runner) |
153 : main_task_runner_(main_task_runner), | 195 : file_task_runner_(std::move(file_task_runner)), |
154 url_request_context_(new SimpleURLRequestContextGetter(io_task_runner)) {} | 196 url_request_context_( |
| 197 new SimpleURLRequestContextGetter(network_task_runner)), |
| 198 weak_factory_(this) {} |
155 | 199 |
156 AssignmentSource::~AssignmentSource() {} | 200 AssignmentSource::~AssignmentSource() {} |
157 | 201 |
158 void AssignmentSource::GetAssignment(const std::string& client_auth_token, | 202 void AssignmentSource::GetAssignment(const std::string& client_auth_token, |
159 const AssignmentCallback& callback) { | 203 const AssignmentCallback& callback) { |
160 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 204 DCHECK(callback_.is_null()); |
161 | |
162 // Cancel any outstanding callback. | |
163 if (!callback_.is_null()) { | |
164 base::ResetAndReturn(&callback_) | |
165 .Run(AssignmentSource::Result::RESULT_SERVER_INTERRUPTED, Assignment()); | |
166 } | |
167 callback_ = AssignmentCallback(callback); | 205 callback_ = AssignmentCallback(callback); |
168 | 206 |
169 Assignment assignment = GetCustomBlimpletAssignment(); | 207 if (base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kEngineIP)) { |
170 if (!assignment.is_null()) { | 208 base::PostTaskAndReplyWithResult( |
171 // Post the result so that the behavior of this function is consistent. | 209 file_task_runner_.get(), FROM_HERE, |
172 main_task_runner_->PostTask( | 210 base::Bind(&GetAssignmentFromCommandLine), |
173 FROM_HERE, base::Bind(base::ResetAndReturn(&callback_), | 211 base::Bind(&AssignmentSource::OnGetAssignmentFromCommandLineDone, |
174 AssignmentSource::Result::RESULT_OK, assignment)); | 212 weak_factory_.GetWeakPtr(), client_auth_token)); |
| 213 } else { |
| 214 QueryAssigner(client_auth_token); |
| 215 } |
| 216 } |
| 217 |
| 218 void AssignmentSource::OnGetAssignmentFromCommandLineDone( |
| 219 const std::string& client_auth_token, |
| 220 Assignment parsed_assignment) { |
| 221 // If GetAssignmentFromCommandLine succeeded, then return its output. |
| 222 if (parsed_assignment.IsValid()) { |
| 223 base::ResetAndReturn(&callback_) |
| 224 .Run(AssignmentSource::RESULT_OK, parsed_assignment); |
175 return; | 225 return; |
176 } | 226 } |
177 | 227 |
| 228 // If no assignment was passed via the command line, then fall back on |
| 229 // querying the Assigner service. |
| 230 QueryAssigner(client_auth_token); |
| 231 } |
| 232 |
| 233 void AssignmentSource::QueryAssigner(const std::string& client_auth_token) { |
178 // Call out to the network for a real assignment. Build the network request | 234 // Call out to the network for a real assignment. Build the network request |
179 // to hit the assigner. | 235 // to hit the assigner. |
180 url_fetcher_ = net::URLFetcher::Create(GetBlimpAssignerURL(), | 236 url_fetcher_ = net::URLFetcher::Create(GetBlimpAssignerURL(), |
181 net::URLFetcher::POST, this); | 237 net::URLFetcher::POST, this); |
182 url_fetcher_->SetRequestContext(url_request_context_.get()); | 238 url_fetcher_->SetRequestContext(url_request_context_.get()); |
183 url_fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SAVE_COOKIES | | 239 url_fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SAVE_COOKIES | |
184 net::LOAD_DO_NOT_SEND_COOKIES); | 240 net::LOAD_DO_NOT_SEND_COOKIES); |
185 url_fetcher_->AddExtraRequestHeader("Authorization: Bearer " + | 241 url_fetcher_->AddExtraRequestHeader("Authorization: Bearer " + |
186 client_auth_token); | 242 client_auth_token); |
187 | 243 |
188 // Write the JSON for the request data. | 244 // Write the JSON for the request data. |
189 base::DictionaryValue dictionary; | 245 base::DictionaryValue dictionary; |
190 dictionary.SetString(kProtocolVersionKey, blimp::kEngineVersion); | 246 dictionary.SetString(kProtocolVersionKey, blimp::kEngineVersion); |
191 std::string json; | 247 std::string json; |
192 base::JSONWriter::Write(dictionary, &json); | 248 base::JSONWriter::Write(dictionary, &json); |
193 url_fetcher_->SetUploadData("application/json", json); | 249 url_fetcher_->SetUploadData("application/json", json); |
194 | |
195 url_fetcher_->Start(); | 250 url_fetcher_->Start(); |
196 } | 251 } |
197 | 252 |
198 void AssignmentSource::OnURLFetchComplete(const net::URLFetcher* source) { | 253 void AssignmentSource::OnURLFetchComplete(const net::URLFetcher* source) { |
199 DCHECK(main_task_runner_->BelongsToCurrentThread()); | |
200 DCHECK(!callback_.is_null()); | 254 DCHECK(!callback_.is_null()); |
201 DCHECK_EQ(url_fetcher_.get(), source); | 255 DCHECK_EQ(url_fetcher_.get(), source); |
202 | 256 |
203 if (!source->GetStatus().is_success()) { | 257 if (!source->GetStatus().is_success()) { |
204 DVLOG(1) << "Assignment request failed due to network error: " | 258 DVLOG(1) << "Assignment request failed due to network error: " |
205 << net::ErrorToString(source->GetStatus().error()); | 259 << net::ErrorToString(source->GetStatus().error()); |
206 base::ResetAndReturn(&callback_) | 260 base::ResetAndReturn(&callback_) |
207 .Run(AssignmentSource::Result::RESULT_NETWORK_FAILURE, Assignment()); | 261 .Run(AssignmentSource::Result::RESULT_NETWORK_FAILURE, Assignment()); |
208 return; | 262 return; |
209 } | 263 } |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
246 DCHECK_EQ(net::HTTP_OK, url_fetcher_->GetResponseCode()); | 300 DCHECK_EQ(net::HTTP_OK, url_fetcher_->GetResponseCode()); |
247 | 301 |
248 // Grab the response from the assigner request. | 302 // Grab the response from the assigner request. |
249 std::string response; | 303 std::string response; |
250 if (!url_fetcher_->GetResponseAsString(&response)) { | 304 if (!url_fetcher_->GetResponseAsString(&response)) { |
251 base::ResetAndReturn(&callback_) | 305 base::ResetAndReturn(&callback_) |
252 .Run(AssignmentSource::Result::RESULT_BAD_RESPONSE, Assignment()); | 306 .Run(AssignmentSource::Result::RESULT_BAD_RESPONSE, Assignment()); |
253 return; | 307 return; |
254 } | 308 } |
255 | 309 |
256 // Attempt to interpret the response as JSON and treat it as a dictionary. | 310 safe_json::SafeJsonParser::Parse( |
257 scoped_ptr<base::Value> json = base::JSONReader::Read(response); | 311 response, |
258 if (!json) { | 312 base::Bind(&AssignmentSource::OnJsonParsed, weak_factory_.GetWeakPtr()), |
259 base::ResetAndReturn(&callback_) | 313 base::Bind(&AssignmentSource::OnJsonParseError, |
260 .Run(AssignmentSource::Result::RESULT_BAD_RESPONSE, Assignment()); | 314 weak_factory_.GetWeakPtr())); |
261 return; | 315 } |
262 } | |
263 | 316 |
| 317 void AssignmentSource::OnJsonParsed(scoped_ptr<base::Value> json) { |
264 const base::DictionaryValue* dict; | 318 const base::DictionaryValue* dict; |
265 if (!json->GetAsDictionary(&dict)) { | 319 if (!json->GetAsDictionary(&dict)) { |
266 base::ResetAndReturn(&callback_) | 320 base::ResetAndReturn(&callback_) |
267 .Run(AssignmentSource::Result::RESULT_BAD_RESPONSE, Assignment()); | 321 .Run(AssignmentSource::Result::RESULT_BAD_RESPONSE, Assignment()); |
268 return; | 322 return; |
269 } | 323 } |
270 | 324 |
271 // Validate that all the expected fields are present. | 325 // Validate that all the expected fields are present. |
272 std::string client_token; | 326 std::string client_token; |
273 std::string host; | 327 std::string host; |
274 int port; | 328 int port; |
275 std::string cert_fingerprint; | 329 std::string cert_str; |
276 std::string cert; | |
277 if (!(dict->GetString(kClientTokenKey, &client_token) && | 330 if (!(dict->GetString(kClientTokenKey, &client_token) && |
278 dict->GetString(kHostKey, &host) && dict->GetInteger(kPortKey, &port) && | 331 dict->GetString(kHostKey, &host) && dict->GetInteger(kPortKey, &port) && |
279 dict->GetString(kCertificateFingerprintKey, &cert_fingerprint) && | 332 dict->GetString(kCertificateKey, &cert_str))) { |
280 dict->GetString(kCertificateKey, &cert))) { | |
281 base::ResetAndReturn(&callback_) | 333 base::ResetAndReturn(&callback_) |
282 .Run(AssignmentSource::Result::RESULT_BAD_RESPONSE, Assignment()); | 334 .Run(AssignmentSource::Result::RESULT_BAD_RESPONSE, Assignment()); |
283 return; | 335 return; |
284 } | 336 } |
285 | 337 |
286 net::IPAddress ip_address; | 338 net::IPAddress ip_address; |
287 if (!ip_address.AssignFromIPLiteral(host)) { | 339 if (!ip_address.AssignFromIPLiteral(host)) { |
288 base::ResetAndReturn(&callback_) | 340 base::ResetAndReturn(&callback_) |
289 .Run(AssignmentSource::Result::RESULT_BAD_RESPONSE, Assignment()); | 341 .Run(AssignmentSource::Result::RESULT_BAD_RESPONSE, Assignment()); |
290 return; | 342 return; |
291 } | 343 } |
292 | 344 |
293 if (!base::IsValueInRangeForNumericType<uint16_t>(port)) { | 345 if (!base::IsValueInRangeForNumericType<uint16_t>(port)) { |
294 base::ResetAndReturn(&callback_) | 346 base::ResetAndReturn(&callback_) |
295 .Run(AssignmentSource::Result::RESULT_BAD_RESPONSE, Assignment()); | 347 .Run(AssignmentSource::Result::RESULT_BAD_RESPONSE, Assignment()); |
296 return; | 348 return; |
297 } | 349 } |
298 | 350 |
299 Assignment assignment; | 351 net::CertificateList cert_list = |
| 352 net::X509Certificate::CreateCertificateListFromBytes( |
| 353 cert_str.data(), cert_str.size(), |
| 354 net::X509Certificate::FORMAT_PEM_CERT_SEQUENCE); |
| 355 if (cert_list.size() != 1) { |
| 356 base::ResetAndReturn(&callback_) |
| 357 .Run(AssignmentSource::Result::RESULT_INVALID_CERT, Assignment()); |
| 358 return; |
| 359 } |
| 360 |
300 // The assigner assumes SSL-only and all engines it assigns only communicate | 361 // The assigner assumes SSL-only and all engines it assigns only communicate |
301 // over SSL. | 362 // over SSL. |
| 363 Assignment assignment; |
302 assignment.transport_protocol = Assignment::TransportProtocol::SSL; | 364 assignment.transport_protocol = Assignment::TransportProtocol::SSL; |
303 assignment.ip_endpoint = net::IPEndPoint(ip_address, port); | 365 assignment.engine_endpoint = net::IPEndPoint(ip_address, port); |
304 assignment.client_token = client_token; | 366 assignment.client_token = client_token; |
305 assignment.certificate = cert; | 367 assignment.cert = std::move(cert_list[0]); |
306 assignment.certificate_fingerprint = cert_fingerprint; | |
307 | 368 |
308 base::ResetAndReturn(&callback_) | 369 base::ResetAndReturn(&callback_) |
309 .Run(AssignmentSource::Result::RESULT_OK, assignment); | 370 .Run(AssignmentSource::Result::RESULT_OK, assignment); |
310 } | 371 } |
311 | 372 |
| 373 void AssignmentSource::OnJsonParseError(const std::string& error) { |
| 374 DLOG(ERROR) << "Error while parsing assigner JSON: " << error; |
| 375 base::ResetAndReturn(&callback_) |
| 376 .Run(AssignmentSource::Result::RESULT_BAD_RESPONSE, Assignment()); |
| 377 } |
| 378 |
312 } // namespace client | 379 } // namespace client |
313 } // namespace blimp | 380 } // namespace blimp |
OLD | NEW |