Skip to content

Commit 0fcecd2

Browse files
author
Justin Richer
committed
renamed JWSUtils -> IdTokenHashUtils, renamed internal variables
Conflicts: openid-connect-server/src/main/java/org/mitre/openid/connect/token/ConnectTokenEnhancer.java
1 parent 6866d2e commit 0fcecd2

File tree

3 files changed

+34
-15
lines changed

3 files changed

+34
-15
lines changed

openid-connect-server/src/main/java/org/mitre/openid/connect/token/ConnectTokenEnhancer.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626
import org.mitre.oauth2.model.OAuth2AccessTokenEntity;
2727
import org.mitre.oauth2.service.ClientDetailsEntityService;
2828
import org.mitre.openid.connect.config.ConfigurationPropertiesBean;
29-
import org.mitre.openid.connect.util.JWSUtils;
29+
import org.mitre.openid.connect.service.ApprovedSiteService;
30+
import org.mitre.openid.connect.util.IdTokenHashUtils;
3031
import org.mitre.openid.connect.web.AuthenticationTimeStamper;
3132
import org.slf4j.Logger;
3233
import org.slf4j.LoggerFactory;
@@ -147,7 +148,7 @@ public OAuth2AccessToken enhance(OAuth2AccessToken accessToken, OAuth2Authentica
147148
Set<String> responseTypes = OAuth2Utils.parseParameterList(responseType);
148149
if (responseTypes.contains("token")) {
149150
// calculate the token hash
150-
Base64URL at_hash = JWSUtils.getAccessTokenHash(signingAlg, token);
151+
Base64URL at_hash = IdTokenHashUtils.getAccessTokenHash(signingAlg, token);
151152
//TODO: What should happen if the hash cannot be calculated?
152153
idClaims.setClaim("at_hash", at_hash);
153154
}

openid-connect-server/src/main/java/org/mitre/openid/connect/util/JWSUtils.java renamed to openid-connect-server/src/main/java/org/mitre/openid/connect/util/IdTokenHashUtils.java

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
/*******************************************************************************
2+
* Copyright 2013 The MITRE Corporation
3+
* and the MIT Kerberos and Internet Trust Consortium
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
******************************************************************************/
17+
118
package org.mitre.openid.connect.util;
219

320
import java.security.MessageDigest;
@@ -12,14 +29,15 @@
1229
import com.nimbusds.jose.util.Base64URL;
1330

1431
/**
15-
* Utility class for JWS processing.
32+
* Utility class for generating hashes for access tokens and authorization codes
33+
* to be included in an ID Token.
1634
*
1735
* @author Amanda Anganes
18-
*
36+
*
1937
*/
20-
public class JWSUtils {
38+
public class IdTokenHashUtils {
2139

22-
private static Logger logger = LoggerFactory.getLogger(JWSUtils.class);
40+
private static Logger logger = LoggerFactory.getLogger(IdTokenHashUtils.class);
2341

2442
/**
2543
* Compute the SHA hash of an authorization code
@@ -72,11 +90,11 @@ else if (signingAlg.equals(JWSAlgorithm.ES512) || signingAlg.equals(JWSAlgorithm
7290
hasher.reset();
7391
hasher.update(bytes);
7492

75-
byte[] atHashBytes = hasher.digest();
76-
byte[] atHashBytesLeftHalf = Arrays.copyOf(atHashBytes, atHashBytes.length / 2);
77-
Base64URL at_hash = Base64URL.encode(atHashBytesLeftHalf);
93+
byte[] hashBytes = hasher.digest();
94+
byte[] hashBytesLeftHalf = Arrays.copyOf(hashBytes, hashBytes.length / 2);
95+
Base64URL encodedHash = Base64URL.encode(hashBytesLeftHalf);
7896

79-
return at_hash;
97+
return encodedHash;
8098

8199
} catch (NoSuchAlgorithmException e) {
82100

openid-connect-server/src/test/java/org/mitre/openid/connect/util/TestJWSUtils.java renamed to openid-connect-server/src/test/java/org/mitre/openid/connect/util/TestIdTokenHashUtils.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
*
3939
*/
4040
@RunWith(MockitoJUnitRunner.class)
41-
public class TestJWSUtils {
41+
public class TestIdTokenHashUtils {
4242

4343
@Mock
4444
OAuth2AccessTokenEntity mockToken256;
@@ -83,7 +83,7 @@ public void getAccessTokenHash256() {
8383
String token = mockToken256.getJwt().serialize();
8484
Base64URL expectedHash = new Base64URL("EP1gXNeESRH-n57baopfTQ");
8585

86-
Base64URL resultHash = JWSUtils.getAccessTokenHash(JWSAlgorithm.HS256, mockToken256);
86+
Base64URL resultHash = IdTokenHashUtils.getAccessTokenHash(JWSAlgorithm.HS256, mockToken256);
8787

8888
assertEquals(expectedHash, resultHash);
8989
}
@@ -100,7 +100,7 @@ public void getAccessTokenHash384() {
100100
String token = mockToken384.getJwt().serialize();
101101
Base64URL expectedHash = new Base64URL("BWfFK73PQI36M1rg9R6VjMyWOE0-XvBK");
102102

103-
Base64URL resultHash = JWSUtils.getAccessTokenHash(JWSAlgorithm.ES384, mockToken384);
103+
Base64URL resultHash = IdTokenHashUtils.getAccessTokenHash(JWSAlgorithm.ES384, mockToken384);
104104

105105
assertEquals(expectedHash, resultHash);
106106
}
@@ -117,7 +117,7 @@ public void getAccessTokenHash512() {
117117
String token = mockToken512.getJwt().serialize();
118118
Base64URL expectedHash = new Base64URL("vGH3QMY-knpACkLgzdkTqu3C9jtvbf2Wk_RSu2vAx8k");
119119

120-
Base64URL resultHash = JWSUtils.getAccessTokenHash(JWSAlgorithm.RS512, mockToken512);
120+
Base64URL resultHash = IdTokenHashUtils.getAccessTokenHash(JWSAlgorithm.RS512, mockToken512);
121121

122122
assertEquals(expectedHash, resultHash);
123123
}
@@ -129,7 +129,7 @@ public void getCodeHash512() {
129129

130130
Base64URL expectedHash = new Base64URL("R5DCRi5eOjlvyTAJfry2dNM9adJ2ElpDEKYYByYU920"); // independently generated
131131

132-
Base64URL resultHash = JWSUtils.getCodeHash(JWSAlgorithm.ES512, testCode);
132+
Base64URL resultHash = IdTokenHashUtils.getCodeHash(JWSAlgorithm.ES512, testCode);
133133

134134
assertEquals(expectedHash, resultHash);
135135
}

0 commit comments

Comments
 (0)