Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ secret_key
*.key
*.secret
.env
.idea/
12 changes: 0 additions & 12 deletions .idea/iroh-proxy.iml

This file was deleted.

8 changes: 0 additions & 8 deletions .idea/modules.xml

This file was deleted.

6 changes: 0 additions & 6 deletions .idea/vcs.xml

This file was deleted.

112 changes: 0 additions & 112 deletions .idea/workspace.xml

This file was deleted.

6 changes: 5 additions & 1 deletion src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ pub struct ForwardSection {
pub fn default_config_path() -> PathBuf {
ProjectDirs::from("", "", "iroh-proxy")
.map(|dirs| dirs.config_dir().join("config.toml"))
.unwrap_or_else(|| PathBuf::from(".config/iroh-proxy/config.toml"))
.unwrap_or_else(|| {
PathBuf::from(".config")
.join("iroh-proxy")
.join("config.toml")
})
}

pub fn load_config(path: &Path) -> Result<Config> {
Expand Down
17 changes: 10 additions & 7 deletions src/keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ use std::path::{Path, PathBuf};
use anyhow::{Context, Result, anyhow};
use directories::ProjectDirs;
use iroh::SecretKey;
use rand::SeedableRng;
use rand::rngs::StdRng;

pub struct ServeKeyLock {
file: File,
Expand All @@ -13,7 +15,11 @@ pub struct ServeKeyLock {
pub fn default_key_path() -> PathBuf {
ProjectDirs::from("", "", "iroh-proxy")
.map(|dirs| dirs.config_dir().join("secret_key"))
.unwrap_or_else(|| PathBuf::from(".config/iroh-proxy/secret_key"))
.unwrap_or_else(|| {
PathBuf::from(".config")
.join("iroh-proxy")
.join("secret_key")
})
}

pub fn load_or_create_secret_key(path: &Path) -> Result<SecretKey> {
Expand All @@ -29,8 +35,7 @@ pub fn load_or_create_secret_key(path: &Path) -> Result<SecretKey> {
.with_context(|| format!("invalid key in {}", path.display()));
}

let mut rng = rand::rng();
let sk = SecretKey::generate(&mut rng);
let sk = SecretKey::generate(&mut StdRng::from_os_rng());
std::fs::write(path, sk.to_bytes())
.with_context(|| format!("failed to write key file {}", path.display()))?;
Ok(sk)
Expand All @@ -45,8 +50,7 @@ fn load_or_create_secret_key_from_file(file: &mut File, path: &Path) -> Result<S
.with_context(|| format!("failed to read key file {}", path.display()))?;

if raw.is_empty() {
let mut rng = rand::rng();
let sk = SecretKey::generate(&mut rng);
let sk = SecretKey::generate(&mut StdRng::from_os_rng());
file.set_len(0)
.with_context(|| format!("failed to truncate key file {}", path.display()))?;
file.seek(SeekFrom::Start(0))
Expand Down Expand Up @@ -107,6 +111,5 @@ pub fn load_or_create_forward_key(key_file: Option<&Path>) -> Result<SecretKey>
if let Some(path) = key_file {
return load_or_create_secret_key(path);
}
let mut rng = rand::rng();
Ok(SecretKey::generate(&mut rng))
Ok(SecretKey::generate(&mut StdRng::from_os_rng()))
}
Loading