提交 ec9ff2a5 编写于 作者: X xuelei

7025073: Stricter check on trust anchor makes VerifyCACerts.java test fail

Summary: loosen the check for version 1 and 2 X.509 certificate
Reviewed-by: mullan, weijun
上级 b7c0645f
...@@ -46,10 +46,16 @@ import sun.security.x509.AuthorityKeyIdentifierExtension; ...@@ -46,10 +46,16 @@ import sun.security.x509.AuthorityKeyIdentifierExtension;
*/ */
class AdaptableX509CertSelector extends X509CertSelector { class AdaptableX509CertSelector extends X509CertSelector {
// The start date of a validity period. // The start date of a validity period.
private Date startDate = null; private Date startDate;
// The end date of a validity period. // The end date of a validity period.
private Date endDate = null; private Date endDate;
// Is subject key identifier sensitive?
private boolean isSKIDSensitive = false;
// Is serial number sensitive?
private boolean isSNSensitive = false;
AdaptableX509CertSelector() { AdaptableX509CertSelector() {
super(); super();
...@@ -97,15 +103,24 @@ class AdaptableX509CertSelector extends X509CertSelector { ...@@ -97,15 +103,24 @@ class AdaptableX509CertSelector extends X509CertSelector {
if (akidext != null) { if (akidext != null) {
KeyIdentifier akid = (KeyIdentifier)akidext.get(akidext.KEY_ID); KeyIdentifier akid = (KeyIdentifier)akidext.get(akidext.KEY_ID);
if (akid != null) { if (akid != null) {
// Do not override the previous setting
if (getSubjectKeyIdentifier() == null) {
DerOutputStream derout = new DerOutputStream(); DerOutputStream derout = new DerOutputStream();
derout.putOctetString(akid.getIdentifier()); derout.putOctetString(akid.getIdentifier());
super.setSubjectKeyIdentifier(derout.toByteArray()); super.setSubjectKeyIdentifier(derout.toByteArray());
isSKIDSensitive = true;
}
} }
SerialNumber asn = SerialNumber asn =
(SerialNumber)akidext.get(akidext.SERIAL_NUMBER); (SerialNumber)akidext.get(akidext.SERIAL_NUMBER);
if (asn != null) { if (asn != null) {
// Do not override the previous setting
if (getSerialNumber() == null) {
super.setSerialNumber(asn.getNumber()); super.setSerialNumber(asn.getNumber());
isSNSensitive = true;
}
} }
// the subject criterion should be set by the caller. // the subject criterion should be set by the caller.
...@@ -148,11 +163,25 @@ class AdaptableX509CertSelector extends X509CertSelector { ...@@ -148,11 +163,25 @@ class AdaptableX509CertSelector extends X509CertSelector {
} }
} }
if (version < 3 || xcert.getExtensionValue("2.5.29.14") == null) {
// If no SubjectKeyIdentifier extension, don't bother to check it. // If no SubjectKeyIdentifier extension, don't bother to check it.
if (isSKIDSensitive &&
(version < 3 || xcert.getExtensionValue("2.5.29.14") == null)) {
setSubjectKeyIdentifier(null); setSubjectKeyIdentifier(null);
} }
// In practice, a CA may replace its root certificate and require that
// the existing certificate is still valid, even if the AKID extension
// does not match the replacement root certificate fields.
//
// Conservatively, we only support the replacement for version 1 and
// version 2 certificate. As for version 2, the certificate extension
// may contain sensitive information (for example, policies), the
// AKID need to be respected to seek the exact certificate in case
// of key or certificate abuse.
if (isSNSensitive && version < 3) {
setSerialNumber(null);
}
return super.match(cert); return super.match(cert);
} }
......
...@@ -243,12 +243,6 @@ class ForwardBuilder extends Builder { ...@@ -243,12 +243,6 @@ class ForwardBuilder extends Builder {
caTargetSelector.setPolicy(getMatchingPolicies()); caTargetSelector.setPolicy(getMatchingPolicies());
} }
/*
* Require CA certs with a pathLenConstraint that allows
* at least as many CA certs that have already been traversed
*/
caTargetSelector.setBasicConstraints(currentState.traversedCACerts);
sel = caTargetSelector; sel = caTargetSelector;
} else { } else {
...@@ -282,12 +276,6 @@ class ForwardBuilder extends Builder { ...@@ -282,12 +276,6 @@ class ForwardBuilder extends Builder {
CertPathHelper.setPathToNames CertPathHelper.setPathToNames
(caSelector, currentState.subjectNamesTraversed); (caSelector, currentState.subjectNamesTraversed);
/*
* Require CA certs with a pathLenConstraint that allows
* at least as many CA certs that have already been traversed
*/
caSelector.setBasicConstraints(currentState.traversedCACerts);
/* /*
* Facilitate certification path construction with authority * Facilitate certification path construction with authority
* key identifier and subject key identifier. * key identifier and subject key identifier.
...@@ -305,6 +293,14 @@ class ForwardBuilder extends Builder { ...@@ -305,6 +293,14 @@ class ForwardBuilder extends Builder {
sel = caSelector; sel = caSelector;
} }
/*
* For compatibility, conservatively, we don't check the path
* length constraint of trusted anchors. Please don't set the
* basic constraints criterion unless the trusted certificate
* matching is completed.
*/
sel.setBasicConstraints(-1);
for (X509Certificate trustedCert : trustedCerts) { for (X509Certificate trustedCert : trustedCerts) {
if (sel.match(trustedCert)) { if (sel.match(trustedCert)) {
if (debug != null) { if (debug != null) {
...@@ -323,6 +319,12 @@ class ForwardBuilder extends Builder { ...@@ -323,6 +319,12 @@ class ForwardBuilder extends Builder {
*/ */
sel.setCertificateValid(date); sel.setCertificateValid(date);
/*
* Require CA certs with a pathLenConstraint that allows
* at least as many CA certs that have already been traversed
*/
sel.setBasicConstraints(currentState.traversedCACerts);
/* /*
* If we have already traversed as many CA certs as the maxPathLength * If we have already traversed as many CA certs as the maxPathLength
* will allow us to, then we don't bother looking through these * will allow us to, then we don't bother looking through these
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册