/// <summary>
 /// Get the proxy message replied from the server.
 /// NULL will be returned if not response is received.
 /// </summary>
 /// <returns>The responded proxy message</returns>
 public KDCProxyMessage GetProxyResponse()
 {
     if (responseBytes == null)
     {
         return null;
     }
     KDCProxyMessage message = new KDCProxyMessage();
     message.FromBytes(responseBytes);
     return message;
 }
 /// <summary>
 /// Wrap the KerberosPdu provided into proxy message.
 /// </summary>
 /// <param name="pdu">the specified KerberosPdu to be wrapped</param>
 public KDCProxyMessage MakeProxyMessage(KerberosPdu pdu)
 {
     //prepare proxy message
     KDCProxyMessage message = new KDCProxyMessage(pdu);
     if (!string.IsNullOrEmpty(TargetDomain))
     {
         message.TargetDomain = TargetDomain;
     }
     if (DCLocatorHint.HasValue)
     {
         message.DCLocatorHint = DCLocatorHint.Value;
     }
     return message;
 }
        /// <summary>
        /// Send the specified proxy message using https.
        /// </summary>
        /// <param name="message"></param>
        public void SendProxyRequest(KDCProxyMessage message)
        {
            //create web request
            HttpWebRequest webRequest = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(new Uri(config.KKDCPServerURL));
            webRequest.KeepAlive = config.HttpKeepAlive;
            webRequest.Method = "POST";
            webRequest.ProtocolVersion = config.HttpVersion;
            webRequest.CachePolicy = config.HttpCachePolicy;
            webRequest.UserAgent = config.HttpUserAgent;
            webRequest.Timeout = config.HttpRequestTimeout;

            if (config.TlsClientCertificate != null)
            {
                webRequest.ClientCertificates.Add(config.TlsClientCertificate);
            }
            //send message
            byte[] data = message.ToBytes();
            webRequest.ContentLength = data.Length;
            Stream postData = webRequest.GetRequestStream();
            postData.Write(data, 0, data.Length);
            postData.Close();

            //get response
            try
            {
                HttpWebResponse response = (System.Net.HttpWebResponse)webRequest.GetResponse();
                if (response.StatusCode == HttpStatusCode.Forbidden)
                {
                    //HTTP 403 error received, set ERROR to STATUS_AUTHENTICATION_FIREWALL_FAILED.
                    Error = KKDCPError.STATUS_AUTHENTICATION_FIREWALL_FAILED;
                    return;
                }
                using (Stream responseDataSteam = response.GetResponseStream())
                {
                    using (MemoryStream ms = new MemoryStream())
                    {
                        responseDataSteam.CopyTo(ms);
                        responseBytes = ms.ToArray();
                    }
                }
                response.Close();
            }
            catch (WebException)
            {
                //server dropped the TCP connection
                //set Error to STATUS_NO_LOGON_SERVERS
                Error = KKDCPError.STATUS_NO_LOGON_SERVERS;
            }
        }