]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - share/examples/uefisign/uefikeys
Merge bmake-20230909
[FreeBSD/FreeBSD.git] / share / examples / uefisign / uefikeys
1 #!/bin/sh
2 #
3 # See uefisign(8) manual page for usage instructions.
4 #
5 #
6
7 die() {
8         echo "$*" > /dev/stderr
9         exit 1
10 }
11
12 if [ $# -ne 1 ]; then
13         echo "usage: $0 common-name"
14         exit 1
15 fi
16
17 certfile="${1}.pem"
18 efifile="${1}.cer"
19 keyfile="${1}.key"
20 # XXX: Set this to ten years; we don't want system to suddenly stop booting
21 #      due to certificate expiration.  Better way would be to use Authenticode
22 #      Timestamp.  That said, the rumor is UEFI implementations ignore it anyway.
23 days="3650"
24 subj="/CN=${1}"
25
26 [ ! -e "${certfile}" ] || die "${certfile} already exists"
27 [ ! -e "${efifile}" ] || die "${efifile} already exists"
28 [ ! -e "${keyfile}" ] || die "${keyfile} already exists"
29
30 umask 077 || die "umask 077 failed"
31
32 openssl genrsa -out "${keyfile}" 2048 2> /dev/null || die "openssl genrsa failed"
33 openssl req -new -x509 -sha256 -days "${days}" -subj "${subj}" -key "${keyfile}" -out "${certfile}" || die "openssl req failed"
34 openssl x509 -inform PEM -outform DER -in "${certfile}" -out "${efifile}" || die "openssl x509 failed"
35
36 echo "certificate: ${certfile}; private key: ${keyfile}; certificate to enroll in UEFI: ${efifile}"