From: Krzysztof Jackiewicz Date: Wed, 2 Dec 2020 17:07:09 +0000 (+0100) Subject: Fix negative CBC decryption test X-Git-Tag: accepted/tizen/unified/20201214.124456~3 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=1910f98daf6b8e954b9af11ba2459b17868ef037;p=platform%2Fcore%2Fsecurity%2Fkey-manager.git Fix negative CBC decryption test There's a high chance that the padding ^ 0x1 will produce a 0x01 trailing byte which happens to be a valid padding. In such case make sure that the length of the decrypted data is different. Change-Id: I60b7f9e708d850c49dbddbdda64ff178d730b4f7 --- diff --git a/unit-tests/test_sw-backend.cpp b/unit-tests/test_sw-backend.cpp index c740e9a..0232d99 100644 --- a/unit-tests/test_sw-backend.cpp +++ b/unit-tests/test_sw-backend.cpp @@ -558,7 +558,20 @@ NEGATIVE_TEST_CASE(symmetricEncryptDecryptCbc) // broken padding encrypted.back() ^= 0x1; - BOOST_REQUIRE_THROW(key->decrypt(ca, encrypted), Exc::Crypto::InputParam); + try { + auto decrypted = key->decrypt(ca, encrypted); + + /* + * There's a high chance that the above ^= 0x1 will produce a 0x01 trailing byte which + * happens to be a valid padding. In such case make sure that the length of the + * decrypted data is different. + */ + BOOST_REQUIRE(decrypted.size() != data.size()); + } catch (const Exc::Crypto::InputParam&) { + // This is fine + } catch (...) { + BOOST_FAIL("Exc::Crypto::InputParam expected"); + } } POSITIVE_TEST_CASE(asymmetricEncryptDecrypt)