Browse Source

Format code

pull/5/head
Rodolphe Breard 6 years ago
parent
commit
a59a909cc6
  1. 6
      acmed/src/acme_proto.rs
  2. 36
      acmed/src/acme_proto/http.rs
  3. 10
      acmed/src/main.rs

6
acmed/src/acme_proto.rs

@ -124,7 +124,8 @@ pub fn request_certificate(cert: &Certificate, root_certs: &[String]) -> Result<
// 8. Tell the server the challenge has been completed
let chall_url = challenge.get_url();
let data_builder = set_data_builder!(account, b"{}", chall_url);
let new_nonce = http::post_challenge_response(root_certs, &chall_url, &data_builder, &nonce)?;
let new_nonce =
http::post_challenge_response(root_certs, &chall_url, &data_builder, &nonce)?;
nonce = new_nonce;
}
}
@ -147,7 +148,8 @@ pub fn request_certificate(cert: &Certificate, root_certs: &[String]) -> Result<
let (priv_key, pub_key) = certificate::get_key_pair(cert)?;
let csr = certificate::generate_csr(cert, &priv_key, &pub_key)?;
let data_builder = set_data_builder!(account, csr.as_bytes(), order.finalize);
let (_, nonce): (Order, String) = http::get_obj(root_certs, &order.finalize, &data_builder, &nonce)?;
let (_, nonce): (Order, String) =
http::get_obj(root_certs, &order.finalize, &data_builder, &nonce)?;
// 12. Pool the order in order to see whether or not it is valid
let data_builder = set_empty_data_builder!(account, order_url);

36
acmed/src/acme_proto/http.rs

@ -4,9 +4,9 @@ use http_req::request::{Method, Request};
use http_req::response::Response;
use http_req::uri::Uri;
use log::{debug, trace, warn};
use std::path::Path;
use std::str::FromStr;
use std::{thread, time};
use std::path::Path;
const CONTENT_TYPE_JOSE: &str = "application/jose+json";
const CONTENT_TYPE_JSON: &str = "application/json";
@ -97,7 +97,12 @@ fn nonce_from_response(res: &Response) -> Result<String, Error> {
}
}
fn post_jose_type(root_certs: &[String], url: &str, data: &[u8], accept_type: &str) -> Result<(Response, String), Error> {
fn post_jose_type(
root_certs: &[String],
url: &str,
data: &[u8],
accept_type: &str,
) -> Result<(Response, String), Error> {
let uri = url.parse::<Uri>()?;
let mut request = new_request(root_certs, &uri, Method::POST);
request.header("Content-Type", CONTENT_TYPE_JOSE);
@ -155,7 +160,12 @@ where
Err("Too much errors, will not retry".into())
}
fn fetch_obj<T, G>(root_certs: &[String], url: &str, data_builder: &G, nonce: &str) -> Result<(T, String, String), Error>
fn fetch_obj<T, G>(
root_certs: &[String],
url: &str,
data_builder: &G,
nonce: &str,
) -> Result<(T, String, String), Error>
where
T: std::str::FromStr<Err = Error>,
G: Fn(&str) -> Result<String, Error>,
@ -181,7 +191,12 @@ where
}
}
pub fn get_obj<T, G>(root_certs: &[String], url: &str, data_builder: &G, nonce: &str) -> Result<(T, String), Error>
pub fn get_obj<T, G>(
root_certs: &[String],
url: &str,
data_builder: &G,
nonce: &str,
) -> Result<(T, String), Error>
where
T: std::str::FromStr<Err = Error>,
G: Fn(&str) -> Result<String, Error>,
@ -215,11 +230,17 @@ where
Err(msg.into())
}
pub fn post_challenge_response<G>(root_certs: &[String], url: &str, data_builder: &G, nonce: &str) -> Result<String, Error>
pub fn post_challenge_response<G>(
root_certs: &[String],
url: &str,
data_builder: &G,
nonce: &str,
) -> Result<String, Error>
where
G: Fn(&str) -> Result<String, Error>,
{
let (_, _, nonce): (DummyString, String, String) = fetch_obj(root_certs, url, data_builder, nonce)?;
let (_, _, nonce): (DummyString, String, String) =
fetch_obj(root_certs, url, data_builder, nonce)?;
Ok(nonce)
}
@ -232,7 +253,8 @@ pub fn get_certificate<G>(
where
G: Fn(&str) -> Result<String, Error>,
{
let (res_body, _, nonce): (DummyString, String, String) = fetch_obj(root_certs, url, data_builder, nonce)?;
let (res_body, _, nonce): (DummyString, String, String) =
fetch_obj(root_certs, url, data_builder, nonce)?;
Ok((res_body.content, nonce))
}

10
acmed/src/main.rs

@ -77,11 +77,11 @@ fn main() {
)
.arg(
Arg::with_name("root-cert")
.long("root-cert")
.help("Add a root certificate to the trust store")
.takes_value(true)
.multiple(true)
.value_name("FILE")
.long("root-cert")
.help("Add a root certificate to the trust store")
.takes_value(true)
.multiple(true)
.value_name("FILE"),
)
.get_matches();

Loading…
Cancel
Save