SSE streaming with long-poll fallback; encrypted unicast profile; registry enc keys
This commit is contained in:
@@ -148,6 +148,15 @@ pub fn key_show(config_path: &Path) -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn key_show_enc(config_path: &Path) -> Result<()> {
|
||||
let config = Config::load(config_path)?;
|
||||
let secret = config
|
||||
.load_enc_key()?
|
||||
.ok_or_else(|| anyhow!("no encryption key at {}", config.enc_key_path().display()))?;
|
||||
println!("{}", crate::crypto::enc_public_from_secret(&secret)?);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn key_rotate(config_path: &Path) -> Result<()> {
|
||||
let config = Config::load(config_path)?;
|
||||
let old = config.load_key()?;
|
||||
@@ -155,8 +164,11 @@ pub fn key_rotate(config_path: &Path) -> Result<()> {
|
||||
std::fs::copy(config.key_path(), &backup)?;
|
||||
let new_key = Keypair::generate();
|
||||
config.save_key(&new_key)?;
|
||||
let (enc_secret, enc_public) = crate::crypto::generate_enc_keypair();
|
||||
config.save_enc_key(&enc_secret)?;
|
||||
println!("old pubkey {}", old.public_hex());
|
||||
println!("new pubkey {}", new_key.public_hex());
|
||||
println!("new enc pubkey {enc_public}");
|
||||
println!("old key saved to {}", backup.display());
|
||||
println!(
|
||||
"peers accept the new key via: frxd member add <name> {} --previous {}",
|
||||
@@ -293,8 +305,10 @@ pub fn registry_add(
|
||||
class: &str,
|
||||
not_before: Option<u64>,
|
||||
not_after: Option<u64>,
|
||||
enc_key: Option<String>,
|
||||
) -> Result<()> {
|
||||
let pubkey = normalize_key(pubkey)?;
|
||||
let enc_key = enc_key.map(|key| normalize_key(&key)).transpose()?;
|
||||
let class = if class == CLASS_ENRICHMENT {
|
||||
CLASS_ENRICHMENT
|
||||
} else {
|
||||
@@ -312,6 +326,7 @@ pub fn registry_add(
|
||||
not_before: not_before.unwrap_or_else(now_ts),
|
||||
not_after,
|
||||
}],
|
||||
enc_key: enc_key.clone(),
|
||||
});
|
||||
Ok(())
|
||||
})?;
|
||||
@@ -319,6 +334,19 @@ pub fn registry_add(
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn registry_set_enc_key(dir: &Path, id: &str, enc_key: &str) -> Result<()> {
|
||||
let enc_key = normalize_key(enc_key)?;
|
||||
mutate_registry(dir, |doc| {
|
||||
let Some(member) = doc.members.iter_mut().find(|member| member.id == id) else {
|
||||
return Err(anyhow!("no member named {id}"));
|
||||
};
|
||||
member.enc_key = Some(enc_key.clone());
|
||||
Ok(())
|
||||
})?;
|
||||
println!("set enc key for {id}");
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn registry_add_key(
|
||||
dir: &Path,
|
||||
id: &str,
|
||||
@@ -387,6 +415,9 @@ pub fn registry_list(dir: &Path) -> Result<()> {
|
||||
};
|
||||
println!(" {} ({window})", entry.key);
|
||||
}
|
||||
if let Some(enc_key) = &member.enc_key {
|
||||
println!(" enc {enc_key}");
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user