Okhttp: javax.net.ssl.SSLHandshakeException: Chain validation failed

Created on 22 Feb 2017  Â·  16Comments  Â·  Source: square/okhttp

This error occurs only in Android Nougat and above when use self-signed certificate。

Most helpful comment

I can reproduce anytime i set my system clock into the future (testing 1 month ahead of the current time)

All 16 comments

targetSdkVersion 22
compileSdkVersion 25

Can someone explain the reason why this issue was closed? Was it fixed? Or it's not a valid issue (why)?

We see this issue on Android 7.0 with the latest version 3.8.1.

It happens only in the first time when we try to make a https post request after device bootups.
After that, it just works fine.

I have the same issue on android emulator with API 26

OkHttp version: 3.8.0
targetSdkVersion: 25
compileSdkVersion: 25

With api 22 the request works!

Is anyone monitoring this? It'll be nice if someone makes a comment.

Creating an executable test case is the best way to get something fixed.

When trying to implement a test case, I found out the possible cause for my issue.

The device I'm using always resets its system time to a fixed time in the past when booting up, and updates the time to the current time shortly after. The certificate verification fails if the https request is made before the system time is updated.

Not related to okhttp. Should have found this before coming to here. Sorry for the trouble.

Not related to okhttp.

get it

I can reproduce it 100% with an xiaomi mi a1. On nexus 9, 10, 6p, pixel, essential ph1 works.

I can reproduce anytime i set my system clock into the future (testing 1 month ahead of the current time)

@scottkruse so SSL and faking time don't mix well. e.g. let's encrypt use certificates for 90 days, so many popular sites will issue certificates that have expired in the next month.

It works for me,thank you

When trying to implement a test case, I found out the possible cause for my issue.

The device I'm using always resets its system time to a fixed time in the past when booting up, and updates the time to the current time shortly after. The certificate verification fails if the https request is made before the system time is updated.

Not related to okhttp. Should have found this before coming to here. Sorry for the trouble.

Did it not work at the wrong time? How to fix it?

Did it not work at the wrong time? How to fix it?

If the system time is set to time point at which the server certificate is not valid, https will fail.

We fixed it by waiting for system time to be updated before making any https requests.

I fixed it by just changing the api's base url from "https" to "http"

Was this page helpful?
0 / 5 - 0 ratings