2011-04-18 78 views
3

嗨,大家好。我刚刚开始在Java中使用XMPP,包括服务器端和客户端。 在服务器端,我使用的是Apache Vysper 0.7,在客户端,我使用的是Ignite Smack 3.1.0 我使用的是apache vysper演示页面中的一个小型XMPP嵌入式服务器,它使用源代码随附的TLS证书代码:如何使用java中的Smack XMPP库处理TLS证书

XMPPServer server = new XMPPServer("localhost"); 

    StorageProviderRegistry providerRegistry = new MemoryStorageProviderRegistry(); 

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

    Entity user = EntityImpl.parseUnchecked("[email protected]"); 
    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做同样的事情,但我不知道如何。

我嫌API我使用的是这样的:

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

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

    connection.login(userName, password); 

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

回答

6

在阿帕奇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

+0

谢谢。你的例子可以帮助我,因为它不会再伤害我的xmpp客户端,但是我正在寻找的是类似于pidgin处理这种情况的方法。例如:如果(证书有效){做某事}其他{显示警告与接受拒绝} – 2011-04-19 22:55:26

+0

任何想法如何使用smack 4 api做到这一点? – 2014-08-25 22:41:56

1

我认为你是looking

config.setSelfSignedCertificateEnabled(true) 
+0

谢谢您的回答,但现在我收到以下错误:无法处理来自xmpp服务器的传入节。你知道那是什么意思吗? – 2011-04-19 08:14:37