File tree Expand file tree Collapse file tree 7 files changed +81
-1
lines changed
Expand file tree Collapse file tree 7 files changed +81
-1
lines changed Original file line number Diff line number Diff line change 1+ # Feature: gpg
2+
3+ Feature adds GnuPG (The Universal Crypto Engine) and public keys to the image to
4+ verify image signatures.
5+
6+ https://www.gnupg.org/software/index.html
7+
8+ ## Parameters
9+
10+ - ** GPG_PUBKEYS** -- List of files with public gpg keys.
11+ - ** GPG_PROG** -- The name of the gpg utility. This may be necessary if gpg is
12+ gpg-1.x and not gpg-2.x or higher.
Original file line number Diff line number Diff line change 1+ # SPDX-License-Identifier: GPL-3.0-or-later
2+ # $(call feature-requires,pipeline)
3+
4+ GPG_DATADIR = $(FEATURESDIR ) /gpg/data
5+
6+ GPG_PROG ?= gpg2
7+ GPG_PUBKEYS ?=
Original file line number Diff line number Diff line change 1+ # SPDX-License-Identifier: GPL-3.0-or-later
2+ PUT_FEATURE_DIRS += $(GPG_DATADIR )
3+ PUT_FEATURE_PROGS += $(GPG_PROG )
4+
5+ ifeq ($(GPG_PUBKEYS ) ,)
6+ $(error "GPG_PUBKEYS" must be specified)
7+ endif
8+
9+ PHONY += gpg
10+
11+ gpg : create
12+ @$(VMSG ) " Putting gpg keyring ..."
13+ @mkdir -p -- $(ROOTDIR ) /etc/initrd/gnupg
14+ @$(GPG_PROG ) --import --homedir " $( ROOTDIR) /etc/initrd/gnupg" $(GPG_PUBKEYS )
15+ @[ -e " $( ROOTDIR) " /bin/gpg ] || ln -s -- " ` type -P $( GPG_PROG) ` " " $( ROOTDIR) " /bin/gpg
16+
17+ pack : gpg
Original file line number Diff line number Diff line change @@ -131,4 +131,41 @@ pipe_failed()
131131 [ " $failed " -le " ${PIPE_RETRY:- } " ]
132132}
133133
134+ in_comma_list ()
135+ {
136+ local var arg list
137+
138+ var=" $1 " ; shift
139+
140+ list=()
141+ readarray -t -d, list < <( printf ' %s' " $1 " )
142+
143+ for arg in " ${list[@]} " ; do
144+ [ " $var " != " $arg " ] || return 0
145+ done
146+ return 1
147+ }
148+
149+ pipe_gpg_verify ()
150+ {
151+ local stepname signfile datafile err
152+
153+ stepname=" $1 " ; shift
154+ signfile=" $1 " ; shift
155+ datafile=" $1 " ; shift
156+
157+ in_comma_list " $stepname " " ${PIPE_VERIFY_SIGN-} " ||
158+ return 0
159+
160+ if [ ! -f " $signfile " ]; then
161+ message " unable to verify the signature because the signature file could not be found: $signfile "
162+ exit 2
163+ fi
164+
165+ if ! err=" $( gpg --verify --homedir /etc/initrd/gnupg " $signfile " " $datafile " ) " ; then
166+ printf >&2 ' %s\n' " $err "
167+ exit 2
168+ fi
169+ }
170+
134171fi # __pipeline_sh_functions
Original file line number Diff line number Diff line change 11register_parameter string PIPELINE
22register_parameter number PIPE_RETRY
3+ register_parameter string PIPE_VERIFY_SIGN
34register_array string PING
45register_array string GETIMAGE
56register_array string MOUNTFS
Original file line number Diff line number Diff line change @@ -14,7 +14,11 @@ if [ -n "${url##file://*}" ]; then
1414 sleep 3
1515 done
1616else
17- cp -f -- " ${url# file:// } " " $datadir /image"
17+ target=" ${url# file:// } "
18+
19+ pipe_gpg_verify " getimage" " $target .asc" " $target "
20+
21+ cp -f -- " $target " " $datadir /image"
1822fi
1923modprobe -q ' devname:loop-control' || :
2024run mount -o ro,loop " $datadir /image" " $destdir "
Original file line number Diff line number Diff line change @@ -14,6 +14,8 @@ opts="$(get_parameter MOUNTFS_OPTS)"
1414if [ ! -c " $target " ] && [ ! -b " $target " ]; then
1515 modprobe -q ' devname:loop-control' || :
1616 opts=" ${opts: +$opts ,} ro,loop"
17+
18+ pipe_gpg_verify " mountfs" " $target .asc" " $target "
1719fi
1820
1921run mount ${opts: +-o $opts } " $target " " $destdir "
You can’t perform that action at this time.
0 commit comments