undefect. CWE-407 — 63 sites patched across 27 ecosystems
Authors: russell@unturf.com · brackishbert@gmail.com · foxhop.net · TimeHexOn.com Patches, unit tests, benchmarks, whitepaper, and outreach briefs. Public domain — no copyright claimed. Use freely.
This commit is contained in:
commit
0a580b313d
70422 changed files with 17213626 additions and 0 deletions
63
test/jdk/java/security/cert/CertPath/Serialize.java
Normal file
63
test/jdk/java/security/cert/CertPath/Serialize.java
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
/*
|
||||
* Copyright (c) 2001, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @bug 4404718
|
||||
* @summary Make sure that a CertPath object can be serialized
|
||||
*/
|
||||
import java.io.*;
|
||||
import java.security.cert.*;
|
||||
import java.util.Collections;
|
||||
|
||||
public class Serialize {
|
||||
|
||||
public static void main(String args[]) throws Exception {
|
||||
|
||||
// create a certpath consisting of one certificate
|
||||
File f = new File(System.getProperty("test.src", "."), "cert_file");
|
||||
FileInputStream fis = new FileInputStream(f);
|
||||
CertificateFactory cf = CertificateFactory.getInstance("X.509");
|
||||
Certificate c = cf.generateCertificate(fis);
|
||||
fis.close();
|
||||
CertPath outcp = cf.generateCertPath(Collections.singletonList(c));
|
||||
|
||||
// serialize certpath and write it out
|
||||
FileOutputStream fos = new FileOutputStream("certpath.ser");
|
||||
ObjectOutputStream oos = new ObjectOutputStream(fos);
|
||||
oos.writeObject(outcp);
|
||||
oos.flush();
|
||||
oos.close();
|
||||
fos.close();
|
||||
|
||||
// read certpath in and deserialize
|
||||
FileInputStream cfis = new FileInputStream("certpath.ser");
|
||||
ObjectInputStream ois = new ObjectInputStream(cfis);
|
||||
CertPath incp = (CertPath)ois.readObject();
|
||||
ois.close();
|
||||
cfis.close();
|
||||
|
||||
if (!incp.equals(outcp))
|
||||
throw new Exception("CertPath serialization test FAILED");
|
||||
}
|
||||
}
|
||||
BIN
test/jdk/java/security/cert/CertPath/cert_file
Normal file
BIN
test/jdk/java/security/cert/CertPath/cert_file
Normal file
Binary file not shown.
45
test/jdk/java/security/cert/CertPathBuilder/GetInstance.java
Normal file
45
test/jdk/java/security/cert/CertPathBuilder/GetInstance.java
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
/*
|
||||
* Copyright (c) 2001, 2025, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 4408997
|
||||
* @summary Should be able to pass a Provider object to getInstance().
|
||||
* @compile StubProvider.java StubProviderImpl.java
|
||||
* @run main GetInstance
|
||||
* The test passes if it returns.
|
||||
* The test fails if an exception is thrown.
|
||||
*/
|
||||
import java.security.Provider;
|
||||
import java.security.cert.CertPathBuilder;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
|
||||
|
||||
public class GetInstance {
|
||||
|
||||
public static void main(String[] argv) throws Exception {
|
||||
Provider stubProvider = new StubProvider();
|
||||
CertPathBuilder cpb = CertPathBuilder.getInstance("PKIX", stubProvider);
|
||||
System.out.println("Test passed.");
|
||||
}
|
||||
}
|
||||
142
test/jdk/java/security/cert/CertPathBuilder/NoExtensions.java
Normal file
142
test/jdk/java/security/cert/CertPathBuilder/NoExtensions.java
Normal file
|
|
@ -0,0 +1,142 @@
|
|||
/*
|
||||
* Copyright (c) 2001, 2025, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 4519462
|
||||
* @summary Verify Sun CertPathBuilder implementation handles certificates with no extensions
|
||||
* @enablePreview
|
||||
*/
|
||||
|
||||
import java.security.PEMDecoder;
|
||||
import java.security.cert.X509Certificate;
|
||||
import java.security.cert.TrustAnchor;
|
||||
import java.security.cert.CollectionCertStoreParameters;
|
||||
import java.security.cert.CertStore;
|
||||
import java.security.cert.X509CertSelector;
|
||||
import java.security.cert.CertPathBuilder;
|
||||
import java.security.cert.PKIXBuilderParameters;
|
||||
import java.security.cert.CertPathBuilderResult;
|
||||
import java.security.cert.CertPath;
|
||||
import java.util.HashSet;
|
||||
import java.util.ArrayList;
|
||||
|
||||
// Test based on user code submitted with bug by daniel.boggs@compass.net
|
||||
public class NoExtensions {
|
||||
|
||||
private static final PEMDecoder pemDecoder = PEMDecoder.of();
|
||||
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
NoExtensions certs = new NoExtensions();
|
||||
|
||||
// the first certificate has the Authority Key Identifier extension
|
||||
certs.doBuild(getUserCertificate1());
|
||||
System.out.println("successfully built path for the first certificate");
|
||||
|
||||
// the second certificate does not have the Authority Key Identifier extension
|
||||
// this will not succeed
|
||||
certs.doBuild(getUserCertificate2());
|
||||
System.out.println("successfully built path for the second certificate");
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private void doBuild(X509Certificate userCert) throws Exception {
|
||||
// get the set of trusted CA certificates (only one in this instance)
|
||||
HashSet trustAnchors = new HashSet();
|
||||
X509Certificate trustedCert = getTrustedCertificate();
|
||||
trustAnchors.add(new TrustAnchor(trustedCert, null));
|
||||
|
||||
// put together a CertStore (repository of the certificates and CRLs)
|
||||
ArrayList certs = new ArrayList();
|
||||
certs.add(trustedCert);
|
||||
certs.add(userCert);
|
||||
CollectionCertStoreParameters certStoreParams = new CollectionCertStoreParameters(certs);
|
||||
CertStore certStore = CertStore.getInstance("Collection", certStoreParams);
|
||||
|
||||
// specify the target certificate via a CertSelector
|
||||
X509CertSelector certSelector = new X509CertSelector();
|
||||
certSelector.setCertificate(userCert);
|
||||
certSelector.setSubject(userCert.getSubjectDN().getName()); // seems to be required
|
||||
|
||||
// build a valid cerificate path
|
||||
CertPathBuilder certPathBuilder = CertPathBuilder.getInstance("PKIX", "SUN");
|
||||
PKIXBuilderParameters certPathBuilderParams = new PKIXBuilderParameters(trustAnchors, certSelector);
|
||||
certPathBuilderParams.addCertStore(certStore);
|
||||
certPathBuilderParams.setRevocationEnabled(false);
|
||||
CertPathBuilderResult result = certPathBuilder.build(certPathBuilderParams);
|
||||
|
||||
// get and show cert path
|
||||
CertPath certPath = result.getCertPath();
|
||||
// System.out.println(certPath.toString());
|
||||
}
|
||||
|
||||
private static X509Certificate getTrustedCertificate() {
|
||||
String sCert =
|
||||
"-----BEGIN CERTIFICATE-----\n"
|
||||
+ "MIIBezCCASWgAwIBAgIQyWD8dLUoqpJFyDxrfRlrsTANBgkqhkiG9w0BAQQFADAW\n"
|
||||
+ "MRQwEgYDVQQDEwtSb290IEFnZW5jeTAeFw0wMTEwMTkxMjU5MjZaFw0zOTEyMzEy\n"
|
||||
+ "MzU5NTlaMBoxGDAWBgNVBAMTD1Jvb3RDZXJ0aWZpY2F0ZTBcMA0GCSqGSIb3DQEB\n"
|
||||
+ "AQUAA0sAMEgCQQC+NFKszPjatUZKWmyWaFjir1wB93FX2u5SL+GMjgUsMs1JcTKQ\n"
|
||||
+ "Kh0cnnQKknNkV4cTW4NPn31YCoB1+0KA3mknAgMBAAGjSzBJMEcGA1UdAQRAMD6A\n"
|
||||
+ "EBLkCS0GHR1PAI1hIdwWZGOhGDAWMRQwEgYDVQQDEwtSb290IEFnZW5jeYIQBjds\n"
|
||||
+ "AKoAZIoRz7jUqlw19DANBgkqhkiG9w0BAQQFAANBACJxAfP57yqaT9N+nRgAOugM\n"
|
||||
+ "JG0aN3/peCIvL3p29epRL2xoWFvxpUUlsH2I39OZ6b8+twWCebhkv1I62segXAk=\n"
|
||||
+ "-----END CERTIFICATE-----";
|
||||
return pemDecoder.decode(sCert, X509Certificate.class);
|
||||
}
|
||||
|
||||
private static X509Certificate getUserCertificate1() {
|
||||
// this certificate includes an extension
|
||||
String sCert =
|
||||
"-----BEGIN CERTIFICATE-----\n"
|
||||
+ "MIIBfzCCASmgAwIBAgIQWFSKzCWO2ptOAc2F3MKZSzANBgkqhkiG9w0BAQQFADAa\n"
|
||||
+ "MRgwFgYDVQQDEw9Sb290Q2VydGlmaWNhdGUwHhcNMDExMDE5MTMwNzQxWhcNMzkx\n"
|
||||
+ "MjMxMjM1OTU5WjAaMRgwFgYDVQQDEw9Vc2VyQ2VydGlmaWNhdGUwXDANBgkqhkiG\n"
|
||||
+ "9w0BAQEFAANLADBIAkEA24gypa2YFGZHKznEWWbqIWNVXCM35W7RwJwhGpNsuBCj\n"
|
||||
+ "NT6KEo66F+OOMgZmb0KrEZHBJASJ3n4Cqbt4aHm/2wIDAQABo0swSTBHBgNVHQEE\n"
|
||||
+ "QDA+gBBch+eYzOPgVRbMq5vGpVWooRgwFjEUMBIGA1UEAxMLUm9vdCBBZ2VuY3mC\n"
|
||||
+ "EMlg/HS1KKqSRcg8a30Za7EwDQYJKoZIhvcNAQEEBQADQQCYBIHBqQQJePi5Hzfo\n"
|
||||
+ "CxeUaYlXmvbxVNkxM65Pplsj3h4ntfZaynmlhahH3YsnnA8wk6xPt04LjSId12RB\n"
|
||||
+ "PeuO\n"
|
||||
+ "-----END CERTIFICATE-----";
|
||||
return pemDecoder.decode(sCert, X509Certificate.class);
|
||||
}
|
||||
|
||||
private static X509Certificate getUserCertificate2() {
|
||||
// this certificate does not include any extensions
|
||||
String sCert =
|
||||
"-----BEGIN CERTIFICATE-----\n"
|
||||
+ "MIIBMjCB3aADAgECAhB6225ckZVssEukPuvk1U1PMA0GCSqGSIb3DQEBBAUAMBox\n"
|
||||
+ "GDAWBgNVBAMTD1Jvb3RDZXJ0aWZpY2F0ZTAeFw0wMTEwMTkxNjA5NTZaFw0wMjEw\n"
|
||||
+ "MTkyMjA5NTZaMBsxGTAXBgNVBAMTEFVzZXJDZXJ0aWZpY2F0ZTIwXDANBgkqhkiG\n"
|
||||
+ "9w0BAQEFAANLADBIAkEAzicGiW9aUlUoQIZnLy1l8MMV5OvA+4VJ4T/xo/PpN8Oq\n"
|
||||
+ "WgZVGKeEp6JCzMlXEJk3TGLfpXL4Ytw+Ldhv0QPhLwIDAnMpMA0GCSqGSIb3DQEB\n"
|
||||
+ "BAUAA0EAQmj9SFHEx66JyAps3ew4pcSS3QvfVZ/6qsNUYCG75rFGcTUPHcXKql9y\n"
|
||||
+ "qBT83iNLJ//krjw5Ju0WRPg/buHSww==\n"
|
||||
+ "-----END CERTIFICATE-----";
|
||||
return pemDecoder.decode(sCert, X509Certificate.class);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,36 @@
|
|||
/*
|
||||
* Copyright (c) 2001, 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/*
|
||||
*
|
||||
* @bug 4408997 8130181
|
||||
* Used by GetInstance test.
|
||||
*/
|
||||
import java.security.Provider;
|
||||
|
||||
public class StubProvider extends Provider {
|
||||
public StubProvider() {
|
||||
super( "StubProvider", "1.1", "No Info");
|
||||
put("CertPathBuilder.PKIX", "StubProviderImpl");
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,43 @@
|
|||
/*
|
||||
* Copyright (c) 2001, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/*
|
||||
*
|
||||
* @bug 4408997
|
||||
* Used by GetInstance test.
|
||||
*/
|
||||
import java.security.cert.CertPathParameters;
|
||||
import java.security.cert.CertPathBuilderResult;
|
||||
import java.security.cert.CertPathBuilderSpi;
|
||||
|
||||
public class StubProviderImpl extends CertPathBuilderSpi {
|
||||
public boolean called;
|
||||
public StubProviderImpl() {
|
||||
super();
|
||||
called = false;
|
||||
}
|
||||
public CertPathBuilderResult engineBuild(CertPathParameters params) {
|
||||
called = true;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,143 @@
|
|||
/*
|
||||
* Copyright (c) 2014, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @bug 8025708
|
||||
* @summary make sure a PKIX CertPathBuilder can build a path when an
|
||||
* intermediate CA certificate contains an AKI extension with a key
|
||||
* identifier and no serial number and the end-entity certificate contains
|
||||
* an AKI extension with both a key identifier and a serial number.
|
||||
*/
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.security.cert.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Base64;
|
||||
import java.util.Collections;
|
||||
|
||||
public class AKISerialNumber {
|
||||
|
||||
private static final String ROOT_CERT =
|
||||
"MIICfTCCAeagAwIBAgIBATANBgkqhkiG9w0BAQUFADB3MQ0wCwYDVQQDEwRSb290\n" +
|
||||
"MRYwFAYDVQQLEw1UZXN0IE9yZyBVbml0MREwDwYDVQQKEwhUZXN0IE9yZzEWMBQG\n" +
|
||||
"A1UEBxMNVGVzdCBMb2NhbGl0eTEWMBQGA1UECBMNTWFzc2FjaHVzZXR0czELMAkG\n" +
|
||||
"A1UEBhMCVVMwHhcNMTQwMjAxMDUwMDAwWhcNMjQwMjAxMDUwMDAwWjB3MQ0wCwYD\n" +
|
||||
"VQQDEwRSb290MRYwFAYDVQQLEw1UZXN0IE9yZyBVbml0MREwDwYDVQQKEwhUZXN0\n" +
|
||||
"IE9yZzEWMBQGA1UEBxMNVGVzdCBMb2NhbGl0eTEWMBQGA1UECBMNTWFzc2FjaHVz\n" +
|
||||
"ZXR0czELMAkGA1UEBhMCVVMwgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBAJvL\n" +
|
||||
"cZu6Rzf9IrduEDjJxEFv5uBvUNMlIAph7NhfmFH9puPW3Ksci4a5yTCzxI9VeVf3\n" +
|
||||
"oYZ/UrZdF+mNZmS23RUh71X5tjMO+xew196M1xNpCRLbjcZ6i4tNdZYkdRIe8ejN\n" +
|
||||
"sbBoD7OAvPbQqTygeG4jYjK6ODofSrba3BndNoFxAgMBAAGjGTAXMBUGA1UdEwEB\n" +
|
||||
"/wQLMAkBAf8CBH////8wDQYJKoZIhvcNAQEFBQADgYEATvCqn69pNHv0zLiZAXk7\n" +
|
||||
"3AKwAoza0wa+1S2rVuZGfBWbV7CxmBHbgcDDbU7/I8pQVkCwOHNkVFnBgNpMuAvU\n" +
|
||||
"aDyrHSNS/av5d1yk5WAuGX2B9mSwZdhnAvtz2fsV1q9NptdF54EkIiKtQQmTGnr9\n" +
|
||||
"TID8CFEk/qje+AB272B1UJw=\n";
|
||||
|
||||
/**
|
||||
* This certificate contains an AuthorityKeyIdentifier with only the
|
||||
* keyIdentifier field filled in.
|
||||
*/
|
||||
private static final String INT_CERT_WITH_KEYID_AKI =
|
||||
"MIICqTCCAhKgAwIBAgIBAjANBgkqhkiG9w0BAQUFADB3MQ0wCwYDVQQDEwRSb290\n" +
|
||||
"MRYwFAYDVQQLEw1UZXN0IE9yZyBVbml0MREwDwYDVQQKEwhUZXN0IE9yZzEWMBQG\n" +
|
||||
"A1UEBxMNVGVzdCBMb2NhbGl0eTEWMBQGA1UECBMNTWFzc2FjaHVzZXR0czELMAkG\n" +
|
||||
"A1UEBhMCVVMwHhcNMTQwMjAxMDUwMDAwWhcNMjQwMjAxMDUwMDAwWjCBhDEaMBgG\n" +
|
||||
"A1UEAxMRSW50ZXJtZWRpYXRlIENBIDIxFjAUBgNVBAsTDVRlc3QgT3JnIFVuaXQx\n" +
|
||||
"ETAPBgNVBAoTCFRlc3QgT3JnMRYwFAYDVQQHEw1UZXN0IExvY2FsaXR5MRYwFAYD\n" +
|
||||
"VQQIEw1NYXNzYWNodXNldHRzMQswCQYDVQQGEwJVUzCBnzANBgkqhkiG9w0BAQEF\n" +
|
||||
"AAOBjQAwgYkCgYEAwKTZekCqb9F9T54s2IXjkQbmLIjQamMpkUlZNrpjjNq9CpTT\n" +
|
||||
"POkfxv2UPwzTz3Ij4XFL/kJFBLm8NUOsS5xPJ62pGoZBPw9R0iMTsTce+Fpukqnr\n" +
|
||||
"I+8jTRaAvr0tR3pqrE6uHKg7dWYN2SsWesDia/LHhwEN38yyWtSuTTLo4hcCAwEA\n" +
|
||||
"AaM3MDUwHwYDVR0jBBgwFoAU6gZP1pO8v7+i8gsFf1gWTf/j3PkwEgYDVR0TAQH/\n" +
|
||||
"BAgwBgEB/wIBADANBgkqhkiG9w0BAQUFAAOBgQAQxeQruav4AqQM4gmEfrHr5hOq\n" +
|
||||
"mB2CNJ1ZqVfpDZ8GHijncKTpjNoXzzQtV23Ge+39JHOVBNWtk+aghB3iu6xGq7Qn\n" +
|
||||
"HlBhg9meqHFqd3igDDD/jhABL2/bEo/M9rv6saYWDFZ8nCIEE6iTLTpRRko4W2Xb\n" +
|
||||
"DyzMzMsO1kPNrJaxRg==\n";
|
||||
|
||||
/**
|
||||
* This certificate contains an AuthorityKeyIdentifier with all 3 fields
|
||||
* (keyIdentifier, authorityCertIssuer, and authorityCertSerialNumber)
|
||||
* filled in.
|
||||
*/
|
||||
private static final String EE_CERT_WITH_FULL_AKI =
|
||||
"MIIDLjCCApegAwIBAgIBAzANBgkqhkiG9w0BAQUFADCBhDEaMBgGA1UEAxMRSW50\n" +
|
||||
"ZXJtZWRpYXRlIENBIDIxFjAUBgNVBAsTDVRlc3QgT3JnIFVuaXQxETAPBgNVBAoT\n" +
|
||||
"CFRlc3QgT3JnMRYwFAYDVQQHEw1UZXN0IExvY2FsaXR5MRYwFAYDVQQIEw1NYXNz\n" +
|
||||
"YWNodXNldHRzMQswCQYDVQQGEwJVUzAeFw0xNDAyMDEwNTAwMDBaFw0yNDAyMDEw\n" +
|
||||
"NTAwMDBaMH0xEzARBgNVBAMTCkVuZCBFbnRpdHkxFjAUBgNVBAsTDVRlc3QgT3Jn\n" +
|
||||
"IFVuaXQxETAPBgNVBAoTCFRlc3QgT3JnMRYwFAYDVQQHEw1UZXN0IExvY2FsaXR5\n" +
|
||||
"MRYwFAYDVQQIEw1NYXNzYWNodXNldHRzMQswCQYDVQQGEwJVUzCBnzANBgkqhkiG\n" +
|
||||
"9w0BAQEFAAOBjQAwgYkCgYEAqady46PdwlKHVP1iaP11CxVyL6cDlPjpwhHCcIUv\n" +
|
||||
"nKHbzdamqmHebDcWVBNN/I0TLNCl3ga7n8KyygSN379fG7haU8SNjpy4IDAXM0/x\n" +
|
||||
"mwTWNTbKfJEkSoiqx1WUy2JTzRUMhgYPguQNECPxBXAdQrthZ7wQosv6Ro2ySP9O\n" +
|
||||
"YqsCAwEAAaOBtTCBsjCBoQYDVR0jBIGZMIGWgBQdeoKxTvlTgW2KgprD69vgHV4X\n" +
|
||||
"kKF7pHkwdzENMAsGA1UEAxMEUm9vdDEWMBQGA1UECxMNVGVzdCBPcmcgVW5pdDER\n" +
|
||||
"MA8GA1UEChMIVGVzdCBPcmcxFjAUBgNVBAcTDVRlc3QgTG9jYWxpdHkxFjAUBgNV\n" +
|
||||
"BAgTDU1hc3NhY2h1c2V0dHMxCzAJBgNVBAYTAlVTggECMAwGA1UdEwEB/wQCMAAw\n" +
|
||||
"DQYJKoZIhvcNAQEFBQADgYEAuG4mM1nLF7STQWwmceELZEl49ntapH/RVoekknmd\n" +
|
||||
"aNzcL4XQf6BTl8KFUXuThHaukQnGIzFbSZV0hrpSQ5fTN2cSZgD4Fji+HuNURmmd\n" +
|
||||
"+Kayl0piHyO1FSbrty0TFhlVNvzKXjmMp6Jdn42KyGOSCoROQcvUWN6xkV3Hvrei\n" +
|
||||
"0ZE=\n";
|
||||
|
||||
private static Base64.Decoder b64Decoder = Base64.getMimeDecoder();
|
||||
private static CertificateFactory cf;
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
|
||||
cf = CertificateFactory.getInstance("X.509");
|
||||
|
||||
X509Certificate rootCert = getCertFromMimeEncoding(ROOT_CERT);
|
||||
TrustAnchor anchor = new TrustAnchor(rootCert, null);
|
||||
|
||||
X509Certificate eeCert = getCertFromMimeEncoding(EE_CERT_WITH_FULL_AKI);
|
||||
X509Certificate intCert = getCertFromMimeEncoding(INT_CERT_WITH_KEYID_AKI);
|
||||
|
||||
X509CertSelector sel = new X509CertSelector();
|
||||
sel.setCertificate(eeCert);
|
||||
PKIXBuilderParameters params = new PKIXBuilderParameters
|
||||
(Collections.singleton(anchor), sel);
|
||||
params.setRevocationEnabled(false);
|
||||
// Set date to 2024-01-01 to satisfy cert constraints
|
||||
params.setDate(new java.util.Date(1704067200000l));
|
||||
|
||||
ArrayList<X509Certificate> certs = new ArrayList<>();
|
||||
certs.add(intCert);
|
||||
certs.add(eeCert);
|
||||
CollectionCertStoreParameters ccsp =
|
||||
new CollectionCertStoreParameters(certs);
|
||||
CertStore cs = CertStore.getInstance("Collection", ccsp);
|
||||
params.addCertStore(cs);
|
||||
|
||||
CertPathBuilder cpb = CertPathBuilder.getInstance("PKIX");
|
||||
CertPathBuilderResult res = cpb.build(params);
|
||||
}
|
||||
|
||||
private static X509Certificate getCertFromMimeEncoding(String encoded)
|
||||
throws CertificateException
|
||||
{
|
||||
byte[] bytes = b64Decoder.decode(encoded);
|
||||
ByteArrayInputStream stream = new ByteArrayInputStream(bytes);
|
||||
return (X509Certificate)cf.generateCertificate(stream);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,253 @@
|
|||
/*
|
||||
* Copyright (c) 2009, 2025, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
//
|
||||
// Security properties, once set, cannot revert to unset. To avoid
|
||||
// conflicts with tests running in the same VM isolate this test by
|
||||
// running it in otherVM mode.
|
||||
//
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @bug 6852744
|
||||
* @summary PIT b61: PKI test suite fails because self signed certificates
|
||||
* are being rejected
|
||||
* @modules java.base/sun.security.util
|
||||
* @run main/othervm DisableRevocation subca
|
||||
* @run main/othervm DisableRevocation subci
|
||||
* @run main/othervm DisableRevocation alice
|
||||
* @enablePreview
|
||||
* @author Xuelei Fan
|
||||
*/
|
||||
|
||||
import java.io.*;
|
||||
import java.net.SocketException;
|
||||
import java.security.DEREncodable;
|
||||
import java.security.PEMDecoder;
|
||||
import java.util.*;
|
||||
import java.security.Security;
|
||||
import java.security.cert.*;
|
||||
import java.security.cert.CertPathValidatorException.BasicReason;
|
||||
import sun.security.util.DerInputStream;
|
||||
|
||||
/**
|
||||
* A test case helps to ensure that a certification path building process is
|
||||
* able to identify a self-issued certificate from its issuer when disable
|
||||
* revocation checking.
|
||||
*/
|
||||
public final class DisableRevocation {
|
||||
|
||||
// the trust anchor
|
||||
static String selfSignedCertStr =
|
||||
"-----BEGIN CERTIFICATE-----\n" +
|
||||
"MIICPjCCAaegAwIBAgIBADANBgkqhkiG9w0BAQQFADAfMQswCQYDVQQGEwJVUzEQ\n" +
|
||||
"MA4GA1UEChMHRXhhbXBsZTAeFw0wOTA2MjgxMzMyMThaFw0zMDA2MDgxMzMyMTha\n" +
|
||||
"MB8xCzAJBgNVBAYTAlVTMRAwDgYDVQQKEwdFeGFtcGxlMIGfMA0GCSqGSIb3DQEB\n" +
|
||||
"AQUAA4GNADCBiQKBgQDInJhXi0655bPXAVkz1n5I6fAcZejzPnOPuwq3hU3OxFw8\n" +
|
||||
"81Uf6o9oKI1h4w4XAD8u1cUNOgiX+wPwojronlp68bIfO6FVhNf287pLtLhNJo+7\n" +
|
||||
"m6Qxw3ymFvEKy+PVj20CHSggdKHxUa4MBZBmHMFNBuxfYmjwzn+yTMmCCXOvSwID\n" +
|
||||
"AQABo4GJMIGGMB0GA1UdDgQWBBSQ52Dpau+gtL+Kc31dusYnKj16ZTBHBgNVHSME\n" +
|
||||
"QDA+gBSQ52Dpau+gtL+Kc31dusYnKj16ZaEjpCEwHzELMAkGA1UEBhMCVVMxEDAO\n" +
|
||||
"BgNVBAoTB0V4YW1wbGWCAQAwDwYDVR0TAQH/BAUwAwEB/zALBgNVHQ8EBAMCAQYw\n" +
|
||||
"DQYJKoZIhvcNAQEEBQADgYEAjBt6ea65HCqbGsS2rs/HhlGusYXtThRVC5vwXSey\n" +
|
||||
"ZFYwSgukuq1KDzckqZFu1meNImEwdZjwxdN0e2p/nVREPC42rZliSj6V1ThayKXj\n" +
|
||||
"DWEZW1U5aR8T+3NYfDrdKcJGx4Hzfz0qKz1j4ssV1M9ptJxYYv4y2Da+592IN1S9\n" +
|
||||
"v/E=\n" +
|
||||
"-----END CERTIFICATE-----";
|
||||
|
||||
// the sub-ca
|
||||
static String subCaCertStr =
|
||||
"-----BEGIN CERTIFICATE-----\n" +
|
||||
"MIICUDCCAbmgAwIBAgIBAzANBgkqhkiG9w0BAQQFADAfMQswCQYDVQQGEwJVUzEQ\n" +
|
||||
"MA4GA1UEChMHRXhhbXBsZTAeFw0wOTA2MjgxMzMyMjRaFw0yOTAzMTUxMzMyMjRa\n" +
|
||||
"MDExCzAJBgNVBAYTAlVTMRAwDgYDVQQKEwdFeGFtcGxlMRAwDgYDVQQLEwdDbGFz\n" +
|
||||
"cy0xMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDPFv24SK78VI0gWlyIrq/X\n" +
|
||||
"srl1431K5hJJxMYZtaQunyPmrYg3oI9KvKFykxnR0N4XDPaIi75p9dXGppVu80BA\n" +
|
||||
"+csvIPBwlBQoNmKDQWTziDOqfK4tE+IMuL/Y7pxnH6CDMY7VGpvatty2zcmH+m/v\n" +
|
||||
"E/n+HPyeELJQT2rT/3T+7wIDAQABo4GJMIGGMB0GA1UdDgQWBBRidC8Dt3dBzYES\n" +
|
||||
"KpR2tR560sZ0+zBHBgNVHSMEQDA+gBSQ52Dpau+gtL+Kc31dusYnKj16ZaEjpCEw\n" +
|
||||
"HzELMAkGA1UEBhMCVVMxEDAOBgNVBAoTB0V4YW1wbGWCAQAwDwYDVR0TAQH/BAUw\n" +
|
||||
"AwEB/zALBgNVHQ8EBAMCAQYwDQYJKoZIhvcNAQEEBQADgYEAMeMKqrMr5d3eTQsv\n" +
|
||||
"MYOD15Dl3THQGLAa4ad5Eyq5/1eUeEOpztzCgDfi0iPD8YCubIEVasBTSqTiGXqb\n" +
|
||||
"RpGuPHOwwfWvHrTeHSludiFBAUiKj7aEV+oQa0FBn4U4TT8HA62HQ93FhzTDI3jP\n" +
|
||||
"iil34GktVl6gfMKGzUEW/Dh8OM4=\n" +
|
||||
"-----END CERTIFICATE-----";
|
||||
|
||||
// a delegated CRL issuer, it's a self-issued certificate of trust anchor
|
||||
static String topCrlIssuerCertStr =
|
||||
"-----BEGIN CERTIFICATE-----\n" +
|
||||
"MIICPjCCAaegAwIBAgIBAjANBgkqhkiG9w0BAQQFADAfMQswCQYDVQQGEwJVUzEQ\n" +
|
||||
"MA4GA1UEChMHRXhhbXBsZTAeFw0wOTA2MjgxMzMyMjNaFw0yOTAzMTUxMzMyMjNa\n" +
|
||||
"MB8xCzAJBgNVBAYTAlVTMRAwDgYDVQQKEwdFeGFtcGxlMIGfMA0GCSqGSIb3DQEB\n" +
|
||||
"AQUAA4GNADCBiQKBgQC99u93trf+WmpfiqunJy/P31ej1l4rESxft2JSGNjKuLFN\n" +
|
||||
"/BO3SAugGJSkCARAwXjB0c8eeXhXWhVVWdNpbKepRJTxrjDfnFIavLgtUvmFwn/3\n" +
|
||||
"hPXe+RQeA8+AJ99Y+o+10kY8JAZLa2j93C2FdmwOjUbo8aIz85yhbiV1tEDjLwID\n" +
|
||||
"AQABo4GJMIGGMB0GA1UdDgQWBBSyFyA3XWLbdL6W6hksmBn7RKsQmDBHBgNVHSME\n" +
|
||||
"QDA+gBSQ52Dpau+gtL+Kc31dusYnKj16ZaEjpCEwHzELMAkGA1UEBhMCVVMxEDAO\n" +
|
||||
"BgNVBAoTB0V4YW1wbGWCAQAwDwYDVR0TAQH/BAUwAwEB/zALBgNVHQ8EBAMCAQYw\n" +
|
||||
"DQYJKoZIhvcNAQEEBQADgYEAHTm8aRTeakgCfEBCgSWK9wvMW1c18ANGMm8OFDBk\n" +
|
||||
"xabVy9BT0MVFHlaneh89oIxTZN0FMTpg21GZMAvIzhEt7DGdO7HLsW7JniN7/OZ0\n" +
|
||||
"rACmpK5frmZrLS03zUm8c+rTbazNfYLoZVG3/mDZbKIi+4y8IGnFcgLVsHsYoBNP\n" +
|
||||
"G0c=\n" +
|
||||
"-----END CERTIFICATE-----";
|
||||
|
||||
// a delegated CRL issuer, it's a self-issued certificate of sub-ca
|
||||
static String subCrlIssuerCertStr =
|
||||
"-----BEGIN CERTIFICATE-----\n" +
|
||||
"MIICUDCCAbmgAwIBAgIBBDANBgkqhkiG9w0BAQQFADAfMQswCQYDVQQGEwJVUzEQ\n" +
|
||||
"MA4GA1UEChMHRXhhbXBsZTAeFw0wOTA2MjgxMzMyMjdaFw0yOTAzMTUxMzMyMjda\n" +
|
||||
"MDExCzAJBgNVBAYTAlVTMRAwDgYDVQQKEwdFeGFtcGxlMRAwDgYDVQQLEwdDbGFz\n" +
|
||||
"cy0xMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC+8AcLJtGAVUWvv3ifcyQw\n" +
|
||||
"OGqwzcPrBw/XCs6vTMlcdtFzcH1M+Z3/QHN9+5VT1gqeTIZ+b8g9005Og3XKy/HX\n" +
|
||||
"obXZeLv20VZsr+jm52ySghEYOVCTJ9OyFOAp5adp6nf0cA66Feh3LsmVhpTEcDOG\n" +
|
||||
"GnyntQm0DBYxRoOT/GBlvQIDAQABo4GJMIGGMB0GA1UdDgQWBBSRWhMuZLQoHSDN\n" +
|
||||
"xhxr+vdDmfAY8jBHBgNVHSMEQDA+gBSQ52Dpau+gtL+Kc31dusYnKj16ZaEjpCEw\n" +
|
||||
"HzELMAkGA1UEBhMCVVMxEDAOBgNVBAoTB0V4YW1wbGWCAQAwDwYDVR0TAQH/BAUw\n" +
|
||||
"AwEB/zALBgNVHQ8EBAMCAQYwDQYJKoZIhvcNAQEEBQADgYEAMIDZLdOLFiPyS1bh\n" +
|
||||
"Ch4eUYHT+K1WG93skbga3kVYg3GSe+gctwkKwKK13bwfi8zc7wwz6MtmQwEYhppc\n" +
|
||||
"pKKKEwi5QirBCP54rihLCvRQaj6ZqUJ6VP+zPAqHYMDbzlBbHtVF/1lQUP30I6SV\n" +
|
||||
"Fu987DvLmZ2GuQA9FKJsnlD9pbU=\n" +
|
||||
"-----END CERTIFICATE-----";
|
||||
|
||||
// the target EE certificate
|
||||
static String targetCertStr =
|
||||
"-----BEGIN CERTIFICATE-----\n" +
|
||||
"MIICNzCCAaCgAwIBAgIBAjANBgkqhkiG9w0BAQQFADAxMQswCQYDVQQGEwJVUzEQ\n" +
|
||||
"MA4GA1UEChMHRXhhbXBsZTEQMA4GA1UECxMHQ2xhc3MtMTAeFw0wOTA2MjgxMzMy\n" +
|
||||
"MzBaFw0yOTAzMTUxMzMyMzBaMEExCzAJBgNVBAYTAlVTMRAwDgYDVQQKEwdFeGFt\n" +
|
||||
"cGxlMRAwDgYDVQQLEwdDbGFzcy0xMQ4wDAYDVQQDEwVBbGljZTCBnzANBgkqhkiG\n" +
|
||||
"9w0BAQEFAAOBjQAwgYkCgYEA7wnsvR4XEOfVznf40l8ClLod+7L0y2/+smVV+GM/\n" +
|
||||
"T1/QF/stajAJxXNy08gK00WKZ6ruTHhR9vh/Z6+EQM2RZDCpU0A7LPa3kLE/XTmS\n" +
|
||||
"1MLDu8ntkdlpURpvhdDWem+rl2HU5oZgzV8Jkcov9vXuSjqEDfr45FlPuV40T8+7\n" +
|
||||
"cxsCAwEAAaNPME0wCwYDVR0PBAQDAgPoMB0GA1UdDgQWBBSBwsAhi6Z1kriOs3ty\n" +
|
||||
"uSIujv9a3DAfBgNVHSMEGDAWgBRidC8Dt3dBzYESKpR2tR560sZ0+zANBgkqhkiG\n" +
|
||||
"9w0BAQQFAAOBgQDEiBqd5AMy2SQopFaS3dYkzj8MHlwtbCSoNVYkOfDnewcatrbk\n" +
|
||||
"yFcp6FX++PMdOQFHWvvnDdkCUAzZQp8kCkF9tGLVLBtOK7XxQ1us1LZym7kOPzsd\n" +
|
||||
"G93Dcf0U1JRO77juc61Br5paAy8Bok18Y/MeG7uKgB2MAEJYKhGKbCrfMw==\n" +
|
||||
"-----END CERTIFICATE-----";
|
||||
|
||||
private static final PEMDecoder PEM_DECODER = PEMDecoder.of();
|
||||
|
||||
private static Set<TrustAnchor> generateTrustAnchors()
|
||||
throws CertificateException {
|
||||
// generate certificate from cert string
|
||||
X509Certificate selfSignedCert = PEM_DECODER.decode(selfSignedCertStr, X509Certificate.class);
|
||||
|
||||
// generate a trust anchor
|
||||
TrustAnchor anchor =
|
||||
new TrustAnchor(selfSignedCert, null);
|
||||
|
||||
return Collections.singleton(anchor);
|
||||
}
|
||||
|
||||
private static CertStore generateCertificateStore() throws Exception {
|
||||
Collection<DEREncodable> entries = new HashSet<>();
|
||||
|
||||
// generate certificate from certificate string
|
||||
entries.add(PEM_DECODER.decode(targetCertStr, X509Certificate.class));
|
||||
entries.add(PEM_DECODER.decode(subCaCertStr, X509Certificate.class));
|
||||
entries.add(PEM_DECODER.decode(selfSignedCertStr, X509Certificate.class));
|
||||
entries.add(PEM_DECODER.decode(topCrlIssuerCertStr, X509Certificate.class));
|
||||
entries.add(PEM_DECODER.decode(subCrlIssuerCertStr, X509Certificate.class));
|
||||
|
||||
return CertStore.getInstance("Collection",
|
||||
new CollectionCertStoreParameters(entries));
|
||||
}
|
||||
|
||||
private static X509CertSelector generateSelector(String name)
|
||||
throws Exception {
|
||||
X509CertSelector selector = new X509CertSelector();
|
||||
|
||||
// generate certificate from certificate string
|
||||
CertificateFactory cf = CertificateFactory.getInstance("X.509");
|
||||
ByteArrayInputStream is = null;
|
||||
String cert;
|
||||
if (name.equals("subca")) {
|
||||
cert = subCaCertStr;
|
||||
} else if (name.equals("subci")) {
|
||||
cert = subCrlIssuerCertStr;
|
||||
} else {
|
||||
cert = targetCertStr;
|
||||
}
|
||||
|
||||
X509Certificate target = PEM_DECODER.decode(cert, X509Certificate.class);
|
||||
byte[] extVal = target.getExtensionValue("2.5.29.14");
|
||||
if (extVal != null) {
|
||||
DerInputStream in = new DerInputStream(extVal);
|
||||
byte[] subjectKID = in.getOctetString();
|
||||
selector.setSubjectKeyIdentifier(subjectKID);
|
||||
} else {
|
||||
// unlikely to happen.
|
||||
throw new Exception("unexpected certificate: no SKID extension");
|
||||
}
|
||||
|
||||
return selector;
|
||||
}
|
||||
|
||||
private static boolean match(String name, Certificate cert)
|
||||
throws Exception {
|
||||
|
||||
// generate certificate from certificate string
|
||||
String newCert;
|
||||
if (name.equals("subca")) {
|
||||
newCert = subCaCertStr;
|
||||
} else if (name.equals("subci")) {
|
||||
newCert = subCrlIssuerCertStr;
|
||||
} else {
|
||||
newCert = targetCertStr;
|
||||
}
|
||||
X509Certificate target = PEM_DECODER.decode(newCert, X509Certificate.class);
|
||||
|
||||
return target.equals(cert);
|
||||
}
|
||||
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
// MD5 is used in this test case, don't disable MD5 algorithm.
|
||||
Security.setProperty(
|
||||
"jdk.certpath.disabledAlgorithms", "MD2, RSA keySize < 1024");
|
||||
|
||||
CertPathBuilder builder = CertPathBuilder.getInstance("PKIX");
|
||||
|
||||
X509CertSelector selector = generateSelector(args[0]);
|
||||
|
||||
Set<TrustAnchor> anchors = generateTrustAnchors();
|
||||
CertStore certs = generateCertificateStore();
|
||||
|
||||
|
||||
PKIXBuilderParameters params =
|
||||
new PKIXBuilderParameters(anchors, selector);
|
||||
params.addCertStore(certs);
|
||||
params.setRevocationEnabled(false);
|
||||
params.setDate(new Date(109, 7, 1)); // 2009-07-01
|
||||
Security.setProperty("ocsp.enable", "false");
|
||||
System.setProperty("com.sun.security.enableCRLDP", "false");
|
||||
|
||||
PKIXCertPathBuilderResult result =
|
||||
(PKIXCertPathBuilderResult)builder.build(params);
|
||||
|
||||
if (!match(args[0], result.getCertPath().getCertificates().get(0))) {
|
||||
throw new Exception("unexpected certificate");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,288 @@
|
|||
/*
|
||||
* Copyright (c) 2009, 2025, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
//
|
||||
// Security properties, once set, cannot revert to unset. To avoid
|
||||
// conflicts with tests running in the same VM isolate this test by
|
||||
// running it in otherVM mode.
|
||||
//
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @bug 6852744 8133489
|
||||
* @summary PIT b61: PKI test suite fails because self signed certificates
|
||||
* are being rejected
|
||||
* @enablePreview
|
||||
* @modules java.base/sun.security.util
|
||||
* @run main/othervm -Djava.security.debug=certpath KeyUsageMatters subca
|
||||
* @run main/othervm -Djava.security.debug=certpath KeyUsageMatters subci
|
||||
* @run main/othervm -Djava.security.debug=certpath KeyUsageMatters alice
|
||||
* @author Xuelei Fan
|
||||
*/
|
||||
|
||||
import java.io.*;
|
||||
import java.net.SocketException;
|
||||
import java.security.DEREncodable;
|
||||
import java.security.PEMDecoder;
|
||||
import java.util.*;
|
||||
import java.security.Security;
|
||||
import java.security.cert.*;
|
||||
import java.security.cert.CertPathValidatorException.BasicReason;
|
||||
import sun.security.util.DerInputStream;
|
||||
|
||||
/**
|
||||
* KeyUsage extension plays a important rule during looking for the issuer
|
||||
* of a certificate or CRL. A certificate issuer should have the keyCertSign
|
||||
* bit set, and a CRL issuer should have the cRLSign bit set.
|
||||
*
|
||||
* Sometime, a delegated CRL issuer would also have the keyCertSign bit set,
|
||||
* as would be troublesome to find the proper CRL issuer during certificate
|
||||
* path build if the delegated CRL issuer is a self-issued certificate, for
|
||||
* it is hard to identify it from its issuer by the "issuer" field only.
|
||||
*
|
||||
* The fix of 6852744 should addresses above issue, and allow a delegated CRL
|
||||
* issuer to have keyCertSign bit set.
|
||||
*
|
||||
* In the test case, the delegated CRL issuers have cRLSign bit set only, and
|
||||
* the CAs have the keyCertSign bit set only, it is expected to work before
|
||||
* and after the bug fix of 6852744.
|
||||
*/
|
||||
public final class KeyUsageMatters {
|
||||
|
||||
private static final PEMDecoder PEM_DECODER = PEMDecoder.of();
|
||||
|
||||
// the trust anchor
|
||||
static String selfSignedCertStr =
|
||||
"-----BEGIN CERTIFICATE-----\n" +
|
||||
"MIICPjCCAaegAwIBAgIBADANBgkqhkiG9w0BAQQFADAfMQswCQYDVQQGEwJVUzEQ\n" +
|
||||
"MA4GA1UEChMHRXhhbXBsZTAeFw0wOTA0MjcwMjI0MzJaFw0zMDA0MDcwMjI0MzJa\n" +
|
||||
"MB8xCzAJBgNVBAYTAlVTMRAwDgYDVQQKEwdFeGFtcGxlMIGfMA0GCSqGSIb3DQEB\n" +
|
||||
"AQUAA4GNADCBiQKBgQC4OTag24sTxL2tXTNuvpmUEtdxrYAZoFsslFQ60T+WD9wQ\n" +
|
||||
"Jeiw87FSPsR2vxRuv0j8DNm2a4h7LNNIFcLurfNldbz5pvgZ7VqdbbUMPE9qP85n\n" +
|
||||
"jgDl4woyRTSUeRI4A7O0CO6NpES21dtbdhroWQrEkHxpnrDPxsxrz5gf2m3gqwID\n" +
|
||||
"AQABo4GJMIGGMB0GA1UdDgQWBBSCJd0hpl5PdAD9IZS+Hzng4lXLGzBHBgNVHSME\n" +
|
||||
"QDA+gBSCJd0hpl5PdAD9IZS+Hzng4lXLG6EjpCEwHzELMAkGA1UEBhMCVVMxEDAO\n" +
|
||||
"BgNVBAoTB0V4YW1wbGWCAQAwDwYDVR0TAQH/BAUwAwEB/zALBgNVHQ8EBAMCAgQw\n" +
|
||||
"DQYJKoZIhvcNAQEEBQADgYEAluy6HIjWcq009lTLmhp+Np6dxU78pInBK8RZkza0\n" +
|
||||
"484qGaxFGD3UGyZkI5uWmsH2XuMbuox5khfIq6781gmkPBHXBIEtJN8eLusOHEye\n" +
|
||||
"iE8h7WI+N3qa6Pj56WionMrioqC/3X+b06o147bbhx8U0vkYv/HyPaITOFfMXTdz\n" +
|
||||
"Vjw=\n" +
|
||||
"-----END CERTIFICATE-----";
|
||||
|
||||
// the sub-ca
|
||||
static String subCaCertStr =
|
||||
"-----BEGIN CERTIFICATE-----\n" +
|
||||
"MIICUDCCAbmgAwIBAgIBAzANBgkqhkiG9w0BAQQFADAfMQswCQYDVQQGEwJVUzEQ\n" +
|
||||
"MA4GA1UEChMHRXhhbXBsZTAeFw0wOTA0MjcwMjI0MzRaFw0yOTAxMTIwMjI0MzRa\n" +
|
||||
"MDExCzAJBgNVBAYTAlVTMRAwDgYDVQQKEwdFeGFtcGxlMRAwDgYDVQQLEwdDbGFz\n" +
|
||||
"cy0xMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCiAJnAQW2ad3ZMKUhSJVZj\n" +
|
||||
"8pBqxTcHSTwAVguQkDglsN/OIwUpvR5Jgp3lpRWUEt6idEp0FZzORpvtjt3pr5MG\n" +
|
||||
"Eg2CDptekC5BSPS+fIAIKlncB3HwOiFFhH6b3wTydDCdEd2fvsi4QMOSVrIYMeA8\n" +
|
||||
"P/mCz6kRhfUQPE0CMmOUewIDAQABo4GJMIGGMB0GA1UdDgQWBBT0/nNP8WpyxmYr\n" +
|
||||
"IBp4tN8y08jw2jBHBgNVHSMEQDA+gBSCJd0hpl5PdAD9IZS+Hzng4lXLG6EjpCEw\n" +
|
||||
"HzELMAkGA1UEBhMCVVMxEDAOBgNVBAoTB0V4YW1wbGWCAQAwDwYDVR0TAQH/BAUw\n" +
|
||||
"AwEB/zALBgNVHQ8EBAMCAgQwDQYJKoZIhvcNAQEEBQADgYEAS9PzI6B39R/U9fRj\n" +
|
||||
"UExzN1FXNP5awnAPtiv34kSCL6n6MryqkfG+8aaAOdZsSjmTylNFaF7cW/Xp1VBF\n" +
|
||||
"hq0bg/SbEAbK7+UwL8GSC3crhULHLbh+1iFdVTEwxCw5YmB8ji3BaZ/WKW/PkjCZ\n" +
|
||||
"7cXP6VDeZMG6oRQ4hbOcixoFPXo=\n" +
|
||||
"-----END CERTIFICATE-----";
|
||||
|
||||
// a delegated CRL issuer, it's a self-issued certificate of trust anchor
|
||||
static String topCrlIssuerCertStr =
|
||||
"-----BEGIN CERTIFICATE-----\n" +
|
||||
"MIICKzCCAZSgAwIBAgIBAjANBgkqhkiG9w0BAQQFADAfMQswCQYDVQQGEwJVUzEQ\n" +
|
||||
"MA4GA1UEChMHRXhhbXBsZTAeFw0wOTA0MjcwMjI0MzNaFw0yOTAxMTIwMjI0MzNa\n" +
|
||||
"MB8xCzAJBgNVBAYTAlVTMRAwDgYDVQQKEwdFeGFtcGxlMIGfMA0GCSqGSIb3DQEB\n" +
|
||||
"AQUAA4GNADCBiQKBgQDMJeBMBybHykI/YpwUJ4O9euqDSLb1kpWpceBS8TVqvgBC\n" +
|
||||
"SgUJWtFZL0i6bdvF6mMdlbuBkGzhXqHiVAi96/zRLbUC9F8SMEJ6MuD+YhQ0ZFTQ\n" +
|
||||
"atKy8zf8O9XzztelLJ26Gqb7QPV133WY3haAqHtCXOhEKkCN16NOYNC37DTaJwID\n" +
|
||||
"AQABo3cwdTAdBgNVHQ4EFgQULXSWzXzUOIpOJpzbSCpW42IJUugwRwYDVR0jBEAw\n" +
|
||||
"PoAUgiXdIaZeT3QA/SGUvh854OJVyxuhI6QhMB8xCzAJBgNVBAYTAlVTMRAwDgYD\n" +
|
||||
"VQQKEwdFeGFtcGxlggEAMAsGA1UdDwQEAwIBAjANBgkqhkiG9w0BAQQFAAOBgQAY\n" +
|
||||
"eMnf5AHSNlyUlzXk8o2S0h4gCuvKX6C3kFfKuZcWvFAbx4yQOWLS2s15/nzR4+AP\n" +
|
||||
"FGX3lgJjROyAh7fGedTQK+NFWwkM2ag1g3hXktnlnT1qHohi0w31nVBJxXEDO/Ck\n" +
|
||||
"uJTpJGt8XxxbFaw5v7cHy7XuTAeU/sekvjEiNHW00Q==\n" +
|
||||
"-----END CERTIFICATE-----";
|
||||
|
||||
// a delegated CRL issuer, it's a self-issued certificate of sub-ca
|
||||
static String subCrlIssuerCertStr =
|
||||
"-----BEGIN CERTIFICATE-----\n" +
|
||||
"MIICPTCCAaagAwIBAgIBBDANBgkqhkiG9w0BAQQFADAfMQswCQYDVQQGEwJVUzEQ\n" +
|
||||
"MA4GA1UEChMHRXhhbXBsZTAeFw0wOTA0MjcwMjI0MzRaFw0yOTAxMTIwMjI0MzRa\n" +
|
||||
"MDExCzAJBgNVBAYTAlVTMRAwDgYDVQQKEwdFeGFtcGxlMRAwDgYDVQQLEwdDbGFz\n" +
|
||||
"cy0xMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDWUtDQx2MB/7arDiquMJyd\n" +
|
||||
"LWwSg6p8sg5z6wKrC1v47MT4DBhFX+0RUgTMUdQgYpgxGpczn+6y4zfV76064S0N\n" +
|
||||
"4L/IQ+SunTW1w4yRGjB+xkyyJmWAqijG1nr+Dgkv5nxPI+9Er5lHcoVWVMEcvvRm\n" +
|
||||
"6jIBQdldVlSgv+VgUnFm5wIDAQABo3cwdTAdBgNVHQ4EFgQUkV3Qqtk7gIot9n60\n" +
|
||||
"jX6dloxrfMEwRwYDVR0jBEAwPoAUgiXdIaZeT3QA/SGUvh854OJVyxuhI6QhMB8x\n" +
|
||||
"CzAJBgNVBAYTAlVTMRAwDgYDVQQKEwdFeGFtcGxlggEAMAsGA1UdDwQEAwIBAjAN\n" +
|
||||
"BgkqhkiG9w0BAQQFAAOBgQADu4GM8EdmIKhC7FRvk5jF90zfvZ38wbXBzCjKI4jX\n" +
|
||||
"QJrhne1bfyeNNm5c1w+VKidT+XzBzBGH7ZqYzoZmzRIfcbLKX2brEBKiukeeAyL3\n" +
|
||||
"bctQtbp19tX+uu2dQberD188AAysKTkHcJUV+rRsTwVJ9vcYKxoRxKk8DhH7ZS3M\n" +
|
||||
"rg==\n" +
|
||||
"-----END CERTIFICATE-----";
|
||||
|
||||
// the target EE certificate
|
||||
static String targetCertStr =
|
||||
"-----BEGIN CERTIFICATE-----\n" +
|
||||
"MIICNzCCAaCgAwIBAgIBAjANBgkqhkiG9w0BAQQFADAxMQswCQYDVQQGEwJVUzEQ\n" +
|
||||
"MA4GA1UEChMHRXhhbXBsZTEQMA4GA1UECxMHQ2xhc3MtMTAeFw0wOTA0MjcwMjI0\n" +
|
||||
"MzZaFw0yOTAxMTIwMjI0MzZaMEExCzAJBgNVBAYTAlVTMRAwDgYDVQQKEwdFeGFt\n" +
|
||||
"cGxlMRAwDgYDVQQLEwdDbGFzcy0xMQ4wDAYDVQQDEwVBbGljZTCBnzANBgkqhkiG\n" +
|
||||
"9w0BAQEFAAOBjQAwgYkCgYEAvYSaU3oiE4Pxp/aUIXwMqOwSiWkZ+O3aTu13hRtK\n" +
|
||||
"ZyR+Wtj63IuvaigAC4uC+zBypF93ThjwCzVR2qKDQaQzV8CLleO96gStt7Y+i3G2\n" +
|
||||
"V3IUGgrVCqeK7N6nNYu0wW84sibcPqG/TIy0UoaQMqgB21xtRF+1DUVlFh4Z89X/\n" +
|
||||
"pskCAwEAAaNPME0wCwYDVR0PBAQDAgPoMB0GA1UdDgQWBBSynMEdcal/e9TmvlNE\n" +
|
||||
"4suXGA4+hjAfBgNVHSMEGDAWgBT0/nNP8WpyxmYrIBp4tN8y08jw2jANBgkqhkiG\n" +
|
||||
"9w0BAQQFAAOBgQB/jru7E/+piSmUwByw5qbZsoQZVcgR97pd2TErNJpJMAX2oIHR\n" +
|
||||
"wJH6w4NuYs27+fEAX7wK4whc6EUH/w1SI6o28F2rG6HqYQPPZ2E2WqwbBQL9nYE3\n" +
|
||||
"Vfzu/G9axTUQXFbf90h80UErA+mZVxqc2xtymLuH0YEaMZImtRZ2MXHfXg==\n" +
|
||||
"-----END CERTIFICATE-----";
|
||||
|
||||
// CRL issued by the delegated CRL issuer, topCrlIssuerCertStr
|
||||
static String topCrlStr =
|
||||
"-----BEGIN X509 CRL-----\n" +
|
||||
"MIIBGzCBhQIBATANBgkqhkiG9w0BAQQFADAfMQswCQYDVQQGEwJVUzEQMA4GA1UE\n" +
|
||||
"ChMHRXhhbXBsZRcNMDkwNDI3MDIzODA0WhcNMjgwNjI2MDIzODA0WjAiMCACAQUX\n" +
|
||||
"DTA5MDQyNzAyMzgwMFowDDAKBgNVHRUEAwoBBKAOMAwwCgYDVR0UBAMCAQIwDQYJ\n" +
|
||||
"KoZIhvcNAQEEBQADgYEAoarfzXEtw3ZDi4f9U8eSvRIipHSyxOrJC7HR/hM5VhmY\n" +
|
||||
"CErChny6x9lBVg9s57tfD/P9PSzBLusCcHwHMAbMOEcTltVVKUWZnnbumpywlYyg\n" +
|
||||
"oKLrE9+yCOkYUOpiRlz43/3vkEL5hjIKMcDSZnPKBZi1h16Yj2hPe9GMibNip54=\n" +
|
||||
"-----END X509 CRL-----";
|
||||
|
||||
// CRL issued by the delegated CRL issuer, subCrlIssuerCertStr
|
||||
static String subCrlStr =
|
||||
"-----BEGIN X509 CRL-----\n" +
|
||||
"MIIBLTCBlwIBATANBgkqhkiG9w0BAQQFADAxMQswCQYDVQQGEwJVUzEQMA4GA1UE\n" +
|
||||
"ChMHRXhhbXBsZTEQMA4GA1UECxMHQ2xhc3MtMRcNMDkwNDI3MDIzODA0WhcNMjgw\n" +
|
||||
"NjI2MDIzODA0WjAiMCACAQQXDTA5MDQyNzAyMzgwMVowDDAKBgNVHRUEAwoBBKAO\n" +
|
||||
"MAwwCgYDVR0UBAMCAQIwDQYJKoZIhvcNAQEEBQADgYEAeS+POqYEIHIIJcsLxuUr\n" +
|
||||
"aJFzQ/ujH0QmnyMNEL3Uavyq4VQuAahF+w6aTPb5UBzms0uX8NAvD2vNoUJvmJOX\n" +
|
||||
"nGKuq4Q1DFj82E7/9d25nXdWGOmFvFCRVO+St2Xe5n8CJuZNBiz388FDSIOiFSCa\n" +
|
||||
"ARGr6Qu68MYGtLMC6ZqP3u0=\n" +
|
||||
"-----END X509 CRL-----";
|
||||
|
||||
private static Set<TrustAnchor> generateTrustAnchors()
|
||||
throws CertificateException {
|
||||
|
||||
// generate certificate from cert string
|
||||
X509Certificate selfSignedCert = PEM_DECODER.decode(selfSignedCertStr, X509Certificate.class);
|
||||
|
||||
// generate a trust anchor
|
||||
TrustAnchor anchor =
|
||||
new TrustAnchor(selfSignedCert, null);
|
||||
|
||||
return Collections.singleton(anchor);
|
||||
}
|
||||
|
||||
private static CertStore generateCertificateStore() throws Exception {
|
||||
Collection<DEREncodable> entries = new HashSet<>();
|
||||
|
||||
// Decode and add certificates
|
||||
entries.add(PEM_DECODER.decode(targetCertStr, X509Certificate.class));
|
||||
entries.add(PEM_DECODER.decode(subCaCertStr, X509Certificate.class));
|
||||
entries.add(PEM_DECODER.decode(selfSignedCertStr, X509Certificate.class));
|
||||
entries.add(PEM_DECODER.decode(topCrlIssuerCertStr, X509Certificate.class));
|
||||
entries.add(PEM_DECODER.decode(subCrlIssuerCertStr, X509Certificate.class));
|
||||
|
||||
// Decode and add CRLs
|
||||
entries.add(PEM_DECODER.decode(topCrlStr, X509CRL.class));
|
||||
entries.add(PEM_DECODER.decode(subCrlStr, X509CRL.class));
|
||||
return CertStore.getInstance("Collection",
|
||||
new CollectionCertStoreParameters(entries));
|
||||
}
|
||||
|
||||
private static X509CertSelector generateSelector(String name)
|
||||
throws Exception {
|
||||
X509CertSelector selector = new X509CertSelector();
|
||||
|
||||
// generate certificate from certificate string
|
||||
String cert;
|
||||
if (name.equals("subca")) {
|
||||
cert = subCaCertStr;
|
||||
} else if (name.equals("subci")) {
|
||||
cert = subCrlIssuerCertStr;
|
||||
} else {
|
||||
cert = targetCertStr;
|
||||
}
|
||||
|
||||
X509Certificate target = PEM_DECODER.decode(cert, X509Certificate.class);
|
||||
byte[] extVal = target.getExtensionValue("2.5.29.14");
|
||||
if (extVal != null) {
|
||||
DerInputStream in = new DerInputStream(extVal);
|
||||
byte[] subjectKID = in.getOctetString();
|
||||
selector.setSubjectKeyIdentifier(subjectKID);
|
||||
} else {
|
||||
// unlikely to happen.
|
||||
throw new Exception("unexpected certificate: no SKID extension");
|
||||
}
|
||||
|
||||
return selector;
|
||||
}
|
||||
|
||||
private static boolean match(String name, Certificate cert) {
|
||||
|
||||
// generate certificate from certificate string
|
||||
String newCert;
|
||||
if (name.equals("subca")) {
|
||||
newCert = subCaCertStr;
|
||||
} else if (name.equals("subci")) {
|
||||
newCert = subCrlIssuerCertStr;
|
||||
} else {
|
||||
newCert = targetCertStr;
|
||||
}
|
||||
X509Certificate target = PEM_DECODER.decode(newCert, X509Certificate.class);
|
||||
|
||||
return target.equals(cert);
|
||||
}
|
||||
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
// MD5 is used in this test case, don't disable MD5 algorithm.
|
||||
Security.setProperty(
|
||||
"jdk.certpath.disabledAlgorithms", "MD2, RSA keySize < 1024");
|
||||
|
||||
CertPathBuilder builder = CertPathBuilder.getInstance("PKIX");
|
||||
|
||||
X509CertSelector selector = generateSelector(args[0]);
|
||||
|
||||
Set<TrustAnchor> anchors = generateTrustAnchors();
|
||||
CertStore certs = generateCertificateStore();
|
||||
|
||||
|
||||
PKIXBuilderParameters params =
|
||||
new PKIXBuilderParameters(anchors, selector);
|
||||
params.addCertStore(certs);
|
||||
params.setRevocationEnabled(true);
|
||||
params.setDate(new Date(109, 5, 1)); // 2009-05-01
|
||||
Security.setProperty("ocsp.enable", "false");
|
||||
System.setProperty("com.sun.security.enableCRLDP", "true");
|
||||
|
||||
PKIXCertPathBuilderResult result =
|
||||
(PKIXCertPathBuilderResult)builder.build(params);
|
||||
|
||||
if (!match(args[0], result.getCertPath().getCertificates().get(0))) {
|
||||
throw new Exception("unexpected certificate");
|
||||
}
|
||||
}
|
||||
}
|
||||
382
test/jdk/java/security/cert/CertPathBuilder/selfIssued/README
Normal file
382
test/jdk/java/security/cert/CertPathBuilder/selfIssued/README
Normal file
|
|
@ -0,0 +1,382 @@
|
|||
/*
|
||||
* Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
Certificates and CRLs
|
||||
|
||||
The certificates and CRLs used by KeyUsageMatters.java are copied from
|
||||
test/java/security/cert/CertPathValidator/indirectCRL.
|
||||
|
||||
Here lists the local generated certificates and CRLs used in the test cases.
|
||||
|
||||
The generate.sh depends on openssl, and it should be run under ksh. The
|
||||
script will create many directories and files, please run it in a
|
||||
directory outside of JDK workspace.
|
||||
|
||||
1. root certifiate and key
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIICPjCCAaegAwIBAgIBADANBgkqhkiG9w0BAQQFADAfMQswCQYDVQQGEwJVUzEQ
|
||||
MA4GA1UEChMHRXhhbXBsZTAeFw0wOTA2MjgxMzMyMThaFw0zMDA2MDgxMzMyMTha
|
||||
MB8xCzAJBgNVBAYTAlVTMRAwDgYDVQQKEwdFeGFtcGxlMIGfMA0GCSqGSIb3DQEB
|
||||
AQUAA4GNADCBiQKBgQDInJhXi0655bPXAVkz1n5I6fAcZejzPnOPuwq3hU3OxFw8
|
||||
81Uf6o9oKI1h4w4XAD8u1cUNOgiX+wPwojronlp68bIfO6FVhNf287pLtLhNJo+7
|
||||
m6Qxw3ymFvEKy+PVj20CHSggdKHxUa4MBZBmHMFNBuxfYmjwzn+yTMmCCXOvSwID
|
||||
AQABo4GJMIGGMB0GA1UdDgQWBBSQ52Dpau+gtL+Kc31dusYnKj16ZTBHBgNVHSME
|
||||
QDA+gBSQ52Dpau+gtL+Kc31dusYnKj16ZaEjpCEwHzELMAkGA1UEBhMCVVMxEDAO
|
||||
BgNVBAoTB0V4YW1wbGWCAQAwDwYDVR0TAQH/BAUwAwEB/zALBgNVHQ8EBAMCAQYw
|
||||
DQYJKoZIhvcNAQEEBQADgYEAjBt6ea65HCqbGsS2rs/HhlGusYXtThRVC5vwXSey
|
||||
ZFYwSgukuq1KDzckqZFu1meNImEwdZjwxdN0e2p/nVREPC42rZliSj6V1ThayKXj
|
||||
DWEZW1U5aR8T+3NYfDrdKcJGx4Hzfz0qKz1j4ssV1M9ptJxYYv4y2Da+592IN1S9
|
||||
v/E=
|
||||
-----END CERTIFICATE-----
|
||||
|
||||
-----BEGIN RSA PRIVATE KEY-----
|
||||
Proc-Type: 4,ENCRYPTED
|
||||
DEK-Info: DES-EDE3-CBC,46F13CECA9B38323
|
||||
|
||||
AVNWPH7jiPyJVq9KfL3IlGVCwD41KVapg12yJR2t/WWlLaKr19/0oWNvimcrd040
|
||||
txFKvcFO9TFLxmaco33+actCoL0K/XbrCBICThZLybzcFTuYFMum8eqL61avQgBe
|
||||
Kt4CCjcupWLzKWkKTMV/bP6nPnPUSB9U8QeGwutjJYnLDi0TuYx8YSqZo/36vM98
|
||||
r3OvtcSA5XEN4guxxHusZJnhbclVb/Z1WtLVb4v2d5yBtPM2p3R0hK17L4Dnusjl
|
||||
n56z6Z0AIYmfAggM/Fpge2uT3D/5n//l1lZRNoSvsX5UZipKswZKLpvx7IJ+AqgA
|
||||
UO9lcmNLGnIXME3IS3smd83wPi7nxH3NCYWHbGAKLm6mkFMs5LOhofUMOBS3Rxmm
|
||||
2RjCGtuzDxBPKveo9/Y80B//6sEce2gdi7fCKgWwtR4VFuJd0hWODD6CarK3edHH
|
||||
rUG62Kt2aqiI/y/NLEbfHCHbyM37c9/OzS5Zy695dDl22r5EirVFsVgejQR1JGtP
|
||||
ANdc6kkkJW+s6GiqimShssMTp1x0L8twT/+wEa38LafiaPKk4OweleBuyz7k2FxA
|
||||
Rr2u9IOvGU3eKAeH8HSFWvaNE9S2lYFPiWWZ6O/LzVvnb847+gungQ7SPRzOkt4k
|
||||
L4PtHIoKmLWFr5tzML1Q8wiaKcTWMb5LZbRbo+2XYGoIpilxkBBuhX7cMJFwOHEf
|
||||
YJJRixBI97doPsnIQ3GkA8xY+INzQ4LWNQbnEtS7L7t26NA9tDlg4ILU/UfMoQIp
|
||||
Ol4EZY1U7gD8BeMwo2vX3x/WA+a7R2N95klBFNqn9jSkm6a5yoeCZw==
|
||||
-----END RSA PRIVATE KEY-----
|
||||
|
||||
|
||||
2. root crl issuer and key
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIICPjCCAaegAwIBAgIBAjANBgkqhkiG9w0BAQQFADAfMQswCQYDVQQGEwJVUzEQ
|
||||
MA4GA1UEChMHRXhhbXBsZTAeFw0wOTA2MjgxMzMyMjNaFw0yOTAzMTUxMzMyMjNa
|
||||
MB8xCzAJBgNVBAYTAlVTMRAwDgYDVQQKEwdFeGFtcGxlMIGfMA0GCSqGSIb3DQEB
|
||||
AQUAA4GNADCBiQKBgQC99u93trf+WmpfiqunJy/P31ej1l4rESxft2JSGNjKuLFN
|
||||
/BO3SAugGJSkCARAwXjB0c8eeXhXWhVVWdNpbKepRJTxrjDfnFIavLgtUvmFwn/3
|
||||
hPXe+RQeA8+AJ99Y+o+10kY8JAZLa2j93C2FdmwOjUbo8aIz85yhbiV1tEDjLwID
|
||||
AQABo4GJMIGGMB0GA1UdDgQWBBSyFyA3XWLbdL6W6hksmBn7RKsQmDBHBgNVHSME
|
||||
QDA+gBSQ52Dpau+gtL+Kc31dusYnKj16ZaEjpCEwHzELMAkGA1UEBhMCVVMxEDAO
|
||||
BgNVBAoTB0V4YW1wbGWCAQAwDwYDVR0TAQH/BAUwAwEB/zALBgNVHQ8EBAMCAQYw
|
||||
DQYJKoZIhvcNAQEEBQADgYEAHTm8aRTeakgCfEBCgSWK9wvMW1c18ANGMm8OFDBk
|
||||
xabVy9BT0MVFHlaneh89oIxTZN0FMTpg21GZMAvIzhEt7DGdO7HLsW7JniN7/OZ0
|
||||
rACmpK5frmZrLS03zUm8c+rTbazNfYLoZVG3/mDZbKIi+4y8IGnFcgLVsHsYoBNP
|
||||
G0c=
|
||||
-----END CERTIFICATE-----
|
||||
|
||||
-----BEGIN RSA PRIVATE KEY-----
|
||||
Proc-Type: 4,ENCRYPTED
|
||||
DEK-Info: DES-EDE3-CBC,3881A5676C1AD5E5
|
||||
|
||||
KgaAtGlIQXVnsoifcd1oTi4hS1J+InHISFcZepI1h1hrU9KVAJAlwD1GIeM2qAkG
|
||||
P1ABsA0TE0yRJpd3qHih2IPtD42osfc3HmNTw17nh4Trd3ESilrs4w/rrH8e6bR5
|
||||
WlqG0OKsw8x57t44m9yX94+pP3tdPaJwnFk5M7pDCO44IZskmy10S0NHBn7wMwM/
|
||||
mqlZ15mK6YZTwOuLzpdSDJqYPLiv77KpfeiqSN++ISXoNhIcNYHRVyErAS/DcBlx
|
||||
mbrmBaGexhuagQYqVikEDIvg8kBDWD92EjOFbz94Z6eTvliauJ/+E1/Ffefe2cN5
|
||||
LaVwuUsiyW9GjarWwBJDFrXesTikklshC9V35j/ACHVdh5CuO8FGfVijIwlbZ14N
|
||||
xKWJdSlZlJgEjkwUlWfi1KmrFrob+yK20fGMWr3oY1rTKWZdYkrqnnKEYcMQV/TH
|
||||
XNY77D5idJ3FLtvJyziqIFuohdatQsu6xFP5UEOeUi6OhptJDjjS+zDhiBlL4cqA
|
||||
klThzvuycxjZT+5xno0f8GEnZkQNcC6xxPoP6vstNMKLz1rI1CVUSXZBHc5nfMaF
|
||||
m75rrLbvf6F2NLUspaNXnW8TUMHxcu8nNCnM4/u6hkqebQo/N8X1/v1HImsewwWO
|
||||
P5uJwqmqfuRz0vZyMKAk3FzQIfrjJouxDfkNV2YHM9VP/grPlDgzmgiN0+6bCbn+
|
||||
RW2K8kvkSFZehQ1Ygdst9KYH3NEcEYVYY9pH1N1xRNAylcIDJNwrFwf9vfwjt9/q
|
||||
AVsyDxUBT/KVCcqr15LNNq9HmmcP6IZZMRjdyf2BR+/cobxxDRZq1Q==
|
||||
-----END RSA PRIVATE KEY-----
|
||||
|
||||
|
||||
3. root CRL issued by root crl issuer.
|
||||
-----BEGIN X509 CRL-----
|
||||
MIIBGzCBhQIBATANBgkqhkiG9w0BAQQFADAfMQswCQYDVQQGEwJVUzEQMA4GA1UE
|
||||
ChMHRXhhbXBsZRcNMDkwNjI4MTMzMjM4WhcNMjgwODI3MTMzMjM4WjAiMCACAQUX
|
||||
DTA5MDYyODEzMzIzN1owDDAKBgNVHRUEAwoBBKAOMAwwCgYDVR0UBAMCAQEwDQYJ
|
||||
KoZIhvcNAQEEBQADgYEAVUIeu2x7ZwsliafoCBOg+u8Q4S/VFfTe/SQnRyTM3/V1
|
||||
v+Vn5Acc7eo8Rh4AHcnFFbLNk38n6lllov/CaVR0IPZ6hnrNHVa7VYkNlRAwV2aN
|
||||
GUUhkMMOLVLnN25UOrN9J637SHmRE6pB+TRMaEQ73V7UNlWxuSMK4KofWen0A34=
|
||||
-----END X509 CRL-----
|
||||
|
||||
|
||||
4. subca certificate and key
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIICUDCCAbmgAwIBAgIBAzANBgkqhkiG9w0BAQQFADAfMQswCQYDVQQGEwJVUzEQ
|
||||
MA4GA1UEChMHRXhhbXBsZTAeFw0wOTA2MjgxMzMyMjRaFw0yOTAzMTUxMzMyMjRa
|
||||
MDExCzAJBgNVBAYTAlVTMRAwDgYDVQQKEwdFeGFtcGxlMRAwDgYDVQQLEwdDbGFz
|
||||
cy0xMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDPFv24SK78VI0gWlyIrq/X
|
||||
srl1431K5hJJxMYZtaQunyPmrYg3oI9KvKFykxnR0N4XDPaIi75p9dXGppVu80BA
|
||||
+csvIPBwlBQoNmKDQWTziDOqfK4tE+IMuL/Y7pxnH6CDMY7VGpvatty2zcmH+m/v
|
||||
E/n+HPyeELJQT2rT/3T+7wIDAQABo4GJMIGGMB0GA1UdDgQWBBRidC8Dt3dBzYES
|
||||
KpR2tR560sZ0+zBHBgNVHSMEQDA+gBSQ52Dpau+gtL+Kc31dusYnKj16ZaEjpCEw
|
||||
HzELMAkGA1UEBhMCVVMxEDAOBgNVBAoTB0V4YW1wbGWCAQAwDwYDVR0TAQH/BAUw
|
||||
AwEB/zALBgNVHQ8EBAMCAQYwDQYJKoZIhvcNAQEEBQADgYEAMeMKqrMr5d3eTQsv
|
||||
MYOD15Dl3THQGLAa4ad5Eyq5/1eUeEOpztzCgDfi0iPD8YCubIEVasBTSqTiGXqb
|
||||
RpGuPHOwwfWvHrTeHSludiFBAUiKj7aEV+oQa0FBn4U4TT8HA62HQ93FhzTDI3jP
|
||||
iil34GktVl6gfMKGzUEW/Dh8OM4=
|
||||
-----END CERTIFICATE-----
|
||||
|
||||
-----BEGIN RSA PRIVATE KEY-----
|
||||
Proc-Type: 4,ENCRYPTED
|
||||
DEK-Info: DES-EDE3-CBC,35408AD3018F0049
|
||||
|
||||
4t6WfpFNqpOr47Wc/OAt8+KZK0+WX7d3nlJn47W+QN7AkPfBlLBpcQJkImhP4/eh
|
||||
aJyk8fPOdUhT/4rgc5ORuKk4d9boD36KK5Iz/+/oNBxzuld6TybVb+Hvw41cIZTW
|
||||
CtkvADQpR8XWbPre+3ZH2eAKoTeWX0xR7pYg1JsFk9vxee6U82iqsAYRdUOdot8D
|
||||
9zdDbbeaLWs78UbZkxFtuXREuyNVX880Q17t8qszJL2KmmtMQpUvxTlW04Ope1Ug
|
||||
uIuOxeannzpKRD+37fj+oacM3GRqVFOP47/NVaziOexDBn4b5nlW6OMro6t0qiHt
|
||||
1GLJcw1oLXoFe8ycexfzYWUiHymSz5Vh3wIflsQY+Ik6dopL+fpk2cVD0bncKJlf
|
||||
Ie9PvL04RwannRjgtPl9X05tzcgeyznp2Ix1/rsriZQQpdPTLGA6w6kUhQeK6TwT
|
||||
eX7pXn3iLTGK+VoHRfbxBQR2Fvq1nRJbvsmJFhPOcJU5CYSaDPGGdA6NorbdVgbc
|
||||
14DlkhzojhEpZ7DaUeFNUXUMlQOR5UUTZB+wL3zQoY/FzHci3JD1Gj4NlbC9mMEg
|
||||
ncWZcpZWOnP2kHSz2o/UOxQM80gerukI7NOr020iJ+ZZRb/gyAAzLPnD+mCZ7/e2
|
||||
JJ3x6yHOtVA6WzZiQH1d9/bm79rtcWaRH83X/idG1lHuKXQJFAaw5f7Z2n2/yuF1
|
||||
9pZf7el1M7UoBf74oc68klAl46f4inroy8anAtc/qjSTXUYQrNvKZsWU9AZVS7oH
|
||||
iEuYMVW4KiZh3SHsIg5TZdMbdVYtZpcTsl/Kh6XuY0o0Xsi+rTK5AA==
|
||||
-----END RSA PRIVATE KEY-----
|
||||
|
||||
|
||||
5. crl issuer of subca, the certificate and key
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIICUDCCAbmgAwIBAgIBBDANBgkqhkiG9w0BAQQFADAfMQswCQYDVQQGEwJVUzEQ
|
||||
MA4GA1UEChMHRXhhbXBsZTAeFw0wOTA2MjgxMzMyMjdaFw0yOTAzMTUxMzMyMjda
|
||||
MDExCzAJBgNVBAYTAlVTMRAwDgYDVQQKEwdFeGFtcGxlMRAwDgYDVQQLEwdDbGFz
|
||||
cy0xMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC+8AcLJtGAVUWvv3ifcyQw
|
||||
OGqwzcPrBw/XCs6vTMlcdtFzcH1M+Z3/QHN9+5VT1gqeTIZ+b8g9005Og3XKy/HX
|
||||
obXZeLv20VZsr+jm52ySghEYOVCTJ9OyFOAp5adp6nf0cA66Feh3LsmVhpTEcDOG
|
||||
GnyntQm0DBYxRoOT/GBlvQIDAQABo4GJMIGGMB0GA1UdDgQWBBSRWhMuZLQoHSDN
|
||||
xhxr+vdDmfAY8jBHBgNVHSMEQDA+gBSQ52Dpau+gtL+Kc31dusYnKj16ZaEjpCEw
|
||||
HzELMAkGA1UEBhMCVVMxEDAOBgNVBAoTB0V4YW1wbGWCAQAwDwYDVR0TAQH/BAUw
|
||||
AwEB/zALBgNVHQ8EBAMCAQYwDQYJKoZIhvcNAQEEBQADgYEAMIDZLdOLFiPyS1bh
|
||||
Ch4eUYHT+K1WG93skbga3kVYg3GSe+gctwkKwKK13bwfi8zc7wwz6MtmQwEYhppc
|
||||
pKKKEwi5QirBCP54rihLCvRQaj6ZqUJ6VP+zPAqHYMDbzlBbHtVF/1lQUP30I6SV
|
||||
Fu987DvLmZ2GuQA9FKJsnlD9pbU=
|
||||
-----END CERTIFICATE-----
|
||||
|
||||
-----BEGIN RSA PRIVATE KEY-----
|
||||
Proc-Type: 4,ENCRYPTED
|
||||
DEK-Info: DES-EDE3-CBC,4CD10EAA24AF8C25
|
||||
|
||||
6pTRc9jsn6CJ2EMYhuGX3aWrDThhacnqdtsKIqUzX8Ga7Jz9kq6HseTRlqPkzBfb
|
||||
rCl+eVIkgugrPbf93375mP/ozY8LkEgD9TRAL1uXqha2N6TRLC2ozQJQSoIc441e
|
||||
UZ9XkB6tPGRfPNvi1xE0WTP7bjOUkvkPU9wM9QFuBW6B7mRf3tG2nqkFiTpY6nz8
|
||||
5X5+h9jafcCvMwYhfJm0JFTGWmX4WJWubs8QeYndvIriDDw2zpVNcno45sClSQCb
|
||||
YVekMLgGlKPmNGub5iRfXsozykE3jbMnXRokxrvzk20jjo0XYPVGfCRe9IhJh8Ud
|
||||
iCG/kPaJspbUkUlKXfvIOdp2pnoDFZI5hbfc75YrFYJ8x8dwRYBUl6yRtBkw5Yo/
|
||||
VQDuNq3d7YpxiGxVTwFox6HQ5+rs6jwSGzOilgOCxPSs41fYcdAlogNqLzjvhn+e
|
||||
0GU1XTVyMJbO0Ae6Sgm4PmxU7QM2bdzESuZWbYRFbH2ywwmoR8SahB3ICBhuIA/l
|
||||
lsCrBbq+jL/K2IL1VXBKuaKBN1ShKUPZD/ABWNv4uENNg2AFq1XQ6kvTU8Glfhd9
|
||||
tyK8YnJ0ViY4VLGhdf0s2eEPmbfxOv0HCW0sz/57eASoQSTJTdVApYopWHBOwaNq
|
||||
8qQUEPDMTKaPNqCjA2m/NwGrLPHhU0d5dHmp+9gTbCTmWy4sVenhBPbOy6wvFpNA
|
||||
F+35tJVaZQOOurm/KC2dLOYkKyAvqnB7D2q4zducpWkiyCweg7uYL14Mo5JQmGuq
|
||||
2DwfRiMxdqqoqHFKEOxsoAMrKSwJlYojUknfz/LEaqxtMePQtNwhjw==
|
||||
-----END RSA PRIVATE KEY-----
|
||||
|
||||
|
||||
6. CLR issued by subca CRL issuer
|
||||
-----BEGIN X509 CRL-----
|
||||
MIIBLTCBlwIBATANBgkqhkiG9w0BAQQFADAxMQswCQYDVQQGEwJVUzEQMA4GA1UE
|
||||
ChMHRXhhbXBsZTEQMA4GA1UECxMHQ2xhc3MtMRcNMDkwNjI4MTMzMjQzWhcNMjgw
|
||||
ODI3MTMzMjQzWjAiMCACAQQXDTA5MDYyODEzMzIzOFowDDAKBgNVHRUEAwoBBKAO
|
||||
MAwwCgYDVR0UBAMCAQEwDQYJKoZIhvcNAQEEBQADgYEACQZEf6ydb3fKTMPJ8DBO
|
||||
oo630MsrT3P0x0AC4+aQOueCBaGpNqW/H379uZxXAad7yr+aXUBwaeBMYVKUbwOe
|
||||
5TrN5QWPe2eCkU+MSQvh1SHASDDMH4jhWFMRdO3aPMDKKPlO/Q3s0G72eD7Zo5dr
|
||||
N9AvUXxGxU4DruoJuFPcrCI=
|
||||
-----END X509 CRL-----
|
||||
|
||||
|
||||
7. dumca certificate and key
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIICUDCCAbmgAwIBAgIBBTANBgkqhkiG9w0BAQQFADAfMQswCQYDVQQGEwJVUzEQ
|
||||
MA4GA1UEChMHRXhhbXBsZTAeFw0wOTA2MjgxMzMyMjhaFw0yOTAzMTUxMzMyMjha
|
||||
MDExCzAJBgNVBAYTAlVTMRAwDgYDVQQKEwdFeGFtcGxlMRAwDgYDVQQLEwdDbGFz
|
||||
cy1EMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDeWn+ulgls9+dK3KzzfC1b
|
||||
a9RMSf+gjv/Olw5386Vw6pJOVngR11RytWJoLiKbjYPyGhP1cms2FoUKuAEO31gD
|
||||
3AoUCa+nXgaMLiDtmdC5ATqVv3Oap5aNgAqq0mxMxOylKgcUhfuH2icEnfBtHzEe
|
||||
ST11S69zQr5GGfa/XslbDQIDAQABo4GJMIGGMB0GA1UdDgQWBBRCmXIsp4G3iP7Z
|
||||
Qv4gS19W8W/cLzBHBgNVHSMEQDA+gBSQ52Dpau+gtL+Kc31dusYnKj16ZaEjpCEw
|
||||
HzELMAkGA1UEBhMCVVMxEDAOBgNVBAoTB0V4YW1wbGWCAQAwDwYDVR0TAQH/BAUw
|
||||
AwEB/zALBgNVHQ8EBAMCAQYwDQYJKoZIhvcNAQEEBQADgYEAkRiLpJesXyNQ34ZP
|
||||
Oc4d0gvCl4pyNHx5gsV0yHtxP7oYoIa7Bw4setplQ9Y2YcH5xuXK84xvAby9csWp
|
||||
cod1QOkFzZfb9qj10PXfD8bMoLOyrZfr5nsNAl2scvOtnM1TFL/ll5/S2PVcPthx
|
||||
Z5t128UNQYMu93OmVjZANL5L6Jw=
|
||||
-----END CERTIFICATE-----
|
||||
|
||||
-----BEGIN RSA PRIVATE KEY-----
|
||||
Proc-Type: 4,ENCRYPTED
|
||||
DEK-Info: DES-EDE3-CBC,11485599004D2482
|
||||
|
||||
R+TgUoQo1Ksqpnwh1B1x3u7jxd1qJsfG5st7WJaeJzSY3v+ZnmTS4O008eKgw6Z1
|
||||
eGJevsNW8Z8ButjChzlesCm+90jpKpOqA6MlvzeknAxtGdEfe8rUEytfNOorjJTy
|
||||
1Mu9T8Tlk6tmmmXNTDX1lQytYaHA4e4VVEbYGNceMNcPonT1Y0SyebJwtfd4XKkG
|
||||
Ty40kMnb+qrFr1ZxVRG+LWKDR/bS0S2K2zY6Ha45d8yoYZlgLZ7yVAlrp0T0PF4B
|
||||
UWvSyNK9VOBLrvqXSofK5gNGkR/C63x8FU2V25ISicBQBXLNo9OgIsbrryHF330T
|
||||
2TxhnOpFU1AwgTSfp4Fy/Htkvgo7/jmFRa3r4xelTdEUKvRrwaZeMjg0fT+24529
|
||||
8o8MMOF0YWNtIDNUVRFg9/DgAsD/LoXbOGc/E2ryJdq1D4N914s4m/D5Sox27iu4
|
||||
3op/dt+WMoA0g/YbjhWn2cAfWcH9P8p8/n/FUO8APmGI3aHbtOhJQ8qwxcalp6kO
|
||||
fICWsW4ygWtdpnyJWzAY0Udtsl8mglTppGTl59OYZmlDQTLhJ1hWiXLeNKj0pGPz
|
||||
bAJ5jGQN8zXAk83j019rI5WveAdWp+w1XRGvmPxLL3heojHrkutuYLQ0LOcFwNvg
|
||||
OqmPvZneRBoy6Yshp0XyYy+qioxDm+Vd/NV1/aCWgQXJA3vFqUg3AURLFHHTh+7h
|
||||
fa3DDCLtdg/wJkRtOWjFhq0hgx5sb9zVv8HCuMERbZJbWwDOfSrHJwXj4KaTHVqY
|
||||
OWfBE9vzeAxRpdpe69SZWYg3tyu7uSf6a5Rp55iMI3kjuQMCanvsNA==
|
||||
-----END RSA PRIVATE KEY-----
|
||||
|
||||
|
||||
8. crl issuer for dumca, the certificate and key
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIICUDCCAbmgAwIBAgIBBjANBgkqhkiG9w0BAQQFADAfMQswCQYDVQQGEwJVUzEQ
|
||||
MA4GA1UEChMHRXhhbXBsZTAeFw0wOTA2MjgxMzMyMjlaFw0yOTAzMTUxMzMyMjla
|
||||
MDExCzAJBgNVBAYTAlVTMRAwDgYDVQQKEwdFeGFtcGxlMRAwDgYDVQQLEwdDbGFz
|
||||
cy1EMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDF7NjUUWji4pPmFg3qx4HB
|
||||
kjtInwe7i2lPjRUN0ZwTcWob2RaD1+fhc7seeNmnypjERTa9TXF5cs2PgSHWNISC
|
||||
QbQpbobOUcSsV/6Lr0kvrHJuVowcX13VsApGSJavVs2oJqUiFGNpnch8yR/pMHJf
|
||||
hsd/Go+nUXMOl2xN31DMFQIDAQABo4GJMIGGMB0GA1UdDgQWBBS1XVE2CYKHgO7t
|
||||
1koYVTu2w7xgNTBHBgNVHSMEQDA+gBSQ52Dpau+gtL+Kc31dusYnKj16ZaEjpCEw
|
||||
HzELMAkGA1UEBhMCVVMxEDAOBgNVBAoTB0V4YW1wbGWCAQAwDwYDVR0TAQH/BAUw
|
||||
AwEB/zALBgNVHQ8EBAMCAQYwDQYJKoZIhvcNAQEEBQADgYEAHYraYtdetZFOiTUR
|
||||
dhvUi556el1WT25O8pF21YAzRI7KI4yzl6deD29DtcIPiBc8H1A4U6OhwXSQsqTd
|
||||
taOHHdZxnU+m078mb231OPVvo48uZwpnX35g/qItW+Nb/dIEb08537oQKoGgL0hV
|
||||
sKZPWod70JBkJabDuUirorhlk4A=
|
||||
-----END CERTIFICATE-----
|
||||
|
||||
-----BEGIN RSA PRIVATE KEY-----
|
||||
Proc-Type: 4,ENCRYPTED
|
||||
DEK-Info: DES-EDE3-CBC,1E0E5983F90A10E0
|
||||
|
||||
KdPTRmJjeKXFTgdVIgP0eu+m0evwVD2QFMkT3pPI9HELRxtkgIQzjK8F0KIHK9vi
|
||||
Ur0CMgJkX0zs2v7HIG7jvfQ2fREidRTk1g3xCjHXVbpwjWN2dbo+mR0J2zzxNILy
|
||||
mSs13PlDPdV81Vkn1WkMY0lhdrEpR6senQ4KIiMJTMsWZabG3lyFM6d7ag7CDVC+
|
||||
jnsUFg2XW5dYP/kb09p14+CdiQwruNVeVEWhWPG1pAjl7hXCEM5ssz9fNk6Gyh2X
|
||||
OXB2mMysqTkt+qB+OIqLKj3NTUs2ovVQZnaCaynsnMYTcIEFmv3lC0gJHYAZtBXf
|
||||
IkySb+VaB7wmk1CI1+texDU8+B2sq7wmqX0SLY7dMwkbxP1kydn9U5i4Gqmdxpw5
|
||||
4+jn7dB6oKfVFlXIZTZzhmN44cIdai48qVmse1BRDxUdfmlgd9C2W1mw4N60BXbt
|
||||
DeNr8ua5UtcUOXBGJk6VEJapDU/dnnANhVR4R48Y9t+g1qlhwHB4zbSrAIJ5Rsbg
|
||||
6pvdt7BQmFXtm4flZbf21Lr8awWkNFdc/k/3uXA6xemgsFNxPZXlpXO26KpIP+nz
|
||||
lt9Q82WxIkzE+BvO+qd5wMqQ/GC/ztO8GJeGdRIo6un7KkNKs2AZDoCELo2lO53B
|
||||
EBWHeABtJpB1Fw3lW3iJn0A6YbYzK1omztoNMkesBIi0QI5L/e0tq4Mp+LUjLm+Y
|
||||
ywdrofTiYTu8R7mgS1b5q3eFtwUR9MZuKJGvhsBcSfS41vH2hDezYHg8vW55UIE3
|
||||
h7EhOUnTkHY43OKZnmXHwh3pTEmHv1TfMpeaktiU/w0=
|
||||
-----END RSA PRIVATE KEY-----
|
||||
|
||||
9. end entity certificate issued by subca, Alice
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIICNzCCAaCgAwIBAgIBAjANBgkqhkiG9w0BAQQFADAxMQswCQYDVQQGEwJVUzEQ
|
||||
MA4GA1UEChMHRXhhbXBsZTEQMA4GA1UECxMHQ2xhc3MtMTAeFw0wOTA2MjgxMzMy
|
||||
MzBaFw0yOTAzMTUxMzMyMzBaMEExCzAJBgNVBAYTAlVTMRAwDgYDVQQKEwdFeGFt
|
||||
cGxlMRAwDgYDVQQLEwdDbGFzcy0xMQ4wDAYDVQQDEwVBbGljZTCBnzANBgkqhkiG
|
||||
9w0BAQEFAAOBjQAwgYkCgYEA7wnsvR4XEOfVznf40l8ClLod+7L0y2/+smVV+GM/
|
||||
T1/QF/stajAJxXNy08gK00WKZ6ruTHhR9vh/Z6+EQM2RZDCpU0A7LPa3kLE/XTmS
|
||||
1MLDu8ntkdlpURpvhdDWem+rl2HU5oZgzV8Jkcov9vXuSjqEDfr45FlPuV40T8+7
|
||||
cxsCAwEAAaNPME0wCwYDVR0PBAQDAgPoMB0GA1UdDgQWBBSBwsAhi6Z1kriOs3ty
|
||||
uSIujv9a3DAfBgNVHSMEGDAWgBRidC8Dt3dBzYESKpR2tR560sZ0+zANBgkqhkiG
|
||||
9w0BAQQFAAOBgQDEiBqd5AMy2SQopFaS3dYkzj8MHlwtbCSoNVYkOfDnewcatrbk
|
||||
yFcp6FX++PMdOQFHWvvnDdkCUAzZQp8kCkF9tGLVLBtOK7XxQ1us1LZym7kOPzsd
|
||||
G93Dcf0U1JRO77juc61Br5paAy8Bok18Y/MeG7uKgB2MAEJYKhGKbCrfMw==
|
||||
-----END CERTIFICATE-----
|
||||
|
||||
-----BEGIN RSA PRIVATE KEY-----
|
||||
Proc-Type: 4,ENCRYPTED
|
||||
DEK-Info: DES-EDE3-CBC,9E29E1901B338431
|
||||
|
||||
796Bj4/MwwHdy6+yZQcq3pS12EZPlEm7qsCCTl787y+DYEnnj+9W4WX4+1zWsUGV
|
||||
1+39oe/KOUfi5O9ytMuKiroIrklmkskWHDoW6sr4VcDprnLYL+75AhTfgpOtY+gK
|
||||
q+++N7P2o9V6YF7PiGxaBqGy/3bt0nTu0sjctfzbo4g0PniiId9sus2Y+iRHKebJ
|
||||
r9V0b0jB8USuIsZ+4IQJFZ+/zeKuqqqPM/4v5VKNUahER8oykhRd4L9UactnVH5t
|
||||
dsfowtHmOmKE6ObJX3m+HgJMvauMMf7zJVdqJquU2vy0bUk9ufCrA7t5ws7JDRzd
|
||||
SG5gt7EVQzd5x/yXsQdKbDew5mXsYPB8vz4moTgj4YJU+m6k0t1PH00pz7LUrDHl
|
||||
E8ZAmXIKLEBIih1AWkdASR/YZsfB3URIC8mLyDSZJN5iEVJxl/JWm6pbJlP3Xn3J
|
||||
fraVEXP6uerf29CNhizq520AfGdsSqga6atdx6PXBVm67V0TZ+zmBMUQJrWmJUUC
|
||||
NFGAac+M58lYX9uwsrO9x/x6GSZvhQQu1kfD1m8DHN3IV5m3uHxsEvhmuHaqFEMJ
|
||||
uH336HbqWYENXwZfDHZvOU1o2FejsLZ7QmFjB72iAxhVNQt53pCXed2gF/bERGSn
|
||||
qi0PsYtjyzfEUefqlVRSWVulbQfGwkvl8dX9s6BxmOG1q0BzlDu+cQLYXPS+XOww
|
||||
H8GgkGp6XTd04qT/qCm8gcuxAvdkYkj2zgAIKaqeJ53S3Ua9lrIKnA3L3btiEG5F
|
||||
JTYutSdRqB4liukkB1TciiDVSmOisszjrMHhRRYPfgeLfnRFdX9U9g==
|
||||
-----END RSA PRIVATE KEY-----
|
||||
|
||||
10. end entity certificate issued by subca, Bob
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIICNTCCAZ6gAwIBAgIBAzANBgkqhkiG9w0BAQQFADAxMQswCQYDVQQGEwJVUzEQ
|
||||
MA4GA1UEChMHRXhhbXBsZTEQMA4GA1UECxMHQ2xhc3MtMTAeFw0wOTA2MjgxMzMy
|
||||
MzVaFw0yOTAzMTUxMzMyMzVaMD8xCzAJBgNVBAYTAlVTMRAwDgYDVQQKEwdFeGFt
|
||||
cGxlMRAwDgYDVQQLEwdDbGFzcy0xMQwwCgYDVQQDEwNCb2IwgZ8wDQYJKoZIhvcN
|
||||
AQEBBQADgY0AMIGJAoGBALLrxd3DpXuH7yiAoyi/Rc1F7WsyyeNE1Ra2ymHpcee/
|
||||
3sbldekcgPl6lGQF/JJ5ARBbfeDtaf6ZtAK3j6aXqxVFxDKKu86r96v74gWJB7Vv
|
||||
CHcUPvmE/EGESq3VNFI998DbmvqICLC97nFLUIrKWDH1rRFZjjkmouln40UxQXvV
|
||||
AgMBAAGjTzBNMAsGA1UdDwQEAwID6DAdBgNVHQ4EFgQUTXz1J2viNSKvRHIRVhD6
|
||||
cJE4lgYwHwYDVR0jBBgwFoAUYnQvA7d3Qc2BEiqUdrUeetLGdPswDQYJKoZIhvcN
|
||||
AQEEBQADgYEApsKyLf4FbXb26KsQrxgFn/w0d/7ck4cE8a6oXQqi5OLheNSWfD3S
|
||||
fgD1dR28mGmhBiyOkdLmrhA1+6BuEr4FsuyLgrFnEqKL0ZhVhiqvwKLGqvasWxfU
|
||||
Edaw4WXvRcfRWXfgjtwB6PSj/3nqGKSGRPif/OFIjO6UqHwEM7JEWO4=
|
||||
-----END CERTIFICATE-----
|
||||
|
||||
-----BEGIN RSA PRIVATE KEY-----
|
||||
Proc-Type: 4,ENCRYPTED
|
||||
DEK-Info: DES-EDE3-CBC,4A820975D251613F
|
||||
|
||||
GseD8MIztC0oYMxwpxeBO4/YPs9ZFFjgncXXcy+1oYZdlEsrS1xw87unjeHigL8m
|
||||
QPIn8Guv3DiOsBdvweuMAgPPaA1zlophPClbGZMk7BB3T2acEfjBQH1DZz7kd7Bf
|
||||
OmI2DrqcEg1yDi7l7YutBuTQPiy3nj3d7pbScuFd5YVMu6yH0YpS7JsPvviabFk2
|
||||
eYVlkaiejtQwV+4rUb7sH/0iyqX2uqvnpnGAwVzGp+tfSOl71SByz240nOODBRgY
|
||||
3Uvxkrw6XhCBAayJE0t7rkPMEe1KgZaGO2IU2jsJJbyHVjvNPSugdbsT28prZHN1
|
||||
5M1J1NSOssq/kAq6S3f9sC5j7OzP7oUlx8uMUUSaz09/Ttq22tUoqmTue2IqqxAt
|
||||
lDaeR8duHP5VV1wWnDsW/XaVYlBFQ4eFPJcXqmWsNAkDQVJp327GrcT6ngevP8fD
|
||||
BcIxyX6J0rETPruAE+1+PAGjqy+C+oB0ssyZvKcjzdajHcNxSlRpCuOO2ekDvNPO
|
||||
h+mVukNpHCEBsh3jYmk3z9i7VPLCM0BI+vheJ1TbM+homWP6bXyTQxtLfaKzXZJH
|
||||
jRJ+zGTMBNJoPVKkou03uXFpT6hdWr9nYwbMT6G9hmC0If3wEl8nRjDKbmyMS29B
|
||||
p3im1kPxVJA0DjhghC+7tACy42ffw6KZPALwaVDKHGeitrQBc3xTGfrjOGQOTTcm
|
||||
hZ8icYCY0cjl5KQ2kq2GpXa2zQMujNV/Oj7D4sE0xcASMRXl3tst77R/j0eowx1M
|
||||
niCTRphxx4iTPkieIbjWWeFTpVmSzUBrm4hSw3tiRapVWf6Zo3aAIg==
|
||||
-----END RSA PRIVATE KEY-----
|
||||
|
||||
11. end entity certificate issued by subca, Susan
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIICNzCCAaCgAwIBAgIBBDANBgkqhkiG9w0BAQQFADAxMQswCQYDVQQGEwJVUzEQ
|
||||
MA4GA1UEChMHRXhhbXBsZTEQMA4GA1UECxMHQ2xhc3MtMTAeFw0wOTA2MjgxMzMy
|
||||
MzZaFw0yOTAzMTUxMzMyMzZaMEExCzAJBgNVBAYTAlVTMRAwDgYDVQQKEwdFeGFt
|
||||
cGxlMRAwDgYDVQQLEwdDbGFzcy0xMQ4wDAYDVQQDEwVTdXNhbjCBnzANBgkqhkiG
|
||||
9w0BAQEFAAOBjQAwgYkCgYEAr2u6mdjqAVtfcgPze+9OUFZu3pi+HqoNBoygm2gq
|
||||
qRAe+FVNSUeNAMQesQBo/eB0F1Iv/BjnYJ/7pYMLaf90MLoYr0Q5vNKYlBdcyUee
|
||||
Jn1WmfN2Qk+UoUaiM4HAKHNJnZk13vWpZW54mcW1q09oj0oMjAZtaZsqpY6CtW6/
|
||||
+J8CAwEAAaNPME0wCwYDVR0PBAQDAgPoMB0GA1UdDgQWBBQVK9naug5W9pQlBqD2
|
||||
fVaCXooa1TAfBgNVHSMEGDAWgBRidC8Dt3dBzYESKpR2tR560sZ0+zANBgkqhkiG
|
||||
9w0BAQQFAAOBgQDKYoM8EbP78ucjtsdvw4ywyo21hhSeP9PmRnNz/U3F9sQATmn+
|
||||
QBl6sBsrmbML2yrhkM1ctZTVUVp0S72fAbLgVjNk86p/CF+a2tmi0+lJh1aR7zQi
|
||||
opt+68Nec2/52kgWi64ruF7YITmGHBxS/RDooFbscZbdrPgcow/Jw+5HnQ==
|
||||
-----END CERTIFICATE-----
|
||||
|
||||
-----BEGIN RSA PRIVATE KEY-----
|
||||
Proc-Type: 4,ENCRYPTED
|
||||
DEK-Info: DES-EDE3-CBC,9025CDB2AB43B0DE
|
||||
|
||||
q4hvYnqkhDSDCsbXfxtMjPvzT38ql5wscOsGwDM/xMANSyPk9h/aqAxvB8G+8v6E
|
||||
63x9Q5jRi2YY6z2sOpvu0utu7Xn6KA/H1YrpYFURTEjBbK2Qd41vPQ/NYcIO3nQd
|
||||
PR2Qm3kpNumBSZomyNfJk9oegGxfw+P0af2GIb6YqmTDot+LLCLwpqxrGyQQ1LYp
|
||||
zc4A9D/b19Y0eD+TU9S2KEYszvfUo7RBxRFSZ6QN1rT2SEa7IJN9wb6TvgeB2lRB
|
||||
Ds90tmLtkbuwLTZre+aqbM8mU40+RI9GHh+mPw0Qz55Kw2CUe+PnGsLQnOTm7p/I
|
||||
mLiPTNMJKvwaR18Z88IE9UwL0zE/ND7vZfrhqTn9bHRnzHU4NtBCBsS8zloI+rXZ
|
||||
EIWKMDyzMH3wpbNYq/AemSvvUz1wGOxit5TjG2QwwCNt8hPLl0Es6Q5aWdAPPrLM
|
||||
EfX/6gL7bLTHNyLPz/U32o0H4hz5J7FQ7SuYUPLI3ybiPC2qL11jbtrZMesAYEAX
|
||||
mvRnqO+6dPEpwGmKz8kUj2mC8X8FPKCCiy4kbc8NjLTMao+/vOgD+wBuIePaC3yE
|
||||
vpuZrsUSFZWRJ824sDMmmZFoi2DKsp1zqCV1kXozaPGigaOxtkdp890nBcGkPijQ
|
||||
8F+jCGwSFda6UfuJHCQ/eJB+8LQUWa8u1TeJ9zo98oD2OBfQ5maZU0Vfv1EXvwbp
|
||||
pz2R6HXFaPrQDeGO0xVzD453AbY/fZCGnhIwrEYvPAbwpIKde397MP66gYFMNFhA
|
||||
IaMimFnBv7IHL08Ka0KtqbVhLpEKWFpZ6LsOnyispeB4KF0md+lpGg==
|
||||
-----END RSA PRIVATE KEY-----
|
||||
|
|
@ -0,0 +1,314 @@
|
|||
/*
|
||||
* Copyright (c) 2009, 2025, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
//
|
||||
// Security properties, once set, cannot revert to unset. To avoid
|
||||
// conflicts with tests running in the same VM isolate this test by
|
||||
// running it in otherVM mode.
|
||||
//
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @bug 6852744
|
||||
* @summary PIT b61: PKI test suite fails because self signed certificates
|
||||
* are being rejected
|
||||
* @modules java.base/sun.security.util
|
||||
* @enablePreview
|
||||
* @run main/othervm StatusLoopDependency subca
|
||||
* @run main/othervm StatusLoopDependency subci
|
||||
* @run main/othervm StatusLoopDependency alice
|
||||
*/
|
||||
|
||||
import java.security.DEREncodable;
|
||||
import java.security.PEMDecoder;
|
||||
import java.security.Security;
|
||||
import java.security.cert.CertPathBuilder;
|
||||
import java.security.cert.CertStore;
|
||||
import java.security.cert.Certificate;
|
||||
import java.security.cert.CollectionCertStoreParameters;
|
||||
import java.security.cert.PKIXBuilderParameters;
|
||||
import java.security.cert.PKIXCertPathBuilderResult;
|
||||
import java.security.cert.TrustAnchor;
|
||||
import java.security.cert.X509CRL;
|
||||
import java.security.cert.X509CertSelector;
|
||||
import java.security.cert.X509Certificate;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import sun.security.util.DerInputStream;
|
||||
|
||||
/**
|
||||
* KeyUsage extension plays a important rule during looking for the issuer
|
||||
* of a certificate or CRL. A certificate issuer should have the keyCertSign
|
||||
* bit set, and a CRL issuer should have the cRLSign bit set.
|
||||
*
|
||||
* Sometime, a delegated CRL issuer would also have the keyCertSign bit set,
|
||||
* as would be troublesome to find the proper CRL issuer during certificate
|
||||
* path build if the delegated CRL issuer is a self-issued certificate, for
|
||||
* it is hard to identify it from its issuer by the "issuer" field only.
|
||||
*
|
||||
* In the test case, the delegated CRL issuers have keyCertSign bit set, and
|
||||
* the CAs have the cRLSign bit set also. If we cannot identify the delegated
|
||||
* CRL issuer from its issuer, there is a potential loop to find the correct
|
||||
* CRL.
|
||||
*
|
||||
* And when revocation enabled, needs to check the status of the delegated
|
||||
* CRL issuers. If the delegated CRL issuer issues itself status, there is
|
||||
* a potential loop to verify the CRL and check the status of delegated CRL
|
||||
* issuer.
|
||||
*
|
||||
* The fix of 6852744 should addresses above issues.
|
||||
*/
|
||||
public final class StatusLoopDependency {
|
||||
|
||||
// the trust anchor
|
||||
static String selfSignedCertStr =
|
||||
"-----BEGIN CERTIFICATE-----\n" +
|
||||
"MIICPjCCAaegAwIBAgIBADANBgkqhkiG9w0BAQQFADAfMQswCQYDVQQGEwJVUzEQ\n" +
|
||||
"MA4GA1UEChMHRXhhbXBsZTAeFw0wOTA2MjgxMzMyMThaFw0zMDA2MDgxMzMyMTha\n" +
|
||||
"MB8xCzAJBgNVBAYTAlVTMRAwDgYDVQQKEwdFeGFtcGxlMIGfMA0GCSqGSIb3DQEB\n" +
|
||||
"AQUAA4GNADCBiQKBgQDInJhXi0655bPXAVkz1n5I6fAcZejzPnOPuwq3hU3OxFw8\n" +
|
||||
"81Uf6o9oKI1h4w4XAD8u1cUNOgiX+wPwojronlp68bIfO6FVhNf287pLtLhNJo+7\n" +
|
||||
"m6Qxw3ymFvEKy+PVj20CHSggdKHxUa4MBZBmHMFNBuxfYmjwzn+yTMmCCXOvSwID\n" +
|
||||
"AQABo4GJMIGGMB0GA1UdDgQWBBSQ52Dpau+gtL+Kc31dusYnKj16ZTBHBgNVHSME\n" +
|
||||
"QDA+gBSQ52Dpau+gtL+Kc31dusYnKj16ZaEjpCEwHzELMAkGA1UEBhMCVVMxEDAO\n" +
|
||||
"BgNVBAoTB0V4YW1wbGWCAQAwDwYDVR0TAQH/BAUwAwEB/zALBgNVHQ8EBAMCAQYw\n" +
|
||||
"DQYJKoZIhvcNAQEEBQADgYEAjBt6ea65HCqbGsS2rs/HhlGusYXtThRVC5vwXSey\n" +
|
||||
"ZFYwSgukuq1KDzckqZFu1meNImEwdZjwxdN0e2p/nVREPC42rZliSj6V1ThayKXj\n" +
|
||||
"DWEZW1U5aR8T+3NYfDrdKcJGx4Hzfz0qKz1j4ssV1M9ptJxYYv4y2Da+592IN1S9\n" +
|
||||
"v/E=\n" +
|
||||
"-----END CERTIFICATE-----";
|
||||
|
||||
// the sub-ca
|
||||
static String subCaCertStr =
|
||||
"-----BEGIN CERTIFICATE-----\n" +
|
||||
"MIICUDCCAbmgAwIBAgIBAzANBgkqhkiG9w0BAQQFADAfMQswCQYDVQQGEwJVUzEQ\n" +
|
||||
"MA4GA1UEChMHRXhhbXBsZTAeFw0wOTA2MjgxMzMyMjRaFw0yOTAzMTUxMzMyMjRa\n" +
|
||||
"MDExCzAJBgNVBAYTAlVTMRAwDgYDVQQKEwdFeGFtcGxlMRAwDgYDVQQLEwdDbGFz\n" +
|
||||
"cy0xMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDPFv24SK78VI0gWlyIrq/X\n" +
|
||||
"srl1431K5hJJxMYZtaQunyPmrYg3oI9KvKFykxnR0N4XDPaIi75p9dXGppVu80BA\n" +
|
||||
"+csvIPBwlBQoNmKDQWTziDOqfK4tE+IMuL/Y7pxnH6CDMY7VGpvatty2zcmH+m/v\n" +
|
||||
"E/n+HPyeELJQT2rT/3T+7wIDAQABo4GJMIGGMB0GA1UdDgQWBBRidC8Dt3dBzYES\n" +
|
||||
"KpR2tR560sZ0+zBHBgNVHSMEQDA+gBSQ52Dpau+gtL+Kc31dusYnKj16ZaEjpCEw\n" +
|
||||
"HzELMAkGA1UEBhMCVVMxEDAOBgNVBAoTB0V4YW1wbGWCAQAwDwYDVR0TAQH/BAUw\n" +
|
||||
"AwEB/zALBgNVHQ8EBAMCAQYwDQYJKoZIhvcNAQEEBQADgYEAMeMKqrMr5d3eTQsv\n" +
|
||||
"MYOD15Dl3THQGLAa4ad5Eyq5/1eUeEOpztzCgDfi0iPD8YCubIEVasBTSqTiGXqb\n" +
|
||||
"RpGuPHOwwfWvHrTeHSludiFBAUiKj7aEV+oQa0FBn4U4TT8HA62HQ93FhzTDI3jP\n" +
|
||||
"iil34GktVl6gfMKGzUEW/Dh8OM4=\n" +
|
||||
"-----END CERTIFICATE-----";
|
||||
|
||||
// a delegated CRL issuer, it's a self-issued certificate of trust anchor
|
||||
static String topCrlIssuerCertStr =
|
||||
"-----BEGIN CERTIFICATE-----\n" +
|
||||
"MIICPjCCAaegAwIBAgIBAjANBgkqhkiG9w0BAQQFADAfMQswCQYDVQQGEwJVUzEQ\n" +
|
||||
"MA4GA1UEChMHRXhhbXBsZTAeFw0wOTA2MjgxMzMyMjNaFw0yOTAzMTUxMzMyMjNa\n" +
|
||||
"MB8xCzAJBgNVBAYTAlVTMRAwDgYDVQQKEwdFeGFtcGxlMIGfMA0GCSqGSIb3DQEB\n" +
|
||||
"AQUAA4GNADCBiQKBgQC99u93trf+WmpfiqunJy/P31ej1l4rESxft2JSGNjKuLFN\n" +
|
||||
"/BO3SAugGJSkCARAwXjB0c8eeXhXWhVVWdNpbKepRJTxrjDfnFIavLgtUvmFwn/3\n" +
|
||||
"hPXe+RQeA8+AJ99Y+o+10kY8JAZLa2j93C2FdmwOjUbo8aIz85yhbiV1tEDjLwID\n" +
|
||||
"AQABo4GJMIGGMB0GA1UdDgQWBBSyFyA3XWLbdL6W6hksmBn7RKsQmDBHBgNVHSME\n" +
|
||||
"QDA+gBSQ52Dpau+gtL+Kc31dusYnKj16ZaEjpCEwHzELMAkGA1UEBhMCVVMxEDAO\n" +
|
||||
"BgNVBAoTB0V4YW1wbGWCAQAwDwYDVR0TAQH/BAUwAwEB/zALBgNVHQ8EBAMCAQYw\n" +
|
||||
"DQYJKoZIhvcNAQEEBQADgYEAHTm8aRTeakgCfEBCgSWK9wvMW1c18ANGMm8OFDBk\n" +
|
||||
"xabVy9BT0MVFHlaneh89oIxTZN0FMTpg21GZMAvIzhEt7DGdO7HLsW7JniN7/OZ0\n" +
|
||||
"rACmpK5frmZrLS03zUm8c+rTbazNfYLoZVG3/mDZbKIi+4y8IGnFcgLVsHsYoBNP\n" +
|
||||
"G0c=\n" +
|
||||
"-----END CERTIFICATE-----";
|
||||
|
||||
// a delegated CRL issuer, it's a self-issued certificate of sub-ca
|
||||
static String subCrlIssuerCertStr =
|
||||
"-----BEGIN CERTIFICATE-----\n" +
|
||||
"MIICUDCCAbmgAwIBAgIBBDANBgkqhkiG9w0BAQQFADAfMQswCQYDVQQGEwJVUzEQ\n" +
|
||||
"MA4GA1UEChMHRXhhbXBsZTAeFw0wOTA2MjgxMzMyMjdaFw0yOTAzMTUxMzMyMjda\n" +
|
||||
"MDExCzAJBgNVBAYTAlVTMRAwDgYDVQQKEwdFeGFtcGxlMRAwDgYDVQQLEwdDbGFz\n" +
|
||||
"cy0xMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC+8AcLJtGAVUWvv3ifcyQw\n" +
|
||||
"OGqwzcPrBw/XCs6vTMlcdtFzcH1M+Z3/QHN9+5VT1gqeTIZ+b8g9005Og3XKy/HX\n" +
|
||||
"obXZeLv20VZsr+jm52ySghEYOVCTJ9OyFOAp5adp6nf0cA66Feh3LsmVhpTEcDOG\n" +
|
||||
"GnyntQm0DBYxRoOT/GBlvQIDAQABo4GJMIGGMB0GA1UdDgQWBBSRWhMuZLQoHSDN\n" +
|
||||
"xhxr+vdDmfAY8jBHBgNVHSMEQDA+gBSQ52Dpau+gtL+Kc31dusYnKj16ZaEjpCEw\n" +
|
||||
"HzELMAkGA1UEBhMCVVMxEDAOBgNVBAoTB0V4YW1wbGWCAQAwDwYDVR0TAQH/BAUw\n" +
|
||||
"AwEB/zALBgNVHQ8EBAMCAQYwDQYJKoZIhvcNAQEEBQADgYEAMIDZLdOLFiPyS1bh\n" +
|
||||
"Ch4eUYHT+K1WG93skbga3kVYg3GSe+gctwkKwKK13bwfi8zc7wwz6MtmQwEYhppc\n" +
|
||||
"pKKKEwi5QirBCP54rihLCvRQaj6ZqUJ6VP+zPAqHYMDbzlBbHtVF/1lQUP30I6SV\n" +
|
||||
"Fu987DvLmZ2GuQA9FKJsnlD9pbU=\n" +
|
||||
"-----END CERTIFICATE-----";
|
||||
|
||||
// the target EE certificate
|
||||
static String targetCertStr =
|
||||
"-----BEGIN CERTIFICATE-----\n" +
|
||||
"MIICNzCCAaCgAwIBAgIBAjANBgkqhkiG9w0BAQQFADAxMQswCQYDVQQGEwJVUzEQ\n" +
|
||||
"MA4GA1UEChMHRXhhbXBsZTEQMA4GA1UECxMHQ2xhc3MtMTAeFw0wOTA2MjgxMzMy\n" +
|
||||
"MzBaFw0yOTAzMTUxMzMyMzBaMEExCzAJBgNVBAYTAlVTMRAwDgYDVQQKEwdFeGFt\n" +
|
||||
"cGxlMRAwDgYDVQQLEwdDbGFzcy0xMQ4wDAYDVQQDEwVBbGljZTCBnzANBgkqhkiG\n" +
|
||||
"9w0BAQEFAAOBjQAwgYkCgYEA7wnsvR4XEOfVznf40l8ClLod+7L0y2/+smVV+GM/\n" +
|
||||
"T1/QF/stajAJxXNy08gK00WKZ6ruTHhR9vh/Z6+EQM2RZDCpU0A7LPa3kLE/XTmS\n" +
|
||||
"1MLDu8ntkdlpURpvhdDWem+rl2HU5oZgzV8Jkcov9vXuSjqEDfr45FlPuV40T8+7\n" +
|
||||
"cxsCAwEAAaNPME0wCwYDVR0PBAQDAgPoMB0GA1UdDgQWBBSBwsAhi6Z1kriOs3ty\n" +
|
||||
"uSIujv9a3DAfBgNVHSMEGDAWgBRidC8Dt3dBzYESKpR2tR560sZ0+zANBgkqhkiG\n" +
|
||||
"9w0BAQQFAAOBgQDEiBqd5AMy2SQopFaS3dYkzj8MHlwtbCSoNVYkOfDnewcatrbk\n" +
|
||||
"yFcp6FX++PMdOQFHWvvnDdkCUAzZQp8kCkF9tGLVLBtOK7XxQ1us1LZym7kOPzsd\n" +
|
||||
"G93Dcf0U1JRO77juc61Br5paAy8Bok18Y/MeG7uKgB2MAEJYKhGKbCrfMw==\n" +
|
||||
"-----END CERTIFICATE-----";
|
||||
|
||||
// CRL issued by the delegated CRL issuer, topCrlIssuerCertStr
|
||||
static String topCrlStr =
|
||||
"-----BEGIN X509 CRL-----\n" +
|
||||
"MIIBGzCBhQIBATANBgkqhkiG9w0BAQQFADAfMQswCQYDVQQGEwJVUzEQMA4GA1UE\n" +
|
||||
"ChMHRXhhbXBsZRcNMDkwNjI4MTMzMjM4WhcNMjgwODI3MTMzMjM4WjAiMCACAQUX\n" +
|
||||
"DTA5MDYyODEzMzIzN1owDDAKBgNVHRUEAwoBBKAOMAwwCgYDVR0UBAMCAQEwDQYJ\n" +
|
||||
"KoZIhvcNAQEEBQADgYEAVUIeu2x7ZwsliafoCBOg+u8Q4S/VFfTe/SQnRyTM3/V1\n" +
|
||||
"v+Vn5Acc7eo8Rh4AHcnFFbLNk38n6lllov/CaVR0IPZ6hnrNHVa7VYkNlRAwV2aN\n" +
|
||||
"GUUhkMMOLVLnN25UOrN9J637SHmRE6pB+TRMaEQ73V7UNlWxuSMK4KofWen0A34=\n" +
|
||||
"-----END X509 CRL-----";
|
||||
|
||||
// CRL issued by the delegated CRL issuer, subCrlIssuerCertStr
|
||||
static String subCrlStr =
|
||||
"-----BEGIN X509 CRL-----\n" +
|
||||
"MIIBLTCBlwIBATANBgkqhkiG9w0BAQQFADAxMQswCQYDVQQGEwJVUzEQMA4GA1UE\n" +
|
||||
"ChMHRXhhbXBsZTEQMA4GA1UECxMHQ2xhc3MtMRcNMDkwNjI4MTMzMjQzWhcNMjgw\n" +
|
||||
"ODI3MTMzMjQzWjAiMCACAQQXDTA5MDYyODEzMzIzOFowDDAKBgNVHRUEAwoBBKAO\n" +
|
||||
"MAwwCgYDVR0UBAMCAQEwDQYJKoZIhvcNAQEEBQADgYEACQZEf6ydb3fKTMPJ8DBO\n" +
|
||||
"oo630MsrT3P0x0AC4+aQOueCBaGpNqW/H379uZxXAad7yr+aXUBwaeBMYVKUbwOe\n" +
|
||||
"5TrN5QWPe2eCkU+MSQvh1SHASDDMH4jhWFMRdO3aPMDKKPlO/Q3s0G72eD7Zo5dr\n" +
|
||||
"N9AvUXxGxU4DruoJuFPcrCI=\n" +
|
||||
"-----END X509 CRL-----";
|
||||
|
||||
private static final PEMDecoder pemDecoder = PEMDecoder.of();
|
||||
|
||||
private static Set<TrustAnchor> generateTrustAnchors() {
|
||||
X509Certificate selfSignedCert = pemDecoder.decode(selfSignedCertStr, X509Certificate.class);
|
||||
|
||||
// generate a trust anchor
|
||||
TrustAnchor anchor =
|
||||
new TrustAnchor(selfSignedCert, null);
|
||||
|
||||
return Collections.singleton(anchor);
|
||||
}
|
||||
|
||||
private static CertStore generateCertificateStore() throws Exception {
|
||||
|
||||
Collection<DEREncodable> entries = new HashSet<>();
|
||||
|
||||
DEREncodable cert = pemDecoder.decode(targetCertStr, X509Certificate.class);
|
||||
entries.add(cert);
|
||||
|
||||
cert = pemDecoder.decode(subCaCertStr, X509Certificate.class);
|
||||
entries.add(cert);
|
||||
|
||||
cert = pemDecoder.decode(selfSignedCertStr, X509Certificate.class);
|
||||
entries.add(cert);
|
||||
|
||||
cert = pemDecoder.decode(topCrlIssuerCertStr, X509Certificate.class);
|
||||
entries.add(cert);
|
||||
|
||||
cert = pemDecoder.decode(subCrlIssuerCertStr, X509Certificate.class);
|
||||
entries.add(cert);
|
||||
|
||||
// generate CRL from CRL string
|
||||
DEREncodable mixes = pemDecoder.decode(topCrlStr, X509CRL.class);
|
||||
entries.add(mixes);
|
||||
|
||||
mixes = pemDecoder.decode(subCrlStr, X509CRL.class);
|
||||
entries.add(mixes);
|
||||
|
||||
return CertStore.getInstance("Collection",
|
||||
new CollectionCertStoreParameters(entries));
|
||||
}
|
||||
|
||||
private static X509CertSelector generateSelector(String name)
|
||||
throws Exception {
|
||||
X509CertSelector selector = new X509CertSelector();
|
||||
|
||||
// generate certificate from certificate string
|
||||
String cert;
|
||||
if (name.equals("subca")) {
|
||||
cert = subCaCertStr;
|
||||
} else if (name.equals("subci")) {
|
||||
cert = subCrlIssuerCertStr;
|
||||
} else {
|
||||
cert = targetCertStr;
|
||||
}
|
||||
|
||||
X509Certificate target = pemDecoder.decode(cert, X509Certificate.class);
|
||||
byte[] extVal = target.getExtensionValue("2.5.29.14");
|
||||
if (extVal != null) {
|
||||
DerInputStream in = new DerInputStream(extVal);
|
||||
byte[] subjectKID = in.getOctetString();
|
||||
selector.setSubjectKeyIdentifier(subjectKID);
|
||||
} else {
|
||||
// unlikely to happen.
|
||||
throw new Exception("unexpected certificate: no SKID extension");
|
||||
}
|
||||
|
||||
return selector;
|
||||
}
|
||||
|
||||
private static boolean match(String name, Certificate cert) {
|
||||
|
||||
// generate certificate from certificate string
|
||||
String newCert;
|
||||
if (name.equals("subca")) {
|
||||
newCert = subCaCertStr;
|
||||
} else if (name.equals("subci")) {
|
||||
newCert = subCrlIssuerCertStr;
|
||||
} else {
|
||||
newCert = targetCertStr;
|
||||
}
|
||||
X509Certificate target = pemDecoder.decode(newCert, X509Certificate.class);
|
||||
|
||||
return target.equals(cert);
|
||||
}
|
||||
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
// MD5 is used in this test case, don't disable MD5 algorithm.
|
||||
Security.setProperty(
|
||||
"jdk.certpath.disabledAlgorithms", "MD2, RSA keySize < 1024");
|
||||
|
||||
CertPathBuilder builder = CertPathBuilder.getInstance("PKIX");
|
||||
|
||||
X509CertSelector selector = generateSelector(args[0]);
|
||||
|
||||
Set<TrustAnchor> anchors = generateTrustAnchors();
|
||||
CertStore certs = generateCertificateStore();
|
||||
|
||||
|
||||
PKIXBuilderParameters params =
|
||||
new PKIXBuilderParameters(anchors, selector);
|
||||
params.addCertStore(certs);
|
||||
params.setRevocationEnabled(true);
|
||||
params.setDate(new Date(109, 7, 1)); // 2009-07-01
|
||||
Security.setProperty("ocsp.enable", "false");
|
||||
System.setProperty("com.sun.security.enableCRLDP", "true");
|
||||
|
||||
PKIXCertPathBuilderResult result =
|
||||
(PKIXCertPathBuilderResult)builder.build(params);
|
||||
|
||||
if (!match(args[0], result.getCertPath().getCertificates().get(0))) {
|
||||
throw new Exception("unexpected certificate");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,219 @@
|
|||
#
|
||||
# Copyright (c) 2009, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
#
|
||||
# This code is free software; you can redistribute it and/or modify it
|
||||
# under the terms of the GNU General Public License version 2 only, as
|
||||
# published by the Free Software Foundation.
|
||||
#
|
||||
# This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
# version 2 for more details (a copy is included in the LICENSE file that
|
||||
# accompanied this code).
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License version
|
||||
# 2 along with this work; if not, write to the Free Software Foundation,
|
||||
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
#
|
||||
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
# or visit www.oracle.com if you need additional information or have any
|
||||
# questions.
|
||||
#
|
||||
|
||||
#!/bin/ksh
|
||||
#
|
||||
# needs ksh to run the script.
|
||||
|
||||
# generate a self-signed root certificate
|
||||
if [ ! -f root/root_cert.pem ]; then
|
||||
if [ ! -d root ]; then
|
||||
mkdir root
|
||||
fi
|
||||
|
||||
openssl req -x509 -newkey rsa:1024 -keyout root/root_key.pem \
|
||||
-out root/root_cert.pem -subj "/C=US/O=Example" \
|
||||
-config openssl.cnf -reqexts cert_issuer -days 7650 \
|
||||
-passin pass:passphrase -passout pass:passphrase
|
||||
fi
|
||||
|
||||
# generate a sele-issued root crl issuer certificate
|
||||
if [ ! -f root/top_crlissuer_cert.pem ]; then
|
||||
if [ ! -d root ]; then
|
||||
mkdir root
|
||||
fi
|
||||
|
||||
openssl req -newkey rsa:1024 -keyout root/top_crlissuer_key.pem \
|
||||
-out root/top_crlissuer_req.pem -subj "/C=US/O=Example" -days 7650 \
|
||||
-passin pass:passphrase -passout pass:passphrase
|
||||
|
||||
openssl x509 -req -in root/top_crlissuer_req.pem -extfile openssl.cnf \
|
||||
-extensions crl_issuer -CA root/root_cert.pem \
|
||||
-CAkey root/root_key.pem -out root/top_crlissuer_cert.pem \
|
||||
-CAcreateserial -CAserial root/root_cert.srl -days 7200 \
|
||||
-passin pass:passphrase
|
||||
fi
|
||||
|
||||
# generate subca cert issuer and crl iuuser certificates
|
||||
if [ ! -f subca/subca_cert.pem ]; then
|
||||
if [ ! -d subca ]; then
|
||||
mkdir subca
|
||||
fi
|
||||
|
||||
openssl req -newkey rsa:1024 -keyout subca/subca_key.pem \
|
||||
-out subca/subca_req.pem -subj "/C=US/O=Example/OU=Class-1" \
|
||||
-days 7650 -passin pass:passphrase -passout pass:passphrase
|
||||
|
||||
openssl x509 -req -in subca/subca_req.pem -extfile openssl.cnf \
|
||||
-extensions cert_issuer -CA root/root_cert.pem \
|
||||
-CAkey root/root_key.pem -out subca/subca_cert.pem -CAcreateserial \
|
||||
-CAserial root/root_cert.srl -days 7200 -passin pass:passphrase
|
||||
|
||||
openssl req -newkey rsa:1024 -keyout subca/subca_crlissuer_key.pem \
|
||||
-out subca/subca_crlissuer_req.pem -subj "/C=US/O=Example/OU=Class-1" \
|
||||
-days 7650 -passin pass:passphrase -passout pass:passphrase
|
||||
|
||||
openssl x509 -req -in subca/subca_crlissuer_req.pem -extfile openssl.cnf \
|
||||
-extensions crl_issuer -CA root/root_cert.pem \
|
||||
-CAkey root/root_key.pem -out subca/subca_crlissuer_cert.pem \
|
||||
-CAcreateserial -CAserial root/root_cert.srl -days 7200 \
|
||||
-passin pass:passphrase
|
||||
fi
|
||||
|
||||
# generate dumca cert issuer and crl iuuser certificates
|
||||
if [ ! -f dumca/dumca_cert.pem ]; then
|
||||
if [ ! -d sumca ]; then
|
||||
mkdir dumca
|
||||
fi
|
||||
|
||||
openssl req -newkey rsa:1024 -keyout dumca/dumca_key.pem \
|
||||
-out dumca/dumca_req.pem -subj "/C=US/O=Example/OU=Class-D" \
|
||||
-days 7650 -passin pass:passphrase -passout pass:passphrase
|
||||
|
||||
openssl x509 -req -in dumca/dumca_req.pem -extfile openssl.cnf \
|
||||
-extensions cert_issuer -CA root/root_cert.pem \
|
||||
-CAkey root/root_key.pem -out dumca/dumca_cert.pem \
|
||||
-CAcreateserial -CAserial root/root_cert.srl -days 7200 \
|
||||
-passin pass:passphrase
|
||||
|
||||
openssl req -newkey rsa:1024 -keyout dumca/dumca_crlissuer_key.pem \
|
||||
-out dumca/dumca_crlissuer_req.pem -subj "/C=US/O=Example/OU=Class-D" \
|
||||
-days 7650 -passin pass:passphrase -passout pass:passphrase
|
||||
|
||||
openssl x509 -req -in dumca/dumca_crlissuer_req.pem \
|
||||
-extfile openssl.cnf -extensions crl_issuer -CA root/root_cert.pem \
|
||||
-CAkey root/root_key.pem -out dumca/dumca_crlissuer_cert.pem \
|
||||
-CAcreateserial -CAserial root/root_cert.srl -days 7200 \
|
||||
-passin pass:passphrase
|
||||
fi
|
||||
|
||||
# generate certifiacte for Alice
|
||||
if [ ! -f subca/alice/alice_cert.pem ]; then
|
||||
if [ ! -d subca/alice ]; then
|
||||
mkdir -p subca/alice
|
||||
fi
|
||||
|
||||
openssl req -newkey rsa:1024 -keyout subca/alice/alice_key.pem \
|
||||
-out subca/alice/alice_req.pem \
|
||||
-subj "/C=US/O=Example/OU=Class-1/CN=Alice" -days 7650 \
|
||||
-passin pass:passphrase -passout pass:passphrase
|
||||
|
||||
openssl x509 -req -in subca/alice/alice_req.pem \
|
||||
-extfile openssl.cnf -extensions ee_of_subca \
|
||||
-CA subca/subca_cert.pem -CAkey subca/subca_key.pem \
|
||||
-out subca/alice/alice_cert.pem -CAcreateserial \
|
||||
-CAserial subca/subca_cert.srl -days 7200 -passin pass:passphrase
|
||||
fi
|
||||
|
||||
# generate certifiacte for Bob
|
||||
if [ ! -f subca/bob/bob_cert.pem ]; then
|
||||
if [ ! -d subca/bob ]; then
|
||||
mkdir -p subca/bob
|
||||
fi
|
||||
|
||||
openssl req -newkey rsa:1024 -keyout subca/bob/bob_key.pem \
|
||||
-out subca/bob/bob_req.pem \
|
||||
-subj "/C=US/O=Example/OU=Class-1/CN=Bob" -days 7650 \
|
||||
-passin pass:passphrase -passout pass:passphrase
|
||||
|
||||
openssl x509 -req -in subca/bob/bob_req.pem \
|
||||
-extfile openssl.cnf -extensions ee_of_subca \
|
||||
-CA subca/subca_cert.pem -CAkey subca/subca_key.pem \
|
||||
-out subca/bob/bob_cert.pem -CAcreateserial \
|
||||
-CAserial subca/subca_cert.srl -days 7200 -passin pass:passphrase
|
||||
fi
|
||||
|
||||
# generate certifiacte for Susan
|
||||
if [ ! -f subca/susan/susan_cert.pem ]; then
|
||||
if [ ! -d subca/susan ]; then
|
||||
mkdir -p subca/susan
|
||||
fi
|
||||
|
||||
openssl req -newkey rsa:1024 -keyout subca/susan/susan_key.pem \
|
||||
-out subca/susan/susan_req.pem \
|
||||
-subj "/C=US/O=Example/OU=Class-1/CN=Susan" -days 7650 \
|
||||
-passin pass:passphrase -passout pass:passphrase
|
||||
|
||||
openssl x509 -req -in subca/susan/susan_req.pem -extfile openssl.cnf \
|
||||
-extensions ee_of_subca -CA subca/subca_cert.pem \
|
||||
-CAkey subca/subca_key.pem -out subca/susan/susan_cert.pem \
|
||||
-CAcreateserial -CAserial subca/subca_cert.srl -days 7200 \
|
||||
-passin pass:passphrase
|
||||
fi
|
||||
|
||||
|
||||
# generate the top CRL
|
||||
if [ ! -f root/top_crl.pem ]; then
|
||||
if [ ! -d root ]; then
|
||||
mkdir root
|
||||
fi
|
||||
|
||||
if [ ! -f root/index.txt ]; then
|
||||
touch root/index.txt
|
||||
echo 00 > root/crlnumber
|
||||
fi
|
||||
|
||||
openssl ca -gencrl -config openssl.cnf -name ca_top -crldays 7000 \
|
||||
-crl_reason superseded -keyfile root/top_crlissuer_key.pem \
|
||||
-cert root/top_crlissuer_cert.pem -out root/top_crl.pem \
|
||||
-passin pass:passphrase
|
||||
fi
|
||||
|
||||
# revoke dumca
|
||||
openssl ca -revoke dumca/dumca_cert.pem -config openssl.cnf \
|
||||
-name ca_top -crl_reason superseded \
|
||||
-keyfile root/top_crlissuer_key.pem -cert root/top_crlissuer_cert.pem \
|
||||
-passin pass:passphrase
|
||||
|
||||
openssl ca -gencrl -config openssl.cnf -name ca_top -crldays 7000 \
|
||||
-crl_reason superseded -keyfile root/top_crlissuer_key.pem \
|
||||
-cert root/top_crlissuer_cert.pem -out root/top_crl.pem \
|
||||
-passin pass:passphrase
|
||||
|
||||
# revoke for subca
|
||||
if [ ! -f subca/subca_crl.pem ]; then
|
||||
if [ ! -d subca ]; then
|
||||
mkdir subca
|
||||
fi
|
||||
|
||||
if [ ! -f subca/index.txt ]; then
|
||||
touch subca/index.txt
|
||||
echo 00 > subca/crlnumber
|
||||
fi
|
||||
|
||||
openssl ca -gencrl -config openssl.cnf -name ca_subca -crldays 7000 \
|
||||
-crl_reason superseded -keyfile subca/subca_crlissuer_key.pem \
|
||||
-cert subca/subca_crlissuer_cert.pem -out subca/subca_crl.pem \
|
||||
-passin pass:passphrase
|
||||
fi
|
||||
|
||||
# revoke susan
|
||||
openssl ca -revoke subca/susan/susan_cert.pem -config openssl.cnf \
|
||||
-name ca_subca -crl_reason superseded \
|
||||
-keyfile subca/subca_crlissuer_key.pem \
|
||||
-cert subca/subca_crlissuer_cert.pem -passin pass:passphrase
|
||||
|
||||
openssl ca -gencrl -config openssl.cnf -name ca_subca -crldays 7000 \
|
||||
-crl_reason superseded -keyfile subca/subca_crlissuer_key.pem \
|
||||
-cert subca/subca_crlissuer_cert.pem -out subca/subca_crl.pem \
|
||||
-passin pass:passphrase
|
||||
|
|
@ -0,0 +1,203 @@
|
|||
#
|
||||
# Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
|
||||
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
#
|
||||
# This code is free software; you can redistribute it and/or modify it
|
||||
# under the terms of the GNU General Public License version 2 only, as
|
||||
# published by the Free Software Foundation.
|
||||
#
|
||||
# This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
# version 2 for more details (a copy is included in the LICENSE file that
|
||||
# accompanied this code).
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License version
|
||||
# 2 along with this work; if not, write to the Free Software Foundation,
|
||||
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
#
|
||||
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
# or visit www.oracle.com if you need additional information or have any
|
||||
# questions.
|
||||
#
|
||||
|
||||
#
|
||||
# OpenSSL configuration file.
|
||||
#
|
||||
|
||||
HOME = .
|
||||
RANDFILE = $ENV::HOME/.rnd
|
||||
|
||||
[ ca ]
|
||||
default_ca = CA_default
|
||||
|
||||
[ CA_default ]
|
||||
dir = ./top
|
||||
certs = $dir/certs
|
||||
crl_dir = $dir/crl
|
||||
database = $dir/index.txt
|
||||
unique_subject = no
|
||||
new_certs_dir = $dir/newcerts
|
||||
certificate = $dir/cacert.pem
|
||||
serial = $dir/serial
|
||||
crlnumber = $dir/crlnumber
|
||||
crl = $dir/crl.pem
|
||||
private_key = $dir/private/cakey.pem
|
||||
RANDFILE = $dir/private/.rand
|
||||
x509_extensions = v3_ca
|
||||
|
||||
name_opt = ca_default
|
||||
cert_opt = ca_default
|
||||
|
||||
default_days = 7650
|
||||
default_crl_days = 30
|
||||
default_md = sha1
|
||||
preserve = no
|
||||
|
||||
policy = policy_anything
|
||||
|
||||
[ ca_top ]
|
||||
dir = ./root
|
||||
certs = $dir/certs
|
||||
crl_dir = $dir/crl
|
||||
database = $dir/index.txt
|
||||
unique_subject = no
|
||||
new_certs_dir = $dir/newcerts
|
||||
certificate = $dir/cacert.pem
|
||||
serial = $dir/serial
|
||||
crlnumber = $dir/crlnumber
|
||||
crl = $dir/crl.pem
|
||||
private_key = $dir/private/cakey.pem
|
||||
RANDFILE = $dir/private/.rand
|
||||
|
||||
x509_extensions = v3_ca
|
||||
|
||||
name_opt = ca_default
|
||||
cert_opt = ca_default
|
||||
|
||||
default_days = 7650
|
||||
default_crl_days = 30
|
||||
default_md = sha1
|
||||
preserve = no
|
||||
|
||||
policy = policy_anything
|
||||
|
||||
[ ca_subca ]
|
||||
dir = ./subca
|
||||
certs = $dir/certs
|
||||
crl_dir = $dir/crl
|
||||
database = $dir/index.txt
|
||||
unique_subject = no
|
||||
new_certs_dir = $dir/newcerts
|
||||
|
||||
certificate = $dir/cacert.pem
|
||||
serial = $dir/serial
|
||||
crlnumber = $dir/crlnumber
|
||||
crl = $dir/crl.pem
|
||||
private_key = $dir/private/cakey.pem
|
||||
RANDFILE = $dir/private/.rand
|
||||
|
||||
x509_extensions = usr_cert
|
||||
|
||||
name_opt = ca_default
|
||||
cert_opt = ca_default
|
||||
|
||||
default_days = 7650
|
||||
default_crl_days = 30
|
||||
default_md = sha1
|
||||
preserve = no
|
||||
|
||||
policy = policy_anything
|
||||
|
||||
[ policy_match ]
|
||||
countryName = match
|
||||
stateOrProvinceName = match
|
||||
organizationName = match
|
||||
organizationalUnitName = optional
|
||||
commonName = supplied
|
||||
emailAddress = optional
|
||||
|
||||
[ policy_anything ]
|
||||
countryName = optional
|
||||
stateOrProvinceName = optional
|
||||
localityName = optional
|
||||
organizationName = optional
|
||||
organizationalUnitName = optional
|
||||
commonName = supplied
|
||||
emailAddress = optional
|
||||
|
||||
[ req ]
|
||||
default_bits = 1024
|
||||
default_keyfile = privkey.pem
|
||||
distinguished_name = req_distinguished_name
|
||||
attributes = req_attributes
|
||||
x509_extensions = v3_ca
|
||||
|
||||
string_mask = nombstr
|
||||
|
||||
[ req_distinguished_name ]
|
||||
countryName = Country Name (2 letter code)
|
||||
countryName_default = NO
|
||||
countryName_min = 2
|
||||
countryName_max = 2
|
||||
|
||||
stateOrProvinceName = State or Province Name (full name)
|
||||
stateOrProvinceName_default = A-State
|
||||
|
||||
localityName = Locality Name (eg, city)
|
||||
|
||||
0.organizationName = Organization Name (eg, company)
|
||||
0.organizationName_default = Internet Widgits Pty Ltd
|
||||
|
||||
organizationalUnitName = Organizational Unit Name (eg, section)
|
||||
|
||||
commonName = Common Name (eg, YOUR name)
|
||||
commonName_max = 64
|
||||
|
||||
emailAddress = Email Address
|
||||
emailAddress_max = 64
|
||||
|
||||
[ req_attributes ]
|
||||
challengePassword = A challenge password
|
||||
challengePassword_min = 4
|
||||
challengePassword_max = 20
|
||||
unstructuredName = An optional company name
|
||||
|
||||
[ usr_cert ]
|
||||
keyUsage = nonRepudiation, digitalSignature, keyEncipherment
|
||||
|
||||
subjectKeyIdentifier = hash
|
||||
authorityKeyIdentifier = keyid,issuer
|
||||
|
||||
[ v3_req ]
|
||||
basicConstraints = CA:FALSE
|
||||
keyUsage = nonRepudiation, digitalSignature, keyEncipherment
|
||||
subjectAltName = email:example@openjdk.net, RID:1.2.3.4:true
|
||||
|
||||
[ v3_ca ]
|
||||
subjectKeyIdentifier = hash
|
||||
authorityKeyIdentifier = keyid:always,issuer:always
|
||||
basicConstraints = critical,CA:true
|
||||
keyUsage = keyCertSign, cRLSign
|
||||
|
||||
[ cert_issuer ]
|
||||
subjectKeyIdentifier = hash
|
||||
authorityKeyIdentifier = keyid:always,issuer:always
|
||||
basicConstraints = critical,CA:true
|
||||
keyUsage = keyCertSign, cRLSign
|
||||
|
||||
[ crl_issuer ]
|
||||
subjectKeyIdentifier = hash
|
||||
authorityKeyIdentifier = keyid:always,issuer:always
|
||||
basicConstraints = critical,CA:true
|
||||
keyUsage = keyCertSign, cRLSign
|
||||
|
||||
|
||||
[ crl_ext ]
|
||||
authorityKeyIdentifier = keyid:always,issuer:always
|
||||
|
||||
[ ee_of_subca ]
|
||||
keyUsage = nonRepudiation, digitalSignature, keyEncipherment, keyAgreement
|
||||
|
||||
subjectKeyIdentifier = hash
|
||||
authorityKeyIdentifier = keyid,issuer
|
||||
|
|
@ -0,0 +1,94 @@
|
|||
/*
|
||||
* Copyright (c) 2008, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
// This test case relies on updated static security property, no way to re-use
|
||||
// security property in samevm/agentvm mode.
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @bug 6714842
|
||||
* @library /test/lib
|
||||
* @run main/othervm BuildEEBasicConstraints
|
||||
* @summary make sure a PKIX CertPathBuilder builds a path to an
|
||||
* end entity certificate when the setBasicConstraints method of the
|
||||
* X509CertSelector of the targetConstraints PKIXBuilderParameters
|
||||
* parameter is set to -2.
|
||||
*/
|
||||
|
||||
import java.security.Security;
|
||||
import java.security.cert.Certificate;
|
||||
import java.security.cert.CertPath;
|
||||
import java.security.cert.CertStore;
|
||||
import java.security.cert.CollectionCertStoreParameters;
|
||||
import java.security.cert.PKIXBuilderParameters;
|
||||
import java.security.cert.PKIXCertPathBuilderResult;
|
||||
import java.security.cert.TrustAnchor;
|
||||
import java.security.cert.X509Certificate;
|
||||
import java.security.cert.X509CertSelector;
|
||||
import java.text.DateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import jdk.test.lib.security.CertUtils;
|
||||
|
||||
public final class BuildEEBasicConstraints {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
// reset the security property to make sure that the algorithms
|
||||
// and keys used in this test are not disabled.
|
||||
Security.setProperty("jdk.certpath.disabledAlgorithms", "MD2");
|
||||
|
||||
X509Certificate rootCert = CertUtils.getCertFromFile("anchor.cer");
|
||||
TrustAnchor anchor = new TrustAnchor
|
||||
(rootCert.getSubjectX500Principal(), rootCert.getPublicKey(), null);
|
||||
X509CertSelector sel = new X509CertSelector();
|
||||
sel.setBasicConstraints(-2);
|
||||
PKIXBuilderParameters params = new PKIXBuilderParameters
|
||||
(Collections.singleton(anchor), sel);
|
||||
params.setRevocationEnabled(false);
|
||||
|
||||
// Certs expired on 7th Nov 2022
|
||||
params.setDate(DateFormat.getDateInstance(DateFormat.MEDIUM,
|
||||
Locale.US).parse("June 01, 2022"));
|
||||
|
||||
X509Certificate eeCert = CertUtils.getCertFromFile("ee.cer");
|
||||
X509Certificate caCert = CertUtils.getCertFromFile("ca.cer");
|
||||
ArrayList<X509Certificate> certs = new ArrayList<X509Certificate>();
|
||||
certs.add(caCert);
|
||||
certs.add(eeCert);
|
||||
CollectionCertStoreParameters ccsp =
|
||||
new CollectionCertStoreParameters(certs);
|
||||
CertStore cs = CertStore.getInstance("Collection", ccsp);
|
||||
params.addCertStore(cs);
|
||||
PKIXCertPathBuilderResult res = CertUtils.build(params);
|
||||
CertPath cp = res.getCertPath();
|
||||
// check that first certificate is an EE cert
|
||||
List<? extends Certificate> certList = cp.getCertificates();
|
||||
X509Certificate cert = (X509Certificate) certList.get(0);
|
||||
if (cert.getBasicConstraints() != -1) {
|
||||
throw new Exception("Target certificate is not an EE certificate");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,139 @@
|
|||
/*
|
||||
* Copyright (c) 2001, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @bug 4459538
|
||||
* @summary make sure a PKIX CertPathBuilder throws an
|
||||
* InvalidAlgorithmParameterException if the target constraints
|
||||
* specified in the PKIXBuilderParameters is not an instance of
|
||||
* X509CertSelector.
|
||||
*/
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import java.security.InvalidAlgorithmParameterException;
|
||||
import java.security.cert.Certificate;
|
||||
import java.security.cert.CertificateFactory;
|
||||
import java.security.cert.CertPathBuilder;
|
||||
import java.security.cert.CertPathBuilderResult;
|
||||
import java.security.cert.PKIXBuilderParameters;
|
||||
import java.security.cert.TrustAnchor;
|
||||
import java.security.cert.X509Certificate;
|
||||
import java.security.cert.CertSelector;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* BuildOddSel tries to perform a simple build of a certification path
|
||||
* using the PKIX algorithm and a bogus target constraints CertSelector
|
||||
* (one that is not an instance of X509CertSelector). On success, it should
|
||||
* throw an InvalidAlgorithmParameterException.
|
||||
*
|
||||
* @author Steve Hanna
|
||||
* @author Sean Mullan
|
||||
*/
|
||||
public final class BuildOddSel {
|
||||
|
||||
private static PKIXBuilderParameters params;
|
||||
private static CertSelector sel;
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
|
||||
try {
|
||||
createParams();
|
||||
build(params);
|
||||
throw new Exception
|
||||
("CertPath should not have been built successfully");
|
||||
} catch (InvalidAlgorithmParameterException iape) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* CertSelector class that should cause SunCertPathBuilder to
|
||||
* throw an InvalidAlgorithmParameterException.
|
||||
*/
|
||||
static class OddSel implements CertSelector {
|
||||
public Object clone() {
|
||||
try {
|
||||
return super.clone();
|
||||
} catch (CloneNotSupportedException e) {
|
||||
throw new UnknownError();
|
||||
}
|
||||
}
|
||||
public boolean match(Certificate cert) {
|
||||
return(false);
|
||||
}
|
||||
}
|
||||
|
||||
public static void createParams() throws Exception {
|
||||
TrustAnchor anchor = new TrustAnchor(getCertFromFile("sun.cer"), null);
|
||||
Set anchors = Collections.singleton(anchor);
|
||||
// Create odd CertSelector
|
||||
sel = new OddSel();
|
||||
params = new PKIXBuilderParameters(anchors, sel);
|
||||
params.setRevocationEnabled(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a DER-encoded X.509 certificate from a file.
|
||||
*
|
||||
* @param certFilePath path to file containing DER-encoded certificate
|
||||
* @return X509Certificate
|
||||
* @throws IOException on error
|
||||
*/
|
||||
public static X509Certificate getCertFromFile(String certFilePath)
|
||||
throws IOException {
|
||||
X509Certificate cert = null;
|
||||
try {
|
||||
File certFile = new File(System.getProperty("test.src", "."),
|
||||
certFilePath);
|
||||
FileInputStream certFileInputStream =
|
||||
new FileInputStream(certFile);
|
||||
CertificateFactory cf = CertificateFactory.getInstance("X509");
|
||||
cert = (X509Certificate)
|
||||
cf.generateCertificate(certFileInputStream);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
throw new IOException("Can't construct X509Certificate: " +
|
||||
e.getMessage());
|
||||
}
|
||||
return cert;
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform a PKIX build.
|
||||
*
|
||||
* @param params PKIXBuilderParameters to use in building
|
||||
* @throws Exception on error
|
||||
*/
|
||||
public static void build(PKIXBuilderParameters params)
|
||||
throws Exception {
|
||||
CertPathBuilder builder =
|
||||
CertPathBuilder.getInstance("PKIX");
|
||||
CertPathBuilderResult cpbr = builder.build(params);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
-----BEGIN CERTIFICATE-----
|
||||
MIIBFzCBwgIBATANBgkqhkiG9w0BAQQFADAXMRUwEwYDVQQDEwxUcnVzdCBBbmNo
|
||||
b3IwHhcNMDIxMTA3MTE1NzAzWhcNMjIxMTA3MTE1NzAzWjAXMRUwEwYDVQQDEwxU
|
||||
cnVzdCBBbmNob3IwXDANBgkqhkiG9w0BAQEFAANLADBIAkEA9uCj12hwDgC1n9go
|
||||
0ozQAVMM+DfX0vpKOemyGNp+ycSLfAq3pxBcUKbQhjSRL7YjPkEL8XC6pRLwyEoF
|
||||
osWweQIDAQABMA0GCSqGSIb3DQEBBAUAA0EAzZta5M1qbbozj7jWnNyTgB4HUpzv
|
||||
4eP0VYQb1pQY1/xEMczaRt+RuoIDnHCq5a1vOiwk6ZbdG6GlJKx9lj0oMQ==
|
||||
-----END CERTIFICATE-----
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
-----BEGIN CERTIFICATE-----
|
||||
MIIBSjCB9aADAgECAgECMA0GCSqGSIb3DQEBBAUAMBcxFTATBgNVBAMTDFRydXN0
|
||||
IEFuY2hvcjAeFw0wMjExMDcxMTU3MDNaFw0yMjExMDcxMTU3MDNaMA0xCzAJBgNV
|
||||
BAMTAkNBMFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAJ8mP3x37PablDfwldGL5G0+
|
||||
l9NgMJSdxVNWBg+ySzQNsZklEFCxGfxPQW+EFYfafHbTbmnni2gsgU1mgPBTQDsC
|
||||
AwEAAaM2MDQwCwYDVR0PBAQDAgIEMBcGA1UdIAQQMA4wBgYEVR0gADAEBgIqADAM
|
||||
BgNVHRMEBTADAQH/MA0GCSqGSIb3DQEBBAUAA0EA9oCyzh0UKmNsKb+KpppbKYs8
|
||||
iA8sDm9oDCwyVSXBM46zrP38nRcx3EdKFvGTwbb/Np+lcZALUsKVYQy3rlU+cQ==
|
||||
-----END CERTIFICATE-----
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
-----BEGIN CERTIFICATE-----
|
||||
MIIBLTCB2KADAgECAgEDMA0GCSqGSIb3DQEBBAUAMA0xCzAJBgNVBAMTAkNBMB4X
|
||||
DTAyMTEwNzExNTcwM1oXDTIyMTEwNzExNTcwM1owFTETMBEGA1UEAxMKRW5kIEVu
|
||||
dGl0eTBcMA0GCSqGSIb3DQEBAQUAA0sAMEgCQQDVBDfF+uBr5s5jzzDs1njKlZNt
|
||||
h8hHzEt3ASh67Peos+QrDzgpUyFXT6fdW2h7iPf0ifjM8eW2xa+3EnPjjU5jAgMB
|
||||
AAGjGzAZMBcGA1UdIAQQMA4wBgYEVR0gADAEBgIqADANBgkqhkiG9w0BAQQFAANB
|
||||
AFo//WOboCNOCcA1fvcWW9oc4MvV8ZPvFIAbyEbgyFd4id5lGDTRbRPvvNZRvdsN
|
||||
NM2gXYr+f87NHIXc9EF3pzw=
|
||||
-----END CERTIFICATE-----
|
||||
Binary file not shown.
|
|
@ -0,0 +1,79 @@
|
|||
/*
|
||||
* Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @bug 4442566 7176326
|
||||
* @summary check that we can build and validate a zero-length
|
||||
* certpath when a trust anchor cert satisfies the target constraints
|
||||
*/
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.security.cert.*;
|
||||
import java.util.Collections;
|
||||
|
||||
public class ZeroLengthPath {
|
||||
|
||||
private static final String ANCHOR =
|
||||
"-----BEGIN CERTIFICATE-----\n" +
|
||||
"MIIBFzCBwgIBATANBgkqhkiG9w0BAQQFADAXMRUwEwYDVQQDEwxUcnVzdCBBbmNo\n" +
|
||||
"b3IwHhcNMDIxMTA3MTE1NzAzWhcNMjIxMTA3MTE1NzAzWjAXMRUwEwYDVQQDEwxU\n" +
|
||||
"cnVzdCBBbmNob3IwXDANBgkqhkiG9w0BAQEFAANLADBIAkEA9uCj12hwDgC1n9go\n" +
|
||||
"0ozQAVMM+DfX0vpKOemyGNp+ycSLfAq3pxBcUKbQhjSRL7YjPkEL8XC6pRLwyEoF\n" +
|
||||
"osWweQIDAQABMA0GCSqGSIb3DQEBBAUAA0EAzZta5M1qbbozj7jWnNyTgB4HUpzv\n" +
|
||||
"4eP0VYQb1pQY1/xEMczaRt+RuoIDnHCq5a1vOiwk6ZbdG6GlJKx9lj0oMQ==\n" +
|
||||
"-----END CERTIFICATE-----";
|
||||
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
|
||||
ByteArrayInputStream is = new ByteArrayInputStream(ANCHOR.getBytes());
|
||||
CertificateFactory cf = CertificateFactory.getInstance("X.509");
|
||||
X509Certificate cert = (X509Certificate)cf.generateCertificate(is);
|
||||
|
||||
X509CertSelector xcs = new X509CertSelector();
|
||||
xcs.setSubject(cert.getSubjectX500Principal().getName());
|
||||
PKIXBuilderParameters p = new PKIXBuilderParameters
|
||||
(Collections.singleton(new TrustAnchor(cert, null)), xcs);
|
||||
CertPathBuilder cpb = CertPathBuilder.getInstance("PKIX");
|
||||
CertPath cp = buildCertPath(cpb, p);
|
||||
validateCertPath(cp, p);
|
||||
}
|
||||
|
||||
private static CertPath buildCertPath(CertPathBuilder cpb,
|
||||
PKIXBuilderParameters params)
|
||||
throws Exception
|
||||
{
|
||||
CertPathBuilderResult res = cpb.build(params);
|
||||
if (res.getCertPath().getCertificates().size() != 0) {
|
||||
throw new Exception("built path is not zero-length");
|
||||
}
|
||||
return res.getCertPath();
|
||||
}
|
||||
|
||||
private static void validateCertPath(CertPath cp, PKIXParameters params)
|
||||
throws Exception
|
||||
{
|
||||
CertPathValidator cpv = CertPathValidator.getInstance("PKIX");
|
||||
CertPathValidatorResult cpvr = cpv.validate(cp, params);
|
||||
}
|
||||
}
|
||||
253
test/jdk/java/security/cert/CertPathEncodingTest.java
Normal file
253
test/jdk/java/security/cert/CertPathEncodingTest.java
Normal file
|
|
@ -0,0 +1,253 @@
|
|||
/*
|
||||
* Copyright (c) 1998, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.security.cert.CertPath;
|
||||
import java.security.cert.Certificate;
|
||||
import java.security.cert.CertificateFactory;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Base64;
|
||||
import java.util.List;
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 8074931
|
||||
* @summary CertPathEncodingTest tests the ability of the CertPath and
|
||||
* CertificateFactory to encode and decode CertPaths.
|
||||
*/
|
||||
public final class CertPathEncodingTest {
|
||||
/*
|
||||
Certificate:
|
||||
Data:
|
||||
Version: 3 (0x2)
|
||||
Serial Number: 935438132 (0x37c1a734)
|
||||
Signature Algorithm: dsaWithSHA1
|
||||
Issuer: C=us, O=sun, OU=east, OU=bcn, CN=yassir
|
||||
Validity
|
||||
Not Before: Aug 23 19:55:32 1999 GMT
|
||||
Not After : Aug 22 19:55:32 2000 GMT
|
||||
Subject: C=us, O=sun, OU=east, OU=bcn
|
||||
Subject Public Key Info:
|
||||
Public Key Algorithm: dsaEncryption
|
||||
pub:
|
||||
63:47:4f:f6:29:e5:98:a2:21:fd:da:97:9e:3f:ca:
|
||||
b0:17:49:8d:8a:a7:06:0d:a6:78:97:39:59:33:72:
|
||||
a2:a5:74:d5:3a:ef:e6:7c:07:d7:8e:8e:d1:66:73:
|
||||
99:14:04:96:f5:31:d6:72:ee:d2:53:f8:90:b5:f3:
|
||||
c3:f1:64:ba:1a:9e:c0:0a:da:92:48:c5:d3:84:7e:
|
||||
48:09:66:d9:51:ba:74:56:5a:77:8a:8c:9a:9c:f6:
|
||||
84:12:61:12:51:dc:c6:4f:84:94:ec:cb:78:51:83:
|
||||
8c:20:8a:53:7b:d2:b6:36:df:50:35:95:1f:cb:50:
|
||||
55:8b:3f:fb:e2:77:cb
|
||||
P:
|
||||
00:fd:7f:53:81:1d:75:12:29:52:df:4a:9c:2e:ec:
|
||||
e4:e7:f6:11:b7:52:3c:ef:44:00:c3:1e:3f:80:b6:
|
||||
51:26:69:45:5d:40:22:51:fb:59:3d:8d:58:fa:bf:
|
||||
c5:f5:ba:30:f6:cb:9b:55:6c:d7:81:3b:80:1d:34:
|
||||
6f:f2:66:60:b7:6b:99:50:a5:a4:9f:9f:e8:04:7b:
|
||||
10:22:c2:4f:bb:a9:d7:fe:b7:c6:1b:f8:3b:57:e7:
|
||||
c6:a8:a6:15:0f:04:fb:83:f6:d3:c5:1e:c3:02:35:
|
||||
54:13:5a:16:91:32:f6:75:f3:ae:2b:61:d7:2a:ef:
|
||||
f2:22:03:19:9d:d1:48:01:c7
|
||||
Q:
|
||||
00:97:60:50:8f:15:23:0b:cc:b2:92:b9:82:a2:eb:
|
||||
84:0b:f0:58:1c:f5
|
||||
G:
|
||||
00:f7:e1:a0:85:d6:9b:3d:de:cb:bc:ab:5c:36:b8:
|
||||
57:b9:79:94:af:bb:fa:3a:ea:82:f9:57:4c:0b:3d:
|
||||
07:82:67:51:59:57:8e:ba:d4:59:4f:e6:71:07:10:
|
||||
81:80:b4:49:16:71:23:e8:4c:28:16:13:b7:cf:09:
|
||||
32:8c:c8:a6:e1:3c:16:7a:8b:54:7c:8d:28:e0:a3:
|
||||
ae:1e:2b:b3:a6:75:91:6e:a3:7f:0b:fa:21:35:62:
|
||||
f1:fb:62:7a:01:24:3b:cc:a4:f1:be:a8:51:90:89:
|
||||
a8:83:df:e1:5a:e5:9f:06:92:8b:66:5e:80:7b:55:
|
||||
25:64:01:4c:3b:fe:cf:49:2a
|
||||
X509v3 extensions:
|
||||
X509v3 Key Usage: critical
|
||||
Digital Signature, Key Encipherment, Certificate Sign
|
||||
Signature Algorithm: dsaWithSHA1
|
||||
r:
|
||||
52:80:52:2b:2c:3d:02:66:58:b4:dc:ef:52:26:70:
|
||||
1b:53:ca:b3:7d
|
||||
s:
|
||||
62:03:b2:ab:3e:18:2a:66:09:b6:ce:d4:05:a5:8e:
|
||||
a5:7a:0d:55:67
|
||||
*/
|
||||
private static final String cert1 =
|
||||
"-----BEGIN CERTIFICATE-----\n" +
|
||||
"MIICzTCCAougAwIBAgIEN8GnNDALBgcqhkjOOAQDBQAwSTELMAkGA1UEBhMCdXMx\n" +
|
||||
"DDAKBgNVBAoTA3N1bjENMAsGA1UECxMEZWFzdDEMMAoGA1UECxMDYmNuMQ8wDQYD\n" +
|
||||
"VQQDEwZ5YXNzaXIwHhcNOTkwODIzMTk1NTMyWhcNMDAwODIyMTk1NTMyWjA4MQsw\n" +
|
||||
"CQYDVQQGEwJ1czEMMAoGA1UEChMDc3VuMQ0wCwYDVQQLEwRlYXN0MQwwCgYDVQQL\n" +
|
||||
"EwNiY24wggG1MIIBLAYHKoZIzjgEATCCAR8CgYEA/X9TgR11EilS30qcLuzk5/YR\n" +
|
||||
"t1I870QAwx4/gLZRJmlFXUAiUftZPY1Y+r/F9bow9subVWzXgTuAHTRv8mZgt2uZ\n" +
|
||||
"UKWkn5/oBHsQIsJPu6nX/rfGG/g7V+fGqKYVDwT7g/bTxR7DAjVUE1oWkTL2dfOu\n" +
|
||||
"K2HXKu/yIgMZndFIAccCFQCXYFCPFSMLzLKSuYKi64QL8Fgc9QKBgQD34aCF1ps9\n" +
|
||||
"3su8q1w2uFe5eZSvu/o66oL5V0wLPQeCZ1FZV4661FlP5nEHEIGAtEkWcSPoTCgW\n" +
|
||||
"E7fPCTKMyKbhPBZ6i1R8jSjgo64eK7OmdZFuo38L+iE1YvH7YnoBJDvMpPG+qFGQ\n" +
|
||||
"iaiD3+Fa5Z8GkotmXoB7VSVkAUw7/s9JKgOBggACf2NHT/Yp5ZiiIf3al54/yrAX\n" +
|
||||
"SY2KpwYNpniXOVkzcqKldNU67+Z8B9eOjtFmc5kUBJb1MdZy7tJT+JC188PxZLoa\n" +
|
||||
"nsAK2pJIxdOEfkgJZtlRunRWWneKjJqc9oQSYRJR3MZPhJTsy3hRg4wgilN70rY2\n" +
|
||||
"31A1lR/LUFWLP/vid8ujEzARMA8GA1UdDwEB/wQFAwMHpAAwCwYHKoZIzjgEAwUA\n" +
|
||||
"Ay8AMCwCFFKAUissPQJmWLTc71ImcBtTyrN9AhRiA7KrPhgqZgm2ztQFpY6leg1V\n" +
|
||||
"Zw==\n" +
|
||||
"-----END CERTIFICATE-----\n" +
|
||||
"";
|
||||
|
||||
/*
|
||||
Certificate:
|
||||
Data:
|
||||
Version: 3 (0x2)
|
||||
Serial Number: 935095671 (0x37bc6d77)
|
||||
Signature Algorithm: dsaWithSHA1
|
||||
Issuer: C=us, O=sun, OU=east, OU=bcn, CN=yassir
|
||||
Validity
|
||||
Not Before: Aug 19 20:47:51 1999 GMT
|
||||
Not After : Aug 18 20:47:51 2000 GMT
|
||||
Subject: C=us, O=sun, OU=east, OU=bcn, CN=yassir
|
||||
Subject Public Key Info:
|
||||
Public Key Algorithm: dsaEncryption
|
||||
pub:
|
||||
0a:cc:a4:ec:d6:88:45:c2:24:6b:0d:78:f1:82:f3:
|
||||
5e:3e:31:5d:fb:64:d5:06:5e:39:16:f1:0a:85:d1:
|
||||
ff:d1:a4:74:c5:e6:b0:ba:93:1c:ee:69:51:be:3b:
|
||||
a6:66:44:50:b4:f0:5e:0e:dd:9f:08:71:fe:a1:91:
|
||||
2e:d4:9e:6b:b2:c0:82:3c:91:6c:18:b0:d9:bc:a3:
|
||||
48:91:3f:8b:59:01:61:00:02:ab:22:31:bc:7c:6c:
|
||||
0d:9f:ed:be:33:e6:5c:44:9e:62:30:95:f8:6d:22:
|
||||
d7:e5:85:4c:b0:98:6e:ad:cc:ca:3b:ad:cb:fa:f7:
|
||||
9f:37:13:f7:ca:e2:22:ba
|
||||
P:
|
||||
00:fd:7f:53:81:1d:75:12:29:52:df:4a:9c:2e:ec:
|
||||
e4:e7:f6:11:b7:52:3c:ef:44:00:c3:1e:3f:80:b6:
|
||||
51:26:69:45:5d:40:22:51:fb:59:3d:8d:58:fa:bf:
|
||||
c5:f5:ba:30:f6:cb:9b:55:6c:d7:81:3b:80:1d:34:
|
||||
6f:f2:66:60:b7:6b:99:50:a5:a4:9f:9f:e8:04:7b:
|
||||
10:22:c2:4f:bb:a9:d7:fe:b7:c6:1b:f8:3b:57:e7:
|
||||
c6:a8:a6:15:0f:04:fb:83:f6:d3:c5:1e:c3:02:35:
|
||||
54:13:5a:16:91:32:f6:75:f3:ae:2b:61:d7:2a:ef:
|
||||
f2:22:03:19:9d:d1:48:01:c7
|
||||
Q:
|
||||
00:97:60:50:8f:15:23:0b:cc:b2:92:b9:82:a2:eb:
|
||||
84:0b:f0:58:1c:f5
|
||||
G:
|
||||
00:f7:e1:a0:85:d6:9b:3d:de:cb:bc:ab:5c:36:b8:
|
||||
57:b9:79:94:af:bb:fa:3a:ea:82:f9:57:4c:0b:3d:
|
||||
07:82:67:51:59:57:8e:ba:d4:59:4f:e6:71:07:10:
|
||||
81:80:b4:49:16:71:23:e8:4c:28:16:13:b7:cf:09:
|
||||
32:8c:c8:a6:e1:3c:16:7a:8b:54:7c:8d:28:e0:a3:
|
||||
ae:1e:2b:b3:a6:75:91:6e:a3:7f:0b:fa:21:35:62:
|
||||
f1:fb:62:7a:01:24:3b:cc:a4:f1:be:a8:51:90:89:
|
||||
a8:83:df:e1:5a:e5:9f:06:92:8b:66:5e:80:7b:55:
|
||||
25:64:01:4c:3b:fe:cf:49:2a
|
||||
X509v3 extensions:
|
||||
X509v3 Key Usage: critical
|
||||
Digital Signature, Key Encipherment, Certificate Sign
|
||||
X509v3 Basic Constraints: critical
|
||||
CA:TRUE, pathlen:5
|
||||
Signature Algorithm: dsaWithSHA1
|
||||
r:
|
||||
2f:88:46:37:94:92:b2:02:07:5b:8d:76:e5:81:23:
|
||||
85:7f:bc:8d:b9
|
||||
s:
|
||||
00:8b:d7:41:fa:11:c7:ab:27:92:5d:0a:03:98:56:
|
||||
36:42:5f:f5:1f:9d
|
||||
*/
|
||||
private static final String cert2 =
|
||||
"-----BEGIN CERTIFICATE-----\n" +
|
||||
"MIIC9TCCArKgAwIBAgIEN7xtdzALBgcqhkjOOAQDBQAwSTELMAkGA1UEBhMCdXMx\n" +
|
||||
"DDAKBgNVBAoTA3N1bjENMAsGA1UECxMEZWFzdDEMMAoGA1UECxMDYmNuMQ8wDQYD\n" +
|
||||
"VQQDEwZ5YXNzaXIwHhcNOTkwODE5MjA0NzUxWhcNMDAwODE4MjA0NzUxWjBJMQsw\n" +
|
||||
"CQYDVQQGEwJ1czEMMAoGA1UEChMDc3VuMQ0wCwYDVQQLEwRlYXN0MQwwCgYDVQQL\n" +
|
||||
"EwNiY24xDzANBgNVBAMTBnlhc3NpcjCCAbcwggEsBgcqhkjOOAQBMIIBHwKBgQD9\n" +
|
||||
"f1OBHXUSKVLfSpwu7OTn9hG3UjzvRADDHj+AtlEmaUVdQCJR+1k9jVj6v8X1ujD2\n" +
|
||||
"y5tVbNeBO4AdNG/yZmC3a5lQpaSfn+gEexAiwk+7qdf+t8Yb+DtX58aophUPBPuD\n" +
|
||||
"9tPFHsMCNVQTWhaRMvZ1864rYdcq7/IiAxmd0UgBxwIVAJdgUI8VIwvMspK5gqLr\n" +
|
||||
"hAvwWBz1AoGBAPfhoIXWmz3ey7yrXDa4V7l5lK+7+jrqgvlXTAs9B4JnUVlXjrrU\n" +
|
||||
"WU/mcQcQgYC0SRZxI+hMKBYTt88JMozIpuE8FnqLVHyNKOCjrh4rs6Z1kW6jfwv6\n" +
|
||||
"ITVi8ftiegEkO8yk8b6oUZCJqIPf4VrlnwaSi2ZegHtVJWQBTDv+z0kqA4GEAAKB\n" +
|
||||
"gArMpOzWiEXCJGsNePGC814+MV37ZNUGXjkW8QqF0f/RpHTF5rC6kxzuaVG+O6Zm\n" +
|
||||
"RFC08F4O3Z8Icf6hkS7UnmuywII8kWwYsNm8o0iRP4tZAWEAAqsiMbx8bA2f7b4z\n" +
|
||||
"5lxEnmIwlfhtItflhUywmG6tzMo7rcv69583E/fK4iK6oycwJTAPBgNVHQ8BAf8E\n" +
|
||||
"BQMDB6QAMBIGA1UdEwEB/wQIMAYBAf8CAQUwCwYHKoZIzjgEAwUAAzAAMC0CFC+I\n" +
|
||||
"RjeUkrICB1uNduWBI4V/vI25AhUAi9dB+hHHqyeSXQoDmFY2Ql/1H50=\n" +
|
||||
"-----END CERTIFICATE-----\n" +
|
||||
"";
|
||||
|
||||
private static final String pkcs7path =
|
||||
"MIIF9QYJKoZIhvcNAQcCoIIF5jCCBeICAQExADALBgkqhkiG9w0BBwGgggXKMIICzTCCAougAwIB\n" +
|
||||
"AgIEN8GnNDALBgcqhkjOOAQDBQAwSTELMAkGA1UEBhMCdXMxDDAKBgNVBAoTA3N1bjENMAsGA1UE\n" +
|
||||
"CxMEZWFzdDEMMAoGA1UECxMDYmNuMQ8wDQYDVQQDEwZ5YXNzaXIwHhcNOTkwODIzMTk1NTMyWhcN\n" +
|
||||
"MDAwODIyMTk1NTMyWjA4MQswCQYDVQQGEwJ1czEMMAoGA1UEChMDc3VuMQ0wCwYDVQQLEwRlYXN0\n" +
|
||||
"MQwwCgYDVQQLEwNiY24wggG1MIIBLAYHKoZIzjgEATCCAR8CgYEA/X9TgR11EilS30qcLuzk5/YR\n" +
|
||||
"t1I870QAwx4/gLZRJmlFXUAiUftZPY1Y+r/F9bow9subVWzXgTuAHTRv8mZgt2uZUKWkn5/oBHsQ\n" +
|
||||
"IsJPu6nX/rfGG/g7V+fGqKYVDwT7g/bTxR7DAjVUE1oWkTL2dfOuK2HXKu/yIgMZndFIAccCFQCX\n" +
|
||||
"YFCPFSMLzLKSuYKi64QL8Fgc9QKBgQD34aCF1ps93su8q1w2uFe5eZSvu/o66oL5V0wLPQeCZ1FZ\n" +
|
||||
"V4661FlP5nEHEIGAtEkWcSPoTCgWE7fPCTKMyKbhPBZ6i1R8jSjgo64eK7OmdZFuo38L+iE1YvH7\n" +
|
||||
"YnoBJDvMpPG+qFGQiaiD3+Fa5Z8GkotmXoB7VSVkAUw7/s9JKgOBggACf2NHT/Yp5ZiiIf3al54/\n" +
|
||||
"yrAXSY2KpwYNpniXOVkzcqKldNU67+Z8B9eOjtFmc5kUBJb1MdZy7tJT+JC188PxZLoansAK2pJI\n" +
|
||||
"xdOEfkgJZtlRunRWWneKjJqc9oQSYRJR3MZPhJTsy3hRg4wgilN70rY231A1lR/LUFWLP/vid8uj\n" +
|
||||
"EzARMA8GA1UdDwEB/wQFAwMHpAAwCwYHKoZIzjgEAwUAAy8AMCwCFFKAUissPQJmWLTc71ImcBtT\n" +
|
||||
"yrN9AhRiA7KrPhgqZgm2ztQFpY6leg1VZzCCAvUwggKyoAMCAQICBDe8bXcwCwYHKoZIzjgEAwUA\n" +
|
||||
"MEkxCzAJBgNVBAYTAnVzMQwwCgYDVQQKEwNzdW4xDTALBgNVBAsTBGVhc3QxDDAKBgNVBAsTA2Jj\n" +
|
||||
"bjEPMA0GA1UEAxMGeWFzc2lyMB4XDTk5MDgxOTIwNDc1MVoXDTAwMDgxODIwNDc1MVowSTELMAkG\n" +
|
||||
"A1UEBhMCdXMxDDAKBgNVBAoTA3N1bjENMAsGA1UECxMEZWFzdDEMMAoGA1UECxMDYmNuMQ8wDQYD\n" +
|
||||
"VQQDEwZ5YXNzaXIwggG3MIIBLAYHKoZIzjgEATCCAR8CgYEA/X9TgR11EilS30qcLuzk5/YRt1I8\n" +
|
||||
"70QAwx4/gLZRJmlFXUAiUftZPY1Y+r/F9bow9subVWzXgTuAHTRv8mZgt2uZUKWkn5/oBHsQIsJP\n" +
|
||||
"u6nX/rfGG/g7V+fGqKYVDwT7g/bTxR7DAjVUE1oWkTL2dfOuK2HXKu/yIgMZndFIAccCFQCXYFCP\n" +
|
||||
"FSMLzLKSuYKi64QL8Fgc9QKBgQD34aCF1ps93su8q1w2uFe5eZSvu/o66oL5V0wLPQeCZ1FZV466\n" +
|
||||
"1FlP5nEHEIGAtEkWcSPoTCgWE7fPCTKMyKbhPBZ6i1R8jSjgo64eK7OmdZFuo38L+iE1YvH7YnoB\n" +
|
||||
"JDvMpPG+qFGQiaiD3+Fa5Z8GkotmXoB7VSVkAUw7/s9JKgOBhAACgYAKzKTs1ohFwiRrDXjxgvNe\n" +
|
||||
"PjFd+2TVBl45FvEKhdH/0aR0xeawupMc7mlRvjumZkRQtPBeDt2fCHH+oZEu1J5rssCCPJFsGLDZ\n" +
|
||||
"vKNIkT+LWQFhAAKrIjG8fGwNn+2+M+ZcRJ5iMJX4bSLX5YVMsJhurczKO63L+vefNxP3yuIiuqMn\n" +
|
||||
"MCUwDwYDVR0PAQH/BAUDAwekADASBgNVHRMBAf8ECDAGAQH/AgEFMAsGByqGSM44BAMFAAMwADAt\n" +
|
||||
"AhQviEY3lJKyAgdbjXblgSOFf7yNuQIVAIvXQfoRx6snkl0KA5hWNkJf9R+dMQA=\n" +
|
||||
"";
|
||||
|
||||
// Runs test of CertPath encoding and decoding.
|
||||
public static void main(String[] args) throws Exception {
|
||||
// Make the CertPath whose encoded form has already been stored
|
||||
CertificateFactory certFac = CertificateFactory.getInstance("X509");
|
||||
|
||||
final List<Certificate> certs = new ArrayList<>();
|
||||
certs.add(certFac.generateCertificate(new ByteArrayInputStream(cert1.getBytes())));
|
||||
certs.add(certFac.generateCertificate(new ByteArrayInputStream(cert2.getBytes())));
|
||||
|
||||
CertPath cp = certFac.generateCertPath(certs);
|
||||
|
||||
// Get the encoded form of the CertPath we made
|
||||
byte[] encoded = cp.getEncoded("PKCS7");
|
||||
|
||||
// check if it matches the encoded value
|
||||
if (!Arrays.equals(encoded, Base64.getMimeDecoder().decode(pkcs7path.getBytes()))) {
|
||||
throw new RuntimeException("PKCS#7 encoding doesn't match stored value");
|
||||
}
|
||||
|
||||
// Generate a CertPath from the encoded value and check if it equals
|
||||
// the CertPath generated from the certificates
|
||||
CertPath decodedCP = certFac.generateCertPath(new ByteArrayInputStream(encoded), "PKCS7");
|
||||
if (!decodedCP.equals(cp)) {
|
||||
throw new RuntimeException("CertPath decoded from PKCS#7 isn't equal to original");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
-----BEGIN CERTIFICATE-----
|
||||
MIICuDCCAiGgAwIBAgIBBzANBgkqhkiG9w0BAQQFADAtMQswCQYDVQQGEwJVUzEM
|
||||
MAoGA1UEChMDU3VuMRAwDgYDVQQDEwdSb290IENBMB4XDTA3MDMyMzE3MTUzNloX
|
||||
DTM0MDgwODE3MTUzNlowLjELMAkGA1UEBhMCVVMxDDAKBgNVBAoTA1N1bjERMA8G
|
||||
A1UEAxMIUm9iIEZvbGswgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBAJ+BDk0i
|
||||
pXPQrwt7THIXD0sdbJLaMjsSynGheimobX0NAtYOKllWBmBC5bkHCkvjekbprSyV
|
||||
GnwBeEwrJRwfdnfmTyibyinFeB723lN/NQ8LbPSoZTo8Gdkp5193H4SFqfrWCRZ9
|
||||
4RYnmmqS7Ut5PWR5vlsMqktwx0qXlD0kq9TNAgMBAAGjgeYwgeMwCQYDVR0TBAIw
|
||||
ADAsBglghkgBhvhCAQ0EHxYdT3BlblNTTCBHZW5lcmF0ZWQgQ2VydGlmaWNhdGUw
|
||||
HQYDVR0OBBYEFJn9r1+sySfqvyggruKsdeeaF6qsMFUGA1UdIwROMEyAFB1J2ChQ
|
||||
l8QDIVxcr/9Eio/dNxUkoTGkLzAtMQswCQYDVQQGEwJVUzEMMAoGA1UEChMDU3Vu
|
||||
MRAwDgYDVQQDEwdSb290IENBggEAMDIGCCsGAQUFBwEBBCYwJDAiBggrBgEFBQcw
|
||||
AYYWaHR0cDovL2xvY2FsaG9zdDo4ODg4LzANBgkqhkiG9w0BAQQFAAOBgQCOflBZ
|
||||
wXCydtjJ0TGT6/8cZxOYAK0Gy8Nz2GLtYm6N+Dip1HZei+8SOY8VsitURdAb6d60
|
||||
PbJiHHcACdVaK2JLdijTr6xKi2AS6/qtjlxwLV5goX4mRl8W/xQhEf2KkT6cuUP0
|
||||
rM6Lq/qODnJfkhT8s/kUsFDUzNenK0QcCiC6og==
|
||||
-----END CERTIFICATE-----
|
||||
109
test/jdk/java/security/cert/CertPathValidator/OCSP/AIACheck.java
Normal file
109
test/jdk/java/security/cert/CertPathValidator/OCSP/AIACheck.java
Normal file
|
|
@ -0,0 +1,109 @@
|
|||
/*
|
||||
* Copyright (c) 2004, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
//
|
||||
// Security properties, once set, cannot revert to unset. To avoid
|
||||
// conflicts with tests running in the same VM isolate this test by
|
||||
// running it in otherVM mode.
|
||||
//
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @bug 5072953
|
||||
* @summary Verify that the URL for an OCSP responder can be extracted from a
|
||||
* certificate's AuthorityInfoAccess extension when OCSP certifiate
|
||||
* validation has been enabled.
|
||||
* @run main/othervm AIACheck
|
||||
*/
|
||||
|
||||
import java.io.*;
|
||||
import java.net.*;
|
||||
import java.util.*;
|
||||
import java.security.Security;
|
||||
import java.security.cert.*;
|
||||
|
||||
public class AIACheck {
|
||||
|
||||
private final static File baseDir =
|
||||
new File(System.getProperty("test.src", "."));
|
||||
|
||||
private static X509Certificate loadCertificate(String name)
|
||||
throws Exception
|
||||
{
|
||||
File certFile = new File(baseDir, name);
|
||||
InputStream in = new FileInputStream(certFile);
|
||||
CertificateFactory cf = CertificateFactory.getInstance("X.509");
|
||||
X509Certificate cert = (X509Certificate)cf.generateCertificate(in);
|
||||
return cert;
|
||||
}
|
||||
|
||||
public static void main(String args[]) throws Exception {
|
||||
// MD5 is used in this test case, don't disable MD5 algorithm.
|
||||
Security.setProperty(
|
||||
"jdk.certpath.disabledAlgorithms", "MD2, RSA keySize < 1024");
|
||||
|
||||
X509Certificate aiaCert = loadCertificate("AIACert.pem");
|
||||
X509Certificate rootCert = loadCertificate("RootCert.pem");
|
||||
|
||||
List<X509Certificate> list =
|
||||
//Arrays.asList(new X509Certificate[] {aiaCert, rootCert});
|
||||
Arrays.asList(new X509Certificate[] {aiaCert});
|
||||
CertificateFactory cf = CertificateFactory.getInstance("X.509");
|
||||
CertPath path = cf.generateCertPath(list);
|
||||
|
||||
TrustAnchor anchor = new TrustAnchor(rootCert, null);
|
||||
Set<TrustAnchor> anchors = Collections.singleton(anchor);
|
||||
|
||||
PKIXParameters params = new PKIXParameters(anchors);
|
||||
// Activate certificate revocation checking
|
||||
params.setRevocationEnabled(true);
|
||||
|
||||
// Activate OCSP
|
||||
Security.setProperty("ocsp.enable", "true");
|
||||
|
||||
// Ensure that the ocsp.responderURL property is not set.
|
||||
if (Security.getProperty("ocsp.responderURL") != null) {
|
||||
throw new
|
||||
Exception("The ocsp.responderURL property must not be set");
|
||||
}
|
||||
|
||||
CertPathValidator validator = CertPathValidator.getInstance("PKIX");
|
||||
|
||||
try {
|
||||
validator.validate(path, params);
|
||||
throw new Exception("Successfully validated an invalid path");
|
||||
|
||||
} catch (CertPathValidatorException e ) {
|
||||
Throwable rootCause = e.getCause();
|
||||
if (!(rootCause instanceof SocketException ||
|
||||
rootCause instanceof SocketTimeoutException)) {
|
||||
throw e;
|
||||
}
|
||||
|
||||
// Success - client located OCSP responder in AIA extension
|
||||
// and attempted to connect.
|
||||
System.out.println("Extracted the URL of the OCSP responder from " +
|
||||
"the certificate's AuthorityInfoAccess extension.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,281 @@
|
|||
/*
|
||||
* Copyright (c) 2009, 2025, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
//
|
||||
// Security properties, once set, cannot revert to unset. To avoid
|
||||
// conflicts with tests running in the same VM isolate this test by
|
||||
// running it in otherVM mode.
|
||||
//
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @bug 6383095
|
||||
* @summary CRL revoked certificate failures masked by OCSP failures
|
||||
* @run main/othervm FailoverToCRL
|
||||
* @enablePreview
|
||||
* @author Xuelei Fan
|
||||
*/
|
||||
|
||||
/*
|
||||
* Note that the certificate validity is from Mar 16 14:55:35 2009 GMT to
|
||||
* Dec 1 14:55:35 2028 GMT, please update it with newer certificate if
|
||||
* expires.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Certificates used in the test.
|
||||
*
|
||||
* end entity certificate:
|
||||
* Data:
|
||||
* Version: 3 (0x2)
|
||||
* Serial Number: 25 (0x19)
|
||||
* Signature Algorithm: md5WithRSAEncryption
|
||||
* Issuer: C=US, ST=Some-State, L=Some-City, O=Some-Org
|
||||
* Validity
|
||||
* Not Before: Mar 16 14:55:35 2009 GMT
|
||||
* Not After : Dec 1 14:55:35 2028 GMT
|
||||
* Subject: C=US, ST=Some-State, L=Some-City, O=Some-Org, OU=SSL-Client,
|
||||
* CN=localhost
|
||||
* Subject Public Key Info:
|
||||
* Public Key Algorithm: rsaEncryption
|
||||
* RSA Public Key: (1024 bit)
|
||||
* Modulus (1024 bit):
|
||||
* 00:bb:f0:40:36:ac:26:54:4e:f4:a3:5a:00:2f:69:
|
||||
* 21:6f:b9:7a:3a:93:ec:a2:f6:e1:8e:c7:63:d8:2f:
|
||||
* 12:30:99:2e:b0:f2:8f:f8:27:2d:24:78:28:84:f7:
|
||||
* 01:bf:8d:44:79:dd:3b:d2:55:f3:ce:3c:b2:5b:21:
|
||||
* 7d:ef:fd:33:4a:b1:a3:ff:c6:c8:9b:b9:0f:7c:41:
|
||||
* 35:97:f9:db:3a:05:60:05:15:af:59:17:92:a3:10:
|
||||
* ad:16:1c:e4:07:53:af:a8:76:a2:56:2a:92:d3:f9:
|
||||
* 28:e0:78:cf:5e:1f:48:ab:5c:19:dd:e1:67:43:ba:
|
||||
* 75:8d:f5:82:ac:43:92:44:1b
|
||||
* Exponent: 65537 (0x10001)
|
||||
* X509v3 extensions:
|
||||
* X509v3 Basic Constraints:
|
||||
* CA:FALSE
|
||||
* X509v3 Key Usage:
|
||||
* Digital Signature, Non Repudiation, Key Encipherment
|
||||
* X509v3 Subject Key Identifier:
|
||||
* CD:BB:C8:85:AA:91:BD:FD:1D:BE:CD:67:7C:FF:B3:E9:4C:A8:22:E6
|
||||
* X509v3 Authority Key Identifier:
|
||||
* keyid:FA:B9:51:BF:4C:E7:D9:86:98:33:F9:E7:CB:1E:F1:33:49:F7:A8:14
|
||||
* Signature Algorithm: md5WithRSAEncryption
|
||||
*
|
||||
*
|
||||
* trusted certificate authority:
|
||||
* Data:
|
||||
* Version: 3 (0x2)
|
||||
* Serial Number: 0 (0x0)
|
||||
* Signature Algorithm: md5WithRSAEncryption
|
||||
* Issuer: C=US, ST=Some-State, L=Some-City, O=Some-Org
|
||||
* Validity
|
||||
* Not Before: Dec 8 02:43:36 2008 GMT
|
||||
* Not After : Aug 25 02:43:36 2028 GMT
|
||||
* Subject: C=US, ST=Some-State, L=Some-City, O=Some-Org
|
||||
* Subject Public Key Info:
|
||||
* Public Key Algorithm: rsaEncryption
|
||||
* RSA Public Key: (1024 bit)
|
||||
* Modulus (1024 bit):
|
||||
* 00:cb:c4:38:20:07:be:88:a7:93:b0:a1:43:51:2d:
|
||||
* d7:8e:85:af:54:dd:ad:a2:7b:23:5b:cf:99:13:53:
|
||||
* 99:45:7d:ee:6d:ba:2d:bf:e3:ad:6e:3d:9f:1a:f9:
|
||||
* 03:97:e0:17:55:ae:11:26:57:de:01:29:8e:05:3f:
|
||||
* 21:f7:e7:36:e8:2e:37:d7:48:ac:53:d6:60:0e:c7:
|
||||
* 50:6d:f6:c5:85:f7:8b:a6:c5:91:35:72:3c:94:ee:
|
||||
* f1:17:f0:71:e3:ec:1b:ce:ca:4e:40:42:b0:6d:ee:
|
||||
* 6a:0e:d6:e5:ad:3c:0f:c9:ba:82:4f:78:f8:89:97:
|
||||
* 89:2a:95:12:4c:d8:09:2a:e9
|
||||
* Exponent: 65537 (0x10001)
|
||||
* X509v3 extensions:
|
||||
* X509v3 Subject Key Identifier:
|
||||
* FA:B9:51:BF:4C:E7:D9:86:98:33:F9:E7:CB:1E:F1:33:49:F7:A8:14
|
||||
* X509v3 Authority Key Identifier:
|
||||
* keyid:FA:B9:51:BF:4C:E7:D9:86:98:33:F9:E7:CB:1E:F1:33:49:F7:A8:14
|
||||
* DirName:/C=US/ST=Some-State/L=Some-City/O=Some-Org
|
||||
* X509v3 Basic Constraints:
|
||||
* CA:TRUE
|
||||
* Signature Algorithm: md5WithRSAEncryption
|
||||
*
|
||||
* CRL:
|
||||
* Certificate Revocation List (CRL):
|
||||
* Version 2 (0x1)
|
||||
* Signature Algorithm: md5WithRSAEncryption
|
||||
* Issuer: /C=US/ST=Some-State/L=Some-City/O=Some-Org
|
||||
* Last Update: Mar 16 16:27:14 2009 GMT
|
||||
* Next Update: May 15 16:27:14 2028 GMT
|
||||
* CRL extensions:
|
||||
* X509v3 CRL Number:
|
||||
* 2
|
||||
* Revoked Certificates:
|
||||
* Serial Number: 19
|
||||
* Revocation Date: Mar 16 16:22:08 2009 GMT
|
||||
* CRL entry extensions:
|
||||
* X509v3 CRL Reason Code:
|
||||
* Superseded
|
||||
* Signature Algorithm: md5WithRSAEncryption
|
||||
*/
|
||||
|
||||
import java.io.*;
|
||||
import java.net.SocketException;
|
||||
import java.security.DEREncodable;
|
||||
import java.security.PEMDecoder;
|
||||
import java.util.*;
|
||||
import java.security.Security;
|
||||
import java.security.cert.*;
|
||||
import java.security.InvalidAlgorithmParameterException;
|
||||
import java.security.cert.CertPathValidatorException.BasicReason;
|
||||
import java.util.Collections;
|
||||
|
||||
public class FailoverToCRL {
|
||||
|
||||
static String trusedCertStr =
|
||||
"-----BEGIN CERTIFICATE-----\n" +
|
||||
"MIICrDCCAhWgAwIBAgIBADANBgkqhkiG9w0BAQQFADBJMQswCQYDVQQGEwJVUzET\n" +
|
||||
"MBEGA1UECBMKU29tZS1TdGF0ZTESMBAGA1UEBxMJU29tZS1DaXR5MREwDwYDVQQK\n" +
|
||||
"EwhTb21lLU9yZzAeFw0wODEyMDgwMjQzMzZaFw0yODA4MjUwMjQzMzZaMEkxCzAJ\n" +
|
||||
"BgNVBAYTAlVTMRMwEQYDVQQIEwpTb21lLVN0YXRlMRIwEAYDVQQHEwlTb21lLUNp\n" +
|
||||
"dHkxETAPBgNVBAoTCFNvbWUtT3JnMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKB\n" +
|
||||
"gQDLxDggB76Ip5OwoUNRLdeOha9U3a2ieyNbz5kTU5lFfe5tui2/461uPZ8a+QOX\n" +
|
||||
"4BdVrhEmV94BKY4FPyH35zboLjfXSKxT1mAOx1Bt9sWF94umxZE1cjyU7vEX8HHj\n" +
|
||||
"7BvOyk5AQrBt7moO1uWtPA/JuoJPePiJl4kqlRJM2Akq6QIDAQABo4GjMIGgMB0G\n" +
|
||||
"A1UdDgQWBBT6uVG/TOfZhpgz+efLHvEzSfeoFDBxBgNVHSMEajBogBT6uVG/TOfZ\n" +
|
||||
"hpgz+efLHvEzSfeoFKFNpEswSTELMAkGA1UEBhMCVVMxEzARBgNVBAgTClNvbWUt\n" +
|
||||
"U3RhdGUxEjAQBgNVBAcTCVNvbWUtQ2l0eTERMA8GA1UEChMIU29tZS1PcmeCAQAw\n" +
|
||||
"DAYDVR0TBAUwAwEB/zANBgkqhkiG9w0BAQQFAAOBgQBcIm534U123Hz+rtyYO5uA\n" +
|
||||
"ofd81G6FnTfEAV8Kw9fGyyEbQZclBv34A9JsFKeMvU4OFIaixD7nLZ/NZ+IWbhmZ\n" +
|
||||
"LovmJXyCkOufea73pNiZ+f/4/ScZaIlM/PRycQSqbFNd4j9Wott+08qxHPLpsf3P\n" +
|
||||
"6Mvf0r1PNTY2hwTJLJmKtg==\n" +
|
||||
"-----END CERTIFICATE-----";
|
||||
|
||||
static String targetCertStr =
|
||||
"-----BEGIN CERTIFICATE-----\n" +
|
||||
"MIICizCCAfSgAwIBAgIBGTANBgkqhkiG9w0BAQQFADBJMQswCQYDVQQGEwJVUzET\n" +
|
||||
"MBEGA1UECBMKU29tZS1TdGF0ZTESMBAGA1UEBxMJU29tZS1DaXR5MREwDwYDVQQK\n" +
|
||||
"EwhTb21lLU9yZzAeFw0wOTAzMTYxNDU1MzVaFw0yODEyMDExNDU1MzVaMHIxCzAJ\n" +
|
||||
"BgNVBAYTAlVTMRMwEQYDVQQIEwpTb21lLVN0YXRlMRIwEAYDVQQHEwlTb21lLUNp\n" +
|
||||
"dHkxETAPBgNVBAoTCFNvbWUtT3JnMRMwEQYDVQQLEwpTU0wtQ2xpZW50MRIwEAYD\n" +
|
||||
"VQQDEwlsb2NhbGhvc3QwgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBALvwQDas\n" +
|
||||
"JlRO9KNaAC9pIW+5ejqT7KL24Y7HY9gvEjCZLrDyj/gnLSR4KIT3Ab+NRHndO9JV\n" +
|
||||
"8848slshfe/9M0qxo//GyJu5D3xBNZf52zoFYAUVr1kXkqMQrRYc5AdTr6h2olYq\n" +
|
||||
"ktP5KOB4z14fSKtcGd3hZ0O6dY31gqxDkkQbAgMBAAGjWjBYMAkGA1UdEwQCMAAw\n" +
|
||||
"CwYDVR0PBAQDAgXgMB0GA1UdDgQWBBTNu8iFqpG9/R2+zWd8/7PpTKgi5jAfBgNV\n" +
|
||||
"HSMEGDAWgBT6uVG/TOfZhpgz+efLHvEzSfeoFDANBgkqhkiG9w0BAQQFAAOBgQBv\n" +
|
||||
"p7JjCDOrMBNun46xs4Gz7Y4ygM5VHaFP0oO7369twvRSu0pCuIdZd5OIMPFeRqQw\n" +
|
||||
"PA68ZdhYVR0pG5W7isV+jB+Dfge/IOgOA85sZ/6FlP3PBRW+YMQKKdRr5So3ook9\n" +
|
||||
"PimQ7rbxRAofPECv20IUKFBbOUkU+gFcn+WbTKYxBw==\n" +
|
||||
"-----END CERTIFICATE-----";
|
||||
|
||||
static String crlStr =
|
||||
"-----BEGIN X509 CRL-----\n" +
|
||||
"MIIBRTCBrwIBATANBgkqhkiG9w0BAQQFADBJMQswCQYDVQQGEwJVUzETMBEGA1UE\n" +
|
||||
"CBMKU29tZS1TdGF0ZTESMBAGA1UEBxMJU29tZS1DaXR5MREwDwYDVQQKEwhTb21l\n" +
|
||||
"LU9yZxcNMDkwMzE2MTYyNzE0WhcNMjgwNTE1MTYyNzE0WjAiMCACARkXDTA5MDMx\n" +
|
||||
"NjE2MjIwOFowDDAKBgNVHRUEAwoBBKAOMAwwCgYDVR0UBAMCAQIwDQYJKoZIhvcN\n" +
|
||||
"AQEEBQADgYEAMixJI9vBwYpOGosn46+T/MTEtlm2S5pIVT/xPDrHkCPfw8l4Zrgp\n" +
|
||||
"dGPuUkglWdrGdxY9MNRUj2YFNfdZi6zZ7JF6XbkDHYOAKYgPDJRjS/0VcBntn5RJ\n" +
|
||||
"sQfZsBqc9fFSP8gknRRn3LT41kr9xNRxTT1t3YYjv7J3zkMYyInqeUA=\n" +
|
||||
"-----END X509 CRL-----";
|
||||
|
||||
|
||||
private static final PEMDecoder PEM_DECODER = PEMDecoder.of();
|
||||
|
||||
private static CertPath generateCertificatePath()
|
||||
throws CertificateException, IOException {
|
||||
// generate certificate from cert strings
|
||||
CertificateFactory cf = CertificateFactory.getInstance("X.509");
|
||||
|
||||
ByteArrayInputStream is =
|
||||
new ByteArrayInputStream(targetCertStr.getBytes());
|
||||
|
||||
// generate certification path
|
||||
List<Certificate> list = Collections.singletonList(PEM_DECODER.decode
|
||||
(is, X509Certificate.class));
|
||||
|
||||
return cf.generateCertPath(list);
|
||||
}
|
||||
|
||||
private static Set<TrustAnchor> generateTrustAnchors() {
|
||||
// generate certificate from cert string
|
||||
X509Certificate trustedCert = PEM_DECODER.decode(trusedCertStr, X509Certificate.class);
|
||||
|
||||
// generate a trust anchor
|
||||
TrustAnchor anchor = new TrustAnchor(trustedCert, null);
|
||||
|
||||
return Collections.singleton(anchor);
|
||||
}
|
||||
|
||||
private static CertStore generateCertificateStore() throws Exception {
|
||||
// generate CRL from CRL string
|
||||
CertificateFactory cf = CertificateFactory.getInstance("X.509");
|
||||
|
||||
ByteArrayInputStream is =
|
||||
new ByteArrayInputStream(crlStr.getBytes());
|
||||
|
||||
// generate a cert store
|
||||
Collection<DEREncodable> crls = new HashSet<>();
|
||||
|
||||
crls.add(PEM_DECODER.decode(crlStr, X509CRL.class));
|
||||
|
||||
return CertStore.getInstance("Collection",
|
||||
new CollectionCertStoreParameters(crls));
|
||||
}
|
||||
|
||||
public static void main(String args[]) throws Exception {
|
||||
// MD5 is used in this test case, don't disable MD5 algorithm.
|
||||
Security.setProperty(
|
||||
"jdk.certpath.disabledAlgorithms", "MD2, RSA keySize < 1024");
|
||||
|
||||
CertPath path = generateCertificatePath();
|
||||
Set<TrustAnchor> anchors = generateTrustAnchors();
|
||||
CertStore crls = generateCertificateStore();
|
||||
|
||||
PKIXParameters params = new PKIXParameters(anchors);
|
||||
|
||||
// add the CRL store
|
||||
params.addCertStore(crls);
|
||||
|
||||
// Activate certificate revocation checking
|
||||
params.setRevocationEnabled(true);
|
||||
|
||||
// Activate OCSP
|
||||
Security.setProperty("ocsp.enable", "true");
|
||||
System.setProperty("com.sun.security.enableCRLDP", "true");
|
||||
|
||||
// Ensure that the ocsp.responderURL property is not set.
|
||||
if (Security.getProperty("ocsp.responderURL") != null) {
|
||||
throw new
|
||||
Exception("The ocsp.responderURL property must not be set");
|
||||
}
|
||||
|
||||
CertPathValidator validator = CertPathValidator.getInstance("PKIX");
|
||||
|
||||
try {
|
||||
validator.validate(path, params);
|
||||
} catch (CertPathValidatorException cpve) {
|
||||
if (cpve.getReason() != BasicReason.REVOKED) {
|
||||
throw new Exception(
|
||||
"unexpected exception, should be a REVOKED CPVE", cpve);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,267 @@
|
|||
/*
|
||||
* Copyright (c) 2020, 2025, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @bug 8179503 8328638
|
||||
* @summary Java should support GET OCSP calls
|
||||
* @library /javax/net/ssl/templates /test/lib
|
||||
* @modules java.base/sun.security.util
|
||||
* java.base/sun.security.provider.certpath
|
||||
* java.base/sun.security.x509
|
||||
* @run main/othervm GetAndPostTests
|
||||
* @run main/othervm -Dcom.sun.security.ocsp.useget=false GetAndPostTests
|
||||
* @run main/othervm -Dcom.sun.security.ocsp.useget=foo GetAndPostTests
|
||||
*/
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.net.URI;
|
||||
import java.security.GeneralSecurityException;
|
||||
import java.security.KeyFactory;
|
||||
import java.security.KeyStore;
|
||||
import java.security.PrivateKey;
|
||||
import java.security.SecureRandom;
|
||||
import java.security.cert.CertPath;
|
||||
import java.security.cert.CertPathValidator;
|
||||
import java.security.cert.Certificate;
|
||||
import java.security.cert.CertificateException;
|
||||
import java.security.cert.CertificateFactory;
|
||||
import java.security.cert.Extension;
|
||||
import java.security.cert.PKIXCertPathChecker;
|
||||
import java.security.cert.PKIXParameters;
|
||||
import java.security.cert.PKIXRevocationChecker;
|
||||
import java.security.cert.TrustAnchor;
|
||||
import java.security.cert.X509Certificate;
|
||||
import java.security.spec.PKCS8EncodedKeySpec;
|
||||
import java.util.Base64;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import jdk.test.lib.security.SimpleOCSPServer;
|
||||
import sun.security.util.DerOutputStream;
|
||||
import sun.security.util.DerValue;
|
||||
import sun.security.util.ObjectIdentifier;
|
||||
|
||||
public class GetAndPostTests {
|
||||
private static final String PASS = "passphrase";
|
||||
private static final int SERVER_WAIT_SECS = 60;
|
||||
private static CertificateFactory certFac;
|
||||
|
||||
public static void main(String args[]) throws Exception {
|
||||
SimpleOCSPServer ocspResponder = null;
|
||||
|
||||
try {
|
||||
certFac = CertificateFactory.getInstance("X.509");
|
||||
|
||||
// Read in the certificates and keys needed for this test and
|
||||
// create the keystore for the SimpleOCSPServer. For the purposes
|
||||
// of this test, the CA certificate will also be the OCSP responder
|
||||
// signing certificate.
|
||||
SSLSocketTemplate.Cert certAuth =
|
||||
SSLSocketTemplate.Cert.CA_ECDSA_SECP256R1;
|
||||
X509Certificate caCert = pem2Cert(certAuth.certStr);
|
||||
PrivateKey caKey = pem2Key(certAuth.privKeyStr, certAuth.keyAlgo);
|
||||
X509Certificate endEntCert =
|
||||
pem2Cert(SSLSocketTemplate.Cert.EE_ECDSA_SECP256R1.certStr);
|
||||
|
||||
KeyStore.Builder keyStoreBuilder =
|
||||
KeyStore.Builder.newInstance("PKCS12", null,
|
||||
new KeyStore.PasswordProtection(PASS.toCharArray()));
|
||||
KeyStore ocspStore = keyStoreBuilder.getKeyStore();
|
||||
Certificate[] ocspChain = {caCert};
|
||||
ocspStore.setKeyEntry("ocspsigner", caKey, PASS.toCharArray(),
|
||||
ocspChain);
|
||||
|
||||
// Create the certificate path we'll use for cert path validation.
|
||||
CertPath path = certFac.generateCertPath(List.of(endEntCert));
|
||||
|
||||
// Next, create and start the OCSP responder. Obtain the socket
|
||||
// address so we can set that in the PKIXRevocationChecker since
|
||||
// these certificates do not have AIA extensions on them.
|
||||
ocspResponder = new SimpleOCSPServer(ocspStore, PASS,
|
||||
"ocspsigner", null);
|
||||
ocspResponder.setSignatureAlgorithm("SHA256WithECDSA");
|
||||
ocspResponder.enableLog(true);
|
||||
ocspResponder.setNextUpdateInterval(3600);
|
||||
ocspResponder.updateStatusDb(Map.of(
|
||||
endEntCert.getSerialNumber(),
|
||||
new SimpleOCSPServer.CertStatusInfo(
|
||||
SimpleOCSPServer.CertStatus.CERT_STATUS_GOOD)));
|
||||
|
||||
startOcspServer(ocspResponder);
|
||||
|
||||
int ocspPort = ocspResponder.getPort();
|
||||
URI ocspURI = new URI("http://localhost:" + ocspPort);
|
||||
System.out.println("Configured CPV to connect to " + ocspURI);
|
||||
|
||||
// Create the PKIXParameters needed for path validation and
|
||||
// configure any necessary OCSP parameters to control the OCSP
|
||||
// request size.
|
||||
Set<TrustAnchor> anchors = Set.of(new TrustAnchor(caCert, null));
|
||||
|
||||
CertPathValidator validator = CertPathValidator.getInstance("PKIX");
|
||||
PKIXRevocationChecker revChkr =
|
||||
(PKIXRevocationChecker)validator.getRevocationChecker();
|
||||
revChkr.setOcspResponder(ocspURI);
|
||||
revChkr.setOptions(Set.of(
|
||||
PKIXRevocationChecker.Option.ONLY_END_ENTITY,
|
||||
PKIXRevocationChecker.Option.NO_FALLBACK));
|
||||
|
||||
PKIXParameters params = new PKIXParameters(anchors);
|
||||
params.setRevocationEnabled(true);
|
||||
params.setDate(new Date(1590926400000L)); // 05/31/2020 @ 12:00:00Z
|
||||
params.addCertPathChecker(revChkr);
|
||||
|
||||
System.out.println("Test 1: Request < 255 bytes, HTTP GET");
|
||||
validator.validate(path, params);
|
||||
|
||||
System.out.println("Test 2: Request > 255 bytes, HTTP POST");
|
||||
// Modify the PKIXRevocationChecker to include a bogus non-critical
|
||||
// request extension that makes the request large enough to be
|
||||
// issued as an HTTP POST.
|
||||
List<PKIXCertPathChecker> chkrList = params.getCertPathCheckers();
|
||||
for (PKIXCertPathChecker chkr : chkrList) {
|
||||
if (chkr instanceof PKIXRevocationChecker) {
|
||||
((PKIXRevocationChecker)chkr).setOcspExtensions(
|
||||
List.of(new BogusExtension("1.2.3.4.5.6.7.8.9",
|
||||
false, 256)));
|
||||
}
|
||||
}
|
||||
params.setCertPathCheckers(chkrList);
|
||||
validator.validate(path, params);
|
||||
|
||||
} finally {
|
||||
if (ocspResponder != null) {
|
||||
ocspResponder.stop();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void startOcspServer(SimpleOCSPServer ocspResponder) throws InterruptedException, IOException {
|
||||
ocspResponder.start();
|
||||
if (!ocspResponder.awaitServerReady(SERVER_WAIT_SECS, TimeUnit.SECONDS)) {
|
||||
throw new RuntimeException("Server not ready after " + SERVER_WAIT_SECS
|
||||
+ " seconds.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an X509Certificate object from its PEM encoding
|
||||
*
|
||||
* @param pemCert the base64 encoded certificate
|
||||
*
|
||||
* @return the corresponding X509Certificate object from the PEM encoding.
|
||||
*
|
||||
* @throws IOException if any InputStream or Base64 decoding failures occur.
|
||||
* @throws CertificateException if any certificate parsing errors occur.
|
||||
*/
|
||||
private static X509Certificate pem2Cert(String pemCert)
|
||||
throws IOException, CertificateException {
|
||||
return (X509Certificate)certFac.generateCertificate(
|
||||
new ByteArrayInputStream(pemCert.getBytes()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a private key from its PEM-encoded PKCS#8 representation.
|
||||
*
|
||||
* @param pemKey the private key in PEM-encoded PKCS#8 unencrypted format
|
||||
* @param algorithm the private key algorithm
|
||||
*
|
||||
* @return the PrivateKey extracted from the PKCS#8 encoding.
|
||||
*
|
||||
* @throws GeneralSecurityException if any errors take place during
|
||||
* decoding or parsing.
|
||||
*/
|
||||
private static PrivateKey pem2Key(String pemKey, String algorithm)
|
||||
throws GeneralSecurityException {
|
||||
byte[] p8Der = Base64.getMimeDecoder().decode(pemKey);
|
||||
PKCS8EncodedKeySpec spec = new PKCS8EncodedKeySpec(p8Der, algorithm);
|
||||
KeyFactory kf = KeyFactory.getInstance(algorithm);
|
||||
return kf.generatePrivate(spec);
|
||||
}
|
||||
|
||||
/**
|
||||
* The BogusOcspExtension is an extension with random data in the
|
||||
* extension value field. It is used in this test to expand the size
|
||||
* of the OCSP request so it crosses the boundary that forces an HTTP
|
||||
* POST operation instead of a GET.
|
||||
*/
|
||||
private static class BogusExtension implements Extension {
|
||||
private final ObjectIdentifier oid;
|
||||
private final boolean critical;
|
||||
private final byte[] data;
|
||||
|
||||
public BogusExtension(String oidStr, boolean isCrit, int size)
|
||||
throws IOException {
|
||||
// For this test we don't need anything larger than 10K
|
||||
if (size > 0 && size <= 10240) {
|
||||
data = new byte[size];
|
||||
} else {
|
||||
throw new IllegalArgumentException(
|
||||
"Size must be 0 < X <= 10240");
|
||||
}
|
||||
oid = ObjectIdentifier.of(oidStr);
|
||||
SecureRandom sr = new SecureRandom();
|
||||
sr.nextBytes(data);
|
||||
critical = isCrit;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getId() {
|
||||
return oid.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCritical() {
|
||||
return critical;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] getValue() {
|
||||
return data.clone();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void encode(OutputStream out) throws IOException {
|
||||
Objects.requireNonNull(out, "Non-null OutputStream required");
|
||||
|
||||
DerOutputStream dos1 = new DerOutputStream();
|
||||
DerOutputStream dos2 = new DerOutputStream();
|
||||
|
||||
dos1.putOID(oid);
|
||||
if (critical) {
|
||||
dos1.putBoolean(critical);
|
||||
}
|
||||
dos1.putOctetString(data);
|
||||
|
||||
dos2.write(DerValue.tag_Sequence, dos1);
|
||||
out.write(dos2.toByteArray());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,300 @@
|
|||
/*
|
||||
* Copyright (c) 2023, 2025, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
//
|
||||
// Security properties, once set, cannot revert to unset. To avoid
|
||||
// conflicts with tests running in the same VM isolate this test by
|
||||
// running it in otherVM mode.
|
||||
//
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @bug 8179502
|
||||
* @summary Enhance OCSP, CRL and Certificate Fetch Timeouts
|
||||
* @modules java.base/sun.security.x509
|
||||
* java.base/sun.security.provider.certpath
|
||||
* java.base/sun.security.util
|
||||
* @library /test/lib
|
||||
* @run main/othervm -Djava.security.debug=certpath OCSPTimeout 1000 true
|
||||
* @run main/othervm -Djava.security.debug=certpath
|
||||
* -Dcom.sun.security.ocsp.readtimeout=5 OCSPTimeout 1000 true
|
||||
* @run main/othervm -Djava.security.debug=certpath
|
||||
* -Dcom.sun.security.ocsp.readtimeout=1 OCSPTimeout 5000 false
|
||||
* @run main/othervm -Djava.security.debug=certpath
|
||||
* -Dcom.sun.security.ocsp.readtimeout=1s OCSPTimeout 5000 false
|
||||
* @run main/othervm -Djava.security.debug=certpath
|
||||
* -Dcom.sun.security.ocsp.readtimeout=1500ms OCSPTimeout 5000 false
|
||||
* @run main/othervm -Djava.security.debug=certpath
|
||||
* -Dcom.sun.security.ocsp.readtimeout=4500ms OCSPTimeout 1000 true
|
||||
*/
|
||||
|
||||
import java.io.*;
|
||||
import java.math.BigInteger;
|
||||
import java.net.*;
|
||||
import java.security.*;
|
||||
import java.security.cert.Certificate;
|
||||
import java.security.spec.ECGenParameterSpec;
|
||||
import java.util.*;
|
||||
import java.security.cert.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import jdk.test.lib.security.SimpleOCSPServer;
|
||||
import jdk.test.lib.security.CertificateBuilder;
|
||||
|
||||
import static java.security.cert.PKIXRevocationChecker.Option.*;
|
||||
|
||||
public class OCSPTimeout {
|
||||
|
||||
static String passwd = "passphrase";
|
||||
static String ROOT_ALIAS = "root";
|
||||
static String EE_ALIAS = "endentity";
|
||||
|
||||
// Enable debugging for additional output
|
||||
static final boolean debug = true;
|
||||
|
||||
// PKI components we will need for this test
|
||||
static X509Certificate rootCert; // The root CA certificate
|
||||
static X509Certificate eeCert; // The end entity certificate
|
||||
static KeyStore rootKeystore; // Root CA Keystore
|
||||
static KeyStore eeKeystore; // End Entity Keystore
|
||||
static KeyStore trustStore; // SSL Client trust store
|
||||
static SimpleOCSPServer rootOcsp; // Root CA OCSP Responder
|
||||
static int rootOcspPort; // Port number for root OCSP
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
int ocspTimeout = 15000;
|
||||
boolean expected;
|
||||
|
||||
createPKI();
|
||||
|
||||
try {
|
||||
if (args[0] != null) {
|
||||
ocspTimeout = Integer.parseInt(args[0]);
|
||||
}
|
||||
rootOcsp.setDelay(ocspTimeout);
|
||||
|
||||
expected = (args[1] != null && Boolean.parseBoolean(args[1]));
|
||||
log("Test case expects to " + (expected ? "pass" : "fail"));
|
||||
|
||||
// validate chain
|
||||
CertPathValidator cpv = CertPathValidator.getInstance("PKIX");
|
||||
PKIXRevocationChecker prc =
|
||||
(PKIXRevocationChecker) cpv.getRevocationChecker();
|
||||
prc.setOptions(EnumSet.of(NO_FALLBACK, SOFT_FAIL));
|
||||
PKIXParameters params =
|
||||
new PKIXParameters(Set.of(new TrustAnchor(rootCert, null)));
|
||||
params.addCertPathChecker(prc);
|
||||
CertificateFactory cf = CertificateFactory.getInstance("X.509");
|
||||
CertPath cp = cf.generateCertPath(List.of(eeCert));
|
||||
cpv.validate(cp, params);
|
||||
|
||||
// unwrap soft fail exceptions and check for SocketTimeoutException
|
||||
List<CertPathValidatorException> softExc = prc.getSoftFailExceptions();
|
||||
if (expected) {
|
||||
if (!softExc.isEmpty()) {
|
||||
log("Expected to pass, found " + softExc.size() +
|
||||
" soft fail exceptions");
|
||||
for (CertPathValidatorException cpve : softExc) {
|
||||
log("Exception: " + cpve);
|
||||
}
|
||||
throw new RuntimeException("Expected to pass, found " +
|
||||
softExc.size() + " soft fail exceptions");
|
||||
}
|
||||
} else {
|
||||
// If we expect to fail the validation then there should be a
|
||||
// SocketTimeoutException
|
||||
boolean found = false;
|
||||
for (CertPathValidatorException softFail : softExc) {
|
||||
log("CPVE: " + softFail);
|
||||
Throwable cause = softFail.getCause();
|
||||
log("Cause: " + cause);
|
||||
while (cause != null) {
|
||||
if (cause instanceof SocketTimeoutException) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
cause = cause.getCause();
|
||||
}
|
||||
if (found) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!found) {
|
||||
throw new RuntimeException("SocketTimeoutException not thrown");
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
rootOcsp.stop();
|
||||
rootOcsp.shutdownNow();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the PKI components necessary for this test, including
|
||||
* Root CA, Intermediate CA and SSL server certificates, the keystores
|
||||
* for each entity, a client trust store, and starts the OCSP responders.
|
||||
*/
|
||||
private static void createPKI() throws Exception {
|
||||
CertificateBuilder cbld = new CertificateBuilder();
|
||||
KeyPairGenerator keyGen = KeyPairGenerator.getInstance("EC");
|
||||
keyGen.initialize(new ECGenParameterSpec("secp256r1"));
|
||||
KeyStore.Builder keyStoreBuilder =
|
||||
KeyStore.Builder.newInstance("PKCS12", null,
|
||||
new KeyStore.PasswordProtection(passwd.toCharArray()));
|
||||
|
||||
// Generate Root and EE keys
|
||||
KeyPair rootCaKP = keyGen.genKeyPair();
|
||||
log("Generated Root CA KeyPair");
|
||||
KeyPair eeKP = keyGen.genKeyPair();
|
||||
log("Generated End Entity KeyPair");
|
||||
|
||||
// Set up the Root CA Cert
|
||||
cbld.setSubjectName("CN=Root CA Cert, O=SomeCompany");
|
||||
cbld.setPublicKey(rootCaKP.getPublic());
|
||||
cbld.setSerialNumber(new BigInteger("1"));
|
||||
// Make a 3 year validity starting from 60 days ago
|
||||
long start = System.currentTimeMillis() - TimeUnit.DAYS.toMillis(60);
|
||||
long end = start + TimeUnit.DAYS.toMillis(1085);
|
||||
cbld.setValidity(new Date(start), new Date(end));
|
||||
addCommonExts(cbld, rootCaKP.getPublic(), rootCaKP.getPublic());
|
||||
addCommonCAExts(cbld);
|
||||
// Make our Root CA Cert!
|
||||
rootCert = cbld.build(null, rootCaKP.getPrivate(),
|
||||
"SHA256withECDSA");
|
||||
log("Root CA Created:\n%s", certInfo(rootCert));
|
||||
|
||||
// Now build a keystore and add the keys and cert
|
||||
rootKeystore = keyStoreBuilder.getKeyStore();
|
||||
Certificate[] rootChain = {rootCert};
|
||||
rootKeystore.setKeyEntry(ROOT_ALIAS, rootCaKP.getPrivate(),
|
||||
passwd.toCharArray(), rootChain);
|
||||
|
||||
// Now fire up the OCSP responder
|
||||
rootOcsp = new SimpleOCSPServer(rootKeystore, passwd, ROOT_ALIAS, null);
|
||||
rootOcsp.enableLog(debug);
|
||||
rootOcsp.setNextUpdateInterval(3600);
|
||||
rootOcsp.start();
|
||||
|
||||
// Wait 60 seconds for server ready
|
||||
boolean readyStatus = rootOcsp.awaitServerReady(60, TimeUnit.SECONDS);
|
||||
if (!readyStatus) {
|
||||
throw new RuntimeException("Server not ready");
|
||||
}
|
||||
|
||||
rootOcspPort = rootOcsp.getPort();
|
||||
String rootRespURI = "http://localhost:" + rootOcspPort;
|
||||
log("Root OCSP Responder URI is %s", rootRespURI);
|
||||
|
||||
// Now that we have the root keystore and OCSP responder we can
|
||||
// create our end entity certificate
|
||||
cbld.reset();
|
||||
cbld.setSubjectName("CN=SSLCertificate, O=SomeCompany");
|
||||
cbld.setPublicKey(eeKP.getPublic());
|
||||
cbld.setSerialNumber(new BigInteger("4096"));
|
||||
// Make a 1 year validity starting from 7 days ago
|
||||
start = System.currentTimeMillis() - TimeUnit.DAYS.toMillis(7);
|
||||
end = start + TimeUnit.DAYS.toMillis(365);
|
||||
cbld.setValidity(new Date(start), new Date(end));
|
||||
|
||||
// Add extensions
|
||||
addCommonExts(cbld, eeKP.getPublic(), rootCaKP.getPublic());
|
||||
boolean[] kuBits = {true, false, false, false, false, false,
|
||||
false, false, false};
|
||||
cbld.addKeyUsageExt(kuBits);
|
||||
List<String> ekuOids = new ArrayList<>();
|
||||
ekuOids.add("1.3.6.1.5.5.7.3.1");
|
||||
ekuOids.add("1.3.6.1.5.5.7.3.2");
|
||||
cbld.addExtendedKeyUsageExt(ekuOids);
|
||||
cbld.addSubjectAltNameDNSExt(Collections.singletonList("localhost"));
|
||||
cbld.addAIAExt(Collections.singletonList(rootRespURI));
|
||||
// Make our End Entity Cert!
|
||||
eeCert = cbld.build(rootCert, rootCaKP.getPrivate(),
|
||||
"SHA256withECDSA");
|
||||
log("SSL Certificate Created:\n%s", certInfo(eeCert));
|
||||
|
||||
// Provide end entity cert revocation info to the Root CA
|
||||
// OCSP responder.
|
||||
Map<BigInteger, SimpleOCSPServer.CertStatusInfo> revInfo =
|
||||
new HashMap<>();
|
||||
revInfo.put(eeCert.getSerialNumber(),
|
||||
new SimpleOCSPServer.CertStatusInfo(
|
||||
SimpleOCSPServer.CertStatus.CERT_STATUS_GOOD));
|
||||
rootOcsp.updateStatusDb(revInfo);
|
||||
|
||||
// Now build a keystore and add the keys, chain and root cert as a TA
|
||||
eeKeystore = keyStoreBuilder.getKeyStore();
|
||||
Certificate[] eeChain = {eeCert, rootCert};
|
||||
eeKeystore.setKeyEntry(EE_ALIAS, eeKP.getPrivate(),
|
||||
passwd.toCharArray(), eeChain);
|
||||
eeKeystore.setCertificateEntry(ROOT_ALIAS, rootCert);
|
||||
|
||||
// And finally a Trust Store for the client
|
||||
trustStore = keyStoreBuilder.getKeyStore();
|
||||
trustStore.setCertificateEntry(ROOT_ALIAS, rootCert);
|
||||
}
|
||||
|
||||
private static void addCommonExts(CertificateBuilder cbld,
|
||||
PublicKey subjKey, PublicKey authKey) throws IOException {
|
||||
cbld.addSubjectKeyIdExt(subjKey);
|
||||
cbld.addAuthorityKeyIdExt(authKey);
|
||||
}
|
||||
|
||||
private static void addCommonCAExts(CertificateBuilder cbld)
|
||||
throws IOException {
|
||||
cbld.addBasicConstraintsExt(true, true, -1);
|
||||
// Set key usage bits for digitalSignature, keyCertSign and cRLSign
|
||||
boolean[] kuBitSettings = {true, false, false, false, false, true,
|
||||
true, false, false};
|
||||
cbld.addKeyUsageExt(kuBitSettings);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper routine that dumps only a few cert fields rather than
|
||||
* the whole toString() output.
|
||||
*
|
||||
* @param cert an X509Certificate to be displayed
|
||||
*
|
||||
* @return the String output of the issuer, subject and
|
||||
* serial number
|
||||
*/
|
||||
private static String certInfo(X509Certificate cert) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("Issuer: ").append(cert.getIssuerX500Principal()).
|
||||
append("\n");
|
||||
sb.append("Subject: ").append(cert.getSubjectX500Principal()).
|
||||
append("\n");
|
||||
sb.append("Serial: ").append(cert.getSerialNumber()).append("\n");
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Log a message on stdout
|
||||
*
|
||||
* @param format the format string for the log entry
|
||||
* @param args zero or more arguments corresponding to the format string
|
||||
*/
|
||||
private static void log(String format, Object ... args) {
|
||||
System.out.format(format + "\n", args);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
-----BEGIN CERTIFICATE-----
|
||||
MIICZTCCAc6gAwIBAgIBADANBgkqhkiG9w0BAQQFADAtMQswCQYDVQQGEwJVUzEM
|
||||
MAoGA1UEChMDU3VuMRAwDgYDVQQDEwdSb290IENBMB4XDTA1MTEyNDIzMDU0N1oX
|
||||
DTE1MTEyMjIzMDU0N1owLTELMAkGA1UEBhMCVVMxDDAKBgNVBAoTA1N1bjEQMA4G
|
||||
A1UEAxMHUm9vdCBDQTCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEA1BHB3n1Q
|
||||
G/U/r+MvsKAzKUeDSSTAFzC6+a393zzrGSU3/OIlQjWAWVsoPQOiHilgfhhaox+C
|
||||
DWdV+qwWEPYA3QMyeiZDOQu/Xs1LoKrbfi+zNFqnZyXkqSjzJMP0G1LEI13sUTXz
|
||||
0AHoIdpZWqECXfP74L5reBrQ2Cv1k/zuUaECAwEAAaOBlDCBkTAdBgNVHQ4EFgQU
|
||||
HUnYKFCXxAMhXFyv/0SKj903FSQwVQYDVR0jBE4wTIAUHUnYKFCXxAMhXFyv/0SK
|
||||
j903FSShMaQvMC0xCzAJBgNVBAYTAlVTMQwwCgYDVQQKEwNTdW4xEDAOBgNVBAMT
|
||||
B1Jvb3QgQ0GCAQAwDAYDVR0TBAUwAwEB/zALBgNVHQ8EBAMCAQYwDQYJKoZIhvcN
|
||||
AQEEBQADgYEAO9yV6aPi3yj96Qq4laZ4Sq0FDmHWXUX0iF0ygSUHu/p8LK2iDKd0
|
||||
BoSqyrpz+SLLoWRn4tbbFaqJpsYGI7wEGdAjJJgKtMZOEH1sSuTnwsjaIxaLF9A4
|
||||
44Ki2Y5vbDcY8us2/92qiawGnKEFgDZn2M7OBYleV3PZJmPUQVX5Ffk=
|
||||
-----END CERTIFICATE-----
|
||||
|
|
@ -0,0 +1,229 @@
|
|||
/*
|
||||
* Copyright (c) 2024, 2025, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.math.BigInteger;
|
||||
import java.security.KeyPair;
|
||||
import java.security.KeyPairGenerator;
|
||||
import java.security.cert.CertificateFactory;
|
||||
import java.security.cert.CertPath;
|
||||
import java.security.cert.CertPathValidator;
|
||||
import java.security.cert.CertPathValidatorException;
|
||||
import java.security.cert.CertPathValidatorException.BasicReason;
|
||||
import java.security.cert.PKIXParameters;
|
||||
import java.security.cert.TrustAnchor;
|
||||
import java.security.cert.X509Certificate;
|
||||
import java.security.cert.X509CRL;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import sun.security.x509.AuthorityKeyIdentifierExtension;
|
||||
import sun.security.x509.CRLDistributionPointsExtension;
|
||||
import sun.security.x509.CRLExtensions;
|
||||
import sun.security.x509.CRLNumberExtension;
|
||||
import sun.security.x509.DistributionPoint;
|
||||
import sun.security.x509.Extension;
|
||||
import sun.security.x509.GeneralName;
|
||||
import sun.security.x509.GeneralNames;
|
||||
import sun.security.x509.KeyIdentifier;
|
||||
import sun.security.x509.URIName;
|
||||
import sun.security.x509.X500Name;
|
||||
import sun.security.x509.X509CRLEntryImpl;
|
||||
import sun.security.x509.X509CRLImpl;
|
||||
import static sun.security.x509.X509CRLImpl.TBSCertList;
|
||||
import jdk.test.lib.security.CertificateBuilder;
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 8200566
|
||||
* @summary Check that CRL validation continues to check other CRLs in
|
||||
* CRLDP extension after CRL fetching errors and exhibits same
|
||||
* behavior (fails because cert is revoked) whether CRL cache is
|
||||
* fresh or stale.
|
||||
* @modules java.base/sun.security.x509
|
||||
* java.base/sun.security.util
|
||||
* @library /test/lib
|
||||
* @run main/othervm -Dcom.sun.security.enableCRLDP=true CheckAllCRLs
|
||||
*/
|
||||
public class CheckAllCRLs {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
|
||||
CertificateBuilder cb = new CertificateBuilder();
|
||||
|
||||
// Create CA cert
|
||||
KeyPairGenerator kpg = KeyPairGenerator.getInstance("RSA");
|
||||
KeyPair rootKeyPair = kpg.genKeyPair();
|
||||
X509Certificate rootCert = createCert(cb, "CN=Root CA",
|
||||
rootKeyPair, rootKeyPair, null, "SHA384withRSA", true, false);
|
||||
|
||||
// Create EE cert. This EE cert will contain a CRL Distribution
|
||||
// Points extension with two DistributionPoints - one will be a HTTP
|
||||
// URL to a non-existant HTTP server, and the other will be a File
|
||||
// URL to a file containing the CRL.
|
||||
KeyPair eeKeyPair = kpg.genKeyPair();
|
||||
X509Certificate eeCert1 = createCert(cb, "CN=End Entity",
|
||||
rootKeyPair, eeKeyPair, rootCert, "SHA384withRSA", false, true);
|
||||
|
||||
// Create another EE cert. This EE cert is similar in that it contains
|
||||
// a CRL Distribution Points extension but with one DistributionPoint
|
||||
// containing 2 GeneralName URLs as above.
|
||||
X509Certificate eeCert2 = createCert(cb, "CN=End Entity",
|
||||
rootKeyPair, eeKeyPair, rootCert, "SHA384withRSA", false, false);
|
||||
|
||||
// Create a CRL with no revoked certificates and store it in a file
|
||||
X509CRL crl = createCRL(new X500Name("CN=Root CA"), rootKeyPair,
|
||||
"SHA384withRSA");
|
||||
Files.write(Path.of("root.crl"), crl.getEncoded());
|
||||
|
||||
// Validate path containing eeCert1
|
||||
System.out.println("Validating cert with CRLDP containing one "
|
||||
+ "DistributionPoint with 2 entries, the first non-existent");
|
||||
validatePath(eeCert1, rootCert);
|
||||
|
||||
// Validate path containing eeCert2
|
||||
System.out.println("Validating cert with CRLDP containing two "
|
||||
+ "DistributionPoints with 1 entry each, the first non-existent");
|
||||
validatePath(eeCert2, rootCert);
|
||||
}
|
||||
|
||||
private static X509Certificate createCert(CertificateBuilder cb,
|
||||
String subjectDN, KeyPair issuerKeyPair, KeyPair subjectKeyPair,
|
||||
X509Certificate issuerCert, String sigAlg, boolean isCA,
|
||||
boolean twoDPs) throws Exception {
|
||||
cb.setSubjectName(subjectDN);
|
||||
cb.setPublicKey(subjectKeyPair.getPublic());
|
||||
cb.setSerialNumber(new BigInteger("1"));
|
||||
|
||||
if (isCA) {
|
||||
// Make a 3 year validity starting from 60 days ago
|
||||
long start = System.currentTimeMillis() - TimeUnit.DAYS.toMillis(60);
|
||||
long end = start + TimeUnit.DAYS.toMillis(1085);
|
||||
cb.setValidity(new Date(start), new Date(end));
|
||||
cb.addBasicConstraintsExt(true, true, -1);
|
||||
cb.addKeyUsageExt(new boolean[]
|
||||
{false, false, false, false, false, true, true, false, false});
|
||||
} else {
|
||||
// Make a 1 year validity starting from 7 days ago
|
||||
long start = System.currentTimeMillis() - TimeUnit.DAYS.toMillis(7);
|
||||
long end = start + TimeUnit.DAYS.toMillis(365);
|
||||
cb.setValidity(new Date(start), new Date(end));
|
||||
cb.addAuthorityKeyIdExt(issuerKeyPair.getPublic());
|
||||
cb.addKeyUsageExt(new boolean[]
|
||||
{true, false, false, false, false, false, false, false, false});
|
||||
cb.addExtendedKeyUsageExt(List.of("1.3.6.1.5.5.7.3.1"));
|
||||
GeneralName first = new GeneralName(new URIName(
|
||||
"http://127.0.0.1:48180/crl/will/always/fail/root.crl"));
|
||||
GeneralName second = new GeneralName(new URIName("file:./root.crl"));
|
||||
if (twoDPs) {
|
||||
GeneralNames gn1 = new GeneralNames().add(first);
|
||||
DistributionPoint dp1 = new DistributionPoint(gn1, null, null);
|
||||
GeneralNames gn2 = new GeneralNames().add(second);
|
||||
DistributionPoint dp2 = new DistributionPoint(gn2, null, null);
|
||||
cb.addExtension(new CRLDistributionPointsExtension(List.of(dp1, dp2)));
|
||||
} else {
|
||||
GeneralNames gn = new GeneralNames().add(first).add(second);
|
||||
DistributionPoint dp = new DistributionPoint(gn, null, null);
|
||||
cb.addExtension(new CRLDistributionPointsExtension(List.of(dp)));
|
||||
}
|
||||
}
|
||||
cb.addSubjectKeyIdExt(subjectKeyPair.getPublic());
|
||||
|
||||
// return signed cert
|
||||
return cb.build(issuerCert, issuerKeyPair.getPrivate(), sigAlg);
|
||||
}
|
||||
|
||||
private static X509CRL createCRL(X500Name caIssuer, KeyPair caKeyPair,
|
||||
String sigAlg) throws Exception {
|
||||
|
||||
CRLExtensions crlExts = new CRLExtensions();
|
||||
|
||||
// add AuthorityKeyIdentifier extension
|
||||
KeyIdentifier kid = new KeyIdentifier(caKeyPair.getPublic());
|
||||
Extension ext = new AuthorityKeyIdentifierExtension(kid, null, null);
|
||||
crlExts.setExtension(ext.getId(),
|
||||
new AuthorityKeyIdentifierExtension(kid, null, null));
|
||||
|
||||
// add CRLNumber extension
|
||||
ext = new CRLNumberExtension(1);
|
||||
crlExts.setExtension(ext.getId(), ext);
|
||||
|
||||
// revoke cert
|
||||
X509CRLEntryImpl crlEntry =
|
||||
new X509CRLEntryImpl(new BigInteger("1"), new Date());
|
||||
|
||||
// Create a 1 year validity CRL starting from 7 days ago
|
||||
long start = System.currentTimeMillis() - TimeUnit.DAYS.toMillis(7);
|
||||
long end = start + TimeUnit.DAYS.toMillis(365);
|
||||
TBSCertList tcl = new TBSCertList(caIssuer, new Date(start),
|
||||
new Date(end), new X509CRLEntryImpl[]{ crlEntry }, crlExts);
|
||||
|
||||
// return signed CRL
|
||||
return X509CRLImpl.newSigned(tcl, caKeyPair.getPrivate(), sigAlg);
|
||||
}
|
||||
|
||||
private static void validatePath(X509Certificate eeCert,
|
||||
X509Certificate rootCert) throws Exception {
|
||||
|
||||
// Create certification path and set up PKIXParameters.
|
||||
CertificateFactory cf = CertificateFactory.getInstance("X.509");
|
||||
CertPath cp = cf.generateCertPath(List.of(eeCert));
|
||||
PKIXParameters pp =
|
||||
new PKIXParameters(Set.of(new TrustAnchor(rootCert, null)));
|
||||
pp.setRevocationEnabled(true);
|
||||
|
||||
CertPathValidator cpv = CertPathValidator.getInstance("PKIX");
|
||||
|
||||
// Validate path twice in succession, making sure we get consistent
|
||||
// results the second time when the CRL cache is fresh.
|
||||
System.out.println("First time validating path");
|
||||
validate(cpv, cp, pp);
|
||||
System.out.println("Second time validating path");
|
||||
validate(cpv, cp, pp);
|
||||
|
||||
// CRL lookup cache time is 30s. Sleep for 35 seconds to ensure
|
||||
// cache is stale, and validate one more time to ensure we get
|
||||
// consistent results.
|
||||
System.out.println("Waiting for CRL cache to be cleared");
|
||||
Thread.sleep(30500);
|
||||
|
||||
System.out.println("Third time validating path");
|
||||
validate(cpv, cp, pp);
|
||||
}
|
||||
|
||||
private static void validate(CertPathValidator cpv, CertPath cp,
|
||||
PKIXParameters pp) throws Exception {
|
||||
|
||||
try {
|
||||
cpv.validate(cp, pp);
|
||||
throw new Exception("Validation passed unexpectedly");
|
||||
} catch (CertPathValidatorException cpve) {
|
||||
if (cpve.getReason() != BasicReason.REVOKED) {
|
||||
throw new Exception("Validation failed with unexpected reason", cpve);
|
||||
}
|
||||
System.out.println("Validation failed as expected: " + cpve);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,190 @@
|
|||
/*
|
||||
* Copyright (c) 2009, 2025, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
//
|
||||
// Security properties, once set, cannot revert to unset. To avoid
|
||||
// conflicts with tests running in the same VM isolate this test by
|
||||
// running it in otherVM mode.
|
||||
//
|
||||
|
||||
/**
|
||||
* @test
|
||||
*
|
||||
* @bug 6720721
|
||||
* @summary CRL check with circular depency support needed
|
||||
* @run main/othervm CircularCRLOneLevel
|
||||
* @enablePreview
|
||||
* @author Xuelei Fan
|
||||
*/
|
||||
|
||||
import java.io.*;
|
||||
import java.net.SocketException;
|
||||
import java.security.DEREncodable;
|
||||
import java.security.PEMDecoder;
|
||||
import java.util.*;
|
||||
import java.security.Security;
|
||||
import java.security.cert.*;
|
||||
import java.security.cert.CertPathValidatorException.BasicReason;
|
||||
|
||||
public class CircularCRLOneLevel {
|
||||
|
||||
static String selfSignedCertStr =
|
||||
"-----BEGIN CERTIFICATE-----\n" +
|
||||
"MIICPjCCAaegAwIBAgIBADANBgkqhkiG9w0BAQQFADAfMQswCQYDVQQGEwJVUzEQ\n" +
|
||||
"MA4GA1UEChMHRXhhbXBsZTAeFw0wOTA0MjcwMjI0MzJaFw0zMDA0MDcwMjI0MzJa\n" +
|
||||
"MB8xCzAJBgNVBAYTAlVTMRAwDgYDVQQKEwdFeGFtcGxlMIGfMA0GCSqGSIb3DQEB\n" +
|
||||
"AQUAA4GNADCBiQKBgQC4OTag24sTxL2tXTNuvpmUEtdxrYAZoFsslFQ60T+WD9wQ\n" +
|
||||
"Jeiw87FSPsR2vxRuv0j8DNm2a4h7LNNIFcLurfNldbz5pvgZ7VqdbbUMPE9qP85n\n" +
|
||||
"jgDl4woyRTSUeRI4A7O0CO6NpES21dtbdhroWQrEkHxpnrDPxsxrz5gf2m3gqwID\n" +
|
||||
"AQABo4GJMIGGMB0GA1UdDgQWBBSCJd0hpl5PdAD9IZS+Hzng4lXLGzBHBgNVHSME\n" +
|
||||
"QDA+gBSCJd0hpl5PdAD9IZS+Hzng4lXLG6EjpCEwHzELMAkGA1UEBhMCVVMxEDAO\n" +
|
||||
"BgNVBAoTB0V4YW1wbGWCAQAwDwYDVR0TAQH/BAUwAwEB/zALBgNVHQ8EBAMCAgQw\n" +
|
||||
"DQYJKoZIhvcNAQEEBQADgYEAluy6HIjWcq009lTLmhp+Np6dxU78pInBK8RZkza0\n" +
|
||||
"484qGaxFGD3UGyZkI5uWmsH2XuMbuox5khfIq6781gmkPBHXBIEtJN8eLusOHEye\n" +
|
||||
"iE8h7WI+N3qa6Pj56WionMrioqC/3X+b06o147bbhx8U0vkYv/HyPaITOFfMXTdz\n" +
|
||||
"Vjw=\n" +
|
||||
"-----END CERTIFICATE-----";
|
||||
|
||||
static String subCaCertStr =
|
||||
"-----BEGIN CERTIFICATE-----\n" +
|
||||
"MIICUDCCAbmgAwIBAgIBAzANBgkqhkiG9w0BAQQFADAfMQswCQYDVQQGEwJVUzEQ\n" +
|
||||
"MA4GA1UEChMHRXhhbXBsZTAeFw0wOTA0MjcwMjI0MzRaFw0yOTAxMTIwMjI0MzRa\n" +
|
||||
"MDExCzAJBgNVBAYTAlVTMRAwDgYDVQQKEwdFeGFtcGxlMRAwDgYDVQQLEwdDbGFz\n" +
|
||||
"cy0xMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCiAJnAQW2ad3ZMKUhSJVZj\n" +
|
||||
"8pBqxTcHSTwAVguQkDglsN/OIwUpvR5Jgp3lpRWUEt6idEp0FZzORpvtjt3pr5MG\n" +
|
||||
"Eg2CDptekC5BSPS+fIAIKlncB3HwOiFFhH6b3wTydDCdEd2fvsi4QMOSVrIYMeA8\n" +
|
||||
"P/mCz6kRhfUQPE0CMmOUewIDAQABo4GJMIGGMB0GA1UdDgQWBBT0/nNP8WpyxmYr\n" +
|
||||
"IBp4tN8y08jw2jBHBgNVHSMEQDA+gBSCJd0hpl5PdAD9IZS+Hzng4lXLG6EjpCEw\n" +
|
||||
"HzELMAkGA1UEBhMCVVMxEDAOBgNVBAoTB0V4YW1wbGWCAQAwDwYDVR0TAQH/BAUw\n" +
|
||||
"AwEB/zALBgNVHQ8EBAMCAgQwDQYJKoZIhvcNAQEEBQADgYEAS9PzI6B39R/U9fRj\n" +
|
||||
"UExzN1FXNP5awnAPtiv34kSCL6n6MryqkfG+8aaAOdZsSjmTylNFaF7cW/Xp1VBF\n" +
|
||||
"hq0bg/SbEAbK7+UwL8GSC3crhULHLbh+1iFdVTEwxCw5YmB8ji3BaZ/WKW/PkjCZ\n" +
|
||||
"7cXP6VDeZMG6oRQ4hbOcixoFPXo=\n" +
|
||||
"-----END CERTIFICATE-----";
|
||||
|
||||
static String targetCertStr = subCaCertStr;
|
||||
|
||||
static String crlIssuerCertStr =
|
||||
"-----BEGIN CERTIFICATE-----\n" +
|
||||
"MIICKzCCAZSgAwIBAgIBAjANBgkqhkiG9w0BAQQFADAfMQswCQYDVQQGEwJVUzEQ\n" +
|
||||
"MA4GA1UEChMHRXhhbXBsZTAeFw0wOTA0MjcwMjI0MzNaFw0yOTAxMTIwMjI0MzNa\n" +
|
||||
"MB8xCzAJBgNVBAYTAlVTMRAwDgYDVQQKEwdFeGFtcGxlMIGfMA0GCSqGSIb3DQEB\n" +
|
||||
"AQUAA4GNADCBiQKBgQDMJeBMBybHykI/YpwUJ4O9euqDSLb1kpWpceBS8TVqvgBC\n" +
|
||||
"SgUJWtFZL0i6bdvF6mMdlbuBkGzhXqHiVAi96/zRLbUC9F8SMEJ6MuD+YhQ0ZFTQ\n" +
|
||||
"atKy8zf8O9XzztelLJ26Gqb7QPV133WY3haAqHtCXOhEKkCN16NOYNC37DTaJwID\n" +
|
||||
"AQABo3cwdTAdBgNVHQ4EFgQULXSWzXzUOIpOJpzbSCpW42IJUugwRwYDVR0jBEAw\n" +
|
||||
"PoAUgiXdIaZeT3QA/SGUvh854OJVyxuhI6QhMB8xCzAJBgNVBAYTAlVTMRAwDgYD\n" +
|
||||
"VQQKEwdFeGFtcGxlggEAMAsGA1UdDwQEAwIBAjANBgkqhkiG9w0BAQQFAAOBgQAY\n" +
|
||||
"eMnf5AHSNlyUlzXk8o2S0h4gCuvKX6C3kFfKuZcWvFAbx4yQOWLS2s15/nzR4+AP\n" +
|
||||
"FGX3lgJjROyAh7fGedTQK+NFWwkM2ag1g3hXktnlnT1qHohi0w31nVBJxXEDO/Ck\n" +
|
||||
"uJTpJGt8XxxbFaw5v7cHy7XuTAeU/sekvjEiNHW00Q==\n" +
|
||||
"-----END CERTIFICATE-----";
|
||||
|
||||
static String crlStr =
|
||||
"-----BEGIN X509 CRL-----\n" +
|
||||
"MIIBGzCBhQIBATANBgkqhkiG9w0BAQQFADAfMQswCQYDVQQGEwJVUzEQMA4GA1UE\n" +
|
||||
"ChMHRXhhbXBsZRcNMDkwNDI3MDIzODA0WhcNMjgwNjI2MDIzODA0WjAiMCACAQUX\n" +
|
||||
"DTA5MDQyNzAyMzgwMFowDDAKBgNVHRUEAwoBBKAOMAwwCgYDVR0UBAMCAQIwDQYJ\n" +
|
||||
"KoZIhvcNAQEEBQADgYEAoarfzXEtw3ZDi4f9U8eSvRIipHSyxOrJC7HR/hM5VhmY\n" +
|
||||
"CErChny6x9lBVg9s57tfD/P9PSzBLusCcHwHMAbMOEcTltVVKUWZnnbumpywlYyg\n" +
|
||||
"oKLrE9+yCOkYUOpiRlz43/3vkEL5hjIKMcDSZnPKBZi1h16Yj2hPe9GMibNip54=\n" +
|
||||
"-----END X509 CRL-----";
|
||||
|
||||
private static final PEMDecoder PEM_DECODER = PEMDecoder.of();
|
||||
|
||||
private static CertPath generateCertificatePath()
|
||||
throws CertificateException {
|
||||
// generate certificate from cert strings
|
||||
CertificateFactory cf = CertificateFactory.getInstance("X.509");
|
||||
|
||||
Certificate targetCert = PEM_DECODER.decode(targetCertStr, X509Certificate.class);
|
||||
|
||||
Certificate selfSignedCert = PEM_DECODER.decode(selfSignedCertStr, X509Certificate.class);
|
||||
|
||||
// generate certification path
|
||||
List<Certificate> list = Arrays.asList(targetCert, selfSignedCert);
|
||||
|
||||
return cf.generateCertPath(list);
|
||||
}
|
||||
|
||||
private static Set<TrustAnchor> generateTrustAnchors()
|
||||
throws CertificateException {
|
||||
// generate certificate from cert string
|
||||
X509Certificate selfSignedCert = PEM_DECODER.decode(selfSignedCertStr, X509Certificate.class);
|
||||
|
||||
// generate a trust anchor
|
||||
TrustAnchor anchor =
|
||||
new TrustAnchor(selfSignedCert, null);
|
||||
|
||||
return Collections.singleton(anchor);
|
||||
}
|
||||
|
||||
private static CertStore generateCertificateStore() throws Exception {
|
||||
|
||||
// generate a cert store
|
||||
Collection<DEREncodable> entries = new HashSet<>();
|
||||
entries.add(PEM_DECODER.decode(crlStr, X509CRL.class));
|
||||
entries.add(PEM_DECODER.decode(crlIssuerCertStr, X509Certificate.class));
|
||||
|
||||
return CertStore.getInstance("Collection",
|
||||
new CollectionCertStoreParameters(entries));
|
||||
}
|
||||
|
||||
public static void main(String args[]) throws Exception {
|
||||
// MD5 is used in this test case, don't disable MD5 algorithm.
|
||||
Security.setProperty(
|
||||
"jdk.certpath.disabledAlgorithms", "MD2, RSA keySize < 1024");
|
||||
|
||||
CertPath path = generateCertificatePath();
|
||||
Set<TrustAnchor> anchors = generateTrustAnchors();
|
||||
CertStore crls = generateCertificateStore();
|
||||
|
||||
PKIXParameters params = new PKIXParameters(anchors);
|
||||
|
||||
// add the CRL store
|
||||
params.addCertStore(crls);
|
||||
|
||||
// Activate certificate revocation checking
|
||||
params.setRevocationEnabled(true);
|
||||
|
||||
// set the validation time
|
||||
params.setDate(new Date(109, 5, 1)); // 2009-05-01
|
||||
|
||||
// disable OCSP checker
|
||||
Security.setProperty("ocsp.enable", "false");
|
||||
|
||||
// enable CRL checker
|
||||
System.setProperty("com.sun.security.enableCRLDP", "true");
|
||||
|
||||
CertPathValidator validator = CertPathValidator.getInstance("PKIX");
|
||||
|
||||
try {
|
||||
validator.validate(path, params);
|
||||
} catch (CertPathValidatorException cpve) {
|
||||
if (cpve.getReason() != BasicReason.REVOKED) {
|
||||
throw new Exception(
|
||||
"unexpect exception, should be a REVOKED CPVE", cpve);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,192 @@
|
|||
/*
|
||||
* Copyright (c) 2009, 2025, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
//
|
||||
// Security properties, once set, cannot revert to unset. To avoid
|
||||
// conflicts with tests running in the same VM isolate this test by
|
||||
// running it in otherVM mode.
|
||||
//
|
||||
|
||||
/**
|
||||
* @test
|
||||
*
|
||||
* @bug 6720721
|
||||
* @summary CRL check with circular depency support needed
|
||||
* @run main/othervm CircularCRLOneLevelRevoked
|
||||
* @enablePreview
|
||||
* @author Xuelei Fan
|
||||
*/
|
||||
|
||||
import java.io.*;
|
||||
import java.net.SocketException;
|
||||
import java.security.DEREncodable;
|
||||
import java.security.PEMDecoder;
|
||||
import java.util.*;
|
||||
import java.security.Security;
|
||||
import java.security.cert.*;
|
||||
import java.security.cert.CertPathValidatorException.BasicReason;
|
||||
|
||||
public class CircularCRLOneLevelRevoked {
|
||||
|
||||
static String selfSignedCertStr =
|
||||
"-----BEGIN CERTIFICATE-----\n" +
|
||||
"MIICPjCCAaegAwIBAgIBADANBgkqhkiG9w0BAQQFADAfMQswCQYDVQQGEwJVUzEQ\n" +
|
||||
"MA4GA1UEChMHRXhhbXBsZTAeFw0wOTA0MjcwMjI0MzJaFw0zMDA0MDcwMjI0MzJa\n" +
|
||||
"MB8xCzAJBgNVBAYTAlVTMRAwDgYDVQQKEwdFeGFtcGxlMIGfMA0GCSqGSIb3DQEB\n" +
|
||||
"AQUAA4GNADCBiQKBgQC4OTag24sTxL2tXTNuvpmUEtdxrYAZoFsslFQ60T+WD9wQ\n" +
|
||||
"Jeiw87FSPsR2vxRuv0j8DNm2a4h7LNNIFcLurfNldbz5pvgZ7VqdbbUMPE9qP85n\n" +
|
||||
"jgDl4woyRTSUeRI4A7O0CO6NpES21dtbdhroWQrEkHxpnrDPxsxrz5gf2m3gqwID\n" +
|
||||
"AQABo4GJMIGGMB0GA1UdDgQWBBSCJd0hpl5PdAD9IZS+Hzng4lXLGzBHBgNVHSME\n" +
|
||||
"QDA+gBSCJd0hpl5PdAD9IZS+Hzng4lXLG6EjpCEwHzELMAkGA1UEBhMCVVMxEDAO\n" +
|
||||
"BgNVBAoTB0V4YW1wbGWCAQAwDwYDVR0TAQH/BAUwAwEB/zALBgNVHQ8EBAMCAgQw\n" +
|
||||
"DQYJKoZIhvcNAQEEBQADgYEAluy6HIjWcq009lTLmhp+Np6dxU78pInBK8RZkza0\n" +
|
||||
"484qGaxFGD3UGyZkI5uWmsH2XuMbuox5khfIq6781gmkPBHXBIEtJN8eLusOHEye\n" +
|
||||
"iE8h7WI+N3qa6Pj56WionMrioqC/3X+b06o147bbhx8U0vkYv/HyPaITOFfMXTdz\n" +
|
||||
"Vjw=\n" +
|
||||
"-----END CERTIFICATE-----";
|
||||
|
||||
static String dumCaCertStr =
|
||||
"-----BEGIN CERTIFICATE-----\n" +
|
||||
"MIICUDCCAbmgAwIBAgIBBTANBgkqhkiG9w0BAQQFADAfMQswCQYDVQQGEwJVUzEQ\n" +
|
||||
"MA4GA1UEChMHRXhhbXBsZTAeFw0wOTA0MjcwMjI0MzVaFw0yOTAxMTIwMjI0MzVa\n" +
|
||||
"MDExCzAJBgNVBAYTAlVTMRAwDgYDVQQKEwdFeGFtcGxlMRAwDgYDVQQLEwdDbGFz\n" +
|
||||
"cy1EMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDAwfZ3wIYzdCkiFIKjrUKc\n" +
|
||||
"0B32HaRkUeVJthadinLmoAVruCi3GRkLZUIPXDD9b7dFBbdeT1+8qDHV5wu/ES8W\n" +
|
||||
"bgfirO8ng8h2hRuJbZgtfljNnVc3fptjxo7x73aP++w2oIcmjzVwaV08sgahoaY4\n" +
|
||||
"f249t4EXbvjJQ8kuj1I8qQIDAQABo4GJMIGGMB0GA1UdDgQWBBR3fwdjpP4WiuyL\n" +
|
||||
"/MDVrXUORrarXDBHBgNVHSMEQDA+gBSCJd0hpl5PdAD9IZS+Hzng4lXLG6EjpCEw\n" +
|
||||
"HzELMAkGA1UEBhMCVVMxEDAOBgNVBAoTB0V4YW1wbGWCAQAwDwYDVR0TAQH/BAUw\n" +
|
||||
"AwEB/zALBgNVHQ8EBAMCAgQwDQYJKoZIhvcNAQEEBQADgYEAp/2sXI/XLtXu+X05\n" +
|
||||
"EISyBPQqdE3kgN3dmXOuoK9J7Io8jhgetdbr9S1WTSGBonaXZgc52FNsaaDU+VIp\n" +
|
||||
"TGTYU5SFloUyOu/e095eAf9Q867pAPcE5zArfKpXEBLbJwhLFwrsKPk/WZM7Yaxs\n" +
|
||||
"mihnXyZWWTA1sPZlVJu7/abJ2v0=\n" +
|
||||
"-----END CERTIFICATE-----";
|
||||
|
||||
// a revoked certificate
|
||||
static String targetCertStr = dumCaCertStr;
|
||||
|
||||
static String crlIssuerCertStr =
|
||||
"-----BEGIN CERTIFICATE-----\n" +
|
||||
"MIICKzCCAZSgAwIBAgIBAjANBgkqhkiG9w0BAQQFADAfMQswCQYDVQQGEwJVUzEQ\n" +
|
||||
"MA4GA1UEChMHRXhhbXBsZTAeFw0wOTA0MjcwMjI0MzNaFw0yOTAxMTIwMjI0MzNa\n" +
|
||||
"MB8xCzAJBgNVBAYTAlVTMRAwDgYDVQQKEwdFeGFtcGxlMIGfMA0GCSqGSIb3DQEB\n" +
|
||||
"AQUAA4GNADCBiQKBgQDMJeBMBybHykI/YpwUJ4O9euqDSLb1kpWpceBS8TVqvgBC\n" +
|
||||
"SgUJWtFZL0i6bdvF6mMdlbuBkGzhXqHiVAi96/zRLbUC9F8SMEJ6MuD+YhQ0ZFTQ\n" +
|
||||
"atKy8zf8O9XzztelLJ26Gqb7QPV133WY3haAqHtCXOhEKkCN16NOYNC37DTaJwID\n" +
|
||||
"AQABo3cwdTAdBgNVHQ4EFgQULXSWzXzUOIpOJpzbSCpW42IJUugwRwYDVR0jBEAw\n" +
|
||||
"PoAUgiXdIaZeT3QA/SGUvh854OJVyxuhI6QhMB8xCzAJBgNVBAYTAlVTMRAwDgYD\n" +
|
||||
"VQQKEwdFeGFtcGxlggEAMAsGA1UdDwQEAwIBAjANBgkqhkiG9w0BAQQFAAOBgQAY\n" +
|
||||
"eMnf5AHSNlyUlzXk8o2S0h4gCuvKX6C3kFfKuZcWvFAbx4yQOWLS2s15/nzR4+AP\n" +
|
||||
"FGX3lgJjROyAh7fGedTQK+NFWwkM2ag1g3hXktnlnT1qHohi0w31nVBJxXEDO/Ck\n" +
|
||||
"uJTpJGt8XxxbFaw5v7cHy7XuTAeU/sekvjEiNHW00Q==\n" +
|
||||
"-----END CERTIFICATE-----";
|
||||
|
||||
static String crlStr =
|
||||
"-----BEGIN X509 CRL-----\n" +
|
||||
"MIIBGzCBhQIBATANBgkqhkiG9w0BAQQFADAfMQswCQYDVQQGEwJVUzEQMA4GA1UE\n" +
|
||||
"ChMHRXhhbXBsZRcNMDkwNDI3MDIzODA0WhcNMjgwNjI2MDIzODA0WjAiMCACAQUX\n" +
|
||||
"DTA5MDQyNzAyMzgwMFowDDAKBgNVHRUEAwoBBKAOMAwwCgYDVR0UBAMCAQIwDQYJ\n" +
|
||||
"KoZIhvcNAQEEBQADgYEAoarfzXEtw3ZDi4f9U8eSvRIipHSyxOrJC7HR/hM5VhmY\n" +
|
||||
"CErChny6x9lBVg9s57tfD/P9PSzBLusCcHwHMAbMOEcTltVVKUWZnnbumpywlYyg\n" +
|
||||
"oKLrE9+yCOkYUOpiRlz43/3vkEL5hjIKMcDSZnPKBZi1h16Yj2hPe9GMibNip54=\n" +
|
||||
"-----END X509 CRL-----";
|
||||
|
||||
private static final PEMDecoder PEM_DECODER = PEMDecoder.of();
|
||||
|
||||
private static CertPath generateCertificatePath()
|
||||
throws CertificateException {
|
||||
// generate certificate from cert strings
|
||||
CertificateFactory cf = CertificateFactory.getInstance("X.509");
|
||||
|
||||
Certificate targetCert = PEM_DECODER.decode(targetCertStr, X509Certificate.class);
|
||||
|
||||
Certificate selfSignedCert = PEM_DECODER.decode(selfSignedCertStr, X509Certificate.class);
|
||||
|
||||
// generate certification path
|
||||
List<Certificate> list = Arrays.asList(targetCert, selfSignedCert);
|
||||
|
||||
return cf.generateCertPath(list);
|
||||
}
|
||||
|
||||
private static Set<TrustAnchor> generateTrustAnchors()
|
||||
throws CertificateException {
|
||||
// generate certificate from cert string
|
||||
X509Certificate selfSignedCert = PEM_DECODER.decode(selfSignedCertStr, X509Certificate.class);
|
||||
|
||||
// generate a trust anchor
|
||||
TrustAnchor anchor =
|
||||
new TrustAnchor(selfSignedCert, null);
|
||||
|
||||
return Collections.singleton(anchor);
|
||||
}
|
||||
|
||||
private static CertStore generateCertificateStore() throws Exception {
|
||||
// generate CRL from CRL string
|
||||
Collection<DEREncodable> entries = new HashSet<>();
|
||||
entries.add(PEM_DECODER.decode(crlStr, X509CRL.class));
|
||||
entries.add(PEM_DECODER.decode(crlIssuerCertStr, X509Certificate.class));
|
||||
|
||||
return CertStore.getInstance("Collection",
|
||||
new CollectionCertStoreParameters(entries));
|
||||
}
|
||||
|
||||
public static void main(String args[]) throws Exception {
|
||||
// MD5 is used in this test case, don't disable MD5 algorithm.
|
||||
Security.setProperty(
|
||||
"jdk.certpath.disabledAlgorithms", "MD2, RSA keySize < 1024");
|
||||
|
||||
CertPath path = generateCertificatePath();
|
||||
Set<TrustAnchor> anchors = generateTrustAnchors();
|
||||
CertStore crls = generateCertificateStore();
|
||||
|
||||
PKIXParameters params = new PKIXParameters(anchors);
|
||||
|
||||
// add the CRL store
|
||||
params.addCertStore(crls);
|
||||
|
||||
// Activate certificate revocation checking
|
||||
params.setRevocationEnabled(true);
|
||||
|
||||
// set the validation time
|
||||
params.setDate(new Date(109, 5, 1)); // 2009-05-01
|
||||
|
||||
// disable OCSP checker
|
||||
Security.setProperty("ocsp.enable", "false");
|
||||
|
||||
// enable CRL checker
|
||||
System.setProperty("com.sun.security.enableCRLDP", "true");
|
||||
|
||||
CertPathValidator validator = CertPathValidator.getInstance("PKIX");
|
||||
|
||||
try {
|
||||
validator.validate(path, params);
|
||||
throw new Exception("unexpected status, should be REVOKED");
|
||||
} catch (CertPathValidatorException cpve) {
|
||||
if (cpve.getReason() != BasicReason.REVOKED) {
|
||||
throw new Exception(
|
||||
"unexpected exception, should be a REVOKED CPVE", cpve);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,259 @@
|
|||
/*
|
||||
* Copyright (c) 2009, 2025, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
//
|
||||
// Security properties, once set, cannot revert to unset. To avoid
|
||||
// conflicts with tests running in the same VM isolate this test by
|
||||
// running it in otherVM mode.
|
||||
//
|
||||
|
||||
/**
|
||||
* @test
|
||||
*
|
||||
* @bug 6720721
|
||||
* @summary CRL check with circular depency support needed
|
||||
* @enablePreview
|
||||
* @run main/othervm CircularCRLTwoLevel
|
||||
* @author Xuelei Fan
|
||||
*/
|
||||
|
||||
import java.security.DEREncodable;
|
||||
import java.security.PEMDecoder;
|
||||
import java.security.Security;
|
||||
import java.security.cert.CertPath;
|
||||
import java.security.cert.CertPathValidator;
|
||||
import java.security.cert.CertPathValidatorException;
|
||||
import java.security.cert.CertPathValidatorException.BasicReason;
|
||||
import java.security.cert.CertStore;
|
||||
import java.security.cert.Certificate;
|
||||
import java.security.cert.CertificateException;
|
||||
import java.security.cert.CertificateFactory;
|
||||
import java.security.cert.CollectionCertStoreParameters;
|
||||
import java.security.cert.PKIXParameters;
|
||||
import java.security.cert.TrustAnchor;
|
||||
import java.security.cert.X509CRL;
|
||||
import java.security.cert.X509Certificate;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class CircularCRLTwoLevel {
|
||||
|
||||
static String selfSignedCertStr =
|
||||
"-----BEGIN CERTIFICATE-----\n" +
|
||||
"MIICPjCCAaegAwIBAgIBADANBgkqhkiG9w0BAQQFADAfMQswCQYDVQQGEwJVUzEQ\n" +
|
||||
"MA4GA1UEChMHRXhhbXBsZTAeFw0wOTA0MjcwMjI0MzJaFw0zMDA0MDcwMjI0MzJa\n" +
|
||||
"MB8xCzAJBgNVBAYTAlVTMRAwDgYDVQQKEwdFeGFtcGxlMIGfMA0GCSqGSIb3DQEB\n" +
|
||||
"AQUAA4GNADCBiQKBgQC4OTag24sTxL2tXTNuvpmUEtdxrYAZoFsslFQ60T+WD9wQ\n" +
|
||||
"Jeiw87FSPsR2vxRuv0j8DNm2a4h7LNNIFcLurfNldbz5pvgZ7VqdbbUMPE9qP85n\n" +
|
||||
"jgDl4woyRTSUeRI4A7O0CO6NpES21dtbdhroWQrEkHxpnrDPxsxrz5gf2m3gqwID\n" +
|
||||
"AQABo4GJMIGGMB0GA1UdDgQWBBSCJd0hpl5PdAD9IZS+Hzng4lXLGzBHBgNVHSME\n" +
|
||||
"QDA+gBSCJd0hpl5PdAD9IZS+Hzng4lXLG6EjpCEwHzELMAkGA1UEBhMCVVMxEDAO\n" +
|
||||
"BgNVBAoTB0V4YW1wbGWCAQAwDwYDVR0TAQH/BAUwAwEB/zALBgNVHQ8EBAMCAgQw\n" +
|
||||
"DQYJKoZIhvcNAQEEBQADgYEAluy6HIjWcq009lTLmhp+Np6dxU78pInBK8RZkza0\n" +
|
||||
"484qGaxFGD3UGyZkI5uWmsH2XuMbuox5khfIq6781gmkPBHXBIEtJN8eLusOHEye\n" +
|
||||
"iE8h7WI+N3qa6Pj56WionMrioqC/3X+b06o147bbhx8U0vkYv/HyPaITOFfMXTdz\n" +
|
||||
"Vjw=\n" +
|
||||
"-----END CERTIFICATE-----";
|
||||
|
||||
static String subCaCertStr =
|
||||
"-----BEGIN CERTIFICATE-----\n" +
|
||||
"MIICUDCCAbmgAwIBAgIBAzANBgkqhkiG9w0BAQQFADAfMQswCQYDVQQGEwJVUzEQ\n" +
|
||||
"MA4GA1UEChMHRXhhbXBsZTAeFw0wOTA0MjcwMjI0MzRaFw0yOTAxMTIwMjI0MzRa\n" +
|
||||
"MDExCzAJBgNVBAYTAlVTMRAwDgYDVQQKEwdFeGFtcGxlMRAwDgYDVQQLEwdDbGFz\n" +
|
||||
"cy0xMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCiAJnAQW2ad3ZMKUhSJVZj\n" +
|
||||
"8pBqxTcHSTwAVguQkDglsN/OIwUpvR5Jgp3lpRWUEt6idEp0FZzORpvtjt3pr5MG\n" +
|
||||
"Eg2CDptekC5BSPS+fIAIKlncB3HwOiFFhH6b3wTydDCdEd2fvsi4QMOSVrIYMeA8\n" +
|
||||
"P/mCz6kRhfUQPE0CMmOUewIDAQABo4GJMIGGMB0GA1UdDgQWBBT0/nNP8WpyxmYr\n" +
|
||||
"IBp4tN8y08jw2jBHBgNVHSMEQDA+gBSCJd0hpl5PdAD9IZS+Hzng4lXLG6EjpCEw\n" +
|
||||
"HzELMAkGA1UEBhMCVVMxEDAOBgNVBAoTB0V4YW1wbGWCAQAwDwYDVR0TAQH/BAUw\n" +
|
||||
"AwEB/zALBgNVHQ8EBAMCAgQwDQYJKoZIhvcNAQEEBQADgYEAS9PzI6B39R/U9fRj\n" +
|
||||
"UExzN1FXNP5awnAPtiv34kSCL6n6MryqkfG+8aaAOdZsSjmTylNFaF7cW/Xp1VBF\n" +
|
||||
"hq0bg/SbEAbK7+UwL8GSC3crhULHLbh+1iFdVTEwxCw5YmB8ji3BaZ/WKW/PkjCZ\n" +
|
||||
"7cXP6VDeZMG6oRQ4hbOcixoFPXo=\n" +
|
||||
"-----END CERTIFICATE-----";
|
||||
|
||||
static String targetCertStr =
|
||||
"-----BEGIN CERTIFICATE-----\n" +
|
||||
"MIICNzCCAaCgAwIBAgIBAjANBgkqhkiG9w0BAQQFADAxMQswCQYDVQQGEwJVUzEQ\n" +
|
||||
"MA4GA1UEChMHRXhhbXBsZTEQMA4GA1UECxMHQ2xhc3MtMTAeFw0wOTA0MjcwMjI0\n" +
|
||||
"MzZaFw0yOTAxMTIwMjI0MzZaMEExCzAJBgNVBAYTAlVTMRAwDgYDVQQKEwdFeGFt\n" +
|
||||
"cGxlMRAwDgYDVQQLEwdDbGFzcy0xMQ4wDAYDVQQDEwVBbGljZTCBnzANBgkqhkiG\n" +
|
||||
"9w0BAQEFAAOBjQAwgYkCgYEAvYSaU3oiE4Pxp/aUIXwMqOwSiWkZ+O3aTu13hRtK\n" +
|
||||
"ZyR+Wtj63IuvaigAC4uC+zBypF93ThjwCzVR2qKDQaQzV8CLleO96gStt7Y+i3G2\n" +
|
||||
"V3IUGgrVCqeK7N6nNYu0wW84sibcPqG/TIy0UoaQMqgB21xtRF+1DUVlFh4Z89X/\n" +
|
||||
"pskCAwEAAaNPME0wCwYDVR0PBAQDAgPoMB0GA1UdDgQWBBSynMEdcal/e9TmvlNE\n" +
|
||||
"4suXGA4+hjAfBgNVHSMEGDAWgBT0/nNP8WpyxmYrIBp4tN8y08jw2jANBgkqhkiG\n" +
|
||||
"9w0BAQQFAAOBgQB/jru7E/+piSmUwByw5qbZsoQZVcgR97pd2TErNJpJMAX2oIHR\n" +
|
||||
"wJH6w4NuYs27+fEAX7wK4whc6EUH/w1SI6o28F2rG6HqYQPPZ2E2WqwbBQL9nYE3\n" +
|
||||
"Vfzu/G9axTUQXFbf90h80UErA+mZVxqc2xtymLuH0YEaMZImtRZ2MXHfXg==\n" +
|
||||
"-----END CERTIFICATE-----";
|
||||
|
||||
static String topCrlIssuerCertStr =
|
||||
"-----BEGIN CERTIFICATE-----\n" +
|
||||
"MIICKzCCAZSgAwIBAgIBAjANBgkqhkiG9w0BAQQFADAfMQswCQYDVQQGEwJVUzEQ\n" +
|
||||
"MA4GA1UEChMHRXhhbXBsZTAeFw0wOTA0MjcwMjI0MzNaFw0yOTAxMTIwMjI0MzNa\n" +
|
||||
"MB8xCzAJBgNVBAYTAlVTMRAwDgYDVQQKEwdFeGFtcGxlMIGfMA0GCSqGSIb3DQEB\n" +
|
||||
"AQUAA4GNADCBiQKBgQDMJeBMBybHykI/YpwUJ4O9euqDSLb1kpWpceBS8TVqvgBC\n" +
|
||||
"SgUJWtFZL0i6bdvF6mMdlbuBkGzhXqHiVAi96/zRLbUC9F8SMEJ6MuD+YhQ0ZFTQ\n" +
|
||||
"atKy8zf8O9XzztelLJ26Gqb7QPV133WY3haAqHtCXOhEKkCN16NOYNC37DTaJwID\n" +
|
||||
"AQABo3cwdTAdBgNVHQ4EFgQULXSWzXzUOIpOJpzbSCpW42IJUugwRwYDVR0jBEAw\n" +
|
||||
"PoAUgiXdIaZeT3QA/SGUvh854OJVyxuhI6QhMB8xCzAJBgNVBAYTAlVTMRAwDgYD\n" +
|
||||
"VQQKEwdFeGFtcGxlggEAMAsGA1UdDwQEAwIBAjANBgkqhkiG9w0BAQQFAAOBgQAY\n" +
|
||||
"eMnf5AHSNlyUlzXk8o2S0h4gCuvKX6C3kFfKuZcWvFAbx4yQOWLS2s15/nzR4+AP\n" +
|
||||
"FGX3lgJjROyAh7fGedTQK+NFWwkM2ag1g3hXktnlnT1qHohi0w31nVBJxXEDO/Ck\n" +
|
||||
"uJTpJGt8XxxbFaw5v7cHy7XuTAeU/sekvjEiNHW00Q==\n" +
|
||||
"-----END CERTIFICATE-----";
|
||||
|
||||
static String subCrlIssuerCertStr =
|
||||
"-----BEGIN CERTIFICATE-----\n" +
|
||||
"MIICPTCCAaagAwIBAgIBBDANBgkqhkiG9w0BAQQFADAfMQswCQYDVQQGEwJVUzEQ\n" +
|
||||
"MA4GA1UEChMHRXhhbXBsZTAeFw0wOTA0MjcwMjI0MzRaFw0yOTAxMTIwMjI0MzRa\n" +
|
||||
"MDExCzAJBgNVBAYTAlVTMRAwDgYDVQQKEwdFeGFtcGxlMRAwDgYDVQQLEwdDbGFz\n" +
|
||||
"cy0xMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDWUtDQx2MB/7arDiquMJyd\n" +
|
||||
"LWwSg6p8sg5z6wKrC1v47MT4DBhFX+0RUgTMUdQgYpgxGpczn+6y4zfV76064S0N\n" +
|
||||
"4L/IQ+SunTW1w4yRGjB+xkyyJmWAqijG1nr+Dgkv5nxPI+9Er5lHcoVWVMEcvvRm\n" +
|
||||
"6jIBQdldVlSgv+VgUnFm5wIDAQABo3cwdTAdBgNVHQ4EFgQUkV3Qqtk7gIot9n60\n" +
|
||||
"jX6dloxrfMEwRwYDVR0jBEAwPoAUgiXdIaZeT3QA/SGUvh854OJVyxuhI6QhMB8x\n" +
|
||||
"CzAJBgNVBAYTAlVTMRAwDgYDVQQKEwdFeGFtcGxlggEAMAsGA1UdDwQEAwIBAjAN\n" +
|
||||
"BgkqhkiG9w0BAQQFAAOBgQADu4GM8EdmIKhC7FRvk5jF90zfvZ38wbXBzCjKI4jX\n" +
|
||||
"QJrhne1bfyeNNm5c1w+VKidT+XzBzBGH7ZqYzoZmzRIfcbLKX2brEBKiukeeAyL3\n" +
|
||||
"bctQtbp19tX+uu2dQberD188AAysKTkHcJUV+rRsTwVJ9vcYKxoRxKk8DhH7ZS3M\n" +
|
||||
"rg==\n" +
|
||||
"-----END CERTIFICATE-----";
|
||||
|
||||
static String topCrlStr =
|
||||
"-----BEGIN X509 CRL-----\n" +
|
||||
"MIIBGzCBhQIBATANBgkqhkiG9w0BAQQFADAfMQswCQYDVQQGEwJVUzEQMA4GA1UE\n" +
|
||||
"ChMHRXhhbXBsZRcNMDkwNDI3MDIzODA0WhcNMjgwNjI2MDIzODA0WjAiMCACAQUX\n" +
|
||||
"DTA5MDQyNzAyMzgwMFowDDAKBgNVHRUEAwoBBKAOMAwwCgYDVR0UBAMCAQIwDQYJ\n" +
|
||||
"KoZIhvcNAQEEBQADgYEAoarfzXEtw3ZDi4f9U8eSvRIipHSyxOrJC7HR/hM5VhmY\n" +
|
||||
"CErChny6x9lBVg9s57tfD/P9PSzBLusCcHwHMAbMOEcTltVVKUWZnnbumpywlYyg\n" +
|
||||
"oKLrE9+yCOkYUOpiRlz43/3vkEL5hjIKMcDSZnPKBZi1h16Yj2hPe9GMibNip54=\n" +
|
||||
"-----END X509 CRL-----";
|
||||
|
||||
static String subCrlStr =
|
||||
"-----BEGIN X509 CRL-----\n" +
|
||||
"MIIBLTCBlwIBATANBgkqhkiG9w0BAQQFADAxMQswCQYDVQQGEwJVUzEQMA4GA1UE\n" +
|
||||
"ChMHRXhhbXBsZTEQMA4GA1UECxMHQ2xhc3MtMRcNMDkwNDI3MDIzODA0WhcNMjgw\n" +
|
||||
"NjI2MDIzODA0WjAiMCACAQQXDTA5MDQyNzAyMzgwMVowDDAKBgNVHRUEAwoBBKAO\n" +
|
||||
"MAwwCgYDVR0UBAMCAQIwDQYJKoZIhvcNAQEEBQADgYEAeS+POqYEIHIIJcsLxuUr\n" +
|
||||
"aJFzQ/ujH0QmnyMNEL3Uavyq4VQuAahF+w6aTPb5UBzms0uX8NAvD2vNoUJvmJOX\n" +
|
||||
"nGKuq4Q1DFj82E7/9d25nXdWGOmFvFCRVO+St2Xe5n8CJuZNBiz388FDSIOiFSCa\n" +
|
||||
"ARGr6Qu68MYGtLMC6ZqP3u0=\n" +
|
||||
"-----END X509 CRL-----";
|
||||
|
||||
private static final PEMDecoder pemDecoder = PEMDecoder.of();
|
||||
|
||||
private static CertPath generateCertificatePath()
|
||||
throws CertificateException {
|
||||
// generate certificate from cert strings
|
||||
CertificateFactory cf = CertificateFactory.getInstance("X.509");
|
||||
|
||||
Certificate targetCert = pemDecoder.decode(targetCertStr, X509Certificate.class);
|
||||
Certificate subCaCert = pemDecoder.decode(subCaCertStr, X509Certificate.class);
|
||||
Certificate selfSignedCert = pemDecoder.decode(selfSignedCertStr, X509Certificate.class);
|
||||
|
||||
// generate certification path
|
||||
List<Certificate> list = Arrays.asList(targetCert, subCaCert, selfSignedCert);
|
||||
|
||||
return cf.generateCertPath(list);
|
||||
}
|
||||
|
||||
private static Set<TrustAnchor> generateTrustAnchors()
|
||||
throws CertificateException {
|
||||
// generate certificate from cert string
|
||||
|
||||
final X509Certificate selfSignedCert = pemDecoder.decode(selfSignedCertStr, X509Certificate.class);
|
||||
|
||||
// generate a trust anchor
|
||||
TrustAnchor anchor =
|
||||
new TrustAnchor(selfSignedCert, null);
|
||||
|
||||
return Collections.singleton(anchor);
|
||||
}
|
||||
|
||||
private static CertStore generateCertificateStore() throws Exception {
|
||||
Collection<DEREncodable> entries = new HashSet<>();
|
||||
|
||||
// generate CRL from CRL string
|
||||
|
||||
DEREncodable mixes = pemDecoder.decode(topCrlStr, X509CRL.class);
|
||||
entries.add(mixes);
|
||||
|
||||
mixes = pemDecoder.decode(subCrlStr, X509CRL.class);
|
||||
entries.add(mixes);
|
||||
|
||||
// intermediate certs
|
||||
mixes = pemDecoder.decode(topCrlIssuerCertStr, X509Certificate.class);
|
||||
entries.add(mixes);
|
||||
|
||||
mixes = pemDecoder.decode(subCrlIssuerCertStr, X509Certificate.class);
|
||||
entries.add(mixes);
|
||||
|
||||
return CertStore.getInstance("Collection",
|
||||
new CollectionCertStoreParameters(entries));
|
||||
}
|
||||
|
||||
public static void main(String args[]) throws Exception {
|
||||
// MD5 is used in this test case, don't disable MD5 algorithm.
|
||||
Security.setProperty(
|
||||
"jdk.certpath.disabledAlgorithms", "MD2, RSA keySize < 1024");
|
||||
|
||||
CertPath path = generateCertificatePath();
|
||||
Set<TrustAnchor> anchors = generateTrustAnchors();
|
||||
CertStore crls = generateCertificateStore();
|
||||
|
||||
PKIXParameters params = new PKIXParameters(anchors);
|
||||
|
||||
// add the CRL store
|
||||
params.addCertStore(crls);
|
||||
|
||||
// Activate certificate revocation checking
|
||||
params.setRevocationEnabled(true);
|
||||
|
||||
// set the validation time
|
||||
params.setDate(new Date(109, 5, 1)); // 2009-05-01
|
||||
|
||||
// disable OCSP checker
|
||||
Security.setProperty("ocsp.enable", "false");
|
||||
|
||||
// enable CRL checker
|
||||
System.setProperty("com.sun.security.enableCRLDP", "true");
|
||||
|
||||
CertPathValidator validator = CertPathValidator.getInstance("PKIX");
|
||||
|
||||
try {
|
||||
validator.validate(path, params);
|
||||
} catch (CertPathValidatorException cpve) {
|
||||
if (cpve.getReason() != BasicReason.REVOKED) {
|
||||
throw new Exception(
|
||||
"unexpect exception, should be a REVOKED CPVE", cpve);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,261 @@
|
|||
/*
|
||||
* Copyright (c) 2009, 2025, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
//
|
||||
// Security properties, once set, cannot revert to unset. To avoid
|
||||
// conflicts with tests running in the same VM isolate this test by
|
||||
// running it in otherVM mode.
|
||||
//
|
||||
|
||||
/**
|
||||
* @test
|
||||
*
|
||||
* @bug 6720721
|
||||
* @summary CRL check with circular depency support needed
|
||||
* @enablePreview
|
||||
* @run main/othervm CircularCRLTwoLevelRevoked
|
||||
* @author Xuelei Fan
|
||||
*/
|
||||
|
||||
import java.security.DEREncodable;
|
||||
import java.security.PEMDecoder;
|
||||
import java.security.Security;
|
||||
import java.security.cert.CertPath;
|
||||
import java.security.cert.CertPathValidator;
|
||||
import java.security.cert.CertPathValidatorException;
|
||||
import java.security.cert.CertPathValidatorException.BasicReason;
|
||||
import java.security.cert.CertStore;
|
||||
import java.security.cert.Certificate;
|
||||
import java.security.cert.CertificateException;
|
||||
import java.security.cert.CertificateFactory;
|
||||
import java.security.cert.CollectionCertStoreParameters;
|
||||
import java.security.cert.PKIXParameters;
|
||||
import java.security.cert.TrustAnchor;
|
||||
import java.security.cert.X509CRL;
|
||||
import java.security.cert.X509Certificate;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class CircularCRLTwoLevelRevoked {
|
||||
|
||||
static String selfSignedCertStr =
|
||||
"-----BEGIN CERTIFICATE-----\n" +
|
||||
"MIICPjCCAaegAwIBAgIBADANBgkqhkiG9w0BAQQFADAfMQswCQYDVQQGEwJVUzEQ\n" +
|
||||
"MA4GA1UEChMHRXhhbXBsZTAeFw0wOTA0MjcwMjI0MzJaFw0zMDA0MDcwMjI0MzJa\n" +
|
||||
"MB8xCzAJBgNVBAYTAlVTMRAwDgYDVQQKEwdFeGFtcGxlMIGfMA0GCSqGSIb3DQEB\n" +
|
||||
"AQUAA4GNADCBiQKBgQC4OTag24sTxL2tXTNuvpmUEtdxrYAZoFsslFQ60T+WD9wQ\n" +
|
||||
"Jeiw87FSPsR2vxRuv0j8DNm2a4h7LNNIFcLurfNldbz5pvgZ7VqdbbUMPE9qP85n\n" +
|
||||
"jgDl4woyRTSUeRI4A7O0CO6NpES21dtbdhroWQrEkHxpnrDPxsxrz5gf2m3gqwID\n" +
|
||||
"AQABo4GJMIGGMB0GA1UdDgQWBBSCJd0hpl5PdAD9IZS+Hzng4lXLGzBHBgNVHSME\n" +
|
||||
"QDA+gBSCJd0hpl5PdAD9IZS+Hzng4lXLG6EjpCEwHzELMAkGA1UEBhMCVVMxEDAO\n" +
|
||||
"BgNVBAoTB0V4YW1wbGWCAQAwDwYDVR0TAQH/BAUwAwEB/zALBgNVHQ8EBAMCAgQw\n" +
|
||||
"DQYJKoZIhvcNAQEEBQADgYEAluy6HIjWcq009lTLmhp+Np6dxU78pInBK8RZkza0\n" +
|
||||
"484qGaxFGD3UGyZkI5uWmsH2XuMbuox5khfIq6781gmkPBHXBIEtJN8eLusOHEye\n" +
|
||||
"iE8h7WI+N3qa6Pj56WionMrioqC/3X+b06o147bbhx8U0vkYv/HyPaITOFfMXTdz\n" +
|
||||
"Vjw=\n" +
|
||||
"-----END CERTIFICATE-----";
|
||||
|
||||
static String subCaCertStr =
|
||||
"-----BEGIN CERTIFICATE-----\n" +
|
||||
"MIICUDCCAbmgAwIBAgIBAzANBgkqhkiG9w0BAQQFADAfMQswCQYDVQQGEwJVUzEQ\n" +
|
||||
"MA4GA1UEChMHRXhhbXBsZTAeFw0wOTA0MjcwMjI0MzRaFw0yOTAxMTIwMjI0MzRa\n" +
|
||||
"MDExCzAJBgNVBAYTAlVTMRAwDgYDVQQKEwdFeGFtcGxlMRAwDgYDVQQLEwdDbGFz\n" +
|
||||
"cy0xMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCiAJnAQW2ad3ZMKUhSJVZj\n" +
|
||||
"8pBqxTcHSTwAVguQkDglsN/OIwUpvR5Jgp3lpRWUEt6idEp0FZzORpvtjt3pr5MG\n" +
|
||||
"Eg2CDptekC5BSPS+fIAIKlncB3HwOiFFhH6b3wTydDCdEd2fvsi4QMOSVrIYMeA8\n" +
|
||||
"P/mCz6kRhfUQPE0CMmOUewIDAQABo4GJMIGGMB0GA1UdDgQWBBT0/nNP8WpyxmYr\n" +
|
||||
"IBp4tN8y08jw2jBHBgNVHSMEQDA+gBSCJd0hpl5PdAD9IZS+Hzng4lXLG6EjpCEw\n" +
|
||||
"HzELMAkGA1UEBhMCVVMxEDAOBgNVBAoTB0V4YW1wbGWCAQAwDwYDVR0TAQH/BAUw\n" +
|
||||
"AwEB/zALBgNVHQ8EBAMCAgQwDQYJKoZIhvcNAQEEBQADgYEAS9PzI6B39R/U9fRj\n" +
|
||||
"UExzN1FXNP5awnAPtiv34kSCL6n6MryqkfG+8aaAOdZsSjmTylNFaF7cW/Xp1VBF\n" +
|
||||
"hq0bg/SbEAbK7+UwL8GSC3crhULHLbh+1iFdVTEwxCw5YmB8ji3BaZ/WKW/PkjCZ\n" +
|
||||
"7cXP6VDeZMG6oRQ4hbOcixoFPXo=\n" +
|
||||
"-----END CERTIFICATE-----";
|
||||
|
||||
// a revoked certificate
|
||||
static String targetCertStr =
|
||||
"-----BEGIN CERTIFICATE-----\n" +
|
||||
"MIICNzCCAaCgAwIBAgIBBDANBgkqhkiG9w0BAQQFADAxMQswCQYDVQQGEwJVUzEQ\n" +
|
||||
"MA4GA1UEChMHRXhhbXBsZTEQMA4GA1UECxMHQ2xhc3MtMTAeFw0wOTA0MjcwMjI0\n" +
|
||||
"MzhaFw0yOTAxMTIwMjI0MzhaMEExCzAJBgNVBAYTAlVTMRAwDgYDVQQKEwdFeGFt\n" +
|
||||
"cGxlMRAwDgYDVQQLEwdDbGFzcy0xMQ4wDAYDVQQDEwVTdXNhbjCBnzANBgkqhkiG\n" +
|
||||
"9w0BAQEFAAOBjQAwgYkCgYEAyPKlfep+EIIUOpZF3xtYUhAx79qEqe2RPRcH2YeR\n" +
|
||||
"1ogM8+AZMdcXoiuDl4CFLzQwRv1DSKUZAPdPbROLVDsUn+IGvgn2jnE7ZQEUtQQJ\n" +
|
||||
"+rorcasE7bo5MBPuno/0oQRi/4MZn6lX3qB13ZUHAvZH96oCF6C3Ro19LAwav1Lo\n" +
|
||||
"FRcCAwEAAaNPME0wCwYDVR0PBAQDAgPoMB0GA1UdDgQWBBTCUH1tqQk96Pocr8Is\n" +
|
||||
"tDKMoIRQljAfBgNVHSMEGDAWgBT0/nNP8WpyxmYrIBp4tN8y08jw2jANBgkqhkiG\n" +
|
||||
"9w0BAQQFAAOBgQB3YXuTA+QfaImQ2aN/e27Nv5a/FMml6y6t0+pzt5hUYG2W0C2f\n" +
|
||||
"5Hdmf3whNCA7zE5RVDQP0iuGBPgjvrABuN98Vimv2eTV+N5aYTak0Aav/OuR5Lpi\n" +
|
||||
"tYhXMMg5gSmT+JDARba4CX+Ap1oAaNe9Mtv8L6FWdvBqfzzifDHWavdIWA==\n" +
|
||||
"-----END CERTIFICATE-----";
|
||||
|
||||
static String topCrlIssuerCertStr =
|
||||
"-----BEGIN CERTIFICATE-----\n" +
|
||||
"MIICKzCCAZSgAwIBAgIBAjANBgkqhkiG9w0BAQQFADAfMQswCQYDVQQGEwJVUzEQ\n" +
|
||||
"MA4GA1UEChMHRXhhbXBsZTAeFw0wOTA0MjcwMjI0MzNaFw0yOTAxMTIwMjI0MzNa\n" +
|
||||
"MB8xCzAJBgNVBAYTAlVTMRAwDgYDVQQKEwdFeGFtcGxlMIGfMA0GCSqGSIb3DQEB\n" +
|
||||
"AQUAA4GNADCBiQKBgQDMJeBMBybHykI/YpwUJ4O9euqDSLb1kpWpceBS8TVqvgBC\n" +
|
||||
"SgUJWtFZL0i6bdvF6mMdlbuBkGzhXqHiVAi96/zRLbUC9F8SMEJ6MuD+YhQ0ZFTQ\n" +
|
||||
"atKy8zf8O9XzztelLJ26Gqb7QPV133WY3haAqHtCXOhEKkCN16NOYNC37DTaJwID\n" +
|
||||
"AQABo3cwdTAdBgNVHQ4EFgQULXSWzXzUOIpOJpzbSCpW42IJUugwRwYDVR0jBEAw\n" +
|
||||
"PoAUgiXdIaZeT3QA/SGUvh854OJVyxuhI6QhMB8xCzAJBgNVBAYTAlVTMRAwDgYD\n" +
|
||||
"VQQKEwdFeGFtcGxlggEAMAsGA1UdDwQEAwIBAjANBgkqhkiG9w0BAQQFAAOBgQAY\n" +
|
||||
"eMnf5AHSNlyUlzXk8o2S0h4gCuvKX6C3kFfKuZcWvFAbx4yQOWLS2s15/nzR4+AP\n" +
|
||||
"FGX3lgJjROyAh7fGedTQK+NFWwkM2ag1g3hXktnlnT1qHohi0w31nVBJxXEDO/Ck\n" +
|
||||
"uJTpJGt8XxxbFaw5v7cHy7XuTAeU/sekvjEiNHW00Q==\n" +
|
||||
"-----END CERTIFICATE-----";
|
||||
|
||||
static String subCrlIssuerCertStr =
|
||||
"-----BEGIN CERTIFICATE-----\n" +
|
||||
"MIICPTCCAaagAwIBAgIBBDANBgkqhkiG9w0BAQQFADAfMQswCQYDVQQGEwJVUzEQ\n" +
|
||||
"MA4GA1UEChMHRXhhbXBsZTAeFw0wOTA0MjcwMjI0MzRaFw0yOTAxMTIwMjI0MzRa\n" +
|
||||
"MDExCzAJBgNVBAYTAlVTMRAwDgYDVQQKEwdFeGFtcGxlMRAwDgYDVQQLEwdDbGFz\n" +
|
||||
"cy0xMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDWUtDQx2MB/7arDiquMJyd\n" +
|
||||
"LWwSg6p8sg5z6wKrC1v47MT4DBhFX+0RUgTMUdQgYpgxGpczn+6y4zfV76064S0N\n" +
|
||||
"4L/IQ+SunTW1w4yRGjB+xkyyJmWAqijG1nr+Dgkv5nxPI+9Er5lHcoVWVMEcvvRm\n" +
|
||||
"6jIBQdldVlSgv+VgUnFm5wIDAQABo3cwdTAdBgNVHQ4EFgQUkV3Qqtk7gIot9n60\n" +
|
||||
"jX6dloxrfMEwRwYDVR0jBEAwPoAUgiXdIaZeT3QA/SGUvh854OJVyxuhI6QhMB8x\n" +
|
||||
"CzAJBgNVBAYTAlVTMRAwDgYDVQQKEwdFeGFtcGxlggEAMAsGA1UdDwQEAwIBAjAN\n" +
|
||||
"BgkqhkiG9w0BAQQFAAOBgQADu4GM8EdmIKhC7FRvk5jF90zfvZ38wbXBzCjKI4jX\n" +
|
||||
"QJrhne1bfyeNNm5c1w+VKidT+XzBzBGH7ZqYzoZmzRIfcbLKX2brEBKiukeeAyL3\n" +
|
||||
"bctQtbp19tX+uu2dQberD188AAysKTkHcJUV+rRsTwVJ9vcYKxoRxKk8DhH7ZS3M\n" +
|
||||
"rg==\n" +
|
||||
"-----END CERTIFICATE-----";
|
||||
|
||||
static String topCrlStr =
|
||||
"-----BEGIN X509 CRL-----\n" +
|
||||
"MIIBGzCBhQIBATANBgkqhkiG9w0BAQQFADAfMQswCQYDVQQGEwJVUzEQMA4GA1UE\n" +
|
||||
"ChMHRXhhbXBsZRcNMDkwNDI3MDIzODA0WhcNMjgwNjI2MDIzODA0WjAiMCACAQUX\n" +
|
||||
"DTA5MDQyNzAyMzgwMFowDDAKBgNVHRUEAwoBBKAOMAwwCgYDVR0UBAMCAQIwDQYJ\n" +
|
||||
"KoZIhvcNAQEEBQADgYEAoarfzXEtw3ZDi4f9U8eSvRIipHSyxOrJC7HR/hM5VhmY\n" +
|
||||
"CErChny6x9lBVg9s57tfD/P9PSzBLusCcHwHMAbMOEcTltVVKUWZnnbumpywlYyg\n" +
|
||||
"oKLrE9+yCOkYUOpiRlz43/3vkEL5hjIKMcDSZnPKBZi1h16Yj2hPe9GMibNip54=\n" +
|
||||
"-----END X509 CRL-----";
|
||||
|
||||
static String subCrlStr =
|
||||
"-----BEGIN X509 CRL-----\n" +
|
||||
"MIIBLTCBlwIBATANBgkqhkiG9w0BAQQFADAxMQswCQYDVQQGEwJVUzEQMA4GA1UE\n" +
|
||||
"ChMHRXhhbXBsZTEQMA4GA1UECxMHQ2xhc3MtMRcNMDkwNDI3MDIzODA0WhcNMjgw\n" +
|
||||
"NjI2MDIzODA0WjAiMCACAQQXDTA5MDQyNzAyMzgwMVowDDAKBgNVHRUEAwoBBKAO\n" +
|
||||
"MAwwCgYDVR0UBAMCAQIwDQYJKoZIhvcNAQEEBQADgYEAeS+POqYEIHIIJcsLxuUr\n" +
|
||||
"aJFzQ/ujH0QmnyMNEL3Uavyq4VQuAahF+w6aTPb5UBzms0uX8NAvD2vNoUJvmJOX\n" +
|
||||
"nGKuq4Q1DFj82E7/9d25nXdWGOmFvFCRVO+St2Xe5n8CJuZNBiz388FDSIOiFSCa\n" +
|
||||
"ARGr6Qu68MYGtLMC6ZqP3u0=\n" +
|
||||
"-----END X509 CRL-----";
|
||||
|
||||
private static final PEMDecoder pemDecoder = PEMDecoder.of();
|
||||
|
||||
private static CertPath generateCertificatePath()
|
||||
throws CertificateException {
|
||||
// generate certificate from cert strings
|
||||
CertificateFactory cf = CertificateFactory.getInstance("X.509");
|
||||
|
||||
Certificate targetCert = pemDecoder.decode(targetCertStr, X509Certificate.class);
|
||||
Certificate subCaCert = pemDecoder.decode(subCaCertStr, X509Certificate.class);
|
||||
Certificate selfSignedCert = pemDecoder.decode(selfSignedCertStr, X509Certificate.class);
|
||||
|
||||
// generate certification path
|
||||
List<Certificate> list = Arrays.asList(targetCert, subCaCert, selfSignedCert);
|
||||
|
||||
return cf.generateCertPath(list);
|
||||
}
|
||||
|
||||
private static Set<TrustAnchor> generateTrustAnchors()
|
||||
throws CertificateException {
|
||||
// generate certificate from cert string
|
||||
final X509Certificate selfSignedCert = pemDecoder.decode(selfSignedCertStr, X509Certificate.class);
|
||||
|
||||
// generate a trust anchor
|
||||
TrustAnchor anchor =
|
||||
new TrustAnchor(selfSignedCert, null);
|
||||
|
||||
return Collections.singleton(anchor);
|
||||
}
|
||||
|
||||
private static CertStore generateCertificateStore() throws Exception {
|
||||
Collection<DEREncodable> entries = new HashSet<>();
|
||||
|
||||
// generate CRL from CRL string
|
||||
CertificateFactory cf = CertificateFactory.getInstance("X.509");
|
||||
|
||||
DEREncodable mixes = pemDecoder.decode(topCrlStr, X509CRL.class);
|
||||
entries.add(mixes);
|
||||
|
||||
mixes = pemDecoder.decode(subCrlStr, X509CRL.class);
|
||||
entries.add(mixes);
|
||||
|
||||
// intermediate certs
|
||||
mixes = pemDecoder.decode(topCrlIssuerCertStr, X509Certificate.class);
|
||||
entries.add(mixes);
|
||||
|
||||
mixes = pemDecoder.decode(subCrlIssuerCertStr, X509Certificate.class);
|
||||
entries.add(mixes);
|
||||
|
||||
return CertStore.getInstance("Collection",
|
||||
new CollectionCertStoreParameters(entries));
|
||||
}
|
||||
|
||||
public static void main(String args[]) throws Exception {
|
||||
// MD5 is used in this test case, don't disable MD5 algorithm.
|
||||
Security.setProperty(
|
||||
"jdk.certpath.disabledAlgorithms", "MD2, RSA keySize < 1024");
|
||||
|
||||
CertPath path = generateCertificatePath();
|
||||
Set<TrustAnchor> anchors = generateTrustAnchors();
|
||||
CertStore crls = generateCertificateStore();
|
||||
|
||||
PKIXParameters params = new PKIXParameters(anchors);
|
||||
|
||||
// add the CRL store
|
||||
params.addCertStore(crls);
|
||||
|
||||
// Activate certificate revocation checking
|
||||
params.setRevocationEnabled(true);
|
||||
|
||||
// set the validation time
|
||||
params.setDate(new Date(109, 5, 1)); // 2009-05-01
|
||||
|
||||
// disable OCSP checker
|
||||
Security.setProperty("ocsp.enable", "false");
|
||||
|
||||
// enable CRL checker
|
||||
System.setProperty("com.sun.security.enableCRLDP", "true");
|
||||
|
||||
CertPathValidator validator = CertPathValidator.getInstance("PKIX");
|
||||
|
||||
try {
|
||||
validator.validate(path, params);
|
||||
throw new Exception("unexpected status, should be REVOKED");
|
||||
} catch (CertPathValidatorException cpve) {
|
||||
if (cpve.getReason() != BasicReason.REVOKED) {
|
||||
throw new Exception(
|
||||
"unexpect exception, should be a REVOKED CPVE", cpve);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
373
test/jdk/java/security/cert/CertPathValidator/indirectCRL/README
Normal file
373
test/jdk/java/security/cert/CertPathValidator/indirectCRL/README
Normal file
|
|
@ -0,0 +1,373 @@
|
|||
/*
|
||||
* Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
Certificates and CRLs
|
||||
|
||||
Here lists the Certificates and CRLs, which was generated by generate.sh,
|
||||
used in the test cases.
|
||||
|
||||
The generate.sh depends on openssl, and it should be run under ksh. The
|
||||
script will create many directories and files, please run it in a
|
||||
directory outside of JDK workspace.
|
||||
|
||||
1. root certifiate and key
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIICPjCCAaegAwIBAgIBADANBgkqhkiG9w0BAQQFADAfMQswCQYDVQQGEwJVUzEQ
|
||||
MA4GA1UEChMHRXhhbXBsZTAeFw0wOTA0MjcwMjI0MzJaFw0zMDA0MDcwMjI0MzJa
|
||||
MB8xCzAJBgNVBAYTAlVTMRAwDgYDVQQKEwdFeGFtcGxlMIGfMA0GCSqGSIb3DQEB
|
||||
AQUAA4GNADCBiQKBgQC4OTag24sTxL2tXTNuvpmUEtdxrYAZoFsslFQ60T+WD9wQ
|
||||
Jeiw87FSPsR2vxRuv0j8DNm2a4h7LNNIFcLurfNldbz5pvgZ7VqdbbUMPE9qP85n
|
||||
jgDl4woyRTSUeRI4A7O0CO6NpES21dtbdhroWQrEkHxpnrDPxsxrz5gf2m3gqwID
|
||||
AQABo4GJMIGGMB0GA1UdDgQWBBSCJd0hpl5PdAD9IZS+Hzng4lXLGzBHBgNVHSME
|
||||
QDA+gBSCJd0hpl5PdAD9IZS+Hzng4lXLG6EjpCEwHzELMAkGA1UEBhMCVVMxEDAO
|
||||
BgNVBAoTB0V4YW1wbGWCAQAwDwYDVR0TAQH/BAUwAwEB/zALBgNVHQ8EBAMCAgQw
|
||||
DQYJKoZIhvcNAQEEBQADgYEAluy6HIjWcq009lTLmhp+Np6dxU78pInBK8RZkza0
|
||||
484qGaxFGD3UGyZkI5uWmsH2XuMbuox5khfIq6781gmkPBHXBIEtJN8eLusOHEye
|
||||
iE8h7WI+N3qa6Pj56WionMrioqC/3X+b06o147bbhx8U0vkYv/HyPaITOFfMXTdz
|
||||
Vjw=
|
||||
-----END CERTIFICATE-----
|
||||
|
||||
-----BEGIN RSA PRIVATE KEY-----
|
||||
Proc-Type: 4,ENCRYPTED
|
||||
DEK-Info: DES-EDE3-CBC,407A749DF8F6338E
|
||||
|
||||
4ukHU4tkRAh2w17NEjPTICMbVtoS24bNk11Ywd7OzLV0aXnes2nSAV0KnXqnPTP8
|
||||
0VdoMVpp7r/jdaJvd3oL7MF5WcURzcOx2rirg+HeD5lHv0Blrh1FADcI1CQNsi8b
|
||||
WZHVuCc1+feOKxixPB8Fge5lKeeU554iTTk5XjOxAKO6GFn8FInj7b3+Zse4A/1E
|
||||
AOSKVSIWbx71owQyzjrYfoGE/oJVaSRraUbJL4xKcSUYdK+7Qp6h/HI1Cne2DZKu
|
||||
UmApdQnZbxa8hjuLqOiQFu6TVpzJh2UOqu1PEmjJgEM4DQQ9C8AgHdkVYitcLjiI
|
||||
b90H7JFl3EekMbjKEX/w2Z6y4RzFC9oGpJL/QpKvlq6sY7htPd1MK2UbWVE7/yq/
|
||||
holkrvySI1S7BFqKEdIY8Oe0tCNlmELdmL1+yVnQT0LnAX/bkzLNDw1n5J4WpLSX
|
||||
JdsgAXmw1hTh24tnT1E6IUd8HM4QyVrvsqCuEHTSMix1u6QCLvdlw4P6yA39ruiY
|
||||
xbBIcb5PHic0UrcdElRCzXLtW6tRe/98ET7WDEJOLudSUOSG3CKwrEX/kekBqJ11
|
||||
pAO34wLW5gsPwk2AQ1fAaNwHtGBlvKXnmbyuNitytA3/oSENSXnDHD2tIe1Jtep6
|
||||
yrfB9IqYEhINRi9BRR4rCkUwkBSRi4bRI7AzRP8pImG+iCDN6sT7T/mUmTTgFVLX
|
||||
NxPSGxbLxbidxnBU0B2JA3PfXqtt7J2Q5n0t3R3SC3iUxURGOvvccA3TcIWd4H75
|
||||
yQZNzvSIfTG3RhIM0as8/Ahad8hsdE/MqgW50yhzyjNF/UkvFLV8mw==
|
||||
-----END RSA PRIVATE KEY-----
|
||||
|
||||
2. root crl issuer and key
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIICKzCCAZSgAwIBAgIBAjANBgkqhkiG9w0BAQQFADAfMQswCQYDVQQGEwJVUzEQ
|
||||
MA4GA1UEChMHRXhhbXBsZTAeFw0wOTA0MjcwMjI0MzNaFw0yOTAxMTIwMjI0MzNa
|
||||
MB8xCzAJBgNVBAYTAlVTMRAwDgYDVQQKEwdFeGFtcGxlMIGfMA0GCSqGSIb3DQEB
|
||||
AQUAA4GNADCBiQKBgQDMJeBMBybHykI/YpwUJ4O9euqDSLb1kpWpceBS8TVqvgBC
|
||||
SgUJWtFZL0i6bdvF6mMdlbuBkGzhXqHiVAi96/zRLbUC9F8SMEJ6MuD+YhQ0ZFTQ
|
||||
atKy8zf8O9XzztelLJ26Gqb7QPV133WY3haAqHtCXOhEKkCN16NOYNC37DTaJwID
|
||||
AQABo3cwdTAdBgNVHQ4EFgQULXSWzXzUOIpOJpzbSCpW42IJUugwRwYDVR0jBEAw
|
||||
PoAUgiXdIaZeT3QA/SGUvh854OJVyxuhI6QhMB8xCzAJBgNVBAYTAlVTMRAwDgYD
|
||||
VQQKEwdFeGFtcGxlggEAMAsGA1UdDwQEAwIBAjANBgkqhkiG9w0BAQQFAAOBgQAY
|
||||
eMnf5AHSNlyUlzXk8o2S0h4gCuvKX6C3kFfKuZcWvFAbx4yQOWLS2s15/nzR4+AP
|
||||
FGX3lgJjROyAh7fGedTQK+NFWwkM2ag1g3hXktnlnT1qHohi0w31nVBJxXEDO/Ck
|
||||
uJTpJGt8XxxbFaw5v7cHy7XuTAeU/sekvjEiNHW00Q==
|
||||
-----END CERTIFICATE-----
|
||||
|
||||
-----BEGIN RSA PRIVATE KEY-----
|
||||
Proc-Type: 4,ENCRYPTED
|
||||
DEK-Info: DES-EDE3-CBC,96FBBE554515B5A4
|
||||
|
||||
cDfhsWvWCNruFN+9gSWSEz8kffFrqnvp9sxQx2/EwBrC8HNdQQqQqhkcb5moALz0
|
||||
KxAFQMmUG476v1zRv4ZRIpmT9gYhuqSpqKVQLRzFhe9wUDsCOcNCSfqK4I4blt+R
|
||||
gqRF+o97iNun+T2QXvku6B72CgQhJQHrEifoSTSGYpKGIVnhBmBPgadKn864zrv0
|
||||
ZvwjjRtgyC6/QTfKcXTW+8TIa8Bg/821ZJ0FcNsJs+2tQnki/KubRBIo7rGXGcxO
|
||||
f5PtO8BTjsw6G9TMuHKPlozOgGBgkQzf3gNXOLhdjwSDJUlTLLx5ugal+q0VVK7a
|
||||
Np8rK1SLrbC9ReI/VGD8BBW8qHRYhJny2JQ0ub8rXIptILNxH4d8r5ye3NaoskVN
|
||||
S4i5Jr5bgr0ijZ6kdECDiAoUo6UtTX1O9nbZA2AyJLch8gfNs+WeJLDmG9JPGVsW
|
||||
moGPGev1ykTc11Hn8K6S0errWD778B+k0ODLWg3EP8E1GFgdChTdMz2fT+YNrvQ/
|
||||
0iJATduzl4BN9eVB2qnadDAXfWm9kwkaX915ePKU1RpEnU3WygSnze8MfWshVJTn
|
||||
2F/meijLWgqrb4fmyd6KoDeqP5a+ByAPAiw/oAtemWSDviDc6VpXcXCL8dYoIBOV
|
||||
ehg/3Z/DmjfVFHdl5PWQfHiuVbIJbr/soQiTvDsjypYDi/aiY729ils2IxmzIQR8
|
||||
iLhOtBr6yd9qfqQ0761cYrdW5HlsTHOyZFctKxIf98ybzp+bJlskH8ifA1kgNLs3
|
||||
18T2gS+SkKqITi6TmD4Fkob+UtXPyzsb/8g7cNSv82k=
|
||||
-----END RSA PRIVATE KEY-----
|
||||
|
||||
3. root CRL issued by root crl issuer.
|
||||
-----BEGIN X509 CRL-----
|
||||
MIIBGzCBhQIBATANBgkqhkiG9w0BAQQFADAfMQswCQYDVQQGEwJVUzEQMA4GA1UE
|
||||
ChMHRXhhbXBsZRcNMDkwNDI3MDIzODA0WhcNMjgwNjI2MDIzODA0WjAiMCACAQUX
|
||||
DTA5MDQyNzAyMzgwMFowDDAKBgNVHRUEAwoBBKAOMAwwCgYDVR0UBAMCAQIwDQYJ
|
||||
KoZIhvcNAQEEBQADgYEAoarfzXEtw3ZDi4f9U8eSvRIipHSyxOrJC7HR/hM5VhmY
|
||||
CErChny6x9lBVg9s57tfD/P9PSzBLusCcHwHMAbMOEcTltVVKUWZnnbumpywlYyg
|
||||
oKLrE9+yCOkYUOpiRlz43/3vkEL5hjIKMcDSZnPKBZi1h16Yj2hPe9GMibNip54=
|
||||
-----END X509 CRL-----
|
||||
|
||||
4. subca certificate and key
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIICUDCCAbmgAwIBAgIBAzANBgkqhkiG9w0BAQQFADAfMQswCQYDVQQGEwJVUzEQ
|
||||
MA4GA1UEChMHRXhhbXBsZTAeFw0wOTA0MjcwMjI0MzRaFw0yOTAxMTIwMjI0MzRa
|
||||
MDExCzAJBgNVBAYTAlVTMRAwDgYDVQQKEwdFeGFtcGxlMRAwDgYDVQQLEwdDbGFz
|
||||
cy0xMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCiAJnAQW2ad3ZMKUhSJVZj
|
||||
8pBqxTcHSTwAVguQkDglsN/OIwUpvR5Jgp3lpRWUEt6idEp0FZzORpvtjt3pr5MG
|
||||
Eg2CDptekC5BSPS+fIAIKlncB3HwOiFFhH6b3wTydDCdEd2fvsi4QMOSVrIYMeA8
|
||||
P/mCz6kRhfUQPE0CMmOUewIDAQABo4GJMIGGMB0GA1UdDgQWBBT0/nNP8WpyxmYr
|
||||
IBp4tN8y08jw2jBHBgNVHSMEQDA+gBSCJd0hpl5PdAD9IZS+Hzng4lXLG6EjpCEw
|
||||
HzELMAkGA1UEBhMCVVMxEDAOBgNVBAoTB0V4YW1wbGWCAQAwDwYDVR0TAQH/BAUw
|
||||
AwEB/zALBgNVHQ8EBAMCAgQwDQYJKoZIhvcNAQEEBQADgYEAS9PzI6B39R/U9fRj
|
||||
UExzN1FXNP5awnAPtiv34kSCL6n6MryqkfG+8aaAOdZsSjmTylNFaF7cW/Xp1VBF
|
||||
hq0bg/SbEAbK7+UwL8GSC3crhULHLbh+1iFdVTEwxCw5YmB8ji3BaZ/WKW/PkjCZ
|
||||
7cXP6VDeZMG6oRQ4hbOcixoFPXo=
|
||||
-----END CERTIFICATE-----
|
||||
|
||||
-----BEGIN RSA PRIVATE KEY-----
|
||||
Proc-Type: 4,ENCRYPTED
|
||||
DEK-Info: DES-EDE3-CBC,AB196C2474B93EE0
|
||||
|
||||
8S3B4hsTW2OI6CA7bgoou4nt8VQckaRKvC6v+J/gHhnjd9aWnv3wKHhZsQl42+dY
|
||||
HB8DImLTU02gnf3tEGJrTIyrIGrrAjwvio8yzxVqOnNuB6CamlCYx6Td7L09+Wlp
|
||||
8qV1dj+czHhkoH/r0oRHU8NKQMphLQ0kcq3n+hM1UcSzdPxStyIBSRn34dKkuA+t
|
||||
UjKfxbaPMN0dABPesN5emyAUYvVu4qSgDaw4pkqJKk/3+DL6lP3Ih93vTnyx7KU5
|
||||
UexoA9apTDGQuiNbhoKJwOlrG2E7Y57eVOW52b7QPHH8miNCJ5UJALBymPkBc76s
|
||||
D1ioMSdPWfy5C70Hh219oWync3UTToL/Jh1jc0ir5XI5l9lFz/IEA9uhxg137ixB
|
||||
Gj1f2S+eSgnQ3SADVrA5wwX88nrjDufrFpH7ofq947IbI9F6iTMOSqR1uIy0SryW
|
||||
jhB6t/fB0alZceqn8dLAFMV2WvVCGsWx53zcGg09q29FkjpLJpZiI6Bc6EYdk+nn
|
||||
aeGbHLxwKf/vLcD0Oyx4FiJS1vMAEex41eblcwqjiU6vql9LbIFX4hVjGoQ/cL0U
|
||||
bjEZjWlNPAvbBVAlStEXOyZzrrDJUags5gqhdv6VKvzQouwH3+Ivbx7UiSTpJ3If
|
||||
A9txNSVsqc5MTy4hA30RSdMwoP4lK2PrHvivNnZi/kD7Knxn9OuEVBL3KXTmYduQ
|
||||
kDmJzsKWOPvXHEgAZkfXIPKYNT2Z5LuS3yPSlGUcInImBawOkqgs5NJvUTrkbDMk
|
||||
uSrOUFUBdBczU4I5oD1vs9yNhLtaK0S6w3gfiHNpIfg4FIFbdqmnAA==
|
||||
-----END RSA PRIVATE KEY-----
|
||||
|
||||
5. crl issuer of subca, the certificate and key
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIICPTCCAaagAwIBAgIBBDANBgkqhkiG9w0BAQQFADAfMQswCQYDVQQGEwJVUzEQ
|
||||
MA4GA1UEChMHRXhhbXBsZTAeFw0wOTA0MjcwMjI0MzRaFw0yOTAxMTIwMjI0MzRa
|
||||
MDExCzAJBgNVBAYTAlVTMRAwDgYDVQQKEwdFeGFtcGxlMRAwDgYDVQQLEwdDbGFz
|
||||
cy0xMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDWUtDQx2MB/7arDiquMJyd
|
||||
LWwSg6p8sg5z6wKrC1v47MT4DBhFX+0RUgTMUdQgYpgxGpczn+6y4zfV76064S0N
|
||||
4L/IQ+SunTW1w4yRGjB+xkyyJmWAqijG1nr+Dgkv5nxPI+9Er5lHcoVWVMEcvvRm
|
||||
6jIBQdldVlSgv+VgUnFm5wIDAQABo3cwdTAdBgNVHQ4EFgQUkV3Qqtk7gIot9n60
|
||||
jX6dloxrfMEwRwYDVR0jBEAwPoAUgiXdIaZeT3QA/SGUvh854OJVyxuhI6QhMB8x
|
||||
CzAJBgNVBAYTAlVTMRAwDgYDVQQKEwdFeGFtcGxlggEAMAsGA1UdDwQEAwIBAjAN
|
||||
BgkqhkiG9w0BAQQFAAOBgQADu4GM8EdmIKhC7FRvk5jF90zfvZ38wbXBzCjKI4jX
|
||||
QJrhne1bfyeNNm5c1w+VKidT+XzBzBGH7ZqYzoZmzRIfcbLKX2brEBKiukeeAyL3
|
||||
bctQtbp19tX+uu2dQberD188AAysKTkHcJUV+rRsTwVJ9vcYKxoRxKk8DhH7ZS3M
|
||||
rg==
|
||||
-----END CERTIFICATE-----
|
||||
|
||||
-----BEGIN RSA PRIVATE KEY-----
|
||||
Proc-Type: 4,ENCRYPTED
|
||||
DEK-Info: DES-EDE3-CBC,8C523D20E1687EC3
|
||||
|
||||
KdLa0JlKnRDBf/bwtpvmcerBOzJNPidRoIrqDt8fZ5r4WyUWhmBzkNgmBu6KFFPQ
|
||||
4IKK4GW7Oo/D7x1w4hIyDt+JaMSdWWgSyvlIWZ6gSDEsqhzMHQpFNxDet8oD3B6H
|
||||
CMdfXuQ7VHWcYhjX078FNxSRqTQvKR1eAv3AdnXAkuH6Z8V/if1dlQ/yFteSKzCZ
|
||||
Y468leZR14Fl0J8au8LOHxZ6tUBvVXUTo0/FutsfOs9BfLTLkKvLS2pEjMdwnfvS
|
||||
4utV/keK7edAXALfnclAshjYShxgwcyAWszJs9M16k/jqAGdDLAfluoZaznfZ1sc
|
||||
KhAyIKYRo1XivjmTQxvQRwdG+X/w8CYUzawybt8TtXyLyu4cRdEHsEDyjJ5eG9ap
|
||||
+ZDP+djWmrjUPKN5Ahc+Fjtsi6i8PcVFnYTnMAwfjiBd4iU+zJEhne0YUB4QRZee
|
||||
5jdLC8OUfqU0tByj7kDxn6shU2F3r7gIjPqx9DEWGWSf5XDlfk880GGIR67cNEqo
|
||||
lMLP/9/KUEeCwgrvqKdoD/O7qbNlmX7JyGcl/eU2Zsq5P5xkLWenuRHwpJlmV19m
|
||||
2Ovg2gK24okl7FiUgP3vNAzDznqHfyoyoR4noKPwtRANOI3otJxokMFGlgzQAXZB
|
||||
4Eg6M+VLuTxoV14tsSqtkBGNFOUE06n3G5CKuXbh3gXQs0gc8BvzuRMawVSHC144
|
||||
UJM3X73aqSM42lwO2pBjMfxyPdFNkxf3lDuyfMOhGlpDwsny4N4EAOS5ctKNl3Ua
|
||||
oP0BiqyKSuzreg1Ouwq1XxxnWec6XqlHm9482I/vautunqLYQDcfQQ==
|
||||
-----END RSA PRIVATE KEY-----
|
||||
|
||||
6. CLR issued by subca CRL issuer
|
||||
-----BEGIN X509 CRL-----
|
||||
MIIBLTCBlwIBATANBgkqhkiG9w0BAQQFADAxMQswCQYDVQQGEwJVUzEQMA4GA1UE
|
||||
ChMHRXhhbXBsZTEQMA4GA1UECxMHQ2xhc3MtMRcNMDkwNDI3MDIzODA0WhcNMjgw
|
||||
NjI2MDIzODA0WjAiMCACAQQXDTA5MDQyNzAyMzgwMVowDDAKBgNVHRUEAwoBBKAO
|
||||
MAwwCgYDVR0UBAMCAQIwDQYJKoZIhvcNAQEEBQADgYEAeS+POqYEIHIIJcsLxuUr
|
||||
aJFzQ/ujH0QmnyMNEL3Uavyq4VQuAahF+w6aTPb5UBzms0uX8NAvD2vNoUJvmJOX
|
||||
nGKuq4Q1DFj82E7/9d25nXdWGOmFvFCRVO+St2Xe5n8CJuZNBiz388FDSIOiFSCa
|
||||
ARGr6Qu68MYGtLMC6ZqP3u0=
|
||||
-----END X509 CRL-----
|
||||
|
||||
7. dumca certificate and key
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIICUDCCAbmgAwIBAgIBBTANBgkqhkiG9w0BAQQFADAfMQswCQYDVQQGEwJVUzEQ
|
||||
MA4GA1UEChMHRXhhbXBsZTAeFw0wOTA0MjcwMjI0MzVaFw0yOTAxMTIwMjI0MzVa
|
||||
MDExCzAJBgNVBAYTAlVTMRAwDgYDVQQKEwdFeGFtcGxlMRAwDgYDVQQLEwdDbGFz
|
||||
cy1EMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDAwfZ3wIYzdCkiFIKjrUKc
|
||||
0B32HaRkUeVJthadinLmoAVruCi3GRkLZUIPXDD9b7dFBbdeT1+8qDHV5wu/ES8W
|
||||
bgfirO8ng8h2hRuJbZgtfljNnVc3fptjxo7x73aP++w2oIcmjzVwaV08sgahoaY4
|
||||
f249t4EXbvjJQ8kuj1I8qQIDAQABo4GJMIGGMB0GA1UdDgQWBBR3fwdjpP4WiuyL
|
||||
/MDVrXUORrarXDBHBgNVHSMEQDA+gBSCJd0hpl5PdAD9IZS+Hzng4lXLG6EjpCEw
|
||||
HzELMAkGA1UEBhMCVVMxEDAOBgNVBAoTB0V4YW1wbGWCAQAwDwYDVR0TAQH/BAUw
|
||||
AwEB/zALBgNVHQ8EBAMCAgQwDQYJKoZIhvcNAQEEBQADgYEAp/2sXI/XLtXu+X05
|
||||
EISyBPQqdE3kgN3dmXOuoK9J7Io8jhgetdbr9S1WTSGBonaXZgc52FNsaaDU+VIp
|
||||
TGTYU5SFloUyOu/e095eAf9Q867pAPcE5zArfKpXEBLbJwhLFwrsKPk/WZM7Yaxs
|
||||
mihnXyZWWTA1sPZlVJu7/abJ2v0=
|
||||
-----END CERTIFICATE-----
|
||||
|
||||
-----BEGIN RSA PRIVATE KEY-----
|
||||
Proc-Type: 4,ENCRYPTED
|
||||
DEK-Info: DES-EDE3-CBC,8CE4AB01D39EC5B3
|
||||
|
||||
KUkwAyP6ba59QAdDbaXGLmtxtrAilKjFVB+2eawq2Arpumu4cl1joeLtMANF9f1f
|
||||
afG5FDATYke6C0FMD/bfF4VkUcVUq+Daw8uS5LkDTYjRqrxE4nCLBhxDJdNiIhUi
|
||||
VNuTMITqcpOOU77nUu2O5LW9Z40F6H9x86SeHOeY0IrmhlFVgHuxr81jdrd8OLYK
|
||||
7DkKPUa5F331fAkknOQIYnhmCXeHtlTv8ozU5bfBc6TePAL6Y1jn7Hv7EB9C2yYU
|
||||
6qejxzKBgxWWWuYU21K0gayPmq8gAKyfi21xSxFR+a9GxRlf+K/x07i7w7oT6QLh
|
||||
Qft76I+UER2jYYeQm3sxEeLBq9nDb2HfSjOnLjh3J2c5Tp9B2dmLxPk2hHim4cUn
|
||||
nyE8lGDwt/+t6lM8GWfAPn92r2/YOQWr+MXcwE7hi8NZp4cjRR+UqXc0p4+3rKzQ
|
||||
IuD5CGgtx78sxMrAxfwvkedmYpjf9L8nGWdbivOI25mNKSXhEjMNzv+lC6nLQE7o
|
||||
6LLA3voN+SiVh7wu45FMJHsz1JOjUjwYXS931GsHyd/sy9q7wUkzokKc1WHML2vl
|
||||
NglC/4w3NOuEYm5ZDlu6QYQh2uIg/pHPO3am2NTjffjFV0uXEZGd0Qw3gPv9gPNv
|
||||
iMRa+6vQfl97xOYOtep4yp5L7XatoLMrVmboykdrojUuAQSiZgfwIR/f/NPbVvHp
|
||||
q3/fadE2hLpkkSJjPm5ensFXoLn14QTdVpKl3mjnAa0rb8q5edz4d8r644NHaYH0
|
||||
nxToTdZpSH7uGAuOMZwvUaKT//hojKBj6hjlDuVJWs/kwRHbWJEd4A==
|
||||
-----END RSA PRIVATE KEY-----
|
||||
|
||||
8. crl issuer for dumca, the certificate and key
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIICPTCCAaagAwIBAgIBBjANBgkqhkiG9w0BAQQFADAfMQswCQYDVQQGEwJVUzEQ
|
||||
MA4GA1UEChMHRXhhbXBsZTAeFw0wOTA0MjcwMjI0MzVaFw0yOTAxMTIwMjI0MzVa
|
||||
MDExCzAJBgNVBAYTAlVTMRAwDgYDVQQKEwdFeGFtcGxlMRAwDgYDVQQLEwdDbGFz
|
||||
cy1EMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCcDDBVR9IPJq6ND9z3Wpsv
|
||||
s0VfJief2QW6U7fNYAnpD4eXNXdwWtZvybMI12crUp31AWzjIaffsBzlFjBO3vKn
|
||||
edJ+Om2nhqPPT31nDIWIx1VdS7jL+XoFpo8QgzJQpX0rDZNhaTbQcgnuRhzOZ+x2
|
||||
AzxxQf7aMI6YQ5xklO1ftQIDAQABo3cwdTAdBgNVHQ4EFgQUYqt5Hbekj/p4UkfY
|
||||
sP4Ma5HdTpkwRwYDVR0jBEAwPoAUgiXdIaZeT3QA/SGUvh854OJVyxuhI6QhMB8x
|
||||
CzAJBgNVBAYTAlVTMRAwDgYDVQQKEwdFeGFtcGxlggEAMAsGA1UdDwQEAwIBAjAN
|
||||
BgkqhkiG9w0BAQQFAAOBgQAMBqjEfALPFj+asQfTjSqXZimybm5WCYJcv92WAaFm
|
||||
2aJe08jUKCwCVo29CFMMgVG5X0UhEP+ude9RyonYNrMg84hFrQdZSto4Co5yfCGi
|
||||
SMaa91gkN8/W4VKFjDoooOQ/9o6i22OC7av6+r+qhGMsop5mqRMumAM+C00dy1m6
|
||||
5g==
|
||||
-----END CERTIFICATE-----
|
||||
|
||||
-----BEGIN RSA PRIVATE KEY-----
|
||||
Proc-Type: 4,ENCRYPTED
|
||||
DEK-Info: DES-EDE3-CBC,FE34D030ADCF25E5
|
||||
|
||||
V+hWLshb8wbqv8MqBFVZUBK3T995hc6xxWt9wn1aFVcvoxSmWQ20/9LdYDFNhf5j
|
||||
3grRdy6sBmQY1Ch73Q1N8egl0FlqqttBY62ulpVQFCYcYhCSMJKSDJyw5pYlQjd4
|
||||
LpVXhqsTCB1KdeOVkdB45Ljg7wy+idWfo6U0pAPjhnbPysZWuPrIGVIrVfDMz1tw
|
||||
ohuh/NOsF8r2w/U3zBaGKoeW/TGkxXBCKhMU78fve5ytEwv9Gp5m1O5yHJDqNC1M
|
||||
gtAQvvXifeLaCRfOpQtCHGuoR0fhdOnQPJQ/4Nre/dRG8zDVa3FKvWjMPbse4cxJ
|
||||
OljgVyd7UWrnUvnlNufI3T069b6aAfk16eLz9RAJZNZfpXflboRcaHW9VmjU8m7Y
|
||||
ir353hxKQk+P+lU2Ysmu7hx/QKmfG8aKI+r7tXnm1J0dmbeOZE69i4lhvXNvx1N2
|
||||
kPNKXsQ3kMKdJNVg5TQrUaqa7GtdQlg3Nr+FpaZ5aZJhTNFejQZrTV9bnQHob0q2
|
||||
1KCveDPOy2qtRY/mK+BnlNwGx1Ti87iGHv0Om8tXI53G0UkJs3LMI5JPcmHXVC1c
|
||||
skU6nAxhdNPSDN7EBMF80xte99qQTTtDbYQbIqMtd8lCP4HaYhTtlBeaROuntEjx
|
||||
3XDXVIHKHxSsrrKn/dE8Ls7tv1j0XxarzGekhQWZ6xbxxursiMstZUfDeQR7SlwC
|
||||
a3Lem76iGo2BqZd6wbv0i45P2hVQ8DuNhmOphC7DTFQmudOnFJKHPp8pmca+LGfV
|
||||
dgFmct3vSnWjnTvRDktFblfYa0r0QZDSKZt7TiI4QjR5iqP8WEziKA==
|
||||
-----END RSA PRIVATE KEY-----
|
||||
|
||||
9. end entity certificate issued by subca, Alice
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIICNzCCAaCgAwIBAgIBAjANBgkqhkiG9w0BAQQFADAxMQswCQYDVQQGEwJVUzEQ
|
||||
MA4GA1UEChMHRXhhbXBsZTEQMA4GA1UECxMHQ2xhc3MtMTAeFw0wOTA0MjcwMjI0
|
||||
MzZaFw0yOTAxMTIwMjI0MzZaMEExCzAJBgNVBAYTAlVTMRAwDgYDVQQKEwdFeGFt
|
||||
cGxlMRAwDgYDVQQLEwdDbGFzcy0xMQ4wDAYDVQQDEwVBbGljZTCBnzANBgkqhkiG
|
||||
9w0BAQEFAAOBjQAwgYkCgYEAvYSaU3oiE4Pxp/aUIXwMqOwSiWkZ+O3aTu13hRtK
|
||||
ZyR+Wtj63IuvaigAC4uC+zBypF93ThjwCzVR2qKDQaQzV8CLleO96gStt7Y+i3G2
|
||||
V3IUGgrVCqeK7N6nNYu0wW84sibcPqG/TIy0UoaQMqgB21xtRF+1DUVlFh4Z89X/
|
||||
pskCAwEAAaNPME0wCwYDVR0PBAQDAgPoMB0GA1UdDgQWBBSynMEdcal/e9TmvlNE
|
||||
4suXGA4+hjAfBgNVHSMEGDAWgBT0/nNP8WpyxmYrIBp4tN8y08jw2jANBgkqhkiG
|
||||
9w0BAQQFAAOBgQB/jru7E/+piSmUwByw5qbZsoQZVcgR97pd2TErNJpJMAX2oIHR
|
||||
wJH6w4NuYs27+fEAX7wK4whc6EUH/w1SI6o28F2rG6HqYQPPZ2E2WqwbBQL9nYE3
|
||||
Vfzu/G9axTUQXFbf90h80UErA+mZVxqc2xtymLuH0YEaMZImtRZ2MXHfXg==
|
||||
-----END CERTIFICATE-----
|
||||
|
||||
-----BEGIN RSA PRIVATE KEY-----
|
||||
Proc-Type: 4,ENCRYPTED
|
||||
DEK-Info: DES-EDE3-CBC,3616B3F098ED6707
|
||||
|
||||
uXoAPYIUINSr8Cc67K1XdLPO/toBasXYJAYYodq+qMsqYVhjgUgzJWYBwayav04Y
|
||||
tPgID3f4olLMQP77h5nHLArQCdgI3ZmKDZ6tYR7c2YglTqO1h4pzptv3Csc6lsnr
|
||||
zYS43Wg5YK8lAVxAbaDqG/xRiJhEG6+Xqno/lyDSUcDjcsyULWCf1mUZUR66fpnO
|
||||
Kcvmec3RFS6PPpYKJ/3Hl6Px5TsnSMEgb8OIrLik4Tj08XhdBEZxTJcyA1JPeAUP
|
||||
PH9hm+TWb3E+kDywpItMlTFIhS6b41JGo6Rq6HwVYquCoE4NO32vovd57u5R20yy
|
||||
3mfzc0udAYDD8drnzp2XPridqy47m/zFpVgfYU+irH3uW/n1QSB0w3fdCRXNEl6c
|
||||
5dAAwwIR1Pn+RAVUvZ7sQ/qReSOHg85uH7FjY9+m4d4vtf8aV410pyDbaNnevvfK
|
||||
fTiwmopWujL9sJoZZYP04QZ1f+8aGA41dWS837d9e2F/9BtI5zlymEhLs8UFHziJ
|
||||
Cw41xnOHHaoxtDFSvSmc2G6o0jfwJ0AZf8toyB5kj+rd5iu2Z1Kmk8vd4bK5SCwT
|
||||
dZRLri75Hyns7fLMXuzOrJXLaYkLp7gk2YaN368M7mj2Z7yLBV0CoVopS2tfRVJn
|
||||
fzaxyrkzmZKPKq+m8+UjnlwRW7yR+2RYlFNP3/KemB2i+nXd35f1QCZqb20Lmbbx
|
||||
jDc1CxESY1wzY5oqUGXeFapbM4YKhQQ5BK90AjVfss1ymBT5vhSjoJSIW2yeklcI
|
||||
F/WuQ/CrBlmODbiM2LsQMTSoYcAIOUaRcVh/7kvlOlQ=
|
||||
-----END RSA PRIVATE KEY-----
|
||||
|
||||
10. end entity certificate issued by subca, Bob
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIICNTCCAZ6gAwIBAgIBAzANBgkqhkiG9w0BAQQFADAxMQswCQYDVQQGEwJVUzEQ
|
||||
MA4GA1UEChMHRXhhbXBsZTEQMA4GA1UECxMHQ2xhc3MtMTAeFw0wOTA0MjcwMjI0
|
||||
MzdaFw0yOTAxMTIwMjI0MzdaMD8xCzAJBgNVBAYTAlVTMRAwDgYDVQQKEwdFeGFt
|
||||
cGxlMRAwDgYDVQQLEwdDbGFzcy0xMQwwCgYDVQQDEwNCb2IwgZ8wDQYJKoZIhvcN
|
||||
AQEBBQADgY0AMIGJAoGBANHxsJI6N5CawwUWJ63i2bvgdHzrsKUeBs7CXEIovPll
|
||||
+utfqwJGGkkiW9FVxQ2NQfMoHKdSrbLQaZ4I6U75yh40ZiSgSCELzlW8JC48kX7u
|
||||
txYJzszjT6lATW+mRdMoO0guxAS4NcldoFHZ0nLkAvhRRpZgdS+wdc0LODxeplqT
|
||||
AgMBAAGjTzBNMAsGA1UdDwQEAwID6DAdBgNVHQ4EFgQU2yqQyfYTig4K30lCbEsR
|
||||
rSrhM6UwHwYDVR0jBBgwFoAU9P5zT/FqcsZmKyAaeLTfMtPI8NowDQYJKoZIhvcN
|
||||
AQEEBQADgYEAn6j1wY0G5dieYdwUBAJuh6zP1Cu+J12NgdetHAaN6Q3tP339ToCi
|
||||
C2NQYvFSwOZ7CKf2ofQq5qWA4EFd7PNxpYaVjhhxzkeQRuv/r/sA3rH+01MPx5ob
|
||||
N1wXY5QmBOuHJIKroNH60u9GzOIGIANZuYWsluw4spWRpvOdqudJWlg=
|
||||
-----END CERTIFICATE-----
|
||||
|
||||
-----BEGIN RSA PRIVATE KEY-----
|
||||
Proc-Type: 4,ENCRYPTED
|
||||
DEK-Info: DES-EDE3-CBC,3DD8B45BA8A57B72
|
||||
|
||||
cC15d0phhzxu+Y3FMLu22WejN0JEVGCD0Qbwz73+ahVCqivd7aaipXfnuyuIJW12
|
||||
ZHKR0ixZUwezRqqM0/D4vKyFR9giJ14A5Tk7RFzimm0JqdJYRXrmVEp+QdVYbJFC
|
||||
5ncmU/KCAJcHwewixbjo5pkrWNDpIWeIqI8F6rvY1MLSMCCwYfr+1SP5U6AB3+1T
|
||||
yySvWwK+TIAgVMNjhDKlJ78BxQ3C/AMw5grAU0t2jmuuuXJPML72mQ95ZBgcJsRF
|
||||
S0walZGZlK+p9S/b4EVzO+oaR1icazH1WJTyuzKOOurlFjFk3tmsnhNuWQTkNjgV
|
||||
wKODHLA8E8tBajYAYmkQX+uQOmol9LXSOrQFrxvHF3dWC5giOtPYeh9ibEFx+RMu
|
||||
2EmkF/9VFxzh+kK9KL2qplm4K3HoL/v9g/LlKowjQlr7LoJRCRDOmESCUWX0JPPB
|
||||
nD01HvyRjgpUAeKtxR3hjH3CrUM1rdLAJaFi1RzgjvXeXhX5stD3X6UCWFbeBBh1
|
||||
yic4RIGYWjqE7RJRd/Q+/11rCkONg9stYcpe1PL5fJWSC8Sixo6XQTQDbxOJBQbr
|
||||
gCoUFfCcN8nOYdSe2wWrE/l7r/mRFYbwlErlpomSaxye5yzXhombnZ2k4jNKylEp
|
||||
TMsvFtVXFyoLWFqhtrv/Sg+0zDox1HMx+qzePYsz9+/rrS7ej6b5c8r6yqmg7nHn
|
||||
XM4REA46bWcAVjkLNpNZU4i0iURrkjuK0uVFYfnFIxrvGLys8dzH+xAfAHcP0zZ3
|
||||
/K54gAGk4ZVVXOt8JKOVxAOj2+8f0Gbf28leRx/VOJlEZBpU6UVg4g==
|
||||
-----END RSA PRIVATE KEY-----
|
||||
|
||||
10. end entity certificate issued by subca, Susan
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIICNzCCAaCgAwIBAgIBBDANBgkqhkiG9w0BAQQFADAxMQswCQYDVQQGEwJVUzEQ
|
||||
MA4GA1UEChMHRXhhbXBsZTEQMA4GA1UECxMHQ2xhc3MtMTAeFw0wOTA0MjcwMjI0
|
||||
MzhaFw0yOTAxMTIwMjI0MzhaMEExCzAJBgNVBAYTAlVTMRAwDgYDVQQKEwdFeGFt
|
||||
cGxlMRAwDgYDVQQLEwdDbGFzcy0xMQ4wDAYDVQQDEwVTdXNhbjCBnzANBgkqhkiG
|
||||
9w0BAQEFAAOBjQAwgYkCgYEAyPKlfep+EIIUOpZF3xtYUhAx79qEqe2RPRcH2YeR
|
||||
1ogM8+AZMdcXoiuDl4CFLzQwRv1DSKUZAPdPbROLVDsUn+IGvgn2jnE7ZQEUtQQJ
|
||||
+rorcasE7bo5MBPuno/0oQRi/4MZn6lX3qB13ZUHAvZH96oCF6C3Ro19LAwav1Lo
|
||||
FRcCAwEAAaNPME0wCwYDVR0PBAQDAgPoMB0GA1UdDgQWBBTCUH1tqQk96Pocr8Is
|
||||
tDKMoIRQljAfBgNVHSMEGDAWgBT0/nNP8WpyxmYrIBp4tN8y08jw2jANBgkqhkiG
|
||||
9w0BAQQFAAOBgQB3YXuTA+QfaImQ2aN/e27Nv5a/FMml6y6t0+pzt5hUYG2W0C2f
|
||||
5Hdmf3whNCA7zE5RVDQP0iuGBPgjvrABuN98Vimv2eTV+N5aYTak0Aav/OuR5Lpi
|
||||
tYhXMMg5gSmT+JDARba4CX+Ap1oAaNe9Mtv8L6FWdvBqfzzifDHWavdIWA==
|
||||
-----END CERTIFICATE-----
|
||||
|
||||
-----BEGIN RSA PRIVATE KEY-----
|
||||
Proc-Type: 4,ENCRYPTED
|
||||
DEK-Info: DES-EDE3-CBC,A03CB9ABBA747E7A
|
||||
|
||||
YhChWe6DOA1Ck5BAjWrHmPkHcS9x5pDw81p31gSf7SE9MCwfsvAIq9jZ7xol3cIJ
|
||||
5dhbXtBaJIRghke11McQ6zM2DE+9izCO4itedw94i95jSzgpEHTk6gwp9MuomSsm
|
||||
ytrqIhwEtVC8PaQmywqshKWnpDn3tZESwySNZjUjzHhyzn2Vuyrb0WaHmw3uk33O
|
||||
7muGNkmn/1yP1qRyJ3YSGcMNpk2zvJDZS5CfJH9sb00+LL4PTKg4dymw4Vjk7b5f
|
||||
P5JGLbFCBbQ73CwSNLsQGV4qGz7AnRhsmPmNughshOoLKSEAxUsRHE67qyl+Flx0
|
||||
KZEGeKZUJD9fzgMMdNoYk0Pg9zxzM1oNewxsFk2tTrtMfGq+XFokWKfJoQWguStY
|
||||
BJWETGrSbXiDMIE93gX40C2zlT06ziOYfFCXeVRcBarolonTrOXt3RZzsQpY4lTz
|
||||
AAGrb2I9ZByL59ujfniTqljtBpuCKAm+jS0ofcGlQQ0MawtSOeSbQkFKHcKpcK0V
|
||||
cKMFL3sEzeJf+1LCt7Xnt4gaoXtTpVoWVWFZkghDSmIAHzKaWHAHn5PcUjwAAZHb
|
||||
47IRq+pe1WLc+tb61+E2jkhFC06QOSxmWSV3CHfMZTxkXX7B7RCiqs+tVH5Vlj/C
|
||||
ZhkSfmANUVPW1H0KXsDq6lzrEnvaZXZIzTLvj+OsLcG1anXdwPn0NPikfRU0GTvA
|
||||
fCzg7ZWlexJgl5I48X7AzpHpTPGAHGeNpYjzGWbxmC0KREcAM0yD15uFVac/ZIVI
|
||||
TO0icmSiRoshC70zo9/u2hUP1e4+s1vl0laq0WjGfFORE1JZ1Cs2Dg==
|
||||
-----END RSA PRIVATE KEY-----
|
||||
|
||||
|
|
@ -0,0 +1,219 @@
|
|||
#
|
||||
# Copyright (c) 2009, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
#
|
||||
# This code is free software; you can redistribute it and/or modify it
|
||||
# under the terms of the GNU General Public License version 2 only, as
|
||||
# published by the Free Software Foundation.
|
||||
#
|
||||
# This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
# version 2 for more details (a copy is included in the LICENSE file that
|
||||
# accompanied this code).
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License version
|
||||
# 2 along with this work; if not, write to the Free Software Foundation,
|
||||
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
#
|
||||
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
# or visit www.oracle.com if you need additional information or have any
|
||||
# questions.
|
||||
#
|
||||
|
||||
#!/bin/ksh
|
||||
#
|
||||
# needs ksh to run the script.
|
||||
|
||||
# generate a self-signed root certificate
|
||||
if [ ! -f root/root_cert.pem ]; then
|
||||
if [ ! -d root ]; then
|
||||
mkdir root
|
||||
fi
|
||||
|
||||
openssl req -x509 -newkey rsa:1024 -keyout root/root_key.pem \
|
||||
-out root/root_cert.pem -subj "/C=US/O=Example" \
|
||||
-config openssl.cnf -reqexts cert_issuer -days 7650 \
|
||||
-passin pass:passphrase -passout pass:passphrase
|
||||
fi
|
||||
|
||||
# generate a sele-issued root crl issuer certificate
|
||||
if [ ! -f root/top_crlissuer_cert.pem ]; then
|
||||
if [ ! -d root ]; then
|
||||
mkdir root
|
||||
fi
|
||||
|
||||
openssl req -newkey rsa:1024 -keyout root/top_crlissuer_key.pem \
|
||||
-out root/top_crlissuer_req.pem -subj "/C=US/O=Example" -days 7650 \
|
||||
-passin pass:passphrase -passout pass:passphrase
|
||||
|
||||
openssl x509 -req -in root/top_crlissuer_req.pem -extfile openssl.cnf \
|
||||
-extensions crl_issuer -CA root/root_cert.pem \
|
||||
-CAkey root/root_key.pem -out root/top_crlissuer_cert.pem \
|
||||
-CAcreateserial -CAserial root/root_cert.srl -days 7200 \
|
||||
-passin pass:passphrase
|
||||
fi
|
||||
|
||||
# generate subca cert issuer and crl iuuser certificates
|
||||
if [ ! -f subca/subca_cert.pem ]; then
|
||||
if [ ! -d subca ]; then
|
||||
mkdir subca
|
||||
fi
|
||||
|
||||
openssl req -newkey rsa:1024 -keyout subca/subca_key.pem \
|
||||
-out subca/subca_req.pem -subj "/C=US/O=Example/OU=Class-1" \
|
||||
-days 7650 -passin pass:passphrase -passout pass:passphrase
|
||||
|
||||
openssl x509 -req -in subca/subca_req.pem -extfile openssl.cnf \
|
||||
-extensions cert_issuer -CA root/root_cert.pem \
|
||||
-CAkey root/root_key.pem -out subca/subca_cert.pem -CAcreateserial \
|
||||
-CAserial root/root_cert.srl -days 7200 -passin pass:passphrase
|
||||
|
||||
openssl req -newkey rsa:1024 -keyout subca/subca_crlissuer_key.pem \
|
||||
-out subca/subca_crlissuer_req.pem -subj "/C=US/O=Example/OU=Class-1" \
|
||||
-days 7650 -passin pass:passphrase -passout pass:passphrase
|
||||
|
||||
openssl x509 -req -in subca/subca_crlissuer_req.pem -extfile openssl.cnf \
|
||||
-extensions crl_issuer -CA root/root_cert.pem \
|
||||
-CAkey root/root_key.pem -out subca/subca_crlissuer_cert.pem \
|
||||
-CAcreateserial -CAserial root/root_cert.srl -days 7200 \
|
||||
-passin pass:passphrase
|
||||
fi
|
||||
|
||||
# generate dumca cert issuer and crl iuuser certificates
|
||||
if [ ! -f dumca/dumca_cert.pem ]; then
|
||||
if [ ! -d sumca ]; then
|
||||
mkdir dumca
|
||||
fi
|
||||
|
||||
openssl req -newkey rsa:1024 -keyout dumca/dumca_key.pem \
|
||||
-out dumca/dumca_req.pem -subj "/C=US/O=Example/OU=Class-D" \
|
||||
-days 7650 -passin pass:passphrase -passout pass:passphrase
|
||||
|
||||
openssl x509 -req -in dumca/dumca_req.pem -extfile openssl.cnf \
|
||||
-extensions cert_issuer -CA root/root_cert.pem \
|
||||
-CAkey root/root_key.pem -out dumca/dumca_cert.pem \
|
||||
-CAcreateserial -CAserial root/root_cert.srl -days 7200 \
|
||||
-passin pass:passphrase
|
||||
|
||||
openssl req -newkey rsa:1024 -keyout dumca/dumca_crlissuer_key.pem \
|
||||
-out dumca/dumca_crlissuer_req.pem -subj "/C=US/O=Example/OU=Class-D" \
|
||||
-days 7650 -passin pass:passphrase -passout pass:passphrase
|
||||
|
||||
openssl x509 -req -in dumca/dumca_crlissuer_req.pem \
|
||||
-extfile openssl.cnf -extensions crl_issuer -CA root/root_cert.pem \
|
||||
-CAkey root/root_key.pem -out dumca/dumca_crlissuer_cert.pem \
|
||||
-CAcreateserial -CAserial root/root_cert.srl -days 7200 \
|
||||
-passin pass:passphrase
|
||||
fi
|
||||
|
||||
# generate certifiacte for Alice
|
||||
if [ ! -f subca/alice/alice_cert.pem ]; then
|
||||
if [ ! -d subca/alice ]; then
|
||||
mkdir -p subca/alice
|
||||
fi
|
||||
|
||||
openssl req -newkey rsa:1024 -keyout subca/alice/alice_key.pem \
|
||||
-out subca/alice/alice_req.pem \
|
||||
-subj "/C=US/O=Example/OU=Class-1/CN=Alice" -days 7650 \
|
||||
-passin pass:passphrase -passout pass:passphrase
|
||||
|
||||
openssl x509 -req -in subca/alice/alice_req.pem \
|
||||
-extfile openssl.cnf -extensions ee_of_subca \
|
||||
-CA subca/subca_cert.pem -CAkey subca/subca_key.pem \
|
||||
-out subca/alice/alice_cert.pem -CAcreateserial \
|
||||
-CAserial subca/subca_cert.srl -days 7200 -passin pass:passphrase
|
||||
fi
|
||||
|
||||
# generate certifiacte for Bob
|
||||
if [ ! -f subca/bob/bob_cert.pem ]; then
|
||||
if [ ! -d subca/bob ]; then
|
||||
mkdir -p subca/bob
|
||||
fi
|
||||
|
||||
openssl req -newkey rsa:1024 -keyout subca/bob/bob_key.pem \
|
||||
-out subca/bob/bob_req.pem \
|
||||
-subj "/C=US/O=Example/OU=Class-1/CN=Bob" -days 7650 \
|
||||
-passin pass:passphrase -passout pass:passphrase
|
||||
|
||||
openssl x509 -req -in subca/bob/bob_req.pem \
|
||||
-extfile openssl.cnf -extensions ee_of_subca \
|
||||
-CA subca/subca_cert.pem -CAkey subca/subca_key.pem \
|
||||
-out subca/bob/bob_cert.pem -CAcreateserial \
|
||||
-CAserial subca/subca_cert.srl -days 7200 -passin pass:passphrase
|
||||
fi
|
||||
|
||||
# generate certifiacte for Susan
|
||||
if [ ! -f subca/susan/susan_cert.pem ]; then
|
||||
if [ ! -d subca/susan ]; then
|
||||
mkdir -p subca/susan
|
||||
fi
|
||||
|
||||
openssl req -newkey rsa:1024 -keyout subca/susan/susan_key.pem \
|
||||
-out subca/susan/susan_req.pem \
|
||||
-subj "/C=US/O=Example/OU=Class-1/CN=Susan" -days 7650 \
|
||||
-passin pass:passphrase -passout pass:passphrase
|
||||
|
||||
openssl x509 -req -in subca/susan/susan_req.pem -extfile openssl.cnf \
|
||||
-extensions ee_of_subca -CA subca/subca_cert.pem \
|
||||
-CAkey subca/subca_key.pem -out subca/susan/susan_cert.pem \
|
||||
-CAcreateserial -CAserial subca/subca_cert.srl -days 7200 \
|
||||
-passin pass:passphrase
|
||||
fi
|
||||
|
||||
|
||||
# generate the top CRL
|
||||
if [ ! -f root/top_crl.pem ]; then
|
||||
if [ ! -d root ]; then
|
||||
mkdir root
|
||||
fi
|
||||
|
||||
if [ ! -f root/index.txt ]; then
|
||||
touch root/index.txt
|
||||
echo 00 > root/crlnumber
|
||||
fi
|
||||
|
||||
openssl ca -gencrl -config openssl.cnf -name ca_top -crldays 7000 \
|
||||
-crl_reason superseded -keyfile root/top_crlissuer_key.pem \
|
||||
-cert root/top_crlissuer_cert.pem -out root/top_crl.pem \
|
||||
-passin pass:passphrase
|
||||
fi
|
||||
|
||||
# revoke dumca
|
||||
openssl ca -revoke dumca/dumca_cert.pem -config openssl.cnf \
|
||||
-name ca_top -crl_reason superseded \
|
||||
-keyfile root/top_crlissuer_key.pem -cert root/top_crlissuer_cert.pem \
|
||||
-passin pass:passphrase
|
||||
|
||||
openssl ca -gencrl -config openssl.cnf -name ca_top -crldays 7000 \
|
||||
-crl_reason superseded -keyfile root/top_crlissuer_key.pem \
|
||||
-cert root/top_crlissuer_cert.pem -out root/top_crl.pem \
|
||||
-passin pass:passphrase
|
||||
|
||||
# revoke for subca
|
||||
if [ ! -f subca/subca_crl.pem ]; then
|
||||
if [ ! -d subca ]; then
|
||||
mkdir subca
|
||||
fi
|
||||
|
||||
if [ ! -f subca/index.txt ]; then
|
||||
touch subca/index.txt
|
||||
echo 00 > subca/crlnumber
|
||||
fi
|
||||
|
||||
openssl ca -gencrl -config openssl.cnf -name ca_subca -crldays 7000 \
|
||||
-crl_reason superseded -keyfile subca/subca_crlissuer_key.pem \
|
||||
-cert subca/subca_crlissuer_cert.pem -out subca/subca_crl.pem \
|
||||
-passin pass:passphrase
|
||||
fi
|
||||
|
||||
# revoke susan
|
||||
openssl ca -revoke subca/susan/susan_cert.pem -config openssl.cnf \
|
||||
-name ca_subca -crl_reason superseded \
|
||||
-keyfile subca/subca_crlissuer_key.pem \
|
||||
-cert subca/subca_crlissuer_cert.pem -passin pass:passphrase
|
||||
|
||||
openssl ca -gencrl -config openssl.cnf -name ca_subca -crldays 7000 \
|
||||
-crl_reason superseded -keyfile subca/subca_crlissuer_key.pem \
|
||||
-cert subca/subca_crlissuer_cert.pem -out subca/subca_crl.pem \
|
||||
-passin pass:passphrase
|
||||
|
|
@ -0,0 +1,204 @@
|
|||
#
|
||||
# Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
|
||||
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
#
|
||||
# This code is free software; you can redistribute it and/or modify it
|
||||
# under the terms of the GNU General Public License version 2 only, as
|
||||
# published by the Free Software Foundation.
|
||||
#
|
||||
# This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
# version 2 for more details (a copy is included in the LICENSE file that
|
||||
# accompanied this code).
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License version
|
||||
# 2 along with this work; if not, write to the Free Software Foundation,
|
||||
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
#
|
||||
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
# or visit www.oracle.com if you need additional information or have any
|
||||
# questions.
|
||||
#
|
||||
|
||||
#
|
||||
# OpenSSL configuration file.
|
||||
#
|
||||
|
||||
HOME = .
|
||||
RANDFILE = $ENV::HOME/.rnd
|
||||
|
||||
[ ca ]
|
||||
default_ca = CA_default
|
||||
|
||||
[ CA_default ]
|
||||
dir = ./top
|
||||
certs = $dir/certs
|
||||
crl_dir = $dir/crl
|
||||
database = $dir/index.txt
|
||||
unique_subject = no
|
||||
new_certs_dir = $dir/newcerts
|
||||
certificate = $dir/cacert.pem
|
||||
serial = $dir/serial
|
||||
crlnumber = $dir/crlnumber
|
||||
crl = $dir/crl.pem
|
||||
private_key = $dir/private/cakey.pem
|
||||
RANDFILE = $dir/private/.rand
|
||||
x509_extensions = v3_ca
|
||||
|
||||
name_opt = ca_default
|
||||
cert_opt = ca_default
|
||||
|
||||
default_days = 7650
|
||||
default_crl_days = 30
|
||||
default_md = sha1
|
||||
preserve = no
|
||||
|
||||
policy = policy_anything
|
||||
|
||||
[ ca_top ]
|
||||
dir = ./root
|
||||
certs = $dir/certs
|
||||
crl_dir = $dir/crl
|
||||
database = $dir/index.txt
|
||||
unique_subject = no
|
||||
new_certs_dir = $dir/newcerts
|
||||
certificate = $dir/cacert.pem
|
||||
serial = $dir/serial
|
||||
crlnumber = $dir/crlnumber
|
||||
crl = $dir/crl.pem
|
||||
private_key = $dir/private/cakey.pem
|
||||
RANDFILE = $dir/private/.rand
|
||||
|
||||
x509_extensions = v3_ca
|
||||
|
||||
name_opt = ca_default
|
||||
cert_opt = ca_default
|
||||
|
||||
default_days = 7650
|
||||
default_crl_days = 30
|
||||
default_md = sha1
|
||||
preserve = no
|
||||
|
||||
policy = policy_anything
|
||||
|
||||
[ ca_subca ]
|
||||
dir = ./subca
|
||||
certs = $dir/certs
|
||||
crl_dir = $dir/crl
|
||||
database = $dir/index.txt
|
||||
unique_subject = no
|
||||
new_certs_dir = $dir/newcerts
|
||||
|
||||
certificate = $dir/cacert.pem
|
||||
serial = $dir/serial
|
||||
crlnumber = $dir/crlnumber
|
||||
crl = $dir/crl.pem
|
||||
private_key = $dir/private/cakey.pem
|
||||
RANDFILE = $dir/private/.rand
|
||||
|
||||
x509_extensions = usr_cert
|
||||
|
||||
name_opt = ca_default
|
||||
cert_opt = ca_default
|
||||
|
||||
default_days = 7650
|
||||
default_crl_days = 30
|
||||
default_md = sha1
|
||||
preserve = no
|
||||
|
||||
policy = policy_anything
|
||||
|
||||
[ policy_match ]
|
||||
countryName = match
|
||||
stateOrProvinceName = match
|
||||
organizationName = match
|
||||
organizationalUnitName = optional
|
||||
commonName = supplied
|
||||
emailAddress = optional
|
||||
|
||||
[ policy_anything ]
|
||||
countryName = optional
|
||||
stateOrProvinceName = optional
|
||||
localityName = optional
|
||||
organizationName = optional
|
||||
organizationalUnitName = optional
|
||||
commonName = supplied
|
||||
emailAddress = optional
|
||||
|
||||
[ req ]
|
||||
default_bits = 1024
|
||||
default_keyfile = privkey.pem
|
||||
distinguished_name = req_distinguished_name
|
||||
attributes = req_attributes
|
||||
x509_extensions = v3_ca
|
||||
|
||||
string_mask = nombstr
|
||||
|
||||
[ req_distinguished_name ]
|
||||
countryName = Country Name (2 letter code)
|
||||
countryName_default = NO
|
||||
countryName_min = 2
|
||||
countryName_max = 2
|
||||
|
||||
stateOrProvinceName = State or Province Name (full name)
|
||||
stateOrProvinceName_default = A-State
|
||||
|
||||
localityName = Locality Name (eg, city)
|
||||
|
||||
0.organizationName = Organization Name (eg, company)
|
||||
0.organizationName_default = Internet Widgits Pty Ltd
|
||||
|
||||
organizationalUnitName = Organizational Unit Name (eg, section)
|
||||
|
||||
commonName = Common Name (eg, YOUR name)
|
||||
commonName_max = 64
|
||||
|
||||
emailAddress = Email Address
|
||||
emailAddress_max = 64
|
||||
|
||||
[ req_attributes ]
|
||||
challengePassword = A challenge password
|
||||
challengePassword_min = 4
|
||||
challengePassword_max = 20
|
||||
unstructuredName = An optional company name
|
||||
|
||||
|
||||
[ usr_cert ]
|
||||
keyUsage = nonRepudiation, digitalSignature, keyEncipherment
|
||||
|
||||
subjectKeyIdentifier = hash
|
||||
authorityKeyIdentifier = keyid,issuer
|
||||
|
||||
[ v3_req ]
|
||||
basicConstraints = CA:FALSE
|
||||
keyUsage = nonRepudiation, digitalSignature, keyEncipherment
|
||||
subjectAltName = email:example@openjdk.net, RID:1.2.3.4:true
|
||||
|
||||
[ v3_ca ]
|
||||
subjectKeyIdentifier = hash
|
||||
authorityKeyIdentifier = keyid:always,issuer:always
|
||||
basicConstraints = critical,CA:true
|
||||
keyUsage = keyCertSign
|
||||
|
||||
[ cert_issuer ]
|
||||
subjectKeyIdentifier = hash
|
||||
authorityKeyIdentifier = keyid:always,issuer:always
|
||||
basicConstraints = critical,CA:true
|
||||
keyUsage = keyCertSign
|
||||
|
||||
|
||||
[ crl_issuer ]
|
||||
subjectKeyIdentifier = hash
|
||||
authorityKeyIdentifier = keyid:always,issuer:always
|
||||
keyUsage = cRLSign
|
||||
|
||||
|
||||
[ crl_ext ]
|
||||
authorityKeyIdentifier = keyid:always,issuer:always
|
||||
|
||||
[ ee_of_subca ]
|
||||
keyUsage = nonRepudiation, digitalSignature, keyEncipherment, keyAgreement
|
||||
|
||||
subjectKeyIdentifier = hash
|
||||
authorityKeyIdentifier = keyid,issuer
|
||||
|
|
@ -0,0 +1,155 @@
|
|||
/*
|
||||
* Copyright (c) 2009, 2025, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @test
|
||||
*
|
||||
* @bug 6845286
|
||||
* @summary Add regression test for name constraints
|
||||
* @enablePreview
|
||||
* @author Xuelei Fan
|
||||
*/
|
||||
|
||||
import java.io.*;
|
||||
import java.net.SocketException;
|
||||
import java.security.PEMDecoder;
|
||||
import java.util.*;
|
||||
import java.security.Security;
|
||||
import java.security.cert.*;
|
||||
import java.security.cert.CertPathValidatorException.BasicReason;
|
||||
|
||||
public class NameConstraintsWithRID {
|
||||
|
||||
static String selfSignedCertStr =
|
||||
"-----BEGIN CERTIFICATE-----\n" +
|
||||
"MIICTjCCAbegAwIBAgIJAIoSzC1A/k4vMA0GCSqGSIb3DQEBBQUAMB8xCzAJBgNV\n" +
|
||||
"BAYTAlVTMRAwDgYDVQQKEwdFeGFtcGxlMB4XDTA5MDUwNzA5MjcxMloXDTMwMDQx\n" +
|
||||
"NzA5MjcxMlowHzELMAkGA1UEBhMCVVMxEDAOBgNVBAoTB0V4YW1wbGUwgZ8wDQYJ\n" +
|
||||
"KoZIhvcNAQEBBQADgY0AMIGJAoGBANXzlv5Fn2cdgBRdEK/37/o8rqQXIRIMZqX6\n" +
|
||||
"BPuo46Cdhctv+n3hu5bj/PwgJVbAJcqcQfDudSSF5gwGlRqDX9vekPSS47XZXjOZ\n" +
|
||||
"qFcnDoWP0gSQXLYVVtjuItkecTrPyUE5v2lRIAh13MGKOSh3ZsrtFvj7Y5d9EqIP\n" +
|
||||
"SLxWWPuHAgMBAAGjgZEwgY4wHQYDVR0OBBYEFFydJvQMB2j4EDHW2bQabNsPUvDt\n" +
|
||||
"ME8GA1UdIwRIMEaAFFydJvQMB2j4EDHW2bQabNsPUvDtoSOkITAfMQswCQYDVQQG\n" +
|
||||
"EwJVUzEQMA4GA1UEChMHRXhhbXBsZYIJAIoSzC1A/k4vMA8GA1UdEwEB/wQFMAMB\n" +
|
||||
"Af8wCwYDVR0PBAQDAgIEMA0GCSqGSIb3DQEBBQUAA4GBAHgoopmZ1Q4qXhMDbbYQ\n" +
|
||||
"YCi4Cg6cXPFblx5gzhWu/6l9SkvZbAZiLszgyMq5dGj9WyTtibNEp232dQsKTFu7\n" +
|
||||
"3ag0DiFqoQ8btgvbwBlzhnRagoeVFjhuBBQutOScw7x8NCSBkZQow+31127mwu3y\n" +
|
||||
"YGYhEmI2dNmgbv1hVYTGmLXW\n" +
|
||||
"-----END CERTIFICATE-----";
|
||||
|
||||
static String subCaCertStr =
|
||||
"-----BEGIN CERTIFICATE-----\n" +
|
||||
"MIICdTCCAd6gAwIBAgIJAL+MYVyy7k5YMA0GCSqGSIb3DQEBBQUAMB8xCzAJBgNV\n" +
|
||||
"BAYTAlVTMRAwDgYDVQQKEwdFeGFtcGxlMB4XDTA5MDUwNzA5MjcxNFoXDTI5MDEy\n" +
|
||||
"MjA5MjcxNFowMTELMAkGA1UEBhMCVVMxEDAOBgNVBAoTB0V4YW1wbGUxEDAOBgNV\n" +
|
||||
"BAsTB0NsYXNzLTEwgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBAM2mwX8dhP3M\n" +
|
||||
"i6ATRsd0wco+c7rsyEbP0CRQunVIP8/kOL8+zyQix+QZquY23tvBCbia424GXDkT\n" +
|
||||
"irvK/M4yGzrdS51hA5dlH3SHY3CWOAqEPqKtNLn1My4MWtTiUWbHi0YjFuOv0BXz\n" +
|
||||
"x9lTEfMf+3QcOgO5FitcqHIMP4jIlT+lAgMBAAGjgaYwgaMwHQYDVR0OBBYEFJHg\n" +
|
||||
"eyEWcjxcAwc01BPQrau/4HJaME8GA1UdIwRIMEaAFFydJvQMB2j4EDHW2bQabNsP\n" +
|
||||
"UvDtoSOkITAfMQswCQYDVQQGEwJVUzEQMA4GA1UEChMHRXhhbXBsZYIJAIoSzC1A\n" +
|
||||
"/k4vMA8GA1UdEwEB/wQFMAMBAf8wCwYDVR0PBAQDAgIEMBMGA1UdHgQMMAqhCDAG\n" +
|
||||
"iAQqAwQFMA0GCSqGSIb3DQEBBQUAA4GBAI3CDQWZiTlVVVqfCiZwc/yIL7G5bu2g\n" +
|
||||
"ccgVz9PyKfTpq8vk59S23TvPwdPt4ZVx4RSoar9ONtbrcLxfP3X6WQ7e9popWNZV\n" +
|
||||
"q49YfyU1tD5HFuxj7CAsvfykuRo4ovXaTCVWlTMi7fJJdzU0Eb4xkXXhiWT/RbHG\n" +
|
||||
"R7J+8ROMZ+nR\n" +
|
||||
"-----END CERTIFICATE-----";
|
||||
|
||||
static String targetCertStr =
|
||||
"-----BEGIN CERTIFICATE-----\n" +
|
||||
"MIICUDCCAbmgAwIBAgIJAOA8c10w019XMA0GCSqGSIb3DQEBBQUAMDExCzAJBgNV\n" +
|
||||
"BAYTAlVTMRAwDgYDVQQKEwdFeGFtcGxlMRAwDgYDVQQLEwdDbGFzcy0xMB4XDTA5\n" +
|
||||
"MDUwNzEwMjY0M1oXDTI5MDEyMjEwMjY0M1owQTELMAkGA1UEBhMCVVMxEDAOBgNV\n" +
|
||||
"BAoTB0V4YW1wbGUxEDAOBgNVBAsTB0NsYXNzLTExDjAMBgNVBAMTBVN1c2FuMIGf\n" +
|
||||
"MA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDlmyS8SskMX3mreD95oBaXUGNvPTK0\n" +
|
||||
"39IBdxle2TpJEBL/BcS4QUb2+67WjrXhUZWFtpc4RzywfvSSxZH2wbwDDJPs56OC\n" +
|
||||
"Eczsdnqe7gOroYm2TMfY0/pItgP3mRkhJpxAWFc/y7Qr8jJbPmKfiYbYROp1eR2t\n" +
|
||||
"BrjUiUTrAtM7GwIDAQABo2AwXjALBgNVHQ8EBAMCA+gwDwYDVR0RBAgwBogEKgME\n" +
|
||||
"BTAdBgNVHQ4EFgQUyqtfkWtPah5J658LHN8CEGIgAbgwHwYDVR0jBBgwFoAUkeB7\n" +
|
||||
"IRZyPFwDBzTUE9Ctq7/gclowDQYJKoZIhvcNAQEFBQADgYEAnwaLBteuJhXF56Rg\n" +
|
||||
"l8FIEzgJtT4yu/8WsYjhN6/aLGkgJ37VavWdhjwXIb1RVJE/ab3hTbWF5ht7jMcQ\n" +
|
||||
"/WnD8R8CpwEEX/n2wpb3zMHZ8zT7k0mWYm10mPHw1psjOUvJd/zB4gT4tc2A2soM\n" +
|
||||
"FbcNIaCtg8blO5ImdOz5hAi+NuY=\n" +
|
||||
"-----END CERTIFICATE-----";
|
||||
|
||||
private static final PEMDecoder PEM_DECODER = PEMDecoder.of();
|
||||
|
||||
private static CertPath generateCertificatePath()
|
||||
throws CertificateException {
|
||||
// generate certificate from cert strings
|
||||
CertificateFactory cf = CertificateFactory.getInstance("X.509");
|
||||
|
||||
Certificate targetCert = PEM_DECODER.decode(targetCertStr, X509Certificate.class);
|
||||
|
||||
Certificate subCaCert = PEM_DECODER.decode(subCaCertStr, X509Certificate.class);
|
||||
|
||||
Certificate selfSignedCert = PEM_DECODER.decode(selfSignedCertStr, X509Certificate.class);
|
||||
|
||||
// generate certification path
|
||||
List<Certificate> list = Arrays.asList(targetCert, subCaCert, selfSignedCert);
|
||||
|
||||
return cf.generateCertPath(list);
|
||||
}
|
||||
|
||||
private static Set<TrustAnchor> generateTrustAnchors()
|
||||
throws CertificateException {
|
||||
// generate certificate from cert string
|
||||
X509Certificate selfSignedCert = PEM_DECODER.decode(selfSignedCertStr, X509Certificate.class);
|
||||
|
||||
// generate a trust anchor
|
||||
TrustAnchor anchor =
|
||||
new TrustAnchor(selfSignedCert, null);
|
||||
|
||||
return Collections.singleton(anchor);
|
||||
}
|
||||
|
||||
public static void main(String args[]) throws Exception {
|
||||
CertPath path = generateCertificatePath();
|
||||
Set<TrustAnchor> anchors = generateTrustAnchors();
|
||||
|
||||
PKIXParameters params = new PKIXParameters(anchors);
|
||||
|
||||
// disable certificate revocation checking
|
||||
params.setRevocationEnabled(false);
|
||||
|
||||
// set the validation time
|
||||
params.setDate(new Date(109, 5, 8)); // 2009-05-01
|
||||
|
||||
// disable OCSP checker
|
||||
Security.setProperty("ocsp.enable", "false");
|
||||
|
||||
// disable CRL checker
|
||||
System.setProperty("com.sun.security.enableCRLDP", "false");
|
||||
|
||||
CertPathValidator validator = CertPathValidator.getInstance("PKIX");
|
||||
|
||||
try {
|
||||
validator.validate(path, params);
|
||||
throw new Exception(
|
||||
"the subjectAltName is excluded by NameConstraints, " +
|
||||
"should thrown CertPathValidatorException");
|
||||
} catch (CertPathValidatorException uoe) {
|
||||
// that is the expected exception.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,160 @@
|
|||
/*
|
||||
* Copyright (c) 2009, 2025, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @test
|
||||
*
|
||||
* @bug 6845286
|
||||
* @summary Add regression test for name constraints
|
||||
* @enablePreview
|
||||
* @author Xuelei Fan
|
||||
*/
|
||||
|
||||
import java.io.*;
|
||||
import java.net.SocketException;
|
||||
import java.security.PEMDecoder;
|
||||
import java.util.*;
|
||||
import java.security.Security;
|
||||
import java.security.cert.*;
|
||||
import java.security.cert.CertPathValidatorException.BasicReason;
|
||||
|
||||
public class NameConstraintsWithUnexpectedRID {
|
||||
|
||||
static String selfSignedCertStr =
|
||||
"-----BEGIN CERTIFICATE-----\n" +
|
||||
"MIICTjCCAbegAwIBAgIJAIoSzC1A/k4vMA0GCSqGSIb3DQEBBQUAMB8xCzAJBgNV\n" +
|
||||
"BAYTAlVTMRAwDgYDVQQKEwdFeGFtcGxlMB4XDTA5MDUwNzA5MjcxMloXDTMwMDQx\n" +
|
||||
"NzA5MjcxMlowHzELMAkGA1UEBhMCVVMxEDAOBgNVBAoTB0V4YW1wbGUwgZ8wDQYJ\n" +
|
||||
"KoZIhvcNAQEBBQADgY0AMIGJAoGBANXzlv5Fn2cdgBRdEK/37/o8rqQXIRIMZqX6\n" +
|
||||
"BPuo46Cdhctv+n3hu5bj/PwgJVbAJcqcQfDudSSF5gwGlRqDX9vekPSS47XZXjOZ\n" +
|
||||
"qFcnDoWP0gSQXLYVVtjuItkecTrPyUE5v2lRIAh13MGKOSh3ZsrtFvj7Y5d9EqIP\n" +
|
||||
"SLxWWPuHAgMBAAGjgZEwgY4wHQYDVR0OBBYEFFydJvQMB2j4EDHW2bQabNsPUvDt\n" +
|
||||
"ME8GA1UdIwRIMEaAFFydJvQMB2j4EDHW2bQabNsPUvDtoSOkITAfMQswCQYDVQQG\n" +
|
||||
"EwJVUzEQMA4GA1UEChMHRXhhbXBsZYIJAIoSzC1A/k4vMA8GA1UdEwEB/wQFMAMB\n" +
|
||||
"Af8wCwYDVR0PBAQDAgIEMA0GCSqGSIb3DQEBBQUAA4GBAHgoopmZ1Q4qXhMDbbYQ\n" +
|
||||
"YCi4Cg6cXPFblx5gzhWu/6l9SkvZbAZiLszgyMq5dGj9WyTtibNEp232dQsKTFu7\n" +
|
||||
"3ag0DiFqoQ8btgvbwBlzhnRagoeVFjhuBBQutOScw7x8NCSBkZQow+31127mwu3y\n" +
|
||||
"YGYhEmI2dNmgbv1hVYTGmLXW\n" +
|
||||
"-----END CERTIFICATE-----";
|
||||
|
||||
static String subCaCertStr =
|
||||
"-----BEGIN CERTIFICATE-----\n" +
|
||||
"MIICdTCCAd6gAwIBAgIJAL+MYVyy7k5YMA0GCSqGSIb3DQEBBQUAMB8xCzAJBgNV\n" +
|
||||
"BAYTAlVTMRAwDgYDVQQKEwdFeGFtcGxlMB4XDTA5MDUwNzA5MjcxNFoXDTI5MDEy\n" +
|
||||
"MjA5MjcxNFowMTELMAkGA1UEBhMCVVMxEDAOBgNVBAoTB0V4YW1wbGUxEDAOBgNV\n" +
|
||||
"BAsTB0NsYXNzLTEwgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBAM2mwX8dhP3M\n" +
|
||||
"i6ATRsd0wco+c7rsyEbP0CRQunVIP8/kOL8+zyQix+QZquY23tvBCbia424GXDkT\n" +
|
||||
"irvK/M4yGzrdS51hA5dlH3SHY3CWOAqEPqKtNLn1My4MWtTiUWbHi0YjFuOv0BXz\n" +
|
||||
"x9lTEfMf+3QcOgO5FitcqHIMP4jIlT+lAgMBAAGjgaYwgaMwHQYDVR0OBBYEFJHg\n" +
|
||||
"eyEWcjxcAwc01BPQrau/4HJaME8GA1UdIwRIMEaAFFydJvQMB2j4EDHW2bQabNsP\n" +
|
||||
"UvDtoSOkITAfMQswCQYDVQQGEwJVUzEQMA4GA1UEChMHRXhhbXBsZYIJAIoSzC1A\n" +
|
||||
"/k4vMA8GA1UdEwEB/wQFMAMBAf8wCwYDVR0PBAQDAgIEMBMGA1UdHgQMMAqhCDAG\n" +
|
||||
"iAQqAwQFMA0GCSqGSIb3DQEBBQUAA4GBAI3CDQWZiTlVVVqfCiZwc/yIL7G5bu2g\n" +
|
||||
"ccgVz9PyKfTpq8vk59S23TvPwdPt4ZVx4RSoar9ONtbrcLxfP3X6WQ7e9popWNZV\n" +
|
||||
"q49YfyU1tD5HFuxj7CAsvfykuRo4ovXaTCVWlTMi7fJJdzU0Eb4xkXXhiWT/RbHG\n" +
|
||||
"R7J+8ROMZ+nR\n" +
|
||||
"-----END CERTIFICATE-----";
|
||||
|
||||
static String targetCertStr =
|
||||
"-----BEGIN CERTIFICATE-----\n" +
|
||||
"MIICTzCCAbigAwIBAgIJAOA8c10w019UMA0GCSqGSIb3DQEBBQUAMDExCzAJBgNV\n" +
|
||||
"BAYTAlVTMRAwDgYDVQQKEwdFeGFtcGxlMRAwDgYDVQQLEwdDbGFzcy0xMB4XDTA5\n" +
|
||||
"MDUwNzA5NTg0OVoXDTI5MDEyMjA5NTg0OVowQTELMAkGA1UEBhMCVVMxEDAOBgNV\n" +
|
||||
"BAoTB0V4YW1wbGUxEDAOBgNVBAsTB0NsYXNzLTExDjAMBgNVBAMTBUFsaWNlMIGf\n" +
|
||||
"MA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDfekJF8IZeOe3Ff1rexVyx9yTmPSKh\n" +
|
||||
"itEW7tW9m8DgqLGDptJLmbexvUCWNkFquQW1J8sjzjqrkIk8amA2SlHQ6Z15RoxC\n" +
|
||||
"E19qi5V5ms97X3lyuJcwwtT24J5PBk9ic/V6zclsNXSj/NoqlciKMxyvRy9zWk6Z\n" +
|
||||
"W5cVDf7DTzN2cwIDAQABo18wXTALBgNVHQ8EBAMCA+gwDgYDVR0RBAcwBYgDKgME\n" +
|
||||
"MB0GA1UdDgQWBBRh8rvMhT17VI+S3pCVzTwQzVMjOTAfBgNVHSMEGDAWgBSR4Hsh\n" +
|
||||
"FnI8XAMHNNQT0K2rv+ByWjANBgkqhkiG9w0BAQUFAAOBgQCNDnJ0Jz37+SmO9uRJ\n" +
|
||||
"z5Rr15oJAKsde5LGhghHZwTTYInOwGOYAABkWRB7JhUHNjIoQg9veqObSHEgcYMh\n" +
|
||||
"ZmO3rklIxyTeoyn86KR49cdvQUoqEhx1jKrEbFBsAwSbJDw//S+wNYgMHYtcynf4\n" +
|
||||
"dcVScVdLUDeqE/3f+5yt1JPRuA==\n" +
|
||||
"-----END CERTIFICATE-----";
|
||||
|
||||
private static final PEMDecoder PEM_DECODER = PEMDecoder.of()
|
||||
;
|
||||
private static CertPath generateCertificatePath()
|
||||
throws CertificateException, IOException {
|
||||
// generate certificate from cert strings
|
||||
CertificateFactory cf = CertificateFactory.getInstance("X.509");
|
||||
|
||||
ByteArrayInputStream is;
|
||||
|
||||
is = new ByteArrayInputStream(targetCertStr.getBytes());
|
||||
Certificate targetCert = PEM_DECODER.decode(is, X509Certificate.class);
|
||||
|
||||
is = new ByteArrayInputStream(subCaCertStr.getBytes());
|
||||
Certificate subCaCert = PEM_DECODER.decode(is, X509Certificate.class);
|
||||
|
||||
is = new ByteArrayInputStream(selfSignedCertStr.getBytes());
|
||||
Certificate selfSignedCert = PEM_DECODER.decode(is, X509Certificate.class);
|
||||
|
||||
// generate certification path
|
||||
List<Certificate> list = Arrays.asList(targetCert, subCaCert, selfSignedCert);
|
||||
|
||||
return cf.generateCertPath(list);
|
||||
}
|
||||
|
||||
private static Set<TrustAnchor> generateTrustAnchors()
|
||||
throws IOException {
|
||||
// generate certificate from cert string
|
||||
ByteArrayInputStream is =
|
||||
new ByteArrayInputStream(selfSignedCertStr.getBytes());
|
||||
X509Certificate selfSignedCert = PEM_DECODER.decode(is, X509Certificate.class);;
|
||||
|
||||
// generate a trust anchor
|
||||
TrustAnchor anchor =
|
||||
new TrustAnchor(selfSignedCert, null);
|
||||
|
||||
return Collections.singleton(anchor);
|
||||
}
|
||||
|
||||
public static void main(String args[]) throws Exception {
|
||||
CertPath path = generateCertificatePath();
|
||||
Set<TrustAnchor> anchors = generateTrustAnchors();
|
||||
|
||||
PKIXParameters params = new PKIXParameters(anchors);
|
||||
|
||||
// disable certificate revocation checking
|
||||
params.setRevocationEnabled(false);
|
||||
|
||||
// set the validation time
|
||||
params.setDate(new Date(109, 5, 8)); // 2009-05-01
|
||||
|
||||
// disable OCSP checker
|
||||
Security.setProperty("ocsp.enable", "false");
|
||||
|
||||
// disable CRL checker
|
||||
System.setProperty("com.sun.security.enableCRLDP", "false");
|
||||
|
||||
CertPathValidator validator = CertPathValidator.getInstance("PKIX");
|
||||
|
||||
try {
|
||||
validator.validate(path, params);
|
||||
throw new Exception("Should thrown UnsupportedOperationException");
|
||||
} catch (UnsupportedOperationException uoe) {
|
||||
// that is the expected exception.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,153 @@
|
|||
/*
|
||||
* Copyright (c) 2009, 2025, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @test
|
||||
*
|
||||
* @bug 6845286
|
||||
* @summary Add regression test for name constraints
|
||||
* @enablePreview
|
||||
* @author Xuelei Fan
|
||||
*/
|
||||
|
||||
import java.io.*;
|
||||
import java.net.SocketException;
|
||||
import java.security.PEMDecoder;
|
||||
import java.util.*;
|
||||
import java.security.Security;
|
||||
import java.security.cert.*;
|
||||
import java.security.cert.CertPathValidatorException.BasicReason;
|
||||
|
||||
public class NameConstraintsWithoutRID {
|
||||
|
||||
static String selfSignedCertStr =
|
||||
"-----BEGIN CERTIFICATE-----\n" +
|
||||
"MIICTjCCAbegAwIBAgIJAIoSzC1A/k4vMA0GCSqGSIb3DQEBBQUAMB8xCzAJBgNV\n" +
|
||||
"BAYTAlVTMRAwDgYDVQQKEwdFeGFtcGxlMB4XDTA5MDUwNzA5MjcxMloXDTMwMDQx\n" +
|
||||
"NzA5MjcxMlowHzELMAkGA1UEBhMCVVMxEDAOBgNVBAoTB0V4YW1wbGUwgZ8wDQYJ\n" +
|
||||
"KoZIhvcNAQEBBQADgY0AMIGJAoGBANXzlv5Fn2cdgBRdEK/37/o8rqQXIRIMZqX6\n" +
|
||||
"BPuo46Cdhctv+n3hu5bj/PwgJVbAJcqcQfDudSSF5gwGlRqDX9vekPSS47XZXjOZ\n" +
|
||||
"qFcnDoWP0gSQXLYVVtjuItkecTrPyUE5v2lRIAh13MGKOSh3ZsrtFvj7Y5d9EqIP\n" +
|
||||
"SLxWWPuHAgMBAAGjgZEwgY4wHQYDVR0OBBYEFFydJvQMB2j4EDHW2bQabNsPUvDt\n" +
|
||||
"ME8GA1UdIwRIMEaAFFydJvQMB2j4EDHW2bQabNsPUvDtoSOkITAfMQswCQYDVQQG\n" +
|
||||
"EwJVUzEQMA4GA1UEChMHRXhhbXBsZYIJAIoSzC1A/k4vMA8GA1UdEwEB/wQFMAMB\n" +
|
||||
"Af8wCwYDVR0PBAQDAgIEMA0GCSqGSIb3DQEBBQUAA4GBAHgoopmZ1Q4qXhMDbbYQ\n" +
|
||||
"YCi4Cg6cXPFblx5gzhWu/6l9SkvZbAZiLszgyMq5dGj9WyTtibNEp232dQsKTFu7\n" +
|
||||
"3ag0DiFqoQ8btgvbwBlzhnRagoeVFjhuBBQutOScw7x8NCSBkZQow+31127mwu3y\n" +
|
||||
"YGYhEmI2dNmgbv1hVYTGmLXW\n" +
|
||||
"-----END CERTIFICATE-----";
|
||||
|
||||
static String subCaCertStr =
|
||||
"-----BEGIN CERTIFICATE-----\n" +
|
||||
"MIICdTCCAd6gAwIBAgIJAL+MYVyy7k5YMA0GCSqGSIb3DQEBBQUAMB8xCzAJBgNV\n" +
|
||||
"BAYTAlVTMRAwDgYDVQQKEwdFeGFtcGxlMB4XDTA5MDUwNzA5MjcxNFoXDTI5MDEy\n" +
|
||||
"MjA5MjcxNFowMTELMAkGA1UEBhMCVVMxEDAOBgNVBAoTB0V4YW1wbGUxEDAOBgNV\n" +
|
||||
"BAsTB0NsYXNzLTEwgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBAM2mwX8dhP3M\n" +
|
||||
"i6ATRsd0wco+c7rsyEbP0CRQunVIP8/kOL8+zyQix+QZquY23tvBCbia424GXDkT\n" +
|
||||
"irvK/M4yGzrdS51hA5dlH3SHY3CWOAqEPqKtNLn1My4MWtTiUWbHi0YjFuOv0BXz\n" +
|
||||
"x9lTEfMf+3QcOgO5FitcqHIMP4jIlT+lAgMBAAGjgaYwgaMwHQYDVR0OBBYEFJHg\n" +
|
||||
"eyEWcjxcAwc01BPQrau/4HJaME8GA1UdIwRIMEaAFFydJvQMB2j4EDHW2bQabNsP\n" +
|
||||
"UvDtoSOkITAfMQswCQYDVQQGEwJVUzEQMA4GA1UEChMHRXhhbXBsZYIJAIoSzC1A\n" +
|
||||
"/k4vMA8GA1UdEwEB/wQFMAMBAf8wCwYDVR0PBAQDAgIEMBMGA1UdHgQMMAqhCDAG\n" +
|
||||
"iAQqAwQFMA0GCSqGSIb3DQEBBQUAA4GBAI3CDQWZiTlVVVqfCiZwc/yIL7G5bu2g\n" +
|
||||
"ccgVz9PyKfTpq8vk59S23TvPwdPt4ZVx4RSoar9ONtbrcLxfP3X6WQ7e9popWNZV\n" +
|
||||
"q49YfyU1tD5HFuxj7CAsvfykuRo4ovXaTCVWlTMi7fJJdzU0Eb4xkXXhiWT/RbHG\n" +
|
||||
"R7J+8ROMZ+nR\n" +
|
||||
"-----END CERTIFICATE-----";
|
||||
|
||||
static String targetCertStr =
|
||||
"-----BEGIN CERTIFICATE-----\n" +
|
||||
"MIICPTCCAaagAwIBAgIJAOA8c10w019WMA0GCSqGSIb3DQEBBQUAMDExCzAJBgNV\n" +
|
||||
"BAYTAlVTMRAwDgYDVQQKEwdFeGFtcGxlMRAwDgYDVQQLEwdDbGFzcy0xMB4XDTA5\n" +
|
||||
"MDUwNzEwMjY0MloXDTI5MDEyMjEwMjY0MlowPzELMAkGA1UEBhMCVVMxEDAOBgNV\n" +
|
||||
"BAoTB0V4YW1wbGUxEDAOBgNVBAsTB0NsYXNzLTExDDAKBgNVBAMTA0JvYjCBnzAN\n" +
|
||||
"BgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEAx4N+y29y5mAGnVQHA3x3fQehxm3nFohQ\n" +
|
||||
"gKV10bZ24/hwZn6rZXG6VsBaqkrgw7ipRZzk99etihAomAFL9k0q/0nxFP/Ovwio\n" +
|
||||
"NzacF3vpv85FF6ATwY1Zs+p4hfxU3WnnyyS9la9Z3o5QBhQbV/WjA/JSG5+ImQFp\n" +
|
||||
"nLkPfzU4wXECAwEAAaNPME0wCwYDVR0PBAQDAgPoMB0GA1UdDgQWBBTxUJG+QewS\n" +
|
||||
"rSGcuiJy+K4gb1g/BzAfBgNVHSMEGDAWgBSR4HshFnI8XAMHNNQT0K2rv+ByWjAN\n" +
|
||||
"BgkqhkiG9w0BAQUFAAOBgQA9fDeTtSXmP/MEni0vtAmgTPd6R31NcPWKibDizwYS\n" +
|
||||
"BWjUMcbTN8xeXjm4uQLMK8ZQy2+cmNrTvQ59BZ8Y97y7SJUcBLOW5eivO/mKuBsC\n" +
|
||||
"ACB9IxBUGVEwNup7KJ5ixox5jKt+qPwzCheyQQb9NEDJdB0YaHRhFpCcpCFak8yK\n" +
|
||||
"/A==\n" +
|
||||
"-----END CERTIFICATE-----";
|
||||
|
||||
private static final PEMDecoder PEM_DECODER = PEMDecoder.of();
|
||||
|
||||
private static CertPath generateCertificatePath()
|
||||
throws CertificateException {
|
||||
// generate certificate from cert strings
|
||||
CertificateFactory cf = CertificateFactory.getInstance("X.509");
|
||||
|
||||
Certificate targetCert = PEM_DECODER.decode(targetCertStr, X509Certificate.class);
|
||||
|
||||
Certificate subCaCert = PEM_DECODER.decode(subCaCertStr, X509Certificate.class);
|
||||
|
||||
Certificate selfSignedCert = PEM_DECODER.decode(selfSignedCertStr, X509Certificate.class);
|
||||
|
||||
// generate certification path
|
||||
List<Certificate> list = Arrays.asList(targetCert, subCaCert, selfSignedCert);
|
||||
|
||||
return cf.generateCertPath(list);
|
||||
}
|
||||
|
||||
private static Set<TrustAnchor> generateTrustAnchors()
|
||||
throws CertificateException {
|
||||
// generate certificate from cert string
|
||||
X509Certificate selfSignedCert = PEM_DECODER.decode(selfSignedCertStr, X509Certificate.class);
|
||||
|
||||
// generate a trust anchor
|
||||
TrustAnchor anchor =
|
||||
new TrustAnchor(selfSignedCert, null);
|
||||
|
||||
return Collections.singleton(anchor);
|
||||
}
|
||||
|
||||
public static void main(String args[]) throws Exception {
|
||||
CertPath path = generateCertificatePath();
|
||||
Set<TrustAnchor> anchors = generateTrustAnchors();
|
||||
|
||||
PKIXParameters params = new PKIXParameters(anchors);
|
||||
|
||||
// disable certificate revocation checking
|
||||
params.setRevocationEnabled(false);
|
||||
|
||||
// set the validation time
|
||||
params.setDate(new Date(109, 5, 8)); // 2009-05-01
|
||||
|
||||
// disable OCSP checker
|
||||
Security.setProperty("ocsp.enable", "false");
|
||||
|
||||
// disable CRL checker
|
||||
System.setProperty("com.sun.security.enableCRLDP", "false");
|
||||
|
||||
CertPathValidator validator = CertPathValidator.getInstance("PKIX");
|
||||
|
||||
try {
|
||||
validator.validate(path, params);
|
||||
} catch (CertPathValidatorException uoe) {
|
||||
// unexpected exception, rethrow it.
|
||||
throw uoe;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,110 @@
|
|||
#
|
||||
# Copyright (c) 2009, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
#
|
||||
# This code is free software; you can redistribute it and/or modify it
|
||||
# under the terms of the GNU General Public License version 2 only, as
|
||||
# published by the Free Software Foundation.
|
||||
#
|
||||
# This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
# version 2 for more details (a copy is included in the LICENSE file that
|
||||
# accompanied this code).
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License version
|
||||
# 2 along with this work; if not, write to the Free Software Foundation,
|
||||
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
#
|
||||
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
# or visit www.oracle.com if you need additional information or have any
|
||||
# questions.
|
||||
#
|
||||
|
||||
#!/bin/ksh
|
||||
#
|
||||
# needs ksh to run the script.
|
||||
OPENSSL=openssl
|
||||
|
||||
# generate a self-signed root certificate
|
||||
if [ ! -f root/root_cert.pem ]; then
|
||||
if [ ! -d root ]; then
|
||||
mkdir root
|
||||
fi
|
||||
|
||||
${OPENSSL} req -x509 -newkey rsa:1024 -keyout root/root_key.pem \
|
||||
-out root/root_cert.pem -subj "/C=US/O=Example" \
|
||||
-config openssl.cnf -reqexts cert_issuer -days 7650 \
|
||||
-passin pass:passphrase -passout pass:passphrase
|
||||
fi
|
||||
|
||||
# generate subca cert issuer
|
||||
if [ ! -f subca/subca_cert.pem ]; then
|
||||
if [ ! -d subca ]; then
|
||||
mkdir subca
|
||||
fi
|
||||
|
||||
${OPENSSL} req -newkey rsa:1024 -keyout subca/subca_key.pem \
|
||||
-out subca/subca_req.pem -subj "/C=US/O=Example/OU=Class-1" \
|
||||
-days 7650 -passin pass:passphrase -passout pass:passphrase
|
||||
|
||||
${OPENSSL} x509 -req -in subca/subca_req.pem -extfile openssl.cnf \
|
||||
-extensions cert_issuer -CA root/root_cert.pem \
|
||||
-CAkey root/root_key.pem -out subca/subca_cert.pem -CAcreateserial \
|
||||
-CAserial root/root_cert.srl -days 7200 -passin pass:passphrase
|
||||
fi
|
||||
|
||||
# generate certifiacte for Alice
|
||||
if [ ! -f subca/alice/alice_cert.pem ]; then
|
||||
if [ ! -d subca/alice ]; then
|
||||
mkdir -p subca/alice
|
||||
fi
|
||||
|
||||
${OPENSSL} req -newkey rsa:1024 -keyout subca/alice/alice_key.pem \
|
||||
-out subca/alice/alice_req.pem \
|
||||
-subj "/C=US/O=Example/OU=Class-1/CN=Alice" -days 7650 \
|
||||
-passin pass:passphrase -passout pass:passphrase
|
||||
|
||||
${OPENSSL} x509 -req -in subca/alice/alice_req.pem \
|
||||
-extfile openssl.cnf -extensions alice_of_subca \
|
||||
-CA subca/subca_cert.pem -CAkey subca/subca_key.pem \
|
||||
-out subca/alice/alice_cert.pem -CAcreateserial \
|
||||
-CAserial subca/subca_cert.srl -days 7200 -passin pass:passphrase
|
||||
fi
|
||||
|
||||
# generate certifiacte for Bob
|
||||
if [ ! -f subca/bob/bob.pem ]; then
|
||||
if [ ! -d subca/bob ]; then
|
||||
mkdir -p subca/bob
|
||||
fi
|
||||
|
||||
${OPENSSL} req -newkey rsa:1024 -keyout subca/bob/bob_key.pem \
|
||||
-out subca/bob/bob_req.pem \
|
||||
-subj "/C=US/O=Example/OU=Class-1/CN=Bob" -days 7650 \
|
||||
-passin pass:passphrase -passout pass:passphrase
|
||||
|
||||
${OPENSSL} x509 -req -in subca/bob/bob_req.pem \
|
||||
-extfile openssl.cnf -extensions ee_of_subca \
|
||||
-CA subca/subca_cert.pem -CAkey subca/subca_key.pem \
|
||||
-out subca/bob/bob_cert.pem -CAcreateserial \
|
||||
-CAserial subca/subca_cert.srl -days 7200 -passin pass:passphrase
|
||||
fi
|
||||
|
||||
# generate certifiacte for Susan
|
||||
if [ ! -f subca/susan/susan_cert.pem ]; then
|
||||
if [ ! -d subca/susan ]; then
|
||||
mkdir -p subca/susan
|
||||
fi
|
||||
|
||||
${OPENSSL} req -newkey rsa:1024 -keyout subca/susan/susan_key.pem \
|
||||
-out subca/susan/susan_req.pem \
|
||||
-subj "/C=US/O=Example/OU=Class-1/CN=Susan" -days 7650 \
|
||||
-passin pass:passphrase -passout pass:passphrase
|
||||
|
||||
${OPENSSL} x509 -req -in subca/susan/susan_req.pem \
|
||||
-extfile openssl.cnf -extensions susan_of_subca \
|
||||
-CA subca/subca_cert.pem -CAkey subca/subca_key.pem \
|
||||
-out subca/susan/susan_cert.pem -CAcreateserial \
|
||||
-CAserial subca/subca_cert.srl -days 7200 -passin pass:passphrase
|
||||
fi
|
||||
|
||||
|
|
@ -0,0 +1,218 @@
|
|||
#
|
||||
# Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
|
||||
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
#
|
||||
# This code is free software; you can redistribute it and/or modify it
|
||||
# under the terms of the GNU General Public License version 2 only, as
|
||||
# published by the Free Software Foundation.
|
||||
#
|
||||
# This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
# version 2 for more details (a copy is included in the LICENSE file that
|
||||
# accompanied this code).
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License version
|
||||
# 2 along with this work; if not, write to the Free Software Foundation,
|
||||
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
#
|
||||
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
# or visit www.oracle.com if you need additional information or have any
|
||||
# questions.
|
||||
#
|
||||
|
||||
#
|
||||
# OpenSSL configuration file.
|
||||
#
|
||||
|
||||
HOME = .
|
||||
RANDFILE = $ENV::HOME/.rnd
|
||||
|
||||
[ ca ]
|
||||
default_ca = CA_default
|
||||
|
||||
[ CA_default ]
|
||||
dir = ./top
|
||||
certs = $dir/certs
|
||||
crl_dir = $dir/crl
|
||||
database = $dir/index.txt
|
||||
unique_subject = no
|
||||
new_certs_dir = $dir/newcerts
|
||||
certificate = $dir/cacert.pem
|
||||
serial = $dir/serial
|
||||
crlnumber = $dir/crlnumber
|
||||
crl = $dir/crl.pem
|
||||
private_key = $dir/private/cakey.pem
|
||||
RANDFILE = $dir/private/.rand
|
||||
x509_extensions = v3_ca
|
||||
|
||||
name_opt = ca_default
|
||||
cert_opt = ca_default
|
||||
|
||||
default_days = 7650
|
||||
default_crl_days = 30
|
||||
default_md = sha1
|
||||
preserve = no
|
||||
|
||||
policy = policy_anything
|
||||
|
||||
[ ca_top ]
|
||||
dir = ./root
|
||||
certs = $dir/certs
|
||||
crl_dir = $dir/crl
|
||||
database = $dir/index.txt
|
||||
unique_subject = no
|
||||
new_certs_dir = $dir/newcerts
|
||||
certificate = $dir/cacert.pem
|
||||
serial = $dir/serial
|
||||
crlnumber = $dir/crlnumber
|
||||
crl = $dir/crl.pem
|
||||
private_key = $dir/private/cakey.pem
|
||||
RANDFILE = $dir/private/.rand
|
||||
|
||||
x509_extensions = v3_ca
|
||||
|
||||
name_opt = ca_default
|
||||
cert_opt = ca_default
|
||||
|
||||
default_days = 7650
|
||||
default_crl_days = 30
|
||||
default_md = sha1
|
||||
preserve = no
|
||||
|
||||
policy = policy_anything
|
||||
|
||||
[ ca_subca ]
|
||||
dir = ./subca
|
||||
certs = $dir/certs
|
||||
crl_dir = $dir/crl
|
||||
database = $dir/index.txt
|
||||
unique_subject = no
|
||||
new_certs_dir = $dir/newcerts
|
||||
|
||||
certificate = $dir/cacert.pem
|
||||
serial = $dir/serial
|
||||
crlnumber = $dir/crlnumber
|
||||
crl = $dir/crl.pem
|
||||
private_key = $dir/private/cakey.pem
|
||||
RANDFILE = $dir/private/.rand
|
||||
|
||||
x509_extensions = usr_cert
|
||||
|
||||
name_opt = ca_default
|
||||
cert_opt = ca_default
|
||||
|
||||
default_days = 7650
|
||||
default_crl_days = 30
|
||||
default_md = sha1
|
||||
preserve = no
|
||||
|
||||
policy = policy_anything
|
||||
|
||||
[ policy_match ]
|
||||
countryName = match
|
||||
stateOrProvinceName = match
|
||||
organizationName = match
|
||||
organizationalUnitName = optional
|
||||
commonName = supplied
|
||||
emailAddress = optional
|
||||
|
||||
[ policy_anything ]
|
||||
countryName = optional
|
||||
stateOrProvinceName = optional
|
||||
localityName = optional
|
||||
organizationName = optional
|
||||
organizationalUnitName = optional
|
||||
commonName = supplied
|
||||
emailAddress = optional
|
||||
|
||||
[ req ]
|
||||
default_bits = 1024
|
||||
default_keyfile = privkey.pem
|
||||
distinguished_name = req_distinguished_name
|
||||
attributes = req_attributes
|
||||
x509_extensions = v3_ca
|
||||
|
||||
string_mask = nombstr
|
||||
|
||||
[ req_distinguished_name ]
|
||||
countryName = Country Name (2 letter code)
|
||||
countryName_default = NO
|
||||
countryName_min = 2
|
||||
countryName_max = 2
|
||||
|
||||
stateOrProvinceName = State or Province Name (full name)
|
||||
stateOrProvinceName_default = A-State
|
||||
|
||||
localityName = Locality Name (eg, city)
|
||||
|
||||
0.organizationName = Organization Name (eg, company)
|
||||
0.organizationName_default = Internet Widgits Pty Ltd
|
||||
|
||||
organizationalUnitName = Organizational Unit Name (eg, section)
|
||||
|
||||
commonName = Common Name (eg, YOUR name)
|
||||
commonName_max = 64
|
||||
|
||||
emailAddress = Email Address
|
||||
emailAddress_max = 64
|
||||
|
||||
[ req_attributes ]
|
||||
challengePassword = A challenge password
|
||||
challengePassword_min = 4
|
||||
challengePassword_max = 20
|
||||
unstructuredName = An optional company name
|
||||
|
||||
|
||||
[ usr_cert ]
|
||||
keyUsage = nonRepudiation, digitalSignature, keyEncipherment
|
||||
|
||||
subjectKeyIdentifier = hash
|
||||
authorityKeyIdentifier = keyid,issuer
|
||||
|
||||
[ v3_req ]
|
||||
basicConstraints = CA:FALSE
|
||||
keyUsage = nonRepudiation, digitalSignature, keyEncipherment
|
||||
subjectAltName = email:example@openjdk.net, RID:1.2.3.4:true
|
||||
|
||||
[ v3_ca ]
|
||||
subjectKeyIdentifier = hash
|
||||
authorityKeyIdentifier = keyid:always,issuer:always
|
||||
basicConstraints = critical,CA:true
|
||||
keyUsage = keyCertSign
|
||||
|
||||
[ cert_issuer ]
|
||||
subjectKeyIdentifier = hash
|
||||
authorityKeyIdentifier = keyid:always,issuer:always
|
||||
basicConstraints = critical,CA:true
|
||||
keyUsage = keyCertSign
|
||||
nameConstraints = excluded;RID:1.2.3.4.5
|
||||
|
||||
[ crl_issuer ]
|
||||
subjectKeyIdentifier = hash
|
||||
authorityKeyIdentifier = keyid:always,issuer:always
|
||||
keyUsage = cRLSign
|
||||
|
||||
|
||||
[ crl_ext ]
|
||||
authorityKeyIdentifier = keyid:always,issuer:always
|
||||
|
||||
[ ee_of_subca ]
|
||||
keyUsage = nonRepudiation, digitalSignature, keyEncipherment, keyAgreement
|
||||
|
||||
subjectKeyIdentifier = hash
|
||||
authorityKeyIdentifier = keyid,issuer
|
||||
|
||||
[ alice_of_subca ]
|
||||
keyUsage = nonRepudiation, digitalSignature, keyEncipherment, keyAgreement
|
||||
subjectAltName = RID:1.2.3.4
|
||||
|
||||
subjectKeyIdentifier = hash
|
||||
authorityKeyIdentifier = keyid,issuer
|
||||
|
||||
[ susan_of_subca ]
|
||||
keyUsage = nonRepudiation, digitalSignature, keyEncipherment, keyAgreement
|
||||
subjectAltName = RID:1.2.3.4.5
|
||||
|
||||
subjectKeyIdentifier = hash
|
||||
authorityKeyIdentifier = keyid,issuer
|
||||
|
|
@ -0,0 +1,168 @@
|
|||
/*
|
||||
* Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 4684810 6994717
|
||||
* @summary Verify that RFC822 name constraints are checked correctly
|
||||
*/
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.InputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import java.security.cert.*;
|
||||
import java.security.cert.PKIXReason;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* ValidateCertPath performs a simple validation of a certification path.
|
||||
* On success, it prints the CertPathValidatorResult. On failure, it
|
||||
* prints the error.
|
||||
*
|
||||
* Synopsis:
|
||||
* <pre>
|
||||
* ValidateCertPath trustAnchor [certFile ...]
|
||||
* where each argument is the path to a file that contains a
|
||||
* certificate. Each certificate should have an issuer equal to
|
||||
* the subject of the preceding certificate.
|
||||
*</pre>
|
||||
*
|
||||
* @author Steve Hanna
|
||||
*/
|
||||
public final class ValidateCertPath {
|
||||
|
||||
private final static String BASE = System.getProperty("test.src", "./");
|
||||
|
||||
private static CertPath path;
|
||||
private static PKIXParameters params;
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
|
||||
try {
|
||||
parseArgs(args);
|
||||
validate(path, params);
|
||||
throw new Exception("Successfully validated invalid path.");
|
||||
} catch (CertPathValidatorException e) {
|
||||
if (e.getReason() != PKIXReason.INVALID_NAME) {
|
||||
throw new Exception("unexpected reason: " + e.getReason());
|
||||
}
|
||||
System.out.println("Path rejected as expected: " + e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse the command line arguments. Populate the static
|
||||
* class fields based on the values of the arugments. In
|
||||
* case of bad arguments, print usage and exit. In case of
|
||||
* other error, throw an exception.
|
||||
*
|
||||
* @param args command line arguments
|
||||
* @throws Exception on error
|
||||
*/
|
||||
public static void parseArgs(String[] args) throws Exception {
|
||||
args = new String[] {"jane2jane.cer", "jane2steve.cer", "steve2tom.cer"};
|
||||
|
||||
TrustAnchor anchor = new TrustAnchor(getCertFromFile(args[0]), null);
|
||||
List<X509Certificate> list = new ArrayList<X509Certificate>();
|
||||
for (int i = 1; i < args.length; i++) {
|
||||
list.add(0, getCertFromFile(args[i]));
|
||||
}
|
||||
CertificateFactory cf = CertificateFactory.getInstance("X509");
|
||||
path = cf.generateCertPath(list);
|
||||
|
||||
Set<TrustAnchor> anchors = Collections.singleton(anchor);
|
||||
params = new PKIXParameters(anchors);
|
||||
params.setRevocationEnabled(false);
|
||||
// The certificates expired on 10/22/10, so set the validity date to
|
||||
// 05/01/2009 to avoid expiration failures
|
||||
params.setDate(new Date(1243828800000l));
|
||||
}
|
||||
|
||||
/*
|
||||
* Reads the entire input stream into a byte array.
|
||||
*/
|
||||
private static byte[] getTotalBytes(InputStream is) throws IOException {
|
||||
byte[] buffer = new byte[8192];
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream(2048);
|
||||
int n;
|
||||
baos.reset();
|
||||
while ((n = is.read(buffer, 0, buffer.length)) != -1) {
|
||||
baos.write(buffer, 0, n);
|
||||
}
|
||||
return baos.toByteArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a DER-encoded X.509 certificate from a file.
|
||||
*
|
||||
* @param certFilePath path to file containing DER-encoded certificate
|
||||
* @return X509Certificate
|
||||
* @throws IOException on error
|
||||
*/
|
||||
public static X509Certificate getCertFromFile(String certFilePath)
|
||||
throws IOException {
|
||||
X509Certificate cert = null;
|
||||
try {
|
||||
File certFile = new File(BASE, certFilePath);
|
||||
if (!certFile.canRead())
|
||||
throw new IOException("File " +
|
||||
certFile.toString() +
|
||||
" is not a readable file.");
|
||||
FileInputStream certFileInputStream =
|
||||
new FileInputStream(certFile);
|
||||
CertificateFactory cf = CertificateFactory.getInstance("X509");
|
||||
cert = (X509Certificate)
|
||||
cf.generateCertificate(certFileInputStream);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
throw new IOException("Can't construct X509Certificate: " +
|
||||
e.getMessage());
|
||||
}
|
||||
return cert;
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform a PKIX validation. On success, print the
|
||||
* CertPathValidatorResult on System.out. On failure,
|
||||
* throw an exception.
|
||||
*
|
||||
* @param path CertPath to validate
|
||||
* @param params PKIXParameters to use in validation
|
||||
* @throws Exception on error
|
||||
*/
|
||||
public static void validate(CertPath path, PKIXParameters params)
|
||||
throws Exception {
|
||||
CertPathValidator validator =
|
||||
CertPathValidator.getInstance("PKIX");
|
||||
CertPathValidatorResult cpvr = validator.validate(path, params);
|
||||
System.out.println("ValidateCertPath successful.");
|
||||
}
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
|
@ -0,0 +1,136 @@
|
|||
/*
|
||||
* Copyright (c) 2001, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @bug 4459538
|
||||
* @summary make sure that target constraints are processed correctly
|
||||
* by a PKIX CertPathValidator
|
||||
*/
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import java.math.BigInteger;
|
||||
|
||||
import java.security.cert.CertificateFactory;
|
||||
import java.security.cert.CertPath;
|
||||
import java.security.cert.CertPathValidator;
|
||||
import java.security.cert.CertPathValidatorException;
|
||||
import java.security.cert.CertPathValidatorResult;
|
||||
import java.security.cert.PKIXParameters;
|
||||
import java.security.cert.TrustAnchor;
|
||||
import java.security.cert.X509Certificate;
|
||||
import java.security.cert.X509CertSelector;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* ValidateTargetConstraints performs a simple validation of a certification
|
||||
* path, but adds a requirement that the serial number of the last
|
||||
* certificate match an arbitrarily chosen number. This should cause the
|
||||
* validation to fail.
|
||||
*
|
||||
* @author Steve Hanna
|
||||
* @author Sean Mullan
|
||||
*/
|
||||
public final class ValidateTargetConstraints {
|
||||
|
||||
private static CertPath path;
|
||||
private static PKIXParameters params;
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
|
||||
String[] certs = { "sun.cer", "sun2labs1.cer" };
|
||||
|
||||
try {
|
||||
createPath(certs);
|
||||
validate(path, params);
|
||||
throw new Exception
|
||||
("CertPath should not have been validated succesfully");
|
||||
} catch (CertPathValidatorException cpve) {
|
||||
System.out.println("Test failed as expected: " + cpve);
|
||||
}
|
||||
}
|
||||
|
||||
public static void createPath(String[] certs) throws Exception {
|
||||
TrustAnchor anchor = new TrustAnchor(getCertFromFile(certs[0]), null);
|
||||
List list = new ArrayList();
|
||||
for (int i = 1; i < certs.length; i++) {
|
||||
list.add(0, getCertFromFile(certs[i]));
|
||||
}
|
||||
CertificateFactory cf = CertificateFactory.getInstance("X509");
|
||||
path = cf.generateCertPath(list);
|
||||
|
||||
Set anchors = Collections.singleton(anchor);
|
||||
params = new PKIXParameters(anchors);
|
||||
params.setRevocationEnabled(false);
|
||||
X509CertSelector sel = new X509CertSelector();
|
||||
sel.setSerialNumber(new BigInteger("1427"));
|
||||
params.setTargetCertConstraints(sel);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a DER-encoded X.509 certificate from a file.
|
||||
*
|
||||
* @param certFilePath path to file containing DER-encoded certificate
|
||||
* @return X509Certificate
|
||||
* @throws IOException on error
|
||||
*/
|
||||
public static X509Certificate getCertFromFile(String certFilePath)
|
||||
throws IOException {
|
||||
X509Certificate cert = null;
|
||||
try {
|
||||
File certFile = new File(System.getProperty("test.src", "."),
|
||||
certFilePath);
|
||||
FileInputStream certFileInputStream =
|
||||
new FileInputStream(certFile);
|
||||
CertificateFactory cf = CertificateFactory.getInstance("X509");
|
||||
cert = (X509Certificate)
|
||||
cf.generateCertificate(certFileInputStream);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
throw new IOException("Can't construct X509Certificate: " +
|
||||
e.getMessage());
|
||||
}
|
||||
return cert;
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform a PKIX validation.
|
||||
*
|
||||
* @param path CertPath to validate
|
||||
* @param params PKIXParameters to use in validation
|
||||
* @throws Exception on error
|
||||
*/
|
||||
public static void validate(CertPath path, PKIXParameters params)
|
||||
throws Exception {
|
||||
CertPathValidator validator =
|
||||
CertPathValidator.getInstance("PKIX");
|
||||
CertPathValidatorResult cpvr = validator.validate(path, params);
|
||||
}
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
|
|
@ -0,0 +1,290 @@
|
|||
/*
|
||||
* Copyright (c) 2004, 2025, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 8132926
|
||||
* @summary PKIXParameters built with public key form of TrustAnchor causes
|
||||
* NPE during cert path building/validation
|
||||
* @enablePreview
|
||||
* @run main ValWithAnchorByName
|
||||
*/
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.security.PEMDecoder;
|
||||
import java.security.cert.CertificateException;
|
||||
import java.security.cert.CertificateFactory;
|
||||
import java.security.cert.CertPath;
|
||||
import java.security.cert.CertPathValidator;
|
||||
import java.security.cert.PKIXParameters;
|
||||
import java.security.cert.PKIXRevocationChecker;
|
||||
import java.security.cert.TrustAnchor;
|
||||
import java.security.cert.X509Certificate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Base64;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.HashMap;
|
||||
|
||||
// To get certpath debugging, add -Djava.security.debug=certpath
|
||||
|
||||
public class ValWithAnchorByName {
|
||||
|
||||
// The following certificates and OCSP responses were captured from
|
||||
// a test run that used certificates and responses generated by
|
||||
// jdk.test.lib.security.CertificateBuilder and
|
||||
// jdk.test.lib.security.SimpleOCSPServer.
|
||||
|
||||
// Subject: CN=SSLCertificate, O=SomeCompany
|
||||
// Issuer: CN=Intermediate CA Cert, O=SomeCompany
|
||||
// Validity: Tue Aug 30 14:37:19 PDT 2016 to Wed Aug 30 14:37:19 PDT 2017
|
||||
private static final String EE_CERT =
|
||||
"-----BEGIN CERTIFICATE-----\n" +
|
||||
"MIIDnTCCAoWgAwIBAgICEAAwDQYJKoZIhvcNAQELBQAwNTEUMBIGA1UEChMLU29t\n" +
|
||||
"ZUNvbXBhbnkxHTAbBgNVBAMTFEludGVybWVkaWF0ZSBDQSBDZXJ0MB4XDTE2MDgz\n" +
|
||||
"MDIxMzcxOVoXDTE3MDgzMDIxMzcxOVowLzEUMBIGA1UEChMLU29tZUNvbXBhbnkx\n" +
|
||||
"FzAVBgNVBAMTDlNTTENlcnRpZmljYXRlMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8A\n" +
|
||||
"MIIBCgKCAQEAjgv8KKE4CO0rbCjRLA1hXjRiSq30jeusCJ8frbRG+QOBgQ3j6jgc\n" +
|
||||
"vk5wG1aTu7R4AFn0/HRDMzP9ZbRlZVIbJUTd8YiaNyZeyWapPnxHWrPCd5e1xopk\n" +
|
||||
"ElieDdEH5FiLGtIrWy56CGA1hfQb1vUVYegyeY+TTtMFVHt0PrmMk4ZRgj/GtVNp\n" +
|
||||
"BQQYIzaYAcrcWMeCn30ZrhaGAL1hsdgmEVV1wsTD4JeNMSwLwMYem7fg8ondGZIR\n" +
|
||||
"kZuGtuSdOHu4Xz+mgDNXTeX/Bp/dQFucxCG+FOOM9Hoz72RY2W8YqgL38RlnwYWp\n" +
|
||||
"nUNxhXWFH6vyINRQVEu3IgahR6HXjxM7LwIDAQABo4G8MIG5MBQGA1UdEQQNMAuC\n" +
|
||||
"CWxvY2FsaG9zdDAyBggrBgEFBQcBAQQmMCQwIgYIKwYBBQUHMAGGFmh0dHA6Ly9s\n" +
|
||||
"b2NhbGhvc3Q6NDIzMzMwHwYDVR0jBBgwFoAUYT525lwHCI4CmuWs8a7poaeKRJ4w\n" +
|
||||
"HQYDVR0OBBYEFCaQnOX4L1ovqyfeKuoay+kI+lXgMA4GA1UdDwEB/wQEAwIFoDAd\n" +
|
||||
"BgNVHSUEFjAUBggrBgEFBQcDAQYIKwYBBQUHAwIwDQYJKoZIhvcNAQELBQADggEB\n" +
|
||||
"AD8dqQIqFasJcL8lm4mPTsBl0JgNiN8tQcXM7VCvcH+yDvEyh9vudDjuhpSORqPq\n" +
|
||||
"f1o/EvJ+gfs269mBnYQujYRvmSd6EAcBntv5zn6amOh03o6PqTY9KaUC/mL9hB84\n" +
|
||||
"Y5/LYioP16sME7egKnlrGUgKh0ZvGzm7c3SYx3Z5YoeFBOkZajc7Jm+cBw/uBQkF\n" +
|
||||
"a9mLEczIvOgkq1wto8vr2ptH1gEuvFRcorN3muvq34bk40G08+AHlP3fCLFpI3FA\n" +
|
||||
"IStJLJZRcO+Ib4sOcKuaBGnuMo/QVOCEMDUs6RgiWtSd93OZKFIUOASVp6YIkcSs\n" +
|
||||
"5/rmc06sICqBjLfPEB68Jjw=\n" +
|
||||
"-----END CERTIFICATE-----";
|
||||
|
||||
// Subject: CN=Intermediate CA Cert, O=SomeCompany
|
||||
// Issuer: CN=Root CA Cert, O=SomeCompany
|
||||
// Validity: Sun Aug 07 14:37:19 PDT 2016 to Tue Aug 07 14:37:19 PDT 2018
|
||||
private static final String INT_CA_CERT =
|
||||
"-----BEGIN CERTIFICATE-----\n" +
|
||||
"MIIDdjCCAl6gAwIBAgIBZDANBgkqhkiG9w0BAQsFADAtMRQwEgYDVQQKEwtTb21l\n" +
|
||||
"Q29tcGFueTEVMBMGA1UEAxMMUm9vdCBDQSBDZXJ0MB4XDTE2MDgwNzIxMzcxOVoX\n" +
|
||||
"DTE4MDgwNzIxMzcxOVowNTEUMBIGA1UEChMLU29tZUNvbXBhbnkxHTAbBgNVBAMT\n" +
|
||||
"FEludGVybWVkaWF0ZSBDQSBDZXJ0MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIB\n" +
|
||||
"CgKCAQEAnJR5CnE7GKlQjigExSJ6hHu302mc0PcA6TDgsIitPYD/r8RBbBuE51OQ\n" +
|
||||
"7IP7AXmfPUV3/+pO/uxx6mgY5O6XeUl7KadhVPtPcL0BVVevCSOdTMVa3iV4zRpa\n" +
|
||||
"C6Uy2ouUFnafKnDtlbieggyETUoNgVNJYA9L0XNhtSnENoLHC4Pq0v8OsNtsOWFR\n" +
|
||||
"NiMTOA49NNDBw85WgPyFAxjqO4z0J0zxdWq3W4rSMB8xrkulv2Rvj3GcfYJK/ab8\n" +
|
||||
"V1IJ6PMWCpujASY3BzvYPnN7BKuBjbWJPgZdPYfX1cxeG80u0tOuMfWWiNONSMSA\n" +
|
||||
"7m9y304QA0gKqlrFFn9U4hU89kv1IwIDAQABo4GYMIGVMA8GA1UdEwEB/wQFMAMB\n" +
|
||||
"Af8wMgYIKwYBBQUHAQEEJjAkMCIGCCsGAQUFBzABhhZodHRwOi8vbG9jYWxob3N0\n" +
|
||||
"OjM5MTM0MB8GA1UdIwQYMBaAFJNMsejEyJUB9tiWycVczvpiMVQZMB0GA1UdDgQW\n" +
|
||||
"BBRhPnbmXAcIjgKa5azxrumhp4pEnjAOBgNVHQ8BAf8EBAMCAYYwDQYJKoZIhvcN\n" +
|
||||
"AQELBQADggEBAE4nOFdW9OirPnRvxihQXYL9CXLuGQz5tr0XgN8wSY6Un9b6CRiK\n" +
|
||||
"7obgIGimVdhvUC1qdRcwJqgOfJ2/jR5/5Qo0TVp+ww4dHNdUoj73tagJ7jTu0ZMz\n" +
|
||||
"5Zdp0uwd4RD/syvTeVcbPc3m4awtgEvRgzpDMcSeKPZWInlo7fbnowKSAUAfO8de\n" +
|
||||
"0cDkxEBkzPIzGNu256cdLZOqOK9wLJ9mQ0zKgi/2NsldNc2pl/6jkGpA6uL5lJsm\n" +
|
||||
"fo9sDusWNHV1YggqjDQ19hrf40VuuC9GFl/qAW3marMuEzY/NiKVUxty1q1s48SO\n" +
|
||||
"g5LoEPDDkbygOt7ICL3HYG1VufhC1Q2YY9c=\n" +
|
||||
"-----END CERTIFICATE-----";
|
||||
|
||||
// Subject: CN=Root CA Cert, O=SomeCompany
|
||||
// Issuer: CN=Root CA Cert, O=SomeCompany
|
||||
// Validity: Fri Jul 08 14:37:18 PDT 2016 to Fri Jun 28 14:37:18 PDT 2019
|
||||
private static final String ROOT_CA_CERT =
|
||||
"-----BEGIN CERTIFICATE-----\n" +
|
||||
"MIIDODCCAiCgAwIBAgIBATANBgkqhkiG9w0BAQsFADAtMRQwEgYDVQQKEwtTb21l\n" +
|
||||
"Q29tcGFueTEVMBMGA1UEAxMMUm9vdCBDQSBDZXJ0MB4XDTE2MDcwODIxMzcxOFoX\n" +
|
||||
"DTE5MDYyODIxMzcxOFowLTEUMBIGA1UEChMLU29tZUNvbXBhbnkxFTATBgNVBAMT\n" +
|
||||
"DFJvb3QgQ0EgQ2VydDCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAIlN\n" +
|
||||
"M3WYEqkU2elXEZrV9QSDbDKwyaLEHafLFciH8Edoag3q/7jEzFJxI7JZ831tdbWQ\n" +
|
||||
"Bm6Hgo+8pvetOFW1BckL8eIjyOONP2CKfFaeMaozsWi1cgxa+rjpU/Rekc+zBqvv\n" +
|
||||
"y4Sr97TwT6nQiLlgjC1nCfR1SVpO51qoDChS7n785rsKEZxw/p+kkVWSZffU7zN9\n" +
|
||||
"c645cPg//L/kjiyeKMkaquGQOYS68gQgy8YZXQv1E3l/8e8Ci1s1DYA5wpCbaBqg\n" +
|
||||
"Tw84Rr4zlUEQBgXzQlRt+mPzeaDpdG1EeGkXrcdkZ+0EMELoOVXOEn6VNsz6vT3I\n" +
|
||||
"KrnvQBSnN06xq/iWwC0CAwEAAaNjMGEwDwYDVR0TAQH/BAUwAwEB/zAfBgNVHSME\n" +
|
||||
"GDAWgBSTTLHoxMiVAfbYlsnFXM76YjFUGTAdBgNVHQ4EFgQUk0yx6MTIlQH22JbJ\n" +
|
||||
"xVzO+mIxVBkwDgYDVR0PAQH/BAQDAgGGMA0GCSqGSIb3DQEBCwUAA4IBAQAAi+Nl\n" +
|
||||
"sxP9t2IhiZIHRJGSBZuQlXIjwYIwbq3ZWc/ApZ+0oxtl7DYQi5uRNt8/opcGNCHc\n" +
|
||||
"IY0fG93SbkDubXbxPYBW6D/RUjbz59ZryaP5ym55p1MjHTOqy+AM8g41xNTJikc3\n" +
|
||||
"UUFXXnckeFbawijCsb7vf71owzKuxgBXi9n1rmXXtncKoA/LrUVXoUlKefdgDnsU\n" +
|
||||
"sl3Q29eibE3HSqziMMoAOLm0jjekFGWIgLeTtyRYR1d0dNaUwsHTrQpPjxxUTn1x\n" +
|
||||
"sAPpXKfzPnsYAZeeiaaE75GwbWlHzrNinvxdZQd0zctpfBJfVqD/+lWANlw+rOaK\n" +
|
||||
"J2GyCaJINsyaI/I2\n" +
|
||||
"-----END CERTIFICATE-----";
|
||||
|
||||
// OCSP Response Status: successful (0x0)
|
||||
// Response Type: Basic OCSP Response
|
||||
// Version: 1 (0x0)
|
||||
// Responder Id: CN=Intermediate CA Cert, O=SomeCompany
|
||||
// Produced At: Sep 6 21:37:20 2016 GMT
|
||||
// Responses:
|
||||
// Certificate ID:
|
||||
// Hash Algorithm: sha1
|
||||
// Issuer Name Hash: 7ED23D4396152EAB7D0C4AD8C1CA1418AA05DD54
|
||||
// Issuer Key Hash: 613E76E65C07088E029AE5ACF1AEE9A1A78A449E
|
||||
// Serial Number: 1000
|
||||
// Cert Status: good
|
||||
// This Update: Sep 6 21:37:20 2016 GMT
|
||||
// Next Update: Sep 6 22:37:19 2016 GMT
|
||||
private static final String EE_OCSP_RESP =
|
||||
"MIIFbAoBAKCCBWUwggVhBgkrBgEFBQcwAQEEggVSMIIFTjCBtaE3MDUxFDASBgNV\n" +
|
||||
"BAoTC1NvbWVDb21wYW55MR0wGwYDVQQDExRJbnRlcm1lZGlhdGUgQ0EgQ2VydBgP\n" +
|
||||
"MjAxNjA5MDYyMTM3MjBaMGUwYzA7MAkGBSsOAwIaBQAEFH7SPUOWFS6rfQxK2MHK\n" +
|
||||
"FBiqBd1UBBRhPnbmXAcIjgKa5azxrumhp4pEngICEACAABgPMjAxNjA5MDYyMTM3\n" +
|
||||
"MjBaoBEYDzIwMTYwOTA2MjIzNzE5WqECMAAwDQYJKoZIhvcNAQELBQADggEBAF13\n" +
|
||||
"cLwxDG8UYPIbzID86vZGOWUuv5c35VnvebMk/ajAUdpItDYshIQVi90Z8BB2TEi/\n" +
|
||||
"wtx1aNkIv7db0uQ0NnRfvME8vG2PWbty36CNAYr/M5UVzUmELH2sGTyf2fKfNIUK\n" +
|
||||
"Iya/NRxCqxLAc34NYH0YyGJ9VcDjbEMNSBAHIqDdBNqKUPnjn454yoivU2oEs294\n" +
|
||||
"cGePMx3QLyPepMwUss8nW74yIF7vxfJ+KFDBGWNuZDRfXScsGIoeM0Vt9B+4fmnV\n" +
|
||||
"nP4Dw6l3IwmQH4ppjg08qTKvyrXcF2dPDWa98Xw6bA5G085Z/b/6/6GpkvKx/q6i\n" +
|
||||
"UqKwF7q5hkDcB+N4/5SgggN+MIIDejCCA3YwggJeoAMCAQICAWQwDQYJKoZIhvcN\n" +
|
||||
"AQELBQAwLTEUMBIGA1UEChMLU29tZUNvbXBhbnkxFTATBgNVBAMTDFJvb3QgQ0Eg\n" +
|
||||
"Q2VydDAeFw0xNjA4MDcyMTM3MTlaFw0xODA4MDcyMTM3MTlaMDUxFDASBgNVBAoT\n" +
|
||||
"C1NvbWVDb21wYW55MR0wGwYDVQQDExRJbnRlcm1lZGlhdGUgQ0EgQ2VydDCCASIw\n" +
|
||||
"DQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAJyUeQpxOxipUI4oBMUieoR7t9Np\n" +
|
||||
"nND3AOkw4LCIrT2A/6/EQWwbhOdTkOyD+wF5nz1Fd//qTv7scepoGOTul3lJeymn\n" +
|
||||
"YVT7T3C9AVVXrwkjnUzFWt4leM0aWgulMtqLlBZ2nypw7ZW4noIMhE1KDYFTSWAP\n" +
|
||||
"S9FzYbUpxDaCxwuD6tL/DrDbbDlhUTYjEzgOPTTQwcPOVoD8hQMY6juM9CdM8XVq\n" +
|
||||
"t1uK0jAfMa5Lpb9kb49xnH2CSv2m/FdSCejzFgqbowEmNwc72D5zewSrgY21iT4G\n" +
|
||||
"XT2H19XMXhvNLtLTrjH1lojTjUjEgO5vct9OEANICqpaxRZ/VOIVPPZL9SMCAwEA\n" +
|
||||
"AaOBmDCBlTAPBgNVHRMBAf8EBTADAQH/MDIGCCsGAQUFBwEBBCYwJDAiBggrBgEF\n" +
|
||||
"BQcwAYYWaHR0cDovL2xvY2FsaG9zdDozOTEzNDAfBgNVHSMEGDAWgBSTTLHoxMiV\n" +
|
||||
"AfbYlsnFXM76YjFUGTAdBgNVHQ4EFgQUYT525lwHCI4CmuWs8a7poaeKRJ4wDgYD\n" +
|
||||
"VR0PAQH/BAQDAgGGMA0GCSqGSIb3DQEBCwUAA4IBAQBOJzhXVvToqz50b8YoUF2C\n" +
|
||||
"/Qly7hkM+ba9F4DfMEmOlJ/W+gkYiu6G4CBoplXYb1AtanUXMCaoDnydv40ef+UK\n" +
|
||||
"NE1afsMOHRzXVKI+97WoCe407tGTM+WXadLsHeEQ/7Mr03lXGz3N5uGsLYBL0YM6\n" +
|
||||
"QzHEnij2ViJ5aO3256MCkgFAHzvHXtHA5MRAZMzyMxjbtuenHS2TqjivcCyfZkNM\n" +
|
||||
"yoIv9jbJXTXNqZf+o5BqQOri+ZSbJn6PbA7rFjR1dWIIKow0NfYa3+NFbrgvRhZf\n" +
|
||||
"6gFt5mqzLhM2PzYilVMbctatbOPEjoOS6BDww5G8oDreyAi9x2BtVbn4QtUNmGPX";
|
||||
|
||||
// OCSP Response Status: successful (0x0)
|
||||
// Response Type: Basic OCSP Response
|
||||
// Version: 1 (0x0)
|
||||
// Responder Id: O = SomeCompany, CN = Root CA Cert
|
||||
// Produced At: Sep 6 21:37:20 2016 GMT
|
||||
// Responses:
|
||||
// Certificate ID:
|
||||
// Hash Algorithm: sha1
|
||||
// Issuer Name Hash: C8ED9F4E9AC0052A978257C569E6A7C9C45F5CB5
|
||||
// Issuer Key Hash: 934CB1E8C4C89501F6D896C9C55CCEFA62315419
|
||||
// Serial Number: 64
|
||||
// Cert Status: good
|
||||
// This Update: Sep 6 21:37:20 2016 GMT
|
||||
// Next Update: Sep 6 22:37:19 2016 GMT
|
||||
private static final String INT_CA_OCSP_RESP =
|
||||
"MIIFJQoBAKCCBR4wggUaBgkrBgEFBQcwAQEEggULMIIFBzCBrKEvMC0xFDASBgNV\n" +
|
||||
"BAoTC1NvbWVDb21wYW55MRUwEwYDVQQDEwxSb290IENBIENlcnQYDzIwMTYwOTA2\n" +
|
||||
"MjEzNzIwWjBkMGIwOjAJBgUrDgMCGgUABBTI7Z9OmsAFKpeCV8Vp5qfJxF9ctQQU\n" +
|
||||
"k0yx6MTIlQH22JbJxVzO+mIxVBkCAWSAABgPMjAxNjA5MDYyMTM3MjBaoBEYDzIw\n" +
|
||||
"MTYwOTA2MjIzNzE5WqECMAAwDQYJKoZIhvcNAQELBQADggEBAAgs8jpuEejPD8qO\n" +
|
||||
"+xckvqMz/5pItOHaSB0xyPNpIapqjcDkLktJdBVq5XJWernO9DU+P7yr7TDbvo6h\n" +
|
||||
"P5jBZklLz16Z1aRlEyow2jhelVjNl6nxoiij/6LOGK4tLHa8fK7hTB4Ykw22Bxzt\n" +
|
||||
"LcbrU5jgUDhdZkTrs+rWM8nw7mVWIQYQfwzCMDZ5a02MxzhdwggJGRzqMrbhY/Q7\n" +
|
||||
"RRUK3ohSgzHmLjVkvA0KeM/Px7EefzbEbww08fSsLybmBoIEbcckWSHkkXx4cuIR\n" +
|
||||
"T9FiTz4Ms4r8qzPCo61qeklE2I5lfnfieROADV6sfwbul/0U1HqKhHVaxJ8yYw+T\n" +
|
||||
"/FMxrUKgggNAMIIDPDCCAzgwggIgoAMCAQICAQEwDQYJKoZIhvcNAQELBQAwLTEU\n" +
|
||||
"MBIGA1UEChMLU29tZUNvbXBhbnkxFTATBgNVBAMTDFJvb3QgQ0EgQ2VydDAeFw0x\n" +
|
||||
"NjA3MDgyMTM3MThaFw0xOTA2MjgyMTM3MThaMC0xFDASBgNVBAoTC1NvbWVDb21w\n" +
|
||||
"YW55MRUwEwYDVQQDEwxSb290IENBIENlcnQwggEiMA0GCSqGSIb3DQEBAQUAA4IB\n" +
|
||||
"DwAwggEKAoIBAQCJTTN1mBKpFNnpVxGa1fUEg2wysMmixB2nyxXIh/BHaGoN6v+4\n" +
|
||||
"xMxScSOyWfN9bXW1kAZuh4KPvKb3rThVtQXJC/HiI8jjjT9ginxWnjGqM7FotXIM\n" +
|
||||
"Wvq46VP0XpHPswar78uEq/e08E+p0Ii5YIwtZwn0dUlaTudaqAwoUu5+/Oa7ChGc\n" +
|
||||
"cP6fpJFVkmX31O8zfXOuOXD4P/y/5I4snijJGqrhkDmEuvIEIMvGGV0L9RN5f/Hv\n" +
|
||||
"AotbNQ2AOcKQm2gaoE8POEa+M5VBEAYF80JUbfpj83mg6XRtRHhpF63HZGftBDBC\n" +
|
||||
"6DlVzhJ+lTbM+r09yCq570AUpzdOsav4lsAtAgMBAAGjYzBhMA8GA1UdEwEB/wQF\n" +
|
||||
"MAMBAf8wHwYDVR0jBBgwFoAUk0yx6MTIlQH22JbJxVzO+mIxVBkwHQYDVR0OBBYE\n" +
|
||||
"FJNMsejEyJUB9tiWycVczvpiMVQZMA4GA1UdDwEB/wQEAwIBhjANBgkqhkiG9w0B\n" +
|
||||
"AQsFAAOCAQEAAIvjZbMT/bdiIYmSB0SRkgWbkJVyI8GCMG6t2VnPwKWftKMbZew2\n" +
|
||||
"EIubkTbfP6KXBjQh3CGNHxvd0m5A7m128T2AVug/0VI28+fWa8mj+cpueadTIx0z\n" +
|
||||
"qsvgDPIONcTUyYpHN1FBV153JHhW2sIowrG+73+9aMMyrsYAV4vZ9a5l17Z3CqAP\n" +
|
||||
"y61FV6FJSnn3YA57FLJd0NvXomxNx0qs4jDKADi5tI43pBRliIC3k7ckWEdXdHTW\n" +
|
||||
"lMLB060KT48cVE59cbAD6Vyn8z57GAGXnommhO+RsG1pR86zYp78XWUHdM3LaXwS\n" +
|
||||
"X1ag//pVgDZcPqzmiidhsgmiSDbMmiPyNg==";
|
||||
|
||||
// Do path validation as if it is always Tue, 06 Sep 2016 22:12:21 GMT
|
||||
// This value is within the lifetimes of all certificates and both OCSP
|
||||
// responses.
|
||||
private static final Date EVAL_DATE = new Date(1473199941000L);
|
||||
|
||||
private static final Base64.Decoder DECODER = Base64.getMimeDecoder();
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
TrustAnchor anchor;
|
||||
CertificateFactory cf = CertificateFactory.getInstance("X.509");
|
||||
PEMDecoder pemDecoder = PEMDecoder.of();
|
||||
X509Certificate rootCert = pemDecoder.decode(ROOT_CA_CERT, X509Certificate.class);
|
||||
X509Certificate eeCert = pemDecoder.decode(EE_CERT, X509Certificate.class);
|
||||
X509Certificate intCaCert = pemDecoder.decode(INT_CA_CERT, X509Certificate.class);
|
||||
List<X509Certificate> certList = new ArrayList<X509Certificate>() {{
|
||||
add(eeCert);
|
||||
add(intCaCert);
|
||||
}};
|
||||
|
||||
System.out.println("==== Certificate Path =====");
|
||||
for (X509Certificate c : certList) {
|
||||
System.out.println(c + "\n");
|
||||
}
|
||||
System.out.println("===========================");
|
||||
|
||||
System.out.println("===== Test 1: TA(X509Certificate) =====");
|
||||
anchor = new TrustAnchor(rootCert, null);
|
||||
runTest(cf, certList, anchor);
|
||||
|
||||
System.out.println("===== Test 2: TA(X500Principal, PublicKey =====");
|
||||
anchor = new TrustAnchor(rootCert.getSubjectX500Principal(),
|
||||
rootCert.getPublicKey(), null);
|
||||
runTest(cf, certList, anchor);
|
||||
|
||||
System.out.println("===== Test 3: TA(String, PublicKey =====");
|
||||
anchor = new TrustAnchor(rootCert.getSubjectX500Principal().getName(),
|
||||
rootCert.getPublicKey(), null);
|
||||
runTest(cf, certList, anchor);
|
||||
}
|
||||
|
||||
private static void runTest(CertificateFactory cf,
|
||||
List<X509Certificate> certList, TrustAnchor anchor)
|
||||
throws Exception {
|
||||
CertPath path = cf.generateCertPath(certList);
|
||||
CertPathValidator validator = CertPathValidator.getInstance("PKIX");
|
||||
|
||||
System.out.println(anchor);
|
||||
|
||||
// Attach the OCSP responses to a PKIXParameters object
|
||||
PKIXRevocationChecker pkrev =
|
||||
(PKIXRevocationChecker)validator.getRevocationChecker();
|
||||
Map<X509Certificate, byte[]> responseMap = new HashMap<>();
|
||||
responseMap.put(certList.get(0), DECODER.decode(EE_OCSP_RESP));
|
||||
responseMap.put(certList.get(1), DECODER.decode(INT_CA_OCSP_RESP));
|
||||
pkrev.setOcspResponses(responseMap);
|
||||
PKIXParameters params =
|
||||
new PKIXParameters(Collections.singleton(anchor));
|
||||
params.addCertPathChecker(pkrev);
|
||||
params.setDate(EVAL_DATE);
|
||||
|
||||
validator.validate(path, params);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,171 @@
|
|||
/*
|
||||
* Copyright (c) 2001, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @bug 4458951
|
||||
* @summary Check that Sun's PKIX implementation of
|
||||
* CertPathValidator.validate() and CertPathBuilder.build() throw an
|
||||
* InvalidAlgorithmParameterException if any of the TrustAnchors specified
|
||||
* contain nameConstraints
|
||||
* @modules java.base/sun.security.util
|
||||
*/
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import java.security.InvalidAlgorithmParameterException;
|
||||
import java.security.cert.CertificateFactory;
|
||||
import java.security.cert.CertPath;
|
||||
import java.security.cert.CertPathBuilder;
|
||||
import java.security.cert.CertPathBuilderResult;
|
||||
import java.security.cert.CertPathValidator;
|
||||
import java.security.cert.CertPathValidatorResult;
|
||||
import java.security.cert.PKIXParameters;
|
||||
import java.security.cert.PKIXBuilderParameters;
|
||||
import java.security.cert.TrustAnchor;
|
||||
import java.security.cert.X509Certificate;
|
||||
import java.security.cert.X509CertSelector;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import sun.security.util.DerInputStream;
|
||||
|
||||
/**
|
||||
* ValidateNC performs a validation and build of a certification path, using any
|
||||
* name constraints provided in the trust anchor's certificate. Using
|
||||
* Sun's provider, the validation and build should fail because name constraints
|
||||
* on trust anchors are not supported.
|
||||
*
|
||||
* @author Steve Hanna
|
||||
* @author Sean Mullan
|
||||
*/
|
||||
public final class ValidateNC {
|
||||
|
||||
private static CertPath path;
|
||||
private static PKIXParameters params;
|
||||
private static Set anchors;
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
|
||||
String[] certs = { "sun2labs2.cer", "labs2isrg2.cer" };
|
||||
|
||||
createPath(certs);
|
||||
try {
|
||||
validate(path, params);
|
||||
throw new Exception("CertPathValidator should have thrown an " +
|
||||
"InvalidAlgorithmParameterException");
|
||||
} catch (InvalidAlgorithmParameterException iape) {
|
||||
// success!
|
||||
}
|
||||
|
||||
try {
|
||||
X509CertSelector sel = new X509CertSelector();
|
||||
sel.setSubject("cn=sean");
|
||||
PKIXBuilderParameters bparams =
|
||||
new PKIXBuilderParameters(anchors, sel);
|
||||
build(bparams);
|
||||
throw new Exception("CertPathBuilder should have thrown an " +
|
||||
"InvalidAlgorithmParameterException");
|
||||
} catch (InvalidAlgorithmParameterException iape) {
|
||||
// success!
|
||||
}
|
||||
}
|
||||
|
||||
public static void createPath(String[] certs) throws Exception {
|
||||
|
||||
X509Certificate anchorCert = getCertFromFile(certs[0]);
|
||||
byte [] nameConstraints = anchorCert.getExtensionValue("2.5.29.30");
|
||||
if (nameConstraints != null) {
|
||||
DerInputStream in = new DerInputStream(nameConstraints);
|
||||
nameConstraints = in.getOctetString();
|
||||
}
|
||||
TrustAnchor anchor = new TrustAnchor(anchorCert, nameConstraints);
|
||||
List list = new ArrayList();
|
||||
for (int i = 1; i < certs.length; i++) {
|
||||
list.add(0, getCertFromFile(certs[i]));
|
||||
}
|
||||
CertificateFactory cf = CertificateFactory.getInstance("X509");
|
||||
path = cf.generateCertPath(list);
|
||||
|
||||
anchors = Collections.singleton(anchor);
|
||||
params = new PKIXParameters(anchors);
|
||||
params.setRevocationEnabled(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a DER-encoded X.509 certificate from a file.
|
||||
*
|
||||
* @param certFilePath path to file containing DER-encoded certificate
|
||||
* @return X509Certificate
|
||||
* @throws IOException on error
|
||||
*/
|
||||
public static X509Certificate getCertFromFile(String certFilePath)
|
||||
throws IOException {
|
||||
X509Certificate cert = null;
|
||||
try {
|
||||
File certFile = new File(System.getProperty("test.src", "."),
|
||||
certFilePath);
|
||||
FileInputStream certFileInputStream =
|
||||
new FileInputStream(certFile);
|
||||
CertificateFactory cf = CertificateFactory.getInstance("X509");
|
||||
cert = (X509Certificate)
|
||||
cf.generateCertificate(certFileInputStream);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
throw new IOException("Can't construct X509Certificate: " +
|
||||
e.getMessage());
|
||||
}
|
||||
return cert;
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform a PKIX validation.
|
||||
*
|
||||
* @param path CertPath to validate
|
||||
* @param params PKIXParameters to use in validation
|
||||
* @throws Exception on error
|
||||
*/
|
||||
public static void validate(CertPath path, PKIXParameters params)
|
||||
throws Exception {
|
||||
CertPathValidator validator =
|
||||
CertPathValidator.getInstance("PKIX", "SUN");
|
||||
CertPathValidatorResult cpvr = validator.validate(path, params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform a PKIX build.
|
||||
*
|
||||
* @param params PKIXBuilderParameters to use in the build
|
||||
* @throws Exception on error
|
||||
*/
|
||||
public static void build(PKIXBuilderParameters params)
|
||||
throws Exception {
|
||||
CertPathBuilder builder =
|
||||
CertPathBuilder.getInstance("PKIX", "SUN");
|
||||
CertPathBuilderResult cpbr = builder.build(params);
|
||||
}
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
|
|
@ -0,0 +1,63 @@
|
|||
/*
|
||||
* Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 6765046
|
||||
* @summary check that getMessage(cause) returns cause.toString if cause != null
|
||||
*/
|
||||
|
||||
import java.security.cert.CertPathValidatorException;
|
||||
|
||||
public class GetMessage {
|
||||
private static volatile boolean failed = false;
|
||||
public static void main(String[] args) throws Exception {
|
||||
|
||||
Throwable[] causes = {
|
||||
new Throwable(),
|
||||
new Throwable("message"),
|
||||
new Throwable("message", new Throwable()) };
|
||||
|
||||
for (Throwable cause: causes) {
|
||||
CertPathValidatorException cpve =
|
||||
new CertPathValidatorException(cause);
|
||||
|
||||
// from CertPathValidatorException(Throwable cause) spec:
|
||||
// The detail message is set to (cause==null ? null : cause.toString() )
|
||||
// (which typically contains the class and detail message of cause).
|
||||
String expMsg = (cause == null ? null : cause.toString());
|
||||
String actualMsg = cpve.getMessage();
|
||||
|
||||
boolean msgsEqual =
|
||||
(expMsg == null ? actualMsg == null : expMsg.equals(actualMsg));
|
||||
if (!msgsEqual) {
|
||||
System.out.println("expected message:" + expMsg);
|
||||
System.out.println("getMessage():" + actualMsg);
|
||||
failed = true;
|
||||
}
|
||||
}
|
||||
if (failed) {
|
||||
throw new Exception("Some tests FAILED");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,67 @@
|
|||
/*
|
||||
* Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 6465942
|
||||
* @summary unit test for CertPathValidatorException.Reason
|
||||
*/
|
||||
|
||||
import java.security.cert.CertPathValidatorException;
|
||||
import java.security.cert.CertPathValidatorException.BasicReason;
|
||||
|
||||
public class ReasonTest {
|
||||
private static volatile boolean failed = false;
|
||||
public static void main(String[] args) throws Exception {
|
||||
|
||||
// check that getReason returns UNSPECIFIED if reason not specified
|
||||
CertPathValidatorException cpve = new CertPathValidatorException("abc");
|
||||
if (cpve.getReason() != BasicReason.UNSPECIFIED) {
|
||||
failed = true;
|
||||
System.err.println("FAILED: unexpected reason: " + cpve.getReason());
|
||||
}
|
||||
|
||||
// check that getReason returns specified reason
|
||||
cpve = new CertPathValidatorException
|
||||
("abc", null, null, -1, BasicReason.REVOKED);
|
||||
if (cpve.getReason() != BasicReason.REVOKED) {
|
||||
failed = true;
|
||||
System.err.println("FAILED: unexpected reason: " + cpve.getReason());
|
||||
}
|
||||
|
||||
// check that ctor throws NPE when reason is null
|
||||
try {
|
||||
cpve = new CertPathValidatorException("abc", null, null, -1, null);
|
||||
failed = true;
|
||||
System.err.println("ctor did not throw NPE for null reason");
|
||||
} catch (Exception e) {
|
||||
if (!(e instanceof NullPointerException)) {
|
||||
failed = true;
|
||||
System.err.println("FAILED: unexpected exception: " + e);
|
||||
}
|
||||
}
|
||||
if (failed) {
|
||||
throw new Exception("Some tests FAILED");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,113 @@
|
|||
/*
|
||||
* Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 6465942
|
||||
* @summary Test deserialization of CertPathValidatorException
|
||||
*/
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
//import java.io.FileOutputStream;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.security.cert.Certificate;
|
||||
import java.security.cert.CertificateFactory;
|
||||
import java.security.cert.CertPath;
|
||||
import java.security.cert.CertPathValidatorException;
|
||||
import java.security.cert.CertPathValidatorException.BasicReason;
|
||||
import java.util.Collections;
|
||||
|
||||
/**
|
||||
* This class tests to see if CertPathValidatorException can be serialized and
|
||||
* deserialized properly.
|
||||
*/
|
||||
public class Serial {
|
||||
private static volatile boolean failed = false;
|
||||
public static void main(String[] args) throws Exception {
|
||||
|
||||
File f = new File(System.getProperty("test.src", "."), "cert_file");
|
||||
FileInputStream fis = new FileInputStream(f);
|
||||
CertificateFactory cf = CertificateFactory.getInstance("X.509");
|
||||
Certificate c = cf.generateCertificate(fis);
|
||||
fis.close();
|
||||
CertPath cp = cf.generateCertPath(Collections.singletonList(c));
|
||||
|
||||
CertPathValidatorException cpve1 =
|
||||
new CertPathValidatorException
|
||||
("Test", new Exception("Expired"), cp, 0, BasicReason.EXPIRED);
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
// FileOutputStream fos = new FileOutputStream("jdk7.serial");
|
||||
ObjectOutputStream oos = new ObjectOutputStream(baos);
|
||||
// ObjectOutputStream foos = new ObjectOutputStream(fos);
|
||||
oos.writeObject(cpve1);
|
||||
// foos.writeObject(cpve1);
|
||||
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
|
||||
ObjectInputStream ois = new ObjectInputStream(bais);
|
||||
CertPathValidatorException cpve2 =
|
||||
(CertPathValidatorException) ois.readObject();
|
||||
check(!cpve1.getMessage().equals(cpve2.getMessage()),
|
||||
"CertPathValidatorException messages not equal");
|
||||
check(!cpve1.getCause().getMessage().equals(cpve2.getCause().getMessage()),
|
||||
"CertPathValidatorException causes not equal");
|
||||
check(!cpve1.getCertPath().equals(cpve2.getCertPath()),
|
||||
"CertPathValidatorException certpaths not equal");
|
||||
check(cpve1.getIndex() != cpve2.getIndex(),
|
||||
"CertPathValidatorException indexes not equal");
|
||||
check(cpve1.getReason() != cpve2.getReason(),
|
||||
"CertPathValidatorException reasons not equal");
|
||||
oos.close();
|
||||
ois.close();
|
||||
|
||||
f = new File(System.getProperty("test.src", "."), "jdk6.serial");
|
||||
fis = new FileInputStream(f);
|
||||
ois = new ObjectInputStream(fis);
|
||||
cpve2 = (CertPathValidatorException) ois.readObject();
|
||||
check(!cpve1.getMessage().equals(cpve2.getMessage()),
|
||||
"CertPathValidatorException messages not equal");
|
||||
check(!cpve1.getCause().getMessage().equals(cpve2.getCause().getMessage()),
|
||||
"CertPathValidatorException causes not equal");
|
||||
check(!cpve1.getCertPath().equals(cpve2.getCertPath()),
|
||||
"CertPathValidatorException certpaths not equal");
|
||||
check(cpve1.getIndex() != cpve2.getIndex(),
|
||||
"CertPathValidatorException indexes not equal");
|
||||
// System.out.println(cpve2.getReason());
|
||||
check(cpve2.getReason() != BasicReason.UNSPECIFIED,
|
||||
"CertPathValidatorException reasons not equal");
|
||||
oos.close();
|
||||
ois.close();
|
||||
if (failed) {
|
||||
throw new Exception("Some tests FAILED");
|
||||
}
|
||||
}
|
||||
|
||||
private static void check(boolean expr, String message) {
|
||||
if (expr) {
|
||||
failed = true;
|
||||
System.err.println("FAILED: " + message);
|
||||
}
|
||||
}
|
||||
}
|
||||
BIN
test/jdk/java/security/cert/CertPathValidatorException/cert_file
Normal file
BIN
test/jdk/java/security/cert/CertPathValidatorException/cert_file
Normal file
Binary file not shown.
Binary file not shown.
53
test/jdk/java/security/cert/CertStore/NoLDAP.java
Normal file
53
test/jdk/java/security/cert/CertStore/NoLDAP.java
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
/*
|
||||
* Copyright (c) 2012, 2025, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/* @test
|
||||
* @bug 8004502
|
||||
* @summary Sanity check that NoSuchAlgorithmException is thrown when requesting
|
||||
* a CertStore of type "LDAP" and LDAP is not available.
|
||||
* @library /test/lib
|
||||
*/
|
||||
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.cert.CertStore;
|
||||
import java.security.cert.LDAPCertStoreParameters;
|
||||
import jtreg.SkippedException;
|
||||
|
||||
|
||||
public class NoLDAP {
|
||||
public static void main(String[] args) throws Exception {
|
||||
try {
|
||||
Class.forName("javax.naming.ldap.LdapName");
|
||||
throw new SkippedException("LDAP is present");
|
||||
} catch (ClassNotFoundException ignore) {
|
||||
System.err.println("Expected: class not found exception " + ignore.getMessage());
|
||||
}
|
||||
|
||||
try {
|
||||
CertStore.getInstance("LDAP", new LDAPCertStoreParameters());
|
||||
throw new RuntimeException("NoSuchAlgorithmException expected");
|
||||
} catch (NoSuchAlgorithmException x) {
|
||||
System.out.println("NoSuchAlgorithmException thrown as expected");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,49 @@
|
|||
/*
|
||||
* Copyright (c) 2000, 2009, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 4302894
|
||||
* @summary check that bad X.509 encoded certificate data throws
|
||||
* CertificateParsingException
|
||||
*/
|
||||
|
||||
import java.io.*;
|
||||
import java.security.cert.*;
|
||||
|
||||
public class BadX509CertData {
|
||||
|
||||
private static final String data = "\211\0\225\3\5\0\70\154\157\231";
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
CertificateFactory factory = CertificateFactory.getInstance("X.509");
|
||||
InputStream is = new ByteArrayInputStream(data.getBytes("ISO8859_1"));
|
||||
try {
|
||||
Certificate cert = factory.generateCertificate(is);
|
||||
} catch (CertificateException ce) {
|
||||
return;
|
||||
}
|
||||
throw new Exception("CertificateFactory.generateCertificate() did "
|
||||
+ "not throw CertificateParsingException on bad X.509 cert data");
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,66 @@
|
|||
/*
|
||||
* Copyright (c) 2000, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 4371801
|
||||
* @summary check that generateCertificates() returns an empty
|
||||
* Collection when the input stream contains an encoded
|
||||
* PKCS #7 SignedData object with no certificates.
|
||||
*/
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.security.cert.CertificateFactory;
|
||||
import java.util.Collection;
|
||||
|
||||
public class GenerateCertificatesEmptyCollection {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
/*
|
||||
* create an empty SignedData content type in ASN.1
|
||||
* as defined in PKCS#7
|
||||
*/
|
||||
byte[] b = { 0x30, 0x23,
|
||||
/* contentInfo ::= signedData */
|
||||
0x06, 0x09, 0x2A, (byte)0x86, 0x48,
|
||||
(byte)0x86, (byte)0xF7, 0x0D,
|
||||
0x01, 0x07, 0x02,
|
||||
0x00, 0x16,
|
||||
0x30, 0x14, /* SignedData */
|
||||
0x02, 0x01, 0x01, /* version */
|
||||
0x31, 0x00, /* digestAlgorithms */
|
||||
0x30, 0x0B, /* contentInfo ::= data */
|
||||
0x06, 0x09, 0x2A, (byte)0x86, 0x48,
|
||||
(byte)0x86, (byte)0xF7, 0x0D,
|
||||
0x01, 0x07, 0x01,
|
||||
/* certificates are absent */
|
||||
0x31, 0x00 /* signerInfos */
|
||||
};
|
||||
|
||||
CertificateFactory cf = CertificateFactory.getInstance( "X509", "SUN");
|
||||
Collection c = cf.generateCertificates( new ByteArrayInputStream(b));
|
||||
if (!c.isEmpty())
|
||||
throw new Exception("CertificateFactory.generateCertificates() "
|
||||
+ "did not return an empty Collection");
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,64 @@
|
|||
/*
|
||||
* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 6813340
|
||||
* @summary X509Factory should not depend on is.available()==0
|
||||
*/
|
||||
import java.io.*;
|
||||
import java.security.cert.*;
|
||||
|
||||
/**
|
||||
* Tests ol'Mac style file, end witha single '\r'
|
||||
*/
|
||||
public class ReturnStream {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
FileInputStream fin = new FileInputStream(new File(new File(
|
||||
System.getProperty("test.src", "."), "openssl"), "pem"));
|
||||
byte[] buffer = new byte[4096];
|
||||
int size = 0;
|
||||
while (true) {
|
||||
int len = fin.read(buffer, size, 4096-size);
|
||||
if (len < 0) break;
|
||||
size += len;
|
||||
}
|
||||
fin.close();
|
||||
|
||||
// Make a copy
|
||||
System.arraycopy(buffer, 0, buffer, size, size);
|
||||
size += size;
|
||||
|
||||
// Create a ol'Mac style file.
|
||||
for (int i=0; i<size; i++) {
|
||||
if (buffer[i] == '\n') buffer[i] = '\r';
|
||||
}
|
||||
|
||||
CertificateFactory factory = CertificateFactory.getInstance("X.509");
|
||||
if (factory.generateCertificates(
|
||||
new ByteArrayInputStream(buffer, 0, size)).size() != 2) {
|
||||
throw new Exception("Cert not OK");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,94 @@
|
|||
/*
|
||||
* Copyright (c) 2010, 2025, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 6813340
|
||||
* @summary X509Factory should not depend on is.available()==0
|
||||
*/
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.PipedInputStream;
|
||||
import java.io.PipedOutputStream;
|
||||
import java.security.cert.CertificateFactory;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
public class SlowStream {
|
||||
public static void main(String[] args) throws Exception {
|
||||
final var outputStream = new PipedOutputStream();
|
||||
final var inputStream = new PipedInputStream(outputStream);
|
||||
|
||||
final var failed = new AtomicBoolean(false);
|
||||
|
||||
final var writer = new Thread(() -> {
|
||||
try {
|
||||
for (int i = 0; i < 5; i++) {
|
||||
try (final var fin = new FileInputStream(new File(
|
||||
new File(System.getProperty("test.src", "."),
|
||||
"openssl"),
|
||||
"pem"))) {
|
||||
|
||||
fin.transferTo(outputStream);
|
||||
|
||||
Thread.sleep(2000);
|
||||
}
|
||||
}
|
||||
outputStream.close();
|
||||
} catch (final Exception e) {
|
||||
System.out.println("Writer Thread Error: ");
|
||||
e.printStackTrace(System.out);
|
||||
failed.set(true);
|
||||
}
|
||||
});
|
||||
|
||||
final var reader = new Thread(() -> {
|
||||
try {
|
||||
final var factory = CertificateFactory.getInstance("X.509");
|
||||
final var numOfCerts = factory.generateCertificates(inputStream).size();
|
||||
if (numOfCerts != 5) {
|
||||
throw new Exception(
|
||||
String.format("Not all certs read. %d found 5 expected", numOfCerts)
|
||||
);
|
||||
}
|
||||
inputStream.close();
|
||||
} catch (final Exception e) {
|
||||
System.out.println("Reader Thread Error: ");
|
||||
e.printStackTrace(System.out);
|
||||
failed.set(true);
|
||||
}
|
||||
});
|
||||
|
||||
writer.start();
|
||||
reader.start();
|
||||
|
||||
writer.join();
|
||||
reader.join();
|
||||
|
||||
if (failed.get()) {
|
||||
throw new RuntimeException(
|
||||
"The test failed, please check the reader and writer threads output"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,570 @@
|
|||
/*
|
||||
* Copyright (c) 2003, 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @bug 4776466 8032573
|
||||
* @summary check that CertificateFactory rejects invalid encoded X.509 certs
|
||||
*/
|
||||
|
||||
import java.io.*;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.LinkedList;
|
||||
import javax.security.auth.x500.X500Principal;
|
||||
import java.security.GeneralSecurityException;
|
||||
import java.security.cert.*;
|
||||
|
||||
public class DetectInvalidEncoding {
|
||||
|
||||
// Originally found in the test file:
|
||||
// java/security/cert/CertificateFactory/invalidEncodedCerts/invalidcert.pem
|
||||
// The first character of the PEM encoding has been changed from "M" to
|
||||
// "X" to force a failure during decoding.
|
||||
private static final String INVALID_CERT =
|
||||
"-----BEGIN CERTIFICATE-----\n" +
|
||||
"XIICJjCCAdCgAwIBAgIBITANBgkqhkiG9w0BAQQFADCBqTELMAkGA1UEBhMCVVMx\n" +
|
||||
"EzARBgNVBAgTCkNhbGlmb3JuaWExFjAUBgNVBAcTDVNhbiBGcmFuY2lzY28xFTAT\n" +
|
||||
"BgNVBAoTDEJFQSBXZWJMb2dpYzERMA8GA1UECxMIU2VjdXJpdHkxIzAhBgNVBAMT\n" +
|
||||
"GkRlbW8gQ2VydGlmaWNhdGUgQXV0aG9yaXR5MR4wHAYJKoZIhvcNAQkBFg9zdXBw\n" +
|
||||
"b3J0QGJlYS5jb20wHhcNMDAwNTMwMjEzODAxWhcNMDQwNTEzMjEzODAxWjCBjDEL\n" +
|
||||
"MAkGA1UEBhMCVVMxEzARBgNVBAgTCkNhbGlmb3JuaWExFjAUBgNVBAcTDVNhbiBG\n" +
|
||||
"cmFuY2lzY28xFTATBgNVBAoTDEJFQSBXZWJMb2dpYzEZMBcGA1UEAxMQd2VibG9n\n" +
|
||||
"aWMuYmVhLmNvbTEeMBwGCSqGSIb3DQEJARYPc3VwcG9ydEBiZWEuY29tMFwwDQYJ\n" +
|
||||
"KoZIhvcNAQEBBQADSwAwSAJBALdsXEHqKHgs6zj0hU5sXMAUHzoT8kgWXmNkKHXH\n" +
|
||||
"79qbPh6EfdlriW9G/AbRF/pKrCQu7hhllAxREbqTuSlf2EMCAwEAATANBgkqhkiG\n" +
|
||||
"9w0BAQQFAANBACgmqflL5m5LNeJGpWx9aIoABCiuDcpw1fFyegsqGX7CBhffcruS\n" +
|
||||
"1p8h5vkHVbMu1frD1UgGnPlOO/K7Ig/KrsU=\n" +
|
||||
"-----END CERTIFICATE-----";
|
||||
|
||||
// Created with keytool:
|
||||
// keytool -genkeypair -keyalg rsa -keysize 2048 -keystore <KS_FILE>
|
||||
// -alias root -sigalg SHA256withRSA -dname "CN=Root, O=SomeCompany"
|
||||
// -validity 730 -ext bc:critical=ca:true
|
||||
// -ext ku:critical=keyCertSign,cRLSign
|
||||
private static final String SINGLE_ROOT_CERT =
|
||||
"-----BEGIN CERTIFICATE-----\n" +
|
||||
"MIIDCjCCAfKgAwIBAgIEDUiw+DANBgkqhkiG9w0BAQsFADAlMRQwEgYDVQQKEwtT\n" +
|
||||
"b21lQ29tcGFueTENMAsGA1UEAxMEUm9vdDAeFw0xNDA4MjgyMTI5MjZaFw0xNjA4\n" +
|
||||
"MjcyMTI5MjZaMCUxFDASBgNVBAoTC1NvbWVDb21wYW55MQ0wCwYDVQQDEwRSb290\n" +
|
||||
"MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA0VFecSNdH6CJhPOSG127\n" +
|
||||
"tuvld4y7GGJ0kQf3Q0b8qgprsXAmn0/bQR+YX7PfS408cFW+q2SWXeY2kC/3chvi\n" +
|
||||
"2syMsGdUJrDzuMbYsbvKPKyuJ2GJskX3mSbLMJj5Tzhg4qmwbzDTFIJ51yGa1Wmh\n" +
|
||||
"i2+4PhltqT0TohvSVJlBrOWNhmvwv5UWsF4e2i04rebDZQoWkmD3MpImZXF/HYre\n" +
|
||||
"9P8NP97vN0xZmh5PySHy2ILXN3ZhTn3tq0YxNSQTaMUfhgoyzWFvZKAnm/tZIh/1\n" +
|
||||
"oswwEQPIZJ25AUTm9r3YPQXl1hsNdLU0asEVYRsgzGSTX5gCuUY+KzhStzisOcUY\n" +
|
||||
"uQIDAQABo0IwQDAPBgNVHRMBAf8EBTADAQH/MA4GA1UdDwEB/wQEAwIBBjAdBgNV\n" +
|
||||
"HQ4EFgQUz1FBNixG/KCgcn6FOWzxP1hujG0wDQYJKoZIhvcNAQELBQADggEBAL60\n" +
|
||||
"ZaNc6eIMbKntGVE/pdxxyKwPdDyAAeEevX23KRWoLbQjHXo5jrfDPhI5k45ztlyU\n" +
|
||||
"+tIQbc81LlCl88I4dIx0fvEbxjNaAYhFNXwwSQBs2CuEAdRK8hodXbRcEeI+G10F\n" +
|
||||
"ARIVs2C7JNm/RhxskCWgj6tFIOGaTZ9gHyvlQUEM18sr5fXZlXTqspZCmz3t5XPi\n" +
|
||||
"5/wYLv6vk7k3G8WzMHbBE0bYI+61cCc8rbMHldtymbwSwiqfKC9y7oPEfRCbzVUe\n" +
|
||||
"fgrKcOyVWDuw0y0hhsQL/oONjPp4uK/bl9B7T84t4+ihxdocWKx6eyhFvOvZH9t2\n" +
|
||||
"kUylb9yBUYStwGExMHg=\n" +
|
||||
"-----END CERTIFICATE-----";
|
||||
|
||||
// Created with keytool:
|
||||
// keytool -genkeypair -keyalg rsa -keysize 2048 -keystore <KS_FILE>
|
||||
// -alias root -sigalg SHA256withRSA
|
||||
// -dname "CN=Intermed, O=SomeCompany" -validity 730
|
||||
// -ext bc:critical=ca:true -ext ku:critical=keyCertSign,cRLSign
|
||||
// keytool -certreq -keystore <KS_FILE> -sigalg SHA256withRSA
|
||||
// -alias intermed -dname "CN=Intermed, O=SomeCompany"
|
||||
// keytool -gencert -keystore <KS_FILE> -alias intermed
|
||||
// -sigalg SHA256withRSA -validity 730
|
||||
// -ext bc:critical=ca:true -ext ku:critical=keyCertSign,cRLSign
|
||||
private static final String INTERMED_CA_CERT =
|
||||
"-----BEGIN CERTIFICATE-----\n" +
|
||||
"MIIDLzCCAhegAwIBAgIEIIgOyDANBgkqhkiG9w0BAQsFADAlMRQwEgYDVQQKEwtT\n" +
|
||||
"b21lQ29tcGFueTENMAsGA1UEAxMEUm9vdDAeFw0xNDA4MjgyMjUyNDJaFw0xNjA4\n" +
|
||||
"MDcyMjUyNDJaMCkxFDASBgNVBAoTC1NvbWVDb21wYW55MREwDwYDVQQDEwhJbnRl\n" +
|
||||
"cm1lZDCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAJEecvTWla8kdWx+\n" +
|
||||
"HHu5ryfBpJ95I7V4MEajnmzJVZcwvKhDjlDgABDMuVwFEUUSyeOdbWJF3DLKnyMD\n" +
|
||||
"KTx6/58kuVak3NX2TJ8cmmIlKf1upFbdrEtjYViSnNrApprfO8B3ORdBbO6QDYza\n" +
|
||||
"IkAWdI5GllFnVkb4yhMUBg3zfhglF+bl3D3lVRlp9bCrUZoNRs+mZjhVbcMn22ej\n" +
|
||||
"TfG5Y3VpNM4SN8dFIxPQLLk/aao+cmWEQdbQ0R6ydemRukqrw170olSVLeoGGala\n" +
|
||||
"3D4oJckde8EgNPcghcsdQ6tpGhkpFhmoyzEsuToR7Gq9UT5V2kkqJneiKXqQg4wz\n" +
|
||||
"vMAlUGECAwEAAaNjMGEwHwYDVR0jBBgwFoAUOw+92bevFoJz96pR1DrAkPPUKb0w\n" +
|
||||
"DwYDVR0TAQH/BAUwAwEB/zAOBgNVHQ8BAf8EBAMCAQYwHQYDVR0OBBYEFLbnErBs\n" +
|
||||
"q/Mhci5XElfjjLZp3GRyMA0GCSqGSIb3DQEBCwUAA4IBAQAq8y2DpkSV31IXZ1vr\n" +
|
||||
"/Ye+Nj/2NvBydFeHVRGMAN1LJv6/Q42TCSXbr6cDQ4NWQUtPm90yZBYJSznkbShx\n" +
|
||||
"HOJEE6R8PRJvoUtMm7fJrNtkybTt6jX4j50Lw8gdYB/rgZb4z8ZQZVEo/0zpW4HV\n" +
|
||||
"Gs+q4z8TkdmLR18hl39sUEsxt99AOBk8NtKKVNfBWq9b0QDhRkXfmqhyeXdDsHOV\n" +
|
||||
"8ksulsa7hseheHhdjziEOpQugh8qzSea2kFPrLB53VjWfa4qDzEPaNhahho9piCu\n" +
|
||||
"82XDnOrcEk9KyHWM7sa7vtK7++W+0MXD/p9nkZ6NHrJXweLriU0DXO6ZY3mzNKJK\n" +
|
||||
"435M\n" +
|
||||
"-----END CERTIFICATE-----";
|
||||
|
||||
// Subordinate cert created using keytool, both certs exported to
|
||||
// files individually, then use openssl to place in a PKCS#7:
|
||||
// openssl crl2pkcs7 -nocrl -certfile <INTERMED-CERT-PEM>
|
||||
// -certfile <ROOT-CERT-PEM> -out <P7-DEST-PEM-FILE>
|
||||
private static final String PKCS7_INTERMED_ROOT_CERTS =
|
||||
"-----BEGIN PKCS7-----\n" +
|
||||
"MIIGbgYJKoZIhvcNAQcCoIIGXzCCBlsCAQExADALBgkqhkiG9w0BBwGgggZBMIID\n" +
|
||||
"LzCCAhegAwIBAgIEIIgOyDANBgkqhkiG9w0BAQsFADAlMRQwEgYDVQQKEwtTb21l\n" +
|
||||
"Q29tcGFueTENMAsGA1UEAxMEUm9vdDAeFw0xNDA4MjgyMjUyNDJaFw0xNjA4MDcy\n" +
|
||||
"MjUyNDJaMCkxFDASBgNVBAoTC1NvbWVDb21wYW55MREwDwYDVQQDEwhJbnRlcm1l\n" +
|
||||
"ZDCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAJEecvTWla8kdWx+HHu5\n" +
|
||||
"ryfBpJ95I7V4MEajnmzJVZcwvKhDjlDgABDMuVwFEUUSyeOdbWJF3DLKnyMDKTx6\n" +
|
||||
"/58kuVak3NX2TJ8cmmIlKf1upFbdrEtjYViSnNrApprfO8B3ORdBbO6QDYzaIkAW\n" +
|
||||
"dI5GllFnVkb4yhMUBg3zfhglF+bl3D3lVRlp9bCrUZoNRs+mZjhVbcMn22ejTfG5\n" +
|
||||
"Y3VpNM4SN8dFIxPQLLk/aao+cmWEQdbQ0R6ydemRukqrw170olSVLeoGGala3D4o\n" +
|
||||
"Jckde8EgNPcghcsdQ6tpGhkpFhmoyzEsuToR7Gq9UT5V2kkqJneiKXqQg4wzvMAl\n" +
|
||||
"UGECAwEAAaNjMGEwHwYDVR0jBBgwFoAUOw+92bevFoJz96pR1DrAkPPUKb0wDwYD\n" +
|
||||
"VR0TAQH/BAUwAwEB/zAOBgNVHQ8BAf8EBAMCAQYwHQYDVR0OBBYEFLbnErBsq/Mh\n" +
|
||||
"ci5XElfjjLZp3GRyMA0GCSqGSIb3DQEBCwUAA4IBAQAq8y2DpkSV31IXZ1vr/Ye+\n" +
|
||||
"Nj/2NvBydFeHVRGMAN1LJv6/Q42TCSXbr6cDQ4NWQUtPm90yZBYJSznkbShxHOJE\n" +
|
||||
"E6R8PRJvoUtMm7fJrNtkybTt6jX4j50Lw8gdYB/rgZb4z8ZQZVEo/0zpW4HVGs+q\n" +
|
||||
"4z8TkdmLR18hl39sUEsxt99AOBk8NtKKVNfBWq9b0QDhRkXfmqhyeXdDsHOV8ksu\n" +
|
||||
"lsa7hseheHhdjziEOpQugh8qzSea2kFPrLB53VjWfa4qDzEPaNhahho9piCu82XD\n" +
|
||||
"nOrcEk9KyHWM7sa7vtK7++W+0MXD/p9nkZ6NHrJXweLriU0DXO6ZY3mzNKJK435M\n" +
|
||||
"MIIDCjCCAfKgAwIBAgIEdffjKTANBgkqhkiG9w0BAQsFADAlMRQwEgYDVQQKEwtT\n" +
|
||||
"b21lQ29tcGFueTENMAsGA1UEAxMEUm9vdDAeFw0xNDA4MjgyMjQ2MzZaFw0xNjA4\n" +
|
||||
"MjcyMjQ2MzZaMCUxFDASBgNVBAoTC1NvbWVDb21wYW55MQ0wCwYDVQQDEwRSb290\n" +
|
||||
"MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAhnXc8Avv54Gk2xjVa2yA\n" +
|
||||
"lBL/Cug1nyvKl5wqmN+foT6cMOX6bneCkJOJ4lSbch3gvl4ctlX/9hm3pB/+HhSr\n" +
|
||||
"em2NcLQrLEq8l9Ar4RnqfoXQR4Uy+4P6wj9OcVV7e/v/+ZPnStOoEAtb5nAwsR2b\n" +
|
||||
"hOC/tIFNwflrsmsmtMSoOiNftpYLFF4eOAdpDrXYMrqNu6ZxZsOQ7WZl4SsVOx1N\n" +
|
||||
"/IINXwBLyoHJDzLZ0iJEV0O6mh846s0n6QXeK1P5d0uLcoZaZ1k8Q4sRcdoLA6rS\n" +
|
||||
"e1WffipBFMvIuoDIigkHZIKVYRLG828rO+PFnRah0ybybkVsN6s3oLxfhswZDvut\n" +
|
||||
"OwIDAQABo0IwQDAPBgNVHRMBAf8EBTADAQH/MA4GA1UdDwEB/wQEAwIBBjAdBgNV\n" +
|
||||
"HQ4EFgQUOw+92bevFoJz96pR1DrAkPPUKb0wDQYJKoZIhvcNAQELBQADggEBACBN\n" +
|
||||
"wEaV70FKKBINHtNwesd7TB6fgSaVgDZOO08aseHbXnm7AUhtDV3P5rQR2AsKtbg4\n" +
|
||||
"COhlKw2/Ki18D4DfdCccFKFTRZBjqj2PxNmn6C68l1/bT4PuUXuM7rW++53RcOA7\n" +
|
||||
"TbgLuzA25kSz7XinRvR8L4VwHtppu5tSYEthMIMgLZLGGV9r7kBfpY8lXdxQM8vb\n" +
|
||||
"xZUIysasvVtVUFPOTV6g2dfn8QCoqLOmxyzTLdXe4M6acP6f7lmhgr3LMqDtB6K9\n" +
|
||||
"pN+OImr77zNdZ+jTB+5e9a8gAvc5ZfG7Nk5RfwUatYTAFZ6Uggy2cKmIRpXCia18\n" +
|
||||
"If78mc7goS1+lHkGCs2hADEA\n" +
|
||||
"-----END PKCS7-----";
|
||||
|
||||
// Empty PKCS#7 in DER form can be created with openssl:
|
||||
// openssl crl2pkcs7 -nocrl -outform DER
|
||||
private static final byte[] PKCS7_BER_EMPTY = {
|
||||
48, 39, 6, 9, 42, -122, 72, -122,
|
||||
-9, 13, 1, 7, 2, -96, 26, 48,
|
||||
24, 2, 1, 1, 49, 0, 48, 11,
|
||||
6, 9, 42, -122, 72, -122, -9, 13,
|
||||
1, 7, 1, -96, 0, -95, 0, 49,
|
||||
0
|
||||
};
|
||||
|
||||
private static final String JTEST_ROOT_CRL =
|
||||
"-----BEGIN X509 CRL-----\n" +
|
||||
"MIICoTCBigIBATANBgkqhkiG9w0BAQsFADA1MQ4wDAYDVQQKEwVKVGVzdDELMAkG\n" +
|
||||
"A1UECxMCSVQxFjAUBgNVBAMTDUpUZXN0IFJvb3QgQ0EXDTE0MDkwNDE4NDIyMVqg\n" +
|
||||
"MDAuMB8GA1UdIwQYMBaAFO6bllCV6kctH77MfqAtefNeRdsmMAsGA1UdFAQEAgIA\n" +
|
||||
"jjANBgkqhkiG9w0BAQsFAAOCAgEAmp8ihtiRthknDC+VzehmlQw5u8MftMZYQYk5\n" +
|
||||
"EI04SwyzY9JTL8QHb4u7fXjnZAyN89aYPypI5OSyDsyyGP/JDNsBt2Um/fl0aaCl\n" +
|
||||
"Z4Np6x+dB9+oIU1XY7y2+uyQUC5MHivQ5ddbGPoAvK/msbugTGAjHvZpM+l0okiV\n" +
|
||||
"3SofDrii5BSosFEkXfkf2oG9ZLO3YamsFMEZaOj/eWDyGhTyJMGsq2/8NeTF21Tp\n" +
|
||||
"YkeDcTHqR5KHoYXjOIaS7NjmErm+uDpKH9Lq+JUcYrbUhmjnq5z04EsPF2F2L7Vb\n" +
|
||||
"THI+awQAUQit16lXGuz7fFRZi2vPyiaRP5n2QT5D+ac1dAs+oWLDJw6Tf2v9KVTe\n" +
|
||||
"OmW62yd6zQqCwBg+n57UcNu3sv/Sq3t7iRuN0AmWlIhu659POPQv7Np6bEo6dIpp\n" +
|
||||
"u7Ze6D2KPtM177ETHYlCx2a3g9VEZYKrVhQ2749St0Cp5szVq691jFZAWYOzcfEO\n" +
|
||||
"XfK1y25pmlBjvhNIIVRlU+T5rjNb8GaleYKVYnKOcv700K32QxFzcPf7nbNKwW99\n" +
|
||||
"tcaNHFNP+LW/XP8I3CJ8toXLLcOITKVwMA+0GlO5eL7eX5POc+vE9+7IzGuybmU4\n" +
|
||||
"uslxoLdJ0NSZWpYmf6a6qrJ67cj5i3706H+eBsWQcShfSYreh+TyWQaGk+fkEiUV\n" +
|
||||
"iy4QdJ0=\n" +
|
||||
"-----END X509 CRL-----";
|
||||
|
||||
private static final String JTEST_INTERMED_CRL =
|
||||
"-----BEGIN X509 CRL-----\n" +
|
||||
"MIICzzCBuAIBATANBgkqhkiG9w0BAQsFADA/MQ4wDAYDVQQKEwVKVGVzdDELMAkG\n" +
|
||||
"A1UECxMCSVQxIDAeBgNVBAMTF0pUZXN0IEludGVybWVkaWF0ZSBDQSAxFw0xNDA5\n" +
|
||||
"MDQyMjE2NTRaMCIwIAIBBhcNMTQwOTA0MjIxNjU0WjAMMAoGA1UdFQQDCgEFoDAw\n" +
|
||||
"LjAfBgNVHSMEGDAWgBSvRdjbkSMJ3A7s5H6EWghQ+lkw/zALBgNVHRQEBAICAJsw\n" +
|
||||
"DQYJKoZIhvcNAQELBQADggIBALJmikMwil8oywhenoO8o9xxCOIU0xrt3KdfiSXw\n" +
|
||||
"8MtQXZHT9d1C6tlLAsYkWAfmfTvM2OU6wquFCLLsFmDZszbbCqmn4JhYBSKQMqlm\n" +
|
||||
"IHnsiOFPvITW2FU08fWNLM+FtQzPnTFmx/CJo+wfGpq5tZMIbsccsCJ5uvZVAWGh\n" +
|
||||
"0KbPmYcJG/O384+kzr/2H2IaoZoMMABec5c5FEF/tpp8jawzY+0VFyaVrumKWdan\n" +
|
||||
"+3OvRQxT1wLxfNi2vdxB2rmNPo423qanXZAoVv260um3LYlmXBNK1jwQ9lp78jkT\n" +
|
||||
"B7zMVa4hOUWVxdWc/LE6fUYgPsNqZd+hWy/PolIRp5TS21B5hkc5K87LT59GkexK\n" +
|
||||
"vNVKQennOLGtH+Q7htK4UeY4Gm/W7UydOQ0k7hZzyfMDkCfLfNfK0l63qKwUku36\n" +
|
||||
"UdeI1LXqulPEvb/d7rRAAM9p5Sm+RsECj2bcrZBMdIGXcSo26A5tzZpTEC79i4S1\n" +
|
||||
"yxYIooeBnouUkDJ9+VBsJTSKY5fpU8JSkQPRyHKt+trGAkBt2Ka5MqrHtITzQ1vP\n" +
|
||||
"5q4tNr45JGEXllH83NlBpWURfsdtkDHa3lxTD/pkrywOCyzz7wQ22D8Kul7EN8nT\n" +
|
||||
"7LDbN+O3G9GHICxvWlJHp6HMsqGTuH1MIUR+5uZFOJa1S0IzorUIEieLncDUPgzO\n" +
|
||||
"M4JA\n" +
|
||||
"-----END X509 CRL-----";
|
||||
|
||||
// PKCS#7 CRL Set containing JTEST root and intermediate CRLs
|
||||
private static final String PKCS7_CRL_SET =
|
||||
"-----BEGIN PKCS7-----\n" +
|
||||
"MIIFpQYJKoZIhvcNAQcCoIIFljCCBZICAQExADALBgkqhkiG9w0BBwGgAKGCBXgw\n" +
|
||||
"ggKhMIGKAgEBMA0GCSqGSIb3DQEBCwUAMDUxDjAMBgNVBAoTBUpUZXN0MQswCQYD\n" +
|
||||
"VQQLEwJJVDEWMBQGA1UEAxMNSlRlc3QgUm9vdCBDQRcNMTQwOTA0MTg0MjIxWqAw\n" +
|
||||
"MC4wHwYDVR0jBBgwFoAU7puWUJXqRy0fvsx+oC15815F2yYwCwYDVR0UBAQCAgCO\n" +
|
||||
"MA0GCSqGSIb3DQEBCwUAA4ICAQCanyKG2JG2GScML5XN6GaVDDm7wx+0xlhBiTkQ\n" +
|
||||
"jThLDLNj0lMvxAdvi7t9eOdkDI3z1pg/Kkjk5LIOzLIY/8kM2wG3ZSb9+XRpoKVn\n" +
|
||||
"g2nrH50H36ghTVdjvLb67JBQLkweK9Dl11sY+gC8r+axu6BMYCMe9mkz6XSiSJXd\n" +
|
||||
"Kh8OuKLkFKiwUSRd+R/agb1ks7dhqawUwRlo6P95YPIaFPIkwayrb/w15MXbVOli\n" +
|
||||
"R4NxMepHkoehheM4hpLs2OYSub64Okof0ur4lRxittSGaOernPTgSw8XYXYvtVtM\n" +
|
||||
"cj5rBABRCK3XqVca7Pt8VFmLa8/KJpE/mfZBPkP5pzV0Cz6hYsMnDpN/a/0pVN46\n" +
|
||||
"ZbrbJ3rNCoLAGD6fntRw27ey/9Kre3uJG43QCZaUiG7rn0849C/s2npsSjp0imm7\n" +
|
||||
"tl7oPYo+0zXvsRMdiULHZreD1URlgqtWFDbvj1K3QKnmzNWrr3WMVkBZg7Nx8Q5d\n" +
|
||||
"8rXLbmmaUGO+E0ghVGVT5PmuM1vwZqV5gpVico5y/vTQrfZDEXNw9/uds0rBb321\n" +
|
||||
"xo0cU0/4tb9c/wjcIny2hcstw4hMpXAwD7QaU7l4vt5fk85z68T37sjMa7JuZTi6\n" +
|
||||
"yXGgt0nQ1JlaliZ/prqqsnrtyPmLfvTof54GxZBxKF9Jit6H5PJZBoaT5+QSJRWL\n" +
|
||||
"LhB0nTCCAs8wgbgCAQEwDQYJKoZIhvcNAQELBQAwPzEOMAwGA1UEChMFSlRlc3Qx\n" +
|
||||
"CzAJBgNVBAsTAklUMSAwHgYDVQQDExdKVGVzdCBJbnRlcm1lZGlhdGUgQ0EgMRcN\n" +
|
||||
"MTQwOTA0MjIxNjU0WjAiMCACAQYXDTE0MDkwNDIyMTY1NFowDDAKBgNVHRUEAwoB\n" +
|
||||
"BaAwMC4wHwYDVR0jBBgwFoAUr0XY25EjCdwO7OR+hFoIUPpZMP8wCwYDVR0UBAQC\n" +
|
||||
"AgCbMA0GCSqGSIb3DQEBCwUAA4ICAQCyZopDMIpfKMsIXp6DvKPccQjiFNMa7dyn\n" +
|
||||
"X4kl8PDLUF2R0/XdQurZSwLGJFgH5n07zNjlOsKrhQiy7BZg2bM22wqpp+CYWAUi\n" +
|
||||
"kDKpZiB57IjhT7yE1thVNPH1jSzPhbUMz50xZsfwiaPsHxqaubWTCG7HHLAiebr2\n" +
|
||||
"VQFhodCmz5mHCRvzt/OPpM6/9h9iGqGaDDAAXnOXORRBf7aafI2sM2PtFRcmla7p\n" +
|
||||
"ilnWp/tzr0UMU9cC8XzYtr3cQdq5jT6ONt6mp12QKFb9utLpty2JZlwTStY8EPZa\n" +
|
||||
"e/I5Ewe8zFWuITlFlcXVnPyxOn1GID7DamXfoVsvz6JSEaeU0ttQeYZHOSvOy0+f\n" +
|
||||
"RpHsSrzVSkHp5zixrR/kO4bSuFHmOBpv1u1MnTkNJO4Wc8nzA5Any3zXytJet6is\n" +
|
||||
"FJLt+lHXiNS16rpTxL2/3e60QADPaeUpvkbBAo9m3K2QTHSBl3EqNugObc2aUxAu\n" +
|
||||
"/YuEtcsWCKKHgZ6LlJAyfflQbCU0imOX6VPCUpED0chyrfraxgJAbdimuTKqx7SE\n" +
|
||||
"80Nbz+auLTa+OSRhF5ZR/NzZQaVlEX7HbZAx2t5cUw/6ZK8sDgss8+8ENtg/Crpe\n" +
|
||||
"xDfJ0+yw2zfjtxvRhyAsb1pSR6ehzLKhk7h9TCFEfubmRTiWtUtCM6K1CBIni53A\n" +
|
||||
"1D4MzjOCQDEA\n" +
|
||||
"-----END PKCS7-----";
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
CertificateFactory cf = CertificateFactory.getInstance("X.509");
|
||||
List<DecodeTest> validTests = new LinkedList<>();
|
||||
List<DecodeTest> invalidTests = new LinkedList<>();
|
||||
|
||||
// Load up positive test cases (for sanity checks)
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
validTests.add(new GenMultiCertTest("Single, valid certificate",
|
||||
SINGLE_ROOT_CERT.getBytes(), null,
|
||||
new X500Principal("CN=Root, O=SomeCompany")));
|
||||
validTests.add(new GenMultiCertTest("PEM-encoded PKCS#7 chain",
|
||||
PKCS7_INTERMED_ROOT_CERTS.getBytes(), null,
|
||||
new X500Principal("CN=Intermed, O=SomeCompany"),
|
||||
new X500Principal("CN=Root, O=SomeCompany")));
|
||||
validTests.add(new GenMultiCertTest("Two PEM-encoded X509 certs",
|
||||
(INTERMED_CA_CERT + "\n" + SINGLE_ROOT_CERT).getBytes(),
|
||||
null,
|
||||
new X500Principal("CN=Intermed, O=SomeCompany"),
|
||||
new X500Principal("CN=Root, O=SomeCompany")));
|
||||
validTests.add(new GenMultiCertTest("Empty data", new byte[0], null));
|
||||
|
||||
sb.append("Certificate 1: CN=Root, O=SomeCompany\n");
|
||||
sb.append(SINGLE_ROOT_CERT).append("\n");
|
||||
sb.append("Certificate 2: CN=Intermed, O=SomeCompany\n");
|
||||
sb.append(INTERMED_CA_CERT).append("\n");
|
||||
sb.append("Extra trailing data\n");
|
||||
validTests.add(new GenMultiCertTest(
|
||||
"Two PEM-encoded certs with leading/trailing " +
|
||||
"text data around each.", sb.toString().getBytes(), null,
|
||||
new X500Principal("CN=Root, O=SomeCompany"),
|
||||
new X500Principal("CN=Intermed, O=SomeCompany")));
|
||||
validTests.add(new GenMultiCertTest(
|
||||
"BER-encoded PKCS#7 with empty certificates segment",
|
||||
PKCS7_BER_EMPTY, null));
|
||||
validTests.add(new GenMultiCRLTest(
|
||||
"CRL with leading and trailing text data",
|
||||
("This is a CRL\n" + JTEST_ROOT_CRL +
|
||||
"\nSee? Told you so\n\n").getBytes(), null,
|
||||
new X500Principal("CN=JTest Root CA,OU=IT,O=JTest")));
|
||||
validTests.add(new GenMultiCRLTest(
|
||||
"Two CRLs, one after the other with leading/trailing text",
|
||||
("This is a CRL\n" + JTEST_ROOT_CRL +
|
||||
"\nAnd this is another CRL\n" + JTEST_INTERMED_CRL +
|
||||
"\nAnd this is trailing text\n").getBytes(), null,
|
||||
new X500Principal("CN=JTest Root CA,OU=IT,O=JTest"),
|
||||
new X500Principal(
|
||||
"CN=JTest Intermediate CA 1,OU=IT,O=JTest")));
|
||||
validTests.add(new GenMultiCRLTest("Two CRLs in a PKCS#7 CRL set",
|
||||
PKCS7_CRL_SET.getBytes(), null,
|
||||
new X500Principal("CN=JTest Root CA,OU=IT,O=JTest"),
|
||||
new X500Principal("CN=JTest Intermediate CA 1,OU=IT,O=JTest")));
|
||||
|
||||
// Load up all test cases where we expect failures
|
||||
invalidTests.add(new GenSingleCertTest("Invalid PEM encoding",
|
||||
INVALID_CERT.getBytes(),
|
||||
new CertificateParsingException()));
|
||||
invalidTests.add(new GenMultiCertTest("Invalid PEM encoding",
|
||||
INVALID_CERT.getBytes(),
|
||||
new CertificateParsingException()));
|
||||
invalidTests.add(new GenMultiCertTest(
|
||||
"Two cert sequence, one valid and one invalid",
|
||||
(INTERMED_CA_CERT + "\n" + INVALID_CERT).getBytes(),
|
||||
new CertificateParsingException()));
|
||||
invalidTests.add(new GenMultiCertTest("Non-certificate text",
|
||||
"This is not a certificate".getBytes(),
|
||||
new CertificateException()));
|
||||
invalidTests.add(new GenMultiCertTest(
|
||||
"Non-certificate text with partial PEM header (4 hyphens)",
|
||||
"----This is not a valid x509 certificate".getBytes(),
|
||||
new CertificateException()));
|
||||
invalidTests.add(new GenMultiCertTest(
|
||||
"Leading non-certificate text plus valid PEM header, " +
|
||||
"but not on new line",
|
||||
"This is not valid -----BEGIN CERTIFICATE-----".getBytes(),
|
||||
new CertificateException()));
|
||||
byte[] emptyCString = {0};
|
||||
invalidTests.add(new GenMultiCertTest("Empty C-style string",
|
||||
emptyCString, new CertificateException()));
|
||||
invalidTests.add(new GenMultiCRLTest("Non-CRL text",
|
||||
"This is not a CRL".getBytes(), new CRLException()));
|
||||
invalidTests.add(new GenMultiCRLTest("Valid headers, but not a CRL",
|
||||
INTERMED_CA_CERT.getBytes(), new CRLException()));
|
||||
|
||||
System.out.println("===== Valid Tests =====");
|
||||
for (DecodeTest dt : validTests) {
|
||||
dt.passTest();
|
||||
}
|
||||
System.out.print("\n");
|
||||
|
||||
System.out.println("===== Invalid Tests =====");
|
||||
for (DecodeTest dt : invalidTests) {
|
||||
dt.failTest();
|
||||
}
|
||||
}
|
||||
|
||||
public static abstract class DecodeTest {
|
||||
protected String testName;
|
||||
protected byte[] testData;
|
||||
protected Throwable expectedException;
|
||||
protected X500Principal[] principals;
|
||||
protected CertificateFactory cf;
|
||||
|
||||
/**
|
||||
* Construct a DecodeTest
|
||||
*
|
||||
* @param name The test name
|
||||
* @param input A byte array consisting of the input for this test
|
||||
* @param failType An exception whose class should match the expected
|
||||
* exception that will be thrown when this test is run
|
||||
* @param princs Zero of more X500Principals which will be used
|
||||
* to compare the output in a success case.
|
||||
*/
|
||||
DecodeTest(String name, byte[] input, Throwable failType,
|
||||
X500Principal... princs) throws CertificateException {
|
||||
testName = name;
|
||||
testData = input.clone();
|
||||
expectedException = failType;
|
||||
principals = princs;
|
||||
cf = CertificateFactory.getInstance("X.509");
|
||||
}
|
||||
|
||||
public abstract void passTest() throws GeneralSecurityException;
|
||||
|
||||
public abstract void failTest() throws GeneralSecurityException;
|
||||
}
|
||||
|
||||
public static class GenMultiCertTest extends DecodeTest {
|
||||
public GenMultiCertTest(String name, byte[] input, Throwable failType,
|
||||
X500Principal... princs) throws CertificateException {
|
||||
super(name, input, failType, princs);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void passTest() throws GeneralSecurityException {
|
||||
Collection<? extends Certificate> certs;
|
||||
|
||||
System.out.println("generateCertificates(): " + testName);
|
||||
certs = cf.generateCertificates(new ByteArrayInputStream(testData));
|
||||
|
||||
// Walk the certs Collection and do a comparison of subject names
|
||||
int i = 0;
|
||||
if (certs.size() == principals.length) {
|
||||
for (Certificate crt : certs) {
|
||||
X509Certificate xc = (X509Certificate)crt;
|
||||
if (!xc.getSubjectX500Principal().equals(
|
||||
principals[i])) {
|
||||
throw new RuntimeException("Name mismatch: " +
|
||||
"cert: " + xc.getSubjectX500Principal() +
|
||||
", expected: " + principals[i]);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
} else {
|
||||
throw new RuntimeException("Size mismatch: certs = " +
|
||||
certs.size() + ", expected = " +
|
||||
principals.length);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void failTest() throws GeneralSecurityException {
|
||||
Throwable caughtException = null;
|
||||
Collection<? extends Certificate> certs = null;
|
||||
|
||||
System.out.println("generateCertificates(): " + testName);
|
||||
if (expectedException == null) {
|
||||
throw new RuntimeException("failTest requires non-null " +
|
||||
"expectedException");
|
||||
}
|
||||
|
||||
try {
|
||||
certs =
|
||||
cf.generateCertificates(new ByteArrayInputStream(testData));
|
||||
} catch (CertificateException ce) {
|
||||
caughtException = ce;
|
||||
}
|
||||
|
||||
if (caughtException != null) {
|
||||
// It has to be the right kind of exception though...
|
||||
if (!caughtException.getClass().equals(
|
||||
expectedException.getClass())) {
|
||||
System.err.println("Unexpected exception thrown. " +
|
||||
"Received: " + caughtException + ", Expected: " +
|
||||
expectedException.getClass());
|
||||
throw new RuntimeException(caughtException);
|
||||
}
|
||||
} else {
|
||||
// For a failure test, we'd expect some kind of exception
|
||||
// to be thrown.
|
||||
throw new RuntimeException("Failed to catch expected " +
|
||||
"exception " + expectedException.getClass());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class GenSingleCertTest extends DecodeTest {
|
||||
public GenSingleCertTest(String name, byte[] input, Throwable failType,
|
||||
X500Principal... princs) throws CertificateException {
|
||||
super(name, input, failType, princs);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void passTest() throws GeneralSecurityException {
|
||||
X509Certificate cert;
|
||||
|
||||
System.out.println("generateCertificate(): " + testName);
|
||||
cert = (X509Certificate)cf.generateCertificate(
|
||||
new ByteArrayInputStream(testData));
|
||||
|
||||
// Compare the cert's subject name against the expected value
|
||||
// provided in the test. If multiple X500Principals were provided
|
||||
// just use the first one as the expected value.
|
||||
if (!cert.getSubjectX500Principal().equals(principals[0])) {
|
||||
throw new RuntimeException("Name mismatch: " +
|
||||
"cert: " + cert.getSubjectX500Principal() +
|
||||
", expected: " + principals[0]);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void failTest() throws GeneralSecurityException {
|
||||
Throwable caughtException = null;
|
||||
X509Certificate cert = null;
|
||||
System.out.println("generateCertificate(): " + testName);
|
||||
|
||||
if (expectedException == null) {
|
||||
throw new RuntimeException("failTest requires non-null " +
|
||||
"expectedException");
|
||||
}
|
||||
|
||||
try {
|
||||
cert = (X509Certificate)cf.generateCertificate(
|
||||
new ByteArrayInputStream(testData));
|
||||
} catch (CertificateException e) {
|
||||
caughtException = e;
|
||||
}
|
||||
|
||||
if (caughtException != null) {
|
||||
// It has to be the right kind of exception though...
|
||||
if (!caughtException.getClass().equals(
|
||||
expectedException.getClass())) {
|
||||
System.err.println("Unexpected exception thrown. " +
|
||||
"Received: " + caughtException + ", Expected: " +
|
||||
expectedException.getClass());
|
||||
throw new RuntimeException(caughtException);
|
||||
}
|
||||
} else {
|
||||
// For a failure test, we'd expect some kind of exception
|
||||
// to be thrown.
|
||||
throw new RuntimeException("Failed to catch expected " +
|
||||
"exception " + expectedException.getClass());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class GenMultiCRLTest extends DecodeTest {
|
||||
public GenMultiCRLTest(String name, byte[] input, Throwable failType,
|
||||
X500Principal... princs) throws CertificateException {
|
||||
super(name, input, failType, princs);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void passTest() throws GeneralSecurityException {
|
||||
Collection<? extends CRL> crls;
|
||||
|
||||
System.out.println("generateCRLs(): " + testName);
|
||||
crls = cf.generateCRLs(new ByteArrayInputStream(testData));
|
||||
|
||||
// Walk the crls Collection and do a comparison of issuer names
|
||||
int i = 0;
|
||||
if (crls.size() == principals.length) {
|
||||
for (CRL revlist : crls) {
|
||||
X509CRL xc = (X509CRL)revlist;
|
||||
if (!xc.getIssuerX500Principal().equals(principals[i])) {
|
||||
throw new RuntimeException("Name mismatch: " +
|
||||
"CRL: " + xc.getIssuerX500Principal() +
|
||||
", expected: " + principals[i]);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
} else {
|
||||
throw new RuntimeException("Size mismatch: crls = " +
|
||||
crls.size() + ", expected = " +
|
||||
principals.length);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void failTest() throws GeneralSecurityException {
|
||||
Throwable caughtException = null;
|
||||
Collection<? extends CRL> crls = null;
|
||||
|
||||
System.out.println("generateCRLs(): " + testName);
|
||||
if (expectedException == null) {
|
||||
throw new RuntimeException("failTest requires non-null " +
|
||||
"expectedException");
|
||||
}
|
||||
|
||||
try {
|
||||
crls =
|
||||
cf.generateCRLs(new ByteArrayInputStream(testData));
|
||||
} catch (CRLException e) {
|
||||
caughtException = e;
|
||||
}
|
||||
|
||||
if (caughtException != null) {
|
||||
// It has to be the right kind of exception though...
|
||||
if (!caughtException.getClass().equals(
|
||||
expectedException.getClass())) {
|
||||
System.err.println("Unexpected exception thrown. " +
|
||||
"Received: " + caughtException + ", Expected: " +
|
||||
expectedException.getClass());
|
||||
throw new RuntimeException(caughtException);
|
||||
}
|
||||
} else {
|
||||
// For a failure test, we'd expect some kind of exception
|
||||
// to be thrown.
|
||||
throw new RuntimeException("Failed to catch expected " +
|
||||
"exception " + expectedException.getClass());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,80 @@
|
|||
/*
|
||||
* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/*
|
||||
* @test
|
||||
* @bug 6948781
|
||||
* @summary CertificateFactory.generateCertificate doesn't throw
|
||||
* CertificateException for malformed certificate
|
||||
*/
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.security.cert.CertificateFactory;
|
||||
import java.security.cert.CertificateException;
|
||||
|
||||
public class BadFooter {
|
||||
public static void main(String[] args) throws Exception {
|
||||
// The two sections below are identical, a self-signed cert generated
|
||||
// for a fake principal:
|
||||
// CN=Me, OU=Office, O=A-B-C, L=Backside, ST=Moon, C=EA
|
||||
String cert =
|
||||
"-----BEGIN CERTIFICATE-----\n" +
|
||||
"MIIDGDCCAtWgAwIBAgIERgH/AjALBgcqhkjOOAQDBQAwXTELMAkGA1UEBhMCRUExDTALBgNVBAgT\n" +
|
||||
"BE1vb24xETAPBgNVBAcTCEJhY2tzaWRlMQ4wDAYDVQQKEwVBLUItQzEPMA0GA1UECxMGT2ZmaWNl\n" +
|
||||
"MQswCQYDVQQDEwJNZTAeFw0wNzAzMjIwMzU4NThaFw0wNzA2MjAwMzU4NThaMF0xCzAJBgNVBAYT\n" +
|
||||
"AkVBMQ0wCwYDVQQIEwRNb29uMREwDwYDVQQHEwhCYWNrc2lkZTEOMAwGA1UEChMFQS1CLUMxDzAN\n" +
|
||||
"BgNVBAsTBk9mZmljZTELMAkGA1UEAxMCTWUwggG4MIIBLAYHKoZIzjgEATCCAR8CgYEA/X9TgR11\n" +
|
||||
"EilS30qcLuzk5/YRt1I870QAwx4/gLZRJmlFXUAiUftZPY1Y+r/F9bow9subVWzXgTuAHTRv8mZg\n" +
|
||||
"t2uZUKWkn5/oBHsQIsJPu6nX/rfGG/g7V+fGqKYVDwT7g/bTxR7DAjVUE1oWkTL2dfOuK2HXKu/y\n" +
|
||||
"IgMZndFIAccCFQCXYFCPFSMLzLKSuYKi64QL8Fgc9QKBgQD34aCF1ps93su8q1w2uFe5eZSvu/o6\n" +
|
||||
"6oL5V0wLPQeCZ1FZV4661FlP5nEHEIGAtEkWcSPoTCgWE7fPCTKMyKbhPBZ6i1R8jSjgo64eK7Om\n" +
|
||||
"dZFuo38L+iE1YvH7YnoBJDvMpPG+qFGQiaiD3+Fa5Z8GkotmXoB7VSVkAUw7/s9JKgOBhQACgYEA\n" +
|
||||
"xc7ovvDeJ5yIkiEoz6U4jcFf5ZDSC+rUEsqGuARXHUF0PlIth7h2e9KV12cwdjVH++mGvwU/m/Ju\n" +
|
||||
"OpaaWOEFRHgCMe5fZ2xE0pWPcmKkPicc85SKHguYTMCc9D0XbTbkoBIEAeQ4nr2GmXuEQ5tYaO/O\n" +
|
||||
"PYXjk9EfGhikHlnKgC6jITAfMB0GA1UdDgQWBBTtv4rKVwXtXJpyZWlswQL4MAKkazALBgcqhkjO\n" +
|
||||
"OAQDBQADMAAwLQIVAIU4pnnUcMjh2CUvh/B0PSZZTHHvAhQVMhAdwNHOGPSL6sCL19q6UjoN9w==\n" +
|
||||
"-----BEGIN CERTIFICATE-----\n" +
|
||||
"MIIDGDCCAtWgAwIBAgIERgH/AjALBgcqhkjOOAQDBQAwXTELMAkGA1UEBhMCRUExDTALBgNVBAgT\n" +
|
||||
"BE1vb24xETAPBgNVBAcTCEJhY2tzaWRlMQ4wDAYDVQQKEwVBLUItQzEPMA0GA1UECxMGT2ZmaWNl\n" +
|
||||
"MQswCQYDVQQDEwJNZTAeFw0wNzAzMjIwMzU4NThaFw0wNzA2MjAwMzU4NThaMF0xCzAJBgNVBAYT\n" +
|
||||
"AkVBMQ0wCwYDVQQIEwRNb29uMREwDwYDVQQHEwhCYWNrc2lkZTEOMAwGA1UEChMFQS1CLUMxDzAN\n" +
|
||||
"BgNVBAsTBk9mZmljZTELMAkGA1UEAxMCTWUwggG4MIIBLAYHKoZIzjgEATCCAR8CgYEA/X9TgR11\n" +
|
||||
"EilS30qcLuzk5/YRt1I870QAwx4/gLZRJmlFXUAiUftZPY1Y+r/F9bow9subVWzXgTuAHTRv8mZg\n" +
|
||||
"t2uZUKWkn5/oBHsQIsJPu6nX/rfGG/g7V+fGqKYVDwT7g/bTxR7DAjVUE1oWkTL2dfOuK2HXKu/y\n" +
|
||||
"IgMZndFIAccCFQCXYFCPFSMLzLKSuYKi64QL8Fgc9QKBgQD34aCF1ps93su8q1w2uFe5eZSvu/o6\n" +
|
||||
"6oL5V0wLPQeCZ1FZV4661FlP5nEHEIGAtEkWcSPoTCgWE7fPCTKMyKbhPBZ6i1R8jSjgo64eK7Om\n" +
|
||||
"dZFuo38L+iE1YvH7YnoBJDvMpPG+qFGQiaiD3+Fa5Z8GkotmXoB7VSVkAUw7/s9JKgOBhQACgYEA\n" +
|
||||
"xc7ovvDeJ5yIkiEoz6U4jcFf5ZDSC+rUEsqGuARXHUF0PlIth7h2e9KV12cwdjVH++mGvwU/m/Ju\n" +
|
||||
"OpaaWOEFRHgCMe5fZ2xE0pWPcmKkPicc85SKHguYTMCc9D0XbTbkoBIEAeQ4nr2GmXuEQ5tYaO/O\n" +
|
||||
"PYXjk9EfGhikHlnKgC6jITAfMB0GA1UdDgQWBBTtv4rKVwXtXJpyZWlswQL4MAKkazALBgcqhkjO\n" +
|
||||
"OAQDBQADMAAwLQIVAIU4pnnUcMjh2CUvh/B0PSZZTHHvAhQVMhAdwNHOGPSL6sCL19q6UjoN9w==\n" +
|
||||
"-----END CERTIFICATE-----\n";
|
||||
try {
|
||||
CertificateFactory.getInstance("X509").generateCertificates(
|
||||
new ByteArrayInputStream(cert.getBytes()));
|
||||
throw new Exception("Fail. certificate generation should fail");
|
||||
} catch (CertificateException ce) {
|
||||
ce.printStackTrace();
|
||||
// This is the correct result
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,67 @@
|
|||
/*
|
||||
* Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/*
|
||||
* @test
|
||||
* @bug 6535697
|
||||
* @summary keytool can be more flexible on format of PEM-encoded
|
||||
* X.509 certificates
|
||||
*/
|
||||
|
||||
import java.io.*;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Arrays;
|
||||
import java.security.cert.CertificateFactory;
|
||||
|
||||
public class OpenSSLCert {
|
||||
static final String OUTFILE = "6535697.test";
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
test("open");
|
||||
test("pem");
|
||||
test("open", "open");
|
||||
test("open", "pem");
|
||||
test("pem", "pem");
|
||||
test("pem", "open");
|
||||
test("open", "pem", "open");
|
||||
test("pem", "open", "pem");
|
||||
}
|
||||
|
||||
static void test(String... files) throws Exception {
|
||||
try (FileOutputStream fout = new FileOutputStream(OUTFILE)) {
|
||||
String here = System.getProperty("test.src", "");
|
||||
for (String file: files) {
|
||||
Files.copy(Paths.get(here, file), fout);
|
||||
}
|
||||
}
|
||||
try (FileInputStream fin = new FileInputStream(OUTFILE)) {
|
||||
System.out.println("Testing " + Arrays.toString(files) + "...");
|
||||
if (CertificateFactory.getInstance("X509")
|
||||
.generateCertificates(fin)
|
||||
.size() != files.length) {
|
||||
throw new Exception("Not same number");
|
||||
}
|
||||
}
|
||||
Files.delete(Paths.get(OUTFILE));
|
||||
}
|
||||
}
|
||||
72
test/jdk/java/security/cert/CertificateFactory/openssl/open
Normal file
72
test/jdk/java/security/cert/CertificateFactory/openssl/open
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
Certificate:
|
||||
Data:
|
||||
Version: 3 (0x2)
|
||||
Serial Number: 1174535938 (0x4601ff02)
|
||||
Signature Algorithm: dsaWithSHA1
|
||||
Issuer: C=EA, ST=Moon, L=Backside, O=A-B-C, OU=Office, CN=Me
|
||||
Validity
|
||||
Not Before: Mar 22 03:58:58 2007 GMT
|
||||
Not After : Jun 20 03:58:58 2007 GMT
|
||||
Subject: C=EA, ST=Moon, L=Backside, O=A-B-C, OU=Office, CN=Me
|
||||
Subject Public Key Info:
|
||||
Public Key Algorithm: dsaEncryption
|
||||
DSA Public Key:
|
||||
pub:
|
||||
00:c5:ce:e8:be:f0:de:27:9c:88:92:21:28:cf:a5:
|
||||
38:8d:c1:5f:e5:90:d2:0b:ea:d4:12:ca:86:b8:04:
|
||||
57:1d:41:74:3e:52:2d:87:b8:76:7b:d2:95:d7:67:
|
||||
30:76:35:47:fb:e9:86:bf:05:3f:9b:f2:6e:3a:96:
|
||||
9a:58:e1:05:44:78:02:31:ee:5f:67:6c:44:d2:95:
|
||||
8f:72:62:a4:3e:27:1c:f3:94:8a:1e:0b:98:4c:c0:
|
||||
9c:f4:3d:17:6d:36:e4:a0:12:04:01:e4:38:9e:bd:
|
||||
86:99:7b:84:43:9b:58:68:ef:ce:3d:85:e3:93:d1:
|
||||
1f:1a:18:a4:1e:59:ca:80:2e
|
||||
P:
|
||||
00:fd:7f:53:81:1d:75:12:29:52:df:4a:9c:2e:ec:
|
||||
e4:e7:f6:11:b7:52:3c:ef:44:00:c3:1e:3f:80:b6:
|
||||
51:26:69:45:5d:40:22:51:fb:59:3d:8d:58:fa:bf:
|
||||
c5:f5:ba:30:f6:cb:9b:55:6c:d7:81:3b:80:1d:34:
|
||||
6f:f2:66:60:b7:6b:99:50:a5:a4:9f:9f:e8:04:7b:
|
||||
10:22:c2:4f:bb:a9:d7:fe:b7:c6:1b:f8:3b:57:e7:
|
||||
c6:a8:a6:15:0f:04:fb:83:f6:d3:c5:1e:c3:02:35:
|
||||
54:13:5a:16:91:32:f6:75:f3:ae:2b:61:d7:2a:ef:
|
||||
f2:22:03:19:9d:d1:48:01:c7
|
||||
Q:
|
||||
00:97:60:50:8f:15:23:0b:cc:b2:92:b9:82:a2:eb:
|
||||
84:0b:f0:58:1c:f5
|
||||
G:
|
||||
00:f7:e1:a0:85:d6:9b:3d:de:cb:bc:ab:5c:36:b8:
|
||||
57:b9:79:94:af:bb:fa:3a:ea:82:f9:57:4c:0b:3d:
|
||||
07:82:67:51:59:57:8e:ba:d4:59:4f:e6:71:07:10:
|
||||
81:80:b4:49:16:71:23:e8:4c:28:16:13:b7:cf:09:
|
||||
32:8c:c8:a6:e1:3c:16:7a:8b:54:7c:8d:28:e0:a3:
|
||||
ae:1e:2b:b3:a6:75:91:6e:a3:7f:0b:fa:21:35:62:
|
||||
f1:fb:62:7a:01:24:3b:cc:a4:f1:be:a8:51:90:89:
|
||||
a8:83:df:e1:5a:e5:9f:06:92:8b:66:5e:80:7b:55:
|
||||
25:64:01:4c:3b:fe:cf:49:2a
|
||||
X509v3 extensions:
|
||||
X509v3 Subject Key Identifier:
|
||||
ED:BF:8A:CA:57:05:ED:5C:9A:72:65:69:6C:C1:02:F8:30:02:A4:6B
|
||||
Signature Algorithm: dsaWithSHA1
|
||||
30:2d:02:15:00:85:38:a6:79:d4:70:c8:e1:d8:25:2f:87:f0:
|
||||
74:3d:26:59:4c:71:ef:02:14:15:32:10:1d:c0:d1:ce:18:f4:
|
||||
8b:ea:c0:8b:d7:da:ba:52:3a:0d:f7
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIIDGDCCAtWgAwIBAgIERgH/AjALBgcqhkjOOAQDBQAwXTELMAkGA1UEBhMCRUEx
|
||||
DTALBgNVBAgTBE1vb24xETAPBgNVBAcTCEJhY2tzaWRlMQ4wDAYDVQQKEwVBLUIt
|
||||
QzEPMA0GA1UECxMGT2ZmaWNlMQswCQYDVQQDEwJNZTAeFw0wNzAzMjIwMzU4NTha
|
||||
Fw0wNzA2MjAwMzU4NThaMF0xCzAJBgNVBAYTAkVBMQ0wCwYDVQQIEwRNb29uMREw
|
||||
DwYDVQQHEwhCYWNrc2lkZTEOMAwGA1UEChMFQS1CLUMxDzANBgNVBAsTBk9mZmlj
|
||||
ZTELMAkGA1UEAxMCTWUwggG4MIIBLAYHKoZIzjgEATCCAR8CgYEA/X9TgR11EilS
|
||||
30qcLuzk5/YRt1I870QAwx4/gLZRJmlFXUAiUftZPY1Y+r/F9bow9subVWzXgTuA
|
||||
HTRv8mZgt2uZUKWkn5/oBHsQIsJPu6nX/rfGG/g7V+fGqKYVDwT7g/bTxR7DAjVU
|
||||
E1oWkTL2dfOuK2HXKu/yIgMZndFIAccCFQCXYFCPFSMLzLKSuYKi64QL8Fgc9QKB
|
||||
gQD34aCF1ps93su8q1w2uFe5eZSvu/o66oL5V0wLPQeCZ1FZV4661FlP5nEHEIGA
|
||||
tEkWcSPoTCgWE7fPCTKMyKbhPBZ6i1R8jSjgo64eK7OmdZFuo38L+iE1YvH7YnoB
|
||||
JDvMpPG+qFGQiaiD3+Fa5Z8GkotmXoB7VSVkAUw7/s9JKgOBhQACgYEAxc7ovvDe
|
||||
J5yIkiEoz6U4jcFf5ZDSC+rUEsqGuARXHUF0PlIth7h2e9KV12cwdjVH++mGvwU/
|
||||
m/JuOpaaWOEFRHgCMe5fZ2xE0pWPcmKkPicc85SKHguYTMCc9D0XbTbkoBIEAeQ4
|
||||
nr2GmXuEQ5tYaO/OPYXjk9EfGhikHlnKgC6jITAfMB0GA1UdDgQWBBTtv4rKVwXt
|
||||
XJpyZWlswQL4MAKkazALBgcqhkjOOAQDBQADMAAwLQIVAIU4pnnUcMjh2CUvh/B0
|
||||
PSZZTHHvAhQVMhAdwNHOGPSL6sCL19q6UjoN9w==
|
||||
-----END CERTIFICATE-----
|
||||
16
test/jdk/java/security/cert/CertificateFactory/openssl/pem
Normal file
16
test/jdk/java/security/cert/CertificateFactory/openssl/pem
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
-----BEGIN CERTIFICATE-----
|
||||
MIIDGDCCAtWgAwIBAgIERgH/AjALBgcqhkjOOAQDBQAwXTELMAkGA1UEBhMCRUExDTALBgNVBAgT
|
||||
BE1vb24xETAPBgNVBAcTCEJhY2tzaWRlMQ4wDAYDVQQKEwVBLUItQzEPMA0GA1UECxMGT2ZmaWNl
|
||||
MQswCQYDVQQDEwJNZTAeFw0wNzAzMjIwMzU4NThaFw0wNzA2MjAwMzU4NThaMF0xCzAJBgNVBAYT
|
||||
AkVBMQ0wCwYDVQQIEwRNb29uMREwDwYDVQQHEwhCYWNrc2lkZTEOMAwGA1UEChMFQS1CLUMxDzAN
|
||||
BgNVBAsTBk9mZmljZTELMAkGA1UEAxMCTWUwggG4MIIBLAYHKoZIzjgEATCCAR8CgYEA/X9TgR11
|
||||
EilS30qcLuzk5/YRt1I870QAwx4/gLZRJmlFXUAiUftZPY1Y+r/F9bow9subVWzXgTuAHTRv8mZg
|
||||
t2uZUKWkn5/oBHsQIsJPu6nX/rfGG/g7V+fGqKYVDwT7g/bTxR7DAjVUE1oWkTL2dfOuK2HXKu/y
|
||||
IgMZndFIAccCFQCXYFCPFSMLzLKSuYKi64QL8Fgc9QKBgQD34aCF1ps93su8q1w2uFe5eZSvu/o6
|
||||
6oL5V0wLPQeCZ1FZV4661FlP5nEHEIGAtEkWcSPoTCgWE7fPCTKMyKbhPBZ6i1R8jSjgo64eK7Om
|
||||
dZFuo38L+iE1YvH7YnoBJDvMpPG+qFGQiaiD3+Fa5Z8GkotmXoB7VSVkAUw7/s9JKgOBhQACgYEA
|
||||
xc7ovvDeJ5yIkiEoz6U4jcFf5ZDSC+rUEsqGuARXHUF0PlIth7h2e9KV12cwdjVH++mGvwU/m/Ju
|
||||
OpaaWOEFRHgCMe5fZ2xE0pWPcmKkPicc85SKHguYTMCc9D0XbTbkoBIEAeQ4nr2GmXuEQ5tYaO/O
|
||||
PYXjk9EfGhikHlnKgC6jITAfMB0GA1UdDgQWBBTtv4rKVwXtXJpyZWlswQL4MAKkazALBgcqhkjO
|
||||
OAQDBQADMAAwLQIVAIU4pnnUcMjh2CUvh/B0PSZZTHHvAhQVMhAdwNHOGPSL6sCL19q6UjoN9w==
|
||||
-----END CERTIFICATE-----
|
||||
|
|
@ -0,0 +1,131 @@
|
|||
/*
|
||||
* Copyright (c) 2007, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @bug 4946388
|
||||
* @summary Unit test for CertificateRevokedException
|
||||
* @modules java.base/sun.security.x509
|
||||
*/
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.security.cert.CertificateRevokedException;
|
||||
import java.security.cert.CRLReason;
|
||||
import java.security.cert.Extension;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import javax.security.auth.x500.X500Principal;
|
||||
|
||||
import sun.security.x509.InvalidityDateExtension;
|
||||
|
||||
public class Basic {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
|
||||
// test ctor for NPE
|
||||
CertificateRevokedException cre = null;
|
||||
try {
|
||||
cre = new CertificateRevokedException(null, null, null, null);
|
||||
throw new Exception("Did not throw expected NullPointerException");
|
||||
} catch (NullPointerException npe) {}
|
||||
|
||||
// test getRevocationDate returns clone
|
||||
Date date = Calendar.getInstance().getTime();
|
||||
long time = date.getTime();
|
||||
Map<String, Extension> extensions = new HashMap<String, Extension>();
|
||||
Date invDate = new Date(date.getTime());
|
||||
extensions.put("2.5.29.24", new InvalidityDateExtension(invDate));
|
||||
cre = new CertificateRevokedException(date, CRLReason.UNSPECIFIED,
|
||||
new X500Principal("CN=TestCA"), extensions);
|
||||
Date date2 = cre.getRevocationDate();
|
||||
if (date2 == date) {
|
||||
throw new Exception("getRevocationDate does not return copy");
|
||||
}
|
||||
|
||||
// test getRevocationDate returns the same date as specified in ctor
|
||||
if (!date.equals(date2)) {
|
||||
throw new Exception("getRevocationDate returns different date");
|
||||
}
|
||||
|
||||
// test ctor copies date
|
||||
date.setTime(777);
|
||||
date2 = cre.getRevocationDate();
|
||||
if (date2.getTime() != time) {
|
||||
throw new Exception("Constructor did not copy date parameter");
|
||||
}
|
||||
|
||||
// test getReason returns same reason as specified in ctor
|
||||
CRLReason reason = cre.getRevocationReason();
|
||||
if (reason != CRLReason.UNSPECIFIED) {
|
||||
throw new Exception("getRevocationReason returns different reason");
|
||||
}
|
||||
|
||||
// test getAuthorityName returns same name as specified in ctor
|
||||
if (!cre.getAuthorityName().equals(new X500Principal("CN=TestCA"))) {
|
||||
throw new Exception("getAuthorityName returns different name");
|
||||
}
|
||||
|
||||
// test getInvalidityDate returns invalidity date
|
||||
Date invalidity = cre.getInvalidityDate();
|
||||
if (invalidity == null) {
|
||||
throw new Exception("getInvalidityDate returned null");
|
||||
}
|
||||
if (invalidity.getTime() != time) {
|
||||
throw new Exception("getInvalidityDate returned wrong date");
|
||||
}
|
||||
// test getInvalidityDate copies date
|
||||
invDate.setTime(777);
|
||||
if (invalidity.getTime() != time) {
|
||||
throw new Exception("getInvalidityDate did not return copy of date");
|
||||
}
|
||||
|
||||
// test serialization
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
ObjectOutputStream oos = new ObjectOutputStream(baos);
|
||||
oos.writeObject(cre);
|
||||
oos.close();
|
||||
|
||||
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
|
||||
ObjectInputStream ois = new ObjectInputStream(bais);
|
||||
CertificateRevokedException cre2 =
|
||||
(CertificateRevokedException) ois.readObject();
|
||||
|
||||
if (cre2.getRevocationDate().getTime() != time) {
|
||||
throw new Exception("deserialized exception returns different date");
|
||||
}
|
||||
if (cre2.getRevocationReason() != CRLReason.UNSPECIFIED) {
|
||||
throw new Exception("deserialized exception returns different reason");
|
||||
}
|
||||
if (!cre2.getAuthorityName().equals(new X500Principal("CN=TestCA"))) {
|
||||
throw new Exception("deserialized exception returns different name");
|
||||
}
|
||||
if (!cre2.getExtensions().keySet().equals(cre.getExtensions().keySet())) {
|
||||
throw new Exception("deserialized exception returns different extensions");
|
||||
}
|
||||
}
|
||||
}
|
||||
72
test/jdk/java/security/cert/GetInstance.java
Normal file
72
test/jdk/java/security/cert/GetInstance.java
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
/*
|
||||
* Copyright (c) 2001, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @bug 4416946
|
||||
* @summary Make sure {CertStore,CertPathBuilder,CertPathValidator,
|
||||
* CertificateFactory}.getInstance throws InvalidAlgorithmParameterException
|
||||
* if invalid params are specified and NoSuchAlgorithmException (or
|
||||
* CertificateException for CertificateFactory) if bogus type is specified
|
||||
*/
|
||||
import java.security.*;
|
||||
import java.security.cert.*;
|
||||
import java.util.*;
|
||||
|
||||
public class GetInstance {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
|
||||
CollectionCertStoreParameters ccsp
|
||||
= new CollectionCertStoreParameters(new ArrayList());
|
||||
try {
|
||||
CertStore cs = CertStore.getInstance("LDAP", ccsp);
|
||||
throw new Exception("CertStore.getInstance() should have thrown " +
|
||||
"InvalidAlgorithmParameterException");
|
||||
} catch (InvalidAlgorithmParameterException iape) { }
|
||||
|
||||
try {
|
||||
CertStore cs = CertStore.getInstance("BOGUS", null);
|
||||
throw new Exception("CertStore.getInstance() should have thrown " +
|
||||
"NoSuchAlgorithmException");
|
||||
} catch (NoSuchAlgorithmException nsae) { }
|
||||
|
||||
try {
|
||||
CertPathBuilder cpb = CertPathBuilder.getInstance("BOGUS");
|
||||
throw new Exception("CertPathBuilder.getInstance() should have " +
|
||||
"thrown NoSuchAlgorithmException");
|
||||
} catch (NoSuchAlgorithmException nsae) { }
|
||||
|
||||
try {
|
||||
CertPathValidator cpv = CertPathValidator.getInstance("BOGUS");
|
||||
throw new Exception("CertPathValidator.getInstance() should have " +
|
||||
"thrown NoSuchAlgorithmException");
|
||||
} catch (NoSuchAlgorithmException nsae) { }
|
||||
|
||||
try {
|
||||
CertificateFactory cf = CertificateFactory.getInstance("BOGUS");
|
||||
throw new Exception("CertificateFactory.getInstance() should " +
|
||||
"have thrown CertificateException");
|
||||
} catch (CertificateException ce) { }
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,64 @@
|
|||
/*
|
||||
* Copyright (c) 2001, 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 4422738
|
||||
* @compile InvalidParameters.java
|
||||
* @run main InvalidParameters
|
||||
* @summary Make sure PKIXBuilderParameters(Set) detects invalid
|
||||
* parameters and throws correct exceptions
|
||||
*/
|
||||
import java.security.InvalidAlgorithmParameterException;
|
||||
import java.security.cert.PKIXBuilderParameters;
|
||||
import java.security.cert.TrustAnchor;
|
||||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
|
||||
public class InvalidParameters {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
|
||||
// make sure empty Set of anchors throws InvAlgParamExc
|
||||
try {
|
||||
PKIXBuilderParameters p =
|
||||
new PKIXBuilderParameters(Collections.EMPTY_SET, null);
|
||||
throw new Exception("should have thrown InvalidAlgorithmParameterExc");
|
||||
} catch (InvalidAlgorithmParameterException iape) { }
|
||||
|
||||
// make sure null Set of anchors throws NullPointerException
|
||||
try {
|
||||
PKIXBuilderParameters p = new PKIXBuilderParameters((Set) null, null);
|
||||
throw new Exception("should have thrown NullPointerException");
|
||||
} catch (NullPointerException npe) { }
|
||||
|
||||
// make sure Set of invalid objects throws ClassCastException
|
||||
try {
|
||||
@SuppressWarnings("unchecked") // Knowingly do something bad
|
||||
Set<TrustAnchor> badSet = (Set<TrustAnchor>) (Set) Collections.singleton(new String());
|
||||
PKIXBuilderParameters p =
|
||||
new PKIXBuilderParameters(badSet, null);
|
||||
throw new Exception("should have thrown ClassCastException");
|
||||
} catch (ClassCastException cce) { }
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,84 @@
|
|||
/*
|
||||
* Copyright (c) 2001, 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @bug 4422738
|
||||
* @compile InvalidParameters.java
|
||||
* @run main InvalidParameters
|
||||
* @summary Make sure PKIXParameters(Set) and setTrustAnchors() detects invalid
|
||||
* parameters and throws correct exceptions
|
||||
*/
|
||||
import java.security.InvalidAlgorithmParameterException;
|
||||
import java.security.PublicKey;
|
||||
import java.security.cert.PKIXParameters;
|
||||
import java.security.cert.TrustAnchor;
|
||||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
|
||||
public class InvalidParameters {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
|
||||
TrustAnchor anchor = new TrustAnchor("cn=sean", new TestPublicKey(), null);
|
||||
PKIXParameters params = new PKIXParameters(Collections.singleton(anchor));
|
||||
|
||||
// make sure empty Set of anchors throws InvAlgParamExc
|
||||
try {
|
||||
PKIXParameters p = new PKIXParameters(Collections.EMPTY_SET);
|
||||
throw new Exception("should have thrown InvalidAlgorithmParameterExc");
|
||||
} catch (InvalidAlgorithmParameterException iape) { }
|
||||
try {
|
||||
params.setTrustAnchors(Collections.EMPTY_SET);
|
||||
throw new Exception("should have thrown InvalidAlgorithmParameterExc");
|
||||
} catch (InvalidAlgorithmParameterException iape) { }
|
||||
|
||||
// make sure null Set of anchors throws NullPointerException
|
||||
try {
|
||||
PKIXParameters p = new PKIXParameters((Set) null);
|
||||
throw new Exception("should have thrown NullPointerException");
|
||||
} catch (NullPointerException npe) { }
|
||||
try {
|
||||
params.setTrustAnchors((Set) null);
|
||||
throw new Exception("should have thrown NullPointerException");
|
||||
} catch (NullPointerException npe) { }
|
||||
|
||||
// make sure Set of invalid objects throws ClassCastException
|
||||
@SuppressWarnings("unchecked") // Knowingly do something bad
|
||||
Set<TrustAnchor> badSet = (Set<TrustAnchor>) (Set) Collections.singleton(new String());
|
||||
try {
|
||||
PKIXParameters p = new PKIXParameters(badSet);
|
||||
throw new Exception("should have thrown ClassCastException");
|
||||
} catch (ClassCastException cce) { }
|
||||
try {
|
||||
params.setTrustAnchors(badSet);
|
||||
throw new Exception("should have thrown ClassCastException");
|
||||
} catch (ClassCastException cce) { }
|
||||
}
|
||||
|
||||
static class TestPublicKey implements PublicKey {
|
||||
public String getAlgorithm() { return "Test"; }
|
||||
public String getFormat() { return null; }
|
||||
public byte[] getEncoded() { return null; }
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,113 @@
|
|||
/*
|
||||
* Copyright (c) 2013, 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @bug 8023362
|
||||
* @run main/othervm OcspUnauthorized
|
||||
* @summary Make sure Ocsp UNAUTHORIZED response is treated as failure when
|
||||
* SOFT_FAIL option is set
|
||||
*/
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.security.Security;
|
||||
import java.security.cert.CertPathValidatorException.BasicReason;
|
||||
import java.security.cert.*;
|
||||
import java.security.cert.PKIXRevocationChecker.Option;
|
||||
import java.util.Base64;
|
||||
import java.util.Collections;
|
||||
import java.util.EnumSet;
|
||||
|
||||
public class OcspUnauthorized {
|
||||
|
||||
private final static String OCSP_RESPONSE = "MAMKAQY=";
|
||||
|
||||
private final static String EE_CERT =
|
||||
"MIICADCCAWmgAwIBAgIEOvxUmjANBgkqhkiG9w0BAQQFADAqMQswCQYDVQQGEwJ1czE" +
|
||||
"MMAoGA1UEChMDc3VuMQ0wCwYDVQQLEwRsYWJzMB4XDTAxMDUxNDIwNDQyMVoXDTI4MD" +
|
||||
"kyOTIwNDQyMVowOTELMAkGA1UEBhMCdXMxDDAKBgNVBAoTA3N1bjENMAsGA1UECxMEb" +
|
||||
"GFiczENMAsGA1UECxMEaXNyZzCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEA4MmP" +
|
||||
"GDriFJ+OhDlTuLpHzPy0nawDKyIYUJPZmU9M/pCAUbZewAOyAXGPYVU1og2ZiO9tWBi" +
|
||||
"ZBeJGoFHEkkhfeqSVb2PsRckiXvPZ3AiSVmdX0uD/a963abmhRMYB1gDO2+jBe3F/DU" +
|
||||
"pHwpyThchy8tYUMh7Gr7+m/8FwZbdbSpMCAwEAAaMkMCIwDwYDVR0PAQH/BAUDAwekA" +
|
||||
"DAPBgNVHRMBAf8EBTADAQH/MA0GCSqGSIb3DQEBBAUAA4GBAME3fmXvES0FVDXSD1iC" +
|
||||
"TJLf86kUy3H+uMG7h5pOQmcfF1o9PVWlNByVf4r2b4GRgftPQ3Ao0SAvq1aSkW7YpkN" +
|
||||
"pcartYqNk2E5brPajOC0v+Pkxf/g/pkRTT6Zp+9erGQF4Ta62q0iwOyc3FovSbh0Ph2" +
|
||||
"WidZRP4qUG5I6JmGkI";
|
||||
|
||||
private final static String TRUST_ANCHOR =
|
||||
"MIICIzCCAYygAwIBAgIEOvxT7DANBgkqhkiG9w0BAQQFADAbMQswCQYDVQQGEwJ1czE" +
|
||||
"MMAoGA1UEChMDc3VuMB4XDTAxMDUxNDIxMDQyOVoXDTI4MDkyOTIxMDQyOVowKjELMA" +
|
||||
"kGA1UEBhMCdXMxDDAKBgNVBAoTA3N1bjENMAsGA1UECxMEbGFiczCBnzANBgkqhkiG9" +
|
||||
"w0BAQEFAAOBjQAwgYkCgYEA0/16V87rhznCM0y7IqyGcfQBentG+PglA+1hiqCuQY/A" +
|
||||
"jFiDKr5N+LpcfU28P41E4M+DSDrMIEe4JchRcXeJY6aIVhpOveVV9mgtBaEKlsScrIJ" +
|
||||
"zmVqM07PG9JENg2FibECnB5TNUSfVbFKfvtAqaZ7Pc971oZVoIePBWnfKV9kCAwEAAa" +
|
||||
"NlMGMwPwYDVR0eAQH/BDUwM6AxMC+kKjELMAkGA1UEBhMCdXMxDDAKBgNVBAoTA3N1b" +
|
||||
"jENMAsGA1UECxMEbGFic4ABAzAPBgNVHQ8BAf8EBQMDB6QAMA8GA1UdEwEB/wQFMAMB" +
|
||||
"Af8wDQYJKoZIhvcNAQEEBQADgYEAfJ5HWd7K5PmX0+Vbsux4SYhoaejDwwgS43BRNa+" +
|
||||
"AmFq9LIZ+ZcjBMVte8Y3sJF+nz9+1qBaUhNhbaECCqsgmWSwvI+0kUzJXL89k9AdQ8m" +
|
||||
"AYf6CB6+kaZQBgrdSdqSGz3tCVa2MIK8wmb0ROM40oJ7vt3qSwgFi3UTltxkFfwQ0=";
|
||||
|
||||
private static CertificateFactory cf;
|
||||
private static Base64.Decoder base64Decoder = Base64.getDecoder();
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
// EE_CERT is signed with MD5withRSA
|
||||
Security.setProperty("jdk.certpath.disabledAlgorithms", "");
|
||||
cf = CertificateFactory.getInstance("X.509");
|
||||
X509Certificate taCert = getX509Cert(TRUST_ANCHOR);
|
||||
X509Certificate eeCert = getX509Cert(EE_CERT);
|
||||
CertPath cp = cf.generateCertPath(Collections.singletonList(eeCert));
|
||||
|
||||
CertPathValidator cpv = CertPathValidator.getInstance("PKIX");
|
||||
PKIXRevocationChecker prc =
|
||||
(PKIXRevocationChecker)cpv.getRevocationChecker();
|
||||
prc.setOptions(EnumSet.of(Option.SOFT_FAIL, Option.NO_FALLBACK));
|
||||
byte[] response = base64Decoder.decode(OCSP_RESPONSE);
|
||||
|
||||
prc.setOcspResponses(Collections.singletonMap(eeCert, response));
|
||||
|
||||
TrustAnchor ta = new TrustAnchor(taCert, null);
|
||||
PKIXParameters params = new PKIXParameters(Collections.singleton(ta));
|
||||
|
||||
params.addCertPathChecker(prc);
|
||||
|
||||
try {
|
||||
cpv.validate(cp, params);
|
||||
throw new Exception("FAILED: expected CertPathValidatorException");
|
||||
} catch (CertPathValidatorException cpve) {
|
||||
cpve.printStackTrace();
|
||||
if (cpve.getReason() != BasicReason.UNSPECIFIED &&
|
||||
!cpve.getMessage().contains("OCSP response error: UNAUTHORIZED")) {
|
||||
throw new Exception("FAILED: unexpected " +
|
||||
"CertPathValidatorException reason");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static X509Certificate getX509Cert(String enc) throws Exception {
|
||||
byte[] bytes = base64Decoder.decode(enc);
|
||||
ByteArrayInputStream is = new ByteArrayInputStream(bytes);
|
||||
return (X509Certificate)cf.generateCertificate(is);
|
||||
}
|
||||
}
|
||||
185
test/jdk/java/security/cert/PKIXRevocationChecker/UnitTest.java
Normal file
185
test/jdk/java/security/cert/PKIXRevocationChecker/UnitTest.java
Normal file
|
|
@ -0,0 +1,185 @@
|
|||
/*
|
||||
* Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @bug 6854712 7171570 8010748 8025287
|
||||
* @summary Basic unit test for PKIXRevocationChecker
|
||||
*/
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.InputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.net.URI;
|
||||
import java.security.cert.*;
|
||||
import java.security.cert.PKIXRevocationChecker.Option;
|
||||
import java.util.*;
|
||||
|
||||
public class UnitTest {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
|
||||
CertPathValidator cpv = CertPathValidator.getInstance("PKIX");
|
||||
CertPathChecker cpc = cpv.getRevocationChecker();
|
||||
PKIXRevocationChecker prc = (PKIXRevocationChecker)cpc;
|
||||
|
||||
prc.init(false);
|
||||
|
||||
System.out.println("Testing that get methods return null or " +
|
||||
"empty lists/sets/maps");
|
||||
requireNull(prc.getOcspResponder(), "getOcspResponder()");
|
||||
requireNull(prc.getOcspResponderCert(), "getOcspResponderCert()");
|
||||
requireEmpty(prc.getOcspExtensions(), "getOcspExtensions()");
|
||||
requireEmpty(prc.getOcspResponses(), "getOcspResponses()");
|
||||
requireEmpty(prc.getOptions(), "getOptions()");
|
||||
requireEmpty(prc.getSoftFailExceptions(), "getSoftFailExceptions()");
|
||||
|
||||
System.out.println("Testing that get methods return same parameters " +
|
||||
"that are passed to set methods");
|
||||
URI uri = new URI("http://localhost");
|
||||
prc.setOcspResponder(uri);
|
||||
requireEquals(uri, prc.getOcspResponder(), "getOcspResponder()");
|
||||
|
||||
X509Certificate cert = getCert();
|
||||
prc.setOcspResponderCert(cert);
|
||||
requireEquals(cert, prc.getOcspResponderCert(),
|
||||
"getOcspResponderCert()");
|
||||
|
||||
List<Extension> exts = new ArrayList<>();
|
||||
for (String oid : cert.getNonCriticalExtensionOIDs()) {
|
||||
System.out.println(oid);
|
||||
exts.add(new ExtensionImpl(oid,
|
||||
cert.getExtensionValue(oid), false));
|
||||
}
|
||||
prc.setOcspExtensions(exts);
|
||||
requireEquals(exts, prc.getOcspExtensions(), "getOcspExtensions()");
|
||||
|
||||
Set<Option> options = EnumSet.of(Option.ONLY_END_ENTITY);
|
||||
prc.setOptions(options);
|
||||
requireEquals(options, prc.getOptions(), "getOptions()");
|
||||
|
||||
System.out.println("Testing that parameters are re-initialized to " +
|
||||
"default values if null is passed to set methods");
|
||||
prc.setOcspResponder(null);
|
||||
requireNull(prc.getOcspResponder(), "getOcspResponder()");
|
||||
prc.setOcspResponderCert(null);
|
||||
requireNull(prc.getOcspResponderCert(), "getOcspResponderCert()");
|
||||
prc.setOcspExtensions(null);
|
||||
requireEmpty(prc.getOcspExtensions(), "getOcspExtensions()");
|
||||
prc.setOcspResponses(null);
|
||||
requireEmpty(prc.getOcspResponses(), "getOcspResponses()");
|
||||
prc.setOptions(null);
|
||||
requireEmpty(prc.getOptions(), "getOptions()");
|
||||
|
||||
System.out.println("Testing that getRevocationChecker returns new " +
|
||||
"instance each time");
|
||||
CertPathChecker first = cpv.getRevocationChecker();
|
||||
CertPathChecker second = cpv.getRevocationChecker();
|
||||
if (first == second) {
|
||||
throw new Exception("FAILED: CertPathCheckers not new instances");
|
||||
}
|
||||
CertPathBuilder cpb = CertPathBuilder.getInstance("PKIX");
|
||||
first = cpb.getRevocationChecker();
|
||||
second = cpb.getRevocationChecker();
|
||||
if (first == second) {
|
||||
throw new Exception("FAILED: CertPathCheckers not new instances");
|
||||
}
|
||||
}
|
||||
|
||||
static void requireNull(Object o, String msg) throws Exception {
|
||||
if (o != null) {
|
||||
throw new Exception("FAILED: " + msg + " must return null");
|
||||
}
|
||||
}
|
||||
|
||||
static void requireEmpty(Map<?,?> m, String msg) throws Exception {
|
||||
if (!m.isEmpty()) {
|
||||
throw new Exception("FAILED: " + msg + " must return an empty map");
|
||||
}
|
||||
}
|
||||
|
||||
static void requireEmpty(List<?> l, String msg) throws Exception {
|
||||
if (!l.isEmpty()) {
|
||||
throw new Exception("FAILED: " + msg +" must return an empty list");
|
||||
}
|
||||
}
|
||||
|
||||
static void requireEmpty(Set<?> s, String msg) throws Exception {
|
||||
if (!s.isEmpty()) {
|
||||
throw new Exception("FAILED: " + msg + " must return an empty set");
|
||||
}
|
||||
}
|
||||
|
||||
static void requireEquals(Object a, Object b, String msg) throws Exception {
|
||||
if (!a.equals(b)) {
|
||||
throw new Exception("FAILED: " + msg + " does not return the " +
|
||||
"same object that was set");
|
||||
}
|
||||
}
|
||||
|
||||
static X509Certificate getCert() throws Exception {
|
||||
String b64 =
|
||||
"-----BEGIN CERTIFICATE-----\n" +
|
||||
"MIIBLTCB2KADAgECAgEDMA0GCSqGSIb3DQEBBAUAMA0xCzAJBgNVBAMTAkNBMB4X\n" +
|
||||
"DTAyMTEwNzExNTcwM1oXDTIyMTEwNzExNTcwM1owFTETMBEGA1UEAxMKRW5kIEVu\n" +
|
||||
"dGl0eTBcMA0GCSqGSIb3DQEBAQUAA0sAMEgCQQDVBDfF+uBr5s5jzzDs1njKlZNt\n" +
|
||||
"h8hHzEt3ASh67Peos+QrDzgpUyFXT6fdW2h7iPf0ifjM8eW2xa+3EnPjjU5jAgMB\n" +
|
||||
"AAGjGzAZMBcGA1UdIAQQMA4wBgYEVR0gADAEBgIqADANBgkqhkiG9w0BAQQFAANB\n" +
|
||||
"AFo//WOboCNOCcA1fvcWW9oc4MvV8ZPvFIAbyEbgyFd4id5lGDTRbRPvvNZRvdsN\n" +
|
||||
"NM2gXYr+f87NHIXc9EF3pzw=\n" +
|
||||
"-----END CERTIFICATE-----";
|
||||
|
||||
InputStream is = new ByteArrayInputStream(b64.getBytes("UTF-8"));
|
||||
CertificateFactory cf = CertificateFactory.getInstance("X.509");
|
||||
return (X509Certificate)cf.generateCertificate(is);
|
||||
}
|
||||
|
||||
static class ExtensionImpl implements Extension {
|
||||
private final String oid;
|
||||
private final byte[] val;
|
||||
private final boolean critical;
|
||||
|
||||
ExtensionImpl(String oid, byte[] val, boolean critical) {
|
||||
this.oid = oid;
|
||||
this.val = val;
|
||||
this.critical = critical;
|
||||
}
|
||||
|
||||
public void encode(OutputStream out) throws IOException {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return oid;
|
||||
}
|
||||
|
||||
public byte[] getValue() {
|
||||
return val.clone();
|
||||
}
|
||||
|
||||
public boolean isCritical() {
|
||||
return critical;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,88 @@
|
|||
/*
|
||||
* Copyright (c) 2001, 2020, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @bug 4414263
|
||||
* @summary Make sure PolicyNode.getPolicyQualifiers() returns
|
||||
* Set of PolicyQualifierInfos.
|
||||
*/
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.security.cert.*;
|
||||
import java.text.DateFormat;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
|
||||
public class GetPolicyQualifiers {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
|
||||
CertificateFactory cf = CertificateFactory.getInstance("X.509", "SUN");
|
||||
File f = new File(System.getProperty("test.src", "."), "speech2speech");
|
||||
X509Certificate mostTrustedCaCert = (X509Certificate)
|
||||
cf.generateCertificate(new FileInputStream(f));
|
||||
Set trustAnchors = Collections.singleton(
|
||||
new TrustAnchor(mostTrustedCaCert, null));
|
||||
f = new File(System.getProperty("test.src", "."), "speech2eve");
|
||||
X509Certificate eeCert = (X509Certificate)
|
||||
cf.generateCertificate(new FileInputStream(f));
|
||||
CertPathValidator cpv = CertPathValidator.getInstance("PKIX", "SUN");
|
||||
PKIXParameters params = new PKIXParameters(trustAnchors);
|
||||
params.setPolicyQualifiersRejected(false);
|
||||
params.setRevocationEnabled(false);
|
||||
// Certificates expired on Oct 6th, 2020
|
||||
params.setDate(DateFormat.getDateInstance(DateFormat.MEDIUM,
|
||||
Locale.US).parse("July 01, 2020"));
|
||||
List certList = Collections.singletonList(eeCert);
|
||||
CertPath cp = cf.generateCertPath(certList);
|
||||
PKIXCertPathValidatorResult result =
|
||||
(PKIXCertPathValidatorResult) cpv.validate(cp, params);
|
||||
|
||||
PolicyNode policyTree = result.getPolicyTree();
|
||||
Iterator children = policyTree.getChildren();
|
||||
PolicyNode child = (PolicyNode) children.next();
|
||||
Set policyQualifiers = child.getPolicyQualifiers();
|
||||
Iterator i = policyQualifiers.iterator();
|
||||
while (i.hasNext()) {
|
||||
Object next = i.next();
|
||||
if (!(next instanceof PolicyQualifierInfo))
|
||||
throw new Exception("not a PolicyQualifierInfo");
|
||||
}
|
||||
|
||||
params.setPolicyQualifiersRejected(true);
|
||||
try {
|
||||
result = (PKIXCertPathValidatorResult) cpv.validate(cp, params);
|
||||
throw new Exception("Validation of CertPath containing critical " +
|
||||
"qualifiers should have failed when policyQualifiersRejected " +
|
||||
"flag is true");
|
||||
} catch (CertPathValidatorException cpve) {
|
||||
if (cpve.getReason() != PKIXReason.INVALID_POLICY) {
|
||||
throw new Exception("unexpected reason: " + cpve.getReason());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
BIN
test/jdk/java/security/cert/PolicyNode/speech2eve
Normal file
BIN
test/jdk/java/security/cert/PolicyNode/speech2eve
Normal file
Binary file not shown.
BIN
test/jdk/java/security/cert/PolicyNode/speech2speech
Normal file
BIN
test/jdk/java/security/cert/PolicyNode/speech2speech
Normal file
Binary file not shown.
|
|
@ -0,0 +1,85 @@
|
|||
/*
|
||||
* Copyright (c) 2015, 2025, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
import java.security.cert.CertStore;
|
||||
import java.security.cert.URICertStoreParameters;
|
||||
import java.net.URI;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 8038084 8355379
|
||||
* @summary Basic testing for URICertStoreParameters
|
||||
* @run main TestBasic
|
||||
*/
|
||||
public class TestBasic {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
String str1 = "ldap://myownhost:5000/";
|
||||
String str2 = "ldap://myownhost:5000/cn=foo";
|
||||
test(str1, str2);
|
||||
testRepeatedHashCode(str1);
|
||||
System.out.println("Test passed");
|
||||
}
|
||||
|
||||
private static void test(String str1, String str2) throws Exception {
|
||||
System.out.println("Testing clone");
|
||||
URICertStoreParameters p1 = new URICertStoreParameters(new URI(str1));
|
||||
URICertStoreParameters p1Too = p1.clone();
|
||||
if (!(p1.getURI().equals(p1Too.getURI())) ||
|
||||
!(p1.equals(p1Too))) {
|
||||
throw new Exception("Error: problem with clone");
|
||||
}
|
||||
System.out.println("Testing equal and hashCode");
|
||||
p1Too = new URICertStoreParameters(new URI(str1));
|
||||
URICertStoreParameters p2 = new URICertStoreParameters(new URI(str2));
|
||||
|
||||
if (p1.equals(null)) {
|
||||
throw new Exception("Error: p1 should NOT equal null");
|
||||
}
|
||||
if ((!p1.equals(p1)) || (p1.hashCode() != p1.hashCode())) {
|
||||
throw new Exception("Error: p1 should equal p1");
|
||||
}
|
||||
if ((!p1.equals(p1Too)) || (p1.hashCode() != p1Too.hashCode())) {
|
||||
throw new Exception("Error: p1 should equal p1Too");
|
||||
}
|
||||
if ((!p1Too.equals(p1)) || (p1Too.hashCode() != p1.hashCode())) {
|
||||
throw new Exception("Error: p1Too should equal p1");
|
||||
}
|
||||
if (p1.equals(p2) || p1Too.equals(p2)) {
|
||||
throw new Exception("Error: p1/p1Too should NOT equal p2");
|
||||
}
|
||||
}
|
||||
|
||||
private static void testRepeatedHashCode(String str) throws Exception {
|
||||
System.out.println("Testing repeated hashCode consistency");
|
||||
URICertStoreParameters p = new URICertStoreParameters(new URI(str));
|
||||
int h1 = p.hashCode();
|
||||
int h2 = p.hashCode();
|
||||
if (h1 != h2) {
|
||||
throw new Exception("hashCode inconsistent across calls");
|
||||
}
|
||||
System.out.println("hashCode consistency verified");
|
||||
}
|
||||
}
|
||||
134
test/jdk/java/security/cert/X509CRL/VerifyDefault.java
Normal file
134
test/jdk/java/security/cert/X509CRL/VerifyDefault.java
Normal file
|
|
@ -0,0 +1,134 @@
|
|||
/*
|
||||
* Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @bug 8175029
|
||||
* @library /test/lib
|
||||
* @summary check that default implementation of
|
||||
* X509CRL.verify(PublicKey, Provider) works on custom X509CRL impl.
|
||||
*/
|
||||
|
||||
import java.math.BigInteger;
|
||||
import java.security.InvalidKeyException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.NoSuchProviderException;
|
||||
import java.security.Principal;
|
||||
import java.security.Provider;
|
||||
import java.security.PublicKey;
|
||||
import java.security.SignatureException;
|
||||
import java.security.cert.Certificate;
|
||||
import java.security.cert.CRLException;
|
||||
import java.security.cert.X509Certificate;
|
||||
import java.security.cert.X509CRL;
|
||||
import java.security.cert.X509CRLEntry;
|
||||
import java.util.Date;
|
||||
import java.util.Set;
|
||||
import jdk.test.lib.security.CertUtils;
|
||||
|
||||
public class VerifyDefault {
|
||||
private static final String TEST_CRL =
|
||||
"-----BEGIN X509 CRL-----\n" +
|
||||
"MIIBGzCBhQIBATANBgkqhkiG9w0BAQQFADAfMQswCQYDVQQGEwJVUzEQMA4GA1UE\n" +
|
||||
"ChMHRXhhbXBsZRcNMDkwNDI3MDIzODA0WhcNMjgwNjI2MDIzODA0WjAiMCACAQUX\n" +
|
||||
"DTA5MDQyNzAyMzgwMFowDDAKBgNVHRUEAwoBBKAOMAwwCgYDVR0UBAMCAQIwDQYJ\n" +
|
||||
"KoZIhvcNAQEEBQADgYEAoarfzXEtw3ZDi4f9U8eSvRIipHSyxOrJC7HR/hM5VhmY\n" +
|
||||
"CErChny6x9lBVg9s57tfD/P9PSzBLusCcHwHMAbMOEcTltVVKUWZnnbumpywlYyg\n" +
|
||||
"oKLrE9+yCOkYUOpiRlz43/3vkEL5hjIKMcDSZnPKBZi1h16Yj2hPe9GMibNip54=\n" +
|
||||
"-----END X509 CRL-----";
|
||||
|
||||
private static final String TEST_CERT =
|
||||
"-----BEGIN CERTIFICATE-----\n" +
|
||||
"MIICKzCCAZSgAwIBAgIBAjANBgkqhkiG9w0BAQQFADAfMQswCQYDVQQGEwJVUzEQ\n" +
|
||||
"MA4GA1UEChMHRXhhbXBsZTAeFw0wOTA0MjcwMjI0MzNaFw0yOTAxMTIwMjI0MzNa\n" +
|
||||
"MB8xCzAJBgNVBAYTAlVTMRAwDgYDVQQKEwdFeGFtcGxlMIGfMA0GCSqGSIb3DQEB\n" +
|
||||
"AQUAA4GNADCBiQKBgQDMJeBMBybHykI/YpwUJ4O9euqDSLb1kpWpceBS8TVqvgBC\n" +
|
||||
"SgUJWtFZL0i6bdvF6mMdlbuBkGzhXqHiVAi96/zRLbUC9F8SMEJ6MuD+YhQ0ZFTQ\n" +
|
||||
"atKy8zf8O9XzztelLJ26Gqb7QPV133WY3haAqHtCXOhEKkCN16NOYNC37DTaJwID\n" +
|
||||
"AQABo3cwdTAdBgNVHQ4EFgQULXSWzXzUOIpOJpzbSCpW42IJUugwRwYDVR0jBEAw\n" +
|
||||
"PoAUgiXdIaZeT3QA/SGUvh854OJVyxuhI6QhMB8xCzAJBgNVBAYTAlVTMRAwDgYD\n" +
|
||||
"VQQKEwdFeGFtcGxlggEAMAsGA1UdDwQEAwIBAjANBgkqhkiG9w0BAQQFAAOBgQAY\n" +
|
||||
"eMnf5AHSNlyUlzXk8o2S0h4gCuvKX6C3kFfKuZcWvFAbx4yQOWLS2s15/nzR4+AP\n" +
|
||||
"FGX3lgJjROyAh7fGedTQK+NFWwkM2ag1g3hXktnlnT1qHohi0w31nVBJxXEDO/Ck\n" +
|
||||
"uJTpJGt8XxxbFaw5v7cHy7XuTAeU/sekvjEiNHW00Q==\n" +
|
||||
"-----END CERTIFICATE-----";
|
||||
|
||||
private static class TestX509CRL extends X509CRL {
|
||||
private final X509CRL crl;
|
||||
TestX509CRL(X509CRL crl) {
|
||||
this.crl = crl;
|
||||
}
|
||||
public Set<String> getCriticalExtensionOIDs() {
|
||||
return crl.getCriticalExtensionOIDs();
|
||||
}
|
||||
public byte[] getExtensionValue(String oid) {
|
||||
return crl.getExtensionValue(oid);
|
||||
}
|
||||
public Set<String> getNonCriticalExtensionOIDs() {
|
||||
return crl.getNonCriticalExtensionOIDs();
|
||||
}
|
||||
public boolean hasUnsupportedCriticalExtension() {
|
||||
return crl.hasUnsupportedCriticalExtension();
|
||||
}
|
||||
public Set<? extends X509CRLEntry> getRevokedCertificates() {
|
||||
return crl.getRevokedCertificates();
|
||||
}
|
||||
public X509CRLEntry getRevokedCertificate(BigInteger serialNumber) {
|
||||
return crl.getRevokedCertificate(serialNumber);
|
||||
}
|
||||
public boolean isRevoked(Certificate cert) {
|
||||
return crl.isRevoked(cert);
|
||||
}
|
||||
public Date getNextUpdate() { return crl.getNextUpdate(); }
|
||||
public Date getThisUpdate() { return crl.getThisUpdate(); }
|
||||
public int getVersion() { return crl.getVersion(); }
|
||||
public Principal getIssuerDN() { return crl.getIssuerDN(); }
|
||||
public byte[] getTBSCertList() throws CRLException {
|
||||
return crl.getTBSCertList();
|
||||
}
|
||||
public byte[] getSignature() { return crl.getSignature(); }
|
||||
public String getSigAlgName() { return crl.getSigAlgName(); }
|
||||
public String getSigAlgOID() { return crl.getSigAlgOID(); }
|
||||
public byte[] getSigAlgParams() { return crl.getSigAlgParams(); }
|
||||
public byte[] getEncoded() throws CRLException {
|
||||
return crl.getEncoded();
|
||||
}
|
||||
public void verify(PublicKey key) throws CRLException,
|
||||
InvalidKeyException, NoSuchAlgorithmException,
|
||||
NoSuchProviderException, SignatureException {
|
||||
crl.verify(key);
|
||||
}
|
||||
public void verify(PublicKey key, String sigProvider) throws
|
||||
CRLException, InvalidKeyException, NoSuchAlgorithmException,
|
||||
NoSuchProviderException, SignatureException {
|
||||
crl.verify(key, sigProvider);
|
||||
}
|
||||
public String toString() { return crl.toString(); }
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
X509Certificate cert = CertUtils.getCertFromString(TEST_CERT);
|
||||
X509CRL crl = CertUtils.getCRLFromString(TEST_CRL);
|
||||
new TestX509CRL(crl).verify(cert.getPublicKey(), (Provider)null);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,77 @@
|
|||
/*
|
||||
* Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
import jdk.test.lib.Asserts;
|
||||
import sun.security.x509.CRLExtensions;
|
||||
import sun.security.x509.CRLNumberExtension;
|
||||
import sun.security.x509.X500Name;
|
||||
import sun.security.x509.X509CRLImpl;
|
||||
|
||||
import java.math.BigInteger;
|
||||
import java.security.KeyPairGenerator;
|
||||
import java.security.cert.X509CRLSelector;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @bug 8296399
|
||||
* @summary crlNumExtVal might be null inside X509CRLSelector::match
|
||||
* @library /test/lib
|
||||
* @modules java.base/sun.security.x509
|
||||
*/
|
||||
|
||||
public class CRLNumberMissing {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
|
||||
var pk = KeyPairGenerator.getInstance("Ed25519")
|
||||
.generateKeyPair().getPrivate();
|
||||
|
||||
var crlWithoutNum = X509CRLImpl.newSigned(
|
||||
new X509CRLImpl.TBSCertList(
|
||||
new X500Name("CN=CRL"), new Date(), new Date()),
|
||||
pk, "Ed25519");
|
||||
|
||||
var exts = new CRLExtensions();
|
||||
exts.setExtension("CRLNumber", new CRLNumberExtension(1));
|
||||
var crlWithNum = X509CRLImpl.newSigned(
|
||||
new X509CRLImpl.TBSCertList(
|
||||
new X500Name("CN=CRL"), new Date(), new Date(),
|
||||
null, exts),
|
||||
pk, "Ed25519");
|
||||
|
||||
var sel = new X509CRLSelector();
|
||||
Asserts.assertTrue(sel.match(crlWithNum));
|
||||
Asserts.assertTrue(sel.match(crlWithoutNum));
|
||||
|
||||
sel = new X509CRLSelector();
|
||||
sel.setMinCRLNumber(BigInteger.ZERO);
|
||||
Asserts.assertTrue(sel.match(crlWithNum));
|
||||
Asserts.assertFalse(sel.match(crlWithoutNum));
|
||||
|
||||
sel = new X509CRLSelector();
|
||||
sel.setMinCRLNumber(BigInteger.TWO);
|
||||
Asserts.assertFalse(sel.match(crlWithNum));
|
||||
Asserts.assertFalse(sel.match(crlWithoutNum));
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
/*
|
||||
* Copyright (c) 2000, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @bug 4391244
|
||||
* @summary Check setNameConstraints() doesn't throw exception when
|
||||
* bytes parameter contains DER-encoded empty ASN.1 SEQUENCE.
|
||||
*/
|
||||
|
||||
import java.security.cert.X509CertSelector;
|
||||
|
||||
public class SetNameConstraintsEmptySequence {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
X509CertSelector certSel = new X509CertSelector();
|
||||
byte[] data = {0x30, 0x00}; // An empty SEQUENCE
|
||||
certSel.setNameConstraints(data);
|
||||
}
|
||||
}
|
||||
543
test/jdk/java/security/cert/X509CertSelectorTest.java
Normal file
543
test/jdk/java/security/cert/X509CertSelectorTest.java
Normal file
|
|
@ -0,0 +1,543 @@
|
|||
/*
|
||||
* Copyright (c) 2000, 2023, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
import static sun.security.x509.GeneralNameInterface.NAME_DIRECTORY;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.math.BigInteger;
|
||||
import java.security.GeneralSecurityException;
|
||||
import java.security.KeyFactory;
|
||||
import java.security.PublicKey;
|
||||
import java.security.cert.CertificateException;
|
||||
import java.security.cert.CertificateFactory;
|
||||
import java.security.cert.X509CertSelector;
|
||||
import java.security.cert.X509Certificate;
|
||||
import java.security.spec.X509EncodedKeySpec;
|
||||
import java.util.Base64;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import sun.security.util.DerInputStream;
|
||||
import sun.security.util.DerOutputStream;
|
||||
import sun.security.util.DerValue;
|
||||
import sun.security.util.ObjectIdentifier;
|
||||
import sun.security.x509.AlgorithmId;
|
||||
import sun.security.x509.AuthorityKeyIdentifierExtension;
|
||||
import sun.security.x509.CertificatePoliciesExtension;
|
||||
import sun.security.x509.DNSName;
|
||||
import sun.security.x509.GeneralName;
|
||||
import sun.security.x509.GeneralNameInterface;
|
||||
import sun.security.x509.GeneralNames;
|
||||
import sun.security.x509.GeneralSubtree;
|
||||
import sun.security.x509.GeneralSubtrees;
|
||||
import sun.security.x509.KeyIdentifier;
|
||||
import sun.security.x509.NameConstraintsExtension;
|
||||
import sun.security.x509.PolicyInformation;
|
||||
import sun.security.x509.PrivateKeyUsageExtension;
|
||||
import sun.security.x509.SubjectAlternativeNameExtension;
|
||||
import sun.security.x509.X500Name;
|
||||
import sun.security.util.Debug;
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 8074931 8296787
|
||||
* @summary This class tests the X509CertSelector. The tests check particular criteria
|
||||
* by setting them to a value that should match our test certificate and
|
||||
* ensuring that they do match, then setting them to a value that should not
|
||||
* match our test certificate and ensuring that they do not match.
|
||||
* @modules java.base/sun.security.x509
|
||||
* java.base/sun.security.util
|
||||
*/
|
||||
public class X509CertSelectorTest {
|
||||
/*
|
||||
Certificate:
|
||||
Data:
|
||||
Version: 3 (0x2)
|
||||
Serial Number: 954172088 (0x38df82b8)
|
||||
Signature Algorithm: dsaWithSHA1
|
||||
Issuer: C=us, O=sun, OU=testing
|
||||
Validity
|
||||
Not Before: Mar 27 15:48:08 2000 GMT
|
||||
Not After : Jun 25 14:48:08 2000 GMT
|
||||
Subject: C=us, O=sun, OU=testing, CN=mullan
|
||||
Subject Public Key Info:
|
||||
Public Key Algorithm: dsaEncryption
|
||||
pub: 0
|
||||
P: 0
|
||||
Q: 0
|
||||
G: 0
|
||||
X509v3 extensions:
|
||||
X509v3 Name Constraints: critical
|
||||
0D.B0@.>1.0...U....us1.0
|
||||
..U.
|
||||
..sun1.0...U....testing1.0
|
||||
..U....mullan
|
||||
X509v3 Subject Key Identifier:
|
||||
56:E8:88:AE:9D:B5:3F:2B:CB:A0:4C:4B:E2:87:53:07:33:77:1B:DF
|
||||
X509v3 Authority Key Identifier:
|
||||
keyid:8E:DD:AF:6F:EE:02:12:F4:61:E9:2F:E3:64:1A:6F:71:32:25:20:C0
|
||||
|
||||
X509v3 Subject Alternative Name:
|
||||
email:mullan@east.sun.com
|
||||
X509v3 Private Key Usage Period:
|
||||
Not Before: Jan 1 05:00:00 2000 GMT, Not After: Jan 1 05:00:00 2001 GMT
|
||||
X509v3 Key Usage: critical
|
||||
Digital Signature
|
||||
X509v3 Certificate Policies:
|
||||
0$0\..*...0.0...+.......0..
|
||||
Testing...
|
||||
Signature Algorithm: dsaWithSHA1
|
||||
r:
|
||||
44:c7:35:40:5d:6c:28:75:7f:73:b2:f8:0d:72:6c:
|
||||
09:65:b8:81:14
|
||||
s:
|
||||
76:79:f5:c7:37:3b:0d:9b:db:70:2f:20:80:36:e3:
|
||||
80:e8:a6:c6:71
|
||||
*/
|
||||
private static final String testCert =
|
||||
"-----BEGIN CERTIFICATE-----\n" +
|
||||
"MIICLjCCAeygAwIBAgIEON+CuDALBgcqhkjOOAQDBQAwLTELMAkGA1UEBhMCdXMx\n" +
|
||||
"DDAKBgNVBAoTA3N1bjEQMA4GA1UECxMHdGVzdGluZzAeFw0wMDAzMjcxNTQ4MDha\n" +
|
||||
"Fw0wMDA2MjUxNDQ4MDhaMD4xCzAJBgNVBAYTAnVzMQwwCgYDVQQKEwNzdW4xEDAO\n" +
|
||||
"BgNVBAsTB3Rlc3RpbmcxDzANBgNVBAMTBm11bGxhbjAcMBQGByqGSM44BAEwCQIB\n" +
|
||||
"AAIBAAIBAAMEAAIBAKOCASMwggEfMFAGA1UdHgEB/wRGMESgQjBApD4xCzAJBgNV\n" +
|
||||
"BAYTAnVzMQwwCgYDVQQKEwNzdW4xEDAOBgNVBAsTB3Rlc3RpbmcxDzANBgNVBAMT\n" +
|
||||
"Bm11bGxhbjAdBgNVHQ4EFgQUVuiIrp21PyvLoExL4odTBzN3G98wHwYDVR0jBBgw\n" +
|
||||
"FoAUjt2vb+4CEvRh6S/jZBpvcTIlIMAwHgYDVR0RBBcwFYETbXVsbGFuQGVhc3Qu\n" +
|
||||
"c3VuLmNvbTArBgNVHRAEJDAigA8yMDAwMDEwMTA1MDAwMFqBDzIwMDEwMTAxMDUw\n" +
|
||||
"MDAwWjAPBgNVHQ8BAf8EBQMDB4AAMC0GA1UdIAQmMCQwIgYEKoSAADAaMBgGCCsG\n" +
|
||||
"AQUFBwICMAwSClRlc3RpbmcuLi4wCwYHKoZIzjgEAwUAAy8AMCwCFETHNUBdbCh1\n" +
|
||||
"f3Oy+A1ybAlluIEUAhR2efXHNzsNm9twLyCANuOA6KbGcQ==\n" +
|
||||
"-----END CERTIFICATE-----\n" +
|
||||
"";
|
||||
|
||||
private static final String testKey =
|
||||
"MIIBtjCCASsGByqGSM44BAEwggEeAoGBAIVWPEkcxbxhQRCqVzg55tNqbP5j0K4kdu4bkmXvfqC5\n" +
|
||||
"+qA75DvnfzsOJseb+9AuKXWk/DvCzFDmrY1YaU3scZC3OQEO9lEO3F4VDKOaudY6OT1SI22pAIwz\n" +
|
||||
"j5pvq+i7zOp4xUqkQUeh/4iQSfxOT5UrFGjkcbnbpVkCXD/GxAz7AhUAjtnm3dVIddUUHl6wxpZ7\n" +
|
||||
"GcA6gSsCgYAf/PXzQtemgIDjpFrNNSgTEKkLposBXKatAM+gUKlMUjf8SQvquqPxDtRrscGjXkoL\n" +
|
||||
"oTkaR7/akULYFpBvUcFkeIFiCnJg8M9XhCWdLvn9MPt+jR2oxookvCb9xLtD6WvIM/wd/nZ1iK4u\n" +
|
||||
"iY1+q85xvns/Awbtwl7oZDAwE2TUKAOBhAACgYBDc9UZ+3xsZubUZvRG5cpyJceYpJp2exOPVJXn\n" +
|
||||
"jR4CcR+cT9bAJpFSxqE/8KtNHXxHdu4f3DU67IMOVDpugzihyzXJvNm3w2H9x+6xczHG2wjvAJeh\n" +
|
||||
"X62EWbUatxPXFAoVKZWuUbaYaZzdWBDtNRrCuKKsLo0GFy8g2BZISuD3jw==\n" +
|
||||
"";
|
||||
|
||||
// Certificate to run tests on
|
||||
private final X509Certificate cert;
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
X509CertSelectorTest test = new X509CertSelectorTest();
|
||||
test.doTest();
|
||||
}
|
||||
|
||||
public X509CertSelectorTest() throws CertificateException, IOException {
|
||||
cert = (X509Certificate) CertificateFactory.getInstance("X.509")
|
||||
.generateCertificate(new ByteArrayInputStream(testCert.getBytes()));
|
||||
}
|
||||
|
||||
// Runs the test.
|
||||
private void doTest() throws Exception {
|
||||
System.out.println("START OF TESTS FOR " + "X509CertSelector");
|
||||
|
||||
testSerialNumber();
|
||||
testIssuer();
|
||||
testSubjectKeyIdentifier();
|
||||
testAuthorityKeyIdentifier();
|
||||
testCertificateValid();
|
||||
testPrivateKeyValid();
|
||||
testSubjectPublicKeyAlgID();
|
||||
testKeyUsage();
|
||||
testSubjectAltName();
|
||||
testPolicy();
|
||||
testPathToName();
|
||||
testSubject();
|
||||
testSubjectPublicKey();
|
||||
testNameConstraints();
|
||||
testBasicConstraints();
|
||||
testCertificate();
|
||||
}
|
||||
|
||||
// Tests matching on the serial number contained in the certificate.
|
||||
private void testSerialNumber() {
|
||||
System.out.println("X.509 Certificate Match on serialNumber");
|
||||
// bad match
|
||||
X509CertSelector selector = new X509CertSelector();
|
||||
selector.setSerialNumber(new BigInteger("999999999"));
|
||||
checkMatch(selector, cert, false);
|
||||
|
||||
// good match
|
||||
selector.setSerialNumber(cert.getSerialNumber());
|
||||
checkMatch(selector, cert, true);
|
||||
|
||||
// check serial number format
|
||||
String serialNum = Debug.toString(selector.getSerialNumber());
|
||||
String expected = "38:df:82:b8";
|
||||
if (!serialNum.equals(expected)) {
|
||||
throw new RuntimeException("Serial number toString format is incorrect. Got: "
|
||||
+ serialNum + " Expected: " + expected);
|
||||
}
|
||||
}
|
||||
|
||||
// Tests matching on the issuer name contained in the certificate.
|
||||
private void testIssuer() throws IOException {
|
||||
System.out.println("X.509 Certificate Match on issuer");
|
||||
// bad match
|
||||
X509CertSelector selector = new X509CertSelector();
|
||||
selector.setIssuer("ou=bogus,ou=east,o=sun,c=us");
|
||||
checkMatch(selector, cert, false);
|
||||
|
||||
// good match
|
||||
selector.setIssuer((cert.getIssuerX500Principal()).getName("RFC2253"));
|
||||
checkMatch(selector, cert, true);
|
||||
}
|
||||
|
||||
/*
|
||||
* Tests matching on the subject key identifier contained in the
|
||||
* certificate.
|
||||
*/
|
||||
private void testSubjectKeyIdentifier() throws IOException {
|
||||
System.out.println("X.509 Certificate Match on subjectKeyIdentifier");
|
||||
// bad match
|
||||
X509CertSelector selector = new X509CertSelector();
|
||||
byte[] b = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
|
||||
selector.setSubjectKeyIdentifier(b);
|
||||
checkMatch(selector, cert, false);
|
||||
|
||||
// good match
|
||||
DerInputStream in = new DerInputStream(cert.getExtensionValue("2.5.29.14"));
|
||||
byte[] encoded = in.getOctetString();
|
||||
selector.setSubjectKeyIdentifier(encoded);
|
||||
checkMatch(selector, cert, true);
|
||||
}
|
||||
|
||||
/*
|
||||
* Tests matching on the authority key identifier contained in the
|
||||
* certificate.
|
||||
*/
|
||||
private void testAuthorityKeyIdentifier() throws IOException {
|
||||
System.out.println("X.509 Certificate Match on authorityKeyIdentifier");
|
||||
// bad match
|
||||
X509CertSelector selector = new X509CertSelector();
|
||||
byte[] b = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
|
||||
AuthorityKeyIdentifierExtension a = new AuthorityKeyIdentifierExtension(new KeyIdentifier(b), null, null);
|
||||
selector.setAuthorityKeyIdentifier(a.getExtensionValue());
|
||||
checkMatch(selector, cert, false);
|
||||
|
||||
// good match
|
||||
DerInputStream in = new DerInputStream(cert.getExtensionValue("2.5.29.35"));
|
||||
byte[] encoded = in.getOctetString();
|
||||
selector.setAuthorityKeyIdentifier(encoded);
|
||||
checkMatch(selector, cert, true);
|
||||
}
|
||||
|
||||
/*
|
||||
* Tests matching on the certificate validity component contained in the
|
||||
* certificate.
|
||||
*/
|
||||
private void testCertificateValid() {
|
||||
System.out.println("X.509 Certificate Match on certificateValid");
|
||||
// bad match
|
||||
X509CertSelector selector = new X509CertSelector();
|
||||
Calendar cal = Calendar.getInstance();
|
||||
cal.set(1968, 12, 31);
|
||||
selector.setCertificateValid(cal.getTime());
|
||||
checkMatch(selector, cert, false);
|
||||
|
||||
// good match
|
||||
selector.setCertificateValid(cert.getNotBefore());
|
||||
checkMatch(selector, cert, true);
|
||||
}
|
||||
|
||||
/*
|
||||
* Tests matching on the private key validity component contained in the
|
||||
* certificate.
|
||||
*/
|
||||
private void testPrivateKeyValid() throws IOException, CertificateException {
|
||||
System.out.println("X.509 Certificate Match on privateKeyValid");
|
||||
// bad match
|
||||
X509CertSelector selector = new X509CertSelector();
|
||||
Calendar cal = Calendar.getInstance();
|
||||
cal.set(1968, 12, 31);
|
||||
selector.setPrivateKeyValid(cal.getTime());
|
||||
checkMatch(selector, cert, false);
|
||||
|
||||
// good match
|
||||
DerInputStream in = new DerInputStream(cert.getExtensionValue("2.5.29.16"));
|
||||
byte[] encoded = in.getOctetString();
|
||||
PrivateKeyUsageExtension ext = new PrivateKeyUsageExtension(false, encoded);
|
||||
Date validDate = ext.getNotBefore();
|
||||
selector.setPrivateKeyValid(validDate);
|
||||
checkMatch(selector, cert, true);
|
||||
|
||||
}
|
||||
|
||||
private ObjectIdentifier getCertPubKeyAlgOID(X509Certificate xcert) throws IOException {
|
||||
byte[] encodedKey = xcert.getPublicKey().getEncoded();
|
||||
DerValue val = new DerValue(encodedKey);
|
||||
if (val.tag != DerValue.tag_Sequence) {
|
||||
throw new RuntimeException("invalid key format");
|
||||
}
|
||||
|
||||
return AlgorithmId.parse(val.data.getDerValue()).getOID();
|
||||
}
|
||||
|
||||
/*
|
||||
* Tests matching on the subject public key algorithm ID component contained
|
||||
* in the certificate.
|
||||
*/
|
||||
private void testSubjectPublicKeyAlgID() throws IOException {
|
||||
System.out.println("X.509 Certificate Match on subjectPublicKeyAlgID");
|
||||
// bad match
|
||||
X509CertSelector selector = new X509CertSelector();
|
||||
selector.setSubjectPublicKeyAlgID("2.5.29.14");
|
||||
checkMatch(selector, cert, false);
|
||||
|
||||
// good match
|
||||
selector.setSubjectPublicKeyAlgID(getCertPubKeyAlgOID(cert).toString());
|
||||
checkMatch(selector, cert, true);
|
||||
|
||||
}
|
||||
|
||||
// Tests matching on the key usage extension contained in the certificate.
|
||||
private void testKeyUsage() {
|
||||
System.out.println("X.509 Certificate Match on keyUsage");
|
||||
// bad match
|
||||
X509CertSelector selector = new X509CertSelector();
|
||||
boolean[] keyUsage = { true, false, true, false, true, false, true, false };
|
||||
selector.setKeyUsage(keyUsage);
|
||||
System.out.println("Selector = " + selector.toString());
|
||||
checkMatch(selector, cert, false);
|
||||
|
||||
// good match
|
||||
selector.setKeyUsage(cert.getKeyUsage());
|
||||
System.out.println("Selector = " + selector.toString());
|
||||
checkMatch(selector, cert, true);
|
||||
}
|
||||
|
||||
/*
|
||||
* Tests matching on the subject alternative name extension contained in the
|
||||
* certificate.
|
||||
*/
|
||||
private void testSubjectAltName() throws IOException {
|
||||
System.out.println("X.509 Certificate Match on subjectAltName");
|
||||
// bad match
|
||||
X509CertSelector selector = new X509CertSelector();
|
||||
GeneralNameInterface dnsName = new DNSName("foo.com");
|
||||
DerOutputStream tmp = new DerOutputStream();
|
||||
dnsName.encode(tmp);
|
||||
selector.addSubjectAlternativeName(2, tmp.toByteArray());
|
||||
checkMatch(selector, cert, false);
|
||||
|
||||
// good match
|
||||
DerInputStream in = new DerInputStream(cert.getExtensionValue("2.5.29.17"));
|
||||
byte[] encoded = in.getOctetString();
|
||||
SubjectAlternativeNameExtension ext = new SubjectAlternativeNameExtension(false, encoded);
|
||||
GeneralNames names = ext.getNames();
|
||||
GeneralName name = names.get(0);
|
||||
selector.setSubjectAlternativeNames(null);
|
||||
DerOutputStream tmp2 = new DerOutputStream();
|
||||
name.getName().encode(tmp2);
|
||||
selector.addSubjectAlternativeName(name.getType(), tmp2.toByteArray());
|
||||
checkMatch(selector, cert, true);
|
||||
|
||||
// good match 2 (matches at least one)
|
||||
selector.setMatchAllSubjectAltNames(false);
|
||||
selector.addSubjectAlternativeName(2, "foo.com");
|
||||
checkMatch(selector, cert, true);
|
||||
}
|
||||
|
||||
/*
|
||||
* Tests matching on the policy constraints extension contained in the
|
||||
* certificate.
|
||||
*/
|
||||
private void testPolicy() throws IOException {
|
||||
System.out.println("X.509 Certificate Match on certificatePolicies");
|
||||
// test encoding of CertificatePoliciesExtension because we wrote the
|
||||
// code
|
||||
// bad match
|
||||
X509CertSelector selector = new X509CertSelector();
|
||||
Set<String> s = new HashSet<>();
|
||||
s.add(new String("1.2.5.7.68"));
|
||||
selector.setPolicy(s);
|
||||
checkMatch(selector, cert, false);
|
||||
|
||||
// good match
|
||||
DerInputStream in = new DerInputStream(cert.getExtensionValue("2.5.29.32"));
|
||||
CertificatePoliciesExtension ext = new CertificatePoliciesExtension(false, in.getOctetString());
|
||||
List<PolicyInformation> policies = ext.getCertPolicies();
|
||||
// match on the first policy id
|
||||
PolicyInformation policyInfo = (PolicyInformation) policies.get(0);
|
||||
s.clear();
|
||||
s.add(policyInfo.getPolicyIdentifier().getIdentifier().toString());
|
||||
selector.setPolicy(s);
|
||||
checkMatch(selector, cert, true);
|
||||
}
|
||||
|
||||
/*
|
||||
* Tests matching on the name constraints extension contained in the
|
||||
* certificate.
|
||||
*/
|
||||
private void testPathToName() throws IOException {
|
||||
System.out.println("X.509 Certificate Match on pathToName");
|
||||
|
||||
X509CertSelector selector = null;
|
||||
DerInputStream in = new DerInputStream(cert.getExtensionValue("2.5.29.30"));
|
||||
byte[] encoded = in.getOctetString();
|
||||
NameConstraintsExtension ext = new NameConstraintsExtension(false, encoded);
|
||||
GeneralSubtrees permitted = ext.getPermittedSubtrees();
|
||||
GeneralSubtrees excluded = ext.getExcludedSubtrees();
|
||||
|
||||
// bad matches on pathToName within excluded subtrees
|
||||
if (excluded != null) {
|
||||
Iterator<GeneralSubtree> e = excluded.iterator();
|
||||
while (e.hasNext()) {
|
||||
GeneralSubtree tree = e.next();
|
||||
if (tree.getName().getType() == NAME_DIRECTORY) {
|
||||
X500Name excludedDN1 = new X500Name(tree.getName().toString());
|
||||
X500Name excludedDN2 = new X500Name("CN=Bogus, " + tree.getName().toString());
|
||||
DerOutputStream derDN1 = new DerOutputStream();
|
||||
DerOutputStream derDN2 = new DerOutputStream();
|
||||
excludedDN1.encode(derDN1);
|
||||
excludedDN2.encode(derDN2);
|
||||
selector = new X509CertSelector();
|
||||
selector.addPathToName(NAME_DIRECTORY, derDN1.toByteArray());
|
||||
checkMatch(selector, cert, false);
|
||||
selector.setPathToNames(null);
|
||||
selector.addPathToName(NAME_DIRECTORY, derDN2.toByteArray());
|
||||
checkMatch(selector, cert, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// good matches on pathToName within permitted subtrees
|
||||
if (permitted != null) {
|
||||
Iterator<GeneralSubtree> e = permitted.iterator();
|
||||
while (e.hasNext()) {
|
||||
GeneralSubtree tree = e.next();
|
||||
if (tree.getName().getType() == NAME_DIRECTORY) {
|
||||
X500Name permittedDN1 = new X500Name(tree.getName().toString());
|
||||
X500Name permittedDN2 = new X500Name("CN=good, " + tree.getName().toString());
|
||||
DerOutputStream derDN1 = new DerOutputStream();
|
||||
DerOutputStream derDN2 = new DerOutputStream();
|
||||
permittedDN1.encode(derDN1);
|
||||
permittedDN2.encode(derDN2);
|
||||
selector = new X509CertSelector();
|
||||
selector.addPathToName(NAME_DIRECTORY, derDN1.toByteArray());
|
||||
checkMatch(selector, cert, true);
|
||||
selector.setPathToNames(null);
|
||||
selector.addPathToName(NAME_DIRECTORY, derDN2.toByteArray());
|
||||
checkMatch(selector, cert, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Tests matching on the subject name contained in the certificate.
|
||||
private void testSubject() throws IOException {
|
||||
System.out.println("X.509 Certificate Match on subject");
|
||||
// bad match
|
||||
X509CertSelector selector = new X509CertSelector();
|
||||
selector.setSubject("ou=bogus,ou=east,o=sun,c=us");
|
||||
checkMatch(selector, cert, false);
|
||||
|
||||
// good match
|
||||
selector.setSubject(cert.getSubjectX500Principal().getName("RFC2253"));
|
||||
checkMatch(selector, cert, true);
|
||||
}
|
||||
|
||||
// Tests matching on the subject public key contained in the certificate.
|
||||
private void testSubjectPublicKey() throws IOException, GeneralSecurityException {
|
||||
System.out.println("X.509 Certificate Match on subject public key");
|
||||
// bad match
|
||||
X509CertSelector selector = new X509CertSelector();
|
||||
X509EncodedKeySpec keySpec = new X509EncodedKeySpec(
|
||||
Base64.getMimeDecoder().decode(testKey.getBytes()));
|
||||
KeyFactory keyFactory = KeyFactory.getInstance("DSA");
|
||||
PublicKey pubKey = keyFactory.generatePublic(keySpec);
|
||||
selector.setSubjectPublicKey(pubKey);
|
||||
checkMatch(selector, cert, false);
|
||||
|
||||
// good match
|
||||
selector.setSubjectPublicKey(cert.getPublicKey());
|
||||
checkMatch(selector, cert, true);
|
||||
}
|
||||
|
||||
// Tests matching on the name constraints contained in the certificate.
|
||||
private void testNameConstraints() throws IOException {
|
||||
System.out.println("X.509 Certificate Match on name constraints");
|
||||
// bad match
|
||||
GeneralSubtrees subjectTree = new GeneralSubtrees();
|
||||
subjectTree.add(getGeneralSubtree((X500Name) cert.getSubjectDN()));
|
||||
NameConstraintsExtension ext = new NameConstraintsExtension((GeneralSubtrees) null, subjectTree);
|
||||
X509CertSelector selector = new X509CertSelector();
|
||||
selector.setNameConstraints(ext.getExtensionValue());
|
||||
checkMatch(selector, cert, false);
|
||||
|
||||
// good match
|
||||
ext = new NameConstraintsExtension(subjectTree, null);
|
||||
selector.setNameConstraints(ext.getExtensionValue());
|
||||
checkMatch(selector, cert, true);
|
||||
}
|
||||
|
||||
// Tests matching on basic constraints.
|
||||
private void testBasicConstraints() {
|
||||
System.out.println("X.509 Certificate Match on basic constraints");
|
||||
// bad match
|
||||
X509CertSelector selector = new X509CertSelector();
|
||||
int mpl = cert.getBasicConstraints();
|
||||
selector.setBasicConstraints(0);
|
||||
checkMatch(selector, cert, false);
|
||||
|
||||
// good match
|
||||
selector.setBasicConstraints(mpl);
|
||||
checkMatch(selector, cert, true);
|
||||
}
|
||||
|
||||
// Tests certificateEquals criterion
|
||||
private void testCertificate() {
|
||||
System.out.println("X.509 Certificate Match on certificateEquals criterion");
|
||||
|
||||
X509CertSelector selector = new X509CertSelector();
|
||||
// good match
|
||||
selector.setCertificate(cert);
|
||||
checkMatch(selector, cert, true);
|
||||
}
|
||||
|
||||
private void checkMatch(X509CertSelector selector, X509Certificate cert, boolean match) {
|
||||
boolean result = selector.match(cert);
|
||||
if (match != result)
|
||||
throw new RuntimeException(selector + " match " + cert + " is " + result + ", but expect " + match);
|
||||
}
|
||||
|
||||
private static GeneralSubtree getGeneralSubtree(GeneralNameInterface gni) {
|
||||
// Create a new GeneralSubtree with the specified name, 0 base, and
|
||||
// unlimited length
|
||||
GeneralName gn = new GeneralName(gni);
|
||||
GeneralSubtree subTree = new GeneralSubtree(gn, 0, -1);
|
||||
return subTree;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,69 @@
|
|||
/*
|
||||
* Copyright (c) 2001, 2002, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @test 1.2, 01/06/27
|
||||
* @bug 4474914
|
||||
*
|
||||
* @summary getSubjectDN and getSubjectX500Principal are underspecified
|
||||
* if subject is empty
|
||||
*/
|
||||
import java.io.*;
|
||||
import java.security.Principal;
|
||||
import java.security.cert.*;
|
||||
import javax.security.auth.x500.X500Principal;
|
||||
|
||||
public class EmptySubject {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
|
||||
try {
|
||||
File f = new File(System.getProperty("test.src", "."),
|
||||
"emptySubjectCert");
|
||||
CertificateFactory cf = CertificateFactory.getInstance("X.509");
|
||||
|
||||
try {
|
||||
X509Certificate cert = (X509Certificate)
|
||||
cf.generateCertificate(new FileInputStream(f));
|
||||
throw new Exception("Test 1 Failed - parsed invalid cert");
|
||||
} catch (CertificateParsingException e) {
|
||||
System.out.println("Test 1 passed: " + e.toString());
|
||||
}
|
||||
|
||||
f = new File(System.getProperty("test.src", "."),
|
||||
"emptyIssuerCert");
|
||||
|
||||
try {
|
||||
X509Certificate cert2 = (X509Certificate)
|
||||
cf.generateCertificate(new FileInputStream(f));
|
||||
throw new Exception("Test 2 Failed - parsed invalid cert");
|
||||
} catch (CertificateParsingException e) {
|
||||
System.out.println("Test 2 passed: " + e.toString());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
SecurityException se = new SecurityException("Test Failed");
|
||||
se.initCause(e);
|
||||
throw se;
|
||||
}
|
||||
}
|
||||
}
|
||||
59
test/jdk/java/security/cert/X509Certificate/ExtKeyUsage.java
Normal file
59
test/jdk/java/security/cert/X509Certificate/ExtKeyUsage.java
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
/*
|
||||
* Copyright (c) 2001, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @bug 4427888
|
||||
* @summary Incorrect key usage check for server certificates
|
||||
*/
|
||||
import java.io.*;
|
||||
import java.security.cert.*;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
public class ExtKeyUsage {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
File f = new File(System.getProperty("test.src", "."),
|
||||
"certextkeyusage");
|
||||
CertificateFactory cf = CertificateFactory.getInstance("X.509");
|
||||
X509Certificate cert = (X509Certificate)
|
||||
cf.generateCertificate(new FileInputStream(f));
|
||||
List extKeyUsage = cert.getExtendedKeyUsage();
|
||||
if (extKeyUsage.size() != 1)
|
||||
throw new Exception("getExtendedKeyUsage()) returned an " +
|
||||
"unexpected number of entries: "+extKeyUsage.size());
|
||||
|
||||
// Test immutability
|
||||
try {
|
||||
extKeyUsage.clear();
|
||||
throw new Exception("List returned by " +
|
||||
"getExtendedKeyUsage() is not immutable");
|
||||
} catch (UnsupportedOperationException e) {}
|
||||
|
||||
if (!extKeyUsage.contains("1.3.6.1.5.5.7.3.1")) {
|
||||
throw new Exception("List returned by "+
|
||||
"getExtendedKeyUsage() doesn't contain expected entry");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,49 @@
|
|||
/*
|
||||
* Copyright (c) 2021, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 8259428
|
||||
* @library /test/lib
|
||||
* @summary Verify X509Certificate.getSigAlgParams() returns new array each
|
||||
* time it is called
|
||||
* @modules java.base/sun.security.tools.keytool java.base/sun.security.x509
|
||||
*/
|
||||
|
||||
import java.security.cert.X509Certificate;
|
||||
import jdk.test.lib.security.SecurityUtils;
|
||||
import sun.security.tools.keytool.CertAndKeyGen;
|
||||
import sun.security.x509.X500Name;
|
||||
|
||||
public class GetSigAlgParams {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
|
||||
CertAndKeyGen cakg = new CertAndKeyGen("RSASSA-PSS", "RSASSA-PSS");
|
||||
cakg.generate(SecurityUtils.getTestKeySize("RSA"));
|
||||
X509Certificate c = cakg.getSelfCertificate(new X500Name("CN=Me"), 100);
|
||||
if (c.getSigAlgParams() == c.getSigAlgParams()) {
|
||||
throw new Exception("Encoded params are the same byte array");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,86 @@
|
|||
/*
|
||||
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
import java.security.cert.CertificateParsingException;
|
||||
import java.security.cert.X509Certificate;
|
||||
import jdk.test.lib.security.CertUtils;
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 8251468
|
||||
* @library /test/lib
|
||||
* @summary Check that X509Certificate.getSubjectAlternativeNames,
|
||||
* getIssuerAlternativeNames and getExtendedKeyUsage throw
|
||||
* CertificateParsingException if extension is unparseable/invalid.
|
||||
*/
|
||||
public class GetUnparseableExtensions {
|
||||
|
||||
// Cert has 3 badly encoded extensions:
|
||||
// 1. SubjectAlternativeNameExtension with a null RFC822Name
|
||||
// 2. IssuerAlternativeNameExtension with a null RFC822Name
|
||||
// 3. ExtendedKeyUsageExtension encoded as a Set instead of a Sequence
|
||||
private final static String CERT_WITH_UNPARSEABLE_EXTS = """
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIIDDTCCAfWgAwIBAgIIc/2fukmBqZgwDQYJKoZIhvcNAQELBQAwDTELMAkGA1UE
|
||||
AxMCQ0EwHhcNMjExMDI2MTgxNzU4WhcNMjIwMTI0MTgxNzU4WjANMQswCQYDVQQD
|
||||
EwJFMTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAKIIIsP6ghZ94hIl
|
||||
U3G+D11vASSP7JMmX6G6opGKel60dZ5So3Tdj0E6VHehwcxEdh94LEIxvOkS3Cdh
|
||||
hd1iiB4/q2InvLuGzSVvWAwYNkB7GbR31pIst0GAFdH+z/tVjjHcacBGwmysk8DN
|
||||
Rmxm66AyJxHA1U/v64vx5kSGNoUAEcWm+OslxfdJ7nygnU+S6a/06sRvifVn7q7c
|
||||
Kg4AIFE1+vWrcgYbApkPNjLiRGAr33TAb1y+nN1zW/luEMEQIJBd+YJW9OrPGMUr
|
||||
SDSXfB06HscH1bTUfN2ngsxT2hy9eiCiDtagPIwYA0sVNjyUtfPsjAH1oxDPXzC5
|
||||
quJB5/sCAwEAAaNxMG8wHQYDVR0OBBYEFCqWMQBki21cSqKIHp4rFitf6pQ2MAsG
|
||||
A1UdEQQEMAKBADALBgNVHRIEBDACgQAwHwYDVR0jBBgwFoAUJbvRN17hEohYsg1M
|
||||
icq1mMpIwoAwEwYDVR0lBAwxCgYIKwYBBQUHAwEwDQYJKoZIhvcNAQELBQADggEB
|
||||
ABBqJ/yYXD1xueB63GRY4ZotO6ukEkJiPZIwrr2vZW+GMws2b9gqNoD+dL9AeYCA
|
||||
Zb6RYbaNDY5OoJmEty9KbtON7Rt1LtCFuZbYKxrhW0dJgXLyNOgXr+x0g2btbvWV
|
||||
r8U1icwHapZM5IqDKLivzZNzwv52mrJDuzWqmlhAIlPLIU1QfNQ1oC8HpFkL71Bb
|
||||
sB/4OIxxjRzf0AGmb7aeQNfxag2oKlOwqzum1FLt8BaVjylc0aUATPtkgothK8nK
|
||||
m5jXJmA4zA11ck0uJW39gDRuR0D1k4qm/s/5Iuhd6MRVDXEhVbJXuH2yzHcmbgRs
|
||||
paD/he6C1JszWf7YrTsX3Fc=
|
||||
-----END CERTIFICATE-----
|
||||
""";
|
||||
|
||||
@FunctionalInterface
|
||||
public interface TestCase<T> {
|
||||
T test() throws Exception;
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
|
||||
X509Certificate cert =
|
||||
CertUtils.getCertFromString(CERT_WITH_UNPARSEABLE_EXTS);
|
||||
getExtension(() -> cert.getSubjectAlternativeNames());
|
||||
getExtension(() -> cert.getIssuerAlternativeNames());
|
||||
getExtension(() -> cert.getExtendedKeyUsage());
|
||||
}
|
||||
|
||||
private static void getExtension(TestCase<?> t) throws Exception {
|
||||
try {
|
||||
t.test();
|
||||
throw new Exception("Test FAILED");
|
||||
} catch (CertificateParsingException cpe) {
|
||||
System.out.println(cpe.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
140
test/jdk/java/security/cert/X509Certificate/VerifyDefault.java
Normal file
140
test/jdk/java/security/cert/X509Certificate/VerifyDefault.java
Normal file
|
|
@ -0,0 +1,140 @@
|
|||
/*
|
||||
* Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @bug 8175029
|
||||
* @library /test/lib
|
||||
* @summary check that default implementation of
|
||||
* X509Certificate.verify(PublicKey, Provider) works on custom
|
||||
* X509Certificate impl.
|
||||
*/
|
||||
|
||||
import java.math.BigInteger;
|
||||
import java.security.InvalidKeyException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.NoSuchProviderException;
|
||||
import java.security.Principal;
|
||||
import java.security.Provider;
|
||||
import java.security.PublicKey;
|
||||
import java.security.SignatureException;
|
||||
import java.security.cert.CertificateEncodingException;
|
||||
import java.security.cert.CertificateException;
|
||||
import java.security.cert.CertificateExpiredException;
|
||||
import java.security.cert.CertificateNotYetValidException;
|
||||
import java.security.cert.X509Certificate;
|
||||
import java.util.Collection;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import jdk.test.lib.security.CertUtils;
|
||||
|
||||
public class VerifyDefault {
|
||||
private static final String TEST_CERT =
|
||||
"-----BEGIN CERTIFICATE-----\n" +
|
||||
"MIICvTCCAaWgAwIBAgIEGYqL9TANBgkqhkiG9w0BAQsFADAPMQ0wCwYDVQQDEwRT\n" +
|
||||
"ZWxmMB4XDTE3MDMyODE2NDcyNloXDTE3MDYyNjE2NDcyNlowDzENMAsGA1UEAxME\n" +
|
||||
"U2VsZjCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAL1pfSJljFVSABOL\n" +
|
||||
"tJbIVPEkz1+2AFgzY1hqwE0EH80lvhOEkiPPYCKwBE5VTZdyFfwFjpyx7eEeJMNT\n" +
|
||||
"o7cixfmkQaiXHr/S1AS4BRTqLG/zgLzoJpVbzi45rnVEZc0oTm11KG3uUxkZTRr3\n" +
|
||||
"5ORbYyZpkscKwHL2M0J/1GmnA1hmhQdwUQyIKxg4eKQwyE+/TdbFlCWVNnOlb+91\n" +
|
||||
"eXvS11nIJ1oaBgn7u4qihuVmFmngLMxExnLYKV6AwdkwFD6pERObclRD9vAl5eUk\n" +
|
||||
"+sM6zQYwfLdyC2i8e+ETBeOg1ijptM4KT5Uaq89zxjLR0DPH4S+aILp3gYHGrW5r\n" +
|
||||
"eMxZAEMCAwEAAaMhMB8wHQYDVR0OBBYEFOME39JtbjzQaK3ufpKo/Pl4sZ8XMA0G\n" +
|
||||
"CSqGSIb3DQEBCwUAA4IBAQCDcw0+Sf0yeVROVlb2/VV3oIblHkGQheXeIurW64k7\n" +
|
||||
"tEzHtx9i8dnj5lzTZNH6hU4GRlyULbSDzjcM3P2XFRsM+0a/kEJZVqnLz5ji//7/\n" +
|
||||
"ZXaRX0TiE2IfFOTGbO6LusO3yR4tOER/WHllz2H21C2SbW3+92Ou28glTZa42AAZ\n" +
|
||||
"mUj9j+p6mZqD4/tUBqAEqqQoMIhw9CNjc46STNayBjt/0/+I2pfy6LagrMbjBzZ0\n" +
|
||||
"A5kXg9WjnywGk8XFr/3RZz8DrUmCYs2qCYLCHQHsuCE6gCuf9wKhKyD51MFXXRr0\n" +
|
||||
"cyG6LYQjrreMHYk4ZfN2NPC6lGjWxB5mIbV/DuikCnYu\n" +
|
||||
"-----END CERTIFICATE-----";
|
||||
|
||||
private static class TestX509Certificate extends X509Certificate {
|
||||
private final X509Certificate cert;
|
||||
TestX509Certificate(X509Certificate cert) {
|
||||
this.cert = cert;
|
||||
}
|
||||
public Set<String> getCriticalExtensionOIDs() {
|
||||
return cert.getCriticalExtensionOIDs();
|
||||
}
|
||||
public byte[] getExtensionValue(String oid) {
|
||||
return cert.getExtensionValue(oid);
|
||||
}
|
||||
public Set<String> getNonCriticalExtensionOIDs() {
|
||||
return cert.getNonCriticalExtensionOIDs();
|
||||
}
|
||||
public boolean hasUnsupportedCriticalExtension() {
|
||||
return cert.hasUnsupportedCriticalExtension();
|
||||
}
|
||||
public void checkValidity() throws CertificateExpiredException,
|
||||
CertificateNotYetValidException {
|
||||
cert.checkValidity();
|
||||
}
|
||||
public void checkValidity(Date date) throws CertificateExpiredException,
|
||||
CertificateNotYetValidException {
|
||||
cert.checkValidity(date);
|
||||
}
|
||||
public int getVersion() { return cert.getVersion(); }
|
||||
public BigInteger getSerialNumber() { return cert.getSerialNumber(); }
|
||||
public Principal getIssuerDN() { return cert.getIssuerDN(); }
|
||||
public Principal getSubjectDN() { return cert.getSubjectDN(); }
|
||||
public Date getNotBefore() { return cert.getNotBefore(); }
|
||||
public Date getNotAfter() { return cert.getNotAfter(); }
|
||||
public byte[] getTBSCertificate() throws CertificateEncodingException {
|
||||
return cert.getTBSCertificate();
|
||||
}
|
||||
public byte[] getSignature() { return cert.getSignature(); }
|
||||
public String getSigAlgName() { return cert.getSigAlgName(); }
|
||||
public String getSigAlgOID() { return cert.getSigAlgOID(); }
|
||||
public byte[] getSigAlgParams() { return cert.getSigAlgParams(); }
|
||||
public boolean[] getIssuerUniqueID() {
|
||||
return cert.getIssuerUniqueID();
|
||||
}
|
||||
public boolean[] getSubjectUniqueID() {
|
||||
return cert.getSubjectUniqueID();
|
||||
}
|
||||
public boolean[] getKeyUsage() { return cert.getKeyUsage(); }
|
||||
public int getBasicConstraints() { return cert.getBasicConstraints(); }
|
||||
public byte[] getEncoded() throws CertificateEncodingException {
|
||||
return cert.getEncoded();
|
||||
}
|
||||
public void verify(PublicKey key) throws CertificateException,
|
||||
InvalidKeyException, NoSuchAlgorithmException,
|
||||
NoSuchProviderException, SignatureException {
|
||||
cert.verify(key);
|
||||
}
|
||||
public void verify(PublicKey key, String sigProvider) throws
|
||||
CertificateException, InvalidKeyException, NoSuchAlgorithmException,
|
||||
NoSuchProviderException, SignatureException {
|
||||
cert.verify(key, sigProvider);
|
||||
}
|
||||
public PublicKey getPublicKey() { return cert.getPublicKey(); }
|
||||
public String toString() { return cert.toString(); }
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
X509Certificate cert = CertUtils.getCertFromString(TEST_CERT);
|
||||
new TestX509Certificate(cert).verify(cert.getPublicKey(),
|
||||
(Provider)null);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,64 @@
|
|||
/*
|
||||
* Copyright (c) 2001, 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @bug 8028431 8028591
|
||||
* @summary Make sure that proper CertificateException is thrown
|
||||
* when loading bad x509 certificate
|
||||
* @author Artem Smotrakov
|
||||
*/
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.security.cert.CertificateFactory;
|
||||
import java.security.cert.X509Certificate;
|
||||
import java.security.cert.CertificateException;
|
||||
|
||||
public class X509BadCertificate {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
test("bad-cert-1.pem");
|
||||
test("bad-cert-2.pem");
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse X509 certificates.
|
||||
*/
|
||||
static void test(String filename) throws Exception {
|
||||
try {
|
||||
System.out.println("Parse file " + filename);
|
||||
File f = new File(System.getProperty("test.src", "."), filename);
|
||||
try (FileInputStream fis = new FileInputStream(f)) {
|
||||
CertificateFactory cf = CertificateFactory.getInstance("X509");
|
||||
X509Certificate cert = (X509Certificate)
|
||||
cf.generateCertificate(fis);
|
||||
}
|
||||
throw new Exception("Test failed: " +
|
||||
"expected CertificateParsingException was not thrown");
|
||||
} catch (CertificateException e) {
|
||||
System.out.println("Test passed: expected exception was thrown: " +
|
||||
e.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
21
test/jdk/java/security/cert/X509Certificate/bad-cert-1.pem
Normal file
21
test/jdk/java/security/cert/X509Certificate/bad-cert-1.pem
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
-----BEGIN CERTIFICATE-----
|
||||
MIIDZzCCAk+gAwIBAgIJAJYB3qu9C2kiMA0GCSqGSIb3DQEBBQUAMEoxDTALBgNV
|
||||
BAMMBFRlc3QxDTALBgNVBAsMBEphdmExDzANBgNVBAoMBk9yYWNsZTEMMAoGA1UE
|
||||
BwwDU1BCMQswCQYDVQQGEwJSVTAeFw0xMzEyMjMwNzA4MDhaFw0yMzEyMjEwNzA4
|
||||
MDhaMEoxDTALBgNVBAMMBFRlc3QxDTALBgNVBAsMBEphdmExDzANBgNVBAoMBk9y
|
||||
YWNsZTEMMAoGA1UMBwwDU1BCMQswCQYDVQQGEwJSVTCCASIwDQYJKoZIhvcNAQEB
|
||||
BQADggEPADCCAQoCggEBAOqiCN4gFxehl547Q7/VNGbGApr+wszLdanHPucAH6Wf
|
||||
LtcRhKNUSqtBAQxEpFrTpMNEqm2GElAjiPa6m48qIjLVSvOb/9w3G/yXB8zyZbIm
|
||||
/Nfp2sT4OEaa1JSEZSpolhS4FfqYzjGQp5cn4Xn4zKjDgiceHgfLls5x2dRydQZO
|
||||
Yf91qSIioZxVHUtlo8yztkieiSaqPWt3nJ4PIwhFbsu1HVmWaYZD+nBYCKgVHqrS
|
||||
cueO98Ca4Doz73O27X1dVbQBdLS0JI7qVAG8LD388iPL8qbsOkgWPzmEQ+kLRKO4
|
||||
g7RpuwlXuwaMSh95NWaxlu4Ob6GRJQmpconYoe13+7ECAwEAAaNQME4wHQYDVR0O
|
||||
BBYEFIG8TPobXcbNbDi+zKudd9whpxoNMB8GA1UdIwQYMBaAFIG8TPobXcbNbDi+
|
||||
zKudd9whpxoNMAwGA1UdEwQFMAMBAf8wDQYJKoZIhvcNAQEFRQADggEBAAynN+e7
|
||||
h+ufT5SBKN/gBuJAnF1mKIPESiipuv5KoYUGZOY8ShgYLcwY+qnbuHYFUlvq6Zns
|
||||
K4/e+x/16h32vD7dEPkNvukbvER4YJQQiN6osDfXpTPzixYftWdmtX0u8xQfwb/g
|
||||
R8DS7bazz99jVXk+jTK4yWBY+gMwEat+LyNQ5cyq8Qhi1oBKUbGRbiOts19B97fn
|
||||
Rv8TsyXN3INLGYhdVxZoD7E5tyG1ydSFmOMadulAC2epBXDHOXZnz2UWauJc0XW5
|
||||
1L/YQVri47VkdHS3tisBzELEJdLmdMDb+5tAU+lItXmTXe2/PB53WIvsEIb4t+eQ
|
||||
wY0hCj9lVJlajTQ=
|
||||
-----END CERTIFICATE-----
|
||||
21
test/jdk/java/security/cert/X509Certificate/bad-cert-2.pem
Normal file
21
test/jdk/java/security/cert/X509Certificate/bad-cert-2.pem
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
-----BEGIN CERTIFICATE-----
|
||||
MIIDZzCCAk+gAwIBAgIJAJYB3qu9C2kiMA0GCSqGSIb3DQEBBQUAMEoxDTALBgNV
|
||||
BAMMBFRlc3QxDTALBgNVBAsMBEphdmExDzANBgNVBAoMBk9yYWNsZTEMMAoGA1UE
|
||||
BwwDU1BCMQswCQYDVQQGEwJSVTAeFw0xMzEyMjMwNzA4MDhaFw0yMzEyMjEwNzA4
|
||||
MDhaMEoxDTALBgNVBAMMBFRlc3QxDTALBgNVBAsMBEphdmExDzANBgNVBAoMBk9y
|
||||
YWNsZTEMMAoGA1UEBwwDU1BCMQswCQYDVQQGEwJSVTCCASIwDQYJKoZIhvcNAQEB
|
||||
BQADgGEPADCCAQoCggEBAOqiCN4gFxehl547Q7/VNGbGApr+wszLdanHPucAH6Wf
|
||||
LtcRhKNUSqtBAQxEpFrTpMNEqm2GElAjiPa6m48qIjLVSvOb/9w3G/yXB8zyZbIm
|
||||
/Nfp2sT4OEaa1JSEZSpolhS4FfqYzjGQp5cn4Xn4zKjDgiceHgfLls5x2dRydQZO
|
||||
Yf91qSIioZxVHUtlo8yztkieiSaqPWt3nJ4PIwhFbsu1HVmWaYZD+nBYCKgVHqrS
|
||||
cueO98Ca4Doz73O27X1dVbQBdLS0JI7qVAG8LD388iPL8qbsOkgWPzmEQ+kLRKO4
|
||||
g7RpuwlXuwaMSh95NWaxlu4Ob6GRJQmpconYoe13+7ECAwEAAaNQME4wHQYDVR0O
|
||||
BBYEFIG8TPobXcbNbDi+zKudd9whpxoNMB8GA1UdIwQYMBaAFIG8TPobXcbNbDi+
|
||||
zKudd9whpxoNMAwGA1UdEwQFMAMBAf8wDQYJKoZIhvcNAQEFBQADggEBAAynN+e7
|
||||
h+ufT5SBKN/gBuJAnF1mKIPESiipuv5KoYUGZOY8ShgYLcwY+qnbuHYFUlvq6Zns
|
||||
K4/e+x/16h32vD7dEPkNvukbvER4YJQQiN6osDfXpTPzixYftWdmtX0u8xQfwb/g
|
||||
R8DS7bazz99jVXk+jTK4yWBY+gMwEat+LyNQ5cyq8Qhi1oBKUbGRbiOts19B97fn
|
||||
Rv8TsyXN3INLGYhdVxZoD7E5tyG1ydSFmOMadulAC2epBXDHOXZnz2UWauJc0XW5
|
||||
1L/YQVri47VkdHS3tisBzELEJdLmdMDb+5tAU+lItXmTXe2/PB53WIvsEIb4t+eQ
|
||||
wY0hCj9lVJlajTQ=
|
||||
-----END CERTIFICATE-----
|
||||
BIN
test/jdk/java/security/cert/X509Certificate/certextkeyusage
Normal file
BIN
test/jdk/java/security/cert/X509Certificate/certextkeyusage
Normal file
Binary file not shown.
BIN
test/jdk/java/security/cert/X509Certificate/emptyIssuerCert
Normal file
BIN
test/jdk/java/security/cert/X509Certificate/emptyIssuerCert
Normal file
Binary file not shown.
BIN
test/jdk/java/security/cert/X509Certificate/emptySubjectCert
Normal file
BIN
test/jdk/java/security/cert/X509Certificate/emptySubjectCert
Normal file
Binary file not shown.
|
|
@ -0,0 +1,137 @@
|
|||
/*
|
||||
* Copyright (c) 2001, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @bug 4458778
|
||||
* @summary verify name constraints check for min and max fields
|
||||
*/
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.InputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import java.security.cert.CertificateFactory;
|
||||
import java.security.cert.CertPath;
|
||||
import java.security.cert.CertPathValidator;
|
||||
import java.security.cert.CertPathValidatorException;
|
||||
import java.security.cert.CertPathValidatorResult;
|
||||
import java.security.cert.PKIXParameters;
|
||||
import java.security.cert.TrustAnchor;
|
||||
import java.security.cert.X509Certificate;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public final class VerifyNameConstraints {
|
||||
|
||||
private static PKIXParameters params;
|
||||
private static CertPath path;
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
|
||||
String[] certs = { "sun.cer", "sun2labs2.cer", "labs2isrg2.cer" };
|
||||
try {
|
||||
createPath(certs);
|
||||
validate(path, params);
|
||||
throw new Exception
|
||||
("CertPath should not have been validated succesfully");
|
||||
} catch (CertPathValidatorException cve) {
|
||||
System.out.println("Test failed as expected: " + cve);
|
||||
}
|
||||
}
|
||||
|
||||
public static void createPath(String[] certs) throws Exception {
|
||||
TrustAnchor anchor = new TrustAnchor(getCertFromFile(certs[0]), null);
|
||||
List list = new ArrayList();
|
||||
for (int i = 1; i < certs.length; i++) {
|
||||
list.add(0, getCertFromFile(certs[i]));
|
||||
}
|
||||
CertificateFactory cf = CertificateFactory.getInstance("X509");
|
||||
path = cf.generateCertPath(list);
|
||||
|
||||
Set anchors = Collections.singleton(anchor);
|
||||
params = new PKIXParameters(anchors);
|
||||
params.setRevocationEnabled(false);
|
||||
}
|
||||
|
||||
/*
|
||||
* Reads the entire input stream into a byte array.
|
||||
*/
|
||||
private static byte[] getTotalBytes(InputStream is) throws IOException {
|
||||
byte[] buffer = new byte[8192];
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream(2048);
|
||||
int n;
|
||||
baos.reset();
|
||||
while ((n = is.read(buffer, 0, buffer.length)) != -1) {
|
||||
baos.write(buffer, 0, n);
|
||||
}
|
||||
return baos.toByteArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a DER-encoded X.509 certificate from a file.
|
||||
*
|
||||
* @param certFilePath path to file containing DER-encoded certificate
|
||||
* @return X509Certificate
|
||||
* @throws IOException on error
|
||||
*/
|
||||
public static X509Certificate getCertFromFile(String certFilePath)
|
||||
throws IOException {
|
||||
X509Certificate cert = null;
|
||||
try {
|
||||
File certFile = new File(System.getProperty("test.src", "."),
|
||||
certFilePath);
|
||||
FileInputStream certFileInputStream =
|
||||
new FileInputStream(certFile);
|
||||
CertificateFactory cf = CertificateFactory.getInstance("X509");
|
||||
cert = (X509Certificate)
|
||||
cf.generateCertificate(certFileInputStream);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
throw new IOException("Can't construct X509Certificate: " +
|
||||
e.getMessage());
|
||||
}
|
||||
return cert;
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform a PKIX validation. On success, print the
|
||||
* CertPathValidatorResult on System.out. On failure,
|
||||
* throw an exception.
|
||||
*
|
||||
* @param path CertPath to validate
|
||||
* @param params PKIXParameters to use in validation
|
||||
* @throws Exception on error
|
||||
*/
|
||||
public static void validate(CertPath path, PKIXParameters params)
|
||||
throws Exception {
|
||||
CertPathValidator validator =
|
||||
CertPathValidator.getInstance("PKIX");
|
||||
CertPathValidatorResult cpvr = validator.validate(path, params);
|
||||
}
|
||||
}
|
||||
Binary file not shown.
BIN
test/jdk/java/security/cert/pkix/nameConstraintsMinMax/sun.cer
Normal file
BIN
test/jdk/java/security/cert/pkix/nameConstraintsMinMax/sun.cer
Normal file
Binary file not shown.
Binary file not shown.
139
test/jdk/java/security/cert/pkix/policyChanges/TestPolicy.java
Normal file
139
test/jdk/java/security/cert/pkix/policyChanges/TestPolicy.java
Normal file
|
|
@ -0,0 +1,139 @@
|
|||
/*
|
||||
* Copyright (c) 2002, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
// This test case relies on updated static security property, no way to re-use
|
||||
// security property in samevm/agentvm mode.
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @bug 4684793
|
||||
* @summary verify that the RFC3280 policy processing changes are
|
||||
* implemented correctly
|
||||
* @run main/othervm TestPolicy
|
||||
* @author Andreas Sterbenz
|
||||
*/
|
||||
|
||||
import java.io.*;
|
||||
import java.text.DateFormat;
|
||||
import java.util.*;
|
||||
|
||||
import java.security.Security;
|
||||
import java.security.cert.*;
|
||||
|
||||
public class TestPolicy {
|
||||
|
||||
private final static String BASE = System.getProperty("test.src");
|
||||
|
||||
private static CertificateFactory factory;
|
||||
|
||||
private static X509Certificate loadCertificate(String name) throws Exception {
|
||||
InputStream in = new FileInputStream(new File(BASE, name));
|
||||
X509Certificate cert = (X509Certificate)factory.generateCertificate(in);
|
||||
in.close();
|
||||
return cert;
|
||||
}
|
||||
|
||||
private static class TestCase {
|
||||
final String resultTree;
|
||||
final Set initialPolicies;
|
||||
TestCase(String resultTree, String p1, String p2, String p3) {
|
||||
this.resultTree = resultTree;
|
||||
this.initialPolicies = new HashSet();
|
||||
initialPolicies.add(p1);
|
||||
initialPolicies.add(p2);
|
||||
initialPolicies.add(p3);
|
||||
initialPolicies.remove(null);
|
||||
}
|
||||
public String toString() {
|
||||
return initialPolicies.toString();
|
||||
}
|
||||
}
|
||||
|
||||
private final static TestCase[] TEST_CASES = new TestCase[] {
|
||||
new TestCase("2.5.29.32.0[1.2.0[1.2.0], 2.5.29.32.0[2.5.29.32.0]]", "2.5.29.32.0", null, null),
|
||||
new TestCase("2.5.29.32.0[1.2.0[1.2.0]]", "1.2.0", null, null),
|
||||
new TestCase("2.5.29.32.0[2.5.29.32.0[1.2.1]]", "1.2.1", null, null),
|
||||
new TestCase("2.5.29.32.0[1.2.0[1.2.0], 2.5.29.32.0[1.2.1]]", "1.2.0", "1.2.1", null),
|
||||
new TestCase("2.5.29.32.0[2.5.29.32.0[1.2.1, 1.2.2]]", "1.2.1", "1.2.2", null),
|
||||
new TestCase("2.5.29.32.0[1.2.0[1.2.0], 2.5.29.32.0[1.2.1, 1.2.2]]", "1.2.0", "1.2.1", "1.2.2"),
|
||||
};
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
// reset the security property to make sure that the algorithms
|
||||
// and keys used in this test are not disabled.
|
||||
Security.setProperty("jdk.certpath.disabledAlgorithms", "MD2");
|
||||
|
||||
factory = CertificateFactory.getInstance("X.509");
|
||||
|
||||
X509Certificate anchor = loadCertificate("anchor.cer");
|
||||
X509Certificate ca = loadCertificate("ca.cer");
|
||||
X509Certificate ee = loadCertificate("ee.cer");
|
||||
|
||||
for (int i = 0; i < TEST_CASES.length; i++) {
|
||||
TestCase testCase = TEST_CASES[i];
|
||||
System.out.println("*** Running test: " + testCase);
|
||||
CertPathValidator validator = CertPathValidator.getInstance("PKIX");
|
||||
|
||||
PKIXParameters params = new PKIXParameters(Collections.singleton(new TrustAnchor(anchor, null)));
|
||||
params.setRevocationEnabled(false);
|
||||
params.setInitialPolicies(testCase.initialPolicies);
|
||||
|
||||
// Certs expired on 7th Nov 2022
|
||||
params.setDate(DateFormat.getDateInstance(DateFormat.MEDIUM,
|
||||
Locale.US).parse("June 01, 2022"));
|
||||
|
||||
CertPath path = factory.generateCertPath(Arrays.asList(new X509Certificate[] {ee, ca}));
|
||||
|
||||
PKIXCertPathValidatorResult result = (PKIXCertPathValidatorResult)validator.validate(path, params);
|
||||
|
||||
PolicyNode tree = result.getPolicyTree();
|
||||
System.out.println(tree);
|
||||
|
||||
String resultTree = toString(tree);
|
||||
if (resultTree.equals(testCase.resultTree) == false) {
|
||||
System.out.println("Mismatch");
|
||||
System.out.println("Should: " + testCase.resultTree);
|
||||
System.out.println("Is: " + resultTree);
|
||||
throw new Exception("Test failed: " + testCase);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static String toString(PolicyNode tree) {
|
||||
if (tree == null) {
|
||||
return "";
|
||||
}
|
||||
Iterator t = tree.getChildren();
|
||||
if (t.hasNext() == false) {
|
||||
return tree.getValidPolicy();
|
||||
}
|
||||
StringBuffer sb = new StringBuffer();
|
||||
List list = new ArrayList();
|
||||
while (t.hasNext()) {
|
||||
PolicyNode next = (PolicyNode)t.next();
|
||||
list.add(toString(next));
|
||||
}
|
||||
Collections.sort(list);
|
||||
return tree.getValidPolicy() + list;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
-----BEGIN CERTIFICATE-----
|
||||
MIIBFzCBwgIBATANBgkqhkiG9w0BAQQFADAXMRUwEwYDVQQDEwxUcnVzdCBBbmNo
|
||||
b3IwHhcNMDIxMTA3MTE1NzAzWhcNMjIxMTA3MTE1NzAzWjAXMRUwEwYDVQQDEwxU
|
||||
cnVzdCBBbmNob3IwXDANBgkqhkiG9w0BAQEFAANLADBIAkEA9uCj12hwDgC1n9go
|
||||
0ozQAVMM+DfX0vpKOemyGNp+ycSLfAq3pxBcUKbQhjSRL7YjPkEL8XC6pRLwyEoF
|
||||
osWweQIDAQABMA0GCSqGSIb3DQEBBAUAA0EAzZta5M1qbbozj7jWnNyTgB4HUpzv
|
||||
4eP0VYQb1pQY1/xEMczaRt+RuoIDnHCq5a1vOiwk6ZbdG6GlJKx9lj0oMQ==
|
||||
-----END CERTIFICATE-----
|
||||
9
test/jdk/java/security/cert/pkix/policyChanges/ca.cer
Normal file
9
test/jdk/java/security/cert/pkix/policyChanges/ca.cer
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
-----BEGIN CERTIFICATE-----
|
||||
MIIBSjCB9aADAgECAgECMA0GCSqGSIb3DQEBBAUAMBcxFTATBgNVBAMTDFRydXN0
|
||||
IEFuY2hvcjAeFw0wMjExMDcxMTU3MDNaFw0yMjExMDcxMTU3MDNaMA0xCzAJBgNV
|
||||
BAMTAkNBMFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAJ8mP3x37PablDfwldGL5G0+
|
||||
l9NgMJSdxVNWBg+ySzQNsZklEFCxGfxPQW+EFYfafHbTbmnni2gsgU1mgPBTQDsC
|
||||
AwEAAaM2MDQwCwYDVR0PBAQDAgIEMBcGA1UdIAQQMA4wBgYEVR0gADAEBgIqADAM
|
||||
BgNVHRMEBTADAQH/MA0GCSqGSIb3DQEBBAUAA0EA9oCyzh0UKmNsKb+KpppbKYs8
|
||||
iA8sDm9oDCwyVSXBM46zrP38nRcx3EdKFvGTwbb/Np+lcZALUsKVYQy3rlU+cQ==
|
||||
-----END CERTIFICATE-----
|
||||
9
test/jdk/java/security/cert/pkix/policyChanges/ee.cer
Normal file
9
test/jdk/java/security/cert/pkix/policyChanges/ee.cer
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
-----BEGIN CERTIFICATE-----
|
||||
MIIBLTCB2KADAgECAgEDMA0GCSqGSIb3DQEBBAUAMA0xCzAJBgNVBAMTAkNBMB4X
|
||||
DTAyMTEwNzExNTcwM1oXDTIyMTEwNzExNTcwM1owFTETMBEGA1UEAxMKRW5kIEVu
|
||||
dGl0eTBcMA0GCSqGSIb3DQEBAQUAA0sAMEgCQQDVBDfF+uBr5s5jzzDs1njKlZNt
|
||||
h8hHzEt3ASh67Peos+QrDzgpUyFXT6fdW2h7iPf0ifjM8eW2xa+3EnPjjU5jAgMB
|
||||
AAGjGzAZMBcGA1UdIAQQMA4wBgYEVR0gADAEBgIqADANBgkqhkiG9w0BAQQFAANB
|
||||
AFo//WOboCNOCcA1fvcWW9oc4MvV8ZPvFIAbyEbgyFd4id5lGDTRbRPvvNZRvdsN
|
||||
NM2gXYr+f87NHIXc9EF3pzw=
|
||||
-----END CERTIFICATE-----
|
||||
Loading…
Add table
Add a link
Reference in a new issue