diff --git a/Cargo.toml b/Cargo.toml index 53ef68b..5bbf2d2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,9 +15,8 @@ log = "0.4" serde = "1.0" serde_json = "1.0" serde_derive = "1.0" -base64 = "0.9" -hyper = "0.10" -reqwest = "0.6" +base64 = "0.13" +reqwest = { version = "0.10", default-features = false, features = ["blocking", "rustls-tls"] } openssl = "0.10" clap = { version = "2", optional = true } env_logger = { version = "0.4", optional = true } diff --git a/src/lib.rs b/src/lib.rs index f8d2fb6..33d2bb7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -274,8 +274,6 @@ pub extern crate openssl; extern crate log; #[macro_use] extern crate error_chain; -#[macro_use] -extern crate hyper; extern crate reqwest; extern crate serde; extern crate serde_json; @@ -291,7 +289,7 @@ use openssl::hash::{hash, MessageDigest}; use openssl::pkey::PKey; use openssl::x509::{X509, X509Req}; -use reqwest::{Client, StatusCode}; +use reqwest::{blocking::Client, StatusCode}; use helper::{gen_key, b64, read_pkey, gen_csr}; use error::{Result, ErrorKind}; @@ -399,7 +397,7 @@ impl Directory { /// # fn main () { try_main().unwrap(); } /// ``` pub fn from_url(url: &str) -> Result { - 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)?; @@ -450,12 +448,12 @@ impl Directory { /// it will try to get nonce header from directory url. fn get_nonce(&self) -> Result { 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::() + .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(|s| s.to_string()).map_err(|e| e.into())) } /// Makes a new post request to directory, signs payload with pkey. @@ -474,11 +472,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 = { @@ -491,7 +489,7 @@ impl Directory { } }; - Ok((*res.status(), res_json)) + Ok((res.status(), res_json)) } /// Makes a Flattened JSON Web Signature from payload @@ -557,7 +555,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()); } @@ -646,8 +644,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()), } @@ -733,8 +731,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()), }; @@ -793,17 +791,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)?; @@ -895,7 +893,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 { - let client = Client::new()?; + let client = Client::new(); let mut res = client .get(url.unwrap_or(LETSENCRYPT_INTERMEDIATE_CERT_URL)) .send()?; @@ -1015,8 +1013,8 @@ 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(); @@ -1024,7 +1022,7 @@ impl<'a> Challenge<'a> { from_str(&res_content)? }; - if resp.status() != &StatusCode::Accepted { + if resp.status() != StatusCode::ACCEPTED { return Err(ErrorKind::AcmeServerError(res_json).into()); } @@ -1058,19 +1056,10 @@ impl<'a> Challenge<'a> { } -// header! is making a public struct, -// our custom header is private and only used privately in this module -mod hyperx { - // ReplayNonce header for hyper - header! { (ReplayNonce, "Replay-Nonce") => [String] } -} - - /// Error and result types. pub mod error { use std::io; use openssl; - use hyper; use reqwest; use serde_json; @@ -1085,8 +1074,8 @@ pub mod error { foreign_links { OpenSslErrorStack(openssl::error::ErrorStack); IoError(io::Error); - HyperError(hyper::Error); ReqwestError(reqwest::Error); + ReqwestToStrError(reqwest::header::ToStrError); ValueParserError(serde_json::Error); }