Signature layout

This commit is contained in:
2026-08-12 09:04:30 -04:00
parent 019c2888cb
commit 9cc2014e55
2 changed files with 32 additions and 15 deletions
+16 -4
View File
@@ -1,4 +1,7 @@
use std::sync::Arc;
use std::{
sync::Arc,
time::{SystemTime, UNIX_EPOCH},
};
use axum::extract::ws::WebSocket;
use ed25519_dalek::Signer;
@@ -11,8 +14,10 @@ impl super::Client {
pub async fn initialize(server: &Arc<Server>, mut socket: WebSocket) -> anyhow::Result<Self> {
let Some(ServerMethod::Initialize {
public_key: public_key_string,
timestamp,
signature,
timestamp,
hostname,
}) = Client::read_socket(&mut socket).await?
else {
Client::send_socket(
@@ -32,7 +37,7 @@ impl super::Client {
if public_key
.verify_strict(
format!("{public_key_string}@{timestamp}@").as_bytes(),
format!("{timestamp}@{hostname}").as_bytes(),
&crate::signature::from_string_sig(&signature)?,
)
.is_ok()
@@ -40,17 +45,24 @@ impl super::Client {
return Err(anyhow::anyhow!("Invalid signature"));
}
{
let timestamp = SystemTime::now().duration_since(UNIX_EPOCH)?.as_secs();
Client::send_socket(
&mut socket,
ClientMethod::Initialized {
public_key: crate::signature::to_string(&server.key.verifying_key()),
signature: server
.key
.sign(format!("{public_key_string}@{timestamp}").as_bytes())
.sign(format!("{timestamp}@{hostname}@{public_key_string}").as_bytes())
.to_string(),
timestamp,
hostname,
},
)
.await?;
}
Ok(Self {
socket,
+6 -1
View File
@@ -27,6 +27,9 @@ pub enum ClientMethod {
Initialized {
public_key: String,
signature: String,
timestamp: u64,
hostname: String,
},
Error {
@@ -39,8 +42,10 @@ pub enum ClientMethod {
pub enum ServerMethod {
Initialize {
public_key: String,
timestamp: u64,
signature: String,
timestamp: u64,
hostname: String,
},
Error {