Network Startup Resource Center                            http://www.nsrc.org/

                   Automated zone INLINE signing with BIND
                   ---------------------------------------

Remember that if you see '#' before a command, it means
you need to run this command as root, either via:

a) sudo -s

b) sudo command

We'll build on the previous labs and enable inline signing on BIND (9.9+)

When doing inline signing, the original zone is never modified: this
allows the operator to make, for example, a dump of a DB containing the
zone, and BIND will just sign it.

When the unsigned zone is updated, named detects the changes, and re-signs.

*** ON YOUR MASTER SERVER ***

1. We're going to add a couple of statements to the BIND named.conf
   configuration file to enable inline dnssec signing.

   First, edit named.conf under /etc/namedb/, and make the following changes:

        zone "mytld" {
                file "/etc/namedb/master/mytld";
                type master;

                key-directory "/etc/namedb/keys";
                auto-dnssec maintain;
                inline-signing yes;
                dnssec-dnskey-kskonly yes;
       };

    Save and exit.

2. Preparing the keys

	If you've done the manual signing lab from before, you have already
	generated keys, and we can reuse those. Otherwise, we'll generate
	a new set of keys.

    a) If you already have keys (otherwise go to step b)

   We need to make sure the directory has the right permissions - since BIND
   will be managing this, it needs access to the files and the directory:

	# chown -R bind /etc/namedb/keys

   Let's look at the keys:

    # cd /etc/namedb/keys/
    # ls -l Kmytld*
    -rw-r--r--  1 bind  wheel   591 Feb 18 15:52 Kmytld.+005+32044.key
    -rw-------  1 bind  wheel  1774 Feb 18 15:52 Kmytld.+005+32044.private
    -rw-r--r--  1 bind  wheel   417 Feb 18 15:52 Kmytld.+005+64860.key
    -rw-------  1 bind  wheel  1010 Feb 18 15:52 Kmytld.+005+64860.private

	b) If you don't have keys yet:

        # mkdir -p /etc/namedb/keys
        # cd /etc/namedb/keys

	- Generate first key pair (Zone Signing Key)

        # dnssec-keygen -a RSASHA256 -b 1024 mytld

    (  will output something like:
    Generating key pair......................+++++ + ....
    Kmytld.+008+43116 )

	- Generate second key pair (Key Signing Key)

        # dnssec-keygen -a RSASHA256 -b 2048 -f KSK mytld
        Kmytld.+008+52159

        (once again, some output will show)

        Make sure bind can read them:

        # chown bind *

        Check that the keys are there:

        # ls -l Kmytld*

3. Now let's take care of the zone file

   If you have made a backup of your zone file, let's copy it back over
   our zone, to start fresh:

        # cd /etc/namedb/master
        # cp mytld.backup mytld

   Remove the old .signed zone - BIND will create that automatically!

        # rm mytld.signed

   Again, remember to check in named.conf, that you are loading "mytld",
   and *NOT* "mytld.signed".

   We also need to make sure BIND can write in the master directory:

        # chown bind /etc/namedb/master

4. Now reconfig the nameserver

        # rndc reconfig

    At this point you should see some new files appear in the master/ dir:

        # cd /etc/namedb/master
        # ls -l

...
-rw-r--r--  1 root  wheel   497 Sep 13 14:56 mytld
-rw-r--r--  1 root  wheel   497 Sep 12 09:49 mytld.backup
-rw-r--r--  1 bind  wheel   512 Sep 13 15:04 mytld.jbk
-rw-r--r--  1 bind  wheel  1331 Sep 13 15:04 mytld.signed
-rw-r--r--  1 bind  wheel  3581 Sep 13 15:04 mytld.signed.jnl
...

	Check that signing did work:

        # rndc signing -list mytld
        Done signing with key 22603/RSASHA1
        Done signing with key 39978/RSASHA1

        Look at system log:

        # tail /var/log/messages

	Also look in the logs if configured in named.conf:

	# less /etc/namedb/logs/general

13-Sep-2012 15:04:27.444 reloading configuration succeeded
13-Sep-2012 15:04:27.450 zone mytld/IN (unsigned): loaded serial 2012022301
13-Sep-2012 15:04:27.451 any newly configured zones are now loaded
13-Sep-2012 15:04:27.471 zone mytld/IN (signed): loaded serial 2012022301
13-Sep-2012 15:04:27.493 zone mytld/IN (signed): receive_secure_serial: unchanged
13-Sep-2012 15:04:27.501 zone mytld/IN (signed): reconfiguring zone keys
13-Sep-2012 15:04:27.544 zone mytld/IN (signed): next key event: 13-Sep-2012 16:04:27.501

        # dig +dnssec @10.10.XX.1 mytld NS

	Note that the signed zone is NOT stored in a human readable format.

	To see the contents of the signed zone, one can either do a zone
	transfer (axfr) 

        # dig @10.10.XX.1 axfr mytld | less

        or:

        # named-checkzone -D -f raw -o - mytld mytld.signed | less

        In particular look at the DNSKEY RRset and enure the inception 
        and expiration times make sense.

        # dig +dnssec @10.10.XX.1 mytld dnskey


5. Changes to the zone

	So how do we update the zone and resign it? Simple!

	Let's modify the zone and add a "mail" record with the IP address
	of the auth1 server:

        mail  IN  A  10.10.XX.1   ; XX is your group

	by editing "/etc/namedb/master/mytld" and adding the line above.

	Remember to change the serial.

	Now, reload the zone. named will be automatically resign the zone:

        # rndc reload mytld

	Wait a few seconds, then:

        # tail /etc/namedb/log/general

	What do you observe ?

        # dig @10.10.XX.1 mail.mytld a
        # dig @10.10.XX.1 mytld soa

	Notice the serial

6. If you haven't already uploaded the DS record in a previous lab, it's
   time to communicate it to your parent (the root). Otherwise, you can
   skip the rest of this lab!

    (DS = digest fingerprint of the Key Signing Key).

   Generate a "DS" from your key:

    Find which key is the key signing key:

    # cd /etc/namedb/keys
    # more Kmytld*key
    
    Look at which one has "IN DNSKEY 257". Find the "keyid" and replace
    the string "+008+32044" below with "+008+keyid" where "keyid" is the
    number displayed.

    # dnssec-dsfromkey Kmytld.+008+32044

7. Submit the dsset for your zone (containing the hash of your KSK) to the
   parent as you did with the name server record by going to 
   https://rzm.dnssek.org and cutting and pasting the results above
   into the appropriate fields. After "Commit" inform the instructor 
   that you have completed this step.

8. After a few minutes you should be able to verify that the changes were made
   and propagated through the resolver:

    # dig +dnssec DS mytld.
    # dig +dnssec A www.mytld.

   Notice the "AD" bit in the "flags" section.
