Skip to content
This repository was archived by the owner on Feb 2, 2023. It is now read-only.

Commit 79497f6

Browse files
author
Alexey Bakhtin
committed
8269039: Disable SHA-1 Signed JARs
Reviewed-by: yan Backport-of: 6d91a3eb7bd1e1403cfb67f7eb8ce06d7e08e7a7
1 parent d9202d6 commit 79497f6

File tree

25 files changed

+416
-330
lines changed

25 files changed

+416
-330
lines changed

src/java.base/share/classes/module-info.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,8 @@
288288
jdk.crypto.cryptoki,
289289
jdk.security.auth;
290290
exports sun.security.provider.certpath to
291-
java.naming;
291+
java.naming,
292+
jdk.jartool;
292293
exports sun.security.rsa to
293294
jdk.crypto.cryptoki;
294295
exports sun.security.timestamp to

src/java.base/share/classes/sun/security/provider/certpath/AlgorithmChecker.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2009, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2009, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -131,7 +131,7 @@ public AlgorithmChecker(AlgorithmConstraints constraints, String variant) {
131131
* certificate
132132
* @param constraints the algorithm constraints (or null)
133133
* @param date the date specified by the PKIXParameters date, or the
134-
* JAR timestamp if jar files are being validated and the
134+
* timestamp if JAR files are being validated and the
135135
* JAR is timestamped. May be null if no timestamp or
136136
* PKIXParameter date is set.
137137
* @param variant the Validator variant of the operation. A null value
@@ -160,17 +160,19 @@ public AlgorithmChecker(TrustAnchor anchor,
160160

161161
/**
162162
* Create a new {@code AlgorithmChecker} with the given {@code TrustAnchor},
163-
* {@code PKIXParameter} date, and {@code varient}
163+
* {@code PKIXParameter} date, and {@code variant}.
164164
*
165165
* @param anchor the trust anchor selected to validate the target
166166
* certificate
167-
* @param pkixdate Date the constraints are checked against. The value is
168-
* either the PKIXParameters date or null for the current date.
167+
* @param date the date specified by the PKIXParameters date, or the
168+
* timestamp if JAR files are being validated and the
169+
* JAR is timestamped. May be null if no timestamp or
170+
* PKIXParameter date is set.
169171
* @param variant the Validator variant of the operation. A null value
170172
* passed will set it to Validator.GENERIC.
171173
*/
172-
public AlgorithmChecker(TrustAnchor anchor, Date pkixdate, String variant) {
173-
this(anchor, certPathDefaultConstraints, pkixdate, variant);
174+
public AlgorithmChecker(TrustAnchor anchor, Date date, String variant) {
175+
this(anchor, certPathDefaultConstraints, date, variant);
174176
}
175177

176178
@Override

src/java.base/share/classes/sun/security/provider/certpath/CertPathConstraintsParameters.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2020, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -39,7 +39,7 @@
3939
* constraints specified in the jdk.certpath.disabledAlgorithms security
4040
* property.
4141
*/
42-
class CertPathConstraintsParameters implements ConstraintsParameters {
42+
public class CertPathConstraintsParameters implements ConstraintsParameters {
4343
// The public key of the certificate
4444
private final Key key;
4545
// The certificate's trust anchor which will be checked against the
@@ -103,7 +103,7 @@ public String extendedExceptionMsg() {
103103
@Override
104104
public String toString() {
105105
StringBuilder sb = new StringBuilder("[\n");
106-
sb.append("\n Variant: ").append(variant);
106+
sb.append(" Variant: ").append(variant);
107107
if (anchor != null) {
108108
sb.append("\n Anchor: ").append(anchor);
109109
}

src/java.base/share/classes/sun/security/provider/certpath/PKIX.java

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ static class ValidatorParams {
8888
private Set<TrustAnchor> anchors;
8989
private List<X509Certificate> certs;
9090
private Timestamp timestamp;
91+
private Date timestampDate;
9192
private String variant = Validator.VAR_GENERIC;
9293

9394
ValidatorParams(CertPath cp, PKIXParameters params)
@@ -154,10 +155,20 @@ List<CertStore> certStores() {
154155
stores = params.getCertStores();
155156
return stores;
156157
}
158+
// The date() param is used when enforcing the validity period
159+
// of certificates and when checking the time period of revocation data.
160+
// The main difference between the date() and timestamp() method is
161+
// that the date() method only uses the timestamp (if specified)
162+
// for certificates in a code signer's chain.
157163
Date date() {
158164
if (!gotDate) {
159-
// use timestamp if checking signed code that is
160-
// timestamped, otherwise use date parameter
165+
// Use timestamp if checking signed code that is
166+
// timestamped, otherwise use date parameter.
167+
// Note that TSA server certificates do not use the
168+
// timestamp, which means that an expired TSA certificate
169+
// is considered a validation failure. This policy means
170+
// that signed and timestamped code is valid until the TSA
171+
// certificate expires (assuming all other checks are valid).
161172
if (timestamp != null &&
162173
(variant.equals(Validator.VAR_CODE_SIGNING) ||
163174
variant.equals(Validator.VAR_PLUGIN_CODE_SIGNING))) {
@@ -210,6 +221,17 @@ PKIXParameters getPKIXParameters() {
210221
String variant() {
211222
return variant;
212223
}
224+
// The timestamp() param is passed as the date param when creating an
225+
// AlgorithmChecker. An AlgorithmChecker always uses the timestamp
226+
// if specified in order to enforce the denyAfter constraint.
227+
Date timestamp() {
228+
// return timestamp date if set, otherwise use date parameter
229+
if (timestampDate == null) {
230+
timestampDate = (timestamp != null)
231+
? timestamp.getTimestamp() : date();
232+
}
233+
return timestampDate;
234+
}
213235
}
214236

215237
static class BuilderParams extends ValidatorParams {

src/java.base/share/classes/sun/security/provider/certpath/PKIXCertPathValidator.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2000, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -176,8 +176,8 @@ private static PKIXCertPathValidatorResult validate(TrustAnchor anchor,
176176
List<PKIXCertPathChecker> certPathCheckers = new ArrayList<>();
177177
// add standard checkers that we will be using
178178
certPathCheckers.add(untrustedChecker);
179-
certPathCheckers.add(new AlgorithmChecker(anchor, null, params.date(),
180-
params.variant()));
179+
certPathCheckers.add(new AlgorithmChecker(anchor, null,
180+
params.timestamp(), params.variant()));
181181
certPathCheckers.add(new KeyChecker(certPathLen,
182182
params.targetCertConstraints()));
183183
certPathCheckers.add(new ConstraintsChecker(certPathLen));

src/java.base/share/classes/sun/security/provider/certpath/SunCertPathBuilder.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2000, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -344,7 +344,7 @@ private void depthFirstSearchForward(X500Principal dN,
344344

345345
// add the algorithm checker
346346
checkers.add(new AlgorithmChecker(builder.trustAnchor,
347-
buildParams.date(), buildParams.variant()));
347+
buildParams.timestamp(), buildParams.variant()));
348348

349349
BasicChecker basicChecker = null;
350350
if (nextState.keyParamsNeeded()) {

src/java.base/share/classes/sun/security/util/DisabledAlgorithmConstraints.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
import java.security.spec.MGF1ParameterSpec;
4040
import java.security.spec.NamedParameterSpec;
4141
import java.security.spec.PSSParameterSpec;
42-
import java.text.SimpleDateFormat;
4342
import java.util.ArrayList;
4443
import java.util.Arrays;
4544
import java.util.Calendar;
@@ -683,8 +682,6 @@ public void permits(ConstraintsParameters cp)
683682
*/
684683
private static class DenyAfterConstraint extends Constraint {
685684
private Date denyAfterDate;
686-
private static final SimpleDateFormat dateFormat =
687-
new SimpleDateFormat("EEE, MMM d HH:mm:ss z yyyy");
688685

689686
DenyAfterConstraint(String algo, int year, int month, int day) {
690687
Calendar c;
@@ -718,7 +715,7 @@ private static class DenyAfterConstraint extends Constraint {
718715
denyAfterDate = c.getTime();
719716
if (debug != null) {
720717
debug.println("DenyAfterConstraint date set to: " +
721-
dateFormat.format(denyAfterDate));
718+
denyAfterDate);
722719
}
723720
}
724721

@@ -749,8 +746,8 @@ public void permits(ConstraintsParameters cp)
749746
throw new CertPathValidatorException(
750747
"denyAfter constraint check failed: " + algorithm +
751748
" used with Constraint date: " +
752-
dateFormat.format(denyAfterDate) + "; params date: " +
753-
dateFormat.format(currentDate) + cp.extendedExceptionMsg(),
749+
denyAfterDate + "; params date: " +
750+
currentDate + cp.extendedExceptionMsg(),
754751
null, null, -1, BasicReason.ALGORITHM_CONSTRAINED);
755752
}
756753
}

src/java.base/share/classes/sun/security/util/JarConstraintsParameters.java

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2020, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -50,9 +50,9 @@ public class JarConstraintsParameters implements ConstraintsParameters {
5050
private boolean anchorIsJdkCASet;
5151
// The timestamp of the signed JAR file, if timestamped
5252
private Date timestamp;
53-
// The keys of the signers
53+
// The keys of the signers and TSA
5454
private final Set<Key> keys;
55-
// The certs in the signers' chains that are issued by the trust anchor
55+
// The certs in the signers and TSA chain that are issued by the trust anchor
5656
private final Set<X509Certificate> certsIssuedByAnchor;
5757
// The extended exception message
5858
private String message;
@@ -73,7 +73,7 @@ public JarConstraintsParameters(CodeSigner[] signers) {
7373
// used for checking if the signer's certificate chains back to a
7474
// JDK root CA
7575
for (CodeSigner signer : signers) {
76-
init(signer.getSignerCertPath());
76+
addToCertsAndKeys(signer.getSignerCertPath());
7777
Timestamp timestamp = signer.getTimestamp();
7878
if (timestamp == null) {
7979
// this means one of the signers doesn't have a timestamp
@@ -82,7 +82,7 @@ public JarConstraintsParameters(CodeSigner[] signers) {
8282
skipTimestamp = true;
8383
} else {
8484
// add the key and last cert of TSA too
85-
init(timestamp.getSignerCertPath());
85+
addToCertsAndKeys(timestamp.getSignerCertPath());
8686
if (!skipTimestamp) {
8787
Date timestampDate = timestamp.getTimestamp();
8888
if (latestTimestamp == null) {
@@ -98,11 +98,27 @@ public JarConstraintsParameters(CodeSigner[] signers) {
9898
this.timestamp = latestTimestamp;
9999
}
100100

101-
// extract last certificate and key from chain
102-
private void init(CertPath cp) {
101+
public JarConstraintsParameters(List<X509Certificate> chain, Timestamp timestamp) {
102+
this.keys = new HashSet<>();
103+
this.certsIssuedByAnchor = new HashSet<>();
104+
addToCertsAndKeys(chain);
105+
if (timestamp != null) {
106+
addToCertsAndKeys(timestamp.getSignerCertPath());
107+
this.timestamp = timestamp.getTimestamp();
108+
} else {
109+
this.timestamp = null;
110+
}
111+
}
112+
113+
// extract last certificate and signer's public key from chain
114+
private void addToCertsAndKeys(CertPath cp) {
103115
@SuppressWarnings("unchecked")
104116
List<X509Certificate> chain =
105117
(List<X509Certificate>)cp.getCertificates();
118+
addToCertsAndKeys(chain);
119+
}
120+
121+
private void addToCertsAndKeys(List<X509Certificate> chain) {
106122
if (!chain.isEmpty()) {
107123
this.certsIssuedByAnchor.add(chain.get(chain.size() - 1));
108124
this.keys.add(chain.get(0).getPublicKey());
@@ -168,7 +184,7 @@ public String extendedExceptionMsg() {
168184
@Override
169185
public String toString() {
170186
StringBuilder sb = new StringBuilder("[\n");
171-
sb.append("\n Variant: ").append(getVariant());
187+
sb.append(" Variant: ").append(getVariant());
172188
sb.append("\n Certs Issued by Anchor:");
173189
for (X509Certificate cert : certsIssuedByAnchor) {
174190
sb.append("\n Cert Issuer: ")

src/java.base/share/conf/security/java.security

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,7 @@ jdk.disabled.namedCurves = secp112r1, secp112r2, secp128r1, secp128r2, \
575575
# can be included in the disabledAlgorithms properties. These properties are
576576
# to help manage common actions easier across multiple disabledAlgorithm
577577
# properties.
578-
# There is one defined security property: jdk.disabled.NamedCurves
578+
# There is one defined security property: jdk.disabled.namedCurves
579579
# See the property for more specific details.
580580
#
581581
#
@@ -652,6 +652,7 @@ jdk.disabled.namedCurves = secp112r1, secp112r2, secp128r1, secp128r2, \
652652
#
653653
jdk.certpath.disabledAlgorithms=MD2, MD5, SHA1 jdkCA & usage TLSServer, \
654654
RSA keySize < 1024, DSA keySize < 1024, EC keySize < 224, \
655+
SHA1 usage SignedJAR & denyAfter 2019-01-01, \
655656
include jdk.disabled.namedCurves
656657

657658
#
@@ -716,7 +717,8 @@ jdk.security.legacyAlgorithms=SHA1, \
716717
# See "jdk.certpath.disabledAlgorithms" for syntax descriptions.
717718
#
718719
jdk.jar.disabledAlgorithms=MD2, MD5, RSA keySize < 1024, \
719-
DSA keySize < 1024, include jdk.disabled.namedCurves
720+
DSA keySize < 1024, SHA1 denyAfter 2019-01-01, \
721+
include jdk.disabled.namedCurves
720722

721723
#
722724
# Algorithm restrictions for Secure Socket Layer/Transport Layer Security

0 commit comments

Comments
 (0)