Skip to content

Commit

Permalink
--generate-url parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
ssrlive committed Jun 2, 2024
1 parent 2ad9fdf commit f167c48
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 40 deletions.
2 changes: 1 addition & 1 deletion install/overtls-install-musl.sh
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,7 @@ function print_qrcode() {
check_file_exists "${ot_exe_path}"
check_file_exists "${ot_cfg_path}"

local qrcode="$( ${ot_exe_path} -q -c ${ot_cfg_path} )"
local qrcode="$( ${ot_exe_path} -g -c ${ot_cfg_path} )"
echo "${qrcode}"
qrencode -t UTF8 "${qrcode}" | cat
}
Expand Down
2 changes: 1 addition & 1 deletion install/overtls-install-selfsign.sh
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ function print_url() {
check_file_exists "${ot_exe_path}"
check_file_exists "${ot_cfg_path}"

local qrcode="$( ${ot_exe_path} -q --qrcode-cert -c ${ot_cfg_path} )"
local qrcode="$( ${ot_exe_path} -g -c ${ot_cfg_path} )"
echo "${qrcode}"
}

Expand Down
2 changes: 1 addition & 1 deletion install/overtls-install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -771,7 +771,7 @@ function print_qrcode() {
check_file_exists "${ot_exe_path}"
check_file_exists "${ot_cfg_path}"

local qrcode="$( ${ot_exe_path} -q -c ${ot_cfg_path} )"
local qrcode="$( ${ot_exe_path} -g -c ${ot_cfg_path} )"
echo "${qrcode}"
qrencode -t UTF8 "${qrcode}" | cat
}
Expand Down
8 changes: 4 additions & 4 deletions readme-cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,9 @@ overtls -r client -c config.json
如果你確實沒有 `域名`, 可以使用 `openssl` 生成自簽證書 來臨時連接服務端,以便你能處理你的緊急事務。
```bash
wget https://raw.githubusercontent.com/shadowsocksr-live/overtls/master/install/selfsign.sh
head selfsign.sh -n 25
chmod +x selfsign.sh
./selfsign.sh CN JiangSu ChangZhou MyGreatOrg Root_CA Server1 [email protected] example.com 123.45.67.89
sudo apt install -y wget # Debian/Ubuntu
sudo yum install -y wget # CentOS
wget https://raw.githubusercontent.com/shadowsocksr-live/overtls/master/install/overtls-install-selfsign.sh
bash ./overtls-install-selfsign.sh
```
> 注意:`GFW` 可能會因爲你使用了自簽證書而封鎖你的服務器。所以請不要長期用於正式場合。
10 changes: 5 additions & 5 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ and apply for a certificate.
Currently only 3 `CPU` architectures of `Linux` machines are supported: `x86_64`, `armv7` and `arm64`.
```
```bash
sudo apt install -y wget # Debian/Ubuntu
sudo yum install -y wget # CentOS
wget https://raw.githubusercontent.com/shadowsocksr-live/overtls/master/install/overtls-install-musl.sh
Expand Down Expand Up @@ -155,10 +155,10 @@ If you have not owned a `domain name`, you can use the `openssl` command to gene
for testing purposes.
```bash
wget https://raw.githubusercontent.com/shadowsocksr-live/overtls/master/install/selfsign.sh
head selfsign.sh -n 25
chmod +x selfsign.sh
./selfsign.sh CN JiangSu ChangZhou MyGreatOrg Root_CA Server1 [email protected] example.com 123.45.67.89
sudo apt install -y wget # Debian/Ubuntu
sudo yum install -y wget # CentOS
wget https://raw.githubusercontent.com/shadowsocksr-live/overtls/master/install/overtls-install-selfsign.sh
bash ./overtls-install-selfsign.sh
```
> Note: The `GFW` maybe block your server since you are using a self-signed certificate.
> So please do not use it for long-term production purposes.
4 changes: 2 additions & 2 deletions src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,13 +156,13 @@ pub unsafe extern "C" fn over_tls_client_stop() -> c_int {
///
/// Create a SSR URL from the config file.
#[no_mangle]
pub unsafe extern "C" fn overtls_generate_url(cfg_path: *const c_char, include_ca_file: bool) -> *mut c_char {
pub unsafe extern "C" fn overtls_generate_url(cfg_path: *const c_char) -> *mut c_char {
let cfg_path = std::ffi::CStr::from_ptr(cfg_path);
let cfg_path = match cfg_path.to_str() {
Ok(s) => s,
Err(_) => return std::ptr::null_mut(),
};
let url = match crate::config::generate_ssr_url(cfg_path, include_ca_file) {
let url = match crate::config::generate_ssr_url(cfg_path) {
Ok(s) => s,
Err(_) => return std::ptr::null_mut(),
};
Expand Down
12 changes: 3 additions & 9 deletions src/bin/overtls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,9 @@ fn main() -> Result<(), BoxError> {
let mut config = Config::from_config_file(&opt.config)?;
config.set_cache_dns(opt.cache_dns);

if opt.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);
if opt.generate_url {
let url = config.generate_ssr_url()?;
println!("{}", url);
return Ok(());
}

Expand Down
8 changes: 2 additions & 6 deletions src/cmdopt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,9 @@ pub struct CmdOpt {
/// Daemonize for unix family.
pub daemonize: bool,

/// Generate QR code for client.
/// Generate URL of the server node for client.
#[arg(short, long)]
pub qrcode: bool,

/// QR code contains certificate content.
#[arg(long)]
pub qrcode_cert: bool,
pub generate_url: bool,

/// Use C API for client.
#[arg(long)]
Expand Down
20 changes: 9 additions & 11 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ impl Config {
Ok(config)
}

pub fn generate_ssr_url(&self, include_ca_file: bool) -> Result<String> {
pub fn generate_ssr_url(&self) -> Result<String> {
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());
Expand All @@ -467,26 +467,24 @@ 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 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));
}
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)))
}
}

pub(crate) fn generate_ssr_url<P>(path: P, include_ca_file: bool) -> Result<String>
pub(crate) fn generate_ssr_url<P>(path: P) -> Result<String>
where
P: AsRef<std::path::Path>,
{
let config = Config::from_config_file(path)?;
if config.certificate_content().is_some() && !include_ca_file {
log::warn!("Certificate content discarded");
if config.certificate_content().is_some() {
log::warn!("Certificate content exists!");
}
config.generate_ssr_url(include_ca_file)
config.generate_ssr_url()
}

#[test]
Expand All @@ -507,7 +505,7 @@ fn test_config() {

config.check_correctness(false).unwrap();

let qrcode = config.generate_ssr_url(true).unwrap();
let qrcode = config.generate_ssr_url().unwrap();
println!("{:?}", qrcode);

let config = Config::from_ssr_url(&qrcode).unwrap();
Expand Down

0 comments on commit f167c48

Please sign in to comment.