Skip to content

Commit 03154a1

Browse files
committed
Add comment to explain why padding is removed.
Change-Id: I0882e0c5d99310b179ace493b937669520626263
1 parent 0dd70a0 commit 03154a1

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,8 @@ public AccessToken generateToken(CredentialAccessBoundary accessBoundary)
206206

207207
byte[] encryptedRestrictions = this.encryptRestrictions(rawRestrictions, sessionKey);
208208

209+
// withoutPadding() is used to stay consistent with server-side CAB
210+
// withoutPadding() avoids additional URL encoded token issues (i.e. extra equal signs `=` in the path)
209211
String tokenValue =
210212
intermediateToken + "." + Base64.getUrlEncoder().withoutPadding().encodeToString(encryptedRestrictions);
211213

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -745,7 +745,9 @@ public void generateToken_withAvailablityCondition_success() throws Exception {
745745
CabToken cabToken = parseCabToken(token);
746746
assertEquals("accessToken", cabToken.intermediateToken);
747747

748-
// Verifies the encrypted restriction has no padding
748+
// Base64 encoding output by default has `=` padding at the end if the input length
749+
// is not a multiple of 3. Here we verify the use of `withoutPadding` that removes
750+
// this padding.
749751
assertFalse(cabToken.encryptedRestriction.contains(String.valueOf("=")));
750752

751753
// Checks the encrypted restriction is the correct proto format of the CredentialAccessBoundary.
@@ -798,7 +800,9 @@ public void generateToken_withoutAvailabilityCondition_success() throws Exceptio
798800
CabToken cabToken = parseCabToken(token);
799801
assertEquals("accessToken", cabToken.intermediateToken);
800802

801-
// Verifies the encrypted restriction has no padding
803+
// Base64 encoding output by default has `=` padding at the end if the input length
804+
// is not a multiple of 3. Here we verify the use of `withoutPadding` that removes
805+
// this padding.
802806
assertFalse(cabToken.encryptedRestriction.contains(String.valueOf("=")));
803807

804808
// Checks the encrypted restriction is the correct proto format of the CredentialAccessBoundary.

0 commit comments

Comments
 (0)