xmpp-certwatch
created pr with
xmpp-certwatch/deadline-patch.1
added xmpp-certwatch/deadline-patch.2
1: 7f16f12 < -: ------- Point to fork of dane
-: ------- > 1: 89cbec1 Point to fork of dane
commented
Patch applied to dane:From e2cd4b16559a4e6d42ceaf4db9123de61a59612a Mon Sep 17 00:00:00 2001
From: Eric Roberts <ericroberts@gmail.com>
Date: Mon, 26 Oct 2026 14:40:49 -0400
Subject: [PATCH] Add deadline in DialStartTLS STARTTLS negotiation
getSTARTTLSconn now applies TimeoutTCP as a connection deadline covering
the whole STARTTLS exchange and TLS handshake, and startTLSHandshake
clears it on success so the returned conn is not left with an absolute
deadline, since previously only the TCP connect was bounded and a
stalled server could hang DialStartTLS indefinitely.
---
starttls.go | 27 +++++++++++++++++++--------
utils.go | 12 ++++++++++++
2 files changed, 31 insertions(+), 8 deletions(-)
diff --git a/starttls.go b/starttls.go
index e3205b9..0b85021 100644
--- a/starttls.go
+++ b/starttls.go
@@ -4,9 +4,11 @@ import (
bufio
crypto/tls
fmt
+ net
os
strconv
strings
+ time
)
const bufsize = 2048
@@ -23,7 +25,7 @@ func DoXMPP(tlsconfig *tls.Config, daneconfig *Config) (*tls.Conn, error) {
buf := make([]byte, bufsize)
server := daneconfig.Server
- conn, err := getTCPconn(server.Ipaddr, server.Port, daneconfig.TimeoutTCP)
+ conn, err := getSTARTTLSconn(server.Ipaddr, server.Port, daneconfig.TimeoutTCP)
if err != nil {
return nil, err
}
@@ -87,7 +89,7 @@ func DoXMPP(tlsconfig *tls.Config, daneconfig *Config) (*tls.Conn, error) {
}
daneconfig.Transcript = transcript
- return TLShandshake(conn, tlsconfig)
+ return startTLSHandshake(conn, tlsconfig)
}
//
@@ -99,7 +101,7 @@ func DoPOP3(tlsconfig *tls.Config, daneconfig *Config) (*tls.Conn, error) {
var line, transcript string
server := daneconfig.Server
- conn, err := getTCPconn(server.Ipaddr, server.Port, daneconfig.TimeoutTCP)
+ conn, err := getSTARTTLSconn(server.Ipaddr, server.Port, daneconfig.TimeoutTCP)
if err != nil {
return nil, err
}
@@ -132,7 +134,7 @@ func DoPOP3(tlsconfig *tls.Config, daneconfig *Config) (*tls.Conn, error) {
}
daneconfig.Transcript = transcript
- return TLShandshake(conn, tlsconfig)
+ return startTLSHandshake(conn, tlsconfig)
}
//
@@ -145,7 +147,7 @@ func DoIMAP(tlsconfig *tls.Config, daneconfig *Config) (*tls.Conn, error) {
var line, transcript string
server := daneconfig.Server
- conn, err := getTCPconn(server.Ipaddr, server.Port, daneconfig.TimeoutTCP)
+ conn, err := getSTARTTLSconn(server.Ipaddr, server.Port, daneconfig.TimeoutTCP)
if err != nil {
return nil, err
}
@@ -202,7 +204,7 @@ func DoIMAP(tlsconfig *tls.Config, daneconfig *Config) (*tls.Conn, error) {
}
daneconfig.Transcript = transcript
- return TLShandshake(conn, tlsconfig)
+ return startTLSHandshake(conn, tlsconfig)
}
//
@@ -236,7 +238,7 @@ func DoSMTP(tlsconfig *tls.Config, daneconfig *Config) (*tls.Conn, error) {
var responseDone, gotSTARTTLS bool
server := daneconfig.Server
- conn, err := getTCPconn(server.Ipaddr, server.Port, daneconfig.TimeoutTCP)
+ conn, err := getSTARTTLSconn(server.Ipaddr, server.Port, daneconfig.TimeoutTCP)
if err != nil {
return nil, err
}
@@ -320,7 +322,16 @@ func DoSMTP(tlsconfig *tls.Config, daneconfig *Config) (*tls.Conn, error) {
}
daneconfig.Transcript = transcript
- return TLShandshake(conn, tlsconfig)
+ return startTLSHandshake(conn, tlsconfig)
+}
+
+func startTLSHandshake(conn net.Conn, tlsconfig *tls.Config) (*tls.Conn, error) {
+
+ tlsconn, err := TLShandshake(conn, tlsconfig)
+ if err == nil {
+ _ = conn.SetDeadline(time.Time{})
+ }
+ return tlsconn, err
}
//
diff --git a/utils.go b/utils.go
index 0fa4f20..ce4ef72 100644
--- a/utils.go
+++ b/utils.go
@@ -45,6 +45,18 @@ func getTCPconn(address net.IP, port int, timeout int) (net.Conn, error) {
return conn, err
}
+func getSTARTTLSconn(address net.IP, port int, timeout int) (net.Conn, error) {
+
+ conn, err := getTCPconn(address, port, timeout)
+ if err != nil {
+ return nil, err
+ }
+ if timeout > 0 {
+ _ = conn.SetDeadline(time.Now().Add(time.Second * time.Duration(timeout)))
+ }
+ return conn, nil
+}
+
//
// CertToPEMBytes returns PEM encoded bytes corresponding to the given
// x.509 certificate.
--
2.55.0
cmds
checkout latest patchset:
ssh pr.pico.sh pull xmpp-certwatch:deadline-patch | git am -3checkout specific patchset revision:
ssh pr.pico.sh pull xmpp-certwatch:deadline-patch [rev] | git am -3add changes to patch request:
git format-patch main --stdout | ssh pr.pico.sh xmpp-certwatch:deadline-patchadd comment to patch request:
ssh pr.pico.sh comment xmpp-certwatch:deadline-patch "lgtm!"
Patchset
xmpp-certwatch/deadline-patch.2
Point to fork of dane
Eric Roberts
2026-10-26T18:48:44ZWhich adds deadline for dialStartTLS and should hopefully fix our issue.
Semantic diff summary
0 added,
0 modified,
0 signature changed,
0 removed
across 0 analyzed files
(2 files skipped: unsupported file type)
+2
-0
go.mod
#
+2
-0
go.sum
#
| ... | ... | @@ -50,3 +50,5 @@ mellium.im/xmlstream v0.15.4 h1:gLKxcWl4rLMUpKgtzrTBvr4OexPeO/edYus+uK3F6ZI= | |
| 50 | 50 | mellium.im/xmlstream v0.15.4/go.mod h1:yXaCW2++fmVO4L9piKVkyLDqnCmictVYF7FDQW8prb4= | |
| 51 | 51 | mellium.im/xmpp v0.21.4 h1:hhAGFC/mGt2Bbmx46vPn+kQT0pJec7uaq+9xckkr9uI= | |
| 52 | 52 | mellium.im/xmpp v0.21.4/go.mod h1:Emo7bXXyEEgH2hdTO9zp9eGJoc9yK5dAlG0/YVJlh+U= | |
| 53 | + | tangled.org/mrry.band/dane v0.0.0-20261026184049-e2cd4b16559a h1:q6Talb03OQYFjSrfuzfxKILRqq4HI6ZnleLONA0eQYk= | |
| 54 | + | tangled.org/mrry.band/dane v0.0.0-20261026184049-e2cd4b16559a/go.mod h1:073qaSQS+yVGykJJezTRYcA+leXW1MH7uvvq5ZCeosw= |