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" |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 ExtensionFunction::ResponseAction | 123 ExtensionFunction::ResponseAction |
124 PlatformKeysInternalGetPublicKeyFunction::Run() { | 124 PlatformKeysInternalGetPublicKeyFunction::Run() { |
125 scoped_ptr<api_pki::GetPublicKey::Params> params( | 125 scoped_ptr<api_pki::GetPublicKey::Params> params( |
126 api_pki::GetPublicKey::Params::Create(*args_)); | 126 api_pki::GetPublicKey::Params::Create(*args_)); |
127 EXTENSION_FUNCTION_VALIDATE(params); | 127 EXTENSION_FUNCTION_VALIDATE(params); |
128 | 128 |
129 const std::vector<char>& cert_der = params->certificate; | 129 const std::vector<char>& cert_der = params->certificate; |
130 if (cert_der.empty()) | 130 if (cert_der.empty()) |
131 return RespondNow(Error(platform_keys::kErrorInvalidX509Cert)); | 131 return RespondNow(Error(platform_keys::kErrorInvalidX509Cert)); |
132 scoped_refptr<net::X509Certificate> cert_x509 = | 132 scoped_refptr<net::X509Certificate> cert_x509 = |
133 net::X509Certificate::CreateFromBytes(vector_as_array(&cert_der), | 133 net::X509Certificate::CreateFromBytes(cert_der.data(), cert_der.size()); |
134 cert_der.size()); | |
135 if (!cert_x509) | 134 if (!cert_x509) |
136 return RespondNow(Error(platform_keys::kErrorInvalidX509Cert)); | 135 return RespondNow(Error(platform_keys::kErrorInvalidX509Cert)); |
137 | 136 |
138 PublicKeyInfo key_info; | 137 PublicKeyInfo key_info; |
139 key_info.public_key_spki_der = | 138 key_info.public_key_spki_der = |
140 chromeos::platform_keys::GetSubjectPublicKeyInfo(cert_x509); | 139 chromeos::platform_keys::GetSubjectPublicKeyInfo(cert_x509); |
141 if (!chromeos::platform_keys::GetPublicKey(cert_x509, &key_info.key_type, | 140 if (!chromeos::platform_keys::GetPublicKey(cert_x509, &key_info.key_type, |
142 &key_info.key_size_bits) || | 141 &key_info.key_size_bits) || |
143 key_info.key_type != net::X509Certificate::kPublicKeyTypeRSA) { | 142 key_info.key_type != net::X509Certificate::kPublicKeyTypeRSA) { |
144 return RespondNow(Error(kErrorAlgorithmNotSupported)); | 143 return RespondNow(Error(kErrorAlgorithmNotSupported)); |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
199 } | 198 } |
200 | 199 |
201 scoped_ptr<net::CertificateList> client_certs; | 200 scoped_ptr<net::CertificateList> client_certs; |
202 if (params->details.client_certs) { | 201 if (params->details.client_certs) { |
203 client_certs.reset(new net::CertificateList); | 202 client_certs.reset(new net::CertificateList); |
204 for (const std::vector<char>& client_cert_der : | 203 for (const std::vector<char>& client_cert_der : |
205 *params->details.client_certs) { | 204 *params->details.client_certs) { |
206 if (client_cert_der.empty()) | 205 if (client_cert_der.empty()) |
207 return RespondNow(Error(platform_keys::kErrorInvalidX509Cert)); | 206 return RespondNow(Error(platform_keys::kErrorInvalidX509Cert)); |
208 scoped_refptr<net::X509Certificate> client_cert_x509 = | 207 scoped_refptr<net::X509Certificate> client_cert_x509 = |
209 net::X509Certificate::CreateFromBytes( | 208 net::X509Certificate::CreateFromBytes(client_cert_der.data(), |
210 vector_as_array(&client_cert_der), client_cert_der.size()); | 209 client_cert_der.size()); |
211 if (!client_cert_x509) | 210 if (!client_cert_x509) |
212 return RespondNow(Error(platform_keys::kErrorInvalidX509Cert)); | 211 return RespondNow(Error(platform_keys::kErrorInvalidX509Cert)); |
213 client_certs->push_back(client_cert_x509); | 212 client_certs->push_back(client_cert_x509); |
214 } | 213 } |
215 } | 214 } |
216 | 215 |
217 content::WebContents* web_contents = nullptr; | 216 content::WebContents* web_contents = nullptr; |
218 if (params->details.interactive) { | 217 if (params->details.interactive) { |
219 web_contents = GetSenderWebContents(); | 218 web_contents = GetSenderWebContents(); |
220 | 219 |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
382 result.debug_errors.push_back(kCertStatusErrors[i].name); | 381 result.debug_errors.push_back(kCertStatusErrors[i].name); |
383 } | 382 } |
384 } | 383 } |
385 } | 384 } |
386 | 385 |
387 Respond(ArgumentList( | 386 Respond(ArgumentList( |
388 api_pk::VerifyTLSServerCertificate::Results::Create(result))); | 387 api_pk::VerifyTLSServerCertificate::Results::Create(result))); |
389 } | 388 } |
390 | 389 |
391 } // namespace extensions | 390 } // namespace extensions |
OLD | NEW |