Skip to content

Commit b6849c9

Browse files
committed
- Added RFC 8976
- Added Zone Validation - Optimized Zone Signing - Optimized Zone masterfile parsing - Optimized pipelined client transport
1 parent 5bff4c5 commit b6849c9

37 files changed

+1419
-718
lines changed

ARSoft.Tools.Net/ARSoft.Tools.Net.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
1717
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
1818
<Copyright>Copyright 2010..2023 Alexander Reinert</Copyright>
19-
<VersionPrefix>3.4.0</VersionPrefix>
19+
<VersionPrefix>3.5.0</VersionPrefix>
2020
</PropertyGroup>
2121

2222
<ItemGroup>
+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#region Copyright and License
2+
// Copyright 2010..2023 Alexander Reinert
3+
//
4+
// This file is part of the ARSoft.Tools.Net - C# DNS client/server and SPF Library (https://github.com/alexreinert/ARSoft.Tools.Net)
5+
//
6+
// Licensed under the Apache License, Version 2.0 (the "License");
7+
// you may not use this file except in compliance with the License.
8+
// You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// Unless required by applicable law or agreed to in writing, software
13+
// distributed under the License is distributed on an "AS IS" BASIS,
14+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
// See the License for the specific language governing permissions and
16+
// limitations under the License.
17+
#endregion
18+
19+
namespace ARSoft.Tools.Net;
20+
21+
internal static class DisposableExtensions
22+
{
23+
public static bool TryDispose(this IDisposable disposable)
24+
{
25+
try
26+
{
27+
disposable.Dispose();
28+
return true;
29+
}
30+
catch
31+
{
32+
return false;
33+
}
34+
}
35+
}

ARSoft.Tools.Net/Dns/DnsMessageBase.cs

+3-6
Original file line numberDiff line numberDiff line change
@@ -814,12 +814,9 @@ internal static void EncodeTextBlock(IList<byte> messageData, ref int currentPos
814814
{
815815
var textData = Encoding.ASCII.GetBytes(text);
816816

817-
for (var i = 0; i < textData.Length; i += 255)
818-
{
819-
var blockLength = Math.Min(255, (textData.Length - i));
820-
messageData[currentPosition++] = (byte) blockLength;
821-
EncodeByteArray(messageData, ref currentPosition, textData, i, blockLength);
822-
}
817+
var blockLength = Math.Min(255, textData.Length);
818+
messageData[currentPosition++] = (byte) blockLength;
819+
EncodeByteArray(messageData, ref currentPosition, textData, 0, blockLength);
823820
}
824821

825822
internal static void EncodeTextWithoutLength(IList<byte> messageData, ref int currentPosition, string text)

ARSoft.Tools.Net/Dns/DnsRecord/AplRecord.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ internal static AddressPrefix Parse(string s)
117117
if ((address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork) && (groups["fam"].Value != "1"))
118118
throw new FormatException();
119119

120-
return new AddressPrefix(groups["isneg"].Success, address, Byte.Parse(groups["pref"].Value));
120+
return new AddressPrefix(groups["isneg"].Length > 0, address, Byte.Parse(groups["pref"].Value));
121121
}
122122
}
123123

ARSoft.Tools.Net/Dns/DnsRecord/CertRecord.cs

+12-1
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ internal CertRecord(DomainName name, RecordType recordType, RecordClass recordCl
172172
if (stringRepresentation.Length < 4)
173173
throw new FormatException();
174174

175-
Type = (CertType) UInt16.Parse(stringRepresentation[0]);
175+
Type = ParseCertType(stringRepresentation[0]);
176176
KeyTag = UInt16.Parse(stringRepresentation[1]);
177177
Algorithm = (DnsSecAlgorithm) Byte.Parse(stringRepresentation[2]);
178178
Certificate = String.Join(String.Empty, stringRepresentation.Skip(3)).FromBase64String();
@@ -196,6 +196,17 @@ public CertRecord(DomainName name, int timeToLive, CertType type, ushort keyTag,
196196
Certificate = certificate ?? new byte[] { };
197197
}
198198

199+
private static CertType ParseCertType(string s)
200+
{
201+
if (EnumHelper<CertType>.TryParse(s, true, out var mnemonic))
202+
return mnemonic;
203+
204+
if (UInt16.TryParse(s, out var numeric))
205+
return (CertType) numeric;
206+
207+
throw new FormatException();
208+
}
209+
199210
internal override string RecordDataToString()
200211
{
201212
return (ushort) Type

ARSoft.Tools.Net/Dns/DnsRecord/DnsRecordBase.cs

+8-8
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,8 @@ internal static DnsRecordBase ParseRecordFromBinary(int recordStartPosition, Dom
174174
return new OpenPGPKeyRecord(name, recordType, recordClass, timeToLive, resultData, recordDataPosition, recordDataLength);
175175
case RecordType.CSync:
176176
return new CSyncRecord(name, recordType, recordClass, timeToLive, resultData, recordDataPosition, recordDataLength);
177+
case RecordType.ZoneMD:
178+
return new ZoneMDRecord(name, recordType, recordClass, timeToLive, resultData, recordDataPosition, recordDataLength);
177179
case RecordType.SvcB:
178180
return new SvcBRecord(name, recordType, recordClass, timeToLive, resultData, recordDataPosition, recordDataLength);
179181
case RecordType.Https:
@@ -322,6 +324,8 @@ internal static DnsRecordBase ParseFromStringRepresentation(DomainName name, Rec
322324
return new OpenPGPKeyRecord(name, recordType, recordClass, timeToLive, origin, stringRepresentation);
323325
case RecordType.CSync:
324326
return new CSyncRecord(name, recordType, recordClass, timeToLive, origin, stringRepresentation);
327+
case RecordType.ZoneMD:
328+
return new ZoneMDRecord(name, recordType, recordClass, timeToLive, origin, stringRepresentation);
325329
case RecordType.SvcB:
326330
return new SvcBRecord(name, recordType, recordClass, timeToLive, origin, stringRepresentation);
327331
case RecordType.Https:
@@ -372,13 +376,13 @@ protected DomainName ParseDomainName(DomainName origin, string name)
372376
#region Encoding
373377
internal sealed override int MaximumLength => Name.MaximumRecordDataLength + 12 + MaximumRecordDataLength;
374378

375-
internal void Encode(IList<byte> messageData, ref int currentPosition, Dictionary<DomainName, ushort> domainNames, bool useCanonical = false)
379+
internal void Encode(IList<byte> messageData, ref int currentPosition, Dictionary<DomainName, ushort>? domainNames, bool useCanonical = false)
376380
{
377381
EncodeRecordHeader(messageData, ref currentPosition, domainNames, useCanonical);
378382
EncodeRecordBody(messageData, ref currentPosition, domainNames, useCanonical);
379383
}
380384

381-
internal void EncodeRecordHeader(IList<byte> messageData, ref int currentPosition, Dictionary<DomainName, ushort> domainNames, bool useCanonical)
385+
internal void EncodeRecordHeader(IList<byte> messageData, ref int currentPosition, Dictionary<DomainName, ushort>? domainNames, bool useCanonical)
382386
{
383387
DnsMessageBase.EncodeDomainName(messageData, ref currentPosition, Name, domainNames, useCanonical);
384388
DnsMessageBase.EncodeUShort(messageData, ref currentPosition, (ushort) RecordType);
@@ -508,17 +512,13 @@ public int CompareTo(DnsRecordBase? other)
508512
if (compare != 0)
509513
return compare;
510514

511-
compare = TimeToLive.CompareTo(other.TimeToLive);
512-
if (compare != 0)
513-
return compare;
514-
515515
var thisBuffer = new byte[MaximumRecordDataLength];
516516
int thisLength = 0;
517-
EncodeRecordData(thisBuffer, ref thisLength, null, false);
517+
EncodeRecordData(thisBuffer, ref thisLength, null, true);
518518

519519
var otherBuffer = new byte[other.MaximumRecordDataLength];
520520
int otherLength = 0;
521-
other.EncodeRecordData(otherBuffer, ref otherLength, null, false);
521+
other.EncodeRecordData(otherBuffer, ref otherLength, null, true);
522522

523523
for (int i = 0; i < Math.Min(thisLength, otherLength); i++)
524524
{

ARSoft.Tools.Net/Dns/DnsRecord/LocRecord.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ namespace ARSoft.Tools.Net.Dns
3535
/// </summary>
3636
public class LocRecord : DnsRecordBase
3737
{
38-
private static readonly Regex _parserRegex = new Regex(@"^(?<latd>\d{1,2})( (?<latm>\d{1,2})( (?<lats>\d{1,2})(\.(?<latms>\d{1,3}))?)?)? (?<lat>(N|S)) (?<longd>\d{1,2})( (?<longm>\d{1,2})( (?<longs>\d{1,2})(\.(?<longms>\d{1,3}))?)?)? (?<long>(W|E)) (?<alt>-?\d{1,2}(\.\d+)?)m?( (?<size>\d+(\.\d+)?)m?( (?<hp>\d+(\.\d+)?)m?( (?<vp>\d+(\.\d+)?)m?)?)?)?$", RegexOptions.IgnoreCase | RegexOptions.ExplicitCapture | RegexOptions.Compiled);
38+
private static readonly Regex _parserRegex = new Regex(@"^(?<latd>\d{1,2})( (?<latm>\d{1,2})( (?<lats>\d{1,2})(\.(?<latms>\d{1,3}))?)?)? (?<lat>(N|S)) (?<longd>\d{1,3})( (?<longm>\d{1,2})( (?<longs>\d{1,2})(\.(?<longms>\d{1,3}))?)?)? (?<long>(W|E)) (?<alt>-?\d+(\.\d+)?)m?( (?<size>\d+(\.\d+)?)m?( (?<hp>\d+(\.\d+)?)m?( (?<vp>\d+(\.\d+)?)m?)?)?)?$", RegexOptions.IgnoreCase | RegexOptions.ExplicitCapture | RegexOptions.Compiled);
3939

4040
/// <summary>
4141
/// Represents a geopgraphical degree

ARSoft.Tools.Net/Dns/DnsRecord/NaptrRecord.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ internal NaptrRecord(DomainName name, RecordType recordType, RecordClass recordC
8181
: base(name, recordType, recordClass, timeToLive)
8282
{
8383
if (stringRepresentation.Length != 6)
84-
throw new NotSupportedException();
84+
throw new FormatException();
8585

8686
Order = UInt16.Parse(stringRepresentation[0]);
8787
Preference = UInt16.Parse(stringRepresentation[1]);

0 commit comments

Comments
 (0)