Skip to content

Commit 11cea86

Browse files
committed
added check to make sure MAC loaded where no data in an AEAD based stream, relates to github #2139
1 parent c403460 commit 11cea86

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

prov/src/main/java/org/bouncycastle/jcajce/io/CipherInputStream.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public class CipherInputStream
3131
private final Cipher cipher;
3232
private final byte[] inputBuffer = new byte[512];
3333
private boolean finalized = false;
34+
private boolean nextChunkCalled = false;
3435
private byte[] buf;
3536
private int maxBuf;
3637
private int bufOff;
@@ -58,6 +59,7 @@ private int nextChunk()
5859
return -1;
5960
}
6061

62+
nextChunkCalled = true;
6163
bufOff = 0;
6264
maxBuf = 0;
6365

@@ -86,10 +88,16 @@ private int nextChunk()
8688
}
8789

8890
private byte[] finaliseCipher()
89-
throws InvalidCipherTextIOException
91+
throws InvalidCipherTextIOException, IOException
9092
{
9193
try
9294
{
95+
// for an AEAD cipher with 0 encrypted Data nextChunk may not have been
96+
// called - we still need to read the MAC though!
97+
if (!nextChunkCalled)
98+
{
99+
nextChunk();
100+
}
93101
if (!finalized)
94102
{
95103
finalized = true;

0 commit comments

Comments
 (0)