sign.sh revision c73d8c1b72ddc3330cfc21e2070dffabca324bf7
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews#!/bin/sh -e
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews#
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews# Copyright (C) 2004, 2006-2010 Internet Systems Consortium, Inc. ("ISC")
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews# Copyright (C) 2000-2003 Internet Software Consortium.
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews#
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews# Permission to use, copy, modify, and/or distribute this software for any
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews# purpose with or without fee is hereby granted, provided that the above
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews# copyright notice and this permission notice appear in all copies.
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews#
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews# THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews# AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews# LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews# OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews# PERFORMANCE OF THIS SOFTWARE.
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews# $Id: sign.sh,v 1.39 2010/08/13 06:46:25 marka Exp $
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews
4a53e3c2b83c476a93148eaee0272649beb221caMark AndrewsSYSTEMTESTTOP=../..
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews. $SYSTEMTESTTOP/conf.sh
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews
4a53e3c2b83c476a93148eaee0272649beb221caMark AndrewsRANDFILE=../random.data
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrewszone=example.
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrewsinfile=example.db.in
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrewszonefile=example.db
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews# Have the child generate a zone key and pass it to us.
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews( cd ../ns3 && sh sign.sh )
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrewsfor subdomain in secure bogus dynamic keyless nsec3 optout nsec3-unknown \
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews optout-unknown multiple rsasha256 rsasha512 kskonly
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrewsdo
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews cp ../ns3/dsset-$subdomain.example. .
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrewsdone
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrewskeyname1=`$KEYGEN -q -r $RANDFILE -a DSA -b 768 -n zone $zone`
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrewskeyname2=`$KEYGEN -q -r $RANDFILE -a DSA -b 768 -n zone $zone`
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrewscat $infile $keyname1.key $keyname2.key >$zonefile
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews$SIGNER -P -g -r $RANDFILE -o $zone -k $keyname1 $zonefile $keyname2 > /dev/null
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews#
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews# lower/uppercase the signature bits with the exception of the last characters
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews# changing the last 4 characters will lead to a bad base64 encoding.
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews#
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews$CHECKZONE -D -q -i local $zone $zonefile.signed |
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrewsawk '
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrewstolower($1) == "bad-cname.example." && $4 == "RRSIG" && $5 == "CNAME" {
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews for (i = 1; i <= NF; i++ ) {
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews if (i <= 12) {
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews printf("%s ", $i);
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews continue;
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews }
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews prefix = substr($i, 1, length($i) - 4);
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews suffix = substr($i, length($i) - 4, 4);
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews if (i > 12 && tolower(prefix) != prefix)
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews printf("%s%s", tolower(prefix), suffix);
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews else if (i > 12 && toupper(prefix) != prefix)
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews printf("%s%s", toupper(prefix), suffix);
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews else
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews printf("%s%s ", prefix, suffix);
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews }
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews printf("\n");
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews next;
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews}
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrewstolower($1) == "bad-dname.example." && $4 == "RRSIG" && $5 == "DNAME" {
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews for (i = 1; i <= NF; i++ ) {
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews if (i <= 12) {
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews printf("%s ", $i);
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews continue;
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews }
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews prefix = substr($i, 1, length($i) - 4);
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews suffix = substr($i, length($i) - 4, 4);
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews if (i > 12 && tolower(prefix) != prefix)
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews printf("%s%s", tolower(prefix), suffix);
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews else if (i > 12 && toupper(prefix) != prefix)
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews printf("%s%s", toupper(prefix), suffix);
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews else
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews printf("%s%s ", prefix, suffix);
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews }
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews printf("\n");
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews next;
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews}
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews{ print; }' > $zonefile.signed++ && mv $zonefile.signed++ $zonefile.signed
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews# Sign the privately secure file
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrewsprivzone=private.secure.example.
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrewsprivinfile=private.secure.example.db.in
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrewsprivzonefile=private.secure.example.db
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrewsprivkeyname=`$KEYGEN -q -r $RANDFILE -a RSAMD5 -b 768 -n zone $privzone`
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrewscat $privinfile $privkeyname.key >$privzonefile
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews$SIGNER -P -g -r $RANDFILE -o $privzone -l dlv $privzonefile > /dev/null
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews# Sign the DLV secure zone.
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrewsdlvzone=dlv.
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrewsdlvinfile=dlv.db.in
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrewsdlvzonefile=dlv.db
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrewsdlvkeyname=`$KEYGEN -q -r $RANDFILE -a RSAMD5 -b 768 -n zone $dlvzone`
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrewscat $dlvinfile $dlvkeyname.key dlvset-$privzone > $dlvzonefile
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews$SIGNER -P -g -r $RANDFILE -o $dlvzone $dlvzonefile > /dev/null
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews# Sign the badparam secure file
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrewszone=badparam.
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrewsinfile=badparam.db.in
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrewszonefile=badparam.db
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrewskeyname1=`$KEYGEN -q -r $RANDFILE -a RSASHA256 -b 1024 -n zone -f KSK $zone`
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrewskeyname2=`$KEYGEN -q -r $RANDFILE -a RSASHA256 -b 1024 -n zone $zone`
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrewscat $infile $keyname1.key $keyname2.key >$zonefile
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews$SIGNER -P -3 - -H 1 -g -r $RANDFILE -o $zone -k $keyname1 $zonefile $keyname2 > /dev/null
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrewssed 's/IN NSEC3 1 0 1 /IN NSEC3 1 0 10 /' $zonefile.signed > $zonefile.bad
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews