Beispiel #1
0
        /// <summary>
        /// Posts the data to the specified URI.
        /// </summary>
        /// <typeparam name="T">The type of expected result</typeparam>
        /// <param name="client">The client.</param>
        /// <param name="context">The context.</param>
        /// <param name="location">The URI.</param>
        /// <param name="entity">The payload.</param>
        /// <param name="ensureSuccessStatusCode">if set to <c>true</c>, throw exception if the request failed.</param>
        /// <returns>
        /// The response from ACME server.
        /// </returns>
        /// <exception cref="Exception">
        /// If the HTTP request failed and <paramref name="ensureSuccessStatusCode"/> is <c>true</c>.
        /// </exception>
        internal static async Task <AcmeHttpResponse <T> > Post <T>(this IAcmeHttpClient client,
                                                                    IAcmeContext context,
                                                                    Uri location,
                                                                    object entity,
                                                                    bool ensureSuccessStatusCode)
        {
            var payload = await context.Sign(entity, location);

            var response = await client.Post <T>(location, payload);

            var retryCount = context.BadNonceRetryCount;

            while (response.Error?.Status == System.Net.HttpStatusCode.BadRequest &&
                   response.Error.Type?.CompareTo("urn:ietf:params:acme:error:badNonce") == 0 &&
                   retryCount-- > 0)
            {
                payload = await context.Sign(entity, location);

                response = await client.Post <T>(location, payload);
            }

            if (ensureSuccessStatusCode && response.Error != null)
            {
                throw new AcmeRequestException(
                          string.Format(Strings.ErrorFetchResource, location),
                          response.Error);
            }

            return(response);
        }
Beispiel #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AcmeContext" /> class.
 /// </summary>
 /// <param name="directoryUri">The directory URI.</param>
 /// <param name="accountKey">The account key.</param>
 /// <param name="http">The HTTP client.</param>
 /// <param name="badNonceRetryCount">The number of retries on a bad nonce.</param>
 /// <exception cref="ArgumentNullException">
 /// If <paramref name="directoryUri"/> is <c>null</c>.
 /// </exception>
 public AcmeContext(Uri directoryUri, IKey accountKey = null, IAcmeHttpClient http = null, int badNonceRetryCount = 1)
 {
     DirectoryUri       = directoryUri ?? throw new ArgumentNullException(nameof(directoryUri));
     AccountKey         = accountKey ?? KeyFactory.NewKey(defaultKeyType);
     HttpClient         = http ?? new AcmeHttpClient(directoryUri);
     BadNonceRetryCount = badNonceRetryCount;
 }
        /// <summary>
        /// Posts the data to the specified URI.
        /// </summary>
        /// <typeparam name="T">The type of expected result</typeparam>
        /// <param name="client">The client.</param>
        /// <param name="uri">The URI.</param>
        /// <param name="payload">The payload.</param>
        /// <param name="ensureSuccessStatusCode">if set to <c>true</c>, throw exception if the request failed.</param>
        /// <returns>
        /// The response from ACME server.
        /// </returns>
        /// <exception cref="Exception">
        /// If the HTTP request failed and <paramref name="ensureSuccessStatusCode"/> is <c>true</c>.
        /// </exception>
        internal static async Task<AcmeHttpResponse<T>> Post<T>(this IAcmeHttpClient client, Uri uri, object payload, bool ensureSuccessStatusCode)
        {
            var resp = await client.Post<T>(uri, payload);
            if (ensureSuccessStatusCode && resp.Error != null)
            {
                throw new Exception(resp.Error.Detail);
            }

            return resp;
        }
Beispiel #4
0
        /// <summary>
        /// Posts the data to the specified URI.
        /// </summary>
        /// <typeparam name="T">The type of expected result</typeparam>
        /// <param name="client">The client.</param>
        /// <param name="uri">The URI.</param>
        /// <param name="payload">The payload.</param>
        /// <param name="ensureSuccessStatusCode">if set to <c>true</c>, throw exception if the request failed.</param>
        /// <returns>
        /// The response from ACME server.
        /// </returns>
        /// <exception cref="Exception">
        /// If the HTTP request failed and <paramref name="ensureSuccessStatusCode"/> is <c>true</c>.
        /// </exception>
        internal static async Task <AcmeHttpResponse <T> > Post <T>(this IAcmeHttpClient client, Uri uri, object payload, bool ensureSuccessStatusCode)
        {
            var resp = await client.Post <T>(uri, payload);

            if (ensureSuccessStatusCode && resp.Error != null)
            {
                throw new AcmeRequestException(
                          string.Format(Strings.ErrorFetchResource, uri),
                          resp.Error);
            }

            return(resp);
        }
Beispiel #5
0
 public LetsEncryptRepository(IOptions <Settings> options, IAcmeHttpClient acmeHttpClient, IAzureAuthenticationService azureAuthenticationService)
 {
     settings                        = options.Value;
     this.acmeHttpClient             = acmeHttpClient;
     this.azureAuthenticationService = azureAuthenticationService;
 }