v0.26.5 minor doc update and code cleanup

This commit is contained in:
lixen committed 2026-10-05 15:12:32 -04:00
1 parent b2f11f6104
commit 6425eed5ef
8 files changed
+60 -23

No files matched your search

+3 -2
View File
@@ -35,7 +35,8 @@ const (
)
// processKey is the key of every generated listener certificate: reloads
// reissue certificates and keep it, so a pin holds until lw restarts.
// reissue certificates and keep it, so a pin holds until lw restarts, and
// matches every such listener of the process, self-signed or issued.
var processKey = sync.OnceValues(NewKey)
func NewKey() (*ecdsa.PrivateKey, error) { return ecdsa.GenerateKey(elliptic.P256(), rand.Reader) }
@@ -188,7 +189,7 @@ func pin(spki []byte) string {
// verifyPins replaces chain verification: the server's key must hash to one
// of the ';'-separated pins. Its name and validity are not checked. Go skips
// it on a resumed session, and no dialer keeps a ClientSessionCache.
// it on a resumed session, which Client therefore disables.
func verifyPins(s string) (func([][]byte, [][]*x509.Certificate) error, error) {
var pins [][]byte
for p := range strings.SplitSeq(s, ";") {
+3 -1
View File
@@ -112,7 +112,9 @@ func Client(o *config.TLSOptions, host string) (*tls.Config, error) {
if cfg.VerifyPeerCertificate, err = verifyPins(o.PinSHA256); err != nil {
return nil, err
}
cfg.InsecureSkipVerify = true // the pin check above replaces it
// The pin check replaces Go's; Go skips it on a resumed session, so a
// pinned dialer never resumes, and a pin dropped by a reload holds
cfg.InsecureSkipVerify, cfg.SessionTicketsDisabled = true, true
}
if o.CAFile != "" {
pool, err := loadPool(o.CAFile)
+45
View File
@@ -1,6 +1,7 @@
package tlsx
import (
"crypto/tls"
"crypto/x509"
"crypto/x509/pkix"
"net"
@@ -84,6 +85,50 @@ func TestSelfSignedListenerIsVerifiedByItsPin(t *testing.T) {
}
}
// Go skips the pin check on a resumed session, so a pinned dialer never
// resumes one, even given a session cache
func TestPinnedDialerNeverResumes(t *testing.T) {
server, err := Server(&config.TLSOptions{Enabled: true, SelfSigned: true}, "127.0.0.1")
if err != nil {
t.Fatal(err)
}
client, err := Client(&config.TLSOptions{Enabled: true, PinSHA256: PinSHA256(server.Certificates[0].Leaf)}, "127.0.0.1")
if err != nil {
t.Fatal(err)
}
client.ClientSessionCache = tls.NewLRUClientSessionCache(1)
ln, err := net.Listen("tcp4", "127.0.0.1:0")
if err != nil {
t.Fatal(err)
}
defer ln.Close()
go func() {
for {
conn, err := ln.Accept()
if err != nil {
return
}
conn.SetDeadline(time.Now().Add(5 * time.Second))
tconn := tls.Server(conn, server)
tconn.Write([]byte{1}) // after the handshake and its session ticket
tconn.Close()
}
}()
for i := range 2 {
conn, err := tls.Dial("tcp4", ln.Addr().String(), client)
if err != nil {
t.Fatal(err)
}
conn.SetDeadline(time.Now().Add(5 * time.Second))
_, err = conn.Read(make([]byte, 1)) // stores a ticket, if one came
resumed := conn.ConnectionState().DidResume
conn.Close()
if err != nil || resumed {
t.Fatalf("connection %d: resumed %v, %v", i+1, resumed, err)
}
}
}
// An issuer-signed listener chains to the CA file, for its host, and expires
// with its issuer; a certificate that is no CA cannot issue.
func TestIssuedListenerCertificateChainsToTheIssuer(t *testing.T) {