mirror of
https://github.com/Corfirean/coa-server-manager.git
synced 2026-11-25 19:25:56 +00:00
Integrate isolated rulesets, portable admission, and compatible relay authentication
This commit is contained in:
commit
d5f1e9cc83
112 files changed
+5892
-965
No files matched your search
@@ -103,6 +103,7 @@ pub enum Request {
|
||||
TransferOffer {
|
||||
transfer_id: Uuid,
|
||||
character_id: Uuid,
|
||||
ruleset: String,
|
||||
canonical_revision: u64,
|
||||
content_hash: String,
|
||||
total_size: usize,
|
||||
@@ -189,6 +190,7 @@ pub enum Response {
|
||||
/// appearance and vanity ids the Host holds for the account (kind -> ids).
|
||||
Claimed {
|
||||
character_id: Uuid,
|
||||
ruleset: String,
|
||||
sha256: String,
|
||||
payload: String,
|
||||
collections: BTreeMap<String, Vec<u32>>,
|
||||
@@ -273,11 +275,15 @@ pub fn decode_request(bytes: &[u8]) -> Result<Request> {
|
||||
return invalid("the client name is too long")
|
||||
}
|
||||
Request::TransferOffer {
|
||||
ruleset,
|
||||
content_hash,
|
||||
total_size,
|
||||
collections,
|
||||
..
|
||||
} => {
|
||||
if !matches!(ruleset.as_str(), "coa" | "wildcard" | "reborn") {
|
||||
return invalid("transfer ruleset must be coa, wildcard, or reborn");
|
||||
}
|
||||
if content_hash.len() != 64 || !content_hash.chars().all(|c| c.is_ascii_hexdigit()) {
|
||||
return invalid("transfer content hash must be 64 hex characters");
|
||||
}
|
||||
@@ -430,6 +436,7 @@ mod tests {
|
||||
let offer = Request::TransferOffer {
|
||||
transfer_id: tid,
|
||||
character_id: cid,
|
||||
ruleset: "coa".into(),
|
||||
canonical_revision: 5,
|
||||
content_hash: hash.clone(),
|
||||
total_size: 1024,
|
||||
@@ -442,6 +449,7 @@ mod tests {
|
||||
let bad_hash = Request::TransferOffer {
|
||||
transfer_id: tid,
|
||||
character_id: cid,
|
||||
ruleset: "coa".into(),
|
||||
canonical_revision: 5,
|
||||
content_hash: "too_short".into(),
|
||||
total_size: 1024,
|
||||
@@ -466,5 +474,21 @@ mod tests {
|
||||
};
|
||||
let resp_dec = decode_response(&encode_response(&resp)).unwrap();
|
||||
assert_eq!(resp, resp_dec);
|
||||
|
||||
// Control protocol v2 requires ruleset in TransferOffer; missing is rejected
|
||||
let missing_ruleset_json = serde_json::json!({
|
||||
"op": "transfer_offer",
|
||||
"transfer_id": tid,
|
||||
"character_id": cid,
|
||||
"canonical_revision": 5,
|
||||
"content_hash": hash,
|
||||
"total_size": 1024,
|
||||
"collections": {}
|
||||
});
|
||||
let encoded_missing = serde_json::to_vec(&missing_ruleset_json).unwrap();
|
||||
assert!(
|
||||
decode_request(&encoded_missing).is_err(),
|
||||
"missing ruleset in v2 must be rejected"
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -112,6 +112,10 @@ pub struct ProbeResponse {
|
||||
pub all_reachable: bool,
|
||||
}
|
||||
|
||||
/// Coordinator authentication is independent of the encrypted application protocol.
|
||||
/// Changing portable messages must not invalidate deployed v1 host/player proofs.
|
||||
pub const COORDINATOR_PROTOCOL_VERSION: u32 = 1;
|
||||
|
||||
pub fn challenge_nonce() -> String {
|
||||
let mut n = [0u8; 32];
|
||||
n[..16].copy_from_slice(Uuid::new_v4().as_bytes());
|
||||
@@ -122,7 +126,7 @@ pub fn challenge_nonce() -> String {
|
||||
fn host_input(realm: &RealmId, nonce: &str, ts: i64) -> Vec<u8> {
|
||||
format!(
|
||||
"coa-coord-host-v1\n{}\n{realm}\n{nonce}\n{ts}",
|
||||
crate::CONTROL_PROTOCOL_VERSION
|
||||
COORDINATOR_PROTOCOL_VERSION
|
||||
)
|
||||
.into_bytes()
|
||||
}
|
||||
@@ -130,7 +134,7 @@ fn host_input(realm: &RealmId, nonce: &str, ts: i64) -> Vec<u8> {
|
||||
fn player_input(player: &Uuid, public_key: &str, realm: &RealmId, nonce: &str, ts: i64) -> Vec<u8> {
|
||||
format!(
|
||||
"coa-coord-player-v1\n{}\n{}\n{public_key}\n{realm}\n{nonce}\n{ts}",
|
||||
crate::CONTROL_PROTOCOL_VERSION,
|
||||
COORDINATOR_PROTOCOL_VERSION,
|
||||
player.hyphenated()
|
||||
)
|
||||
.into_bytes()
|
||||
@@ -277,6 +281,14 @@ pub fn to_text(frame: &Frame) -> String {
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn deployed_coordinator_proofs_stay_v1_when_application_protocol_changes() {
|
||||
let realm = RealmId::new();
|
||||
let player = Uuid::now_v7();
|
||||
assert_eq!(host_input(&realm, "nonce", 42), format!("coa-coord-host-v1\n1\n{realm}\nnonce\n42").into_bytes());
|
||||
assert_eq!(player_input(&player, "public", &realm, "nonce", 42), format!("coa-coord-player-v1\n1\n{player}\npublic\n{realm}\nnonce\n42").into_bytes());
|
||||
}
|
||||
|
||||
fn key(n: u8) -> SigningKey {
|
||||
SigningKey::from_bytes(&[n; 32])
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ pub mod coord;
|
||||
pub mod noise;
|
||||
pub mod relay;
|
||||
|
||||
pub const CONTROL_PROTOCOL_VERSION: u32 = 1;
|
||||
pub const CONTROL_PROTOCOL_VERSION: u32 = 2;
|
||||
|
||||
#[derive(Debug, thiserror::Error, PartialEq, Eq)]
|
||||
pub enum ControlError {
|
||||
|
||||
Reference in new issue
Block a user