Skip to content

Commit 67cbf29

Browse files
committed
remove decrypt cipher init
1 parent cc105f6 commit 67cbf29

File tree

1 file changed

+26
-35
lines changed

1 file changed

+26
-35
lines changed

src/main/java/software/amazon/encryption/s3/internal/GetEncryptedObjectPipeline.java

Lines changed: 26 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,8 @@
1717
import software.amazon.encryption.s3.materials.DecryptionMaterials;
1818
import software.amazon.encryption.s3.materials.EncryptedDataKey;
1919

20-
import javax.crypto.Cipher;
2120
import javax.crypto.SecretKey;
22-
import javax.crypto.spec.GCMParameterSpec;
23-
import javax.crypto.spec.IvParameterSpec;
2421
import java.nio.ByteBuffer;
25-
import java.security.GeneralSecurityException;
2622
import java.util.Collections;
2723
import java.util.List;
2824
import java.util.concurrent.CompletableFuture;
@@ -149,37 +145,32 @@ public void onStream(SdkPublisher<ByteBuffer> ciphertextPublisher) {
149145
if (algorithmSuite == AlgorithmSuite.ALG_AES_256_CTR_IV16_TAG16_NO_KDF) {
150146
iv = AesCtrUtils.adjustIV(iv, cryptoRange[0]);
151147
}
152-
try {
153-
final Cipher cipher = CryptoFactory.createCipher(algorithmSuite.cipherName(), materials.cryptoProvider());
154-
switch (algorithmSuite) {
155-
case ALG_AES_256_GCM_IV12_TAG16_NO_KDF:
156-
System.out.println("initting a GCM cipher for decrypt...");
157-
cipher.init(Cipher.DECRYPT_MODE, contentKey, new GCMParameterSpec(tagLength, iv));
158-
break;
159-
case ALG_AES_256_CTR_IV16_TAG16_NO_KDF:
160-
case ALG_AES_256_CBC_IV16_NO_KDF:
161-
cipher.init(Cipher.DECRYPT_MODE, contentKey, new IvParameterSpec(iv));
162-
break;
163-
default:
164-
throw new S3EncryptionClientException("Unknown algorithm: " + algorithmSuite.cipherName());
165-
}
166-
167-
if (algorithmSuite.equals(AlgorithmSuite.ALG_AES_256_CBC_IV16_NO_KDF)
168-
|| algorithmSuite.equals(AlgorithmSuite.ALG_AES_256_CTR_IV16_TAG16_NO_KDF)
169-
|| _enableDelayedAuthentication) {
170-
// CBC and GCM with delayed auth enabled use a standard publisher
171-
CipherPublisher plaintextPublisher = new CipherPublisher(ciphertextPublisher,
172-
getObjectResponse.contentLength(), desiredRange, contentMetadata.contentRange(), algorithmSuite.cipherTagLengthBits(), materials, iv);
173-
wrappedAsyncResponseTransformer.onStream(plaintextPublisher);
174-
} else {
175-
// Use buffered publisher for GCM when delayed auth is not enabled
176-
BufferedCipherPublisher plaintextPublisher = new BufferedCipherPublisher(ciphertextPublisher,
177-
getObjectResponse.contentLength(), materials, iv, _bufferSize);
178-
wrappedAsyncResponseTransformer.onStream(plaintextPublisher);
179-
}
180-
181-
} catch (GeneralSecurityException e) {
182-
throw new S3EncryptionClientException("Unable to " + algorithmSuite.cipherName() + " content decrypt.", e);
148+
// final Cipher cipher = CryptoFactory.createCipher(algorithmSuite.cipherName(), materials.cryptoProvider());
149+
switch (algorithmSuite) {
150+
case ALG_AES_256_GCM_IV12_TAG16_NO_KDF:
151+
System.out.println("initting a GCM cipher for decrypt...");
152+
// cipher.init(Cipher.DECRYPT_MODE, contentKey, new GCMParameterSpec(tagLength, iv));
153+
break;
154+
case ALG_AES_256_CTR_IV16_TAG16_NO_KDF:
155+
case ALG_AES_256_CBC_IV16_NO_KDF:
156+
// cipher.init(Cipher.DECRYPT_MODE, contentKey, new IvParameterSpec(iv));
157+
break;
158+
default:
159+
throw new S3EncryptionClientException("Unknown algorithm: " + algorithmSuite.cipherName());
160+
}
161+
162+
if (algorithmSuite.equals(AlgorithmSuite.ALG_AES_256_CBC_IV16_NO_KDF)
163+
|| algorithmSuite.equals(AlgorithmSuite.ALG_AES_256_CTR_IV16_TAG16_NO_KDF)
164+
|| _enableDelayedAuthentication) {
165+
// CBC and GCM with delayed auth enabled use a standard publisher
166+
CipherPublisher plaintextPublisher = new CipherPublisher(ciphertextPublisher,
167+
getObjectResponse.contentLength(), desiredRange, contentMetadata.contentRange(), algorithmSuite.cipherTagLengthBits(), materials, iv);
168+
wrappedAsyncResponseTransformer.onStream(plaintextPublisher);
169+
} else {
170+
// Use buffered publisher for GCM when delayed auth is not enabled
171+
BufferedCipherPublisher plaintextPublisher = new BufferedCipherPublisher(ciphertextPublisher,
172+
getObjectResponse.contentLength(), materials, iv, _bufferSize);
173+
wrappedAsyncResponseTransformer.onStream(plaintextPublisher);
183174
}
184175
}
185176
}

0 commit comments

Comments
 (0)