Add and use keyfile_to_key_id() helper function

When trying to extract the key ID from a key file name, some test code
incorrectly attempts to strip all leading zeros.  This breaks tests when
keys with ID 0 are generated.  Add a new helper shell function,
keyfile_to_key_id(), which properly handles keys with ID 0 and use it in
test code whenever a key ID needs to be extracted from a key file name.
This commit is contained in:
Michał Kępień
2019-06-28 13:11:26 +02:00
parent f895e4aaf2
commit 7d6eaad1bd
13 changed files with 56 additions and 49 deletions

View File

@@ -1563,9 +1563,9 @@ ret=0
zone=example
key1=$($KEYGEN -K signer -q -f KSK -a RSASHA1 -b 1024 -n zone $zone)
key2=$($KEYGEN -K signer -q -a RSASHA1 -b 1024 -n zone $zone)
keyid2=$(echo "$key2" | sed 's/^Kexample.+005+0*\([0-9]\)/\1/')
keyid2=$(keyfile_to_key_id "$key2")
key3=$($KEYGEN -K signer -q -a RSASHA1 -b 1024 -n zone $zone)
keyid3=$(echo "$key3" | sed 's/^Kexample.+005+0*\([0-9]\)/\1/')
keyid3=$(keyfile_to_key_id "$key3")
(
cd signer || exit 1
cat example.db.in "$key1.key" "$key2.key" > example.db
@@ -3951,7 +3951,7 @@ status=$((status+ret))
# Roll the ZSK.
zsk2=$("$KEYGEN" -q -a "$DEFAULT_ALGORITHM" -b "$DEFAULT_BITS" -K ns2 -n zone "$zone")
echo "$zsk2" | sed -e 's/.*[+]//' -e 's/^0*//' > ns2/$zone.zsk.id2
keyfile_to_key_id "$zsk2" > ns2/$zone.zsk.id2
ZSK_ID2=`cat ns2/$zone.zsk.id2`
echo_i "load new ZSK $ZSK_ID2 for $zone ($n)"
@@ -4023,7 +4023,7 @@ mv ns2/$KSK.private.bak ns2/$KSK.private
# Roll the ZSK again.
zsk3=$("$KEYGEN" -q -a "$DEFAULT_ALGORITHM" -b "$DEFAULT_BITS" -K ns2 -n zone "$zone")
echo "$zsk3" | sed -e 's/.*[+]//' -e 's/^0*//' > ns2/$zone.zsk.id3
keyfile_to_key_id "$zsk3" > ns2/$zone.zsk.id3
ZSK_ID3=`cat ns2/$zone.zsk.id3`
echo_i "load new ZSK $ZSK_ID3 for $zone ($n)"