Skip to content

Commit 894634a

Browse files
committed
New feature to verify signature
Signed-off-by: Alexey Gladkov <[email protected]>
1 parent cdc3f9d commit 894634a

File tree

7 files changed

+81
-1
lines changed

7 files changed

+81
-1
lines changed

features/gpg/README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
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.

features/gpg/config.mk

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
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 ?=

features/gpg/rules.mk

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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

features/pipeline/data/bin/pipeline-sh-functions

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff 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+
134171
fi # __pipeline_sh_functions

features/pipeline/data/etc/initrd/cmdline.d/pipeline

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
register_parameter string PIPELINE
22
register_parameter number PIPE_RETRY
3+
register_parameter string PIPE_VERIFY_SIGN
34
register_array string PING
45
register_array string GETIMAGE
56
register_array string MOUNTFS

features/pipeline/data/lib/pipeline/getimage

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@ if [ -n "${url##file://*}" ]; then
1414
sleep 3
1515
done
1616
else
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"
1822
fi
1923
modprobe -q 'devname:loop-control' ||:
2024
run mount -o ro,loop "$datadir/image" "$destdir"

features/pipeline/data/lib/pipeline/mountfs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ opts="$(get_parameter MOUNTFS_OPTS)"
1414
if [ ! -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"
1719
fi
1820

1921
run mount ${opts:+-o $opts} "$target" "$destdir"

0 commit comments

Comments
 (0)