androidthings / weatherstation

Sensor-based peripheral sample using Android Things
Apache License 2.0
212 stars 78 forks source link

Certificate exceptions with Google Cloud Platform #5

Closed RamGude closed 7 years ago

RamGude commented 7 years ago

Hi all,

The Weather Station app runs fine on my board, when I add the google cloud bits into my project I get certificate errors as below. Any suggestions on what might be going on? More details on my steps: I did not see a raw folder under /src/main/res after I cloned the project. I created the raw directory, created a new file called credentials.json and inserted the contents of myproject.json file that was downloaded.

01-01 01:18:51.245 8855-8894/com.example.androidthings.weatherstation E/PubsubPublisher: Error publishing message javax.net.ssl.SSLHandshakeException: Unacceptable certificate: CN=Google Internet Authority G2, O=Google Inc, C=US at com.android.org.conscrypt.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:361) at com.android.okhttp.Connection.connectTls(Connection.java:235) at com.android.okhttp.Connection.connectSocket(Connection.java:199) at com.android.okhttp.Connection.connect(Connection.java:172) at com.android.okhttp.Connection.connectAndSetOwner(Connection.java:367) at com.android.okhttp.OkHttpClient$1.connectAndSetOwner(OkHttpClient.java:130) at com.android.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:329) at com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:246) at com.android.okhttp.internal.huc.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:457) at com.android.okhttp.internal.huc.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:126) at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getOutputStream(HttpURLConnectionImpl.java:257) at com.android.okhttp.internal.huc.DelegatingHttpsURLConnection.getOutputStream(DelegatingHttpsURLConnection.java:218) at com.android.okhttp.internal.huc.HttpsURLConnectionImpl.getOutputStream(HttpsURLConnectionImpl.java) at com.google.api.client.http.javanet.NetHttpRequest.execute(NetHttpRequest.java:77) at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:981) at com.google.api.client.auth.oauth2.TokenRequest.executeUnparsed(TokenRequest.java:283) at com.google.api.client.auth.oauth2.TokenRequest.execute(TokenRequest.java:307) at com.google.api.client.googleapis.auth.oauth2.GoogleCredential.executeRefreshToken(GoogleCredential.java:384) at com.google.api.client.auth.oauth2.Credential.refreshToken(Credential.java:489) at com.google.api.client.auth.oauth2.Credential.intercept(Credential.java:217) at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:868) at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:419) at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:352) at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.execute(AbstractGoogleClientRequest.java:469) at com.example.androidthings.weatherstation.PubsubPublisher$3.run(PubsubPublisher.java:158) at android.os.Handler.handleCallback(Handler.java:751) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:154) at android.os.HandlerThread.run(HandlerThread.java:61) Caused by: java.security.cert.CertificateException: Unacceptable certificate: CN=Google Internet Authority G2, O=Google Inc, C=US at com.android.org.conscrypt.TrustManagerImpl.checkTrustedRecursive(TrustManagerImpl.java:501) at com.android.org.conscrypt.TrustManagerImpl.checkTrusted(TrustManagerImpl.java:401) at com.android.org.conscrypt.TrustManagerImpl.checkTrusted(TrustManagerImpl.java:375) at com.android.org.conscrypt.TrustManagerImpl.getTrustedChainForServer(TrustManagerImpl.java:304) at android.security.net.config.NetworkSecurityTrustManager.checkServerTrusted(NetworkSecurityTrustManager.java:94) at android.security.net.config.RootTrustManager.checkServerTrusted(RootTrustManager.java:88) at com.android.org.conscrypt.Platform.checkServerTrusted(Platform.java:178) at com.android.org.conscrypt.OpenSSLSocketImpl.verifyCertificateChain(OpenSSLSocketImpl.java:596) at com.android.org.conscrypt.NativeCrypto.SSL_do_handshake(Native Method) at com.android.org.conscrypt.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:357) at com.android.okhttp.Connection.connectTls(Connection.java:235)  at com.android.okhttp.Connection.connectSocket(Connection.java:199)  at com.android.okhttp.Connection.connect(Connection.java:172)  at com.android.okhttp.Connection.connectAndSetOwner(Connection.java:367)  at com.android.okhttp.OkHttpClient$1.connectAndSetOwner(OkHttpClient.java:130)  at com.android.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:329)  at com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:246)  at com.android.okhttp.internal.huc.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:457)  at com.android.okhttp.internal.huc.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:126)  at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getOutputStream(HttpURLConnectionImpl.java:257)  at com.android.okhttp.internal.huc.DelegatingHttpsURLConnection.getOutputStream(DelegatingHttpsURLConnection.java:218)  at com.android.okhttp.internal.huc.HttpsURLConnectionImpl.getOutputStream(HttpsURLConnectionImpl.java)  at com.google.api.client.http.javanet.NetHttpRequest.execute(NetHttpRequest.java:77)  at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:981)  at com.google.api.client.auth.oauth2.TokenRequest.executeUnparsed(TokenRequest.java:283)  at com.google.api.client.auth.oauth2.TokenRequest.execute(TokenRequest.java:307)  at com.google.api.client.googleapis.auth.oauth2.GoogleCredential.executeRefreshToken(GoogleCredential.java:384)  at com.google.api.client.auth.oauth2.Credential.refreshToken(Credential.java:489)  at com.google.api.client.auth.oauth2.Credential.intercept(Credential.java:217)  at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:868)  at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:419)  at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:352)  at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.execute(AbstractGoogleClientRequest.java:469)  at com.example.androidthings.weatherstation.PubsubPublisher$3.run(PubsubPublisher.java:158)  at android.os.Handler.handleCallback(Handler.java:751)  at android.os.Handler.dispatchMessage(Handler.java:95)  at android.os.Looper.loop(Looper.java:154)  at android.os.HandlerThread.run(HandlerThread.java:61)  Caused by: java.security.cert.CertificateNotYetValidException: Certificate not valid until Wed Apr 01 00:00:00 GMT+00:00 2015 (compared to Thu Jan 01 01:18:51 GMT+00:00 1970) at com.android.org.conscrypt.OpenSSLX509Certificate.checkValidity(OpenSSLX509Certificate.java:229) 01-01 01:18:51.245 8855-8894/com.example.androidthings.weatherstation E/PubsubPublisher: at com.android.org.conscrypt.OpenSSLX509Certificate.checkValidity(OpenSSLX509Certificate.java:222) at com.android.org.conscrypt.TrustManagerImpl.checkTrustedRecursive(TrustManagerImpl.java:498) ... 37 more

RamGude commented 7 years ago

@proppy Could you take a look at this? Would be much appreciated.

proppy commented 7 years ago

Did you check the system date on your board?

RamGude commented 7 years ago

Thanks, that helped! Thanks for the quick turnaround. Appreciate it.