/// <summary> /// Constructs an instance out of the algorithm, inception, expiration, mode, error, key and other fields. /// </summary> /// <param name="algorithm"> /// Name of the algorithm in domain name syntax. /// The algorithm determines how the secret keying material agreed to using the TKEY RR is actually used to derive the algorithm specific key. /// </param> /// <param name="inception"> /// Number of seconds since the beginning of 1 January 1970 GMT ignoring leap seconds treated as modulo 2**32 using ring arithmetic. /// In messages between a DNS resolver and a DNS server where this field is meaningful, /// it is either the requested validity interval start for the keying material asked for or /// specify the validity interval start of keying material provided. /// /// To avoid different interpretations of the inception time in TKEY RRs, /// resolvers and servers exchanging them must have the same idea of what time it is. /// One way of doing this is with the NTP protocol [RFC 2030] but that or any other time synchronization used for this purpose must be done securely. /// </param> /// <param name="expiration"> /// Number of seconds since the beginning of 1 January 1970 GMT ignoring leap seconds treated as modulo 2**32 using ring arithmetic. /// In messages between a DNS resolver and a DNS server where this field is meaningful, /// it is either the requested validity interval end for the keying material asked for or /// specify the validity interval end of keying material provided. /// /// To avoid different interpretations of the expiration time in TKEY RRs, /// resolvers and servers exchanging them must have the same idea of what time it is. /// One way of doing this is with the NTP protocol [RFC 2030] but that or any other time synchronization used for this purpose must be done securely. /// </param> /// <param name="mode"> /// Specifies the general scheme for key agreement or the purpose of the TKEY DNS message. /// Servers and resolvers supporting this specification must implement the Diffie-Hellman key agreement mode and the key deletion mode for queries. /// All other modes are optional. /// A server supporting TKEY that receives a TKEY request with a mode it does not support returns the BADMODE error. /// </param> /// <param name="error"> /// When the TKEY Error Field is non-zero in a response to a TKEY query, the DNS header RCODE field indicates no error. /// However, it is possible if a TKEY is spontaneously included in a response the TKEY RR and DNS header error field /// could have unrelated non-zero error codes. /// </param> /// <param name="key">The key exchange data. The meaning of this data depends on the mode.</param> /// <param name="other">May be used in future extensions.</param> public DnsResourceDataTransactionKey(DnsDomainName algorithm, SerialNumber32 inception, SerialNumber32 expiration, DnsTransactionKeyMode mode, DnsResponseCode error, DataSegment key, DataSegment other) { if (key == null) { throw new ArgumentNullException("key"); } if (other == null) { throw new ArgumentNullException("other"); } if (key.Length > ushort.MaxValue) { throw new ArgumentOutOfRangeException("key", key.Length, string.Format(CultureInfo.InvariantCulture, "Cannot be longer than {0}", ushort.MaxValue)); } if (other.Length > ushort.MaxValue) { throw new ArgumentOutOfRangeException("other", other.Length, string.Format(CultureInfo.InvariantCulture, "Cannot be longer than {0}", ushort.MaxValue)); } Algorithm = algorithm; Inception = inception; Expiration = expiration; Mode = mode; Error = error; Key = key; Other = other; }
internal override DnsResourceData CreateInstance(DnsDatagram dns, int offsetInDns, int length) { if (length < ConstantPartLength + DnsDomainName.RootLength) { return(null); } DnsDomainName algorithm; int algorithmLength; if (!DnsDomainName.TryParse(dns, offsetInDns, length - ConstantPartLength, out algorithm, out algorithmLength)) { return(null); } offsetInDns += algorithmLength; length -= algorithmLength; if (length < ConstantPartLength) { return(null); } uint inception = dns.ReadUInt(offsetInDns + OffsetAfterAlgorithm.Inception, Endianity.Big); uint expiration = dns.ReadUInt(offsetInDns + OffsetAfterAlgorithm.Expiration, Endianity.Big); DnsTransactionKeyMode mode = (DnsTransactionKeyMode)dns.ReadUShort(offsetInDns + OffsetAfterAlgorithm.Mode, Endianity.Big); DnsResponseCode error = (DnsResponseCode)dns.ReadUShort(offsetInDns + OffsetAfterAlgorithm.Error, Endianity.Big); int keySize = dns.ReadUShort(offsetInDns + OffsetAfterAlgorithm.KeySize, Endianity.Big); if (length < ConstantPartLength + keySize) { return(null); } DataSegment key = dns.Subsegment(offsetInDns + OffsetAfterAlgorithm.KeyData, keySize); int totalReadAfterAlgorithm = OffsetAfterAlgorithm.KeyData + keySize; offsetInDns += totalReadAfterAlgorithm; length -= totalReadAfterAlgorithm; int otherSize = dns.ReadUShort(offsetInDns, Endianity.Big); if (length != sizeof(ushort) + otherSize) { return(null); } DataSegment other = dns.Subsegment(offsetInDns + sizeof(ushort), otherSize); return(new DnsResourceDataTransactionKey(algorithm, inception, expiration, mode, error, key, other)); }
internal override DnsResourceData CreateInstance(DnsDatagram dns, int offsetInDns, int length) { if (length < 17) { return((DnsResourceData)null); } DnsDomainName domainName; int numBytesRead; if (!DnsDomainName.TryParse(dns, offsetInDns, length - 16, out domainName, out numBytesRead)) { return((DnsResourceData)null); } offsetInDns += numBytesRead; length -= numBytesRead; if (length < 16) { return((DnsResourceData)null); } uint num1 = dns.ReadUInt(offsetInDns, Endianity.Big); uint num2 = dns.ReadUInt(offsetInDns + 4, Endianity.Big); DnsTransactionKeyMode mode = (DnsTransactionKeyMode)dns.ReadUShort(offsetInDns + 8, Endianity.Big); DnsResponseCode error = (DnsResponseCode)dns.ReadUShort(offsetInDns + 10, Endianity.Big); int length1 = (int)dns.ReadUShort(offsetInDns + 12, Endianity.Big); if (length < 16 + length1) { return((DnsResourceData)null); } DataSegment key = dns.Subsegment(offsetInDns + 14, length1); int num3 = 14 + length1; offsetInDns += num3; length -= num3; int length2 = (int)dns.ReadUShort(offsetInDns, Endianity.Big); if (length != 2 + length2) { return((DnsResourceData)null); } DataSegment other = dns.Subsegment(offsetInDns + 2, length2); return((DnsResourceData) new DnsResourceDataTransactionKey(domainName, (SerialNumber32)num1, (SerialNumber32)num2, mode, error, key, other)); }
public DnsResourceDataTransactionKey(DnsDomainName algorithm, SerialNumber32 inception, SerialNumber32 expiration, DnsTransactionKeyMode mode, DnsResponseCode error, DataSegment key, DataSegment other) { if (key == null) { throw new ArgumentNullException("key"); } if (other == null) { throw new ArgumentNullException("other"); } if (key.Length > (int)ushort.MaxValue) { throw new ArgumentOutOfRangeException("key", (object)key.Length, string.Format((IFormatProvider)CultureInfo.InvariantCulture, "Cannot be longer than {0}", new object[1] { (object)ushort.MaxValue })); } if (other.Length > (int)ushort.MaxValue) { throw new ArgumentOutOfRangeException("other", (object)other.Length, string.Format((IFormatProvider)CultureInfo.InvariantCulture, "Cannot be longer than {0}", new object[1] { (object)ushort.MaxValue })); } this.Algorithm = algorithm; this.Inception = inception; this.Expiration = expiration; this.Mode = mode; this.Error = error; this.Key = key; this.Other = other; }