2017-04-15 118 views
0

因此,我試圖通過我的Android連接使用TLS v1.2(Let's Encrypt)的API https://api.ramein.id。採用Android> 20時,但使用的是Android < 21 android的顯示器時無法使用Android中的Retrofit 2連接到HTTPS <21

一切工作正常說:

W/dalvikvm: VFY: unable to find class referenced in signature (Ljava/nio/file/Path;) 
W/dalvikvm: VFY: unable to find class referenced in signature ([Ljava/nio/file/OpenOption;) 
I/dalvikvm: Could not find method java.nio.file.Files.newOutputStream, referenced from method okio.Okio.sink 
W/dalvikvm: VFY: unable to resolve static method 23633: Ljava/nio/file/Files;.newOutputStream (Ljava/nio/file/Path;[Ljava/nio/file/OpenOption;)Ljava/io/OutputStream; 
D/dalvikvm: VFY: replacing opcode 0x71 at 0x000a 
W/dalvikvm: VFY: unable to find class referenced in signature (Ljava/nio/file/Path;) 
W/dalvikvm: VFY: unable to find class referenced in signature ([Ljava/nio/file/OpenOption;) 
I/dalvikvm: Could not find method java.nio.file.Files.newInputStream, referenced from method okio.Okio.source 
W/dalvikvm: VFY: unable to resolve static method 23632: Ljava/nio/file/Files;.newInputStream (Ljava/nio/file/Path;[Ljava/nio/file/OpenOption;)Ljava/io/InputStream; 
D/dalvikvm: VFY: replacing opcode 0x71 at 0x000a 
D/Error: java.net.ConnectException: Failed to connect to api.ramein.id/64:ff9b::8b3b:eb77:443 

我從這裏實施的TLSSocketFactory https://gist.github.com/fkrauthan/ac8624466a4dee4fd02f

然後用它的東西像這樣:

httpClient = new OkHttpClient.Builder(); 

ConnectionSpec spec = new ConnectionSpec.Builder(ConnectionSpec.MODERN_TLS) 
       .tlsVersions(TlsVersion.TLS_1_2, TlsVersion.TLS_1_1) 
       .build(); 

if (Build.VERSION.SDK_INT < 21) { 
    X509TrustManager trustManager = TLSPatch.systemDefaultTrustManager(); 
    httpClient.sslSocketFactory(new TLSPatch.TLSSocketFactory(), trustManager); 
} 

httpClient.connectionSpecs(Collections.singletonList(spec)) 
    .readTimeout(60, TimeUnit.SECONDS); 

有沒有人有這樣的問題?

回答

0

哎呀,我想我發現了這個問題。

因爲我的API使用密碼AES_256_GCM,我認爲SSL握手總是失敗(幕後)。所以,改爲使用密碼AES_256_GCM,我將其更改爲AES_128_GCM

這是我的配置 https://gist.github.com/nmfzone/d175d66752a0c1e1f460fd559b62546f

然後,我的代碼正常工作。其實,沒有定製SSLSocketFactory在Android < 21也應該可以工作。