提交 ffcf3ce4 编写于 作者: M mullan

8010112: NullPointerException in sun.security.provider.certpath.CertId()

Reviewed-by: vinnie
上级 f257643d
/* /*
* Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2003, 2013, 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
...@@ -29,8 +29,10 @@ import java.io.IOException; ...@@ -29,8 +29,10 @@ import java.io.IOException;
import java.math.BigInteger; import java.math.BigInteger;
import java.security.MessageDigest; import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException; import java.security.NoSuchAlgorithmException;
import java.security.PublicKey;
import java.security.cert.X509Certificate; import java.security.cert.X509Certificate;
import java.util.Arrays; import java.util.Arrays;
import javax.security.auth.x500.X500Principal;
import sun.misc.HexDumpEncoder; import sun.misc.HexDumpEncoder;
import sun.security.x509.*; import sun.security.x509.*;
import sun.security.util.*; import sun.security.util.*;
...@@ -70,6 +72,13 @@ public class CertId { ...@@ -70,6 +72,13 @@ public class CertId {
public CertId(X509Certificate issuerCert, SerialNumber serialNumber) public CertId(X509Certificate issuerCert, SerialNumber serialNumber)
throws IOException { throws IOException {
this(issuerCert.getSubjectX500Principal(),
issuerCert.getPublicKey(), serialNumber);
}
public CertId(X500Principal issuerName, PublicKey issuerKey,
SerialNumber serialNumber) throws IOException {
// compute issuerNameHash // compute issuerNameHash
MessageDigest md = null; MessageDigest md = null;
try { try {
...@@ -78,11 +87,11 @@ public class CertId { ...@@ -78,11 +87,11 @@ public class CertId {
throw new IOException("Unable to create CertId", nsae); throw new IOException("Unable to create CertId", nsae);
} }
hashAlgId = SHA1_ALGID; hashAlgId = SHA1_ALGID;
md.update(issuerCert.getSubjectX500Principal().getEncoded()); md.update(issuerName.getEncoded());
issuerNameHash = md.digest(); issuerNameHash = md.digest();
// compute issuerKeyHash (remove the tag and length) // compute issuerKeyHash (remove the tag and length)
byte[] pubKey = issuerCert.getPublicKey().getEncoded(); byte[] pubKey = issuerKey.getEncoded();
DerValue val = new DerValue(pubKey); DerValue val = new DerValue(pubKey);
DerValue[] seq = new DerValue[2]; DerValue[] seq = new DerValue[2];
seq[0] = val.data.getDerValue(); // AlgorithmID seq[0] = val.data.getDerValue(); // AlgorithmID
...@@ -94,7 +103,7 @@ public class CertId { ...@@ -94,7 +103,7 @@ public class CertId {
if (debug) { if (debug) {
HexDumpEncoder encoder = new HexDumpEncoder(); HexDumpEncoder encoder = new HexDumpEncoder();
System.out.println("Issuer Certificate is " + issuerCert); System.out.println("Issuer Name is " + issuerName);
System.out.println("issuerNameHash is " + System.out.println("issuerNameHash is " +
encoder.encodeBuffer(issuerNameHash)); encoder.encodeBuffer(issuerNameHash));
System.out.println("issuerKeyHash is " + System.out.println("issuerKeyHash is " +
......
/* /*
* Copyright (c) 2002, 2012, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2002, 2013, 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
...@@ -345,10 +345,8 @@ class DistributionPointFetcher { ...@@ -345,10 +345,8 @@ class DistributionPointFetcher {
return false; return false;
} else { } else {
// in case of self-issued indirect CRL issuer. // in case of self-issued indirect CRL issuer.
byte[] certAKID = certImpl.getExtensionValue( KeyIdentifier certAKID = certImpl.getAuthKeyId();
AuthorityKey_Id.toString()); KeyIdentifier crlAKID = crlImpl.getAuthKeyId();
byte[] crlAKID = crlImpl.getExtensionValue(
AuthorityKey_Id.toString());
if (certAKID == null || crlAKID == null) { if (certAKID == null || crlAKID == null) {
// cannot recognize indirect CRL without AKID // cannot recognize indirect CRL without AKID
...@@ -359,7 +357,7 @@ class DistributionPointFetcher { ...@@ -359,7 +357,7 @@ class DistributionPointFetcher {
// reset the public key used to verify the CRL's signature // reset the public key used to verify the CRL's signature
prevKey = certImpl.getPublicKey(); prevKey = certImpl.getPublicKey();
} }
} else if (!Arrays.equals(certAKID, crlAKID)) { } else if (!certAKID.equals(crlAKID)) {
// we accept the case that a CRL issuer provide status // we accept the case that a CRL issuer provide status
// information for itself. // information for itself.
if (issues(certImpl, crlImpl, provider)) { if (issues(certImpl, crlImpl, provider)) {
......
/* /*
* Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2012, 2013, 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
...@@ -643,7 +643,14 @@ class RevocationChecker extends PKIXRevocationChecker { ...@@ -643,7 +643,14 @@ class RevocationChecker extends PKIXRevocationChecker {
OCSPResponse response = null; OCSPResponse response = null;
CertId certId = null; CertId certId = null;
try { try {
certId = new CertId(issuerCert, currCert.getSerialNumberObject()); if (issuerCert != null) {
certId = new CertId(issuerCert,
currCert.getSerialNumberObject());
} else {
// must be an anchor name and key
certId = new CertId(anchor.getCA(), anchor.getCAPublicKey(),
currCert.getSerialNumberObject());
}
// check if there is a cached OCSP response available // check if there is a cached OCSP response available
byte[] responseBytes = ocspResponses.get(cert); byte[] responseBytes = ocspResponses.get(cert);
......
/* /*
* Copyright (c) 1996, 2012, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1996, 2013, 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
...@@ -1095,6 +1095,18 @@ public class X509CertImpl extends X509Certificate implements DerEncoder { ...@@ -1095,6 +1095,18 @@ public class X509CertImpl extends X509Certificate implements DerEncoder {
} }
} }
public KeyIdentifier getAuthKeyId() {
AuthorityKeyIdentifierExtension aki
= getAuthorityKeyIdentifierExtension();
if (aki != null) {
try {
return (KeyIdentifier)aki.get(
AuthorityKeyIdentifierExtension.KEY_ID);
} catch (IOException ioe) {} // not possible
}
return null;
}
/** /**
* Get AuthorityKeyIdentifier extension * Get AuthorityKeyIdentifier extension
* @return AuthorityKeyIdentifier object or null (if no such object * @return AuthorityKeyIdentifier object or null (if no such object
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册