From 7959a37ba0936508894ee23ab637e9c7f744e35a Mon Sep 17 00:00:00 2001 From: Krzysztof Jackiewicz Date: Wed, 22 Mar 2023 09:48:31 +0100 Subject: [PATCH 01/16] Key unwrapping implementation in TZ backend Change-Id: I1ada1788c7f436b9cdd22cc7734eb3ab0159c544 --- src/manager/crypto/tz-backend/internals.cpp | 72 ++++++++++++++++++++++++++++ src/manager/crypto/tz-backend/internals.h | 9 ++++ src/manager/crypto/tz-backend/obj.cpp | 36 ++++++++++++++ src/manager/crypto/tz-backend/obj.h | 11 +++++ src/manager/crypto/tz-backend/tz-context.cpp | 51 ++++++++++++++++++++ src/manager/crypto/tz-backend/tz-context.h | 13 +++++ 6 files changed, 192 insertions(+) diff --git a/src/manager/crypto/tz-backend/internals.cpp b/src/manager/crypto/tz-backend/internals.cpp index 5b8ad1e..cec70b8 100644 --- a/src/manager/crypto/tz-backend/internals.cpp +++ b/src/manager/crypto/tz-backend/internals.cpp @@ -151,6 +151,8 @@ namespace Crypto { namespace TZ { namespace Internals { +namespace { + tz_algo_type getGenSKeyType(AlgoType type) { switch (type) @@ -189,6 +191,44 @@ tz_hash_type getHashType(HashAlgorithm hash) } } +void decompose(const CryptoAlgorithm &alg, + AlgoType &algo, + uint32_t &ctrLenOrTagSizeBits, + RawBuffer &iv, + RawBuffer &aad) +{ + algo = unpack(alg, ParamName::ALGO_TYPE); + switch (algo) { + case AlgoType::AES_CTR: + iv = unpack(alg, ParamName::ED_IV); + ctrLenOrTagSizeBits = unpack(alg, ParamName::ED_CTR_LEN); + // counter length is in bits + if (ctrLenOrTagSizeBits != Params::DEFAULT_AES_IV_LEN * 8) { + LogError("CTR length invalid: " << std::to_string(ctrLenOrTagSizeBits)); + ThrowErr(Exc::Crypto::InputParam, "Invalid CTR length"); + } + break; + case AlgoType::AES_CBC: + iv = unpack(alg, ParamName::ED_IV); + break; + case AlgoType::AES_CFB: + iv = unpack(alg, ParamName::ED_IV); + break; + case AlgoType::AES_GCM: + iv = unpack(alg, ParamName::ED_IV); + alg.getParam(ParamName::ED_TAG_LEN, ctrLenOrTagSizeBits); + alg.getParam(ParamName::ED_AAD, aad); + break; + case AlgoType::RSA_OAEP: + break; + default: + ThrowErr(Exc::Crypto::InputParam, "Invalid decryption algorithm"); + break; + } +} + +} // namespace + RawBuffer generateIV() { RawBuffer result; @@ -324,6 +364,38 @@ void importData(const Data &data, hash); } +void importWrappedKey(const RawBuffer &wrappingKey, + const Pwd &wrappingKeyPwd, + const CryptoAlgorithm &alg, + const Data &encryptedKey, + const Password &encryptedKeyPassword, + const RawBuffer &encryptedKeyIV, + RawBuffer &encryptedKeyTag, + const RawBuffer &encryptedKeyId) +{ + RawBuffer encryptedKeyPwdBuf(encryptedKeyPassword.begin(), encryptedKeyPassword.end()); + + AlgoType algo; + uint32_t ctrLenOrTagSizeBits = 0; + RawBuffer iv; + RawBuffer aad; + decompose(alg, algo, ctrLenOrTagSizeBits, iv, aad); + + // TODO it is awful! + TrustZoneContext::Instance().importWrappedKey(wrappingKey, + wrappingKeyPwd, + getAlgType(algo), + iv, + ctrLenOrTagSizeBits, + aad, + toTzDataType(encryptedKey.type), + encryptedKey.data, + encryptedKeyPwdBuf, + encryptedKeyIV, + encryptedKeyTag, + encryptedKeyId); +} + RawBuffer getData(const RawBuffer &dataId, const Pwd &pwd) { diff --git a/src/manager/crypto/tz-backend/internals.h b/src/manager/crypto/tz-backend/internals.h index bdfcc03..77b8c36 100644 --- a/src/manager/crypto/tz-backend/internals.h +++ b/src/manager/crypto/tz-backend/internals.h @@ -62,6 +62,15 @@ void importData(const Data &key, RawBuffer &tag, const RawBuffer &hash); +void importWrappedKey(const RawBuffer &wrappingKey, + const Pwd &wrappingKeyPwd, + const CryptoAlgorithm &alg, + const Data &encryptedKey, + const Password &encryptedKeyPassword, + const RawBuffer &encryptedKeyIV, + RawBuffer &encryptedKeyTag, + const RawBuffer &encryptedKeyId); + RawBuffer getData(const RawBuffer &dataId, const Pwd &pwd); diff --git a/src/manager/crypto/tz-backend/obj.cpp b/src/manager/crypto/tz-backend/obj.cpp index 86ac7a6..717c012 100644 --- a/src/manager/crypto/tz-backend/obj.cpp +++ b/src/manager/crypto/tz-backend/obj.cpp @@ -68,6 +68,35 @@ Token BData::derive(const CryptoAlgorithm &alg, const Password &pass, const RawB return Token(backendId(), DataType(KeyType::KEY_AES), Store::pack(hash, pass, iv, tag)); } +Token Key::unwrap(const CryptoAlgorithm ¶ms, + const Data &encryptedKey, + const Password &pass, + const RawBuffer &hash) +{ + + if (!encryptedKey.type.isKey() || encryptedKey.type.isEllipticCurve()) + ThrowErr(Exc::Crypto::DataTypeNotSupported, "Invalid data provided for import"); + + RawBuffer passIV; + RawBuffer tag; + + if (!pass.empty()) { + // IV is needed for data encryption with pwd + passIV = Internals::generateIV(); + } + + Internals::importWrappedKey(getBinary(), + getPassword(), + params, + encryptedKey, + pass, + passIV, + tag, + hash); + + return Token(backendId(), encryptedKey.type, Store::pack(hash, pass, passIV, tag)); +} + RawBuffer SKey::encrypt(const CryptoAlgorithm &alg, const RawBuffer &data) { return Internals::symmetricEncrypt(getBinary(), getPassword(), alg, data); @@ -134,6 +163,13 @@ int AKey::verify(const CryptoAlgorithm &alg, const RawBuffer &message, return Internals::verify(getBinary(), getPassword(), algWithType, message, sign); } +Token Cert::unwrap(const CryptoAlgorithm &, + const Data &, + const Password &, + const RawBuffer &) +{ + ThrowErr(Exc::Crypto::OperationNotSupported); +} } // namespace TZ } // namespace Crypto diff --git a/src/manager/crypto/tz-backend/obj.h b/src/manager/crypto/tz-backend/obj.h index 77b3be8..96e4efc 100644 --- a/src/manager/crypto/tz-backend/obj.h +++ b/src/manager/crypto/tz-backend/obj.h @@ -21,6 +21,7 @@ #pragma once #include +#include #include namespace CKM { @@ -90,6 +91,11 @@ public: return m_password; } + Token unwrap(const CryptoAlgorithm ¶ms, + const Data &encryptedKey, + const Password &pass, + const RawBuffer &hash) override; + protected: int m_scheme; Pwd m_password; @@ -122,6 +128,11 @@ class Cert : public AKey { public: Cert(CryptoBackend backendId, int scheme, RawBuffer buffer, Pwd pwd, DataType dataType) : AKey(backendId, scheme, std::move(buffer), std::move(pwd), dataType) {} + + Token unwrap(const CryptoAlgorithm &, + const Data &, + const Password &, + const RawBuffer &) override; }; } // namespace TZ diff --git a/src/manager/crypto/tz-backend/tz-context.cpp b/src/manager/crypto/tz-backend/tz-context.cpp index a058e1b..a998bc9 100644 --- a/src/manager/crypto/tz-backend/tz-context.cpp +++ b/src/manager/crypto/tz-backend/tz-context.cpp @@ -599,6 +599,57 @@ void TrustZoneContext::importData( LogDebug("Imported object ID is (hex): " << rawToHexString(hash)); } +void TrustZoneContext::importWrappedKey(const RawBuffer &wrappingKey, + const Pwd &wrappingKeyPwd, + tz_algo_type algo, + const RawBuffer &iv, + const uint32_t ctrLenOrTagSizeBits, + const RawBuffer &aad, + const tz_data_type encryptedKeyType, + const RawBuffer &encryptedKey, + const RawBuffer &encryptedKeyPwdBuf, + const RawBuffer &encryptedKeyIV, + RawBuffer &encryptedKeyTag, + const RawBuffer &encryptedKeyId) +{ + // command ID = CMD_IMPORT_WRAPPED_KEY + LogDebug("TrustZoneContext::importWrappedKey encryptedKey size = [" << encryptedKey.size() << "]"); + + auto sIn = makeSerializer(wrappingKey, + wrappingKeyPwd, + algo, + iv, + ctrLenOrTagSizeBits, + aad, + encryptedKeyType, + encryptedKey, + EncPwd{encryptedKeyPwdBuf, encryptedKeyIV}, + encryptedKeyId); + + TrustZoneMemory inMemory(m_Context, sIn.GetSize(), TEEC_MEM_INPUT); + sIn.Serialize(inMemory); + + TZSerializer sOut; + if (!encryptedKeyPwdBuf.empty()) { + sOut.Push(new TZSerializableBinary(Params::DEFAULT_AES_GCM_TAG_LEN_BYTES)); + } + + TrustZoneMemory outMemory(m_Context, sOut.GetSize(), TEEC_MEM_OUTPUT); + + TEEC_Operation op = makeOp(TEEC_VALUE_INOUT, inMemory); + if (!encryptedKeyPwdBuf.empty()) + op = makeOp(TEEC_VALUE_INOUT, inMemory, outMemory); + + Execute(CMD_IMPORT_WRAPPED_KEY, &op); + + if (!encryptedKeyPwdBuf.empty()) { + sOut.Deserialize(outMemory); + sOut.Pull(encryptedKeyTag); + } + + LogDebug("Imported object ID is (hex): " << rawToHexString(encryptedKeyId)); +} + void TrustZoneContext::GetDataSize(const RawBuffer &dataId, uint32_t &dataSize) { // command ID = CMD_GET_DATA_SIZE diff --git a/src/manager/crypto/tz-backend/tz-context.h b/src/manager/crypto/tz-backend/tz-context.h index 2a1cff3..71ef9c9 100644 --- a/src/manager/crypto/tz-backend/tz-context.h +++ b/src/manager/crypto/tz-backend/tz-context.h @@ -89,6 +89,19 @@ public: RawBuffer &pwdTag, const RawBuffer &hash); + void importWrappedKey(const RawBuffer &wrappingKey, + const Pwd &wrappingKeyPwd, + tz_algo_type algo, + const RawBuffer &iv, + const uint32_t ctrLenOrTagSizeBits, + const RawBuffer &aad, + const tz_data_type encryptedKeyType, + const RawBuffer &encryptedKey, + const RawBuffer &encryptedKeyPwdBuf, + const RawBuffer &encryptedKeyIV, + RawBuffer &encryptedKeyTag, + const RawBuffer &encryptedKeyHash); + void executeCrypt(tz_command cmd, tz_algo_type algo, const RawBuffer &keyId, -- 2.7.4 From 12b745376eba24d5da65e70bb0fcf681b2cb57a4 Mon Sep 17 00:00:00 2001 From: Krzysztof Jackiewicz Date: Thu, 23 Mar 2023 09:21:05 +0100 Subject: [PATCH 02/16] Key wrapping implementation in TZ backend Change-Id: I3d33a0b41e8eb4b58706a32fb298b0476a0525cc --- src/manager/crypto/tz-backend/internals.cpp | 23 ++++++++++++++ src/manager/crypto/tz-backend/internals.h | 6 ++++ src/manager/crypto/tz-backend/obj.cpp | 29 +++++++++++++++++ src/manager/crypto/tz-backend/obj.h | 8 +++++ src/manager/crypto/tz-backend/tz-context.cpp | 47 ++++++++++++++++++++++++++++ src/manager/crypto/tz-backend/tz-context.h | 9 ++++++ 6 files changed, 122 insertions(+) diff --git a/src/manager/crypto/tz-backend/internals.cpp b/src/manager/crypto/tz-backend/internals.cpp index cec70b8..d732c4c 100644 --- a/src/manager/crypto/tz-backend/internals.cpp +++ b/src/manager/crypto/tz-backend/internals.cpp @@ -396,6 +396,29 @@ void importWrappedKey(const RawBuffer &wrappingKey, encryptedKeyId); } +RawBuffer exportWrappedKey(const RawBuffer &wrappingKey, + const Pwd &wrappingKeyPwd, + const CryptoAlgorithm &alg, + const RawBuffer &keyToWrapId, + const Pwd &keyToWrapPwd) +{ + AlgoType algo; + uint32_t ctrLenOrTagSizeBits = 0; + RawBuffer iv; + RawBuffer aad; + decompose(alg, algo, ctrLenOrTagSizeBits, iv, aad); + + // TODO it is awful! + return TrustZoneContext::Instance().exportWrappedKey(wrappingKey, + wrappingKeyPwd, + getAlgType(algo), + iv, + ctrLenOrTagSizeBits, + aad, + keyToWrapId, + keyToWrapPwd); +} + RawBuffer getData(const RawBuffer &dataId, const Pwd &pwd) { diff --git a/src/manager/crypto/tz-backend/internals.h b/src/manager/crypto/tz-backend/internals.h index 77b8c36..5c1596c 100644 --- a/src/manager/crypto/tz-backend/internals.h +++ b/src/manager/crypto/tz-backend/internals.h @@ -71,6 +71,12 @@ void importWrappedKey(const RawBuffer &wrappingKey, RawBuffer &encryptedKeyTag, const RawBuffer &encryptedKeyId); +RawBuffer exportWrappedKey(const RawBuffer &wrappingKey, + const Pwd &wrappingKeyPwd, + const CryptoAlgorithm &alg, + const RawBuffer &keyToWrapId, + const Pwd &keyToWrapPwd); + RawBuffer getData(const RawBuffer &dataId, const Pwd &pwd); diff --git a/src/manager/crypto/tz-backend/obj.cpp b/src/manager/crypto/tz-backend/obj.cpp index 717c012..94a4c58 100644 --- a/src/manager/crypto/tz-backend/obj.cpp +++ b/src/manager/crypto/tz-backend/obj.cpp @@ -97,6 +97,28 @@ Token Key::unwrap(const CryptoAlgorithm ¶ms, return Token(backendId(), encryptedKey.type, Store::pack(hash, pass, passIV, tag)); } +RawBuffer Key::wrap(const CryptoAlgorithm &alg, + const Token &keyToWrap, + const Password &keyToWrapPass) +{ + int keyToWrapScheme; + RawBuffer keyToWrapId; + RawBuffer keyToWrapIV; + RawBuffer keyToWrapTag; + Store::unpack(keyToWrap.data, + keyToWrapPass, + keyToWrapScheme, + keyToWrapId, + keyToWrapIV, + keyToWrapTag); + + return Internals::exportWrappedKey(getBinary(), + getPassword(), + alg, + keyToWrapId, + Pwd(keyToWrapPass, keyToWrapIV, keyToWrapTag)); +} + RawBuffer SKey::encrypt(const CryptoAlgorithm &alg, const RawBuffer &data) { return Internals::symmetricEncrypt(getBinary(), getPassword(), alg, data); @@ -171,6 +193,13 @@ Token Cert::unwrap(const CryptoAlgorithm &, ThrowErr(Exc::Crypto::OperationNotSupported); } +RawBuffer Cert::wrap(const CryptoAlgorithm &, + const Token &, + const Password &) +{ + ThrowErr(Exc::Crypto::OperationNotSupported); +} + } // namespace TZ } // namespace Crypto } // namespace CKM diff --git a/src/manager/crypto/tz-backend/obj.h b/src/manager/crypto/tz-backend/obj.h index 96e4efc..13f63a0 100644 --- a/src/manager/crypto/tz-backend/obj.h +++ b/src/manager/crypto/tz-backend/obj.h @@ -96,6 +96,10 @@ public: const Password &pass, const RawBuffer &hash) override; + RawBuffer wrap(const CryptoAlgorithm ¶ms, + const Token &keyToWrap, + const Password &keyToWrapPass) override; + protected: int m_scheme; Pwd m_password; @@ -133,6 +137,10 @@ public: const Data &, const Password &, const RawBuffer &) override; + + RawBuffer wrap(const CryptoAlgorithm ¶ms, + const Token &keyToWrap, + const Password &keyToWrapPass) override; }; } // namespace TZ diff --git a/src/manager/crypto/tz-backend/tz-context.cpp b/src/manager/crypto/tz-backend/tz-context.cpp index a998bc9..bf603c9 100644 --- a/src/manager/crypto/tz-backend/tz-context.cpp +++ b/src/manager/crypto/tz-backend/tz-context.cpp @@ -650,6 +650,53 @@ void TrustZoneContext::importWrappedKey(const RawBuffer &wrappingKey, LogDebug("Imported object ID is (hex): " << rawToHexString(encryptedKeyId)); } +RawBuffer TrustZoneContext::exportWrappedKey(const RawBuffer &wrappingKey, + const Pwd &wrappingKeyPwd, + tz_algo_type algo, + const RawBuffer &iv, + const uint32_t ctrLenOrTagSizeBits, + const RawBuffer &aad, + const RawBuffer &keyToWrapId, + const Pwd &keyToWrapPwd) +{ + // command ID = CMD_EXPORT_WRAPPED_KEY + LogDebug("TrustZoneContext::exportWrappedKey"); + + auto sIn = makeSerializer(wrappingKey, + wrappingKeyPwd, + algo, + iv, + ctrLenOrTagSizeBits, + aad, + keyToWrapId, + keyToWrapPwd); + + TrustZoneMemory inMemory(m_Context, sIn.GetSize(), TEEC_MEM_INPUT); + sIn.Serialize(inMemory); + + uint32_t data_size = 0; + GetDataSize(keyToWrapId, data_size); + + LogDebug("GetData data_size = [" << data_size << "]"); + + // encrypted data may be longer + TZSerializer sOut; + sOut.Push(new TZSerializableBinary(data_size + KM_ENCRYPTION_OVERHEAD)); + TrustZoneMemory outMemory(m_Context, sOut.GetSize(), TEEC_MEM_OUTPUT); + sOut.Serialize(outMemory); + + TEEC_Operation op = makeOp(TEEC_VALUE_INOUT, inMemory, outMemory); + + Execute(CMD_EXPORT_WRAPPED_KEY, &op); + + sOut.Deserialize(outMemory); + + RawBuffer wrappedKey; + sOut.Pull(wrappedKey); + + return wrappedKey; +} + void TrustZoneContext::GetDataSize(const RawBuffer &dataId, uint32_t &dataSize) { // command ID = CMD_GET_DATA_SIZE diff --git a/src/manager/crypto/tz-backend/tz-context.h b/src/manager/crypto/tz-backend/tz-context.h index 71ef9c9..e48e642 100644 --- a/src/manager/crypto/tz-backend/tz-context.h +++ b/src/manager/crypto/tz-backend/tz-context.h @@ -102,6 +102,15 @@ public: RawBuffer &encryptedKeyTag, const RawBuffer &encryptedKeyHash); + RawBuffer exportWrappedKey(const RawBuffer &wrappingKey, + const Pwd &wrappingKeyPwd, + tz_algo_type algo, + const RawBuffer &iv, + const uint32_t ctrLenOrTagSizeBits, + const RawBuffer &aad, + const RawBuffer &keyToWrapId, + const Pwd &keyToWrapPwd); + void executeCrypt(tz_command cmd, tz_algo_type algo, const RawBuffer &keyId, -- 2.7.4 From 5c87be872fe0c2b56879ce0bc9dc94a585c1cc7d Mon Sep 17 00:00:00 2001 From: Krzysztof Jackiewicz Date: Fri, 31 Mar 2023 14:50:02 +0200 Subject: [PATCH 03/16] Release 0.1.48 * E2EE implementation Change-Id: Id51fe9009dbc7ef78322274415153df855dde8ea --- packaging/key-manager.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/key-manager.spec b/packaging/key-manager.spec index 88b7c97..e16392a 100644 --- a/packaging/key-manager.spec +++ b/packaging/key-manager.spec @@ -12,7 +12,7 @@ Name: key-manager Summary: Central Key Manager and utilities -Version: 0.1.47 +Version: 0.1.48 Release: 1 Group: Security/Secure Storage License: Apache-2.0 and BSD-3-Clause -- 2.7.4 From dc7515e4e8c379e1acba0b9adea3fa0540d18b0c Mon Sep 17 00:00:00 2001 From: Tomasz Swierczek Date: Mon, 3 Apr 2023 07:41:27 +0200 Subject: [PATCH 04/16] Fix build for 64-bit architectures. Change-Id: I5d658ee32d7d631145ea759c8bb3cb72b13359cd --- src/manager/crypto/sw-backend/kbkdf.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/manager/crypto/sw-backend/kbkdf.cpp b/src/manager/crypto/sw-backend/kbkdf.cpp index 18e5448..9f579fd 100644 --- a/src/manager/crypto/sw-backend/kbkdf.cpp +++ b/src/manager/crypto/sw-backend/kbkdf.cpp @@ -57,7 +57,7 @@ public: RawBuffer Finalize() override { RawBuffer output(outputSize); - size_t size; + unsigned size; if (HMAC_Final(ctx, output.data(), &size) != 1) ThrowErr(Exc::Crypto::InternalError, "HMAC_Final failed"); -- 2.7.4 From f790dfb898a671b87b3031822074a8c87dd84a56 Mon Sep 17 00:00:00 2001 From: Tomasz Swierczek Date: Mon, 3 Apr 2023 07:47:41 +0200 Subject: [PATCH 05/16] Release 0.1.49 * Fix build for 64-bit architectures Change-Id: Ib0e29f479d86f012872a25388d927a4c37f77e26 --- packaging/key-manager.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/key-manager.spec b/packaging/key-manager.spec index e16392a..e967f95 100644 --- a/packaging/key-manager.spec +++ b/packaging/key-manager.spec @@ -12,7 +12,7 @@ Name: key-manager Summary: Central Key Manager and utilities -Version: 0.1.48 +Version: 0.1.49 Release: 1 Group: Security/Secure Storage License: Apache-2.0 and BSD-3-Clause -- 2.7.4 From 55ac958364fb4a335d0089804571d66e7f1d2f7d Mon Sep 17 00:00:00 2001 From: Krzysztof Jackiewicz Date: Mon, 3 Apr 2023 17:46:07 +0200 Subject: [PATCH 06/16] Fix svace/coverity issues Change-Id: I681fd80cddf5f56bc99b35546940e111d29a5311 --- doc/examples/key_derive.cpp | 61 +++++++++++++++-------------- src/manager/client-async/descriptor-set.cpp | 2 +- src/manager/client-capi/ckmc-manager.cpp | 2 +- src/manager/client/client-manager-impl.cpp | 6 +-- src/manager/main/socket-manager.cpp | 20 ++++------ src/manager/main/socket-manager.h | 5 +-- src/manager/service/ckm-logic.cpp | 2 +- src/manager/service/key-provider.cpp | 10 ++--- src/manager/service/key-provider.h | 12 +++--- unit-tests/test_db_crypto.cpp | 2 +- unit-tests/test_descriptor-set.cpp | 6 +-- 11 files changed, 62 insertions(+), 66 deletions(-) diff --git a/doc/examples/key_derive.cpp b/doc/examples/key_derive.cpp index 79c6507..39f2706 100644 --- a/doc/examples/key_derive.cpp +++ b/doc/examples/key_derive.cpp @@ -28,6 +28,14 @@ int key_derive(const ckmc_raw_buffer_s* peers_public) const char* const OURS_PRV_ALIAS = "ours_private"; const char* const OURS_PUB_ALIAS = "ours_public"; + char label[] = "label"; + char context[] = "context"; + + ckmc_param_list_h ecdh_params = nullptr; + ckmc_param_list_h kbkdf_params = nullptr; + ckmc_raw_buffer_s* label_buf = nullptr; + ckmc_raw_buffer_s* context_buf = nullptr; + ckmc_policy_s unexportable { nullptr, false }; ckmc_policy_s exportable { nullptr, true }; @@ -41,84 +49,77 @@ int key_derive(const ckmc_raw_buffer_s* peers_public) return -1; // set ECDH params - ckmc_param_list_h ecdh_params; ret = ckmc_param_list_new(&ecdh_params); if (ret != CKMC_ERROR_NONE) - return -1; + goto exit; ret = ckmc_param_list_set_integer(ecdh_params, CKMC_PARAM_ALGO_TYPE, CKMC_ALGO_ECDH); if (ret != CKMC_ERROR_NONE) - return -1; + goto exit; ret = ckmc_param_list_set_buffer(ecdh_params, CKMC_PARAM_ECDH_PUBKEY, peers_public); if (ret != CKMC_ERROR_NONE) - return -1; + goto exit; // derive shared secret ret = ckmc_key_derive(ecdh_params, OURS_PRV_ALIAS, nullptr, SECRET_ALIAS, unexportable); if (ret != CKMC_ERROR_NONE) - return -1; + goto exit; // set KBKDF params - ckmc_param_list_h kbkdf_params; ret = ckmc_param_list_new(&kbkdf_params); if (ret != CKMC_ERROR_NONE) - return -1; + goto exit; ret = ckmc_param_list_set_integer(kbkdf_params, CKMC_PARAM_ALGO_TYPE, CKMC_ALGO_KBKDF); if (ret != CKMC_ERROR_NONE) - return -1; + goto exit; ret = ckmc_param_list_set_integer(kbkdf_params, CKMC_PARAM_KDF_PRF, CKMC_KDF_PRF_HMAC_SHA256); if (ret != CKMC_ERROR_NONE) - return -1; + goto exit; ret = ckmc_param_list_set_integer(kbkdf_params, CKMC_PARAM_KBKDF_MODE, CKMC_KBKDF_MODE_COUNTER); if (ret != CKMC_ERROR_NONE) - return -1; + goto exit; ret = ckmc_param_list_set_integer(kbkdf_params, CKMC_PARAM_KBKDF_COUNTER_LOCATION, CKMC_KBKDF_COUNTER_BEFORE_FIXED); if (ret != CKMC_ERROR_NONE) - return -1; + goto exit; - char label[] = "label"; - ckmc_raw_buffer_s* label_buf = nullptr; ret = ckmc_buffer_new(reinterpret_cast(label), strlen(label), &label_buf); if (ret != CKMC_ERROR_NONE) - return -1; + goto exit; ret = ckmc_param_list_set_buffer(kbkdf_params, CKMC_PARAM_KBKDF_LABEL, label_buf); - ckmc_buffer_free(label_buf); if (ret != CKMC_ERROR_NONE) - return -1; + goto exit; - char context[] = "context"; - ckmc_raw_buffer_s* context_buf = nullptr; ret = ckmc_buffer_new(reinterpret_cast(context), strlen(context), &context_buf); if (ret != CKMC_ERROR_NONE) - return -1; + goto exit; ret = ckmc_param_list_set_buffer(kbkdf_params, CKMC_PARAM_KBKDF_CONTEXT, context_buf); - ckmc_buffer_free(context_buf); if (ret != CKMC_ERROR_NONE) - return -1; + goto exit; ret = ckmc_param_list_set_integer(kbkdf_params, CKMC_PARAM_KDF_LEN, 32); if (ret != CKMC_ERROR_NONE) - return -1; + goto exit; // derive symmetric key ret = ckmc_key_derive(kbkdf_params, SECRET_ALIAS, nullptr, KEY_ALIAS, unexportable); - if (ret != CKMC_ERROR_NONE) - return -1; - - // remove shared secret - ret = ckmc_remove_key(SECRET_ALIAS); - if (ret != CKMC_ERROR_NONE) - return -1; - return 0; +exit: + ckmc_remove_alias(OURS_PRV_ALIAS); + ckmc_remove_alias(OURS_PUB_ALIAS); + ckmc_param_list_free(ecdh_params); + ckmc_buffer_free(label_buf); + ckmc_buffer_free(context_buf); + ckmc_param_list_free(kbkdf_params); + ckmc_remove_alias(SECRET_ALIAS); + return ret; } //! [KEY_DERIVE example] diff --git a/src/manager/client-async/descriptor-set.cpp b/src/manager/client-async/descriptor-set.cpp index fdee29d..316ea09 100644 --- a/src/manager/client-async/descriptor-set.cpp +++ b/src/manager/client-async/descriptor-set.cpp @@ -40,7 +40,7 @@ DescriptorSet::~DescriptorSet() void DescriptorSet::purge() { - for (auto it : m_descriptors) + for (auto& it : m_descriptors) close(it.first); m_descriptors.clear(); diff --git a/src/manager/client-capi/ckmc-manager.cpp b/src/manager/client-capi/ckmc-manager.cpp index 083ee28..24aa8cb 100644 --- a/src/manager/client-capi/ckmc-manager.cpp +++ b/src/manager/client-capi/ckmc-manager.cpp @@ -1072,7 +1072,7 @@ int ckmc_export_wrapped_key(const ckmc_param_list_h params, int ret = 0; ckmc_key_s *wrapped_key = nullptr; CKM::RawBuffer wrappedKey; - CKM::KeyType keyType; + CKM::KeyType keyType = CKM::KeyType::KEY_NONE; auto mgr = CKM::Manager::create(); ret = to_ckmc_error(mgr->exportWrappedKey(*ca, diff --git a/src/manager/client/client-manager-impl.cpp b/src/manager/client/client-manager-impl.cpp index 8628daf..b788197 100644 --- a/src/manager/client/client-manager-impl.cpp +++ b/src/manager/client/client-manager-impl.cpp @@ -801,7 +801,7 @@ int Manager::Impl::exportWrappedKey(const CryptoAlgorithm ¶ms, AliasSupport wrapping_helper(wrappingKeyAlias); AliasSupport wrapped_helper(wrappedKeyAlias); - DataType *dataTypeKey = nullptr; + DataType dataTypeKey; int retCode = Request(*this, LogicCommand::EXPORT_WRAPPED_KEY, @@ -818,9 +818,9 @@ int Manager::Impl::exportWrappedKey(const CryptoAlgorithm ¶ms, if (retCode != CKM_API_SUCCESS) return retCode; - if (dataTypeKey->isSKey()) { + if (dataTypeKey.isSKey()) { keyType = KeyType::KEY_AES; - } else if (dataTypeKey->isKeyPrivate()) { + } else if (dataTypeKey.isKeyPrivate()) { keyType = KeyType::KEY_RSA_PRIVATE; } else { return CKM_API_ERROR_INVALID_FORMAT; diff --git a/src/manager/main/socket-manager.cpp b/src/manager/main/socket-manager.cpp index a7ea5b4..0d6d26b 100644 --- a/src/manager/main/socket-manager.cpp +++ b/src/manager/main/socket-manager.cpp @@ -51,9 +51,9 @@ namespace { #ifdef OVERRIDE_SOCKET_TIMEOUT -const time_t SOCKET_TIMEOUT = OVERRIDE_SOCKET_TIMEOUT; +const std::chrono::seconds SOCKET_TIMEOUT(OVERRIDE_SOCKET_TIMEOUT); #else // OVERRIDE_SOCKET_TIMEOUT -const time_t SOCKET_TIMEOUT = 1000; +const std::chrono::seconds SOCKET_TIMEOUT(1000); #endif // OVERRIDE_SOCKET_TIMEOUT int getCredentialsFromSocket(int sock, CKM::Credentials &cred) @@ -76,14 +76,8 @@ int getCredentialsFromSocket(int sock, CKM::Credentials &cred) return 0; } -time_t monotonicNow() { - struct timespec now; - if (clock_gettime(CLOCK_MONOTONIC_RAW, &now) == -1) { - int err = errno; - LogError("Can't access monotonic clock, error: " << CKM::GetErrnoString(err)); - return 0; - } - return now.tv_sec; +std::chrono::time_point monotonicNow() { + return std::chrono::steady_clock::now(); } } // namespace anonymous @@ -445,12 +439,14 @@ void SocketManager::MainLoop() LogDebug("No usable timeout found."); ptrTimeout = NULL; // select will wait without timeout } else { - time_t currentTime = monotonicNow(); + auto currentTime = monotonicNow(); auto &pqTimeout = m_socketDescriptionVector[m_timeoutQueue.front()].timeout; // 0 means that select won't block and socket will be closed ;-) ptrTimeout->tv_sec = - currentTime < pqTimeout ? pqTimeout - currentTime : 0; + currentTime < pqTimeout ? + std::chrono::duration_cast(pqTimeout - currentTime).count() : + 0; ptrTimeout->tv_usec = 0; } diff --git a/src/manager/main/socket-manager.h b/src/manager/main/socket-manager.h index 39ac3e7..1c7e295 100644 --- a/src/manager/main/socket-manager.h +++ b/src/manager/main/socket-manager.h @@ -33,7 +33,7 @@ #include #include #include -#include +#include #include @@ -114,7 +114,7 @@ protected: InterfaceID interfaceID; GenericSocketService *service; - time_t timeout; + std::chrono::time_point timeout; RawBuffer rawBuffer; int counter; std::string cynaraPrivilege; @@ -124,7 +124,6 @@ protected: SocketDescription() : interfaceID(-1), service(nullptr), - timeout(0), counter(0), m_flags(0) {} diff --git a/src/manager/service/ckm-logic.cpp b/src/manager/service/ckm-logic.cpp index de74c47..5366ca9 100644 --- a/src/manager/service/ckm-logic.cpp +++ b/src/manager/service/ckm-logic.cpp @@ -1101,7 +1101,7 @@ std::tuple CKMLogic::beginAndGetPerm const Name &name, const ClientId &owner) { - PermissionMask permission; + PermissionMask permission = Permission::NONE; auto [dbOp, retCode] = begin(cred, name, owner); if (retCode == CKM_API_SUCCESS) permission = toPermissionMask(dbOp.database().getPermissionRow(name, owner, cred.client)); diff --git a/src/manager/service/key-provider.cpp b/src/manager/service/key-provider.cpp index 24c48aa..cf15ed8 100644 --- a/src/manager/service/key-provider.cpp +++ b/src/manager/service/key-provider.cpp @@ -281,12 +281,12 @@ KeyProvider::KeyProvider(KeyProvider &&second) second.m_domainKEK = NULL; } -bool KeyProvider::isInitialized() +bool KeyProvider::isInitialized() const { return m_isInitialized; } -RawBuffer KeyProvider::getPureDomainKEK() +RawBuffer KeyProvider::getPureDomainKEK() const { if (!m_isInitialized) ThrowErr(Exc::InternalError, "Object not initialized!"); @@ -295,7 +295,7 @@ RawBuffer KeyProvider::getPureDomainKEK() return RawBuffer(m_domainKEK->key, m_domainKEK->key + m_domainKEK->info.keyLength); } -RawBuffer KeyProvider::getWrappedDomainKEK(const Password &password) +RawBuffer KeyProvider::getWrappedDomainKEK(const Password &password) const { if (!m_isInitialized) ThrowErr(Exc::InternalError, "Object not initialized!"); @@ -303,7 +303,7 @@ RawBuffer KeyProvider::getWrappedDomainKEK(const Password &password) return wrapDomainKEK(*m_domainKEK, password); } -RawBuffer KeyProvider::getPureDEK(const RawBuffer &wrappedDEKbuffer) +RawBuffer KeyProvider::getPureDEK(const RawBuffer &wrappedDEKbuffer) const { if (!m_isInitialized) ThrowErr(Exc::InternalError, "Object not initialized!"); @@ -335,7 +335,7 @@ RawBuffer KeyProvider::getPureDEK(const RawBuffer &wrappedDEKbuffer) return RawBuffer(DEK.key, DEK.key + DEK.info.keyLength); } -RawBuffer KeyProvider::generateDEK(const std::string &client) +RawBuffer KeyProvider::generateDEK(const std::string &client) const { if (!m_isInitialized) ThrowErr(Exc::InternalError, "Object not initialized!"); diff --git a/src/manager/service/key-provider.h b/src/manager/service/key-provider.h index 1d6a6c2..2d283c6 100644 --- a/src/manager/service/key-provider.h +++ b/src/manager/service/key-provider.h @@ -42,7 +42,7 @@ struct KeyInfo { struct DomainKEKInfo : KeyInfo { DomainKEKInfo() = default; - DomainKEKInfo(const KeyInfo& info) : KeyInfo(info) {} + explicit DomainKEKInfo(const KeyInfo& info) : KeyInfo(info) {} uint32_t version; uint32_t backend; }; @@ -109,23 +109,23 @@ public: KeyProvider &operator=(const KeyProvider &) = delete; KeyProvider &operator=(KeyProvider &&); - bool isInitialized(); + bool isInitialized() const; // Returns Key used to decrypt database. - RawBuffer getPureDomainKEK(); + RawBuffer getPureDomainKEK() const; // Returns Key in form used to store key in file - RawBuffer getWrappedDomainKEK(const Password &password); + RawBuffer getWrappedDomainKEK(const Password &password) const; // Unwraps (decrypts) a DEK using a key derived from DomainKEK and data stored in wrapped key // info. It returns the DEK in unencrypted form. - RawBuffer getPureDEK(const RawBuffer &wrappedDEKbuffer); + RawBuffer getPureDEK(const RawBuffer &wrappedDEKbuffer) const; // Generates a random DEK and encrypts it using a key derived from DomainKEK and custom client // string (not to be confused with ClientId). The function returns the DEK in wrapped // (encrypted) form. The function is used to produce a key for database encryption as well as // application keys. - RawBuffer generateDEK(const std::string &client); + RawBuffer generateDEK(const std::string &client) const; // First run of application for some user. DomainKEK was not created yet. We must create one. // This key will be used to encrypt user database. diff --git a/unit-tests/test_db_crypto.cpp b/unit-tests/test_db_crypto.cpp index b73e762..ab2ce10 100644 --- a/unit-tests/test_db_crypto.cpp +++ b/unit-tests/test_db_crypto.cpp @@ -425,7 +425,7 @@ void verifyDBisValid(DBFixture &fixture) DataType::BINARY_DATA)); BOOST_REQUIRE((migration_names / migration_owners) == ret_list.size()); - for (auto it : ret_list) + for (auto& it : ret_list) BOOST_REQUIRE(it.first == current_owner); ret_list.clear(); diff --git a/unit-tests/test_descriptor-set.cpp b/unit-tests/test_descriptor-set.cpp index 83b6b65..5aad04b 100644 --- a/unit-tests/test_descriptor-set.cpp +++ b/unit-tests/test_descriptor-set.cpp @@ -261,10 +261,10 @@ POSITIVE_TEST_CASE(T090_WriteAfterRead) readFd(desc, fd[0], revents); descriptors.remove(desc); - descriptors.add(fd2[1], POLLOUT, [&](int desc, short revents) { + descriptors.add(fd2[1], POLLOUT, [&](int desc2, short revents) { callback2 = true; - writeFd(desc, fd2[1], revents); - descriptors.remove(desc); + writeFd(desc2, fd2[1], revents); + descriptors.remove(desc2); }); }); -- 2.7.4 From 94d217aaae134ff79882fc8aad6761580c7e038d Mon Sep 17 00:00:00 2001 From: Krzysztof Jackiewicz Date: Tue, 4 Apr 2023 15:18:42 +0200 Subject: [PATCH 07/16] Release 0.1.50 * Fix svace/coverity issues Change-Id: I618080688b381fd110248331f615fce26cc30b30 --- packaging/key-manager.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/key-manager.spec b/packaging/key-manager.spec index e967f95..23c39d3 100644 --- a/packaging/key-manager.spec +++ b/packaging/key-manager.spec @@ -12,7 +12,7 @@ Name: key-manager Summary: Central Key Manager and utilities -Version: 0.1.49 +Version: 0.1.50 Release: 1 Group: Security/Secure Storage License: Apache-2.0 and BSD-3-Clause -- 2.7.4 From fcd50819b8b8d4d72f2a15e9f300671c9876c04f Mon Sep 17 00:00:00 2001 From: Krzysztof Jackiewicz Date: Thu, 6 Apr 2023 16:37:45 +0200 Subject: [PATCH 08/16] Fix documentation issues * Issues raised by check-header.py (see: https://github.sec.samsung.net/RPO7-TIZEN/tizen-native-api-review-script) * Other issues raised during ACR. * Own initiative cleanup. Change-Id: If38c6477ecb782e12651766bd2ef344ccaae1e84 --- src/include/ckmc/ckmc-control.h | 82 +++---- src/include/ckmc/ckmc-error.h | 6 +- src/include/ckmc/ckmc-manager.h | 489 +++++++++++++++++++++++++--------------- src/include/ckmc/ckmc-type.h | 278 +++++++++++++---------- 4 files changed, 509 insertions(+), 346 deletions(-) diff --git a/src/include/ckmc/ckmc-control.h b/src/include/ckmc/ckmc-control.h index 459c480..d21230d 100644 --- a/src/include/ckmc/ckmc-control.h +++ b/src/include/ckmc/ckmc-control.h @@ -19,8 +19,8 @@ * @brief Provides control functions for the key manager. */ -#ifndef __TIZEN_CORE_CKMC_CONTROL_H -#define __TIZEN_CORE_CKMC_CONTROL_H +#ifndef __TIZEN_CORE_CKMC_CONTROL_H__ +#define __TIZEN_CORE_CKMC_CONTROL_H__ #include @@ -39,9 +39,9 @@ extern "C" { */ /** - * @brief Decrypts a user key(DKEK) with password. - * A decrypted user key exists only on memory. If this API is called for the first time, a - * user key will be generated internally. + * @platform + * @brief Decrypts a user key(DKEK) with password. A decrypted user key exists only on memory. If + * this function is called for the first time, a user key will be generated internally. * * @since_tizen 2.3 * @privlevel platform @@ -57,10 +57,10 @@ extern "C" { * otherwise a negative error value * * @retval #CKMC_ERROR_NONE Successful - * @retval #CKMC_ERROR_SERVER_ERROR Failed to unlock user key + * @retval #CKMC_ERROR_PERMISSION_DENIED Failed to access key manager * @retval #CKMC_ERROR_INVALID_PARAMETER Invalid input parameter + * @retval #CKMC_ERROR_SERVER_ERROR Failed to unlock user key * @retval #CKMC_ERROR_AUTHENTICATION_FAILED Not correct password - * @retval #CKMC_ERROR_PERMISSION_DENIED Failed to access key manager * * @see ckmc_lock_user_key() * @see ckmc_remove_user_data() @@ -70,7 +70,8 @@ extern "C" { int ckmc_unlock_user_key(uid_t user, const char *password); /** - * @brief Removes a decrypted user key(DKEK) from memory + * @platform + * @brief Removes a decrypted user key(DKEK) from memory. * * @since_tizen 2.3 * @privlevel platform @@ -82,8 +83,8 @@ int ckmc_unlock_user_key(uid_t user, const char *password); * otherwise a negative error value * * @retval #CKMC_ERROR_NONE Successful - * @retval #CKMC_ERROR_INVALID_PARAMETER Invalid input parameter * @retval #CKMC_ERROR_PERMISSION_DENIED Failed to access key manager + * @retval #CKMC_ERROR_INVALID_PARAMETER Invalid input parameter * * @see ckmc_unlock_user_key() * @see ckmc_remove_user_data() @@ -93,6 +94,7 @@ int ckmc_unlock_user_key(uid_t user, const char *password); int ckmc_lock_user_key(uid_t user); /** + * @platform * @brief Removes user data from Store and erases a user key(DKEK) used for encryption. * * @since_tizen 2.3 @@ -105,8 +107,8 @@ int ckmc_lock_user_key(uid_t user); * otherwise a negative error value * * @retval #CKMC_ERROR_NONE Successful - * @retval #CKMC_ERROR_INVALID_PARAMETER Invalid input parameter * @retval #CKMC_ERROR_PERMISSION_DENIED Failed to access key manager + * @retval #CKMC_ERROR_INVALID_PARAMETER Invalid input parameter * * @see ckmc_unlock_user_key() * @see ckmc_lock_user_key() @@ -116,9 +118,9 @@ int ckmc_lock_user_key(uid_t user); int ckmc_remove_user_data(uid_t user); /** - * @brief Changes a password for a user. - * The key manager decrypts a user key (DKEK) with old password and re-encrypts a user key - * with new password. + * @platform + * @brief Changes a password for a user. The key manager decrypts a user key (DKEK) with old + * password and re-encrypts a user key with new password. * * @since_tizen 2.3 * @privlevel platform @@ -132,20 +134,20 @@ int ckmc_remove_user_data(uid_t user); * otherwise a negative error value * * @retval #CKMC_ERROR_NONE Successful + * @retval #CKMC_ERROR_PERMISSION_DENIED Failed to access key manager * @retval #CKMC_ERROR_INVALID_PARAMETER Invalid input parameter * @retval #CKMC_ERROR_AUTHENTICATION_FAILED Not correct password * @retval #CKMC_ERROR_BAD_REQUEST No information about old password - * @retval #CKMC_ERROR_PERMISSION_DENIED Failed to access key manager * * @see ckmc_unlock_user_key() * @see ckmc_lock_user_key() * @see ckmc_remove_user_data() * @see ckmc_reset_user_password() */ -int ckmc_change_user_password(uid_t user, const char *old_password, - const char *new_password); +int ckmc_change_user_password(uid_t user, const char *old_password, const char *new_password); /** + * @platform * @brief Changes a password for a user without old password. * * @since_tizen 2.3 @@ -159,9 +161,9 @@ int ckmc_change_user_password(uid_t user, const char *old_password, * otherwise a negative error value * * @retval #CKMC_ERROR_NONE Successful + * @retval #CKMC_ERROR_PERMISSION_DENIED Failed to access key manager * @retval #CKMC_ERROR_INVALID_PARAMETER Invalid input parameter * @retval #CKMC_ERROR_BAD_REQUEST A user key is not unlocked - * @retval #CKMC_ERROR_PERMISSION_DENIED Failed to access key manager * * @pre User is already logged in and the user key is already loaded into memory in plain text form. * @@ -174,8 +176,9 @@ int ckmc_change_user_password(uid_t user, const char *old_password, int ckmc_reset_user_password(uid_t user, const char *new_password); /** - * @deprecated, see ckmc_set_permission_by_adm() - * @brief Allows another application to access client's application data + * @deprecated Deprecated since 4.0. See ckmc_set_permission_by_adm() + * @platform + * @brief Allows another application to access client's application data. * * @since_tizen 2.3 * @privlevel platform @@ -192,11 +195,11 @@ int ckmc_reset_user_password(uid_t user, const char *new_password); * @return @c 0 on success, otherwise a negative error value * * @retval #CKMC_ERROR_NONE Successful + * @retval #CKMC_ERROR_PERMISSION_DENIED Failed to access key manager * @retval #CKMC_ERROR_INVALID_PARAMETER Input parameter is invalid * @retval #CKMC_ERROR_DB_LOCKED A user key is not loaded in memory (a user is not logged * in) * @retval #CKMC_ERROR_DB_ALIAS_UNKNOWN Alias does not exist - * @retval #CKMC_ERROR_PERMISSION_DENIED Failed to access key manager * * @pre User is already logged in and the user key is already loaded into memory in plain text form. * @@ -204,50 +207,48 @@ int ckmc_reset_user_password(uid_t user, const char *new_password); * @see ckmc_set_permission() */ int ckmc_allow_access_by_adm(uid_t user, - const char *owner, - const char *alias, - const char *accessor, - ckmc_access_right_e granted) -TIZEN_DEPRECATED_API; + const char *owner, + const char *alias, + const char *accessor, + ckmc_access_right_e granted) TIZEN_DEPRECATED_API; /** - * @brief Allows another application to access client's application data + * @platform + * @brief Allows another application to access client's application data. * * @since_tizen 3.0 * @privlevel platform * @privilege %http://tizen.org/privilege/keymanager.admin * * @remarks Data identified by @a alias should exist - * @remarks @a alias must contain owner id and name - * () + * @remarks @a alias must contain owner id and name () * * @param[in] user User ID of a user whose data will be affected * @param[in] alias Data alias for which access will be granted * @param[in] accessor Package id of the application that will gain access rights - * @param[in] mask Mask of permissions granted for @a accessor application - * (@a ckmc_permission_e) + * @param[in] mask Mask of permissions granted for @a accessor application (#ckmc_permission_e) * (previous permission mask will be replaced with the new mask value) * * @return @c 0 on success, otherwise a negative error value * * @retval #CKMC_ERROR_NONE Successful + * @retval #CKMC_ERROR_PERMISSION_DENIED Failed to access key manager * @retval #CKMC_ERROR_INVALID_PARAMETER Input parameter is invalid * @retval #CKMC_ERROR_DB_LOCKED A user key is not loaded in memory (a user is not logged * in) * @retval #CKMC_ERROR_DB_ALIAS_UNKNOWN Alias does not exist - * @retval #CKMC_ERROR_PERMISSION_DENIED Failed to access key manager * * @pre User is already logged in and the user key is already loaded into memory in plain text form. * * @see ckmc_set_permission() */ -int ckmc_set_permission_by_adm(uid_t user, const char *alias, - const char *accessor, int mask); +int ckmc_set_permission_by_adm(uid_t user, const char *alias, const char *accessor, int mask); /** - * @deprecated, see ckmc_set_permission_by_adm() - * @brief Revokes another application's access to client's application data + * @deprecated Deprecated since 4.0. See ckmc_set_permission_by_adm() + * @platform + * @brief Revokes another application's access to client's application data. * * @since_tizen 2.3 * @privlevel platform @@ -264,21 +265,22 @@ int ckmc_set_permission_by_adm(uid_t user, const char *alias, * @return @c 0 on success, otherwise a negative error value * * @retval #CKMC_ERROR_NONE Successful + * @retval #CKMC_ERROR_PERMISSION_DENIED Failed to access key manager * @retval #CKMC_ERROR_INVALID_PARAMETER Input parameter is invalid or the @a accessor doesn't * have access to @a alias * @retval #CKMC_ERROR_DB_LOCKED A user key is not loaded in memory (a user is not logged * in) * @retval #CKMC_ERROR_DB_ALIAS_UNKNOWN Alias does not exist - * @retval #CKMC_ERROR_PERMISSION_DENIED Failed to access key manager * * @pre User is already logged in and the user key is already loaded into memory in plain text form. * * @see ckmc_set_permission() * @see ckmc_set_permission_by_adm() */ -int ckmc_deny_access_by_adm(uid_t user, const char *owner, const char *alias, - const char *accessor) -TIZEN_DEPRECATED_API; +int ckmc_deny_access_by_adm(uid_t user, + const char *owner, + const char *alias, + const char *accessor) TIZEN_DEPRECATED_API; /** * @} @@ -289,4 +291,4 @@ TIZEN_DEPRECATED_API; #endif -#endif /* __TIZEN_CORE_CKMC_CONTROL_H */ +#endif /* __TIZEN_CORE_CKMC_CONTROL_H__ */ diff --git a/src/include/ckmc/ckmc-error.h b/src/include/ckmc/ckmc-error.h index defd187..2e4ec4e 100644 --- a/src/include/ckmc/ckmc-error.h +++ b/src/include/ckmc/ckmc-error.h @@ -19,8 +19,8 @@ */ -#ifndef __TIZEN_CORE_CKMC_ERROR_H_ -#define __TIZEN_CORE_CKMC_ERROR_H_ +#ifndef __TIZEN_CORE_CKMC_ERROR_H__ +#define __TIZEN_CORE_CKMC_ERROR_H__ #include @@ -79,4 +79,4 @@ typedef enum { #endif -#endif /* __TIZEN_CORE_CKMC_ERROR_H_ */ +#endif /* __TIZEN_CORE_CKMC_ERROR_H__*/ diff --git a/src/include/ckmc/ckmc-manager.h b/src/include/ckmc/ckmc-manager.h index fd92c25..03d22f6 100644 --- a/src/include/ckmc/ckmc-manager.h +++ b/src/include/ckmc/ckmc-manager.h @@ -21,8 +21,8 @@ */ -#ifndef __TIZEN_CORE_CKMC_MANAGER_H -#define __TIZEN_CORE_CKMC_MANAGER_H +#ifndef __TIZEN_CORE_CKMC_MANAGER_H__ +#define __TIZEN_CORE_CKMC_MANAGER_H__ #include @@ -46,23 +46,29 @@ extern "C" { /** * @brief Stores a key inside key manager based on the provided policy. * @since_tizen 2.3 - * @remarks %http://tizen.org/privilege/keymanager (public level privilege) is no longer required to use this API since 3.0. - * @remarks Currently API supports seven types of keys. These are RSA public/private key, DSA public/private key, ECDSA public/private key, and AES symmetric key. - * @remarks key_type in key may be set to #CKMC_KEY_NONE as an input. key_type is determined inside key manager during storing keys. - * @remarks Some private key files are protected by a password. If raw_key in key read from those encrypted files is encrypted with a password, the password should be provided in the #ckmc_key_s structure. - * @remarks If password in policy is provided, the key is additionally encrypted with the password in the policy. + * @remarks %http://tizen.org/privilege/keymanager (public level privilege) is no longer required to + * use this function since 3.0. + * @remarks Currently API supports seven types of keys. These are RSA public/private key, + * DSA public/private key, ECDSA public/private key, and AES symmetric key. + * @remarks key_type in key may be set to #CKMC_KEY_NONE as an input. key_type is determined inside + * key manager during storing keys. + * @remarks Some private key files are protected by a password. If raw_key in key read from those + * encrypted files is encrypted with a password, the password should be provided in + * the #ckmc_key_s structure. + * @remarks If password in policy is provided, the key is additionally encrypted with the password + * in the policy. * @param[in] alias The name of a key to be stored * @param[in] key The key's binary value to be stored * @param[in] policy The policy about how to store a key securely * @return @c 0 on success, * otherwise a negative error value * @retval #CKMC_ERROR_NONE Successful + * @retval #CKMC_ERROR_PERMISSION_DENIED Failed to access key manager * @retval #CKMC_ERROR_INVALID_PARAMETER Input parameter is invalid * @retval #CKMC_ERROR_DB_LOCKED A user key is not loaded in memory (a user is not logged in) * @retval #CKMC_ERROR_DB_ALIAS_EXISTS Alias already exists * @retval #CKMC_ERROR_INVALID_FORMAT The format of raw_key is not valid * @retval #CKMC_ERROR_DB_ERROR Failed due to a database error - * @retval #CKMC_ERROR_PERMISSION_DENIED Failed to access key manager * @pre User is already logged in and the user key is already loaded into memory in plain text form. * @see ckmc_remove_alias() * @see ckmc_get_key() @@ -74,21 +80,23 @@ int ckmc_save_key(const char *alias, const ckmc_key_s key, const ckmc_policy_s p /** - * @deprecated Deprecated since @if MOBILE 2.4. @elseif WEARABLE 3.0. @endif [Use ckmc_remove_alias() instead] + * @deprecated Deprecated since @if MOBILE 2.4. @elseif WEARABLE 3.0. @endif + * [Use ckmc_remove_alias() instead] * @brief Removes a key from key manager. * @since_tizen 2.3 - * @remarks %http://tizen.org/privilege/keymanager (public level privilege) is no longer required to use this API since 3.0. + * @remarks %http://tizen.org/privilege/keymanager (public level privilege) is no longer required to + * use this function since 3.0. * @remarks To remove key, client must have remove permission to the specified key. * @remarks The key owner can remove by default. * @param[in] alias The name of a key to be removed * @return @c 0 on success, * otherwise a negative error value * @retval #CKMC_ERROR_NONE Successful + * @retval #CKMC_ERROR_PERMISSION_DENIED Failed to access key manager * @retval #CKMC_ERROR_INVALID_PARAMETER Input parameter is invalid * @retval #CKMC_ERROR_DB_LOCKED A user key is not loaded in memory (a user is not logged in) * @retval #CKMC_ERROR_DB_ERROR Failed due to a database error * @retval #CKMC_ERROR_DB_ALIAS_UNKNOWN Alias does not exist - * @retval #CKMC_ERROR_PERMISSION_DENIED Failed to access key manager * @pre User is already logged in and the user key is already loaded into memory in plain text form. * @see ckmc_save_key() * @see ckmc_get_key() @@ -101,21 +109,22 @@ TIZEN_DEPRECATED_API; /** * @brief Gets a key from key manager. * @since_tizen 2.3 - * @remarks %http://tizen.org/privilege/keymanager (public level privilege) is no longer required to use this API since 3.0. + * @remarks %http://tizen.org/privilege/keymanager (public level privilege) is no longer required to + * use this function since 3.0. * @remarks A client can access only data stored by the client. * @remarks You must destroy the newly created @a ppkey by calling ckmc_key_free() if it is no longer needed. * @param[in] alias The name of a key to retrieve - * @param[in] password The password used in decrypting a key value \n - * If password of policy is provided in ckmc_save_key(), the same password should be provided + * @param[in] password The password used in decrypting a key value. If password of policy is + * provided in ckmc_save_key(), the same password should be provided * @param[out] ppkey The pointer to a newly created ckmc_key_s handle * @return @c 0 on success, * otherwise a negative error value * @retval #CKMC_ERROR_NONE Successful + * @retval #CKMC_ERROR_PERMISSION_DENIED Failed to access key manager * @retval #CKMC_ERROR_INVALID_PARAMETER Input parameter is invalid * @retval #CKMC_ERROR_DB_LOCKED A user key is not loaded in memory (a user is not logged in) * @retval #CKMC_ERROR_DB_ERROR Failed due to a database error * @retval #CKMC_ERROR_DB_ALIAS_UNKNOWN Alias does not exist - * @retval #CKMC_ERROR_PERMISSION_DENIED Failed to access key manager * @retval #CKMC_ERROR_AUTHENTICATION_FAILED Decryption failed because password is incorrect * @pre User is already logged in and the user key is already loaded into memory in plain text form. * @see ckmc_save_key() @@ -128,21 +137,22 @@ int ckmc_get_key(const char *alias, const char *password, ckmc_key_s **ppkey); /** * @brief Gets all the alias of keys that the client can access. * @since_tizen 2.3 - * @remarks %http://tizen.org/privilege/keymanager (public level privilege) is no longer required to use this API since 3.0. + * @remarks %http://tizen.org/privilege/keymanager (public level privilege) is no longer required to + * use this function since 3.0. * @remarks A client can access only data stored by the client. * @remarks You must destroy the newly created @a ppalias_list by calling ckmc_alias_list_all_free() * if it is no longer needed. - * @param[out] ppalias_list The pointer to a newly created ckmc_alias_list_s handle containing all - * available alias of keys \n - * If there is no available key alias, *ppalias_list will be null + * @param[out] ppalias_list The pointer to a newly created #ckmc_alias_list_s handle containing all + * available alias of keys. If there is no available key alias, + * *ppalias_list will be NULL * @return @c 0 on success, * otherwise a negative error value * @retval #CKMC_ERROR_NONE Successful + * @retval #CKMC_ERROR_PERMISSION_DENIED Failed to access key manager * @retval #CKMC_ERROR_INVALID_PARAMETER Input parameter is invalid * @retval #CKMC_ERROR_DB_LOCKED A user key is not loaded in memory (a user is not logged in) * @retval #CKMC_ERROR_DB_ERROR Failed due to a database error * @retval #CKMC_ERROR_DB_ALIAS_UNKNOWN Alias does not exist - * @retval #CKMC_ERROR_PERMISSION_DENIED Failed to access key manager * @pre User is already logged in and the user key is already loaded into memory in plain text form. * @see ckmc_save_key() * @see ckmc_remove_alias() @@ -156,19 +166,20 @@ int ckmc_get_key_alias_list(ckmc_alias_list_s **ppalias_list); * @since_tizen 5.5 * @remarks A client can access only data stored by the client and the entries from system database * if it was explicitly permitted to. - * @remarks You must destroy the newly created @a ppalias_list by calling ckmc_alias_info_list_all_free() - * if it is no longer needed. + * @remarks You must destroy the newly created @a ppalias_list by calling + * ckmc_alias_info_list_all_free() if it is no longer needed. * @param[out] ppalias_list The pointer to a newly created ckmc_alias_info_list_s handle containing - * information about all key aliases \n - * If there is no available key alias, *ppalias_list will be null + * information about all key aliases. If there is no available key alias, + * *ppalias_list will be NULL * @return @c 0 on success, * otherwise a negative error value * @retval #CKMC_ERROR_NONE Successful + * @retval #CKMC_ERROR_PERMISSION_DENIED Insufficient permissions to access key manager or to read + * the alias list * @retval #CKMC_ERROR_INVALID_PARAMETER Input parameter is invalid * @retval #CKMC_ERROR_DB_LOCKED A user key is not loaded in memory (a user is not logged in) * @retval #CKMC_ERROR_DB_ERROR Failed due to a database error * @retval #CKMC_ERROR_DB_ALIAS_UNKNOWN Alias does not exist - * @retval #CKMC_ERROR_PERMISSION_DENIED Failed to access key manager * @pre User is already logged in and the user key is already loaded into memory in plain text form. * @see ckmc_save_key() * @see ckmc_remove_alias() @@ -180,20 +191,22 @@ int ckmc_get_key_alias_info_list(ckmc_alias_info_list_s **ppalias_list); /** * @brief Stores a certificate inside key manager based on the provided policy. * @since_tizen 2.3 - * @remarks %http://tizen.org/privilege/keymanager (public level privilege) is no longer required to use this API since 3.0 - * @remarks The certificate's binary value will be converted and saved as binary DER encoded certificates. + * @remarks %http://tizen.org/privilege/keymanager (public level privilege) is no longer required to + * use this function since 3.0 + * @remarks The certificate's binary value will be converted and saved as binary DER encoded + * certificates. * @param[in] alias The name of a certificate to be stored * @param[in] cert The certificate's binary value to be stored * @param[in] policy The policy about how to store a certificate securely * @return @c 0 on success, * otherwise a negative error value * @retval #CKMC_ERROR_NONE Successful + * @retval #CKMC_ERROR_PERMISSION_DENIED Failed to access key manager * @retval #CKMC_ERROR_INVALID_PARAMETER Input parameter is invalid * @retval #CKMC_ERROR_DB_LOCKED A user key is not loaded in memory (a user is not logged in) * @retval #CKMC_ERROR_DB_ALIAS_EXISTS Alias already exists * @retval #CKMC_ERROR_INVALID_FORMAT The format of raw_cert is not valid * @retval #CKMC_ERROR_DB_ERROR Failed due to a database error - * @retval #CKMC_ERROR_PERMISSION_DENIED Failed to access key manager * @pre User is already logged in and the user key is already loaded into memory in plain text form. * @see ckmc_remove_alias() * @see ckmc_get_cert() @@ -205,21 +218,23 @@ int ckmc_save_cert(const char *alias, const ckmc_cert_s cert, const ckmc_policy_ /** - * @deprecated Deprecated since @if MOBILE 2.4. @elseif WEARABLE 3.0. @endif [Use ckmc_remove_alias() instead] + * @deprecated Deprecated since @if MOBILE 2.4. @elseif WEARABLE 3.0. @endif + * [Use ckmc_remove_alias() instead] * @brief Removes a certificate from key manager. * @since_tizen 2.3 - * @remarks %http://tizen.org/privilege/keymanager (public level privilege) is no longer required to use this API since 3.0. + * @remarks %http://tizen.org/privilege/keymanager (public level privilege) is no longer required to + * use this function since 3.0. * @remarks To remove certificate, client must have remove permission to the specified certificate. * @remarks The key owner can remove by default. * @param[in] alias The name of a certificate to be removed * @return @c 0 on success, * otherwise a negative error value * @retval #CKMC_ERROR_NONE Successful + * @retval #CKMC_ERROR_PERMISSION_DENIED Failed to access key manager * @retval #CKMC_ERROR_INVALID_PARAMETER Input parameter is invalid * @retval #CKMC_ERROR_DB_LOCKED A user key is not loaded in memory (a user is not logged in) * @retval #CKMC_ERROR_DB_ERROR Failed due to a database error * @retval #CKMC_ERROR_DB_ALIAS_UNKNOWN Alias does not exist - * @retval #CKMC_ERROR_PERMISSION_DENIED Failed to access key manager * @pre User is already logged in and the user key is already loaded into memory in plain text form. * @see ckmc_save_cert() * @see ckmc_get_cert() @@ -232,23 +247,24 @@ TIZEN_DEPRECATED_API; /** * @brief Gets a certificate from key manager. * @since_tizen 2.3 - * @remarks %http://tizen.org/privilege/keymanager (public level privilege) is no longer required to use this API since 3.0. + * @remarks %http://tizen.org/privilege/keymanager (public level privilege) is no longer required to + * use this function since 3.0. * @remarks A client can access only certificate stored by the client. * @remarks A DER encoded certificate will be returned as a return value. - * @remarks You must destroy the newly created @a ppcert by calling ckmc_cert_free() if it is no longer needed. + * @remarks You must destroy the newly created @a ppcert by calling ckmc_cert_free() if it is no + * longer needed. * @param[in] alias The name of a certificate to retrieve - * @param[in] password The password used in decrypting a certificate value \n - * If password of policy is provided in ckmc_save_cert(), the same password - * should be provided + * @param[in] password The password used in decrypting a certificate value. If password of policy is + * provided in ckmc_save_cert(), the same password should be provided * @param[out] ppcert The pointer to a newly created ckmc_cert_s handle * @return @c 0 on success, * otherwise a negative error value * @retval #CKMC_ERROR_NONE Successful + * @retval #CKMC_ERROR_PERMISSION_DENIED Failed to access key manager * @retval #CKMC_ERROR_INVALID_PARAMETER Input parameter is invalid * @retval #CKMC_ERROR_DB_LOCKED A user key is not loaded in memory (a user is not logged in) * @retval #CKMC_ERROR_DB_ERROR Failed due to a database error * @retval #CKMC_ERROR_DB_ALIAS_UNKNOWN Alias does not exists - * @retval #CKMC_ERROR_PERMISSION_DENIED Failed to access key manager * @retval #CKMC_ERROR_AUTHENTICATION_FAILED Decryption failed because password is incorrect * @pre User is already logged in and the user key is already loaded into memory in plain text form. * @see ckmc_save_cert() @@ -261,19 +277,22 @@ int ckmc_get_cert(const char *alias, const char *password, ckmc_cert_s **ppcert) /** * @brief Gets all alias of certificates which the client can access. * @since_tizen 2.3 - * @remarks %http://tizen.org/privilege/keymanager (public level privilege) is no longer required to use this API since 3.0. + * @remarks %http://tizen.org/privilege/keymanager (public level privilege) is no longer required to + * use this function since 3.0. * @remarks A client can access only data stored by the client. - * @remarks You must destroy the newly created @a ppalias_list by calling ckmc_alias_list_all_free() if it is no longer needed. - * @param[out] ppalias_list The pointer to a newly created ckmc_alias_list_s handle containing all available alias of keys \n - * If there is no available key alias, *ppalias_list will be null + * @remarks You must destroy the newly created @a ppalias_list by calling ckmc_alias_list_all_free() + * if it is no longer needed. + * @param[out] ppalias_list The pointer to a newly created ckmc_alias_list_s handle containing all + * available alias of keys. If there is no available key alias, + * *ppalias_list will be NULL * @return @c 0 on success, * otherwise a negative error value * @retval #CKMC_ERROR_NONE Successful + * @retval #CKMC_ERROR_PERMISSION_DENIED Failed to access key manager * @retval #CKMC_ERROR_INVALID_PARAMETER Input parameter is invalid * @retval #CKMC_ERROR_DB_LOCKED A user key is not loaded in memory (a user is not logged in) * @retval #CKMC_ERROR_DB_ERROR Failed due to a database error * @retval #CKMC_ERROR_DB_ALIAS_UNKNOWN Alias does not exist - * @retval #CKMC_ERROR_PERMISSION_DENIED Failed to access key manager * @pre User is already logged in and the user key is already loaded into memory in plain text form. * @see ckmc_save_cert() * @see ckmc_remove_alias() @@ -287,19 +306,20 @@ int ckmc_get_cert_alias_list(ckmc_alias_list_s **ppalias_list); * @since_tizen 5.5 * @remarks A client can access only data stored by the client and the entries from system database * if it was explicitly permitted to. - * @remarks You must destroy the newly created @a ppalias_list by calling ckmc_alias_info_list_all_free() - * if it is no longer needed. + * @remarks You must destroy the newly created @a ppalias_list by calling + * ckmc_alias_info_list_all_free() if it is no longer needed. * @param[out] ppalias_list The pointer to a newly created ckmc_alias_info_list_s handle containing - * information about all certificate aliases \n - * If there is no available certificate alias, *ppalias_list will be null + * information about all certificate aliases. If there is no available + * certificate alias, *ppalias_list will be NULL * @return @c 0 on success, * otherwise a negative error value * @retval #CKMC_ERROR_NONE Successful + * @retval #CKMC_ERROR_PERMISSION_DENIED Insufficient permissions to access key manager or to read + * the alias list * @retval #CKMC_ERROR_INVALID_PARAMETER Input parameter is invalid * @retval #CKMC_ERROR_DB_LOCKED A user key is not loaded in memory (a user is not logged in) * @retval #CKMC_ERROR_DB_ERROR Failed due to a database error * @retval #CKMC_ERROR_DB_ALIAS_UNKNOWN Alias does not exist - * @retval #CKMC_ERROR_PERMISSION_DENIED Failed to access key manager * @pre User is already logged in and the user key is already loaded into memory in plain text form. * @see ckmc_save_cert() * @see ckmc_remove_alias() @@ -309,9 +329,11 @@ int ckmc_get_cert_alias_info_list(ckmc_alias_info_list_s **ppalias_list); /** - * @brief Stores PKCS12's contents inside key manager based on the provided policies. All items from the PKCS12 will use the same alias. + * @brief Stores PKCS12's contents inside key manager based on the provided policies. All items from + * the PKCS12 will use the same alias. * @since_tizen @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif - * @remarks %http://tizen.org/privilege/keymanager (public level privilege) is no longer required to use this API since 3.0. + * @remarks %http://tizen.org/privilege/keymanager (public level privilege) is no longer required to + * use this function since 3.0. * @param[in] alias The name of a data to be stored * @param[in] pkcs Pointer to the pkcs12 structure to be saved * @param[in] key_policy The policy about how to store pkcs's private key @@ -319,11 +341,11 @@ int ckmc_get_cert_alias_info_list(ckmc_alias_info_list_s **ppalias_list); * @return @c 0 on success, * otherwise a negative error value * @retval #CKMC_ERROR_NONE Successful + * @retval #CKMC_ERROR_PERMISSION_DENIED Failed to access key manager * @retval #CKMC_ERROR_INVALID_PARAMETER Input parameter is invalid * @retval #CKMC_ERROR_DB_LOCKED A user key is not loaded in memory (a user is not logged in) * @retval #CKMC_ERROR_DB_ALIAS_EXISTS Alias already exists * @retval #CKMC_ERROR_DB_ERROR Failed due to a database error - * @retval #CKMC_ERROR_PERMISSION_DENIED Failed to access key manager * @pre User is already logged in and the user key is already loaded into memory in plain text form. * @see ckmc_remove_alias() * @see ckmc_get_pkcs12() @@ -332,15 +354,20 @@ int ckmc_get_cert_alias_info_list(ckmc_alias_info_list_s **ppalias_list); * @see #ckmc_pkcs12_s * @see #ckmc_policy_s */ -int ckmc_save_pkcs12(const char *alias, const ckmc_pkcs12_s *pkcs, const ckmc_policy_s key_policy,const ckmc_policy_s cert_policy); +int ckmc_save_pkcs12(const char *alias, + const ckmc_pkcs12_s *pkcs, + const ckmc_policy_s key_policy, + const ckmc_policy_s cert_policy); /** * @brief Gets a pkcs12 from key manager. * @since_tizen @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif - * @remarks %http://tizen.org/privilege/keymanager (public level privilege) is no longer required to use this API since 3.0. + * @remarks %http://tizen.org/privilege/keymanager (public level privilege) is no longer required to + * use this function since 3.0. * @remarks A client can access only data stored by the client. - * @remarks You must destroy the newly created @a pkcs12 by calling ckmc_pkcs12_free() if it is no longer needed. + * @remarks You must destroy the newly created @a pkcs12 by calling ckmc_pkcs12_free() if it is no + * longer needed. * @param[in] alias The name of a data to retrieve * @param[in] key_password Password that was used to encrypt privateKey (may be NULL) * @param[in] cert_password Password used to encrypt certificates (may be NULL) @@ -348,34 +375,39 @@ int ckmc_save_pkcs12(const char *alias, const ckmc_pkcs12_s *pkcs, const ckmc_po * @return @c 0 on success, * otherwise a negative error value * @retval #CKMC_ERROR_NONE Successful + * @retval #CKMC_ERROR_PERMISSION_DENIED Failed to access key manager * @retval #CKMC_ERROR_INVALID_PARAMETER Input parameter is invalid * @retval #CKMC_ERROR_DB_LOCKED A user key is not loaded in memory (a user is not logged in) * @retval #CKMC_ERROR_DB_ERROR Failed due to a database error * @retval #CKMC_ERROR_DB_ALIAS_UNKNOWN Alias does not exist - * @retval #CKMC_ERROR_PERMISSION_DENIED Failed to access key manager - * @retval #CKMC_ERROR_AUTHENTICATION_FAILED key_password or cert_password does not match with password used to encrypt data + * @retval #CKMC_ERROR_AUTHENTICATION_FAILED key_password or cert_password does not match with + * password used to encrypt data * @pre User is already logged in and the user key is already loaded into memory in plain text form. * @see ckmc_save_pkcs12() * @see ckmc_remove_alias() */ -int ckmc_get_pkcs12(const char *alias, const char *key_password, const char *cert_password, ckmc_pkcs12_s **pkcs12); +int ckmc_get_pkcs12(const char *alias, + const char *key_password, + const char *cert_password, + ckmc_pkcs12_s **pkcs12); /** * @brief Stores a data inside key manager based on the provided policy. * @since_tizen 2.3 - * @remarks %http://tizen.org/privilege/keymanager (public level privilege) is no longer required to use this API since 3.0. + * @remarks %http://tizen.org/privilege/keymanager (public level privilege) is no longer required to + * use this function since 3.0. * @param[in] alias The name of a data to be stored * @param[in] data The binary value to be stored * @param[in] policy The policy about how to store a data securely * @return @c 0 on success, * otherwise a negative error value * @retval #CKMC_ERROR_NONE Successful + * @retval #CKMC_ERROR_PERMISSION_DENIED Failed to access key manager * @retval #CKMC_ERROR_INVALID_PARAMETER Input parameter is invalid * @retval #CKMC_ERROR_DB_LOCKED A user key is not loaded in memory (a user is not logged in) * @retval #CKMC_ERROR_DB_ALIAS_EXISTS Alias already exists * @retval #CKMC_ERROR_DB_ERROR Failed due to a database error - * @retval #CKMC_ERROR_PERMISSION_DENIED Failed to access key manager * @pre User is already logged in and the user key is already loaded into memory in plain text form. * @see ckmc_remove_alias() * @see ckmc_get_data() @@ -387,21 +419,23 @@ int ckmc_save_data(const char *alias, ckmc_raw_buffer_s data, const ckmc_policy_ /** - * @deprecated Deprecated since @if MOBILE 2.4. @elseif WEARABLE 3.0. @endif [Use ckmc_remove_alias() instead] + * @deprecated Deprecated since @if MOBILE 2.4. @elseif WEARABLE 3.0. @endif + * [Use ckmc_remove_alias() instead] * @brief Removes a data from key manager. * @since_tizen 2.3 - * @remarks %http://tizen.org/privilege/keymanager (public level privilege) is no longer required to use this API since 3.0. + * @remarks %http://tizen.org/privilege/keymanager (public level privilege) is no longer required to + * use this function since 3.0. * @remarks To remove data, client must have remove permission to the specified data object. * @remarks The data owner can remove by default. * @param[in] alias The name of a data to be removed * @return @c 0 on success, * otherwise a negative error value * @retval #CKMC_ERROR_NONE Successful + * @retval #CKMC_ERROR_PERMISSION_DENIED Failed to access key manager * @retval #CKMC_ERROR_INVALID_PARAMETER Input parameter is invalid * @retval #CKMC_ERROR_DB_LOCKED A user key is not loaded in memory (a user is not logged in) * @retval #CKMC_ERROR_DB_ERROR Failed due to the error with unknown reason * @retval #CKMC_ERROR_DB_ALIAS_UNKNOWN Alias does not exist - * @retval #CKMC_ERROR_PERMISSION_DENIED Failed to access key manager * @pre User is already logged in and the user key is already loaded into memory in plain text form. * @see ckmc_save_data() * @see ckmc_get_data() @@ -414,22 +448,23 @@ TIZEN_DEPRECATED_API; /** * @brief Gets a data from key manager. * @since_tizen 2.3 - * @remarks %http://tizen.org/privilege/keymanager (public level privilege) is no longer required to use this API since 3.0. + * @remarks %http://tizen.org/privilege/keymanager (public level privilege) is no longer required to + * use this function since 3.0. * @remarks A client can access only data stored by the client. - * @remarks You must destroy the newly created @a ppdata by calling ckmc_buffer_free() if it is no longer needed. + * @remarks You must destroy the newly created @a ppdata by calling ckmc_buffer_free() if it is no + * longer needed. * @param[in] alias The name of a data to retrieve - * @param[in] password The password used in decrypting a data value \n - * If password of policy is provided in ckmc_save_data(), the same password - * should be provided + * @param[in] password The password used in decrypting a data value. If password of policy is + * provided in ckmc_save_data(), the same password should be provided * @param[out] ppdata The pointer to a newly created ckmc_raw_buffer_s handle * @return @c 0 on success, * otherwise a negative error value * @retval #CKMC_ERROR_NONE Successful + * @retval #CKMC_ERROR_PERMISSION_DENIED Failed to access key manager * @retval #CKMC_ERROR_INVALID_PARAMETER Input parameter is invalid * @retval #CKMC_ERROR_DB_LOCKED A user key is not loaded in memory (a user is not logged in) * @retval #CKMC_ERROR_DB_ERROR Failed due to the error with unknown reason * @retval #CKMC_ERROR_DB_ALIAS_UNKNOWN Alias does not exist - * @retval #CKMC_ERROR_PERMISSION_DENIED Failed to access key manager * @retval #CKMC_ERROR_AUTHENTICATION_FAILED Decryption failed because password is incorrect * @pre User is already logged in and the user key is already loaded into memory in plain text form. * @see ckmc_save_data() @@ -442,19 +477,22 @@ int ckmc_get_data(const char *alias, const char *password, ckmc_raw_buffer_s **p /** * @brief Gets all alias of data which the client can access. * @since_tizen 2.3 - * @remarks %http://tizen.org/privilege/keymanager (public level privilege) is no longer required to use this API since 3.0. + * @remarks %http://tizen.org/privilege/keymanager (public level privilege) is no longer required to + * use this function since 3.0. * @remarks A client can access only data stored by the client. - * @remarks You must destroy the newly created @a ppalias_list by calling ckmc_alias_list_all_free() if it is no longer needed. - * @param[out] ppalias_list The pointer to a newly created ckmc_alias_list_s handle containing all available alias of keys \n - * If there is no available key alias, *ppalias_list will be null + * @remarks You must destroy the newly created @a ppalias_list by calling ckmc_alias_list_all_free() + * if it is no longer needed. + * @param[out] ppalias_list The pointer to a newly created ckmc_alias_list_s handle containing all + * available alias of keys. If there is no available key alias, *ppalias_list will be + * NULL * @return @c 0 on success, * otherwise a negative error value * @retval #CKMC_ERROR_NONE Successful + * @retval #CKMC_ERROR_PERMISSION_DENIED Failed to access key manager * @retval #CKMC_ERROR_INVALID_PARAMETER Input parameter is invalid * @retval #CKMC_ERROR_DB_LOCKED A user key is not loaded in memory (a user is not logged in) * @retval #CKMC_ERROR_DB_ERROR Failed due to the error with unknown reason * @retval #CKMC_ERROR_DB_ALIAS_UNKNOWN Alias does not exist - * @retval #CKMC_ERROR_PERMISSION_DENIED Failed to access key manager * @pre User is already logged in and the user key is already loaded into memory in plain text form. * @see ckmc_save_data() * @see ckmc_remove_alias() @@ -468,19 +506,20 @@ int ckmc_get_data_alias_list(ckmc_alias_list_s **ppalias_list); * @since_tizen 5.5 * @remarks A client can access only data stored by the client and the entries from system database * if it was explicitly permitted to. - * @remarks You must destroy the newly created @a ppalias_list by calling ckmc_alias_info_list_all_free() - * if it is no longer needed. + * @remarks You must destroy the newly created @a ppalias_list by calling + * ckmc_alias_info_list_all_free() if it is no longer needed. * @param[out] ppalias_list The pointer to a newly created ckmc_alias_info_list_s handle containing - * information about all data aliases \n - * If there is no available data alias, *ppalias_list will be null + * information about all data aliases. If there is no available data alias, + * *ppalias_list will be NULL * @return @c 0 on success, * otherwise a negative error value * @retval #CKMC_ERROR_NONE Successful + * @retval #CKMC_ERROR_PERMISSION_DENIED Insufficient permissions to access key manager or to read + * the alias list * @retval #CKMC_ERROR_INVALID_PARAMETER Input parameter is invalid * @retval #CKMC_ERROR_DB_LOCKED A user key is not loaded in memory (a user is not logged in) * @retval #CKMC_ERROR_DB_ERROR Failed due to the error with unknown reason * @retval #CKMC_ERROR_DB_ALIAS_UNKNOWN Alias does not exist - * @retval #CKMC_ERROR_PERMISSION_DENIED Failed to access key manager * @pre User is already logged in and the user key is already loaded into memory in plain text form. * @see ckmc_save_data() * @see ckmc_remove_alias() @@ -490,12 +529,15 @@ int ckmc_get_data_alias_info_list(ckmc_alias_info_list_s **ppalias_list); /** - * @brief Creates RSA private/public key pair and stores them inside key manager based on each policy. + * @brief Creates RSA private/public key pair and stores them inside key manager based on each + * policy. * @since_tizen 2.3 - * @remarks %http://tizen.org/privilege/keymanager (public level privilege) is no longer required to use this API since 3.0. - * @remarks If password in the policy is provided, the key is additionally encrypted with the password in the policy. - * @param[in] size The size of key strength to be created \n - * @c 1024, @c 2048, and @c 4096 are supported + * @remarks %http://tizen.org/privilege/keymanager (public level privilege) is no longer required to + * use this function since 3.0. + * @remarks If password in the policy is provided, the key is additionally encrypted with the + * password in the policy. + * @param[in] size The size of key strength to be created. @c 1024, @c 2048, and @c 4096 are + * supported * @param[in] private_key_alias The name of private key to be stored * @param[in] public_key_alias The name of public key to be stored * @param[in] policy_private_key The policy about how to store a private key securely @@ -503,27 +545,33 @@ int ckmc_get_data_alias_info_list(ckmc_alias_info_list_s **ppalias_list); * @return @c 0 on success, * otherwise a negative error value * @retval #CKMC_ERROR_NONE Successful + * @retval #CKMC_ERROR_PERMISSION_DENIED Failed to access key manager * @retval #CKMC_ERROR_INVALID_PARAMETER Input parameter is invalid * @retval #CKMC_ERROR_DB_LOCKED A user key is not loaded in memory (a user is not logged in) * @retval #CKMC_ERROR_DB_ALIAS_EXISTS Alias already exists * @retval #CKMC_ERROR_DB_ERROR Failed due to other DB transaction unexpectedly - * @retval #CKMC_ERROR_PERMISSION_DENIED Failed to access key manager * @pre User is already logged in and the user key is already loaded into memory in plain text form. * @see ckmc_create_key_pair_dsa() * @see ckmc_create_key_pair_ecdsa() * @see ckmc_create_signature() * @see ckmc_verify_signature() */ -int ckmc_create_key_pair_rsa(const size_t size, const char *private_key_alias, const char *public_key_alias, const ckmc_policy_s policy_private_key, const ckmc_policy_s policy_public_key); +int ckmc_create_key_pair_rsa(const size_t size, + const char *private_key_alias, + const char *public_key_alias, + const ckmc_policy_s policy_private_key, + const ckmc_policy_s policy_public_key); /** * @brief Creates DSA private/public key pair and stores them inside key manager based on each policy. * @since_tizen 2.3 - * @remarks %http://tizen.org/privilege/keymanager (public level privilege) is no longer required to use this API since 3.0. - * @remarks If password in the policy is provided, the key is additionally encrypted with the password in the policy. - * @param[in] size The size of key strength to be created \n - * @c 1024, @c 2048, @c 3072 and @c 4096 are supported + * @remarks %http://tizen.org/privilege/keymanager (public level privilege) is no longer required to + * use this function since 3.0. + * @remarks If password in the policy is provided, the key is additionally encrypted with the + * password in the policy. + * @param[in] size The size of key strength to be created. @c 1024, @c 2048, @c 3072 and @c 4096 are + * supported * @param[in] private_key_alias The name of private key to be stored * @param[in] public_key_alias The name of public key to be stored * @param[in] policy_private_key The policy about how to store a private key securely @@ -531,25 +579,31 @@ int ckmc_create_key_pair_rsa(const size_t size, const char *private_key_alias, c * @return @c 0 on success, * otherwise a negative error value * @retval #CKMC_ERROR_NONE Successful + * @retval #CKMC_ERROR_PERMISSION_DENIED Failed to access key manager * @retval #CKMC_ERROR_INVALID_PARAMETER Input parameter is invalid * @retval #CKMC_ERROR_DB_LOCKED A user key is not loaded in memory (a user is not logged in) * @retval #CKMC_ERROR_DB_ALIAS_EXISTS Alias already exists * @retval #CKMC_ERROR_DB_ERROR Failed due to other DB transaction unexpectedly - * @retval #CKMC_ERROR_PERMISSION_DENIED Failed to access key manager * @pre User is already logged in and the user key is already loaded into memory in plain text form. * @see ckmc_create_key_pair_rsa() * @see ckmc_create_key_pair_ecdsa() * @see ckmc_create_signature() * @see ckmc_verify_signature() */ -int ckmc_create_key_pair_dsa(const size_t size, const char *private_key_alias, const char *public_key_alias, const ckmc_policy_s policy_private_key, const ckmc_policy_s policy_public_key); +int ckmc_create_key_pair_dsa(const size_t size, + const char *private_key_alias, + const char *public_key_alias, + const ckmc_policy_s policy_private_key, + const ckmc_policy_s policy_public_key); /** * @brief Creates ECDSA private/public key pair and stores them inside key manager based on each policy. * @since_tizen 2.3 - * @remarks %http://tizen.org/privilege/keymanager (public level privilege) is no longer required to use this API since 3.0. - * @remarks If password in the policy is provided, the key is additionally encrypted with the password in the policy. + * @remarks %http://tizen.org/privilege/keymanager (public level privilege) is no longer required to + * use this function since 3.0. + * @remarks If password in the policy is provided, the key is additionally encrypted with the + * password in the policy. * @param[in] type The type of elliptic curve of ECDSA * @param[in] private_key_alias The name of private key to be stored * @param[in] public_key_alias The name of public key to be stored @@ -558,11 +612,11 @@ int ckmc_create_key_pair_dsa(const size_t size, const char *private_key_alias, c * @return @c 0 on success, * otherwise a negative error value * @retval #CKMC_ERROR_NONE Successful + * @retval #CKMC_ERROR_PERMISSION_DENIED Failed to access key manager * @retval #CKMC_ERROR_INVALID_PARAMETER Input parameter is invalid * @retval #CKMC_ERROR_DB_LOCKED A user key is not loaded in memory (a user is not logged in) * @retval #CKMC_ERROR_DB_ALIAS_EXISTS Alias already exists * @retval #CKMC_ERROR_DB_ERROR Failed due to other DB transaction unexpectedly - * @retval #CKMC_ERROR_PERMISSION_DENIED Failed to access key manager * @pre User is already logged in and the user key is already loaded into memory in plain text form. * @see ckmc_create_key_pair_rsa() * @see ckmc_create_key_pair_dsa() @@ -570,25 +624,30 @@ int ckmc_create_key_pair_dsa(const size_t size, const char *private_key_alias, c * @see ckmc_verify_signature() * @see #ckmc_ec_type_e */ -int ckmc_create_key_pair_ecdsa(const ckmc_ec_type_e type, const char *private_key_alias, const char *public_key_alias, const ckmc_policy_s policy_private_key, const ckmc_policy_s policy_public_key); +int ckmc_create_key_pair_ecdsa(const ckmc_ec_type_e type, + const char *private_key_alias, + const char *public_key_alias, + const ckmc_policy_s policy_private_key, + const ckmc_policy_s policy_public_key); /** * @brief Creates AES key and stores it inside key manager based on the policy. * @since_tizen 3.0 - * @remarks If password in the policy is provided, the key is additionally encrypted with the password in the policy. - * @param[in] size The size of key strength to be created \n - * @c 128, @c 192 and @c 256 are supported + * @remarks If password in the policy is provided, the key is additionally encrypted with the + * password in the policy. + * @param[in] size The size of key strength to be created. @c 128, @c 192 and @c 256 are supported * @param[in] key_alias The name of key to be stored * @param[in] key_policy The policy about how to store the key securely * @return @c 0 on success, * otherwise a negative error value * @retval #CKMC_ERROR_NONE Successful + * @retval #CKMC_ERROR_PERMISSION_DENIED Insufficient permissions to access key manager or to create + * the key * @retval #CKMC_ERROR_INVALID_PARAMETER Input parameter is invalid * @retval #CKMC_ERROR_DB_LOCKED A user key is not loaded in memory (a user is not logged in) * @retval #CKMC_ERROR_DB_ALIAS_EXISTS Alias already exists * @retval #CKMC_ERROR_DB_ERROR Failed due to other DB transaction unexpectedly - * @retval #CKMC_ERROR_PERMISSION_DENIED Failed to access key manager * @pre User is already logged in and the user key is already loaded into memory in plain text form. * @see ckmc_create_key_pair_rsa() * @see ckmc_create_key_pair_dsa() @@ -601,27 +660,30 @@ int ckmc_create_key_aes(size_t size, const char *key_alias, ckmc_policy_s key_po /** * @brief Creates a signature on a given message using a private key and returns the signature. * @since_tizen 2.3 - * @remarks %http://tizen.org/privilege/keymanager (public level privilege) is no longer required to use this API since 3.0. - * @remarks If password of policy is provided during storing a key, the same password should be provided. - * @remarks You must destroy the newly created @a ppsignature by calling ckmc_buffer_free() if it is no longer needed. + * @remarks %http://tizen.org/privilege/keymanager (public level privilege) is no longer required to + * use this function since 3.0. + * @remarks If password of policy is provided during storing a key, the same password should be + * provided. + * @remarks You must destroy the newly created @a ppsignature by calling ckmc_buffer_free() if it is + * no longer needed. * @param[in] private_key_alias The name of private key * @param[in] password The password used in decrypting a private key value * @param[in] message The message that is signed with a private key - * @param[in] hash The hash algorithm used in creating signature. CKMC_HASH_NONE is invalid for DSA & ECDSA - * @param[in] padding The RSA padding algorithm used in creating signature \n - * It is used only when the signature algorithm is RSA. If + * @param[in] hash The hash algorithm used in creating signature. CKMC_HASH_NONE is invalid for DSA + * & ECDSA + * @param[in] padding The RSA padding algorithm used in creating signature. It is used only when the signature algorithm is RSA. If * @a padding is CKMC_NONE_PADDING you must use CKMC_HASH_NONE * and the message must be equal to key length - * @param[out] ppsignature The pointer to a newly created signature \n - * If an error occurs, @a *ppsignature will be null + * @param[out] ppsignature The pointer to a newly created signature. If an error occurs, + * *ppsignature will be NULL * @return @c 0 on success, * otherwise a negative error value * @retval #CKMC_ERROR_NONE Successful + * @retval #CKMC_ERROR_PERMISSION_DENIED Failed to access key manager * @retval #CKMC_ERROR_INVALID_PARAMETER Input parameter is invalid * @retval #CKMC_ERROR_DB_LOCKED A user key is not loaded in memory (a user is not logged in) * @retval #CKMC_ERROR_DB_ERROR Failed due to the error with unknown reason * @retval #CKMC_ERROR_DB_ALIAS_UNKNOWN Alias does not exist - * @retval #CKMC_ERROR_PERMISSION_DENIED Failed to access key manager * @retval #CKMC_ERROR_AUTHENTICATION_FAILED Decryption failed because password is incorrect * @pre User is already logged in and the user key is already loaded into memory in plain text form. * @see ckmc_create_key_pair_rsa() @@ -631,32 +693,40 @@ int ckmc_create_key_aes(size_t size, const char *key_alias, ckmc_policy_s key_po * @see #ckmc_hash_algo_e * @see #ckmc_rsa_padding_algo_e */ -int ckmc_create_signature(const char *private_key_alias, const char *password, const ckmc_raw_buffer_s message, const ckmc_hash_algo_e hash, const ckmc_rsa_padding_algo_e padding, ckmc_raw_buffer_s **ppsignature); +int ckmc_create_signature(const char *private_key_alias, + const char *password, + const ckmc_raw_buffer_s message, + const ckmc_hash_algo_e hash, + const ckmc_rsa_padding_algo_e padding, + ckmc_raw_buffer_s **ppsignature); /** - * @brief Verifies a given signature on a given message using a public key and returns the signature status. + * @brief Verifies a given signature on a given message using a public key and returns the signature + * status. * @since_tizen 2.3 - * @remarks %http://tizen.org/privilege/keymanager (public level privilege) is no longer required to use this API since 3.0. - * @remarks If password of policy is provided during storing a key, the same password should be provided. + * @remarks %http://tizen.org/privilege/keymanager (public level privilege) is no longer required to + * use this function since 3.0. + * @remarks If password of policy is provided during storing a key, the same password should be + * provided. * @param[in] public_key_alias The name of public key * @param[in] password The password used in decrypting a public key value * @param[in] message The input on which the signature is created * @param[in] signature The signature that is verified with public key - * @param[in] hash The hash algorithm used in verifying signature. CKMC_HASH_NONE is invalid for DSA & ECDSA - * @param[in] padding The RSA padding algorithm used in verifying signature \n - * It is used only when the signature algorithm is RSA. If - * @a padding is CKMC_NONE_PADDING you must use CKMC_HASH_NONE - * and the message must be equal to key length + * @param[in] hash The hash algorithm used in verifying signature. CKMC_HASH_NONE is invalid for DSA + * & ECDSA + * @param[in] padding The RSA padding algorithm used in verifying signature. It is used only when + * the signature algorithm is RSA. If @a padding is CKMC_NONE_PADDING you must + * use CKMC_HASH_NONE and the message must be equal to key length * @return @c 0 on success and the signature is valid, * otherwise a negative error value * @retval #CKMC_ERROR_NONE Successful - * @retval #CKMC_ERROR_VERIFICATION_FAILED The signature is invalid + * @retval #CKMC_ERROR_PERMISSION_DENIED Failed to access key manager * @retval #CKMC_ERROR_INVALID_PARAMETER Input parameter is invalid + * @retval #CKMC_ERROR_VERIFICATION_FAILED The signature is invalid * @retval #CKMC_ERROR_DB_LOCKED A user key is not loaded in memory (a user is not logged in) * @retval #CKMC_ERROR_DB_ERROR Failed due to the error with unknown reason * @retval #CKMC_ERROR_DB_ALIAS_UNKNOWN Alias does not exist - * @retval #CKMC_ERROR_PERMISSION_DENIED Failed to access key manager * @retval #CKMC_ERROR_AUTHENTICATION_FAILED Decryption failed because password is incorrect * @pre User is already logged in and the user key is already loaded into memory in plain text form. * @see ckmc_create_key_pair_rsa() @@ -665,122 +735,156 @@ int ckmc_create_signature(const char *private_key_alias, const char *password, c * @see #ckmc_hash_algo_e * @see #ckmc_rsa_padding_algo_e */ -int ckmc_verify_signature(const char *public_key_alias, const char *password, const ckmc_raw_buffer_s message, const ckmc_raw_buffer_s signature, const ckmc_hash_algo_e hash, const ckmc_rsa_padding_algo_e padding); +int ckmc_verify_signature(const char *public_key_alias, + const char *password, + const ckmc_raw_buffer_s message, + const ckmc_raw_buffer_s signature, + const ckmc_hash_algo_e hash, + const ckmc_rsa_padding_algo_e padding); /** * @brief Verifies a certificate chain and returns that chain. * @since_tizen 2.3 - * @remarks %http://tizen.org/privilege/keymanager (public level privilege) is no longer required to use this API since 3.0. - * @remarks The trusted root certificate of the chain should exist in the system's certificate storage. - * @remarks You must destroy the newly created @a ppcert_chain_list by calling ckmc_cert_list_all_free() if it is no longer needed. + * @remarks %http://tizen.org/privilege/keymanager (public level privilege) is no longer required to + * use this function since 3.0. + * @remarks The trusted root certificate of the chain should exist in the system's certificate + * storage. + * @remarks You must destroy the newly created @a ppcert_chain_list by calling + * ckmc_cert_list_all_free() if it is no longer needed. * @param[in] cert The certificate to be verified - * @param[in] untrustedcerts The untrusted CA certificates to be used in verifying a certificate chain - * @param[out] ppcert_chain_list The pointer to a newly created certificate chain's handle \n - * If an error occurs, @a *ppcert_chain_list will be null + * @param[in] untrustedcerts The untrusted CA certificates to be used in verifying a certificate + * chain + * @param[out] ppcert_chain_list The pointer to a newly created certificate chain's handle. If an + * error occurs, *ppcert_chain_list will be NULL * @return @c 0 on success and the signature is valid, * otherwise a negative error value * @retval #CKMC_ERROR_NONE Successful - * @retval #CKMC_ERROR_VERIFICATION_FAILED The certificate chain is not valid + * @retval #CKMC_ERROR_PERMISSION_DENIED Failed to access key manager * @retval #CKMC_ERROR_INVALID_PARAMETER Input parameter is invalid + * @retval #CKMC_ERROR_VERIFICATION_FAILED The certificate chain is not valid * @retval #CKMC_ERROR_DB_LOCKED A user key is not loaded in memory (a user is not logged in) * @retval #CKMC_ERROR_DB_ERROR Failed due to the error with unknown reason * @retval #CKMC_ERROR_INVALID_FORMAT The format of certificate is not valid - * @retval #CKMC_ERROR_PERMISSION_DENIED Failed to access key manager * @retval #CKMC_ERROR_AUTHENTICATION_FAILED Decryption failed because password is incorrect * @pre User is already logged in and the user key is already loaded into memory in plain text form. * @see ckmc_cert_list_all_free() */ -int ckmc_get_cert_chain(const ckmc_cert_s *cert, const ckmc_cert_list_s *untrustedcerts, ckmc_cert_list_s **ppcert_chain_list); +int ckmc_get_cert_chain(const ckmc_cert_s *cert, + const ckmc_cert_list_s *untrustedcerts, + ckmc_cert_list_s **ppcert_chain_list); /** - * @deprecated Deprecated since @if MOBILE 2.4. @elseif WEARABLE 3.0. @endif [Use ckmc_get_cert_chain() instead] - * @brief Verifies a certificate chain using an alias list of untrusted certificates and return that chain. + * @deprecated Deprecated since @if MOBILE 2.4. @elseif WEARABLE 3.0. @endif + * [Use ckmc_get_cert_chain() instead] + * @brief Verifies a certificate chain using an alias list of untrusted certificates and return that + * chain. * @since_tizen 2.3 - * @remarks %http://tizen.org/privilege/keymanager (public level privilege) is no longer required to use this API since 3.0. - * @remarks The trusted root certificate of the chain should exist in the system's certificate storage. - * @remarks You must destroy the newly created @a ppcert_chain_list by calling ckmc_cert_list_all_free() if it is no longer needed. + * @remarks %http://tizen.org/privilege/keymanager (public level privilege) is no longer required to + * use this function since 3.0. + * @remarks The trusted root certificate of the chain should exist in the system's certificate + * storage. + * @remarks You must destroy the newly created @a ppcert_chain_list by calling + * ckmc_cert_list_all_free() if it is no longer needed. * @remarks @a untrustedcerts shouldn't be protected with optional password. * @param[in] cert The certificate to be verified - * @param[in] untrustedcerts The alias list of untrusted CA certificates stored in key manager to be used in verifying a certificate chain - * @param[out] ppcert_chain_list The pointer to a newly created certificate chain's handle \n - * If an error occurs, @a *ppcert_chain_list will be null + * @param[in] untrustedcerts The alias list of untrusted CA certificates stored in key manager to be + * used in verifying a certificate chain + * @param[out] ppcert_chain_list The pointer to a newly created certificate chain's handle. If an + * error occurs, *ppcert_chain_list will be NULL * @return @c 0 on success and the signature is valid, * otherwise a negative error value * @retval #CKMC_ERROR_NONE Successful - * @retval #CKMC_ERROR_VERIFICATION_FAILED The certificate chain is not valid + * @retval #CKMC_ERROR_PERMISSION_DENIED Failed to access key manager * @retval #CKMC_ERROR_INVALID_PARAMETER Input parameter is invalid + * @retval #CKMC_ERROR_VERIFICATION_FAILED The certificate chain is not valid * @retval #CKMC_ERROR_DB_LOCKED A user key is not loaded in memory (a user is not logged in) * @retval #CKMC_ERROR_DB_ERROR Failed due to the error with unknown reason * @retval #CKMC_ERROR_DB_ALIAS_UNKNOWN Alias does not exist * @retval #CKMC_ERROR_INVALID_FORMAT The format of certificate is not valid - * @retval #CKMC_ERROR_PERMISSION_DENIED Failed to access key manager - * @retval #CKMC_ERROR_AUTHENTICATION_FAILED Some certificates were encrypted with password and could not be used + * @retval #CKMC_ERROR_AUTHENTICATION_FAILED Some certificates were encrypted with password and + * could not be used * @pre User is already logged in and the user key is already loaded into memory in plain text form. * @see ckmc_get_cert_chain() * @see ckmc_cert_list_all_free() */ -int ckmc_get_cert_chain_with_alias(const ckmc_cert_s *cert, const ckmc_alias_list_s *untrustedcerts, ckmc_cert_list_s **ppcert_chain_list) TIZEN_DEPRECATED_API; +int ckmc_get_cert_chain_with_alias(const ckmc_cert_s *cert, + const ckmc_alias_list_s *untrustedcerts, + ckmc_cert_list_s **ppcert_chain_list) TIZEN_DEPRECATED_API; /** - * @brief Verifies a certificate chain and returns that chain using user-entered, trusted, and untrusted CA certificates. + * @brief Verifies a certificate chain and returns that chain using user-entered, trusted, and + * untrusted CA certificates. * @since_tizen @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif - * @remarks %http://tizen.org/privilege/keymanager (public level privilege) is no longer required to use this API since 3.0. - * @remarks If the trusted root certificates are provided as a user input, these certificates do not need to exist in the system's certificate storage. - * @remarks You must destroy the newly created @a ppcert_chain_list by calling ckmc_cert_list_all_free() if it is no longer needed. + * @remarks %http://tizen.org/privilege/keymanager (public level privilege) is no longer required to + * use this function since 3.0. + * @remarks If the trusted root certificates are provided as a user input, these certificates do not + * need to exist in the system's certificate storage. + * @remarks You must destroy the newly created @a ppcert_chain_list by calling + * ckmc_cert_list_all_free() if it is no longer needed. * @param[in] cert The certificate to be verified - * @param[in] untrustedcerts The untrusted CA certificates to be used in verifying a certificate chain + * @param[in] untrustedcerts The untrusted CA certificates to be used in verifying a certificate + * chain * @param[in] trustedcerts The trusted CA certificates to be used in verifying a certificate chain - * @param[in] use_trustedsystemcerts The flag indicating the use of the trusted root certificates in the system's certificate storage - * @param[out] ppcert_chain_list The pointer to a newly created certificate chain's handle \n - * If an error occurs, @a *ppcert_chain_list will be null + * @param[in] use_trustedsystemcerts The flag indicating the use of the trusted root certificates in + * the system's certificate storage + * @param[out] ppcert_chain_list The pointer to a newly created certificate chain's handle. If an + * error occurs, *ppcert_chain_list will be NULL * @return @c 0 on success and the signature is valid, * otherwise a negative error value * @retval #CKMC_ERROR_NONE Successful - * @retval #CKMC_ERROR_VERIFICATION_FAILED The certificate chain is not valid + * @retval #CKMC_ERROR_PERMISSION_DENIED Failed to access key manager * @retval #CKMC_ERROR_INVALID_PARAMETER Input parameter is invalid + * @retval #CKMC_ERROR_VERIFICATION_FAILED The certificate chain is not valid * @retval #CKMC_ERROR_DB_LOCKED A user key is not loaded in memory (a user is not logged in) * @retval #CKMC_ERROR_DB_ERROR Failed due to the error with unknown reason * @retval #CKMC_ERROR_INVALID_FORMAT The format of certificate is not valid - * @retval #CKMC_ERROR_PERMISSION_DENIED Failed to access key manager * @pre User is already logged in and the user key is already loaded into memory in plain text form. * @see ckmc_cert_list_all_free() */ -int ckmc_get_cert_chain_with_trustedcert(const ckmc_cert_s *cert, const ckmc_cert_list_s *untrustedcerts, const ckmc_cert_list_s *trustedcerts, const bool use_trustedsystemcerts, ckmc_cert_list_s **ppcert_chain_list); +int ckmc_get_cert_chain_with_trustedcert(const ckmc_cert_s *cert, + const ckmc_cert_list_s *untrustedcerts, + const ckmc_cert_list_s *trustedcerts, + const bool use_trustedsystemcerts, + ckmc_cert_list_s **ppcert_chain_list); /** * @deprecated Deprecated since 6.5. Use raw OpenSSL instead. - * @brief Perform OCSP that checks certificate is whether revoked or not. + * @brief Performs OCSP that checks certificate is whether revoked or not. * @since_tizen @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif * @privlevel public * @privilege %http://tizen.org/privilege/internet - * @remarks %http://tizen.org/privilege/internet (public level privilege) is required to use this API instead of %http://tizen.org/privilege/keymanager (public level privilege) since 3.0. + * @remarks %http://tizen.org/privilege/internet (public level privilege) is required to use this + * function instead of %http://tizen.org/privilege/keymanager (public level privilege) + * since 3.0. * @param[in] pcert_chain_list Valid certificate chain to perform OCSP check * @param[out] ocsp_status The pointer to status result of OCSP check * @return @c 0 on success, * otherwise a negative error value * @retval #CKMC_ERROR_NONE Successful - * @retval #CKMC_ERROR_INVALID_PARAMETER Input parameter is invalid - * @retval #CKMC_ERROR_PERMISSION_DENIED Failed to access key manager * @retval #CKMC_ERROR_NOT_SUPPORTED Device needed to run API is not supported + * @retval #CKMC_ERROR_PERMISSION_DENIED Failed to access key manager + * @retval #CKMC_ERROR_INVALID_PARAMETER Input parameter is invalid * @pre User is already logged in and the user key is already loaded into memory in plain text form. * @pre @a pcert_chain_list is created with ckmc_get_certificate_chain() or * ckmc_get_certificate_chain_with_alias(). * @see ckmc_get_cert_chain()) * @see ckmc_cert_list_all_free() */ -int ckmc_ocsp_check(const ckmc_cert_list_s *pcert_chain_list, ckmc_ocsp_status_e *ocsp_status) -TIZEN_DEPRECATED_API; +int ckmc_ocsp_check(const ckmc_cert_list_s *pcert_chain_list, + ckmc_ocsp_status_e *ocsp_status) TIZEN_DEPRECATED_API; /** - * @deprecated Deprecated since @if MOBILE 2.4. @elseif WEARABLE 3.0. @endif [Use ckmc_set_permission() instead] + * @deprecated Deprecated since @if MOBILE 2.4. @elseif WEARABLE 3.0. @endif + * [Use ckmc_set_permission() instead] * @brief Allows another application to access client's application data. * @since_tizen 2.3 - * @remarks %http://tizen.org/privilege/keymanager (public level privilege) is no longer required to use this API since 3.0. + * @remarks %http://tizen.org/privilege/keymanager (public level privilege) is no longer required to + * use this function since 3.0. * @remarks Data identified by @a alias should exist. * @param[in] alias Data alias for which access will be granted * @param[in] accessor Package id of the application that will gain access rights @@ -788,21 +892,24 @@ TIZEN_DEPRECATED_API; * @return @c 0 on success, * otherwise a negative error value * @retval #CKMC_ERROR_NONE Successful + * @retval #CKMC_ERROR_PERMISSION_DENIED Failed to access key manager or modify permissions * @retval #CKMC_ERROR_INVALID_PARAMETER Input parameter is invalid * @retval #CKMC_ERROR_DB_LOCKED A user key is not loaded in memory (a user is not logged in) * @retval #CKMC_ERROR_DB_ERROR Failed due to the error with unknown reason * @retval #CKMC_ERROR_DB_ALIAS_UNKNOWN Alias does not exist - * @retval #CKMC_ERROR_PERMISSION_DENIED Failed to access key manager * @pre User is already logged in and the user key is already loaded into memory in plain text form. * @see ckmc_deny_access() */ -int ckmc_allow_access(const char *alias, const char *accessor, ckmc_access_right_e granted) TIZEN_DEPRECATED_API; +int ckmc_allow_access(const char *alias, + const char *accessor, + ckmc_access_right_e granted) TIZEN_DEPRECATED_API; /** * @brief Allows another application to access client's application data. * @since_tizen @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif - * @remarks %http://tizen.org/privilege/keymanager (public level privilege) is no longer required to use this API since 3.0. + * @remarks %http://tizen.org/privilege/keymanager (public level privilege) is no longer required to + * use this function since 3.0. * @remarks Data identified by @a alias should exist. * @param[in] alias Data alias for which access will be granted * @param[in] accessor Package id of the application that will gain access rights @@ -812,33 +919,36 @@ int ckmc_allow_access(const char *alias, const char *accessor, ckmc_access_right * @return @c 0 on success, * otherwise a negative error value * @retval #CKMC_ERROR_NONE Successful + * @retval #CKMC_ERROR_PERMISSION_DENIED Failed to access key manager or modify permissions * @retval #CKMC_ERROR_INVALID_PARAMETER Input parameter is invalid * @retval #CKMC_ERROR_DB_LOCKED A user key is not loaded in memory (a user is not logged in) * @retval #CKMC_ERROR_DB_ERROR Failed due to the error with unknown reason * @retval #CKMC_ERROR_DB_ALIAS_UNKNOWN Alias does not exist - * @retval #CKMC_ERROR_PERMISSION_DENIED Failed to access key manager * @pre User is already logged in and the user key is already loaded into memory in plain text form. */ int ckmc_set_permission(const char *alias, const char *accessor, int permissions); /** - * @deprecated Deprecated since @if MOBILE 2.4. @elseif WEARABLE 3.0. @endif [Use ckmc_set_permission() instead] + * @deprecated Deprecated since @if MOBILE 2.4. @elseif WEARABLE 3.0. @endif + * [Use ckmc_set_permission() instead] * @brief Revokes another application's access to client's application data. * @since_tizen 2.3 - * @remarks %http://tizen.org/privilege/keymanager (public level privilege) is no longer required to use this API since 3.0. + * @remarks %http://tizen.org/privilege/keymanager (public level privilege) is no longer required to + * use this function since 3.0. * @remarks Data identified by @a alias should exist. - * @remarks Only access previously granted with ckmc_allow_access can be revoked. + * @remarks Only access previously granted with ckmc_allow_access() can be revoked. * @param[in] alias Data alias for which access will be revoked * @param[in] accessor Package id of the application that will lose access rights * @return @c 0 on success, * otherwise a negative error value * @retval #CKMC_ERROR_NONE Successful - * @retval #CKMC_ERROR_INVALID_PARAMETER Input parameter is invalid or the @a accessor doesn't have access to @a alias + * @retval #CKMC_ERROR_PERMISSION_DENIED Failed to access key manager or modify permissions + * @retval #CKMC_ERROR_INVALID_PARAMETER Input parameter is invalid or the @a accessor doesn't have + * access to @a alias * @retval #CKMC_ERROR_DB_LOCKED A user key is not loaded in memory (a user is not logged in) * @retval #CKMC_ERROR_DB_ERROR Failed due to the error with unknown reason * @retval #CKMC_ERROR_DB_ALIAS_UNKNOWN Alias does not exist - * @retval #CKMC_ERROR_PERMISSION_DENIED Failed to access key manager * @pre User is already logged in and the user key is already loaded into memory in plain text form. * @see ckmc_allow_access() * @see ckmc_set_permission() @@ -849,18 +959,19 @@ int ckmc_deny_access(const char *alias, const char *accessor) TIZEN_DEPRECATED_A /** * @brief Removes an entry (no matter of type) from the key manager. * @since_tizen @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif - * @remarks %http://tizen.org/privilege/keymanager (public level privilege) is no longer required to use this API since 3.0. + * @remarks %http://tizen.org/privilege/keymanager (public level privilege) is no longer required to + * use this function since 3.0. * @remarks To remove item, client must have remove permission to the specified item. * @remarks The item owner can remove by default. * @param[in] alias Item alias to be removed * @return @c 0 on success, * otherwise a negative error value * @retval #CKMC_ERROR_NONE Successful + * @retval #CKMC_ERROR_PERMISSION_DENIED Failed to access key manager or the item to remove * @retval #CKMC_ERROR_INVALID_PARAMETER Input parameter is invalid * @retval #CKMC_ERROR_DB_LOCKED A user key is not loaded in memory (a user is not logged in) * @retval #CKMC_ERROR_DB_ERROR Failed due to a database error * @retval #CKMC_ERROR_DB_ALIAS_UNKNOWN Alias does not exist - * @retval #CKMC_ERROR_PERMISSION_DENIED Failed to access key manager * @pre User is already logged in and the user key is already loaded into memory in plain text form. * @see ckmc_save_key() * @see ckmc_save_cert() @@ -879,6 +990,7 @@ int ckmc_remove_alias(const char *alias); * @since_tizen 3.0 * * @remarks Key identified by @a key_alias should exist. + * @remarks You must destroy @a ppencrypted with ckmc_buffer_free(). * * @param[in] params Algorithm parameter list handle. See #ckmc_param_list_h and #ckmc_algo_type_e * for details. Supported algorithms: @@ -888,9 +1000,8 @@ int ckmc_remove_alias(const char *alias); * - #CKMC_ALGO_AES_CFB, * - #CKMC_ALGO_RSA_OAEP * @param[in] key_alias Alias of the key to be used for encryption - * @param[in] password The password used in decrypting a key value \n - * If password of the policy is provided in ckmc_save_key(), the same password - * should be provided + * @param[in] password The password used in decrypting a key value. If password of the policy is + * provided in ckmc_save_key(), the same password should be provided * @param[in] decrypted Data to be encrypted. In case of AES algorithm there are no restrictions on * the size of data, if S/W backend is used. If module uses TEE backend (since * Tizen 5.0 on chosen images), maximum size of data is implementation-specific @@ -898,19 +1009,17 @@ int ckmc_remove_alias(const char *alias); * in bytes - 42. * Example: for 1024 RSA key the maximum data size is 1024/8 - 42 = 86. * @param[out] ppencrypted Encrypted data (some algorithms may return additional information - * embedded in encrypted data. AES GCM is an example) \n - * The caller is responsible for freeing @a encrypted with - * ckmc_buffer_free() + * embedded in encrypted data. AES GCM is an example) * * @return @c 0 on success, otherwise a negative error value * @retval #CKMC_ERROR_NONE Successful + * @retval #CKMC_ERROR_PERMISSION_DENIED Failed to access key manager or the encrypting key * @retval #CKMC_ERROR_INVALID_PARAMETER Input parameter is invalid (missing or invalid mandatory * algorithm parameter or RSA data too long, decrypted = NULL, * ppencrypted = NULL) * @retval #CKMC_ERROR_DB_LOCKED A user key is not loaded in memory (a user is not logged in) * @retval #CKMC_ERROR_DB_ERROR Failed due to the error with unknown reason * @retval #CKMC_ERROR_DB_ALIAS_UNKNOWN Key with given alias does not exist - * @retval #CKMC_ERROR_PERMISSION_DENIED Failed to access key manager * @retval #CKMC_ERROR_AUTHENTICATION_FAILED Key decryption failed because password is incorrect * @retval #CKMC_ERROR_SERVER_ERROR Too big data size or unsupported GCM mode (32 and 64 bit tag * lengths not supported on TEE backend) or internal error @@ -927,7 +1036,11 @@ int ckmc_remove_alias(const char *alias); * @see #ckmc_param_name_e * @see #ckmc_algo_type_e */ -int ckmc_encrypt_data(ckmc_param_list_h params, const char *key_alias, const char *password, const ckmc_raw_buffer_s decrypted, ckmc_raw_buffer_s **ppencrypted); +int ckmc_encrypt_data(ckmc_param_list_h params, + const char *key_alias, + const char *password, + const ckmc_raw_buffer_s decrypted, + ckmc_raw_buffer_s **ppencrypted); /** @@ -936,6 +1049,7 @@ int ckmc_encrypt_data(ckmc_param_list_h params, const char *key_alias, const cha * @since_tizen 3.0 * * @remarks Key identified by @a key_alias should exist. + * @remarks You must destroy @a ppdecrypted with ckmc_buffer_free(). * * @param[in] params Algorithm parameter list handle. You should use the same parameters that were * used for encryption. See #ckmc_param_list_h and #ckmc_algo_type_e for details. @@ -946,19 +1060,17 @@ int ckmc_encrypt_data(ckmc_param_list_h params, const char *key_alias, const cha * - #CKMC_ALGO_AES_CFB, * - #CKMC_ALGO_RSA_OAEP * @param[in] key_alias Alias of the key to be used for encryption - * @param[in] password The password used in decrypting a key value \n - * If password of the policy is provided in ckmc_save_key(), the same password - * should be provided + * @param[in] password The password used in decrypting a key value. If password of the policy is + * provided in ckmc_save_key(), the same password should be provided * @param[in] encrypted Data to be decrypted (some algorithms may require additional information * embedded in encrypted data. AES GCM is an example) Since Tizen 5.0, on * chosen images where module is using TEE backend, data size is limited to at * least 500 kB (TEE implementation-specific). - * @param[out] ppdecrypted Decrypted data \n - * The caller is responsible for freeing @a decrypted with - * ckmc_buffer_free() + * @param[out] ppdecrypted Decrypted data * * @return @c 0 on success, otherwise a negative error value * @retval #CKMC_ERROR_NONE Successful + * @retval #CKMC_ERROR_PERMISSION_DENIED Failed to access key manager or the decrypting key * @retval #CKMC_ERROR_INVALID_PARAMETER Input parameter is invalid (missing or invalid mandatory * algorithm parameter, GCM tag authentication failed, key or * data is wrong, in case of RSA key is wrong or data too @@ -966,7 +1078,6 @@ int ckmc_encrypt_data(ckmc_param_list_h params, const char *key_alias, const cha * @retval #CKMC_ERROR_DB_LOCKED A user key is not loaded in memory (a user is not logged in) * @retval #CKMC_ERROR_DB_ERROR Failed due to the error with unknown reason * @retval #CKMC_ERROR_DB_ALIAS_UNKNOWN Key with given alias does not exist - * @retval #CKMC_ERROR_PERMISSION_DENIED Failed to access key manager * @retval #CKMC_ERROR_AUTHENTICATION_FAILED Key decryption failed because password is incorrect * @retval #CKMC_ERROR_SERVER_ERROR Too big data size or unsupported GCM mode (32 and 64 bit tag * lengths not supported on TEE backend) or internal error @@ -983,7 +1094,11 @@ int ckmc_encrypt_data(ckmc_param_list_h params, const char *key_alias, const cha * @see #ckmc_param_name_e * @see #ckmc_algo_type_e */ -int ckmc_decrypt_data(ckmc_param_list_h params, const char *key_alias, const char *password, const ckmc_raw_buffer_s encrypted, ckmc_raw_buffer_s **ppdecrypted); +int ckmc_decrypt_data(ckmc_param_list_h params, + const char *key_alias, + const char *password, + const ckmc_raw_buffer_s encrypted, + ckmc_raw_buffer_s **ppdecrypted); /** @@ -1148,4 +1263,4 @@ int ckmc_key_derive(const ckmc_param_list_h params, */ -#endif /* __TIZEN_CORE_CKMC_MANAGER_H */ +#endif /* __TIZEN_CORE_CKMC_MANAGER_H__ */ diff --git a/src/include/ckmc/ckmc-type.h b/src/include/ckmc/ckmc-type.h index bb49883..d1fddef 100644 --- a/src/include/ckmc/ckmc-type.h +++ b/src/include/ckmc/ckmc-type.h @@ -20,8 +20,8 @@ */ -#ifndef __TIZEN_CORE_CKMC_TYPE_H -#define __TIZEN_CORE_CKMC_TYPE_H +#ifndef __TIZEN_CORE_CKMC_TYPE_H__ +#define __TIZEN_CORE_CKMC_TYPE_H__ #include @@ -76,9 +76,10 @@ KEY_MANAGER_CAPI extern char const *const ckmc_owner_id_separator; /** * @brief The owner of system database. * @since_tizen 3.0 - * @remarks #ckmc_owner_id_system contains id connected with all system applications that run with uid less than 5000. - * Client should use #ckmc_owner_id_system to access data owned by system application and stored in system database. - * Client must have permission to access proper row. + * @remarks #ckmc_owner_id_system contains id connected with all system applications that run with + * uid less than 5000. Client should use #ckmc_owner_id_system to access data owned by + * system application and stored in system database. Client must have permission to access + * proper row. * @see ckmc_alias_new() */ KEY_MANAGER_CAPI extern char const *const ckmc_owner_id_system; @@ -150,7 +151,8 @@ typedef enum __ckmc_rsa_padding_algo { /** - * @deprecated Deprecated since @if MOBILE 2.4. @elseif WEARABLE 3.0. @endif [Use ckmc_permission_e() instead] + * @deprecated Deprecated since @if MOBILE 2.4. @elseif WEARABLE 3.0. @endif + * [Use #ckmc_permission_e instead] * @brief Enumeration for database access rights. * @since_tizen 2.3 */ @@ -186,9 +188,9 @@ typedef struct __ckmc_raw_buff { * @since_tizen 2.3 */ typedef struct __ckmc_policy { - char *password; /**< Byte array used to encrypt data inside CKM. If it is not null, the data - (or key, or certificate) is stored encrypted with this password inside - key manager */ + char *password; /**< Byte array used to encrypt data inside CKM. If it is not NULL, the data + (or key, or certificate) is stored encrypted with this password inside + key manager */ bool extractable; /**< If true key may be extracted from storage */ } ckmc_policy_s; @@ -223,8 +225,7 @@ typedef struct __ckmc_cert { */ typedef struct __ckmc_alias_list { char *alias; /**< The name of key, certificate or data stored in key manager */ - struct __ckmc_alias_list - *next; /**< The pointer pointing to the next ckmc_alias_list_s */ + struct __ckmc_alias_list *next; /**< The pointer pointing to the next #ckmc_alias_list_s */ } ckmc_alias_list_s; struct ckmc_alias_info_s; @@ -240,21 +241,20 @@ typedef struct ckmc_alias_info_s ckmc_alias_info_s; * @since_tizen 5.5 */ typedef struct __ckmc_alias_info_list_s { - struct ckmc_alias_info_s* info; /**< The pointer pointing to the alias structure - with additional information */ - struct __ckmc_alias_info_list_s* - next; /**< The pointer pointing to the next ckmc_alias_info_list_s */ + struct ckmc_alias_info_s* info; /**< The pointer pointing to the alias structure with additional + information */ + struct __ckmc_alias_info_list_s* next; /**< The pointer pointing to the next + #ckmc_alias_info_list_s */ } ckmc_alias_info_list_s; /** - * @brief The structure for linked list of ckmc_cert_s + * @brief The structure for linked list of #ckmc_cert_s. * @since_tizen 2.3 */ typedef struct __ckmc_cert_list { - ckmc_cert_s *cert; /**< The pointer of ckmc_cert_s */ - struct __ckmc_cert_list - *next; /**< The pointer pointing to the next ckmc_cert_list_s */ + ckmc_cert_s *cert; /**< The pointer of #ckmc_cert_s */ + struct __ckmc_cert_list *next; /**< The pointer pointing to the next #ckmc_cert_list_s */ } ckmc_cert_list_s; @@ -280,9 +280,9 @@ typedef enum __ckmc_ocsp_status { * @since_tizen @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif */ typedef struct __ckmc_pkcs12 { - ckmc_key_s *priv_key; /**< The private key, may be null */ - ckmc_cert_s *cert; /**< The certificate, may be null */ - ckmc_cert_list_s *ca_chain; /**< The chain certificate list, may be null */ + ckmc_key_s *priv_key; /**< The private key, may be NULL */ + ckmc_cert_s *cert; /**< The certificate, may be NULL */ + ckmc_cert_list_s *ca_chain; /**< The chain certificate list, may be NULL */ } ckmc_pkcs12_s; @@ -292,13 +292,13 @@ typedef struct __ckmc_pkcs12 { * @see #ckmc_algo_type_e */ typedef enum __ckmc_param_name { - CKMC_PARAM_ALGO_TYPE = 1, + CKMC_PARAM_ALGO_TYPE = 1, /**< integer - type of algorithm (see #ckmc_algo_type_e) */ CKMC_PARAM_ED_IV = 101, /**< 16B buffer (up to 2^64-1 bytes long in case of AES GCM) */ CKMC_PARAM_ED_CTR_LEN, /**< integer - ctr length in bits*/ - CKMC_PARAM_ED_AAD, /**< buffer */ + CKMC_PARAM_ED_AAD, /**< buffer - Additional Authentication Data for AES GCM */ CKMC_PARAM_ED_TAG_LEN, /**< integer - tag length in bits */ - CKMC_PARAM_ED_LABEL, /**< buffer */ + CKMC_PARAM_ED_LABEL, /**< buffer - RSA OAEP label (not supported at the moment) */ CKMC_PARAM_KDF_PRF = 401, /**< integer - pseudo-random function number (see #ckmc_kdf_prf_e) */ CKMC_PARAM_KDF_LEN, /**< integer - length of the derived key in bytes. The value must be one of @@ -381,8 +381,9 @@ typedef enum __ckmc_kbkdf_counter_location { /** * @brief Algorithm parameter list handle. * @since_tizen 3.0 - * @remarks Each parameter list must have at least one CKMC_PARAM_ALGO_TYPE parameter that identifies the algorithm. - * See #ckmc_algo_type_e for available algorithms and additional parameters they support. + * @remarks Each parameter list must have at least one #CKMC_PARAM_ALGO_TYPE parameter that + * identifies the algorithm. See #ckmc_algo_type_e for available algorithms and additional + * parameters they support. * @see ckmc_generate_new_params() * @see ckmc_param_list_new() * @see ckmc_param_list_set_integer() @@ -404,35 +405,35 @@ typedef struct __ckmc_param_list *ckmc_param_list_h; typedef enum __ckmc_algo_type { CKMC_ALGO_AES_CTR = 1, /**< AES-CTR algorithm Supported parameters: - - CKMC_PARAM_ALGO_TYPE = CKMC_ALGO_AES_CTR(mandatory), - - CKMC_PARAM_ED_IV = 16-byte initialization vector(mandatory) - - CKMC_PARAM_ED_CTR_LEN = length of counter block in bits + - #CKMC_PARAM_ALGO_TYPE = #CKMC_ALGO_AES_CTR (mandatory), + - #CKMC_PARAM_ED_IV = 16-byte initialization vector (mandatory) + - #CKMC_PARAM_ED_CTR_LEN = length of counter block in bits (optional, only 128b is supported at the moment) */ CKMC_ALGO_AES_CBC, /**< AES-CBC algorithm Supported parameters: - - CKMC_PARAM_ALGO_TYPE = CKMC_ALGO_AES_CBC(mandatory), - - CKMC_PARAM_ED_IV = 16-byte initialization vector(mandatory) */ + - #CKMC_PARAM_ALGO_TYPE = #CKMC_ALGO_AES_CBC (mandatory), + - #CKMC_PARAM_ED_IV = 16-byte initialization vector (mandatory) */ CKMC_ALGO_AES_GCM, /**< AES-GCM algorithm Supported parameters: - - CKMC_PARAM_ALGO_TYPE = CKMC_ALGO_AES_GCM(mandatory), - - CKMC_PARAM_ED_IV = initialization vector(mandatory) - - CKMC_PARAM_ED_TAG_LEN = GCM tag length in bits. One of + - #CKMC_PARAM_ALGO_TYPE = #CKMC_ALGO_AES_GCM (mandatory), + - #CKMC_PARAM_ED_IV = initialization vector (mandatory) + - #CKMC_PARAM_ED_TAG_LEN = GCM tag length in bits. One of {32, 64, 96, 104, 112, 120, 128} (optional, if not present, the length 128 is used; since Tizen 5.0, if TrustZone backend is used, 32 and 64 lengths are not supported) - - CKMC_PARAM_ED_AAD = additional authentication data(optional) */ + - #CKMC_PARAM_ED_AAD = additional authentication data(optional) */ CKMC_ALGO_AES_CFB, /**< AES-CFB algorithm Supported parameters: - - CKMC_PARAM_ALGO_TYPE = CKMC_ALGO_AES_CFB(mandatory), - - CKMC_PARAM_ED_IV = 16-byte initialization vector(mandatory) */ + - #CKMC_PARAM_ALGO_TYPE = #CKMC_ALGO_AES_CFB (mandatory), + - #CKMC_PARAM_ED_IV = 16-byte initialization vector (mandatory) */ CKMC_ALGO_RSA_OAEP, /**< RSA-OAEP algorithm Supported parameters: - - CKMC_PARAM_ALGO_TYPE = CKMC_ALGO_RSA_OAEP(required), - - CKMC_PARAM_ED_LABEL = label to be associated with the message + - #CKMC_PARAM_ALGO_TYPE = #CKMC_ALGO_RSA_OAEP (mandatory), + - #CKMC_PARAM_ED_LABEL = label to be associated with the message (optional, not supported at the moment) */ CKMC_ALGO_KBKDF, /**< Key based key derivation algorithm @@ -485,7 +486,8 @@ int ckmc_alias_info_get_alias(const ckmc_alias_info_s* info, char** alias); int ckmc_alias_info_is_password_protected(const ckmc_alias_info_s* info, bool* is_password_protected); /** - * @brief Destroys the #ckmc_alias_info_list_s handle and releases resources of #ckmc_alias_info_list_s from the provided first handle cascadingly. + * @brief Destroys the #ckmc_alias_info_list_s handle and releases resources of + * #ckmc_alias_info_list_s from the provided first handle cascadingly. * @since_tizen 5.5 * @param[in] first The first #ckmc_alias_info_list_s handle to destroy * @see #ckmc_alias_info_list_s @@ -519,13 +521,13 @@ int ckmc_alias_new(const char *owner_id, const char *alias, char **full_alias); /** * @brief Creates a new #ckmc_key_s handle and returns it. * @since_tizen @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif - * @remarks You must destroy the newly created #ckmc_key_s by calling ckmc_key_free() if it is no longer needed. - * @param[in] raw_key The byte array of key \n - * @a raw_key may be encrypted with password + * @remarks You must destroy the newly created #ckmc_key_s by calling ckmc_key_free() if it is no + * longer needed. + * @param[in] raw_key The byte array of key. The @a raw_key may be encrypted with password. * @param[in] key_size The byte size of @a raw_key - * @param[in] key_type The @a raw_key's type - * @param[in] password The byte array used to decrypt @a raw_key inside key manager \n - * If @a raw_key is not encrypted, @a password can be null + * @param[in] key_type The type of @a raw_key + * @param[in] password The byte array used to decrypt @a raw_key inside key manager. If @a raw_key + * is not encrypted, @a password can be NULL * @param[out] ppkey The pointer to a newly created #ckmc_key_s handle * @return #CKMC_ERROR_NONE on success, * otherwise a negative error value @@ -535,7 +537,11 @@ int ckmc_alias_new(const char *owner_id, const char *alias, char **full_alias); * @see ckmc_key_free() * @see #ckmc_key_s */ -int ckmc_key_new(unsigned char *raw_key, size_t key_size, ckmc_key_type_e key_type, char *password, ckmc_key_s **ppkey); +int ckmc_key_new(unsigned char *raw_key, + size_t key_size, + ckmc_key_type_e key_type, + char *password, + ckmc_key_s **ppkey); /** @@ -549,7 +555,8 @@ void ckmc_key_free(ckmc_key_s *key); /** * @brief Creates a new #ckmc_raw_buffer_s handle and returns it. * @since_tizen @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif - * @remarks You must destroy the newly created #ckmc_raw_buffer_s by calling ckmc_buffer_free() if it is no longer needed. + * @remarks You must destroy the newly created #ckmc_raw_buffer_s by calling ckmc_buffer_free() if + * it is no longer needed. * @param[in] data The byte array of buffer * @param[in] size The byte size of buffer * @param[out] ppbuffer The pointer to a newly created #ckmc_raw_buffer_s handle @@ -575,7 +582,8 @@ void ckmc_buffer_free(ckmc_raw_buffer_s *buffer); /** * @brief Creates a new #ckmc_cert_s handle and returns it. * @since_tizen @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif - * @remarks You must destroy the newly created #ckmc_cert_s by calling ckmc_cert_free() if it is no longer needed. + * @remarks You must destroy the newly created #ckmc_cert_s by calling ckmc_cert_free() if it is no + * longer needed. * @param[in] raw_cert The byte array of certificate * @param[in] cert_size The byte size of raw_cert * @param[in] data_format The encoding format of raw_cert @@ -589,7 +597,10 @@ void ckmc_buffer_free(ckmc_raw_buffer_s *buffer); * @see ckmc_load_cert_from_file() * @see #ckmc_cert_s */ -int ckmc_cert_new(unsigned char *raw_cert, size_t cert_size, ckmc_data_format_e data_format, ckmc_cert_s **ppcert); +int ckmc_cert_new(unsigned char *raw_cert, + size_t cert_size, + ckmc_data_format_e data_format, + ckmc_cert_s **ppcert); /** @@ -604,9 +615,10 @@ void ckmc_cert_free(ckmc_cert_s *cert); /** * @brief Creates a new #ckmc_cert_s handle from a given file and returns it. * @since_tizen 2.3 - * @remarks You must destroy the newly created #ckmc_cert_s by calling ckmc_cert_free() if it is no longer needed. - * @param[in] file_path The path of certificate file to be loaded \n - * The only DER or PEM encoded certificate file is supported + * @remarks You must destroy the newly created #ckmc_cert_s by calling ckmc_cert_free() if it is no + * longer needed. + * @param[in] file_path The path of certificate file to be loaded. Only DER or PEM encoded + * certificate file is supported * @param[out] cert The pointer of newly created #ckmc_cert_s handle * @return #CKMC_ERROR_NONE on success, * otherwise a negative error value @@ -623,8 +635,10 @@ int ckmc_load_cert_from_file(const char *file_path, ckmc_cert_s **cert); /** * @brief Creates a new #ckmc_pkcs12_s handle and returns it. * @since_tizen @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif - * @remarks You must destroy the newly created #ckmc_pkcs12_s by calling ckmc_pkcs12_free() if it is no longer needed. - * @remarks On success, private_key, cert && ca_cert_list ownership is transferred into newly returned ckmc_pkcs12_s. + * @remarks You must destroy the newly created #ckmc_pkcs12_s by calling ckmc_pkcs12_free() if it is + * no longer needed. + * @remarks On success, private_key, cert && ca_cert_list ownership is transferred into newly + * returned @a pkcs12_bundle. * @param[in] private_key #ckmc_key_s handle to the private key (optional) * @param[in] cert #ckmc_cert_s handle to the certificate (optional) * @param[in] ca_cert_list #ckmc_cert_list_s list of chain certificate handles (optional) @@ -632,7 +646,8 @@ int ckmc_load_cert_from_file(const char *file_path, ckmc_cert_s **cert); * @return #CKMC_ERROR_NONE on success, * otherwise a negative error value * @retval #CKMC_ERROR_NONE Successful - * @retval #CKMC_ERROR_INVALID_PARAMETER Input parameter is invalid or private_key, cert and ca_cert_list all are null + * @retval #CKMC_ERROR_INVALID_PARAMETER Input parameter is invalid or @a private_key, @a cert and + * @a ca_cert_list all are NULL * @retval #CKMC_ERROR_OUT_OF_MEMORY Not enough memory * @see ckmc_pkcs12_free() * @see ckmc_pkcs12_load() @@ -641,24 +656,30 @@ int ckmc_load_cert_from_file(const char *file_path, ckmc_cert_s **cert); * @see #ckmc_cert_list_s * @see #ckmc_pkcs12_s */ -int ckmc_pkcs12_new(ckmc_key_s *private_key, ckmc_cert_s *cert, ckmc_cert_list_s *ca_cert_list, ckmc_pkcs12_s **pkcs12_bundle); +int ckmc_pkcs12_new(ckmc_key_s *private_key, + ckmc_cert_s *cert, + ckmc_cert_list_s *ca_cert_list, + ckmc_pkcs12_s **pkcs12_bundle); /** - * @deprecated Deprecated since @if MOBILE 2.4. @elseif WEARABLE 3.0. @endif [Use ckmc_pkcs12_load() instead] - * @brief Creates a new #ckmc_key_s (@a private_key), #ckmc_cert_s (@a cert), and #ckmc_cert_list_s (@a ca_cert_list) handle from a given PKCS#12 file and returns them. + * @deprecated Deprecated since @if MOBILE 2.4. @elseif WEARABLE 3.0. @endif + * [Use ckmc_pkcs12_load() instead] + * @brief Creates a new #ckmc_key_s (@a private_key), #ckmc_cert_s (@a cert), + * and #ckmc_cert_list_s (@a ca_cert_list) handle from a given PKCS#12 file and returns them. * @since_tizen 2.3 - * @remarks You must destroy the newly created #ckmc_key_s, #ckmc_cert_s, and - * #ckmc_cert_list_s by calling ckmc_key_free(), ckmc_cert_free(), and - * ckmc_cert_list_all_free() if they are no longer needed. + * @remarks You must destroy the newly created @a private_key, @a cert and @a ca_cert_list + by calling ckmc_key_free(), ckmc_cert_free(), and ckmc_cert_list_all_free() if they are + no longer needed. * @param[in] file_path The path of PKCS12 file to be loaded - * @param[in] passphrase The passphrase used to decrypt the PCKS12 file \n - * If PKCS12 file is not encrypted, passphrase can be null + * @param[in] passphrase The passphrase used to decrypt the PCKS12 file. If PKCS12 file is not + * encrypted, passphrase can be NULL * @param[out] private_key The pointer of newly created #ckmc_key_s handle for a private key - * @param[out] cert The pointer of newly created #ckmc_cert_s handle for a certificate \n - * It is null if the PKCS12 file does not contain a certificate - * @param[out] ca_cert_list The pointer of newly created #ckmc_cert_list_s handle for CA certificates \n - * It is null if the PKCS12 file does not contain CA certificates + * @param[out] cert The pointer of newly created #ckmc_cert_s handle for a certificate. It is NULL + * if the PKCS12 file does not contain a certificate + * @param[out] ca_cert_list The pointer of newly created #ckmc_cert_list_s handle for CA + * certificates. It is NULL if the PKCS12 file does not contain + * CA certificates * @return #CKMC_ERROR_NONE on success, * otherwise a negative error value * @retval #CKMC_ERROR_NONE Successful @@ -674,21 +695,28 @@ int ckmc_pkcs12_new(ckmc_key_s *private_key, ckmc_cert_s *cert, ckmc_cert_list_s * @see #ckmc_cert_s * @see #ckmc_cert_list_s */ -int ckmc_load_from_pkcs12_file(const char *file_path, const char *passphrase, ckmc_key_s **private_key, ckmc_cert_s **cert, ckmc_cert_list_s **ca_cert_list) TIZEN_DEPRECATED_API; +int ckmc_load_from_pkcs12_file(const char *file_path, + const char *passphrase, + ckmc_key_s **private_key, + ckmc_cert_s **cert, + ckmc_cert_list_s **ca_cert_list) TIZEN_DEPRECATED_API; /** * @brief Creates a new #ckmc_pkcs12_s handle from a given PKCS#12 file and returns it. * @since_tizen @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif - * @remarks You must destroy the newly created #ckmc_pkcs12_s by calling ckmc_pkcs12_free() if they are no longer needed. + * @remarks You must destroy the newly created #ckmc_pkcs12_s by calling ckmc_pkcs12_free() if they + * are no longer needed. * @param[in] file_path The path of PKCS12 file to be loaded - * @param[in] passphrase The passphrase used to decrypt the PCKS12 file \n - * If PKCS12 file is not encrypted, passphrase can be null - * @param[out] pkcs12_bundle The pointer of newly created #ckmc_cert_list_s handle for CA certificates \n - * It is null if the PKCS12 file does not contain CA certificates + * @param[in] passphrase The passphrase used to decrypt the PCKS12 file. If PKCS12 file is not + * encrypted, passphrase can be NULL + * @param[out] pkcs12_bundle The pointer of newly created #ckmc_cert_list_s handle for + * CA certificates. It is NULL if the PKCS12 file does not contain + * CA certificates * @return #CKMC_ERROR_NONE on success, * otherwise a negative error value * @retval #CKMC_ERROR_NONE Successful + * @retval #CKMC_ERROR_INVALID_PARAMETER Input parameter is invalid * @retval #CKMC_ERROR_OUT_OF_MEMORY Not enough memory space * @retval #CKMC_ERROR_INVALID_FORMAT Invalid PKCS12 file format * @retval #CKMC_ERROR_FILE_ACCESS_DENIED Provided file does not exist or cannot be accessed @@ -709,11 +737,11 @@ void ckmc_pkcs12_free(ckmc_pkcs12_s *pkcs12); /** - * @brief Creates a new #ckmc_alias_list_s handle and returns it. - * The alias pointer in the returned #ckmc_alias_list_s handle points to the provided characters and next is null. + * @brief Creates a new #ckmc_alias_list_s handle and returns it. The alias pointer in the returned + * #ckmc_alias_list_s handle points to the provided characters and next is NULL. * @since_tizen @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif - * @remarks You must destroy the newly created #ckmc_alias_list_s - * by calling ckmc_alias_list_free() or ckmc_alias_list_all_free() if it is no longer needed. + * @remarks You must destroy the newly created #ckmc_alias_list_s by calling ckmc_alias_list_free() + * or ckmc_alias_list_all_free() if it is no longer needed. * @param[in] alias The first item to be set in the newly created #ckmc_alias_list_s * @param[out] ppalias_list The pointer to a newly created #ckmc_alias_list_s handle * @return #CKMC_ERROR_NONE on success, @@ -728,10 +756,13 @@ int ckmc_alias_list_new(char *alias, ckmc_alias_list_s **ppalias_list); /** - * @brief Creates a new #ckmc_alias_list_s handle, adds it to a previous #ckmc_alias_list_s and returns it. - * The alias pointer in the returned #ckmc_alias_list_s handle points to the provided characters and next is null. + * @brief Creates a new #ckmc_alias_list_s handle, adds it to a previous #ckmc_alias_list_s and + * returns it. The alias pointer in the returned #ckmc_alias_list_s handle points to the + * provided characters and next is NULL. * @since_tizen @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif - * @param[in] previous The last #ckmc_alias_list_s handle to which a newly created #ckmc_alias_list_s is added + * @remarks You must destroy the newly created @a pplast using ckmc_alias_list_free() + * @param[in] previous The last #ckmc_alias_list_s handle to which a newly created + * #ckmc_alias_list_s is added * @param[in] alias The item to be set in the newly created #ckmc_alias_list_s * @param[out] pplast The pointer to a newly created and added #ckmc_alias_list_s handle * @return #CKMC_ERROR_NONE on success, @@ -746,7 +777,8 @@ int ckmc_alias_list_add(ckmc_alias_list_s *previous, char *alias, ckmc_alias_lis /** - * @brief Destroys the #ckmc_alias_list_s handle and releases resources of #ckmc_alias_list_s from the provided first handle cascadingly. + * @brief Destroys the #ckmc_alias_list_s handle and releases resources of #ckmc_alias_list_s from + * the provided first handle cascadingly. * @since_tizen @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif * @remarks It does not destroy an alias itself in #ckmc_alias_list_s. * @param[in] first The first #ckmc_alias_list_s handle to destroy @@ -757,7 +789,8 @@ void ckmc_alias_list_free(ckmc_alias_list_s *first); /** - * @brief Destroys the #ckmc_alias_list_s handle and releases all its resources from the provided first handle cascadingly. + * @brief Destroys the #ckmc_alias_list_s handle and releases all its resources from the provided + * first handle cascadingly. * @since_tizen @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif * @remarks It also destroys the alias in #ckmc_alias_list_s. * @param[in] first The first #ckmc_alias_list_s handle to destroy @@ -767,10 +800,11 @@ void ckmc_alias_list_all_free(ckmc_alias_list_s *first); /** - * @brief Creates a new #ckmc_cert_list_s handle and returns it. - * The cert pointer in the returned #ckmc_cert_list_s handle points to the provided #ckmc_cert_s and next is null. + * @brief Creates a new #ckmc_cert_list_s handle and returns it. The cert pointer in the returned + * #ckmc_cert_list_s handle points to the provided #ckmc_cert_s and next is NULL. * @since_tizen @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif - * @remarks You must destroy the newly created #ckmc_cert_list_s by calling ckmc_cert_list_free() or ckmc_cert_list_all_free() if it is no longer needed. + * @remarks You must destroy the newly created #ckmc_cert_list_s by calling ckmc_cert_list_free() or + * ckmc_cert_list_all_free() if it is no longer needed. * @param[in] cert The first item to be set in the newly created #ckmc_cert_list_s * @param[out] ppalias_list The pointer to a newly created #ckmc_alias_list_s handle * @return #CKMC_ERROR_NONE on success, @@ -785,10 +819,13 @@ int ckmc_cert_list_new(ckmc_cert_s *cert, ckmc_cert_list_s **ppalias_list); /** - * @brief Creates a new #ckmc_cert_list_s handle, adds it to a previous #ckmc_cert_list_s and returns it. - * The cert pointer in the returned #ckmc_alias_list_s handle points to the provided #ckmc_cert_s and next is null. + * @brief Creates a new #ckmc_cert_list_s handle, adds it to a previous #ckmc_cert_list_s and + * returns it. The cert pointer in the returned #ckmc_alias_list_s handle points to the + * provided #ckmc_cert_s and next is NULL. * @since_tizen @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif - * @param[in] previous The last #ckmc_cert_list_s handle to which a newly created #ckmc_cert_list_s is added + * @remarks You must destroy the newly created @a pplast using ckmc_cert_list_free() + * @param[in] previous The last #ckmc_cert_list_s handle to which a newly created #ckmc_cert_list_s + * is added * @param[in] cert The item to be set in the newly created #ckmc_cert_list_s * @param[out] pplast The pointer to a newly created and added #ckmc_alias_list_s handle * @return #CKMC_ERROR_NONE on success, @@ -803,7 +840,8 @@ int ckmc_cert_list_add(ckmc_cert_list_s *previous, ckmc_cert_s *cert, ckmc_cert_ /** - * @brief Destroys the #ckmc_cert_list_s handle and releases resources of #ckmc_cert_list_s from the provided first handle cascadingly. + * @brief Destroys the #ckmc_cert_list_s handle and releases resources of #ckmc_cert_list_s from the + * provided first handle cascadingly. * @since_tizen @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif * @remarks It does not destroy #ckmc_cert_s itself in #ckmc_cert_list_s. * @param[in] first The first #ckmc_cert_list_s handle to destroy @@ -814,7 +852,8 @@ void ckmc_cert_list_free(ckmc_cert_list_s *first); /** - * @brief Destroys the #ckmc_cert_list_s handle and releases all its resources from the provided first handle cascadingly. + * @brief Destroys the #ckmc_cert_list_s handle and releases all its resources from the provided + * first handle cascadingly. * @since_tizen 2.3 * @remarks It also destroys #ckmc_cert_s in #ckmc_cert_list_s. * @param[in] first The first #ckmc_cert_list_s handle to destroy @@ -827,7 +866,8 @@ void ckmc_cert_list_all_free(ckmc_cert_list_s *first); * @brief Creates new parameter list. * @since_tizen 3.0 * @remarks Caller is responsible for freeing it with ckmc_param_list_free(). - * @param[in] pparams Double pointer to the handle of param list to which the newly created algorithm param list will be assigned + * @param[in] pparams Double pointer to the handle of param list to which the newly created + * algorithm param list will be assigned * @return #CKMC_ERROR_NONE on success, * otherwise a negative error value * @retval #CKMC_ERROR_NONE Successful @@ -847,11 +887,11 @@ int ckmc_param_list_new(ckmc_param_list_h *pparams); * @brief Sets integer parameter to the list. * @since_tizen 3.0 * @remarks Caller is responsible for #ckmc_param_list_h creation. - * @param[in] params Algorithm param list handle created with ckmc_param_list_new() or ckmc_generate_new_params() \n - * New param with @a name and @a value will be set here - * @param[in] name Name of parameter to set \n - * Existing parameter will be overwritten \n - * Passing invalid parameter name will result in an error + * @param[in] params Algorithm param list handle created with ckmc_param_list_new() or + * ckmc_generate_new_params(). New param with @a name and @a value will be set + * here + * @param[in] name Name of parameter to set. Existing parameter will be overwritten. Passing invalid + * parameter name will result in an error * @param[in] value Value of the parameter in form of a integer * @return #CKMC_ERROR_NONE on success, * otherwise a negative error value @@ -874,13 +914,13 @@ int ckmc_param_list_set_integer(ckmc_param_list_h params, ckmc_param_name_e name * @brief Sets buffer parameter to the list. * @since_tizen 3.0 * @remarks Caller is responsible for #ckmc_param_list_h creation. - * @param[in] params Algorithm param list handle created with ckmc_param_list_new() or ckmc_generate_new_params() - * New param with @a name and @a buffer will be set here - * @param[in] name Name of parameter to set \n - * Existing parameter will be overwritten \n - * Passing invalid parameter name will result in an error - * @param[in] buffer Value of the parameter in form of a buffer \n - * Caller is responsible for creating and freeing the buffer + * @param[in] params Algorithm param list handle created with ckmc_param_list_new() or + * ckmc_generate_new_params(). New param with @a name and @a buffer will be set + * here + * @param[in] name Name of parameter to set. Existing parameter will be overwritten. Passing invalid + * parameter name will result in an error + * @param[in] buffer Value of the parameter in form of a buffer. Caller is responsible for creating + * and freeing the buffer * @return #CKMC_ERROR_NONE on success, * otherwise a negative error value * @retval #CKMC_ERROR_NONE Successful @@ -895,15 +935,17 @@ int ckmc_param_list_set_integer(ckmc_param_list_h params, ckmc_param_name_e name * @see #ckmc_param_name_e * @see #ckmc_algo_type_e */ -int ckmc_param_list_set_buffer(ckmc_param_list_h params, ckmc_param_name_e name, const ckmc_raw_buffer_s *buffer); +int ckmc_param_list_set_buffer(ckmc_param_list_h params, + ckmc_param_name_e name, + const ckmc_raw_buffer_s *buffer); /** * @brief Gets integer parameter from the list. * @since_tizen 3.0 * @remarks Caller is responsible for #ckmc_param_list_h creation. - * @param[in] params Algorithm param list handle created with ckmc_param_list_new() or ckmc_generate_new_params() - * which contains param with @a name + * @param[in] params Algorithm param list handle created with ckmc_param_list_new() or + * ckmc_generate_new_params() which contains param with @a name * @param[in] name Name of parameter to get * @param[out] pvalue Value of the parameter in form of a integer * @return #CKMC_ERROR_NONE on success, @@ -927,11 +969,11 @@ int ckmc_param_list_get_integer(ckmc_param_list_h params, ckmc_param_name_e name * @brief Gets buffer parameter from the list. * @since_tizen 3.0 * @remarks Caller is responsible for #ckmc_param_list_h creation. - * @param[in] params Algorithm param list handle created with ckmc_param_list_new() or ckmc_generate_new_params() - * which contains param with @a name + * @remarks You must destroy the @a ppbuffer using ckmc_buffer_free() + * @param[in] params Algorithm param list handle created with ckmc_param_list_new() or + * ckmc_generate_new_params() which contains param with @a name * @param[in] name Name of parameter to get - * @param[out] ppbuffer Value of the parameter in form of a buffer \n - * Caller is responsible for creating and freeing the buffer + * @param[out] ppbuffer Value of the parameter in form of a buffer * @return #CKMC_ERROR_NONE on success, * otherwise a negative error value * @retval #CKMC_ERROR_NONE Successful @@ -947,7 +989,9 @@ int ckmc_param_list_get_integer(ckmc_param_list_h params, ckmc_param_name_e name * @see #ckmc_param_name_e * @see #ckmc_algo_type_e */ -int ckmc_param_list_get_buffer(ckmc_param_list_h params, ckmc_param_name_e name, ckmc_raw_buffer_s **ppbuffer); +int ckmc_param_list_get_buffer(ckmc_param_list_h params, + ckmc_param_name_e name, + ckmc_raw_buffer_s **ppbuffer); /** @@ -974,9 +1018,11 @@ void ckmc_param_list_free(ckmc_param_list_h params); * @remarks Algorithm parameters are set to default values. Optional fields are left empty. * Initialization vectors are left empty (they have to be set manually). * Caller is responsible for freeing the list with ckmc_param_list_free(). - * @remarks If the function returns error, provided param list may contain some of default parameters. + * @remarks If the function returns error, provided param list may contain some of default + * parameters. * @param[in] type Type of the algorithm - * @param[out] pparams Newly generated handle of param list which should be freed by caller after use + * @param[out] pparams Newly generated handle of param list which should be freed by caller after + * use * @return #CKMC_ERROR_NONE on success, * otherwise a negative error value * @retval #CKMC_ERROR_NONE Successful @@ -1004,4 +1050,4 @@ int ckmc_generate_new_params(ckmc_algo_type_e type, ckmc_param_list_h *pparams); #endif -#endif /* __TIZEN_CORE_CKMC_TYPE_H */ +#endif /* __TIZEN_CORE_CKMC_TYPE_H__ */ -- 2.7.4 From f93707e7ba4c13728244c67c6e3c50bc7ffb1686 Mon Sep 17 00:00:00 2001 From: Krzysztof Jackiewicz Date: Thu, 6 Apr 2023 15:41:12 +0200 Subject: [PATCH 09/16] Fix documentation issues in E2EE API * Issues raised by check-header.py (see: https://github.sec.samsung.net/RPO7-TIZEN/tizen-native-api-review-script) * Other issues raised during ACR. * Own initiative cleanup. Changes done separately to simplify ACR review. Change-Id: I346b979cd16f1cda8a0fd970ae38f7db7bb093d7 --- src/include/ckmc/ckmc-manager.h | 32 ++++++++++--------- src/include/ckmc/ckmc-type.h | 68 ++++++++++++++++++++++------------------- 2 files changed, 54 insertions(+), 46 deletions(-) diff --git a/src/include/ckmc/ckmc-manager.h b/src/include/ckmc/ckmc-manager.h index 03d22f6..dcec32a 100644 --- a/src/include/ckmc/ckmc-manager.h +++ b/src/include/ckmc/ckmc-manager.h @@ -1104,7 +1104,7 @@ int ckmc_decrypt_data(ckmc_param_list_h params, /** * @brief Unwraps one key with another and stores it inside key manager. * - * @since_tizen 7.5 + * @since_tizen 6.5 * * @remarks The wrapping key must be either symmetric (#CKMC_KEY_AES) or private RSA * (#CKMC_KEY_RSA_PRIVATE). @@ -1131,6 +1131,8 @@ int ckmc_decrypt_data(ckmc_param_list_h params, * * @return @c 0 on success, otherwise a negative error value * @retval #CKMC_ERROR_NONE Successful + * @retval #CKMC_ERROR_PERMISSION_DENIED Insufficient permissions to access key manager, the + * wrapping key or to create the unwrapped key * @retval #CKMC_ERROR_INVALID_PARAMETER Input parameter is invalid (missing or invalid mandatory * algorithm parameter, GCM tag authentication failed, * @a wrapping_key_alias = NULL, @a alias = NULL, @@ -1142,7 +1144,6 @@ int ckmc_decrypt_data(ckmc_param_list_h params, * @retval #CKMC_ERROR_DB_ERROR Failed due to a database error * @retval #CKMC_ERROR_AUTHENTICATION_FAILED Wrapping key decryption failed because * @a wrapping_key_password is incorrect - * @retval #CKMC_ERROR_PERMISSION_DENIED Failed to access key manager * @retval #CKMC_ERROR_SERVER_ERROR Unknown error * * @pre User is already logged in and the user key is already loaded into memory in plain text form. @@ -1163,10 +1164,11 @@ int ckmc_import_wrapped_key(const ckmc_param_list_h params, /** * @brief Wraps one key with another and returns it to the client. * - * @since_tizen 7.5 + * @since_tizen 6.5 * * @remarks The wrapping key must be either symmetric (#CKMC_KEY_AES) or public RSA * (#CKMC_KEY_RSA_PUBLIC). + * @remarks The @a ppwrapped_key should be released using ckmc_key_free(). * * @param[in] params Algorithm parameter list handle. See #ckmc_param_list_h and #ckmc_algo_type_e * for details. Supported algorithms: @@ -1177,22 +1179,23 @@ int ckmc_import_wrapped_key(const ckmc_param_list_h params, * - #CKMC_ALGO_RSA_OAEP * @param[in] wrapping_key_alias The name of the wrapping key * @param[in] wrapping_key_password An optional password of the wrapping key - * @param[in] wrapped_key_alias The name of the key to be wrapped and exported - * @param[in] wrapped_key_password An optional password used to decrypt the key pointed by @a wrapped_key_alias + * @param[in] alias The name of the key to be wrapped and exported + * @param[in] password An optional password used to decrypt the key pointed by @a alias * @param[out] ppwrapped_key The wrapped key * * @return @c 0 on success, otherwise a negative error value * @retval #CKMC_ERROR_NONE Successful + * @retval #CKMC_ERROR_PERMISSION_DENIED Insuffucient permissions to access key manager, the + * wrapping key or the key being wrapped * @retval #CKMC_ERROR_INVALID_PARAMETER Input parameter is invalid (missing or invalid mandatory * algorithm parameter, GCM tag authentication failed, - * @a wrapping_key_alias = NULL, @a wrapped_key_alias = NULL, + * @a wrapping_key_alias = NULL, @a alias = NULL, * @a ppwrapped_key = NULL) * @retval #CKMC_ERROR_DB_LOCKED A user key is not loaded in memory (a user is not logged in) - * @retval #CKMC_ERROR_DB_ALIAS_UNKNOWN @a wrapping_key_alias or @a wrapped_key_alias does not exist + * @retval #CKMC_ERROR_DB_ALIAS_UNKNOWN @a wrapping_key_alias or @a alias does not exist * @retval #CKMC_ERROR_DB_ERROR Failed due to a database error * @retval #CKMC_ERROR_AUTHENTICATION_FAILED Wrapping key decryption failed because * @a wrapping_key_password is incorrect - * @retval #CKMC_ERROR_PERMISSION_DENIED Failed to access key manager * @retval #CKMC_ERROR_SERVER_ERROR Unknown error * * @pre User is already logged in and the user key is already loaded into memory in plain text form. @@ -1204,15 +1207,15 @@ int ckmc_import_wrapped_key(const ckmc_param_list_h params, int ckmc_export_wrapped_key(const ckmc_param_list_h params, const char *wrapping_key_alias, const char *wrapping_key_password, - const char *wrapped_key_alias, - const char *wrapped_key_password, + const char *alias, + const char *password, ckmc_key_s **ppwrapped_key); /** * @brief Derives a key from another key/secret and stores it inside key manager. * - * @since_tizen 7.5 + * @since_tizen 6.5 * * @remarks The derived key will be a symmetric one. It will be stored as a #CKMC_KEY_AES. * @@ -1227,6 +1230,8 @@ int ckmc_export_wrapped_key(const ckmc_param_list_h params, * * @return @c 0 on success, otherwise a negative error value * @retval #CKMC_ERROR_NONE Successful + * @retval #CKMC_ERROR_PERMISSION_DENIED Insufficient permissions to access key manager, the secret + * or to create the new key * @retval #CKMC_ERROR_INVALID_PARAMETER Input parameter is invalid (missing or invalid mandatory * algorithm parameter, @a secret_alias = NULL, * @a new_key_alias = NULL) @@ -1234,15 +1239,14 @@ int ckmc_export_wrapped_key(const ckmc_param_list_h params, * @retval #CKMC_ERROR_DB_ALIAS_UNKNOWN @a secret_alias does not exist * @retval #CKMC_ERROR_DB_ALIAS_EXISTS @a new_key_alias already exists * @retval #CKMC_ERROR_DB_ERROR Failed due to a database error - * @retval #CKMC_ERROR_PERMISSION_DENIED Failed to access key manager - * @retval #CKMC_ERROR_AUTHENTICATION_FAILED Secret decryption failed because @a secret_password is + * @retval #CKMC_ERROR_AUTHENTICATION_FAILED Secret decryption failed because @a secret_password is * incorrect * @retval #CKMC_ERROR_SERVER_ERROR Unknown error * * @pre User is already logged in and the user key is already loaded into memory in plain text form. * * @par Example - * @snippet examples/key_derive.cpp KEY_DERIVE example + * @snippet key_derive.cpp KEY_DERIVE example * * @see #ckmc_param_list_h * @see #ckmc_policy_s diff --git a/src/include/ckmc/ckmc-type.h b/src/include/ckmc/ckmc-type.h index d1fddef..e568655 100644 --- a/src/include/ckmc/ckmc-type.h +++ b/src/include/ckmc/ckmc-type.h @@ -300,45 +300,46 @@ typedef enum __ckmc_param_name { CKMC_PARAM_ED_TAG_LEN, /**< integer - tag length in bits */ CKMC_PARAM_ED_LABEL, /**< buffer - RSA OAEP label (not supported at the moment) */ - CKMC_PARAM_KDF_PRF = 401, /**< integer - pseudo-random function number (see #ckmc_kdf_prf_e) */ + CKMC_PARAM_KDF_PRF = 401, /**< integer - pseudo-random function number (see #ckmc_kdf_prf_e) + (Since 6.5) */ CKMC_PARAM_KDF_LEN, /**< integer - length of the derived key in bytes. The value must be one of - {16, 24, 32} */ + {16, 24, 32} (Since 6.5) */ - CKMC_PARAM_KBKDF_MODE, /**< integer - KDF mode number (see #ckmc_kbkdf_mode_e) */ + CKMC_PARAM_KBKDF_MODE, /**< integer - KDF mode number (see #ckmc_kbkdf_mode_e) (Since 6.5) */ CKMC_PARAM_KBKDF_LABEL, /**< buffer - the purpose for the derived key. Conflicts with - #CKMC_PARAM_KBKDF_FIXED_INPUT */ + #CKMC_PARAM_KBKDF_FIXED_INPUT (Since 6.5) */ CKMC_PARAM_KBKDF_CONTEXT, /**< buffer - information related to the derived key. Conflicts with - #CKMC_PARAM_KBKDF_FIXED_INPUT */ + #CKMC_PARAM_KBKDF_FIXED_INPUT (Since 6.5) */ - CKMC_PARAM_KBKDF_FIXED_INPUT, /**< buffer - KBKDF fixed input replacing context and label. - Conflicts with: + CKMC_PARAM_KBKDF_FIXED_INPUT, /**< buffer - KBKDF fixed input replacing context and label + (Since 6.5). Conflicts with: - #CKMC_PARAM_KBKDF_LABEL, - #CKMC_PARAM_KBKDF_CONTEXT, - #CKMC_PARAM_KBKDF_LLEN, - #CKMC_PARAM_KBKDF_NO_SEPARATOR */ CKMC_PARAM_KBKDF_COUNTER_LOCATION, /**< integer - specifies location of the counter in KBKDF - (see #ckmc_kbkdf_counter_location_e) */ + (see #ckmc_kbkdf_counter_location_e) (Since 6.5) */ CKMC_PARAM_KBKDF_RLEN, /**< integer - specifies the length of the counter representation in bits in KBKDF. The value must be one of {8, 16, 24, 32}. If not set, the - default value = 32 will be used */ + default value = 32 will be used. (Since 6.5) */ CKMC_PARAM_KBKDF_LLEN, /**< integer - specifies the length of the length suffix representation in bits in KBKDF. The value must be one of {0, 8, 16, 24, 32}. If set to 0 the length suffix will be skipped. If not set, the default value = 32 will be used. The length suffix is skipped if #CKMC_PARAM_KBKDF_FIXED_INPUT is passed and this parameter conflicts - with it */ + with it. (Since 6.5) */ CKMC_PARAM_KBKDF_NO_SEPARATOR, /**< integer - presence of this parameter will skip the zero octet separator between label and context in KBKDF. All values are allowed. This parameter conflicts with - #CKMC_PARAM_KBKDF_FIXED_INPUT. */ + #CKMC_PARAM_KBKDF_FIXED_INPUT. (Since 6.5) */ - CKMC_PARAM_ECDH_PUBKEY, /**< buffer - EC public key in DER form (see #ckmc_key_s) */ + CKMC_PARAM_ECDH_PUBKEY, /**< buffer - EC public key in DER form (see #ckmc_key_s) (Since 6.5) */ } ckmc_param_name_e; /** - * @brief Enumeration for key derivation function pseudo-random function parameter - * @since_tizen 7.5 + * @brief Enumeration for key derivation function pseudo-random function parameter. + * @since_tizen 6.5 * * @see ckmc_key_derive() * @see #ckmc_param_name_e @@ -350,8 +351,8 @@ typedef enum __ckmc_kdf_prf { } ckmc_kdf_prf_e; /** - * @brief Enumeration for key based key derivation function mode - * @since_tizen 7.5 + * @brief Enumeration for key based key derivation function mode. + * @since_tizen 6.5 * * @see ckmc_key_derive() * @see #ckmc_param_name_e @@ -361,8 +362,8 @@ typedef enum __ckmc_kbkdf_mode { } ckmc_kbkdf_mode_e; /** - * @brief Enumeration for KBKDF counter location relative to fixed input - * @since_tizen 7.5 + * @brief Enumeration for KBKDF counter location relative to fixed input. + * @since_tizen 6.5 * * @see ckmc_key_derive() * @see #ckmc_param_name_e @@ -438,23 +439,26 @@ typedef enum __ckmc_algo_type { CKMC_ALGO_KBKDF, /**< Key based key derivation algorithm Supported parameters: - - CKMC_PARAM_ALGO_TYPE = CKMC_ALGO_KBKDF(mandatory), - - CKMC_PARAM_KDF_PRF = pseudo-random function (see #ckmc_kdf_prf_e)(mandatory), - - CKMC_PARAM_KBKDF_MODE = KDF mode (see #ckmc_kbkdf_mode_e)(mandatory), - - CKMC_PARAM_KBKDF_LABEL = the purpose for the derived key(optional), - - CKMC_PARAM_KBKDF_CONTEXT = information related to the derived key(optional), - - CKMC_PARAM_KDF_LEN = length of the derived key(mandatory) - - CKMC_PARAM_KBKDF_FIXED_INPUT = replacement for context and label(optional), - - CKMC_PARAM_KBKDF_COUNTER_LOCATION = counter location - (see #ckmc_kbkdf_counter_location_e)(mandatory), - - CKMC_PARAM_KBKDF_RLEN = length of the counter representation(optional), - - CKMC_PARAM_KBKDF_LLEN = length of the length suffix representation(optional), - - CKMC_PARAM_KBKDF_NO_SEPARATOR = existence of zero separator(optional) */ + - #CKMC_PARAM_ALGO_TYPE = #CKMC_ALGO_KBKDF (mandatory), + - #CKMC_PARAM_KDF_PRF = pseudo-random function (see #ckmc_kdf_prf_e) + (mandatory), + - #CKMC_PARAM_KBKDF_MODE = KDF mode (see #ckmc_kbkdf_mode_e) (mandatory), + - #CKMC_PARAM_KBKDF_LABEL = the purpose for the derived key (optional), + - #CKMC_PARAM_KBKDF_CONTEXT = information related to the derived key + (optional), + - #CKMC_PARAM_KDF_LEN = length of the derived key (mandatory) + - #CKMC_PARAM_KBKDF_FIXED_INPUT = replacement for context and label (optional), + - #CKMC_PARAM_KBKDF_COUNTER_LOCATION = counter location + (see #ckmc_kbkdf_counter_location_e) (mandatory), + - #CKMC_PARAM_KBKDF_RLEN = length of the counter representation (optional), + - #CKMC_PARAM_KBKDF_LLEN = length of the length suffix representation + (optional), + - #CKMC_PARAM_KBKDF_NO_SEPARATOR = existence of zero separator (optional) */ CKMC_ALGO_ECDH, /**< ECDH shared secret key agreement protocol Supported parameters (all are required): - - CKMC_PARAM_ALGO_TYPE = CKMC_ALGO_ECDH, - - CKMC_PARAM_ECDH_PUBKEY = peer's public key (see #ckmc_key_s) */ + - #CKMC_PARAM_ALGO_TYPE = #CKMC_ALGO_ECDH, + - #CKMC_PARAM_ECDH_PUBKEY = peer's public key (see #ckmc_key_s) */ } ckmc_algo_type_e; /** -- 2.7.4 From 27e65e26aa203b5625c951179778639bea94340d Mon Sep 17 00:00:00 2001 From: Krzysztof Jackiewicz Date: Mon, 17 Apr 2023 12:01:09 +0200 Subject: [PATCH 10/16] Unify variable naming in key export Change-Id: Ic89b6105e420b9eceb93e9e6bdf112c4de3c1a65 --- src/include/ckm/ckm-manager.h | 4 ++-- src/manager/client-capi/ckmc-manager.cpp | 25 ++++++++++++++----------- src/manager/client/client-manager-impl.cpp | 12 ++++++------ src/manager/client/client-manager-impl.h | 4 ++-- src/manager/client/client-manager.cpp | 8 ++++---- src/manager/service/ckm-logic.cpp | 12 ++++++------ src/manager/service/ckm-logic.h | 6 +++--- src/manager/service/ckm-service.cpp | 17 ++++++++--------- 8 files changed, 45 insertions(+), 43 deletions(-) diff --git a/src/include/ckm/ckm-manager.h b/src/include/ckm/ckm-manager.h index 5eb3f17..2208def 100644 --- a/src/include/ckm/ckm-manager.h +++ b/src/include/ckm/ckm-manager.h @@ -187,8 +187,8 @@ public: int exportWrappedKey(const CryptoAlgorithm ¶ms, const Alias &wrappingKeyAlias, const Password &wrappingKeyPassword, - const Alias &wrappedKeyAlias, - const Password &wrappedKeyPassword, + const Alias &alias, + const Password &password, KeyType &keyType, RawBuffer &wrappedKey); diff --git a/src/manager/client-capi/ckmc-manager.cpp b/src/manager/client-capi/ckmc-manager.cpp index 24aa8cb..1e12ee4 100644 --- a/src/manager/client-capi/ckmc-manager.cpp +++ b/src/manager/client-capi/ckmc-manager.cpp @@ -1054,15 +1054,15 @@ KEY_MANAGER_CAPI int ckmc_export_wrapped_key(const ckmc_param_list_h params, const char *wrapping_key_alias, const char *wrapping_key_password, - const char *wrapped_key_alias, - const char *wrapped_key_password, + const char *alias, + const char *password, ckmc_key_s **ppwrapped_key) { EXCEPTION_GUARD_START_CAPI if (params == nullptr || wrapping_key_alias == nullptr || - wrapped_key_alias == nullptr || + alias == nullptr || ppwrapped_key == nullptr) return CKMC_ERROR_INVALID_PARAMETER; @@ -1071,21 +1071,24 @@ int ckmc_export_wrapped_key(const ckmc_param_list_h params, int ret = 0; ckmc_key_s *wrapped_key = nullptr; - CKM::RawBuffer wrappedKey; - CKM::KeyType keyType = CKM::KeyType::KEY_NONE; + CKM::RawBuffer wrapped_key_buffer; + CKM::KeyType key_type = CKM::KeyType::KEY_NONE; auto mgr = CKM::Manager::create(); ret = to_ckmc_error(mgr->exportWrappedKey(*ca, CKM::Alias(wrapping_key_alias), _tostring(wrapping_key_password), - CKM::Alias(wrapped_key_alias), - _tostring(wrapped_key_password), - keyType, - wrappedKey)); + CKM::Alias(alias), + _tostring(password), + key_type, + wrapped_key_buffer)); if (ret == CKMC_ERROR_NONE) { - ckmc_key_type_e key_type = static_cast(keyType); - ret = ckmc_key_new(wrappedKey.data(), wrappedKey.size(), key_type, nullptr, &wrapped_key); + ret = ckmc_key_new(wrapped_key_buffer.data(), + wrapped_key_buffer.size(), + static_cast(key_type), + nullptr, + &wrapped_key); if (ret == CKMC_ERROR_NONE) *ppwrapped_key = wrapped_key; } diff --git a/src/manager/client/client-manager-impl.cpp b/src/manager/client/client-manager-impl.cpp index b788197..14173e1 100644 --- a/src/manager/client/client-manager-impl.cpp +++ b/src/manager/client/client-manager-impl.cpp @@ -792,15 +792,15 @@ int Manager::Impl::importWrappedKey(const CryptoAlgorithm ¶ms, int Manager::Impl::exportWrappedKey(const CryptoAlgorithm ¶ms, const Alias &wrappingKeyAlias, const Password &wrappingKeyPassword, - const Alias &wrappedKeyAlias, - const Password &wrappedKeyPassword, + const Alias &alias, + const Password &password, KeyType &keyType, RawBuffer &wrappedKey) { EXCEPTION_GUARD_START_CPPAPI AliasSupport wrapping_helper(wrappingKeyAlias); - AliasSupport wrapped_helper(wrappedKeyAlias); + AliasSupport helper(alias); DataType dataTypeKey; int retCode = Request(*this, @@ -810,9 +810,9 @@ int Manager::Impl::exportWrappedKey(const CryptoAlgorithm ¶ms, wrapping_helper.getName(), wrapping_helper.getOwner(), wrappingKeyPassword, - wrapped_helper.getName(), - wrapped_helper.getOwner(), - wrappedKeyPassword + helper.getName(), + helper.getOwner(), + password ).maybeDeserialize(dataTypeKey, wrappedKey); if (retCode != CKM_API_SUCCESS) diff --git a/src/manager/client/client-manager-impl.h b/src/manager/client/client-manager-impl.h index b63598c..fb06743 100644 --- a/src/manager/client/client-manager-impl.h +++ b/src/manager/client/client-manager-impl.h @@ -152,8 +152,8 @@ public: int exportWrappedKey(const CryptoAlgorithm ¶ms, const Alias &wrappingKeyAlias, const Password &wrappingKeyPassword, - const Alias &wrappedKeyAlias, - const Password &wrappedKeyPassword, + const Alias &alias, + const Password &password, KeyType &keyType, RawBuffer &wrappedKey); diff --git a/src/manager/client/client-manager.cpp b/src/manager/client/client-manager.cpp index 4d9fcd6..71be983 100644 --- a/src/manager/client/client-manager.cpp +++ b/src/manager/client/client-manager.cpp @@ -318,8 +318,8 @@ int Manager::exportWrappedKey( const CryptoAlgorithm ¶ms, const Alias &wrappingKeyAlias, const Password &wrappingKeyPassword, - const Alias &wrappedKeyAlias, - const Password &wrappedKeyPassword, + const Alias &alias, + const Password &password, KeyType &keyType, RawBuffer &wrappedKey) { @@ -327,8 +327,8 @@ int Manager::exportWrappedKey( params, wrappingKeyAlias, wrappingKeyPassword, - wrappedKeyAlias, - wrappedKeyPassword, + alias, + password, keyType, wrappedKey ); diff --git a/src/manager/service/ckm-logic.cpp b/src/manager/service/ckm-logic.cpp index 5366ca9..21f0ac3 100644 --- a/src/manager/service/ckm-logic.cpp +++ b/src/manager/service/ckm-logic.cpp @@ -1605,9 +1605,9 @@ RawBuffer CKMLogic::exportWrappedKey( const Name &wrappingKeyName, const ClientId &wrappingKeyOwner, const Password &wrappingKeyPassword, - const Name &wrappedKeyName, - const ClientId &wrappedKeyOwner, - const Password &wrappedKeyPassword) + const Name &keyName, + const ClientId &keyOwner, + const Password &keyPassword) { Crypto::GObjUPtr wrappingKey; DB::Row wrappedKeyRow; @@ -1620,12 +1620,12 @@ RawBuffer CKMLogic::exportWrappedKey( if (retCode != CKM_API_SUCCESS) return retCode; - retCode = readRowHelper(false, cred, DataType::DB_KEY_FIRST, wrappedKeyName, - wrappedKeyOwner, wrappedKeyPassword, wrappedKeyRow, wrappedKeyType); + retCode = readRowHelper(false, cred, DataType::DB_KEY_FIRST, keyName, + keyOwner, keyPassword, wrappedKeyRow, wrappedKeyType); if (retCode != CKM_API_SUCCESS) return retCode; - wrappedKey = wrappingKey->wrap(params, wrappedKeyRow, wrappedKeyPassword); + wrappedKey = wrappingKey->wrap(params, wrappedKeyRow, keyPassword); return retCode; }); diff --git a/src/manager/service/ckm-logic.h b/src/manager/service/ckm-logic.h index 933ba08..36eb56d 100644 --- a/src/manager/service/ckm-logic.h +++ b/src/manager/service/ckm-logic.h @@ -222,9 +222,9 @@ public: const Name &wrappingKeyName, const ClientId &wrappingKeyOwner, const Password &wrappingKeyPassword, - const Name &wrappedKeyName, - const ClientId &wrappedKeyOwner, - const Password &wrappedKeyPassword); + const Name &keyName, + const ClientId &keyOwner, + const Password &keyPassword); int setPermissionHelper( const Credentials &cred, diff --git a/src/manager/service/ckm-service.cpp b/src/manager/service/ckm-service.cpp index 71899ab..511f271 100644 --- a/src/manager/service/ckm-service.cpp +++ b/src/manager/service/ckm-service.cpp @@ -497,17 +497,16 @@ RawBuffer CKMService::ProcessStorage(Credentials &cred, MessageBuffer &buffer) Name wrappingKeyName; ClientId wrappingKeyOwner; Password wrappingKeyPassword; - Name wrappedKeyName; - ClientId wrappedKeyOwner; - Password wrappedKeyPassword; + Name keyName; + Password keyPassword; buffer.Deserialize(params, wrappingKeyName, wrappingKeyOwner, wrappingKeyPassword, - wrappedKeyName, - wrappedKeyOwner, - wrappedKeyPassword); + keyName, + explicitOwner, + keyPassword); return m_logic->exportWrappedKey( cred, @@ -516,9 +515,9 @@ RawBuffer CKMService::ProcessStorage(Credentials &cred, MessageBuffer &buffer) wrappingKeyName, cred.effectiveOwner(wrappingKeyOwner), wrappingKeyPassword, - wrappedKeyName, - cred.effectiveOwner(wrappedKeyOwner), - wrappedKeyPassword); + keyName, + cred.effectiveOwner(explicitOwner), + keyPassword); } default: -- 2.7.4 From 6864d366d3dac8b9e2702d28d84102f3ef64bed3 Mon Sep 17 00:00:00 2001 From: Krzysztof Jackiewicz Date: Tue, 18 Apr 2023 11:08:24 +0200 Subject: [PATCH 11/16] Release 0.1.51 * Unify variable naming in key export * Fix documentation issues in E2EE API * Fix documentation issues Change-Id: I211ecfb0a2fa8fb705fc355158e17e5cd9021356 --- packaging/key-manager.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/key-manager.spec b/packaging/key-manager.spec index 23c39d3..bd8d7c5 100644 --- a/packaging/key-manager.spec +++ b/packaging/key-manager.spec @@ -12,7 +12,7 @@ Name: key-manager Summary: Central Key Manager and utilities -Version: 0.1.50 +Version: 0.1.51 Release: 1 Group: Security/Secure Storage License: Apache-2.0 and BSD-3-Clause -- 2.7.4 From 951a51a951cbaefccb7c98dcee86a09f6e19582d Mon Sep 17 00:00:00 2001 From: Krzysztof Jackiewicz Date: Fri, 5 May 2023 14:38:16 +0200 Subject: [PATCH 12/16] Fix ckmc_key_derive API description Describe input and output key/secret types in detail. Change-Id: I1f82fe45f4a8b5145b7236b9b8d5db998959b1ed --- src/include/ckmc/ckmc-manager.h | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/include/ckmc/ckmc-manager.h b/src/include/ckmc/ckmc-manager.h index dcec32a..686d939 100644 --- a/src/include/ckmc/ckmc-manager.h +++ b/src/include/ckmc/ckmc-manager.h @@ -1213,11 +1213,16 @@ int ckmc_export_wrapped_key(const ckmc_param_list_h params, /** - * @brief Derives a key from another key/secret and stores it inside key manager. + * @brief Derives a secret or key from another key/secret and stores it inside key manager. * * @since_tizen 6.5 * - * @remarks The derived key will be a symmetric one. It will be stored as a #CKMC_KEY_AES. + * @remarks In case of #CKMC_ALGO_KBKDF algorithm, the secret pointed to by @a secret_alias must be + * a binary data or a symmetric key (#CKMC_KEY_AES). The derived key pointed to by + * @a new_key_alias will be a symmetric one. It will be stored as a #CKMC_KEY_AES. + * @remarks In case of #CKMC_ALGO_ECDH algorithm, the key pointed to by @a secret_alias must be a + * private EC key (#CKMC_KEY_ECDSA_PRIVATE). The derived secret pointed to by + * @a new_key_alias will be in binary data form. * * @param[in] params Algorithm parameter list handle. See #ckmc_param_list_h and #ckmc_algo_type_e * for details. Supported algorithms: @@ -1225,13 +1230,13 @@ int ckmc_export_wrapped_key(const ckmc_param_list_h params, * - #CKMC_ALGO_ECDH, * @param[in] secret_alias Alias of the secret/key to use as an input * @param[in] secret_password Optional password of the secret/key used as an input - * @param[in] new_key_alias The name under which the derived key will be stored - * @param[in] new_key_policy Policy used to store the derived key + * @param[in] new_key_alias The name under which the derived key or secret will be stored + * @param[in] new_key_policy Policy used to store the derived key or secret * * @return @c 0 on success, otherwise a negative error value * @retval #CKMC_ERROR_NONE Successful * @retval #CKMC_ERROR_PERMISSION_DENIED Insufficient permissions to access key manager, the secret - * or to create the new key + * or to create the new key/secret * @retval #CKMC_ERROR_INVALID_PARAMETER Input parameter is invalid (missing or invalid mandatory * algorithm parameter, @a secret_alias = NULL, * @a new_key_alias = NULL) -- 2.7.4 From 733f084dca9bafa67af48aa9e287e1f8d600bb2c Mon Sep 17 00:00:00 2001 From: Krzysztof Jackiewicz Date: Wed, 26 Apr 2023 12:17:14 +0200 Subject: [PATCH 13/16] Multi-stage encryption API Change-Id: If56a367a40f1ca3a6d4dcebfbb38543c7ec44fd5 --- src/include/ckmc/ckmc-manager.h | 114 +++++++++++++++++++++++++++++++++++++++- src/include/ckmc/ckmc-type.h | 10 ++++ 2 files changed, 123 insertions(+), 1 deletion(-) diff --git a/src/include/ckmc/ckmc-manager.h b/src/include/ckmc/ckmc-manager.h index 686d939..07d5305 100644 --- a/src/include/ckmc/ckmc-manager.h +++ b/src/include/ckmc/ckmc-manager.h @@ -1244,7 +1244,7 @@ int ckmc_export_wrapped_key(const ckmc_param_list_h params, * @retval #CKMC_ERROR_DB_ALIAS_UNKNOWN @a secret_alias does not exist * @retval #CKMC_ERROR_DB_ALIAS_EXISTS @a new_key_alias already exists * @retval #CKMC_ERROR_DB_ERROR Failed due to a database error - * @retval #CKMC_ERROR_AUTHENTICATION_FAILED Secret decryption failed because @a secret_password is + * @retval #CKMC_ERROR_AUTHENTICATION_FAILED Secret decryption failed because @a secret_password is * incorrect * @retval #CKMC_ERROR_SERVER_ERROR Unknown error * @@ -1262,6 +1262,118 @@ int ckmc_key_derive(const ckmc_param_list_h params, const char *new_key_alias, ckmc_policy_s new_key_policy); +/** + * @brief Sets up a symmetric encryption or decryption context with given key and parameters. + * + * @since_tizen 6.5 + * + * @remarks The newly created @a context must be destroyed using ckmc_cipher_free() when it's no + * longer needed. + * @remarks To perform the encryption/decryption, one or more calls to ckmc_cipher_update() must be + * folowed by one call to ckmc_cipher_finalize(). + * + * @param[in] params Algorithm parameter list handle. See #ckmc_param_list_h and #ckmc_algo_type_e + * for details. Supported algorithms: + * - #CKMC_ALGO_AES_GCM, + * @param[in] key_alias Alias of the key to be used for encryption/decryption + * @param[in] key_password Optional password of the key used for encryption/decryption + * @param[in] encrypt Encryption/decryption switch (true=encryption, false=decryption) + * @param[out] context Encryption/decryption context + * + * @return @c 0 on success, otherwise a negative error value + * @retval #CKMC_ERROR_NONE Successful + * @retval #CKMC_ERROR_PERMISSION_DENIED Insufficient permissions to access key manager or the key + * @retval #CKMC_ERROR_INVALID_PARAMETER Input parameter is invalid (missing or invalid mandatory + * algorithm parameter, @a key_alias = NULL, + * @a context = NULL) + * @retval #CKMC_ERROR_DB_LOCKED A user key is not loaded in memory (a user is not logged in) + * @retval #CKMC_ERROR_DB_ALIAS_UNKNOWN @a key_alias does not exist + * @retval #CKMC_ERROR_DB_ERROR Failed due to a database error + * @retval #CKMC_ERROR_AUTHENTICATION_FAILED Key decryption failed because @a key_password is + * incorrect + * @retval #CKMC_ERROR_SERVER_ERROR Unknown error + * + * @pre User is already logged in and the user key is already loaded into memory in plain text form. + * + * @see #ckmc_cipher_ctx_h + * @see ckmc_cipher_update() + * @see ckmc_cipher_finalize() + * @see ckmc_cipher_free() + */ +int ckmc_cipher_initialize(ckmc_param_list_h params, + const char *key_alias, + const char *key_password, + bool encrypt, + ckmc_cipher_ctx_h *context); + +/** + * @brief Performs symmetric encryption or decryption of the input and places the result in the + * output. + * + * @since_tizen 6.5 + * + * @remarks The function may be called multiple times to encrypt succcessive blocks of data. + * @remarks The newly created @a ppout must be destroyed using ckmc_buffer_free() when it's no + * longer needed. + * + * @param[in] context Encryption/decryption context created with ckmc_cipher_initialize() + * @param[in] in Encryption/decryption input + * @param[out] ppout Encryption/decryption output + * + * @return @c 0 on success, otherwise a negative error value + * @retval #CKMC_ERROR_NONE Successful + * @retval #CKMC_ERROR_INVALID_PARAMETER Input parameter is invalid (@a context = NULL, + * @a ppout = NULL) + * @retval #CKMC_ERROR_SERVER_ERROR Unknown error + * + * @see #ckmc_cipher_ctx_h + * @see ckmc_cipher_initialize() + * @see ckmc_cipher_finalize() + * @see ckmc_cipher_free() + */ +int ckmc_cipher_update(ckmc_cipher_ctx_h context, + const ckmc_raw_buffer_s in, + ckmc_raw_buffer_s **ppout); + +/** + * @brief Finalizes symmetric encryption or decryption and returns remaining output if any. + * + * @since_tizen 6.5 + * + * @remarks After the call to this function the ckmc_cipher_update() can be called no more. + * @remarks The newly created @a ppout must be destroyed using ckmc_buffer_free() when it's no + * longer needed. + * + * @param[in] context Encryption/decryption context created with ckmc_cipher_initialize() + * @param[out] ppout Encryption/decryption output + * + * @return @c 0 on success, otherwise a negative error value + * @retval #CKMC_ERROR_NONE Successful + * @retval #CKMC_ERROR_INVALID_PARAMETER Input parameter is invalid (@a context = NULL, + * @a ppout = NULL) + * @retval #CKMC_ERROR_SERVER_ERROR Unknown error + * + * @see #ckmc_cipher_ctx_h + * @see ckmc_cipher_initialize() + * @see ckmc_cipher_update() + * @see ckmc_cipher_free() + */ +int ckmc_cipher_finalize(ckmc_cipher_ctx_h context, ckmc_raw_buffer_s **ppout); + +/** + * @brief Destroys the encryption/decryption context and releases all its resources. + * + * @since_tizen 6.5 + * + * @param[in] context Encryption/decryption context created with ckmc_cipher_initialize() + * + * @see #ckmc_cipher_ctx_h + * @see ckmc_cipher_initialize() + * @see ckmc_cipher_update() + * @see ckmc_cipher_finalize() + */ +void ckmc_cipher_free(ckmc_cipher_ctx_h context); + #ifdef __cplusplus } #endif diff --git a/src/include/ckmc/ckmc-type.h b/src/include/ckmc/ckmc-type.h index e568655..8897712 100644 --- a/src/include/ckmc/ckmc-type.h +++ b/src/include/ckmc/ckmc-type.h @@ -462,6 +462,16 @@ typedef enum __ckmc_algo_type { } ckmc_algo_type_e; /** + * @brief Encryption/decryption context handle. + * @since_tizen 6.5 + * @see ckmc_cipher_initialize() + * @see ckmc_cipher_update() + * @see ckmc_cipher_finalize() + * @see ckmc_cipher_free() + */ +typedef struct __ckmc_cipher_ctx *ckmc_cipher_ctx_h; + +/** * @brief Gets the alias from #ckmc_alias_info_s structure. * @since_tizen 5.5 * @remarks The @a alias should not be released. -- 2.7.4 From 647c61e72f911ab241d0c708f0894dfd161ce433 Mon Sep 17 00:00:00 2001 From: Krzysztof Jackiewicz Date: Thu, 27 Apr 2023 11:33:20 +0200 Subject: [PATCH 14/16] Backend info API New API: - getting backend associated with given object - getting backend information for given backend - getting max encryption chunk size from backend information Change-Id: I8c66e623ba49ebda0a9fad28dcb3b48bd21b175f --- src/include/ckm/ckm-manager.h | 6 +-- src/include/ckm/ckm-type.h | 14 +++++- src/include/ckmc/ckmc-manager.h | 26 ++++++++++ src/include/ckmc/ckmc-type.h | 79 ++++++++++++++++++++++++++++-- src/manager/client-capi/ckmc-manager.cpp | 52 +++++++++++++++----- src/manager/client-capi/ckmc-type.cpp | 33 ++++++++++++- src/manager/client/client-common.h | 5 ++ src/manager/client/client-manager-impl.cpp | 19 +++---- src/manager/client/client-manager-impl.h | 10 ++-- src/manager/client/client-manager.cpp | 12 ++--- 10 files changed, 215 insertions(+), 41 deletions(-) diff --git a/src/include/ckm/ckm-manager.h b/src/include/ckm/ckm-manager.h index 2208def..8076456 100644 --- a/src/include/ckm/ckm-manager.h +++ b/src/include/ckm/ckm-manager.h @@ -74,13 +74,13 @@ public: // send request for list of all keys/certificates/data that application/user may use int getKeyAliasVector(AliasVector &aliasVector); - int getKeyAliasPwdVector(AliasPwdVector &aliasPwdVector); + int getKeyAliasInfoVector(AliasInfoVector &aliasInfoVector); int getKeyEncryptionStatus(const Alias &alias, bool &status); int getCertificateAliasVector(AliasVector &aliasVector); - int getCertificateAliasPwdVector(AliasPwdVector &aliasPwdVector); + int getCertificateAliasInfoVector(AliasInfoVector &aliasInfoVector); int getCertificateEncryptionStatus(const Alias &alias, bool &status); int getDataAliasVector(AliasVector &aliasVector); - int getDataAliasPwdVector(AliasPwdVector &aliasPwdVector); + int getDataAliasInfoVector(AliasInfoVector &aliasInfoVector); int getDataEncryptionStatus(const Alias &alias, bool &status); int createKeyPairRSA( diff --git a/src/include/ckm/ckm-type.h b/src/include/ckm/ckm-type.h index 2bc7610..72ab1c4 100644 --- a/src/include/ckm/ckm-type.h +++ b/src/include/ckm/ckm-type.h @@ -51,7 +51,19 @@ typedef std::string Alias; */ typedef std::string ClientId; typedef std::vector AliasVector; -typedef std::vector> AliasPwdVector; + +// backend identifiers +enum class BackendId : int { + SW = 0, + TZ, + // keep in sync with ckmc_backend_id_e ! +}; + +struct AliasInfo { + bool passwordProtected; + BackendId backend; +}; +typedef std::vector> AliasInfoVector; enum class KeyType : int { KEY_NONE = 0, diff --git a/src/include/ckmc/ckmc-manager.h b/src/include/ckmc/ckmc-manager.h index 07d5305..6edbe51 100644 --- a/src/include/ckmc/ckmc-manager.h +++ b/src/include/ckmc/ckmc-manager.h @@ -1374,6 +1374,32 @@ int ckmc_cipher_finalize(ckmc_cipher_ctx_h context, ckmc_raw_buffer_s **ppout); */ void ckmc_cipher_free(ckmc_cipher_ctx_h context); +/** + * @brief Retrieves backend information. + * + * @since_tizen 6.5 + * + * @remarks The newly created @a ppinfo must be destroyed using ckmc_backend_info_free() when it's + * no longer needed. + * + * @param[in] backend Backend identifier + * @param[out] ppinfo Backend information handle + * + * @return @c 0 on success, otherwise a negative error value + * @retval #CKMC_ERROR_NONE Successful + * @retval #CKMC_ERROR_PERMISSION_DENIED Insufficient permissions to access key manager + * @retval #CKMC_ERROR_INVALID_PARAMETER Input parameter is invalid (@a backend is invalid, + * @a ppinfo = NULL) + * @retval #CKMC_ERROR_SERVER_ERROR Unknown error + * + * @see #ckmc_backend_id_e + * @see #ckmc_backend_info_h + * @see ckmc_alias_info_get_backend() + * @see ckmc_backend_get_max_chunk_size() + * @see ckmc_backend_info_free() + */ +int ckmc_get_backend_info(ckmc_backend_id_e backend, ckmc_backend_info_h* ppinfo); + #ifdef __cplusplus } #endif diff --git a/src/include/ckmc/ckmc-type.h b/src/include/ckmc/ckmc-type.h index 8897712..54c1f06 100644 --- a/src/include/ckmc/ckmc-type.h +++ b/src/include/ckmc/ckmc-type.h @@ -172,7 +172,6 @@ typedef enum __ckmc_permission { CKMC_PERMISSION_REMOVE = 0x02 /**< Remove allowed */ } ckmc_permission_e; - /** * @brief The structure for binary buffer used in key manager CAPI. * @since_tizen 2.3 @@ -462,6 +461,29 @@ typedef enum __ckmc_algo_type { } ckmc_algo_type_e; /** + * @brief Enumeration for backend identifiers. + * @since_tizen 6.5 + * @see ckmc_get_backend_info() + * @see ckmc_alias_info_get_backend() + */ +typedef enum __ckmc_backend_id { + CKMC_BACKEND_SW = 0, /**< Software backend */ + CKMC_BACKEND_TZ /**< TrustZone backend */ +} ckmc_backend_id_e; + +struct __ckmc_backend_info_s; + +/** + * @brief Backend information handle. + * @since_tizen 6.5 + * @see ckmc_alias_info_get_backend() + * @see ckmc_get_backend_info() + * @see ckmc_backend_get_max_chunk_size() + * @see ckmc_backend_info_free() + */ +typedef struct __ckmc_backend_info_s *ckmc_backend_info_h; + +/** * @brief Encryption/decryption context handle. * @since_tizen 6.5 * @see ckmc_cipher_initialize() @@ -479,7 +501,7 @@ typedef struct __ckmc_cipher_ctx *ckmc_cipher_ctx_h; * @param[in] info The pointer to the #ckmc_alias_info_s structure * @param[out] alias The pointer to the alias * @return #CKMC_ERROR_NONE on success, - * othervise a negative error value + * otherwise a negative error value * @retval #CKMC_ERROR_NONE Successful * @retval #CKMC_ERROR_INVALID_PARAMETER Input parameter is invalid * @see #ckmc_alias_info_s @@ -492,12 +514,29 @@ int ckmc_alias_info_get_alias(const ckmc_alias_info_s* info, char** alias); * @param[in] info The pointer to the #ckmc_alias_info_s structure * @param[out] is_password_protected The pointer to the password protection flag * @return #CKMC_ERROR_NONE on success, - * othervise a negative error value + * otherwise a negative error value + * @retval #CKMC_ERROR_NONE Successful + * @retval #CKMC_ERROR_INVALID_PARAMETER Input parameter is invalid + * @see #ckmc_alias_info_s + */ +int ckmc_alias_info_is_password_protected(const ckmc_alias_info_s* info, + bool* is_password_protected); + +/** + * @brief Gets the backend identifier from #ckmc_alias_info_s structure. + * @since_tizen 6.5 + * @param[in] info The pointer to the #ckmc_alias_info_s structure + * @param[out] backend The pointer to the backend identifier + * @return #CKMC_ERROR_NONE on success, otherwise a negative error value * @retval #CKMC_ERROR_NONE Successful * @retval #CKMC_ERROR_INVALID_PARAMETER Input parameter is invalid + * @see #ckmc_backend_id_e * @see #ckmc_alias_info_s + * @see ckmc_get_backend_info() + * @see ckmc_backend_info_free() + * @see ckmc_backend_get_max_chunk_size() */ -int ckmc_alias_info_is_password_protected(const ckmc_alias_info_s* info, bool* is_password_protected); +int ckmc_alias_info_get_backend(const ckmc_alias_info_s* info, ckmc_backend_id_e* backend); /** * @brief Destroys the #ckmc_alias_info_list_s handle and releases resources of @@ -1053,6 +1092,38 @@ void ckmc_param_list_free(ckmc_param_list_h params); */ int ckmc_generate_new_params(ckmc_algo_type_e type, ckmc_param_list_h *pparams); +/** + * @brief Retrieves maximum data chunk size that can be passed to given backend. This is the maximum + * size of data passed for encryption/decryption. + * + * @since_tizen 6.5 + * + * @param[in] info Backend info handle + * @param[out] size Maximum chunk size + * + * @return @c 0 on success, otherwise a negative error value + * @retval #CKMC_ERROR_NONE Successful + * @retval #CKMC_ERROR_INVALID_PARAMETER Input parameter is invalid (@a info is invalid, + * @a size = NULL) + * + * @see #ckmc_backend_info_h + * @see ckmc_get_backend_info() + */ +int ckmc_backend_get_max_chunk_size(const ckmc_backend_info_h info, size_t* size); + +/** + * @brief Destroys the backend information handle and releases all its resources. + * + * @since_tizen 6.5 + * + * @param[in] info Backend information handle created with ckmc_get_backend_info() + * + * @see #ckmc_backend_info_h + * @see ckmc_get_backend_info() + * @see ckmc_backend_get_max_chunk_size() + */ +void ckmc_backend_info_free(ckmc_backend_info_h info); + /** * @} diff --git a/src/manager/client-capi/ckmc-manager.cpp b/src/manager/client-capi/ckmc-manager.cpp index 1e12ee4..47bd944 100644 --- a/src/manager/client-capi/ckmc-manager.cpp +++ b/src/manager/client-capi/ckmc-manager.cpp @@ -37,7 +37,10 @@ namespace { const CKM::CertificateShPtrVector EMPTY_CERT_VECTOR; const CKM::AliasVector EMPTY_ALIAS_VECTOR; -int _ckmc_alias_info_new(const char* alias, bool is_password_protected, ckmc_alias_info_s** info) +int _ckmc_alias_info_new(const char* alias, + bool is_password_protected, + ckmc_backend_id_e backend, + ckmc_alias_info_s** info) { if (alias == NULL) return CKMC_ERROR_SERVER_ERROR; @@ -57,6 +60,7 @@ int _ckmc_alias_info_new(const char* alias, bool is_password_protected, ckmc_ali return CKMC_ERROR_OUT_OF_MEMORY; } _info->is_password_protected = is_password_protected; + _info->backend = backend; *info = _info; return CKMC_ERROR_NONE; } @@ -200,7 +204,7 @@ int _cryptoOperation(cryptoFn operation, return ckmc_buffer_new(outBuffer.data(), outBuffer.size(), ppout); } -int _toNewCkmcAliasInfoList(const CKM::AliasPwdVector &aliasPwdVector, +int _toNewCkmcAliasInfoList(const CKM::AliasInfoVector &aliasInfoVector, ckmc_alias_info_list_s **alias_info_list) { int ret = CKMC_ERROR_NONE; @@ -208,7 +212,7 @@ int _toNewCkmcAliasInfoList(const CKM::AliasPwdVector &aliasPwdVector, if (alias_info_list == nullptr) return CKMC_ERROR_UNKNOWN; - if (aliasPwdVector.size() == 0) { + if (aliasInfoVector.size() == 0) { *alias_info_list = nullptr; // according to documentation from header return CKMC_ERROR_DB_ALIAS_UNKNOWN; } @@ -217,7 +221,7 @@ int _toNewCkmcAliasInfoList(const CKM::AliasPwdVector &aliasPwdVector, ckmc_alias_info_list_s *plist = nullptr; ckmc_alias_info_list_s *previous = nullptr; - for (const auto &it : aliasPwdVector) { + for (const auto &it : aliasInfoVector) { previous = plist; @@ -235,7 +239,11 @@ int _toNewCkmcAliasInfoList(const CKM::AliasPwdVector &aliasPwdVector, if (previous != nullptr) previous->next = plist; - ret = _ckmc_alias_info_new(std::get<0>(it).c_str(), std::get<1>(it), &plist->info); + const auto& info = std::get<1>(it); + ret = _ckmc_alias_info_new(std::get<0>(it).c_str(), + info.passwordProtected, + static_cast(info.backend), + &plist->info); if (ret != CKMC_ERROR_NONE) break; } @@ -252,7 +260,7 @@ int _toNewCkmcAliasInfoList(const CKM::AliasPwdVector &aliasPwdVector, } int ckmc_generic_get_alias_info_list_helper(ckmc_alias_info_list_s **alias_info_list, - int(CKM::Manager::*func)(CKM::AliasPwdVector&)) + int(CKM::Manager::*func)(CKM::AliasInfoVector&)) { EXCEPTION_GUARD_START_CAPI @@ -262,12 +270,12 @@ int ckmc_generic_get_alias_info_list_helper(ckmc_alias_info_list_s **alias_info_ if (alias_info_list == nullptr) return CKMC_ERROR_INVALID_PARAMETER; - CKM::AliasPwdVector aliasPwdVector; + CKM::AliasInfoVector aliasInfoVector; - if ((ret = ((*mgr).*func)(aliasPwdVector)) != CKM_API_SUCCESS) + if ((ret = ((*mgr).*func)(aliasInfoVector)) != CKM_API_SUCCESS) return to_ckmc_error(ret); - if ((ret = _toNewCkmcAliasInfoList(aliasPwdVector, alias_info_list)) != CKM_API_SUCCESS) + if ((ret = _toNewCkmcAliasInfoList(aliasInfoVector, alias_info_list)) != CKM_API_SUCCESS) return ret; return CKMC_ERROR_NONE; @@ -400,7 +408,7 @@ int ckmc_get_key_alias_info_list(ckmc_alias_info_list_s **alias_info_list) { return ckmc_generic_get_alias_info_list_helper(alias_info_list, - &CKM::Manager::getKeyAliasPwdVector); + &CKM::Manager::getKeyAliasInfoVector); } KEY_MANAGER_CAPI @@ -464,7 +472,7 @@ KEY_MANAGER_CAPI int ckmc_get_cert_alias_info_list(ckmc_alias_info_list_s **alias_info_list) { return ckmc_generic_get_alias_info_list_helper(alias_info_list, - &CKM::Manager::getCertificateAliasPwdVector); + &CKM::Manager::getCertificateAliasInfoVector); } KEY_MANAGER_CAPI @@ -621,7 +629,7 @@ KEY_MANAGER_CAPI int ckmc_get_data_alias_info_list(ckmc_alias_info_list_s **alias_info_list) { return ckmc_generic_get_alias_info_list_helper(alias_info_list, - &CKM::Manager::getDataAliasPwdVector); + &CKM::Manager::getDataAliasInfoVector); } KEY_MANAGER_CAPI @@ -1096,3 +1104,23 @@ int ckmc_export_wrapped_key(const ckmc_param_list_h params, return ret; EXCEPTION_GUARD_END } + +KEY_MANAGER_CAPI +int ckmc_get_backend_info(ckmc_backend_id_e backend, ckmc_backend_info_h* ppinfo) +{ + EXCEPTION_GUARD_START_CAPI + + if (backend < CKMC_BACKEND_SW || backend > CKMC_BACKEND_TZ || ppinfo == nullptr) + return CKMC_ERROR_INVALID_PARAMETER; + + // TODO get it + auto _info = static_cast(malloc(sizeof(__ckmc_backend_info_s))); + if (_info == nullptr) + return CKMC_ERROR_OUT_OF_MEMORY; + + *ppinfo = _info; + + return CKMC_ERROR_SERVER_ERROR; + + EXCEPTION_GUARD_END +} diff --git a/src/manager/client-capi/ckmc-type.cpp b/src/manager/client-capi/ckmc-type.cpp index f79c2e1..fc7e431 100644 --- a/src/manager/client-capi/ckmc-type.cpp +++ b/src/manager/client-capi/ckmc-type.cpp @@ -616,7 +616,18 @@ int ckmc_alias_info_get_alias(const ckmc_alias_info_s* info, char** alias) } KEY_MANAGER_CAPI -int ckmc_alias_info_is_password_protected(const ckmc_alias_info_s* info, bool* is_password_protected) +int ckmc_alias_info_get_backend(const ckmc_alias_info_s* info, ckmc_backend_id_e* backend) +{ + if (info == NULL || backend == NULL) + return CKMC_ERROR_INVALID_PARAMETER; + + *backend = info->backend; + return CKMC_ERROR_NONE; +} + +KEY_MANAGER_CAPI +int ckmc_alias_info_is_password_protected(const ckmc_alias_info_s* info, + bool* is_password_protected) { if (info == NULL || is_password_protected == NULL) return CKMC_ERROR_INVALID_PARAMETER; @@ -838,3 +849,23 @@ int ckmc_generate_new_params(ckmc_algo_type_e type, ckmc_param_list_h *pparams) return CKMC_ERROR_NONE; } + +KEY_MANAGER_CAPI +int ckmc_backend_get_max_chunk_size(const ckmc_backend_info_h info, size_t* size) +{ + EXCEPTION_GUARD_START_CAPI + + if (info == nullptr || size == nullptr) + return CKMC_ERROR_INVALID_PARAMETER; + + *size = info->max_chunk_size; + return CKMC_ERROR_NONE; + + EXCEPTION_GUARD_END +} + +KEY_MANAGER_CAPI +void ckmc_backend_info_free(ckmc_backend_info_h info) +{ + free(info); +} diff --git a/src/manager/client/client-common.h b/src/manager/client/client-common.h index 35f57f9..98fe38f 100644 --- a/src/manager/client/client-common.h +++ b/src/manager/client/client-common.h @@ -31,6 +31,7 @@ #include #include +#include #include #include #include @@ -45,8 +46,12 @@ extern "C" { struct ckmc_alias_info_s { char* alias; bool is_password_protected; + ckmc_backend_id_e backend; }; + struct __ckmc_backend_info_s { + size_t max_chunk_size; + }; } namespace CKM { diff --git a/src/manager/client/client-manager-impl.cpp b/src/manager/client/client-manager-impl.cpp index 14173e1..540c93f 100644 --- a/src/manager/client/client-manager-impl.cpp +++ b/src/manager/client/client-manager-impl.cpp @@ -385,8 +385,8 @@ int Manager::Impl::getBinaryDataAliasVector(DataType dataType, EXCEPTION_GUARD_END } -int Manager::Impl::getBinaryDataAliasPwdVector(DataType dataType, - AliasPwdVector &aliasPwdVector) +int Manager::Impl::getBinaryDataAliasInfoVector(DataType dataType, + AliasInfoVector &aliasInfoVector) { EXCEPTION_GUARD_START_CPPAPI OwnerNameVector ownerNameVector; @@ -405,7 +405,8 @@ int Manager::Impl::getBinaryDataAliasPwdVector(DataType dataType, if (retCode != CKM_API_SUCCESS) return retCode; - aliasPwdVector.push_back(std::make_pair(alias, status)); + // TODO get the actual backend + aliasInfoVector.push_back(std::make_pair(alias, AliasInfo({status, BackendId::SW}))); } return CKM_API_SUCCESS; EXCEPTION_GUARD_END @@ -428,9 +429,9 @@ int Manager::Impl::getDataAliasVector(AliasVector &aliasVector) return getBinaryDataAliasVector(DataType::BINARY_DATA, aliasVector); } -int Manager::Impl::getKeyAliasPwdVector(AliasPwdVector &aliasPwdVector) +int Manager::Impl::getKeyAliasInfoVector(AliasInfoVector &aliasInfoVector) { - return getBinaryDataAliasPwdVector(DataType::DB_KEY_LAST, aliasPwdVector); + return getBinaryDataAliasInfoVector(DataType::DB_KEY_LAST, aliasInfoVector); } int Manager::Impl::getKeyEncryptionStatus(const Alias &alias, bool &status) @@ -438,9 +439,9 @@ int Manager::Impl::getKeyEncryptionStatus(const Alias &alias, bool &status) return getBinaryDataEncryptionStatus(DataType::DB_KEY_LAST, alias, status); } -int Manager::Impl::getCertificateAliasPwdVector(AliasPwdVector &aliasPwdVector) +int Manager::Impl::getCertificateAliasInfoVector(AliasInfoVector &aliasInfoVector) { - return getBinaryDataAliasPwdVector(DataType::CERTIFICATE, aliasPwdVector); + return getBinaryDataAliasInfoVector(DataType::CERTIFICATE, aliasInfoVector); } int Manager::Impl::getCertificateEncryptionStatus(const Alias &alias, bool &status) @@ -448,9 +449,9 @@ int Manager::Impl::getCertificateEncryptionStatus(const Alias &alias, bool &stat return getBinaryDataEncryptionStatus(DataType::CERTIFICATE, alias, status); } -int Manager::Impl::getDataAliasPwdVector(AliasPwdVector &aliasPwdVector) +int Manager::Impl::getDataAliasInfoVector(AliasInfoVector &aliasInfoVector) { - return getBinaryDataAliasPwdVector(DataType::BINARY_DATA, aliasPwdVector); + return getBinaryDataAliasInfoVector(DataType::BINARY_DATA, aliasInfoVector); } int Manager::Impl::getDataEncryptionStatus(const Alias &alias, bool &status) diff --git a/src/manager/client/client-manager-impl.h b/src/manager/client/client-manager-impl.h index fb06743..c10b6b4 100644 --- a/src/manager/client/client-manager-impl.h +++ b/src/manager/client/client-manager-impl.h @@ -35,7 +35,7 @@ public: int saveKey(const Alias &alias, const KeyShPtr &key, const Policy &policy); int getKey(const Alias &alias, const Password &password, KeyShPtr &key); int getKeyAliasVector(AliasVector &aliasVector); - int getKeyAliasPwdVector(AliasPwdVector &aliasPwdVector); + int getKeyAliasInfoVector(AliasInfoVector &aliasInfoVector); int getKeyEncryptionStatus(const Alias &alias, bool &status); int saveCertificate(const Alias &alias, const CertificateShPtr &cert, @@ -43,14 +43,14 @@ public: int getCertificate(const Alias &alias, const Password &password, CertificateShPtr &cert); int getCertificateAliasVector(AliasVector &aliasVector); - int getCertificateAliasPwdVector(AliasPwdVector &aliasPwdVector); + int getCertificateAliasInfoVector(AliasInfoVector &aliasInfoVector); int getCertificateEncryptionStatus(const Alias &alias, bool &status); int saveData(const Alias &alias, const RawBuffer &rawData, const Policy &policy); int getData(const Alias &alias, const Password &password, RawBuffer &cert); int getDataAliasVector(AliasVector &aliasVector); - int getDataAliasPwdVector(AliasPwdVector &aliasPwdVector); + int getDataAliasInfoVector(AliasInfoVector &aliasInfoVector); int getDataEncryptionStatus(const Alias &alias, bool &status); int savePKCS12( @@ -184,9 +184,9 @@ private: DataType sendDataType, OwnerNameVector &ownerNameVector); - int getBinaryDataAliasPwdVector( + int getBinaryDataAliasInfoVector( DataType sendDataType, - AliasPwdVector &aliasPwdVector); + AliasInfoVector &aliasInfoVector); int createKeyPair( const KeyType key_type, diff --git a/src/manager/client/client-manager.cpp b/src/manager/client/client-manager.cpp index 71be983..ee0d368 100644 --- a/src/manager/client/client-manager.cpp +++ b/src/manager/client/client-manager.cpp @@ -117,9 +117,9 @@ int Manager::getKeyAliasVector(AliasVector &aliasVector) return m_impl->getKeyAliasVector(aliasVector); } -int Manager::getKeyAliasPwdVector(AliasPwdVector &aliasPwdVector) +int Manager::getKeyAliasInfoVector(AliasInfoVector &aliasInfoVector) { - return m_impl->getKeyAliasPwdVector(aliasPwdVector); + return m_impl->getKeyAliasInfoVector(aliasInfoVector); } int Manager::getCertificateAliasVector(AliasVector &aliasVector) @@ -127,9 +127,9 @@ int Manager::getCertificateAliasVector(AliasVector &aliasVector) return m_impl->getCertificateAliasVector(aliasVector); } -int Manager::getCertificateAliasPwdVector(AliasPwdVector &aliasPwdVector) +int Manager::getCertificateAliasInfoVector(AliasInfoVector &aliasInfoVector) { - return m_impl->getCertificateAliasPwdVector(aliasPwdVector); + return m_impl->getCertificateAliasInfoVector(aliasInfoVector); } int Manager::getDataAliasVector(AliasVector &aliasVector) @@ -137,9 +137,9 @@ int Manager::getDataAliasVector(AliasVector &aliasVector) return m_impl->getDataAliasVector(aliasVector); } -int Manager::getDataAliasPwdVector(AliasPwdVector &aliasPwdVector) +int Manager::getDataAliasInfoVector(AliasInfoVector &aliasInfoVector) { - return m_impl->getDataAliasPwdVector(aliasPwdVector); + return m_impl->getDataAliasInfoVector(aliasInfoVector); } int Manager::createKeyPairRSA( -- 2.7.4 From eec9291ef51f719cf24d1f65cf7ed9ec63bf76d3 Mon Sep 17 00:00:00 2001 From: Krzysztof Jackiewicz Date: Mon, 8 May 2023 20:43:51 +0200 Subject: [PATCH 15/16] Fix default value for KBKDF LLEN parameter Change the default value of CKMC_PARAM_KBKDF_LLEN from 0 to 32 according to API description. Change-Id: I972d95227b047394c5f59addc9242d43c9c68be7 --- src/manager/crypto/sw-backend/internals.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/manager/crypto/sw-backend/internals.cpp b/src/manager/crypto/sw-backend/internals.cpp index 9796b2e..26a5f33 100644 --- a/src/manager/crypto/sw-backend/internals.cpp +++ b/src/manager/crypto/sw-backend/internals.cpp @@ -1040,7 +1040,7 @@ Data deriveKBKDF(const RawBuffer &secret, const CryptoAlgorithm &alg) RawBuffer label, context, fixed; KbkdfCounterLocation counterLocation; KdfPrf prf; - size_t length, rlenBits = 32, llenBits = 0, tmp; + size_t length, rlenBits = 32, llenBits = 32, tmp; bool hasLabel = alg.getParam(ParamName::KBKDF_LABEL, label); bool hasContext = alg.getParam(ParamName::KBKDF_CONTEXT, context); bool hasFixed = alg.getParam(ParamName::KBKDF_FIXED_INPUT, fixed); @@ -1048,7 +1048,7 @@ Data deriveKBKDF(const RawBuffer &secret, const CryptoAlgorithm &alg) alg.getParam(ParamName::KDF_PRF, prf); alg.getParam(ParamName::KDF_LEN, length); alg.getParam(ParamName::KBKDF_RLEN, rlenBits); - alg.getParam(ParamName::KBKDF_LLEN, llenBits); + bool hasLLen = alg.getParam(ParamName::KBKDF_LLEN, llenBits); bool useSeparator = !alg.getParam(ParamName::KBKDF_NO_SEPARATOR, tmp); const EVP_MD* md = nullptr; @@ -1068,7 +1068,7 @@ Data deriveKBKDF(const RawBuffer &secret, const CryptoAlgorithm &alg) RawBuffer key; if (hasFixed) { - if (hasLabel || hasContext || !useSeparator || llenBits > 0 || + if (hasLabel || hasContext || !useSeparator || hasLLen || counterLocation == KbkdfCounterLocation::MIDDLE_FIXED) ThrowErr(Exc::Crypto::InputParam, "Unexpected parameters for fixed input mode."); -- 2.7.4 From 2bbadc1a86d85db0ad29ff26725e05c99629c312 Mon Sep 17 00:00:00 2001 From: Krzysztof Jackiewicz Date: Tue, 16 May 2023 15:35:30 +0200 Subject: [PATCH 16/16] Fix backend selection logic In some cases the backend selection was not working properly: - Key derivation, wrapped key import: the backend compatibility was not checked at all. This resulted in a possibility of saving an exportable key in TZ backend which normally is not allowed. - Encrypted initial values could have been imported to incompatible SW backend if the TZ backend fails to initialize or the SW backend is forced. The Decider API was also unclear and different policies were in force depending on the usecase. This commit introduces following changes: * Keep the policy in a single place. * Return a prioritized list of backends compatible with given use case. * Add backend check to key derivation and wrapped key import. * Do not assume SW backend is suitable for all cases. * Handle illegal cases by returning empty list of compatible backends. Change-Id: I2d5dbbb3c4ba9385ac756eb419f95ac877cdd532 --- src/manager/common/data-type.h | 2 +- src/manager/crypto/platform/decider.cpp | 161 ++++++++++++++++++++------------ src/manager/crypto/platform/decider.h | 15 ++- src/manager/service/ckm-logic.cpp | 30 ++++-- 4 files changed, 139 insertions(+), 69 deletions(-) diff --git a/src/manager/common/data-type.h b/src/manager/common/data-type.h index 33884b7..017e214 100644 --- a/src/manager/common/data-type.h +++ b/src/manager/common/data-type.h @@ -81,7 +81,7 @@ public: bool isKey() const; /* - * Number of times someone mistook it for isKey() (or the opposite): 3 + * Number of times someone mistook it for isKey() (or the opposite): 4 * Increase the counter if it happened to you. * I will rename this function if the counter reaches 4. */ diff --git a/src/manager/crypto/platform/decider.cpp b/src/manager/crypto/platform/decider.cpp index 9109fb2..8dca91c 100644 --- a/src/manager/crypto/platform/decider.cpp +++ b/src/manager/crypto/platform/decider.cpp @@ -34,43 +34,6 @@ namespace CKM { namespace Crypto { -namespace { - -#ifdef TZ_BACKEND_ENABLED -CryptoBackend tryGetTzBackend() -{ - try { - LogDebug("Trying to open TA session..."); - TZ::Internals::TrustZoneContext::Instance(); - } catch (const Exc::Crypto::InternalError& e) { - LogDebug("...failed. Selecting SW backend."); - return CryptoBackend::OpenSSL; - } - - LogDebug("...succeeded. Selecting TZ backend."); - return CryptoBackend::TrustZone; -} -#endif - -template -CryptoBackend chooseBackend(const Policy &policy, const ForceOpenSSL &forceOpenSSL) -{ -#ifdef TZ_BACKEND_ENABLED - switch (policy.backend) { - case CKM::PolicyBackend::FORCE_SOFTWARE: return CryptoBackend::OpenSSL; - case CKM::PolicyBackend::FORCE_HARDWARE: return CryptoBackend::TrustZone; - case CKM::PolicyBackend::DEFAULT: break; - } - return forceOpenSSL() ? CryptoBackend::OpenSSL : tryGetTzBackend(); -#else // TZ_BACKEND_ENABLED - (void)policy; - (void)forceOpenSSL; - return CryptoBackend::OpenSSL; -#endif // TZ_BACKEND_ENABLED -} - -} // namespace - Decider::Decider() : m_swStore(CryptoBackend::OpenSSL) #ifdef TZ_BACKEND_ENABLED @@ -81,43 +44,125 @@ Decider::Decider() GStore &Decider::getStore(const Token &token) { - return getStore(token.backendId); -}; - -GStore &Decider::getStore(CryptoBackend cryptoBackend) -{ GStore *gStore = NULL; - if (cryptoBackend == CryptoBackend::OpenSSL) + if (token.backendId == CryptoBackend::OpenSSL) gStore = &m_swStore; #ifdef TZ_BACKEND_ENABLED - if (cryptoBackend == CryptoBackend::TrustZone) + if (token.backendId == CryptoBackend::TrustZone) gStore = &m_tzStore; #endif if (gStore) return *gStore; ThrowErr(Exc::Crypto::InternalError, - "Backend not available. BackendId: ", (int)cryptoBackend); + "Backend not available. BackendId: ", + static_cast(token.backendId)); +}; + +GStore* Decider::tryBackend(CryptoBackend backend) +{ + switch(backend) { + case CryptoBackend::OpenSSL: + return &m_swStore; + case CryptoBackend::TrustZone: +#ifdef TZ_BACKEND_ENABLED + try { + LogDebug("Trying to open TA session..."); + TZ::Internals::TrustZoneContext::Instance(); + LogDebug("...succeeded. Selecting TZ backend."); + return &m_tzStore; + } catch (const Exc::Crypto::InternalError& e) { + LogDebug("...failed."); + } +#endif + default: + break; + } + return nullptr; +} + +/* + * operation encrypted type extractable backend + * ---------------------------------------------- + * import FALSE binary - TZ/SW + * skey FALSE TZ/SW + * skey TRUE SW + * akey - SW + * cert - SW + * TRUE binary - TZ + * skey FALSE TZ + * skey TRUE NONE + * akey - NONE + * cert - NONE + * generate - binary FALSE TZ/SW + * - binary TRUE SW + * - cert - NONE + * - skey FALSE TZ/SW + * - skey TRUE SW + * - akey FALSE TZ/SW + * - akey TRUE SW + */ +std::deque Decider::getCompatibleBackends(DataType data, + const Policy &policy, + bool import, + bool encrypted) +{ + std::deque backends; + + auto addSW = [&]{ + if (policy.backend != CKM::PolicyBackend::FORCE_HARDWARE) + backends.push_back(CryptoBackend::OpenSSL); + }; + + auto addTZ = [&]{ +#ifdef TZ_BACKEND_ENABLED + if (policy.backend != CKM::PolicyBackend::FORCE_SOFTWARE) + backends.push_front(CryptoBackend::TrustZone); +#endif + }; + + if (import) { + if (!encrypted) + addSW(); + + if (data.isBinaryData() || (data.isSKey() && !policy.extractable)) + addTZ(); + } else { // generate/derive + assert(!encrypted); + + if (!data.isCertificate() && !data.isChainCert()) { + addSW(); + + if (!policy.extractable) + addTZ(); + } + } + return backends; } -GStore &Decider::getStore(DataType data, const Policy &policy, bool encrypted) +GStore &Decider::getStore(DataType data, const Policy &policy, bool import, bool encrypted) { - return getStore(chooseBackend(policy, [&]{ - return !encrypted && !data.isBinaryData() && ( - // tz-backend allows only for data binary export - policy.extractable || - // Use TrustZone only with symmetric keys or unencrypted binary - // data until asymmetric cryptography is implemented - !data.isSKey() - ); - })); + auto backends = getCompatibleBackends(data, policy, import, encrypted); + if (backends.empty()) + ThrowErr(Exc::Crypto::InputParam, "No backend supports this operation."); + + for (auto id : backends) { + auto backend = tryBackend(id); + if (backend != nullptr) + return *backend; + } + ThrowErr(Exc::Crypto::InternalError, "Failed to connect to a compatible backend."); } -GStore &Decider::getStore(const Policy &policyPrv) +bool Decider::checkStore(CryptoBackend requestedBackend, DataType data, const Policy &policy, bool import) { - // extractable private key can only be handled by OpenSSL - return getStore(chooseBackend(policyPrv, [&]{ return policyPrv.extractable; })); + auto backends = getCompatibleBackends(data, policy, import); + for (auto id : backends) { + if (id == requestedBackend) + return true; + } + return false; } } // namespace Crypto diff --git a/src/manager/crypto/platform/decider.h b/src/manager/crypto/platform/decider.h index 08ab78e..3315e76 100644 --- a/src/manager/crypto/platform/decider.h +++ b/src/manager/crypto/platform/decider.h @@ -20,6 +20,8 @@ */ #pragma once +#include + #include #include @@ -40,11 +42,18 @@ class Decider final { public: Decider(); GStore &getStore(const Token &token); - GStore &getStore(DataType data, const Policy &policy, bool encrypted = false); - GStore &getStore(const Policy &policyPrv); + GStore &getStore(DataType data, + const Policy &policy, + bool import = true, + bool encrypted = false); + bool checkStore(CryptoBackend id, DataType data, const Policy &policy, bool import); private: - GStore &getStore(CryptoBackend id); + GStore* tryBackend(CryptoBackend backend); + std::deque getCompatibleBackends(DataType data, + const Policy &policy, + bool import = true, + bool encrypted = false); SW::Store m_swStore; #ifdef TZ_BACKEND_ENABLED diff --git a/src/manager/service/ckm-logic.cpp b/src/manager/service/ckm-logic.cpp index 21f0ac3..a5b158e 100644 --- a/src/manager/service/ckm-logic.cpp +++ b/src/manager/service/ckm-logic.cpp @@ -1028,7 +1028,7 @@ int CKMLogic::importInitialData( if (retCode != CKM_API_SUCCESS) return retCode; - Crypto::GStore &store = m_decider.getStore(data.type, policy, !encParams.iv.empty()); + Crypto::GStore &store = m_decider.getStore(data.type, policy, true, !encParams.iv.empty()); Token token; if (encParams.iv.empty()) { @@ -1177,7 +1177,8 @@ RawBuffer CKMLogic::createKeyPair( bool exportable = policyPrv.extractable || policyPub.extractable; Policy lessRestricted(Password(), exportable, policyPrv.backend); - TokenPair keys = m_decider.getStore(policyPrv).generateAKey( + // For now any asymmetric key will do. If necessary we can extract it from keyGenParams. + TokenPair keys = m_decider.getStore(DataType::DB_KEY_FIRST, policyPrv, false).generateAKey( keyGenParams, policyPrv.password, policyPub.password, @@ -1210,9 +1211,9 @@ RawBuffer CKMLogic::createKeyAES( CryptoAlgorithm keyGenAlgorithm; keyGenAlgorithm.setParam(ParamName::ALGO_TYPE, AlgoType::AES_GEN); keyGenAlgorithm.setParam(ParamName::GEN_KEY_LEN, size); - Token key = m_decider.getStore(DataType::KEY_AES, policy).generateSKey(keyGenAlgorithm, - policy.password, - digest); + + auto& store = m_decider.getStore(DataType::KEY_AES, policy, false); + Token key = store.generateSKey(keyGenAlgorithm, policy.password, digest); dbOp.finalize(std::move(key), policy); return CKM_API_SUCCESS; @@ -1537,14 +1538,15 @@ RawBuffer CKMLogic::deriveKey( return SerializeMessage(msgID, tryRet([&] { // Get key/secret for internal service use. It won't be exported to the client Crypto::GObjUPtr obj; + DataType objType; int retCode = readDataHelper(false, cred, DataType::DB_KEY_FIRST, - secretName, secretOwner, secretPassword, obj); + secretName, secretOwner, secretPassword, obj, objType); if (retCode != CKM_API_SUCCESS) { if (retCode != CKM_API_ERROR_DB_ALIAS_UNKNOWN) return retCode; retCode = readDataHelper(false, cred, DataType::BINARY_DATA, - secretName, secretOwner, secretPassword, obj); + secretName, secretOwner, secretPassword, obj, objType); if (retCode != CKM_API_SUCCESS) return retCode; } @@ -1553,6 +1555,14 @@ RawBuffer CKMLogic::deriveKey( if (ret != CKM_API_SUCCESS) return ret; + // ECDH (private key) -> binary secret, KBKDF -> symmetric key + DataType newKeyType = objType.isKeyPrivate() ? DataType::BINARY_DATA : DataType::KEY_AES; + if (!m_decider.checkStore(obj->backendId(), newKeyType, newKeyPolicy, false)) { + LogDebug("Can't import the derived key to backend " << + static_cast(obj->backendId()) << " with given policy"); + return CKM_API_ERROR_INPUT_PARAM; + } + // derive Token derived = obj->derive(params, newKeyPolicy.password, digest); @@ -1587,6 +1597,12 @@ RawBuffer CKMLogic::importWrappedKey( if (retCode != CKM_API_SUCCESS) return retCode; + if (!m_decider.checkStore(wrappingKey->backendId(), keyType, policy, true)) { + LogDebug("Can't import the wrapped key to backend " << + static_cast(wrappingKey->backendId()) << " with given policy"); + return CKM_API_ERROR_INPUT_PARAM; + } + Token token = wrappingKey->unwrap(params, Crypto::Data(keyType, std::move(wrappedKey)), policy.password, -- 2.7.4