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.
This commit is contained in:
Simone Basso 2022-05-22 19:53:37 +02:00 committed by GitHub
commit ebc00a95fe
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 151 additions and 58 deletions

View file

@ -1,8 +1,7 @@
package httptransport
import (
"net/http"
oohttp "github.com/ooni/oohttp"
"github.com/ooni/probe-cli/v3/internal/model"
)
@ -13,7 +12,7 @@ import (
//
// New code should use netxlite.NewHTTPTransport instead.
func NewSystemTransport(config Config) model.HTTPTransport {
txp := http.DefaultTransport.(*http.Transport).Clone()
txp := oohttp.DefaultTransport.(*oohttp.Transport).Clone()
txp.DialContext = config.Dialer.DialContext
txp.DialTLSContext = config.TLSDialer.DialTLSContext
// Better for Cloudflare DNS and also better because we have less
@ -24,12 +23,12 @@ func NewSystemTransport(config Config) model.HTTPTransport {
// back the true headers, such as Content-Length. This change is
// functional to OONI's goal of observing the network.
txp.DisableCompression = true
return &SystemTransportWrapper{txp}
return &SystemTransportWrapper{&oohttp.StdlibTransport{Transport: txp}}
}
// SystemTransportWrapper adapts *http.Transport to have the .Network method
type SystemTransportWrapper struct {
*http.Transport
*oohttp.StdlibTransport
}
func (txp *SystemTransportWrapper) Network() string {

View file

@ -5,6 +5,7 @@ import (
"testing"
"github.com/apex/log"
oohttp "github.com/ooni/oohttp"
"github.com/ooni/probe-cli/v3/internal/netxlite"
)
@ -19,9 +20,11 @@ func TestTLSDialerSuccess(t *testing.T) {
DebugLogger: log.Log,
},
}
txp := &http.Transport{
DialTLSContext: dialer.DialTLSContext,
ForceAttemptHTTP2: true,
txp := &oohttp.StdlibTransport{
Transport: &oohttp.Transport{
DialTLSContext: dialer.DialTLSContext,
ForceAttemptHTTP2: true,
},
}
client := &http.Client{Transport: txp}
resp, err := client.Get("https://www.google.com")