Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,11 @@ public String decrypt(String value) throws InvalidKeyException {

try {
byte[] iv = new byte[16];

if (bytes.length < iv.length) {
throw new InvalidKeyException("Invalid characters in decrypted value");
}

System.arraycopy(bytes, 0, iv, 0, iv.length);
IvParameterSpec ivspec = new IvParameterSpec(iv);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@

package com.sun.faces.util;

import java.security.InvalidKeyException;
import javax.xml.bind.DatatypeConverter;
import org.junit.Test;

import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;


public class ByteArrayGuardAESCTRTest {
Expand All @@ -39,5 +41,16 @@ public void testSmallerSizeBytes() throws Exception {

}

@Test(expected = InvalidKeyException.class)
public void testDecryptValueWithoutIvBytes() throws InvalidKeyException {
ByteArrayGuardAESCTR sut = new ByteArrayGuardAESCTR();

String value = "noIV";
byte[] bytes = DatatypeConverter.parseBase64Binary(value);
assertTrue(bytes.length < 16);

sut.decrypt(value);
}

}