From: Konrad Lipinski Date: Tue, 22 Oct 2019 16:52:52 +0000 (+0200) Subject: Implement asymmetric key initial value import X-Git-Tag: accepted/tizen/unified/20191125.135522~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F56%2F216256%2F2;p=platform%2Fcore%2Fsecurity%2Fkey-manager.git Implement asymmetric key initial value import Change-Id: I0f5e4ab9b156abc3ab97a59f32b4adef9779eb98 --- diff --git a/src/manager/crypto/tz-backend/internals.cpp b/src/manager/crypto/tz-backend/internals.cpp index cc8efca..9962cf5 100644 --- a/src/manager/crypto/tz-backend/internals.cpp +++ b/src/manager/crypto/tz-backend/internals.cpp @@ -84,6 +84,20 @@ void generateDSAParams(const int sizeBits, CKM::RawBuffer &prime, #endif } +tz_data_type toTzDataType(const CKM::DataType dataType) { + switch (int(dataType)) { + case CKM::DataType::Type::BINARY_DATA: return TYPE_GENERIC_SECRET; + case CKM::DataType::Type::KEY_AES: return TYPE_SKEY; + case CKM::DataType::Type::KEY_DSA_PRIVATE: return TYPE_AKEY_PRIVATE_DSA; + case CKM::DataType::Type::KEY_RSA_PRIVATE: return TYPE_AKEY_PRIVATE_RSA; + case CKM::DataType::Type::KEY_DSA_PUBLIC: return TYPE_AKEY_PUBLIC_DSA; + case CKM::DataType::Type::KEY_RSA_PUBLIC: return TYPE_AKEY_PUBLIC_RSA; + default: + ThrowErr(CKM::Exc::Crypto::DataTypeNotSupported, + "Data type could not be imported by tz-backend"); + } +} + } // namespace namespace CKM { @@ -265,21 +279,7 @@ RawBuffer importData(const Data &data, RawBuffer &tag) { - uint32_t dataType; - - if (data.type.isSKey()) { - dataType = TYPE_SKEY; - } else if (data.type.isBinaryData()) { - dataType = TYPE_GENERIC_SECRET; - } else if (data.type.isKeyPrivate()) { - dataType = TYPE_AKEY_PRIVATE; - } else if (data.type.isKeyPublic()) { - dataType = TYPE_AKEY_PUBLIC; - } else { - ThrowErr(Exc::Crypto::DataTypeNotSupported, - "Data type could not be imported by tz-backend"); - } - + const auto dataType = toTzDataType(data.type); RawBuffer result; RawBuffer pwdBuf(pwd.begin(), pwd.end()); @@ -493,7 +493,7 @@ RawBuffer asymmetricEncrypt(const RawBuffer &key, getAlgType(algo), key, pwd, - unpack(alg, ParamName::ED_IV), + result, // unused dummy data, result); return result; @@ -521,7 +521,7 @@ RawBuffer asymmetricDecrypt(const RawBuffer &key, getAlgType(algo), key, pwd, - unpack(alg, ParamName::ED_IV), + result, // unused dummy cipher, result); return result; diff --git a/tools/ckm_initial_values/main.cpp b/tools/ckm_initial_values/main.cpp index f717e5e..c5d9e7d 100644 --- a/tools/ckm_initial_values/main.cpp +++ b/tools/ckm_initial_values/main.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018 Samsung Electronics Co., Ltd All Rights Reserved + * Copyright (c) 2018-2019 Samsung Electronics Co., Ltd. All rights reserved * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -137,7 +137,7 @@ void usage() " -a|--accessors [,[,...]]" << std::endl << " A list of key-manager clients allowed to access given initial" << std::endl << " value separated by commas." << std::endl << - " -b|--backend A key-manager's backed to use when saving the initial values." << std::endl << + " -b|--backend A key-manager's backend to use when saving the initial values." << std::endl << " Allowed values: 'software' and 'hardware'." << std::endl; }