Skip to content

Commit 8515e37

Browse files
committed
Improve cert generate.sh script
Use ECDSA curve ed25519 key instead of RSA. Minor improvements: * Add shebang * Fail script if any of the command fails and print the failed command along with the error message * Make sure to not override existing key without explicit approval * Add explanation messages for each step
1 parent 983d133 commit 8515e37

File tree

1 file changed

+25
-3
lines changed

1 file changed

+25
-3
lines changed

cert/generate.sh

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,27 @@
1+
#!/bin/sh
2+
3+
set -e
4+
# Keep track of the last executed command.
5+
trap 'last_command=$current_command; current_command=$BASH_COMMAND' DEBUG
6+
# Echo an error message before exiting.
7+
trap 'echo "\"${last_command}\" command failed with exit code $?"' ERR
8+
9+
110
cd "$(dirname "$0")"
2-
openssl genrsa -out key.pem 2048
3-
openssl req -new -out self.pem -key key.pem -subj '/CN=localhost'
11+
12+
KEY_FILE=key.pem
13+
if [[ -f "$KEY_FILE" ]]; then
14+
read -e -p "Are you sure you want to replace existing key? [y/N] " YES_NO
15+
[[ "$YES_NO" != 'y' && "$YES_NO" != 'Y' ]] && exit 0
16+
fi
17+
18+
echo "Generating private ed25519 key"
19+
openssl genpkey -algorithm ed25519 -out $KEY_FILE
20+
21+
echo "Generating certificate signing request"
22+
openssl req -new -out self.pem -key $KEY_FILE -subj '/CN=localhost'
23+
424
openssl req -text -noout -in self.pem
5-
openssl x509 -req -days 1024 -in self.pem -signkey key.pem -out cert.pem -extfile generate.ext
25+
26+
echo "Generating certificate"
27+
openssl x509 -req -days 1024 -in self.pem -signkey $KEY_FILE -out cert.pem -extfile generate.ext

0 commit comments

Comments
 (0)