Prevent using public key for decryption 39/299139/2
authorKrzysztof Jackiewicz <k.jackiewicz@samsung.com>
Wed, 20 Sep 2023 10:57:56 +0000 (12:57 +0200)
committerKrzysztof Jackiewicz <k.jackiewicz@samsung.com>
Wed, 20 Sep 2023 11:57:08 +0000 (13:57 +0200)
We could leave it for backends but since we have all the info, let's
fail early.

Change-Id: I7d3257370124ad19d423b859f380ce60f6da4d95

src/manager/service/ckm-logic.cpp

index ae9a7ed..4bcb3c7 100644 (file)
@@ -1594,11 +1594,23 @@ RawBuffer CKMLogic::importWrappedKey(
                if (retCode != CKM_API_SUCCESS)
                        return retCode;
 
-               retCode = readDataHelper(false, cred, DataType::DB_KEY_FIRST, wrappingKeyName,
-                                                               wrappingKeyOwner, wrappingKeyPassword, wrappingKey);
+               DataType wrappingKeyType;
+               retCode = readDataHelper(false,
+                                                                cred,
+                                                                DataType::DB_KEY_FIRST,
+                                                                wrappingKeyName,
+                                                                wrappingKeyOwner,
+                                                                wrappingKeyPassword,
+                                                                wrappingKey,
+                                                                wrappingKeyType);
                if (retCode != CKM_API_SUCCESS)
                        return retCode;
 
+               if (wrappingKeyType.isKeyPublic()) {
+                       LogError("Public key can not be used for decryption");
+                       return CKM_API_ERROR_INPUT_PARAM;
+               }
+
                if (!m_decider.checkStore(wrappingKey->backendId(), keyType, policy, true)) {
                        LogDebug("Can't import the wrapped key to backend " <<
                                 static_cast<int>(wrappingKey->backendId()) << " with given policy");