Skip to content

Commit 009b631

Browse files
Merge pull request #219 from puppetlabs/GH-216
Determine validation key from asc signature file
2 parents c0908a2 + 4e3e52a commit 009b631

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

tasks/download.json

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,9 @@
1414
"description": "Whether to check the integrity of the downloaded file",
1515
"default": true
1616
},
17-
"key_id": {
18-
"type": "String",
19-
"description": "The GPG key ID to use when verifying the download",
20-
"default": "4528B6CD9E61EF26"
21-
},
2217
"key_server": {
2318
"type": "String",
24-
"description": "The GPG keyserver to retrieve the GPG key from",
19+
"description": "The GPG keyserver to retrieve GPG keys from",
2520
"default": "hkp://keyserver.ubuntu.com:11371"
2621
}
2722
},

tasks/download.sh

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ EX_UNAVAILABLE=69
88
verify-file() {
99
local sig="$1"
1010
local doc="$2"
11+
local keyid
1112

1213
# The GPG binary is required to be present in order to perform file download
1314
# verification. If it is not present, return EX_UNAVAILABLE.
@@ -19,8 +20,12 @@ verify-file() {
1920
# The verification key must be present, or it must be possible to download it
2021
# from the keyserver to perform file verification. If it is not present,
2122
# return EX_UNAVAILABLE.
22-
if ! { gpg --list-keys "$PT_key_id" || gpg --keyserver "$PT_key_server" --recv-key "$PT_key_id"; } then
23-
echo "Unable to download verification key ${PT_key_id}"
23+
keyid=$(gpg --list-packets --with-colons "$sig" | awk '/:signature packet:/{print $NF; exit 0}')
24+
if [[ -z "$keyid" ]]; then
25+
echo "Unable to determine verification key from ${sig}"
26+
return "$EX_UNAVAILABLE"
27+
elif ! { gpg --list-keys "$keyid" || gpg --keyserver "$PT_key_server" --recv-key "$keyid"; } then
28+
echo "Unable to download verification key ${keyid}"
2429
return "$EX_UNAVAILABLE"
2530
fi
2631

@@ -37,14 +42,15 @@ verify-file() {
3742
download() {
3843
printf '%s\n' "Downloading: ${1}"
3944
tmp_file=$(mktemp)
40-
echo "Temporary file created at: ${tmp_file}"
45+
echo "Downloading to temporary file ${tmp_file}"
4146

4247
if curl -s -f -L -o ${tmp_file} "$1"; then
48+
echo "Moving ${tmp_file} to target path ${2}"
4349
mv "${tmp_file}" "$2"
4450
return 0
4551
else
4652
echo "Error: Curl has failed to download the file"
47-
echo "Removing temporary file: ${tmp_file}"
53+
echo "Removing temporary file ${tmp_file}"
4854
rm "${tmp_file}"
4955
return 1
5056
fi

0 commit comments

Comments
 (0)