Fix AES GCM IV setting in KeyProvider 51/299451/4
authorKrzysztof Jackiewicz <k.jackiewicz@samsung.com>
Fri, 29 Sep 2023 05:09:19 +0000 (07:09 +0200)
committerKrzysztof Jackiewicz <k.jackiewicz@samsung.com>
Fri, 29 Sep 2023 09:34:28 +0000 (11:34 +0200)
commite740f3916cc5ed78d256a92577abd11302927ab3
treee9e365bee68b4259fb3b86ff27d55081d41f1310
parente3cd18a4b91aa6b46bb4b6c469312fb7d4190e9e
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