Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve the server key exchange portion of the s2s specification #1423

Merged
merged 9 commits into from Aug 1, 2018

Conversation

turt2live
Copy link
Member

@turt2live turt2live commented Jul 16, 2018

Rendered: See "docs" commit status.

Most of the text has been shuffled into the swagger definitions to bring it closer to where it matters.

This also attempts to clarify what is out in the wild. Most importantly, the first version of the key exchange is outright removed from the specification. Other research points/questions are:

The examples and descriptions were also improved as part of this commit.

@turt2live turt2live added the blocked Something needs to be done before action can be taken on this PR/issue. label Jul 16, 2018
@turt2live turt2live force-pushed the travis/s2s/keys branch 2 times, most recently from debc062 to 5fb786b Compare July 18, 2018 16:51
Most of the text has been shuffled into the swagger definitions to bring it closer to where it matters.

This also attempts to clarify what is out in the wild. Most importantly, the first version of the key exchange is outright removed from the specification. Other research points/questions are:

* What is a "Key ID"?
  * https://github.com/matrix-org/synapse/blob/1241156c82644d5609f45659607a356af5d8fe08/synapse/rest/key/v2/local_key_resource.py#L81-L83
  * https://github.com/matrix-org/synapse/blob/1241156c82644d5609f45659607a356af5d8fe08/synapse/rest/key/v2/local_key_resource.py#L88-L91
* Returning a cached response if the server throws a 400, 500, or otherwise not-offline status code
  * https://github.com/matrix-org/synapse/blob/1241156c82644d5609f45659607a356af5d8fe08/synapse/rest/key/v2/remote_key_resource.py#L227-L229
* `minimum_valid_until_ts` default
  * This branch of the ladder: https://github.com/matrix-org/synapse/blob/1241156c82644d5609f45659607a356af5d8fe08/synapse/rest/key/v2/remote_key_resource.py#L192
* Returning empty arrays when querying offline/no servers
  * Queried by hand against matrix.org as a notary server with a fake domain name to query
* Returning all keys even when querying for specific keys
  * Queried by hand using matrix.org as a notary server against a server publishing multiple keys.

The examples and descriptions were also improved as part of this commit.
@turt2live turt2live requested a review from a team July 26, 2018 14:47
@turt2live turt2live removed the blocked Something needs to be done before action can be taken on this PR/issue. label Jul 26, 2018
required: true
example: "Base+64+Encoded+Signature+Verification+Key"
example: "VGhpcyBzaG91bGQgYmUgYSByZWFsIGVkMjU1MTkgcGF5bG9hZA=="
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if it's unpadded base64... why is this padded?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(this is a theme throughout the examples)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because I did the examples before the docs in this case. Will fix.

}
}
properties:
expired_ts:
type: integer
format: int64
description: The expiration time.
description: POSIX timestamp for when this key expired.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

normally we explicitly say it's in ms.

}
}
properties:
expired_ts:
type: integer
format: int64
description: The expiration time.
description: POSIX timestamp for when this key expired.
required: true
example: 922834800000
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

funny-looking timestamp.

Copy link
Member Author

@turt2live turt2live Jul 26, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's from 1999. Considering this is the "expired" parameter, it seems fine? (it's also ported from ancient docs)

Edit: will make more modern.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, the problem is that I expect timestamps to start with 14 or 15 or so; when I see one starting with a 9 I wonder if it is actually a posix timestamp.

description: |-
Query for keys from multiple servers in a batch format. The receiving (notary)
server must sign the keys returned by the queried servers.
operationId: postQueryKeys
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure this is a better operationId

description: |-
Gets the homeserver's published TLS fingerprints and signing keys.
The homeserver may have any number of active keys and may have a
number of old keys. Homeservers SHOULD return a single JSON object
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure they SHOULD... tbh I think it's a bug in synapse that they do.

maybe we should deprecate the keyId parameter?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deprecating seems best, given both synapse and dendrite ignore it.

operationId: getServerKey
parameters:
- in: path
name: keyId
type: string
description: Key ID
description: |-
The key ID to look up. If omitted or empty, all server keys are
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this conflicts with the text in the description,

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How so? The argument is optional, so the last bit here is to reinforce what should happen when the parameter isn't provided.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well, it's incorrect by omission. Apparently it should be ignored?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose. Will update alongside deprecation.


Each homeserver publishes its public keys under ``/_matrix/key/v2/server/``.
Homeservers query for keys by either getting ``/_matrix/key/v2/server/``
Each homeserver publishes its public keys under ``/_matrix/key/v2/server/{keyId}`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing `

@@ -87,10 +97,12 @@ properties:
properties:
sha256:
type: string
description: The encoded fingerprint.
example: Base+64+Encoded+SHA-256-Fingerprint
description: The `Unpadded Base64`_ encoded fingerprint
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

given we now say this is unpadded base64, we can probably remove it from the description on tls_fingerprints.

description: |-
Public keys of the homeserver for verifying digital signatures.

The object's key is the algorithm and version combined (``ed25519`` being the
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should have some words here about what constitutes a valid version. I don't know if you want to grasp that particular nettle right now though.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like synapse uses [a-zA-Z0-9_] - is it fair to say that it must match that regex?

Source: https://github.com/matrix-org/synapse/blob/f7b133fc267f92734b88000f0f0450b3118ca713/synapse/config/key.py#L159

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, that sounds good. let's go with it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@turt2live
Copy link
Member Author

@richvdh should be updated. Please take another look.

@turt2live turt2live assigned richvdh and unassigned turt2live Jul 27, 2018
@turt2live turt2live mentioned this pull request Jul 31, 2018
35 tasks
Copy link
Member

@richvdh richvdh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks amazing. sorry for forgetting to review it.

@richvdh richvdh assigned turt2live and unassigned richvdh Aug 1, 2018
@turt2live
Copy link
Member Author

\o/ one down, half a billion to go :)

Thanks for taking a look

@turt2live turt2live merged commit b96ee3e into matrix-org:master Aug 1, 2018
@turt2live turt2live deleted the travis/s2s/keys branch August 1, 2018 13:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants