mirror of
https://github.com/devvmhq/devvm.git
synced 2026-12-01 06:23:17 -10:00
golangci-lint now also runs govet's nilness, unusedwrite, hostport and waitgroup analyzers, nilnesserr, durationcheck, canonicalheader, errchkjson, forcetypeassert, contextcheck and gochecksumtype. - errchkjson checks each JSON encoding's error where the value could fail and drops it where errchkjson proves it can't, and reports structs without exported fields; tests may drop theirs. - forcetypeassert holds the code; tests are exempt. - gochecksumtype: agentlogin's format is a sum type (//sumtype:decl), and a switch on one names every case, default or not. - canonicalheader: WWW-Authenticate, X-Request-ID, X-Api-Key. - contextcheck: ctx threaded through carry, peekClientHello and sniOf, and through inject and value, whose cached lookup takes WithTimeout(WithoutCancel(ctx)), so two forbidigo nolints go; openTransparent takes its dialer's ctx. nolints stay where contextcheck can't follow: ReverseProxy's Rewrite, WithoutCancel alone, cobra's cmd.Context, e2e's runner window. - No-behaviour fixes: scrubList for redact's list, the loopback forward's ports kept with its listeners, upgradetest's Key keeps its public key, a CA's leaves read through leafOf. Contributing's Go lint rules lists each one and the sum-type convention. Co-Authored-By: Claude Opus 5.5 <[email protected]>
44 lines
1.6 KiB
Go
44 lines
1.6 KiB
Go
package proxy
|
|
|
|
import (
|
|
"bytes"
|
|
"context"
|
|
"crypto/tls"
|
|
"errors"
|
|
"io"
|
|
"net"
|
|
"time"
|
|
)
|
|
|
|
var errStop = errors.New("stop after ClientHello")
|
|
|
|
// sniOf returns the server name in a TLS ClientHello record, "" for none, and whether the record
|
|
// held a whole ClientHello that parsed: one split across records, cut short or refused by
|
|
// crypto/tls (a trailing dot, two names) didn't, and names nothing. It lets crypto/tls parse the
|
|
// record and stops the handshake at the ClientHello callback. The record is in memory, so ctx's
|
|
// end changes nothing.
|
|
func sniOf(ctx context.Context, rec []byte) (string, bool) {
|
|
var name string
|
|
parsed := false
|
|
c := tls.Server(helloConn{bytes.NewReader(rec)}, &tls.Config{
|
|
GetConfigForClient: func(h *tls.ClientHelloInfo) (*tls.Config, error) {
|
|
name, parsed = h.ServerName, true
|
|
return nil, errStop
|
|
},
|
|
})
|
|
_ = c.HandshakeContext(ctx)
|
|
return name, parsed
|
|
}
|
|
|
|
// helloConn: a net.Conn that reads the recorded bytes and discards writes.
|
|
type helloConn struct{ r io.Reader }
|
|
|
|
func (c helloConn) Read(b []byte) (int, error) { return c.r.Read(b) }
|
|
func (c helloConn) Write(b []byte) (int, error) { return len(b), nil }
|
|
func (c helloConn) Close() error { return nil }
|
|
func (c helloConn) LocalAddr() net.Addr { return &net.TCPAddr{} }
|
|
func (c helloConn) RemoteAddr() net.Addr { return &net.TCPAddr{} }
|
|
func (c helloConn) SetDeadline(time.Time) error { return nil }
|
|
func (c helloConn) SetReadDeadline(time.Time) error { return nil }
|
|
func (c helloConn) SetWriteDeadline(time.Time) error { return nil }
|