public void DnsRecordFactory_DsRecord() { var expectedDigest = "3490A6806D47F17A34C29E2CE80E8A999FFBE4BE"; var expectedBytes = Enumerable.Range(0, expectedDigest.Length) .Where(x => x % 2 == 0) .Select(x => Convert.ToByte(expectedDigest.Substring(x, 2), 16)) .ToArray(); var name = DnsString.Parse("example.com"); var writer = new DnsDatagramWriter(); writer.WriteInt16NetworkOrder(31589); writer.WriteByte(8); // algorithm writer.WriteByte(1); // type writer.WriteBytes(expectedBytes, expectedBytes.Length); var factory = GetFactory(writer.Data.ToArray()); var info = new ResourceRecordInfo(name, ResourceRecordType.DS, QueryClass.IN, 0, writer.Data.Count); var result = factory.GetRecord(info) as DsRecord; Assert.Equal(expectedBytes, result.Digest); Assert.Equal(expectedDigest, result.DigestAsString); Assert.Equal(31589, result.KeyTag); Assert.Equal(8, (int)result.Algorithm); Assert.Equal(1, result.DigestType); }
public override DnsResponseMessage Query( IPEndPoint server, DnsRequestMessage request, TimeSpan timeout) { using (var writer = new DnsDatagramWriter()) { GetRequestData(request, writer); if (writer.Data.Count != _questionRaw.Length) { throw new Exception(); } } // Allocation test will probably include this copy of the array, but the data has to be copied, otherwise the ID change would be shared... using (var writer = new DnsDatagramWriter(new ArraySegment <byte>(_answer.ToArray()))) { writer.Index = 0; writer.WriteInt16NetworkOrder((short)request.Header.Id); writer.Index = _answer.Length; var response = GetResponseMessage(writer.Data); if (response.Header.Id != request.Header.Id) { throw new Exception(); } return(response); } }
public void DnsRecordFactory_RRSIGRecord() { var type = ResourceRecordType.NSEC; var algorithmNumber = DnsSecurityAlgorithm.ECDSAP256SHA256; var labels = 5; var originalTtl = 300; var signatureExpiration = 1589414400; var signatureInception = 1587600000; short keytag = 3942; var signersName = DnsString.Parse("result.example.com"); var signatureString = "kfyyKQoPZJFyOFSDqav7wj5XNRPqZssV2K2k8MJun28QSsCMHyWOjw9Hk4KofnEIUWNui3mMgAEFYbwoeRKkMf5uDAh6ryJ4veQNj86mgYJrpJppUplqlqJE8o1bx0I1VfwheL+M23bL5MnqSGiI5igmMDyeVUraVOO4RQyfGN0="; var signature = Convert.FromBase64String(signatureString); var writer = new DnsDatagramWriter(); writer.WriteInt16NetworkOrder((short)type); writer.WriteByte((byte)algorithmNumber); writer.WriteByte((byte)labels); writer.WriteInt32NetworkOrder(originalTtl); writer.WriteInt32NetworkOrder(signatureExpiration); writer.WriteInt32NetworkOrder(signatureInception); writer.WriteInt16NetworkOrder(keytag); writer.WriteHostName(signersName.Value); writer.WriteBytes(signature, signature.Length); var factory = GetFactory(writer.Data.ToArray()); var info = new ResourceRecordInfo("query.example.com", ResourceRecordType.RRSIG, QueryClass.IN, 0, writer.Data.Count); var result = factory.GetRecord(info) as RRSigRecord; Assert.Equal(type, result.CoveredType); Assert.Equal(algorithmNumber, result.Algorithm); Assert.Equal(labels, result.Labels); Assert.Equal(originalTtl, result.OriginalTtl); Assert.Equal(DateTimeOffset.FromUnixTimeSeconds(signatureExpiration), result.SignatureExpiration); Assert.Equal(DateTimeOffset.FromUnixTimeSeconds(signatureInception), result.SignatureInception); Assert.Equal(signersName.Value, result.SignersName); Assert.Equal(signature, result.Signature); Assert.Equal(signatureString, result.SignatureAsString); }
public override DnsResponseMessage Query( IPEndPoint server, DnsRequestMessage request, TimeSpan timeout) { var writer = new DnsDatagramWriter(new ArraySegment <byte>(ZoneData.ToArray())); writer.Index = 0; writer.WriteInt16NetworkOrder((short)request.Header.Id); writer.Index = ZoneData.Length; var response = GetResponseMessage(writer.Data); if (response.Header.Id != request.Header.Id) { throw new Exception(); } return(response); }
public void DnsRecordFactory_DnsKeyRecord() { var expectedPublicKey = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; var expectedBytes = Encoding.UTF8.GetBytes(expectedPublicKey); var name = DnsString.Parse("example.com"); var writer = new DnsDatagramWriter(); writer.WriteInt16NetworkOrder(256); writer.WriteByte(3); writer.WriteByte((byte)DnsSecurityAlgorithm.RSASHA256); writer.WriteBytes(expectedBytes, expectedBytes.Length); var factory = GetFactory(writer.Data.ToArray()); var info = new ResourceRecordInfo(name, ResourceRecordType.DNSKEY, QueryClass.IN, 0, writer.Data.Count); var result = factory.GetRecord(info) as DnsKeyRecord; Assert.Equal(expectedBytes, result.PublicKey); Assert.Equal(256, result.Flags); Assert.Equal(3, result.Protocol); Assert.Equal(DnsSecurityAlgorithm.RSASHA256, result.Algorithm); }