TechnitiumSoftware/DnsServer · error · ArgumentException

The private key must be a Zone Signing Key.

Error message

The private key must be a Zone Signing Key.

What it means

Thrown by PrimaryZone.SignZone(kskPrivateKey, zskPrivateKey, ...) when zskPrivateKey.KeyType != DnssecPrivateKeyType.ZoneSigningKey. The ZSK signs the non-DNSKEY RRsets, so a KSK in the second slot is rejected with ArgumentException naming 'zskPrivateKey' before salt/iteration handling.

Source

Thrown at DnsServerCore/Dns/Zones/PrimaryZone.cs:451

            {
                Timer dnssecTimer = _dnssecTimer;
                if (dnssecTimer is not null)
                {
                    lock (dnssecTimer)
                    {
                        dnssecTimer.Change(DNSSEC_TIMER_PERIODIC_INTERVAL, Timeout.Infinite);
                    }
                }
            }
        }

        public void SignZone(DnssecPrivateKey kskPrivateKey, DnssecPrivateKey zskPrivateKey, uint dnsKeyTtl, bool useNSec3, ushort iterations = 0, byte saltLength = 0)
        {
            if (kskPrivateKey.KeyType != DnssecPrivateKeyType.KeySigningKey)
                throw new ArgumentException("The private key must be a Key Signing Key.", nameof(kskPrivateKey));

            if (zskPrivateKey.KeyType != DnssecPrivateKeyType.ZoneSigningKey)
                throw new ArgumentException("The private key must be a Zone Signing Key.", nameof(zskPrivateKey));

            byte[] salt = null;

            if (useNSec3)
            {
                if (saltLength > 32)
                    throw new ArgumentOutOfRangeException(nameof(saltLength), "NSEC3 salt length valid range is 0-32");

                if (saltLength > 0)
                {
                    salt = new byte[saltLength];
                    RandomNumberGenerator.Fill(salt);
                }
                else
                {
                    salt = [];
                }
            }

View on GitHub (pinned to d0484b6c1e)

Solutions

  1. Pass a key whose KeyType == DnssecPrivateKeyType.ZoneSigningKey as the second argument.
  2. Generate and persist a dedicated ZSK alongside the KSK.
  3. Assert the ZSK role at load time.

Example fix

// before
zone.SignZone(ksk, ksk2, ttl, false);

// after
var zsk = keys.Single(k => k.KeyType == DnssecPrivateKeyType.ZoneSigningKey);
zone.SignZone(ksk, zsk, ttl, false);
Defensive patterns

Strategy: validation

Validate before calling

if (zskPrivateKey.KeyType != DnssecPrivateKeyType.ZoneSigningKey)
    throw new ArgumentException("A ZoneSigningKey is required.");
zone.SignZone(kskPrivateKey, zskPrivateKey, ttl, useNSec3);

Type guard

static bool IsZsk(DnssecPrivateKey k) => k.KeyType == DnssecPrivateKeyType.ZoneSigningKey;

Prevention

When it happens

Trigger: primaryZone.SignZone(ksk, wrongKey, ...) where the second argument's KeyType != ZoneSigningKey.

Common situations: Reusing a single KSK for both slots; mislabeled keys imported from PEM/KSK store.

Related errors


AI-assisted analysis of TechnitiumSoftware/DnsServer@d0484b6c1e (2026-08-13). Data as JSON: /api/errors/d5bc31af0ff4d0e1. Report an issue: GitHub.