相关疑难解决方法(0)

未找到Android SSL连接的信任锚

我正在尝试连接到运行godaddy 256位SSL证书的IIS6盒子,我收到错误:

java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.
Run Code Online (Sandbox Code Playgroud)

一直试图确定可能导致这种情况的原因,但现在正在绘制空白.

这是我如何连接:

HttpsURLConnection conn;              
conn = (HttpsURLConnection) (new URL(mURL)).openConnection();
conn.setConnectTimeout(20000);
conn.setDoInput(true);
conn.setDoOutput(true);
conn.connect();
String tempString = toString(conn.getInputStream()); 
Run Code Online (Sandbox Code Playgroud)

ssl android ssl-certificate

156
推荐指数
10
解决办法
33万
查看次数

CertPathValidatorException:找不到证书路径的信任锚 - Retrofit Android

我正在创建一个https用于与服务器通信的android应用程序.我正在使用retrofitOkHttp提出请求.这些适用于标准http请求.以下是我遵循的步骤.

步骤1: 使用该命令从服务器获取cert文件

echo -n | openssl s_client -connect api.****.tk:443 | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > gtux.cert
Run Code Online (Sandbox Code Playgroud)

步骤2: 使用以下命令将证书转换为BKS格式

keytool -importcert -v -trustcacerts -file "gtux.cert" -alias imeto_alias -keystore "my_keystore.bks" -provider org.bouncycastle.jce.provider.BouncyCastleProvider -providerpath "bcprov-jdk16-146.jar" -storetype BKS
Run Code Online (Sandbox Code Playgroud)

它问我密码并且文件已成功创建.

第3步:

创建一个OkHttpClient并使用它来发出https请求

public class MySSLTrust {
public static OkHttpClient trustcert(Context context){
    OkHttpClient okHttpClient = new OkHttpClient();
    try {
        KeyStore ksTrust = KeyStore.getInstance("BKS");
        InputStream instream = context.getResources().openRawResource(R.raw.my_keystore);
        ksTrust.load(instream, "secret".toCharArray());
        // TrustManager decides which certificate authorities to …
Run Code Online (Sandbox Code Playgroud)

ssl android retrofit okhttp

54
推荐指数
5
解决办法
9万
查看次数

如何将 SSL 证书添加到 okHttp 双向 TLS 连接?

我已经有一个 .pem 和一个 .key 文件,我不想在本地安装/导入它,只需告诉我的客户使用它们,这可能吗?它不是自签名证书

基本上,在我的卷曲中,我做了这样的事情:

curl --key mykey.key --cert mycert.pem https://someurl.com/my-endpoint
Run Code Online (Sandbox Code Playgroud)

我已经检查过这个答案

如何在Retrofit中使用ssl证书发出https请求

还有这个https://github.com/square/okhttp/blob/master/samples/guide/src/main/java/okhttp3/recipes/CustomTrust.java(但可能没有意义,因为我没有得到该类型的对象我需要)

基本上我有我的 okHttpClient

val okHttpClient = OkHttpClient.Builder()
    .sslSocketFactory(?, ?) //here I tried to call sslSocketFactory, trustManager following the example from the CustomTrust.java
    .build()
Run Code Online (Sandbox Code Playgroud)

有什么解决方案的想法吗?

也检查了此文档,但 ssl 部分未完成,示例中也未完成

https://square.github.io/okhttp/https/#customizing-trusted-certificates-kt-java

所以我尝试这样做(基于 okhttp 示例)

private fun trustedCertificatesInputStream(): InputStream {
        val comodoRsaCertificationAuthority = (""
            + "-----BEGIN CERTIFICATE-----\n" +
            "-----END CERTIFICATE-----")
        return Buffer()
            .writeUtf8(comodoRsaCertificationAuthority)
            .inputStream()
    }


    val loggingInterceptor = HttpLoggingInterceptor().apply {
        level = HttpLoggingInterceptor.Level.BODY
    }


    fun createClient() : OkHttpClient …
Run Code Online (Sandbox Code Playgroud)

java ssl kotlin retrofit okhttp

6
推荐指数
2
解决办法
2万
查看次数

标签 统计

ssl ×3

android ×2

okhttp ×2

retrofit ×2

java ×1

kotlin ×1

ssl-certificate ×1