Skip to content

Commit 6e0af79

Browse files
authored
Merge pull request #7 from jfut/mtls
feat: add mTLS CA and client certificate generation flow
2 parents a668b06 + d456860 commit 6e0af79

2 files changed

Lines changed: 463 additions & 33 deletions

File tree

README.md

Lines changed: 42 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,28 @@
33
![Tag](https://img.shields.io/github/tag/jfut/sslcert-cli.svg)
44
[![License](https://img.shields.io/badge/license-MIT-blue.svg)](https://opensource.org/licenses/MIT)
55

6-
sslcert-cli is a command line tool that create SSL certificate files such as a private key, CSR, and CRT.
6+
`sslcert-cli` is a command line tool that creates SSL certificate files such as a private key, CSR, and CRT, and also supports generating mTLS private CA and client certificates.
77

88
## Usage
99

1010
```bash
11-
sslcert-cli 1.1.0
11+
sslcert-cli 1.2.0
1212

13-
Create SSL certificate files such as a private key, CSR, and CRT.
13+
Create SSL certificate files such as a private key, CSR, and CRT, and also support generating mTLS private CA and client certificates.
1414

1515
Usage:
1616
sslcert-cli [-f] [-o OUTPUT_DIR] [-l KEY_BIT_LENGTH] [-p KEY_PASS_PHRASE] [-s SUBJECT] [-S] [-A SUBJECT_ALT_NAMES] [-D EXPIRE_DAYS] -n FQDN
17+
18+
sslcert-cli -m mtls [-f] [-o OUTPUT_DIR] [-l KEY_BIT_LENGTH] [-p KEY_PASS_PHRASE] [-s SUBJECT] [-D EXPIRE_DAYS] -n CA_NAME
19+
sslcert-cli -m mtls -i [-f] [-o OUTPUT_DIR] [-l KEY_BIT_LENGTH] [-p KEY_PASS_PHRASE] [-s SUBJECT] [-R CA_DIR] [-k CA_KEY_FILE] [-r CA_CRT_FILE] [-P MTLS_CA_KEY_PASS_PHRASE] [-A SUBJECT_ALT_NAMES] [-D EXPIRE_DAYS] -n CLIENT_NAME
20+
1721
sslcert-cli -c FQDN_CSR_FILE
18-
sslcert-cli -c FQDN_CRT_FILE
22+
sslcert-cli -C FQDN_CRT_FILE
1923

2024
Default options:
2125
-o Output directory (default: FQDN/YYYY-MM-DD/)
2226
-l Key bit length (default: 2048)
23-
-d Expiration date of self-signed certificate file (default: 365)
27+
-D Expiration days of certificate file (default: 365)
2428

2529
Examples:
2630
Create private key and CSR files:
@@ -37,20 +41,49 @@ Examples:
3741
Create private key and CSR files in a specific output directory:
3842
sslcert-cli -o /path/to/output/ -n example.org
3943

40-
Create private key and CSR files in a specific output directory with overwrite:
44+
Create private key and CSR files in a specific output directory with overwrite enabled:
4145
sslcert-cli -o /path/to/output/ -n example.org -f
4246

4347
Create private key, CSR and self-signed CRT files with an expiration date of 3650 days:
44-
sslcert-cli -n example.org
48+
sslcert-cli -n example.org \
4549
-s "/C=JP/ST=Tokyo/L=Shinjuku-ku/O=Example Corporation/OU=Example Group/CN=example.org/emailAddress=ssladmin@example.org" \
4650
-S -A "*.example.org,example.com" \
4751
-D 3650
4852

53+
# mTLS
54+
55+
Create mTLS private CA only:
56+
MTLS_CA_KEY_PASS_PHRASE=$(read -s -p "MTLS_CA_KEY_PASS_PHRASE: " MTLS_CA_KEY_PASS_PHRASE; echo ${MTLS_CA_KEY_PASS_PHRASE})
57+
sslcert-cli -m mtls -P "${MTLS_CA_KEY_PASS_PHRASE}" -n mtls.example.com \
58+
-s "/C=JP/ST=Tokyo/L=Shinjuku-ku/O=Example Corporation/OU=Example Group/CN=mtls.example.com" -D 36500
59+
60+
Create mTLS client certificate by auto-detecting CA files from directory:
61+
MTLS_CA_KEY_PASS_PHRASE=$(read -s -p "MTLS_CA_KEY_PASS_PHRASE: " MTLS_CA_KEY_PASS_PHRASE; echo ${MTLS_CA_KEY_PASS_PHRASE})
62+
MTLS_CLIENT_KEY_PASS_PHRASE=$(read -s -p "MTLS_CLIENT_KEY_PASS_PHRASE: " MTLS_CLIENT_KEY_PASS_PHRASE; echo ${MTLS_CLIENT_KEY_PASS_PHRASE})
63+
sslcert-cli -m mtls -i -n client1.mtls.example.com \
64+
-R mtls.example.com/YYYY-MM-DD/ \
65+
-P "${MTLS_CA_KEY_PASS_PHRASE}" \
66+
-p "${MTLS_CLIENT_KEY_PASS_PHRASE}" \
67+
-D 36500
68+
# If both client and CA pairs exist, *-mtls-ca.key/crt is preferred automatically.
69+
# If -o is specified together with -R, the -o path is used as the output directory.
70+
71+
Create mTLS client certificate with existing private CA:
72+
MTLS_CA_KEY_PASS_PHRASE=$(read -s -p "MTLS_CA_KEY_PASS_PHRASE: " MTLS_CA_KEY_PASS_PHRASE; echo ${MTLS_CA_KEY_PASS_PHRASE})
73+
MTLS_CLIENT_KEY_PASS_PHRASE=$(read -s -p "MTLS_CLIENT_KEY_PASS_PHRASE: " MTLS_CLIENT_KEY_PASS_PHRASE; echo ${MTLS_CLIENT_KEY_PASS_PHRASE})
74+
sslcert-cli -m mtls -i -n client1.example.com \
75+
-k mtls.example.com/YYYY-MM-DD/private-ca.key -r /path/to/private-ca.crt \
76+
-P "${MTLS_CA_KEY_PASS_PHRASE}" \
77+
-p "${MTLS_CLIENT_KEY_PASS_PHRASE}" \
78+
-D 36500
79+
80+
# Check
81+
4982
Check CSR file:
5083
sslcert-cli -c example.org.csr
5184

5285
Check CRT file:
53-
sslcert-cli -c example.org.crt
86+
sslcert-cli -C example.org.crt
5487

5588
Server configuration examples:
5689
Apache:
@@ -59,7 +92,7 @@ Server configuration examples:
5992
SSLCertificateChainFile /path/to/example.org.ca.crt
6093

6194
nginx:
62-
ssl_certificate /path/to/example.org.crt;
95+
ssl_certificate /path/to/example.org.fullchain.crt;
6396
ssl_certificate_key /path/to/example.org.key;
6497
```
6598

0 commit comments

Comments
 (0)