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" | |
11 #include "base/json/json_reader.h" | 10 #include "base/json/json_reader.h" |
12 #include "base/json/json_writer.h" | 11 #include "base/json/json_writer.h" |
13 #include "base/location.h" | 12 #include "base/location.h" |
14 #include "base/memory/ref_counted.h" | |
15 #include "base/numerics/safe_conversions.h" | 13 #include "base/numerics/safe_conversions.h" |
16 #include "base/strings/string_number_conversions.h" | 14 #include "base/strings/string_number_conversions.h" |
17 #include "base/task_runner_util.h" | |
18 #include "base/values.h" | 15 #include "base/values.h" |
19 #include "blimp/client/app/blimp_client_switches.h" | 16 #include "blimp/client/app/blimp_client_switches.h" |
20 #include "blimp/common/protocol_version.h" | 17 #include "blimp/common/protocol_version.h" |
21 #include "components/safe_json/safe_json_parser.h" | |
22 #include "net/base/ip_address.h" | 18 #include "net/base/ip_address.h" |
23 #include "net/base/ip_endpoint.h" | 19 #include "net/base/ip_endpoint.h" |
24 #include "net/base/load_flags.h" | 20 #include "net/base/load_flags.h" |
25 #include "net/base/net_errors.h" | 21 #include "net/base/net_errors.h" |
| 22 #include "net/base/url_util.h" |
26 #include "net/http/http_status_code.h" | 23 #include "net/http/http_status_code.h" |
27 #include "net/proxy/proxy_config_service.h" | 24 #include "net/proxy/proxy_config_service.h" |
28 #include "net/proxy/proxy_service.h" | 25 #include "net/proxy/proxy_service.h" |
29 #include "net/url_request/url_fetcher.h" | 26 #include "net/url_request/url_fetcher.h" |
30 #include "net/url_request/url_request_context.h" | 27 #include "net/url_request/url_request_context.h" |
31 #include "net/url_request/url_request_context_builder.h" | 28 #include "net/url_request/url_request_context_builder.h" |
32 #include "net/url_request/url_request_context_getter.h" | 29 #include "net/url_request/url_request_context_getter.h" |
33 | 30 |
34 namespace blimp { | 31 namespace blimp { |
35 namespace client { | 32 namespace client { |
36 | 33 |
37 namespace { | 34 namespace { |
38 | 35 |
39 // Assignment request JSON keys. | 36 // Assignment request JSON keys. |
40 const char kProtocolVersionKey[] = "protocol_version"; | 37 const char kProtocolVersionKey[] = "protocol_version"; |
41 | 38 |
42 // Assignment response JSON keys. | 39 // Assignment response JSON keys. |
43 const char kClientTokenKey[] = "clientToken"; | 40 const char kClientTokenKey[] = "clientToken"; |
44 const char kHostKey[] = "host"; | 41 const char kHostKey[] = "host"; |
45 const char kPortKey[] = "port"; | 42 const char kPortKey[] = "port"; |
| 43 const char kCertificateFingerprintKey[] = "certificateFingerprint"; |
46 const char kCertificateKey[] = "certificate"; | 44 const char kCertificateKey[] = "certificate"; |
47 | 45 |
48 // Possible arguments for the "--engine-transport" command line parameter. | 46 // URL scheme constants for custom assignments. See the '--blimplet-endpoint' |
49 const char kSSLTransportValue[] = "ssl"; | 47 // documentation in blimp_client_switches.cc for details. |
50 const char kTCPTransportValue[] = "tcp"; | 48 const char kCustomSSLScheme[] = "ssl"; |
| 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 } |
51 | 92 |
52 GURL GetBlimpAssignerURL() { | 93 GURL GetBlimpAssignerURL() { |
53 // TODO(dtrainor): Add a way to specify another assigner. | 94 // TODO(dtrainor): Add a way to specify another assigner. |
54 return GURL(kDefaultAssignerURL); | 95 return GURL(kDefaultAssignerURL); |
55 } | 96 } |
56 | 97 |
57 class SimpleURLRequestContextGetter : public net::URLRequestContextGetter { | 98 class SimpleURLRequestContextGetter : public net::URLRequestContextGetter { |
58 public: | 99 public: |
59 SimpleURLRequestContextGetter( | 100 SimpleURLRequestContextGetter( |
60 scoped_refptr<base::SingleThreadTaskRunner> io_loop_task_runner) | 101 const scoped_refptr<base::SingleThreadTaskRunner>& io_loop_task_runner) |
61 : io_loop_task_runner_(std::move(io_loop_task_runner)), | 102 : io_loop_task_runner_(io_loop_task_runner), |
62 proxy_config_service_(net::ProxyService::CreateSystemProxyConfigService( | 103 proxy_config_service_(net::ProxyService::CreateSystemProxyConfigService( |
63 io_loop_task_runner_, | 104 io_loop_task_runner_, |
64 io_loop_task_runner_)) {} | 105 io_loop_task_runner_)) {} |
65 | 106 |
66 // net::URLRequestContextGetter implementation. | 107 // net::URLRequestContextGetter implementation. |
67 net::URLRequestContext* GetURLRequestContext() override { | 108 net::URLRequestContext* GetURLRequestContext() override { |
68 if (!url_request_context_) { | 109 if (!url_request_context_) { |
69 net::URLRequestContextBuilder builder; | 110 net::URLRequestContextBuilder builder; |
70 builder.set_proxy_config_service(std::move(proxy_config_service_)); | 111 builder.set_proxy_config_service(std::move(proxy_config_service_)); |
71 builder.DisableHttpCache(); | 112 builder.DisableHttpCache(); |
(...skipping 16 matching lines...) Expand all Loading... |
88 | 129 |
89 // Temporary storage for the ProxyConfigService, which needs to be created on | 130 // Temporary storage for the ProxyConfigService, which needs to be created on |
90 // the main thread but cleared on the IO thread. This will be built in the | 131 // the main thread but cleared on the IO thread. This will be built in the |
91 // constructor and cleared on the IO thread. Due to the usage of this class | 132 // constructor and cleared on the IO thread. Due to the usage of this class |
92 // this is safe. | 133 // this is safe. |
93 scoped_ptr<net::ProxyConfigService> proxy_config_service_; | 134 scoped_ptr<net::ProxyConfigService> proxy_config_service_; |
94 | 135 |
95 DISALLOW_COPY_AND_ASSIGN(SimpleURLRequestContextGetter); | 136 DISALLOW_COPY_AND_ASSIGN(SimpleURLRequestContextGetter); |
96 }; | 137 }; |
97 | 138 |
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 | |
175 } // namespace | 139 } // namespace |
176 | 140 |
177 Assignment::Assignment() : transport_protocol(TransportProtocol::UNKNOWN) {} | 141 Assignment::Assignment() : transport_protocol(TransportProtocol::UNKNOWN) {} |
178 | 142 |
179 Assignment::~Assignment() {} | 143 Assignment::~Assignment() {} |
180 | 144 |
181 bool Assignment::IsValid() const { | 145 bool Assignment::is_null() const { |
182 if (engine_endpoint.address().empty() || engine_endpoint.port() == 0 || | 146 return ip_endpoint.address().empty() || ip_endpoint.port() == 0 || |
183 transport_protocol == TransportProtocol::UNKNOWN) { | 147 transport_protocol == TransportProtocol::UNKNOWN; |
184 return false; | |
185 } | |
186 if (transport_protocol == TransportProtocol::SSL && !cert) { | |
187 return false; | |
188 } | |
189 return true; | |
190 } | 148 } |
191 | 149 |
192 AssignmentSource::AssignmentSource( | 150 AssignmentSource::AssignmentSource( |
193 const scoped_refptr<base::SingleThreadTaskRunner>& network_task_runner, | 151 const scoped_refptr<base::SingleThreadTaskRunner>& main_task_runner, |
194 const scoped_refptr<base::SingleThreadTaskRunner>& file_task_runner) | 152 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner) |
195 : file_task_runner_(std::move(file_task_runner)), | 153 : main_task_runner_(main_task_runner), |
196 url_request_context_( | 154 url_request_context_(new SimpleURLRequestContextGetter(io_task_runner)) {} |
197 new SimpleURLRequestContextGetter(network_task_runner)), | |
198 weak_factory_(this) {} | |
199 | 155 |
200 AssignmentSource::~AssignmentSource() {} | 156 AssignmentSource::~AssignmentSource() {} |
201 | 157 |
202 void AssignmentSource::GetAssignment(const std::string& client_auth_token, | 158 void AssignmentSource::GetAssignment(const std::string& client_auth_token, |
203 const AssignmentCallback& callback) { | 159 const AssignmentCallback& callback) { |
204 DCHECK(callback_.is_null()); | 160 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 161 |
| 162 // Cancel any outstanding callback. |
| 163 if (!callback_.is_null()) { |
| 164 base::ResetAndReturn(&callback_) |
| 165 .Run(AssignmentSource::Result::RESULT_SERVER_INTERRUPTED, Assignment()); |
| 166 } |
205 callback_ = AssignmentCallback(callback); | 167 callback_ = AssignmentCallback(callback); |
206 | 168 |
207 if (base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kEngineIP)) { | 169 Assignment assignment = GetCustomBlimpletAssignment(); |
208 base::PostTaskAndReplyWithResult( | 170 if (!assignment.is_null()) { |
209 file_task_runner_.get(), FROM_HERE, | 171 // Post the result so that the behavior of this function is consistent. |
210 base::Bind(&GetAssignmentFromCommandLine), | 172 main_task_runner_->PostTask( |
211 base::Bind(&AssignmentSource::OnGetAssignmentFromCommandLineDone, | 173 FROM_HERE, base::Bind(base::ResetAndReturn(&callback_), |
212 weak_factory_.GetWeakPtr(), client_auth_token)); | 174 AssignmentSource::Result::RESULT_OK, assignment)); |
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); | |
225 return; | 175 return; |
226 } | 176 } |
227 | 177 |
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) { | |
234 // Call out to the network for a real assignment. Build the network request | 178 // Call out to the network for a real assignment. Build the network request |
235 // to hit the assigner. | 179 // to hit the assigner. |
236 url_fetcher_ = net::URLFetcher::Create(GetBlimpAssignerURL(), | 180 url_fetcher_ = net::URLFetcher::Create(GetBlimpAssignerURL(), |
237 net::URLFetcher::POST, this); | 181 net::URLFetcher::POST, this); |
238 url_fetcher_->SetRequestContext(url_request_context_.get()); | 182 url_fetcher_->SetRequestContext(url_request_context_.get()); |
239 url_fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SAVE_COOKIES | | 183 url_fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SAVE_COOKIES | |
240 net::LOAD_DO_NOT_SEND_COOKIES); | 184 net::LOAD_DO_NOT_SEND_COOKIES); |
241 url_fetcher_->AddExtraRequestHeader("Authorization: Bearer " + | 185 url_fetcher_->AddExtraRequestHeader("Authorization: Bearer " + |
242 client_auth_token); | 186 client_auth_token); |
243 | 187 |
244 // Write the JSON for the request data. | 188 // Write the JSON for the request data. |
245 base::DictionaryValue dictionary; | 189 base::DictionaryValue dictionary; |
246 dictionary.SetString(kProtocolVersionKey, blimp::kEngineVersion); | 190 dictionary.SetString(kProtocolVersionKey, blimp::kEngineVersion); |
247 std::string json; | 191 std::string json; |
248 base::JSONWriter::Write(dictionary, &json); | 192 base::JSONWriter::Write(dictionary, &json); |
249 url_fetcher_->SetUploadData("application/json", json); | 193 url_fetcher_->SetUploadData("application/json", json); |
| 194 |
250 url_fetcher_->Start(); | 195 url_fetcher_->Start(); |
251 } | 196 } |
252 | 197 |
253 void AssignmentSource::OnURLFetchComplete(const net::URLFetcher* source) { | 198 void AssignmentSource::OnURLFetchComplete(const net::URLFetcher* source) { |
| 199 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
254 DCHECK(!callback_.is_null()); | 200 DCHECK(!callback_.is_null()); |
255 DCHECK_EQ(url_fetcher_.get(), source); | 201 DCHECK_EQ(url_fetcher_.get(), source); |
256 | 202 |
257 if (!source->GetStatus().is_success()) { | 203 if (!source->GetStatus().is_success()) { |
258 DVLOG(1) << "Assignment request failed due to network error: " | 204 DVLOG(1) << "Assignment request failed due to network error: " |
259 << net::ErrorToString(source->GetStatus().error()); | 205 << net::ErrorToString(source->GetStatus().error()); |
260 base::ResetAndReturn(&callback_) | 206 base::ResetAndReturn(&callback_) |
261 .Run(AssignmentSource::Result::RESULT_NETWORK_FAILURE, Assignment()); | 207 .Run(AssignmentSource::Result::RESULT_NETWORK_FAILURE, Assignment()); |
262 return; | 208 return; |
263 } | 209 } |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
300 DCHECK_EQ(net::HTTP_OK, url_fetcher_->GetResponseCode()); | 246 DCHECK_EQ(net::HTTP_OK, url_fetcher_->GetResponseCode()); |
301 | 247 |
302 // Grab the response from the assigner request. | 248 // Grab the response from the assigner request. |
303 std::string response; | 249 std::string response; |
304 if (!url_fetcher_->GetResponseAsString(&response)) { | 250 if (!url_fetcher_->GetResponseAsString(&response)) { |
305 base::ResetAndReturn(&callback_) | 251 base::ResetAndReturn(&callback_) |
306 .Run(AssignmentSource::Result::RESULT_BAD_RESPONSE, Assignment()); | 252 .Run(AssignmentSource::Result::RESULT_BAD_RESPONSE, Assignment()); |
307 return; | 253 return; |
308 } | 254 } |
309 | 255 |
310 safe_json::SafeJsonParser::Parse( | 256 // Attempt to interpret the response as JSON and treat it as a dictionary. |
311 response, | 257 scoped_ptr<base::Value> json = base::JSONReader::Read(response); |
312 base::Bind(&AssignmentSource::OnJsonParsed, weak_factory_.GetWeakPtr()), | 258 if (!json) { |
313 base::Bind(&AssignmentSource::OnJsonParseError, | 259 base::ResetAndReturn(&callback_) |
314 weak_factory_.GetWeakPtr())); | 260 .Run(AssignmentSource::Result::RESULT_BAD_RESPONSE, Assignment()); |
315 } | 261 return; |
| 262 } |
316 | 263 |
317 void AssignmentSource::OnJsonParsed(scoped_ptr<base::Value> json) { | |
318 const base::DictionaryValue* dict; | 264 const base::DictionaryValue* dict; |
319 if (!json->GetAsDictionary(&dict)) { | 265 if (!json->GetAsDictionary(&dict)) { |
320 base::ResetAndReturn(&callback_) | 266 base::ResetAndReturn(&callback_) |
321 .Run(AssignmentSource::Result::RESULT_BAD_RESPONSE, Assignment()); | 267 .Run(AssignmentSource::Result::RESULT_BAD_RESPONSE, Assignment()); |
322 return; | 268 return; |
323 } | 269 } |
324 | 270 |
325 // Validate that all the expected fields are present. | 271 // Validate that all the expected fields are present. |
326 std::string client_token; | 272 std::string client_token; |
327 std::string host; | 273 std::string host; |
328 int port; | 274 int port; |
329 std::string cert_str; | 275 std::string cert_fingerprint; |
| 276 std::string cert; |
330 if (!(dict->GetString(kClientTokenKey, &client_token) && | 277 if (!(dict->GetString(kClientTokenKey, &client_token) && |
331 dict->GetString(kHostKey, &host) && dict->GetInteger(kPortKey, &port) && | 278 dict->GetString(kHostKey, &host) && dict->GetInteger(kPortKey, &port) && |
332 dict->GetString(kCertificateKey, &cert_str))) { | 279 dict->GetString(kCertificateFingerprintKey, &cert_fingerprint) && |
| 280 dict->GetString(kCertificateKey, &cert))) { |
333 base::ResetAndReturn(&callback_) | 281 base::ResetAndReturn(&callback_) |
334 .Run(AssignmentSource::Result::RESULT_BAD_RESPONSE, Assignment()); | 282 .Run(AssignmentSource::Result::RESULT_BAD_RESPONSE, Assignment()); |
335 return; | 283 return; |
336 } | 284 } |
337 | 285 |
338 net::IPAddress ip_address; | 286 net::IPAddress ip_address; |
339 if (!ip_address.AssignFromIPLiteral(host)) { | 287 if (!ip_address.AssignFromIPLiteral(host)) { |
340 base::ResetAndReturn(&callback_) | 288 base::ResetAndReturn(&callback_) |
341 .Run(AssignmentSource::Result::RESULT_BAD_RESPONSE, Assignment()); | 289 .Run(AssignmentSource::Result::RESULT_BAD_RESPONSE, Assignment()); |
342 return; | 290 return; |
343 } | 291 } |
344 | 292 |
345 if (!base::IsValueInRangeForNumericType<uint16_t>(port)) { | 293 if (!base::IsValueInRangeForNumericType<uint16_t>(port)) { |
346 base::ResetAndReturn(&callback_) | 294 base::ResetAndReturn(&callback_) |
347 .Run(AssignmentSource::Result::RESULT_BAD_RESPONSE, Assignment()); | 295 .Run(AssignmentSource::Result::RESULT_BAD_RESPONSE, Assignment()); |
348 return; | 296 return; |
349 } | 297 } |
350 | 298 |
351 net::CertificateList cert_list = | 299 Assignment assignment; |
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 | |
361 // The assigner assumes SSL-only and all engines it assigns only communicate | 300 // The assigner assumes SSL-only and all engines it assigns only communicate |
362 // over SSL. | 301 // over SSL. |
363 Assignment assignment; | |
364 assignment.transport_protocol = Assignment::TransportProtocol::SSL; | 302 assignment.transport_protocol = Assignment::TransportProtocol::SSL; |
365 assignment.engine_endpoint = net::IPEndPoint(ip_address, port); | 303 assignment.ip_endpoint = net::IPEndPoint(ip_address, port); |
366 assignment.client_token = client_token; | 304 assignment.client_token = client_token; |
367 assignment.cert = std::move(cert_list[0]); | 305 assignment.certificate = cert; |
| 306 assignment.certificate_fingerprint = cert_fingerprint; |
368 | 307 |
369 base::ResetAndReturn(&callback_) | 308 base::ResetAndReturn(&callback_) |
370 .Run(AssignmentSource::Result::RESULT_OK, assignment); | 309 .Run(AssignmentSource::Result::RESULT_OK, assignment); |
371 } | 310 } |
372 | 311 |
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 | |
379 } // namespace client | 312 } // namespace client |
380 } // namespace blimp | 313 } // namespace blimp |
OLD | NEW |