Skip to content

Commit

Permalink
upgrade reqwest
Browse files Browse the repository at this point in the history
  • Loading branch information
axos88 committed Apr 26, 2019
1 parent 04677fd commit 6f15afc
Show file tree
Hide file tree
Showing 8 changed files with 494 additions and 20 deletions.
15 changes: 15 additions & 0 deletions .idea/acme-client.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/sbt.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

431 changes: 431 additions & 0 deletions .idea/workspace.xml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ serde_json = "1.0"
serde_derive = "1.0"
base64 = "0.9"
hyper = "0.10"
reqwest = "0.6"
reqwest = "0.9"
openssl = "0.10"
clap = { version = "2", optional = true }
env_logger = { version = "0.4", optional = true }
Expand Down
40 changes: 21 additions & 19 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ impl Directory {
/// # fn main () { try_main().unwrap(); }
/// ```
pub fn from_url(url: &str) -> Result<Directory> {
let client = Client::new()?;
let client = Client::new();
let mut res = client.get(url).send()?;
let mut content = String::new();
res.read_to_string(&mut content)?;
Expand Down Expand Up @@ -450,12 +450,13 @@ impl Directory {
/// it will try to get nonce header from directory url.
fn get_nonce(&self) -> Result<String> {
let url = self.url_for("new-nonce").unwrap_or(&self.url);
let client = Client::new()?;
let client = Client::new();
let res = client.get(url).send()?;
res.headers()
.get::<hyperx::ReplayNonce>()
.get("Replay-Nonce")
.ok_or("Replay-Nonce header not found".into())
.and_then(|nonce| Ok(nonce.as_str().to_string()))
.and_then(|nonce| nonce.to_str().map_err(|_| "Nonce header value contains invalid characters".into()))
.map(|nonce| nonce.to_string())
}

/// Makes a new post request to directory, signs payload with pkey.
Expand All @@ -474,11 +475,11 @@ impl Directory {
.and_then(|obj| obj.insert("resource".to_owned(), resource_json));

let jws = self.jws(pkey, json)?;
let client = Client::new()?;
let client = Client::new();
let mut res = client
.post(self.url_for(resource)
.ok_or(format!("URL for resource: {} not found", resource))?)
.body(&jws[..])
.body(jws)
.send()?;

let res_json = {
Expand All @@ -491,7 +492,7 @@ impl Directory {
}
};

Ok((*res.status(), res_json))
Ok((res.status(), res_json))
}

/// Makes a Flattened JSON Web Signature from payload
Expand Down Expand Up @@ -557,7 +558,7 @@ impl Account {
});
let (status, resp) = self.directory().request(self.pkey(), "new-authz", map)?;

if status != StatusCode::Created {
if status != StatusCode::CREATED {
return Err(ErrorKind::AcmeServerError(resp).into());
}

Expand Down Expand Up @@ -587,6 +588,7 @@ impl Account {
// This seems really cryptic but it's not
// https://tools.ietf.org/html/draft-ietf-acme-acme-05#section-7.1
// key-authz = token || '.' || base64url(JWK\_Thumbprint(accountKey))

let key_authorization = format!("{}.{}",
token,
b64(&hash(MessageDigest::sha256(),
Expand Down Expand Up @@ -646,8 +648,8 @@ impl Account {
};

match status {
StatusCode::Ok => info!("Certificate successfully revoked"),
StatusCode::Conflict => warn!("Certificate already revoked"),
StatusCode::OK => info!("Certificate successfully revoked"),
StatusCode::CONFLICT => warn!("Certificate already revoked"),
_ => return Err(ErrorKind::AcmeServerError(resp).into()),
}

Expand Down Expand Up @@ -733,8 +735,8 @@ impl AccountRegistration {
let (status, resp) = self.directory.request(&pkey, "new-reg", map)?;

match status {
StatusCode::Created => debug!("User successfully registered"),
StatusCode::Conflict => debug!("User already registered"),
StatusCode::CREATED => debug!("User successfully registered"),
StatusCode::CONFLICT => debug!("User already registered"),
_ => return Err(ErrorKind::AcmeServerError(resp).into()),
};

Expand Down Expand Up @@ -793,17 +795,17 @@ impl<'a> CertificateSigner<'a> {
map.insert("resource".to_owned(), "new-cert".to_owned());
map.insert("csr".to_owned(), b64(&csr.to_der()?));

let client = Client::new()?;
let client = Client::new();
let jws = self.account.directory().jws(self.account.pkey(), map)?;
let mut res = client
.post(self.account
.directory()
.url_for("new-cert")
.ok_or("new-cert url not found")?)
.body(&jws[..])
.body(jws)
.send()?;

if res.status() != &StatusCode::Created {
if res.status() != StatusCode::CREATED {
let res_json = {
let mut res_content = String::new();
res.read_to_string(&mut res_content)?;
Expand Down Expand Up @@ -895,7 +897,7 @@ impl SignedCertificate {
/// [`LETSENCRYPT_INTERMEDIATE_CERT_URL`](constant.LETSENCRYPT_INTERMEDIATE_CERT_URL.html).
/// will be used if url is None.
fn get_intermediate_certificate(&self, url: Option<&str>) -> Result<X509> {
let client = Client::new()?;
let client = Client::new();
let mut res = client
.get(url.unwrap_or(LETSENCRYPT_INTERMEDIATE_CERT_URL))
.send()?;
Expand Down Expand Up @@ -1015,16 +1017,16 @@ impl<'a> Challenge<'a> {
self.account.directory().jws(self.account.pkey(), map)?
};

let client = Client::new()?;
let mut resp = client.post(&self.url).body(&payload[..]).send()?;
let client = Client::new();
let mut resp = client.post(&self.url).body(payload).send()?;

let mut res_json: Value = {
let mut res_content = String::new();
resp.read_to_string(&mut res_content)?;
from_str(&res_content)?
};

if resp.status() != &StatusCode::Accepted {
if resp.status() != StatusCode::ACCEPTED {
return Err(ErrorKind::AcmeServerError(res_json).into());
}

Expand Down

0 comments on commit 6f15afc

Please sign in to comment.