Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Gencert with TLS1.3 compatibility #169

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 48 additions & 7 deletions scripts/kvmd-gencert
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
# #
# ========================================================================== #


set -e
export LC_ALL=C

Expand All @@ -43,21 +42,63 @@ if [ "$2" == --vnc ]; then
fi
path="/etc/kvmd/$target/ssl"

set -e

#Read Serial Number or use default all-zeros
get_serial_number() {
serialnumber=$(cat /proc/device-tree/serial-number 2>/dev/null || echo "0000000000000000")
echo "$serialnumber"
}
serial=$(get_serial_number)
san="DNS:pikvm-${serial}.local"

# Function to fetch IP addresses
get_ip_addresses() {
ip address | awk '/inet / {print $2}' | cut -d/ -f1
}

# Try to get IP addresses
ip_addresses=$(get_ip_addresses || true)
set +e

# Update SAN variable for IP certs
for ip in $ip_addresses; do
san="${san},IP:${ip}"
done

set -x

mkdir -p "$path"
rm -f "$path"/*
cd "$path"

# XXX: Why ECC?
# - https://www.leaderssl.com/articles/345-what-is-ecc-and-why-you-should-use-it
# - https://www.digitalocean.com/community/tutorials/how-to-create-an-ecc-certificate-on-nginx-for-debian-8
# - https://msol.io/blog/tech/create-a-self-signed-ecc-certificate
# Generate the OpenSSL configuration file for SAN
cat >openssl.cnf <<EOL
[ req ]
distinguished_name = req_distinguished_name
x509_extensions = v3_req
prompt = no

[ req_distinguished_name ]
C = RU
ST = Moscow
L = Moscow
O = PiKVM
OU = PiKVM
CN = localhost

[ v3_req ]
subjectAltName = ${san}
EOL

# Generate the ECC key and self-signed certificate with SAN
openssl ecparam -out server.key -name prime256v1 -genkey
openssl req -new -x509 -sha256 -nodes -key server.key -out server.crt -days 3650 \
-subj "/C=RU/ST=Moscow/L=Moscow/O=PiKVM/OU=PiKVM/CN=localhost"
openssl req -new -x509 -sha256 -nodes -key server.key -out server.crt -days 3650 -config openssl.cnf

chown "root:kvmd-$target" "$path"/*
chmod 440 "$path/server.key"
chmod 444 "$path/server.crt"
chmod 755 "$path"

# Clean up
rm -f openssl.cnf
Loading