Initial commit: split VNOX monorepo into VNOX-Server
Unified server binary (vnox-serverd) combining: - Gateway (TCP, auth, channels, sessions, SQLite) - Voice-node (UDP relay, Opus, jitter buffer) Standalone gateway (vnox-gateway) and voice-node (vnox-voice-node) preserved as sub-crates.
This commit is contained in:
commit
e751e0bf5b
94 changed files with 9771 additions and 0 deletions
1
gateway/src/bootstrap/mod.rs
Normal file
1
gateway/src/bootstrap/mod.rs
Normal file
|
|
@ -0,0 +1 @@
|
|||
pub mod server_identity;
|
||||
58
gateway/src/bootstrap/server_identity.rs
Normal file
58
gateway/src/bootstrap/server_identity.rs
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
use anyhow::Result;
|
||||
use ed25519_dalek::SigningKey;
|
||||
use rand::rngs::OsRng;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::path::Path;
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
struct StoredIdentity {
|
||||
pubkey_hex: String,
|
||||
privkey_hex: String,
|
||||
}
|
||||
|
||||
/// Gateway Ed25519 identity — loaded from disk or generated on first start.
|
||||
pub struct ServerIdentity {
|
||||
signing_key: SigningKey,
|
||||
}
|
||||
|
||||
impl ServerIdentity {
|
||||
pub fn pubkey_hex(&self) -> String {
|
||||
hex::encode(self.signing_key.verifying_key().to_bytes())
|
||||
}
|
||||
|
||||
pub fn load_or_generate(data_dir: &Path) -> Result<Self> {
|
||||
let path = data_dir.join("server_identity.json");
|
||||
|
||||
if path.exists() {
|
||||
let text = std::fs::read_to_string(&path)?;
|
||||
let stored: StoredIdentity = serde_json::from_str(&text)?;
|
||||
let signing_key = SigningKey::from_bytes(
|
||||
hex::decode(&stored.privkey_hex)?
|
||||
.as_slice()
|
||||
.try_into()
|
||||
.map_err(|_| anyhow::anyhow!("invalid server private key length"))?,
|
||||
);
|
||||
let computed_pubkey = hex::encode(signing_key.verifying_key().to_bytes());
|
||||
if stored.pubkey_hex != computed_pubkey {
|
||||
return Err(anyhow::anyhow!(
|
||||
"server_identity.json pubkey does not match private key"
|
||||
));
|
||||
}
|
||||
return Ok(Self { signing_key });
|
||||
}
|
||||
|
||||
let signing_key = SigningKey::generate(&mut OsRng);
|
||||
let verifying_key = signing_key.verifying_key();
|
||||
let pubkey_hex = hex::encode(verifying_key.to_bytes());
|
||||
|
||||
let stored = StoredIdentity {
|
||||
pubkey_hex,
|
||||
privkey_hex: hex::encode(signing_key.to_bytes()),
|
||||
};
|
||||
|
||||
std::fs::create_dir_all(data_dir)?;
|
||||
std::fs::write(&path, serde_json::to_string_pretty(&stored)?)?;
|
||||
|
||||
Ok(Self { signing_key })
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue