我正在尝试使用SSL连接smack客户端的ejabberd服务器。我获得了SSL证书,并且我在ejabberd上成功配置了https。每当我尝试用来自smack的http连接ejabber时,我都获得了成功。但是当我在ejabberd中启用https并尝试连接时,我收到错误: “证书的主机名验证失败。证书无法验证”
smack的Java代码是:
config=XMPPTCPConnectionConfiguration.builder();
//config.setUsernameAndPassword("ramsey", "123");
config.setResource("smack");
config.setServiceName("*MY Domain*");
config.setHost("*MY Domain*");
config.setPort(5222);
config.setSecurityMode(ConnectionConfiguration.SecurityMode.ifpossible);
SSLContext sc = SSLContext.getInstance("TLS");
sc.init(new KeyManager[0], new TrustManager[]{new TLSUtils.AcceptAllTrustManager()}, new SecureRandom());
config.setCustomSSLContext(sc);
conn = new XMPPTCPConnection(config.build());
conn.connect();
需要在Java代码中添加证书。请给我一些建议或参考链接。