When using Java's keytool
, you already end up with a self-signed certificate if you just use the -genkey
command.
Try this, and you'll see there is already a certificate in the keystore:
$ keytool -list -v -keystore mykeystore
If you want to get that certificate signed by a CA, you can use the CSR you generated for that purpose, and then execute these commands.
You'll need to import the root and intermediate certificates from the CA first:
$ keytool -import -alias [Authority.CA] -trustcacerts -file [authority's CA cert] -keystore ${HOSTNAME}.jks
$ keytool -import -alias [Authority.intermediate] -trustcacerts -file [authority's intermediate cert] -keystore ${HOSTNAME}.jks
$ keytool -import -alias ${HOSTNAME} -file ${HOSTNAME}.crt -keystore ${HOSTNAME}.jks
These days, there's really no reason not to get a freely-signed certificate from Let's Encrypt.