Skip to content

Commit 20b0ac4

Browse files
Added support for CDS/CDNS records as specified in RFC 7344 (#232)
Added support for CDS/CDNS records as specified in RFC 7344
1 parent f1e7ca3 commit 20b0ac4

File tree

6 files changed

+106
-1
lines changed

6 files changed

+106
-1
lines changed

src/DnsClient/DnsRecordFactory.cs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,14 @@ public DnsResourceRecord GetRecord(ResourceRecordInfo info)
180180
result = ResolveTlsaRecord(info);
181181
break;
182182

183+
case ResourceRecordType.CDS: //59
184+
result = ResolveCdsRecord(info);
185+
break;
186+
187+
case ResourceRecordType.CDNS: //60
188+
result = ResolveCdnsKeyRecord(info);
189+
break;
190+
183191
case ResourceRecordType.SPF: // 99
184192
result = ResolveTxtRecord(info);
185193
break;
@@ -378,6 +386,26 @@ private TlsaRecord ResolveTlsaRecord(ResourceRecordInfo info)
378386
return new TlsaRecord(info, certificateUsage, selector, matchingType, certificateAssociationData);
379387
}
380388

389+
private CdsRecord ResolveCdsRecord(ResourceRecordInfo info)
390+
{
391+
var startIndex = _reader.Index;
392+
var keyTag = _reader.ReadUInt16NetworkOrder();
393+
var algorithm = _reader.ReadByte();
394+
var digestType = _reader.ReadByte();
395+
var digest = _reader.ReadBytesToEnd(startIndex, info.RawDataLength).ToArray();
396+
return new CdsRecord(info, keyTag, algorithm, digestType, digest);
397+
}
398+
399+
private CdnsKeyRecord ResolveCdnsKeyRecord(ResourceRecordInfo info)
400+
{
401+
var startIndex = _reader.Index;
402+
int flags = _reader.ReadUInt16NetworkOrder();
403+
var protocol = _reader.ReadByte();
404+
var algorithm = _reader.ReadByte();
405+
var publicKey = _reader.ReadBytesToEnd(startIndex, info.RawDataLength).ToArray();
406+
return new CdnsKeyRecord(info, flags, protocol, algorithm, publicKey);
407+
}
408+
381409
private UriRecord ResolveUriRecord(ResourceRecordInfo info)
382410
{
383411
var prio = _reader.ReadUInt16NetworkOrder();
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using System;
2+
3+
namespace DnsClient.Protocol
4+
{
5+
/// <summary>
6+
/// https://datatracker.ietf.org/doc/html/rfc7344#section-3.2
7+
/// The wire and presentation format of the CDNSKEY ("Child DNSKEY") resource record is identical to the DNSKEY record.
8+
/// </summary>
9+
public class CdnsKeyRecord : DnsKeyRecord
10+
{
11+
/// <summary>
12+
/// Initializes a new instance of the <see cref="CdnsKeyRecord"/> class. The record is identical to <see cref="DnsKeyRecord"/>
13+
/// </summary>
14+
/// <param name="info"></param>
15+
/// <param name="flags"></param>
16+
/// <param name="protocol"></param>
17+
/// <param name="algorithm"></param>
18+
/// <param name="publicKey"></param>
19+
/// <exception cref="ArgumentNullException">If <paramref name="info"/> or <paramref name="publicKey"/> is null.</exception>
20+
public CdnsKeyRecord(ResourceRecordInfo info, int flags, byte protocol, byte algorithm, byte[] publicKey) : base(info, flags, protocol, algorithm, publicKey)
21+
{
22+
}
23+
}
24+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using System;
2+
3+
namespace DnsClient.Protocol
4+
{
5+
/// <summary>
6+
/// https://datatracker.ietf.org/doc/html/rfc7344#section-3.1
7+
/// The wire and presentation format of the Child DS (CDS) resource record is identical to the DS record [RFC4034]
8+
/// </summary>
9+
public class CdsRecord : DsRecord
10+
{
11+
/// <summary>
12+
/// Initializes a new instance of the <see cref="CdsRecord"/> class. The record is identical to <see cref="DsRecord"/>
13+
/// </summary>
14+
/// <param name="info"></param>
15+
/// <param name="keyTag"></param>
16+
/// <param name="algorithm"></param>
17+
/// <param name="digestType"></param>
18+
/// <param name="digest"></param>
19+
/// <exception cref="ArgumentNullException">If <paramref name="info"/> or <paramref name="digest"/> is null.</exception>
20+
public CdsRecord(ResourceRecordInfo info, int keyTag, byte algorithm, byte digestType, byte[] digest) : base(info, keyTag, algorithm, digestType, digest)
21+
{
22+
}
23+
}
24+
}

src/DnsClient/Protocol/ResourceRecordType.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,20 @@ public enum ResourceRecordType
241241
/// <seealso href="https://https://tools.ietf.org/html/rfc6698">RFC 6698</seealso>
242242
TLSA = 52,
243243

244+
/// <summary>
245+
/// TLSA rfc7344.
246+
/// </summary>
247+
/// <seealso href="https://https://tools.ietf.org/html/rfc7344">RFC 7344</seealso>
248+
CDS = 59,
249+
250+
/// <summary>
251+
/// TLSA rfc7344.
252+
/// </summary>
253+
/// <seealso href="https://https://tools.ietf.org/html/rfc7344">RFC 7344</seealso>
254+
CDNS = 60,
255+
256+
257+
244258
/// <summary>
245259
/// SPF records don't officially have a dedicated RR type, <see cref="TXT"/> should be used instead.
246260
/// The behavior of TXT and SPF are the same.

src/DnsClient/QueryType.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,19 @@ public enum QueryType
225225
/// <seealso href="https://https://tools.ietf.org/html/rfc6698">RFC 6698</seealso>
226226
TLSA = ResourceRecordType.TLSA,
227227

228+
/// <summary>
229+
/// TLSA rfc7344.
230+
/// </summary>
231+
/// <seealso href="https://https://tools.ietf.org/html/rfc7344">RFC 7344</seealso>
232+
CDS = ResourceRecordType.CDS,
233+
234+
/// <summary>
235+
/// TLSA rfc7344.
236+
/// </summary>
237+
/// <seealso href="https://https://tools.ietf.org/html/rfc7344">RFC 7344</seealso>
238+
CDNS = ResourceRecordType.CDNS,
239+
240+
228241
/// <summary>
229242
/// SPF records don't officially have a dedicated RR type, <see cref="ResourceRecordType.TXT"/> should be used instead.
230243
/// The behavior of TXT and SPF are the same.

test/DnsClient.Tests/DnsResponseParsingTest.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ public void DnsRecordFactory_McnetValidateSupport()
5151
ResourceRecordType.SPF,
5252
ResourceRecordType.DNSKEY,
5353
ResourceRecordType.DS,
54-
ResourceRecordType.CERT
54+
ResourceRecordType.CERT,
55+
ResourceRecordType.CDS,
56+
ResourceRecordType.CDNS
5557
};
5658

5759
foreach (var t in types)

0 commit comments

Comments
 (0)