OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "remoting/host/token_validator_base.h" | 5 #include "remoting/host/token_validator_base.h" |
6 | 6 |
7 #include "base/base64.h" | 7 #include "base/base64.h" |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/callback.h" | 9 #include "base/callback.h" |
10 #include "base/json/json_reader.h" | 10 #include "base/json/json_reader.h" |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
13 #include "base/single_thread_task_runner.h" | 13 #include "base/single_thread_task_runner.h" |
14 #include "base/strings/string_util.h" | 14 #include "base/strings/string_util.h" |
15 #include "base/values.h" | 15 #include "base/values.h" |
16 #include "net/base/escape.h" | 16 #include "net/base/escape.h" |
17 #include "net/base/io_buffer.h" | 17 #include "net/base/io_buffer.h" |
18 #include "net/base/request_priority.h" | 18 #include "net/base/request_priority.h" |
19 #include "net/base/upload_bytes_element_reader.h" | 19 #include "net/base/upload_bytes_element_reader.h" |
20 #include "net/base/upload_data_stream.h" | 20 #include "net/base/upload_data_stream.h" |
21 #include "net/ssl/client_cert_store.h" | 21 #include "net/ssl/client_cert_store.h" |
22 #if defined(USE_NSS_CERTS) | 22 #if defined(USE_NSS_CERTS) |
23 #include "net/ssl/client_cert_store_nss.h" | 23 #include "net/ssl/client_cert_store_nss.h" |
24 #elif defined(OS_WIN) | 24 #elif defined(OS_WIN) |
25 #include "net/ssl/client_cert_store_win.h" | 25 #include "net/ssl/client_cert_store_win.h" |
26 #elif defined(OS_MACOSX) | 26 #elif defined(OS_MACOSX) |
27 #include "net/ssl/client_cert_store_mac.h" | 27 #include "net/ssl/client_cert_store_mac.h" |
28 #endif | 28 #endif |
29 #include "net/ssl/ssl_cert_request_info.h" | 29 #include "net/ssl/ssl_cert_request_info.h" |
30 #include "net/ssl/ssl_platform_key.h" | |
31 #include "net/ssl/ssl_private_key.h" | |
30 #include "net/url_request/url_request.h" | 32 #include "net/url_request/url_request.h" |
31 #include "net/url_request/url_request_context.h" | 33 #include "net/url_request/url_request_context.h" |
32 #include "net/url_request/url_request_status.h" | 34 #include "net/url_request/url_request_status.h" |
33 #include "url/gurl.h" | 35 #include "url/gurl.h" |
34 | 36 |
35 namespace { | 37 namespace { |
36 | 38 |
37 const int kBufferSize = 4096; | 39 const int kBufferSize = 4096; |
38 const char kCertIssuerWildCard[] = "*"; | 40 const char kCertIssuerWildCard[] = "*"; |
39 | 41 |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
147 | 149 |
148 void TokenValidatorBase::OnCertificatesSelected( | 150 void TokenValidatorBase::OnCertificatesSelected( |
149 net::CertificateList* selected_certs, | 151 net::CertificateList* selected_certs, |
150 net::ClientCertStore* unused) { | 152 net::ClientCertStore* unused) { |
151 const std::string& issuer = | 153 const std::string& issuer = |
152 third_party_auth_config_.token_validation_cert_issuer; | 154 third_party_auth_config_.token_validation_cert_issuer; |
153 if (request_) { | 155 if (request_) { |
154 for (size_t i = 0; i < selected_certs->size(); ++i) { | 156 for (size_t i = 0; i < selected_certs->size(); ++i) { |
155 if (issuer == kCertIssuerWildCard || | 157 if (issuer == kCertIssuerWildCard || |
156 issuer == (*selected_certs)[i]->issuer().common_name) { | 158 issuer == (*selected_certs)[i]->issuer().common_name) { |
157 request_->ContinueWithCertificate((*selected_certs)[i].get()); | 159 scoped_refptr<net::SSLPrivateKey> private_key = |
Sergey Ulanov
2015/11/11 19:05:02
nit: this code would be shorter and more readable
svaldez
2015/11/16 21:36:22
Done.
| |
160 net::FetchClientCertPrivateKey((*selected_certs)[i].get()); | |
161 request_->ContinueWithCertificate((*selected_certs)[i].get(), | |
162 private_key.get()); | |
158 return; | 163 return; |
159 } | 164 } |
160 } | 165 } |
161 request_->ContinueWithCertificate(nullptr); | 166 request_->ContinueWithCertificate(nullptr, nullptr); |
162 } | 167 } |
163 } | 168 } |
164 | 169 |
165 bool TokenValidatorBase::IsValidScope(const std::string& token_scope) { | 170 bool TokenValidatorBase::IsValidScope(const std::string& token_scope) { |
166 // TODO(rmsousa): Deal with reordering/subsets/supersets/aliases/etc. | 171 // TODO(rmsousa): Deal with reordering/subsets/supersets/aliases/etc. |
167 return token_scope == token_scope_; | 172 return token_scope == token_scope_; |
168 } | 173 } |
169 | 174 |
170 std::string TokenValidatorBase::ProcessResponse() { | 175 std::string TokenValidatorBase::ProcessResponse() { |
171 // Verify that we got a successful response. | 176 // Verify that we got a successful response. |
(...skipping 27 matching lines...) Expand all Loading... | |
199 return std::string(); | 204 return std::string(); |
200 } | 205 } |
201 | 206 |
202 std::string shared_secret; | 207 std::string shared_secret; |
203 // Everything is valid, so return the shared secret to the caller. | 208 // Everything is valid, so return the shared secret to the caller. |
204 dict->GetStringWithoutPathExpansion("access_token", &shared_secret); | 209 dict->GetStringWithoutPathExpansion("access_token", &shared_secret); |
205 return shared_secret; | 210 return shared_secret; |
206 } | 211 } |
207 | 212 |
208 } // namespace remoting | 213 } // namespace remoting |
OLD | NEW |