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