Skip to content

fix: Add Locale.ROOT to String uppercase conversions #1880

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Dec 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.security.PublicKey;
import java.security.spec.AlgorithmParameterSpec;
import java.security.spec.MGF1ParameterSpec;
import java.util.Locale;
import java.util.Map;
import java.util.logging.Logger;
import java.util.regex.Matcher;
Expand Down Expand Up @@ -49,7 +50,7 @@ class RsaJceKeyCipher extends JceKeyCipher {
final String hashUnknownCase = matcher.group(1);
if (hashUnknownCase != null) {
// OAEP mode a.k.a PKCS #1v2
final String hash = hashUnknownCase.toUpperCase();
final String hash = hashUnknownCase.toUpperCase(Locale.ROOT);
transformation_ = "RSA/ECB/OAEPPadding";

final MGF1ParameterSpec mgf1Spec;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import javax.crypto.SecretKey;
import javax.crypto.spec.SecretKeySpec;
Expand Down Expand Up @@ -59,7 +60,7 @@ public static JceMasterKey getInstance(
final String provider,
final String keyId,
final String wrappingAlgorithm) {
switch (wrappingAlgorithm.toUpperCase()) {
switch (wrappingAlgorithm.toUpperCase(Locale.ROOT)) {
case "AES/GCM/NOPADDING":
return new JceMasterKey(provider, keyId, JceKeyCipher.aesGcm(key));
default:
Expand All @@ -82,7 +83,7 @@ public static JceMasterKey getInstance(
final String provider,
final String keyId,
final String wrappingAlgorithm) {
if (wrappingAlgorithm.toUpperCase().startsWith("RSA/ECB/")) {
if (wrappingAlgorithm.toUpperCase(Locale.ROOT).startsWith("RSA/ECB/")) {
return new JceMasterKey(
provider, keyId, JceKeyCipher.rsa(wrappingKey, unwrappingKey, wrappingAlgorithm));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
import java.util.Map;

/**
Expand Down Expand Up @@ -79,7 +80,7 @@ public KeyStoreProvider(
wrappingAlgorithm_ = wrappingAlgorithm;
aliasNames_ = Arrays.asList(aliasNames);
providerName_ = providerName;
keyAlgorithm_ = wrappingAlgorithm.split("/", 2)[0].toUpperCase();
keyAlgorithm_ = wrappingAlgorithm.split("/", 2)[0].toUpperCase(Locale.ROOT);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.concurrent.Callable;
import java.util.function.Supplier;
Expand Down Expand Up @@ -333,7 +334,9 @@ private static <T> TestCase parseTest(
transformation += "PKCS1Padding";
} else if ("oaep-mgf1".equals(padding)) {
final String hashName =
((String) mkEntry.get("padding-hash")).replace("sha", "sha-").toUpperCase();
((String) mkEntry.get("padding-hash"))
.replace("sha", "sha-")
.toUpperCase(Locale.ROOT);
transformation += "OAEPWith" + hashName + "AndMGF1Padding";
} else {
throw new IllegalArgumentException("Unsupported padding:" + padding);
Expand Down Expand Up @@ -438,7 +441,9 @@ private static TestCase parseTest(
transformation += "PKCS1Padding";
} else if ("oaep-mgf1".equals(padding)) {
final String hashName =
((String) mkEntry.get("padding-hash")).replace("sha", "sha-").toUpperCase();
((String) mkEntry.get("padding-hash"))
.replace("sha", "sha-")
.toUpperCase(Locale.ROOT);
transformation += "OAEPWith" + hashName + "AndMGF1Padding";
} else {
throw new IllegalArgumentException("Unsupported padding:" + padding);
Expand Down Expand Up @@ -544,7 +549,7 @@ private static Map<String, KeyEntry> parseKeyManifest(final Map<String, Object>
name,
keyId,
keyType,
new SecretKeySpec(Base64.decode(material), algorithm.toUpperCase()));
new SecretKeySpec(Base64.decode(material), algorithm.toUpperCase(Locale.ROOT)));
break;
case "private":
kf = KeyFactory.getInstance(algorithm);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import javax.crypto.spec.SecretKeySpec;
import org.apache.commons.lang3.StringUtils;
Expand Down Expand Up @@ -143,7 +144,7 @@ public static Collection<Object[]> data() throws Exception {
+ "."
+ paddingHash;
String encAlg = (String) aMasterKey.get("encryption_algorithm");
switch (encAlg.toUpperCase()) {
switch (encAlg.toUpperCase(Locale.ROOT)) {
case "RSA":
String cipherBase = "RSA/ECB/";
String cipherName;
Expand Down Expand Up @@ -176,7 +177,7 @@ public static Collection<Object[]> data() throws Exception {
break;
default:
throw new IllegalArgumentException(
"Unknown encryption algorithm: " + encAlg.toUpperCase());
"Unknown encryption algorithm: " + encAlg.toUpperCase(Locale.ROOT));
}
}
}
Expand Down