Skip to content
This repository was archived by the owner on Mar 20, 2021. It is now read-only.

Fixes #4386 - ELFlash sometimes throws ArrayIndexOutOfBoundsException if cookie contains invalid values #4412

Open
wants to merge 1 commit into
base: MOJARRA_2_3X_ROLLING
Choose a base branch
from
Open
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 @@ -149,11 +149,16 @@ public String encrypt(String value) {
}

public String decrypt(String value) throws InvalidKeyException {
byte[] bytes = DatatypeConverter.parseBase64Binary(value);;

byte[] bytes = DatatypeConverter.parseBase64Binary(value);

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 @@ -39,6 +39,8 @@
*/
package com.sun.faces.util;

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

import static org.junit.Assert.assertTrue;
Expand All @@ -61,6 +63,17 @@ 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);
}

}