Add client TLS auth on server side
This commit is contained in:
@ -8,7 +8,7 @@ static mut ROOT_CERT: Option<Vec<u8>> = None;
|
||||
pub struct ClientConfig {
|
||||
/// Access token
|
||||
#[clap(short, long)]
|
||||
pub token: String,
|
||||
pub token: Option<String>,
|
||||
|
||||
/// Relay server
|
||||
#[clap(short, long, default_value = "http://127.0.0.1:8000")]
|
||||
@ -24,6 +24,11 @@ pub struct ClientConfig {
|
||||
}
|
||||
|
||||
impl ClientConfig {
|
||||
/// Get client token, returning a dummy token if none was specified
|
||||
pub fn get_auth_token(&self) -> &str {
|
||||
self.token.as_deref().unwrap_or("none")
|
||||
}
|
||||
|
||||
/// Load root certificate
|
||||
pub fn get_root_certificate(&self) -> Option<Vec<u8>> {
|
||||
self.root_certificate.as_ref()?;
|
||||
|
@ -23,7 +23,7 @@ async fn get_server_config(config: &ClientConfig) -> Result<RemoteConfig, Box<dy
|
||||
let client = client.build().expect("Failed to build reqwest client");
|
||||
|
||||
let req = client.get(url)
|
||||
.header("Authorization", format!("Bearer {}", config.token))
|
||||
.header("Authorization", format!("Bearer {}", config.get_auth_token()))
|
||||
.send()
|
||||
.await?;
|
||||
if req.status().as_u16() != 200 {
|
||||
@ -51,7 +51,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
|
||||
|
||||
let h = tokio::spawn(relay_client(
|
||||
format!("{}/ws?id={}&token={}",
|
||||
args.relay_url, port.id, urlencoding::encode(&args.token))
|
||||
args.relay_url, port.id, urlencoding::encode(args.get_auth_token()))
|
||||
.replace("http", "ws"),
|
||||
listen_address,
|
||||
args.clone(),
|
||||
|
Reference in New Issue
Block a user