Implement asymmetric key initial value import 56/216256/2
authorKonrad Lipinski <k.lipinski2@samsung.com>
Tue, 22 Oct 2019 16:52:52 +0000 (18:52 +0200)
committerKrzysztof Jackiewicz <k.jackiewicz@samsung.com>
Tue, 19 Nov 2019 13:19:40 +0000 (13:19 +0000)
Change-Id: I0f5e4ab9b156abc3ab97a59f32b4adef9779eb98

src/manager/crypto/tz-backend/internals.cpp
tools/ckm_initial_values/main.cpp

index cc8efca..9962cf5 100644 (file)
@@ -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<RawBuffer>(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<RawBuffer>(alg, ParamName::ED_IV),
+                                                                                               result, // unused dummy
                                                                                                cipher,
                                                                                                result);
                return result;
index f717e5e..c5d9e7d 100644 (file)
@@ -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 <accessor1>[,<accessor2>[,...]]" << std::endl <<
            "                           A list of key-manager clients allowed to access given initial" << std::endl <<
            "                           value separated by commas." << std::endl <<
-           " -b|--backend <backend>    A key-manager's backed to use when saving the initial values." << std::endl <<
+           " -b|--backend <backend>    A key-manager's backend to use when saving the initial values." << std::endl <<
            "                           Allowed values: 'software' and 'hardware'." << std::endl;
 }