Commit Graph

182 Commits

Author SHA1 Message Date
Simone Basso
7a0a156aec
Spring cleanup: remove unused/unneded code (#761)
* cleanup: remove the archival package

See https://github.com/ooni/probe/issues/2116

* cleanup: remove websteps fall 2021 edition

See https://github.com/ooni/probe/issues/2116

* cleanup: remove JavaScript based testing framework

https://github.com/ooni/probe/issues/2116

* cleanup: remove the unused ooapi package

See https://github.com/ooni/probe/issues/2116
2022-05-25 13:21:39 +02:00
Simone Basso
2d721baa91
cleanup: merge httpheader and httpfailure into model (#758)
These two small packages could easily be merged into the model
package, since they're clearly model-like packages.

Part of https://github.com/ooni/probe/issues/2115
2022-05-25 09:54:50 +02:00
Simone Basso
d922bd9afc
cleanup: mark more integration tests as !short mode (#755)
The objective is to make PR checks run much faster.

See https://github.com/ooni/probe/issues/2113 for context.

Regarding netxlite's tests:

Checking for every commit on master or on a release branch is
good enough and makes pull requests faster than one minute since
netxlite for windows is now 1m slower than coverage.

We're losing some coverage but coverage from integration tests
is not so good anyway, so I'm not super sad about this loss.
2022-05-24 21:01:15 +02:00
Simone Basso
6924d1ad81
refactor: only use shaping dialer for ndt7 and dash (#754)
See https://github.com/ooni/probe/issues/2112 for context.

While there, run `go fix -fix buildtag ./...`
2022-05-24 18:23:42 +02:00
Simone Basso
ebc00a95fe
refactor: use ooni/oocrypto instead of ooni/go (#751)
Rather than building for Android using ooni/go, we're now using
ooni/oocryto as the TLS dependency. Such a repository only forks
crypto/tls and some minor crypto packages and includes the
same set of patches that we have been using in ooni/go.

This new strategy should be better than the previous one in
terms of building for Android, because we can use the vanilla
go1.18.2 build. It also seems that it is easier to track and
merge from upstream with ooni/oocrypto than it is with ooni/go.

Should this assessment be wrong, we can revert back to the
previous scenario where we used ooni/go.

See https://github.com/ooni/probe/issues/2106 for extra context.
2022-05-22 19:53:37 +02:00
Simone Basso
1a7234e0f1
chore: run go generate ./... (#743)
See https://github.com/ooni/probe/issues/2100
2022-05-19 20:44:39 +02:00
Simone Basso
7c45f7b88c
fix(netxlite): ensure we only accept DNS responses (#735)
Previously, the DNS decoder did not check whether it was parsing
a DNS query or a DNS response, which was wrong.

As a side note, it seems I am using "reply" in the codebase instead
of "response". The latter seems correct DNS terminology.

This diff has been extracted from 9249d14f80

See https://github.com/ooni/probe/issues/2096.
2022-05-16 11:17:30 +02:00
Simone Basso
ce052b665e
feat(netxlite): implements NS queries (#734)
This diff has been extracted from eb0bf38957.

See https://github.com/ooni/probe/issues/2096.

While there, skip the broken tests caused by issue
https://github.com/ooni/probe/issues/2098.
2022-05-16 10:46:53 +02:00
Simone Basso
c1b06a2d09
fix(netxlite): prefer composition over embedding (#733)
This diff has been extracted and adapted from 8848c8c516

The reason to prefer composition over embedding is that we want the
build to break if we add new methods to interfaces we define. If the build
does not break, we may forget about wrapping methods we should
actually be wrapping. I noticed this issue inside netxlite when I was working
on websteps-illustrated and I added support for NS and PTR queries.

See https://github.com/ooni/probe/issues/2096

While there, perform comprehensive netxlite code review
and apply minor changes and improve the docs.
2022-05-15 19:25:27 +02:00
Simone Basso
9d2301cae2
fix(netxlite): reject replies with wrong queryID (#732)
This diff has been extracted from c2f7ccab0e

See https://github.com/ooni/probe/issues/2096

While there, export DecodeReply to decode a raw reply without
interpreting the Rcode or parsing the results, which seems a
nice extra feature to have to more flexibly parse DNS replies
in other parts of the codebase.
2022-05-14 19:38:46 +02:00
Simone Basso
f5b801ae95
refactor(netxlite): add Transport suffix to DNS transports (#731)
This diff has been extracted from c2f7ccab0e

See https://github.com/ooni/probe/issues/2096
2022-05-14 17:38:31 +02:00
Simone Basso
6c388d2c61
netxlite: factor common code for parsing UDPAddr (#730)
This diff has been extracted from c2f7ccab0e

See https://github.com/ooni/probe/issues/2096
2022-05-14 17:15:08 +02:00
Simone Basso
2238908afe
cleanup(quic): wait for handshake completion in netxlite (#729)
See https://github.com/ooni/probe/issues/2097
2022-05-14 16:32:32 +02:00
Simone Basso
5904e6988d
fix(netxlite): map servfail error (#728)
This error occurred for example when querying kazemjalali.com
in websteps measurements run from Iran.

This error is relatively uncommon, but it still makes sense to
create a specific mapping rule for it.

Originally: 4269e82fbd

See https://github.com/ooni/probe/issues/2096
2022-05-13 19:25:22 +02:00
Simone Basso
b872dd0e1e
fix(netxlite): HTTPSSvc: better no_answer checks (#727)
I've seen some measurements returning some IP addresses for HTTPSSvc
queries but not returning any ALPN value.

For example:

```
% d4
decoding DNS round trip 0:

;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 57768
;; flags: rd; QUERY: 1, ANSWER: 0, AUTHORITY: 0, ADDITIONAL: 0
;; QUESTION SECTION:
;psiphon.ca.                    IN      HTTPS

;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 57768
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0
;; QUESTION SECTION:
;psiphon.ca.                    IN      HTTPS
;; ANSWER SECTION:
psiphon.ca.             121     IN      A       31.13.85.53
```

Now, the response is clearly bogus. At the time of this writing that
IP address belongs to Facebook. This measurement has been collected in
China, so it's expected for the GFW to behave like this.

Yet, I don't feel like it's accurate to report this measurement as a
"no answer" response. Rather, this response is a valid one containing
a clearly invalid IP address and should be flagged as such.

Originally: 57a023bcf4

See https://github.com/ooni/probe/issues/2096
2022-05-13 19:00:51 +02:00
Simone Basso
192dfd49b4
fix(netxlite): consolidate IPv4/IPv6 checking code (#726)
Originally 966e7f7cdd

See https://github.com/ooni/probe/issues/2096
2022-05-13 18:49:18 +02:00
Simone Basso
e126e73de7
fix(netxlite): LookupHTTPS: short circuit IP addr (#725)
This diff fixes the short-circuit-IP-addr resolver to
correctly handle IP addrs during LookupHTTPS.

The original diff was: 2b51d144bf

See https://github.com/ooni/probe/issues/2096

While there, add unit tests for IPv6.
2022-05-13 18:26:15 +02:00
Simone Basso
ec0561ea8c
feat(netxlite): implement parallel resolver (#724)
This diff imports the parallel resolver from websteps winter 2022
edition, which was originally implemented here:

55231d73cd

See https://github.com/ooni/probe/issues/2096
2022-05-13 17:36:58 +02:00
Simone Basso
0efd4ff130
chore: import improved bogons handling code (#723)
This diff imports improved bogons handling code from websteps
winter 2022 edition's repository.

See https://github.com/ooni/probe/issues/2095

See a65f3e8579/internal/netxlite/bogon.go
2022-05-13 15:32:47 +02:00
DecFox
5d2afaade4
cli: upgrade to lucas-clemente/quic-go@v0.27.0 (#715)
* quic-go upgrade: replaced Session/EarlySession with Connection/EarlyConnection

* quic-go upgrade: added context to RoundTripper.Dial

* quic-go upgrade: made corresponding changes to tutorial

* quic-go upgrade: changed sess variable instances to qconn

* quic-go upgrade: made corresponding changes to tutorial

* cleanup: remove unnecessary comments

Those comments made sense in terms of illustrating the changes
but they're going to be less useful once we merge.

* fix(go.mod): apparently we needed `go1.18.1 mod tidy`

VSCode just warned me about this. It seems fine to apply this
change as part of the pull request at hand.

* cleanup(netxlite): http3dialer can be removed

We used to use http3dialer to glue a QUIC dialer, which had a
context as its first argument, to the Dial function used by the
HTTP3 transport, which did not have a context as its first
argument.

Now that HTTP3 transport has a Dial function taking a context as
its first argument, we don't need http3dialer
anymore, since we can use the QUIC dialer directly.

Cc: @DecFox

* Revert "cleanup(netxlite): http3dialer can be removed"

This reverts commit c62244c620cee5fadcc2ca89d8228c8db0b96add
to investigate the build failure mentioned at
https://github.com/ooni/probe-cli/pull/715#issuecomment-1119450484

* chore(netx): show that test was already broken

We didn't see the breakage before because we were not using
the created transport, but the issue of using a nil dialer was
already present before, we just didn't see it.

Now we understand why removing the http3transport in
c62244c620cee5fadcc2ca89d8228c8db0b96add did cause the
breakage mentioned at
https://github.com/ooni/probe-cli/pull/715#issuecomment-1119450484

* fix(netx): convert broken integration test to working unit test

There's no point in using the network here. Add a fake dialer that
breaks and ensure we're getting the expected error.

We've now improved upon the original test because the original test was
not doing anything while now we're testing whether we get back a QUIC
dialer that _can be used_.

After this commit, I can then readd the cleanup commit
c62244c620cee5fadcc2ca89d8228c8db0b96add and it won't be
broken anymore (at least, this is what I expected to happen).

* Revert "Revert "cleanup(netxlite): http3dialer can be removed""

This reverts commit 0e254bfc6ba3bfd65365ce3d8de2c8ec51b925ff
because now we should have fixed the broken test.

Co-authored-by: decfox <decfox>
Co-authored-by: Simone Basso <bassosimone@gmail.com>
2022-05-06 12:24:03 +02:00
Simone Basso
306d18e466
chore: support go1.18 and update dependencies (#708)
Here's the squash of the following patches that enable support
for go1.18 and update our dependencies.

This diff WILL need to be backported to the release/3.14 branch.

* chore: use go1.17.8

See https://github.com/ooni/probe/issues/2067

* chore: upgrade to probe-assets@v0.8.0

See https://github.com/ooni/probe/issues/2067.

* chore: update dependencies and enable go1.18

As mentioned in 7a0d17ea91,
the tree won't build with `go1.18` unless we say it does.

So, not only here we need to update dependencies but also we
need to explicitly say `go1.18` in the `go.mod`.

This work is part of https://github.com/ooni/probe/issues/2067.

* chore(coverage.yml): run with go1.18

This change will give us a bare minimum confidence that we're
going to build our tree using version 1.18 of golang.

See https://github.com/ooni/probe/issues/2067.

* chore: update user agent used for measuring

See https://github.com/ooni/probe/issues/2067

* chore: run `go generate ./...`

See https://github.com/ooni/probe/issues/2067

* fix(dialer_test.go): make test work with go1.17 and go1.18

1. the original test wanted the dial to fail, so ensure we're not
passing any domain name to exercise dialing not resolving;

2. match the end of the error rather than the whole error string.

Tested locally with both go1.17 and go1.18.

See https://github.com/ooni/probe-cli/pull/708#issuecomment-1096447186
2022-04-12 11:43:12 +02:00
Dionysis Grigoropoulos
07f8db9dc2
feat: add support for OpenBSD (#703)
Closes https://github.com/ooni/probe/issues/2052
2022-03-08 12:25:33 +01:00
Simone Basso
ce8ec5b391
fix(reduceErrors): return error when given an empty list (#675)
See https://github.com/ooni/probe/issues/1985 for context.

While there, ensure nextlite has 100% of coverage.
2022-01-26 12:18:36 +01:00
Simone Basso
2a566f2046
feat: start preparing for a cli release (#672)
This diff includes some final changes to be ready for blessing
a cli release. These changes are:

1. run `go generate ./...` to update the bundled CA

2. update the header we use for measuring

3. ensure `mk` uses the latest version of several tools

Reference issue: https://github.com/ooni/probe/issues/1845
2022-01-24 14:56:51 +01:00
Simone Basso
e904b90006
feature: merge measurex and netx archival layer (1/N) (#663)
This diff introduces a new package called `./internal/archival`. This package collects data from `./internal/model` network interfaces (e.g., `Dialer`, `QUICDialer`, `HTTPTransport`), saves such data into an internal tabular data format suitable for on-line processing and analysis, and allows exporting data into the OONI data format.

The code for collecting and the internal tabular data formats are adapted from `measurex`. The code for formatting and exporting OONI data-format-compliant structures is adapted from `netx/archival`.

My original objective was to _also_ (1) fully replace `netx/archival` with this package and (2) adapt `measurex` to use this package rather than its own code. Both operations seem easily feasible because: (a) this code is `measurex` code without extensions that are `measurex` related, which will need to be added back as part of the process; (b) the API provided by this code allows for trivially converting from using `netx/archival` to using this code.

Yet, both changes should not be taken lightly. After implementing them, there's need to spend some time doing QA and ensuring all nettests work as intended. However, I am planning a release in the next two weeks, and this QA task is likely going to defer the release. For this reason, I have chosen to commit the work done so far into the tree and defer the second part of this refactoring for a later moment in time. (This explains why the title mentions "1/N").

On a more high-level perspective, it would also be beneficial, I guess, to explain _why_ I am doing these changes. There are two intertwined reasons. The first reason is that `netx/archival` has shortcomings deriving from its original https://github.com/ooni/netx legacy. The most relevant shortcoming is that it saves all kind of data into the same tabular structure named `Event`. This design choice is unfortunate because it does not allow one to apply data-type specific logic when processing the results. In turn, this choice results in complex processing code. Therefore, I believe that replacing the code with event-specific data structures is clearly an improvement in terms of code maintainability and would quite likely lead us to more confidently change and evolve the codebase.

The second reason why I would like to move forward these changes is to unify the codepaths used for measuring. At this point in time, we basically have two codepaths: `./internal/engine/netx` and `./internal/measurex`. They both have pros and cons and I don't think we want to rewrite whole experiments using `netx`. Rather, what we probably want is to gradually merge these two codepaths such that `netx` is a set of abstractions on top of `measurex` (which is more low-level and has a more-easily-testable design). Because saving events and generating an archival data format out of them consists of at least 50% of the complexity of both `netx` and `measurex`, it seems reasonable to unify this archival-related part of the two codebases as the first step.

At the highest level of abstraction, these changes are part of the train of changes which will eventually lead us to bless `websteps` as a first class citizen in OONI land. Because `websteps` requires different underlying primitives, I chose to develop these primitives from scratch rather than wrestling with `netx`, which used another model. The model used by `websteps` is that we perform each operation in isolation and immediately we save the results, while `netx` creates whole data structures and collects all the events happening via tracing. We believe the model used by `websteps` to be better because it does not require your code to figure out everything that happened after the measurement, which is a source of subtle bugs in the current implementation. So, when I started implementing websteps I extracted the bits of `netx` that could also be beneficial to `websteps` into a separate library, thus `netxlite` was born.

The reference issue describing merging the archival of `netx` and `measurex` is https://github.com/ooni/probe/issues/1957. As of this writing the issue still references the original plan, which I could not complete by the end of this Sprint, so I am going to adapt the text of the issue to only refer to what was done in here next. Of course, I also need follow-up issues.
2022-01-14 12:13:10 +01:00
Simone Basso
b5da8be183
fix(netxlite): robust {ReadAll,Copy}Context with wrapped io.EOF (#661)
* chore(netxlite): add currently failing test case

This diff introduces a test cases that will fail because of the reason
explained in https://github.com/ooni/probe/issues/1965.

* chore(netxlite/iox_test.go): add failing unit tests

These tests directly show how the Go implementation of ReadAll
and Copy has the issue of checking for io.EOF equality.

* fix(netxlite): make {ReadAll,Copy}Context robust to wrapped io.EOF

The fix is simple: we just need to check for `errors.Is(err, io.EOF)`
after either io.ReadAll or io.Copy has returned. When this condition is
true, we need to convert the error back to `nil` as it ought to be.

While there, observe that the unit tests I committed in the previous
commit are wrongly asserting that the error must be wrapped. This
assertion is not correct, because in both cases we have just ensured
that the returned error is `nil` (i.e., success).

See https://github.com/ooni/probe/issues/1965.

* cleanup: remove previous workaround for wrapped io.EOF

These workarounds were partial, meaning that they would cover some
cases in which the issue occurred but not all of them.

Handling the problem in `netxlite.{ReadAll,Copy}Context` is the
right thing to do _as long as_ we always use these functions instead
of `io.{ReadAll,Copy}`.

This is why it's now important to ensure we clearly mention that
inside of the `CONTRIBUTING.md` guide and to also ensure that we're
not using these functions in the code base.

* fix(urlgetter): repair tests who assumed to see EOF error

Now that we have established that we should normalize EOF when
reading bodies like the stdlib does and now that it's clear why
our behavior diverged from the stdlib, we also need to repair
all the tests that assumed this incorrect behavior.

* fix(all): don't use io{,util}.{Copy,ReadAll}

* feat: add checks to ensure we don't use io.{Copy,ReadAll}

* doc(netxlite): document we know how to deal w/ wrapped io.EOF

* fix(nocopyreadall.bash): add exception for i/n/iox.go
2022-01-12 14:26:10 +01:00
Simone Basso
566c6b246a
cleanup: remove unnecessary legacy interfaces (#656)
This diff addresses another point of https://github.com/ooni/probe/issues/1956:

> - [ ] observe that we're still using a bunch of private interfaces for common interfaces such as the `Dialer`, so we can get rid of these private interfaces and always use the ones in `model`, which allows us to remove a bunch of legacy wrappers

Additional cleanups may still be possible. The more I cleanup, the more I see
there's extra legacy code we can dispose of (which seems good?).
2022-01-07 18:33:37 +01:00
Simone Basso
1c057d322d
cleanup: merge legacy errorsx in netxlite and hide classifiers (#655)
This diff implements the first two cleanups defined at https://github.com/ooni/probe/issues/1956:

> - [ ] observe that `netxlite` and `netx` differ in error wrapping only in the way in which we set `ErrWrapper.Operation`. Observe that the code using `netxlite` does not care about such a field. Therefore, we can modify `netxlite` to set such a field using the code of `netx` and we can remove `netx` specific code for errors (which currently lives inside of the `./internal/engine/legacy/errorsx` package
>
> - [ ] after we've done the previous cleanup, we can make all the classifiers code private, since there's no code outside `netxlite` that needs them

A subsequent diff will address the remaining cleanup.

While there, notice that there are failing, unrelated obfs4 tests, so disable them in short mode. (I am confident these tests are unrelated because they fail for me when running test locally from the `master` branch.)
2022-01-07 17:31:21 +01:00
Simone Basso
99ec7ffca9
fix: ensure experiments return nil when we want to submit (#654)
Since https://github.com/ooni/probe-cli/pull/527, if an experiment
returns an error, the corresponding measurement is not submitted since
the semantics of returning an error is that something fundamental
went wrong (e.g., we could not parse the input URL).

This diff ensures that all experiments only return and error when
something fundamental was wrong and return nil otherwise.

Reference issue: https://github.com/ooni/probe/issues/1808.
2022-01-07 13:17:20 +01:00
Simone Basso
f0181c432f
refactor: move httpx into the internal package (#646)
This concludes the TODO list at https://github.com/ooni/probe/issues/1951
2022-01-05 17:17:20 +01:00
Simone Basso
273b70bacc
refactor: interfaces and data types into the model package (#642)
## Checklist

- [x] I have read the [contribution guidelines](https://github.com/ooni/probe-cli/blob/master/CONTRIBUTING.md)
- [x] reference issue for this pull request: https://github.com/ooni/probe/issues/1885
- [x] related ooni/spec pull request: N/A

Location of the issue tracker: https://github.com/ooni/probe

## Description

This PR contains a set of changes to move important interfaces and data types into the `./internal/model` package.

The criteria for including an interface or data type in here is roughly that the type should be important and used by several packages. We are especially interested to move more interfaces here to increase modularity.

An additional side effect is that, by reading this package, one should be able to understand more quickly how different parts of the codebase interact with each other.

This is what I want to move in `internal/model`:

- [x] most important interfaces from `internal/netxlite`
- [x] everything that was previously part of `internal/engine/model`
- [x] mocks from `internal/netxlite/mocks` should also be moved in here as a subpackage
2022-01-03 13:53:23 +01:00
Simone Basso
611fed05f4
[forwardport] release 3.11: update all the dependencies (#636) (#637)
* [forwardport] release 3.11: update all the dependencies (#636)

This diff forward ports e291e436b3c332300f5567796f9c48bb9bc1e652.

* chore: use go1.17.4 everywhere

Part of https://github.com/ooni/probe/issues/1843

* chore: update to the latest ooni/oohttp

Part of https://github.com/ooni/probe/issues/1843

* chore: update the dependencies

Note: I did an update and not an upgrade (i.e., I didn't check
whether we have next-major-versions of dependencies).

Part of https://github.com/ooni/probe/issues/1843

* chore: update the user-agent we use

Part of https://github.com/ooni/probe/issues/1843

* chore: update ooni/oohttp and ooni/probe-assets

Part of https://github.com/ooni/probe/issues/1843

* chore: run go generate again

Part of https://github.com/ooni/probe/issues/1843

* fix(jafar): skip currently broken test

Created issue for it here: https://github.com/ooni/probe/issues/1913
2021-12-06 17:46:13 +01:00
Simone Basso
50576daec8
[forwardport] fix(ios): make sure we can build an iOS release (#598) (#599)
This diff forward ports f47b0c6c16e0cd417e3591358eb85b45962f307d to master.

Original commit message:

- - -

1. we now need to name the framework `.xcframework` otherwise
gomobile refuses to build a new framework for us ¯\_(ツ)_/¯

2. remove duplicate errno definition for iOS (iOS and darwin
are considered the same, therefore we don't need iOS defs)

Reference issue for this PR: https://github.com/ooni/probe/issues/1876

This diff WILL need to be forwardported to master.
2021-11-15 14:24:20 +01:00
Simone Basso
0a322ebab0
[forwardport] fix: avoid http3 for dns.google and www.google.com (#593) (#594)
This commit forward ports dedd84fa7ecb09f718f6b1a9c83999cb37b34dfa.

Original commit message:

- - -

This diff changes code the release/3.11 branch to ensure we're not using dns.google and www.google.com over HTTP3. As documented in https://github.com/ooni/probe/issues/1873, since this morning (approx) these services do not support HTTP3 anymore. (I didn't bother with checking whether this issue affects _other_ Google services; I just limited my analysis to the services that we were using as part of testing.)

This patch WILL require forward porting to the master branch.
2021-11-12 14:43:28 +01:00
Simone Basso
0d65438ea1
[forwardport] fix(netxlite): remove android-specific errno (#586) (#587)
This commit forward ports 74947dbbd12266c12a38fad51a70fc78a21720fd from
the `release/3.11` branch to `master`. Here's the original commit message:

- - -

Android is also Linux. The Android build fails because both
errno_linux.go and errno_android.go are compiled.

There's no difference between the files except into a comment
that mentions "linux" or "android".

Therefore, it's safe to remove the android-specific file
and just keep and use the linux-specific one.

Part of https://github.com/ooni/probe/issues/1863, where we're
forward porting ooni/go patches to go1.17.

I'm still trying to figure out whether I can build oonimkall
using the forward ported patches and this error prevents me
from building, because the build fails.

"やれやれだぜ"

Note that this patch WILL need to be forward ported to master.

This bug was previosuly reported to me by @hellais.

Because I did run `go generate ./internal/netxlite/...` we also
get for free updated certificates, which is OK.
2021-11-10 13:00:41 +01:00
Simone Basso
6a935d5407
fix(netxlite): ensure HTTP errors are always wrapped (#584)
1. introduce implementations of HTTPTransport and HTTPClient
that apply an error wrapping policy using the constructor
for a generic top-level error wrapper

2. make sure we use the implementations in point 1 when we
are constructing HTTPTransport and HTTPClient

3. make sure we apply error wrapping using the constructor for
a generic top-level error wrapper when reading bodies

4. acknowledge that error wrapping would be broken if we do
not return the same classification _and_ operation when we wrap
an already wrapped error, so fix the to code to do that

5. acknowledge that the classifiers already deal with preserving
the error string and explain why this is a quirk and why we
cannot remove it right now and what needs to happen to safely
remove this quirk from the codebase

Closes https://github.com/ooni/probe/issues/1860
2021-11-06 17:49:58 +01:00
Simone Basso
100cc559a2
Revert "feat(filtering): implement the divert policy (#569)" (#570)
This reverts commit 851b9913fa because
it seems it's not enough to allow us to see certificate errors with
quic, plus it's complex code. So, we'd rather develop a better approach,
and perhaps a simpler one, that works with QUIC as well.
2021-11-03 14:01:32 +01:00
Simone Basso
851b9913fa
feat(filtering): implement the divert policy (#569)
This is the policy we need to provoke certificate errors. We'll divert
from, say, `8.8.8.8:443/udp` to, say, `1.1.1.1:443/udp`.

We'll do something similar for `443/tcp`.

This will cause certificate validation errors.

With this change, we have now implemented the simple design described
by https://github.com/ooni/probe/issues/1803#issuecomment-957323297.
2021-11-03 00:29:14 +01:00
Simone Basso
675e3a5ba5
feat(filtering): introduce DNS cache (#568)
When we're testing multiple endpoints, it's quite important to control
the order with which they are returned to the code.

This feature is especially relevant to Web Connectivity, which will
check the endpoints to connect to in order.

Therefore, we need to force deterministic results to ensure that we can
have deterministic tests when doing Web Connectivity QA.

This diff gives us the guarantee that we can have determinism.

Part of https://github.com/ooni/probe/issues/1803#issuecomment-957323297.
2021-11-02 23:35:09 +01:00
Simone Basso
11ccd16a0c
feat(filtering): add transparent proxy with censorship policies (#566)
This PR implements the core concept described at
https://github.com/ooni/probe/issues/1803#issuecomment-957323297
2021-11-02 21:52:32 +01:00
Simone Basso
560b1a9a97
fix(filtering): avoid the if err == nil pattern (#567)
1. in normal code is better to always do if err != nil so that
the ifs only contain error code (this is ~coding policy)

2. in tests we want to ensure we narrow down the error to the
real error that happened, to have greater confidence

Written while working on https://github.com/ooni/probe/issues/1803#issuecomment-957323297
2021-11-02 19:48:10 +01:00
Simone Basso
374577f5a8
feat(filtering): implement HTTP filtering proxy (#565)
Needed to finish the design at https://github.com/ooni/probe/issues/1803#issuecomment-957323297
2021-11-02 14:13:54 +01:00
Simone Basso
a6f5388bac
fix(filtering/dns.go): serve requests in parallel (#564)
Without this change, it takes too much to serve a single query and
we cannot properly use this code for QA.

See https://github.com/ooni/probe/issues/1803#issuecomment-957323297
2021-11-02 12:40:18 +01:00
Simone Basso
d9c43f1d1b
refactor(netxlite/filtering): use strings for blocking policies (#563)
This change will simplify follow-up work done as part of
https://github.com/ooni/probe/issues/1803#issuecomment-957323297 to
implement a comprehensive self-censoring solution.

While there, rename the "proxy" action to "pass" because what we
are effectively doing is passing traffic to the network (that's a
minor change but it seems a better analogy).
2021-11-02 12:31:42 +01:00
Simone Basso
f91de2ecd6
cleanup: move bogon checking code in netxlite (#562)
I develop this diff while working on https://github.com/ooni/probe/issues/1803#issuecomment-957323297.

While there, make sure we don't have duplicate bogon code
and always use the code inside netxlite.
2021-11-02 12:20:04 +01:00
Simone Basso
ffdafaf351
feat(netxlite): implement hooks for transparent proxy (#561)
See https://github.com/ooni/probe/issues/1803#issuecomment-957323297.
2021-11-02 12:04:40 +01:00
Simone Basso
d44970a43f
master: update deps and set version to 3.12.0-alpha (#548)
* chore: update all workflows to use go1.17.2

See https://github.com/ooni/probe/issues/1815

* chore: update all dependencies

See https://github.com/ooni/probe/issues/1815

* chore: run `go generate`

See https://github.com/ooni/probe/issues/1815

* chore: update the user-agent

Part of https://github.com/ooni/probe/issues/1815

* Set version to 3.12.0-alpha

Part of https://github.com/ooni/probe/issues/1815

* fix: update to ooni/probe-assets@v0.5.0

This overcomes https://github.com/ooni/probe/issues/1836 in the CLI and,
while there, let us also make maxminddb tests stricter.

* fix(QA/Dockerfile): build using go1.17

See https://github.com/ooni/probe-cli/pull/547#issuecomment-947760839

* chore(mk): use go1.17.2

Part of https://github.com/ooni/probe/issues/1815

* fix(codeql): always run for master

Otherwise we see a warning that there is no CodeQL information
available for the base branch and this is sub-optimal.

Part of https://github.com/ooni/probe/issues/1815
2021-10-20 18:16:40 +02:00
Simone Basso
2fa87f0e00
fix(wcth): match legacy TH w/ empty DNS reply (#546)
See https://github.com/ooni/probe/issues/1707#issuecomment-944322725
2021-10-15 16:20:07 +02:00
Simone Basso
762fb27c0b
fix(netxlite/quic): close udp conn after failed handshake (#533)
Closes https://github.com/ooni/probe/issues/1794
2021-09-30 18:00:38 +02:00
Simone Basso
8931a36cb3
fix(netxlite): make test less flaky on macOS (#526)
The explanatory comment in the diff says it all.

Work done while I was converging with https://github.com/ooni/probe/issues/1733.
2021-09-30 00:25:05 +02:00
Simone Basso
26f84ccc20
fix(resolver_test.go): remove race and make deterministic (#524)
Should fix https://github.com/ooni/probe-cli/pull/523#issuecomment-930430124.

Work part of https://github.com/ooni/probe-cli/pull/506.
2021-09-29 20:33:39 +02:00
Simone Basso
b2b1a4b2f1
doc(netxlite): revamp the documentation (#523)
Part of https://github.com/ooni/probe-cli/pull/506. In parallel with
tutorials, we also need to make sure we have good documentation.
2021-09-29 20:21:25 +02:00
Simone Basso
b9a844ecee
feat: run ~always netxlite integration tests (#522)
* feat: run ~always netxlite integration tests

This diff ensures that we check on windows, linux, macos that our
fundamental networking library (netxlite) works.

We combine unit and integration tests.

This work is part of https://github.com/ooni/probe/issues/1733, where
I want to have more strong guarantees about the foundations.

* fix(filtering/tls_test.go): make portable on Windows

The trick here is to use the wrapped error so to normalize the
different errors messages we see on Windows.

* fix(netxlite/quic_test.go): make portable on windows

Rather than using the zero port, use the `x` port which fails
when the stdlib is parsing the address.

The zero port seems to work on Windows while it does not on Unix.

* fix(serialresolver_test.go): make error more timeout than before

This seems enough to convince Go on Windows about this error
being really a timeout timeouty timeouted thingie.
2021-09-29 16:04:26 +02:00
Simone Basso
9967803c31
fix(netxlite): map additional GetAddrInfoW errors (#521)
On Windows, GetAddrInfoW is a syscall and the Go resolver does
not attempt to map errors beyond WSA_HOST_NOT_FOUND, which becomes
"no such host", which we map to "dns_nxdomain_error".

See https://github.com/golang/go/blob/go1.17.1/src/net/lookup_windows.go#L16.

To map more GetAddrInfoW errors, thus, we need to enhance our
error classifier to have system specific errors.

Then, we need to filter for the WSA errors that are most likely
to pop up and map them to OONI failures. Those are three:

- WSANO_DATA which we have from our own UDP resolver as well
and which we can map to `dns_no_answer`

- WSANO_RECOVERY which we don't have but existed for MK so
we will use `dns_non_recoverable_failure`, which was an MK error

- WSATRY_AGAIN which likewise we map to the error that MK
used to emit, so `dns_temporary_failure`

This diff should address https://github.com/ooni/probe/issues/1467.
2021-09-29 11:21:28 +02:00
Simone Basso
9523753b87
fix: allow to build miniooni for windows (#520)
I need to run test on Windows and I just discovered that:

1. the `errno_unix.go` filename does not mean anything because
`unix` is not a valid platform, so we need a filename for
each platform that we care about;

2. on Windows we need to use WSA prefixed names;

3. `i/e/session_psiphon.go` was not building because of the
migration from `netxlite/iox` to `netxlite`.

This diff attempts to fix all three issues.

The reference issue is https://github.com/ooni/probe/issues/1733,
because I was working on such an issue.
2021-09-28 18:27:28 +02:00
Simone Basso
9ef4d9df7d
doc: add tutorial on how to use netxlite (#519)
The main tutorial will be the one at https://github.com/ooni/probe-cli/pull/506, but
it's useful to also document the primitives used by measurex.

So, here's the companion tutorial, which explains how to use the
features in netxlite to perform measurements.

This work is part of https://github.com/ooni/ooni.org/issues/361.
2021-09-28 18:15:38 +02:00
Simone Basso
6d3a4f1db8
refactor: merge dnsx and errorsx into netxlite (#517)
When preparing a tutorial for netxlite, I figured it is easier
to tell people "hey, this is the package you should use for all
low-level networking stuff" rather than introducing people to
a set of packages working together where some piece of functionality
is here and some other piece is there.

Part of https://github.com/ooni/probe/issues/1591
2021-09-28 12:42:01 +02:00
Simone Basso
de130d249c
refactor(dnsx): group tests together (#516)
Part of https://github.com/ooni/probe/issues/1591
2021-09-28 11:26:16 +02:00
Simone Basso
12cf4b9990
refactor(dnsx): prepare for merging with netxlite (#515)
Part of https://github.com/ooni/probe/issues/1591
2021-09-28 10:47:59 +02:00
Simone Basso
8b9fe1a160
feat(netxlite): implement LookupHTTPS (#514)
This new API call performs DNS lookups for HTTPS records.

Part of https://github.com/ooni/probe/issues/1733 and diff has been
extracted from https://github.com/ooni/probe-cli/pull/506.
2021-09-27 23:09:41 +02:00
Simone Basso
24b230fd38
fix(netxlite/dns): more stricly mirror stdlib error strings (#513)
This diff attempts to modify the errors reported by our custom
resolver by matching more strings from the stdlib.

Part of https://github.com/ooni/probe/issues/1733 and diff has been
extracted from https://github.com/ooni/probe-cli/pull/506.
2021-09-27 16:48:46 +02:00
Simone Basso
201f602a40
feat(errorsx): introduce NewTopLevelGenericErrWrapper (#511)
Part of https://github.com/ooni/probe/issues/1733 and diff has been
extracted from https://github.com/ooni/probe-cli/pull/506.
2021-09-27 14:55:47 +02:00
Simone Basso
d7b9c8f0a8
fix(netxlite/errorsx): map "use of closed network connection" (#510)
Part of https://github.com/ooni/probe/issues/1733 and diff has been
extracted from https://github.com/ooni/probe-cli/pull/506.
2021-09-27 14:40:25 +02:00
Simone Basso
273774bb03
fix(netxlite/quic): wrap Close (#509)
While there, make sure netxlite has 100% coverage.

Part of https://github.com/ooni/probe/issues/1733 and diff
has been extracted from https://github.com/ooni/probe-cli/pull/506.
2021-09-27 14:14:17 +02:00
Simone Basso
deb1589bdb
fix(netxlite): do not mutate outgoing requests (#508)
I have recently seen a data race related our way of
mutating the outgoing request to set the host header.

Unfortunately, I've lost track of the race output,
because I rebooted my Linux box before saving it.

Though, after inspecting why and and where we're mutating
outgoing requets, I've found that:

1. we add the host header when logging to have it logged,
which is not a big deal since we already emit the URL
rather than just the URL path when logging a request, and
so we can safely zap this piece of code;

2. as a result, in measurements we may omit the host header
but again this is pretty much obvious from the URL itself
and so it should not be very important (nonetheless,
avoid surprises and keep the existing behavior);

3. when the User-Agent header is not set, we default to
a `miniooni/0.1.0-dev` user agent, which is probably not
very useful anyway, so we can actually remove it.

Part of https://github.com/ooni/probe/issues/1733 (this diff
has been extracted from https://github.com/ooni/probe-cli/pull/506).
2021-09-27 13:35:47 +02:00
Simone Basso
741a8bc4c2
feat(netxlite): introduce wrapping constructors (#507)
This diff has been extracted from https://github.com/ooni/probe-cli/pull/506.

In it, we introduce wrapping constructors for types and we
update the docs. These new constructures are used by the code
in https://github.com/ooni/probe-cli/pull/506.

In itself, this work is part of https://github.com/ooni/probe/issues/1733.
2021-09-27 12:00:43 +02:00
Simone Basso
3cb782f0a2
refactor(netx): move dns transports in netxlite/dnsx (#503)
While there, modernize the way in which we run tests to avoid
depending on the fake files scattered around the tree and to
use some well defined mock structures instead.

Part of https://github.com/ooni/probe/issues/1591
2021-09-09 21:24:27 +02:00
Simone Basso
1eb9e8c9b0
refactor(netx/resolver): add CloseIdleConnections to RoundTripper (#501)
While there, also change to pointer receiver and use internal
testing for what are clearly unit tests.

Part of https://github.com/ooni/probe/issues/1591.
2021-09-09 20:49:12 +02:00
Simone Basso
5ab3c3b689
refactor(netx): use netxlite for AddressResolver (#500)
Part of https://github.com/ooni/probe/issues/1591.
2021-09-09 20:21:43 +02:00
Simone Basso
1d79d70b43
refactor: migrate apitool from netx to netxlite (#496)
I discovered which transport were used by apitool and made sure he gets the same transports now. While there, I discovered an issue with ooni/oohttp that has been fixed with cba9b1ce5e.

Part of https://github.com/ooni/probe/issues/1591
2021-09-09 01:19:17 +02:00
Simone Basso
00a85cb7f0
fix(quic): properly unwrap OONI errors from TransportError (#495)
Noticed while playing around with QUIC code.

Part of https://github.com/ooni/probe/issues/1544.
2021-09-09 00:07:38 +02:00
Simone Basso
50b58672c6
netxlite: code quality, improve tests, docs (#494)
See https://github.com/ooni/probe/issues/1591
2021-09-08 22:48:10 +02:00
Simone Basso
3cd88debdc
netxlite: improve docs, tests, and code quality (#493)
* netxlite: improve docs, tests, and code quality

* better documentation

* more strict testing of dialer (especially make sure we
document the quirk in https://github.com/ooni/probe/issues/1779
and we have tests to guarantee we don't screw up here)

* introduce NewErrWrapper factory for creating errors so we
have confidence we are creating them correctly

Part of https://github.com/ooni/probe/issues/1591
2021-09-08 21:19:51 +02:00
Simone Basso
e68adec9a5
fix(netxlite): http3 transport needs logging by default (#492)
Adapt other places where it was not using a logger to either choose
a reasonable logger or disable logging for backwards compat.

See https://github.com/ooni/probe/issues/1591
2021-09-08 20:49:01 +02:00
Simone Basso
18b2eb37ff
fix(netxlite/errorsx): serialize directly to JSON (#491)
This simplifies serializing errors to `*string`. It did not
occur to me before. It seems quite a nice improvement.

Part of https://github.com/ooni/probe/issues/1591
2021-09-08 17:42:36 +02:00
Simone Basso
957185d659
doc(netxlite/tls.go): explain what the handshake returns (#490)
Part of https://github.com/ooni/probe/issues/1591
2021-09-08 17:21:51 +02:00
Simone Basso
26360f5a29
feat(netxlite): introduce null dialers (#489)
See https://github.com/ooni/probe/issues/1591
2021-09-08 14:46:17 +02:00
Simone Basso
f2e3e5cc08
refactor(netxlite): finish grouping tests (#488)
They are now more readable. I'll do another pass and start
separating integration testing from unit testing.

I think we need to have some always on integration testing
for netxlite that runs on macOS, linux, and windows.

See https://github.com/ooni/probe/issues/1591
2021-09-08 11:39:27 +02:00
Simone Basso
493b72b170
refactor(netxlite): improve tests for http and http3 (#487)
* refactor(netxlite): improve tests for http and http3

See https://github.com/ooni/probe/issues/1591

* Update internal/netxlite/http3.go
2021-09-08 00:59:48 +02:00
Simone Basso
6d39118b26
refactor(netxlite): restructure dialer tests (#486)
While there, add one more test checking for whether the internal
CA bundle we use can actually be loaded.

Part of https://github.com/ooni/probe/issues/1591
2021-09-08 00:00:53 +02:00
Simone Basso
f054ec3201
refactor(netxlite/mocks): group tests, fix naming inconsistencies (#485)
Part of https://github.com/ooni/probe/issues/1591
2021-09-07 23:12:23 +02:00
Simone Basso
9e82e37ab8
refactor(netxlite/iox): group tests and avoid races (#484)
Part of https://github.com/ooni/probe/issues/1591
2021-09-07 22:41:34 +02:00
Simone Basso
1472f7530b
refactor(netxlite/errorsx): change all tests to be unit tests (#483)
Later we will try to write comprehensive integration tests for
the whole netxlite package. We want just unit tests here.
2021-09-07 22:10:29 +02:00
Simone Basso
b7786a7324
refactor(netxlite/errorsx): extract string-suffix classifier (#482)
This change makes the code more tidy and easier to read.

No functional change, though.

See https://github.com/ooni/probe/issues/1591.
2021-09-07 21:18:26 +02:00
Simone Basso
a56b284b0e
refactor(netxlite/errors): improve docs and format code (#481)
No real functional change. A few are needed and they will come
next. With this diff I just wanted to do cosmetic changes and
documentation changes, to ensure this package is okay.

See https://github.com/ooni/probe/issues/1591
2021-09-07 20:39:32 +02:00
Simone Basso
323266da83
fix(netxlite): add error wrappers (#480)
See https://github.com/ooni/probe/issues/1591
2021-09-07 19:56:42 +02:00
Simone Basso
83440cf110
refactor: split errorsx in good and legacy (#477)
The legacy part for now is internal/errorsx. It will stay there until
I figure out whether it also needs some extra bug fixing.

The good part is now in internal/netxlite/errorsx and contains all the
logic for mapping errors. We need to further improve upon this logic
by writing more thorough integration tests for QUIC.

We also need to copy the various dialer, conn, etc adapters that set
errors. We will put them inside netxlite and we will generate errors in
a way that is less crazy with respect to the major operation. (The
idea is to always wrap, given that now we measure in an incremental way
and we don't measure every operation together.)

Part of https://github.com/ooni/probe/issues/1591
2021-09-07 17:09:30 +02:00
Simone Basso
8b38ea7e98
refactor(errorsx): improve errno generating code (#473)
No functional change, as it's clearly obvious from the output.

While there, also rename the generator for certifi. We are planning
on merging errorsx into netxlite. The first step is to give different
names to the code generating programs.

See https://github.com/ooni/probe/issues/1591
2021-09-07 14:25:42 +02:00
Simone Basso
fe3c90479d
refactor(netxlite): adapt single-use-quic-dialer from websteps (#472)
This is the last bit of functionality we need before rewriting a
chunk of websteps to use netxlite.

To rewrite most of it, we still need to move over:

1. dnstransport code

2. errorsx code

With both done, netxlite is a good library for websteps as well
as for most other operations we perform outside of the experiments.

Part of https://github.com/ooni/probe/issues/1591
2021-09-06 22:14:49 +02:00
Simone Basso
b9c4ad0b2b
fix(netxlite): http3 propagates CloseIdleConnections to its dialer (#471)
With this change, we are now able to change more dependent code to simplify
the way in which we create and manage resolvers.

See https://github.com/ooni/probe/issues/1591
2021-09-06 21:52:00 +02:00
Simone Basso
bdad392b61
feat(netxlite): write factories for quic code (#470)
Part of https://github.com/ooni/probe/issues/1591
2021-09-06 21:34:14 +02:00
Simone Basso
3ba5626b95
feat(netxlite): add CloseIdleConnections to quic dialer (#469)
Like before, do not touch the rest of the tree. Rather create
compatibility types declared as legacy.

We will soon be able to close idle connections for an HTTP3
transport using any kind of resolvers more easily.

See https://github.com/ooni/probe/issues/1591
2021-09-06 20:56:14 +02:00
Simone Basso
aa77867145
fix(netxlite): clearly document quirk and make code robust (#468)
This quirk really saddens me. It's a piece of tech debt we're
carrying over from the original netx implementation.

We cannot remove it _until_ we have legacy netx code around.

The second best thing we can do is to clearly move this code in
a place where it's clear it's a quirk and write and use some extra
code that makes sure the quirk's assumptions are always met.

Sigh.

See https://github.com/ooni/probe/issues/1591
2021-09-06 20:17:45 +02:00
Simone Basso
ba5bae4769
refactor(netxlite): let NewHTTPTransport work with single-use dialers (#467)
To make this happen, we need to take as argument a TLSDialer rather than
a TLSHandshaker. Then, we need to arrange the code so that we always
enforce a timeout for both TCP and TLS connections.

Because a TLSDialer can be constructed with a custom TLSConfig, we cover
also the case where the users wants to provide such a config.

While there, make sure we have better unit tests of the HTTP code.

See https://github.com/ooni/probe/issues/1591
2021-09-06 19:27:59 +02:00
Simone Basso
3114d6ca0e
feat(netxlite): integrate websteps code to use ooni/oohttp (#466)
Part of https://github.com/ooni/probe/issues/1591
2021-09-06 17:21:34 +02:00
Simone Basso
6df27d919d
fix(netxlite): http factory that propagates close-idle-connections (#465)
While there reorganize mocks' tls implementation to use a single file
called tls.go (and tls_test.go) just like netxlite does.

While there write tests ensuring we always add timeouts when we are
making TCP connections (be them TLS or cleartext).

See https://github.com/ooni/probe/issues/1591
2021-09-06 16:53:28 +02:00
Simone Basso
2572376fdb
feat(netxlite): implement single use {,tls} dialer (#464)
This basically adapts already existing code inside websteps to
instead be into the netxlite package, where it belongs.

In the process, abstract the TLSDialer but keep a reference to the
previous name to avoid refactoring existing code (just for now).

While there, notice that the right name is CloseIdleConnections (i.e.,
plural not singular) and change the name.

While there, since we abstracted TLSDialer to be an interface, create
suitable factories for making a TLSDialer type from a Dialer and a
TLSHandshaker.

See https://github.com/ooni/probe/issues/1591
2021-09-06 14:12:30 +02:00
Simone Basso
ef9592f75e
feat(netxlite): TLSDialer closes idle connections (#463)
We are proceeding with this plan of every major type being able to
close idle connections, which will simplify making DNS resolvers.

See https://github.com/ooni/probe/issues/1591.
2021-09-06 13:29:37 +02:00
Simone Basso
3caf5800a2
fix(netxlite): gracefully handle utls panics (#462)
* fix(netxlite): gracefully handle utls panics

See https://github.com/ooni/probe/issues/1770

* fix(netxlite): remove wrong timeout from newly written test
2021-09-05 21:41:49 +02:00
Simone Basso
b834af83ac
feat: upgrade oohttp and propagate changes (#461)
Part of https://github.com/ooni/probe/issues/1506
2021-09-05 21:23:47 +02:00