Gentoo Archives: gentoo-dev

From: "Haelwenn (lanodan) Monnier" <contact@×××××××××.me>
To: gentoo-dev@l.g.o
Subject: Re: [gentoo-dev] [PATCH] verify-sig.eclass: add app-crypt/signify support
Date: Wed, 08 Dec 2021 12:54:53
Message-Id: YbCrEbA8UL761X3F@cloudsdale.the-delta.net.eu.org
In Reply to: [gentoo-dev] [PATCH] verify-sig.eclass: add app-crypt/signify support by Anna Vyalkova
1 Nice patch, got few things that I think should be changed though:
2
3 [2021-12-08 07:54:04+0500] Anna Vyalkova:
4 >+case ${VERIFY_SIG_IMPL} in
5 >+ gnupg)
6 >+ BDEPEND="
7 >+ verify-sig? (
8 >+ app-crypt/gnupg
9 >+ >=app-portage/gemato-16
10 >+ )"
11 >+ ;;
12 >+ signify)
13 >+ BDEPEND="verify-sig? ( app-crypt/signify )"
14
15 Might be worth it to depend on app-crypt/minisign instead or depend on any.
16 minisign is already stabilized and I slightly prefer it's implementation over
17 the ported signify as there is no vendoring.
18 That said minisign could be considered bloated compared to signify.
19
20
21 > verify-sig_verify_detached() {
22 > local file=${1}
23 > local sig=${2}
24 > local key=${3:-${VERIFY_SIG_OPENPGP_KEY_PATH}}
25 >
26 > [[ -n ${key} ]] ||
27 > die "${FUNCNAME}: no key passed and VERIFY_SIG_OPENPGP_KEY_PATH unset"
28 >
29 > local extra_args=()
30 > [[ ${VERIFY_SIG_OPENPGP_KEY_REFRESH} == yes ]] || extra_args+=( -R )
31 >- [[ -n ${VERIFY_SIG_OPENPGP_KEYSERVER+1} ]] && extra_args+=(
32 >- --keyserver "${VERIFY_SIG_OPENPGP_KEYSERVER}"
33 >- )
34 >+ if [[ -n ${VERIFY_SIG_OPENPGP_KEYSERVER+1} ]]; then
35 >+ [[ ${VERIFY_SIG_IMPL} == gnupg ]] ||
36 >+ die "${FUNCNAME}: VERIFY_SIG_OPENPGP_KEYSERVER is not supported"
37 >+
38 >+ extra_args+=(
39 >+ --keyserver "${VERIFY_SIG_OPENPGP_KEYSERVER}"
40 >+ )
41 >+ fi
42 >
43 > # GPG upstream knows better than to follow the spec, so we can't
44 > # override this directory. However, there is a clean fallback
45 > # to GNUPGHOME.
46 > addpredict /run/user
47 >
48 > local filename=${file##*/}
49 > [[ ${file} == - ]] && filename='(stdin)'
50 > einfo "Verifying ${filename} ..."
51 >- gemato gpg-wrap -K "${key}" "${extra_args[@]}" -- \
52 >- gpg --verify "${sig}" "${file}" ||
53 >- die "PGP signature verification failed"
54 >+ case ${VERIFY_SIG_IMPL} in
55 >+ gnupg)
56 >+ gemato gpg-wrap -K "${key}" "${extra_args[@]}" -- \
57 >+ gpg --verify "${sig}" "${file}" ||
58 >+ die "PGP signature verification failed"
59 >+ ;;
60 >+ signify)
61 >+ signify -V -p "${key}" -m "${file}" -x "${sig}" ||
62 >+ die "PGP signature verification failed"
63
64 Should be something like "Signify signature verification failed".
65
66 >+ ;;
67 >+ esac
68 > }
69 >
70 > # @FUNCTION: verify-sig_verify_message
71 > # @USAGE: <file> <output-file> [<key-file>]
72 > # @DESCRIPTION:
73 > # Verify that the file ('-' for stdin) contains a valid, signed PGP
74 > # message and write the message into <output-file> ('-' for stdout).
75 > # <key-file> can either be passed directly, or it defaults
76 > # to VERIFY_SIG_OPENPGP_KEY_PATH. The function dies if verification
77 > # fails. Note that using output from <output-file> is important as it
78 > # prevents the injection of unsigned data.
79 > verify-sig_verify_message() {
80 > local file=${1}
81 > local output_file=${2}
82 > local key=${3:-${VERIFY_SIG_OPENPGP_KEY_PATH}}
83 >
84 > [[ -n ${key} ]] ||
85 > die "${FUNCNAME}: no key passed and VERIFY_SIG_OPENPGP_KEY_PATH unset"
86 >
87 > local extra_args=()
88 > [[ ${VERIFY_SIG_OPENPGP_KEY_REFRESH} == yes ]] || extra_args+=( -R )
89 >- [[ -n ${VERIFY_SIG_OPENPGP_KEYSERVER+1} ]] && extra_args+=(
90 >- --keyserver "${VERIFY_SIG_OPENPGP_KEYSERVER}"
91 >- )
92 >+ if [[ -n ${VERIFY_SIG_OPENPGP_KEYSERVER+1} ]]; then
93 >+ [[ ${VERIFY_SIG_IMPL} == gnupg ]] ||
94 >+ die "${FUNCNAME}: VERIFY_SIG_OPENPGP_KEYSERVER is not supported"
95 >+
96 >+ extra_args+=(
97 >+ --keyserver "${VERIFY_SIG_OPENPGP_KEYSERVER}"
98 >+ )
99 >+ fi
100 >
101 > # GPG upstream knows better than to follow the spec, so we can't
102 > # override this directory. However, there is a clean fallback
103 > # to GNUPGHOME.
104 > addpredict /run/user
105 >
106 > local filename=${file##*/}
107 > [[ ${file} == - ]] && filename='(stdin)'
108 > einfo "Verifying ${filename} ..."
109 >- gemato gpg-wrap -K "${key}" "${extra_args[@]}" -- \
110 >- gpg --verify --output="${output_file}" "${file}" ||
111 >- die "PGP signature verification failed"
112 >+ case ${VERIFY_SIG_IMPL} in
113 >+ gnupg)
114 >+ gemato gpg-wrap -K "${key}" "${extra_args[@]}" -- \
115 >+ gpg --verify --output="${output_file}" "${file}" ||
116 >+ die "PGP signature verification failed"
117 >+ ;;
118 >+ signify)
119 >+ signify -V -e -p "${key}" -m "${output_file}" -x "${file}" ||
120 >+ die "PGP signature verification failed"
121
122 Should be something like "Signify signature verification failed".
123
124 >+# @FUNCTION: verify-sig_verify_signed_checksums
125 >+# @USAGE: <checksum-file> <algo> <files> [<key-file>]
126 >+# @DESCRIPTION:
127 >+# Verify the checksums for all files listed in the space-separated list
128 >+# <files> (akin to ${A}) using a PGP-signed <checksum-file>. <algo>
129 >+# specified the checksum algorithm (e.g. sha256). <key-file> can either
130 >+# be passed directly, or it defaults to VERIFY_SIG_OPENPGP_KEY_PATH.
131 >+#
132 >+# The function dies if PGP verification fails, the checksum file
133 >+# contains unsigned data, one of the files do not match checksums
134 >+# or are missing from the checksum file.
135 >+verify-sig_verify_signed_checksums() {
136 >+ local checksum_file=${1}
137 >+ local algo=${2}
138 >+ local files=()
139 >+ read -r -d '' -a files <<<"${3}"
140 >+ local key=${4:-${VERIFY_SIG_OPENPGP_KEY_PATH}}
141 >+
142 >+ [[ -n ${key} ]] ||
143 >+ die "${FUNCNAME}: no key passed and VERIFY_SIG_OPENPGP_KEY_PATH unset"
144 >+
145 >+ case ${VERIFY_SIG_IMPL} in
146 >+ gnupg)
147 >+ _gpg_verify_signed_checksums \
148 >+ "${checksum_file}" "${algo}" "${files[@]}" "${key}"
149 >+ ;;
150 >+ signify)
151 >+ signify -C -p "${key}" \
152 >+ -x "${checksum_file}" "${files[@]}" ||
153 >+ die "PGP signature verification failed"
154
155 Should be something like "Signify signature verification failed".

Replies

Subject Author
Re: [gentoo-dev] [PATCH] verify-sig.eclass: add app-crypt/signify support Anna Vyalkova <cyber+gentoo@×××××.in>