提交 d32b6188 编写于 作者: M mullan

7195409: CertPath/CertPathValidatorTest/KeyParamsInheritanceTest fails with NullPointerException

Reviewed-by: xuelei
上级 ca758867
/* /*
* Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2009, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -259,8 +259,7 @@ final public class AlgorithmChecker extends PKIXCertPathChecker { ...@@ -259,8 +259,7 @@ final public class AlgorithmChecker extends PKIXCertPathChecker {
} }
// Inherit key parameters from previous key // Inherit key parameters from previous key
if (currPubKey instanceof DSAPublicKey && if (PKIX.isDSAPublicKeyWithoutParams(currPubKey)) {
((DSAPublicKey)currPubKey).getParams() == null) {
// Inherit DSA parameters from previous key // Inherit DSA parameters from previous key
if (!(prevPubKey instanceof DSAPublicKey)) { if (!(prevPubKey instanceof DSAPublicKey)) {
throw new CertPathValidatorException("Input key is not " + throw new CertPathValidatorException("Input key is not " +
......
...@@ -101,9 +101,7 @@ class BasicChecker extends PKIXCertPathChecker { ...@@ -101,9 +101,7 @@ class BasicChecker extends PKIXCertPathChecker {
public void init(boolean forward) throws CertPathValidatorException { public void init(boolean forward) throws CertPathValidatorException {
if (!forward) { if (!forward) {
prevPubKey = trustedPubKey; prevPubKey = trustedPubKey;
if (prevPubKey instanceof DSAPublicKey && if (PKIX.isDSAPublicKeyWithoutParams(prevPubKey)) {
((DSAPublicKey)prevPubKey).getParams() == null)
{
// If TrustAnchor is a DSA public key and it has no params, it // If TrustAnchor is a DSA public key and it has no params, it
// cannot be used to verify the signature of the first cert, // cannot be used to verify the signature of the first cert,
// so throw exception // so throw exception
...@@ -248,8 +246,7 @@ class BasicChecker extends PKIXCertPathChecker { ...@@ -248,8 +246,7 @@ class BasicChecker extends PKIXCertPathChecker {
currCert.getSubjectX500Principal() + "; serial#: " + currCert.getSubjectX500Principal() + "; serial#: " +
currCert.getSerialNumber().toString()); currCert.getSerialNumber().toString());
} }
if (cKey instanceof DSAPublicKey && if (PKIX.isDSAPublicKeyWithoutParams(cKey)) {
((DSAPublicKey)cKey).getParams() == null) {
// cKey needs to inherit DSA parameters from prev key // cKey needs to inherit DSA parameters from prev key
cKey = makeInheritedParamsKey(cKey, prevPubKey); cKey = makeInheritedParamsKey(cKey, prevPubKey);
if (debug != null) debug.println("BasicChecker.updateState Made " + if (debug != null) debug.println("BasicChecker.updateState Made " +
......
...@@ -817,7 +817,7 @@ class ForwardBuilder extends Builder { ...@@ -817,7 +817,7 @@ class ForwardBuilder extends Builder {
} else { } else {
continue; continue;
} }
} else { }
X500Principal principal = anchor.getCA(); X500Principal principal = anchor.getCA();
PublicKey publicKey = anchor.getCAPublicKey(); PublicKey publicKey = anchor.getCAPublicKey();
...@@ -836,17 +836,17 @@ class ForwardBuilder extends Builder { ...@@ -836,17 +836,17 @@ class ForwardBuilder extends Builder {
!principal.equals(cert.getIssuerX500Principal())) { !principal.equals(cert.getIssuerX500Principal())) {
continue; continue;
} }
// skip anchor if it contains a DSA key with no DSA params
if (PKIX.isDSAPublicKeyWithoutParams(publicKey)) {
continue;
} }
/* /*
* Check signature * Check signature
*/ */
try { try {
// NOTE: the DSA public key in the buildParams may lack cert.verify(publicKey, buildParams.sigProvider());
// parameters, yet there is no key to inherit the parameters
// from. This is probably such a rare case that it is not worth
// trying to detect the situation earlier.
cert.verify(anchor.getCAPublicKey(), buildParams.sigProvider());
} catch (InvalidKeyException ike) { } catch (InvalidKeyException ike) {
if (debug != null) { if (debug != null) {
debug.println("ForwardBuilder.isPathCompleted() invalid " debug.println("ForwardBuilder.isPathCompleted() invalid "
......
...@@ -26,12 +26,10 @@ ...@@ -26,12 +26,10 @@
package sun.security.provider.certpath; package sun.security.provider.certpath;
import java.io.IOException; import java.io.IOException;
import java.security.PublicKey;
import java.security.cert.CertificateException; import java.security.cert.CertificateException;
import java.security.cert.CertPathValidatorException; import java.security.cert.CertPathValidatorException;
import java.security.cert.PKIXCertPathChecker; import java.security.cert.PKIXCertPathChecker;
import java.security.cert.X509Certificate; import java.security.cert.X509Certificate;
import java.security.interfaces.DSAPublicKey;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
...@@ -169,9 +167,7 @@ class ForwardState implements State { ...@@ -169,9 +167,7 @@ class ForwardState implements State {
X509CertImpl icert = X509CertImpl.toImpl(cert); X509CertImpl icert = X509CertImpl.toImpl(cert);
/* see if certificate key has null parameters */ /* see if certificate key has null parameters */
PublicKey newKey = icert.getPublicKey(); if (PKIX.isDSAPublicKeyWithoutParams(icert.getPublicKey())) {
if (newKey instanceof DSAPublicKey &&
((DSAPublicKey)newKey).getParams() == null) {
keyParamsNeededFlag = true; keyParamsNeededFlag = true;
} }
......
...@@ -26,7 +26,9 @@ package sun.security.provider.certpath; ...@@ -26,7 +26,9 @@ package sun.security.provider.certpath;
import java.security.InvalidAlgorithmParameterException; import java.security.InvalidAlgorithmParameterException;
import java.security.KeyStore; import java.security.KeyStore;
import java.security.PublicKey;
import java.security.cert.*; import java.security.cert.*;
import java.security.interfaces.DSAPublicKey;
import java.util.*; import java.util.*;
import javax.security.auth.x500.X500Principal; import javax.security.auth.x500.X500Principal;
...@@ -42,6 +44,11 @@ class PKIX { ...@@ -42,6 +44,11 @@ class PKIX {
private PKIX() { } private PKIX() { }
static boolean isDSAPublicKeyWithoutParams(PublicKey publicKey) {
return (publicKey instanceof DSAPublicKey &&
((DSAPublicKey)publicKey).getParams() == null);
}
static ValidatorParams checkParams(CertPath cp, CertPathParameters params) static ValidatorParams checkParams(CertPath cp, CertPathParameters params)
throws InvalidAlgorithmParameterException throws InvalidAlgorithmParameterException
{ {
......
...@@ -32,7 +32,6 @@ import java.security.cert.CertPathValidatorException; ...@@ -32,7 +32,6 @@ import java.security.cert.CertPathValidatorException;
import java.security.cert.PKIXCertPathChecker; import java.security.cert.PKIXCertPathChecker;
import java.security.cert.TrustAnchor; import java.security.cert.TrustAnchor;
import java.security.cert.X509Certificate; import java.security.cert.X509Certificate;
import java.security.interfaces.DSAPublicKey;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
...@@ -287,8 +286,7 @@ class ReverseState implements State { ...@@ -287,8 +286,7 @@ class ReverseState implements State {
/* check for key needing to inherit alg parameters */ /* check for key needing to inherit alg parameters */
X509CertImpl icert = X509CertImpl.toImpl(cert); X509CertImpl icert = X509CertImpl.toImpl(cert);
PublicKey newKey = cert.getPublicKey(); PublicKey newKey = cert.getPublicKey();
if (newKey instanceof DSAPublicKey && if (PKIX.isDSAPublicKeyWithoutParams(newKey)) {
(((DSAPublicKey)newKey).getParams() == null)) {
newKey = BasicChecker.makeInheritedParamsKey(newKey, pubKey); newKey = BasicChecker.makeInheritedParamsKey(newKey, pubKey);
} }
......
...@@ -38,7 +38,6 @@ import java.security.Security; ...@@ -38,7 +38,6 @@ import java.security.Security;
import java.security.cert.CertPathValidatorException.BasicReason; import java.security.cert.CertPathValidatorException.BasicReason;
import java.security.cert.Extension; import java.security.cert.Extension;
import java.security.cert.*; import java.security.cert.*;
import java.security.interfaces.DSAPublicKey;
import java.util.Arrays; import java.util.Arrays;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
...@@ -406,8 +405,7 @@ class RevocationChecker extends PKIXRevocationChecker { ...@@ -406,8 +405,7 @@ class RevocationChecker extends PKIXRevocationChecker {
// Make new public key if parameters are missing // Make new public key if parameters are missing
PublicKey pubKey = cert.getPublicKey(); PublicKey pubKey = cert.getPublicKey();
if (pubKey instanceof DSAPublicKey && if (PKIX.isDSAPublicKeyWithoutParams(pubKey)) {
((DSAPublicKey)pubKey).getParams() == null) {
// pubKey needs to inherit DSA parameters from prev key // pubKey needs to inherit DSA parameters from prev key
pubKey = BasicChecker.makeInheritedParamsKey(pubKey, prevPubKey); pubKey = BasicChecker.makeInheritedParamsKey(pubKey, prevPubKey);
} }
......
...@@ -31,7 +31,6 @@ import java.security.InvalidAlgorithmParameterException; ...@@ -31,7 +31,6 @@ import java.security.InvalidAlgorithmParameterException;
import java.security.PublicKey; import java.security.PublicKey;
import java.security.cert.*; import java.security.cert.*;
import java.security.cert.PKIXReason; import java.security.cert.PKIXReason;
import java.security.interfaces.DSAPublicKey;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
...@@ -242,6 +241,15 @@ public final class SunCertPathBuilder extends CertPathBuilderSpi { ...@@ -242,6 +241,15 @@ public final class SunCertPathBuilder extends CertPathBuilderSpi {
break; break;
} }
// skip anchor if it contains a DSA key with no DSA params
X509Certificate trustedCert = anchor.getTrustedCert();
PublicKey pubKey = trustedCert != null ? trustedCert.getPublicKey()
: anchor.getCAPublicKey();
if (PKIX.isDSAPublicKeyWithoutParams(pubKey)) {
continue;
}
/* Initialize current state */ /* Initialize current state */
currentState.initState(buildParams); currentState.initState(buildParams);
currentState.updateState(anchor, buildParams); currentState.updateState(anchor, buildParams);
...@@ -705,9 +713,7 @@ public final class SunCertPathBuilder extends CertPathBuilderSpi { ...@@ -705,9 +713,7 @@ public final class SunCertPathBuilder extends CertPathBuilderSpi {
* Extract and save the final target public key * Extract and save the final target public key
*/ */
finalPublicKey = cert.getPublicKey(); finalPublicKey = cert.getPublicKey();
if (finalPublicKey instanceof DSAPublicKey && if (PKIX.isDSAPublicKeyWithoutParams(finalPublicKey)) {
((DSAPublicKey)finalPublicKey).getParams() == null)
{
finalPublicKey = finalPublicKey =
BasicChecker.makeInheritedParamsKey BasicChecker.makeInheritedParamsKey
(finalPublicKey, currentState.pubKey); (finalPublicKey, currentState.pubKey);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册