Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How correct certificate is getting picked up in JKS in ssl handshake

Tags:

java

ssl

jks

Lets say I have a JAVA client app and it tries to connect to a server (example.com) over https. Client app has a trust store JKS , which has the server's certificate and some other certificates as well. In the hand shake process when server sends it certificate to this client app, how correct certificate will be picked up from the trust store jks. i.e based on what parameters java matches the certificate sent by the server with the certificates stored in JKS.

like image 559
Jenananthan Avatar asked Oct 23 '25 14:10

Jenananthan


1 Answers

Matching is done by the certificate's Subject.

E.g. if you browse https://www.google.com/ and look at their certificate, it shows a certificate chain with:

Subject:    /C=US/ST=California/L=Mountain View/O=Google Inc/CN=www.google.com
Issued by: /C=US/O=Google Inc/CN=Google Internet Authority G2
Issued by: /C=US/O=GeoTrust Inc./CN=GeoTrust Global CA
Issues by: /C=US/O=Equifax/OU=Equifax Secure Certificate Authority

* Actually obtained using openssl s_client -connect www.google.com:443 -showcerts

The certificate will be trusted if any of these are in your truststore.

You can scan the truststore like this (assuming you have grep):

keytool -list -keystore /path/to/cacerts -storepass changeit -v | grep "CN=GeoTrust Global CA" -B 4 -A 8

To get this kind of output:

Alias name: geotrustglobalca
Creation date: Jul 18, 2003
Entry type: trustedCertEntry

Owner: CN=GeoTrust Global CA, O=GeoTrust Inc., C=US
Issuer: CN=GeoTrust Global CA, O=GeoTrust Inc., C=US
Serial number: 23456
Valid from: Tue May 21 00:00:00 EDT 2002 until: Sat May 21 00:00:00 EDT 2022
Certificate fingerprints:
         MD5:  F7:75:AB:29:FB:51:4E:B7:77:5E:FF:05:3C:99:8E:F5
         SHA1: DE:28:F4:A4:FF:E5:B9:2F:A3:C5:03:D1:A3:49:A7:F9:96:2A:82:12
         SHA256: FF:85:6A:2D:25:1D:CD:88:D3:66:56:F4:50:12:67:98:CF:AB:AA:DE:40:79:9C:72:2D:E4:D2:B5:DB:36:A7:3A
         Signature algorithm name: SHA1withRSA
         Version: 3
like image 108
Andreas Avatar answered Oct 26 '25 06:10

Andreas



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!