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

BREAKING CHANGE: fix: pin certificates to hosts #40

Merged
merged 2 commits into from Sep 20, 2023
Merged

Conversation

bassosimone
Copy link
Member

@bassosimone bassosimone commented Sep 20, 2023

Before writing this diff, netem automatically generated the correct cert on the fly based on the given SNI or local addr.

While this behavior has been okay so far, it turns out there is a set of tests we cannot write because of it.

Namely, we cannot check whether we can connect to a given host using another SNI, because netem would generate a certificate for the provided SNI, which is not how the internet works.

If I'm connecting to www.example.com with www.google.com as the SNI, in the internet the server would return a valid certificate for www.example.com, rather than for www.google.com.

This diff rectifies netem's behavior by forcing the programmer to pin the certificate to a set of names and addresses when creating the server that needs such a certificate.

Accordingly, we can stop using a forked google/martian/v3/mitm implementation and we can just roll out our own, which is still based on martian (fear not, not reinventing the wheel here!) but allows us to create a certificate with specific addresses and domain names pinned to it.

While there, notice that there was code we were not using, such as stdlib.go, and that we also don't need in ooni/probe-cli, so we can definitely kill this piece of code.

While there, don't be shy and make a bunch of constructors of the Must kind. They will panic on failure, which is fine in the netem context, because this library is meant to only be used when writing tests.

Part of ooni/probe#2531, because the tests I was trying to write belong to such an issue.

Before writing this diff, netem automatically generated the correct
cert on the fly based on the given SNI or local addr.

While this behavior has been okay so far, it turns out there is a
set of tests we cannot write because of it.

Namely, we cannot check whether we can connect to a given host
using another SNI, because netem would generate a certificate
for the provided SNI, which is not how the internet works.

If I'm connecting to www.example.com with www.google.com as the
SNI, in the internet the server would return a valid certificate
for www.example.com, rather than for www.google.com.

This diff rectifies netem's behavior by forcing the user to pin
the certificate to a set of names and addresses when creating the
server that needs such a certificate.

Accordingly, we can stop using a forked google/martian/v3/mitm
implementation and we can just roll out our own, which is still
based on martian (feat not, not reinventing the wheel here)
but allows us to create a certificate with specific addresses
and domain names pinned to it.

While there, notice that there was code we were not using,
such as stdlib.go, and that we also don't need in ooni/probe-cli,
so we can definitely kill this piece of code.

Part of ooni/probe#2531, because the
tests I was trying to write belong to such an issue.
@bassosimone bassosimone merged commit 45a7aa9 into main Sep 20, 2023
4 checks passed
@bassosimone bassosimone deleted the issue/2531 branch September 20, 2023 18:33
bassosimone added a commit to ooni/probe-cli that referenced this pull request Sep 20, 2023
As explained in ooni/netem#40, netem used to
generate on the fly certificates for any host.

I then discovered that this behavior is not desirable because the
internet doesn't work like that. Specifically, TLS dialing to, say,
www.example.com with www.google.com as the SNI must return a TLS
error (`ssl_invalid_hostname` in OONI).

This wrong behavior of netem has become a bottleneck for writing
new tests for the beacons functionality, so it must change.

I have already changed netem and this diff updates the probe-cli
tree to use a netem version that behaves more correctly.

While there, I noticed that sniblocking tests were wrong because of
the previous netem behavior and asserted that the control should
return a nil failure, while it should have been `ssl_invalid_hostname`.

Part of ooni/probe#2531
bassosimone added a commit to ooni/probe-cli that referenced this pull request Sep 20, 2023
As explained in ooni/netem#40, netem used to
generate on the fly certificates for any host.

I then discovered that this behavior is not desirable because the
internet doesn't work like that. Specifically, TLS dialing to, say,
www.example.com with www.google.com as the SNI must return a TLS error
(`ssl_invalid_hostname` in OONI).

This wrong behavior of netem has become a bottleneck for writing new
tests for the beacons functionality, so it must change.

I have already changed netem and this diff updates the probe-cli tree to
use a netem version that behaves more correctly.

While there, I noticed that sniblocking tests were wrong because of the
previous netem behavior and asserted that the control should return a
nil failure, while it should have been `ssl_invalid_hostname`.

Part of ooni/probe#2531
Murphy-OrangeMud pushed a commit to Murphy-OrangeMud/probe-cli that referenced this pull request Feb 13, 2024
As explained in ooni/netem#40, netem used to
generate on the fly certificates for any host.

I then discovered that this behavior is not desirable because the
internet doesn't work like that. Specifically, TLS dialing to, say,
www.example.com with www.google.com as the SNI must return a TLS error
(`ssl_invalid_hostname` in OONI).

This wrong behavior of netem has become a bottleneck for writing new
tests for the beacons functionality, so it must change.

I have already changed netem and this diff updates the probe-cli tree to
use a netem version that behaves more correctly.

While there, I noticed that sniblocking tests were wrong because of the
previous netem behavior and asserted that the control should return a
nil failure, while it should have been `ssl_invalid_hostname`.

Part of ooni/probe#2531
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant