Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(674)

Side by Side Diff: chrome/browser/extensions/api/enterprise_certificates/enterprise_certificates_internal_api.cc

Issue 214863002: Extension API enterprise.platformKeys. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Allow import of non-extractable keys. Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/extensions/api/enterprise_certificates/enterprise_certi ficates_internal_api.h"
6
7 #include "base/logging.h"
8 #include "chrome/browser/net/nss_context.h"
9 #include "chrome/common/extensions/api/enterprise_certificates_internal.h"
10 #include "net/base/crypto_module.h"
11 #include "net/base/net_errors.h"
12 #include "net/cert/nss_cert_database.h"
13 #include "net/cert/x509_certificate.h"
14
15 namespace extensions {
16 namespace api_eci = api::enterprise_certificates_internal;
17
18 bool ECIImport::RunImpl() {
19 LOG(ERROR) << "Called internal import";
20
21 scoped_ptr<api_eci::ImportClientCertificate::Params> params(
22 api_eci::ImportClientCertificate::Params::Create(*args_));
23 EXTENSION_FUNCTION_VALIDATE(params.get());
24
25 GetNSSCertDatabaseForProfile(
26 GetProfile(), base::Bind(&ECIImport::DidGetCertDB, this));
27 return true;
28 }
29
30 void ECIImport::DidGetCertDB(net::NSSCertDatabase* cert_db) {
31 if (!cert_db) {
32 LOG(ERROR) << "Couldn't get NSSCertDatabase.";
33 SendResponse(false);
34 return;
35 }
36
37 scoped_ptr<api_eci::ImportClientCertificate::Params> params(
38 api_eci::ImportClientCertificate::Params::Create(*args_));
39
40 const std::string& cert_der = params->certificate;
41 scoped_refptr<net::X509Certificate> cert =
42 net::X509Certificate::CreateFromBytes(cert_der.data(), cert_der.size());
43 if (!cert) {
44 LOG(ERROR) << "Could not parse X509 cert.";
45 SendResponse(false);
46 return;
47 }
48
49 crypto::ScopedPK11Slot private_slot(cert_db->GetPrivateSlot());
50 if (!private_slot) {
51 LOG(ERROR) << "No private slot";
52 SendResponse(false);
53 return;
54 }
55
56 scoped_refptr<net::CryptoModule> module(
57 net::CryptoModule::CreateFromHandle(private_slot.get()));
58 const std::string& pkcs8 = params->key;
59 if (!cert_db->ImportPKCS8KeyAndCertificate(pkcs8, cert.get(), module.get())) {
60 LOG(ERROR) << "Could not import key or cert.";
61 SendResponse(false);
62 return;
63 }
64
65 SendResponse(true);
66 return;
67 }
68
69 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698