Skip to content

Commit 32a0dea

Browse files
author
Rico Huijbers
committed
Update to use new secret naming scheme so we can have multiple keys
1 parent 104c54f commit 32a0dea

1 file changed

Lines changed: 17 additions & 12 deletions

File tree

sign.sh

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,37 @@
11
#!/bin/bash
22
set -euo pipefail
33

4-
if [[ "${1:-}" == "" ]]; then
5-
echo "Usage: sign.sh FILE" >&2
4+
if [[ "${2:-}" == "" ]]; then
5+
echo "Usage: sign.sh ARTIFACTTYPE FILE [FILE...]" >&2
6+
echo "">&2
7+
echo "Creates detached signature as FILE.sig." >&2
68
exit 1
79
fi
810

911

1012
tmpdir=$(mktemp -d)
1113
trap "shred $tmpdir/* && rm -rf $tmpdir" EXIT
1214

13-
SECRET=CDK/SigningKey
15+
SECRET=CDK/$1/SigningKey
1416

1517
# Use secrets manager to obtain the key and passphrase into a JSON file
16-
echo "Retrieving key..." >&2
18+
echo "Retrieving key $SECRET..." >&2
1719
aws --region us-east-1 secretsmanager get-secret-value --secret-id "$SECRET" --output text --query SecretString > $tmpdir/secret.txt
1820
passphrase=$(python -c "import json; print(json.load(file('$tmpdir/secret.txt'))['Passphrase'])")
1921

2022
echo "Importing key..." >&2
2123
gpg --homedir $tmpdir --import <(python -c "import json; print(json.load(file('$tmpdir/secret.txt'))['PrivateKey'])")
2224

23-
echo "Signing $1..." >&2
24-
echo $passphrase | gpg \
25-
--homedir $tmpdir \
26-
--local-user aws-cdk@amazon.com \
27-
--batch --yes \
28-
--passphrase-fd 0 \
29-
--output $1.sig \
30-
--detach-sign $1
25+
while [[ "${2:-}" != "" ]]; do
26+
echo "Signing $2..." >&2
27+
echo $passphrase | gpg \
28+
--homedir $tmpdir \
29+
--local-user aws-cdk@amazon.com \
30+
--batch --yes \
31+
--passphrase-fd 0 \
32+
--output $2.sig \
33+
--detach-sign $2
34+
shift
35+
done
3136

3237
echo "Done!" >&2

0 commit comments

Comments
 (0)