Fix AES GCM IV setting in KeyProvider 74/299874/1
authorKrzysztof Jackiewicz <k.jackiewicz@samsung.com>
Fri, 29 Sep 2023 05:09:19 +0000 (07:09 +0200)
committerKrzysztof Jackiewicz <k.jackiewicz@samsung.com>
Wed, 11 Oct 2023 08:57:58 +0000 (10:57 +0200)
commit2ff0107495755b00da3789b8f02901d97129c371
treeff4678a098418e6b609b87553ef1874f31210736
parent8ff166a91c65a7e3e5d10d2781f123c6809108c3
Fix AES GCM IV setting in KeyProvider

The proper order of setting an IV of custom length in GCM is to firstly
pass the length and then the IV during both encryption and decryption.
The KeyProvider code was doing the opposite which resulted in
truncating the IV to 12B. In openssl3.0 The effect is somewhat
diffferent but the output is also invalid.

Openssl silently ignores this issue allowing to call the API in wrong
order and get invalid encryption/decryption results.

The issue was not detected until now because the IV truncation was
working the same way during encryption and decryption and no other
module beside key-manager was accessing the encrypted keys.

This commit modifies KeyProvider code in 2 ways:
* Modify encryption and decryption to set the IV length properly.
* If decryption fails retry it with IV truncated to 12B to handle data
  encrypted the old way.

Change-Id: I72e237b0842234d80579f3e93b5e1012a0613140
src/manager/service/key-provider.cpp