Throw exception if decryption/encryption fails 51/108651/16
authorPeter Suna <peter.suna@pantheon.tech>
Wed, 25 Oct 2023 11:52:15 +0000 (13:52 +0200)
committerYaroslav Lastivka <yaroslav.lastivka@pantheon.tech>
Wed, 24 Jan 2024 13:39:35 +0000 (15:39 +0200)
commitb43fe318313a666acefb7bb98b46c85d18b4eef3
tree9349746794d727a6d38a433aac6496b4b8d0b28a
parent517dd25c5b772d3f143b3132176934ce1ddf722c
Throw exception if decryption/encryption fails

Previously, in the case of a failure during encryption or decryption
in AAA, the system would only log an error and return insered string.
This could lead user to believe that the operation was successful,
resulting in them receiving unencrypted/undecrypted data.
Also is possible that IllegalArgumentException is thrown which is also
wrong.

This patch simplifies things by throwing GeneralSecurityException, as
that is quite a natural thing to do.

In terms of IAEs -- this relates to String encoding and not encryption,
so we solve this by simply not providing String-based services, forcing
users to deal with translation themselves.

Since we are in the area, also convert unit tests to JUnit5, as they are
extremely simplistic.

Also make the service null-hostile, as that it almost is -- encrypt path
would throw IAE on null bytes, this turns it into a NPE and guards the
decrypt path the same way.

Finally we take care of the asymmetry in encrypt/descrypt when we do not
have a key -- simply by refusing to start it we fail to initialize.

JIRA: AAA-266
Change-Id: I4c9078e293fe5b98f0e6b69568ca10a75a4fbe07
Signed-off-by: Peter Suna <peter.suna@pantheon.tech>
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
Signed-off-by: Yaroslav Lastivka <yaroslav.lastivka@pantheon.tech>
aaa-cert/src/main/java/org/opendaylight/aaa/cert/impl/KeyStoresDataUtils.java
aaa-cert/src/test/java/org/opendaylight/aaa/cert/impl/AaaCertMdsalProviderTest.java
aaa-cert/src/test/java/org/opendaylight/aaa/cert/impl/AaaCertRpcServiceImplTest.java
aaa-cert/src/test/java/org/opendaylight/aaa/cert/impl/KeyStoresDataUtilsTest.java
aaa-encrypt-service/api/src/main/java/org/opendaylight/aaa/encrypt/AAAEncryptionService.java
aaa-encrypt-service/impl/src/main/java/org/opendaylight/aaa/encrypt/impl/AAAEncryptionServiceImpl.java
aaa-encrypt-service/impl/src/main/java/org/opendaylight/aaa/encrypt/impl/OSGiEncryptionServiceConfigurator.java
aaa-encrypt-service/impl/src/test/java/org/opendaylight/aaa/encrypt/impl/AAAEncryptServiceImplTest.java