Skip to content

Commit f30e685

Browse files
committed
proposal for requiring signed certs for federation
1 parent 767af87 commit f30e685

File tree

1 file changed

+238
-0
lines changed

1 file changed

+238
-0
lines changed
Lines changed: 238 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,238 @@
1+
# MSC1711: X.509 certificate verification for federation connections
2+
3+
TLS connections for server-to-server communication currently rely on an
4+
approach borrowed from the [Perspectives
5+
project](https://web.archive.org/web/20170702024706/https://perspectives-project.org/)
6+
to provide certificate verification, rather than the more normal model using
7+
certificates signed by trusted Certificate Authorities. This document sets out
8+
the reasons that this has not been a success, and suggests that we should
9+
instead revert to the CA model.
10+
11+
## Background: the failure of the Perspectives approach
12+
13+
The Perspectives approach replaces the conventional heirarchy of trust provided
14+
by the Certificate Authority model with a large number of "notary" servers
15+
distributed around the world. The intention is that the notary servers
16+
regularly monitor remote servers and observe the certificates they present;
17+
when making a connection to a new site, a client can correlate the certificate
18+
it presents with that seen by the notary servers. In theory this makes it very
19+
hard to mount a Man-in-the-Middle (MitM) attack, because it would require
20+
intercepting traffic between the target server and a large number of the notary
21+
servers.
22+
23+
It is notable that the Perspectives project itself appears to have largely been
24+
abandoned: its website has largely been repurposed, the [Firefox
25+
extension](https://addons.mozilla.org/en-GB/firefox/addon/perspectives/) does
26+
not work with modern versions of Firefox, the [mailing
27+
list](https://groups.google.com/forum/#!forum/perspectives-dev) is inactive,
28+
and several of the (ten) published notary servers are no longer functional. The
29+
reasons for this are not entirely clear, though clearly it never gained
30+
widespread adoption.
31+
32+
When Matrix was originally designed in 2014, the Perspectives project was
33+
heavily active, and avoiding dependencies on the relatively centralised
34+
Certificate Authorities was attractive, in accordance with Matrix's design as a
35+
decentralised protocol. However, this has not been a success in practice.
36+
37+
Matrix was unable to make use of the existing notary servers (largely because
38+
we wanted to extend the protocol to include signing keys): the intention was
39+
that, as the Matrix ecosystem grew, public Matrix servers would act as notary
40+
servers. However, in practice we have ended up in a situation where almost <sup
41+
id="a1">[1](#f1)</sup> every Matrix homeserver either uses `matrix.org` as the
42+
sole notary, or does no certificate verification at all. Far from avoiding the
43+
centralisation of the Certificate Authorities, the entire protocol is therefore
44+
dependent on a single point of control at `matrix.org` - and because
45+
`matrix.org` only monitors from a single location, the protection against MitM
46+
attacks is weak.
47+
48+
It is also clear that the Perspectives approach is poorly-understood. It is a
49+
common error for homeservers to be deployed behind reverse-proxies which make
50+
the Perspectives-based approach unreliable. The CA model, for all its flaws, is
51+
at least commonly used, which makes it easier for administrators to deploy
52+
(secure) homeservers, and allows server implementations to leverage existing
53+
libraries.
54+
55+
## Proposal
56+
57+
We propose that Matrix homeservers should be required to present valid TLS
58+
certificates, signed by a known Certificate Authority, on their federation
59+
port.
60+
61+
In order to ease transition, we could continue to follow the current,
62+
perspectives-based approach for servers whose TLS certificates fail
63+
validation. However, this should be strictly time-limited (for three months,
64+
say), to give administrators time to switch to a signed certificate. The
65+
`matrix.org` team would proactively attempt to reach out to homeserver
66+
administrators who do not update their certificate.
67+
68+
Once the transition to CA-signed certificates is complete, the
69+
`tls_fingerprints` property of the
70+
[`/_matrix/key/v2`](https://matrix.org/docs/spec/server_server/unstable.html#retrieving-server-keys)
71+
endpoints would be redundant and we should consider removing it.
72+
73+
The process of determining which CAs are trusted to sign certificates would be
74+
implementation-specific, though it should almost certainly make use of existing
75+
operating-system support for maintaining such lists. It might also be useful if
76+
administrators could override this list, for the purpose of setting up a
77+
private federation using their own CA.
78+
79+
### Interaction with SRV records
80+
81+
With the use of `SRV` records, it is possible for the hostname of a homeserver
82+
to be quite different from the matrix domain it is hosting. For example, if
83+
there were an SRV record at `_matrix._tcp.matrix.org` which pointed to
84+
`server.example.com`, then any federation requests for `matrix.org` would be
85+
routed to `server.example.com`. The question arises as to which certificate
86+
`server.example.com` should present.
87+
88+
In short: the server should present a certificate for the matrix domain
89+
(`matrix.org` in the above example). This ensures that traffic cannot be
90+
intercepted by a MitM who can control the DNS response for the `SRV` record
91+
(perhaps via cache-poisoning or falsifying DNS responses).
92+
93+
This will be in line with the current
94+
[requirements](https://matrix.org/docs/spec/server_server/unstable.html#resolving-server-names)
95+
in the Federation API specification for the `Host`, and by implication, the TLS
96+
Server Name Indication <sup id="a2">[2](#f2)</sup>.
97+
98+
### Interaction with `.well-known` files
99+
100+
[MSC1708](https://github.com/matrix-org/matrix-doc/blob/rav/proposal/well-known-for-federation/proposals/1708-well-known-for-federation.md)
101+
proposes an alternative to SRV records, in the form of `.well-known` files. In
102+
this instance, a file at `https://matrix.org/.well-known/matrix/server` might
103+
direct requests to `server.example.com`.
104+
105+
In this case, `server.example.com` would be required to present a valid
106+
certificate for `server.example.com`.
107+
108+
Because the request for the `.well-known` file takes place over a validated TLS
109+
connection, this is not subject to the same DNS-based attacks as the SRV
110+
record, and this mechanism allows the owners of a domain to delegate
111+
responsibility for running their Matrix homeserver without having to hand over
112+
TLS keys for the whole domain.
113+
114+
### Extensions
115+
116+
HTTP-Based Public Key Pinning (HPKP) and
117+
[https://www.certificate-transparency.org](Certificate transparency) are
118+
both HTTP extensions which attempt to work around some of the deficiencies in
119+
the CA model, by making it more obvious if a CA has issued a certificate
120+
incorrectly.
121+
122+
HPKP has not been particularly successful, and is
123+
[deprecated]((https://developers.google.com/web/updates/2018/04/chrome-67-deps-rems#deprecate_http-based_public_key_pinning)
124+
in Google Chrome as of April 2018. Certificate transparency, however, is seeing
125+
widespread adoption from Certificate Authories and HTTP clients.
126+
127+
This proposal sees both technologies as optional techniques which could be
128+
provided by homeserver implementations. We encourage but do not mandate the use
129+
of Certificate Transparency.
130+
131+
### Related work
132+
133+
The Perspectives approach is also currently used for exchanging the keys that
134+
are used by homeservers to sign Matrix events and federation requests (the
135+
"signing keys"). Problems similar to those covered here also apply to that
136+
mechanism. A future MSC will propose improvements in that area.
137+
138+
## Tradeoffs
139+
140+
There are well-known problems with the CA model, including a number of
141+
widely-published incidents in which CAs have issued certificates
142+
incorrectly. It is therefore important to consider alternatives to the CA
143+
model.
144+
145+
### Improving support for the Perspectives model
146+
147+
In principle, we could double-down on the Perspectives approach, and make an effort
148+
to get servers other than `matrix.org` used as notary servers. However, there
149+
remain significant problems with such an approach:
150+
151+
* Perspectives remain complex to configure correctly. Ideally, administrators
152+
need to make conscious choices about which notaries to trust, which is hard
153+
to do, especially for newcomers to the ecosystem. (In practice, people use
154+
the out-of-the-box configuration, which is why everyone just uses
155+
`matrix.org` today).
156+
157+
* A *correct* implementation of Perspectives really needs to take into account
158+
more than the latest state seen by the notary servers: some level of history
159+
should be taken into account too.
160+
161+
Essentially, whilst we still believe the Perspectives approach has some merit,
162+
we believe it needs further research before it can be relied upon. We believe
163+
that the resources of the Matrix ecosystem are better spent elsewhere.
164+
165+
### DANE
166+
167+
DNS-Based Authentication of Named Entities (DANE) can be used as an alternative
168+
to the CA model. (It is arguably more appropriately used *together* with the CA
169+
model.)
170+
171+
It is not obvious to the author of this proposal that DANE provides any
172+
material advantages over the CA model. In particular it replaces the
173+
centralised trust of the CAs with the centralised trust of the DNS registries.
174+
175+
## Potential issues
176+
177+
Beyond the problems already discussed with the CA model, requiring signed
178+
certificates comes with a number of downsides.
179+
180+
### More difficult setup
181+
182+
Configuring a working, federating homeserver is a process fraught with
183+
pitfalls. This proposal adds the requirement to obtain a signed certificate to
184+
that process. Even with modern intiatives such as Let's Encrypt, this is
185+
another procedure requiring manual intervention across several moving parts<sup
186+
id="a3">[3](#f3)</sup>.
187+
188+
On the other hand: obtaining an SSL certificate should be a familiar process to
189+
anybody capable of hosting a production homeserver (indeed, they should
190+
probably already have one for the client port). This change also opens the
191+
possibility of putting the federation port behind a reverse-proxy without the
192+
need for additional configuration. Hopefully making the certificate usage more
193+
conventional will offset the overhead of setting up a certificate.
194+
195+
### Inferior support for IP literals
196+
197+
Whilst it is possible to obtain an SSL cert which is valid for a literal IP
198+
address, this typically requires purchase of a premium certificate; in
199+
particular, Let's Encrypt will not issue certificates for IP literals. This may
200+
make it impractical to run a homeserver which uses an IP literal, rather than a
201+
DNS name, as its `server_name`.
202+
203+
It has long been the view of the `matrix.org` administrators that IP literals
204+
are only really suitable for internal testing. Those who wish to use them for
205+
that purpose could either disable certificate checks inside their network, or
206+
use their own CA to issue certificates.
207+
208+
### Inferior support for hidden services (`.onion` addresses)
209+
210+
It is currently possible to correctly route traffic to a homeserver on a
211+
`.onion` domain, provided any remote servers which may need to reach that
212+
server are configured to route to such addresses via the Tor network. However,
213+
it can be difficult to get a certificate for a `.onion` domain (again, Let's
214+
Encrypt do not support them).
215+
216+
The reasons for requiring a signed certificate (or indeed, for using TLS at
217+
all) are weakened when traffic is routed via the Tor network. It may be
218+
reasonable to relax the requirement for a signed certificate for such traffic.
219+
220+
## Conclusion
221+
222+
We believe that requiring homservers to present an X.509 certificate signed by
223+
a recognised Certificate Authority will improve security, reduce
224+
centralisation, and eliminate some common deployment pitfalls.
225+
226+
<a id="f1"/>[1] It's *possible* to set up homeservers to use servers other than
227+
`matrix.org` as notaries, but we are not aware of any that are set up this
228+
way. [](#a1)
229+
230+
<a id="f2"/>[2] I've not been able to find an authoritative source on this, but
231+
most reverse-proxies will reject requests where the SNI and Host headers do not
232+
match. [](#a2)
233+
234+
<a id="f3"/>[3] Let's Encrypt will issue ACME challenges via port 80 or DNS
235+
(for the `http-01` or `dns-01` challenge types respectively). It is unlikely
236+
that a homeserver implementation would be able to control either port 80 or DNS
237+
responses, so we will be unable to automate a Let's Encrypt certificate
238+
request. [](#a3)

0 commit comments

Comments
 (0)