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78eMcQbSrXZ
G0imQfZgZYxX341a288QQ69C2lf24rxi+J/aD2K+keda/mCOGQFE/GgAGHpYxYWe
1o8APgA46AtUnPx2koFs5k6EhRnCvO+tdLoTBYei3Qi4p6Q=
-----END CERTIFICATE-----

but i didn't find correct solution for my situation. Before asking this question i saw many questions, something like this solution solution

Also tried this piece of code but i don't wan't user to be involved with certificate installation:

Intent intent = KeyChain.createInstallIntent();
InputStream inputStream = getResources().openRawResource(R.raw.root_sertificate);
CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
X509Certificate cert = (X509Certificate)certFactory.generateCertificate(inputStream);
intent.putExtra(KeyChain.EXTRA_CERTIFICATE, cert.getEncoded());
intent.putExtra(KeyChain.EXTRA_NAME, "IAT Cert");
startActivityForResult(intent, 0); 

Third solution that i tried was that:

InputStream inputStream = getResources().openRawResource(R.raw.root_sertificate);
// generate certificate from cert string
CertificateFactory cf = CertificateFactory.getInstance("X.509");
Certificate cert = cf.generateCertificate(inputStream);
KeyStore trustStore  = KeyStore.getInstance(KeyStore.getDefaultType());
trustStore.load(null);//Make an empty store
trustStore.setCertificateEntry("test_alias", cert);

but here i can't find anywhere this installed certificate. I will be glad if someone can direct me to some kind of solution if it possible of course.

Karol Dowbecki
  • 43,645
  • 9
  • 78
  • 111
Kristiyan Varbanov
  • 2,439
  • 2
  • 17
  • 37
  • 3
    This sounds like a proper security vulnerability if it's allowed without user input. – Karol Dowbecki Mar 05 '19 at 15:03
  • @KarolDowbecki i saw many answers for my second solution which i tried trustStore.setCertificateEntry("test_alias", cert); but when i tried to open web site which need to read my certificate its shows that there are no certificate found – Kristiyan Varbanov Mar 05 '19 at 15:10
  • Does the website have to read certificate (2 way SSL) or does the app needs to verify the website (1 way SSL)? – Karol Dowbecki Mar 05 '19 at 15:11
  • @KarolDowbecki the website have to read certificate for sure in my situation and because of that sys admin send me .crt file and told me that i need to import this certificate in to device because site work only with trusted devices – Kristiyan Varbanov Mar 05 '19 at 15:14
  • if this certificate is client certificate for 2-way TLS authentication, then the certificate is missing the private key. You may need to ask sysadmin for private key file (maybe in PKCS#12/PFX format) and install the certificate and private key in the store. – Crypt32 Mar 05 '19 at 16:08

0 Answers0