Skip to content

Commit ecb21b7

Browse files
author
Bryan Donlan
committed
Restore frame size alignment checks
Restoring these for now due to concerns about compatibility with relaxing this restriction.
1 parent 84f7c67 commit ecb21b7

File tree

3 files changed

+15
-41
lines changed

3 files changed

+15
-41
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# Changelog
22

3+
## 1.3.1
4+
5+
### Minor changes
6+
7+
* Frame sizes are once again required to be aligned to 16 bytes
8+
This restriction was relaxed in 1.3.0, but due to compatibility concerns
9+
we'll put this restriction back in for the time being.
10+
311
## 1.3.0
412

513
### Major changes

src/main/java/com/amazonaws/encryptionsdk/AwsCrypto.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,11 @@ public void setEncryptionFrameSize(final int frameSize) {
137137
if (frameSize < 0) {
138138
throw new IllegalArgumentException("frameSize must be non-negative");
139139
}
140+
if (frameSize % 16 != 0) {
141+
// For compatibility reasons we'll still enforce this restriction for now.
142+
// TODO: Investigate whether this can be removed.
143+
throw new IllegalArgumentException("frameSize must be a multiple of 16");
144+
}
140145
encryptionFrameSize_ = frameSize;
141146
}
142147

src/test/java/com/amazonaws/encryptionsdk/AwsCryptoTest.java

Lines changed: 2 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -640,49 +640,10 @@ public void setValidFrameSize() throws IOException {
640640
assertEquals(setFrameSize, getFrameSize);
641641
}
642642

643-
@Test
644-
public void unalignedFrameSizesAreAccepted() throws IOException {
643+
@Test(expected = IllegalArgumentException.class)
644+
public void unalignedFrameSizesAreRejected() throws IOException {
645645
final int frameSize = AwsCrypto.getDefaultCryptoAlgorithm().getBlockSize() - 1;
646646
encryptionClient_.setEncryptionFrameSize(frameSize);
647-
648-
// Make sure we can encrypt with unaligned small frame sizes.
649-
encryptionClient_.decryptData(masterKeyProvider,
650-
encryptionClient_.encryptData(masterKeyProvider, new byte[1]).getResult());
651-
652-
encryptionClient_.setEncryptionFrameSize(frameSize + 2);
653-
encryptionClient_.decryptData(masterKeyProvider,
654-
encryptionClient_.encryptData(masterKeyProvider, new byte[1]).getResult());
655-
656-
// Make sure really large frame sizes work too.
657-
// Note that going all the way up to Integer.MAX_VALUE hits JVM limits.
658-
encryptionClient_.setEncryptionFrameSize(Integer.MAX_VALUE - 16);
659-
OutputStream nullOutputStream = new OutputStream() {
660-
@Override public void write(final int b) throws IOException {
661-
662-
}
663-
664-
@Override public void write(final byte[] b) throws IOException {
665-
666-
}
667-
668-
@Override public void write(final byte[] b, final int off, final int len) throws IOException {
669-
670-
}
671-
};
672-
673-
OutputStream decrypter = encryptionClient_.createDecryptingStream(masterKeyProvider, nullOutputStream);
674-
OutputStream encrypter = encryptionClient_.createEncryptingStream(masterKeyProvider, nullOutputStream);
675-
676-
byte[] buf = new byte[1024*1024];
677-
long bytesRemaining = Integer.MAX_VALUE + 1;
678-
679-
while (bytesRemaining > 0) {
680-
int toWrite = Math.toIntExact(Math.min(buf.length, bytesRemaining));
681-
682-
encrypter.write(buf, 0, toWrite);
683-
}
684-
685-
encrypter.close();
686647
}
687648

688649
@Test(expected = IllegalArgumentException.class)

0 commit comments

Comments
 (0)