[英]How to handle TLS certificate using Smack XMPP library in java
嗨,大家好。 我剛剛開始在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
我想你在找
config.setSelfSignedCertificateEnabled(true)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.