protected DnsRecordBase(string name, RecordType recordType, RecordClass recordClass, int timeToLive) { Name = name ?? String.Empty; RecordType = recordType; RecordClass = recordClass; TimeToLive = timeToLive; }
/// <summary> /// Creates a new instance of the DiffieHellmanKeyRecord class /// </summary> /// <param name="name"> Name of the record </param> /// <param name="recordClass"> Class of the record </param> /// <param name="timeToLive"> Seconds the record should be cached at most </param> /// <param name="flags"> Flags of the key </param> /// <param name="protocol"> Protocol for which the key is used </param> /// <param name="prime"> Binary data of the prime of the key </param> /// <param name="generator"> Binary data of the generator of the key </param> /// <param name="publicValue"> Binary data of the public value </param> public DiffieHellmanKeyRecord(string name, RecordClass recordClass, int timeToLive, ushort flags, ProtocolType protocol, byte[] prime, byte[] generator, byte[] publicValue) : base(name, recordClass, timeToLive, flags, protocol, DnsSecAlgorithm.DiffieHellman) { Prime = prime ?? new byte[] { }; Generator = generator ?? new byte[] { }; PublicValue = publicValue ?? new byte[] { }; }
public void WriteQuestion(Name name, RecordType qtype, RecordClass qclass = RecordClass.Internet) { WriteName(name); WriteUInt16((ushort)qtype); WriteUInt16((ushort)qclass); _questionCount++; }
internal ResourceRecord(string name, RecordType type, RecordClass rClass, DateTime expiry) { _name = name; _type = type; _class = rClass; _expiry = expiry; }
private DnsResponse(ushort messageId, DnsName queryName, RecordType queryType, RecordClass queryClass) { this.MessageId = messageId; this.QueryName = queryName; this.QueryType = queryType; this.QueryClass = queryClass; }
public ResourceRecord(DnsReader br) { _domain = br.ReadDomain(); _qtype = (RecordType)br.ReadInt16(); _qclass = (RecordClass)br.ReadInt16(); _ttl = br.ReadInt32(); int recordLength = br.ReadInt16(); if (recordLength != 0) { switch (_qtype) { case RecordType.A: _record = new ARecord(br); break; case RecordType.CNAME: _record = new CNAMERecord(br); break; case RecordType.MX: _record = new MXRecord(br); break; case RecordType.NS: _record = new NSRecord(br); break; case RecordType.SOA: _record = new SOARecord(br); break; case RecordType.TXT: _record = new TXTRecord(br); break; case RecordType.PTR: _record = new PTRERecord(br); break; // NetBIOS related records case RecordType.NB: _record = new NBRecord(br); break; default: br += recordLength; break; } } }
public LogRecord(String message, RecordClass recordClass, TimeSpan? runningTime, DateTime timeStamp) { this.message = message; this.recordClass = recordClass; this.runningTime = runningTime; this.timeStamp = timeStamp; }
/// <summary> /// Creates a new key record. /// </summary> /// <param name="name">The name.</param> /// <param name="recordClass">The record class.</param> /// <param name="timeToLive">The time-to-live.</param> /// <param name="flags">The flags.</param> /// <param name="protocol">The protocol.</param> /// <param name="algorithm">The algorithm.</param> protected KeyRecordBase(string name, RecordClass recordClass, int timeToLive, ushort flags, ProtocolType protocol, DnsSecAlgorithm algorithm) : base(name, RecordType.Key, recordClass, timeToLive) { this.Flags = flags; this.Protocol = protocol; this.Algorithm = algorithm; }
public DnsKeyRecord(string name, RecordClass recordClass, int timeToLive, ushort flags, byte protocol, DnsSecAlgorithm algorithm, byte[] publicKey) : base(name, RecordType.DnsKey, recordClass, timeToLive) { Flags = flags; Protocol = protocol; Algorithm = algorithm; PublicKey = publicKey ?? new byte[] { }; }
/// <summary> /// Creates a new instance of the DsRecord class. /// </summary> /// <param name="name">Name of the record.</param> /// <param name="recordClass">Class of the record.</param> /// <param name="timeToLive">Seconds the record should be cached at most.</param> /// <param name="keyTag">Key tag.</param> /// <param name="algorithm">Algorithm used.</param> /// <param name="digestType">Type of the digest.</param> /// <param name="digest">Binary data of the digest.</param> public DsRecord(string name, RecordClass recordClass, int timeToLive, ushort keyTag, DnsSecAlgorithm algorithm, DnsSecDigestType digestType, byte[] digest) : base(name, RecordType.Ds, recordClass, timeToLive) { this.KeyTag = keyTag; this.Algorithm = algorithm; this.DigestType = digestType; this.Digest = digest ?? new byte[] { }; }
public NSec3ParamRecord(string name, RecordClass recordClass, int timeToLive, DnsSecAlgorithm hashAlgorithm, byte flags, ushort iterations, byte[] salt) : base(name, RecordType.NSec3Param, recordClass, timeToLive) { HashAlgorithm = hashAlgorithm; Flags = flags; Iterations = iterations; Salt = salt ?? new byte[] { }; }
/// <summary> /// Creates a new instance of the CDsRecord class /// </summary> /// <param name="name"> Name of the record </param> /// <param name="recordClass"> Class of the record </param> /// <param name="timeToLive"> Seconds the record should be cached at most </param> /// <param name="keyTag"> Key tag </param> /// <param name="algorithm"> Algorithm used </param> /// <param name="digestType"> Type of the digest </param> /// <param name="digest"> Binary data of the digest </param> public CDsRecord(DomainName name, RecordClass recordClass, int timeToLive, ushort keyTag, DnsSecAlgorithm algorithm, DnsSecDigestType digestType, byte[] digest) : base(name, RecordType.Ds, recordClass, timeToLive) { KeyTag = keyTag; Algorithm = algorithm; DigestType = digestType; Digest = digest ?? new byte[] { }; }
protected DnsMessageBase(ushort messageId, DnsName queryName, RecordType queryType, RecordClass queryClass) : this() { this.MessageId = messageId; this.QueryCount = 1; this.QueryName = queryName; this.QueryType = queryType; this.QueryClass = queryClass; }
public ResourceRecord(Domain domain, byte[] data, RecordType type, RecordClass klass = RecordClass.IN, TimeSpan ttl = default(TimeSpan)) { this.domain = domain; this.type = type; this.klass = klass; this.ttl = ttl; this.data = data; }
internal PointerRecord(string name, RecordType type, RecordClass rClass, DateTime expiry, PacketReader reader) : base(name, type, rClass, expiry) { ushort dataLen = reader.ReadUShort(); int pos = reader.Position; _targetName = reader.ReadName(); reader.Position = pos + dataLen; }
internal IP4AddressRecord(string name, RecordType type, RecordClass rClass, DateTime expiry, PacketReader reader) : base(name, type, rClass, expiry) { ushort dataLen = reader.ReadUShort(); int pos = reader.Position; _address = new IPAddress(reader.ReadBytes(dataLen)); reader.Position = pos + dataLen; }
static DnsMessage DnsResolve(string name, RecordType recordType, RecordClass recordClass) { DnsClient dnsClient; if (WindowsNameServicesManager.NameServerHookMethod != WindowsNameServicesManager.NameServerHookMethodType.ChangeNS) dnsClient = DnsClient.Default; else { dnsClient = GetNonDefaultDnsClient(); } return dnsClient.Resolve(name, recordType, recordClass); }
protected ResourceRecordBase(DnsName name, RecordType recordType, RecordClass recordClass, uint timeToLive) { if (name == null) { throw new ArgumentNullException(nameof(name)); } this.Name = name; this.RecordType = recordType; this.RecordClass = recordClass; this.TimeToLive = timeToLive; }
/// <summary> /// Queries a dns server for specified records. /// </summary> /// <param name="name"> Domain, that should be queried </param> /// <param name="recordType"> Type the should be queried </param> /// <param name="recordClass"> Class the should be queried </param> /// <returns> The complete response of the dns server </returns> public DnsMessage Resolve(string name, RecordType recordType, RecordClass recordClass) { if (String.IsNullOrEmpty(name)) { throw new ArgumentException("Name must be provided", "name"); } DnsMessage message = new DnsMessage() { IsQuery = true, OperationCode = OperationCode.Query, IsRecursionDesired = true, IsEDnsEnabled = true }; message.Questions.Add(new DnsQuestion(name, recordType, recordClass)); return SendMessage(message); }
internal ServiceRecord(string name, RecordType type, RecordClass rClass, DateTime expiry, PacketReader reader) : base(name, type, rClass, expiry) { ushort dataLen = reader.ReadUShort(); int pos = reader.Position; _priority = reader.ReadUShort(); _weight = reader.ReadUShort(); _port = reader.ReadUShort(); _target = reader.ReadName(); reader.Position = pos + dataLen; }
/// <summary> /// Creates a new instance of the SigRecord class. /// </summary> /// <param name="name">Name of the record.</param> /// <param name="recordClass">Class of the record.</param> /// <param name="timeToLive">Seconds the record should be cached at most.</param> /// <param name="typeCovered"><see cref="RecordType">Record type</see> that is covered by this record.</param> /// <param name="algorithm"><see cref="DnsSecAlgorithm">Algorithm</see> that is used for signature.</param> /// <param name="labels">Label count of original record that is covered by this record.</param> /// <param name="originalTimeToLive">Original time to live value of original record that is covered by this record.</param> /// <param name="signatureExpiration">Signature is valid until this date.</param> /// <param name="signatureInception">Signature is valid from this date.</param> /// <param name="keyTag">Key tag.</param> /// <param name="signersName">Domain name of generator of the signature.</param> /// <param name="signature">Binary data of the signature.</param> public SigRecord(string name, RecordClass recordClass, int timeToLive, RecordType typeCovered, DnsSecAlgorithm algorithm, byte labels, int originalTimeToLive, DateTime signatureExpiration, DateTime signatureInception, ushort keyTag, string signersName, byte[] signature) : base(name, RecordType.Sig, recordClass, timeToLive) { this.TypeCovered = typeCovered; this.Algorithm = algorithm; this.Labels = labels; this.OriginalTimeToLive = originalTimeToLive; this.SignatureExpiration = signatureExpiration; this.SignatureInception = signatureInception; this.KeyTag = keyTag; this.SignersName = signersName ?? String.Empty; this.Signature = signature ?? new byte[] { }; }
/// <summary> /// Creates a new instance of the NSecRecord class /// </summary> /// <param name="name"> Name of the record </param> /// <param name="recordClass"> Class of the record </param> /// <param name="timeToLive"> Seconds the record should be cached at most </param> /// <param name="nextDomainName"> Name of next owner </param> /// <param name="types"> Record types of the next owner </param> public NSecRecord(DomainName name, RecordClass recordClass, int timeToLive, DomainName nextDomainName, List<RecordType> types) : base(name, RecordType.NSec, recordClass, timeToLive) { NextDomainName = nextDomainName ?? DomainName.Root; if ((types == null) || (types.Count == 0)) { Types = new List<RecordType>(); } else { Types = types.Distinct().OrderBy(x => x).ToList(); } }
/// <summary> /// Creates a new instance of the NSecRecord class /// </summary> /// <param name="name"> Name of the record </param> /// <param name="recordClass"> Class of the record </param> /// <param name="timeToLive"> Seconds the record should be cached at most </param> /// <param name="nextDomainName"> Name of next owner </param> /// <param name="types"> Record types of the next owner </param> public NSecRecord(string name, RecordClass recordClass, int timeToLive, string nextDomainName, List<RecordType> types) : base(name, RecordType.NSec, recordClass, timeToLive) { NextDomainName = nextDomainName ?? String.Empty; if ((types == null) || (types.Count == 0)) { Types = new List<RecordType>(); } else { Types = new List<RecordType>(types); types.Sort((left, right) => ((ushort) left).CompareTo((ushort) right)); } }
/// <summary> /// Creates a new instance of the CSyncRecord class /// </summary> /// <param name="name"> Name of the record </param> /// <param name="recordClass"> Class of the record </param> /// <param name="timeToLive"> Seconds the record should be cached at most </param> /// <param name="serialNumber"> SOA Serial Field </param> /// <param name="flags"> Flags</param> /// <param name="types"> Record types of the next owner </param> public CSyncRecord(DomainName name, RecordClass recordClass, int timeToLive, uint serialNumber, CSyncFlags flags, List<RecordType> types) : base(name, RecordType.CSync, recordClass, timeToLive) { SerialNumber = serialNumber; Flags = flags; if ((types == null) || (types.Count == 0)) { Types = new List<RecordType>(); } else { Types = types.Distinct().OrderBy(x => x).ToList(); } }
internal TextRecord(string name, RecordType type, RecordClass rClass, DateTime expiry, PacketReader reader) : base(name, type, rClass, expiry) { _values = new Dictionary<string, byte[]>(); ushort dataLen = reader.ReadUShort(); int pos = reader.Position; while (reader.Position < pos + dataLen) { int valueLen = reader.ReadByte(); byte[] valueBinary = reader.ReadBytes(valueLen); StoreValue(valueBinary); } }
public DnsMessage Resolve(string name, RecordType recordType, RecordClass recordClass) { name = name.ToLower(); lock(lock_) { if(cache_.ContainsKey(name)) return cache_[name]; DnsMessage message = dns_.Resolve(name); if(null == message) return null; cache_.Add(name, message); return message; } }
/// <summary> /// Creates of new instance of the NSec3Record class /// </summary> /// <param name="name"> Name of the record </param> /// <param name="recordClass"> Class of the record </param> /// <param name="timeToLive"> Seconds the record should be cached at most </param> /// <param name="hashAlgorithm"> Algorithm of hash </param> /// <param name="flags"> Flags of the record </param> /// <param name="iterations"> Number of iterations </param> /// <param name="salt"> Binary data of salt </param> /// <param name="nextHashedOwnerName"> Binary data of hash of next owner </param> /// <param name="types"> Types of next owner </param> public NSec3Record(DomainName name, RecordClass recordClass, int timeToLive, NSec3HashAlgorithm hashAlgorithm, byte flags, ushort iterations, byte[] salt, byte[] nextHashedOwnerName, List<RecordType> types) : base(name, RecordType.NSec3, recordClass, timeToLive) { HashAlgorithm = hashAlgorithm; Flags = flags; Iterations = iterations; Salt = salt ?? new byte[] { }; NextHashedOwnerName = nextHashedOwnerName ?? new byte[] { }; if ((types == null) || (types.Count == 0)) { Types = new List<RecordType>(); } else { Types = types.Distinct().OrderBy(x => x).ToList(); } }
/// <summary> /// Creates of new instance of the NSec3Record class. /// </summary> /// <param name="name">Name of the record.</param> /// <param name="recordClass">Class of the record.</param> /// <param name="timeToLive">Seconds the record should be cached at most.</param> /// <param name="hashAlgorithm">Algorithm of hash.</param> /// <param name="flags">Flags of the record.</param> /// <param name="iterations">Number of iterations.</param> /// <param name="salt">Binary data of salt.</param> /// <param name="nextHashedOwnerName">Binary data of hash of next owner.</param> /// <param name="types">Types of next owner.</param> public NSec3Record(string name, RecordClass recordClass, int timeToLive, DnsSecAlgorithm hashAlgorithm, byte flags, ushort iterations, byte[] salt, byte[] nextHashedOwnerName, List<RecordType> types) : base(name, RecordType.NSec3, recordClass, timeToLive) { this.HashAlgorithm = hashAlgorithm; this.Flags = flags; this.Iterations = iterations; this.Salt = salt ?? new byte[] { }; this.NextHashedOwnerName = nextHashedOwnerName ?? new byte[] { }; if ((types == null) || (types.Count == 0)) { this.Types = new List<RecordType>(); } else { this.Types = new List<RecordType>(types); types.Sort((left, right) => ((ushort) left).CompareTo((ushort) right)); } }
public Question(string domain, RecordType qtype, RecordClass qclass) { if (qtype == RecordType.PTR) { IPAddress addr = IPAddress.Parse (domain); StringBuilder sb = new StringBuilder(); byte[] addrBytes = addr.GetAddressBytes(); for(int i=addrBytes.Length -1; i>=0; i--) sb.Append((int)addrBytes[i] + "."); sb.Append ("in-addr.arpa"); _domain = sb.ToString (); } else _domain = domain; _qtype = qtype; _qclass = qclass; }
public void WriteRecordStart(RecordSection recordType, Name name, RecordType type, uint ttl, RecordClass _class = RecordClass.Internet) { Debug.Assert(_recordStartPosition == 0); WriteName(name); WriteUInt16((ushort)type); WriteUInt16((ushort)_class); WriteUInt32(ttl); WriteUInt16(0); switch (recordType) { case RecordSection.Answer: _answerCount++; break; case RecordSection.Additional: _additionalCount++; break; case RecordSection.Authority: _authorityCount++; break; } _recordStartPosition = _stream.Position; }
/// <summary> /// Creates a new signing key pair /// </summary> /// <param name="name">The name of the key or zone</param> /// <param name="recordClass">The record class of the DnsKeyRecord</param> /// <param name="timeToLive">The TTL in seconds to the DnsKeyRecord</param> /// <param name="flags">The Flags of the DnsKeyRecord</param> /// <param name="protocol">The protocol version</param> /// <param name="algorithm">The key algorithm</param> /// <param name="keyStrength">The key strength or 0 for default strength</param> /// <returns></returns> public static DnsKeyRecord CreateSigningKey(DomainName name, RecordClass recordClass, int timeToLive, DnsKeyFlags flags, byte protocol, DnsSecAlgorithm algorithm, int keyStrength = 0) { byte[] privateKey; byte[] publicKey; switch (algorithm) { case DnsSecAlgorithm.RsaSha1: case DnsSecAlgorithm.RsaSha1Nsec3Sha1: case DnsSecAlgorithm.RsaSha256: case DnsSecAlgorithm.RsaSha512: if (keyStrength == 0) { keyStrength = (flags == (DnsKeyFlags.Zone | DnsKeyFlags.SecureEntryPoint)) ? 2048 : 1024; } RsaKeyPairGenerator rsaKeyGen = new RsaKeyPairGenerator(); rsaKeyGen.Init(new KeyGenerationParameters(_secureRandom, keyStrength)); var rsaKey = rsaKeyGen.GenerateKeyPair(); privateKey = PrivateKeyInfoFactory.CreatePrivateKeyInfo(rsaKey.Private).GetDerEncoded(); var rsaPublicKey = (RsaKeyParameters)rsaKey.Public; var rsaExponent = rsaPublicKey.Exponent.ToByteArrayUnsigned(); var rsaModulus = rsaPublicKey.Modulus.ToByteArrayUnsigned(); int offset = 1; if (rsaExponent.Length > 255) { publicKey = new byte[3 + rsaExponent.Length + rsaModulus.Length]; DnsMessageBase.EncodeUShort(publicKey, ref offset, (ushort)publicKey.Length); } else { publicKey = new byte[1 + rsaExponent.Length + rsaModulus.Length]; publicKey[0] = (byte)rsaExponent.Length; } DnsMessageBase.EncodeByteArray(publicKey, ref offset, rsaExponent); DnsMessageBase.EncodeByteArray(publicKey, ref offset, rsaModulus); break; case DnsSecAlgorithm.Dsa: case DnsSecAlgorithm.DsaNsec3Sha1: if (keyStrength == 0) { keyStrength = 1024; } DsaParametersGenerator dsaParamsGen = new DsaParametersGenerator(); dsaParamsGen.Init(keyStrength, 12, _secureRandom); DsaKeyPairGenerator dsaKeyGen = new DsaKeyPairGenerator(); dsaKeyGen.Init(new DsaKeyGenerationParameters(_secureRandom, dsaParamsGen.GenerateParameters())); var dsaKey = dsaKeyGen.GenerateKeyPair(); privateKey = PrivateKeyInfoFactory.CreatePrivateKeyInfo(dsaKey.Private).GetDerEncoded(); var dsaPublicKey = (DsaPublicKeyParameters)dsaKey.Public; var dsaY = dsaPublicKey.Y.ToByteArrayUnsigned(); var dsaP = dsaPublicKey.Parameters.P.ToByteArrayUnsigned(); var dsaQ = dsaPublicKey.Parameters.Q.ToByteArrayUnsigned(); var dsaG = dsaPublicKey.Parameters.G.ToByteArrayUnsigned(); var dsaT = (byte)((dsaY.Length - 64) / 8); publicKey = new byte[21 + 3 * dsaY.Length]; publicKey[0] = dsaT; dsaQ.CopyTo(publicKey, 1); dsaP.CopyTo(publicKey, 21); dsaG.CopyTo(publicKey, 21 + dsaY.Length); dsaY.CopyTo(publicKey, 21 + 2 * dsaY.Length); break; case DnsSecAlgorithm.EccGost: ECDomainParameters gostEcDomainParameters = ECGost3410NamedCurves.GetByOid(CryptoProObjectIdentifiers.GostR3410x2001CryptoProA); var gostKeyGen = new ECKeyPairGenerator(); gostKeyGen.Init(new ECKeyGenerationParameters(gostEcDomainParameters, _secureRandom)); var gostKey = gostKeyGen.GenerateKeyPair(); privateKey = PrivateKeyInfoFactory.CreatePrivateKeyInfo(gostKey.Private).GetDerEncoded(); var gostPublicKey = (ECPublicKeyParameters)gostKey.Public; publicKey = new byte[64]; gostPublicKey.Q.X.ToBigInteger().ToByteArrayUnsigned().CopyTo(publicKey, 32); gostPublicKey.Q.Y.ToBigInteger().ToByteArrayUnsigned().CopyTo(publicKey, 0); publicKey = publicKey.Reverse().ToArray(); break; case DnsSecAlgorithm.EcDsaP256Sha256: case DnsSecAlgorithm.EcDsaP384Sha384: int ecDsaDigestSize; X9ECParameters ecDsaCurveParameter; if (algorithm == DnsSecAlgorithm.EcDsaP256Sha256) { ecDsaDigestSize = new Sha256Digest().GetDigestSize(); ecDsaCurveParameter = NistNamedCurves.GetByOid(SecObjectIdentifiers.SecP256r1); } else { ecDsaDigestSize = new Sha384Digest().GetDigestSize(); ecDsaCurveParameter = NistNamedCurves.GetByOid(SecObjectIdentifiers.SecP384r1); } ECDomainParameters ecDsaP384EcDomainParameters = new ECDomainParameters( ecDsaCurveParameter.Curve, ecDsaCurveParameter.G, ecDsaCurveParameter.N, ecDsaCurveParameter.H, ecDsaCurveParameter.GetSeed()); var ecDsaKeyGen = new ECKeyPairGenerator(); ecDsaKeyGen.Init(new ECKeyGenerationParameters(ecDsaP384EcDomainParameters, _secureRandom)); var ecDsaKey = ecDsaKeyGen.GenerateKeyPair(); privateKey = PrivateKeyInfoFactory.CreatePrivateKeyInfo(ecDsaKey.Private).GetDerEncoded(); var ecDsaPublicKey = (ECPublicKeyParameters)ecDsaKey.Public; publicKey = new byte[ecDsaDigestSize * 2]; ecDsaPublicKey.Q.X.ToBigInteger().ToByteArrayUnsigned().CopyTo(publicKey, 0); ecDsaPublicKey.Q.Y.ToBigInteger().ToByteArrayUnsigned().CopyTo(publicKey, ecDsaDigestSize); break; default: throw new NotSupportedException(); } return(new DnsKeyRecord(name, recordClass, timeToLive, flags, protocol, algorithm, publicKey, privateKey)); }
/// <summary> /// Creates a new instance of the UnknownRecord class /// </summary> /// <param name="name"> Domain name of the record </param> /// <param name="recordType"> Record type </param> /// <param name="recordClass"> Record class </param> /// <param name="timeToLive"> Seconds the record should be cached at most </param> /// <param name="recordData"> Binary data of the RDATA section of the record </param> public UnknownRecord(DomainName name, RecordType recordType, RecordClass recordClass, int timeToLive, byte[] recordData) : base(name, recordType, recordClass, timeToLive) { RecordData = recordData ?? new byte[] { }; }
/// <summary> /// Creates a new instance of the DnsQuestion class /// </summary> /// <param name="name"> Domain name </param> /// <param name="recordType"> Record type </param> /// <param name="recordClass"> Record class </param> public DnsQuestion(string name, RecordType recordType, RecordClass recordClass) { Name = name ?? String.Empty; RecordType = recordType; RecordClass = recordClass; }
/// <summary> /// Creates a new instance of the DnsKeyRecord class /// </summary> /// <param name="name"> Name of the record </param> /// <param name="recordClass"> Class of the record </param> /// <param name="timeToLive"> Seconds the record should be cached at most </param> /// <param name="flags"> Flags of the key </param> /// <param name="protocol"> Protocol field </param> /// <param name="algorithm"> Algorithm of the key </param> /// <param name="publicKey"> Binary data of the public key </param> public DnsKeyRecord(DomainName name, RecordClass recordClass, int timeToLive, DnsKeyFlags flags, byte protocol, DnsSecAlgorithm algorithm, byte[] publicKey) : this(name, recordClass, timeToLive, flags, protocol, algorithm, publicKey, null) { }
/// <summary> /// Queries a the upstream DNS server(s) for specified records as an asynchronous operation. /// </summary> /// <typeparam name="T"> Type of records, that should be returned </typeparam> /// <param name="name"> Domain, that should be queried </param> /// <param name="recordType"> Type the should be queried </param> /// <param name="recordClass"> Class the should be queried </param> /// <param name="token"> The token to monitor cancellation requests </param> /// <returns> A list of matching <see cref="DnsRecordBase">records</see> </returns> public async Task <List <T> > ResolveAsync <T>(DomainName name, RecordType recordType = RecordType.A, RecordClass recordClass = RecordClass.INet, CancellationToken token = default(CancellationToken)) where T : DnsRecordBase { if (name == null) { throw new ArgumentNullException(nameof(name), "Name must be provided"); } List <T> records; if (_cache.TryGetRecords(name, recordType, recordClass, out records)) { return(records); } DnsMessage msg = await _dnsClient.ResolveAsync(name, recordType, recordClass, null, token); if ((msg == null) || ((msg.ReturnCode != ReturnCode.NoError) && (msg.ReturnCode != ReturnCode.NxDomain))) { throw new Exception("DNS request failed"); } CNameRecord cName = msg.AnswerRecords.Where(x => (x.RecordType == RecordType.CName) && (x.RecordClass == recordClass) && x.Name.Equals(name)).OfType <CNameRecord>().FirstOrDefault(); if (cName != null) { records = msg.AnswerRecords.Where(x => (x.RecordType == recordType) && (x.RecordClass == recordClass) && x.Name.Equals(cName.CanonicalName)).OfType <T>().ToList(); if (records.Count > 0) { _cache.Add(name, recordType, recordClass, records, DnsSecValidationResult.Indeterminate, Math.Min(cName.TimeToLive, records.Min(x => x.TimeToLive))); return(records); } records = await ResolveAsync <T>(cName.CanonicalName, recordType, recordClass, token); if (records.Count > 0) { _cache.Add(name, recordType, recordClass, records, DnsSecValidationResult.Indeterminate, Math.Min(cName.TimeToLive, records.Min(x => x.TimeToLive))); } return(records); } records = msg.AnswerRecords.Where(x => x.Name.Equals(name)).OfType <T>().ToList(); if (records.Count > 0) { _cache.Add(name, recordType, recordClass, records, DnsSecValidationResult.Indeterminate, records.Min(x => x.TimeToLive)); } return(records); }
protected UpdateBase(string name, RecordType recordType, RecordClass recordClass, int timeToLive) : base(name, recordType, recordClass, timeToLive) { }
public void Add(DomainName name, RecordType recordType, RecordClass recordClass, DnsCacheRecordList <DnsRecordBase> records, int timeToLive) { CacheKey key = new CacheKey(name, recordType, recordClass); _cache.TryAdd(key, new CacheValue(records, timeToLive)); }