OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/extensions/api/platform_keys/platform_keys_api.h" | 5 #include "chrome/browser/extensions/api/platform_keys/platform_keys_api.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "chrome/browser/chromeos/platform_keys/platform_keys.h" | 11 #include "chrome/browser/chromeos/platform_keys/platform_keys.h" |
12 #include "chrome/browser/chromeos/platform_keys/platform_keys_service.h" | 12 #include "chrome/browser/chromeos/platform_keys/platform_keys_service.h" |
13 #include "chrome/browser/chromeos/platform_keys/platform_keys_service_factory.h" | 13 #include "chrome/browser/chromeos/platform_keys/platform_keys_service_factory.h" |
14 #include "chrome/common/extensions/api/platform_keys_internal.h" | 14 #include "chrome/common/extensions/api/platform_keys_internal.h" |
15 #include "content/public/browser/browser_thread.h" | 15 #include "content/public/browser/browser_thread.h" |
16 #include "net/cert/x509_certificate.h" | 16 #include "net/cert/x509_certificate.h" |
17 | 17 |
18 namespace extensions { | 18 namespace extensions { |
19 | 19 |
| 20 namespace api_pk = api::platform_keys; |
20 namespace api_pki = api::platform_keys_internal; | 21 namespace api_pki = api::platform_keys_internal; |
21 | 22 |
22 namespace platform_keys { | 23 namespace platform_keys { |
23 | 24 |
24 const char kErrorInvalidToken[] = "The token is not valid."; | 25 const char kErrorInvalidToken[] = "The token is not valid."; |
25 const char kErrorAlgorithmNotSupported[] = "Algorithm not supported."; | 26 const char kErrorAlgorithmNotSupported[] = "Algorithm not supported."; |
26 const char kTokenIdUser[] = "user"; | 27 const char kTokenIdUser[] = "user"; |
27 const char kTokenIdSystem[] = "system"; | 28 const char kTokenIdSystem[] = "system"; |
28 | 29 |
29 // Returns whether |token_id| references a known Token. | 30 // Returns whether |token_id| references a known Token. |
(...skipping 16 matching lines...) Expand all Loading... |
46 if (platform_keys_token_id == chromeos::platform_keys::kTokenIdUser) | 47 if (platform_keys_token_id == chromeos::platform_keys::kTokenIdUser) |
47 return kTokenIdUser; | 48 return kTokenIdUser; |
48 if (platform_keys_token_id == chromeos::platform_keys::kTokenIdSystem) | 49 if (platform_keys_token_id == chromeos::platform_keys::kTokenIdSystem) |
49 return kTokenIdSystem; | 50 return kTokenIdSystem; |
50 | 51 |
51 return std::string(); | 52 return std::string(); |
52 } | 53 } |
53 | 54 |
54 } // namespace platform_keys | 55 } // namespace platform_keys |
55 | 56 |
| 57 PlatformKeysInternalSelectClientCertificatesFunction:: |
| 58 ~PlatformKeysInternalSelectClientCertificatesFunction() { |
| 59 } |
| 60 |
| 61 ExtensionFunction::ResponseAction |
| 62 PlatformKeysInternalSelectClientCertificatesFunction::Run() { |
| 63 scoped_ptr<api_pki::SelectClientCertificates::Params> params( |
| 64 api_pki::SelectClientCertificates::Params::Create(*args_)); |
| 65 EXTENSION_FUNCTION_VALIDATE(params); |
| 66 |
| 67 chromeos::PlatformKeysService* service = |
| 68 chromeos::PlatformKeysServiceFactory::GetForBrowserContext( |
| 69 browser_context()); |
| 70 DCHECK(service); |
| 71 |
| 72 chromeos::platform_keys::ClientCertificateRequest request; |
| 73 for (const std::vector<char>& cert_authority : |
| 74 params->details.request.certificate_authorities) { |
| 75 request.certificate_authorities.push_back( |
| 76 std::string(cert_authority.begin(), cert_authority.end())); |
| 77 } |
| 78 |
| 79 service->SelectClientCertificates( |
| 80 request, extension_id(), |
| 81 base::Bind(&PlatformKeysInternalSelectClientCertificatesFunction:: |
| 82 OnSelectedCertificates, |
| 83 this)); |
| 84 return RespondLater(); |
| 85 } |
| 86 |
| 87 void PlatformKeysInternalSelectClientCertificatesFunction:: |
| 88 OnSelectedCertificates(scoped_ptr<net::CertificateList> matches, |
| 89 const std::string& error_message) { |
| 90 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 91 if (!error_message.empty()) { |
| 92 Respond(Error(error_message)); |
| 93 return; |
| 94 } |
| 95 DCHECK(matches); |
| 96 std::vector<linked_ptr<api_pk::Match>> result_matches; |
| 97 for (const scoped_refptr<net::X509Certificate>& match : *matches) { |
| 98 linked_ptr<api_pk::Match> result_match(new api_pk::Match); |
| 99 std::string der_encoded_cert; |
| 100 net::X509Certificate::GetDEREncoded(match->os_cert_handle(), |
| 101 &der_encoded_cert); |
| 102 result_match->certificate.assign(der_encoded_cert.begin(), |
| 103 der_encoded_cert.end()); |
| 104 result_matches.push_back(result_match); |
| 105 } |
| 106 Respond(ArgumentList( |
| 107 api_pki::SelectClientCertificates::Results::Create(result_matches))); |
| 108 } |
| 109 |
56 PlatformKeysInternalSignFunction::~PlatformKeysInternalSignFunction() { | 110 PlatformKeysInternalSignFunction::~PlatformKeysInternalSignFunction() { |
57 } | 111 } |
58 | 112 |
59 ExtensionFunction::ResponseAction PlatformKeysInternalSignFunction::Run() { | 113 ExtensionFunction::ResponseAction PlatformKeysInternalSignFunction::Run() { |
60 scoped_ptr<api_pki::Sign::Params> params( | 114 scoped_ptr<api_pki::Sign::Params> params( |
61 api_pki::Sign::Params::Create(*args_)); | 115 api_pki::Sign::Params::Create(*args_)); |
62 EXTENSION_FUNCTION_VALIDATE(params); | 116 EXTENSION_FUNCTION_VALIDATE(params); |
63 std::string platform_keys_token_id; | 117 std::string platform_keys_token_id; |
64 if (!platform_keys::ValidateToken(params->token_id, &platform_keys_token_id)) | 118 if (!platform_keys::ValidateToken(params->token_id, &platform_keys_token_id)) |
65 return RespondNow(Error(platform_keys::kErrorInvalidToken)); | 119 return RespondNow(Error(platform_keys::kErrorInvalidToken)); |
(...skipping 29 matching lines...) Expand all Loading... |
95 const std::string& error_message) { | 149 const std::string& error_message) { |
96 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 150 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
97 if (error_message.empty()) | 151 if (error_message.empty()) |
98 Respond(ArgumentList(api_pki::Sign::Results::Create( | 152 Respond(ArgumentList(api_pki::Sign::Results::Create( |
99 std::vector<char>(signature.begin(), signature.end())))); | 153 std::vector<char>(signature.begin(), signature.end())))); |
100 else | 154 else |
101 Respond(Error(error_message)); | 155 Respond(Error(error_message)); |
102 } | 156 } |
103 | 157 |
104 } // namespace extensions | 158 } // namespace extensions |
OLD | NEW |