2017-11-04 17 views
0

Oreo 장치에서 작동하도록하고 있습니다. 이것은 Oreo가 아닌 오래된 장치에서는 완벽하게 작동합니다. 내가 악수 문제가 있었다 그래서 나는 클라이언트에Retrofit 2.3 8.0 장치에서 수용 가능한 프로토콜을 찾을 수 없습니다.

ConnectionSpec spec = new ConnectionSpec.Builder(ConnectionSpec.MODERN_TLS) 
    .tlsVersions(TlsVersion.TLS_1_2) 
    .cipherSuites(CipherSuite.TLS_DHE_RSA_WITH_AES_256_CBC_SHA) 
    .build(); 

그리고

.connectionSpecs(Collections.singletonList(spec)) 

을 추가했다. 전체 코드 :

private static Retrofit getClient() { 
    HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor(); 
    interceptor.setLevel(HttpLoggingInterceptor.Level.BODY); 
    ConnectionSpec spec = new ConnectionSpec.Builder(ConnectionSpec.MODERN_TLS) 
      .tlsVersions(TlsVersion.TLS_1_2) 
      .cipherSuites(CipherSuite.TLS_DHE_RSA_WITH_AES_256_CBC_SHA) 
      .build(); 

    OkHttpClient client = new OkHttpClient.Builder() 
      .addInterceptor(interceptor) 
      .connectionSpecs(Collections.singletonList(spec)) 
      .build(); 

    if (retrofit == null) { 
     retrofit = new Retrofit.Builder() 
       .baseUrl(BASE_URL) 
       .addConverterFactory(GsonConverterFactory.create()) 
       .client(client) 
       .build(); 
    } 
    return retrofit; 
} 

하지만 지금은 오류

D/OkHttp: <-- HTTP FAILED: java.net.UnknownServiceException: Unable to find acceptable protocols. isFallback=false, modes=[ConnectionSpec(cipherSuites=[TLS_DHE_RSA_WITH_AES_256_CBC_SHA], tlsVersions=[TLS_1_3], supportsTlsExtensions=true)], supported protocols=[TLSv1, TLSv1.1, TLSv1.2]

D/Error: Unable to find acceptable protocols. isFallback=false, modes=[ConnectionSpec(cipherSuites=[TLS_DHE_RSA_WITH_AES_256_CBC_SHA], tlsVersions=[TLS_1_3], supportsTlsExtensions=true)], supported protocols=[TLSv1, TLSv1.1, TLSv1.2]

모든 suggetions가 있어요?

수정 지금까지 해본 결과 작동했습니다.

if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { 
      client = new OkHttpClient.Builder() 
        .addInterceptor(interceptor) 
        .build(); 
     }else { 
      ConnectionSpec spec = new ConnectionSpec.Builder(ConnectionSpec.MODERN_TLS) 
        .tlsVersions(TlsVersion.TLS_1_2) 
        .cipherSuites(CipherSuite.TLS_DHE_RSA_WITH_AES_256_CBC_SHA) 
        .build(); 

      client = new OkHttpClient.Builder() 
        .addInterceptor(interceptor) 
        .connectionSpecs(Collections.singletonList(spec)) 
        .build(); 
     } 

답변

1

OkHttp는 장치에서 활성화 된 TLS 버전의 교차를 자체 연결 사양으로 사용합니다. 그리고 암호 스위트에 대해서도 마찬가지입니다.

여기서 발생하는 문제는 교차로에 웹 서버에서 지원하는 내용이 모두 포함되어 있지 않다는 것입니다.