Fix decryption with unexpected password 90/288590/2
authorKrzysztof Jackiewicz <k.jackiewicz@samsung.com>
Fri, 17 Feb 2023 20:13:46 +0000 (21:13 +0100)
committerKrzysztof Jackiewicz <k.jackiewicz@samsung.com>
Thu, 23 Feb 2023 14:12:35 +0000 (15:12 +0100)
Passing a password when a row was not additionally encrypted with one
did not fail as it should. Make it do so.

Change-Id: Ifd84cca1b55c67ef7e5b470cc42bb4efac6a0703

src/manager/crypto/sw-backend/store.cpp

index 3c5b898..a75d078 100644 (file)
@@ -76,12 +76,15 @@ RawBuffer unpack(const RawBuffer &packed, const Password &pass)
 {
        MessageBuffer buffer;
        buffer.Push(RawBuffer(packed));
-       int encryptionScheme = 0;
+       int encryptionScheme = EncryptionScheme::NONE;
        RawBuffer data;
        buffer.Deserialize(encryptionScheme, data);
 
-       if (encryptionScheme == 0)
+       if (encryptionScheme == EncryptionScheme::NONE) {
+               if (!pass.empty())
+                       ThrowErr(Exc::AuthenticationFailed, "Unexpected custom password.");
                return data;
+       }
 
        MessageBuffer internalBuffer;
        internalBuffer.Push(std::move(data));
@@ -97,7 +100,6 @@ RawBuffer unpack(const RawBuffer &packed, const Password &pass)
         * AES GCM will check data integrity and handle cases where:
         * - wrong password is used
         * - password is empty when it shouldn't be
-        * - password is not empty when it should be
         */
        RawBuffer key = passwordToKey(pass, iv, Params::DERIVED_KEY_LENGTH);