hava jabber-bot。 XMPP over smack 4.2.0 with TLS
Posted
技术标签:
【中文标题】hava jabber-bot。 XMPP over smack 4.2.0 with TLS【英文标题】:hava jabber-bot. XMPP over smack 4.2.0 with TLS 【发布时间】:2017-04-27 07:44:27 【问题描述】:我需要开发迷你 jabber-bot。我有一个只有 TLS 连接规则的 openfire 服务器。我曾经 smack 4.2.0 - 来自http://www.igniterealtime.org/downloads/ 的最后一个稳定版本我尝试连接但有一个例外: 代码:
XMPPTCPConnectionConfiguration config = XMPPTCPConnectionConfiguration.builder()
.setUsernameAndPassword("testjava", "12345678")
.setServiceName(server)
.setPort(5222)
.setHost(server) .setSecurityMode(ConnectionConfiguration.SecurityMode.required)
.setDebuggerEnabled(true)
.build();
AbstractXMPPConnection conn2 = new XMPPTCPConnection(config);
conn2.connect();
日志:
10:35:31 AM SENT (0): <stream:stream xmlns='jabber:client' to='***.pro' xmlns:stream='http://etherx.jabber.org/streams' version='1.0' from='testjava@***.pro' xml:lang='en'>
10:35:31 AM RECV (0): <?xml version='1.0' encoding='UTF-8'?><stream:stream xmlns:stream="http://etherx.jabber.org/streams" xmlns="jabber:client" from="***.pro" id="xb9bamjxw" xml:lang="en" version="1.0">
10:35:32 AM RECV (0): <stream:features><starttls xmlns="urn:ietf:params:xml:ns:xmpp-tls"><required/></starttls><mechanisms xmlns="urn:ietf:params:xml:ns:xmpp-sasl"><mechanism>PLAIN</mechanism></mechanisms></stream:features>
10:35:32 AM SENT (0): <starttls xmlns='urn:ietf:params:xml:ns:xmpp-tls'></starttls>
10:35:32 AM RECV (0): <proceed xmlns="urn:ietf:params:xml:ns:xmpp-tls"/>
Exception in thread "main" org.jivesoftware.smack.SmackException: javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader.parsePackets(XMPPTCPConnection.java:1010)
at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader.access$200(XMPPTCPConnection.java:937)
at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader$1.run(XMPPTCPConnection.java:952)
at java.lang.Thread.run(Thread.java:745)
我使用 Pidgin 并已建立与服务器的连接。我需要在我的代码中添加什么来支持 TLS 身份验证?
【问题讨论】:
Smack 4 throws "SSLHandshakeException: ValidatorException: SunCertPathBuilderException" on connect的可能重复 【参考方案1】:您的服务器似乎没有“有效”证书。购买有效证书,或将库配置为允许“不受信任”证书。
【讨论】:
以上是关于hava jabber-bot。 XMPP over smack 4.2.0 with TLS的主要内容,如果未能解决你的问题,请参考以下文章
如何使用 Smack 在 XMPP openfire 中了解打字状态
如何使用 Smack 在 XMPP openfire 中了解打字状态
Field does not hava a corresponding compenont
[2016-3-18]OMG美语每日笔记-Hava you ever felt so devastated after not being chosen by a club you really wa