diff --git a/src/bin/overtls.rs b/src/bin/overtls.rs index 3fdc196..a9d8449 100644 --- a/src/bin/overtls.rs +++ b/src/bin/overtls.rs @@ -44,7 +44,13 @@ fn main() -> Result<(), BoxError> { config.set_cache_dns(opt.cache_dns); if opt.qrcode { - let qrcode = config.generate_ssr_qrcode()?; + if let Some(ref ca) = config.certificate_content() { + if !opt.qrcode_cert { + eprintln!("Certificate content:"); + eprint!("{}", ca); + } + } + let qrcode = config.generate_ssr_url(opt.qrcode_cert)?; println!("{}", qrcode); return Ok(()); } diff --git a/src/cmdopt.rs b/src/cmdopt.rs index 664553d..bdeb395 100644 --- a/src/cmdopt.rs +++ b/src/cmdopt.rs @@ -101,6 +101,10 @@ pub struct CmdOpt { #[arg(short, long)] pub qrcode: bool, + /// QR code contains certificate content. + #[arg(long)] + pub qrcode_cert: bool, + /// Use C API for client. #[arg(long)] pub c_api: bool, diff --git a/src/config.rs b/src/config.rs index bd177ec..07ea9a1 100644 --- a/src/config.rs +++ b/src/config.rs @@ -449,7 +449,7 @@ impl Config { Ok(config) } - pub fn generate_ssr_qrcode(&self) -> Result { + pub fn generate_ssr_url(&self, include_ca_file: bool) -> Result { let client = self.client.as_ref().ok_or(Error::from("client is not set"))?; let engine = crate::Base64Engine::UrlSafeNoPad; let method = self.method.as_ref().map_or("none".to_string(), |m| m.clone()); @@ -467,9 +467,11 @@ impl Config { let mut url = format!("{host}:{port}:origin:{method}:plain:{password}/?remarks={remarks}&ot_enable=1"); url.push_str(&format!("&ot_domain={domain}&ot_path={tunnel_path}")); - if let Some(ref ca) = client.certificate_content() { - let ca = crate::base64_encode(ca.as_bytes(), engine); - url.push_str(&format!("&ot_cert={}", ca)); + if include_ca_file { + if let Some(ref ca) = client.certificate_content() { + let ca = crate::base64_encode(ca.as_bytes(), engine); + url.push_str(&format!("&ot_cert={}", ca)); + } } Ok(format!("ssr://{}", crate::base64_encode(url.as_bytes(), engine))) @@ -494,7 +496,7 @@ fn test_config() { config.check_correctness(false).unwrap(); - let qrcode = config.generate_ssr_qrcode().unwrap(); + let qrcode = config.generate_ssr_url(true).unwrap(); println!("{:?}", qrcode); let config = Config::from_ssr_url(&qrcode).unwrap();