|
| 1 | +## 📥 Install mkcert |
| 2 | +> Do NOT download the binary directly from the Releases page, especially on macOS, as it can lead to issues. |
| 3 | +> Instead, follow the installation steps provided in the official [README](https://github.com/FiloSottile/mkcert). |
| 4 | +
|
| 5 | +```shell |
| 6 | +# Install root CA in the system trust store (requires root privileges). |
| 7 | +# The root CA is valid for 10 years. |
| 8 | +# To undo this later, you can run: mkcert -uninstall |
| 9 | +mkcert -install |
| 10 | + |
| 11 | +# Get the directory where the root CA is stored: |
| 12 | +cd "$(mkcert -CAROOT)" |
| 13 | + |
| 14 | +# In this directory, you'll find rootCA.pem and rootCA-key.pem |
| 15 | +``` |
| 16 | +## 📄 Generate Certificates |
| 17 | +```shell |
| 18 | +# Generate certificate and private key for the domain example.com and its subdomains: |
| 19 | +mkcert example.com "*.example.com" |
| 20 | +``` |
| 21 | +## 🔐 Create a Java KeyStore (JKS) |
| 22 | +```shell |
| 23 | +# Step 1: Convert to PKCS12 format (example.com.p12) |
| 24 | +openssl pkcs12 -export \ |
| 25 | + -in example.com.pem \ |
| 26 | + -inkey example.com-key.pem \ |
| 27 | + -out example.com.p12 \ |
| 28 | + -name example.com \ |
| 29 | + -CAfile rootCA.pem \ |
| 30 | + -caname root |
| 31 | + |
| 32 | +# Step 2: Import the PKCS12 file into a Java KeyStore (JKS) |
| 33 | +keytool -importkeystore \ |
| 34 | + -srckeystore example.com.p12 \ |
| 35 | + -srcstoretype PKCS12 \ |
| 36 | + -destkeystore example.com.jks \ |
| 37 | + -deststoretype JKS \ |
| 38 | + -alias example.com |
| 39 | + |
| 40 | +# 🔍 View the JKS Contents |
| 41 | +keytool -list -v -keystore example.com.jks -storepass changeit |
| 42 | +``` |
| 43 | +> You can repeat the keytool -importkeystore step multiple times to import multiple .p12 files into the same JKS. |
| 44 | +
|
| 45 | +## 📦 Install the Root CA on Another Machine |
| 46 | +```shell |
| 47 | +# 1. Copy the rootCA.pem to the target machine. |
| 48 | +# 2. Set the CAROOT environment variable to the directory containing rootCA.pem |
| 49 | +export CAROOT=$(pwd) |
| 50 | + |
| 51 | +# 3. Verify the environment variable |
| 52 | +echo $CAROOT |
| 53 | + |
| 54 | +# 4. Install the root CA into the local trust store on the target machine |
| 55 | +mkcert -install |
| 56 | +``` |
| 57 | +> ⚠️ Note: Ensure the JAVA_HOME environment variable is correctly set on the machine. |
| 58 | +If not, mkcert will not be able to inject the CA into the Java truststore. |
| 59 | + |
0 commit comments