3

嗨,大家好。我刚刚开始在 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);

所以就在这里。我需要做什么来接受或拒绝无效证书?谢谢你的帮助。

4

2 回答 2

6

在 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

于 2011-04-19T13:01:32.743 回答
1

我想你正在寻找

config.setSelfSignedCertificateEnabled(true)
于 2011-04-19T07:22:37.273 回答