2021-07-01 18:00:09 +02:00
|
|
|
package errorsx
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"crypto/tls"
|
|
|
|
"net"
|
2021-09-07 17:09:30 +02:00
|
|
|
|
|
|
|
"github.com/ooni/probe-cli/v3/internal/netxlite/errorsx"
|
2021-07-01 18:00:09 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
// TLSHandshaker is the generic TLS handshaker
|
|
|
|
type TLSHandshaker interface {
|
|
|
|
Handshake(ctx context.Context, conn net.Conn, config *tls.Config) (
|
|
|
|
net.Conn, tls.ConnectionState, error)
|
|
|
|
}
|
|
|
|
|
|
|
|
// ErrorWrapperTLSHandshaker wraps the returned error to be an OONI error
|
|
|
|
type ErrorWrapperTLSHandshaker struct {
|
|
|
|
TLSHandshaker
|
|
|
|
}
|
|
|
|
|
|
|
|
// Handshake implements TLSHandshaker.Handshake
|
|
|
|
func (h *ErrorWrapperTLSHandshaker) Handshake(
|
|
|
|
ctx context.Context, conn net.Conn, config *tls.Config,
|
|
|
|
) (net.Conn, tls.ConnectionState, error) {
|
|
|
|
tlsconn, state, err := h.TLSHandshaker.Handshake(ctx, conn, config)
|
|
|
|
err = SafeErrWrapperBuilder{
|
2021-09-07 17:09:30 +02:00
|
|
|
Classifier: errorsx.ClassifyTLSHandshakeError,
|
2021-07-01 18:00:09 +02:00
|
|
|
Error: err,
|
2021-09-07 17:09:30 +02:00
|
|
|
Operation: errorsx.TLSHandshakeOperation,
|
2021-07-01 18:00:09 +02:00
|
|
|
}.MaybeBuild()
|
|
|
|
return tlsconn, state, err
|
|
|
|
}
|