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