加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

如何在java中使用Smack XMPP库处理TLS证书

发布时间:2020-12-15 08:39:43 所属栏目:Java 来源:网络整理
导读:嗨,大家好.我刚刚开始在 Java中使用XMPP,包括服务器端和客户端端. 在服务器端,我使用的是Apache Vysper 0.7,在客户端,我使用的是Ignite Smack 3.1.0 我正在使用apache vysper演示页面中的一个小型XMPP嵌入式服务器,使用源代码附带的TLS证书: XMPPServer ser
嗨,大家好.我刚刚开始在 Java中使用XMPP,包括服务器端和客户端端.
在服务器端,我使用的是Apache Vysper 0.7,在客户端,我使用的是Ignite Smack 3.1.0
我正在使用apache vysper演示页面中的一个小型XMPP嵌入式服务器,使用源代码附带的TLS证书:

XMPPServer server = new XMPPServer("localhost");  

    StorageProviderRegistry providerRegistry = new MemoryStorageProviderRegistry();  

    AccountManagement accountManagement = (AccountManagement) providerRegistry.retrieve(AccountManagement.class);  

    Entity user = EntityImpl.parseUnchecked("user@localhost");  
    accountManagement.addUser(user,"password");

    server.setStorageProviderRegistry(providerRegistry);  

    server.addEndpoint(new TCPEndpoint());  

    server.setTLSCertificateInfo(new File("bogus_mina_tls.cert"),"boguspw");  

    server.start();  
    System.out.println("Vysper server is running...");

问题是这不是正确/有效的证书.如果我使用pidgin测试我的服务器,会弹出一个警告窗口并告诉我证书无效,以及一个按钮,以防我想为此添加例外.

我想要的是用Smack api做同样的事情,但我不知道怎么做.

在我的smack api上我使用的是这样的东西:

ConnectionConfiguration config = new ConnectionConfiguration("localhost",5222,"localhost");
    config.setSASLAuthenticationEnabled(false);

    connection = new XMPPConnection(config);
    connection.connect();

    connection.login(userName,password);

所以这就是.接受或拒绝无效证书需要做什么?
谢谢你的帮助.

解决方法

在Apache Vysper的集成测试中,我们使用类似的东西:

ConnectionConfiguration connectionConfiguration = new ConnectionConfiguration("localhost",5222);
connectionConfiguration.setSecurityMode(ConnectionConfiguration.SecurityMode.required);
connectionConfiguration.setSASLAuthenticationEnabled(true);
connectionConfiguration.setKeystorePath("src/main/resources/bogus_mina_tls.cert");
connectionConfiguration.setTruststorePath("src/main/resources/bogus_mina_tls.cert");
connectionConfiguration.setTruststorePassword("boguspw");

参见例如:https://svn.apache.org/repos/asf/mina/vysper/trunk/server/core-inttest/src/test/java/org/apache/vysper/xmpp/modules/extension/xep0199_xmppping/AbstractIntegrationTestCase.java

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读