提交 0c9da838 编写于 作者: I igerasim

7065233: To interpret case-insensitive string locale independently

Reviewed-by: xuelei
上级 c0818f6e
/*
* Copyright (c) 1998, 2011, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
......@@ -107,7 +107,7 @@ public final class JceKeyStore extends KeyStoreSpi {
{
Key key = null;
Object entry = entries.get(alias.toLowerCase());
Object entry = entries.get(alias.toLowerCase(Locale.ENGLISH));
if (!((entry instanceof PrivateKeyEntry) ||
(entry instanceof SecretKeyEntry))) {
......@@ -150,7 +150,7 @@ public final class JceKeyStore extends KeyStoreSpi {
{
Certificate[] chain = null;
Object entry = entries.get(alias.toLowerCase());
Object entry = entries.get(alias.toLowerCase(Locale.ENGLISH));
if ((entry instanceof PrivateKeyEntry)
&& (((PrivateKeyEntry)entry).chain != null)) {
......@@ -178,7 +178,7 @@ public final class JceKeyStore extends KeyStoreSpi {
public Certificate engineGetCertificate(String alias) {
Certificate cert = null;
Object entry = entries.get(alias.toLowerCase());
Object entry = entries.get(alias.toLowerCase(Locale.ENGLISH));
if (entry != null) {
if (entry instanceof TrustedCertEntry) {
......@@ -203,7 +203,7 @@ public final class JceKeyStore extends KeyStoreSpi {
public Date engineGetCreationDate(String alias) {
Date date = null;
Object entry = entries.get(alias.toLowerCase());
Object entry = entries.get(alias.toLowerCase(Locale.ENGLISH));
if (entry != null) {
// We have to create a new instance of java.util.Date because
......@@ -266,7 +266,7 @@ public final class JceKeyStore extends KeyStoreSpi {
}
// store the entry
entries.put(alias.toLowerCase(), entry);
entries.put(alias.toLowerCase(Locale.ENGLISH), entry);
} else {
SecretKeyEntry entry = new SecretKeyEntry();
......@@ -274,7 +274,7 @@ public final class JceKeyStore extends KeyStoreSpi {
// seal and store the key
entry.sealedKey = keyProtector.seal(key);
entries.put(alias.toLowerCase(), entry);
entries.put(alias.toLowerCase(Locale.ENGLISH), entry);
}
} catch (Exception e) {
......@@ -322,7 +322,7 @@ public final class JceKeyStore extends KeyStoreSpi {
entry.chain = null;
}
entries.put(alias.toLowerCase(), entry);
entries.put(alias.toLowerCase(Locale.ENGLISH), entry);
}
}
......@@ -345,7 +345,7 @@ public final class JceKeyStore extends KeyStoreSpi {
{
synchronized(entries) {
Object entry = entries.get(alias.toLowerCase());
Object entry = entries.get(alias.toLowerCase(Locale.ENGLISH));
if (entry != null) {
if (entry instanceof PrivateKeyEntry) {
throw new KeyStoreException("Cannot overwrite own "
......@@ -358,7 +358,7 @@ public final class JceKeyStore extends KeyStoreSpi {
TrustedCertEntry trustedCertEntry = new TrustedCertEntry();
trustedCertEntry.cert = cert;
trustedCertEntry.date = new Date();
entries.put(alias.toLowerCase(), trustedCertEntry);
entries.put(alias.toLowerCase(Locale.ENGLISH), trustedCertEntry);
}
}
......@@ -373,7 +373,7 @@ public final class JceKeyStore extends KeyStoreSpi {
throws KeyStoreException
{
synchronized(entries) {
entries.remove(alias.toLowerCase());
entries.remove(alias.toLowerCase(Locale.ENGLISH));
}
}
......@@ -394,7 +394,7 @@ public final class JceKeyStore extends KeyStoreSpi {
* @return true if the alias exists, false otherwise
*/
public boolean engineContainsAlias(String alias) {
return entries.containsKey(alias.toLowerCase());
return entries.containsKey(alias.toLowerCase(Locale.ENGLISH));
}
/**
......@@ -416,7 +416,7 @@ public final class JceKeyStore extends KeyStoreSpi {
public boolean engineIsKeyEntry(String alias) {
boolean isKey = false;
Object entry = entries.get(alias.toLowerCase());
Object entry = entries.get(alias.toLowerCase(Locale.ENGLISH));
if ((entry instanceof PrivateKeyEntry)
|| (entry instanceof SecretKeyEntry)) {
isKey = true;
......@@ -434,7 +434,7 @@ public final class JceKeyStore extends KeyStoreSpi {
*/
public boolean engineIsCertificateEntry(String alias) {
boolean isCert = false;
Object entry = entries.get(alias.toLowerCase());
Object entry = entries.get(alias.toLowerCase(Locale.ENGLISH));
if (entry instanceof TrustedCertEntry) {
isCert = true;
}
......
/*
* Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
......@@ -27,6 +27,7 @@ package com.sun.crypto.provider;
import java.security.KeyRep;
import java.security.spec.InvalidKeySpecException;
import java.util.Locale;
import javax.crypto.SecretKey;
import javax.crypto.spec.PBEKeySpec;
......@@ -91,7 +92,7 @@ final class PBEKey implements SecretKey {
for (int i = 1; i < this.key.length; i++) {
retval += this.key[i] * i;
}
return(retval ^= getAlgorithm().toLowerCase().hashCode());
return(retval ^= getAlgorithm().toLowerCase(Locale.ENGLISH).hashCode());
}
public boolean equals(Object obj) {
......
/*
* Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
......@@ -32,6 +32,7 @@ import javax.crypto.SecretKey;
import javax.crypto.SecretKeyFactorySpi;
import javax.crypto.spec.PBEKeySpec;
import java.util.HashSet;
import java.util.Locale;
/**
* This class implements a key factory for PBE keys according to PKCS#5,
......@@ -56,24 +57,24 @@ abstract class PBEKeyFactory extends SecretKeyFactorySpi {
static {
validTypes = new HashSet<String>(17);
validTypes.add("PBEWithMD5AndDES".toUpperCase());
validTypes.add("PBEWithSHA1AndDESede".toUpperCase());
validTypes.add("PBEWithSHA1AndRC2_40".toUpperCase());
validTypes.add("PBEWithSHA1AndRC2_128".toUpperCase());
validTypes.add("PBEWithSHA1AndRC4_40".toUpperCase());
validTypes.add("PBEWithSHA1AndRC4_128".toUpperCase());
validTypes.add("PBEWithMD5AndDES".toUpperCase(Locale.ENGLISH));
validTypes.add("PBEWithSHA1AndDESede".toUpperCase(Locale.ENGLISH));
validTypes.add("PBEWithSHA1AndRC2_40".toUpperCase(Locale.ENGLISH));
validTypes.add("PBEWithSHA1AndRC2_128".toUpperCase(Locale.ENGLISH));
validTypes.add("PBEWithSHA1AndRC4_40".toUpperCase(Locale.ENGLISH));
validTypes.add("PBEWithSHA1AndRC4_128".toUpperCase(Locale.ENGLISH));
// Proprietary algorithm.
validTypes.add("PBEWithMD5AndTripleDES".toUpperCase());
validTypes.add("PBEWithHmacSHA1AndAES_128".toUpperCase());
validTypes.add("PBEWithHmacSHA224AndAES_128".toUpperCase());
validTypes.add("PBEWithHmacSHA256AndAES_128".toUpperCase());
validTypes.add("PBEWithHmacSHA384AndAES_128".toUpperCase());
validTypes.add("PBEWithHmacSHA512AndAES_128".toUpperCase());
validTypes.add("PBEWithHmacSHA1AndAES_256".toUpperCase());
validTypes.add("PBEWithHmacSHA224AndAES_256".toUpperCase());
validTypes.add("PBEWithHmacSHA256AndAES_256".toUpperCase());
validTypes.add("PBEWithHmacSHA384AndAES_256".toUpperCase());
validTypes.add("PBEWithHmacSHA512AndAES_256".toUpperCase());
validTypes.add("PBEWithMD5AndTripleDES".toUpperCase(Locale.ENGLISH));
validTypes.add("PBEWithHmacSHA1AndAES_128".toUpperCase(Locale.ENGLISH));
validTypes.add("PBEWithHmacSHA224AndAES_128".toUpperCase(Locale.ENGLISH));
validTypes.add("PBEWithHmacSHA256AndAES_128".toUpperCase(Locale.ENGLISH));
validTypes.add("PBEWithHmacSHA384AndAES_128".toUpperCase(Locale.ENGLISH));
validTypes.add("PBEWithHmacSHA512AndAES_128".toUpperCase(Locale.ENGLISH));
validTypes.add("PBEWithHmacSHA1AndAES_256".toUpperCase(Locale.ENGLISH));
validTypes.add("PBEWithHmacSHA224AndAES_256".toUpperCase(Locale.ENGLISH));
validTypes.add("PBEWithHmacSHA256AndAES_256".toUpperCase(Locale.ENGLISH));
validTypes.add("PBEWithHmacSHA384AndAES_256".toUpperCase(Locale.ENGLISH));
validTypes.add("PBEWithHmacSHA512AndAES_256".toUpperCase(Locale.ENGLISH));
}
public static final class PBEWithMD5AndDES
......@@ -237,7 +238,7 @@ abstract class PBEKeyFactory extends SecretKeyFactorySpi {
protected KeySpec engineGetKeySpec(SecretKey key, Class<?> keySpecCl)
throws InvalidKeySpecException {
if ((key instanceof SecretKey)
&& (validTypes.contains(key.getAlgorithm().toUpperCase()))
&& (validTypes.contains(key.getAlgorithm().toUpperCase(Locale.ENGLISH)))
&& (key.getFormat().equalsIgnoreCase("RAW"))) {
// Check if requested key spec is amongst the valid ones
......@@ -279,7 +280,7 @@ abstract class PBEKeyFactory extends SecretKeyFactorySpi {
{
try {
if ((key != null) &&
(validTypes.contains(key.getAlgorithm().toUpperCase())) &&
(validTypes.contains(key.getAlgorithm().toUpperCase(Locale.ENGLISH))) &&
(key.getFormat().equalsIgnoreCase("RAW"))) {
// Check if key originates from this factory
......
/*
* Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2005, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
......@@ -30,6 +30,7 @@ import java.nio.ByteBuffer;
import java.nio.CharBuffer;
import java.nio.charset.Charset;
import java.util.Arrays;
import java.util.Locale;
import java.security.KeyRep;
import java.security.GeneralSecurityException;
import java.security.NoSuchAlgorithmException;
......@@ -143,7 +144,7 @@ final class PBKDF2KeyImpl implements javax.crypto.interfaces.PBEKey {
@Override
public int hashCode() {
return Arrays.hashCode(password) * 41 +
prf.getAlgorithm().toLowerCase().hashCode();
prf.getAlgorithm().toLowerCase(Locale.ENGLISH).hashCode();
}
@Override
public boolean equals(Object obj) {
......@@ -221,7 +222,7 @@ final class PBKDF2KeyImpl implements javax.crypto.interfaces.PBEKey {
for (int i = 1; i < this.key.length; i++) {
retval += this.key[i] * i;
}
return(retval ^= getAlgorithm().toLowerCase().hashCode());
return(retval ^= getAlgorithm().toLowerCase(Locale.ENGLISH).hashCode());
}
public boolean equals(Object obj) {
......
/*
* Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
......@@ -26,6 +26,7 @@
package javax.crypto.spec;
import java.security.spec.KeySpec;
import java.util.Locale;
import javax.crypto.SecretKey;
/**
......@@ -194,7 +195,8 @@ public class SecretKeySpec implements KeySpec, SecretKey {
if (this.algorithm.equalsIgnoreCase("TripleDES"))
return (retval ^= "desede".hashCode());
else
return (retval ^= this.algorithm.toLowerCase().hashCode());
return (retval ^=
this.algorithm.toLowerCase(Locale.ENGLISH).hashCode());
}
/**
......
/*
* Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1999, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
......@@ -900,7 +900,7 @@ public final class PKCS12KeyStore extends KeyStoreSpi {
private static ObjectIdentifier mapPBEAlgorithmToOID(String algorithm)
throws NoSuchAlgorithmException {
// Check for PBES2 algorithms
if (algorithm.toLowerCase().startsWith("pbewithhmacsha")) {
if (algorithm.toLowerCase(Locale.ENGLISH).startsWith("pbewithhmacsha")) {
return pbes2_OID;
}
return AlgorithmId.get(algorithm).getOID();
......
/*
* Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
......@@ -451,7 +451,7 @@ public final class ConfigFile extends Configuration {
// controlFlag (required, optional, etc)
LoginModuleControlFlag controlFlag;
String sflag = match("controlFlag").toUpperCase();
String sflag = match("controlFlag").toUpperCase(Locale.ENGLISH);
switch (sflag) {
case "REQUIRED":
controlFlag = LoginModuleControlFlag.REQUIRED;
......
/*
* Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
......@@ -707,7 +707,7 @@ public class PolicyParser {
} catch (PropertyExpander.ExpandException peee) {
throw new IOException(peee.getLocalizedMessage());
}
properties.put(key.toLowerCase(), value);
properties.put(key.toLowerCase(Locale.ENGLISH), value);
}
return properties;
......
......@@ -1494,7 +1494,7 @@ public final class Main {
boolean useDefaultPBEAlgorithm = true;
SecretKey secKey = null;
if (keyAlgName.toUpperCase().startsWith("PBE")) {
if (keyAlgName.toUpperCase(Locale.ENGLISH).startsWith("PBE")) {
SecretKeyFactory factory = SecretKeyFactory.getInstance("PBE");
// User is prompted for PBE credential
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册