2 * Copyright (c) 2000 - 2014 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
18 * @author Bartlomiej Grzelewski (b.grzelewski@samsung.com)
20 * @brief Sample service implementation.
22 #include <dpl/serialization.h>
23 #include <dpl/log/log.h>
24 #include <ckm/ckm-error.h>
25 #include <ckm/ckm-type.h>
26 #include <key-provider.h>
27 #include <file-system.h>
28 #include <CryptoService.h>
29 #include <ckm-logic.h>
33 const char * const CERT_SYSTEM_DIR = "/etc/ssl/certs";
34 } // anonymous namespace
40 int retCode = FileSystem::init();
41 // TODO what can I do when init went wrong? exit(-1) ??
43 LogError("Fatal error in FileSystem::init()");
46 if (CKM_API_SUCCESS != m_certStore.setSystemCertificateDir(CERT_SYSTEM_DIR)) {
47 LogError("Fatal error in CertificateStore::setSystemCertificateDir. Chain creation will not work");
50 cc_mode_status = CCModeState::CC_MODE_OFF;
53 CKMLogic::~CKMLogic(){}
55 RawBuffer CKMLogic::unlockUserKey(uid_t user, const Password &password) {
56 // TODO try catch for all errors that should be supported by error code
57 int retCode = CKM_API_SUCCESS;
60 if (0 == m_userDataMap.count(user) || !(m_userDataMap[user].keyProvider.isInitialized())) {
61 auto &handle = m_userDataMap[user];
63 auto wrappedDomainKEK = fs.getDKEK();
65 if (wrappedDomainKEK.empty()) {
66 wrappedDomainKEK = KeyProvider::generateDomainKEK(std::to_string(user), password);
67 fs.saveDKEK(wrappedDomainKEK);
70 handle.keyProvider = KeyProvider(wrappedDomainKEK, password);
72 auto wrappedDatabaseDEK = fs.getDBDEK();
74 if (wrappedDatabaseDEK.empty()) {
75 wrappedDatabaseDEK = handle.keyProvider.generateDEK(std::to_string(user));
76 fs.saveDBDEK(wrappedDatabaseDEK);
79 RawBuffer key = handle.keyProvider.getPureDEK(wrappedDatabaseDEK);
80 handle.database = DBCrypto(fs.getDBPath(), key);
81 handle.crypto = CryptoLogic();
83 // remove data of removed apps during locked state
84 AppLabelVector removedApps = fs.clearRemovedsApps();
85 for(auto& appSmackLabel : removedApps) {
86 handle.database.deleteKey(appSmackLabel);
91 } catch (const KeyProvider::Exception::PassWordError &e) {
92 LogError("Incorrect Password " << e.GetMessage());
93 retCode = CKM_API_ERROR_AUTHENTICATION_FAILED;
94 } catch (const KeyProvider::Exception::Base &e) {
95 LogError("Error in KeyProvider " << e.GetMessage());
96 retCode = CKM_API_ERROR_SERVER_ERROR;
97 } catch (const CryptoLogic::Exception::Base &e) {
98 LogError("CryptoLogic error: " << e.GetMessage());
99 retCode = CKM_API_ERROR_SERVER_ERROR;
100 } catch (const CKM::Exception &e) {
101 LogError("CKM::Exception: " << e.GetMessage());
102 retCode = CKM_API_ERROR_SERVER_ERROR;
105 if(retCode != CKM_API_SUCCESS) {
106 // When not successful, UserData in m_userDataMap should be erased.
107 // Because other operations make decision based on the existence of UserData in m_userDataMap.
108 m_userDataMap.erase(user);
111 MessageBuffer response;
112 Serialization::Serialize(response, retCode);
113 return response.Pop();
116 RawBuffer CKMLogic::setCCModeStatus(CCModeState mode_status) {
118 int retCode = CKM_API_SUCCESS;
120 if((mode_status != CCModeState:: CC_MODE_OFF) && (mode_status != CCModeState:: CC_MODE_ON)) {
121 retCode = CKM_API_ERROR_INPUT_PARAM;
124 cc_mode_status = mode_status;
126 MessageBuffer response;
127 Serialization::Serialize(response, retCode);
128 return response.Pop();
131 RawBuffer CKMLogic::lockUserKey(uid_t user) {
132 int retCode = CKM_API_SUCCESS;
133 // TODO try catch for all errors that should be supported by error code
134 m_userDataMap.erase(user);
136 MessageBuffer response;
137 Serialization::Serialize(response, retCode);
138 return response.Pop();
141 RawBuffer CKMLogic::removeUserData(uid_t user) {
142 int retCode = CKM_API_SUCCESS;
143 // TODO try catch for all errors that should be supported by error code
144 m_userDataMap.erase(user);
149 MessageBuffer response;
150 Serialization::Serialize(response, retCode);
151 return response.Pop();
154 RawBuffer CKMLogic::changeUserPassword(
156 const Password &oldPassword,
157 const Password &newPassword)
159 int retCode = CKM_API_SUCCESS;
162 auto wrappedDomainKEK = fs.getDKEK();
163 if (wrappedDomainKEK.empty()) {
164 retCode = CKM_API_ERROR_BAD_REQUEST;
166 wrappedDomainKEK = KeyProvider::reencrypt(wrappedDomainKEK, oldPassword, newPassword);
167 fs.saveDKEK(wrappedDomainKEK);
169 } catch (const KeyProvider::Exception::PassWordError &e) {
170 LogError("Incorrect Password " << e.GetMessage());
171 retCode = CKM_API_ERROR_AUTHENTICATION_FAILED;
172 } catch (const KeyProvider::Exception::Base &e) {
173 LogError("Error in KeyProvider " << e.GetMessage());
174 retCode = CKM_API_ERROR_SERVER_ERROR;
175 } catch (const CKM::Exception &e) {
176 LogError("CKM::Exception: " << e.GetMessage());
177 retCode = CKM_API_ERROR_SERVER_ERROR;
180 MessageBuffer response;
181 Serialization::Serialize(response, retCode);
182 return response.Pop();
185 RawBuffer CKMLogic::resetUserPassword(
187 const Password &newPassword)
189 int retCode = CKM_API_SUCCESS;
191 if (0 == m_userDataMap.count(user)) {
192 retCode = CKM_API_ERROR_BAD_REQUEST;
194 auto &handler = m_userDataMap[user];
196 fs.saveDKEK(handler.keyProvider.getWrappedDomainKEK(newPassword));
199 MessageBuffer response;
200 Serialization::Serialize(response, retCode);
201 return response.Pop();
204 RawBuffer CKMLogic::removeApplicationData(const std::string &smackLabel) {
205 int retCode = CKM_API_SUCCESS;
209 if (smackLabel.empty()) {
210 retCode = CKM_API_ERROR_INPUT_PARAM;
212 UidVector uids = FileSystem::getUIDsFromDBFile();
213 for (auto userId : uids) {
214 if (0 == m_userDataMap.count(userId)) {
215 FileSystem fs(userId);
216 fs.addRemovedApp(smackLabel);
218 auto &handle = m_userDataMap[userId];
219 handle.database.deleteKey(smackLabel);
224 } catch (const DBCrypto::Exception::InternalError &e) {
225 LogError("DBCrypto couldn't remove data: " << e.GetMessage());
226 retCode = CKM_API_ERROR_DB_ERROR;
227 } catch (const DBCrypto::Exception::TransactionError &e) {
228 LogError("DBCrypto transaction failed with message " << e.GetMessage());
229 retCode = CKM_API_ERROR_DB_ERROR;
232 MessageBuffer response;
233 Serialization::Serialize(response, retCode);
234 return response.Pop();
237 int CKMLogic::saveDataHelper(
241 const RawBuffer &key,
242 const PolicySerializable &policy)
244 if (0 == m_userDataMap.count(cred.uid))
245 return CKM_API_ERROR_DB_LOCKED;
247 DBRow row = { alias, cred.smackLabel,
248 policy.extractable, dataType, DBCMAlgType::NONE,
249 0, RawBuffer(), static_cast<int>(key.size()), key, RawBuffer() };
251 auto &handler = m_userDataMap[cred.uid];
252 DBCrypto::Transaction transaction(&handler.database);
253 if (!handler.crypto.haveKey(cred.smackLabel)) {
255 auto key_optional = handler.database.getKey(cred.smackLabel);
257 LogDebug("No Key in database found. Generating new one for label: "
259 key = handler.keyProvider.generateDEK(cred.smackLabel);
260 handler.database.saveKey(cred.smackLabel, key);
262 LogDebug("Key from DB");
266 key = handler.keyProvider.getPureDEK(key);
267 handler.crypto.pushKey(cred.smackLabel, key);
270 // Do not encrypt data with password during cc_mode on
271 if(cc_mode_status == CCModeState::CC_MODE_ON) {
272 handler.crypto.encryptRow("", row);
274 handler.crypto.encryptRow(policy.password, row);
277 handler.database.saveDBRow(row);
278 transaction.commit();
279 return CKM_API_SUCCESS;
282 RawBuffer CKMLogic::saveData(
287 const RawBuffer &key,
288 const PolicySerializable &policy)
290 int retCode = CKM_API_SUCCESS;
292 retCode = saveDataHelper(cred, dataType, alias, key, policy);
293 LogDebug("SaveDataHelper returned: " << retCode);
294 } catch (const KeyProvider::Exception::Base &e) {
295 LogError("KeyProvider failed with message: " << e.GetMessage());
296 retCode = CKM_API_ERROR_SERVER_ERROR;
297 } catch (const CryptoLogic::Exception::Base &e) {
298 LogError("CryptoLogic failed with message: " << e.GetMessage());
299 retCode = CKM_API_ERROR_SERVER_ERROR;
300 } catch (const DBCrypto::Exception::InternalError &e) {
301 LogError("DBCrypto failed with message: " << e.GetMessage());
302 retCode = CKM_API_ERROR_DB_ERROR;
303 } catch (const DBCrypto::Exception::AliasExists &e) {
304 LogError("DBCrypto couldn't save duplicate alias");
305 retCode = CKM_API_ERROR_DB_ALIAS_EXISTS;
306 } catch (const DBCrypto::Exception::TransactionError &e) {
307 LogError("DBCrypto transaction failed with message " << e.GetMessage());
308 retCode = CKM_API_ERROR_DB_ERROR;
311 MessageBuffer response;
312 Serialization::Serialize(response, static_cast<int>(LogicCommand::SAVE));
313 Serialization::Serialize(response, commandId);
314 Serialization::Serialize(response, retCode);
315 Serialization::Serialize(response, static_cast<int>(dataType));
317 return response.Pop();
320 RawBuffer CKMLogic::removeData(
326 int retCode = CKM_API_SUCCESS;
328 if (0 < m_userDataMap.count(cred.uid)) {
330 auto erased = m_userDataMap[cred.uid].database.deleteDBRow(alias, cred.smackLabel);
331 // check if the data existed or not
333 LogError("No row for given alias and label");
334 retCode = CKM_API_ERROR_DB_ALIAS_UNKNOWN;
336 } Catch (CKM::Exception) {
337 LogError("Error in deleting row!");
338 retCode = CKM_API_ERROR_DB_ERROR;
341 retCode = CKM_API_ERROR_DB_LOCKED;
344 MessageBuffer response;
345 Serialization::Serialize(response, static_cast<int>(LogicCommand::REMOVE));
346 Serialization::Serialize(response, commandId);
347 Serialization::Serialize(response, retCode);
348 Serialization::Serialize(response, static_cast<int>(dataType));
350 return response.Pop();
353 int CKMLogic::getDataHelper(
357 const Password &password,
361 if (0 == m_userDataMap.count(cred.uid))
362 return CKM_API_ERROR_DB_LOCKED;
364 auto &handler = m_userDataMap[cred.uid];
366 DBCrypto::DBRowOptional row_optional;
367 if (dataType == DBDataType::CERTIFICATE || dataType == DBDataType::BINARY_DATA) {
368 row_optional = handler.database.getDBRow(alias, cred.smackLabel, dataType);
369 } else if ((static_cast<int>(dataType) >= static_cast<int>(DBDataType::DB_KEY_FIRST))
370 && (static_cast<int>(dataType) <= static_cast<int>(DBDataType::DB_KEY_LAST)))
372 row_optional = handler.database.getKeyDBRow(alias, cred.smackLabel);
374 LogError("Unknown type of requested data" << (int)dataType);
375 return CKM_API_ERROR_BAD_REQUEST;
378 LogError("No row for given alias, label and type");
379 return CKM_API_ERROR_DB_ALIAS_UNKNOWN;
384 if (!handler.crypto.haveKey(row.smackLabel)) {
386 auto key_optional = handler.database.getKey(row.smackLabel);
388 LogError("No key for given label in database");
389 return CKM_API_ERROR_DB_ERROR;
392 key = handler.keyProvider.getPureDEK(key);
393 handler.crypto.pushKey(cred.smackLabel, key);
395 handler.crypto.decryptRow(password, row);
397 return CKM_API_SUCCESS;
400 RawBuffer CKMLogic::getData(
405 const Password &password)
407 int retCode = CKM_API_SUCCESS;
411 retCode = getDataHelper(cred, dataType, alias, password, row);
412 } catch (const KeyProvider::Exception::Base &e) {
413 LogError("KeyProvider failed with error: " << e.GetMessage());
414 retCode = CKM_API_ERROR_SERVER_ERROR;
415 } catch (const CryptoLogic::Exception::Base &e) {
416 LogError("CryptoLogic failed with message: " << e.GetMessage());
417 retCode = CKM_API_ERROR_SERVER_ERROR;
418 } catch (const DBCrypto::Exception::Base &e) {
419 LogError("DBCrypto failed with message: " << e.GetMessage());
420 retCode = CKM_API_ERROR_DB_ERROR;
423 if (CKM_API_SUCCESS != retCode) {
425 row.dataType = dataType;
428 if ((CKM_API_SUCCESS == retCode) && (row.exportable == 0)) {
430 retCode = CKM_API_ERROR_NOT_EXPORTABLE;
433 // Prevent extracting private keys during cc-mode on
434 if((cc_mode_status == CCModeState::CC_MODE_ON) && (row.dataType == DBDataType::KEY_RSA_PRIVATE || row.dataType == DBDataType::KEY_ECDSA_PRIVATE || row.dataType == DBDataType::KEY_DSA_PRIVATE)) {
436 retCode = CKM_API_ERROR_BAD_REQUEST;
439 MessageBuffer response;
440 Serialization::Serialize(response, static_cast<int>(LogicCommand::GET));
441 Serialization::Serialize(response, commandId);
442 Serialization::Serialize(response, retCode);
443 Serialization::Serialize(response, static_cast<int>(row.dataType));
444 Serialization::Serialize(response, row.data);
445 return response.Pop();
448 RawBuffer CKMLogic::getDataList(
453 int retCode = CKM_API_SUCCESS;
454 AliasVector aliasVector;
456 if (0 < m_userDataMap.count(cred.uid)) {
457 auto &handler = m_userDataMap[cred.uid];
459 if (dataType == DBDataType::CERTIFICATE || dataType == DBDataType::BINARY_DATA) {
460 handler.database.getAliases(dataType, cred.smackLabel, aliasVector);
462 handler.database.getKeyAliases(cred.smackLabel, aliasVector);
464 } Catch (CKM::Exception) {
465 LogError("Failed to get aliases");
466 retCode = CKM_API_ERROR_DB_ERROR;
469 retCode = CKM_API_ERROR_DB_LOCKED;
472 MessageBuffer response;
473 Serialization::Serialize(response, static_cast<int>(LogicCommand::GET_LIST));
474 Serialization::Serialize(response, commandId);
475 Serialization::Serialize(response, retCode);
476 Serialization::Serialize(response, static_cast<int>(dataType));
477 Serialization::Serialize(response, aliasVector);
478 return response.Pop();
482 int CKMLogic::createKeyPairHelper(
484 const KeyType key_type,
485 const int additional_param,
486 const Alias &aliasPrivate,
487 const Alias &aliasPublic,
488 const PolicySerializable &policyPrivate,
489 const PolicySerializable &policyPublic)
491 if (0 >= m_userDataMap.count(cred.uid))
492 return CKM_API_ERROR_DB_LOCKED;
494 auto &handler = m_userDataMap[cred.uid];
499 case KeyType::KEY_RSA_PUBLIC:
500 case KeyType::KEY_RSA_PRIVATE:
501 retCode = CryptoService::createKeyPairRSA(additional_param, prv, pub);
504 case KeyType::KEY_DSA_PUBLIC:
505 case KeyType::KEY_DSA_PRIVATE:
506 retCode = CryptoService::createKeyPairDSA(additional_param, prv, pub);
509 case KeyType::KEY_ECDSA_PUBLIC:
510 case KeyType::KEY_ECDSA_PRIVATE:
511 retCode = CryptoService::createKeyPairECDSA(static_cast<ElipticCurve>(additional_param), prv, pub);
515 return CKM_API_ERROR_INPUT_PARAM;
518 if (CKM_CRYPTO_CREATEKEY_SUCCESS != retCode)
520 LogDebug("CryptoService error with code: " << retCode);
521 return CKM_API_ERROR_SERVER_ERROR; // TODO error code
524 DBCrypto::Transaction transaction(&handler.database);
525 retCode = saveDataHelper(cred,
526 toDBDataType(prv.getType()),
531 if (CKM_API_SUCCESS != retCode)
534 retCode = saveDataHelper(cred,
535 toDBDataType(pub.getType()),
540 if (CKM_API_SUCCESS != retCode)
543 transaction.commit();
548 RawBuffer CKMLogic::createKeyPair(
550 LogicCommand protocol_cmd,
552 const int additional_param,
553 const Alias &aliasPrivate,
554 const Alias &aliasPublic,
555 const PolicySerializable &policyPrivate,
556 const PolicySerializable &policyPublic)
558 int retCode = CKM_API_SUCCESS;
560 KeyType key_type = KeyType::KEY_NONE;
563 case LogicCommand::CREATE_KEY_PAIR_RSA:
564 key_type = KeyType::KEY_RSA_PUBLIC;
566 case LogicCommand::CREATE_KEY_PAIR_DSA:
567 key_type = KeyType::KEY_DSA_PUBLIC;
569 case LogicCommand::CREATE_KEY_PAIR_ECDSA:
570 key_type = KeyType::KEY_ECDSA_PUBLIC;
577 retCode = createKeyPairHelper(
586 } catch (DBCrypto::Exception::AliasExists &e) {
587 LogDebug("DBCrypto error: alias exists: " << e.GetMessage());
588 retCode = CKM_API_ERROR_DB_ALIAS_EXISTS;
589 } catch (DBCrypto::Exception::TransactionError &e) {
590 LogDebug("DBCrypto error: transaction error: " << e.GetMessage());
591 retCode = CKM_API_ERROR_DB_ERROR;
592 } catch (CKM::CryptoLogic::Exception::Base &e) {
593 LogDebug("CryptoLogic error: " << e.GetMessage());
594 retCode = CKM_API_ERROR_SERVER_ERROR;
595 } catch (DBCrypto::Exception::InternalError &e) {
596 LogDebug("DBCrypto internal error: " << e.GetMessage());
597 retCode = CKM_API_ERROR_DB_ERROR;
600 MessageBuffer response;
601 Serialization::Serialize(response, static_cast<int>(protocol_cmd));
602 Serialization::Serialize(response, commandId);
603 Serialization::Serialize(response, retCode);
605 return response.Pop();
608 RawBuffer CKMLogic::getCertificateChain(
611 const RawBuffer &certificate,
612 const RawBufferVector &untrustedRawCertVector)
616 CertificateImpl cert(certificate, DataFormat::FORM_DER);
617 CertificateImplVector untrustedCertVector;
618 CertificateImplVector chainVector;
619 RawBufferVector chainRawVector;
621 for (auto &e: untrustedRawCertVector)
622 untrustedCertVector.push_back(CertificateImpl(e, DataFormat::FORM_DER));
624 LogDebug("Cert is empty: " << cert.empty());
626 int retCode = m_certStore.verifyCertificate(cert, untrustedCertVector, chainVector);
628 if (retCode == CKM_API_SUCCESS) {
629 for (auto &e : chainVector)
630 chainRawVector.push_back(e.getDER());
633 MessageBuffer response;
634 Serialization::Serialize(response, static_cast<int>(LogicCommand::GET_CHAIN_CERT));
635 Serialization::Serialize(response, commandId);
636 Serialization::Serialize(response, retCode);
637 Serialization::Serialize(response, chainRawVector);
638 return response.Pop();
641 RawBuffer CKMLogic::getCertificateChain(
644 const RawBuffer &certificate,
645 const AliasVector &aliasVector)
647 int retCode = CKM_API_SUCCESS;
648 RawBufferVector chainRawVector;
650 CertificateImpl cert(certificate, DataFormat::FORM_DER);
651 CertificateImplVector untrustedCertVector;
652 CertificateImplVector chainVector;
656 retCode = CKM_API_ERROR_SERVER_ERROR;
660 for (auto &i: aliasVector) {
661 retCode = getDataHelper(cred, DBDataType::CERTIFICATE, i, Password(), row);
663 if (retCode != CKM_API_SUCCESS)
666 untrustedCertVector.push_back(CertificateImpl(row.data, DataFormat::FORM_DER));
669 retCode = m_certStore.verifyCertificate(cert, untrustedCertVector, chainVector);
671 if (retCode != CKM_API_SUCCESS)
674 for (auto &i: chainVector)
675 chainRawVector.push_back(i.getDER());
677 } catch (const CryptoLogic::Exception::Base &e) {
678 LogError("DBCyptorModule failed with message: " << e.GetMessage());
679 retCode = CKM_API_ERROR_SERVER_ERROR;
680 } catch (const DBCrypto::Exception::Base &e) {
681 LogError("DBCrypto failed with message: " << e.GetMessage());
682 retCode = CKM_API_ERROR_DB_ERROR;
684 LogError("Unknown error.");
688 MessageBuffer response;
689 Serialization::Serialize(response, static_cast<int>(LogicCommand::GET_CHAIN_ALIAS));
690 Serialization::Serialize(response, commandId);
691 Serialization::Serialize(response, retCode);
692 Serialization::Serialize(response, chainRawVector);
693 return response.Pop();
696 RawBuffer CKMLogic::createSignature(
699 const Alias &privateKeyAlias,
700 const Password &password, // password for private_key
701 const RawBuffer &message,
702 const HashAlgorithm hash,
703 const RSAPaddingAlgorithm padding)
709 int retCode = CKM_API_SUCCESS;
713 retCode = getDataHelper(cred, DBDataType::DB_KEY_FIRST, privateKeyAlias, password, row);
714 if (CKM_API_SUCCESS != retCode) {
715 LogError("getDataHelper return error");
719 KeyImpl keyParsed(row.data, Password());
720 if (keyParsed.empty())
721 retCode = CKM_API_ERROR_SERVER_ERROR;
723 retCode = cs.createSignature(keyParsed, message, hash, padding, signature);
725 } catch (const KeyProvider::Exception::Base &e) {
726 LogError("KeyProvider failed with message: " << e.GetMessage());
727 retCode = CKM_API_ERROR_SERVER_ERROR;
728 } catch (const CryptoLogic::Exception::Base &e) {
729 LogError("CryptoLogic failed with message: " << e.GetMessage());
730 retCode = CKM_API_ERROR_SERVER_ERROR;
731 } catch (const DBCrypto::Exception::Base &e) {
732 LogError("DBCrypto failed with message: " << e.GetMessage());
733 retCode = CKM_API_ERROR_DB_ERROR;
734 } catch (const CKM::Exception &e) {
735 LogError("Unknown CKM::Exception: " << e.GetMessage());
736 retCode = CKM_API_ERROR_SERVER_ERROR;
739 MessageBuffer response;
740 Serialization::Serialize(response, static_cast<int>(LogicCommand::CREATE_SIGNATURE));
741 Serialization::Serialize(response, commandId);
742 Serialization::Serialize(response, retCode);
743 Serialization::Serialize(response, signature);
744 return response.Pop();
747 RawBuffer CKMLogic::verifySignature(
750 const Alias &publicKeyOrCertAlias,
751 const Password &password, // password for public_key (optional)
752 const RawBuffer &message,
753 const RawBuffer &signature,
754 const HashAlgorithm hash,
755 const RSAPaddingAlgorithm padding)
757 int retCode = CKM_API_ERROR_VERIFICATION_FAILED;
765 retCode = getDataHelper(cred, DBDataType::DB_KEY_FIRST, publicKeyOrCertAlias, password, row);
767 if (retCode == CKM_API_SUCCESS) {
768 key = KeyImpl(row.data);
769 } else if (retCode == CKM_API_ERROR_DB_ALIAS_UNKNOWN) {
770 retCode = getDataHelper(cred, DBDataType::CERTIFICATE, publicKeyOrCertAlias, password, row);
771 if (retCode != CKM_API_SUCCESS)
773 CertificateImpl cert(row.data, DataFormat::FORM_DER);
774 key = cert.getKeyImpl();
780 retCode = CKM_API_ERROR_SERVER_ERROR;
784 retCode = cs.verifySignature(key, message, signature, hash, padding);
786 } catch (const CryptoService::Exception::Crypto_internal &e) {
787 LogError("KeyProvider failed with message: " << e.GetMessage());
788 retCode = CKM_API_ERROR_SERVER_ERROR;
789 } catch (const CryptoService::Exception::opensslError &e) {
790 LogError("KeyProvider failed with message: " << e.GetMessage());
791 retCode = CKM_API_ERROR_SERVER_ERROR;
792 } catch (const KeyProvider::Exception::Base &e) {
793 LogError("KeyProvider failed with error: " << e.GetMessage());
794 retCode = CKM_API_ERROR_SERVER_ERROR;
795 } catch (const CryptoLogic::Exception::Base &e) {
796 LogError("CryptoLogic failed with message: " << e.GetMessage());
797 retCode = CKM_API_ERROR_SERVER_ERROR;
798 } catch (const DBCrypto::Exception::Base &e) {
799 LogError("DBCrypto failed with message: " << e.GetMessage());
800 retCode = CKM_API_ERROR_DB_ERROR;
801 } catch (const CKM::Exception &e) {
802 LogError("Unknown CKM::Exception: " << e.GetMessage());
803 retCode = CKM_API_ERROR_SERVER_ERROR;
806 MessageBuffer response;
807 Serialization::Serialize(response, static_cast<int>(LogicCommand::VERIFY_SIGNATURE));
808 Serialization::Serialize(response, commandId);
809 Serialization::Serialize(response, retCode);
811 return response.Pop();