Skip to content

Commit

Permalink
feat: generate random secret for tunnel (#163)
Browse files Browse the repository at this point in the history
Closes DO-1952
  • Loading branch information
augustoccesar authored Feb 18, 2025
1 parent e1e6743 commit 5884a0d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
7 changes: 7 additions & 0 deletions worker/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -454,3 +454,10 @@ fn cloudflare_client(api_token: &str) -> cloudflare::framework::async_api::Clien
)
.expect("Cloudflare API Client to have been created")
}

pub fn generate_secret() -> String {
let mut random_bytes = [0u8; 32];
getrandom::getrandom(&mut random_bytes).unwrap();

base64::Engine::encode(&base64::prelude::BASE64_STANDARD, random_bytes)
}
11 changes: 1 addition & 10 deletions worker/src/tunnel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ pub async fn create_tunnel(
tunnel_name: &str,
// TODO: Make this tuple into a proper type
) -> Result<(String, String), String> {
let tunnel_secret = generate_tunnel_secret();
let tunnel_secret = crate::generate_secret();
let url = format!(
"https://api.cloudflare.com/client/v4/accounts/{}/cfd_tunnel",
account_id,
Expand Down Expand Up @@ -227,12 +227,3 @@ async fn send_request<T: for<'de> serde::Deserialize<'de>>(
Err("Wot".into())
}
}

fn generate_tunnel_secret() -> String {
// TODO: Use rand and getrandom (with 'js' feature)
// let mut rng = rand::thread_rng();
// let random_bytes: [u8; 32] = rng.gen();
// BASE64_STANDARD.encode(random_bytes)

"AQIDBAUGBwgBAgMEBQYHCAECAwQFBgcIAQIDBAUGBwg=".into()
}

0 comments on commit 5884a0d

Please sign in to comment.