8233884: Avoid looking up standard charsets in security libraries

Reviewed-by: coffeys
This commit is contained in:
Ivan Gerasimov 2019-11-12 01:36:17 -08:00
parent 301e068935
commit 8e859259bc
48 changed files with 317 additions and 391 deletions

View file

@ -45,6 +45,8 @@ import java.security.cert.CertificateFactory;
import java.security.cert.CertificateException;
import javax.crypto.SealedObject;
import static java.nio.charset.StandardCharsets.UTF_8;
/**
* This class provides the keystore implementation referred to as "jceks".
* This implementation strongly protects the keystore private keys using
@ -909,7 +911,8 @@ public final class JceKeyStore extends KeyStoreSpi {
* hash with a bit of whitener.
*/
private MessageDigest getPreKeyedHash(char[] password)
throws NoSuchAlgorithmException, UnsupportedEncodingException {
throws NoSuchAlgorithmException
{
int i, j;
MessageDigest md = MessageDigest.getInstance("SHA");
@ -921,7 +924,7 @@ public final class JceKeyStore extends KeyStoreSpi {
md.update(passwdBytes);
for (i=0; i<passwdBytes.length; i++)
passwdBytes[i] = 0;
md.update("Mighty Aphrodite".getBytes("UTF8"));
md.update("Mighty Aphrodite".getBytes(UTF_8));
return md;
}

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2019, 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
@ -25,7 +25,6 @@
package com.sun.crypto.provider;
import java.io.UnsupportedEncodingException;
import java.security.*;
import java.security.spec.*;
import javax.crypto.*;

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2019, 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
@ -25,7 +25,6 @@
package com.sun.crypto.provider;
import java.io.UnsupportedEncodingException;
import java.security.*;
import java.security.spec.*;
import javax.crypto.*;

View file

@ -29,7 +29,6 @@ import java.io.ObjectStreamException;
import java.lang.ref.Reference;
import java.nio.ByteBuffer;
import java.nio.CharBuffer;
import java.nio.charset.Charset;
import java.util.Arrays;
import java.util.Locale;
import java.security.MessageDigest;
@ -41,6 +40,8 @@ import javax.crypto.Mac;
import javax.crypto.SecretKey;
import javax.crypto.spec.PBEKeySpec;
import static java.nio.charset.StandardCharsets.UTF_8;
import jdk.internal.ref.CleanerFactory;
/**
@ -66,9 +67,8 @@ final class PBKDF2KeyImpl implements javax.crypto.interfaces.PBEKey {
private Mac prf;
private static byte[] getPasswordBytes(char[] passwd) {
Charset utf8 = Charset.forName("UTF-8");
CharBuffer cb = CharBuffer.wrap(passwd);
ByteBuffer bb = utf8.encode(cb);
ByteBuffer bb = UTF_8.encode(cb);
int len = bb.limit();
byte[] passwdBytes = new byte[len];

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2005, 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2005, 2019, 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,8 @@ import java.util.Arrays;
import java.security.*;
import java.security.spec.AlgorithmParameterSpec;
import static java.nio.charset.StandardCharsets.UTF_8;
import javax.crypto.*;
import javax.crypto.spec.SecretKeySpec;
@ -153,7 +155,7 @@ abstract class TlsPrfGenerator extends KeyGeneratorSpi {
SecretKey key = spec.getSecret();
byte[] secret = (key == null) ? null : key.getEncoded();
try {
byte[] labelBytes = spec.getLabel().getBytes("UTF8");
byte[] labelBytes = spec.getLabel().getBytes(UTF_8);
int n = spec.getOutputLength();
byte[] prfBytes = (tls12 ?
doTLS12PRF(secret, labelBytes, spec.getSeed(), n,
@ -163,8 +165,6 @@ abstract class TlsPrfGenerator extends KeyGeneratorSpi {
return new SecretKeySpec(prfBytes, "TlsPrf");
} catch (GeneralSecurityException e) {
throw new ProviderException("Could not generate PRF", e);
} catch (java.io.UnsupportedEncodingException e) {
throw new ProviderException("Could not generate PRF", e);
}
}

View file

@ -40,6 +40,8 @@ import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.IOException;
import static java.nio.charset.StandardCharsets.UTF_8;
/**
* This class contains CryptoPermission objects, organized into
* PermissionCollections according to algorithm names.
@ -99,7 +101,7 @@ implements Serializable {
void load(InputStream in)
throws IOException, CryptoPolicyParser.ParsingException {
CryptoPolicyParser parser = new CryptoPolicyParser();
parser.read(new BufferedReader(new InputStreamReader(in, "UTF-8")));
parser.read(new BufferedReader(new InputStreamReader(in, UTF_8)));
CryptoPermission[] parsingResult = parser.getPermissions();
for (int i = 0; i < parsingResult.length; i++) {

View file

@ -51,6 +51,8 @@ import java.security.spec.KeySpec;
import java.security.spec.PKCS8EncodedKeySpec;
import java.util.*;
import static java.nio.charset.StandardCharsets.UTF_8;
import java.security.AlgorithmParameters;
import java.security.InvalidAlgorithmParameterException;
import javax.crypto.spec.PBEParameterSpec;
@ -687,12 +689,14 @@ public final class PKCS12KeyStore extends KeyStoreSpi {
entry.attributes.addAll(attributes);
}
// set the keyId to current date
entry.keyId = ("Time " + (entry.date).getTime()).getBytes("UTF8");
entry.keyId = ("Time " + (entry.date).getTime()).getBytes(UTF_8);
// set the alias
entry.alias = alias.toLowerCase(Locale.ENGLISH);
// add the entry
entries.put(alias.toLowerCase(Locale.ENGLISH), entry);
} catch (KeyStoreException kse) {
throw kse;
} catch (Exception nsae) {
throw new KeyStoreException("Key protection" +
" algorithm not found: " + nsae, nsae);
@ -746,12 +750,8 @@ public final class PKCS12KeyStore extends KeyStoreSpi {
alias + "'");
}
try {
// set the keyId to current date
entry.keyId = ("Time " + (entry.date).getTime()).getBytes("UTF8");
} catch (UnsupportedEncodingException ex) {
// Won't happen
}
// set the keyId to current date
entry.keyId = ("Time " + (entry.date).getTime()).getBytes(UTF_8);
// set the alias
entry.alias = alias.toLowerCase(Locale.ENGLISH);
@ -2499,18 +2499,18 @@ public final class PKCS12KeyStore extends KeyStoreSpi {
// attribute in pkcs12 with one private key entry and
// associated cert-chain
if (privateKeyCount == 1) {
keyId = "01".getBytes("UTF8");
keyId = "01".getBytes(UTF_8);
} else {
continue;
}
} else {
// keyId in a SecretKeyEntry is not significant
keyId = "00".getBytes("UTF8");
keyId = "00".getBytes(UTF_8);
}
}
entry.keyId = keyId;
// restore date if it exists
String keyIdStr = new String(keyId, "UTF8");
String keyIdStr = new String(keyId, UTF_8);
Date date = null;
if (keyIdStr.startsWith("Time ")) {
try {
@ -2547,7 +2547,7 @@ public final class PKCS12KeyStore extends KeyStoreSpi {
if ((keyId == null) && (privateKeyCount == 1)) {
// insert localKeyID only for EE cert or self-signed cert
if (i == 0) {
keyId = "01".getBytes("UTF8");
keyId = "01".getBytes(UTF_8);
}
}
// Trusted certificate

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2000, 2019, 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
@ -46,6 +46,8 @@ import sun.security.util.Debug;
import sun.security.util.PropertyExpander;
import sun.security.util.ResourcesMgr;
import static java.nio.charset.StandardCharsets.UTF_8;
/**
* This class represents a default implementation for
* {@code javax.security.auth.login.Configuration}.
@ -325,7 +327,7 @@ public final class ConfigFile extends Configuration {
throws IOException {
try (InputStreamReader isr
= new InputStreamReader(getInputStream(config), "UTF-8")) {
= new InputStreamReader(getInputStream(config), UTF_8)) {
readConfig(isr, newConfig);
} catch (FileNotFoundException fnfe) {
if (debugConfig != null) {

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013, 2019, 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
@ -33,6 +33,8 @@ import java.security.cert.CertificateFactory;
import java.security.cert.CertificateException;
import java.util.*;
import static java.nio.charset.StandardCharsets.UTF_8;
import sun.security.pkcs.EncryptedPrivateKeyInfo;
import sun.security.util.PolicyUtil;
@ -768,7 +770,7 @@ abstract class DomainKeyStore extends KeyStoreSpi {
try (InputStreamReader configurationReader =
new InputStreamReader(
PolicyUtil.getInputStream(configuration.toURL()), "UTF-8")) {
PolicyUtil.getInputStream(configuration.toURL()), UTF_8)) {
parser.read(configurationReader);
domains = parser.getDomainEntries();

View file

@ -32,6 +32,8 @@ import java.security.cert.CertificateFactory;
import java.security.cert.CertificateException;
import java.util.*;
import static java.nio.charset.StandardCharsets.UTF_8;
import sun.security.pkcs.EncryptedPrivateKeyInfo;
import sun.security.pkcs12.PKCS12KeyStore;
import sun.security.util.Debug;
@ -805,14 +807,14 @@ public abstract class JavaKeyStore extends KeyStoreSpi {
* hash with a bit of whitener.
*/
private MessageDigest getPreKeyedHash(char[] password)
throws NoSuchAlgorithmException, UnsupportedEncodingException
throws NoSuchAlgorithmException
{
MessageDigest md = MessageDigest.getInstance("SHA");
byte[] passwdBytes = convertToBytes(password);
md.update(passwdBytes);
Arrays.fill(passwdBytes, (byte) 0x00);
md.update("Mighty Aphrodite".getBytes("UTF8"));
md.update("Mighty Aphrodite".getBytes(UTF_8));
return md;
}

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2019, 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,7 +26,6 @@
package sun.security.provider;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.security.Key;
import java.security.KeyStoreException;
import java.security.MessageDigest;

View file

@ -42,12 +42,14 @@ import java.net.SocketPermission;
import java.net.NetPermission;
import java.util.concurrent.ConcurrentHashMap;
import jdk.internal.access.JavaSecurityAccess;
import static jdk.internal.access.JavaSecurityAccess.ProtectionDomainCache;
import jdk.internal.access.SharedSecrets;
import jdk.internal.util.StaticProperty;
import sun.security.util.*;
import sun.net.www.ParseUtil;
import static java.nio.charset.StandardCharsets.UTF_8;
import static jdk.internal.access.JavaSecurityAccess.ProtectionDomainCache;
/**
* This class represents a default Policy implementation for the
* "JavaPolicy" type.
@ -559,8 +561,7 @@ public class PolicyFile extends java.security.Policy {
return false;
}
private InputStreamReader getInputStreamReader(InputStream is)
throws IOException {
private InputStreamReader getInputStreamReader(InputStream is) {
/*
* Read in policy using UTF-8 by default.
*
@ -569,7 +570,7 @@ public class PolicyFile extends java.security.Policy {
*/
return (notUtf8)
? new InputStreamReader(is)
: new InputStreamReader(is, "UTF-8");
: new InputStreamReader(is, UTF_8);
}
private void initStaticPolicy(final PolicyInfo newInfo) {

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2019, 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
@ -45,6 +45,8 @@ import sun.security.action.GetPropertyAction;
import sun.security.util.HexDumpEncoder;
import sun.security.x509.*;
import static java.nio.charset.StandardCharsets.UTF_8;
/**
* Implementation of SSL logger.
*
@ -229,7 +231,7 @@ public final class SSLLogger {
try {
String formatted =
SSLSimpleFormatter.format(this, level, message, thrwbl);
System.err.write(formatted.getBytes("UTF-8"));
System.err.write(formatted.getBytes(UTF_8));
} catch (Exception exp) {
// ignore it, just for debugging.
}
@ -243,7 +245,7 @@ public final class SSLLogger {
try {
String formatted =
SSLSimpleFormatter.format(this, level, message, params);
System.err.write(formatted.getBytes("UTF-8"));
System.err.write(formatted.getBytes(UTF_8));
} catch (Exception exp) {
// ignore it, just for debugging.
}

View file

@ -27,9 +27,12 @@ package sun.security.util;
import java.io.InputStream;
import java.io.IOException;
import java.math.BigInteger;
import java.nio.charset.Charset;
import java.util.Date;
import java.util.Vector;
import java.math.BigInteger;
import static java.nio.charset.StandardCharsets.*;
/**
* A DER input stream, used for parsing ASN.1 DER-encoded data such as
@ -457,7 +460,7 @@ public class DerInputStream {
* Read a string that was encoded as a UTF8String DER value.
*/
public String getUTF8String() throws IOException {
return readString(DerValue.tag_UTF8String, "UTF-8", "UTF8");
return readString(DerValue.tag_UTF8String, "UTF-8", UTF_8);
}
/**
@ -465,7 +468,7 @@ public class DerInputStream {
*/
public String getPrintableString() throws IOException {
return readString(DerValue.tag_PrintableString, "Printable",
"ASCII");
US_ASCII);
}
/**
@ -475,22 +478,21 @@ public class DerInputStream {
/*
* Works for common characters between T61 and ASCII.
*/
return readString(DerValue.tag_T61String, "T61", "ISO-8859-1");
return readString(DerValue.tag_T61String, "T61", ISO_8859_1);
}
/**
* Read a string that was encoded as a IA5tring DER value.
* Read a string that was encoded as a IA5String DER value.
*/
public String getIA5String() throws IOException {
return readString(DerValue.tag_IA5String, "IA5", "ASCII");
return readString(DerValue.tag_IA5String, "IA5", US_ASCII);
}
/**
* Read a string that was encoded as a BMPString DER value.
*/
public String getBMPString() throws IOException {
return readString(DerValue.tag_BMPString, "BMP",
"UnicodeBigUnmarked");
return readString(DerValue.tag_BMPString, "BMP", UTF_16BE);
}
/**
@ -498,7 +500,7 @@ public class DerInputStream {
*/
public String getGeneralString() throws IOException {
return readString(DerValue.tag_GeneralString, "General",
"ASCII");
US_ASCII);
}
/**
@ -510,7 +512,7 @@ public class DerInputStream {
* correspond to the stringTag above.
*/
private String readString(byte stringTag, String stringName,
String enc) throws IOException {
Charset charset) throws IOException {
if (buffer.read() != stringTag)
throw new IOException("DER input not a " +
@ -522,7 +524,7 @@ public class DerInputStream {
throw new IOException("Short read of DER " +
stringName + " string");
return new String(retval, enc);
return new String(retval, charset);
}
/**

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 1996, 2010, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1996, 2019, 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
@ -28,14 +28,16 @@ package sun.security.util;
import java.io.ByteArrayOutputStream;
import java.io.OutputStream;
import java.io.IOException;
import java.math.BigInteger;
import java.nio.charset.Charset;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;
import java.util.Comparator;
import java.util.Arrays;
import java.math.BigInteger;
import java.util.Locale;
import static java.nio.charset.StandardCharsets.*;
/**
* Output stream marshaling DER-encoded data. This is eventually provided
@ -398,14 +400,14 @@ extends ByteArrayOutputStream implements DerEncoder {
* Marshals a string as a DER encoded UTF8String.
*/
public void putUTF8String(String s) throws IOException {
writeString(s, DerValue.tag_UTF8String, "UTF8");
writeString(s, DerValue.tag_UTF8String, UTF_8);
}
/**
* Marshals a string as a DER encoded PrintableString.
*/
public void putPrintableString(String s) throws IOException {
writeString(s, DerValue.tag_PrintableString, "ASCII");
writeString(s, DerValue.tag_PrintableString, US_ASCII);
}
/**
@ -416,28 +418,28 @@ extends ByteArrayOutputStream implements DerEncoder {
* Works for characters that are defined in both ASCII and
* T61.
*/
writeString(s, DerValue.tag_T61String, "ISO-8859-1");
writeString(s, DerValue.tag_T61String, ISO_8859_1);
}
/**
* Marshals a string as a DER encoded IA5String.
*/
public void putIA5String(String s) throws IOException {
writeString(s, DerValue.tag_IA5String, "ASCII");
writeString(s, DerValue.tag_IA5String, US_ASCII);
}
/**
* Marshals a string as a DER encoded BMPString.
*/
public void putBMPString(String s) throws IOException {
writeString(s, DerValue.tag_BMPString, "UnicodeBigUnmarked");
writeString(s, DerValue.tag_BMPString, UTF_16BE);
}
/**
* Marshals a string as a DER encoded GeneralString.
*/
public void putGeneralString(String s) throws IOException {
writeString(s, DerValue.tag_GeneralString, "ASCII");
writeString(s, DerValue.tag_GeneralString, US_ASCII);
}
/**
@ -448,10 +450,10 @@ extends ByteArrayOutputStream implements DerEncoder {
* @param enc the name of the encoder that should be used corresponding
* to the above tag.
*/
private void writeString(String s, byte stringTag, String enc)
private void writeString(String s, byte stringTag, Charset charset)
throws IOException {
byte[] data = s.getBytes(enc);
byte[] data = s.getBytes(charset);
write(stringTag);
putLength(data.length);
write(data);
@ -502,7 +504,7 @@ extends ByteArrayOutputStream implements DerEncoder {
SimpleDateFormat sdf = new SimpleDateFormat(pattern, Locale.US);
sdf.setTimeZone(tz);
byte[] time = (sdf.format(d)).getBytes("ISO-8859-1");
byte[] time = (sdf.format(d)).getBytes(ISO_8859_1);
/*
* Write the formatted date.

View file

@ -27,8 +27,11 @@ package sun.security.util;
import java.io.*;
import java.math.BigInteger;
import java.nio.charset.Charset;
import java.util.Date;
import static java.nio.charset.StandardCharsets.*;
/**
* Represents a single DER-encoded value. DER encoding rules are a subset
* of the "Basic" Encoding Rules (BER), but they only support a single way
@ -204,7 +207,7 @@ public class DerValue {
/**
* Creates a PrintableString or UTF8string DER value from a string
*/
public DerValue(String value) throws IOException {
public DerValue(String value) {
boolean isPrintableString = true;
for (int i = 0; i < value.length(); i++) {
if (!isPrintableStringChar(value.charAt(i))) {
@ -221,7 +224,7 @@ public class DerValue {
* @param stringTag the tag for the DER value to create
* @param value the String object to use for the DER value
*/
public DerValue(byte stringTag, String value) throws IOException {
public DerValue(byte stringTag, String value) {
data = init(stringTag, value);
}
@ -337,9 +340,8 @@ public class DerValue {
this(in, true);
}
private DerInputStream init(byte stringTag, String value)
throws IOException {
String enc = null;
private DerInputStream init(byte stringTag, String value) {
final Charset charset;
tag = stringTag;
@ -347,16 +349,16 @@ public class DerValue {
case tag_PrintableString:
case tag_IA5String:
case tag_GeneralString:
enc = "ASCII";
charset = US_ASCII;
break;
case tag_T61String:
enc = "ISO-8859-1";
charset = ISO_8859_1;
break;
case tag_BMPString:
enc = "UnicodeBigUnmarked";
charset = UTF_16BE;
break;
case tag_UTF8String:
enc = "UTF8";
charset = UTF_8;
break;
// TBD: Need encoder for UniversalString before it can
// be handled.
@ -364,7 +366,7 @@ public class DerValue {
throw new IllegalArgumentException("Unsupported DER string type");
}
byte[] buf = value.getBytes(enc);
byte[] buf = value.getBytes(charset);
length = buf.length;
buffer = new DerInputBuffer(buf, true);
DerInputStream result = new DerInputStream(buffer);
@ -665,7 +667,7 @@ public class DerValue {
throw new IOException(
"DerValue.getPrintableString, not a string " + tag);
return new String(getDataBytes(), "ASCII");
return new String(getDataBytes(), US_ASCII);
}
/**
@ -678,7 +680,7 @@ public class DerValue {
throw new IOException(
"DerValue.getT61String, not T61 " + tag);
return new String(getDataBytes(), "ISO-8859-1");
return new String(getDataBytes(), ISO_8859_1);
}
/**
@ -691,7 +693,7 @@ public class DerValue {
throw new IOException(
"DerValue.getIA5String, not IA5 " + tag);
return new String(getDataBytes(), "ASCII");
return new String(getDataBytes(), US_ASCII);
}
/**
@ -707,7 +709,7 @@ public class DerValue {
// BMPString is the same as Unicode in big endian, unmarked
// format.
return new String(getDataBytes(), "UnicodeBigUnmarked");
return new String(getDataBytes(), UTF_16BE);
}
/**
@ -721,7 +723,7 @@ public class DerValue {
throw new IOException(
"DerValue.getUTF8String, not UTF-8 " + tag);
return new String(getDataBytes(), "UTF8");
return new String(getDataBytes(), UTF_8);
}
/**
@ -735,7 +737,7 @@ public class DerValue {
throw new IOException(
"DerValue.getGeneralString, not GeneralString " + tag);
return new String(getDataBytes(), "ASCII");
return new String(getDataBytes(), US_ASCII);
}
/**

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2017, 2019, 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
@ -45,6 +45,8 @@ import java.util.concurrent.ConcurrentHashMap;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import static java.nio.charset.StandardCharsets.UTF_8;
import sun.security.ssl.SSLLogger;
/**
@ -151,7 +153,7 @@ class DomainName {
private final boolean hasExceptions;
private Rules(InputStream is) throws IOException {
InputStreamReader isr = new InputStreamReader(is, "UTF-8");
InputStreamReader isr = new InputStreamReader(is, UTF_8);
BufferedReader reader = new BufferedReader(isr);
boolean hasExceptions = false;

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 1995, 2015, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1995, 2019, 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
@ -34,6 +34,8 @@ import java.io.OutputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import static java.nio.charset.StandardCharsets.ISO_8859_1;
/**
* This class encodes a buffer into the classic: "Hexadecimal Dump" format of
* the past. It is useful for analyzing the contents of binary buffers.
@ -183,17 +185,15 @@ public class HexDumpEncoder {
*/
public String encode(byte aBuffer[]) {
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
ByteArrayInputStream inStream = new ByteArrayInputStream(aBuffer);
String retVal = null;
ByteArrayInputStream inStream = new ByteArrayInputStream(aBuffer);
try {
encode(inStream, outStream);
// explicit ascii->unicode conversion
retVal = outStream.toString("ISO-8859-1");
} catch (Exception IOException) {
return outStream.toString(ISO_8859_1);
} catch (IOException ignore) {
// This should never happen.
throw new Error("CharacterEncoder.encode internal error");
}
return (retVal);
}
/**

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 1996, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1996, 2019, 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
@ -33,6 +33,8 @@ import java.security.AccessController;
import java.text.Normalizer;
import java.util.*;
import static java.nio.charset.StandardCharsets.UTF_8;
import sun.security.action.GetBooleanAction;
import sun.security.util.*;
import sun.security.pkcs.PKCS9Attribute;
@ -525,14 +527,13 @@ public class AVA implements DerEncoder {
return null;
}
private static String getEmbeddedHexString(List<Byte> hexList)
throws IOException {
private static String getEmbeddedHexString(List<Byte> hexList) {
int n = hexList.size();
byte[] hexBytes = new byte[n];
for (int i = 0; i < n; i++) {
hexBytes[i] = hexList.get(i).byteValue();
hexBytes[i] = hexList.get(i).byteValue();
}
return new String(hexBytes, "UTF8");
return new String(hexBytes, UTF_8);
}
private static boolean isTerminator(int ch, int format) {
@ -752,7 +753,7 @@ public class AVA implements DerEncoder {
*/
String valStr = null;
try {
valStr = new String(value.getDataBytes(), "UTF8");
valStr = new String(value.getDataBytes(), UTF_8);
} catch (IOException ie) {
throw new IllegalArgumentException("DER Value conversion");
}
@ -804,13 +805,7 @@ public class AVA implements DerEncoder {
// embed non-printable/non-escaped char
// as escaped hex pairs for debugging
byte[] valueBytes = null;
try {
valueBytes = Character.toString(c).getBytes("UTF8");
} catch (IOException ie) {
throw new IllegalArgumentException
("DER Value conversion");
}
byte[] valueBytes = Character.toString(c).getBytes(UTF_8);
for (int j = 0; j < valueBytes.length; j++) {
sbuffer.append('\\');
char hexChar = Character.forDigit
@ -905,7 +900,7 @@ public class AVA implements DerEncoder {
*/
String valStr = null;
try {
valStr = new String(value.getDataBytes(), "UTF8");
valStr = new String(value.getDataBytes(), UTF_8);
} catch (IOException ie) {
throw new IllegalArgumentException("DER Value conversion");
}
@ -966,13 +961,7 @@ public class AVA implements DerEncoder {
previousWhite = false;
byte[] valueBytes = null;
try {
valueBytes = Character.toString(c).getBytes("UTF8");
} catch (IOException ie) {
throw new IllegalArgumentException
("DER Value conversion");
}
byte[] valueBytes = Character.toString(c).getBytes(UTF_8);
for (int j = 0; j < valueBytes.length; j++) {
sbuffer.append('\\');
sbuffer.append(Character.forDigit
@ -1116,7 +1105,7 @@ public class AVA implements DerEncoder {
// embed escaped hex pairs
byte[] valueBytes =
Character.toString(c).getBytes("UTF8");
Character.toString(c).getBytes(UTF_8);
for (int j = 0; j < valueBytes.length; j++) {
sbuffer.append('\\');
char hexChar = Character.forDigit

View file

@ -45,6 +45,8 @@ import javax.security.auth.x500.X500Principal;
import sun.security.util.*;
import sun.security.provider.X509Factory;
import static java.nio.charset.StandardCharsets.US_ASCII;
/**
* The X509CertImpl class represents an X.509 certificate. These certificates
* are widely used to support authentication and other functionality in
@ -250,7 +252,7 @@ public class X509CertImpl extends X509Certificate implements DerEncoder {
DerValue der = null;
String line = null;
BufferedReader certBufferedReader =
new BufferedReader(new InputStreamReader(in, "ASCII"));
new BufferedReader(new InputStreamReader(in, US_ASCII));
try {
line = certBufferedReader.readLine();
} catch (IOException ioe1) {