简体   繁体   English

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

[英]How to handle TLS certificate using Smack XMPP library in java

HI everyone. 嗨,大家好。 I've just started to play a little with XMPP in java, both server and client side. 我刚刚开始在Java中使用XMPP,包括服务器端和客户端端。 On the server side I'm using Apache Vysper 0.7 and on client side I'm using Ignite Smack 3.1.0 I'm using a small XMPP embedded server from the apache vysper demo page using a TLS certificate that comes with the source code: 在服务器端我使用的是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...");

The problem is that this is not a correct/valid certificate. 问题是这不是正确/有效的证书。 If I test my server using pidgin an alert window pops up and tells me the certificate is invalid and a button in case I want to add an exception for this. 如果我使用pidgin测试我的服务器,会弹出一个警告窗口并告诉我证书无效,以及一个按钮,以防我想为此添加例外。

What I want is to do the same thing with the Smack api, but I don't know how. 我想要的是用Smack api做同样的事情,但我不知道怎么做。

on my smack api I'm using something like this: 在我的smack api上我使用的是这样的东西:

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

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

    connection.login(userName, password);

So here it is. 所以这就是。 What do I need to do to accept or decline invalid certificates ? 接受或拒绝无效证书需要做什么? Thanks for your help. 谢谢你的帮助。

In the integration tests in Apache Vysper, we use something like: 在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");

See for example: 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 例如: 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

我想你在

config.setSelfSignedCertificateEnabled(true)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM