Skip to content

Commit b2655a7

Browse files
committed
8297955: LDAP CertStore should use LdapName and not String for DNs
8224768: Test ActalisCA.java fails Reviewed-by: sgehwolf Backport-of: 7f1047edba68cfe2fa2660030cb3dd1abad49e4f
1 parent 3b9c787 commit b2655a7

File tree

3 files changed

+211
-243
lines changed

3 files changed

+211
-243
lines changed

jdk/src/share/classes/sun/security/provider/certpath/ldap/LDAPCertStore.java

Lines changed: 54 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2015, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -46,6 +46,7 @@
4646
import java.security.cert.Certificate;
4747
import java.security.cert.*;
4848
import javax.naming.ldap.LdapContext;
49+
import javax.naming.ldap.LdapName;
4950
import javax.security.auth.x500.X500Principal;
5051

5152
import com.sun.jndi.ldap.LdapReferralException;
@@ -290,6 +291,49 @@ private void createInitialDirContext(String server, int port)
290291
}
291292
}
292293

294+
private static String checkName(String name) throws CertStoreException {
295+
if (name == null) {
296+
throw new CertStoreException("Name absent");
297+
}
298+
try {
299+
if (new CompositeName(name).size() > 1) {
300+
throw new CertStoreException("Invalid name: " + name);
301+
}
302+
} catch (InvalidNameException ine) {
303+
throw new CertStoreException("Invalid name: " + name, ine);
304+
}
305+
return name;
306+
}
307+
308+
/**
309+
* Get the values for the given attribute. If the attribute is null
310+
* or does not contain any values, a zero length byte array is
311+
* returned. NOTE that it is assumed that all values are byte arrays.
312+
*/
313+
private static byte[][] getAttributeValues(Attribute attr)
314+
throws NamingException {
315+
byte[][] values;
316+
if (attr == null) {
317+
values = BB0;
318+
} else {
319+
values = new byte[attr.size()][];
320+
int i = 0;
321+
NamingEnumeration<?> enum_ = attr.getAll();
322+
while (enum_.hasMore()) {
323+
Object obj = enum_.next();
324+
if (debug != null) {
325+
if (obj instanceof String) {
326+
debug.println("LDAPCertStore.getAttrValues() "
327+
+ "enum.next is a string!: " + obj);
328+
}
329+
}
330+
byte[] value = (byte[])obj;
331+
values[i++] = value;
332+
}
333+
}
334+
return values;
335+
}
336+
293337
/**
294338
* Private class encapsulating the actual LDAP operations and cache
295339
* handling. Use:
@@ -308,31 +352,20 @@ private void createInitialDirContext(String server, int port)
308352
*/
309353
private class LDAPRequest {
310354

311-
private final String name;
355+
private final LdapName name;
312356
private Map<String, byte[][]> valueMap;
313357
private final List<String> requestedAttributes;
314358

315359
LDAPRequest(String name) throws CertStoreException {
316-
this.name = checkName(name);
317-
requestedAttributes = new ArrayList<>(5);
318-
}
319-
320-
private String checkName(String name) throws CertStoreException {
321-
if (name == null) {
322-
throw new CertStoreException("Name absent");
323-
}
324360
try {
325-
if (new CompositeName(name).size() > 1) {
326-
throw new CertStoreException("Invalid name: " + name);
327-
}
361+
// Convert DN to an LdapName so that it is not treated as a
362+
// composite name by JNDI. In JNDI, using a string name is
363+
// equivalent to calling new CompositeName(stringName).
364+
this.name = new LdapName(name);
328365
} catch (InvalidNameException ine) {
329366
throw new CertStoreException("Invalid name: " + name, ine);
330367
}
331-
return name;
332-
}
333-
334-
String getName() {
335-
return name;
368+
requestedAttributes = new ArrayList<>(5);
336369
}
337370

338371
void addRequestedAttribute(String attrId) {
@@ -409,6 +442,9 @@ private Map<String, byte[][]> getValueMap() throws NamingException {
409442
if (newDn != null && newDn.charAt(0) == '/') {
410443
newDn = newDn.substring(1);
411444
}
445+
// In JNDI, it is not possible to use an LdapName for
446+
// the referral DN, so we must validate the syntax of
447+
// the string DN.
412448
checkName(newDn);
413449
} catch (Exception e) {
414450
throw new NamingException("Cannot follow referral to "
@@ -450,36 +486,6 @@ private void cacheAttribute(String attrId, byte[][] values) {
450486
String cacheKey = name + "|" + attrId;
451487
valueCache.put(cacheKey, values);
452488
}
453-
454-
/**
455-
* Get the values for the given attribute. If the attribute is null
456-
* or does not contain any values, a zero length byte array is
457-
* returned. NOTE that it is assumed that all values are byte arrays.
458-
*/
459-
private byte[][] getAttributeValues(Attribute attr)
460-
throws NamingException {
461-
byte[][] values;
462-
if (attr == null) {
463-
values = BB0;
464-
} else {
465-
values = new byte[attr.size()][];
466-
int i = 0;
467-
NamingEnumeration<?> enum_ = attr.getAll();
468-
while (enum_.hasMore()) {
469-
Object obj = enum_.next();
470-
if (debug != null) {
471-
if (obj instanceof String) {
472-
debug.println("LDAPCertStore.getAttrValues() "
473-
+ "enum.next is a string!: " + obj);
474-
}
475-
}
476-
byte[] value = (byte[])obj;
477-
values[i++] = value;
478-
}
479-
}
480-
return values;
481-
}
482-
483489
}
484490

485491
/*

jdk/test/ProblemList.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -320,8 +320,6 @@ com/sun/crypto/provider/CICO/PBEFunc/CICOPBEFuncTest.java solaris-sparcv9
320320
# 8206912
321321
sun/security/krb5/auto/ReplayCacheTestProc.java solaris-sparcv9
322322

323-
security/infra/java/security/cert/CertPathValidator/certification/ActalisCA.java 8224768 generic-all
324-
325323
sun/security/mscapi/SignedObjectChain.java 8176183 windows-all
326324

327325
javax/security/auth/callback/PasswordCallback/CheckCleanerBound.java 8285785,8286045,8287596 generic-all

0 commit comments

Comments
 (0)