在使用Smack api记忆Xmpp连接中的信任管理器时,如何避免在android中从客户端获得askin许可?

在使用Smack api记忆Xmpp连接中的信任管理器时,如何避免在android中从客户端获得askin许可?,android,openfire,smack,Android,Openfire,Smack,这里我使用Openfire服务器使用Smack api来聊天应用程序。在建立客户端和服务器之间的连接时,我使用了询问证书,因此我使用了记忆信任管理器 SSLContext sslContext = null; try { sslContext = SSLContext.getInstance("TLS"); sslContext.init(null,MemorizingTrustManager.getInstanceList(getApplicat

这里我使用Openfire服务器使用Smack api来聊天应用程序。在建立客户端和服务器之间的连接时,我使用了询问证书,因此我使用了记忆信任管理器

SSLContext sslContext = null;
try {
            sslContext = SSLContext.getInstance("TLS");
            sslContext.init(null,MemorizingTrustManager.getInstanceList(getApplicationContext()), new SecureRandom());
        } catch (NoSuchAlgorithmException | KeyManagementException e) {
            e.printStackTrace();
        }
        XMPPTCPConnectionConfiguration.Builder configBuilder = XMPPTCPConnectionConfiguration.builder();
        configBuilder.setCustomSSLContext(sslContext);
但问题是记忆TrustManager显示弹出窗口以获得用户的权限,如


如果有人知道,请发表你的建议。提前感谢。

如果您查看记忆TrustManager的源代码,您会发现它正在处理两个信任库。一个是系统默认信任存储,一个是应用程序信任存储。您被请求的权限意味着无法在任何商店中验证该证书。所以,一种适当的方法是将该证书加载到应用程序信任库中。这样,在ssl握手过程中,信任存储将进行内部检查并从服务器接收证书

/** Creates an instance of the MemorizingTrustManager class that falls back to a custom TrustManager.
 *
 * You need to supply the application context. This has to be one of:
 *    - Application
 *    - Activity
 *    - Service
 *
 * The context is used for file management, to display the dialog /
 * notification and for obtaining translated strings.
 *
 * @param m Context for the application.
 * @param defaultTrustManager Delegate trust management to this TM. If null, the user must accept every certificate.
 */

public MemorizingTrustManager(Context m, X509TrustManager defaultTrustManager) {
    init(m);
    this.appTrustManager = getTrustManager(appKeyStore);
    this.defaultTrustManager = defaultTrustManager;
}
在这里检查来源


因此,不要传递null,提供一个拥有服务器证书的trustmanager。

我不明白这个问题:当系统无法验证服务的证书(例如,通过安装的CAs)时,显示这个对话框正是MTM应该做的。@Flow,我能在后台接受吗。。。我需要的是,我不想向用户显示此弹出窗口,或者是否有其他方式提供证书而不是MTM。希望我的回答对您有所帮助:还有我的博客: