Keystore 2.0 SPI: Fix engineDoFinal with null input.

AndroidKeyStoreCipherSpiBase.engineDoFinal may get called with a null
input argument. In the case where we forward the operation to the
default provider doFinal() needs to be called instead of
doFinal(byte[], int, int).

Bug: 183913233
Test: atest android.keystore.cts.CipherTest#testEncryptsAndDecryptsUsingCipherStreams
Change-Id: Ia3afaf281be7c8e5493ac8e4155a7aa02d1d37f0
This commit is contained in:
Janis Danisevskis
2021-04-19 10:47:01 -07:00
committed by Hasini Gunasinghe
parent c66289ebd2
commit 70cf430ede

View File

@@ -579,7 +579,11 @@ abstract class AndroidKeyStoreCipherSpiBase extends CipherSpi implements KeyStor
protected final byte[] engineDoFinal(byte[] input, int inputOffset, int inputLen)
throws IllegalBlockSizeException, BadPaddingException {
if (mCipher != null) {
return mCipher.doFinal(input, inputOffset, inputLen);
if (input == null && inputLen == 0) {
return mCipher.doFinal();
} else {
return mCipher.doFinal(input, inputOffset, inputLen);
}
}
if (mCachedException != null) {