Skip to content

Proposal: new client protocol #5406

Closed
Closed

Description

@VeXocide

Adding user accounts per #4519 will require us to change the client protocol to what's proposed below. The authentication aspect is based on https://tools.ietf.org/html/rfc5802#section-5.

  • C → S: the magic version V0_5 whose value has yet to be determined in a bike shed, I propose 0xd27951cc.
  • C → S: a JSON object terminated by a null byte. This JSON object MAY contain a member "authentication" describing the authentication mechanism used, we currently support "SCRAM-SHA-256". If this is used it MUST also contain a member "user" containing the username, and a "nonce" containing a nonce per the above RFC.
  • S → C: the server responds with a JSON object terminated by a null byte which MUST contain a member "version" containing the server version encoded as a string. Upon failure the object MUST contain the member "success" set to the value false, and MAY contain a member "error" containing a description of the error. Upon success the object MUST contain the member "success" set to true. If authentication is enabled the object MUST also contain "nonce" set to the extended nonce, "salt" containing the salt, and "iterations" set to the iteration count represented as a number.

The connection should be terminated if this was not successful. Otherwise, if authentication is not enabled this is the end of the exchange and the connection is now ready for use, else it is continued as follows.

  • C → S: a JSON object terminated by a null byte which MUST contain the members "nonce" with the above nonce, and "proof", a base64 encoded ClientProof.
  • S → C: a JSON object terminated by a null byte which MUST contain a member "success" indicating whether this was success with a boolean. If not successful it MAY contain a member "error" containing a description of the error. However, if successful it MUST contain a member "signature" containing the ServerSignature, again as described in the RFC.

Again, the connection should be terminated if this was not successful, otherwise the connection is ready for use assuming the signature is valid.

Activity

  1. added this to the 2.3 milestone on Feb 17, 2016
  2. self-assigned this
    on Feb 17, 2016
  3. mlucy commented on Feb 17, 2016

    @mlucy
    Member

    This looks good to me. The only thing that comes to mind is that maybe the client should also send a version in the second step so that we don't have to bump the magic number every time we want to make a backwards-incompatible change. (I think the magic number should only change if the wire format changes, not if e.g. the fields in the JSON objects change.)

  4. danielmewes commented on Feb 18, 2016

    @danielmewes
    Member

    Oh right. We were talking about the client version the other day and didn't know what it should be, but indeed it should send something akin to the different magic numbers that we currently have I think.
    Maybe just "{protocol_version: }", where the integer would be 1 for now, and could be incremented in the future if we ever change the handshake again?

    One more remark: "and MAY contain a member "error" containing a description of the error. " / "If not successful it MAY contain a member "error""
    I think both of these should be "MUST contain". The error being optional just adds an additional case that all clients will need to handle.

  5. VeXocide commented on Feb 18, 2016

    @VeXocide
    MemberAuthor

    I'm in favour of requiring the member "error" in failure cases, it simplifies the protocol marginally and an error message makes it easier to debug what's failing.

    Instead of the version I'd like to propose an optional member "capabilities" in the first message from the client to the server containing an array of strings with capabilities that the client supports. We may need to do this server to client as well.

  6. mlucy commented on Feb 18, 2016

    @mlucy
    Member

    I think a protocol version would be better than capabilities.

    Capabilities make sense when you have an extremely complicated ecosystem with multiple providers that have wildly different feature sets (e.g. C++ compilers). They also make sense when it's reasonable for a client to only support a subset of functionality. Neither of those are really true here.

    In this case I think they'd add extra complexity for not much gain, and everyone who wrote a client would have to think about what their capabilities are, instead of just coding exactly to a protocol spec and specifying that they follow that protocol.

    I suppose now that we offer encryption it mightmake sense to let clients specify what encryption algorithms they support or something, so it might make sense to have a capabilities array for something like that, but if we do that I think it should exist in addition to a protocol version.

  7. mlucy commented on Feb 18, 2016

    @mlucy
    Member

    @VeXocide and I talked about this a little bit offline, and he mentioned another thing, which is that it's probably a good idea to have the server report what protocol versions it supports before the client requests a particular protocol version, because that allows you to write clients that can connect to older versions of the server.

    We decided that it's probably a good idea to require the client to specify a protocol version in the first JSON object it sends to the server. He convinced me that we probably need a capabilities array eventually for things like supported encryption/compression options, whether or not a client can print its own backtraces, etc., but it seems better to leave it out of the first version since the server wouldn't actually do anything differently based on what's in the array right now. Later when we add support for things like that, we can bump the protocol version field and say that that new protocol version requires a capabilities array.

    (We also talked a bit about the idea of leaving off the protocol version and adding it later, with the convention that an unspecified protocol version is protocol v0, but that seems like a bad idea because you can't distinguish between a third party client that forgot to specify a protocol version and one written to the spec of the very first protocol, which might make debugging confusing for people.)

    (We also talked a bit about why we would have both a protocol version and a magic number: in my mind the magic number should be bumped when the gross format of the exchange changes. So large changes like the current one where we go from sending plaintext back and forth to sending JSON objects would involve bumping the magic number. I think that if the semantics of the JSON objects we're sending back and forth changes, that shouldn't require bumping the magic number and you should bump the protocol version instead.)

  8. mlucy commented on Feb 18, 2016

    @mlucy
    Member

    So the current proposal is:

    C -> S

    0xd27951cc

    C <- S

    {
      server_version: "2.3.2",
      min_protocol_version: 0,
      max_protocol_version: 5,
      # Maybe other stuff like available encryption options later.
    }
    

    C -> S

    {
      protocol_version: 4,
      authentication: "SCRAM-SHA-256",
      "user": "mlucy",
      "nonce": XXX,
      # Maybe a capabilities array in a future protocol version.
    }
    

    C <- S

    {
      "success": false,
      "error": "GTFO"
    }
    

    or

    {
      "success": true,
      "nonce": XXX,
      "salt": XXX,
      "iterations": n,
    }
    

    C -> S

    {
      "nonce": XXX,
      "proof": XXX
    }
    

    C <- S

    {
      "success": "false",
      "error: "GTFO",
    }
    

    or

    {
      "success": "true",
      "signature": XXX
    }
    

    C -> S

    Queries and stuff.

  9. danielmewes commented on Feb 18, 2016

    @danielmewes
    Member

    Could we merge this message:

    {
      server_version: "2.3.2",
      min_protocol_version: 0,
      max_protocol_version: 5,
      # Maybe other stuff like available encryption options later.
    }
    

    into this one:

    {
      "success": false,
      "error": "GTFO"
    }
    

    ...to reduce the latency for connection setup a bit? The client would have to send the authentication data before it has heard from the server about the supported protocol versions, but my impression is that that wouldn't be an issue.
    The exception I can think of is if we later want to add additional authentication protocols and the client needs to automatically pick which one to use based on the server's supported variants. That might not be necessary though. We could have the authentication method configurable by the user instead, and if the client tries using an unsupported one, the server will reject the connection in the next step. I think that's probably what we would want anyway, since we typically don't want to silently fall back to a less secure method anyway.

  10. VeXocide commented on Feb 18, 2016

    @VeXocide
    MemberAuthor

    We'll definitely want to add additional authentication protocols like x.509 later. Another upside of this setup is that monitoring tools can simply send the magic version and have the server report that it's still good.

  11. mlucy commented on Feb 18, 2016

    @mlucy
    Member

    Merging the messages seems bad. You want the server to say what protocols it speaks before the client starts talking to it, I think.

    One way we could change the protocol to allow lower latency is we could say that if the client asks for a protocol the server doesn't support, the server responds with an error but keeps listening for another protocol request. (So instead of erring out it goes back to waiting for step 3.) Then the client could send the magic number and optimistically send the protocol request, and if the server doesn't support that protocol then the client can send the "correct" protocol request after receiving the server version and swallow the first error.

  12. deontologician commented on Feb 18, 2016

    @deontologician
    Contributor

    Why can't the client send this stuff together?

    0xd27951cc
    {
      protocol_version: 4,
      authentication: "SCRAM-SHA-256",
      "user": "mlucy",
      "nonce": XXX,
      # Maybe a capabilities array in a future protocol version.
    }
    

    It seems like an unnecessary round trip. If the server doesn't support the protocol version or authentication method it can just error as its first response.

  13. VeXocide commented on Feb 18, 2016

    @VeXocide
    MemberAuthor

    @deontologician -- we want to have the client select the highest protocol version that both the client and server support, allowing a client to talk to an older server.

  14. deontologician commented on Feb 18, 2016

    @deontologician
    Contributor

    Ah, ok I missed that clients would support more than one protocol. Sorry

  15. danielmewes commented on Feb 18, 2016

    @danielmewes
    Member

    @mlucy I think allowing for the extra roundtrip in case the protocol isn't supported by the server might be better. It makes the protocol slightly more complex, but removes a round trip. I've seen lots of benchmarks and simple applications where a new connection is opened for each request, so I think connection setup latency does matter.

    In practice, most users are going to run servers that match the client version and hence the fallback case where the authentication protocol isn't supported by the server is going to be very rare.

  16. 3 remaining items

  17. danielmewes commented on Feb 19, 2016

    @danielmewes
    Member
                                                                                      We'll leave that for later. But the new handshake will at least make it easier to add the different framing later and allow clients to communicate which one they want to use. 
    
  18. VeXocide commented on Feb 23, 2016

    @VeXocide
    MemberAuthor

    I guess it's time to bike shed about the V0_5 constant, Protobuf uses a signed integer thus it complains with Integer out of range. on my proposed constant.

  19. VeXocide commented on Feb 23, 2016

    @VeXocide
    MemberAuthor

    We're going with 0x34c2bdc3.

  20. deontologician commented on Feb 23, 2016

    @deontologician
    Contributor

    No way, 0x34c2bdd5 is way better.

  21. mglukhovsky commented on Feb 23, 2016

    @mglukhovsky
    Member

    @deontologician: taking bike-shedding to a whole new level. 🚲

  22. danielmewes commented on Feb 23, 2016

    @danielmewes
    Member

    If your sequence is of general interest, please submit it using the form provided and it will (probably) be added to the OEIS!

    Sounds like a plan.

  23. VeXocide commented on Feb 24, 2016

    @VeXocide
    MemberAuthor

    Note to self, vexocide/5406 is branched off of vexocide/4519.

  24. danielmewes commented on Apr 4, 2016

    @danielmewes
    Member

    It's in next.

  25. added a commit that references this issue on Apr 5, 2016
  26. added a commit that references this issue on Aug 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions