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:
parent
a1df3b4070
commit
ebc00a95fe
9 changed files with 151 additions and 58 deletions
|
|
@ -8,7 +8,9 @@ import (
|
|||
"context"
|
||||
"crypto/tls"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net"
|
||||
"reflect"
|
||||
|
||||
"github.com/ooni/probe-cli/v3/internal/model"
|
||||
utls "gitlab.com/yawning/utls.git"
|
||||
|
|
@ -42,20 +44,50 @@ type utlsConn struct {
|
|||
var _ TLSConn = &utlsConn{}
|
||||
|
||||
// newConnUTLS returns a NewConn function for creating utlsConn instances.
|
||||
func newConnUTLS(clientHello *utls.ClientHelloID) func(conn net.Conn, config *tls.Config) TLSConn {
|
||||
return func(conn net.Conn, config *tls.Config) TLSConn {
|
||||
uConfig := &utls.Config{
|
||||
RootCAs: config.RootCAs,
|
||||
NextProtos: config.NextProtos,
|
||||
ServerName: config.ServerName,
|
||||
InsecureSkipVerify: config.InsecureSkipVerify,
|
||||
DynamicRecordSizingDisabled: config.DynamicRecordSizingDisabled,
|
||||
}
|
||||
tlsConn := utls.UClient(conn, uConfig, *clientHello)
|
||||
return &utlsConn{UConn: tlsConn}
|
||||
func newConnUTLS(clientHello *utls.ClientHelloID) func(conn net.Conn, config *tls.Config) (TLSConn, error) {
|
||||
return func(conn net.Conn, config *tls.Config) (TLSConn, error) {
|
||||
return newConnUTLSWithHelloID(conn, config, clientHello)
|
||||
}
|
||||
}
|
||||
|
||||
// errUTLSIncompatibleStdlibConfig indicates that the stdlib config you passed to
|
||||
// newConnUTLSWithHelloID contains some fields we don't support.
|
||||
var errUTLSIncompatibleStdlibConfig = errors.New("utls: incompatible stdlib config")
|
||||
|
||||
// newConnUTLSWithHelloID creates a new connection with the given client hello ID.
|
||||
func newConnUTLSWithHelloID(conn net.Conn, config *tls.Config, cid *utls.ClientHelloID) (TLSConn, error) {
|
||||
supportedFields := map[string]bool{
|
||||
"DynamicRecordSizingDisabled": true,
|
||||
"InsecureSkipVerify": true,
|
||||
"NextProtos": true,
|
||||
"RootCAs": true,
|
||||
"ServerName": true,
|
||||
}
|
||||
value := reflect.ValueOf(config).Elem()
|
||||
kind := value.Type()
|
||||
for idx := 0; idx < value.NumField(); idx++ {
|
||||
field := value.Field(idx)
|
||||
if field.IsZero() {
|
||||
continue
|
||||
}
|
||||
fieldKind := kind.Field(idx)
|
||||
if supportedFields[fieldKind.Name] {
|
||||
continue
|
||||
}
|
||||
err := fmt.Errorf("%w: field %s is nonzero", errUTLSIncompatibleStdlibConfig, fieldKind.Name)
|
||||
return nil, err
|
||||
}
|
||||
uConfig := &utls.Config{
|
||||
DynamicRecordSizingDisabled: config.DynamicRecordSizingDisabled,
|
||||
InsecureSkipVerify: config.InsecureSkipVerify,
|
||||
RootCAs: config.RootCAs,
|
||||
NextProtos: config.NextProtos,
|
||||
ServerName: config.ServerName,
|
||||
}
|
||||
tlsConn := utls.UClient(conn, uConfig, *cid)
|
||||
return &utlsConn{UConn: tlsConn}, nil
|
||||
}
|
||||
|
||||
// ErrUTLSHandshakePanic indicates that there was panic handshaking
|
||||
// when we were using the yawning/utls library for parroting.
|
||||
// See https://github.com/ooni/probe/issues/1770 for more information.
|
||||
|
|
|
|||
Loading…
Reference in a new issue