From dbe092324f7acf79c9813ee99c5a4f1f61148dd7 Mon Sep 17 00:00:00 2001 From: Stephen Crawford Date: Tue, 11 Oct 2022 10:14:37 -0400 Subject: [PATCH] Byte array encoding fix Signed-off-by: Stephen Crawford --- .../org/opensearch/identity/ExtensionTokenProcessor.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/server/src/main/java/org/opensearch/identity/ExtensionTokenProcessor.java b/server/src/main/java/org/opensearch/identity/ExtensionTokenProcessor.java index 79eed3e7f439b..3c64e6aac7155 100644 --- a/server/src/main/java/org/opensearch/identity/ExtensionTokenProcessor.java +++ b/server/src/main/java/org/opensearch/identity/ExtensionTokenProcessor.java @@ -6,6 +6,7 @@ import java.security.Principal; import java.security.SecureRandom; +import java.util.Arrays; import java.util.Map; import java.io.ByteArrayOutputStream; import java.io.IOException; @@ -132,10 +133,10 @@ public Principal extractPrincipal(PrincipalIdentifierToken token) throws Illegal byte[] token_bytes = token_name.getBytes(); validateToken(token); - String[] parts = token.getToken().split(String.format("*{%d}", KEY_SIZE)); - String pricipalNameEncoded = parts[0]; - byte[] principalNameEncodedBytes = pricipalNameEncoded.getBytes(); - String extensionNameEncoded = parts[1]; + + + byte[] principalNameEncodedBytes = Arrays.copyOfRange(token_bytes, 0, KEY_SIZE); + byte[] extensionNameEncodedBytes = Arrays.copyOfRange(token_bytes, KEY_SIZE, token_bytes.length); Cipher principalCipher = Cipher.getInstance(ALGORITHM);