Skip to content

Commit b469959

Browse files
author
Alex Cioc
committed
Revert "fix: Merge mainline into keyrings, revert the keyring reverts (aws#209)"
This reverts commit 4442958.
1 parent 4442958 commit b469959

File tree

10 files changed

+18
-152
lines changed

10 files changed

+18
-152
lines changed

CHANGELOG.md

+1-11
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,7 @@ calls to `AwsCrypto.encrypt(EncryptRequest)` and `AwsCrypto.decrypt(DecryptReque
2929
[#165](https://github.com/aws/aws-encryption-sdk-java/pull/165),
3030
[#168](https://github.com/aws/aws-encryption-sdk-java/pull/168),
3131
and [#170](https://github.com/aws/aws-encryption-sdk-java/pull/170).
32-
33-
## 1.6.2 -- 2020-05-26
34-
35-
### Patches
36-
* Validate final frame length does not exceed the frame size in the message header [PR #166](https://github.com/aws/aws-encryption-sdk-java/pull/166)
37-
* Validate entire ciphertext has been processed before returning [PR #191](https://github.com/aws/aws-encryption-sdk-java/pull/191)
38-
39-
### Maintenance
40-
* Update AWS Java SDK version from 1.11.561 to 1.11.704. [PR #186](https://github.com/aws/aws-encryption-sdk-java/pull/186)
41-
* Upgrade Bouncy Castle from 1.61 to 1.65 [PR #179](https://github.com/aws/aws-encryption-sdk-java/pull/179)
42-
32+
4333
## 1.6.1 -- 2019-10-29
4434

4535
### Deprecation Warnings

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ You can get the latest release from Maven:
5656
<dependency>
5757
<groupId>com.amazonaws</groupId>
5858
<artifactId>aws-encryption-sdk-java</artifactId>
59-
<version>1.6.2</version>
59+
<version>1.6.1</version>
6060
</dependency>
6161
```
6262

pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
<groupId>com.amazonaws</groupId>
66
<artifactId>aws-encryption-sdk-java</artifactId>
7-
<version>1.6.2</version>
7+
<version>1.6.1</version>
88
<packaging>jar</packaging>
99

1010
<name>aws-encryption-sdk-java</name>

src/main/java/com/amazonaws/encryptionsdk/internal/BlockDecryptionHandler.java

+5-12
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,16 @@
1313

1414
package com.amazonaws.encryptionsdk.internal;
1515

16+
import java.util.Arrays;
17+
18+
import javax.crypto.Cipher;
19+
import javax.crypto.SecretKey;
20+
1621
import com.amazonaws.encryptionsdk.CryptoAlgorithm;
1722
import com.amazonaws.encryptionsdk.exception.AwsCryptoException;
1823
import com.amazonaws.encryptionsdk.exception.BadCiphertextException;
1924
import com.amazonaws.encryptionsdk.model.CipherBlockHeaders;
2025

21-
import javax.crypto.Cipher;
22-
import javax.crypto.SecretKey;
23-
import java.util.Arrays;
24-
2526
/**
2627
* The block decryption handler is an implementation of CryptoHandler that
2728
* provides methods to decrypt content encrypted and stored in a single block.
@@ -96,11 +97,6 @@ public BlockDecryptionHandler(final SecretKey decryptionKey, final short nonceLe
9697
synchronized public ProcessingSummary processBytes(final byte[] in, final int off, final int len,
9798
final byte[] out,
9899
final int outOff) throws AwsCryptoException {
99-
100-
if (complete_) {
101-
throw new AwsCryptoException("Ciphertext has already been processed.");
102-
}
103-
104100
final byte[] bytesToParse = new byte[unparsedBytes_.length + len];
105101
// If there were previously unparsed bytes, add them as the first
106102
// set of bytes to be parsed in this call.
@@ -170,9 +166,6 @@ synchronized public ProcessingSummary processBytes(final byte[] in, final int of
170166
*/
171167
@Override
172168
synchronized public int doFinal(final byte[] out, final int outOff) throws BadCiphertextException {
173-
if (!complete_) {
174-
throw new BadCiphertextException("Unable to process entire ciphertext.");
175-
}
176169
return 0;
177170
}
178171

src/main/java/com/amazonaws/encryptionsdk/internal/DecryptionHandler.java

-4
Original file line numberDiff line numberDiff line change
@@ -335,10 +335,6 @@ public int doFinal(final byte[] out, final int outOff) throws BadCiphertextExcep
335335
} else {
336336
int result = contentCryptoHandler_.doFinal(out, outOff);
337337

338-
if (!ciphertextHeaders_.isComplete() || !contentCryptoHandler_.isComplete()) {
339-
throw new BadCiphertextException("Unable to process entire ciphertext.");
340-
}
341-
342338
return result;
343339
}
344340
}

src/main/java/com/amazonaws/encryptionsdk/internal/FrameDecryptionHandler.java

+3-12
Original file line numberDiff line numberDiff line change
@@ -78,16 +78,16 @@ public FrameDecryptionHandler(final SecretKey decryptionKey, final short nonceLe
7878
*
7979
* @param in
8080
* the input byte array.
81-
* @param off
81+
* @param inOff
8282
* the offset into the in array where the data to be decrypted starts.
83-
* @param len
83+
* @param inLen
8484
* the number of bytes to be decrypted.
8585
* @param out
8686
* the output buffer the decrypted plaintext bytes go into.
8787
* @param outOff
8888
* the offset into the output byte array the decrypted data starts at.
8989
* @return the number of bytes written to out and processed
90-
* @throws BadCiphertextException
90+
* @throws InvalidCiphertextException
9191
* if frame number is invalid/out-of-order or if the bytes do not decrypt correctly.
9292
* @throws AwsCryptoException
9393
* if the content type found in the headers is not of frame type.
@@ -96,11 +96,6 @@ public FrameDecryptionHandler(final SecretKey decryptionKey, final short nonceLe
9696
public ProcessingSummary processBytes(final byte[] in, final int off, final int len, final byte[] out,
9797
final int outOff)
9898
throws BadCiphertextException, AwsCryptoException {
99-
100-
if (complete_) {
101-
throw new AwsCryptoException("Ciphertext has already been processed.");
102-
}
103-
10499
final long totalBytesToParse = unparsedBytes_.length + (long) len;
105100
if (totalBytesToParse > Integer.MAX_VALUE) {
106101
throw new AwsCryptoException(
@@ -205,10 +200,6 @@ public ProcessingSummary processBytes(final byte[] in, final int off, final int
205200
*/
206201
@Override
207202
public int doFinal(final byte[] out, final int outOff) {
208-
if (!complete_) {
209-
throw new BadCiphertextException("Unable to process entire ciphertext.");
210-
}
211-
212203
return 0;
213204
}
214205

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

-46
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
import java.io.InputStream;
3434
import java.io.OutputStream;
3535
import java.nio.charset.StandardCharsets;
36-
import java.util.Arrays;
3736
import java.util.EnumSet;
3837
import java.util.HashMap;
3938
import java.util.Map;
@@ -151,26 +150,6 @@ private void doTamperedEncryptDecryptWithKeyring(final CryptoAlgorithm cryptoAlg
151150
.ciphertext(cipherText).build()));
152151
}
153152

154-
private void doTruncatedEncryptDecrypt(final CryptoAlgorithm cryptoAlg, final int byteSize, final int frameSize) {
155-
final byte[] plaintextBytes = new byte[byteSize];
156-
157-
final Map<String, String> encryptionContext = new HashMap<>(1);
158-
encryptionContext.put("ENC1", "Encrypt-decrypt test with %d" + byteSize);
159-
160-
encryptionClient_.setEncryptionAlgorithm(cryptoAlg);
161-
encryptionClient_.setEncryptionFrameSize(frameSize);
162-
163-
final byte[] cipherText = encryptionClient_.encryptData(
164-
masterKeyProvider,
165-
plaintextBytes,
166-
encryptionContext).getResult();
167-
final byte[] truncatedCipherText = Arrays.copyOf(cipherText, cipherText.length - 1);
168-
169-
assertThrows(BadCiphertextException.class, () -> encryptionClient_.decryptData(
170-
masterKeyProvider,
171-
truncatedCipherText));
172-
}
173-
174153
private void doEncryptDecryptWithParsedCiphertext(final int byteSize, final int frameSize) {
175154
final byte[] plaintextBytes = new byte[byteSize];
176155

@@ -256,31 +235,6 @@ public void encryptDecryptWithBadSignature() {
256235
}
257236
}
258237

259-
@Test
260-
public void encryptDecryptWithTruncatedCiphertext() {
261-
for (final CryptoAlgorithm cryptoAlg : EnumSet.allOf(CryptoAlgorithm.class)) {
262-
final int[] frameSizeToTest = TestUtils.getFrameSizesToTest(cryptoAlg);
263-
264-
for (int i = 0; i < frameSizeToTest.length; i++) {
265-
final int frameSize = frameSizeToTest[i];
266-
int[] bytesToTest = { 0, 1, frameSize - 1, frameSize, frameSize + 1, (int) (frameSize * 1.5),
267-
frameSize * 2, 1000000 };
268-
269-
for (int j = 0; j < bytesToTest.length; j++) {
270-
final int byteSize = bytesToTest[j];
271-
272-
if (byteSize > 500_000) {
273-
continue;
274-
}
275-
276-
if (byteSize >= 0) {
277-
doTruncatedEncryptDecrypt(cryptoAlg, byteSize, frameSize);
278-
}
279-
}
280-
}
281-
}
282-
}
283-
284238
@Test
285239
public void encryptDecryptWithParsedCiphertext() {
286240
for (final CryptoAlgorithm cryptoAlg : EnumSet.allOf(CryptoAlgorithm.class)) {

src/test/java/com/amazonaws/encryptionsdk/internal/BlockDecryptionHandlerTest.java

+7-24
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
package com.amazonaws.encryptionsdk.internal;
1515

16+
import static org.junit.Assert.assertEquals;
1617
import static org.junit.Assert.assertTrue;
1718

1819
import java.nio.ByteBuffer;
@@ -21,7 +22,6 @@
2122
import javax.crypto.SecretKey;
2223
import javax.crypto.spec.SecretKeySpec;
2324

24-
import com.amazonaws.encryptionsdk.exception.BadCiphertextException;
2525
import org.junit.Before;
2626
import org.junit.Test;
2727

@@ -58,9 +58,11 @@ public void estimateOutputSize() {
5858
assertTrue(outSize >= inLen);
5959
}
6060

61-
@Test(expected= BadCiphertextException.class)
62-
public void doFinalCalledWhileNotComplete() {
63-
blockDecryptionHandler_.doFinal(new byte[1], 0);
61+
@Test
62+
public void decryptWithoutHeaders() {
63+
final byte[] out = new byte[1];
64+
final int returnedLen = blockDecryptionHandler_.doFinal(out, 0);
65+
assertEquals(0, returnedLen);
6466
}
6567

6668
@Test(expected = AwsCryptoException.class)
@@ -88,23 +90,4 @@ public void decryptMaxContentLength() {
8890
final byte[] decryptedOut = new byte[decryptedOutLen];
8991
blockDecryptionHandler_.processBytes(outBuff.array(), 0, outBuff.array().length, decryptedOut, 0);
9092
}
91-
92-
@Test(expected = AwsCryptoException.class)
93-
public void processBytesCalledWhileComplete() {
94-
final BlockEncryptionHandler blockEncryptionHandler = new BlockEncryptionHandler(
95-
dataKey_,
96-
nonceLen_,
97-
cryptoAlgorithm_,
98-
messageId_);
99-
final byte[] in = new byte[0];
100-
final int outLen = blockEncryptionHandler.estimateOutputSize(in.length);
101-
final byte[] out = new byte[outLen];
102-
103-
blockEncryptionHandler.processBytes(in, 0, in.length, out, 0);
104-
blockEncryptionHandler.doFinal(out, 0);
105-
106-
final byte[] decryptedOut = new byte[outLen];
107-
blockDecryptionHandler_.processBytes(out, 0, outLen, decryptedOut, 0);
108-
blockDecryptionHandler_.processBytes(out, 0, outLen, decryptedOut, 0);
109-
}
110-
}
93+
}

src/test/java/com/amazonaws/encryptionsdk/internal/DecryptionHandlerTest.java

-15
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
import java.util.Collections;
1717
import java.util.Map;
1818

19-
import com.amazonaws.encryptionsdk.model.CiphertextHeaders;
2019
import com.amazonaws.encryptionsdk.keyrings.Keyring;
2120
import org.junit.Before;
2221
import org.junit.Test;
@@ -147,20 +146,6 @@ public void invalidOffsetProcessBytes() {
147146
decryptionHandler.processBytes(in, -1, in.length, out, 0);
148147
}
149148

150-
@Test(expected = BadCiphertextException.class)
151-
public void incompleteCiphertext() {
152-
byte[] ciphertext = getTestHeaders();
153-
154-
CiphertextHeaders h = new CiphertextHeaders();
155-
h.deserialize(ciphertext, 0);
156-
157-
final DecryptionHandler<StaticMasterKey> decryptionHandler = DecryptionHandler.create(masterKeyProvider_);
158-
final byte[] out = new byte[1];
159-
160-
decryptionHandler.processBytes(ciphertext, 0, ciphertext.length - 1, out, 0);
161-
decryptionHandler.doFinal(out, 0);
162-
}
163-
164149
@Test
165150
public void testNullMasterKey() {
166151
final DecryptionHandler decryptionHandler = DecryptionHandler.create(new DefaultCryptoMaterialsManager(keyring));

src/test/java/com/amazonaws/encryptionsdk/internal/FrameDecryptionHandlerTest.java

-26
Original file line numberDiff line numberDiff line change
@@ -89,30 +89,4 @@ public void finalFrameLengthTooLarge() {
8989

9090
frameDecryptionHandler_.processBytes(in, 0, in.length, out, 0);
9191
}
92-
93-
@Test(expected = BadCiphertextException.class)
94-
public void doFinalCalledWhileNotComplete() {
95-
frameDecryptionHandler_.doFinal(new byte[1], 0);
96-
}
97-
98-
@Test(expected = AwsCryptoException.class)
99-
public void processBytesCalledWhileComplete() {
100-
final FrameEncryptionHandler frameEncryptionHandler = new FrameEncryptionHandler(
101-
dataKey_,
102-
nonceLen_,
103-
cryptoAlgorithm_,
104-
messageId_,
105-
frameSize_);
106-
final byte[] in = new byte[0];
107-
final int outLen = frameEncryptionHandler.estimateOutputSize(in.length);
108-
final byte[] out = new byte[outLen];
109-
110-
frameEncryptionHandler.processBytes(in, 0, in.length, out, 0);
111-
frameEncryptionHandler.doFinal(out, 0);
112-
113-
final byte[] decryptedOut = new byte[outLen];
114-
115-
frameDecryptionHandler_.processBytes(out, 0, out.length, decryptedOut, 0);
116-
frameDecryptionHandler_.processBytes(out, 0, out.length, decryptedOut, 0);
117-
}
11892
}

0 commit comments

Comments
 (0)