Chromium Code Reviews| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/base64.h" | 9 #include "base/base64.h" |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 36 #include "net/url_request/url_request.h" | 36 #include "net/url_request/url_request.h" |
| 37 #include "net/url_request/url_request_context.h" | 37 #include "net/url_request/url_request_context.h" |
| 38 #include "net/url_request/url_request_status.h" | 38 #include "net/url_request/url_request_status.h" |
| 39 #include "url/gurl.h" | 39 #include "url/gurl.h" |
| 40 | 40 |
| 41 namespace { | 41 namespace { |
| 42 | 42 |
| 43 const int kBufferSize = 4096; | 43 const int kBufferSize = 4096; |
| 44 const char kCertIssuerWildCard[] = "*"; | 44 const char kCertIssuerWildCard[] = "*"; |
| 45 | 45 |
| 46 // Returns the best certificate to use. The returned value will only be null if | |
|
Sergey Ulanov
2016/09/27 00:40:06
maybe explain what "best certificate" means.
Yuwei
2016/09/27 21:37:42
Done.
| |
| 47 // both |c1| and |c2| are both null. | |
| 48 net::X509Certificate* GetBestCertificate(net::X509Certificate* c1, | |
|
Lambros
2016/09/27 00:23:33
I wonder if this could be written as a Predicate:
Yuwei
2016/09/27 21:37:41
Done.
| |
| 49 net::X509Certificate* c2) { | |
| 50 if (!c1) { | |
| 51 return c2; | |
| 52 } | |
| 53 if (!c2) { | |
|
Sergey Ulanov
2016/09/27 00:40:06
I think this code would be simpler if it didn't ha
Yuwei
2016/09/27 21:37:41
Obsolete. Now c1 and c2 will never be null.
| |
| 54 return c1; | |
| 55 } | |
| 56 if (c1->valid_start() != c2->valid_start()) { | |
|
Sergey Ulanov
2016/09/27 00:40:06
remove {} for consistency with other single-line
Yuwei
2016/09/27 21:37:42
Done.
| |
| 57 return c1->valid_start() > c2->valid_start() ? c1 : c2; | |
|
Sergey Ulanov
2016/09/27 00:40:06
Should we also verify that valid_start() is not in
Yuwei
2016/09/27 21:37:41
Yep. Forgot that... Added the check.
| |
| 58 } | |
| 59 return c1->valid_expiry() > c2->valid_expiry() ? c1 : c2; | |
| 60 } | |
| 61 | |
| 46 } // namespace | 62 } // namespace |
| 47 | 63 |
| 48 namespace remoting { | 64 namespace remoting { |
| 49 | 65 |
| 50 TokenValidatorBase::TokenValidatorBase( | 66 TokenValidatorBase::TokenValidatorBase( |
| 51 const ThirdPartyAuthConfig& third_party_auth_config, | 67 const ThirdPartyAuthConfig& third_party_auth_config, |
| 52 const std::string& token_scope, | 68 const std::string& token_scope, |
| 53 scoped_refptr<net::URLRequestContextGetter> request_context_getter) | 69 scoped_refptr<net::URLRequestContextGetter> request_context_getter) |
| 54 : third_party_auth_config_(third_party_auth_config), | 70 : third_party_auth_config_(third_party_auth_config), |
| 55 token_scope_(token_scope), | 71 token_scope_(token_scope), |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 167 base::Bind(&TokenValidatorBase::OnCertificatesSelected, | 183 base::Bind(&TokenValidatorBase::OnCertificatesSelected, |
| 168 weak_factory_.GetWeakPtr(), base::Owned(selected_certs), | 184 weak_factory_.GetWeakPtr(), base::Owned(selected_certs), |
| 169 base::Owned(client_cert_store))); | 185 base::Owned(client_cert_store))); |
| 170 } | 186 } |
| 171 | 187 |
| 172 void TokenValidatorBase::OnCertificatesSelected( | 188 void TokenValidatorBase::OnCertificatesSelected( |
| 173 net::CertificateList* selected_certs, | 189 net::CertificateList* selected_certs, |
| 174 net::ClientCertStore* unused) { | 190 net::ClientCertStore* unused) { |
| 175 const std::string& issuer = | 191 const std::string& issuer = |
| 176 third_party_auth_config_.token_validation_cert_issuer; | 192 third_party_auth_config_.token_validation_cert_issuer; |
| 177 if (request_) { | 193 if (request_) { |
|
Sergey Ulanov
2016/09/27 00:40:06
if (!request)
return;
Yuwei
2016/09/27 21:37:42
Done.
| |
| 178 for (size_t i = 0; i < selected_certs->size(); ++i) { | 194 net::X509Certificate* best_match_cert = nullptr; |
| 179 net::X509Certificate* cert = (*selected_certs)[i].get(); | 195 for (auto& cert : *selected_certs) { |
| 180 if (issuer == kCertIssuerWildCard || | 196 if ((issuer == kCertIssuerWildCard || |
| 181 issuer == cert->issuer().common_name) { | 197 issuer == cert->issuer().common_name) && |
| 182 request_->ContinueWithCertificate( | 198 (!cert->HasExpired() || cert->valid_expiry().is_null())) { |
| 183 cert, net::FetchClientCertPrivateKey(cert).get()); | 199 best_match_cert = |
| 184 return; | 200 GetBestCertificate(best_match_cert, cert.get()); |
| 185 } | 201 } |
| 186 } | 202 } |
| 187 request_->ContinueWithCertificate(nullptr, nullptr); | 203 request_->ContinueWithCertificate( |
| 204 best_match_cert, best_match_cert ? | |
| 205 net::FetchClientCertPrivateKey(best_match_cert).get() : nullptr); | |
| 188 } | 206 } |
| 189 } | 207 } |
| 190 | 208 |
| 191 bool TokenValidatorBase::IsValidScope(const std::string& token_scope) { | 209 bool TokenValidatorBase::IsValidScope(const std::string& token_scope) { |
| 192 // TODO(rmsousa): Deal with reordering/subsets/supersets/aliases/etc. | 210 // TODO(rmsousa): Deal with reordering/subsets/supersets/aliases/etc. |
| 193 return token_scope == token_scope_; | 211 return token_scope == token_scope_; |
| 194 } | 212 } |
| 195 | 213 |
| 196 std::string TokenValidatorBase::ProcessResponse(int net_result) { | 214 std::string TokenValidatorBase::ProcessResponse(int net_result) { |
| 197 // Verify that we got a successful response. | 215 // Verify that we got a successful response. |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 223 return std::string(); | 241 return std::string(); |
| 224 } | 242 } |
| 225 | 243 |
| 226 std::string shared_secret; | 244 std::string shared_secret; |
| 227 // Everything is valid, so return the shared secret to the caller. | 245 // Everything is valid, so return the shared secret to the caller. |
| 228 dict->GetStringWithoutPathExpansion("access_token", &shared_secret); | 246 dict->GetStringWithoutPathExpansion("access_token", &shared_secret); |
| 229 return shared_secret; | 247 return shared_secret; |
| 230 } | 248 } |
| 231 | 249 |
| 232 } // namespace remoting | 250 } // namespace remoting |
| OLD | NEW |