示例#1
0
        /// <summary>
        /// Submits an ACME protocol request via an HTTP POST with the necessary semantics
        /// and protocol details.  The result is a simplified and canonicalized response
        /// object capturing the error state, HTTP response headers and content of the
        /// response body.
        /// </summary>
        /// <param name="uri"></param>
        /// <param name="message"></param>
        /// <returns></returns>
        private AcmeHttpResponse RequestHttpPost(Uri uri, object message)
        {
            var acmeSigned = ComputeAcmeSigned(message, Signer);
            var acmeBytes  = Encoding.ASCII.GetBytes(acmeSigned);

            var requ = (HttpWebRequest)WebRequest.Create(uri);

            if (Proxy != null)
            {
                requ.Proxy = Proxy;
            }
            requ.Method        = AcmeProtocol.HTTP_METHOD_POST;
            requ.ContentType   = AcmeProtocol.HTTP_CONTENT_TYPE_JSON;
            requ.ContentLength = acmeBytes.Length;
            requ.UserAgent     = this.UserAgent;
            try
            {
                if (BeforeGetResponseAction != null)
                {
                    BeforeGetResponseAction(requ);
                }

                using (var s = requ.GetRequestStream())
                {
                    s.Write(acmeBytes, 0, acmeBytes.Length);
                }

                using (var resp = (HttpWebResponse)requ.GetResponse())
                {
                    ExtractNonce(resp);
                    var acmeResp = new AcmeHttpResponse(resp);
                    LastResponse = acmeResp;
                    return(acmeResp);
                }
            }
            catch (WebException ex) when(ex.Response != null)
            {
                using (var resp = (HttpWebResponse)ex.Response)
                {
                    var acmeResp = new AcmeHttpResponse(resp)
                    {
                        IsError = true,
                        Error   = ex,
                    };
                    LastResponse = acmeResp;

                    if (ProblemDetailResponse.CONTENT_TYPE == resp.ContentType &&
                        !string.IsNullOrEmpty(acmeResp.ContentAsString))
                    {
                        acmeResp.ProblemDetail = JsonConvert.DeserializeObject <ProblemDetailResponse>(
                            acmeResp.ContentAsString);
                        acmeResp.ProblemDetail.OrignalContent = acmeResp.ContentAsString;
                    }

                    return(acmeResp);
                }
            }
        }
示例#2
0
 public AcmeWebException(WebException innerException, string message = null,
                         AcmeHttpResponse response = null) : base(message, innerException)
 {
     Response = response;
     if (Response?.ProblemDetail?.OrignalContent != null)
     {
         this.With(nameof(Response.ProblemDetail),
                   Response.ProblemDetail.OrignalContent);
     }
 }
示例#3
0
        private AcmeHttpResponse RequestHttpGet(Uri uri)
        {
            var requ = (HttpWebRequest)WebRequest.Create(uri);

            if (Proxy != null)
            {
                requ.Proxy = Proxy;
            }
            requ.Method    = AcmeProtocol.HTTP_METHOD_GET;
            requ.UserAgent = UserAgent;
            if (Language != null)
            {
                requ.Headers.Add(HttpRequestHeader.AcceptLanguage, Language);
            }

            try
            {
                if (BeforeGetResponseAction != null)
                {
                    BeforeGetResponseAction(requ);
                }

                using (var resp = (HttpWebResponse)requ.GetResponse())
                {
                    ExtractNonce(resp);
                    var acmeResp = new AcmeHttpResponse(resp);
                    LastResponse = acmeResp;
                    return(acmeResp);
                }
            }
            catch (WebException ex) when(ex.Response != null)
            {
                using (var resp = (HttpWebResponse)ex.Response)
                {
                    var acmeResp = new AcmeHttpResponse(resp)
                    {
                        IsError = true,
                        Error   = ex,
                    };
                    LastResponse = acmeResp;

                    if (ProblemDetailResponse.CONTENT_TYPE == resp.ContentType &&
                        !string.IsNullOrEmpty(acmeResp.ContentAsString))
                    {
                        acmeResp.ProblemDetail = JsonConvert.DeserializeObject <ProblemDetailResponse>(
                            acmeResp.ContentAsString);
                    }

                    return(acmeResp);
                }
            }
        }
示例#4
0
        /// <summary>
        /// Submits an ACME protocol request via an HTTP POST with the necessary semantics
        /// and protocol details.  The result is a simplified and canonicalized response
        /// object capturing the error state, HTTP response headers and content of the
        /// response body.
        /// </summary>
        /// <param name="uri"></param>
        /// <param name="message"></param>
        /// <returns></returns>
        private AcmeHttpResponse RequestHttpPost(Uri uri, object message)
        {
            var acmeSigned = ComputeAcmeSigned(message, Signer);
            var acmeBytes  = Encoding.ASCII.GetBytes(acmeSigned);

            var requ = (HttpWebRequest)WebRequest.Create(uri);

            if (Proxy != null)
            {
                requ.Proxy = Proxy;
            }
            requ.Method        = "POST";
            requ.ContentType   = "application/json";
            requ.ContentLength = acmeBytes.Length;
            requ.UserAgent     = this.UserAgent;
            using (var s = requ.GetRequestStream())
            {
                s.Write(acmeBytes, 0, acmeBytes.Length);
            }

            try
            {
                using (var resp = (HttpWebResponse)requ.GetResponse())
                {
                    ExtractNonce(resp);
                    return(new AcmeHttpResponse(resp));
                }
            }
            catch (WebException ex) when(ex.Response != null)
            {
                using (var resp = (HttpWebResponse)ex.Response)
                {
                    var acmeResp = new AcmeHttpResponse(resp)
                    {
                        IsError = true,
                        Error   = ex,
                    };

                    if (ProblemDetailResponse.CONTENT_TYPE == resp.ContentType &&
                        !string.IsNullOrEmpty(acmeResp.ContentAsString))
                    {
                        acmeResp.ProblemDetail = JsonConvert.DeserializeObject <ProblemDetailResponse>(
                            acmeResp.ContentAsString);
                    }

                    return(acmeResp);
                }
            }
        }
示例#5
0
        private AcmeHttpResponse RequestHttpGet(Uri uri)
        {
            var requ = (HttpWebRequest)WebRequest.Create(uri);

            if (Proxy != null)
            {
                requ.Proxy = Proxy;
            }
            requ.Method    = "GET";
            requ.UserAgent = this.UserAgent;

            try
            {
                using (var resp = (HttpWebResponse)requ.GetResponse())
                {
                    ExtractNonce(resp);
                    return(new AcmeHttpResponse(resp));
                }
            }
            catch (WebException ex) when(ex.Response != null)
            {
                using (var resp = (HttpWebResponse)ex.Response)
                {
                    var acmeResp = new AcmeHttpResponse(resp)
                    {
                        IsError = true,
                        Error   = ex,
                    };

                    if (ProblemDetailResponse.CONTENT_TYPE == resp.ContentType &&
                        !string.IsNullOrEmpty(acmeResp.ContentAsString))
                    {
                        acmeResp.ProblemDetail = JsonConvert.DeserializeObject <ProblemDetailResponse>(
                            acmeResp.ContentAsString);
                    }

                    return(acmeResp);
                }
            }
        }
示例#6
0
 public AcmeProtocolException(string message, AcmeHttpResponse response = null,
                              Exception innerException = null) : base(message, innerException)
 {
     Response = response;
 }
示例#7
0
 public AcmeWebException(WebException innerException, string message = null,
         AcmeHttpResponse response = null)
     : base(message, innerException)
 {
     Response = response;
 }
示例#8
0
 public AcmeProtocolException(string message, AcmeHttpResponse response = null,
         Exception innerException = null)
     : base(message, innerException)
 {
     Response = response;
 }
示例#9
0
        /// <summary>
        /// Submits an ACME protocol request via an HTTP POST with the necessary semantics
        /// and protocol details.  The result is a simplified and canonicalized response
        /// object capturing the error state, HTTP response headers and content of the
        /// response body.
        /// </summary>
        /// <param name="uri"></param>
        /// <param name="message"></param>
        /// <returns></returns>
        private AcmeHttpResponse RequestHttpPost(Uri uri, object message)
        {
            var acmeSigned = ComputeAcmeSigned(message, Signer);
            var acmeBytes = Encoding.ASCII.GetBytes(acmeSigned);

            var requ = (HttpWebRequest)WebRequest.Create(uri);
            if (Proxy != null)
                requ.Proxy = Proxy;
            requ.Method = AcmeProtocol.HTTP_METHOD_POST;
            requ.ContentType = AcmeProtocol.HTTP_CONTENT_TYPE_JSON;
            requ.ContentLength = acmeBytes.Length;
            requ.UserAgent = this.UserAgent;
            try
            {
                if (BeforeGetResponseAction != null)
                    BeforeGetResponseAction(requ);

                using (var s = requ.GetRequestStream())
                {
                    s.Write(acmeBytes, 0, acmeBytes.Length);
                }

                using (var resp = (HttpWebResponse)requ.GetResponse())
                {
                    ExtractNonce(resp);
                    return new AcmeHttpResponse(resp);
                }
            }
            catch (WebException ex) when (ex.Response != null)
            {
                using (var resp = (HttpWebResponse)ex.Response)
                {
                    var acmeResp = new AcmeHttpResponse(resp)
                    {
                        IsError = true,
                        Error = ex,
                    };

                    if (ProblemDetailResponse.CONTENT_TYPE == resp.ContentType
                            && !string.IsNullOrEmpty(acmeResp.ContentAsString))
                    {
                        acmeResp.ProblemDetail = JsonConvert.DeserializeObject<ProblemDetailResponse>(
                                acmeResp.ContentAsString);
                    }

                    return acmeResp;
                }
            }
        }
示例#10
0
        private AcmeHttpResponse RequestHttpGet(Uri uri)
        {
            var requ = (HttpWebRequest)WebRequest.Create(uri);
            if (Proxy != null)
                requ.Proxy = Proxy;
            requ.Method = AcmeProtocol.HTTP_METHOD_GET;
            requ.UserAgent = this.UserAgent;

            try
            {
                if (BeforeGetResponseAction != null)
                    BeforeGetResponseAction(requ);

                using (var resp = (HttpWebResponse)requ.GetResponse())
                {
                    ExtractNonce(resp);
                    return new AcmeHttpResponse(resp);
                }
            }
            catch (WebException ex) when (ex.Response != null)
            {
                using (var resp = (HttpWebResponse)ex.Response)
                {
                    var acmeResp = new AcmeHttpResponse(resp)
                    {
                        IsError = true,
                        Error = ex,
                    };

                    if (ProblemDetailResponse.CONTENT_TYPE == resp.ContentType
                            && !string.IsNullOrEmpty(acmeResp.ContentAsString))
                    {
                        acmeResp.ProblemDetail = JsonConvert.DeserializeObject<ProblemDetailResponse>(
                                acmeResp.ContentAsString);
                    }

                    return acmeResp;
                }
            }
        }
示例#11
0
 public AcmeWebException(WebException innerException, string message = null,
                         AcmeHttpResponse response = null) : base(message, innerException)
 {
     Response = response;
 }
示例#12
0
 public AcmeWebException(WebException innerException, string message = null,
         AcmeHttpResponse response = null)
     : base(message, innerException)
 {
     Response = response;
     if (Response?.ProblemDetail?.OrignalContent != null)
         this.With(nameof(Response.ProblemDetail),
                 Response.ProblemDetail.OrignalContent);
 }