protected override async Task <(List <string>?Contents, AcmeError?Error)> LoadChallengeResponseAsync(Challenge challenge, CancellationToken cancellationToken) { var challengeUrl = $"http://{challenge.Authorization.Identifier.Value}/.well-known/acme-challenge/{challenge.Token}"; try { var response = await _httpClient.GetAsync(new Uri(challengeUrl), cancellationToken); if (response.StatusCode != System.Net.HttpStatusCode.OK) { var error = new AcmeError("incorrectResponse", $"Got non 200 status code: {response.StatusCode}", challenge.Authorization.Identifier); return(null, error); } var content = await response.Content.ReadAsStringAsync(); return(new List <string> { content }, null); } catch (HttpRequestException ex) { var error = new AcmeError("connection", ex.Message, challenge.Authorization.Identifier); return(null, error); } }
/// <summary> /// Initializes a new instance of the <see cref="AcmeRequestException"/> class. /// </summary> /// <param name="info"> /// The <see cref="SerializationInfo"/> that /// holds the serialized object data about the exception being thrown. /// </param> /// <param name="context"> /// The <see cref="StreamingContext"/> /// that contains contextual information about the source or destination. /// </param> protected AcmeRequestException(SerializationInfo info, StreamingContext context) : base(info, context) { var errorJson = info.GetString("acme.error"); if (!string.IsNullOrWhiteSpace(errorJson)) { Error = JsonConvert.DeserializeObject <AcmeError>(errorJson, jsonSerializerSettings); } }
public void CanSerializeWithError() { var error = new AcmeError { Detail = "error" }; var ex = new AcmeRequestException("certes", error); var serializer = new BinaryFormatter(); using (var buffer = new MemoryStream()) { serializer.Serialize(buffer, ex); buffer.Seek(0, SeekOrigin.Begin); var deserialized = (AcmeRequestException)serializer.Deserialize(buffer); Assert.NotNull(deserialized.Error.Detail); Assert.Equal("error", deserialized.Error.Detail); } }
/// <summary> /// Initializes a new instance of the <see cref="AcmeException" /> class. /// </summary> /// <param name="message">The message that describes the error.</param> /// <param name="error">The error occurred while processing ACME operations.</param> public AcmeRequestException(string message, AcmeError error) : base(message) { Error = error; }