提交 2b762ca4 编写于 作者: M msheppar

8006182: cleanup to use java.util.Base64 in java security component,...

8006182: cleanup to use java.util.Base64 in java security component, providers, and regression tests
Summary: Refactored code to use java.util.Base64 Mime Encoder and Decoder as a replacement for sun.misc.BASE64Encoder and sun.misc.BASE64Decoder
Reviewed-by: vinnie, chegar, sherman
上级 59b202a3
...@@ -37,7 +37,7 @@ import java.security.Signature; ...@@ -37,7 +37,7 @@ import java.security.Signature;
import java.security.SignatureException; import java.security.SignatureException;
import java.security.PublicKey; import java.security.PublicKey;
import sun.misc.BASE64Encoder; import java.util.Base64;
import sun.security.util.*; import sun.security.util.*;
import sun.security.x509.AlgorithmId; import sun.security.x509.AlgorithmId;
...@@ -289,10 +289,9 @@ public class PKCS10 { ...@@ -289,10 +289,9 @@ public class PKCS10 {
if (encoded == null) if (encoded == null)
throw new SignatureException("Cert request was not signed"); throw new SignatureException("Cert request was not signed");
BASE64Encoder encoder = new BASE64Encoder();
out.println("-----BEGIN NEW CERTIFICATE REQUEST-----"); out.println("-----BEGIN NEW CERTIFICATE REQUEST-----");
encoder.encodeBuffer(encoded, out); out.println(Base64.getMimeEncoder().encodeToString(encoded));
out.println("-----END NEW CERTIFICATE REQUEST-----"); out.println("-----END NEW CERTIFICATE REQUEST-----");
} }
......
...@@ -35,7 +35,7 @@ import sun.security.provider.certpath.X509CertPath; ...@@ -35,7 +35,7 @@ import sun.security.provider.certpath.X509CertPath;
import sun.security.provider.certpath.X509CertificatePair; import sun.security.provider.certpath.X509CertificatePair;
import sun.security.util.DerValue; import sun.security.util.DerValue;
import sun.security.util.Cache; import sun.security.util.Cache;
import sun.misc.BASE64Decoder; import java.util.Base64;
import sun.security.pkcs.ParsingException; import sun.security.pkcs.ParsingException;
/** /**
...@@ -512,7 +512,7 @@ public class X509Factory extends CertificateFactorySpi { ...@@ -512,7 +512,7 @@ public class X509Factory extends CertificateFactorySpi {
hyphen = 0; hyphen = 0;
last = next; last = next;
} }
if (hyphen == 5 && (last==-1 || last=='\r' || last=='\n')) { if (hyphen == 5 && (last == -1 || last == '\r' || last == '\n')) {
break; break;
} }
} }
...@@ -575,8 +575,7 @@ public class X509Factory extends CertificateFactorySpi { ...@@ -575,8 +575,7 @@ public class X509Factory extends CertificateFactorySpi {
checkHeaderFooter(header.toString(), footer.toString()); checkHeaderFooter(header.toString(), footer.toString());
BASE64Decoder decoder = new BASE64Decoder(); return Base64.getMimeDecoder().decode(new String(data, 0, pos));
return decoder.decodeBuffer(new String(data, 0, pos));
} }
} }
......
...@@ -57,7 +57,7 @@ import sun.security.tools.KeyStoreUtil; ...@@ -57,7 +57,7 @@ import sun.security.tools.KeyStoreUtil;
import sun.security.tools.PathList; import sun.security.tools.PathList;
import sun.security.x509.*; import sun.security.x509.*;
import sun.security.util.*; import sun.security.util.*;
import sun.misc.BASE64Encoder; import java.util.Base64;
/** /**
...@@ -1120,7 +1120,6 @@ public class Main { ...@@ -1120,7 +1120,6 @@ public class Main {
* different, replace the hash in the manifest with the newly * different, replace the hash in the manifest with the newly
* generated one. (This may invalidate existing signatures!) * generated one. (This may invalidate existing signatures!)
*/ */
BASE64Encoder encoder = new JarBASE64Encoder();
Vector<ZipEntry> mfFiles = new Vector<>(); Vector<ZipEntry> mfFiles = new Vector<>();
boolean wasSigned = false; boolean wasSigned = false;
...@@ -1148,15 +1147,14 @@ public class Main { ...@@ -1148,15 +1147,14 @@ public class Main {
if (manifest.getAttributes(ze.getName()) != null) { if (manifest.getAttributes(ze.getName()) != null) {
// jar entry is contained in manifest, check and // jar entry is contained in manifest, check and
// possibly update its digest attributes // possibly update its digest attributes
if (updateDigests(ze, zipFile, digests, encoder, if (updateDigests(ze, zipFile, digests,
manifest) == true) { manifest) == true) {
mfModified = true; mfModified = true;
} }
} else if (!ze.isDirectory()) { } else if (!ze.isDirectory()) {
// Add entry to manifest // Add entry to manifest
Attributes attrs = getDigestAttributes(ze, zipFile, Attributes attrs = getDigestAttributes(ze, zipFile,
digests, digests);
encoder);
mfEntries.put(ze.getName(), attrs); mfEntries.put(ze.getName(), attrs);
mfModified = true; mfModified = true;
} }
...@@ -1955,8 +1953,7 @@ public class Main { ...@@ -1955,8 +1953,7 @@ public class Main {
* of base64-encoded strings. * of base64-encoded strings.
*/ */
private synchronized String[] getDigests(ZipEntry ze, ZipFile zf, private synchronized String[] getDigests(ZipEntry ze, ZipFile zf,
MessageDigest[] digests, MessageDigest[] digests)
BASE64Encoder encoder)
throws IOException { throws IOException {
int n, i; int n, i;
...@@ -1980,7 +1977,7 @@ public class Main { ...@@ -1980,7 +1977,7 @@ public class Main {
// complete the digests // complete the digests
String[] base64Digests = new String[digests.length]; String[] base64Digests = new String[digests.length];
for (i=0; i<digests.length; i++) { for (i=0; i<digests.length; i++) {
base64Digests[i] = encoder.encode(digests[i].digest()); base64Digests[i] = Base64.getEncoder().encodeToString(digests[i].digest());
} }
return base64Digests; return base64Digests;
} }
...@@ -1990,11 +1987,10 @@ public class Main { ...@@ -1990,11 +1987,10 @@ public class Main {
* attributes * attributes
*/ */
private Attributes getDigestAttributes(ZipEntry ze, ZipFile zf, private Attributes getDigestAttributes(ZipEntry ze, ZipFile zf,
MessageDigest[] digests, MessageDigest[] digests)
BASE64Encoder encoder)
throws IOException { throws IOException {
String[] base64Digests = getDigests(ze, zf, digests, encoder); String[] base64Digests = getDigests(ze, zf, digests);
Attributes attrs = new Attributes(); Attributes attrs = new Attributes();
for (int i=0; i<digests.length; i++) { for (int i=0; i<digests.length; i++) {
...@@ -2016,12 +2012,11 @@ public class Main { ...@@ -2016,12 +2012,11 @@ public class Main {
*/ */
private boolean updateDigests(ZipEntry ze, ZipFile zf, private boolean updateDigests(ZipEntry ze, ZipFile zf,
MessageDigest[] digests, MessageDigest[] digests,
BASE64Encoder encoder,
Manifest mf) throws IOException { Manifest mf) throws IOException {
boolean update = false; boolean update = false;
Attributes attrs = mf.getAttributes(ze.getName()); Attributes attrs = mf.getAttributes(ze.getName());
String[] base64Digests = getDigests(ze, zf, digests, encoder); String[] base64Digests = getDigests(ze, zf, digests);
for (int i=0; i<digests.length; i++) { for (int i=0; i<digests.length; i++) {
// The entry name to be written into attrs // The entry name to be written into attrs
...@@ -2094,19 +2089,6 @@ public class Main { ...@@ -2094,19 +2089,6 @@ public class Main {
} }
} }
/**
* This is a BASE64Encoder that does not insert a default newline at the end of
* every output line. This is necessary because java.util.jar does its own
* line management (see Manifest.make72Safe()). Inserting additional new lines
* can cause line-wrapping problems (see CR 6219522).
*/
class JarBASE64Encoder extends BASE64Encoder {
/**
* Encode the suffix that ends every output line.
*/
protected void encodeLineSuffix(OutputStream aStream) throws IOException { }
}
class SignatureFile { class SignatureFile {
/** SignatureFile */ /** SignatureFile */
...@@ -2129,7 +2111,6 @@ class SignatureFile { ...@@ -2129,7 +2111,6 @@ class SignatureFile {
sf = new Manifest(); sf = new Manifest();
Attributes mattr = sf.getMainAttributes(); Attributes mattr = sf.getMainAttributes();
BASE64Encoder encoder = new JarBASE64Encoder();
mattr.putValue(Attributes.Name.SIGNATURE_VERSION.toString(), "1.0"); mattr.putValue(Attributes.Name.SIGNATURE_VERSION.toString(), "1.0");
mattr.putValue("Created-By", version + " (" + javaVendor + ")"); mattr.putValue("Created-By", version + " (" + javaVendor + ")");
...@@ -2138,7 +2119,7 @@ class SignatureFile { ...@@ -2138,7 +2119,7 @@ class SignatureFile {
// sign the whole manifest // sign the whole manifest
for (int i=0; i < digests.length; i++) { for (int i=0; i < digests.length; i++) {
mattr.putValue(digests[i].getAlgorithm()+"-Digest-Manifest", mattr.putValue(digests[i].getAlgorithm()+"-Digest-Manifest",
encoder.encode(md.manifestDigest(digests[i]))); Base64.getEncoder().encodeToString(md.manifestDigest(digests[i])));
} }
} }
...@@ -2149,7 +2130,7 @@ class SignatureFile { ...@@ -2149,7 +2130,7 @@ class SignatureFile {
for (int i=0; i < digests.length; i++) { for (int i=0; i < digests.length; i++) {
mattr.putValue(digests[i].getAlgorithm() + mattr.putValue(digests[i].getAlgorithm() +
"-Digest-" + ManifestDigester.MF_MAIN_ATTRS, "-Digest-" + ManifestDigester.MF_MAIN_ATTRS,
encoder.encode(mde.digest(digests[i]))); Base64.getEncoder().encodeToString(mde.digest(digests[i])));
} }
} else { } else {
throw new IllegalStateException throw new IllegalStateException
...@@ -2170,7 +2151,7 @@ class SignatureFile { ...@@ -2170,7 +2151,7 @@ class SignatureFile {
Attributes attr = new Attributes(); Attributes attr = new Attributes();
for (int i=0; i < digests.length; i++) { for (int i=0; i < digests.length; i++) {
attr.putValue(digests[i].getAlgorithm()+"-Digest", attr.putValue(digests[i].getAlgorithm()+"-Digest",
encoder.encode(mde.digest(digests[i]))); Base64.getEncoder().encodeToString(mde.digest(digests[i])));
} }
entries.put(name, attr); entries.put(name, attr);
} }
......
...@@ -63,7 +63,7 @@ import java.security.cert.X509CRL; ...@@ -63,7 +63,7 @@ import java.security.cert.X509CRL;
import java.security.cert.X509CRLEntry; import java.security.cert.X509CRLEntry;
import java.security.cert.X509CRLSelector; import java.security.cert.X509CRLSelector;
import javax.security.auth.x500.X500Principal; import javax.security.auth.x500.X500Principal;
import sun.misc.BASE64Encoder; import java.util.Base64;
import sun.security.util.ObjectIdentifier; import sun.security.util.ObjectIdentifier;
import sun.security.pkcs10.PKCS10; import sun.security.pkcs10.PKCS10;
import sun.security.pkcs10.PKCS10Attribute; import sun.security.pkcs10.PKCS10Attribute;
...@@ -73,7 +73,6 @@ import sun.security.util.Password; ...@@ -73,7 +73,6 @@ import sun.security.util.Password;
import javax.crypto.KeyGenerator; import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey; import javax.crypto.SecretKey;
import sun.misc.BASE64Decoder;
import sun.security.pkcs.PKCS9Attribute; import sun.security.pkcs.PKCS9Attribute;
import sun.security.tools.KeyStoreUtil; import sun.security.tools.KeyStoreUtil;
import sun.security.tools.PathList; import sun.security.tools.PathList;
...@@ -555,11 +554,11 @@ public final class Main { ...@@ -555,11 +554,11 @@ public final class Main {
return cmd != PRINTCERT && cmd != PRINTCERTREQ; return cmd != PRINTCERT && cmd != PRINTCERTREQ;
} }
/** /**
* Execute the commands. * Execute the commands.
*/ */
void doCommands(PrintStream out) throws Exception { void doCommands(PrintStream out) throws Exception {
if (storetype == null) { if (storetype == null) {
storetype = KeyStore.getDefaultType(); storetype = KeyStore.getDefaultType();
} }
...@@ -1189,7 +1188,7 @@ public final class Main { ...@@ -1189,7 +1188,7 @@ public final class Main {
sb.append(s); sb.append(s);
} }
} }
byte[] rawReq = new BASE64Decoder().decodeBuffer(new String(sb)); byte[] rawReq = Base64.getMimeDecoder().decode(new String(sb));
PKCS10 req = new PKCS10(rawReq); PKCS10 req = new PKCS10(rawReq);
info.set(X509CertInfo.KEY, new CertificateX509Key(req.getSubjectPublicKeyInfo())); info.set(X509CertInfo.KEY, new CertificateX509Key(req.getSubjectPublicKeyInfo()));
...@@ -1266,7 +1265,7 @@ public final class Main { ...@@ -1266,7 +1265,7 @@ public final class Main {
crl.sign(privateKey, sigAlgName); crl.sign(privateKey, sigAlgName);
if (rfc) { if (rfc) {
out.println("-----BEGIN X509 CRL-----"); out.println("-----BEGIN X509 CRL-----");
new BASE64Encoder().encodeBuffer(crl.getEncodedInternal(), out); out.println(Base64.getMimeEncoder().encodeToString(crl.getEncodedInternal()));
out.println("-----END X509 CRL-----"); out.println("-----END X509 CRL-----");
} else { } else {
out.write(crl.getEncodedInternal()); out.write(crl.getEncodedInternal());
...@@ -2148,7 +2147,7 @@ public final class Main { ...@@ -2148,7 +2147,7 @@ public final class Main {
if (rfc) { if (rfc) {
X509CRL xcrl = (X509CRL)crl; X509CRL xcrl = (X509CRL)crl;
out.println("-----BEGIN X509 CRL-----"); out.println("-----BEGIN X509 CRL-----");
new BASE64Encoder().encodeBuffer(xcrl.getEncoded(), out); out.println(Base64.getMimeEncoder().encodeToString(xcrl.getEncoded()));
out.println("-----END X509 CRL-----"); out.println("-----END X509 CRL-----");
} else { } else {
out.println(crl.toString()); out.println(crl.toString());
...@@ -2175,7 +2174,7 @@ public final class Main { ...@@ -2175,7 +2174,7 @@ public final class Main {
sb.append(s); sb.append(s);
} }
} }
PKCS10 req = new PKCS10(new BASE64Decoder().decodeBuffer(new String(sb))); PKCS10 req = new PKCS10(Base64.getMimeDecoder().decode(new String(sb)));
PublicKey pkey = req.getSubjectPublicKeyInfo(); PublicKey pkey = req.getSubjectPublicKeyInfo();
out.printf(rb.getString("PKCS.10.Certificate.Request.Version.1.0.Subject.s.Public.Key.s.format.s.key."), out.printf(rb.getString("PKCS.10.Certificate.Request.Version.1.0.Subject.s.Public.Key.s.format.s.key."),
...@@ -2227,8 +2226,10 @@ public final class Main { ...@@ -2227,8 +2226,10 @@ public final class Main {
Object[] source = {new Integer(i + 1)}; Object[] source = {new Integer(i + 1)};
out.println(form.format(source)); out.println(form.format(source));
} }
if (rfc) dumpCert(x509Cert, out); if (rfc)
else printX509Cert(x509Cert, out); dumpCert(x509Cert, out);
else
printX509Cert(x509Cert, out);
if (i < (certs.length-1)) { if (i < (certs.length-1)) {
out.println(); out.println();
} }
...@@ -2946,9 +2947,8 @@ public final class Main { ...@@ -2946,9 +2947,8 @@ public final class Main {
throws IOException, CertificateException throws IOException, CertificateException
{ {
if (rfc) { if (rfc) {
BASE64Encoder encoder = new BASE64Encoder();
out.println(X509Factory.BEGIN_CERT); out.println(X509Factory.BEGIN_CERT);
encoder.encodeBuffer(cert.getEncoded(), out); out.println(Base64.getMimeEncoder().encodeToString(cert.getEncoded()));
out.println(X509Factory.END_CERT); out.println(X509Factory.END_CERT);
} else { } else {
out.write(cert.getEncoded()); // binary out.write(cert.getEncoded()); // binary
......
...@@ -31,7 +31,7 @@ import java.security.CodeSigner; ...@@ -31,7 +31,7 @@ import java.security.CodeSigner;
import java.util.*; import java.util.*;
import java.util.jar.*; import java.util.jar.*;
import sun.misc.BASE64Decoder; import java.util.Base64;
import sun.security.jca.Providers; import sun.security.jca.Providers;
...@@ -63,7 +63,6 @@ public class ManifestEntryVerifier { ...@@ -63,7 +63,6 @@ public class ManifestEntryVerifier {
/** the manifest hashes for the digests in use */ /** the manifest hashes for the digests in use */
ArrayList<byte[]> manifestHashes; ArrayList<byte[]> manifestHashes;
private BASE64Decoder decoder = null;
private String name = null; private String name = null;
private Manifest man; private Manifest man;
...@@ -81,7 +80,6 @@ public class ManifestEntryVerifier { ...@@ -81,7 +80,6 @@ public class ManifestEntryVerifier {
createdDigests = new HashMap<String, MessageDigest>(11); createdDigests = new HashMap<String, MessageDigest>(11);
digests = new ArrayList<MessageDigest>(); digests = new ArrayList<MessageDigest>();
manifestHashes = new ArrayList<byte[]>(); manifestHashes = new ArrayList<byte[]>();
decoder = new BASE64Decoder();
this.man = man; this.man = man;
} }
...@@ -147,7 +145,7 @@ public class ManifestEntryVerifier { ...@@ -147,7 +145,7 @@ public class ManifestEntryVerifier {
digest.reset(); digest.reset();
digests.add(digest); digests.add(digest);
manifestHashes.add( manifestHashes.add(
decoder.decodeBuffer((String)se.getValue())); Base64.getMimeDecoder().decode((String)se.getValue()));
} }
} }
} }
......
...@@ -35,7 +35,7 @@ import java.util.*; ...@@ -35,7 +35,7 @@ import java.util.*;
import java.util.jar.*; import java.util.jar.*;
import sun.security.pkcs.*; import sun.security.pkcs.*;
import sun.misc.BASE64Decoder; import java.util.Base64;
import sun.security.jca.Providers; import sun.security.jca.Providers;
...@@ -220,7 +220,6 @@ public class SignatureFileVerifier { ...@@ -220,7 +220,6 @@ public class SignatureFileVerifier {
name); name);
} }
BASE64Decoder decoder = new BASE64Decoder();
CodeSigner[] newSigners = getSigners(infos, block); CodeSigner[] newSigners = getSigners(infos, block);
...@@ -232,10 +231,10 @@ public class SignatureFileVerifier { ...@@ -232,10 +231,10 @@ public class SignatureFileVerifier {
sf.getEntries().entrySet().iterator(); sf.getEntries().entrySet().iterator();
// see if we can verify the whole manifest first // see if we can verify the whole manifest first
boolean manifestSigned = verifyManifestHash(sf, md, decoder, manifestDigests); boolean manifestSigned = verifyManifestHash(sf, md, manifestDigests);
// verify manifest main attributes // verify manifest main attributes
if (!manifestSigned && !verifyManifestMainAttrs(sf, md, decoder)) { if (!manifestSigned && !verifyManifestMainAttrs(sf, md)) {
throw new SecurityException throw new SecurityException
("Invalid signature file digest for Manifest main attributes"); ("Invalid signature file digest for Manifest main attributes");
} }
...@@ -247,7 +246,7 @@ public class SignatureFileVerifier { ...@@ -247,7 +246,7 @@ public class SignatureFileVerifier {
String name = e.getKey(); String name = e.getKey();
if (manifestSigned || if (manifestSigned ||
(verifySection(e.getValue(), name, md, decoder))) { (verifySection(e.getValue(), name, md))) {
if (name.startsWith("./")) if (name.startsWith("./"))
name = name.substring(2); name = name.substring(2);
...@@ -275,7 +274,6 @@ public class SignatureFileVerifier { ...@@ -275,7 +274,6 @@ public class SignatureFileVerifier {
*/ */
private boolean verifyManifestHash(Manifest sf, private boolean verifyManifestHash(Manifest sf,
ManifestDigester md, ManifestDigester md,
BASE64Decoder decoder,
List<Object> manifestDigests) List<Object> manifestDigests)
throws IOException throws IOException
{ {
...@@ -297,7 +295,7 @@ public class SignatureFileVerifier { ...@@ -297,7 +295,7 @@ public class SignatureFileVerifier {
if (digest != null) { if (digest != null) {
byte[] computedHash = md.manifestDigest(digest); byte[] computedHash = md.manifestDigest(digest);
byte[] expectedHash = byte[] expectedHash =
decoder.decodeBuffer((String)se.getValue()); Base64.getMimeDecoder().decode((String)se.getValue());
if (debug != null) { if (debug != null) {
debug.println("Signature File: Manifest digest " + debug.println("Signature File: Manifest digest " +
...@@ -320,8 +318,7 @@ public class SignatureFileVerifier { ...@@ -320,8 +318,7 @@ public class SignatureFileVerifier {
} }
private boolean verifyManifestMainAttrs(Manifest sf, private boolean verifyManifestMainAttrs(Manifest sf,
ManifestDigester md, ManifestDigester md)
BASE64Decoder decoder)
throws IOException throws IOException
{ {
Attributes mattr = sf.getMainAttributes(); Attributes mattr = sf.getMainAttributes();
...@@ -342,7 +339,7 @@ public class SignatureFileVerifier { ...@@ -342,7 +339,7 @@ public class SignatureFileVerifier {
md.get(ManifestDigester.MF_MAIN_ATTRS, false); md.get(ManifestDigester.MF_MAIN_ATTRS, false);
byte[] computedHash = mde.digest(digest); byte[] computedHash = mde.digest(digest);
byte[] expectedHash = byte[] expectedHash =
decoder.decodeBuffer((String)se.getValue()); Base64.getMimeDecoder().decode((String)se.getValue());
if (debug != null) { if (debug != null) {
debug.println("Signature File: " + debug.println("Signature File: " +
...@@ -387,8 +384,7 @@ public class SignatureFileVerifier { ...@@ -387,8 +384,7 @@ public class SignatureFileVerifier {
private boolean verifySection(Attributes sfAttr, private boolean verifySection(Attributes sfAttr,
String name, String name,
ManifestDigester md, ManifestDigester md)
BASE64Decoder decoder)
throws IOException throws IOException
{ {
boolean oneDigestVerified = false; boolean oneDigestVerified = false;
...@@ -418,7 +414,7 @@ public class SignatureFileVerifier { ...@@ -418,7 +414,7 @@ public class SignatureFileVerifier {
boolean ok = false; boolean ok = false;
byte[] expected = byte[] expected =
decoder.decodeBuffer((String)se.getValue()); Base64.getMimeDecoder().decode((String)se.getValue());
byte[] computed; byte[] computed;
if (workaround) { if (workaround) {
computed = mde.digestWorkaround(digest); computed = mde.digestWorkaround(digest);
......
...@@ -41,7 +41,7 @@ import java.util.*; ...@@ -41,7 +41,7 @@ import java.util.*;
import javax.security.auth.x500.X500Principal; import javax.security.auth.x500.X500Principal;
import sun.misc.HexDumpEncoder; import sun.misc.HexDumpEncoder;
import sun.misc.BASE64Decoder; import java.util.Base64;
import sun.security.util.*; import sun.security.util.*;
import sun.security.provider.X509Factory; import sun.security.provider.X509Factory;
...@@ -263,7 +263,6 @@ public class X509CertImpl extends X509Certificate implements DerEncoder { ...@@ -263,7 +263,6 @@ public class X509CertImpl extends X509Certificate implements DerEncoder {
} }
if (line.equals(X509Factory.BEGIN_CERT)) { if (line.equals(X509Factory.BEGIN_CERT)) {
/* stream appears to be hex-encoded bytes */ /* stream appears to be hex-encoded bytes */
BASE64Decoder decoder = new BASE64Decoder();
ByteArrayOutputStream decstream = new ByteArrayOutputStream(); ByteArrayOutputStream decstream = new ByteArrayOutputStream();
try { try {
while ((line = certBufferedReader.readLine()) != null) { while ((line = certBufferedReader.readLine()) != null) {
...@@ -271,7 +270,7 @@ public class X509CertImpl extends X509Certificate implements DerEncoder { ...@@ -271,7 +270,7 @@ public class X509CertImpl extends X509Certificate implements DerEncoder {
der = new DerValue(decstream.toByteArray()); der = new DerValue(decstream.toByteArray());
break; break;
} else { } else {
decstream.write(decoder.decodeBuffer(line)); decstream.write(Base64.getMimeDecoder().decode(line));
} }
} }
} catch (IOException ioe2) { } catch (IOException ioe2) {
......
...@@ -30,8 +30,7 @@ import java.util.*; ...@@ -30,8 +30,7 @@ import java.util.*;
import java.security.*; import java.security.*;
import sun.net.www.MessageHeader; import sun.net.www.MessageHeader;
import sun.misc.BASE64Encoder; import java.util.Base64;
import sun.misc.BASE64Decoder;
/** /**
* This is OBSOLETE. DO NOT USE THIS. Use java.util.jar.Manifest * This is OBSOLETE. DO NOT USE THIS. Use java.util.jar.Manifest
...@@ -178,7 +177,6 @@ public class Manifest { ...@@ -178,7 +177,6 @@ public class Manifest {
return; return;
} }
BASE64Encoder enc = new BASE64Encoder();
/* compute hashes, write over any other "Hash-Algorithms" (?) */ /* compute hashes, write over any other "Hash-Algorithms" (?) */
for (int j = 0; j < hashes.length; ++j) { for (int j = 0; j < hashes.length; ++j) {
...@@ -190,7 +188,7 @@ public class Manifest { ...@@ -190,7 +188,7 @@ public class Manifest {
while ((len = is.read(tmpbuf, 0, tmpbuf.length)) != -1) { while ((len = is.read(tmpbuf, 0, tmpbuf.length)) != -1) {
dig.update(tmpbuf, 0, len); dig.update(tmpbuf, 0, len);
} }
mh.set(hashes[j] + "-Digest", enc.encode(dig.digest())); mh.set(hashes[j] + "-Digest", Base64.getMimeEncoder().encodeToString(dig.digest()));
} catch (NoSuchAlgorithmException e) { } catch (NoSuchAlgorithmException e) {
throw new JarException("Digest algorithm " + hashes[j] + throw new JarException("Digest algorithm " + hashes[j] +
" not available."); " not available.");
......
...@@ -30,8 +30,8 @@ import java.util.*; ...@@ -30,8 +30,8 @@ import java.util.*;
import java.security.*; import java.security.*;
import sun.net.www.MessageHeader; import sun.net.www.MessageHeader;
import sun.misc.BASE64Encoder; import java.util.Base64;
import sun.misc.BASE64Decoder;
import sun.security.pkcs.*; import sun.security.pkcs.*;
import sun.security.x509.AlgorithmId; import sun.security.x509.AlgorithmId;
...@@ -305,7 +305,6 @@ public class SignatureFile { ...@@ -305,7 +305,6 @@ public class SignatureFile {
} }
smh.set("Name", name); smh.set("Name", name);
BASE64Encoder encoder = new BASE64Encoder();
try { try {
for (int i = 0; i < hashes.length; ++i) { for (int i = 0; i < hashes.length; ++i) {
MessageDigest dig = getDigest(hashes[i]); MessageDigest dig = getDigest(hashes[i]);
...@@ -314,7 +313,7 @@ public class SignatureFile { ...@@ -314,7 +313,7 @@ public class SignatureFile {
mh.print(ps); mh.print(ps);
byte[] headerBytes = baos.toByteArray(); byte[] headerBytes = baos.toByteArray();
byte[] digest = dig.digest(headerBytes); byte[] digest = dig.digest(headerBytes);
smh.set(hashes[i] + "-Digest", encoder.encode(digest)); smh.set(hashes[i] + "-Digest", Base64.getMimeEncoder().encodeToString(digest));
} }
return smh; return smh;
} catch (NoSuchAlgorithmException e) { } catch (NoSuchAlgorithmException e) {
......
...@@ -34,7 +34,7 @@ import java.io.*; ...@@ -34,7 +34,7 @@ import java.io.*;
import javax.security.auth.kerberos.KerberosKey; import javax.security.auth.kerberos.KerberosKey;
import javax.security.auth.kerberos.KerberosPrincipal; import javax.security.auth.kerberos.KerberosPrincipal;
import javax.security.auth.kerberos.KerberosTicket; import javax.security.auth.kerberos.KerberosTicket;
import sun.misc.BASE64Decoder; import java.util.Base64;
public class KerberosTixDateTest { public class KerberosTixDateTest {
...@@ -127,7 +127,7 @@ public class KerberosTixDateTest { ...@@ -127,7 +127,7 @@ public class KerberosTixDateTest {
System.out.println("Testing against KerberosTicket from JDK6..."); System.out.println("Testing against KerberosTicket from JDK6...");
byte[] serializedBytes = byte[] serializedBytes =
new BASE64Decoder().decodeBuffer(serializedKerberosTix); Base64.getMimeDecoder().decode(serializedKerberosTix);
checkEqualsAndHashCode(serializedBytes, t); checkEqualsAndHashCode(serializedBytes, t);
System.out.println("Testing against KerberosTicket from current rel..."); System.out.println("Testing against KerberosTicket from current rel...");
......
...@@ -55,6 +55,7 @@ import org.ietf.jgss.GSSCredential; ...@@ -55,6 +55,7 @@ import org.ietf.jgss.GSSCredential;
import org.ietf.jgss.GSSManager; import org.ietf.jgss.GSSManager;
import sun.security.jgss.GSSUtil; import sun.security.jgss.GSSUtil;
import sun.security.krb5.Config; import sun.security.krb5.Config;
import java.util.Base64;
/** /**
* Basic JGSS/krb5 test with 3 parties: client, server, backend server. Each * Basic JGSS/krb5 test with 3 parties: client, server, backend server. Each
...@@ -341,12 +342,11 @@ public class HttpNegotiateServer { ...@@ -341,12 +342,11 @@ public class HttpNegotiateServer {
exch.getHttpContext().getAttributes().put("GSSContext", c); exch.getHttpContext().getAttributes().put("GSSContext", c);
return new com.sun.net.httpserver.Authenticator.Retry(err); return new com.sun.net.httpserver.Authenticator.Retry(err);
} else { // Later requests } else { // Later requests
byte[] token = new sun.misc.BASE64Decoder() byte[] token = Base64.getMimeDecoder().decode(auth.split(" ")[1]);
.decodeBuffer(auth.split(" ")[1]);
token = c.acceptSecContext(token, 0, token.length); token = c.acceptSecContext(token, 0, token.length);
Headers map = exch.getResponseHeaders(); Headers map = exch.getResponseHeaders();
map.set (reqHdr, scheme + " " + new sun.misc.BASE64Encoder() map.set (reqHdr, scheme + " " + Base64.getMimeEncoder()
.encode(token).replaceAll("\\s", "")); .encodeToString(token).replaceAll("\\s", ""));
if (c.isEstablished()) { if (c.isEstablished()) {
return new com.sun.net.httpserver.Authenticator.Success( return new com.sun.net.httpserver.Authenticator.Success(
new HttpPrincipal(c.getSrcName().toString(), "")); new HttpPrincipal(c.getSrcName().toString(), ""));
......
...@@ -46,8 +46,7 @@ import java.security.cert.Certificate; ...@@ -46,8 +46,7 @@ import java.security.cert.Certificate;
import java.security.cert.CertificateFactory; import java.security.cert.CertificateFactory;
import java.security.spec.*; import java.security.spec.*;
import java.security.interfaces.*; import java.security.interfaces.*;
import sun.misc.BASE64Decoder; import java.util.Base64;
public class MD2InTrustAnchor { public class MD2InTrustAnchor {
...@@ -238,7 +237,7 @@ public class MD2InTrustAnchor { ...@@ -238,7 +237,7 @@ public class MD2InTrustAnchor {
if (keyCertStr != null) { if (keyCertStr != null) {
// generate the private key. // generate the private key.
PKCS8EncodedKeySpec priKeySpec = new PKCS8EncodedKeySpec( PKCS8EncodedKeySpec priKeySpec = new PKCS8EncodedKeySpec(
new BASE64Decoder().decodeBuffer(keySpecStr)); Base64.getMimeDecoder().decode(keySpecStr));
KeyFactory kf = KeyFactory.getInstance("RSA"); KeyFactory kf = KeyFactory.getInstance("RSA");
RSAPrivateKey priKey = RSAPrivateKey priKey =
(RSAPrivateKey)kf.generatePrivate(priKeySpec); (RSAPrivateKey)kf.generatePrivate(priKeySpec);
......
...@@ -44,7 +44,7 @@ import java.security.*; ...@@ -44,7 +44,7 @@ import java.security.*;
import java.security.cert.*; import java.security.cert.*;
import java.security.spec.*; import java.security.spec.*;
import java.security.interfaces.*; import java.security.interfaces.*;
import sun.misc.BASE64Decoder; import java.util.Base64;
public class TrustTrustedCert { public class TrustTrustedCert {
...@@ -230,7 +230,7 @@ public class TrustTrustedCert { ...@@ -230,7 +230,7 @@ public class TrustTrustedCert {
// generate the private key. // generate the private key.
PKCS8EncodedKeySpec priKeySpec = new PKCS8EncodedKeySpec( PKCS8EncodedKeySpec priKeySpec = new PKCS8EncodedKeySpec(
new BASE64Decoder().decodeBuffer(targetPrivateKey)); Base64.getMimeDecoder().decode(targetPrivateKey));
KeyFactory kf = KeyFactory.getInstance("RSA"); KeyFactory kf = KeyFactory.getInstance("RSA");
RSAPrivateKey priKey = RSAPrivateKey priKey =
(RSAPrivateKey)kf.generatePrivate(priKeySpec); (RSAPrivateKey)kf.generatePrivate(priKeySpec);
......
...@@ -44,7 +44,7 @@ import java.security.spec.*; ...@@ -44,7 +44,7 @@ import java.security.spec.*;
import java.security.interfaces.*; import java.security.interfaces.*;
import java.math.BigInteger; import java.math.BigInteger;
import sun.misc.BASE64Decoder; import java.util.Base64;
public class BasicConstraints { public class BasicConstraints {
...@@ -400,11 +400,11 @@ public class BasicConstraints { ...@@ -400,11 +400,11 @@ public class BasicConstraints {
PKCS8EncodedKeySpec priKeySpec = null; PKCS8EncodedKeySpec priKeySpec = null;
if (isServer) { if (isServer) {
priKeySpec = new PKCS8EncodedKeySpec( priKeySpec = new PKCS8EncodedKeySpec(
new BASE64Decoder().decodeBuffer(serverPrivateKey)); Base64.getMimeDecoder().decode(serverPrivateKey));
is = new ByteArrayInputStream(serverCertStr.getBytes()); is = new ByteArrayInputStream(serverCertStr.getBytes());
} else { } else {
priKeySpec = new PKCS8EncodedKeySpec( priKeySpec = new PKCS8EncodedKeySpec(
new BASE64Decoder().decodeBuffer(clientPrivateKey)); Base64.getMimeDecoder().decode(clientPrivateKey));
is = new ByteArrayInputStream(clientCertStr.getBytes()); is = new ByteArrayInputStream(clientCertStr.getBytes());
} }
KeyFactory kf = KeyFactory.getInstance("RSA"); KeyFactory kf = KeyFactory.getInstance("RSA");
......
...@@ -45,7 +45,7 @@ import java.security.spec.*; ...@@ -45,7 +45,7 @@ import java.security.spec.*;
import java.security.interfaces.*; import java.security.interfaces.*;
import java.math.BigInteger; import java.math.BigInteger;
import sun.misc.BASE64Decoder; import java.util.Base64;
public class SelfIssuedCert { public class SelfIssuedCert {
...@@ -242,7 +242,7 @@ public class SelfIssuedCert { ...@@ -242,7 +242,7 @@ public class SelfIssuedCert {
if (keyCertStr != null) { if (keyCertStr != null) {
// generate the private key. // generate the private key.
PKCS8EncodedKeySpec priKeySpec = new PKCS8EncodedKeySpec( PKCS8EncodedKeySpec priKeySpec = new PKCS8EncodedKeySpec(
new BASE64Decoder().decodeBuffer(keySpecStr)); Base64.getMimeDecoder().decode(keySpecStr));
KeyFactory kf = KeyFactory.getInstance("RSA"); KeyFactory kf = KeyFactory.getInstance("RSA");
RSAPrivateKey priKey = RSAPrivateKey priKey =
(RSAPrivateKey)kf.generatePrivate(priKeySpec); (RSAPrivateKey)kf.generatePrivate(priKeySpec);
......
...@@ -33,6 +33,7 @@ import java.net.*; ...@@ -33,6 +33,7 @@ import java.net.*;
import javax.net.ssl.*; import javax.net.ssl.*;
import javax.net.ServerSocketFactory; import javax.net.ServerSocketFactory;
import sun.net.www.*; import sun.net.www.*;
import java.util.Base64;
public class ProxyTunnelServer extends Thread { public class ProxyTunnelServer extends Thread {
...@@ -292,12 +293,12 @@ public class ProxyTunnelServer extends Thread { ...@@ -292,12 +293,12 @@ public class ProxyTunnelServer extends Thread {
authInfo.trim(); authInfo.trim();
int ind = authInfo.indexOf(' '); int ind = authInfo.indexOf(' ');
String recvdUserPlusPass = authInfo.substring(ind + 1).trim(); String recvdUserPlusPass = authInfo.substring(ind + 1).trim();
// extract encoded (username:passwd // extract encoded (username:passwd
if (userPlusPass.equals( if (userPlusPass.equals(
new String( new String( Base64.getMimeDecoder()
(new sun.misc.BASE64Decoder()). .decode(recvdUserPlusPass))))
decodeBuffer(recvdUserPlusPass) {
))) {
matched = true; matched = true;
} }
} catch (Exception e) { } catch (Exception e) {
......
...@@ -51,7 +51,7 @@ import java.security.cert.X509Certificate; ...@@ -51,7 +51,7 @@ import java.security.cert.X509Certificate;
import java.security.cert.CertificateFactory; import java.security.cert.CertificateFactory;
import java.security.spec.*; import java.security.spec.*;
import java.security.interfaces.*; import java.security.interfaces.*;
import sun.misc.BASE64Decoder; import java.util.Base64;
public class SSLSocketSNISensitive { public class SSLSocketSNISensitive {
...@@ -391,7 +391,7 @@ public class SSLSocketSNISensitive { ...@@ -391,7 +391,7 @@ public class SSLSocketSNISensitive {
// generate the private key. // generate the private key.
String keySpecStr = keyStrs[i]; String keySpecStr = keyStrs[i];
PKCS8EncodedKeySpec priKeySpec = new PKCS8EncodedKeySpec( PKCS8EncodedKeySpec priKeySpec = new PKCS8EncodedKeySpec(
new BASE64Decoder().decodeBuffer(keySpecStr)); Base64.getMimeDecoder().decode(keySpecStr));
KeyFactory kf = KeyFactory.getInstance("RSA"); KeyFactory kf = KeyFactory.getInstance("RSA");
RSAPrivateKey priKey = RSAPrivateKey priKey =
(RSAPrivateKey)kf.generatePrivate(priKeySpec); (RSAPrivateKey)kf.generatePrivate(priKeySpec);
......
...@@ -53,7 +53,7 @@ import java.security.cert.Certificate; ...@@ -53,7 +53,7 @@ import java.security.cert.Certificate;
import java.security.cert.CertificateFactory; import java.security.cert.CertificateFactory;
import java.security.spec.*; import java.security.spec.*;
import java.security.interfaces.*; import java.security.interfaces.*;
import sun.misc.BASE64Decoder; import java.util.Base64;
public class DisabledShortRSAKeys { public class DisabledShortRSAKeys {
...@@ -244,7 +244,7 @@ public class DisabledShortRSAKeys { ...@@ -244,7 +244,7 @@ public class DisabledShortRSAKeys {
if (keyCertStr != null) { if (keyCertStr != null) {
// generate the private key. // generate the private key.
PKCS8EncodedKeySpec priKeySpec = new PKCS8EncodedKeySpec( PKCS8EncodedKeySpec priKeySpec = new PKCS8EncodedKeySpec(
new BASE64Decoder().decodeBuffer(keySpecStr)); Base64.getMimeDecoder().decode(keySpecStr));
KeyFactory kf = KeyFactory.getInstance("RSA"); KeyFactory kf = KeyFactory.getInstance("RSA");
RSAPrivateKey priKey = RSAPrivateKey priKey =
(RSAPrivateKey)kf.generatePrivate(priKeySpec); (RSAPrivateKey)kf.generatePrivate(priKeySpec);
......
...@@ -48,7 +48,7 @@ import java.security.cert.Certificate; ...@@ -48,7 +48,7 @@ import java.security.cert.Certificate;
import java.security.cert.CertificateFactory; import java.security.cert.CertificateFactory;
import java.security.spec.*; import java.security.spec.*;
import java.security.interfaces.*; import java.security.interfaces.*;
import sun.misc.BASE64Decoder; import java.util.Base64;
public class ShortRSAKey512 { public class ShortRSAKey512 {
...@@ -229,7 +229,7 @@ public class ShortRSAKey512 { ...@@ -229,7 +229,7 @@ public class ShortRSAKey512 {
if (keyCertStr != null) { if (keyCertStr != null) {
// generate the private key. // generate the private key.
PKCS8EncodedKeySpec priKeySpec = new PKCS8EncodedKeySpec( PKCS8EncodedKeySpec priKeySpec = new PKCS8EncodedKeySpec(
new BASE64Decoder().decodeBuffer(keySpecStr)); Base64.getMimeDecoder().decode(keySpecStr));
KeyFactory kf = KeyFactory.getInstance("RSA"); KeyFactory kf = KeyFactory.getInstance("RSA");
RSAPrivateKey priKey = RSAPrivateKey priKey =
(RSAPrivateKey)kf.generatePrivate(priKeySpec); (RSAPrivateKey)kf.generatePrivate(priKeySpec);
......
...@@ -35,6 +35,7 @@ import java.net.*; ...@@ -35,6 +35,7 @@ import java.net.*;
import javax.net.ssl.*; import javax.net.ssl.*;
import javax.net.ServerSocketFactory; import javax.net.ServerSocketFactory;
import sun.net.www.*; import sun.net.www.*;
import java.util.Base64;
public class ProxyTunnelServer extends Thread { public class ProxyTunnelServer extends Thread {
...@@ -296,10 +297,9 @@ public class ProxyTunnelServer extends Thread { ...@@ -296,10 +297,9 @@ public class ProxyTunnelServer extends Thread {
String recvdUserPlusPass = authInfo.substring(ind + 1).trim(); String recvdUserPlusPass = authInfo.substring(ind + 1).trim();
// extract encoded (username:passwd // extract encoded (username:passwd
if (userPlusPass.equals( if (userPlusPass.equals(
new String( new String( Base64.getMimeDecoder()
(new sun.misc.BASE64Decoder()). .decode(recvdUserPlusPass))))
decodeBuffer(recvdUserPlusPass) {
))) {
matched = true; matched = true;
} }
} catch (Exception e) { } catch (Exception e) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册