从 WebLogic 通过 SSL 连接到 LDAP 服务器

问题描述
编写本文档的目的是解决客户在通过 SSL 连接使用 LDAP 服务器时遇到的大部分问题。如果尚未阅读支持模式“理解和探查 SSL 问题”,请先阅读它。使用本文档的前提是已对 LDAP 服务器做了正确配置,且 SSL 连接已建立并正常工作。

不过,本文档也将介绍客户提出的最常见问题,并说明如何调试和分析此类问题。

快速链接:

从 WebLogic 通过 SSL 调用 LDAP
WebLogic 使用 netscape.ldap 包中的类连接到 WebLogic 支持的任何 LDAP 产品。WebLogic 只能通过单向 SSL 连接到 LDAP 服务器。它无法向 LDAP 服务器提供客户端证书。

准备工作
需要确保对 LDAP 服务器做了正确配置,可以接受 WebLogic Server 通过单向 SSL 发送来的 SSL 请求。

如何进行?
通过 SSL 成功连接到 LDAP 服务器的 4 个要点如下:
  1. 必须选中控制台中的“Enable SSL”标志,因为要使用 SSL 连接到 LDAP 服务器。
  2. 必须将 LDAP 服务器的根 CA 存储到 WebLogic 的信任密钥库中。(例如,keytool -import -keystore myWLStrustedkeytore.jks -alias ca -file getcacert.cer -storepass myWLStrustedkeytoreStorePassPhrase -trustcacerts
  3. <>WebLogic 控制台中为 LDAP 配置指定的主机名必须与 LDAP 服务器证书的 CN 匹配
  4. <>在控制台中为 LDAP Authentication Provider 指定的端口必须是 LDAP 服务器的 SSL 端口之一
返回页首

如何调试?
如果认为已正确设置 LDAP 服务器和 WebLogic Server 且一切运行正常,则需要最先确定的是用户和组在 WebLogic 的控制台中是否可见。

如果可见并已为配置设置了 SSL 端口,那么就已经成功了。

现在如果想要百分之百确定一切正常,BEA 建议您执行下列操作:
  • 添加调试语句 DebugSecurityAtn="true",然后启动服务器。
查找:

<4 avr. 2005 08 h 29 BST> <Notice> <Security> <BEA-090169> <Loading trusted certificates from the jks keystore file D:\wls\81\sp4\weblogic81\server\lib\DemoTrust.jks.>
<4 avr. 2005 08 h 29 BST> <Notice> <Security> <BEA-090169> <Loading trusted certificates from the jks keystore file D:\wls\81\sp4\JDK142~1\jre\lib\security\cacerts.>
<4 avr. 2005 08 h 29 BST> <Debug> <SecurityDebug> <000000> <connection succeeded>
<4 avr. 2005 08 h 29 BST> <Debug> <SecurityDebug> <000000> <getConnection return conn:LDAPConnection {ldaps://smalbois02:636 ldapVersion:3 bindDN:"cn=Directory Manager"}>

消息“connection succeeded”确认您已成功连接到 LDAP 服务器。
  • 对 WebLogic Server 进行 Thread Dump。完成此操作后,需要查找的线程即是连接到 LDAP 服务器的线程。如果该线程未出现,则表明连接有问题。

"LDAPConnThread-0 ldaps://smalbois02:636" daemon prio=5 tid=0x032a1988 nid=0x10d0 runnable [3c1f000..3c1fd8c]
        at java.net.SocketInputStream.socketRead0(Native Method)
        at java.net.SocketInputStream.read(SocketInputStream.java:129)
        at weblogic.utils.io.ChunkedInputStream.read(ChunkedInputStream.java:140)
        at java.io.InputStream.read(InputStream.java:89)
        at com.certicom.tls.record.ReadHandler.readFragment(Unknown Source)
        at com.certicom.tls.record.ReadHandler.readRecord(Unknown Source)
        at com.certicom.tls.record.ReadHandler.read(Unknown Source)
        - locked <0x114a83a8> (a com.certicom.tls.record.ReadHandler)
        at com.certicom.io.InputSSLIOStreamWrapper.read(Unknown Source)
        at java.io.BufferedInputStream.fill(BufferedInputStream.java:183)
        at java.io.BufferedInputStream.read(BufferedInputStream.java:201)
        - locked <0x114f7c08> (a java.io.BufferedInputStream)
        at netscape.ldap.ber.stream.BERElement.getElement(BERElement.java:101)
        at netscape.ldap.LDAPConnThread.run(LDAPConnThread.java:538)
        at java.lang.Thread.run(Thread.java:534)

此线程确认已可以通过 SSL 连接到 LDAP 服务器。在本例中,连接到的主机名是 SMALBOIS02,它运行在 SSL 端口 636 上。
  • 检查域目录中的 ldp_trace.log 文件
    查找:ldc=0 Connected to ldaps://smalbois02:636
返回页首

所需调试总结
  1. 在 WebLogic Server 命令行中指定:-Dweblogic.security.SSL.verbose=true -Dssl.debug=true -Dweblogic.StdoutDebugEnabled=true
  2. <>在 config.xml 中指定 - DebugSecurityAtn="true"DebugSSL="true"
    例如:<ServerDebug DebugSSL="true" DebugSecurityAtn="true" Name="myserver"/>
客户端出现了哪些问题?
使用 DebugSecurityAtn="true" 标志时,您可能会注意到 WebLogic Server 由于下述原因无法连接到服务器。

返回页首

常见问题:
问题 1:读通道被关闭 (91)

<1 avr. 2005 17 h 11 BST> <Debug> <SecurityDebug> <000000>
<new LDAP connection to host localhost port 636 use local connection is false>
<1 avr. 2005 17 h 11 BST> <Debug> <SecurityDebug> <000000>
<created new LDAP connection LDAPConnection { ldapVersion:2 bindDN:""}>
<1 avr. 2005 17 h 11 BST> <Notice> <Security> <BEA-090169>
<Loading trusted certificates from the jks keystore
file D:\wls\81\sp4\weblogic81\server\lib\DemoTrust.jks.>
<1 avr. 2005 17 h 11 BST> <Notice> <Security> <BEA-090169>
<Loading trusted certificates from the jks keystore file
D:\wls\81\sp4\JDK142~1\jre\lib\security\cacerts.>
<1 avr. 2005 17 h 11 BST> <Debug> <SecurityDebug> <000000>
<connection failed netscape.ldap.LDAPException: Read channel closed (91)>
java.lang.reflect.InvocationTargetException
        at weblogic.security.providers.authentication.
LDAPAtnDelegate$LDAPFactory.newInstance
(LDAPAtnDelegate.java:3441)
        at weblogic.security.utils.Pool.getInstance(Pool.java:60)
        at weblogic.security.providers.authentication.LDAPAtnDelegate.getConnection
(LDAPAtnDelegate.java:2882)
        at weblogic.security.providers.authentication.LDAPAtnDelegate.authenticate
(LDAPAtnDelegate.java:2918)
        at weblogic.security.providers.authentication.LDAPAtnLoginModuleImpl.login
(LDAPAtnLoginModuleImpl.java:165)

解决办法:
LDAP 服务器上的 SSL 配置可能不正确。请确认在 LDAP 服务器上指定了何种客户端身份验证。应选中“Do not Allow Client Authentication”,因为无法向 LDAP 服务器提供客户端证书。

返回页首

问题 2:证书包含的是 SMALBOIS02 但检查要求的是 locatlhost (91)



<4 avr. 2005 08 h 05 BST> <Warning> <Security> <BEA-090504> <Certificate
chain received from localhost - 127.0.0.1 failed hostname verification
check. Certificate contained SMALBOIS02 but check expected localhost>
<4 avr. 2005 08 h 05 BST> <Debug> <SecurityDebug> <000000>
<connection failed netscape.ldap.LDAPException:
[Security:090504]Certificate chain received from localhost - 127.0.0.1
failed hostname verification check.
Certificate contained SMALBOIS02 but check expected localhost (91)>
java.lang.reflect.InvocationTargetException
        at weblogic.security.providers.authentication.LDAPAtnDelegate$LDAPFactory.newInstance
(LDAPAtnDelegate.java:3441)
                ...

解决办法:
尝试连接到的 LDAP 服务器的主机名与 LDAP 服务器证书不匹配。一般情况下为它指定 LDAP 服务器证书的公用名 (Common Name, CN)。在本例中,我们指定了“localhost”,但 LDAP 服务器证书包含的是“SMALBOIS02”。更新此项后即不会再出现该问题。

返回页首

问题 3:xxxx 不受信任,导致 SSL 握手失败

<4 avr. 2005 08 h 31 BST> <Notice> <Security> <BEA-090169> <Loading trusted
certificates from the jks
keystore file D:\wls\81\sp4\weblogic81\server\lib\DemoTrust.jks.>
<4 avr. 2005 08 h 31 BST> <Notice> <Security> <BEA-090169> <Loading
trusted certificates from the jks keystore file
D:\wls\81\sp4\JDK142~1\jre\lib\security\cacerts.>
<4 avr. 2005 08 h 31 BST> <Warning> <Security> <BEA-090477>
<Certificate chain received from smalbois02 - 127.0.0.1
was not trusted causing SSL handshake failure.>
<4 avr. 2005 08 h 31 BST> <Debug> <SecurityDebug> <000000>
<connection failed netscape.ldap.LDAPException:
[Security:090477]Certificate chain received from smalbois02 - 127.0.0.1
was not trusted causing SSL handshake failure. (91)>
java.lang.reflect.InvocationTargetException
        at weblogic.security.providers.authentication.LDAPAtnDelegate$LDAPFactory.newInstance
(LDAPAtnDelegate.java:3441)
        at weblogic.security.utils.Pool.getInstance(Pool.java:60)
        at weblogic.security.providers.authentication.LDAPAtnDelegate.getConnection
(LDAPAtnDelegate.java:2882)
               ...


解决办法:
在 Weblogic 端使用的信任密钥库不包含 LDAP 服务器的受信任 CA。应使用 keytool 使之包含受信任 CA。例如:
>keytool -import -keystore DemoTrust.jks -alias ca -file getcacert.cer -storepass DemoTrustKeyStorePassPhrase -trustcacerts
Owner:OU=For VeriSign authorized testing only.No assurances (C)VS1997, OU=www.verisign.com/repository/TestCPS Incorp.By Ref. Liab. LTD., O="VeriSign, Inc"Issuer:OU=For VeriSign authorized testing only.No assurances (C)VS1997, OU=www.verisign.com/repository/TestCPS Incorp.By Ref. Liab. LTD., O="VeriSign, Inc"Serial number:52a9f424da674c9daf4f537852abef6e
Valid from:Sun Jun 07 01:00:00 BST 1998 until:Wed Jun 07 00:59:59 BST 2006
Certificate fingerprints:
        MD5: 40:06:53:11:FD:B3:3E:88:0A:6F:7D:D1:4E:22:91:87
         SHA1:93:71:C9:EE:57:09:92:5D:0A:8E:FA:02:0B:E2:F5:E6:98:6C:60:DE
Trust this certificate?[no]: yes
Certificate was added to keystore


备注:getcacert.cer是 Verisign 提供的根 CA,由 LDAP 服务器使用 完成此操作后重新启动 WebLogic Server 即可解决问题。

返回页首

问题 4:127.0.0.1 日期有效性检查失败。(91)

<26 avr. 2005 08 h 49 BST> <Notice> <Security> <BEA-090169>
<Loading trusted certificates from the jks keystore file
D:\wls\81\sp4\weblogic81\server\lib\DemoTrust.jks.>
<26 avr. 2005 08 h 49 BST> <Notice> <Security> <BEA-090169>
<Loading trusted certificates from the jks keystore file
D:\wls\81\sp4\JDK142~1\jre\lib\security\cacerts.>
<26 avr. 2005 08 h 49 BST> <Warning> <Security> <BEA-090479>
<Certificate chain received from smalbois02 - 127.0.0.1 failed date validity checks.>
<26 avr. 2005 08 h 49 BST> <Debug> <SecurityDebug> <000000>
<connection failed netscape.ldap.LDAPException: [Security:090479]
Certificate chain received from smalbois02 - 127.0.0.1 failed date validity checks. (91)>
java.lang.reflect.InvocationTargetException
        at weblogic.security.providers.authentication.LDAPAtnDelegate$LDAPFactory.newInstance
(LDAPAtnDelegate.java:3441)
        at weblogic.security.utils.Pool.getInstance(Pool.java:60)
        at weblogic.security.providers.authentication.LDAPAtnDelegate.getConnection
(LDAPAtnDelegate.java:2882)
               ...

解决办法:
LDAP 服务器上的证书已过期失效,需要用最新的证书替代。
返回页首

问题 5:连接被拒绝:连接 (91)

<4 avr. 2005 09 h 03 BST> <Debug> <SecurityDebug> <000000> <created new LDAP
connection LDAPConnection { ldapVersion:2 bindDN:""}>
<4 avr. 2005 09 h 03 BST> <Notice> <Security> <BEA-090169> <Loading trusted
certificates from the jks keystore file D:\wls\81\sp4\weblogic81\server\lib\DemoTrust.jks.>
<4 avr. 2005 09 h 03 BST> <Notice> <Security> <BEA-090169> <Loading trusted
certificates from the jks keystore file D:\wls\81\sp4\JDK142~1\jre\lib\security\cacerts.>
<4 avr. 2005 09 h 03 BST> <Debug> <SecurityDebug> <000000> <connection
failed netscape.ldap.LDAPException: Connection refused: connect (91)>
java.lang.reflect.InvocationTargetException
        at weblogic.security.providers.authentication.LDAPAtnDelegate$LDAPFactory.newInstance
(LDAPAtnDelegate.java:3441)
        at weblogic.security.utils.Pool.getInstance(Pool.java:60)
        at weblogic.security.providers.authentication.LDAPAtnDelegate.getConnection
(LDAPAtnDelegate.java:2882)
        at weblogic.security.providers.authentication.LDAPAtnDelegate.authenticate
(LDAPAtnDelegate.java:2918)
        at weblogic.security.providers.authentication.LDAPAtnLoginModuleImpl.login
(LDAPAtnLoginModuleImpl.java:165)

解决办法:
请确认 LDAP 服务器正在运行且正在监听您指定的端口。根本无法建立物理连接。

已知问题
您可以定期查看所用 WLS 版本的“Release Notes”,了解 Service Pack 中的“Known Issues”或“Resolved Issues”的详细信息及浏览与 SSL 有关的问题。方便起见,下面提供了这些发行说明的链接:
使用搜索功能也可以搜索到“Release Notes”,还可以搜索到其它支持解决办法及与 CR 有关的信息,如需要更多帮助?中所提到的内容。如果客户签订了技术支持合同,则可以登录 http://support.bea.com/,登录后会看到为 Solutions 和 Bug Central 提供的 Browse portlet,可在其中按产品版本浏览最新提供的 CR。

需要更多帮助?

如果您已经理解这个模式,但仍需要更多帮助,您可以:
  1. http://support.bea.com/ 上查询 AskBEA(例如,使用“SSL issues”),以查找其它已发布的解决办法。技术支持合同客户:确保已经登录,可以访问提供的与 CR 有关的信息。
  2. http://newsgroups.bea.com/ 上,向 BEA 的某个新闻组提出更详细具体的问题。
如果这还不能解决您的问题,并且您拥有有效的技术支持合同,您可以通过登录以下网站来打开支持案例:http://support.bea.com/

反馈

请给我们提供您的意见,说明此支持诊断模式“从 WebLogic 通过 SSL 连接到 LDAP 服务器”一文是否有所帮助、您需要的任何解释,以及对支持诊断模式的新主题的任何要求。