Skip to content

Commit

Permalink
[backport] fix(oohelperd): use cached cert pool for quic and tls
Browse files Browse the repository at this point in the history
This commit backports 8476f11.

This commit creates a private static cert pool to use in the
oohelperd when issuing QUIC and TLS connections.

See ooni/probe#2413 for context.
  • Loading branch information
bassosimone committed Feb 15, 2023
1 parent 3b87f72 commit ebb4ecc
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
7 changes: 7 additions & 0 deletions internal/cmd/oohelperd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ import (

const maxAcceptableBody = 1 << 24

// certpool caches the default X509 certificate pool used by this program. Profiling
// shows that, without caching, this program spends a significant amount of time
// building and garbage collecting the certificate pool.
//
// See https://github.com/ooni/probe/issues/2413 for context.
var certpool = netxlite.NewDefaultCertPool()

var (
endpoint = flag.String("endpoint", "127.0.0.1:8080", "API endpoint")
srvAddr = make(chan string, 1) // with buffer
Expand Down
5 changes: 3 additions & 2 deletions internal/cmd/oohelperd/quic.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"github.com/lucas-clemente/quic-go"
"github.com/ooni/probe-cli/v3/internal/measurexlite"
"github.com/ooni/probe-cli/v3/internal/model"
"github.com/ooni/probe-cli/v3/internal/netxlite"
)

// ctrlQUICResult is the result of the QUIC check performed by the test helper.
Expand Down Expand Up @@ -78,9 +77,11 @@ func quicDo(ctx context.Context, config *quicConfig) {
dialer := config.NewQUICDialer(config.Logger)
defer dialer.CloseIdleConnections()

// See https://github.com/ooni/probe/issues/2413 to understand
// why we're using a cached cert pool.
tlsConfig := &tls.Config{
NextProtos: []string{"h3"},
RootCAs: netxlite.NewDefaultCertPool(),
RootCAs: certpool,
ServerName: config.URLHostname,
}
quicConn, err := dialer.DialContext(ctx, config.Endpoint, tlsConfig, &quic.Config{})
Expand Down
4 changes: 3 additions & 1 deletion internal/cmd/oohelperd/tcptls.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,11 @@ func tcpTLSDo(ctx context.Context, config *tcpTLSConfig) {
ol.Stop(err)
return
}
// See https://github.com/ooni/probe/issues/2413 to understand
// why we're using a cached cert pool.
tlsConfig := &tls.Config{
NextProtos: []string{"h2", "http/1.1"},
RootCAs: netxlite.NewDefaultCertPool(),
RootCAs: certpool,
ServerName: config.URLHostname,
}
thx := config.NewTSLHandshaker(config.Logger)
Expand Down

0 comments on commit ebb4ecc

Please sign in to comment.