2 * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #include "keymanager/keymanager_instance.h"
19 #include <ckmc/ckmc-manager.h>
22 #include "common/logger.h"
23 #include "common/optional.h"
24 #include "common/platform_result.h"
25 #include "common/scope_exit.h"
26 #include "common/task-queue.h"
27 #include "common/tools.h"
28 #include "common/virtual_fs.h"
31 namespace keymanager {
33 using common::ErrorCode;
34 using common::optional;
35 using common::PlatformResult;
36 using common::TaskQueue;
37 using common::VirtualFs;
41 typedef std::vector<unsigned char> RawBuffer;
43 const char* kTypeRSA = "RSA";
44 const char* kTypeECDSA = "ECDSA";
46 RawBuffer Base64ToRawBuffer(const std::string& base64) {
50 guchar* raw_data = g_base64_decode(base64.c_str(), &len);
54 raw_buffer.assign(raw_data, raw_data + len);
61 std::string RawBufferToBase64(const RawBuffer& buf) {
67 gchar* base64 = g_base64_encode(&buf[0], buf.size());
77 KeyManagerInstance::KeyManagerInstance() {
79 using std::placeholders::_1;
80 using std::placeholders::_2;
82 RegisterSyncHandler("KeyManager_getKeyAliasList",
83 std::bind(&KeyManagerInstance::GetKeyAliasList, this, _1, _2));
84 RegisterSyncHandler("KeyManager_getCertificatesAliasList",
85 std::bind(&KeyManagerInstance::GetCertificateAliasList, this, _1, _2));
86 RegisterSyncHandler("KeyManager_getDataAliasList",
87 std::bind(&KeyManagerInstance::GetDataAliasList, this, _1, _2));
88 RegisterSyncHandler("KeyManager_getKey",
89 std::bind(&KeyManagerInstance::GetKey, this, _1, _2));
90 RegisterSyncHandler("KeyManager_saveKey",
91 std::bind(&KeyManagerInstance::SaveKey, this, _1, _2));
92 RegisterSyncHandler("KeyManager_removeKey",
93 std::bind(&KeyManagerInstance::RemoveKey, this, _1, _2));
94 RegisterSyncHandler("KeyManager_generateKeyPair",
95 std::bind(&KeyManagerInstance::GenerateKeyPair, this, _1, _2));
96 RegisterSyncHandler("KeyManager_getCertificate",
97 std::bind(&KeyManagerInstance::GetCertificate, this, _1, _2));
98 RegisterSyncHandler("KeyManager_saveCertificate",
99 std::bind(&KeyManagerInstance::SaveCertificate, this, _1, _2));
100 RegisterSyncHandler("KeyManager_loadCertificateFromFile",
101 std::bind(&KeyManagerInstance::LoadCertificateFromFile, this, _1, _2));
102 RegisterSyncHandler("KeyManager_removeCertificate",
103 std::bind(&KeyManagerInstance::RemoveCertificate, this, _1, _2));
104 RegisterSyncHandler("KeyManager_saveData",
105 std::bind(&KeyManagerInstance::SaveData, this, _1, _2));
106 RegisterSyncHandler("KeyManager_removeData",
107 std::bind(&KeyManagerInstance::RemoveData, this, _1, _2));
108 RegisterSyncHandler("KeyManager_getData",
109 std::bind(&KeyManagerInstance::GetData, this, _1, _2));
110 RegisterSyncHandler("KeyManager_createSignature",
111 std::bind(&KeyManagerInstance::CreateSignature, this, _1, _2));
112 RegisterSyncHandler("KeyManager_verifySignature",
113 std::bind(&KeyManagerInstance::VerifySignature, this, _1, _2));
114 RegisterSyncHandler("KeyManager_loadFromPKCS12File",
115 std::bind(&KeyManagerInstance::LoadFromPKCS12File, this, _1, _2));
116 RegisterSyncHandler("KeyManager_allowAccessControl",
117 std::bind(&KeyManagerInstance::AllowAccessControl, this, _1, _2));
118 RegisterSyncHandler("KeyManager_denyAccessControl",
119 std::bind(&KeyManagerInstance::DenyAccessControl, this, _1, _2));
122 KeyManagerInstance::~KeyManagerInstance() {
126 void KeyManagerInstance::GetKeyAliasList(const picojson::value& args,
127 picojson::object& out) {
131 void KeyManagerInstance::GetCertificateAliasList(const picojson::value& args,
132 picojson::object& out) {
136 void KeyManagerInstance::GetDataAliasList(const picojson::value& args,
137 picojson::object& out) {
141 void KeyManagerInstance::GetKey(const picojson::value& args,
142 picojson::object& out) {
146 void KeyManagerInstance::SaveKey(const picojson::value& args,
147 picojson::object& out) {
151 void KeyManagerInstance::RemoveKey(const picojson::value& args,
152 picojson::object& out) {
156 void KeyManagerInstance::GenerateKeyPair(const picojson::value& args,
157 picojson::object& out) {
161 void KeyManagerInstance::GetCertificate(const picojson::value& args,
162 picojson::object& out) {
166 void KeyManagerInstance::SaveCertificate(const picojson::value& args,
167 picojson::object& out) {
171 void KeyManagerInstance::LoadCertificateFromFile(const picojson::value& args,
172 picojson::object& out) {
176 void KeyManagerInstance::RemoveCertificate(const picojson::value& args,
177 picojson::object& out) {
181 void KeyManagerInstance::SaveData(const picojson::value& args,
182 picojson::object& out) {
186 void KeyManagerInstance::RemoveData(const picojson::value& args,
187 picojson::object& out) {
191 void KeyManagerInstance::GetData(const picojson::value& args,
192 picojson::object& out) {
196 void KeyManagerInstance::CreateSignature(const picojson::value& args,
197 picojson::object& out) {
201 void KeyManagerInstance::VerifySignature(const picojson::value& args,
202 picojson::object& out) {
206 void KeyManagerInstance::LoadFromPKCS12File(const picojson::value& args,
207 picojson::object& out) {
211 void KeyManagerInstance::AllowAccessControl(const picojson::value& args,
212 picojson::object& out) {
216 void KeyManagerInstance::DenyAccessControl(const picojson::value& args,
217 picojson::object& out) {
221 } // namespace keymanager
222 } // namespace extension