matteocorti / check_ssl_cert

A shell script (that can be used as a Nagios/Icinga plugin) to check an SSL/TLS connection.
GNU General Public License v3.0
368 stars 132 forks source link

add support for certificate check inside jks-files #423

Closed claudioth closed 1 year ago

claudioth commented 1 year ago

Proposed Changes

After using your wonderful script for a while, I realized that it would be easy to extend it to also validate certificates in a Java KeyStore/Truststore. To do this, the script would have to be extended as follows:

  1. usage() + parse_command_line_options(): A Java KeyStore/Truststore is a collection of certificates, so before checking, it must be determined which one should be checked. For this purpose the alias of the certificate could be specified by parameters like "--jks-alias ".
  2. fetch_certificate(): Before the check, the certificate to be checked would have to be exported from the KeyStore/Truststore and converted to PEM. "${KEYTOOLBIN}" -exportcert -rfc -keystore "${FILE}" -alias "${JKSALIAS}" -file "${CERT}" -storepass "${PASSWORD_SOURCE}" (I was not shure where you would like to check the existence of "keytool", you may whant to move it to another part in the code)

After these two steps, all functions of your script can be used.

I already implemented it based on your actual code. To test the code I attached a Java Truststore (default cacerts from a jdk) and a Java KeyStore (keystore.jks containing an actual cert from google). key_and_truststore.zip

Test:

matteocorti commented 1 year ago

Thanks! I will take a look as soon as possible