From fa44c40bcdf5388b1e608c1dbaf4d43254ba9569 Mon Sep 17 00:00:00 2001 From: Shreyas Zare Date: Sat, 7 Aug 2021 12:28:05 +0530 Subject: [PATCH] AuthZoneInfo: updated tsig support implementation. --- DnsServerCore/Dns/Zones/AuthZoneInfo.cs | 58 +++++++++---------------- 1 file changed, 21 insertions(+), 37 deletions(-) diff --git a/DnsServerCore/Dns/Zones/AuthZoneInfo.cs b/DnsServerCore/Dns/Zones/AuthZoneInfo.cs index 499b5f57..360231f3 100644 --- a/DnsServerCore/Dns/Zones/AuthZoneInfo.cs +++ b/DnsServerCore/Dns/Zones/AuthZoneInfo.cs @@ -53,7 +53,7 @@ namespace DnsServerCore.Dns.Zones readonly IReadOnlyCollection _notifyNameServers; readonly DateTime _expiry; readonly IReadOnlyList _zoneHistory; //for IXFR support - readonly IReadOnlyDictionary _tsigKeys; + readonly IReadOnlyDictionary _tsigKeyNames; #endregion @@ -160,17 +160,12 @@ namespace DnsServerCore.Dns.Zones if (version >= 4) { int count = bR.ReadByte(); - Dictionary tsigKeys = new Dictionary(count); + Dictionary tsigKeyNames = new Dictionary(count); for (int i = 0; i < count; i++) - { - string keyName = bR.ReadShortString(); - string sharedSecret = bR.ReadShortString(); + tsigKeyNames.Add(bR.ReadShortString(), null); - tsigKeys.Add(keyName, sharedSecret); - } - - _tsigKeys = tsigKeys; + _tsigKeyNames = tsigKeyNames; } break; @@ -194,17 +189,12 @@ namespace DnsServerCore.Dns.Zones if (version >= 4) { int count = bR.ReadByte(); - Dictionary tsigKeys = new Dictionary(count); + Dictionary tsigKeyNames = new Dictionary(count); for (int i = 0; i < count; i++) - { - string keyName = bR.ReadShortString(); - string sharedSecret = bR.ReadShortString(); + tsigKeyNames.Add(bR.ReadShortString(), null); - tsigKeys.Add(keyName, sharedSecret); - } - - _tsigKeys = tsigKeys; + _tsigKeyNames = tsigKeyNames; } break; @@ -232,7 +222,7 @@ namespace DnsServerCore.Dns.Zones if (loadHistory) _zoneHistory = primaryZone.GetHistory(); - _tsigKeys = primaryZone.TsigKeys; + _tsigKeyNames = primaryZone.TsigKeyNames; } else if (_zone is SecondaryZone secondaryZone) { @@ -242,7 +232,7 @@ namespace DnsServerCore.Dns.Zones _zoneHistory = secondaryZone.GetHistory(); _expiry = secondaryZone.Expiry; - _tsigKeys = secondaryZone.TsigKeys; + _tsigKeyNames = secondaryZone.TsigKeyNames; } else if (_zone is StubZone stubZone) { @@ -411,19 +401,16 @@ namespace DnsServerCore.Dns.Zones } } - if (_tsigKeys is null) + if (_tsigKeyNames is null) { bW.Write((byte)0); } else { - bW.Write(Convert.ToByte(_tsigKeys.Count)); + bW.Write(Convert.ToByte(_tsigKeyNames.Count)); - foreach (KeyValuePair tsigKey in _tsigKeys) - { - bW.WriteShortString(tsigKey.Key); - bW.WriteShortString(tsigKey.Value); - } + foreach (KeyValuePair tsigKeyName in _tsigKeyNames) + bW.WriteShortString(tsigKeyName.Key); } break; @@ -450,19 +437,16 @@ namespace DnsServerCore.Dns.Zones } } - if (_tsigKeys is null) + if (_tsigKeyNames is null) { bW.Write((byte)0); } else { - bW.Write(Convert.ToByte(_tsigKeys.Count)); + bW.Write(Convert.ToByte(_tsigKeyNames.Count)); - foreach (KeyValuePair tsigKey in _tsigKeys) - { - bW.WriteShortString(tsigKey.Key); - bW.WriteShortString(tsigKey.Value); - } + foreach (KeyValuePair tsigKeyName in _tsigKeyNames) + bW.WriteShortString(tsigKeyName.Key); } break; @@ -590,9 +574,9 @@ namespace DnsServerCore.Dns.Zones public IReadOnlyList ZoneHistory { get { return _zoneHistory; } } - public IReadOnlyDictionary TsigKeys + public IReadOnlyDictionary TsigKeyNames { - get { return _tsigKeys; } + get { return _tsigKeyNames; } set { if (_zone is null) @@ -601,11 +585,11 @@ namespace DnsServerCore.Dns.Zones switch (_type) { case AuthZoneType.Primary: - (_zone as PrimaryZone).TsigKeys = value; + (_zone as PrimaryZone).TsigKeyNames = value; break; case AuthZoneType.Secondary: - (_zone as SecondaryZone).TsigKeys = value; + (_zone as SecondaryZone).TsigKeyNames = value; break; default: