Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ target/
.classpath
/bin/
.idea/
*.iml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import com.amazonaws.encryptionsdk.internal.Constants;
import com.amazonaws.encryptionsdk.internal.EncryptionContextSerializer;
import com.amazonaws.encryptionsdk.internal.PrimitivesParser;
import com.amazonaws.encryptionsdk.internal.VersionInfo;

/**
* This class implements the headers for the message (ciphertext) produced by
Expand Down Expand Up @@ -179,6 +180,9 @@ public Boolean isComplete() {
*/
private int parseVersion(final byte[] b, final int off) throws ParseException {
version_ = PrimitivesParser.parseByte(b, off);
if(CiphertextType.deserialize(version_).getValue() != VersionInfo.CURRENT_CIPHERTEXT_VERSION ) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Our style requires a space between the if and before the (.

throw new BadCiphertextException("Invalid version type.");
}
return 1;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,24 @@ private void readUptoNonceLen(final ByteBuffer headerBuff) {
headerBuff.get();
}

@Test(expected = BadCiphertextException.class)
public void invalidVersion(){
final Map<String, String> encryptionContext = new HashMap<String, String>(1);
encryptionContext.put("ENC", "CiphertextHeader Streaming Test");

final CiphertextHeaders ciphertextHeaders = createCiphertextHeaders(encryptionContext);
final byte[] headerBytes = ciphertextHeaders.toByteArray();
final ByteBuffer headerBuff = ByteBuffer.wrap(headerBytes);

readUptoType(headerBuff);

//set version to invalid value of 0.
headerBuff.put((byte) 0);

final CiphertextHeaders reconstructedHeaders = new CiphertextHeaders();
reconstructedHeaders.deserialize(headerBuff.array(), 0);
}

@Test(expected = BadCiphertextException.class)
public void invalidType() {
final Map<String, String> encryptionContext = new HashMap<String, String>(1);
Expand Down