sirpent-team / sirpent-rust

A multiplayer snake server to test the bounds of Rust Futures.
https://sirpent-team.github.io/sirpent-rust/
Apache License 2.0
7 stars 0 forks source link

Authenticate players #9

Closed 46bit closed 7 years ago

46bit commented 8 years ago

As of https://github.com/sirpent-team/sirpent-rust/commit/684f32fa923cf2399822453edc912a903c604562, Player.secret is now Command::Hello.secret:

pub enum Command {
    […]
    // The client should decide whether it is compatible with this protocol and server setup.
    // If the client wishes to continue it must send a HELLO message.
    #[serde(rename = "HELLO")]
    Hello {
        player: Player,
        #[serde(skip_serializing_if = "Option::is_none")]
        secret: Option<String>,
    },
    […]
}

Players can provide a secret string, that (once set) must be provided with each connection of a player of that name.

This approach has major caveats.

As such I feel like this nice-and-simple authentication model may have more downsides than previously recognised by myself.

Taneb commented 8 years ago

The way I was imagining it is we don't decide which player is which by name, but by name/secret pair.

So we could have SimpleAI/hunter2 and SimpleAI/password, for example.

Thoughts?

qlkzy commented 8 years ago

Suggestions:

"The genuine player could not use that player name": given shared code, wanting to play multiple copies of an AI against each other, etc., I'd imagine that name collisions need to be handled more broadly. I'd suggest a mechanism whereby the server can override names. So, if SimpleAI is already connected, another player trying to connect as SimpleAI gets SimpleAI (1) or something. Or maybe embed the thesaurus entry for "impostor", and use that before falling back to numbers. In the case of names which can be authenticated, you'd automatically be overridden unless you provided a secret.

"A disclosed secret can never be changed": Exactly how many of these are you expecting to run? There will probably be a fairly small set of players, of which even fewer will encounter this issue. Why not just fix it manually if it happens?

46bit commented 8 years ago

@qlkzy's suggestions have a lot of merit. Here's my plan: do something like what he suggests, and if anyone wants to set a secret value they can get one set out-of-band.

46bit commented 8 years ago

Player names are right-padded with _ until unique.