使用Cloud Endpoints对用户进行身份验证时,Android应用上的SSLHandshakeException

时间:2014-12-20 15:10:27

标签: android google-app-engine android-studio ssl-certificate google-cloud-endpoints

我在Android Studio中使用App Engine和Google Endpoints开发后端。 现在,从Android应用程序(仍然使用Android Studio开发),我想调用受身份验证保护的API。

这是端点

@ApiMethod(
        name = "signInWithGoogle",
        path = "signInWithGoogle",
        httpMethod = ApiMethod.HttpMethod.POST
)
public Profile signInWithGoogle(final User user) throws UnauthorizedException {
    if (user == null) {
        throw new UnauthorizedException("Authorization required");
    }
    Key<Profile> profileKey = Key.create(Profile.class, user.getEmail());
    Profile profile = OfyService.ofy().load().key(profileKey).now();
    return profile;
}

以下是我在一个单独的线程中调用API的方法:

    GoogleAccountCredential credential = new GoogleAccountCredential(context, Constants.AUDIENCE);
    credential.setSelectedAccountName(accountName);
    SignUser signUser = new SignUser.Builder(HTTP_TRANSPORT, JSON_FACTORY, credential).setApplicationName(Constants.APP_ENGINE_PROJECT_ID).build();
    Profile profile = signUser.signInWithGoogle().execute();

受众群体是"server:client_id:XXXXXXX.apps.googleusercontent.com",其中XXXXX是开发者控制台中声明的网络客户端ID的一部分。

如果我调用的API不受OAuth2保护,一切正常。我认为问题在于我错过了一些尝试验证用户身份的内容。

如果您需要其他信息,请问我。 我真的很困难,请帮助。

更新

我忘了我得到的错误。 当它尝试执行请求时,我得到一个SSLHandshakeException:

12-20 19:24:48.472  19810-19991/com.iseeyou.app W/System.err﹕ javax.net.ssl.SSLHandshakeException: Handshake failed
12-20 19:24:48.584  19810-19991/com.iseeyou.app W/System.err﹕ at com.android.org.conscrypt.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:374)
12-20 19:24:48.615  19810-19991/com.iseeyou.app W/System.err﹕ at com.android.okhttp.Connection.upgradeToTls(Connection.java:197)
12-20 19:24:48.635  19810-19991/com.iseeyou.app W/System.err﹕ at com.android.okhttp.Connection.connect(Connection.java:151)
12-20 19:24:48.653  19810-19991/com.iseeyou.app W/System.err﹕ at com.android.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:276)
12-20 19:24:48.673  19810-19991/com.iseeyou.app W/System.err﹕ at com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:211)
12-20 19:24:48.695  19810-19991/com.iseeyou.app W/System.err﹕ at com.android.okhttp.internal.http.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:373)
12-20 19:24:48.716  19810-19991/com.iseeyou.app W/System.err﹕ at com.android.okhttp.internal.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:106)
12-20 19:24:48.740  19810-19991/com.iseeyou.app W/System.err﹕ at com.android.okhttp.internal.http.HttpURLConnectionImpl.getOutputStream(HttpURLConnectionImpl.java:208)
12-20 19:24:48.763  19810-19991/com.iseeyou.app W/System.err﹕ at com.android.okhttp.internal.http.DelegatingHttpsURLConnection.getOutputStream(DelegatingHttpsURLConnection.java:218)
12-20 19:24:48.786  19810-19991/com.iseeyou.app W/System.err﹕ at com.android.okhttp.internal.http.HttpsURLConnectionImpl.getOutputStream(HttpsURLConnectionImpl.java:25)
12-20 19:24:48.806  19810-19991/com.iseeyou.app W/System.err﹕ at com.google.api.client.http.javanet.NetHttpRequest.execute(NetHttpRequest.java:77)
12-20 19:24:48.825  19810-19991/com.iseeyou.app W/System.err﹕ at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:965)
12-20 19:24:48.853  19810-19991/com.iseeyou.app W/System.err﹕ at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:410)
12-20 19:24:48.880  19810-19991/com.iseeyou.app W/System.err﹕ at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:343)
12-20 19:24:48.905  19810-19991/com.iseeyou.app W/System.err﹕ at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.execute(AbstractGoogleClientRequest.java:460)
12-20 19:24:48.927  19810-19991/com.iseeyou.app W/System.err﹕ at com.iseeyou.app.net.api.signUser.SignInWithGoogleJob.onRun(SignInWithGoogleJob.java:29)
12-20 19:24:48.945  19810-19991/com.iseeyou.app W/System.err﹕ at com.path.android.jobqueue.BaseJob.safeRun(BaseJob.java:108)
12-20 19:24:48.963  19810-19991/com.iseeyou.app W/System.err﹕ at com.path.android.jobqueue.JobHolder.safeRun(JobHolder.java:60)
12-20 19:24:48.985  19810-19991/com.iseeyou.app W/System.err﹕ at com.path.android.jobqueue.executor.JobConsumerExecutor$JobConsumer.run(JobConsumerExecutor.java:201)
12-20 19:24:49.001  19810-19991/com.iseeyou.app W/System.err﹕ at java.lang.Thread.run(Thread.java:818)
12-20 19:24:49.019  19810-19991/com.iseeyou.app W/System.err﹕ Caused by: javax.net.ssl.SSLProtocolException: SSL handshake aborted: ssl=0xaf848200: Failure in SSL library, usually a protocol error
12-20 19:24:49.039  19810-19991/com.iseeyou.app W/System.err﹕ error:1407743E:SSL routines:SSL23_GET_SERVER_HELLO:tlsv1 alert inappropriate fallback (external/openssl/ssl/s23_clnt.c:765 0xac46ce61:0x00000000)
12-20 19:24:49.173  19810-19991/com.iseeyou.app W/System.err﹕ at com.android.org.conscrypt.NativeCrypto.SSL_do_handshake(Native Method)
12-20 19:24:49.194  19810-19991/com.iseeyou.app W/System.err﹕ at com.android.org.conscrypt.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:302)
12-20 19:24:49.202  19810-19991/com.iseeyou.app W/System.err﹕ ... 19 more

0 个答案:

没有答案