accepting HTTPS connections with self-signed certificates

前端 未结 13 2086
小蘑菇
小蘑菇 2020-11-22 04:20

I\'m trying to make HTTPS connections, using HttpClient lib, but the problem is that, since the certificate isn\'t signed by a recognized Certificate Authority

13条回答
  •  盖世英雄少女心
    2020-11-22 05:03

    I wrote small library ssl-utils-android to trust particular certificate on Android.

    You can simply load any certificate by giving the filename from assets directory.

    Usage:

    OkHttpClient client = new OkHttpClient();
    SSLContext sslContext = SslUtils.getSslContextForCertificateFile(context, "BPClass2RootCA-sha2.cer");
    client.setSslSocketFactory(sslContext.getSocketFactory());
    

提交回复
热议问题