public NtlmChallengeMessage(ChallengeMessageStruct message, string targetName,
                                    params NtlmTargetInfo[] targetInfos)
        {
            Message    = message;
            TargetName = targetName;

            if (targetInfos != null)
            {
                TargetInfoList = new NtlmTargetInfoList(targetInfos);
            }

            Rectify();
        }
        private static void SendChallengeMessage(HttpContext context, NtlmNegotiateMessage negotiateMessage,
                                                 Action <string> log)
        {
            if (negotiateMessage == null)
            {
                throw new ArgumentNullException(nameof(negotiateMessage));
            }

            if (log != null)
            {
                log($"Message 1 Flags: {negotiateMessage.Flags}");
                log($"Message 1 Domain: {negotiateMessage.Domain}");
                log($"Message 1 Host: {negotiateMessage.Host}");
            }

            var messageStruct = new ChallengeMessageStruct
            {
                Signature = Constants.NtlmsspBytes,
                Type      = MessageType.Challenge,
                Flags     = SupportedMessageFlag & negotiateMessage.Flags,
                Challenge = Challenge,
                Context   = ZeroBytes
            };

            var message2 = new NtlmChallengeMessage(messageStruct, "DOMAIN");

            message2.TargetInfoList.Add(new NtlmTargetInfo(TargetInfoType.DomainName, "DOMAIN", Encoding.Unicode));
            message2.TargetInfoList.Add(new NtlmTargetInfo(TargetInfoType.ServerName, "SERVER", Encoding.Unicode));
            message2.TargetInfoList.Add(new NtlmTargetInfo(TargetInfoType.DnsDomainName, "domain.com", Encoding.Unicode));
            message2.TargetInfoList.Add(new NtlmTargetInfo(TargetInfoType.FQDN, "server.domain.com", Encoding.Unicode));
            message2.TargetInfoList.Add(new NtlmTargetInfo(TargetInfoType.Terminator));
            message2.Rectify();

            if (log != null)
            {
                log($"Message 2 Flags: {message2.Flags}");
                log($"Message 2 TargetName: {message2.TargetName}");
            }

            SendUnauthorized(context, message2.ToBytes());
        }
        public virtual void Fill(byte[] data)
        {
            if (data == null)
            {
                throw new ArgumentNullException(nameof(data));
            }
            if (data.Length == 0)
            {
                throw new ArgumentException($"{nameof(data)} array is empty.");
            }

            Message = data.ToStruct <ChallengeMessageStruct>();

            if (Message.TargetNameLength > 0)
            {
                var targetNameBytes = data.NewCopy(Message.TargetNameOffset, Message.TargetNameLength);
                TargetName = GetEncoding().GetString(targetNameBytes);
            }
            if (Message.TargetNameLength > 0)
            {
                var targetInfosBytes = data.NewCopy(Message.TargetInfosOffset, Message.TargetInfosLength);
                TargetInfoList = NtlmTargetInfoList.Parse(targetInfosBytes, GetEncoding());
            }
        }