diff --git a/src/share/classes/com/sun/security/auth/module/Krb5LoginModule.java b/src/share/classes/com/sun/security/auth/module/Krb5LoginModule.java index e883373b117ff0d58288266f0cebe7435ed154d3..7562f584ada705c22340068d479b83923c751edd 100644 --- a/src/share/classes/com/sun/security/auth/module/Krb5LoginModule.java +++ b/src/share/classes/com/sun/security/auth/module/Krb5LoginModule.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2006 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 2000-2008 Sun Microsystems, Inc. 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 @@ -1145,6 +1145,10 @@ public class Krb5LoginModule implements LoginModule { sharedState.put(NAME, username); sharedState.put(PWD, password); } + } else { + // remove temp results for the next try + encKeys = null; + principal = null; } username = null; password = null; diff --git a/src/share/classes/sun/security/provider/certpath/ConstraintsChecker.java b/src/share/classes/sun/security/provider/certpath/ConstraintsChecker.java index 9b065be8564b4f53e4c13e1db42469fd6b06390a..40872d7d6fca93d0e2acfc3406ee6d7f4d2ec9e1 100644 --- a/src/share/classes/sun/security/provider/certpath/ConstraintsChecker.java +++ b/src/share/classes/sun/security/provider/certpath/ConstraintsChecker.java @@ -59,7 +59,7 @@ class ConstraintsChecker extends PKIXCertPathChecker { private int i; private NameConstraintsExtension prevNC; - private static Set supportedExts; + private Set supportedExts; /** * Creates a ConstraintsChecker. diff --git a/src/share/classes/sun/security/provider/certpath/ForwardBuilder.java b/src/share/classes/sun/security/provider/certpath/ForwardBuilder.java index e60e4c9d7addbf0856cd34fd71031a2cae0beb35..aa886037312c78f320df5a20d6b1a06d2f04a2e5 100644 --- a/src/share/classes/sun/security/provider/certpath/ForwardBuilder.java +++ b/src/share/classes/sun/security/provider/certpath/ForwardBuilder.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2007 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 2000-2008 Sun Microsystems, Inc. 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 @@ -198,6 +198,11 @@ class ForwardBuilder extends Builder { X509CertSelector sel = null; if (currentState.isInitial()) { + if (targetCertConstraints.getBasicConstraints() == -2) { + // no need to continue: this means we never can match a CA cert + return; + } + /* This means a CA is the target, so match on same stuff as * getMatchingEECerts */ diff --git a/src/share/classes/sun/security/provider/certpath/KeyChecker.java b/src/share/classes/sun/security/provider/certpath/KeyChecker.java index e1a98ea616347b181bdee1be27b6104414dc7472..1ed96c567e2017007891a2459cd3fd8a33b6e01a 100644 --- a/src/share/classes/sun/security/provider/certpath/KeyChecker.java +++ b/src/share/classes/sun/security/provider/certpath/KeyChecker.java @@ -50,7 +50,7 @@ class KeyChecker extends PKIXCertPathChecker { private CertSelector targetConstraints; private int remainingCerts; - private static Set supportedExts; + private Set supportedExts; /** * Default Constructor diff --git a/src/share/classes/sun/security/provider/certpath/PolicyChecker.java b/src/share/classes/sun/security/provider/certpath/PolicyChecker.java index a94d0f23d9f363815992340326f76a1b1ebcdb96..3b76f621ceac890e6e38325d00c05fa95c2b3e7e 100644 --- a/src/share/classes/sun/security/provider/certpath/PolicyChecker.java +++ b/src/share/classes/sun/security/provider/certpath/PolicyChecker.java @@ -68,7 +68,7 @@ class PolicyChecker extends PKIXCertPathChecker { private int inhibitAnyPolicy; private int certIndex; - private static Set supportedExts; + private Set supportedExts; private static final Debug debug = Debug.getInstance("certpath"); static final String ANY_POLICY = "2.5.29.32.0"; diff --git a/test/java/security/cert/CertPathBuilder/targetConstraints/BuildEEBasicConstraints.java b/test/java/security/cert/CertPathBuilder/targetConstraints/BuildEEBasicConstraints.java new file mode 100644 index 0000000000000000000000000000000000000000..0ec0be61cc9a97607c275ca71779b7042593f75e --- /dev/null +++ b/test/java/security/cert/CertPathBuilder/targetConstraints/BuildEEBasicConstraints.java @@ -0,0 +1,79 @@ +/* + * Copyright 2008 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + */ + +/** + * @test + * @bug 6714842 + * @library ../../../testlibrary + * @build CertUtils + * @run main 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.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.util.ArrayList; +import java.util.Collections; +import java.util.List; + +public final class BuildEEBasicConstraints { + + public static void main(String[] args) throws Exception { + + 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); + X509Certificate eeCert = CertUtils.getCertFromFile("ee.cer"); + X509Certificate caCert = CertUtils.getCertFromFile("ca.cer"); + ArrayList certs = new ArrayList(); + 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 certList = cp.getCertificates(); + X509Certificate cert = (X509Certificate) certList.get(0); + if (cert.getBasicConstraints() != -1) { + throw new Exception("Target certificate is not an EE certificate"); + } + } +} diff --git a/test/java/security/cert/CertPathBuilder/targetConstraints/anchor.cer b/test/java/security/cert/CertPathBuilder/targetConstraints/anchor.cer new file mode 100644 index 0000000000000000000000000000000000000000..bfb5d5847b4839bb5522620c569bbbada1fc7966 --- /dev/null +++ b/test/java/security/cert/CertPathBuilder/targetConstraints/anchor.cer @@ -0,0 +1,8 @@ +-----BEGIN CERTIFICATE----- +MIIBFzCBwgIBATANBgkqhkiG9w0BAQQFADAXMRUwEwYDVQQDEwxUcnVzdCBBbmNo +b3IwHhcNMDIxMTA3MTE1NzAzWhcNMjIxMTA3MTE1NzAzWjAXMRUwEwYDVQQDEwxU +cnVzdCBBbmNob3IwXDANBgkqhkiG9w0BAQEFAANLADBIAkEA9uCj12hwDgC1n9go +0ozQAVMM+DfX0vpKOemyGNp+ycSLfAq3pxBcUKbQhjSRL7YjPkEL8XC6pRLwyEoF +osWweQIDAQABMA0GCSqGSIb3DQEBBAUAA0EAzZta5M1qbbozj7jWnNyTgB4HUpzv +4eP0VYQb1pQY1/xEMczaRt+RuoIDnHCq5a1vOiwk6ZbdG6GlJKx9lj0oMQ== +-----END CERTIFICATE----- diff --git a/test/java/security/cert/CertPathBuilder/targetConstraints/ca.cer b/test/java/security/cert/CertPathBuilder/targetConstraints/ca.cer new file mode 100644 index 0000000000000000000000000000000000000000..26ffb68c1e00065b9dd95dca93c7b7466633da52 --- /dev/null +++ b/test/java/security/cert/CertPathBuilder/targetConstraints/ca.cer @@ -0,0 +1,9 @@ +-----BEGIN CERTIFICATE----- +MIIBSjCB9aADAgECAgECMA0GCSqGSIb3DQEBBAUAMBcxFTATBgNVBAMTDFRydXN0 +IEFuY2hvcjAeFw0wMjExMDcxMTU3MDNaFw0yMjExMDcxMTU3MDNaMA0xCzAJBgNV +BAMTAkNBMFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAJ8mP3x37PablDfwldGL5G0+ +l9NgMJSdxVNWBg+ySzQNsZklEFCxGfxPQW+EFYfafHbTbmnni2gsgU1mgPBTQDsC +AwEAAaM2MDQwCwYDVR0PBAQDAgIEMBcGA1UdIAQQMA4wBgYEVR0gADAEBgIqADAM +BgNVHRMEBTADAQH/MA0GCSqGSIb3DQEBBAUAA0EA9oCyzh0UKmNsKb+KpppbKYs8 +iA8sDm9oDCwyVSXBM46zrP38nRcx3EdKFvGTwbb/Np+lcZALUsKVYQy3rlU+cQ== +-----END CERTIFICATE----- diff --git a/test/java/security/cert/CertPathBuilder/targetConstraints/ee.cer b/test/java/security/cert/CertPathBuilder/targetConstraints/ee.cer new file mode 100644 index 0000000000000000000000000000000000000000..f20c937ed6c9d3de19443a293d475a101780b112 --- /dev/null +++ b/test/java/security/cert/CertPathBuilder/targetConstraints/ee.cer @@ -0,0 +1,9 @@ +-----BEGIN CERTIFICATE----- +MIIBLTCB2KADAgECAgEDMA0GCSqGSIb3DQEBBAUAMA0xCzAJBgNVBAMTAkNBMB4X +DTAyMTEwNzExNTcwM1oXDTIyMTEwNzExNTcwM1owFTETMBEGA1UEAxMKRW5kIEVu +dGl0eTBcMA0GCSqGSIb3DQEBAQUAA0sAMEgCQQDVBDfF+uBr5s5jzzDs1njKlZNt +h8hHzEt3ASh67Peos+QrDzgpUyFXT6fdW2h7iPf0ifjM8eW2xa+3EnPjjU5jAgMB +AAGjGzAZMBcGA1UdIAQQMA4wBgYEVR0gADAEBgIqADANBgkqhkiG9w0BAQQFAANB +AFo//WOboCNOCcA1fvcWW9oc4MvV8ZPvFIAbyEbgyFd4id5lGDTRbRPvvNZRvdsN +NM2gXYr+f87NHIXc9EF3pzw= +-----END CERTIFICATE-----