8297955: LDAP CertStore should use LdapName and not String for DNs
Reviewed-by: weijun, rhalade
This commit is contained in:
parent
d23a8bfb14
commit
df9aad018a
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2015, 2021, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2015, 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
|
||||
@ -44,6 +44,7 @@ import java.security.cert.*;
|
||||
import javax.naming.CommunicationException;
|
||||
import javax.naming.ldap.InitialLdapContext;
|
||||
import javax.naming.ldap.LdapContext;
|
||||
import javax.naming.ldap.LdapName;
|
||||
import javax.security.auth.x500.X500Principal;
|
||||
|
||||
import com.sun.jndi.ldap.LdapReferralException;
|
||||
@ -218,16 +219,23 @@ final class LDAPCertStoreImpl {
|
||||
*/
|
||||
private class LDAPRequest {
|
||||
|
||||
private final String name;
|
||||
private final LdapName name;
|
||||
private Map<String, byte[][]> valueMap;
|
||||
private final List<String> requestedAttributes;
|
||||
|
||||
LDAPRequest(String name) throws CertStoreException {
|
||||
this.name = checkName(name);
|
||||
try {
|
||||
// Convert DN to an LdapName so that it is not treated as a
|
||||
// composite name by JNDI. In JNDI, using a string name is
|
||||
// equivalent to calling new CompositeName(stringName).
|
||||
this.name = new LdapName(name);
|
||||
} catch (InvalidNameException ine) {
|
||||
throw new CertStoreException("Invalid name: " + name, ine);
|
||||
}
|
||||
requestedAttributes = new ArrayList<>(5);
|
||||
}
|
||||
|
||||
private String checkName(String name) throws CertStoreException {
|
||||
private static String checkName(String name) throws CertStoreException {
|
||||
if (name == null) {
|
||||
throw new CertStoreException("Name absent");
|
||||
}
|
||||
@ -321,6 +329,9 @@ final class LDAPCertStoreImpl {
|
||||
if (newDn != null && newDn.charAt(0) == '/') {
|
||||
newDn = newDn.substring(1);
|
||||
}
|
||||
// In JNDI, it is not possible to use an LdapName for
|
||||
// the referral DN, so we must validate the syntax of
|
||||
// the string DN.
|
||||
checkName(newDn);
|
||||
} catch (Exception e) {
|
||||
throw new NamingException("Cannot follow referral to "
|
||||
@ -371,7 +382,7 @@ final class LDAPCertStoreImpl {
|
||||
* or does not contain any values, a zero length byte array is
|
||||
* returned. NOTE that it is assumed that all values are byte arrays.
|
||||
*/
|
||||
private byte[][] getAttributeValues(Attribute attr)
|
||||
private static byte[][] getAttributeValues(Attribute attr)
|
||||
throws NamingException {
|
||||
byte[][] values;
|
||||
if (attr == null) {
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2017, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2017, 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
|
||||
@ -144,27 +144,26 @@ public class ActalisCA {
|
||||
"rjhpn3C/NptVyZgT8bL4XT5ITrAjwPciBj0yxYzUkrLZO1wKQSQ=\n" +
|
||||
"-----END CERTIFICATE-----";
|
||||
|
||||
// Owner: CN=ssltest-revoked.actalis.it, O=Actalis S.p.A., L=Ponte San Pietro,
|
||||
// ST=Bergamo, C=IT
|
||||
// Issuer: CN=Actalis Organization Validated Server CA G3, O=Actalis S.p .A.,
|
||||
// L=Ponte San Pietro, ST=Bergamo, C=IT
|
||||
// Serial number: 3dbdba0fefe7c6bd978220de52ffe3b2
|
||||
// Valid from: Fri Oct 08 02:23:49 PDT 2021 until: Sat Oct 08 02:23:49 PDT 2022
|
||||
// Owner: CN=ssltest-revoked.actalis.it, O=Actalis S.p.A., L=Ponte San Pietro, ST=Bergamo, C=IT
|
||||
// Issuer: CN=Actalis Organization Validated Server CA G3, O=Actalis S.p.A.,
|
||||
// L=Ponte San Pietro, ST=Bergamo, C=IT
|
||||
// Serial number: 320955171b78d49507508910da2c5bc4
|
||||
// Valid from: Tue Sep 27 03:40:43 PDT 2022 until: Wed Sep 27 03:40:43 PDT 2023
|
||||
private static final String REVOKED = "-----BEGIN CERTIFICATE-----\n" +
|
||||
"MIIH1zCCBb+gAwIBAgIQPb26D+/nxr2XgiDeUv/jsjANBgkqhkiG9w0BAQsFADCB\n" +
|
||||
"MIIH1TCCBb2gAwIBAgIQMglVFxt41JUHUIkQ2ixbxDANBgkqhkiG9w0BAQsFADCB\n" +
|
||||
"iTELMAkGA1UEBhMCSVQxEDAOBgNVBAgMB0JlcmdhbW8xGTAXBgNVBAcMEFBvbnRl\n" +
|
||||
"IFNhbiBQaWV0cm8xFzAVBgNVBAoMDkFjdGFsaXMgUy5wLkEuMTQwMgYDVQQDDCtB\n" +
|
||||
"Y3RhbGlzIE9yZ2FuaXphdGlvbiBWYWxpZGF0ZWQgU2VydmVyIENBIEczMB4XDTIx\n" +
|
||||
"MTAwODA5MjM0OVoXDTIyMTAwODA5MjM0OVoweDELMAkGA1UEBhMCSVQxEDAOBgNV\n" +
|
||||
"Y3RhbGlzIE9yZ2FuaXphdGlvbiBWYWxpZGF0ZWQgU2VydmVyIENBIEczMB4XDTIy\n" +
|
||||
"MDkyNzEwNDA0M1oXDTIzMDkyNzEwNDA0M1oweDELMAkGA1UEBhMCSVQxEDAOBgNV\n" +
|
||||
"BAgMB0JlcmdhbW8xGTAXBgNVBAcMEFBvbnRlIFNhbiBQaWV0cm8xFzAVBgNVBAoM\n" +
|
||||
"DkFjdGFsaXMgUy5wLkEuMSMwIQYDVQQDDBpzc2x0ZXN0LXJldm9rZWQuYWN0YWxp\n" +
|
||||
"cy5pdDCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAPPgHusiIPuBvyPF\n" +
|
||||
"5lvUnfRraGomDTTJ4FBHomWJgbyTcfjJ6WqP5p6dwcRTyXT1U/odp5bxSYGBpj31\n" +
|
||||
"1zi1tqtJGxuXauTytKUPL1pOXOD4V9JpOL9VetDZS5Lvo3bnAjGLJA/B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
|
||||
"U6oIAeW1aKuOve6iNg1vsFAN57aJNh1ih3BOup58J9ve42bNlAYWN8wiNxM+Aeba\n" +
|
||||
"ArUSTnH/QEYCyMRD0XqIREVR9VhNODgSZbL3XedYBAW9wImi1whp+u+8aReXd7lC\n" +
|
||||
"Q3kD9KRyfZ9Kk05Glf3DsZMWvp1N2ZZWaU2Ms5U3ijUheCiBrqrs8a8=\n" +
|
||||
"-----END CERTIFICATE-----";
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
|
||||
ValidatePathWithParams pathValidator = new ValidatePathWithParams(null);
|
||||
boolean ocspEnabled = false;
|
||||
|
||||
if (args.length >= 1 && "CRL".equalsIgnoreCase(args[0])) {
|
||||
pathValidator.enableCRLCheck();
|
||||
} else {
|
||||
// OCSP check by default
|
||||
pathValidator.enableOCSPCheck();
|
||||
ocspEnabled = true;
|
||||
}
|
||||
|
||||
// Validate valid
|
||||
pathValidator.validate(new String[]{VALID, INT},
|
||||
ValidatePathWithParams.Status.GOOD, null, System.out);
|
||||
|
||||
if (ocspEnabled) {
|
||||
// Revoked test certificate will expire in Oct 2022
|
||||
pathValidator.setValidationDate("June 01, 2022");
|
||||
}
|
||||
|
||||
// Validate Revoked
|
||||
pathValidator.validate(new String[]{REVOKED, INT},
|
||||
ValidatePathWithParams.Status.REVOKED,
|
||||
"Mon Mar 07 06:11:11 PST 2022", System.out);
|
||||
"Tue Sep 27 03:52:40 PDT 2022", System.out);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user