How to use smack XMPP library to process TLS certificates in Java

Hi, everyone I have just started using XMPP in Java, including server and client

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 use Pidgin to test my server, a warning window will pop up and tell me that the certificate is invalid, as well as a button in case I want to add an exception

I want to do the same thing with smack API, but I don't know how to do it

On my smack API, I use something like this:

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

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

    connection.login(userName,password);

So that's it What is required to accept or reject an invalid certificate? Thanks for your help.

Solution

In the integration test of Apache vysper, we use something similar:

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

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>