stderr debugging for #517 (tls: bad certificate)

refs #517

cc @asomers
This commit is contained in:
Christian Schwarz 2021-09-20 07:43:22 +02:00
parent b54e477602
commit 6f11e92801
5 changed files with 16 additions and 0 deletions

View File

@ -7,6 +7,7 @@ package transportmux
import ( import (
"context" "context"
"os"
"sync/atomic" "sync/atomic"
"syscall" "syscall"
@ -15,6 +16,7 @@ import (
"net" "net"
"time" "time"
"github.com/kr/pretty"
"github.com/zrepl/zrepl/daemon/logging" "github.com/zrepl/zrepl/daemon/logging"
"github.com/zrepl/zrepl/logger" "github.com/zrepl/zrepl/logger"
"github.com/zrepl/zrepl/transport" "github.com/zrepl/zrepl/transport"
@ -151,6 +153,7 @@ func Demux(ctx context.Context, rawListener transport.AuthenticatedListener, lab
rawConn, err := rawListener.Accept(ctx) rawConn, err := rawListener.Accept(ctx)
if err != nil { if err != nil {
fmt.Fprintf(os.Stderr, "transportmux.Demux: rawListener.Accept() returned error: %T %s\n%s\n", err, err, pretty.Sprint(err))
if ctx.Err() != nil { if ctx.Err() != nil {
return return
} }

View File

@ -10,9 +10,12 @@ import (
"fmt" "fmt"
"io" "io"
"net" "net"
"os"
"strings" "strings"
"time" "time"
"unicode/utf8" "unicode/utf8"
"github.com/kr/pretty"
) )
type HandshakeMessage struct { type HandshakeMessage struct {
@ -93,6 +96,7 @@ func (m *HandshakeMessage) Encode() ([]byte, error) {
func (m *HandshakeMessage) DecodeReader(r io.Reader, maxLen int) error { func (m *HandshakeMessage) DecodeReader(r io.Reader, maxLen int) error {
var lenAndSpace [11]byte var lenAndSpace [11]byte
if _, err := io.ReadFull(r, lenAndSpace[:]); err != nil { if _, err := io.ReadFull(r, lenAndSpace[:]); err != nil {
fmt.Fprintf(os.Stderr, "HandshakeMessage.DecodeReader error: %T\n%s", err, pretty.Sprint(err))
return hsIOErr(err, "error reading protocol banner length: %s", err) return hsIOErr(err, "error reading protocol banner length: %s", err)
} }
if !utf8.Valid(lenAndSpace[:]) { if !utf8.Valid(lenAndSpace[:]) {

View File

@ -2,7 +2,9 @@ package versionhandshake
import ( import (
"context" "context"
"fmt"
"net" "net"
"os"
"time" "time"
"github.com/zrepl/zrepl/transport" "github.com/zrepl/zrepl/transport"
@ -23,6 +25,7 @@ func (c HandshakeConnecter) Connect(ctx context.Context) (transport.Wire, error)
dl = time.Now().Add(c.timeout) dl = time.Now().Add(c.timeout)
} }
if err := DoHandshakeCurrentVersion(conn, dl); err != nil { if err := DoHandshakeCurrentVersion(conn, dl); err != nil {
fmt.Fprintf(os.Stderr, "HandshakeConnecter error: %T\n\t%s\n\t%v\n\t%#v\n\n", err, err, err, err)
conn.Close() conn.Close()
return nil, err return nil, err
} }

View File

@ -3,7 +3,9 @@ package tls
import ( import (
"context" "context"
"crypto/tls" "crypto/tls"
"fmt"
"net" "net"
"os"
"github.com/pkg/errors" "github.com/pkg/errors"
@ -48,6 +50,7 @@ func TLSConnecterFromConfig(in *config.TLSConnect) (*TLSConnecter, error) {
func (c *TLSConnecter) Connect(dialCtx context.Context) (transport.Wire, error) { func (c *TLSConnecter) Connect(dialCtx context.Context) (transport.Wire, error) {
conn, err := c.dialer.DialContext(dialCtx, "tcp", c.Address) conn, err := c.dialer.DialContext(dialCtx, "tcp", c.Address)
if err != nil { if err != nil {
fmt.Fprintf(os.Stderr, "tls connecter error %T\n\t%s\n\t%v\n\t%#v\n\n", err, err, err, err)
return nil, err return nil, err
} }
tcpConn := conn.(*net.TCPConn) tcpConn := conn.(*net.TCPConn)

View File

@ -4,8 +4,10 @@ import (
"context" "context"
"crypto/tls" "crypto/tls"
"fmt" "fmt"
"os"
"time" "time"
"github.com/kr/pretty"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/zrepl/zrepl/config" "github.com/zrepl/zrepl/config"
@ -68,6 +70,7 @@ type tlsAuthListener struct {
func (l tlsAuthListener) Accept(ctx context.Context) (*transport.AuthConn, error) { func (l tlsAuthListener) Accept(ctx context.Context) (*transport.AuthConn, error) {
tcpConn, tlsConn, cn, err := l.ClientAuthListener.Accept() tcpConn, tlsConn, cn, err := l.ClientAuthListener.Accept()
if err != nil { if err != nil {
fmt.Fprintf(os.Stderr, "tlsAuthListener.Accept: l.ClientAuthListener.Accept returned error %T %s\n%s\n", err, err, pretty.Sprint(err))
return nil, err return nil, err
} }
if _, ok := l.clientCNs[cn]; !ok { if _, ok := l.clientCNs[cn]; !ok {