Goal: I want this url ( https://localhost:8083 ) to use my self-signed certiciate on my localmachine.
First, I referenced this url (https://gist.github.com/oslego/f13e136ffeaa6174289a) and what I did was:
$ openssl genrsa -des3 -out server.orig.key 2048
$ openssl rsa -in server.orig.key -out server.key
$ openssl req -new -key server.key -out server.csr
Country Name (2 letter code) [AU]:
...
Common Name: localhost.ssl
...
$ openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt
$ echo "127.0.0.1 localhost.ssl" | sudo tee -a /private/etc/hosts
I then convert server.crt to server.pem by executing
$ openssl x509 -in server.crt -out keystore.pem -outform PEM
$ keytool -import -trustcacerts -alias testCert -file keystore.pem -keypass testpassword -keystore keystore.jks -storepass testpassword
$ keytool -export -alias mykey -keystore keystore.jks -rfc -file truststore
$ vim keystore.password // manually created keystore.password via vim
But when I access to https://localhost:8083, it doesn't work with SSL.
Then,
I also created another certificate with
Common Name: localhost
$ echo "127.0.0.1 localhost" | sudo tee -a /private/etc/hosts
But this is not working as well. How can I make my https://localhost:8083 uses my self-signed certificate?
FYI, I use embedded Jetty and Java reads all the information correctly via config files which defines the locations of keystore.jks, truststore, and keystore.password files.
CN=localhost
is probably wrong. Hostnames always go in the SAN. If its present in the CN, then it must be present in the SAN too (you have to list it twice in this case). For more rules and reasons, see How do you sign Certificate Signing Request with your Certification Authority and How to create a self-signed certificate with openssl? You will also need to place the self-signed certificate in the appropriate trust store. – jww