Skip to content

Commit c501bfa

Browse files
author
Alexey Bakhtin
committed
8269039: Disable SHA-1 Signed JARs
Reviewed-by: mbalao Backport-of: 6d91a3eb7bd1e1403cfb67f7eb8ce06d7e08e7a7
1 parent 5a32484 commit c501bfa

File tree

29 files changed

+442
-342
lines changed

29 files changed

+442
-342
lines changed

jdk/src/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

jdk/src/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
@@ -40,7 +40,7 @@
4040
* constraints specified in the jdk.certpath.disabledAlgorithms security
4141
* property.
4242
*/
43-
class CertPathConstraintsParameters implements ConstraintsParameters {
43+
public class CertPathConstraintsParameters implements ConstraintsParameters {
4444
// The public key of the certificate
4545
private final Key key;
4646
// The certificate's trust anchor which will be checked against the
@@ -105,7 +105,7 @@ public String extendedExceptionMsg() {
105105
@Override
106106
public String toString() {
107107
StringBuilder sb = new StringBuilder("[\n");
108-
sb.append("\n Variant: ").append(variant);
108+
sb.append(" Variant: ").append(variant);
109109
if (anchor != null) {
110110
sb.append("\n Anchor: ").append(anchor);
111111
}

jdk/src/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 {

jdk/src/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
@@ -172,8 +172,8 @@ private static PKIXCertPathValidatorResult validate(TrustAnchor anchor,
172172
List<PKIXCertPathChecker> certPathCheckers = new ArrayList<>();
173173
// add standard checkers that we will be using
174174
certPathCheckers.add(untrustedChecker);
175-
certPathCheckers.add(new AlgorithmChecker(anchor, null, params.date(),
176-
params.variant()));
175+
certPathCheckers.add(new AlgorithmChecker(anchor, null,
176+
params.timestamp(), params.variant()));
177177
certPathCheckers.add(new KeyChecker(certPathLen,
178178
params.targetCertConstraints()));
179179
certPathCheckers.add(new ConstraintsChecker(certPathLen));

jdk/src/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()) {

0 commit comments

Comments
 (0)