-
Notifications
You must be signed in to change notification settings - Fork 122
ParsedCiphertext throws an error if it is not complete #119
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
b3df03b
Adding check for if ciphertext is complete in the ParsedCiphertext co…
shayvana 62b36df
Wrote test for check for if ciphertext is complete in the ParsedCiphe…
shayvana 5ebec3e
Fixed ParsedCiphertext bug
shayvana b9b64ed
Code does not break build
shayvana e326d12
Removed test in CiphertextHeadersTest
shayvana 85da442
Created test file for ParsedCiphertext and wrote a test for initializ…
shayvana 3aad539
Wrote happy test for ParsedCiphertext constructor
shayvana da0938b
Removed CiphertextHeadersTest file from changes
shayvana a0c93ec
Removed declaration of RuntimeException in a throws statement on the …
shayvana db1fc9d
Wrote tests for incomplete ciphertexts of zero and single byte length
shayvana 39883c2
Wrote test for encrypting and decrypting with ParsedCiphertext
shayvana 9590174
Added test for good ParsedCipherText
shayvana ece073c
Added test cases for constructing an incomplete ParsedCipherText with…
shayvana 27a4459
Updated copyright
shayvana fb23a71
Added back test file I accidentally deleted
shayvana 5e5c2db
Removed assertEquals check
shayvana ff29cee
Asserted that offset is greater than 0
shayvana 566975a
Merge branch 'master' into ParsedCiphertext-bug-fix
shayvana 7b7b703
Removed unneeded import statement and CiphertextHeadersTest from changes
shayvana d89ff00
Merge branch 'ParsedCiphertext-bug-fix' of github.com:sprovine/aws-en…
shayvana 22c3e7d
Updated offset check in good ciphertext test
shayvana 3dd630c
Updated test for almost valid ciphertext input for ParsedCipherText
shayvana 07f60a6
Set incomplete single byte ciphertext to a valid version
shayvana ad9f4af
Merge branch 'master' into ParsedCiphertext-bug-fix
SalusaSecondus File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
96 changes: 96 additions & 0 deletions
96
src/test/java/com/amazonaws/encryptionsdk/ParsedCiphertextTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
/* | ||
* Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except | ||
* in compliance with the License. A copy of the License is located at | ||
* | ||
* http://aws.amazon.com/apache2.0 | ||
* | ||
* or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations under the License. | ||
*/ | ||
|
||
package com.amazonaws.encryptionsdk; | ||
|
||
import com.amazonaws.encryptionsdk.internal.StaticMasterKey; | ||
import com.amazonaws.encryptionsdk.internal.VersionInfo; | ||
import com.amazonaws.encryptionsdk.model.CiphertextHeaders; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
import com.amazonaws.encryptionsdk.exception.BadCiphertextException; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.Arrays; | ||
|
||
import static org.junit.Assert.*; | ||
import static org.mockito.Mockito.spy; | ||
|
||
public class ParsedCiphertextTest extends CiphertextHeaders { | ||
private StaticMasterKey masterKeyProvider; | ||
private AwsCrypto encryptionClient_; | ||
|
||
@Before | ||
public void init() { | ||
masterKeyProvider = spy(new StaticMasterKey("testmaterial")); | ||
|
||
encryptionClient_ = new AwsCrypto(); | ||
encryptionClient_.setEncryptionAlgorithm(CryptoAlgorithm.ALG_AES_128_GCM_IV12_TAG16_HKDF_SHA256); | ||
} | ||
|
||
@Test() | ||
public void goodParsedCiphertext() { | ||
final int byteSize = 0; | ||
final int frameSize = 0; | ||
final byte[] plaintextBytes = new byte[byteSize]; | ||
|
||
final Map<String, String> encryptionContext = new HashMap<String, String>(1); | ||
encryptionContext.put("ENC1", "ParsedCiphertext test with %d" + byteSize); | ||
|
||
encryptionClient_.setEncryptionFrameSize(frameSize); | ||
|
||
final byte[] cipherText = encryptionClient_.encryptData( | ||
masterKeyProvider, | ||
plaintextBytes, | ||
encryptionContext).getResult(); | ||
final ParsedCiphertext pCt = new ParsedCiphertext(cipherText); | ||
|
||
assertNotNull(pCt.getCiphertext()); | ||
assertTrue(pCt.getOffset() > 0); | ||
} | ||
|
||
@Test(expected = BadCiphertextException.class) | ||
public void incompleteZeroByteCiphertext() { | ||
final byte[] cipherText = {}; | ||
ParsedCiphertext pCt = new ParsedCiphertext(cipherText); | ||
} | ||
|
||
@Test(expected = BadCiphertextException.class) | ||
public void incompleteSingleByteCiphertext() { | ||
final byte[] cipherText = {VersionInfo.CURRENT_CIPHERTEXT_VERSION}; | ||
ParsedCiphertext pCt = new ParsedCiphertext(cipherText); | ||
lavaleri marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
@Test(expected = BadCiphertextException.class) | ||
public void incompleteCiphertext() { | ||
final int byteSize = 0; | ||
final int frameSize = 0; | ||
final byte[] plaintextBytes = new byte[byteSize]; | ||
|
||
final Map<String, String> encryptionContext = new HashMap<String, String>(1); | ||
encryptionContext.put("ENC1", "ParsedCiphertext test with %d" + byteSize); | ||
|
||
encryptionClient_.setEncryptionFrameSize(frameSize); | ||
|
||
final byte[] cipherText = encryptionClient_.encryptData( | ||
masterKeyProvider, | ||
plaintextBytes, | ||
encryptionContext).getResult(); | ||
ParsedCiphertext pCt = new ParsedCiphertext(cipherText); | ||
|
||
byte[] incompleteCiphertext = Arrays.copyOf(pCt.getCiphertext(), pCt.getOffset() - 1); | ||
ParsedCiphertext badPCt = new ParsedCiphertext(incompleteCiphertext); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.