Exemple #1
0
 internal override void ParseRecordData(byte[] resultData, int startPosition, int length)
 {
     KeyTag     = DnsMessageBase.ParseUShort(resultData, ref startPosition);
     Algorithm  = (DnsSecAlgorithm)resultData[startPosition++];
     DigestType = (DnsSecDigestType)resultData[startPosition++];
     Digest     = DnsMessageBase.ParseByteData(resultData, ref startPosition, length - 4);
 }
Exemple #2
0
 internal override void ParseRecordData(byte[] resultData, int startPosition, int length)
 {
     Flags     = DnsMessageBase.ParseUShort(resultData, ref startPosition);
     Protocol  = resultData[startPosition++];
     Algorithm = (DnsSecAlgorithm)resultData[startPosition++];
     PublicKey = DnsMessageBase.ParseByteData(resultData, ref startPosition, length - 4);
 }
Exemple #3
0
 internal override void ParseRecordData(byte[] resultData, int startPosition, int length)
 {
     Type        = (CertType)DnsMessageBase.ParseUShort(resultData, ref startPosition);
     KeyTag      = DnsMessageBase.ParseUShort(resultData, ref startPosition);
     Algorithm   = (DnsSecAlgorithm)resultData[startPosition++];
     Certificate = DnsMessageBase.ParseByteData(resultData, ref startPosition, length - 5);
 }
Exemple #4
0
 internal override void ParseRecordData(byte[] resultData, int startPosition, int length)
 {
     Priority = DnsMessageBase.ParseUShort(resultData, ref startPosition);
     Weight   = DnsMessageBase.ParseUShort(resultData, ref startPosition);
     Port     = DnsMessageBase.ParseUShort(resultData, ref startPosition);
     Target   = DnsMessageBase.ParseDomainName(resultData, ref startPosition);
 }
Exemple #5
0
        internal override void ParseRecordData(byte[] resultData, int currentPosition, int length)
        {
            int endPosition = currentPosition + length;

            Prefixes = new List <AddressPrefix>();
            while (currentPosition < endPosition)
            {
                Family family = (Family)DnsMessageBase.ParseUShort(resultData, ref currentPosition);
                byte   prefix = resultData[currentPosition++];

                byte addressLength = resultData[currentPosition++];
                bool isNegated     = false;
                if (addressLength > 127)
                {
                    isNegated      = true;
                    addressLength -= 128;
                }

                byte[] addressData = new byte[(family == Family.IpV4) ? 4 : 16];
                Buffer.BlockCopy(resultData, currentPosition, addressData, 0, addressLength);
                currentPosition += addressLength;

                Prefixes.Add(new AddressPrefix(isNegated, new IPAddress(addressData), prefix));
            }
        }
Exemple #6
0
 internal override void ParseData(byte[] resultData, int startPosition, int length)
 {
     Version       = DnsMessageBase.ParseUShort(resultData, ref startPosition);
     OperationCode = (LlqOperationCode)DnsMessageBase.ParseUShort(resultData, ref startPosition);
     ErrorCode     = (LlqErrorCode)DnsMessageBase.ParseUShort(resultData, ref startPosition);
     Id            = DnsMessageBase.ParseULong(resultData, ref startPosition);
     LeaseTime     = TimeSpan.FromSeconds(DnsMessageBase.ParseUInt(resultData, ref startPosition));
 }
Exemple #7
0
 internal override void ParseRecordData(byte[] resultData, int startPosition, int length)
 {
     Order       = DnsMessageBase.ParseUShort(resultData, ref startPosition);
     Preference  = DnsMessageBase.ParseUShort(resultData, ref startPosition);
     Flags       = DnsMessageBase.ParseText(resultData, ref startPosition);
     Services    = DnsMessageBase.ParseText(resultData, ref startPosition);
     RegExp      = DnsMessageBase.ParseText(resultData, ref startPosition);
     Replacement = DnsMessageBase.ParseDomainName(resultData, ref startPosition);
 }
        internal override void ParseRecordData(byte[] resultData, int currentPosition, int length)
        {
            HashAlgorithm = (DnsSecAlgorithm)resultData[currentPosition++];
            Flags         = resultData[currentPosition++];
            Iterations    = DnsMessageBase.ParseUShort(resultData, ref currentPosition);
            int saltLength = resultData[currentPosition++];

            Salt = DnsMessageBase.ParseByteData(resultData, ref currentPosition, saltLength);
        }
Exemple #9
0
        internal override void ParseRecordData(byte[] resultData, int startPosition, int length)
        {
            int endPosition = startPosition + length;

            Options = new List <EDnsOptionBase>();
            while (startPosition < endPosition)
            {
                EDnsOptionType type       = (EDnsOptionType)DnsMessageBase.ParseUShort(resultData, ref startPosition);
                ushort         dataLength = DnsMessageBase.ParseUShort(resultData, ref startPosition);

                EDnsOptionBase option;

                switch (type)
                {
                case EDnsOptionType.LongLivedQuery:
                    option = new LongLivedQueryOption();
                    break;

                case EDnsOptionType.UpdateLease:
                    option = new UpdateLeaseOption();
                    break;

                case EDnsOptionType.NsId:
                    option = new NsIdOption();
                    break;

                case EDnsOptionType.Owner:
                    option = new OwnerOption();
                    break;

                case EDnsOptionType.DnssecAlgorithmUnderstood:
                    option = new DnssecAlgorithmUnderstoodOption();
                    break;

                case EDnsOptionType.DsHashUnderstood:
                    option = new DsHashUnderstoodOption();
                    break;

                case EDnsOptionType.Nsec3HashUnderstood:
                    option = new Nsec3HashUnderstoodOption();
                    break;

                case EDnsOptionType.ClientSubnet:
                    option = new ClientSubnetOption();
                    break;

                default:
                    option = new UnknownOption(type);
                    break;
                }

                option.ParseData(resultData, startPosition, dataLength);
                Options.Add(option);
                startPosition += dataLength;
            }
        }
Exemple #10
0
        private byte[] QueryByTcp(IPAddress nameServer, byte[] messageData, int messageLength, ref TcpClient tcpClient, ref NetworkStream tcpStream, out IPAddress responderAddress)
        {
            responderAddress = nameServer;

            IPEndPoint endPoint = new IPEndPoint(nameServer, _port);

            try
            {
                if (tcpClient == null)
                {
                    tcpClient = new TcpClient(nameServer.AddressFamily)
                    {
                        ReceiveTimeout = QueryTimeout,
                        SendTimeout    = QueryTimeout
                    };

                    tcpClient.Connect(endPoint);
                    tcpStream = tcpClient.GetStream();
                }

                int    tmp          = 0;
                byte[] lengthBuffer = new byte[2];

                if (messageLength > 0)
                {
                    DnsMessageBase.EncodeUShort(lengthBuffer, ref tmp, (ushort)messageLength);

                    tcpStream.Write(lengthBuffer, 0, 2);
                    tcpStream.Write(messageData, 0, messageLength);
                }

                lengthBuffer[0] = (byte)tcpStream.ReadByte();
                lengthBuffer[1] = (byte)tcpStream.ReadByte();

                tmp = 0;
                int length = DnsMessageBase.ParseUShort(lengthBuffer, ref tmp);

                byte[] resultData = new byte[length];

                int readBytes = 0;

                while (readBytes < length)
                {
                    readBytes += tcpStream.Read(resultData, readBytes, length - readBytes);
                }

                return(resultData);
            }
            catch (Exception e)
            {
                Trace.TraceError("Error on dns query: " + e);
                return(null);
            }
        }
Exemple #11
0
        private void TcpReceiveLengthCompleted <TMessage>(IAsyncResult ar)
            where TMessage : DnsMessageBase, new()
        {
            DnsClientAsyncState <TMessage> state = (DnsClientAsyncState <TMessage>)ar.AsyncState;

            if (state.Timer != null)
            {
                state.Timer.Dispose();
            }

            if (state.TimedOut)
            {
                state.EndpointInfoIndex++;
                TcpBeginConnect(state);
            }
            else
            {
                try
                {
                    state.TcpBytesToReceive -= state.TcpStream.EndRead(ar);

                    if (state.TcpBytesToReceive > 0)
                    {
                        IAsyncResult asyncResult = state.TcpStream.BeginRead(state.Buffer, 2 - state.TcpBytesToReceive, state.TcpBytesToReceive, TcpReceiveLengthCompleted <TMessage>, state);
                        state.Timer = new Timer(TcpTimedOut <TMessage>, asyncResult, state.TimeRemaining, Timeout.Infinite);
                    }
                    else
                    {
                        int tmp            = 0;
                        int responseLength = DnsMessageBase.ParseUShort(state.Buffer, ref tmp);

                        state.Buffer            = new byte[responseLength];
                        state.TcpBytesToReceive = responseLength;

                        IAsyncResult asyncResult = state.TcpStream.BeginRead(state.Buffer, 0, responseLength, TcpReceiveCompleted <TMessage>, state);
                        state.Timer = new Timer(TcpTimedOut <TMessage>, asyncResult, state.TimeRemaining, Timeout.Infinite);
                    }
                }
                catch (Exception e)
                {
                    Trace.TraceError("Error on dns query: " + e);

                    try
                    {
                        state.TcpClient.Close();
                        state.Timer.Dispose();
                    }
                    catch {}

                    state.EndpointInfoIndex++;
                    TcpBeginConnect(state);
                }
            }
        }
        protected override void ParsePublicKey(byte[] resultData, int startPosition, int length)
        {
            int primeLength = DnsMessageBase.ParseUShort(resultData, ref startPosition);

            Prime = DnsMessageBase.ParseByteData(resultData, ref startPosition, primeLength);
            int generatorLength = DnsMessageBase.ParseUShort(resultData, ref startPosition);

            Generator = DnsMessageBase.ParseByteData(resultData, ref startPosition, generatorLength);
            int publicValueLength = DnsMessageBase.ParseUShort(resultData, ref startPosition);

            PublicValue = DnsMessageBase.ParseByteData(resultData, ref startPosition, publicValueLength);
        }
Exemple #13
0
        internal override void ParseData(byte[] resultData, int startPosition, int length)
        {
            ushort family = DnsMessageBase.ParseUShort(resultData, ref startPosition);

            SourceNetmask = resultData[startPosition++];
            ScopeNetmask  = resultData[startPosition++];

            byte[] addressData = new byte[family == 1 ? 4 : 16];
            Buffer.BlockCopy(resultData, startPosition, addressData, 0, GetAddressLength());

            Address = new IPAddress(addressData);
        }
Exemple #14
0
        internal override void ParseRecordData(byte[] resultData, int startPosition, int length)
        {
            Algorithm  = TSigAlgorithmHelper.GetAlgorithmByName(DnsMessageBase.ParseDomainName(resultData, ref startPosition));
            Inception  = ParseDateTime(resultData, ref startPosition);
            Expiration = ParseDateTime(resultData, ref startPosition);
            Mode       = (TKeyMode)DnsMessageBase.ParseUShort(resultData, ref startPosition);
            Error      = (ReturnCode)DnsMessageBase.ParseUShort(resultData, ref startPosition);
            int keyLength = DnsMessageBase.ParseUShort(resultData, ref startPosition);

            Key = DnsMessageBase.ParseByteData(resultData, ref startPosition, keyLength);
            int otherDataLength = DnsMessageBase.ParseUShort(resultData, ref startPosition);

            OtherData = DnsMessageBase.ParseByteData(resultData, ref startPosition, otherDataLength);
        }
Exemple #15
0
        internal override void ParseRecordData(byte[] resultData, int startPosition, int length)
        {
            Algorithm  = TSigAlgorithmHelper.GetAlgorithmByName(DnsMessageBase.ParseDomainName(resultData, ref startPosition));
            TimeSigned = ParseDateTime(resultData, ref startPosition);
            Fudge      = TimeSpan.FromSeconds(DnsMessageBase.ParseUShort(resultData, ref startPosition));
            int macSize = DnsMessageBase.ParseUShort(resultData, ref startPosition);

            Mac        = DnsMessageBase.ParseByteData(resultData, ref startPosition, macSize);
            OriginalID = DnsMessageBase.ParseUShort(resultData, ref startPosition);
            Error      = (ReturnCode)DnsMessageBase.ParseUShort(resultData, ref startPosition);
            int otherDataSize = DnsMessageBase.ParseUShort(resultData, ref startPosition);

            OtherData = DnsMessageBase.ParseByteData(resultData, ref startPosition, otherDataSize);
        }
Exemple #16
0
        internal override void ParseRecordData(byte[] resultData, int startPosition, int length)
        {
            int currentPosition = startPosition;

            TypeCovered         = (RecordType)DnsMessageBase.ParseUShort(resultData, ref currentPosition);
            Algorithm           = (DnsSecAlgorithm)resultData[currentPosition++];
            Labels              = resultData[currentPosition++];
            OriginalTimeToLive  = DnsMessageBase.ParseInt(resultData, ref currentPosition);
            SignatureExpiration = ParseDateTime(resultData, ref currentPosition);
            SignatureInception  = ParseDateTime(resultData, ref currentPosition);
            KeyTag              = DnsMessageBase.ParseUShort(resultData, ref currentPosition);
            SignersName         = DnsMessageBase.ParseDomainName(resultData, ref currentPosition);
            Signature           = DnsMessageBase.ParseByteData(resultData, ref currentPosition, length + startPosition - currentPosition);
        }
Exemple #17
0
        private void EndTcpReadLength(IAsyncResult ar)
        {
            TcpClient     client = null;
            NetworkStream stream = null;

            try
            {
                MyState state = (MyState)ar.AsyncState;
                client = state.Client;
                stream = state.Stream;

                state.Timer.Dispose();

                state.BytesToReceive -= stream.EndRead(ar);

                if (state.BytesToReceive > 0)
                {
                    if (!IsTcpClientConnected(client))
                    {
                        HandleTcpException(null, stream, client);
                        return;
                    }

                    state.Timer       = new Timer(TcpTimedOut, state, state.TimeRemaining, System.Threading.Timeout.Infinite);
                    state.AsyncResult = stream.BeginRead(state.Buffer, state.Buffer.Length - state.BytesToReceive, state.BytesToReceive, EndTcpReadLength, state);
                }
                else
                {
                    int tmp    = 0;
                    int length = DnsMessageBase.ParseUShort(state.Buffer, ref tmp);

                    if (length > 0)
                    {
                        state.Buffer = new byte[length];

                        state.Timer       = new Timer(TcpTimedOut, state, state.TimeRemaining, System.Threading.Timeout.Infinite);
                        state.AsyncResult = stream.BeginRead(state.Buffer, 0, length, EndTcpReadData, state);
                    }
                    else
                    {
                        HandleTcpException(null, stream, client);
                    }
                }
            }
            catch (Exception e)
            {
                HandleTcpException(e, stream, client);
            }
        }
Exemple #18
0
        internal override void ParseRecordData(byte[] resultData, int currentPosition, int length)
        {
            int endPosition = currentPosition + length;

            HashAlgorithm = (DnsSecAlgorithm)resultData[currentPosition++];
            Flags         = resultData[currentPosition++];
            Iterations    = DnsMessageBase.ParseUShort(resultData, ref currentPosition);
            int saltLength = resultData[currentPosition++];

            Salt = DnsMessageBase.ParseByteData(resultData, ref currentPosition, saltLength);
            int hashLength = resultData[currentPosition++];

            NextHashedOwnerName = DnsMessageBase.ParseByteData(resultData, ref currentPosition, hashLength);
            Types = NSecRecord.ParseTypeBitMap(resultData, ref currentPosition, endPosition);
        }
Exemple #19
0
        internal override void ParseRecordData(byte[] resultData, int currentPosition, int length)
        {
            int endPosition = currentPosition + length;

            int hitLength = resultData[currentPosition++];

            Algorithm = (IpSecKeyRecord.IpSecAlgorithm)resultData[currentPosition++];
            int publicKeyLength = DnsMessageBase.ParseUShort(resultData, ref currentPosition);

            Hit               = DnsMessageBase.ParseByteData(resultData, ref currentPosition, hitLength);
            PublicKey         = DnsMessageBase.ParseByteData(resultData, ref currentPosition, publicKeyLength);
            RendezvousServers = new List <string>();
            while (currentPosition < endPosition)
            {
                RendezvousServers.Add(DnsMessageBase.ParseDomainName(resultData, ref currentPosition));
            }
        }
Exemple #20
0
 internal override void ParseRecordData(byte[] resultData, int startPosition, int length)
 {
     SubType  = (AfsSubType)DnsMessageBase.ParseUShort(resultData, ref startPosition);
     Hostname = DnsMessageBase.ParseDomainName(resultData, ref startPosition);
 }
Exemple #21
0
 internal override void ParseRecordData(byte[] resultData, int startPosition, int length)
 {
     Preference         = DnsMessageBase.ParseUShort(resultData, ref startPosition);
     ExchangeDomainName = DnsMessageBase.ParseDomainName(resultData, ref startPosition);
 }
Exemple #22
0
 internal override void ParseRecordData(byte[] resultData, int startPosition, int length)
 {
     Preference = DnsMessageBase.ParseUShort(resultData, ref startPosition);
     Locator64  = DnsMessageBase.ParseULong(resultData, ref startPosition);
 }