如何在java中使用Smack XMPP库处理TLS证书
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了如何在java中使用Smack XMPP库处理TLS证书,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2023字,纯文字阅读大概需要3分钟。
内容图文
![如何在java中使用Smack XMPP库处理TLS证书](/upload/InfoBanner/zyjiaocheng/742/3f70d729f43c432bbf0e8264419083d2.jpg)
嗨,大家好.我刚刚开始在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");
内容总结
以上是互联网集市为您收集整理的如何在java中使用Smack XMPP库处理TLS证书全部内容,希望文章能够帮你解决如何在java中使用Smack XMPP库处理TLS证书所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。