]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Replace duplicated code snippet with calls to helper functions
authorMichał Kępień <michal@isc.org>
Wed, 13 Jun 2018 05:47:12 +0000 (07:47 +0200)
committerMichał Kępień <michal@isc.org>
Wed, 13 Jun 2018 06:08:25 +0000 (08:08 +0200)
Reduce code duplication by replacing a code snippet repeated throughout
system tests using "trusted-keys" and/or "managed-keys" configuration
sections with calls to keyfile_to_{managed,trusted}_keys() helper
functions.

(cherry picked from commit dce66f763537450fa78045c679c53fd0ba5cbc5d)

18 files changed:
bin/tests/system/autosign/ns1/keygen.sh
bin/tests/system/dlv/ns1/sign.sh
bin/tests/system/dlv/ns3/sign.sh
bin/tests/system/dnssec/ns1/sign.sh
bin/tests/system/dnssec/ns5/sign.sh
bin/tests/system/dsdigest/ns1/sign.sh
bin/tests/system/ecdsa/ns1/sign.sh
bin/tests/system/eddsa/ns1/sign.sh
bin/tests/system/inline/ns1/sign.sh
bin/tests/system/legacy/ns7/sign.sh
bin/tests/system/mkeys/ns1/sign.sh
bin/tests/system/pending/ns1/sign.sh
bin/tests/system/resolver/ns6/keygen.sh
bin/tests/system/rootkeysentinel/ns1/sign.sh
bin/tests/system/rsabigexponent/ns1/sign.sh
bin/tests/system/sfcache/ns1/sign.sh
bin/tests/system/staticstub/ns3/sign.sh
bin/tests/system/wildcard/ns1/sign.sh

index 8fcf11bc1b0df5657db388e1dbc7ca1b1ddcfe7a..ae98c42b06d72933b14645de9700b3c33cf2499e 100644 (file)
@@ -33,28 +33,12 @@ rm $zsknopriv.private
 ksksby=`$KEYGEN -3 -q -r $RANDFILE -P now -A now+15s -fk $zone`
 kskrev=`$KEYGEN -3 -q -r $RANDFILE -R now+15s -fk $zone`
 
-cat $ksksby.key | grep -v '^; ' | $PERL -n -e '
-local ($dn, $class, $type, $flags, $proto, $alg, @rest) = split;
-local $key = join("", @rest);
-print <<EOF
-trusted-keys {
-    "$dn" $flags $proto $alg "$key";
-};
-EOF
-' > trusted.conf
+keyfile_to_trusted_keys $ksksby > trusted.conf
 cp trusted.conf ../ns2/trusted.conf
 cp trusted.conf ../ns3/trusted.conf
 cp trusted.conf ../ns4/trusted.conf
 
-cat $kskrev.key | grep -v '^; ' | $PERL -n -e '
-local ($dn, $class, $type, $flags, $proto, $alg, @rest) = split;
-local $key = join("", @rest);
-print <<EOF
-trusted-keys {
-    "$dn" $flags $proto $alg "$key";
-};
-EOF
-' > trusted.conf
+keyfile_to_trusted_keys $kskrev > trusted.conf
 cp trusted.conf ../ns5/trusted.conf
 
 echo $zskact > ../active.key
index ddd41a143705b065c955dcedfa0c5bb68b630443..b8151620ccba78e16b77979ef99fef09c20bf7d8 100755 (executable)
@@ -32,14 +32,5 @@ $SIGNER -r $RANDFILE -g -o $zone -f $outfile $zonefile > /dev/null 2> signer.err
 
 echo_i "signed $zone"
 
-grep -v '^;' $keyname2.key | $PERL -n -e '
-local ($dn, $class, $type, $flags, $proto, $alg, @rest) = split;
-local $key = join("", @rest);
-print <<EOF
-trusted-keys {
-    "$dn" $flags $proto $alg "$key";
-};
-EOF
-' > trusted.conf
+keyfile_to_trusted_keys $keyname2 > trusted.conf
 cp trusted.conf ../ns5
-
index cb991323b61ee942086945aa5579f94a06443346..bcc9922e26f164c8d94dee7e4ad6439c7ffa50a0 100755 (executable)
@@ -280,16 +280,7 @@ cat $infile $dlvsets $keyname1.key $keyname2.key >$zonefile
 $SIGNER -r $RANDFILE -o $zone -f $outfile $zonefile > /dev/null 2> signer.err || cat signer.err
 echo_i "signed $zone"
 
-
-grep -v '^;' $keyname2.key | $PERL -n -e '
-local ($dn, $class, $type, $flags, $proto, $alg, @rest) = split;
-local $key = join("", @rest);
-print <<EOF
-trusted-keys {
-    "$dn" $flags $proto $alg "$key";
-};
-EOF
-' > trusted-dlv.conf
+keyfile_to_trusted_keys $keyname2 > trusted-dlv.conf
 cp trusted-dlv.conf ../ns5
 
 cp $dssets ../ns2
index 0d74e183ad40fcab0cfbb4951f0425f624e06bc4..198d60ae1505a50572479ed6194c8d8e17b8aa78 100644 (file)
@@ -34,32 +34,17 @@ cat $infile $keyname.key > $zonefile
 $SIGNER -P -g -r $RANDFILE -o $zone $zonefile > /dev/null
 
 # Configure the resolving server with a trusted key.
-cat $keyname.key | grep -v '^; ' | $PERL -n -e '
-local ($dn, $class, $type, $flags, $proto, $alg, @rest) = split;
-local $key = join("", @rest);
-print <<EOF
-trusted-keys {
-    "$dn" $flags $proto $alg "$key";
-};
-EOF
-' > trusted.conf
-
-# ...or with a managed key.
-cat $keyname.key | grep -v '^; ' | $PERL -n -e '
-local ($dn, $class, $type, $flags, $proto, $alg, @rest) = split;
-local $key = join("", @rest);
-print <<EOF
-managed-keys {
-    "$dn" initial-key $flags $proto $alg "$key";
-};
-EOF
-' > managed.conf
+keyfile_to_trusted_keys $keyname > trusted.conf
 cp trusted.conf ../ns2/trusted.conf
 cp trusted.conf ../ns3/trusted.conf
 cp trusted.conf ../ns4/trusted.conf
 cp trusted.conf ../ns6/trusted.conf
 cp trusted.conf ../ns7/trusted.conf
+
+# ...or with a managed key.
+keyfile_to_managed_keys $keyname > managed.conf
 cp managed.conf ../ns4/managed.conf
+
 #
 #  Save keyid for managed key id test.
 #
index bcd65907eb184576383665b3b1f9ef75056750ac..93ca6767fd57116f612d3d88eec92b4c658d8e52 100644 (file)
@@ -19,15 +19,7 @@ zonefile=root.db.signed
 keyname=`$KEYGEN -r $RANDFILE -qfk $zone`
 
 # copy the KSK out first, then revoke it
-cat $keyname.key | grep -v '^; ' | $PERL -n -e '
-local ($dn, $class, $type, $flags, $proto, $alg, @rest) = split;
-local $key = join("", @rest);
-print <<EOF
-managed-keys {
-    "$dn" initial-key $flags $proto $alg "$key";
-};
-EOF
-' > revoked.conf
+keyfile_to_managed_keys $keyname > revoked.conf
 
 $SETTIME -R now ${keyname}.key > /dev/null
 
index 0d4589043f886034e9d6c0559ae792a8b2aad4e5..81156c42104dd5c5fa56968b08a0a621f8983bb7 100644 (file)
@@ -29,16 +29,7 @@ cat $infile $key1.key $key2.key > $zonefile
 $SIGNER -P -g -r $RANDFILE -o $zone $zonefile > /dev/null
 
 # Configure the resolving server with a trusted key.
-
-cat $key2.key | grep -v '^; ' | $PERL -n -e '
-local ($dn, $class, $type, $flags, $proto, $alg, @rest) = split;
-local $key = join("", @rest);
-print <<EOF
-trusted-keys {
-    "$dn" $flags $proto $alg "$key";
-};
-EOF
-' > trusted.conf
+keyfile_to_trusted_keys $key2 > trusted.conf
 cp trusted.conf ../ns2/trusted.conf
 cp trusted.conf ../ns3/trusted.conf
 cp trusted.conf ../ns4/trusted.conf
index 39eb3366309ccc919c800cca10877e7880457724..176efccc1334ef87f452e0af423df0f9d41a3b2e 100644 (file)
@@ -25,14 +25,5 @@ cat $infile $key1.key $key2.key > $zonefile
 $SIGNER -P -g -r $RANDFILE -o $zone $zonefile > /dev/null 2> signer.err || cat signer.err
 
 # Configure the resolving server with a trusted key.
-
-cat $key1.key | grep -v '^; ' | $PERL -n -e '
-local ($dn, $class, $type, $flags, $proto, $alg, @rest) = split;
-local $key = join("", @rest);
-print <<EOF
-trusted-keys {
-    "$dn" $flags $proto $alg "$key";
-};
-EOF
-' > trusted.conf
+keyfile_to_trusted_keys $key1 > trusted.conf
 cp trusted.conf ../ns2/trusted.conf
index 15814be7eff7bde689ac802379aef1dd7ceb3ce5..ee0b3094ecc19c49f1104644301dd0956d655962 100644 (file)
@@ -26,16 +26,7 @@ cat $infile $key1.key $key2.key > $zonefile
 $SIGNER -P -g -r $RANDFILE -o $zone $zonefile > /dev/null 2> signer.err || cat signer.err
 
 # Configure the resolving server with a trusted key.
-
-cat $key1.key | grep -v '^; ' | $PERL -n -e '
-local ($dn, $class, $type, $flags, $proto, $alg, @rest) = split;
-local $key = join("", @rest);
-print <<EOF
-trusted-keys {
-    "$dn" $flags $proto $alg "$key";
-};
-EOF
-' > trusted.conf
+keyfile_to_trusted_keys $key1 > trusted.conf
 cp trusted.conf ../ns2/trusted.conf
 
 cd ../ns2 && $SHELL sign.sh
index 54f54bd9221c7601909da75368ed5e609fbaa1d1..4c7dfd2a6b4ef826209c0244301a9c4c08e8f473 100644 (file)
@@ -20,14 +20,5 @@ keyname=`$KEYGEN -q -r $RANDFILE -a RSASHA1 -b 1024 -n zone -f KSK $zone`
 $SIGNER -S -x -T 1200 -o ${zone} root.db > signer.out 2>&1
 [ $? = 0 ] || cat signer.out
 
-cat ${keyname}.key | grep -v '^; ' | $PERL -n -e '
-local ($dn, $class, $type, $flags, $proto, $alg, @rest) = split;
-local $key = join("", @rest);
-print <<EOF
-trusted-keys {
-    "$dn" $flags $proto $alg "$key";
-};
-EOF
-' > trusted.conf
-
+keyfile_to_trusted_keys $keyname > trusted.conf
 cp trusted.conf ../ns6/trusted.conf
index d1613a236e31c43d8d4158990b6157f9d4663e10..344a869a52b03e160615248e889a9a95cec855e8 100755 (executable)
@@ -28,13 +28,5 @@ cat $infile $keyname1.key $keyname2.key >$zonefile
 
 $SIGNER -r $RANDFILE -g -o $zone -f $outfile -e +30y $zonefile > /dev/null 2> signer.err || cat signer.err
 
-grep -v '^;' $keyname2.key | $PERL -n -e '
-local ($dn, $class, $type, $flags, $proto, $alg, @rest) = split;
-local $key = join("", @rest);
-print <<EOF
-trusted-keys {
-    "$dn" $flags $proto $alg "$key";
-};
-EOF
-' > trusted.conf
+keyfile_to_trusted_keys $keyname2 > trusted.conf
 cp trusted.conf ../ns1
index f109b951e7c040e2ac3ab36f126333cb97c6f70f..ccc7889ad9896647d07e6904d802c76acfc03f41 100644 (file)
@@ -21,28 +21,12 @@ zskkeyname=`$KEYGEN -q -r $RANDFILE $zone`
 $SIGNER -Sg -r $RANDFILE -o $zone $zonefile > /dev/null 2>/dev/null
 
 # Configure the resolving server with a managed trusted key.
-cat $keyname.key | grep -v '^; ' | $PERL -n -e '
-local ($dn, $class, $type, $flags, $proto, $alg, @rest) = split;
-local $key = join("", @rest);
-print <<EOF
-managed-keys {
-    "$dn" initial-key $flags $proto $alg "$key";
-};
-EOF
-' > managed.conf
+keyfile_to_managed_keys $keyname > managed.conf
 cp managed.conf ../ns2/managed.conf
 cp managed.conf ../ns5/managed.conf
 
-# Configure a trusted key statement (used by delve)
-cat $keyname.key | grep -v '^; ' | $PERL -n -e '
-local ($dn, $class, $type, $flags, $proto, $alg, @rest) = split;
-local $key = join("", @rest);
-print <<EOF
-trusted-keys {
-    "$dn" $flags $proto $alg "$key";
-};
-EOF
-' > trusted.conf
+# Configure a trusted key statement (used by delv)
+keyfile_to_trusted_keys $keyname > trusted.conf
 
 #
 #  Save keyname and keyid for managed key id test.
index 324dc129329b53ddbe37ee964399f751fd86abb4..8a69e1a7be0917dd07376fa702da03a31ef8d0bf 100644 (file)
@@ -28,16 +28,7 @@ cat $infile $keyname1.key $keyname2.key > $zonefile
 $SIGNER -g -r $RANDFILE -o $zone $zonefile > /dev/null 2>&1
 
 # Configure the resolving server with a trusted key.
-
-cat $keyname2.key | grep -v '^; ' | $PERL -n -e '
-local ($dn, $class, $type, $flags, $proto, $alg, @rest) = split;
-local $key = join("", @rest);
-print <<EOF
-trusted-keys {
-    "$dn" $flags $proto $alg "$key";
-};
-EOF
-' > trusted.conf
+keyfile_to_trusted_keys $keyname2 > trusted.conf
 cp trusted.conf ../ns2/trusted.conf
 cp trusted.conf ../ns3/trusted.conf
 cp trusted.conf ../ns4/trusted.conf
index 7fbc1045c4da56a43da43a0cefdd766d31e8ee1e..7b87d97e773b5978726ae6f4a913afb930186c19 100644 (file)
@@ -30,13 +30,5 @@ zsk=`$KEYGEN -q -3 -r $RANDFILE $zone`
 cat $ksk.key $zsk.key dsset-ds.example.net$TP >> $zonefile
 $SIGNER -P -r $RANDFILE -o $zone $zonefile > /dev/null 2>&1
 
-# Configure a trusted key statement (used by delve)
-cat $ksk.key | grep -v '^; ' | $PERL -n -e '
-local ($dn, $class, $type, $flags, $proto, $alg, @rest) = split;
-local $key = join("", @rest);
-print <<EOF
-trusted-keys {
-    "$dn" $flags $proto $alg "$key";
-};
-EOF
-' > ../ns5/trusted.conf
+# Configure a trusted key statement (used by delv)
+keyfile_to_trusted_keys $ksk > ../ns5/trusted.conf
index 9f919286946ad66f211cc46afa57c725271a8424..369f75e00bd701816ee8556d04df9ed82397dfec 100644 (file)
@@ -28,16 +28,7 @@ cat $infile $keyname.key > $zonefile
 $SIGNER -P -g -r $RANDFILE -o $zone $zonefile > /dev/null
 
 # Configure the resolving server with a trusted key.
-cat $keyname.key | grep -v '^; ' | $PERL -n -e '
-local ($dn, $class, $type, $flags, $proto, $alg, @rest) = split;
-local $key = join("", @rest);
-print <<EOF
-trusted-keys {
-    "$dn" $flags $proto $alg "$key";
-};
-EOF
-' > trusted.conf
-
+keyfile_to_trusted_keys $keyname > trusted.conf
 cp trusted.conf ../ns2/trusted.conf
 cp trusted.conf ../ns3/trusted.conf
 cp trusted.conf ../ns4/trusted.conf
index 05615197647b578b6d500f421a5d9f9b068fa87a..8570855d3cfd51c9fce1e8b6a4bdf632b4e472a1 100755 (executable)
@@ -25,16 +25,7 @@ cat $infile $keyname.key > $zonefile
 $SIGNER -P -g -r $RANDFILE -o $zone $zonefile > /dev/null
 
 # Configure the resolving server with a trusted key.
-cat $keyname.key | grep -v '^; ' | $PERL -n -e '
-local ($dn, $class, $type, $flags, $proto, $alg, @rest) = split;
-local $key = join("", @rest);
-print <<EOF
-trusted-keys {
-    "$dn" $flags $proto $alg "$key";
-};
-EOF
-' > trusted.conf
-
+keyfile_to_trusted_keys $keyname > trusted.conf
 cp trusted.conf ../ns2/trusted.conf
 cp trusted.conf ../ns3/trusted.conf
 
index a17d05941cc56805a31da1b7053e99a9080ebdc5..769978bbaedc36c766e33cb2f7b689335abc276b 100644 (file)
@@ -27,24 +27,8 @@ cat $infile $keyname.key > $zonefile
 $SIGNER -P -g -r $RANDFILE -o $zone $zonefile > /dev/null
 
 # Configure the resolving server with a trusted key.
-cat $keyname.key | grep -v '^; ' | $PERL -n -e '
-local ($dn, $class, $type, $flags, $proto, $alg, @rest) = split;
-local $key = join("", @rest);
-print <<EOF
-trusted-keys {
-    "$dn" $flags $proto $alg "$key";
-};
-EOF
-' > trusted.conf
+keyfile_to_trusted_keys $keyname > trusted.conf
+cp trusted.conf ../ns2/trusted.conf
 
 # ...or with a managed key.
-cat $keyname.key | grep -v '^; ' | $PERL -n -e '
-local ($dn, $class, $type, $flags, $proto, $alg, @rest) = split;
-local $key = join("", @rest);
-print <<EOF
-managed-keys {
-    "$dn" initial-key $flags $proto $alg "$key";
-};
-EOF
-' > managed.conf
-cp trusted.conf ../ns2/trusted.conf
+keyfile_to_managed_keys $keyname > managed.conf
index 96cc5851517e94d13de3da5e2c09843b22cd434a..32af7d00ee6b600e31f3e3ce5553f715bce0239a 100755 (executable)
@@ -27,16 +27,7 @@ cat $infile $keyname1.key $keyname2.key > $zonefile
 $SIGNER -g -r $RANDFILE -o $zone $zonefile > /dev/null 2>&1
 
 # Configure the resolving server with a trusted key.
-
-cat $keyname2.key | grep -v '^; ' | $PERL -n -e '
-local ($dn, $class, $type, $flags, $proto, $alg, @rest) = split;
-local $key = join("", @rest);
-print <<EOF
-trusted-keys {
-    "$dn" $flags $proto $alg "$key";
-};
-EOF
-' > trusted.conf
+keyfile_to_trusted_keys $keyname2 > trusted.conf
 
 zone=undelegated
 infile=undelegated.db.in
@@ -47,14 +38,5 @@ cat $infile $keyname1.key $keyname2.key > $zonefile
 
 $SIGNER -g -r $RANDFILE -o $zone $zonefile > /dev/null 2>&1
 
-cat $keyname2.key | grep -v '^; ' | $PERL -n -e '
-local ($dn, $class, $type, $flags, $proto, $alg, @rest) = split;
-local $key = join("", @rest);
-print <<EOF
-trusted-keys {
-    "$dn" $flags $proto $alg "$key";
-};
-EOF
-' >> trusted.conf
-
+keyfile_to_trusted_keys $keyname2 >> trusted.conf
 cp trusted.conf ../ns2/trusted.conf
index 2c3ee9ab553becb205deb5b80cc01042e0a30437..de944230503f2bc72d3296a47d6c996dbf7301a1 100755 (executable)
@@ -57,15 +57,7 @@ cat $infile $keyname1.key $keyname2.key > $zonefile
 $SIGNER -r $RANDFILE -o $zone -f $outfile $zonefile > /dev/null 2> signer.err || cat signer.err
 echo_i "signed $zone"
 
-grep -v '^;' $keyname2.key | $PERL -n -e '
-local ($dn, $class, $type, $flags, $proto, $alg, @rest) = split;
-local $key = join("", @rest);
-print <<EOF
-trusted-keys {
-    "$dn" $flags $proto $alg "$key";
-};
-EOF
-' > private.nsec.conf
+keyfile_to_trusted_keys $keyname2 > private.nsec.conf
 
 zone=nsec3.
 infile=nsec3.db.in
@@ -94,15 +86,7 @@ cat $infile $keyname1.key $keyname2.key > $zonefile
 $SIGNER -r $RANDFILE -3 - -H 10 -o $zone -f $outfile $zonefile > /dev/null 2> signer.err || cat signer.err
 echo_i "signed $zone"
 
-grep -v '^;' $keyname2.key | $PERL -n -e '
-local ($dn, $class, $type, $flags, $proto, $alg, @rest) = split;
-local $key = join("", @rest);
-print <<EOF
-trusted-keys {
-    "$dn" $flags $proto $alg "$key";
-};
-EOF
-' > private.nsec3.conf
+keyfile_to_trusted_keys $keyname2 > private.nsec3.conf
 
 zone=.
 infile=root.db.in
@@ -117,12 +101,4 @@ cat $infile $keyname1.key $keyname2.key $dssets >$zonefile
 $SIGNER -r $RANDFILE -o $zone -f $outfile $zonefile > /dev/null 2> signer.err || cat signer.err
 echo_i "signed $zone"
 
-grep -v '^;' $keyname2.key | $PERL -n -e '
-local ($dn, $class, $type, $flags, $proto, $alg, @rest) = split;
-local $key = join("", @rest);
-print <<EOF
-trusted-keys {
-    "$dn" $flags $proto $alg "$key";
-};
-EOF
-' > trusted.conf
+keyfile_to_trusted_keys $keyname2 > trusted.conf