34

この問題 (javax.net.ssl.SSLPeerUnverifiedException: No peer certificate) に関する投稿は多数ありますが、自分に合うものは見つかりませんでした。

多くの投稿 ( thisthisなど) では、すべての証明書を受け入れることでこれを「解決」していますが、もちろん、これはテスト以外の場合には適切な解決策ではありません。

他のものはかなりローカライズされているようで、私にはうまくいきません。誰かが私に欠けている洞察を持っていることを本当に願っています。

だから、私の問題:HTTPS経由で接続し、ローカルネットワーク経由でのみアクセスできるサーバーでテストしています。ブラウザを介して必要な呼び出しを行うと、正常に機能します。証明書について文句を言う必要はありません。証明書を確認すると、すべて問題ないように見えます。

Android デバイスで試してみると、javax.net.ssl.SSLPeerUnverifiedException: No peer certificate

これを呼び出すコードは次のとおりです。

StringBuilder builder = new StringBuilder();
builder.append( /* stuff goes here*/ );

httpGet.setEntity(new UrlEncodedFormEntity(nameValuePairs));
ResponseHandler<String> responseHandler = new BasicResponseHandler();

// Execute HTTP Post Request. Response body returned as a string
HttpClient httpClient = MyActivity.getHttpClient();
HttpGet httpGet = new HttpGet(builder.toString());

String jsonResponse = httpClient.execute(httpGet, responseHandler); //Line causing the Exception

私のコードMyActivity.getHttpClient()

protected synchronized static HttpClient getHttpClient(){
    if (httpClient != null)
        return httpClient;

    HttpParams httpParameters = new BasicHttpParams();
    HttpConnectionParams.setConnectionTimeout(httpParameters, TIMEOUT_CONNECTION);
    HttpConnectionParams.setSoTimeout(httpParameters, TIMEOUT_SOCKET);
    HttpProtocolParams.setVersion(httpParameters, HttpVersion.HTTP_1_1);

    //Thread safe in case various AsyncTasks try to access it concurrently
    SchemeRegistry schemeRegistry = new SchemeRegistry();
    schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
    schemeRegistry.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443));
    ClientConnectionManager cm = new ThreadSafeClientConnManager(httpParameters, schemeRegistry);

    httpClient = new DefaultHttpClient(cm, httpParameters);

    CookieStore cookieStore = httpClient.getCookieStore();
    HttpContext localContext = new BasicHttpContext();
    localContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore);

    return httpClient;
}

どんな助けでも大歓迎です。

編集

また、別のアプリで他の SSL の問題が発生しましたが、そのSchemeRegistry部分を追加することで以前に修正されました。

編集 2

これまでのところ、Android 3.1 でしかテストしていませんが、Android 2.2 以降で動作させるにはこれが必要です。Android タブ (Android 3.1) のブラウザーでテストしたところ、証明書について不平を言います。PC ブラウザでは問題ありませんが、Android ブラウザやアプリでは問題ありません。

編集 3

iOSブラウザもそれについて不平を言っていることがわかりました。ここで説明されている証明書チェーンの問題だと思い始めています(SSL証明書は信頼されていません-モバイルのみ

4

4 に答える 4

6

In my case everything used to work fine. Suddenly after 2 days my device did not show any https site or image link.

After some investigation it turns out that My time settings was not up to date on device.

I changed my time settings properly and it worked.

于 2016-02-28T11:15:57.150 に答える
6

以下のコードを試してください:-

        BasicHttpResponse httpResponse = null;

        HttpPost httppost = new HttpPost(URL);

        HttpParams httpParameters = new BasicHttpParams();
        // Set the timeout in milliseconds until a connection is
        // established.
        int timeoutConnection = ConstantLib.CONNECTION_TIMEOUT;
        HttpConnectionParams.setConnectionTimeout(httpParameters,
                timeoutConnection);
        // Set the default socket timeout (SO_TIMEOUT)
        // in milliseconds which is the timeout for waiting for data.
        int timeoutSocket = ConstantLib.CONNECTION_TIMEOUT;
        HttpConnectionParams
                .setSoTimeout(httpParameters, timeoutSocket);

        DefaultHttpClient httpClient = new DefaultHttpClient(
                httpParameters);
        List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
        nameValuePairs.add(new BasicNameValuePair(ConstantLib.locale,
                locale));
于 2013-08-12T06:43:45.653 に答える