Using certificate in https

I am writing an Android application. How to use a certificate in httpsinitializing a certificate from a catalog file, and not from packages?

When I have a password file, this code works:   

    KeyStore keyStore = KeyStore.getInstance ("PKCS12");
    keyStore.load (certificateIs, pass.toCharArray ());
    KeyManagerFactory kmf = KeyManagerFactory.getInstance (KeyManagerFactory.getDefaultAlgorithm ());
    kmf.init (keyStore, pass.toCharArray ());
    SSLContext sc = SSLContext.getInstance ("TLS");
    sc.init (kmf.getKeyManagers (), trustAllCerts, new java.security.SecureRandom ());
    HttpsURLConnection.setDefaultSSLSocketFactory (sc.getSocketFactory ());

But I have a certificate initialized from the der file:

    CertificateFactory cf = CertificateFactory.getInstance ("X.509");
    X509Certificate certificate = (X509Certificate) cf.generateCertificate (certBytes);

I do not know how to use this certificate through the connection https.

+3
source share
1 answer

It seems you are talking about client certificate authentication (where your Android device is the client).

-, , , , ( , ). PKCS # 12 . der, , , , . , certificate KeyManagerFactory ( X509KeyManager, getPrivateKey, ).

-, , (, , PKCS # 12).

0

Source: https://habr.com/ru/post/1771193/


All Articles