Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(146)

Side by Side Diff: blimp/client/session/assignment_source.cc

Issue 1958033003: Allows client to access auth token from command line specified file. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Adds documentation Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/files/file_util.h"
11 #include "base/json/json_reader.h" 11 #include "base/json/json_reader.h"
12 #include "base/json/json_writer.h" 12 #include "base/json/json_writer.h"
13 #include "base/location.h" 13 #include "base/location.h"
14 #include "base/memory/ref_counted.h" 14 #include "base/memory/ref_counted.h"
15 #include "base/numerics/safe_conversions.h" 15 #include "base/numerics/safe_conversions.h"
16 #include "base/strings/string_number_conversions.h" 16 #include "base/strings/string_number_conversions.h"
17 #include "base/task_runner_util.h" 17 #include "base/task_runner_util.h"
18 #include "base/threading/thread_restrictions.h"
18 #include "base/values.h" 19 #include "base/values.h"
19 #include "blimp/client/app/blimp_client_switches.h" 20 #include "blimp/client/app/blimp_client_switches.h"
21 #include "blimp/common/get_client_token.h"
20 #include "blimp/common/protocol_version.h" 22 #include "blimp/common/protocol_version.h"
21 #include "components/safe_json/safe_json_parser.h" 23 #include "components/safe_json/safe_json_parser.h"
22 #include "net/base/ip_address.h" 24 #include "net/base/ip_address.h"
23 #include "net/base/ip_endpoint.h" 25 #include "net/base/ip_endpoint.h"
24 #include "net/base/load_flags.h" 26 #include "net/base/load_flags.h"
25 #include "net/base/net_errors.h" 27 #include "net/base/net_errors.h"
26 #include "net/http/http_status_code.h" 28 #include "net/http/http_status_code.h"
27 #include "net/proxy/proxy_config_service.h" 29 #include "net/proxy/proxy_config_service.h"
28 #include "net/proxy/proxy_service.h" 30 #include "net/proxy/proxy_service.h"
29 #include "net/url_request/url_fetcher.h" 31 #include "net/url_request/url_fetcher.h"
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 94
93 bool IsValidIpPortNumber(unsigned port) { 95 bool IsValidIpPortNumber(unsigned port) {
94 return port > 0 && port <= 65535; 96 return port > 0 && port <= 65535;
95 } 97 }
96 98
97 // Populates an Assignment using command-line parameters, if provided. 99 // Populates an Assignment using command-line parameters, if provided.
98 // Returns a null Assignment if no parameters were set. 100 // Returns a null Assignment if no parameters were set.
99 // Must be called on a thread suitable for file IO. 101 // Must be called on a thread suitable for file IO.
100 Assignment GetAssignmentFromCommandLine() { 102 Assignment GetAssignmentFromCommandLine() {
101 Assignment assignment; 103 Assignment assignment;
102 assignment.client_token = kDummyClientToken; 104
105 const base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess();
106 assignment.client_token = GetClientToken(*cmd_line);
107 CHECK(!assignment.client_token.empty()) << "No client token provided.";
103 108
104 unsigned port_parsed = 0; 109 unsigned port_parsed = 0;
105 if (!base::StringToUint( 110 if (!base::StringToUint(
106 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( 111 cmd_line->GetSwitchValueASCII(switches::kEnginePort),
107 switches::kEnginePort), 112 &port_parsed) || !IsValidIpPortNumber(port_parsed)) {
108 &port_parsed) ||
109 !IsValidIpPortNumber(port_parsed)) {
110 DLOG(FATAL) << "--engine-port must be a value between 1 and 65535."; 113 DLOG(FATAL) << "--engine-port must be a value between 1 and 65535.";
111 return Assignment(); 114 return Assignment();
112 } 115 }
113 116
114 net::IPAddress ip_address; 117 net::IPAddress ip_address;
115 std::string ip_str = 118 std::string ip_str = cmd_line->GetSwitchValueASCII(switches::kEngineIP);
116 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
117 switches::kEngineIP);
118 if (!ip_address.AssignFromIPLiteral(ip_str)) { 119 if (!ip_address.AssignFromIPLiteral(ip_str)) {
119 DLOG(FATAL) << "Invalid engine IP " << ip_str; 120 DLOG(FATAL) << "Invalid engine IP " << ip_str;
120 return Assignment(); 121 return Assignment();
121 } 122 }
122 assignment.engine_endpoint = 123 assignment.engine_endpoint =
123 net::IPEndPoint(ip_address, base::checked_cast<uint16_t>(port_parsed)); 124 net::IPEndPoint(ip_address, base::checked_cast<uint16_t>(port_parsed));
124 125
125 std::string transport_str = 126 std::string transport_str =
126 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( 127 cmd_line->GetSwitchValueASCII(switches::kEngineTransport);
127 switches::kEngineTransport);
128 if (transport_str == kSSLTransportValue) { 128 if (transport_str == kSSLTransportValue) {
129 assignment.transport_protocol = Assignment::TransportProtocol::SSL; 129 assignment.transport_protocol = Assignment::TransportProtocol::SSL;
130 } else if (transport_str == kTCPTransportValue) { 130 } else if (transport_str == kTCPTransportValue) {
131 assignment.transport_protocol = Assignment::TransportProtocol::TCP; 131 assignment.transport_protocol = Assignment::TransportProtocol::TCP;
132 } else { 132 } else {
133 DLOG(FATAL) << "Invalid engine transport " << transport_str; 133 DLOG(FATAL) << "Invalid engine transport " << transport_str;
134 return Assignment(); 134 return Assignment();
135 } 135 }
136 136
137 scoped_refptr<net::X509Certificate> cert; 137 scoped_refptr<net::X509Certificate> cert;
138 if (assignment.transport_protocol == Assignment::TransportProtocol::SSL) { 138 if (assignment.transport_protocol == Assignment::TransportProtocol::SSL) {
139 base::FilePath cert_path = 139 base::FilePath cert_path =
140 base::CommandLine::ForCurrentProcess()->GetSwitchValuePath( 140 cmd_line->GetSwitchValuePath(switches::kEngineCertPath);
141 switches::kEngineCertPath);
142 if (cert_path.empty()) { 141 if (cert_path.empty()) {
143 DLOG(FATAL) << "Missing required parameter --" 142 DLOG(FATAL) << "Missing required parameter --"
144 << switches::kEngineCertPath << "."; 143 << switches::kEngineCertPath << ".";
145 return Assignment(); 144 return Assignment();
146 } 145 }
147 std::string cert_str; 146 std::string cert_str;
148 if (!base::ReadFileToString(cert_path, &cert_str)) { 147 if (!base::ReadFileToString(cert_path, &cert_str)) {
149 DLOG(FATAL) << "Couldn't read from file: " 148 DLOG(FATAL) << "Couldn't read from file: "
150 << cert_path.LossyDisplayName(); 149 << cert_path.LossyDisplayName();
151 return Assignment(); 150 return Assignment();
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
372 } 371 }
373 372
374 void AssignmentSource::OnJsonParseError(const std::string& error) { 373 void AssignmentSource::OnJsonParseError(const std::string& error) {
375 DLOG(ERROR) << "Error while parsing assigner JSON: " << error; 374 DLOG(ERROR) << "Error while parsing assigner JSON: " << error;
376 base::ResetAndReturn(&callback_) 375 base::ResetAndReturn(&callback_)
377 .Run(AssignmentSource::Result::RESULT_BAD_RESPONSE, Assignment()); 376 .Run(AssignmentSource::Result::RESULT_BAD_RESPONSE, Assignment());
378 } 377 }
379 378
380 } // namespace client 379 } // namespace client
381 } // namespace blimp 380 } // namespace blimp
OLDNEW
« no previous file with comments | « blimp/client/session/assignment_source.h ('k') | blimp/client/session/assignment_source_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698