From 9a436fc35f489b74bd106a3b2d7976ca1ae1d0ae Mon Sep 17 00:00:00 2001 From: Rodolphe Breard Date: Wed, 11 Mar 2020 21:10:36 +0100 Subject: [PATCH] Remove superfluous characters in JSON In some situations, it has been found that a specific ACME server returns extra characters before and after the JSON, which is therefore invalid. Although this must be fixed in the server, ACMEd should gracefully ignore such erroneous characters instead of refusing the response. --- acmed/src/acme_proto/http.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/acmed/src/acme_proto/http.rs b/acmed/src/acme_proto/http.rs index 2dd874f..4aa7ac7 100644 --- a/acmed/src/acme_proto/http.rs +++ b/acmed/src/acme_proto/http.rs @@ -123,6 +123,18 @@ fn post_jose_type( let rstr = String::from_utf8_lossy(data); cert.trace(&format!("request body: {}", rstr)); let (res, res_body) = send_request(cert, &request)?; + let lpos = res_body.find("{").unwrap_or(0); + let res_body = if lpos == 0 { + res_body + } else { + res_body.chars().skip(lpos).collect::() + }; + let rpos = res_body.rfind("}").unwrap_or(0); + let res_body = if rpos == 0 { + res_body + } else { + res_body.chars().take(rpos + 1).collect::() + }; cert.trace(&format!("response body: {}", res_body)); Ok((res, res_body)) }