diff --git a/acmed/Cargo.toml b/acmed/Cargo.toml index 2639998..012df8b 100644 --- a/acmed/Cargo.toml +++ b/acmed/Cargo.toml @@ -18,6 +18,7 @@ handlebars = "2.0.0-beta.1" http_req = "0.4" log = "0.4" openssl = "0.10" +openssl-sys = "0.9" serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" time = "0.1" diff --git a/acmed/build.rs b/acmed/build.rs index 2902dd1..5907ccc 100644 --- a/acmed/build.rs +++ b/acmed/build.rs @@ -60,19 +60,58 @@ fn set_lock() { if p.name == "http_req" { let agent = format!("{}/{}", p.name, p.version); set_rustc_env_var!("ACMED_HTTP_LIB_AGENT", agent); + set_rustc_env_var!("ACMED_HTTP_LIB_NAME", p.name); + set_rustc_env_var!("ACMED_HTTP_LIB_VERSION", p.version); return; } } } +fn get_openssl_version_unit(n: u64, pos: u32) -> u64 { + let p = 0xff_00_00_00_0 >> (8 * pos); + let n = n & p; + n >> (8 * (3 - pos) + 4) +} + +fn get_openssl_version(v: &str) -> String { + let v = u64::from_str_radix(&v, 16).unwrap(); + let mut version = vec![]; + for i in 0..3 { + let n = get_openssl_version_unit(v, i); + version.push(format!("{}", n)); + } + let version = version.join("."); + let p = get_openssl_version_unit(v, 3); + if p != 0 { + let p = p + 0x60; + let p = std::char::from_u32(p as u32).unwrap(); + format!("{}{}", version, p) + } else { + version + } +} + +fn set_tls() { + if let Ok(v) = env::var("DEP_OPENSSL_VERSION_NUMBER") { + let version = get_openssl_version(&v); + set_rustc_env_var!("ACMED_TLS_LIB_VERSION", version); + set_rustc_env_var!("ACMED_TLS_LIB_NAME", "OpenSSL"); + } + if let Ok(v) = env::var("DEP_OPENSSL_LIBRESSL_VERSION_NUMBER") { + let version = get_openssl_version(&v); + set_rustc_env_var!("ACMED_TLS_LIB_VERSION", version); + set_rustc_env_var!("ACMED_TLS_LIB_NAME", "LibreSSL"); + } +} + fn set_target() { - match env::var("TARGET") { - Ok(target) => set_rustc_env_var!("ACMED_TARGET", target), - Err(_) => {} + if let Ok(target) = env::var("TARGET") { + set_rustc_env_var!("ACMED_TARGET", target); }; } fn main() { set_target(); + set_tls(); set_lock(); } diff --git a/acmed/src/main.rs b/acmed/src/main.rs index 1d2a190..ecd0840 100644 --- a/acmed/src/main.rs +++ b/acmed/src/main.rs @@ -32,8 +32,18 @@ pub const DEFAULT_HTTP_FAIL_WAIT_SEC: u64 = 1; pub const DEFAULT_HOOK_ALLOW_FAILURE: bool = false; fn main() { + let full_version = format!( + "{} {}\n\nCompiled with:\n {} {}\n {} {}", + APP_VERSION, + env!("ACMED_TARGET"), + env!("ACMED_TLS_LIB_NAME"), + env!("ACMED_TLS_LIB_VERSION"), + env!("ACMED_HTTP_LIB_NAME"), + env!("ACMED_HTTP_LIB_VERSION") + ); let matches = App::new(APP_NAME) .version(APP_VERSION) + .long_version(full_version.as_str()) .arg( Arg::with_name("config") .short("c")