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

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: Changed to OO-style API with Token object. 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 const char kTokenNameUser[] = "User";
19
20 bool ECIImport::RunImpl() {
21 scoped_ptr<api_eci::ImportClientCertificateAndRawKey::Params> params(
22 api_eci::ImportClientCertificateAndRawKey::Params::Create(*args_));
23 EXTENSION_FUNCTION_VALIDATE(params.get());
24
25 GetNSSCertDatabaseForProfile(
26 GetProfile(), base::Bind(&ECIImport::DidGetCertDB, this));
Ryan Sleevi 2014/04/15 00:15:04 This file should either be suffixed with _nss or i
pneubeck (no reviews) 2014/05/02 17:44:02 Done.
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::ImportClientCertificateAndRawKey::Params> params(
38 api_eci::ImportClientCertificateAndRawKey::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 bool ECIGetCerts::RunImpl() {
70 scoped_ptr<api_eci::GetClientCertificates::Params> params(
71 api_eci::GetClientCertificates::Params::Create(*args_));
72 EXTENSION_FUNCTION_VALIDATE(params.get());
73
74 GetNSSCertDatabaseForProfile(GetProfile(),
75 base::Bind(&ECIGetCerts::DidGetCertDB, this));
76 return true;
77 }
78
79 void ECIGetCerts::DidGetCertDB(net::NSSCertDatabase* cert_db) {
80 if (!cert_db) {
81 LOG(ERROR) << "Couldn't get NSSCertDatabase.";
82 SendResponse(false);
83 return;
84 }
85
86 cert_db->ListCerts(base::Bind(&ECIGetCerts::DidGetCerts, this));
87 }
88
89 void ECIGetCerts::DidGetCerts(scoped_ptr<net::CertificateList> certs) {
90 scoped_ptr<api_eci::GetClientCertificates::Params> params(
91 api_eci::GetClientCertificates::Params::Create(*args_));
92
93 /*
94 crypto::ScopedPK11Slot private_slot(cert_db->GetPrivateSlot());
95 if (!private_slot) {
96 LOG(ERROR) << "No private slot";
97 SendResponse(false);
98 return;
99 }
100 */
101
102 /*
103 const std::string& cert_der = params->certificate;
104 scoped_refptr<net::X509Certificate> cert =
105 net::X509Certificate::CreateFromBytes(cert_der.data(), cert_der.size());
106 if (!cert) {
107 LOG(ERROR) << "Could not parse X509 cert.";
108 SendResponse(false);
109 return;
110 }
111
112 scoped_refptr<net::CryptoModule> module(
113 net::CryptoModule::CreateFromHandle(private_slot.get()));
114 const std::string& pkcs8 = params->key;
115 if (!cert_db->ImportPKCS8KeyAndCertificate(pkcs8, cert.get(), module.get())) {
116 LOG(ERROR) << "Could not import key or cert.";
117 SendResponse(false);
118 return;
119 }
120 */
121
122 SendResponse(true);
123 return;
124 }
125
126 bool ECIGetTokens::RunImpl() {
127 EXTENSION_FUNCTION_VALIDATE(args_->empty());
128
129 std::vector<std::string> token_names;
130 token_names.push_back(kTokenNameUser);
131 results_ = api_eci::GetTokens::Results::Create(token_names);
132 SendResponse(true);
133 return true;
134 }
135 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698