Skip to content

Commit 730d97e

Browse files
committed
Catch and rethrow the exception of session key not being base64 encoded.
Change-Id: I5fa0c25fe020e9612735e4ac5df2b85a2a5aab11
1 parent e548e4d commit 730d97e

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

cab-token-generator/java/com/google/auth/credentialaccessboundary/ClientSideCredentialAccessBoundaryFactory.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,14 @@ private Expr compileCel(String expr) throws CelValidationException {
518518
* Encrypts the given bytes using a sessionKey using Tink Aead.
519519
*/
520520
private byte[] encryptRestrictions(byte[] restriction, String sessionKey) throws GeneralSecurityException {
521-
byte[] rawKey = Base64.getDecoder().decode(sessionKey);
521+
byte[] rawKey;
522+
523+
try {
524+
rawKey = Base64.getDecoder().decode(sessionKey);
525+
} catch (IllegalArgumentException e) {
526+
// Session key from the server is expected to be Base64 encoded
527+
throw new IllegalStateException("Session key is not Base64 encoded", e);
528+
}
522529

523530
KeysetHandle keysetHandle = TinkProtoKeysetFormat.parseKeyset(
524531
rawKey, InsecureSecretKeyAccess.get());

cab-token-generator/javatests/com/google/auth/credentialaccessboundary/ClientSideCredentialAccessBoundaryFactoryTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
import static org.junit.Assert.assertFalse;
3737
import static org.junit.Assert.assertNotNull;
3838
import static org.junit.Assert.assertThrows;
39-
import static org.junit.Assert.assertTrue;
4039
import static org.mockito.Mockito.mock;
4140
import static org.mockito.Mockito.when;
4241

@@ -876,7 +875,7 @@ public void generateToken_withSessionKeyNotBase64Encoded_failure() throws Except
876875
.build())
877876
.build();
878877

879-
assertThrows(IllegalArgumentException.class,
878+
assertThrows(IllegalStateException.class,
880879
() -> { factory.generateToken(accessBoundary); });
881880
}
882881

0 commit comments

Comments
 (0)