Reputation: 71
When I try to connect to a URL I am getting the below log trace
2017-03-18 00:11:54.519 ERROR: javax.net.ssl.SSLHandshakeException: java.security.cert.CertificateNotYetValidException: NotBefore: Tue Mar 14 13:53:28 PDT 2017
The Server's certificate is valid from Mar 14 2017 and I am trying to connect on Mar 18 2017 still why this error occurs? Is there any other cause for this exception?
Most of the answers for similar question suggest to check the systems time but in this case the logger is added with system time, so it is not the case.
Upvotes: 4
Views: 6486
Reputation: 3332
I had this error in Android TV emulator. Then I noticed that the time and date of the device were wrong. Updating it fixed the problem.
Upvotes: 2
Reputation: 377
In my case, the emulator date wasn't correct, it was set to 8 days earlier then the actual date.
Edit: As a tip, i would recommend to use Cold Boot for the emulator. Because the date and time only get updated on Cold boot, but not on Quick boot.
Upvotes: 14
Reputation: 71
The issue is occurring because of a custom Trust manager created in our code which takes a validation date as input while creation and when the date value is not null it takes that date as current date and validates the certificate against that date.
Thus when the trust manager is created with old date then it causes java.security.cert.CertificateNotYetValidException for certificates whose valid from date is in future to the configured date.
Upvotes: 1