Skip to content

Commit

Permalink
Clarifications and alter the error handling of .well-known
Browse files Browse the repository at this point in the history
Note that MSC1831 changes the order, so the changes to MSC1708 might not make sense when combining all the proposals together. However, independently the change should make sense.
  • Loading branch information
turt2live committed Feb 1, 2019
1 parent 39b7141 commit 6421582
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 28 deletions.
4 changes: 2 additions & 2 deletions proposals/1708-well-known-for-federation.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ redirect loops). If the request does not return a 200, continue to step 4,
otherwise:

The response must be valid JSON which follows the structure documented
below. Otherwise, the request is aborted. It is NOT necessary for the response
to have a `Content-Type` of `application/json`.
below. Otherwise, continue to the next step in the discovery process. It is
NOT necessary for the response to have a `Content-Type` of `application/json`.

If the response is valid, the `m.server` property is parsed as
`<delegated_server_name>[:<delegated_port>]`, and processed as follows:
Expand Down
51 changes: 25 additions & 26 deletions specification/server_server_api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -109,14 +109,14 @@ The process overall is as follows:
1. If the hostname is an IP literal, then that IP address should be used,
together with the given port number, or 8448 if no port is given. The
target server must present a valid certificate for the IP address.
Requests must be made with a ``Host`` header containing the IP address,
without port.
The ``Host`` header in the request should be set to the server name,
including the port if the server name included one.

2. If the hostname is not an IP literal, and the server name includes an explicit port,
resolve the IP address using AAAA or A records. Requests are made to
the resolved IP address and given port with a ``Host`` header of the
original hostname (with port). The target server must present a valid
certificate for the hostname.
2. If the hostname is not an IP literal, and the server name includes an
explicit port, resolve the IP address using AAAA or A records. Requests
are made to the resolved IP address and given port with a ``Host`` header
of the original server name (with port). The target server must present a
valid certificate for the hostname.

3. If the hostname is not an IP literal, a regular HTTPS request is made
to ``https://<hostname>/.well-known/matrix/server``, expecting the
Expand All @@ -130,39 +130,38 @@ The process overall is as follows:
recommended. Errors are recommended to be cached for up to an hour,
and servers are encouraged to exponentially back off for repeated
failures. The schema of the ``/.well-known`` request is later in this
section. If the response is invalid (bad JSON, missing properties, etc),
attempts to connect to the target server are aborted - no connections
should be attempted. If the response is valid, the ``m.server`` property
is parsed as ``<delegated_server_name>[:<delegated_port>]`` and processed
as follows:
section. If the response is invalid (bad JSON, missing properties, non-200
response, etc), skip to step 4. If the response is valid, the ``m.server``
property is parsed as ``<delegated_hostname>[:<delegated_port>]`` and
processed as follows:

* If ``<delegated_server_name>`` is an IP literal, then that IP address
* If ``<delegated_hostname>`` is an IP literal, then that IP address
should be used together with the ``<delegated_port>`` or 8448 if no
port is provided. The target server must present a valid TLS certificate
for the IP address. Requests must be made with a ``Host`` header containing
the IP address, with port.
the IP address, including the port if one was provided.

* If ``<delegated_server_name>`` is not an IP literal, and ``<delegated_port>``
* If ``<delegated_hostname>`` is not an IP literal, and ``<delegated_port>``
is present, an IP address is disovered by looking up an AAAA or A
record for ``<delegated_server_name>``. The resulting IP address is
used, alongside the ``<delegated_port>``, to make requests with a
``Host`` header of ``<delegated_server_name>:<delegated_port>``. The
target server must present a valid certificate for ``<delegated_server_name>``.
record for ``<delegated_hostname>``. The resulting IP address is
used, alongside the ``<delegated_port>``. Requests must be made with a
``Host`` header of ``<delegated_hostname>:<delegated_port>``. The
target server must present a valid certificate for ``<delegated_hostname>``.

* If ``<delegated_server_name>`` is not an IP literal and no
* If ``<delegated_hostname>`` is not an IP literal and no
``<delegated_port>`` is present, an SRV record is looked up for
``_matrix._tcp.<delegated_server_name>``. This may result in another
``_matrix._tcp.<delegated_hostname>``. This may result in another
hostname (to be resolved using AAAA or A records) and port. Requests
should be made to the resolved IP address and port with a ``Host``
header containing the ``<delegated_server_name>``. The target server
must present a valid certificate for ``<delegated_server_name>``.
header containing the ``<delegated_hostname>``. The target server
must present a valid certificate for ``<delegated_hostname>``.

* If no SRV record is found, an IP address is resolved using AAAA
or A records. Requests are then made to the resolve IP address
and a port of 8448, using a ``Host`` header of ``<delegated_server_name>``.
The target server must present a valid certificate for ``<delegated_server_name>``.
and a port of 8448, using a ``Host`` header of ``<delegated_hostname>``.
The target server must present a valid certificate for ``<delegated_hostname>``.

4. If the `/.well-known` request did not result in a 200 response, a server
4. If the `/.well-known` request resulted in an error response, a server
is found by resolving an SRV record for ``_matrix._tcp.<hostname>``. This
may result in a hostname (to be resolved using AAAA or A records) and
port. Requests are made to the resolved IP address and port, using 8448
Expand Down

0 comments on commit 6421582

Please sign in to comment.