aboutsummaryrefslogtreecommitdiff
path: root/src/share/classes/sun
diff options
context:
space:
mode:
Diffstat (limited to 'src/share/classes/sun')
-rw-r--r--src/share/classes/sun/security/krb5/Config.java6
-rw-r--r--src/share/classes/sun/security/pkcs12/PKCS12KeyStore.java29
-rw-r--r--src/share/classes/sun/security/provider/certpath/DistributionPointFetcher.java23
-rw-r--r--src/share/classes/sun/security/rsa/RSACore.java28
-rw-r--r--src/share/classes/sun/security/rsa/RSASignature.java4
-rw-r--r--src/share/classes/sun/security/ssl/ClientHandshaker.java4
-rw-r--r--src/share/classes/sun/security/ssl/Handshaker.java10
-rw-r--r--src/share/classes/sun/security/util/HostnameChecker.java13
-rw-r--r--src/share/classes/sun/security/x509/KeyUsageExtension.java70
-rw-r--r--src/share/classes/sun/security/x509/NetscapeCertTypeExtension.java52
-rw-r--r--src/share/classes/sun/security/x509/ReasonFlags.java54
-rw-r--r--src/share/classes/sun/tools/jar/Main.java83
-rw-r--r--src/share/classes/sun/tools/jar/resources/jar.properties3
-rw-r--r--src/share/classes/sun/util/resources/TimeZoneNames.java4
-rw-r--r--src/share/classes/sun/util/resources/de/TimeZoneNames_de.java4
-rw-r--r--src/share/classes/sun/util/resources/es/TimeZoneNames_es.java4
-rw-r--r--src/share/classes/sun/util/resources/fr/TimeZoneNames_fr.java4
-rw-r--r--src/share/classes/sun/util/resources/it/TimeZoneNames_it.java4
-rw-r--r--src/share/classes/sun/util/resources/ja/TimeZoneNames_ja.java4
-rw-r--r--src/share/classes/sun/util/resources/ko/TimeZoneNames_ko.java4
-rw-r--r--src/share/classes/sun/util/resources/pt/TimeZoneNames_pt_BR.java4
-rw-r--r--src/share/classes/sun/util/resources/sv/TimeZoneNames_sv.java4
-rw-r--r--src/share/classes/sun/util/resources/zh/TimeZoneNames_zh_CN.java4
-rw-r--r--src/share/classes/sun/util/resources/zh/TimeZoneNames_zh_TW.java4
24 files changed, 285 insertions, 138 deletions
diff --git a/src/share/classes/sun/security/krb5/Config.java b/src/share/classes/sun/security/krb5/Config.java
index 3b108622b..48e4e91a2 100644
--- a/src/share/classes/sun/security/krb5/Config.java
+++ b/src/share/classes/sun/security/krb5/Config.java
@@ -763,9 +763,9 @@ public class Config {
private static String trimmed(String s) {
s = s.trim();
- if (s.isEmpty()) return s;
- if (s.charAt(0) == '"' && s.charAt(s.length()-1) == '"' ||
- s.charAt(0) == '\'' && s.charAt(s.length()-1) == '\'') {
+ if (s.length() >= 2 &&
+ ((s.charAt(0) == '"' && s.charAt(s.length()-1) == '"') ||
+ (s.charAt(0) == '\'' && s.charAt(s.length()-1) == '\''))) {
s = s.substring(1, s.length()-1).trim();
}
return s;
diff --git a/src/share/classes/sun/security/pkcs12/PKCS12KeyStore.java b/src/share/classes/sun/security/pkcs12/PKCS12KeyStore.java
index 35564498c..bdedcd091 100644
--- a/src/share/classes/sun/security/pkcs12/PKCS12KeyStore.java
+++ b/src/share/classes/sun/security/pkcs12/PKCS12KeyStore.java
@@ -707,6 +707,11 @@ public final class PKCS12KeyStore extends KeyStoreSpi {
entry.protectedPrivKey = key.clone();
if (chain != null) {
+ // validate cert-chain
+ if ((chain.length > 1) && (!validateChain(chain))) {
+ throw new KeyStoreException("Certificate chain is "
+ + "not valid");
+ }
entry.chain = chain.clone();
certificateCount += chain.length;
@@ -1448,7 +1453,12 @@ public final class PKCS12KeyStore extends KeyStoreSpi {
if (!(issuerDN.equals(subjectDN)))
return false;
}
- return true;
+
+ // Check for loops in the chain. If there are repeated certs,
+ // the Set of certs in the chain will contain fewer certs than
+ // the chain
+ Set<Certificate> set = new HashSet<>(Arrays.asList(certChain));
+ return set.size() == certChain.length;
}
@@ -2022,7 +2032,24 @@ public final class PKCS12KeyStore extends KeyStoreSpi {
ArrayList<X509Certificate> chain =
new ArrayList<X509Certificate>();
X509Certificate cert = findMatchedCertificate(entry);
+
+ mainloop:
while (cert != null) {
+ // Check for loops in the certificate chain
+ if (!chain.isEmpty()) {
+ for (X509Certificate chainCert : chain) {
+ if (cert.equals(chainCert)) {
+ if (debug != null) {
+ debug.println("Loop detected in " +
+ "certificate chain. Skip adding " +
+ "repeated cert to chain. Subject: " +
+ cert.getSubjectX500Principal()
+ .toString());
+ }
+ break mainloop;
+ }
+ }
+ }
chain.add(cert);
X500Principal issuerDN = cert.getIssuerX500Principal();
if (issuerDN.equals(cert.getSubjectX500Principal())) {
diff --git a/src/share/classes/sun/security/provider/certpath/DistributionPointFetcher.java b/src/share/classes/sun/security/provider/certpath/DistributionPointFetcher.java
index 7f275fb80..8ce107618 100644
--- a/src/share/classes/sun/security/provider/certpath/DistributionPointFetcher.java
+++ b/src/share/classes/sun/security/provider/certpath/DistributionPointFetcher.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2002, 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2002, 2015, 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
@@ -541,10 +541,10 @@ public class DistributionPointFetcher {
// set interim reasons mask to the intersection of
// reasons in the DP and onlySomeReasons in the IDP
boolean[] idpReasonFlags = reasons.getFlags();
- for (int i = 0; i < idpReasonFlags.length; i++) {
- if (idpReasonFlags[i] && pointReasonFlags[i]) {
- interimReasonsMask[i] = true;
- }
+ for (int i = 0; i < interimReasonsMask.length; i++) {
+ interimReasonsMask[i] =
+ (i < idpReasonFlags.length && idpReasonFlags[i]) &&
+ (i < pointReasonFlags.length && pointReasonFlags[i]);
}
} else {
// set interim reasons mask to the value of
@@ -558,7 +558,6 @@ public class DistributionPointFetcher {
interimReasonsMask = pointReasonFlags.clone();
} else {
// set interim reasons mask to the special value all-reasons
- interimReasonsMask = new boolean[9];
Arrays.fill(interimReasonsMask, true);
}
}
@@ -567,7 +566,9 @@ public class DistributionPointFetcher {
// not included in the reasons mask
boolean oneOrMore = false;
for (int i = 0; i < interimReasonsMask.length && !oneOrMore; i++) {
- if (!reasonsMask[i] && interimReasonsMask[i]) {
+ if (interimReasonsMask[i] &&
+ !(i < reasonsMask.length && reasonsMask[i]))
+ {
oneOrMore = true;
}
}
@@ -693,11 +694,11 @@ public class DistributionPointFetcher {
}
// update reasonsMask
- for (int i = 0; i < interimReasonsMask.length; i++) {
- if (!reasonsMask[i] && interimReasonsMask[i]) {
- reasonsMask[i] = true;
- }
+ for (int i = 0; i < reasonsMask.length; i++) {
+ reasonsMask[i] = reasonsMask[i] ||
+ (i < interimReasonsMask.length && interimReasonsMask[i]);
}
+
return true;
}
diff --git a/src/share/classes/sun/security/rsa/RSACore.java b/src/share/classes/sun/security/rsa/RSACore.java
index 81b4e3f98..7e933e5b7 100644
--- a/src/share/classes/sun/security/rsa/RSACore.java
+++ b/src/share/classes/sun/security/rsa/RSACore.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003, 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2015, 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
@@ -102,12 +102,24 @@ public final class RSACore {
/**
* Perform an RSA private key operation. Uses CRT if the key is a
- * CRT key.
+ * CRT key with additional verification check after the signature
+ * is computed.
*/
+ @Deprecated
public static byte[] rsa(byte[] msg, RSAPrivateKey key)
throws BadPaddingException {
+ return rsa(msg, key, true);
+ }
+
+ /**
+ * Perform an RSA private key operation. Uses CRT if the key is a
+ * CRT key. Set 'verify' to true if this function is used for
+ * generating a signature.
+ */
+ public static byte[] rsa(byte[] msg, RSAPrivateKey key, boolean verify)
+ throws BadPaddingException {
if (key instanceof RSAPrivateCrtKey) {
- return crtCrypt(msg, (RSAPrivateCrtKey)key);
+ return crtCrypt(msg, (RSAPrivateCrtKey)key, verify);
} else {
return priCrypt(msg, key.getModulus(), key.getPrivateExponent());
}
@@ -148,10 +160,11 @@ public final class RSACore {
* RSA private key operations with CRT. Algorithm and variable naming
* are taken from PKCS#1 v2.1, section 5.1.2.
*/
- private static byte[] crtCrypt(byte[] msg, RSAPrivateCrtKey key)
- throws BadPaddingException {
+ private static byte[] crtCrypt(byte[] msg, RSAPrivateCrtKey key,
+ boolean verify) throws BadPaddingException {
BigInteger n = key.getModulus();
- BigInteger c = parseMsg(msg, n);
+ BigInteger c0 = parseMsg(msg, n);
+ BigInteger c = c0;
BigInteger p = key.getPrimeP();
BigInteger q = key.getPrimeQ();
BigInteger dP = key.getPrimeExponentP();
@@ -184,6 +197,9 @@ public final class RSACore {
if (ENABLE_BLINDING) {
m = m.multiply(brp.v).mod(n);
}
+ if (verify && !c0.equals(m.modPow(e, n))) {
+ throw new BadPaddingException("RSA private key operation failed");
+ }
return toByteArray(m, getByteLength(n));
}
diff --git a/src/share/classes/sun/security/rsa/RSASignature.java b/src/share/classes/sun/security/rsa/RSASignature.java
index 959700f22..d5ba1f826 100644
--- a/src/share/classes/sun/security/rsa/RSASignature.java
+++ b/src/share/classes/sun/security/rsa/RSASignature.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2015, 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
@@ -173,7 +173,7 @@ public abstract class RSASignature extends SignatureSpi {
try {
byte[] encoded = encodeSignature(digestOID, digest);
byte[] padded = padding.pad(encoded);
- byte[] encrypted = RSACore.rsa(padded, privateKey);
+ byte[] encrypted = RSACore.rsa(padded, privateKey, true);
return encrypted;
} catch (GeneralSecurityException e) {
throw new SignatureException("Could not sign data", e);
diff --git a/src/share/classes/sun/security/ssl/ClientHandshaker.java b/src/share/classes/sun/security/ssl/ClientHandshaker.java
index 5e253a782..36afca62d 100644
--- a/src/share/classes/sun/security/ssl/ClientHandshaker.java
+++ b/src/share/classes/sun/security/ssl/ClientHandshaker.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1996, 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1996, 2015, 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
@@ -289,7 +289,7 @@ final class ClientHandshaker extends Handshaker {
case K_ECDH_RSA:
throw new SSLProtocolException(
"Protocol violation: server sent a server key exchange"
- + "message for key exchange " + keyExchange);
+ + " message for key exchange " + keyExchange);
case K_KRB5:
case K_KRB5_EXPORT:
throw new SSLProtocolException(
diff --git a/src/share/classes/sun/security/ssl/Handshaker.java b/src/share/classes/sun/security/ssl/Handshaker.java
index 278a75824..6cb8d7e59 100644
--- a/src/share/classes/sun/security/ssl/Handshaker.java
+++ b/src/share/classes/sun/security/ssl/Handshaker.java
@@ -697,6 +697,16 @@ abstract class Handshaker {
continue;
}
+ if (!algorithmConstraints.permits(
+ EnumSet.of(CryptoPrimitive.KEY_AGREEMENT),
+ protocol.name, null)) {
+ if (debug != null && Debug.isOn("verbose")) {
+ System.out.println(
+ "Ignoring disabled protocol: " + protocol);
+ }
+
+ continue;
+ }
boolean found = false;
for (CipherSuite suite : enabledCipherSuites.collection()) {
if (suite.isAvailable() && suite.obsoleted > protocol.v &&
diff --git a/src/share/classes/sun/security/util/HostnameChecker.java b/src/share/classes/sun/security/util/HostnameChecker.java
index 77f17f71a..0741b2eda 100644
--- a/src/share/classes/sun/security/util/HostnameChecker.java
+++ b/src/share/classes/sun/security/util/HostnameChecker.java
@@ -26,6 +26,8 @@
package sun.security.util;
import java.io.IOException;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
import java.util.*;
import java.security.Principal;
@@ -148,6 +150,17 @@ public class HostnameChecker {
String ipAddress = (String)next.get(1);
if (expectedIP.equalsIgnoreCase(ipAddress)) {
return;
+ } else {
+ // compare InetAddress objects in order to ensure
+ // equality between a long IPv6 address and its
+ // abbreviated form.
+ try {
+ if (InetAddress.getByName(expectedIP).equals(
+ InetAddress.getByName(ipAddress))) {
+ return;
+ }
+ } catch (UnknownHostException e) {
+ } catch (SecurityException e) {}
}
}
}
diff --git a/src/share/classes/sun/security/x509/KeyUsageExtension.java b/src/share/classes/sun/security/x509/KeyUsageExtension.java
index 0f1242d63..f02d8eeb6 100644
--- a/src/share/classes/sun/security/x509/KeyUsageExtension.java
+++ b/src/share/classes/sun/security/x509/KeyUsageExtension.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2015, 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
@@ -83,7 +83,8 @@ implements CertAttrSet<String> {
* @param position the position in the bit string to check.
*/
private boolean isSet(int position) {
- return bitString[position];
+ return (position < bitString.length) &&
+ bitString[position];
}
/**
@@ -275,41 +276,40 @@ implements CertAttrSet<String> {
* Returns a printable representation of the KeyUsage.
*/
public String toString() {
- String s = super.toString() + "KeyUsage [\n";
+ StringBuilder sb = new StringBuilder();
+ sb.append(super.toString());
+ sb.append("KeyUsage [\n");
- try {
- if (isSet(0)) {
- s += " DigitalSignature\n";
- }
- if (isSet(1)) {
- s += " Non_repudiation\n";
- }
- if (isSet(2)) {
- s += " Key_Encipherment\n";
- }
- if (isSet(3)) {
- s += " Data_Encipherment\n";
- }
- if (isSet(4)) {
- s += " Key_Agreement\n";
- }
- if (isSet(5)) {
- s += " Key_CertSign\n";
- }
- if (isSet(6)) {
- s += " Crl_Sign\n";
- }
- if (isSet(7)) {
- s += " Encipher_Only\n";
- }
- if (isSet(8)) {
- s += " Decipher_Only\n";
- }
- } catch (ArrayIndexOutOfBoundsException ex) {}
-
- s += "]\n";
+ if (isSet(0)) {
+ sb.append(" DigitalSignature\n");
+ }
+ if (isSet(1)) {
+ sb.append(" Non_repudiation\n");
+ }
+ if (isSet(2)) {
+ sb.append(" Key_Encipherment\n");
+ }
+ if (isSet(3)) {
+ sb.append(" Data_Encipherment\n");
+ }
+ if (isSet(4)) {
+ sb.append(" Key_Agreement\n");
+ }
+ if (isSet(5)) {
+ sb.append(" Key_CertSign\n");
+ }
+ if (isSet(6)) {
+ sb.append(" Crl_Sign\n");
+ }
+ if (isSet(7)) {
+ sb.append(" Encipher_Only\n");
+ }
+ if (isSet(8)) {
+ sb.append(" Decipher_Only\n");
+ }
+ sb.append("]\n");
- return (s);
+ return sb.toString();
}
/**
diff --git a/src/share/classes/sun/security/x509/NetscapeCertTypeExtension.java b/src/share/classes/sun/security/x509/NetscapeCertTypeExtension.java
index d6d4efd34..735efddfc 100644
--- a/src/share/classes/sun/security/x509/NetscapeCertTypeExtension.java
+++ b/src/share/classes/sun/security/x509/NetscapeCertTypeExtension.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1998, 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 2015, 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
@@ -136,7 +136,8 @@ implements CertAttrSet<String> {
* @param position the position in the bit string to check.
*/
private boolean isSet(int position) {
- return bitString[position];
+ return (position < bitString.length) &&
+ bitString[position];
}
/**
@@ -236,27 +237,34 @@ implements CertAttrSet<String> {
* Returns a printable representation of the NetscapeCertType.
*/
public String toString() {
- String s = super.toString() + "NetscapeCertType [\n";
+ StringBuilder sb = new StringBuilder();
+ sb.append(super.toString());
+ sb.append("NetscapeCertType [\n");
- try {
- if (isSet(getPosition(SSL_CLIENT)))
- s += " SSL client\n";
- if (isSet(getPosition(SSL_SERVER)))
- s += " SSL server\n";
- if (isSet(getPosition(S_MIME)))
- s += " S/MIME\n";
- if (isSet(getPosition(OBJECT_SIGNING)))
- s += " Object Signing\n";
- if (isSet(getPosition(SSL_CA)))
- s += " SSL CA\n";
- if (isSet(getPosition(S_MIME_CA)))
- s += " S/MIME CA\n";
- if (isSet(getPosition(OBJECT_SIGNING_CA)))
- s += " Object Signing CA" ;
- } catch (Exception e) { }
-
- s += "]\n";
- return (s);
+ if (isSet(0)) {
+ sb.append(" SSL client\n");
+ }
+ if (isSet(1)) {
+ sb.append(" SSL server\n");
+ }
+ if (isSet(2)) {
+ sb.append(" S/MIME\n");
+ }
+ if (isSet(3)) {
+ sb.append(" Object Signing\n");
+ }
+ if (isSet(5)) {
+ sb.append(" SSL CA\n");
+ }
+ if (isSet(6)) {
+ sb.append(" S/MIME CA\n");
+ }
+ if (isSet(7)) {
+ sb.append(" Object Signing CA");
+ }
+
+ sb.append("]\n");
+ return sb.toString();
}
/**
diff --git a/src/share/classes/sun/security/x509/ReasonFlags.java b/src/share/classes/sun/security/x509/ReasonFlags.java
index 4549ad454..6a4204620 100644
--- a/src/share/classes/sun/security/x509/ReasonFlags.java
+++ b/src/share/classes/sun/security/x509/ReasonFlags.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1997, 2006, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2015, 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
@@ -99,7 +99,8 @@ public class ReasonFlags {
* @param position the position in the bit string to check.
*/
private boolean isSet(int position) {
- return bitString[position];
+ return (position < bitString.length) &&
+ bitString[position];
}
/**
@@ -199,23 +200,38 @@ public class ReasonFlags {
* Returns a printable representation of the ReasonFlags.
*/
public String toString() {
- String s = "Reason Flags [\n";
-
- try {
- if (isSet(0)) s += " Unused\n";
- if (isSet(1)) s += " Key Compromise\n";
- if (isSet(2)) s += " CA Compromise\n";
- if (isSet(3)) s += " Affiliation_Changed\n";
- if (isSet(4)) s += " Superseded\n";
- if (isSet(5)) s += " Cessation Of Operation\n";
- if (isSet(6)) s += " Certificate Hold\n";
- if (isSet(7)) s += " Privilege Withdrawn\n";
- if (isSet(8)) s += " AA Compromise\n";
- } catch (ArrayIndexOutOfBoundsException ex) {}
-
- s += "]\n";
-
- return (s);
+ StringBuilder sb = new StringBuilder("Reason Flags [\n");
+
+ if (isSet(0)) {
+ sb.append(" Unused\n");
+ }
+ if (isSet(1)) {
+ sb.append(" Key Compromise\n");
+ }
+ if (isSet(2)) {
+ sb.append(" CA Compromise\n");
+ }
+ if (isSet(3)) {
+ sb.append(" Affiliation_Changed\n");
+ }
+ if (isSet(4)) {
+ sb.append(" Superseded\n");
+ }
+ if (isSet(5)) {
+ sb.append(" Cessation Of Operation\n");
+ }
+ if (isSet(6)) {
+ sb.append(" Certificate Hold\n");
+ }
+ if (isSet(7)) {
+ sb.append(" Privilege Withdrawn\n");
+ }
+ if (isSet(8)) {
+ sb.append(" AA Compromise\n");
+ }
+ sb.append("]\n");
+
+ return sb.toString();
}
/**
diff --git a/src/share/classes/sun/tools/jar/Main.java b/src/share/classes/sun/tools/jar/Main.java
index 607304df3..aab29ad0b 100644
--- a/src/share/classes/sun/tools/jar/Main.java
+++ b/src/share/classes/sun/tools/jar/Main.java
@@ -74,8 +74,10 @@ class Main {
* Mflag: DO NOT generate a manifest file (just ZIP)
* iflag: generate jar index
* nflag: Perform jar normalization at the end
+ * pflag: preserve/don't strip leading slash and .. component from file name
+ *
*/
- boolean cflag, uflag, xflag, tflag, vflag, flag0, Mflag, iflag, nflag;
+ boolean cflag, uflag, xflag, tflag, vflag, flag0, Mflag, iflag, nflag, pflag;
static final String MANIFEST_DIR = "META-INF/";
static final String VERSION = "1.0";
@@ -187,6 +189,7 @@ class Main {
addMainClass(manifest, ename);
}
}
+ expand(null, files, false);
OutputStream out;
if (fname != null) {
out = new FileOutputStream(fname);
@@ -208,13 +211,12 @@ class Main {
tmpfile = createTemporaryFile(tmpbase, ".jar");
out = new FileOutputStream(tmpfile);
}
- expand(null, files, false);
create(new BufferedOutputStream(out, 4096), manifest);
if (in != null) {
in.close();
}
out.close();
- if(nflag) {
+ if (nflag) {
JarFile jarFile = null;
File packFile = null;
JarOutputStream jos = null;
@@ -291,7 +293,7 @@ class Main {
list(fname, files);
} else {
InputStream in = new FileInputStream(FileDescriptor.in);
- try{
+ try {
list(new BufferedInputStream(in), files);
} finally {
in.close();
@@ -410,6 +412,9 @@ class Main {
case 'e':
ename = args[count++];
break;
+ case 'P':
+ pflag = true;
+ break;
default:
error(formatMsg("error.illegal.option",
String.valueOf(flags.charAt(i))));
@@ -662,7 +667,6 @@ class Main {
return updateOk;
}
-
private void addIndex(JarIndex index, ZipOutputStream zos)
throws IOException
{
@@ -699,6 +703,47 @@ class Main {
return true;
}
+ private static final boolean isWinDriveLetter(char c) {
+ return ((c >= 'a') && (c <= 'z')) || ((c >= 'A') && (c <= 'Z'));
+ }
+
+ private String safeName(String name) {
+ if (!pflag) {
+ int len = name.length();
+ int i = name.lastIndexOf("../");
+ if (i == -1) {
+ i = 0;
+ } else {
+ i += 3; // strip any dot-dot components
+ }
+ if (File.separatorChar == '\\') {
+ // the spec requests no drive letter. skip if
+ // the entry name has one.
+ while (i < len) {
+ int off = i;
+ if (i + 1 < len &&
+ name.charAt(i + 1) == ':' &&
+ isWinDriveLetter(name.charAt(i))) {
+ i += 2;
+ }
+ while (i < len && name.charAt(i) == '/') {
+ i++;
+ }
+ if (i == off) {
+ break;
+ }
+ }
+ } else {
+ while (i < len && name.charAt(i) == '/') {
+ i++;
+ }
+ }
+ if (i != 0) {
+ name = name.substring(i);
+ }
+ }
+ return name;
+ }
private String entryName(String name) {
name = name.replace(File.separatorChar, '/');
@@ -710,10 +755,10 @@ class Main {
}
}
name = name.substring(matchPath.length());
-
- if (name.startsWith("/")) {
- name = name.substring(1);
- } else if (name.startsWith("./")) {
+ name = safeName(name);
+ // the old implementaton doesn't remove
+ // "./" if it was led by "/" (?)
+ if (name.startsWith("./")) {
name = name.substring(2);
}
return name;
@@ -913,8 +958,11 @@ class Main {
for (ZipEntry ze : zes) {
long lastModified = ze.getTime();
if (lastModified != -1) {
- File f = new File(ze.getName().replace('/', File.separatorChar));
- f.setLastModified(lastModified);
+ String name = safeName(ze.getName().replace(File.separatorChar, '/'));
+ if (name.length() != 0) {
+ File f = new File(name.replace('/', File.separatorChar));
+ f.setLastModified(lastModified);
+ }
}
}
}
@@ -958,7 +1006,6 @@ class Main {
Enumeration<? extends ZipEntry> zes = zf.entries();
while (zes.hasMoreElements()) {
ZipEntry e = zes.nextElement();
- InputStream is;
if (files == null) {
dirs.add(extractFile(zf.getInputStream(e), e));
} else {
@@ -982,8 +1029,16 @@ class Main {
*/
ZipEntry extractFile(InputStream is, ZipEntry e) throws IOException {
ZipEntry rc = null;
- String name = e.getName();
- File f = new File(e.getName().replace('/', File.separatorChar));
+ // The spec requres all slashes MUST be forward '/', it is possible
+ // an offending zip/jar entry may uses the backwards slash in its
+ // name. It might cause problem on Windows platform as it skips
+ // our "safe" check for leading slahs and dot-dot. So replace them
+ // with '/'.
+ String name = safeName(e.getName().replace(File.separatorChar, '/'));
+ if (name.length() == 0) {
+ return rc; // leading '/' or 'dot-dot' only path
+ }
+ File f = new File(name.replace('/', File.separatorChar));
if (e.isDirectory()) {
if (f.exists()) {
if (!f.isDirectory()) {
diff --git a/src/share/classes/sun/tools/jar/resources/jar.properties b/src/share/classes/sun/tools/jar/resources/jar.properties
index beefbd2dd..3b87385c4 100644
--- a/src/share/classes/sun/tools/jar/resources/jar.properties
+++ b/src/share/classes/sun/tools/jar/resources/jar.properties
@@ -68,7 +68,7 @@ out.size=\
(in = {0}) (out= {1})
usage=\
-Usage: jar {ctxui}[vfmn0Me] [jar-file] [manifest-file] [entry-point] [-C dir] files ...\n\
+Usage: jar {ctxui}[vfmn0PMe] [jar-file] [manifest-file] [entry-point] [-C dir] files ...\n\
Options:\n\
\ \ -c create new archive\n\
\ \ -t list table of contents for archive\n\
@@ -81,6 +81,7 @@ Options:\n\
\ \ -e specify application entry point for stand-alone application \n\
\ \ bundled into an executable jar file\n\
\ \ -0 store only; use no ZIP compression\n\
+\ \ -P preserve leading '/' (absolute path) and ".." (parent directory) components from file names\n\
\ \ -M do not create a manifest file for the entries\n\
\ \ -i generate index information for the specified jar files\n\
\ \ -C change to the specified directory and include the following file\n\
diff --git a/src/share/classes/sun/util/resources/TimeZoneNames.java b/src/share/classes/sun/util/resources/TimeZoneNames.java
index 679a5c100..75efc60e0 100644
--- a/src/share/classes/sun/util/resources/TimeZoneNames.java
+++ b/src/share/classes/sun/util/resources/TimeZoneNames.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1996, 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1996, 2015, 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
@@ -408,7 +408,7 @@ public final class TimeZoneNames extends TimeZoneNamesBundle {
{"America/Buenos_Aires", AGT},
{"America/Cambridge_Bay", MST},
{"America/Campo_Grande", AMT},
- {"America/Cancun", CST},
+ {"America/Cancun", EST},
{"America/Caracas", new String[] {"Venezuela Time", "VET",
"Venezuela Summer Time", "VEST",
"Venezuela Time", "VET"}},
diff --git a/src/share/classes/sun/util/resources/de/TimeZoneNames_de.java b/src/share/classes/sun/util/resources/de/TimeZoneNames_de.java
index 83ba77977..7dd97ebd0 100644
--- a/src/share/classes/sun/util/resources/de/TimeZoneNames_de.java
+++ b/src/share/classes/sun/util/resources/de/TimeZoneNames_de.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2015, 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
@@ -409,7 +409,7 @@ public final class TimeZoneNames_de extends TimeZoneNamesBundle {
{"America/Buenos_Aires", AGT},
{"America/Cambridge_Bay", MST},
{"America/Campo_Grande", AMT},
- {"America/Cancun", CST},
+ {"America/Cancun", EST},
{"America/Caracas", new String[] {"Venezuelanische Zeit", "VET",
"Venezuelanische Sommerzeit", "VEST",
"Venezuelanische Zeit", "VET"}},
diff --git a/src/share/classes/sun/util/resources/es/TimeZoneNames_es.java b/src/share/classes/sun/util/resources/es/TimeZoneNames_es.java
index 2b4726694..99f48b2d9 100644
--- a/src/share/classes/sun/util/resources/es/TimeZoneNames_es.java
+++ b/src/share/classes/sun/util/resources/es/TimeZoneNames_es.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2015, 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
@@ -409,7 +409,7 @@ public final class TimeZoneNames_es extends TimeZoneNamesBundle {
{"America/Buenos_Aires", AGT},
{"America/Cambridge_Bay", MST},
{"America/Campo_Grande", AMT},
- {"America/Cancun", CST},
+ {"America/Cancun", EST},
{"America/Caracas", new String[] {"Hora de Venezuela", "VET",
"Hora de verano de Venezuela", "VEST",
"Hora de Venezuela", "VET"}},
diff --git a/src/share/classes/sun/util/resources/fr/TimeZoneNames_fr.java b/src/share/classes/sun/util/resources/fr/TimeZoneNames_fr.java
index 41aefbdad..9a89c8508 100644
--- a/src/share/classes/sun/util/resources/fr/TimeZoneNames_fr.java
+++ b/src/share/classes/sun/util/resources/fr/TimeZoneNames_fr.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2015, 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
@@ -409,7 +409,7 @@ public final class TimeZoneNames_fr extends TimeZoneNamesBundle {
{"America/Buenos_Aires", AGT},
{"America/Cambridge_Bay", MST},
{"America/Campo_Grande", AMT},
- {"America/Cancun", CST},
+ {"America/Cancun", EST},
{"America/Caracas", new String[] {"Heure du Venezuela", "VET",
"Heure d'\u00e9t\u00e9 du Venezuela", "VEST",
"Heure du Venezuela", "VET"}},
diff --git a/src/share/classes/sun/util/resources/it/TimeZoneNames_it.java b/src/share/classes/sun/util/resources/it/TimeZoneNames_it.java
index 8f350fbf3..b3edb6e42 100644
--- a/src/share/classes/sun/util/resources/it/TimeZoneNames_it.java
+++ b/src/share/classes/sun/util/resources/it/TimeZoneNames_it.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2015, 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
@@ -409,7 +409,7 @@ public final class TimeZoneNames_it extends TimeZoneNamesBundle {
{"America/Buenos_Aires", AGT},
{"America/Cambridge_Bay", MST},
{"America/Campo_Grande", AMT},
- {"America/Cancun", CST},
+ {"America/Cancun", EST},
{"America/Caracas", new String[] {"Ora del Venezuela", "VET",
"Ora estiva del Venezuela", "VEST",
"Ora del Venezuela", "VET"}},
diff --git a/src/share/classes/sun/util/resources/ja/TimeZoneNames_ja.java b/src/share/classes/sun/util/resources/ja/TimeZoneNames_ja.java
index 5ae2aa079..df5d3acbb 100644
--- a/src/share/classes/sun/util/resources/ja/TimeZoneNames_ja.java
+++ b/src/share/classes/sun/util/resources/ja/TimeZoneNames_ja.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2015, 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
@@ -409,7 +409,7 @@ public final class TimeZoneNames_ja extends TimeZoneNamesBundle {
{"America/Buenos_Aires", AGT},
{"America/Cambridge_Bay", MST},
{"America/Campo_Grande", AMT},
- {"America/Cancun", CST},
+ {"America/Cancun", EST},
{"America/Caracas", new String[] {"\u30d9\u30cd\u30ba\u30a8\u30e9\u6642\u9593", "VET",
"\u30d9\u30cd\u30ba\u30a8\u30e9\u590f\u6642\u9593", "VEST",
"\u30D9\u30CD\u30BA\u30A8\u30E9\u6642\u9593", "VET"}},
diff --git a/src/share/classes/sun/util/resources/ko/TimeZoneNames_ko.java b/src/share/classes/sun/util/resources/ko/TimeZoneNames_ko.java
index a35768503..2ef152bab 100644
--- a/src/share/classes/sun/util/resources/ko/TimeZoneNames_ko.java
+++ b/src/share/classes/sun/util/resources/ko/TimeZoneNames_ko.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2015, 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
@@ -409,7 +409,7 @@ public final class TimeZoneNames_ko extends TimeZoneNamesBundle {
{"America/Buenos_Aires", AGT},
{"America/Cambridge_Bay", MST},
{"America/Campo_Grande", AMT},
- {"America/Cancun", CST},
+ {"America/Cancun", EST},
{"America/Caracas", new String[] {"\ubca0\ub124\uc218\uc5d8\ub77c \uc2dc\uac04", "VET",
"\ubca0\ub124\uc218\uc5d8\ub77c \uc77c\uad11\uc808\uc57d\uc2dc\uac04", "VEST",
"\uBCA0\uB124\uC218\uC5D8\uB77C \uD45C\uC900\uC2DC", "VET"}},
diff --git a/src/share/classes/sun/util/resources/pt/TimeZoneNames_pt_BR.java b/src/share/classes/sun/util/resources/pt/TimeZoneNames_pt_BR.java
index 942081c53..9ff7e574c 100644
--- a/src/share/classes/sun/util/resources/pt/TimeZoneNames_pt_BR.java
+++ b/src/share/classes/sun/util/resources/pt/TimeZoneNames_pt_BR.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2015, 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
@@ -409,7 +409,7 @@ public final class TimeZoneNames_pt_BR extends TimeZoneNamesBundle {
{"America/Buenos_Aires", AGT},
{"America/Cambridge_Bay", MST},
{"America/Campo_Grande", AMT},
- {"America/Cancun", CST},
+ {"America/Cancun", EST},
{"America/Caracas", new String[] {"Fuso hor\u00e1rio da Venezuela", "VET",
"Fuso hor\u00e1rio de ver\u00e3o da Venezuela", "VEST",
"Hor\u00E1rio da Venezuela", "VET"}},
diff --git a/src/share/classes/sun/util/resources/sv/TimeZoneNames_sv.java b/src/share/classes/sun/util/resources/sv/TimeZoneNames_sv.java
index bd77d58b8..916c2c5d9 100644
--- a/src/share/classes/sun/util/resources/sv/TimeZoneNames_sv.java
+++ b/src/share/classes/sun/util/resources/sv/TimeZoneNames_sv.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2015, 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
@@ -409,7 +409,7 @@ public final class TimeZoneNames_sv extends TimeZoneNamesBundle {
{"America/Buenos_Aires", AGT},
{"America/Cambridge_Bay", MST},
{"America/Campo_Grande", AMT},
- {"America/Cancun", CST},
+ {"America/Cancun", EST},
{"America/Caracas", new String[] {"Venezuela, normaltid", "VET",
"Venezuela, sommartid", "VEST",
"Venezuelansk tid", "VET"}},
diff --git a/src/share/classes/sun/util/resources/zh/TimeZoneNames_zh_CN.java b/src/share/classes/sun/util/resources/zh/TimeZoneNames_zh_CN.java
index c0590e574..5cb70c85e 100644
--- a/src/share/classes/sun/util/resources/zh/TimeZoneNames_zh_CN.java
+++ b/src/share/classes/sun/util/resources/zh/TimeZoneNames_zh_CN.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2015, 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
@@ -409,7 +409,7 @@ public final class TimeZoneNames_zh_CN extends TimeZoneNamesBundle {
{"America/Buenos_Aires", AGT},
{"America/Cambridge_Bay", MST},
{"America/Campo_Grande", AMT},
- {"America/Cancun", CST},
+ {"America/Cancun", EST},
{"America/Caracas", new String[] {"\u59d4\u5185\u745e\u62c9\u65f6\u95f4", "VET",
"\u59d4\u5185\u745e\u62c9\u590f\u4ee4\u65f6", "VEST",
"\u59D4\u5185\u745E\u62C9\u65F6\u95F4", "VET"}},
diff --git a/src/share/classes/sun/util/resources/zh/TimeZoneNames_zh_TW.java b/src/share/classes/sun/util/resources/zh/TimeZoneNames_zh_TW.java
index 19c332dea..0074f49da 100644
--- a/src/share/classes/sun/util/resources/zh/TimeZoneNames_zh_TW.java
+++ b/src/share/classes/sun/util/resources/zh/TimeZoneNames_zh_TW.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2015, 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
@@ -409,7 +409,7 @@ public final class TimeZoneNames_zh_TW extends TimeZoneNamesBundle {
{"America/Buenos_Aires", AGT},
{"America/Cambridge_Bay", MST},
{"America/Campo_Grande", AMT},
- {"America/Cancun", CST},
+ {"America/Cancun", EST},
{"America/Caracas", new String[] {"\u59d4\u5167\u745e\u62c9\u6642\u9593", "VET",
"\u59d4\u5167\u745e\u62c9\u590f\u4ee4\u6642\u9593", "VEST",
"\u59D4\u5167\u745E\u62C9\u6642\u9593", "VET"}},