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 | |
108 unsigned port_parsed = 0; | |
109 if (!base::StringToUint( | |
110 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | |
111 switches::kEnginePort), | |
112 &port_parsed) || | |
113 !IsValidIpPortNumber(port_parsed)) { | |
114 DLOG(FATAL) << "--engine-port must be a value between 1 and 65535."; | |
115 return Assignment(); | |
116 } | |
117 uint16_t port = base::checked_cast<uint16_t>(port_parsed); | |
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 = net::IPEndPoint(ip_address, port); | |
Wez
2016/03/02 02:26:44
nit: I think you can put the checked_cast for port
Kevin M
2016/03/02 18:05:34
Done.
| |
128 | |
129 std::string transport_str = | |
130 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | |
131 switches::kEngineTransport); | |
132 if (transport_str == kSSLTransportValue) { | |
133 assignment.transport_protocol = Assignment::TransportProtocol::SSL; | |
134 } else if (transport_str == kTCPTransportValue) { | |
135 assignment.transport_protocol = Assignment::TransportProtocol::TCP; | |
136 } else { | |
137 DLOG(FATAL) << "Invalid engine transport " << transport_str; | |
138 return Assignment(); | |
139 } | |
140 | |
141 scoped_refptr<net::X509Certificate> cert; | |
142 if (assignment.transport_protocol == Assignment::TransportProtocol::SSL) { | |
143 base::FilePath cert_path = | |
144 base::CommandLine::ForCurrentProcess()->GetSwitchValuePath( | |
145 switches::kEngineCertPath); | |
146 if (cert_path.empty()) { | |
147 DLOG(FATAL) << "Missing required parameter --" | |
148 << switches::kEngineCertPath << "."; | |
149 return Assignment(); | |
150 } | |
151 std::string cert_str; | |
152 if (!base::ReadFileToString(cert_path, &cert_str)) { | |
153 DLOG(FATAL) << "Couldn't read from file: " | |
154 << cert_path.LossyDisplayName(); | |
155 return Assignment(); | |
156 } | |
157 net::CertificateList cert_list = | |
158 net::X509Certificate::CreateCertificateListFromBytes( | |
159 cert_str.data(), cert_str.size(), | |
160 net::X509Certificate::FORMAT_PEM_CERT_SEQUENCE); | |
161 DLOG_IF(FATAL, (cert_list.size() != 1u)) | |
162 << "Only one cert is allowed in PEM cert list."; | |
163 assignment.cert = std::move(cert_list[0]); | |
164 } | |
165 | |
166 if (!assignment.IsValid()) { | |
Wez
2016/03/02 02:26:44
nit: Do you want to DLOG(FATAL) if it's not valid,
Kevin M
2016/03/02 18:05:34
Done.
| |
167 return Assignment(); | |
168 } | |
169 | |
170 assignment.client_token = kDummyClientToken; | |
Wez
2016/03/02 02:26:45
nit: Suggest moving this up to the top, immediatel
Kevin M
2016/03/02 18:05:33
Done.
| |
171 return assignment; | |
172 } | |
173 | |
139 } // namespace | 174 } // namespace |
140 | 175 |
141 Assignment::Assignment() : transport_protocol(TransportProtocol::UNKNOWN) {} | 176 Assignment::Assignment() : transport_protocol(TransportProtocol::UNKNOWN) {} |
142 | 177 |
143 Assignment::~Assignment() {} | 178 Assignment::~Assignment() {} |
144 | 179 |
145 bool Assignment::is_null() const { | 180 bool Assignment::IsValid() const { |
146 return ip_endpoint.address().empty() || ip_endpoint.port() == 0 || | 181 return !engine_endpoint.address().empty() && engine_endpoint.port() != 0 && |
147 transport_protocol == TransportProtocol::UNKNOWN; | 182 transport_protocol != TransportProtocol::UNKNOWN && |
183 (transport_protocol != TransportProtocol::SSL || cert); | |
Wez
2016/03/02 02:26:45
nit: This is getting complex enough to break down
Kevin M
2016/03/02 18:05:33
Done.
| |
148 } | 184 } |
149 | 185 |
150 AssignmentSource::AssignmentSource( | 186 AssignmentSource::AssignmentSource( |
151 const scoped_refptr<base::SingleThreadTaskRunner>& main_task_runner, | 187 const scoped_refptr<base::SingleThreadTaskRunner>& network_task_runner, |
152 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner) | 188 const scoped_refptr<base::SingleThreadTaskRunner>& file_task_runner) |
153 : main_task_runner_(main_task_runner), | 189 : file_task_runner_(std::move(file_task_runner)), |
154 url_request_context_(new SimpleURLRequestContextGetter(io_task_runner)) {} | 190 url_request_context_( |
191 new SimpleURLRequestContextGetter(network_task_runner)), | |
192 weak_factory_(this) {} | |
155 | 193 |
156 AssignmentSource::~AssignmentSource() {} | 194 AssignmentSource::~AssignmentSource() {} |
157 | 195 |
158 void AssignmentSource::GetAssignment(const std::string& client_auth_token, | 196 void AssignmentSource::GetAssignment(const std::string& client_auth_token, |
159 const AssignmentCallback& callback) { | 197 const AssignmentCallback& callback) { |
160 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 198 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); | 199 callback_ = AssignmentCallback(callback); |
168 | 200 |
169 Assignment assignment = GetCustomBlimpletAssignment(); | 201 if (base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kEngineIP)) { |
170 if (!assignment.is_null()) { | 202 base::PostTaskAndReplyWithResult( |
171 // Post the result so that the behavior of this function is consistent. | 203 file_task_runner_.get(), FROM_HERE, |
172 main_task_runner_->PostTask( | 204 base::Bind(&GetAssignmentFromCommandLine), |
173 FROM_HERE, base::Bind(base::ResetAndReturn(&callback_), | 205 base::Bind(&AssignmentSource::OnGetAssignmentFromCommandLineDone, |
174 AssignmentSource::Result::RESULT_OK, assignment)); | 206 weak_factory_.GetWeakPtr(), client_auth_token)); |
207 } else { | |
208 QueryAssigner(client_auth_token); | |
209 } | |
210 } | |
211 | |
212 void AssignmentSource::OnGetAssignmentFromCommandLineDone( | |
213 const std::string& client_auth_token, | |
214 Assignment parsed_assignment) { | |
215 // If GetAssignmentFromCommandLine succeeded, then return the custom | |
216 // assignment directly. | |
217 if (parsed_assignment.IsValid()) { | |
218 base::ResetAndReturn(&callback_) | |
219 .Run(AssignmentSource::RESULT_OK, parsed_assignment); | |
175 return; | 220 return; |
176 } | 221 } |
177 | 222 |
223 // If no assignment was passed via the comamnd line, then fall back on | |
Wez
2016/03/02 02:26:45
typo: command
Kevin M
2016/03/02 18:05:34
Done.
| |
224 // querying the Assigner service. | |
225 QueryAssigner(client_auth_token); | |
226 } | |
227 | |
228 void AssignmentSource::QueryAssigner(const std::string& client_auth_token) { | |
178 // Call out to the network for a real assignment. Build the network request | 229 // Call out to the network for a real assignment. Build the network request |
179 // to hit the assigner. | 230 // to hit the assigner. |
180 url_fetcher_ = net::URLFetcher::Create(GetBlimpAssignerURL(), | 231 url_fetcher_ = net::URLFetcher::Create(GetBlimpAssignerURL(), |
181 net::URLFetcher::POST, this); | 232 net::URLFetcher::POST, this); |
182 url_fetcher_->SetRequestContext(url_request_context_.get()); | 233 url_fetcher_->SetRequestContext(url_request_context_.get()); |
183 url_fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SAVE_COOKIES | | 234 url_fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SAVE_COOKIES | |
184 net::LOAD_DO_NOT_SEND_COOKIES); | 235 net::LOAD_DO_NOT_SEND_COOKIES); |
185 url_fetcher_->AddExtraRequestHeader("Authorization: Bearer " + | 236 url_fetcher_->AddExtraRequestHeader("Authorization: Bearer " + |
186 client_auth_token); | 237 client_auth_token); |
187 | 238 |
188 // Write the JSON for the request data. | 239 // Write the JSON for the request data. |
189 base::DictionaryValue dictionary; | 240 base::DictionaryValue dictionary; |
190 dictionary.SetString(kProtocolVersionKey, blimp::kEngineVersion); | 241 dictionary.SetString(kProtocolVersionKey, blimp::kEngineVersion); |
191 std::string json; | 242 std::string json; |
192 base::JSONWriter::Write(dictionary, &json); | 243 base::JSONWriter::Write(dictionary, &json); |
193 url_fetcher_->SetUploadData("application/json", json); | 244 url_fetcher_->SetUploadData("application/json", json); |
194 | |
195 url_fetcher_->Start(); | 245 url_fetcher_->Start(); |
196 } | 246 } |
197 | 247 |
198 void AssignmentSource::OnURLFetchComplete(const net::URLFetcher* source) { | 248 void AssignmentSource::OnURLFetchComplete(const net::URLFetcher* source) { |
199 DCHECK(main_task_runner_->BelongsToCurrentThread()); | |
200 DCHECK(!callback_.is_null()); | 249 DCHECK(!callback_.is_null()); |
201 DCHECK_EQ(url_fetcher_.get(), source); | 250 DCHECK_EQ(url_fetcher_.get(), source); |
202 | 251 |
203 if (!source->GetStatus().is_success()) { | 252 if (!source->GetStatus().is_success()) { |
204 DVLOG(1) << "Assignment request failed due to network error: " | 253 DVLOG(1) << "Assignment request failed due to network error: " |
205 << net::ErrorToString(source->GetStatus().error()); | 254 << net::ErrorToString(source->GetStatus().error()); |
206 base::ResetAndReturn(&callback_) | 255 base::ResetAndReturn(&callback_) |
207 .Run(AssignmentSource::Result::RESULT_NETWORK_FAILURE, Assignment()); | 256 .Run(AssignmentSource::Result::RESULT_NETWORK_FAILURE, Assignment()); |
208 return; | 257 return; |
209 } | 258 } |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
246 DCHECK_EQ(net::HTTP_OK, url_fetcher_->GetResponseCode()); | 295 DCHECK_EQ(net::HTTP_OK, url_fetcher_->GetResponseCode()); |
247 | 296 |
248 // Grab the response from the assigner request. | 297 // Grab the response from the assigner request. |
249 std::string response; | 298 std::string response; |
250 if (!url_fetcher_->GetResponseAsString(&response)) { | 299 if (!url_fetcher_->GetResponseAsString(&response)) { |
251 base::ResetAndReturn(&callback_) | 300 base::ResetAndReturn(&callback_) |
252 .Run(AssignmentSource::Result::RESULT_BAD_RESPONSE, Assignment()); | 301 .Run(AssignmentSource::Result::RESULT_BAD_RESPONSE, Assignment()); |
253 return; | 302 return; |
254 } | 303 } |
255 | 304 |
256 // Attempt to interpret the response as JSON and treat it as a dictionary. | 305 safe_json::SafeJsonParser::Parse( |
257 scoped_ptr<base::Value> json = base::JSONReader::Read(response); | 306 response, |
258 if (!json) { | 307 base::Bind(&AssignmentSource::OnJsonParsed, weak_factory_.GetWeakPtr()), |
259 base::ResetAndReturn(&callback_) | 308 base::Bind(&AssignmentSource::OnJsonParseError, |
260 .Run(AssignmentSource::Result::RESULT_BAD_RESPONSE, Assignment()); | 309 weak_factory_.GetWeakPtr())); |
261 return; | 310 } |
262 } | |
263 | 311 |
312 void AssignmentSource::OnJsonParsed(scoped_ptr<base::Value> json) { | |
264 const base::DictionaryValue* dict; | 313 const base::DictionaryValue* dict; |
265 if (!json->GetAsDictionary(&dict)) { | 314 if (!json->GetAsDictionary(&dict)) { |
266 base::ResetAndReturn(&callback_) | 315 base::ResetAndReturn(&callback_) |
267 .Run(AssignmentSource::Result::RESULT_BAD_RESPONSE, Assignment()); | 316 .Run(AssignmentSource::Result::RESULT_BAD_RESPONSE, Assignment()); |
268 return; | 317 return; |
269 } | 318 } |
270 | 319 |
271 // Validate that all the expected fields are present. | 320 // Validate that all the expected fields are present. |
272 std::string client_token; | 321 std::string client_token; |
273 std::string host; | 322 std::string host; |
274 int port; | 323 int port; |
275 std::string cert_fingerprint; | 324 std::string cert_str; |
276 std::string cert; | |
277 if (!(dict->GetString(kClientTokenKey, &client_token) && | 325 if (!(dict->GetString(kClientTokenKey, &client_token) && |
278 dict->GetString(kHostKey, &host) && dict->GetInteger(kPortKey, &port) && | 326 dict->GetString(kHostKey, &host) && dict->GetInteger(kPortKey, &port) && |
279 dict->GetString(kCertificateFingerprintKey, &cert_fingerprint) && | 327 dict->GetString(kCertificateKey, &cert_str))) { |
280 dict->GetString(kCertificateKey, &cert))) { | |
281 base::ResetAndReturn(&callback_) | 328 base::ResetAndReturn(&callback_) |
282 .Run(AssignmentSource::Result::RESULT_BAD_RESPONSE, Assignment()); | 329 .Run(AssignmentSource::Result::RESULT_BAD_RESPONSE, Assignment()); |
283 return; | 330 return; |
284 } | 331 } |
285 | 332 |
286 net::IPAddress ip_address; | 333 net::IPAddress ip_address; |
287 if (!ip_address.AssignFromIPLiteral(host)) { | 334 if (!ip_address.AssignFromIPLiteral(host)) { |
288 base::ResetAndReturn(&callback_) | 335 base::ResetAndReturn(&callback_) |
289 .Run(AssignmentSource::Result::RESULT_BAD_RESPONSE, Assignment()); | 336 .Run(AssignmentSource::Result::RESULT_BAD_RESPONSE, Assignment()); |
290 return; | 337 return; |
291 } | 338 } |
292 | 339 |
293 if (!base::IsValueInRangeForNumericType<uint16_t>(port)) { | 340 if (!base::IsValueInRangeForNumericType<uint16_t>(port)) { |
294 base::ResetAndReturn(&callback_) | 341 base::ResetAndReturn(&callback_) |
295 .Run(AssignmentSource::Result::RESULT_BAD_RESPONSE, Assignment()); | 342 .Run(AssignmentSource::Result::RESULT_BAD_RESPONSE, Assignment()); |
296 return; | 343 return; |
297 } | 344 } |
298 | 345 |
299 Assignment assignment; | 346 net::CertificateList cert_list = |
347 net::X509Certificate::CreateCertificateListFromBytes( | |
348 cert_str.data(), cert_str.size(), | |
349 net::X509Certificate::FORMAT_PEM_CERT_SEQUENCE); | |
350 if (cert_list.size() != 1) { | |
351 base::ResetAndReturn(&callback_) | |
352 .Run(AssignmentSource::Result::RESULT_INVALID_CERT, Assignment()); | |
353 return; | |
354 } | |
355 | |
300 // The assigner assumes SSL-only and all engines it assigns only communicate | 356 // The assigner assumes SSL-only and all engines it assigns only communicate |
301 // over SSL. | 357 // over SSL. |
358 Assignment assignment; | |
302 assignment.transport_protocol = Assignment::TransportProtocol::SSL; | 359 assignment.transport_protocol = Assignment::TransportProtocol::SSL; |
303 assignment.ip_endpoint = net::IPEndPoint(ip_address, port); | 360 assignment.engine_endpoint = net::IPEndPoint(ip_address, port); |
304 assignment.client_token = client_token; | 361 assignment.client_token = client_token; |
305 assignment.certificate = cert; | 362 assignment.cert = std::move(cert_list[0]); |
306 assignment.certificate_fingerprint = cert_fingerprint; | |
307 | 363 |
308 base::ResetAndReturn(&callback_) | 364 base::ResetAndReturn(&callback_) |
309 .Run(AssignmentSource::Result::RESULT_OK, assignment); | 365 .Run(AssignmentSource::Result::RESULT_OK, assignment); |
310 } | 366 } |
311 | 367 |
368 void AssignmentSource::OnJsonParseError(const std::string& error) { | |
369 DLOG(ERROR) << "Error while parsing assigner JSON: " << error; | |
370 base::ResetAndReturn(&callback_) | |
371 .Run(AssignmentSource::Result::RESULT_BAD_RESPONSE, Assignment()); | |
372 } | |
373 | |
312 } // namespace client | 374 } // namespace client |
313 } // namespace blimp | 375 } // namespace blimp |
OLD | NEW |