Signature layout
This commit is contained in:
@@ -1,4 +1,7 @@
|
|||||||
use std::sync::Arc;
|
use std::{
|
||||||
|
sync::Arc,
|
||||||
|
time::{SystemTime, UNIX_EPOCH},
|
||||||
|
};
|
||||||
|
|
||||||
use axum::extract::ws::WebSocket;
|
use axum::extract::ws::WebSocket;
|
||||||
use ed25519_dalek::Signer;
|
use ed25519_dalek::Signer;
|
||||||
@@ -11,8 +14,10 @@ impl super::Client {
|
|||||||
pub async fn initialize(server: &Arc<Server>, mut socket: WebSocket) -> anyhow::Result<Self> {
|
pub async fn initialize(server: &Arc<Server>, mut socket: WebSocket) -> anyhow::Result<Self> {
|
||||||
let Some(ServerMethod::Initialize {
|
let Some(ServerMethod::Initialize {
|
||||||
public_key: public_key_string,
|
public_key: public_key_string,
|
||||||
timestamp,
|
|
||||||
signature,
|
signature,
|
||||||
|
|
||||||
|
timestamp,
|
||||||
|
hostname,
|
||||||
}) = Client::read_socket(&mut socket).await?
|
}) = Client::read_socket(&mut socket).await?
|
||||||
else {
|
else {
|
||||||
Client::send_socket(
|
Client::send_socket(
|
||||||
@@ -32,7 +37,7 @@ impl super::Client {
|
|||||||
|
|
||||||
if public_key
|
if public_key
|
||||||
.verify_strict(
|
.verify_strict(
|
||||||
format!("{public_key_string}@{timestamp}@").as_bytes(),
|
format!("{timestamp}@{hostname}").as_bytes(),
|
||||||
&crate::signature::from_string_sig(&signature)?,
|
&crate::signature::from_string_sig(&signature)?,
|
||||||
)
|
)
|
||||||
.is_ok()
|
.is_ok()
|
||||||
@@ -40,17 +45,24 @@ impl super::Client {
|
|||||||
return Err(anyhow::anyhow!("Invalid signature"));
|
return Err(anyhow::anyhow!("Invalid signature"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
let timestamp = SystemTime::now().duration_since(UNIX_EPOCH)?.as_secs();
|
||||||
|
|
||||||
Client::send_socket(
|
Client::send_socket(
|
||||||
&mut socket,
|
&mut socket,
|
||||||
ClientMethod::Initialized {
|
ClientMethod::Initialized {
|
||||||
public_key: crate::signature::to_string(&server.key.verifying_key()),
|
public_key: crate::signature::to_string(&server.key.verifying_key()),
|
||||||
signature: server
|
signature: server
|
||||||
.key
|
.key
|
||||||
.sign(format!("{public_key_string}@{timestamp}").as_bytes())
|
.sign(format!("{timestamp}@{hostname}@{public_key_string}").as_bytes())
|
||||||
.to_string(),
|
.to_string(),
|
||||||
|
|
||||||
|
timestamp,
|
||||||
|
hostname,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
}
|
||||||
|
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
socket,
|
socket,
|
||||||
|
|||||||
+6
-1
@@ -27,6 +27,9 @@ pub enum ClientMethod {
|
|||||||
Initialized {
|
Initialized {
|
||||||
public_key: String,
|
public_key: String,
|
||||||
signature: String,
|
signature: String,
|
||||||
|
|
||||||
|
timestamp: u64,
|
||||||
|
hostname: String,
|
||||||
},
|
},
|
||||||
|
|
||||||
Error {
|
Error {
|
||||||
@@ -39,8 +42,10 @@ pub enum ClientMethod {
|
|||||||
pub enum ServerMethod {
|
pub enum ServerMethod {
|
||||||
Initialize {
|
Initialize {
|
||||||
public_key: String,
|
public_key: String,
|
||||||
timestamp: u64,
|
|
||||||
signature: String,
|
signature: String,
|
||||||
|
|
||||||
|
timestamp: u64,
|
||||||
|
hostname: String,
|
||||||
},
|
},
|
||||||
|
|
||||||
Error {
|
Error {
|
||||||
|
|||||||
Reference in New Issue
Block a user