xref: /freebsd/share/examples/uefisign/uefikeys (revision 7fdf597e96a02165cfe22ff357b857d5fa15ed8a)
1#!/bin/sh
2#
3# See uefisign(8) manual page for usage instructions.
4#
5#
6
7die() {
8	echo "$*" > /dev/stderr
9	exit 1
10}
11
12if [ $# -ne 1 ]; then
13	echo "usage: $0 common-name"
14	exit 1
15fi
16
17certfile="${1}.pem"
18efifile="${1}.cer"
19keyfile="${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.
23days="3650"
24subj="/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
30umask 077 || die "umask 077 failed"
31
32openssl genrsa -out "${keyfile}" 2048 2> /dev/null || die "openssl genrsa failed"
33openssl req -new -x509 -sha256 -days "${days}" -subj "${subj}" -key "${keyfile}" -out "${certfile}" || die "openssl req failed"
34openssl x509 -inform PEM -outform DER -in "${certfile}" -out "${efifile}" || die "openssl x509 failed"
35
36echo "certificate: ${certfile}; private key: ${keyfile}; certificate to enroll in UEFI: ${efifile}"
37