2017-05-26 3 views
0

を投げるこれは、コードの私の作品です:アンドロイドスマッククライアントライブラリを使用してXMPPサーバーに接続しようとするとするCertPathValidatorException

XMPPTCPConnectionConfiguration.Builder connectionBuilder = 
    XMPPTCPConnectionConfiguration.builder(); 

    connectionBuilder 
      .setHost(MY_HOST) 
      .setServiceName(MY_SERVICE_NAME) 
      .setSecurityMode(ConnectionConfiguration.SecurityMode.disabled) 
      .setDebuggerEnabled(true); 


    XMPPTCPConnection connection = new   XMPPTCPConnection(connectionBuilder.build()); 
    connection.connect(); 

実行しているとき、私はこの例外を取得:

W/System.err: org.jivesoftware.smack.SmackException: javax.net.ssl.SSLHandshakeException: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found. 

誰がどんな速いを持っていますこの問題を克服するソリューション?私はSSLプロトコルなどの深い理解には興味がありません。私のプロジェクトのこの段階ではセキュリティについても気にしません。

私はSwiftアプリケーションを使用してサーバーに接続することに成功したと言いたいので、おそらくサーバー側には問題はないでしょう。前もって感謝します。

答えて

0

あなたはあなたに到達しようとしているサーバーの証明書を追加する必要があります

+0

ありがとうございますが、役に立たないです。これらは私の問題を解決する方法を示していない一般的な例です。 –

2
// Create a connection to the jabber.org server. 
    // Create the configuration for this new connection 
    InetAddress addr = null; 
    try { 
     addr = InetAddress.getByName("192.***.**.**"); 
    } catch (UnknownHostException e) { 
     e.printStackTrace(); 
    } 
    HostnameVerifier verifier = new HostnameVerifier() { 
     @Override 
     public boolean verify(String hostname, SSLSession session) { 
      return false; 
     } 
    }; 
    DomainBareJid serviceName = null; 
    try { 
     serviceName = JidCreate.domainBareFrom("localhost"); 
    } catch (XmppStringprepException e) { 
     e.printStackTrace(); 
    } 
    XMPPTCPConnectionConfiguration config = 

XMPPTCPConnectionConfiguration.builder() 
       .setUsernameAndPassword(USER_CURRENT_USER, "password") 
       .setPort(5222) 
       .setSecurityMode(ConnectionConfiguration.SecurityMode.disabled) 
       .setXmppDomain(serviceName) 
       .setHostnameVerifier(verifier) 
       .setHostAddress(addr) 
       .setDebuggerEnabled(true) 
       .build(); 

     connection = new XMPPTCPConnection(config); 
     try { 
      connection.connect(); 
     } catch (SmackException | IOException | InterruptedException | XMPPException e) { 
      e.printStackTrace(); 
     } 

...このリンクをチェクJDKトラストストアを使用するか、上記のようなホスト名の検証を無効にします。

関連する問題