0

I would like to call GitHub API to return the list of repositories based on an arbitrary search parameter like this: https://api.github.com/search/repositories?q=custom_search_param

So the custom_search_param is declared at runtime.

I made this interface:

public interface GitHubClient {

    String BASE_URL = "https://api.github.com/";

    @GET("search/repositories")
    Call<GitHubRepo> getReposForSearchParam (@Query("q") String custom_search_param);
}

I call it in MainActivity onCreate like this:

Retrofit retrofit = new Retrofit.Builder().baseUrl(GitHubClient.BASE_URL).addConverterFactory(GsonConverterFactory.create()).build();
    GitHubClient gitHubClient = retrofit.create(GitHubClient.class);

    Call<GitHubRepo> call = gitHubClient.getReposForSearchParam("tetris");
    call.enqueue(new Callback<GitHubRepo>() {
        @Override
        public void onResponse(Call<GitHubRepo> call, Response<GitHubRepo> response) {
            Log.d("resp",response.toString());
            Log.d("respBody",response.body().toString());
        }

        @Override
        public void onFailure(Call<GitHubRepo> call, Throwable t) {
            Log.e("wentWrong", t.getMessage());
        }
    });

And I am always getting onFailure response with this message:

E/wentWrong: javax.net.ssl.SSLProtocolException: SSL handshake aborted: ssl=0xb8679dd0: Failure in SSL library, usually a protocol error error:1407742E:SSL routines:SSL23_GET_SERVER_HELLO:tlsv1 alert protocol version (external/openssl/ssl/s23_clnt.c:741 0x9db10901:0x000

00000)

Does anyone know what is going wrong here and if GitHubClient interface anottations should be declared in different way?

tynn
  • 38,113
  • 8
  • 108
  • 143
Markonioninioni
  • 402
  • 1
  • 5
  • 16
  • Did you missing the user-agent header with the api request? See https://developer.github.com/v3/#user-agent-required – Vall0n Jun 11 '18 at 12:16
  • I've added @Headers("User-Agent: mygithubusername") to getReposForSearchParam() method and its still the same – Markonioninioni Jun 11 '18 at 12:35
  • 1
    Ok, what device did you use and which api level has the device? Because there is a [ssl issue](https://stackoverflow.com/questions/29916962/javax-net-ssl-sslhandshakeexception-javax-net-ssl-sslprotocolexception-ssl-han?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa) on devices below android 4.4. – Vall0n Jun 11 '18 at 12:39
  • 1
    I think you receive this error because the [GitHub api disabled TLSv1.1](https://githubengineering.com/crypto-removal-notice/) and it seems that your client still tries to handshake with tlsv1. – Vall0n Jun 11 '18 at 12:47
  • Thanks, you are right, I was using android 4.1 emulator, now that I tried it on 6.0, I get the correct response. – Markonioninioni Jun 11 '18 at 12:54
  • I will write it as answer so that you can mark your question as resolved – Vall0n Jun 11 '18 at 13:08

1 Answers1

1

since the GitHub api has disabled TLSv1.1 you need a device or client that supports TLSv1.1 at least. So with an android device below android 4.4 it won't work. See here.

Vall0n
  • 1,601
  • 2
  • 14
  • 19