提交 68301733 编写于 作者: X xuelei

7059542: JNDI name operations should be locale independent

Reviewed-by: weijun
上级 d4e57853
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
package com.sun.jndi.ldap; package com.sun.jndi.ldap;
import java.util.Locale;
import java.util.Arrays; // JDK 1.2 import java.util.Arrays; // JDK 1.2
import java.io.OutputStream; import java.io.OutputStream;
import javax.naming.ldap.Control; import javax.naming.ldap.Control;
...@@ -71,7 +72,7 @@ class ClientId { ...@@ -71,7 +72,7 @@ class ClientId {
ClientId(int version, String hostname, int port, String protocol, ClientId(int version, String hostname, int port, String protocol,
Control[] bindCtls, OutputStream trace, String socketFactory) { Control[] bindCtls, OutputStream trace, String socketFactory) {
this.version = version; this.version = version;
this.hostname = hostname.toLowerCase(); // ignore case this.hostname = hostname.toLowerCase(Locale.ENGLISH); // ignore case
this.port = port; this.port = port;
this.protocol = protocol; this.protocol = protocol;
this.bindCtls = (bindCtls != null ? bindCtls.clone() : null); this.bindCtls = (bindCtls != null ? bindCtls.clone() : null);
...@@ -83,13 +84,15 @@ class ClientId { ...@@ -83,13 +84,15 @@ class ClientId {
if ((socketFactory != null) && if ((socketFactory != null) &&
!socketFactory.equals(LdapCtx.DEFAULT_SSL_FACTORY)) { !socketFactory.equals(LdapCtx.DEFAULT_SSL_FACTORY)) {
try { try {
Class<?> socketFactoryClass = Obj.helper.loadClass(socketFactory); Class<?> socketFactoryClass =
Obj.helper.loadClass(socketFactory);
Class<?> objClass = Class.forName("java.lang.Object"); Class<?> objClass = Class.forName("java.lang.Object");
this.sockComparator = socketFactoryClass.getMethod( this.sockComparator = socketFactoryClass.getMethod(
"compare", new Class<?>[]{objClass, objClass}); "compare", new Class<?>[]{objClass, objClass});
Method getDefault = Method getDefault = socketFactoryClass.getMethod(
socketFactoryClass.getMethod("getDefault", new Class<?>[]{}); "getDefault", new Class<?>[]{});
this.factory = (SocketFactory) getDefault.invoke(null, new Object[]{}); this.factory =
(SocketFactory)getDefault.invoke(null, new Object[]{});
} catch (Exception e) { } catch (Exception e) {
// Ignore it here, the same exceptions are/will be handled by // Ignore it here, the same exceptions are/will be handled by
// LdapPoolManager and Connection classes. // LdapPoolManager and Connection classes.
......
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
package com.sun.jndi.ldap; package com.sun.jndi.ldap;
import java.io.*; import java.io.*;
import java.util.Locale;
import java.util.Vector; import java.util.Vector;
import java.util.Hashtable; import java.util.Hashtable;
...@@ -738,14 +739,15 @@ public final class LdapClient implements PooledConnection { ...@@ -738,14 +739,15 @@ public final class LdapClient implements PooledConnection {
if (hasBinaryValues) { if (hasBinaryValues) {
la.add(ber.parseOctetString(ber.peekByte(), len)); la.add(ber.parseOctetString(ber.peekByte(), len));
} else { } else {
la.add(ber.parseStringWithTag(Ber.ASN_SIMPLE_STRING, isLdapv3, len)); la.add(ber.parseStringWithTag(
Ber.ASN_SIMPLE_STRING, isLdapv3, len));
} }
return len[0]; return len[0];
} }
private boolean isBinaryValued(String attrid, private boolean isBinaryValued(String attrid,
Hashtable<String, Boolean> binaryAttrs) { Hashtable<String, Boolean> binaryAttrs) {
String id = attrid.toLowerCase(); String id = attrid.toLowerCase(Locale.ENGLISH);
return ((id.indexOf(";binary") != -1) || return ((id.indexOf(";binary") != -1) ||
defaultBinaryAttrs.containsKey(id) || defaultBinaryAttrs.containsKey(id) ||
...@@ -753,8 +755,8 @@ public final class LdapClient implements PooledConnection { ...@@ -753,8 +755,8 @@ public final class LdapClient implements PooledConnection {
} }
// package entry point; used by Connection // package entry point; used by Connection
static void parseResult(BerDecoder replyBer, LdapResult res, boolean isLdapv3) static void parseResult(BerDecoder replyBer, LdapResult res,
throws IOException { boolean isLdapv3) throws IOException {
res.status = replyBer.parseEnumeration(); res.status = replyBer.parseEnumeration();
res.matchedDN = replyBer.parseString(isLdapv3); res.matchedDN = replyBer.parseString(isLdapv3);
......
...@@ -33,6 +33,7 @@ import javax.naming.ldap.*; ...@@ -33,6 +33,7 @@ import javax.naming.ldap.*;
import javax.naming.ldap.LdapName; import javax.naming.ldap.LdapName;
import javax.naming.ldap.Rdn; import javax.naming.ldap.Rdn;
import java.util.Locale;
import java.util.Vector; import java.util.Vector;
import java.util.Hashtable; import java.util.Hashtable;
import java.util.List; import java.util.List;
...@@ -2597,7 +2598,7 @@ final public class LdapCtx extends ComponentDirContext ...@@ -2597,7 +2598,7 @@ final public class LdapCtx extends ComponentDirContext
} else { } else {
binaryAttrs = new Hashtable<>(11, 0.75f); binaryAttrs = new Hashtable<>(11, 0.75f);
StringTokenizer tokens = StringTokenizer tokens =
new StringTokenizer(attrIds.toLowerCase(), " "); new StringTokenizer(attrIds.toLowerCase(Locale.ENGLISH), " ");
while (tokens.hasMoreTokens()) { while (tokens.hasMoreTokens()) {
binaryAttrs.put(tokens.nextToken(), Boolean.TRUE); binaryAttrs.put(tokens.nextToken(), Boolean.TRUE);
......
...@@ -28,6 +28,7 @@ package com.sun.jndi.ldap; ...@@ -28,6 +28,7 @@ package com.sun.jndi.ldap;
import java.util.Enumeration; import java.util.Enumeration;
import java.util.Vector; import java.util.Vector;
import java.util.Locale;
import javax.naming.*; import javax.naming.*;
import javax.naming.directory.Attributes; import javax.naming.directory.Attributes;
...@@ -707,7 +708,7 @@ public final class LdapName implements Name { ...@@ -707,7 +708,7 @@ public final class LdapName implements Name {
TypeAndValue that = (TypeAndValue)obj; TypeAndValue that = (TypeAndValue)obj;
int diff = type.toUpperCase().compareTo(that.type.toUpperCase()); int diff = type.compareToIgnoreCase(that.type);
if (diff != 0) { if (diff != 0) {
return diff; return diff;
} }
...@@ -730,7 +731,7 @@ public final class LdapName implements Name { ...@@ -730,7 +731,7 @@ public final class LdapName implements Name {
public int hashCode() { public int hashCode() {
// If two objects are equal, their hash codes must match. // If two objects are equal, their hash codes must match.
return (type.toUpperCase().hashCode() + return (type.toUpperCase(Locale.ENGLISH).hashCode() +
getValueComparable().hashCode()); getValueComparable().hashCode());
} }
...@@ -764,11 +765,12 @@ public final class LdapName implements Name { ...@@ -764,11 +765,12 @@ public final class LdapName implements Name {
// cache result // cache result
if (binary) { if (binary) {
comparable = value.toUpperCase(); comparable = value.toUpperCase(Locale.ENGLISH);
} else { } else {
comparable = (String)unescapeValue(value); comparable = (String)unescapeValue(value);
if (!valueCaseSensitive) { if (!valueCaseSensitive) {
comparable = comparable.toUpperCase(); // ignore case // ignore case
comparable = comparable.toUpperCase(Locale.ENGLISH);
} }
} }
return comparable; return comparable;
...@@ -836,7 +838,7 @@ public final class LdapName implements Name { ...@@ -836,7 +838,7 @@ public final class LdapName implements Name {
buf.append(Character.forDigit(0xF & b, 16)); buf.append(Character.forDigit(0xF & b, 16));
} }
return (new String(buf)).toUpperCase(); return (new String(buf)).toUpperCase(Locale.ENGLISH);
} }
/* /*
......
...@@ -28,6 +28,7 @@ package com.sun.jndi.ldap; ...@@ -28,6 +28,7 @@ package com.sun.jndi.ldap;
import java.io.PrintStream; import java.io.PrintStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.util.Hashtable; import java.util.Hashtable;
import java.util.Locale;
import java.util.StringTokenizer; import java.util.StringTokenizer;
import javax.naming.ldap.Control; import javax.naming.ldap.Control;
...@@ -133,7 +134,7 @@ public final class LdapPoolManager { ...@@ -133,7 +134,7 @@ public final class LdapPoolManager {
String mech; String mech;
int p; int p;
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {
mech = parser.nextToken().toLowerCase(); mech = parser.nextToken().toLowerCase(Locale.ENGLISH);
if (mech.equals("anonymous")) { if (mech.equals("anonymous")) {
mech = "none"; mech = "none";
} }
......
...@@ -910,7 +910,7 @@ final class HierarchicalName extends CompoundName { ...@@ -910,7 +910,7 @@ final class HierarchicalName extends CompoundName {
public int hashCode() { public int hashCode() {
if (hashValue == -1) { if (hashValue == -1) {
String name = toString().toUpperCase(); String name = toString().toUpperCase(Locale.ENGLISH);
int len = name.length(); int len = name.length();
int off = 0; int off = 0;
char val[] = new char[len]; char val[] = new char[len];
......
...@@ -29,6 +29,7 @@ import javax.naming.directory.*; ...@@ -29,6 +29,7 @@ import javax.naming.directory.*;
import java.util.Enumeration; import java.util.Enumeration;
import java.util.StringTokenizer; import java.util.StringTokenizer;
import java.util.Vector; import java.util.Vector;
import java.util.Locale;
/** /**
* A class for parsing LDAP search filters (defined in RFC 1960, 2254) * A class for parsing LDAP search filters (defined in RFC 1960, 2254)
...@@ -395,19 +396,21 @@ public class SearchFilter implements AttrFilter { ...@@ -395,19 +396,21 @@ public class SearchFilter implements AttrFilter {
// do we need to begin with the first token? // do we need to begin with the first token?
if(proto.charAt(0) != WILDCARD_TOKEN && if(proto.charAt(0) != WILDCARD_TOKEN &&
!value.toString().toLowerCase().startsWith( !value.toString().toLowerCase(Locale.ENGLISH).startsWith(
subStrs.nextToken().toLowerCase())) { subStrs.nextToken().toLowerCase(Locale.ENGLISH))) {
if(debug) {System.out.println("faild initial test");} if(debug) {
System.out.println("faild initial test");
}
return false; return false;
} }
while(subStrs.hasMoreTokens()) { while(subStrs.hasMoreTokens()) {
String currentStr = subStrs.nextToken(); String currentStr = subStrs.nextToken();
if (debug) {System.out.println("looking for \"" + if (debug) {System.out.println("looking for \"" +
currentStr +"\"");} currentStr +"\"");}
currentPos = value.toLowerCase().indexOf( currentPos = value.toLowerCase(Locale.ENGLISH).indexOf(
currentStr.toLowerCase(), currentPos); currentStr.toLowerCase(Locale.ENGLISH), currentPos);
if(currentPos == -1) { if(currentPos == -1) {
return false; return false;
} }
......
...@@ -33,6 +33,7 @@ import java.security.MessageDigest; ...@@ -33,6 +33,7 @@ import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException; import java.security.NoSuchAlgorithmException;
import java.security.spec.InvalidKeySpecException; import java.security.spec.InvalidKeySpecException;
import java.util.Arrays; import java.util.Arrays;
import java.util.Locale;
import javax.crypto.BadPaddingException; import javax.crypto.BadPaddingException;
import javax.crypto.Cipher; import javax.crypto.Cipher;
import javax.crypto.IllegalBlockSizeException; import javax.crypto.IllegalBlockSizeException;
...@@ -410,7 +411,8 @@ class NTLM { ...@@ -410,7 +411,8 @@ class NTLM {
static byte[] getP1(char[] password) { static byte[] getP1(char[] password) {
try { try {
return new String(password).toUpperCase().getBytes("ISO8859_1"); return new String(password).toUpperCase(
Locale.ENGLISH).getBytes("ISO8859_1");
} catch (UnsupportedEncodingException ex) { } catch (UnsupportedEncodingException ex) {
return null; return null;
} }
......
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
package java.security; package java.security;
import java.io.*; import java.io.*;
import java.util.Locale;
import java.security.spec.PKCS8EncodedKeySpec; import java.security.spec.PKCS8EncodedKeySpec;
import java.security.spec.X509EncodedKeySpec; import java.security.spec.X509EncodedKeySpec;
...@@ -137,7 +138,7 @@ public class KeyRep implements Serializable { ...@@ -137,7 +138,7 @@ public class KeyRep implements Serializable {
this.type = type; this.type = type;
this.algorithm = algorithm; this.algorithm = algorithm;
this.format = format.toUpperCase(); this.format = format.toUpperCase(Locale.ENGLISH);
this.encoded = encoded.clone(); this.encoded = encoded.clone();
} }
......
...@@ -1087,8 +1087,10 @@ public final class Security { ...@@ -1087,8 +1087,10 @@ public final class Security {
// Check the keys for each provider. // Check the keys for each provider.
for (Enumeration<Object> e = providers[i].keys(); for (Enumeration<Object> e = providers[i].keys();
e.hasMoreElements(); ) { e.hasMoreElements(); ) {
String currentKey = ((String)e.nextElement()).toUpperCase(); String currentKey =
if (currentKey.startsWith(serviceName.toUpperCase())) { ((String)e.nextElement()).toUpperCase(Locale.ENGLISH);
if (currentKey.startsWith(
serviceName.toUpperCase(Locale.ENGLISH))) {
// We should skip the currentKey if it contains a // We should skip the currentKey if it contains a
// whitespace. The reason is: such an entry in the // whitespace. The reason is: such an entry in the
// provider property contains attributes for the // provider property contains attributes for the
...@@ -1096,7 +1098,8 @@ public final class Security { ...@@ -1096,7 +1098,8 @@ public final class Security {
// in entries which lead to the implementation // in entries which lead to the implementation
// classes. // classes.
if (currentKey.indexOf(" ") < 0) { if (currentKey.indexOf(" ") < 0) {
result.add(currentKey.substring(serviceName.length() + 1)); result.add(currentKey.substring(
serviceName.length() + 1));
} }
} }
} }
......
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
package javax.naming; package javax.naming;
import java.util.Locale;
import java.util.Vector; import java.util.Vector;
import java.util.Enumeration; import java.util.Enumeration;
import java.util.Properties; import java.util.Properties;
...@@ -216,7 +217,8 @@ class NameImpl { ...@@ -216,7 +217,8 @@ class NameImpl {
} }
private static boolean toBoolean(String name) { private static boolean toBoolean(String name) {
return ((name != null) && name.toLowerCase().equals("true")); return ((name != null) &&
name.toLowerCase(Locale.ENGLISH).equals("true"));
} }
private final void recordNamingConvention(Properties p) { private final void recordNamingConvention(Properties p) {
...@@ -526,11 +528,14 @@ class NameImpl { ...@@ -526,11 +528,14 @@ class NameImpl {
comp1 = comp1.trim(); comp1 = comp1.trim();
comp2 = comp2.trim(); comp2 = comp2.trim();
} }
int local;
if (syntaxCaseInsensitive) { if (syntaxCaseInsensitive) {
comp1 = comp1.toLowerCase(); local = comp1.compareToIgnoreCase(comp2);
comp2 = comp2.toLowerCase(); } else {
local = comp1.compareTo(comp2);
} }
int local = comp1.compareTo(comp2);
if (local != 0) { if (local != 0) {
return local; return local;
} }
...@@ -696,7 +701,7 @@ class NameImpl { ...@@ -696,7 +701,7 @@ class NameImpl {
comp = comp.trim(); comp = comp.trim();
} }
if (syntaxCaseInsensitive) { if (syntaxCaseInsensitive) {
comp = comp.toLowerCase(); comp = comp.toLowerCase(Locale.ENGLISH);
} }
hash += comp.hashCode(); hash += comp.hashCode();
......
...@@ -28,6 +28,7 @@ package javax.naming.directory; ...@@ -28,6 +28,7 @@ package javax.naming.directory;
import java.util.Hashtable; import java.util.Hashtable;
import java.util.Enumeration; import java.util.Enumeration;
import java.util.Locale;
import javax.naming.NamingException; import javax.naming.NamingException;
import javax.naming.NamingEnumeration; import javax.naming.NamingEnumeration;
...@@ -160,7 +161,7 @@ public class BasicAttributes implements Attributes { ...@@ -160,7 +161,7 @@ public class BasicAttributes implements Attributes {
public Attribute get(String attrID) { public Attribute get(String attrID) {
Attribute attr = attrs.get( Attribute attr = attrs.get(
ignoreCase ? attrID.toLowerCase() : attrID); ignoreCase ? attrID.toLowerCase(Locale.ENGLISH) : attrID);
return (attr); return (attr);
} }
...@@ -179,13 +180,13 @@ public class BasicAttributes implements Attributes { ...@@ -179,13 +180,13 @@ public class BasicAttributes implements Attributes {
public Attribute put(Attribute attr) { public Attribute put(Attribute attr) {
String id = attr.getID(); String id = attr.getID();
if (ignoreCase) { if (ignoreCase) {
id = id.toLowerCase(); id = id.toLowerCase(Locale.ENGLISH);
} }
return attrs.put(id, attr); return attrs.put(id, attr);
} }
public Attribute remove(String attrID) { public Attribute remove(String attrID) {
String id = (ignoreCase ? attrID.toLowerCase() : attrID); String id = (ignoreCase ? attrID.toLowerCase(Locale.ENGLISH) : attrID);
return attrs.remove(id); return attrs.remove(id);
} }
......
...@@ -28,6 +28,7 @@ package javax.naming.ldap; ...@@ -28,6 +28,7 @@ package javax.naming.ldap;
import java.util.Iterator; import java.util.Iterator;
import java.util.NoSuchElementException; import java.util.NoSuchElementException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Locale;
import java.util.Collections; import java.util.Collections;
import javax.naming.InvalidNameException; import javax.naming.InvalidNameException;
...@@ -434,8 +435,7 @@ public class Rdn implements Serializable, Comparable<Object> { ...@@ -434,8 +435,7 @@ public class Rdn implements Serializable, Comparable<Object> {
} }
public int compareTo(RdnEntry that) { public int compareTo(RdnEntry that) {
int diff = type.toUpperCase().compareTo( int diff = type.compareToIgnoreCase(that.type);
that.type.toUpperCase());
if (diff != 0) { if (diff != 0) {
return diff; return diff;
} }
...@@ -462,7 +462,7 @@ public class Rdn implements Serializable, Comparable<Object> { ...@@ -462,7 +462,7 @@ public class Rdn implements Serializable, Comparable<Object> {
} }
public int hashCode() { public int hashCode() {
return (type.toUpperCase().hashCode() + return (type.toUpperCase(Locale.ENGLISH).hashCode() +
getValueComparable().hashCode()); getValueComparable().hashCode());
} }
...@@ -479,7 +479,7 @@ public class Rdn implements Serializable, Comparable<Object> { ...@@ -479,7 +479,7 @@ public class Rdn implements Serializable, Comparable<Object> {
if (value instanceof byte[]) { if (value instanceof byte[]) {
comparable = escapeBinaryValue((byte[]) value); comparable = escapeBinaryValue((byte[]) value);
} else { } else {
comparable = ((String) value).toUpperCase(); comparable = ((String) value).toUpperCase(Locale.ENGLISH);
} }
return comparable; return comparable;
} }
...@@ -569,7 +569,6 @@ public class Rdn implements Serializable, Comparable<Object> { ...@@ -569,7 +569,6 @@ public class Rdn implements Serializable, Comparable<Object> {
builder.append(Character.forDigit(0xF & b, 16)); builder.append(Character.forDigit(0xF & b, 16));
} }
return builder.toString(); return builder.toString();
// return builder.toString().toUpperCase();
} }
/** /**
......
...@@ -35,6 +35,7 @@ import java.io.UnsupportedEncodingException; ...@@ -35,6 +35,7 @@ import java.io.UnsupportedEncodingException;
import java.net.InetAddress; import java.net.InetAddress;
import java.net.UnknownHostException; import java.net.UnknownHostException;
import java.security.Provider; import java.security.Provider;
import java.util.Locale;
/** /**
* Implements the GSSNameSpi for the krb5 mechanism. * Implements the GSSNameSpi for the krb5 mechanism.
...@@ -184,7 +185,7 @@ public class Krb5NameElement ...@@ -184,7 +185,7 @@ public class Krb5NameElement
} catch (UnknownHostException e) { } catch (UnknownHostException e) {
// use hostname as it is // use hostname as it is
} }
hostName = hostName.toLowerCase(); hostName = hostName.toLowerCase(Locale.ENGLISH);
temp = temp.append('/').append(hostName); temp = temp.append('/').append(hostName);
return temp.toString(); return temp.toString();
......
...@@ -35,6 +35,7 @@ import sun.security.krb5.internal.*; ...@@ -35,6 +35,7 @@ import sun.security.krb5.internal.*;
import sun.security.util.*; import sun.security.util.*;
import java.net.*; import java.net.*;
import java.util.Vector; import java.util.Vector;
import java.util.Locale;
import java.io.IOException; import java.io.IOException;
import java.math.BigInteger; import java.math.BigInteger;
import sun.security.krb5.internal.ccache.CCacheOutputStream; import sun.security.krb5.internal.ccache.CCacheOutputStream;
...@@ -389,14 +390,14 @@ public class PrincipalName ...@@ -389,14 +390,14 @@ public class PrincipalName
// Looks if canonicalized is a longer format of hostName, // Looks if canonicalized is a longer format of hostName,
// we accept cases like // we accept cases like
// bunny -> bunny.rabbit.hole // bunny -> bunny.rabbit.hole
if (canonicalized.toLowerCase() if (canonicalized.toLowerCase(Locale.ENGLISH).startsWith(
.startsWith(hostName.toLowerCase()+".")) { hostName.toLowerCase(Locale.ENGLISH)+".")) {
hostName = canonicalized; hostName = canonicalized;
} }
} catch (UnknownHostException e) { } catch (UnknownHostException e) {
// no canonicalization, use old // no canonicalization, use old
} }
nameParts[1] = hostName.toLowerCase(); nameParts[1] = hostName.toLowerCase(Locale.ENGLISH);
} }
nameStrings = nameParts; nameStrings = nameParts;
nameType = type; nameType = type;
......
...@@ -219,7 +219,7 @@ public final class PKCS12KeyStore extends KeyStoreSpi { ...@@ -219,7 +219,7 @@ public final class PKCS12KeyStore extends KeyStoreSpi {
public Key engineGetKey(String alias, char[] password) public Key engineGetKey(String alias, char[] password)
throws NoSuchAlgorithmException, UnrecoverableKeyException throws NoSuchAlgorithmException, UnrecoverableKeyException
{ {
KeyEntry entry = entries.get(alias.toLowerCase()); KeyEntry entry = entries.get(alias.toLowerCase(Locale.ENGLISH));
Key key = null; Key key = null;
if (entry == null) { if (entry == null) {
...@@ -296,7 +296,7 @@ public final class PKCS12KeyStore extends KeyStoreSpi { ...@@ -296,7 +296,7 @@ public final class PKCS12KeyStore extends KeyStoreSpi {
* <i>key entry</i> without a certificate chain). * <i>key entry</i> without a certificate chain).
*/ */
public Certificate[] engineGetCertificateChain(String alias) { public Certificate[] engineGetCertificateChain(String alias) {
KeyEntry entry = entries.get(alias.toLowerCase()); KeyEntry entry = entries.get(alias.toLowerCase(Locale.ENGLISH));
if (entry != null) { if (entry != null) {
if (entry.chain == null) { if (entry.chain == null) {
return null; return null;
...@@ -324,7 +324,7 @@ public final class PKCS12KeyStore extends KeyStoreSpi { ...@@ -324,7 +324,7 @@ public final class PKCS12KeyStore extends KeyStoreSpi {
* does not contain a certificate. * does not contain a certificate.
*/ */
public Certificate engineGetCertificate(String alias) { public Certificate engineGetCertificate(String alias) {
KeyEntry entry = entries.get(alias.toLowerCase()); KeyEntry entry = entries.get(alias.toLowerCase(Locale.ENGLISH));
if (entry != null) { if (entry != null) {
if (entry.chain == null) { if (entry.chain == null) {
return null; return null;
...@@ -345,7 +345,7 @@ public final class PKCS12KeyStore extends KeyStoreSpi { ...@@ -345,7 +345,7 @@ public final class PKCS12KeyStore extends KeyStoreSpi {
* not exist * not exist
*/ */
public Date engineGetCreationDate(String alias) { public Date engineGetCreationDate(String alias) {
KeyEntry entry = entries.get(alias.toLowerCase()); KeyEntry entry = entries.get(alias.toLowerCase(Locale.ENGLISH));
if (entry != null) { if (entry != null) {
return new Date(entry.date.getTime()); return new Date(entry.date.getTime());
} else { } else {
...@@ -409,10 +409,10 @@ public final class PKCS12KeyStore extends KeyStoreSpi { ...@@ -409,10 +409,10 @@ public final class PKCS12KeyStore extends KeyStoreSpi {
// set the keyId to current date // set the keyId to current date
entry.keyId = ("Time " + (entry.date).getTime()).getBytes("UTF8"); entry.keyId = ("Time " + (entry.date).getTime()).getBytes("UTF8");
// set the alias // set the alias
entry.alias = alias.toLowerCase(); entry.alias = alias.toLowerCase(Locale.ENGLISH);
// add the entry // add the entry
entries.put(alias.toLowerCase(), entry); entries.put(alias.toLowerCase(Locale.ENGLISH), entry);
} catch (Exception nsae) { } catch (Exception nsae) {
throw new KeyStoreException("Key protection " + throw new KeyStoreException("Key protection " +
" algorithm not found: " + nsae, nsae); " algorithm not found: " + nsae, nsae);
...@@ -465,7 +465,7 @@ public final class PKCS12KeyStore extends KeyStoreSpi { ...@@ -465,7 +465,7 @@ public final class PKCS12KeyStore extends KeyStoreSpi {
// Won't happen // Won't happen
} }
// set the alias // set the alias
entry.alias = alias.toLowerCase(); entry.alias = alias.toLowerCase(Locale.ENGLISH);
entry.protectedPrivKey = key.clone(); entry.protectedPrivKey = key.clone();
if (chain != null) { if (chain != null) {
...@@ -473,7 +473,7 @@ public final class PKCS12KeyStore extends KeyStoreSpi { ...@@ -473,7 +473,7 @@ public final class PKCS12KeyStore extends KeyStoreSpi {
} }
// add the entry // add the entry
entries.put(alias.toLowerCase(), entry); entries.put(alias.toLowerCase(Locale.ENGLISH), entry);
} }
...@@ -618,7 +618,7 @@ public final class PKCS12KeyStore extends KeyStoreSpi { ...@@ -618,7 +618,7 @@ public final class PKCS12KeyStore extends KeyStoreSpi {
public synchronized void engineSetCertificateEntry(String alias, public synchronized void engineSetCertificateEntry(String alias,
Certificate cert) throws KeyStoreException Certificate cert) throws KeyStoreException
{ {
KeyEntry entry = entries.get(alias.toLowerCase()); KeyEntry entry = entries.get(alias.toLowerCase(Locale.ENGLISH));
if (entry != null) { if (entry != null) {
throw new KeyStoreException("Cannot overwrite own certificate"); throw new KeyStoreException("Cannot overwrite own certificate");
} else } else
...@@ -635,7 +635,7 @@ public final class PKCS12KeyStore extends KeyStoreSpi { ...@@ -635,7 +635,7 @@ public final class PKCS12KeyStore extends KeyStoreSpi {
public synchronized void engineDeleteEntry(String alias) public synchronized void engineDeleteEntry(String alias)
throws KeyStoreException throws KeyStoreException
{ {
entries.remove(alias.toLowerCase()); entries.remove(alias.toLowerCase(Locale.ENGLISH));
} }
/** /**
...@@ -655,7 +655,7 @@ public final class PKCS12KeyStore extends KeyStoreSpi { ...@@ -655,7 +655,7 @@ public final class PKCS12KeyStore 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));
} }
/** /**
...@@ -675,7 +675,7 @@ public final class PKCS12KeyStore extends KeyStoreSpi { ...@@ -675,7 +675,7 @@ public final class PKCS12KeyStore extends KeyStoreSpi {
* <i>key entry</i>, false otherwise. * <i>key entry</i>, false otherwise.
*/ */
public boolean engineIsKeyEntry(String alias) { public boolean engineIsKeyEntry(String alias) {
KeyEntry entry = entries.get(alias.toLowerCase()); KeyEntry entry = entries.get(alias.toLowerCase(Locale.ENGLISH));
if (entry != null) { if (entry != null) {
return true; return true;
} else { } else {
...@@ -1274,7 +1274,8 @@ public final class PKCS12KeyStore extends KeyStoreSpi { ...@@ -1274,7 +1274,8 @@ public final class PKCS12KeyStore extends KeyStoreSpi {
if (password != null && s.available() > 0) { if (password != null && s.available() > 0) {
MacData macData = new MacData(s); MacData macData = new MacData(s);
try { try {
String algName = macData.getDigestAlgName().toUpperCase(); String algName =
macData.getDigestAlgName().toUpperCase(Locale.ENGLISH);
if (algName.equals("SHA") || if (algName.equals("SHA") ||
algName.equals("SHA1") || algName.equals("SHA1") ||
algName.equals("SHA-1")) { algName.equals("SHA-1")) {
...@@ -1479,7 +1480,7 @@ public final class PKCS12KeyStore extends KeyStoreSpi { ...@@ -1479,7 +1480,7 @@ public final class PKCS12KeyStore extends KeyStoreSpi {
if (alias == null) if (alias == null)
alias = getUnfriendlyName(); alias = getUnfriendlyName();
entry.alias = alias; entry.alias = alias;
entries.put(alias.toLowerCase(), entry); entries.put(alias.toLowerCase(Locale.ENGLISH), entry);
} else if (bagItem instanceof X509Certificate) { } else if (bagItem instanceof X509Certificate) {
X509Certificate cert = (X509Certificate)bagItem; X509Certificate cert = (X509Certificate)bagItem;
// Insert a localKeyID for the corresponding cert // Insert a localKeyID for the corresponding cert
......
...@@ -54,7 +54,7 @@ abstract class JavaKeyStore extends KeyStoreSpi { ...@@ -54,7 +54,7 @@ abstract class JavaKeyStore extends KeyStoreSpi {
// regular JKS // regular JKS
public static final class JKS extends JavaKeyStore { public static final class JKS extends JavaKeyStore {
String convertAlias(String alias) { String convertAlias(String alias) {
return alias.toLowerCase(); return alias.toLowerCase(Locale.ENGLISH);
} }
} }
......
...@@ -879,7 +879,8 @@ public class LDAPCertStore extends CertStoreSpi { ...@@ -879,7 +879,8 @@ public class LDAPCertStore extends CertStoreSpi {
if (hashCode == 0) { if (hashCode == 0) {
int result = 17; int result = 17;
result = 37*result + getPort(); result = 37*result + getPort();
result = 37*result + getServerName().toLowerCase().hashCode(); result = 37*result +
getServerName().toLowerCase(Locale.ENGLISH).hashCode();
hashCode = result; hashCode = result;
} }
return hashCode; return hashCode;
......
...@@ -33,6 +33,7 @@ import java.util.Enumeration; ...@@ -33,6 +33,7 @@ import java.util.Enumeration;
import java.util.Hashtable; import java.util.Hashtable;
import java.util.NoSuchElementException; import java.util.NoSuchElementException;
import java.util.Vector; import java.util.Vector;
import java.util.Locale;
import javax.net.ssl.SSLSession; import javax.net.ssl.SSLSession;
import javax.net.ssl.SSLSessionContext; import javax.net.ssl.SSLSessionContext;
...@@ -166,7 +167,8 @@ final class SSLSessionContextImpl implements SSLSessionContext { ...@@ -166,7 +167,8 @@ final class SSLSessionContextImpl implements SSLSessionContext {
} }
private String getKey(String hostname, int port) { private String getKey(String hostname, int port) {
return (hostname + ":" + String.valueOf(port)).toLowerCase(); return (hostname + ":" +
String.valueOf(port)).toLowerCase(Locale.ENGLISH);
} }
// cache a SSLSession // cache a SSLSession
......
...@@ -25,6 +25,8 @@ ...@@ -25,6 +25,8 @@
package sun.security.tools; package sun.security.tools;
import java.util.Locale;
/** /**
* <p> This class provides several utilities to <code>KeyStore</code>. * <p> This class provides several utilities to <code>KeyStore</code>.
* *
...@@ -63,7 +65,7 @@ public class KeyStoreUtil { ...@@ -63,7 +65,7 @@ public class KeyStoreUtil {
} else if(storetype.equalsIgnoreCase("Windows-ROOT")) { } else if(storetype.equalsIgnoreCase("Windows-ROOT")) {
return "Windows-ROOT"; return "Windows-ROOT";
} else { } else {
return storetype.toUpperCase(); return storetype.toUpperCase(Locale.ENGLISH);
} }
} }
} }
...@@ -266,8 +266,8 @@ public class HostnameChecker { ...@@ -266,8 +266,8 @@ public class HostnameChecker {
*/ */
private static boolean matchAllWildcards(String name, private static boolean matchAllWildcards(String name,
String template) { String template) {
name = name.toLowerCase(); name = name.toLowerCase(Locale.ENGLISH);
template = template.toLowerCase(); template = template.toLowerCase(Locale.ENGLISH);
StringTokenizer nameSt = new StringTokenizer(name, "."); StringTokenizer nameSt = new StringTokenizer(name, ".");
StringTokenizer templateSt = new StringTokenizer(template, "."); StringTokenizer templateSt = new StringTokenizer(template, ".");
...@@ -296,8 +296,8 @@ public class HostnameChecker { ...@@ -296,8 +296,8 @@ public class HostnameChecker {
*/ */
private static boolean matchLeftmostWildcard(String name, private static boolean matchLeftmostWildcard(String name,
String template) { String template) {
name = name.toLowerCase(); name = name.toLowerCase(Locale.ENGLISH);
template = template.toLowerCase(); template = template.toLowerCase(Locale.ENGLISH);
// Retreive leftmost component // Retreive leftmost component
int templateIdx = template.indexOf("."); int templateIdx = template.indexOf(".");
......
...@@ -159,7 +159,7 @@ public class DNSName implements GeneralNameInterface { ...@@ -159,7 +159,7 @@ public class DNSName implements GeneralNameInterface {
* @return a hash code value for this object. * @return a hash code value for this object.
*/ */
public int hashCode() { public int hashCode() {
return name.toUpperCase().hashCode(); return name.toUpperCase(Locale.ENGLISH).hashCode();
} }
/** /**
......
...@@ -153,7 +153,7 @@ public class RFC822Name implements GeneralNameInterface ...@@ -153,7 +153,7 @@ public class RFC822Name implements GeneralNameInterface
* @return a hash code value for this object. * @return a hash code value for this object.
*/ */
public int hashCode() { public int hashCode() {
return name.toUpperCase().hashCode(); return name.toUpperCase(Locale.ENGLISH).hashCode();
} }
/** /**
......
/* /*
* Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2003, 2011, 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
...@@ -23,12 +23,14 @@ ...@@ -23,12 +23,14 @@
/* /*
* @test * @test
* @bug 4635618 * @bug 4635618 7059542
* @summary Support for manipulating LDAP Names * @summary Support for manipulating LDAP Names
* JNDI name operations should be locale independent
*/ */
import javax.naming.ldap.*; import javax.naming.ldap.*;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Locale;
import java.util.List; import java.util.List;
import javax.naming.InvalidNameException; import javax.naming.InvalidNameException;
...@@ -39,52 +41,61 @@ public class CompareToEqualsTests { ...@@ -39,52 +41,61 @@ public class CompareToEqualsTests {
public static void main(String args[]) public static void main(String args[])
throws Exception { throws Exception {
Locale reservedLocale = Locale.getDefault();
/** try {
* Test cases: /**
* 1) Same RDNs. * Test cases:
* 2) same RDN sequence with an AVA ordered differently. * 1) Same RDNs.
* 3) RDN sequences of a differing AVA. * 2) same RDN sequence with an AVA ordered differently.
* 4) RDN sequence of different length. * 3) RDN sequences of a differing AVA.
* 5) RDN sequence of different Case. * 4) RDN sequence of different length.
* 6) Matching binary return values. * 5) RDN sequence of different Case.
* 7) Binary values that don't match. * 6) Matching binary return values.
*/ * 7) Binary values that don't match.
String names1[] = new String [] { */
String names1[] = new String [] {
"ou=Sales+cn=Bob", "ou=Sales+cn=Bob", "ou=Sales+cn=Bob", "ou=Sales+cn=Bob", "ou=Sales+cn=Bob", "ou=Sales+cn=Bob",
"ou=Sales+cn=Scott+c=US", "cn=config"}; "ou=Sales+cn=Scott+c=US", "cn=config"};
String names2[] = new String [] { String names2[] = new String [] {
"ou=Sales+cn=Bob", "cn=Bob+ou=Sales", "ou=Sales+cn=Scott", "ou=Sales+cn=Bob", "cn=Bob+ou=Sales", "ou=Sales+cn=Scott",
"ou=Sales+cn=Scott", "Cn=COnFIG"}; "ou=Sales+cn=Scott", "Cn=COnFIG"};
int expectedResults[] = {0, 0, -1, -1, 0}; int expectedResults[] = {0, 0, -1, -1, 0};
for (Locale locale : Locale.getAvailableLocales()) {
// reset the default locale
Locale.setDefault(locale);
for (int i = 0; i < names1.length; i++) { for (int i = 0; i < names1.length; i++) {
checkResults(new LdapName(names1[i]), checkResults(new LdapName(names1[i]),
new LdapName(names2[i]), expectedResults[i]); new LdapName(names2[i]), expectedResults[i]);
}
byte[] value = "abcxyz".getBytes();
Rdn rdn1 = new Rdn("binary", value);
ArrayList rdns1 = new ArrayList();
rdns1.add(rdn1);
LdapName l1 = new LdapName(rdns1);
Rdn rdn2 = new Rdn("binary", value);
ArrayList rdns2 = new ArrayList();
rdns2.add(rdn2);
LdapName l2 = new LdapName(rdns2);
checkResults(l1, l2, 0);
l2 = new LdapName("binary=#61626378797A");
checkResults(l1, l2, 0);
l2 = new LdapName("binary=#61626378797B");
checkResults(l1, l2, -1);
System.out.println("Tests passed");
}
} finally {
// restore the reserved locale
Locale.setDefault(reservedLocale);
} }
byte[] value = "abcxyz".getBytes();
Rdn rdn1 = new Rdn("binary", value);
ArrayList rdns1 = new ArrayList();
rdns1.add(rdn1);
LdapName l1 = new LdapName(rdns1);
Rdn rdn2 = new Rdn("binary", value);
ArrayList rdns2 = new ArrayList();
rdns2.add(rdn2);
LdapName l2 = new LdapName(rdns2);
checkResults(l1, l2, 0);
l2 = new LdapName("binary=#61626378797A");
checkResults(l1, l2, 0);
l2 = new LdapName("binary=#61626378797B");
checkResults(l1, l2, -1);
System.out.println("Tests passed");
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册