Skip to content

Commit c8127a4

Browse files
authored
Merge pull request #22886 from jhanders34/perf-improvement3
Updates to MP JWT features
2 parents abf2045 + b126bde commit c8127a4

File tree

29 files changed

+635
-534
lines changed

29 files changed

+635
-534
lines changed

dev/com.ibm.websphere.appserver.features/visibility/public/mpJwt-1.2/com.ibm.websphere.appserver.mpJwt-1.2.feature

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ Subsystem-Name: MicroProfile JSON Web Token 1.2
2020
com.ibm.websphere.appserver.authFilter-1.0
2121
-bundles=com.ibm.ws.security.mp.jwt,\
2222
com.ibm.ws.security.mp.jwt.cdi,\
23-
io.openliberty.security.mp.jwt.1.2.config,\
24-
com.ibm.ws.security.mp.jwt.1.1.config
23+
io.openliberty.security.mp.jwt.1.2.config
2524
kind=ga
2625
edition=core
2726
WLP-Activation-Type: parallel

dev/com.ibm.websphere.appserver.features/visibility/public/mpJwt-2.0/io.openliberty.mpJwt-2.0.feature

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ Subsystem-Name: MicroProfile JSON Web Token 2.0
2020
com.ibm.websphere.appserver.authFilter-1.0
2121
-bundles=io.openliberty.security.mp.jwt.internal,\
2222
io.openliberty.security.mp.jwt.cdi.internal,\
23-
io.openliberty.security.mp.jwt.1.2.config,\
24-
com.ibm.ws.security.mp.jwt.1.1.config
23+
io.openliberty.security.mp.jwt.1.2.config
2524
kind=ga
2625
edition=core
2726
WLP-Activation-Type: parallel

dev/com.ibm.websphere.appserver.features/visibility/public/mpJwt-2.1/io.openliberty.mpJwt-2.1.feature

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@ Subsystem-Name: MicroProfile JSON Web Token 2.1
1717
io.openliberty.cdi-4.0
1818
-bundles=io.openliberty.security.mp.jwt.internal,\
1919
io.openliberty.security.mp.jwt.cdi.internal,\
20-
io.openliberty.security.mp.jwt.2.1.config,\
21-
io.openliberty.security.mp.jwt.1.2.config,\
22-
com.ibm.ws.security.mp.jwt.1.1.config
20+
io.openliberty.security.mp.jwt.2.1.config
2321
kind=beta
2422
edition=core
2523
WLP-Activation-Type: parallel

dev/com.ibm.ws.security.common.jsonwebkey/src/com/ibm/ws/security/common/jwk/impl/JWKProvider.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2016, 2020 IBM Corporation and others.
2+
* Copyright (c) 2016, 2022 IBM Corporation and others.
33
* All rights reserved. This program and the accompanying materials
44
* are made available under the terms of the Eclipse Public License v1.0
55
* which accompanies this distribution, and is available at
@@ -55,8 +55,6 @@ public class JWKProvider {
5555

5656
protected String publicKeyKid = null;
5757

58-
private KeyAlgorithmChecker keyAlgChecker = new KeyAlgorithmChecker();
59-
6058
protected JWKProvider() {
6159
this(DEFAULT_KEY_SIZE, RS256, DEFAULT_ROTATION_TIME);
6260
}
@@ -142,14 +140,14 @@ protected JWK generateJWK(String alg, int size) {
142140
}
143141

144142
boolean isValidJwkAlgorithm(String alg) {
145-
return keyAlgChecker.isRSAlgorithm(alg) || keyAlgChecker.isESAlgorithm(alg);
143+
return KeyAlgorithmChecker.isRSAlgorithm(alg) || KeyAlgorithmChecker.isESAlgorithm(alg);
146144
}
147145

148146
JWK generateJwkForValidAlgorithmWithExistingKeys(String alg, int size, PublicKey publicKey, PrivateKey privateKey) {
149147
JWK jwk = null;
150-
if (keyAlgChecker.isRSAlgorithm(alg)) {
148+
if (KeyAlgorithmChecker.isRSAlgorithm(alg)) {
151149
jwk = generateRsaJwkWithExistingKeys(alg, publicKey, privateKey);
152-
} else if (keyAlgChecker.isESAlgorithm(alg)) {
150+
} else if (KeyAlgorithmChecker.isESAlgorithm(alg)) {
153151
jwk = generateEcJwkWithExistingKeys(alg, publicKey, privateKey);
154152
}
155153
if (jwk != null) {
@@ -174,9 +172,9 @@ JWK generateEcJwkWithExistingKeys(String alg, PublicKey publicKey, PrivateKey pr
174172

175173
JWK generateJwkForValidAlgorithm(String alg, int size) {
176174
JWK jwk = null;
177-
if (keyAlgChecker.isRSAlgorithm(alg)) {
175+
if (KeyAlgorithmChecker.isRSAlgorithm(alg)) {
178176
jwk = generateRsaJWK(alg, size);
179-
} else if (keyAlgChecker.isESAlgorithm(alg)) {
177+
} else if (KeyAlgorithmChecker.isESAlgorithm(alg)) {
180178
jwk = generateEcJwk(alg);
181179
}
182180
return jwk;

dev/com.ibm.ws.security.common.jsonwebkey/src/com/ibm/ws/security/common/jwk/impl/JwKRetriever.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,6 @@ public enum JwkKeyType {
9696
String keyText = null;
9797
String locationUsed = null;
9898

99-
KeyAlgorithmChecker keyAlgChecker = new KeyAlgorithmChecker();
100-
10199
public HttpUtils httpUtils;
102100

103101
public JwKRetriever(JWKSet jwkSet) {
@@ -528,7 +526,7 @@ protected boolean parseKeyText(@Sensitive String keyText, String location, JWKSe
528526
}
529527

530528
boolean isPemSupportedAlgorithm(String signatureAlgorithm) {
531-
return keyAlgChecker.isRSAlgorithm(signatureAlgorithm) || keyAlgChecker.isESAlgorithm(signatureAlgorithm);
529+
return KeyAlgorithmChecker.isRSAlgorithm(signatureAlgorithm) || KeyAlgorithmChecker.isESAlgorithm(signatureAlgorithm);
532530
}
533531

534532
@Sensitive
@@ -556,7 +554,7 @@ boolean isPublicKeyJwk(KeyType keyType) {
556554

557555
JWK parsePublicKeyJwk(String keyText, String signatureAlgorithm) throws Exception {
558556
PublicKey pubKey = PemKeyUtil.getPublicKey(keyText);
559-
if (keyAlgChecker.isESAlgorithm(signatureAlgorithm)) {
557+
if (KeyAlgorithmChecker.isESAlgorithm(signatureAlgorithm)) {
560558
return getEcJwkPublicKey(pubKey, signatureAlgorithm);
561559
} else {
562560
return getRsaJwkPublicKey(pubKey, signatureAlgorithm);
@@ -566,7 +564,7 @@ JWK parsePublicKeyJwk(String keyText, String signatureAlgorithm) throws Exceptio
566564
@Sensitive
567565
JWK parsePrivateKeyJwk(@Sensitive String keyText, String signatureAlgorithm) throws Exception {
568566
PrivateKey privateKey = PemKeyUtil.getPrivateKey(keyText);
569-
if (keyAlgChecker.isESAlgorithm(signatureAlgorithm)) {
567+
if (KeyAlgorithmChecker.isESAlgorithm(signatureAlgorithm)) {
570568
return getEcJwkPrivateKey(privateKey, signatureAlgorithm);
571569
} else {
572570
return getRsaJwkPrivateKey(privateKey, signatureAlgorithm);

dev/com.ibm.ws.security.common/src/com/ibm/ws/security/common/crypto/KeyAlgorithmChecker.java

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,19 @@ public class KeyAlgorithmChecker {
3535

3636
public static int UNKNOWN_HASH_SIZE = 0;
3737

38-
public boolean isHSAlgorithm(String alg) {
38+
private KeyAlgorithmChecker() {
39+
// no one should new up an instance of this class.
40+
}
41+
42+
public static boolean isHSAlgorithm(String alg) {
3943
if (alg == null) {
4044
return false;
4145
}
4246
Matcher m = HSA_PATTERN.matcher(alg);
4347
return m.matches();
4448
}
4549

46-
public boolean isPublicKeyValidType(Key key, String supportedSigAlg) {
50+
public static boolean isPublicKeyValidType(Key key, String supportedSigAlg) {
4751
if (key == null || supportedSigAlg == null) {
4852
// Rely on caller to do the appropriate checks if the key or algorithm is null
4953
return true;
@@ -59,36 +63,36 @@ public boolean isPublicKeyValidType(Key key, String supportedSigAlg) {
5963
return false;
6064
}
6165

62-
public boolean isRSAlgorithm(String alg) {
66+
public static boolean isRSAlgorithm(String alg) {
6367
if (alg == null) {
6468
return false;
6569
}
6670
Matcher m = RSA_PATTERN.matcher(alg);
6771
return m.matches();
6872
}
6973

70-
public boolean isValidRSAPublicKey(Key key) {
74+
public static boolean isValidRSAPublicKey(Key key) {
7175
String keyAlgorithm = key.getAlgorithm();
7276
// TODO - any way to check hash bit size?
7377
return (keyAlgorithm.equals("RSA") && key instanceof RSAPublicKey);
7478
}
7579

76-
public boolean isESAlgorithm(String alg) {
80+
public static boolean isESAlgorithm(String alg) {
7781
if (alg == null) {
7882
return false;
7983
}
8084
Matcher m = ESA_PATTERN.matcher(alg);
8185
return m.matches();
8286
}
8387

84-
public boolean isValidECPublicKey(String supportedSigAlg, Key key) {
88+
public static boolean isValidECPublicKey(String supportedSigAlg, Key key) {
8589
if (!("EC".equals(key.getAlgorithm()) && key instanceof ECPublicKey)) {
8690
return false;
8791
}
8892
return isValidECKeyParameters(supportedSigAlg, (ECPublicKey) key);
8993
}
9094

91-
boolean isValidECKeyParameters(String supportedSigAlg, ECKey key) {
95+
static boolean isValidECKeyParameters(String supportedSigAlg, ECKey key) {
9296
ECParameterSpec params = key.getParams();
9397
int fieldSize = params.getCurve().getField().getFieldSize();
9498
if (tc.isDebugEnabled()) {
@@ -106,7 +110,7 @@ boolean isValidECKeyParameters(String supportedSigAlg, ECKey key) {
106110
* Extracts the hash size from algorithm strings such as RS256, HS384, or ES512.
107111
*/
108112
@FFDCIgnore(Exception.class)
109-
public int getHashSizeFromAlgorithm(String algorithm) {
113+
public static int getHashSizeFromAlgorithm(String algorithm) {
110114
int hashSize = UNKNOWN_HASH_SIZE;
111115
Matcher algMatcher = ALG_PATTERN.matcher(algorithm);
112116
if (!algMatcher.matches()) {
@@ -127,7 +131,7 @@ public int getHashSizeFromAlgorithm(String algorithm) {
127131
return hashSize;
128132
}
129133

130-
public boolean isPrivateKeyValidType(Key key, String supportedSigAlg) {
134+
public static boolean isPrivateKeyValidType(Key key, String supportedSigAlg) {
131135
if (key == null || supportedSigAlg == null) {
132136
// Rely on caller to do the appropriate checks if the key or algorithm is null
133137
return true;
@@ -143,13 +147,13 @@ public boolean isPrivateKeyValidType(Key key, String supportedSigAlg) {
143147
return false;
144148
}
145149

146-
public boolean isValidRSAPrivateKey(Key key) {
150+
public static boolean isValidRSAPrivateKey(Key key) {
147151
String keyAlgorithm = key.getAlgorithm();
148152
// TODO - any way to check hash bit size?
149153
return (keyAlgorithm.equals("RSA") && key instanceof RSAPrivateKey);
150154
}
151155

152-
public boolean isValidECPrivateKey(String supportedSigAlg, Key key) {
156+
public static boolean isValidECPrivateKey(String supportedSigAlg, Key key) {
153157
if (!("EC".equals(key.getAlgorithm()) && key instanceof ECPrivateKey)) {
154158
return false;
155159
}

0 commit comments

Comments
 (0)