2005-08-14 02:08:48 +00:00
|
|
|
// $Id$
|
2005-08-13 23:18:03 +00:00
|
|
|
//
|
2009-02-02 04:45:49 +00:00
|
|
|
// Copyright (C) 2001-2003, 2009 VeriSign, Inc.
|
2005-08-13 23:18:03 +00:00
|
|
|
//
|
|
|
|
// This library is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU Lesser General Public
|
|
|
|
// License as published by the Free Software Foundation; either
|
|
|
|
// version 2.1 of the License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This library is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
// Lesser General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Lesser General Public
|
|
|
|
// License along with this library; if not, write to the Free Software
|
|
|
|
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
|
|
|
// USA
|
2005-08-14 02:08:48 +00:00
|
|
|
|
2005-08-13 23:18:03 +00:00
|
|
|
package com.verisignlabs.dnssec.security;
|
|
|
|
|
2005-08-14 02:08:48 +00:00
|
|
|
import java.io.IOException;
|
|
|
|
import java.security.GeneralSecurityException;
|
|
|
|
import java.security.KeyPair;
|
|
|
|
import java.security.NoSuchAlgorithmException;
|
|
|
|
import java.security.Signature;
|
|
|
|
import java.security.interfaces.DSAPublicKey;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.Date;
|
|
|
|
import java.util.Iterator;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.ListIterator;
|
|
|
|
|
|
|
|
import org.xbill.DNS.DNSKEYRecord;
|
|
|
|
import org.xbill.DNS.Name;
|
|
|
|
import org.xbill.DNS.RRSIGRecord;
|
|
|
|
import org.xbill.DNS.RRset;
|
|
|
|
import org.xbill.DNS.Record;
|
|
|
|
import org.xbill.DNS.Type;
|
2010-12-05 23:08:13 +00:00
|
|
|
import org.xbill.DNS.utils.hexdump;
|
2005-08-14 02:08:48 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This class contains routines for signing DNS zones.
|
|
|
|
*
|
|
|
|
* In particular, it contains both an ability to sign an individual RRset and
|
2009-02-02 04:45:49 +00:00
|
|
|
* the ability to sign an entire zone. It primarily glues together the more
|
2005-08-14 02:08:48 +00:00
|
|
|
* basic primitives found in {@link SignUtils}.
|
|
|
|
*
|
|
|
|
* @author David Blacka (original)
|
|
|
|
* @author $Author$
|
|
|
|
* @version $Revision$
|
2005-08-13 23:18:03 +00:00
|
|
|
*/
|
2009-02-02 04:45:49 +00:00
|
|
|
|
2005-08-13 23:18:03 +00:00
|
|
|
public class JCEDnsSecSigner
|
|
|
|
{
|
2006-05-23 21:24:00 +00:00
|
|
|
private DnsKeyConverter mKeyConverter;
|
2010-12-05 23:08:13 +00:00
|
|
|
private boolean mVerboseSigning = false;
|
|
|
|
|
|
|
|
public JCEDnsSecSigner()
|
|
|
|
{
|
|
|
|
this.mKeyConverter = null;
|
|
|
|
this.mVerboseSigning = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public JCEDnsSecSigner(boolean verboseSigning)
|
|
|
|
{
|
|
|
|
this.mKeyConverter = null;
|
|
|
|
this.mVerboseSigning = verboseSigning;
|
|
|
|
}
|
2005-08-13 23:18:03 +00:00
|
|
|
|
2005-08-14 02:08:48 +00:00
|
|
|
/**
|
|
|
|
* Cryptographically generate a new DNSSEC key.
|
|
|
|
*
|
2009-02-02 04:45:49 +00:00
|
|
|
* @param owner
|
|
|
|
* the KEY RR's owner name.
|
|
|
|
* @param ttl
|
|
|
|
* the KEY RR's TTL.
|
|
|
|
* @param dclass
|
|
|
|
* the KEY RR's DNS class.
|
|
|
|
* @param algorithm
|
|
|
|
* the DNSSEC algorithm (RSAMD5, RSASHA1, or DSA).
|
|
|
|
* @param flags
|
|
|
|
* any flags for the KEY RR.
|
|
|
|
* @param keysize
|
|
|
|
* the size of the key to generate.
|
|
|
|
* @param useLargeExponent
|
|
|
|
* if generating an RSA key, use the large exponent.
|
2005-08-14 02:08:48 +00:00
|
|
|
* @return a DnsKeyPair with the public and private keys populated.
|
2005-08-13 23:18:03 +00:00
|
|
|
*/
|
2010-12-05 23:08:13 +00:00
|
|
|
public DnsKeyPair generateKey(Name owner, long ttl, int dclass, int algorithm,
|
|
|
|
int flags, int keysize, boolean useLargeExponent)
|
2006-09-10 16:48:21 +00:00
|
|
|
throws NoSuchAlgorithmException
|
2005-08-13 23:18:03 +00:00
|
|
|
{
|
2006-05-23 21:24:00 +00:00
|
|
|
DnsKeyAlgorithm algorithms = DnsKeyAlgorithm.getInstance();
|
2005-08-13 23:18:03 +00:00
|
|
|
|
|
|
|
if (ttl < 0) ttl = 86400; // set to a reasonable default.
|
|
|
|
|
2010-12-05 23:08:13 +00:00
|
|
|
KeyPair pair = algorithms.generateKeyPair(algorithm, keysize, useLargeExponent);
|
2005-08-13 23:18:03 +00:00
|
|
|
|
|
|
|
if (mKeyConverter == null)
|
|
|
|
{
|
|
|
|
mKeyConverter = new DnsKeyConverter();
|
|
|
|
}
|
|
|
|
|
2010-12-05 23:08:13 +00:00
|
|
|
DNSKEYRecord keyrec = mKeyConverter.generateDNSKEYRecord(owner, dclass, ttl, flags,
|
|
|
|
algorithm, pair.getPublic());
|
2006-05-23 21:24:00 +00:00
|
|
|
|
2005-08-13 23:18:03 +00:00
|
|
|
DnsKeyPair dnspair = new DnsKeyPair();
|
|
|
|
dnspair.setDNSKEYRecord(keyrec);
|
2005-08-14 02:08:48 +00:00
|
|
|
dnspair.setPublic(pair.getPublic()); // keep from conv. the keyrec back.
|
2005-08-13 23:18:03 +00:00
|
|
|
dnspair.setPrivate(pair.getPrivate());
|
|
|
|
|
|
|
|
return dnspair;
|
|
|
|
}
|
|
|
|
|
2005-08-14 02:08:48 +00:00
|
|
|
/**
|
|
|
|
* Sign an RRset.
|
|
|
|
*
|
2009-02-02 04:45:49 +00:00
|
|
|
* @param rrset
|
|
|
|
* the RRset to sign -- any existing signatures are ignored.
|
|
|
|
* @param keypars
|
|
|
|
* a list of DnsKeyPair objects containing private keys.
|
|
|
|
* @param start
|
|
|
|
* the inception time for the resulting RRSIG records.
|
|
|
|
* @param expire
|
|
|
|
* the expiration time for the resulting RRSIG records.
|
2005-08-14 02:08:48 +00:00
|
|
|
* @return a list of RRSIGRecord objects.
|
2005-08-13 23:18:03 +00:00
|
|
|
*/
|
|
|
|
public List signRRset(RRset rrset, List keypairs, Date start, Date expire)
|
2005-08-14 02:08:48 +00:00
|
|
|
throws IOException, GeneralSecurityException
|
2005-08-13 23:18:03 +00:00
|
|
|
{
|
|
|
|
if (rrset == null || keypairs == null) return null;
|
|
|
|
|
|
|
|
// default start to now, expire to start + 1 second.
|
|
|
|
if (start == null) start = new Date();
|
|
|
|
if (expire == null) expire = new Date(start.getTime() + 1000L);
|
|
|
|
if (keypairs.size() == 0) return null;
|
|
|
|
|
2010-12-05 23:08:13 +00:00
|
|
|
if (mVerboseSigning)
|
|
|
|
{
|
|
|
|
System.out.println("Signing RRset:");
|
|
|
|
System.out.println(ZoneUtils.rrsetToString(rrset, false));
|
|
|
|
}
|
|
|
|
|
2009-02-02 04:45:49 +00:00
|
|
|
// first, pre-calculate the RRset bytes.
|
2009-08-23 19:13:42 +00:00
|
|
|
byte[] rrset_data = SignUtils.generateCanonicalRRsetData(rrset, 0, 0);
|
2005-08-13 23:18:03 +00:00
|
|
|
|
|
|
|
ArrayList sigs = new ArrayList(keypairs.size());
|
|
|
|
|
2009-02-02 04:45:49 +00:00
|
|
|
// for each keypair, sign the RRset.
|
2005-08-14 02:08:48 +00:00
|
|
|
for (Iterator i = keypairs.iterator(); i.hasNext();)
|
2005-08-13 23:18:03 +00:00
|
|
|
{
|
|
|
|
DnsKeyPair pair = (DnsKeyPair) i.next();
|
|
|
|
DNSKEYRecord keyrec = pair.getDNSKEYRecord();
|
|
|
|
if (keyrec == null) continue;
|
|
|
|
|
2010-12-05 23:08:13 +00:00
|
|
|
RRSIGRecord presig = SignUtils.generatePreRRSIG(rrset, keyrec, start, expire,
|
|
|
|
rrset.getTTL());
|
2005-08-13 23:18:03 +00:00
|
|
|
byte[] sign_data = SignUtils.generateSigData(rrset_data, presig);
|
|
|
|
|
2010-12-05 23:08:13 +00:00
|
|
|
if (mVerboseSigning)
|
|
|
|
{
|
|
|
|
System.out.println("Canonical pre-signature data to sign with key " + keyrec.getName().toString() + "/"
|
|
|
|
+ keyrec.getAlgorithm() + "/" + keyrec.getFootprint() + ":");
|
|
|
|
System.out.println(hexdump.dump(null, sign_data));
|
|
|
|
}
|
|
|
|
|
2005-08-13 23:18:03 +00:00
|
|
|
Signature signer = pair.getSigner();
|
|
|
|
|
|
|
|
if (signer == null)
|
|
|
|
{
|
2005-08-14 02:08:48 +00:00
|
|
|
// debug
|
|
|
|
System.out.println("missing private key that goes with:\n"
|
|
|
|
+ pair.getDNSKEYRecord());
|
2010-12-05 23:08:13 +00:00
|
|
|
throw new GeneralSecurityException("cannot sign without a valid Signer "
|
|
|
|
+ "(probably missing private key)");
|
2005-08-13 23:18:03 +00:00
|
|
|
}
|
2005-08-14 02:08:48 +00:00
|
|
|
|
2005-08-13 23:18:03 +00:00
|
|
|
// sign the data.
|
|
|
|
signer.update(sign_data);
|
|
|
|
byte[] sig = signer.sign();
|
|
|
|
|
2010-12-05 23:08:13 +00:00
|
|
|
if (mVerboseSigning)
|
|
|
|
{
|
|
|
|
System.out.println("Raw Signature:");
|
|
|
|
System.out.println(hexdump.dump(null, sig));
|
|
|
|
}
|
|
|
|
|
2006-05-23 21:24:00 +00:00
|
|
|
DnsKeyAlgorithm algs = DnsKeyAlgorithm.getInstance();
|
2005-08-13 23:18:03 +00:00
|
|
|
// Convert to RFC 2536 format, if necessary.
|
2006-05-23 21:24:00 +00:00
|
|
|
if (algs.baseType(pair.getDNSKEYAlgorithm()) == DnsKeyAlgorithm.DSA)
|
2005-08-13 23:18:03 +00:00
|
|
|
{
|
2010-12-05 23:08:13 +00:00
|
|
|
DSAPublicKey pk = (DSAPublicKey) pair.getPublic();
|
|
|
|
sig = SignUtils.convertDSASignature(pk.getParams(), sig);
|
2005-08-13 23:18:03 +00:00
|
|
|
}
|
|
|
|
RRSIGRecord sigrec = SignUtils.generateRRSIG(sig, presig);
|
2010-12-05 23:08:13 +00:00
|
|
|
if (mVerboseSigning)
|
|
|
|
{
|
|
|
|
System.out.println("RRSIG:\n" + sigrec);
|
|
|
|
System.out.println();
|
|
|
|
}
|
2005-08-13 23:18:03 +00:00
|
|
|
sigs.add(sigrec);
|
|
|
|
}
|
|
|
|
|
|
|
|
return sigs;
|
|
|
|
}
|
|
|
|
|
2005-08-14 02:08:48 +00:00
|
|
|
/**
|
2009-02-02 04:45:49 +00:00
|
|
|
* Create a completely self-signed DNSKEY RRset.
|
2005-08-14 02:08:48 +00:00
|
|
|
*
|
2009-02-02 04:45:49 +00:00
|
|
|
* @param keypairs
|
|
|
|
* the public & private keypairs to use in the keyset.
|
|
|
|
* @param start
|
|
|
|
* the RRSIG inception time.
|
|
|
|
* @param expire
|
|
|
|
* the RRSIG expiration time.
|
2005-08-14 02:08:48 +00:00
|
|
|
* @return a signed RRset.
|
2005-08-13 23:18:03 +00:00
|
|
|
*/
|
2010-12-05 23:08:13 +00:00
|
|
|
public RRset makeKeySet(List keypairs, Date start, Date expire) throws IOException,
|
|
|
|
GeneralSecurityException
|
2005-08-13 23:18:03 +00:00
|
|
|
{
|
|
|
|
// Generate a KEY RR set to sign.
|
2005-08-14 02:08:48 +00:00
|
|
|
|
2005-08-13 23:18:03 +00:00
|
|
|
RRset keyset = new RRset();
|
|
|
|
|
2005-08-14 02:08:48 +00:00
|
|
|
for (Iterator i = keypairs.iterator(); i.hasNext();)
|
2005-08-13 23:18:03 +00:00
|
|
|
{
|
|
|
|
DnsKeyPair pair = (DnsKeyPair) i.next();
|
|
|
|
keyset.addRR(pair.getDNSKEYRecord());
|
|
|
|
}
|
|
|
|
|
|
|
|
List records = signRRset(keyset, keypairs, start, expire);
|
|
|
|
|
2005-08-14 02:08:48 +00:00
|
|
|
for (Iterator i = records.iterator(); i.hasNext();)
|
2005-08-13 23:18:03 +00:00
|
|
|
{
|
|
|
|
keyset.addRR((Record) i.next());
|
|
|
|
}
|
2005-08-14 02:08:48 +00:00
|
|
|
|
2005-08-13 23:18:03 +00:00
|
|
|
return keyset;
|
|
|
|
}
|
|
|
|
|
2005-08-14 02:08:48 +00:00
|
|
|
/**
|
|
|
|
* Conditionally sign an RRset and add it to the toList.
|
|
|
|
*
|
2009-02-02 04:45:49 +00:00
|
|
|
* @param toList
|
|
|
|
* the list to which we are adding the processed RRsets.
|
|
|
|
* @param zonename
|
|
|
|
* the zone apex name.
|
|
|
|
* @param rrset
|
|
|
|
* the RRset under consideration.
|
|
|
|
* @param kskpairs
|
|
|
|
* the List of KSKs..
|
|
|
|
* @param zskpairs
|
|
|
|
* the List of zone keys.
|
|
|
|
* @param start
|
|
|
|
* the RRSIG inception time.
|
|
|
|
* @param expire
|
|
|
|
* the RRSIG expiration time.
|
|
|
|
* @param fullySignKeyset
|
|
|
|
* if true, sign the zone apex keyset with both KSKs and ZSKs.
|
|
|
|
* @param last_cut
|
|
|
|
* the name of the last delegation point encountered.
|
|
|
|
*
|
2005-08-14 02:08:48 +00:00
|
|
|
* @return the name of the new last_cut.
|
2005-08-13 23:18:03 +00:00
|
|
|
*/
|
2009-02-02 04:45:49 +00:00
|
|
|
private Name addRRset(List toList, Name zonename, RRset rrset, List kskpairs,
|
2010-12-05 23:08:13 +00:00
|
|
|
List zskpairs, Date start, Date expire, boolean fullySignKeyset,
|
2010-12-06 00:25:04 +00:00
|
|
|
Name last_cut, Name last_dname) throws IOException, GeneralSecurityException
|
2005-08-13 23:18:03 +00:00
|
|
|
{
|
|
|
|
// add the records themselves
|
2005-08-14 02:08:48 +00:00
|
|
|
for (Iterator i = rrset.rrs(); i.hasNext();)
|
2005-08-13 23:18:03 +00:00
|
|
|
{
|
|
|
|
toList.add(i.next());
|
|
|
|
}
|
|
|
|
|
2010-12-05 23:08:13 +00:00
|
|
|
int type = SignUtils.recordSecType(zonename, rrset.getName(), rrset.getType(),
|
2010-12-06 00:25:04 +00:00
|
|
|
last_cut, last_dname);
|
2005-08-13 23:18:03 +00:00
|
|
|
|
|
|
|
// we don't sign non-normal sets (delegations, glue, invalid).
|
2009-02-07 20:37:29 +00:00
|
|
|
if (type == SignUtils.RR_DELEGATION)
|
|
|
|
{
|
|
|
|
return rrset.getName();
|
|
|
|
}
|
|
|
|
if (type == SignUtils.RR_GLUE || type == SignUtils.RR_INVALID)
|
|
|
|
{
|
|
|
|
return last_cut;
|
|
|
|
}
|
2005-08-13 23:18:03 +00:00
|
|
|
|
|
|
|
// check for the zone apex keyset.
|
|
|
|
if (rrset.getName().equals(zonename) && rrset.getType() == Type.DNSKEY)
|
|
|
|
{
|
2009-02-02 04:45:49 +00:00
|
|
|
// if we have ksks, sign the keyset with them, otherwise we will just sign
|
|
|
|
// them with the zsks.
|
|
|
|
if (kskpairs != null && kskpairs.size() > 0)
|
2005-08-13 23:18:03 +00:00
|
|
|
{
|
2009-02-02 04:45:49 +00:00
|
|
|
List sigs = signRRset(rrset, kskpairs, start, expire);
|
2005-08-14 02:08:48 +00:00
|
|
|
toList.addAll(sigs);
|
2005-08-13 23:18:03 +00:00
|
|
|
|
2005-08-14 02:08:48 +00:00
|
|
|
// If we aren't going to sign with all the keys, bail out now.
|
|
|
|
if (!fullySignKeyset) return last_cut;
|
2005-08-13 23:18:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// otherwise, we are OK to sign this set.
|
2009-02-02 04:45:49 +00:00
|
|
|
List sigs = signRRset(rrset, zskpairs, start, expire);
|
2005-08-13 23:18:03 +00:00
|
|
|
toList.addAll(sigs);
|
|
|
|
|
|
|
|
return last_cut;
|
|
|
|
}
|
|
|
|
|
2009-02-02 04:45:49 +00:00
|
|
|
// Various NSEC/NSEC3 generation modes
|
|
|
|
private static final int NSEC_MODE = 0;
|
|
|
|
private static final int NSEC3_MODE = 1;
|
|
|
|
private static final int NSEC3_OPTOUT_MODE = 2;
|
|
|
|
private static final int NSEC_EXP_OPT_IN = 3;
|
|
|
|
|
2005-08-14 02:08:48 +00:00
|
|
|
/**
|
2009-02-02 04:45:49 +00:00
|
|
|
* Master zone signing method. This method handles all of the different zone
|
|
|
|
* signing variants (NSEC with or without Opt-In, NSEC3 with or without
|
|
|
|
* Opt-Out, etc.) External users of this class are expected to use the
|
|
|
|
* appropriate public signZone* methods instead of this.
|
|
|
|
*
|
|
|
|
* @param zonename
|
|
|
|
* The name of the zone
|
|
|
|
* @param records
|
|
|
|
* The records comprising the zone. They do not have to be in any
|
|
|
|
* particular order, as this method will order them as necessary.
|
|
|
|
* @param kskpairs
|
|
|
|
* The key pairs designated as "key signing keys"
|
|
|
|
* @param zskpairs
|
|
|
|
* The key pairs designated as "zone signing keys"
|
|
|
|
* @param start
|
|
|
|
* The RRSIG inception time
|
|
|
|
* @param expire
|
|
|
|
* The RRSIG expiration time
|
|
|
|
* @param fullySignKeyset
|
|
|
|
* If true, all keys (ksk or zsk) will sign the DNSKEY RRset. If
|
|
|
|
* false, only the ksks will sign it.
|
|
|
|
* @param ds_digest_alg
|
|
|
|
* The hash algorithm to use for generating DS records
|
|
|
|
* (DSRecord.SHA1_DIGEST_ID, e.g.)
|
|
|
|
* @param mode
|
|
|
|
* The NSEC/NSEC3 generation mode: NSEC_MODE, NSEC3_MODE,
|
|
|
|
* NSEC3_OPTOUT_MODE, etc.
|
|
|
|
* @param includedNames
|
|
|
|
* When using an Opt-In/Opt-Out mode, the names listed here will be
|
|
|
|
* included in the NSEC/NSEC3 chain regardless
|
|
|
|
* @param salt
|
|
|
|
* When using an NSEC3 mode, use this salt.
|
|
|
|
* @param iterations
|
|
|
|
* When using an NSEC3 mode, use this number of iterations
|
|
|
|
* @param beConservative
|
|
|
|
* If true, then only turn on the Opt-In flag when there are insecure
|
|
|
|
* delegations in the span. Currently this only works for
|
|
|
|
* NSEC_EXP_OPT_IN mode.
|
2009-02-07 20:37:29 +00:00
|
|
|
* @param nsec3paramttl
|
|
|
|
* The TTL to use for the generated NSEC3PARAM record. Negative
|
|
|
|
* values will use the SOA TTL.
|
2005-08-14 02:08:48 +00:00
|
|
|
* @return an ordered list of {@link org.xbill.DNS.Record} objects,
|
|
|
|
* representing the signed zone.
|
2009-02-02 04:45:49 +00:00
|
|
|
*
|
|
|
|
* @throws IOException
|
|
|
|
* @throws GeneralSecurityException
|
2005-08-13 23:18:03 +00:00
|
|
|
*/
|
2010-12-05 23:08:13 +00:00
|
|
|
private List signZone(Name zonename, List records, List kskpairs, List zskpairs,
|
|
|
|
Date start, Date expire, boolean fullySignKeyset,
|
|
|
|
int ds_digest_alg, int mode, List includedNames, byte[] salt,
|
|
|
|
int iterations, long nsec3paramttl, boolean beConservative)
|
2006-05-24 22:19:31 +00:00
|
|
|
throws IOException, GeneralSecurityException
|
2005-08-13 23:18:03 +00:00
|
|
|
{
|
2009-02-02 04:45:49 +00:00
|
|
|
// Remove any existing generated DNSSEC records (NSEC, NSEC3, NSEC3PARAM,
|
|
|
|
// RRSIG)
|
2005-08-13 23:18:03 +00:00
|
|
|
SignUtils.removeGeneratedRecords(zonename, records);
|
2009-02-02 04:45:49 +00:00
|
|
|
|
|
|
|
RecordComparator rc = new RecordComparator();
|
2005-08-13 23:18:03 +00:00
|
|
|
// Sort the zone
|
2009-02-02 04:45:49 +00:00
|
|
|
Collections.sort(records, rc);
|
2005-08-13 23:18:03 +00:00
|
|
|
|
2009-02-02 04:45:49 +00:00
|
|
|
// Remove duplicate records
|
2005-08-13 23:18:03 +00:00
|
|
|
SignUtils.removeDuplicateRecords(records);
|
|
|
|
|
2009-02-02 04:45:49 +00:00
|
|
|
// Generate DS records. This replaces any non-zone-apex DNSKEY RRs with DS
|
|
|
|
// RRs.
|
|
|
|
SignUtils.generateDSRecords(zonename, records, ds_digest_alg);
|
2005-08-14 02:08:48 +00:00
|
|
|
|
2009-02-02 04:45:49 +00:00
|
|
|
// Generate the NSEC or NSEC3 records based on 'mode'
|
|
|
|
switch (mode)
|
2005-08-13 23:18:03 +00:00
|
|
|
{
|
2009-02-07 20:37:29 +00:00
|
|
|
case NSEC_MODE:
|
|
|
|
SignUtils.generateNSECRecords(zonename, records);
|
|
|
|
break;
|
|
|
|
case NSEC3_MODE:
|
2010-12-05 23:08:13 +00:00
|
|
|
SignUtils.generateNSEC3Records(zonename, records, salt, iterations, nsec3paramttl);
|
2009-02-07 20:37:29 +00:00
|
|
|
break;
|
|
|
|
case NSEC3_OPTOUT_MODE:
|
2010-12-05 23:08:13 +00:00
|
|
|
SignUtils.generateOptOutNSEC3Records(zonename, records, includedNames, salt,
|
|
|
|
iterations, nsec3paramttl);
|
2009-02-07 20:37:29 +00:00
|
|
|
break;
|
|
|
|
case NSEC_EXP_OPT_IN:
|
|
|
|
SignUtils.generateOptInNSECRecords(zonename, records, includedNames,
|
|
|
|
beConservative);
|
|
|
|
break;
|
2005-08-13 23:18:03 +00:00
|
|
|
}
|
2005-08-14 02:08:48 +00:00
|
|
|
|
2009-02-02 04:45:49 +00:00
|
|
|
// Re-sort so we can assemble into rrsets.
|
|
|
|
Collections.sort(records, rc);
|
|
|
|
|
2005-08-13 23:18:03 +00:00
|
|
|
// Assemble into RRsets and sign.
|
2005-08-14 02:08:48 +00:00
|
|
|
RRset rrset = new RRset();
|
2005-08-13 23:18:03 +00:00
|
|
|
ArrayList signed_records = new ArrayList();
|
2005-08-14 02:08:48 +00:00
|
|
|
Name last_cut = null;
|
2010-12-06 00:25:04 +00:00
|
|
|
Name last_dname = null;
|
2005-08-13 23:18:03 +00:00
|
|
|
|
2005-08-14 02:08:48 +00:00
|
|
|
for (ListIterator i = records.listIterator(); i.hasNext();)
|
2005-08-13 23:18:03 +00:00
|
|
|
{
|
|
|
|
Record r = (Record) i.next();
|
|
|
|
|
|
|
|
// First record
|
2009-02-02 04:45:49 +00:00
|
|
|
if (rrset.size() == 0)
|
2005-08-13 23:18:03 +00:00
|
|
|
{
|
|
|
|
rrset.addRR(r);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Current record is part of the current RRset.
|
2010-12-05 23:08:13 +00:00
|
|
|
if (rrset.getName().equals(r.getName()) && rrset.getDClass() == r.getDClass()
|
2005-08-14 02:08:48 +00:00
|
|
|
&& rrset.getType() == r.getType())
|
2005-08-13 23:18:03 +00:00
|
|
|
{
|
|
|
|
rrset.addRR(r);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Otherwise, we have completed the RRset
|
|
|
|
// Sign the records
|
|
|
|
|
|
|
|
// add the RRset to the list of signed_records, regardless of
|
|
|
|
// whether or not we actually end up signing the set.
|
2010-12-05 23:08:13 +00:00
|
|
|
last_cut = addRRset(signed_records, zonename, rrset, kskpairs, zskpairs, start,
|
2010-12-06 00:25:04 +00:00
|
|
|
expire, fullySignKeyset, last_cut, last_dname);
|
|
|
|
if (rrset.getType() == Type.DNAME) last_dname = rrset.getName();
|
2005-08-13 23:18:03 +00:00
|
|
|
|
|
|
|
rrset.clear();
|
|
|
|
rrset.addRR(r);
|
|
|
|
}
|
|
|
|
|
|
|
|
// add the last RR set
|
2010-12-05 23:08:13 +00:00
|
|
|
addRRset(signed_records, zonename, rrset, kskpairs, zskpairs, start, expire,
|
2010-12-06 00:25:04 +00:00
|
|
|
fullySignKeyset, last_cut, last_dname);
|
2005-08-13 23:18:03 +00:00
|
|
|
|
|
|
|
return signed_records;
|
|
|
|
}
|
2009-02-02 04:45:49 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Given a zone, sign it using standard NSEC records.
|
|
|
|
*
|
|
|
|
* @param zonename
|
|
|
|
* The name of the zone.
|
|
|
|
* @param records
|
|
|
|
* The records comprising the zone. They do not have to be in any
|
|
|
|
* particular order, as this method will order them as necessary.
|
|
|
|
* @param kskpairs
|
|
|
|
* The key pairs that are designated as "key signing keys".
|
|
|
|
* @param zskpairs
|
|
|
|
* This key pairs that are designated as "zone signing keys".
|
|
|
|
* @param start
|
|
|
|
* The RRSIG inception time.
|
|
|
|
* @param expire
|
|
|
|
* The RRSIG expiration time.
|
|
|
|
* @param fullySignKeyset
|
|
|
|
* Sign the zone apex keyset with all available keys (instead of just
|
|
|
|
* the key signing keys).
|
|
|
|
* @param ds_digest_alg
|
|
|
|
* The digest algorithm to use when generating DS records.
|
|
|
|
*
|
|
|
|
* @return an ordered list of {@link org.xbill.DNS.Record} objects,
|
|
|
|
* representing the signed zone.
|
|
|
|
*/
|
2010-12-05 23:08:13 +00:00
|
|
|
public List signZone(Name zonename, List records, List kskpairs, List zskpairs,
|
|
|
|
Date start, Date expire, boolean fullySignKeyset, int ds_digest_alg)
|
2009-02-02 04:45:49 +00:00
|
|
|
throws IOException, GeneralSecurityException
|
|
|
|
{
|
|
|
|
return signZone(zonename, records, kskpairs, zskpairs, start, expire,
|
2010-12-05 23:08:13 +00:00
|
|
|
fullySignKeyset, ds_digest_alg, NSEC_MODE, null, null, 0, 0, false);
|
2009-02-02 04:45:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Given a zone, sign it using NSEC3 records.
|
|
|
|
*
|
|
|
|
* @param signer
|
|
|
|
* A signer (utility) object used to actually sign stuff.
|
|
|
|
* @param zonename
|
|
|
|
* The name of the zone being signed.
|
|
|
|
* @param records
|
|
|
|
* The records comprising the zone. They do not have to be in any
|
|
|
|
* particular order, as this method will order them as necessary.
|
|
|
|
* @param kskpairs
|
|
|
|
* The key pairs that are designated as "key signing keys".
|
|
|
|
* @param zskpairs
|
|
|
|
* This key pairs that are designated as "zone signing keys".
|
|
|
|
* @param start
|
|
|
|
* The RRSIG inception time.
|
|
|
|
* @param expire
|
|
|
|
* The RRSIG expiration time.
|
|
|
|
* @param fullySignKeyset
|
|
|
|
* If true then the DNSKEY RRset will be signed by all available
|
|
|
|
* keys, if false, only the key signing keys.
|
|
|
|
* @param useOptOut
|
|
|
|
* If true, insecure delegations will be omitted from the NSEC3
|
|
|
|
* chain, and all NSEC3 records will have the Opt-Out flag set.
|
|
|
|
* @param includedNames
|
|
|
|
* A list of names to include in the NSEC3 chain regardless.
|
|
|
|
* @param salt
|
|
|
|
* The salt to use for the NSEC3 hashing. null means no salt.
|
|
|
|
* @param iterations
|
|
|
|
* The number of iterations to use for the NSEC3 hashing.
|
|
|
|
* @param ds_digest_alg
|
|
|
|
* The digest algorithm to use when generating DS records.
|
2009-02-07 20:37:29 +00:00
|
|
|
* @param nsec3paramttl
|
|
|
|
* The TTL to use for the generated NSEC3PARAM record. Negative
|
|
|
|
* values will use the SOA TTL.
|
2009-02-02 04:45:49 +00:00
|
|
|
* @return an ordered list of {@link org.xbill.DNS.Record} objects,
|
|
|
|
* representing the signed zone.
|
|
|
|
*
|
|
|
|
* @throws IOException
|
|
|
|
* @throws GeneralSecurityException
|
|
|
|
*/
|
2010-12-05 23:08:13 +00:00
|
|
|
public List signZoneNSEC3(Name zonename, List records, List kskpairs, List zskpairs,
|
|
|
|
Date start, Date expire, boolean fullySignKeyset,
|
|
|
|
boolean useOptOut, List includedNames, byte[] salt,
|
|
|
|
int iterations, int ds_digest_alg, long nsec3paramttl)
|
2009-02-02 04:45:49 +00:00
|
|
|
throws IOException, GeneralSecurityException
|
|
|
|
{
|
|
|
|
if (useOptOut)
|
|
|
|
{
|
|
|
|
return signZone(zonename, records, kskpairs, zskpairs, start, expire,
|
2010-12-05 23:08:13 +00:00
|
|
|
fullySignKeyset, ds_digest_alg, NSEC3_OPTOUT_MODE, includedNames,
|
|
|
|
salt, iterations, nsec3paramttl, false);
|
2009-02-02 04:45:49 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return signZone(zonename, records, kskpairs, zskpairs, start, expire,
|
2010-12-05 23:08:13 +00:00
|
|
|
fullySignKeyset, ds_digest_alg, NSEC3_MODE, null, salt, iterations,
|
|
|
|
nsec3paramttl, false);
|
2009-02-02 04:45:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Given a zone, sign it using experimental Opt-In NSEC records (see RFC
|
|
|
|
* 4956).
|
|
|
|
*
|
|
|
|
* @param zonename
|
|
|
|
* the name of the zone.
|
|
|
|
* @param records
|
|
|
|
* the records comprising the zone. They do not have to be in any
|
|
|
|
* particular order, as this method will order them as necessary.
|
|
|
|
* @param kskpairs
|
|
|
|
* the key pairs that are designated as "key signing keys".
|
|
|
|
* @param zskpairs
|
|
|
|
* this key pairs that are designated as "zone signing keys".
|
|
|
|
* @param start
|
|
|
|
* the RRSIG inception time.
|
|
|
|
* @param expire
|
|
|
|
* the RRSIG expiration time.
|
|
|
|
* @param useConservativeOptIn
|
|
|
|
* if true, Opt-In NSEC records will only be generated if there are
|
|
|
|
* insecure, unsigned delegations in the span.
|
|
|
|
* @param fullySignKeyset
|
|
|
|
* sign the zone apex keyset with all available keys.
|
|
|
|
* @param ds_digest_alg
|
|
|
|
* The digest algorithm to use when generating DS records.
|
|
|
|
* @param NSECIncludeNames
|
|
|
|
* names that are to be included in the NSEC chain regardless. This
|
|
|
|
* may be null.
|
|
|
|
* @return an ordered list of {@link org.xbill.DNS.Record} objects,
|
|
|
|
* representing the signed zone.
|
|
|
|
*/
|
2010-12-05 23:08:13 +00:00
|
|
|
public List signZoneOptIn(Name zonename, List records, List kskpairs, List zskpairs,
|
|
|
|
Date start, Date expire, boolean useConservativeOptIn,
|
2009-02-02 04:45:49 +00:00
|
|
|
boolean fullySignKeyset, List NSECIncludeNames,
|
2010-12-05 23:08:13 +00:00
|
|
|
int ds_digest_alg) throws IOException,
|
|
|
|
GeneralSecurityException
|
2009-02-02 04:45:49 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
return signZone(zonename, records, kskpairs, zskpairs, start, expire,
|
2010-12-05 23:08:13 +00:00
|
|
|
fullySignKeyset, ds_digest_alg, NSEC_EXP_OPT_IN, NSECIncludeNames,
|
|
|
|
null, 0, 0, useConservativeOptIn);
|
2009-02-02 04:45:49 +00:00
|
|
|
}
|
2005-08-13 23:18:03 +00:00
|
|
|
}
|