无法使用Android中的Retrofit 2连接到HTTPS< 21

时间:2017-04-15 07:34:37

标签: java android ssl retrofit retrofit2

因此,我尝试通过Android安装使用TLS v1.2(让我们的加密)的API https://api.*****.id

使用Android>时,一切正常20,但使用Android< 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.*****.id/64:ff9b::8b3b:eb77:443

我已经从https://gist.github.com/fkrauthan/ac8624466a4dee4fd02f

实施了TLSSocketFactory

然后使用了这样的东西:

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);

有人有这样的问题吗?

1 个答案:

答案 0 :(得分:1)

哎呀,我想,我发现了问题。

由于我的API使用密码AES_256_GCM,我认为SSL握手总是失败(在场景后面)。因此,我使用密码AES_256_GCM,将其更改为AES_128_GCM

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

然后,我的代码正常运行。实际上,Android中没有自定义SSLSocketFactory&lt; 21也应该有效。