mirror of
https://github.com/Corfirean/coa-server-manager.git
synced 2026-11-25 03:25:56 +00:00
feat(phase15): release and security hardening, DPAPI key store, probe & protocol hardening, secret redaction, audit and readiness report
This commit is contained in:
1 parent
b69fa6b867
commit
51e0f136d6
207 files changed
+38235
-7770
No files matched your search
@@ -23,16 +23,32 @@ const ANSWER: Duration = Duration::from_secs(60);
|
||||
|
||||
impl PlayerChannel {
|
||||
/// `coordinator` is the Coordinator's player endpoint without the query, e.g. `wss://registry.example/coord/v1/player`.
|
||||
pub fn connect(coordinator: &str, realm: &RealmId, realm_key: &VerifyingKey, identity: &PlayerIdentity, clock: &dyn Fn() -> i64) -> Result<PlayerChannel, LinkError> {
|
||||
let mut ws = transport::connect(&format!("{coordinator}?realm={realm}"), Duration::from_millis(500))?;
|
||||
pub fn connect(
|
||||
coordinator: &str,
|
||||
realm: &RealmId,
|
||||
realm_key: &VerifyingKey,
|
||||
identity: &PlayerIdentity,
|
||||
clock: &dyn Fn() -> i64,
|
||||
) -> Result<PlayerChannel, LinkError> {
|
||||
let mut ws = transport::connect(
|
||||
&format!("{coordinator}?realm={realm}"),
|
||||
Duration::from_millis(500),
|
||||
)?;
|
||||
let nonce = match transport::next_frame(&mut ws, STEP)? {
|
||||
Frame::Challenge { nonce, .. } => nonce,
|
||||
_ => return Err(LinkError::Protocol("a challenge was expected".into())),
|
||||
};
|
||||
transport::send_text(&mut ws, &coord::sign_player_hello(&identity.key, &identity.player_id, realm, &nonce, clock()))?;
|
||||
transport::send_text(
|
||||
&mut ws,
|
||||
&coord::sign_player_hello(&identity.key, &identity.player_id, realm, &nonce, clock()),
|
||||
)?;
|
||||
let conn = match transport::next_frame(&mut ws, STEP)? {
|
||||
Frame::PlayerReady { conn, .. } => conn,
|
||||
_ => return Err(LinkError::Protocol("the Coordinator did not accept the hello".into())),
|
||||
_ => {
|
||||
return Err(LinkError::Protocol(
|
||||
"the Coordinator did not accept the hello".into(),
|
||||
))
|
||||
}
|
||||
};
|
||||
let (initiator, msg1) = Initiator::start().map_err(LinkError::from)?;
|
||||
transport::send_binary(&mut ws, msg1)?;
|
||||
@@ -41,10 +57,14 @@ impl PlayerChannel {
|
||||
transport::send_binary(&mut ws, msg3)?;
|
||||
// the Host proves it holds the realm's key on this very channel before anything private is said
|
||||
let proof_bytes = next_message(&mut ws, &mut channel, STEP)?;
|
||||
let proof: HostProof = serde_json::from_slice(&proof_bytes).map_err(|_| LinkError::Auth("the host's proof is not valid".into()))?;
|
||||
let proof: HostProof = serde_json::from_slice(&proof_bytes)
|
||||
.map_err(|_| LinkError::Auth("the host's proof is not valid".into()))?;
|
||||
noise::verify_host_proof(&proof, realm_key, realm, &channel).map_err(LinkError::from)?;
|
||||
let mine = noise::player_proof(&identity.key, realm, &identity.player_id, &channel);
|
||||
for f in channel.seal(&serde_json::to_vec(&mine).map_err(|e| LinkError::Protocol(e.to_string()))?).map_err(LinkError::from)? {
|
||||
for f in channel
|
||||
.seal(&serde_json::to_vec(&mine).map_err(|e| LinkError::Protocol(e.to_string()))?)
|
||||
.map_err(LinkError::from)?
|
||||
{
|
||||
transport::send_binary(&mut ws, f)?;
|
||||
}
|
||||
Ok(PlayerChannel { ws, channel, conn })
|
||||
@@ -55,7 +75,11 @@ impl PlayerChannel {
|
||||
}
|
||||
|
||||
pub fn request(&mut self, request: &Request) -> Result<Response, LinkError> {
|
||||
for f in self.channel.seal(&app::encode_request(request)).map_err(LinkError::from)? {
|
||||
for f in self
|
||||
.channel
|
||||
.seal(&app::encode_request(request))
|
||||
.map_err(LinkError::from)?
|
||||
{
|
||||
transport::send_binary(&mut self.ws, f)?;
|
||||
}
|
||||
let bytes = next_message(&mut self.ws, &mut self.channel, ANSWER)?;
|
||||
@@ -79,12 +103,16 @@ fn next_binary(ws: &mut Ws, total: Duration) -> Result<Vec<u8>, LinkError> {
|
||||
Some(tungstenite::Message::Text(t)) => {
|
||||
// an error frame from the Coordinator (the Host went away, a limit was hit)
|
||||
return match coord::parse_text(t.as_str()).map_err(LinkError::from)? {
|
||||
Frame::Error { code, message } => Err(transport::from_error_frame(code, &message)),
|
||||
Frame::Error { code, message } => {
|
||||
Err(transport::from_error_frame(code, &message))
|
||||
}
|
||||
Frame::Close { .. } => Err(LinkError::HostOffline),
|
||||
_ => Err(LinkError::Protocol("an unexpected control frame".into())),
|
||||
};
|
||||
}
|
||||
Some(tungstenite::Message::Close(_)) => return Err(LinkError::Io("the connection was closed".into())),
|
||||
Some(tungstenite::Message::Close(_)) => {
|
||||
return Err(LinkError::Io("the connection was closed".into()))
|
||||
}
|
||||
Some(_) => continue,
|
||||
}
|
||||
}
|
||||
@@ -94,7 +122,9 @@ fn next_binary(ws: &mut Ws, total: Duration) -> Result<Vec<u8>, LinkError> {
|
||||
fn next_message(ws: &mut Ws, channel: &mut Channel, total: Duration) -> Result<Vec<u8>, LinkError> {
|
||||
let end = std::time::Instant::now() + total;
|
||||
loop {
|
||||
let left = end.checked_duration_since(std::time::Instant::now()).ok_or(LinkError::Timeout)?;
|
||||
let left = end
|
||||
.checked_duration_since(std::time::Instant::now())
|
||||
.ok_or(LinkError::Timeout)?;
|
||||
let frame = next_binary(ws, left)?;
|
||||
if let Some(m) = channel.open_frame(&frame).map_err(LinkError::from)? {
|
||||
return Ok(m);
|
||||
|
||||
Reference in new issue
Block a user