5

I have an instance of X509Certificate in java and I need to check if the issuer is trusted?

thanks gal

Gal Tamir
  • 51
  • 1
  • 3
  • You really need to check the issuer or just trust the certificate issued by the issuer? – ITCuties Mar 01 '12 at 13:12
  • I need to write a method that checks if a X509Certificate has an trusted CA issuer – Gal Tamir Mar 02 '12 at 07:26
  • boolean isTrusted(X509Certificate certificat) – Gal Tamir Mar 02 '12 at 07:27
  • Welcome to Stack Overflow. Please read [How to Ask](http://stackoverflow.com/questions/how-to-ask), [What have you tried?](http://mattgemmell.com/2008/12/08/what-have-you-tried/), and [How To Ask Questions The Smart Way](http://catb.org/esr/faqs/smart-questions.html). –  Mar 02 '12 at 09:16
  • @ITCuties: Can you please help me.. Please have a look at this question http://stackoverflow.com/questions/30184090/add-server-certificate-information-to-trust-manager-android-programmatically – Manu May 28 '15 at 13:01

1 Answers1

2

If you just have the certificate (out of context), you should build a certification path using the Java PKI Cert. Path API. If it's within the context of SSL, you should be able to use a TrustManager and check it when using your SSLContext.

This will verify whether the certificate was issued by a CA you trust (or via one of its intermediate CAs perhaps).

You may also be interested in "What data should I validate when validating X.509 certificates using Java?" (on Security.SE).

Community
  • 1
  • 1
Bruno
  • 119,590
  • 31
  • 270
  • 376
  • How to check using sslContext whether the certificate is trusted or not – Manu May 28 '15 at 12:41
  • @ManoharPerepa Get the array of `TrustManager`s from the `SSLContext`, use its first element and call `checkServerTrusted` using that cert and the certificate algorithm. – Bruno May 28 '15 at 13:01
  • Can you please have a look at this question http://stackoverflow.com/questions/30184090/add-server-certificate-information-to-trust-manager-android-programmatically @Bruno – Manu May 28 '15 at 13:02