Fix AES GCM IV setting in KeyProvider 69/299869/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:53:33 +0000 (10:53 +0200)
commitcb384fdaca572cabf03210b3e5219713b33ab9bd
treefde934e19ac5765d94723f22bd1153422c4ad221
parent537e7a2751c15cef79d2fcd5938b18ba1e95c68c
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