| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 "chrome/browser/chromeos/attestation/attestation_ca_client.h" | 5 #include "chrome/browser/chromeos/attestation/attestation_ca_client.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/command_line.h" |
| 9 #include "chrome/browser/browser_process.h" | 10 #include "chrome/browser/browser_process.h" |
| 11 #include "chromeos/chromeos_switches.h" |
| 10 #include "net/base/load_flags.h" | 12 #include "net/base/load_flags.h" |
| 11 #include "net/http/http_status_code.h" | 13 #include "net/http/http_status_code.h" |
| 12 #include "net/url_request/url_fetcher.h" | 14 #include "net/url_request/url_fetcher.h" |
| 13 #include "net/url_request/url_request_status.h" | 15 #include "net/url_request/url_request_status.h" |
| 14 #include "url/gurl.h" | 16 #include "url/gurl.h" |
| 15 | 17 |
| 16 namespace { | 18 namespace { |
| 19 // Values for the attestation server switch. |
| 20 const char kAttestationServerDefault[] = "default"; |
| 21 const char kAttestationServerTest[] = "test"; |
| 17 | 22 |
| 18 const char kCertificateRequestURL[] = "https://chromeos-ca.gstatic.com/sign"; | 23 // Endpoints for the default Google Privacy CA operations. |
| 19 const char kEnrollRequestURL[] = "https://chromeos-ca.gstatic.com/enroll"; | 24 const char kDefaultEnrollRequestURL[] = |
| 25 "https://chromeos-ca.gstatic.com/enroll"; |
| 26 const char kDefaultCertificateRequestURL[] = |
| 27 "https://chromeos-ca.gstatic.com/sign"; |
| 28 |
| 29 // Endpoints for the test Google Privacy CA operations. |
| 30 const char kTestEnrollRequestURL[] = |
| 31 "https://asbestos-qa.corp.google.com/enroll"; |
| 32 const char kTestCertificateRequestURL[] = |
| 33 "https://asbestos-qa.corp.google.com/sign"; |
| 34 |
| 20 const char kMimeContentType[] = "application/octet-stream"; | 35 const char kMimeContentType[] = "application/octet-stream"; |
| 21 | 36 |
| 22 } // namespace | 37 } // namespace |
| 23 | 38 |
| 24 namespace chromeos { | 39 namespace chromeos { |
| 25 namespace attestation { | 40 namespace attestation { |
| 26 | 41 |
| 27 AttestationCAClient::AttestationCAClient() {} | 42 static PrivacyCAType GetAttestationServerType() { |
| 43 std::string value = |
| 44 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| 45 chromeos::switches::kAttestationServer); |
| 46 if (value.empty() || value == kAttestationServerDefault) { |
| 47 return DEFAULT_PCA; |
| 48 } |
| 49 if (value == kAttestationServerTest) { |
| 50 return TEST_PCA; |
| 51 } |
| 52 LOG(WARNING) << "Invalid attestation server value: " << value |
| 53 << ". Using default."; |
| 54 return DEFAULT_PCA; |
| 55 } |
| 56 |
| 57 AttestationCAClient::AttestationCAClient() { |
| 58 pca_type_ = GetAttestationServerType(); |
| 59 } |
| 28 | 60 |
| 29 AttestationCAClient::~AttestationCAClient() {} | 61 AttestationCAClient::~AttestationCAClient() {} |
| 30 | 62 |
| 31 void AttestationCAClient::SendEnrollRequest(const std::string& request, | 63 void AttestationCAClient::SendEnrollRequest(const std::string& request, |
| 32 const DataCallback& on_response) { | 64 const DataCallback& on_response) { |
| 33 FetchURL(kEnrollRequestURL, request, on_response); | 65 FetchURL( |
| 66 GetType() == TEST_PCA ? kTestEnrollRequestURL : kDefaultEnrollRequestURL, |
| 67 request, on_response); |
| 34 } | 68 } |
| 35 | 69 |
| 36 void AttestationCAClient::SendCertificateRequest( | 70 void AttestationCAClient::SendCertificateRequest( |
| 37 const std::string& request, | 71 const std::string& request, |
| 38 const DataCallback& on_response) { | 72 const DataCallback& on_response) { |
| 39 FetchURL(kCertificateRequestURL, request, on_response); | 73 FetchURL(GetType() == TEST_PCA ? kTestCertificateRequestURL |
| 74 : kDefaultCertificateRequestURL, |
| 75 request, on_response); |
| 40 } | 76 } |
| 41 | 77 |
| 42 void AttestationCAClient::OnURLFetchComplete(const net::URLFetcher* source) { | 78 void AttestationCAClient::OnURLFetchComplete(const net::URLFetcher* source) { |
| 43 FetcherCallbackMap::iterator iter = pending_requests_.find(source); | 79 FetcherCallbackMap::iterator iter = pending_requests_.find(source); |
| 44 if (iter == pending_requests_.end()) { | 80 if (iter == pending_requests_.end()) { |
| 45 LOG(WARNING) << "Callback from unknown source."; | 81 LOG(WARNING) << "Callback from unknown source."; |
| 46 return; | 82 return; |
| 47 } | 83 } |
| 48 | 84 |
| 49 DataCallback callback = iter->second; | 85 DataCallback callback = iter->second; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 .release(); | 118 .release(); |
| 83 fetcher->SetRequestContext(g_browser_process->system_request_context()); | 119 fetcher->SetRequestContext(g_browser_process->system_request_context()); |
| 84 fetcher->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES | | 120 fetcher->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES | |
| 85 net::LOAD_DO_NOT_SAVE_COOKIES | | 121 net::LOAD_DO_NOT_SAVE_COOKIES | |
| 86 net::LOAD_DISABLE_CACHE); | 122 net::LOAD_DISABLE_CACHE); |
| 87 fetcher->SetUploadData(kMimeContentType, request); | 123 fetcher->SetUploadData(kMimeContentType, request); |
| 88 pending_requests_[fetcher] = on_response; | 124 pending_requests_[fetcher] = on_response; |
| 89 fetcher->Start(); | 125 fetcher->Start(); |
| 90 } | 126 } |
| 91 | 127 |
| 128 PrivacyCAType AttestationCAClient::GetType() { |
| 129 return pca_type_; |
| 130 } |
| 131 |
| 92 } // namespace attestation | 132 } // namespace attestation |
| 93 } // namespace chromeos | 133 } // namespace chromeos |
| OLD | NEW |