Skip to content

Commit eae3056

Browse files
authored
Merge pull request #22 from bdonlan/frame-alignment
Restore frame size alignment checks
2 parents 84f7c67 + ca845e2 commit eae3056

File tree

4 files changed

+16
-42
lines changed

4 files changed

+16
-42
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

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ You can get the latest release from Maven:
4545
<dependency>
4646
<groupId>com.amazonaws</groupId>
4747
<artifactId>aws-encryption-sdk-java</artifactId>
48-
<version>1.3.0</version>
48+
<version>1.3.1</version>
4949
</dependency>
5050
```
5151

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)