spring-social / spring-social-google

Spring Social extension with connection support and an API binding for Google

Home Page:https://spring-social-google.github.io/spring-social-google/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Host name 'www.googleapis.com' does not match the certificate subject provided by the peer

sagarrao opened this issue · comments

We have a project which is used to send Google now cards from andriod apps, to users who have registered for the same through the app.

To accomplish this, I have written a controller, for eg, to add the credentials of a user to our data store(redis) so that he would be registered for sending the cards.This is exactly as per the google now api documentations and the current code uses google oauth api client and we thought of using spring-social for establishing the oauth2 connection from the controller. the reason we can't use the google apis is that it is tightly coupled with the google data store and we want to move away from the google app engine.

The controller receives 2 inputs as part of the request as per the documentation :

Exchanges an authorization code for a long-lived refresh token and stores the token. Accepts a user ID and authorization code as POST params sent from the client app. The retrieved refresh token is stored in a DataStore keyed to the user ID. Note that this is the user's ID in your app, as opposed to the user
ID associated with the Google account in the Now API.

I use the authcode in the following manner:

GoogleConnectionFactory connectionFactory = new GoogleConnectionFactory("clientId", "clientSecret");
AccessGrant accessGrant = new AccessGrant(authCode); // sent as request parameter.
Connection connection = connectionFactory.createConnection(accessGrant);

This is the exception that's thrown:

2015-05-06 18:34:45.835 ERROR 9488 --- [nio-8443-exec-3] o.a.c.c.C.[.[.[/].[disp
atcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context
with path [] threw exception [Request processing failed; nested exception is or
g.springframework.web.client.ResourceAccessException: I/O error on GET request f
or "https://www.googleapis.com/plus/v1/people/me":Host name 'www.googleapis.com'
does not match the certificate subject provided by the peer (CN=.storage.googl
eapis.com, O=Google Inc, L=Mountain View, ST=California, C=US); nested exception
is javax.net.ssl.SSLPeerUnverifiedException: Host name 'www.googleapis.com' doe
s not match the certificate subject provided by the peer (CN=
.storage.googleapi
s.com, O=Google Inc, L=Mountain View, ST=California, C=US)] with root cause

javax.net.ssl.SSLPeerUnverifiedException: Host name 'www.googleapis.com' does no
t match the certificate subject provided by the peer (CN=*.storage.googleapis.co
m, O=Google Inc, L=Mountain View, ST=California, C=US)
at org.apache.http.conn.ssl.SSLConnectionSocketFactory.verifyHostname(SS
LConnectionSocketFactory.java:466)
at org.apache.http.conn.ssl.SSLConnectionSocketFactory.createLayeredSock
et(SSLConnectionSocketFactory.java:396)
at org.apache.http.conn.ssl.SSLConnectionSocketFactory.connectSocket(SSL
ConnectionSocketFactory.java:354)
at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect
(DefaultHttpClientConnectionOperator.java:134)
at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(
PoolingHttpClientConnectionManager.java:353)
at org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClie
ntExec.java:380)
at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.
java:236)
at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java
:184)
at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:88)
at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java
:110)
at org.apache.http.impl.client.InternalHttpClixecute(InternalHttpClient.
java:184)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttp
Client.java:82)
at org.springframework.http.client.HttpComponentsClientHttpRequest.execu
teInternal(HttpComponentsClientHttpRequest.java:91)
at org.springframework.http.client.AbstractBufferingClientHttpRequest.ex
ecuteInternal(AbstractBufferingClientHttpRequest.java:48)
at org.springframework.http.client.AbstractClientHttpRequest.execute(Abs
tractClientHttpRequest.java:53)
at org.springframework.http.client.InterceptingClientHttpRequest$Request
Execution.execute(InterceptingClientHttpRequest.java:94)
at org.springframework.social.oauth2.OAuth2RequestInterceptor.intercept(
OAuth2RequestInterceptor.java:45)
at org.springframework.http.client.InterceptingClientHttpRequest$Request
Execution.execute(InterceptingClientHttpRequest.java:84)
at org.springframework.http.client.InterceptingClientHttpRequest.execute
Internal(InterceptingClientHttpRequest.java:69)
at org.springframework.http.client.AbstractBufferingClientHttpRequest.ex
ecuteInternal(AbstractBufferingClientHttpRequest.java:48)
at org.springframework.http.client.AbstractClientHttpRequest.execute(Abs
tractClientHttpRequest.java:53)
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.ja
va:569)
at org.springframework.web.client.RestTemplate.execute(RestTemplate.java
:530)
at org.springframework.web.client.RestTemplate.getForObject(RestTemplate
.java:237)
at org.springframework.social.google.api.impl.AbstractGoogleApiOperation
s.getEntity(AbstractGoogleApiOperations.java:50)
at org.springframework.social.google.api.plus.impl.PlusTemplate.getPerso
n(PlusTemplate.java:105)
at org.springframework.social.google.api.plus.impl.PlusTemplate.getGoogl
eProfile(PlusTemplate.java:110)
at org.springframework.social.google.connect.GoogleAdapter.fetchUserProf
ile(GoogleAdapter.java:51)
at org.springframework.social.google.connect.GoogleAdapter.fetchUserProf
ile(GoogleAdapter.java:31)
at org.springframework.social.google.conneleConnectionFactory.extractPro
viderUserId(GoogleConnectionFactory.java:37)
at org.springframework.social.connect.support.OAuth2ConnectionFactory.cr
eateConnection(OAuth2ConnectionFactory.java:91)
at com.espn.gnow.controller.AddCredentials.addCredentials(AddCredentials
.java:60)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at org.springframework.web.method.support.InvocableHandlerMethod.doInvok
e(InvocableHandlerMethod.java:221)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeF
orRequest(InvocableHandlerMethod.java:137)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocabl
eHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:110)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingH
andlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:776)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingH
andlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:705)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapt
er.handle(AbstractHandlerMethodAdapter.java:85)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(Dispatch
erServlet.java:959)
at org.springframework.web.servlet.DispatcherServlet.doService(Dispatche
rServlet.java:893)
at org.springframework.web.servlet.FrameworkServlet.processRequest(Frame
workServlet.java:966)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServl
et.java:857)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:618)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkSer
vlet.java:842)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
icationFilterChain.java:291)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
ilterChain.java:206)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52
)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
icationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
ilterChain.java:206)
at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInterna
l(HiddenHttpMethodFilter.java:77)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerR
equestFilter.java:107)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
icationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
ilterChain.java:206)
at org.springframework.web.filter.CharacterEncodingFilter.doFilterIntern
al(CharacterEncodingFilter.java:85)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerR
equestFilter.java:107)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
icationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
ilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperV
alve.java:219)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextV
alve.java:106)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(Authentica
torBase.java:501)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.j
ava:142)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.j
ava:79)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineVal
ve.java:88)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.jav
a:516)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp
11Processor.java:1086)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(
AbstractProtocol.java:659)
at org.apache.coyote.http11.Http11NioProtocol$Http11Connectior.process(H
ttp11NioProtocol.java:223)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpo
int.java:1558)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoin
t.java:1515)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.
java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor
.java:617)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskTh
read.java:61)
at java.lang.Thread.run(Thread.java:745)

The documentation states that the connection must happen over https so I added a self signed certificate but to no avail.

I saw that there's another ticket on similar lines :

#67 (comment)

but I couldn't really understand the fix mentioned there... Please provide any pointers for fixing this...

Ensure you are using the Apache HttpClient 4.3.x library, not 4.4.x.