Skip to content

Commit d8ccbd6

Browse files
committed
dns: add ALPN to synthetic HTTPS records for ECH
When using local ECH config, the synthetic HTTPS record only contained ECH parameter without ALPN. Due to ECH spec requirements (svcb_optional=false), Chromium strictly validates DNS ALPN, causing QUIC connections to fail with ERR_DNS_NO_MATCHING_SUPPORTED_ALPN since default "http/1.1" doesn't match "h3". Now adds proper ALPN: "h3" for QUIC mode, "h2" for HTTP/2 mode.
1 parent 7f2b295 commit d8ccbd6

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

naive_client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ func (c *NaiveClient) Start() error {
204204
if echQueryServerName == "" {
205205
echQueryServerName = c.serverName
206206
}
207-
dnsResolver = wrapDNSResolverWithECH(dnsResolver, c.serverName, echQueryServerName, c.getECHConfigList)
207+
dnsResolver = wrapDNSResolverWithECH(dnsResolver, c.serverName, echQueryServerName, c.getECHConfigList, c.quicEnabled)
208208
}
209209

210210
engine.SetDialer(func(address string, port uint16) int {

naive_dns.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,14 +180,21 @@ func wrapDNSResolverWithECH(
180180
serverName string,
181181
echQueryServerName string,
182182
echConfigGetter func() []byte,
183+
quicEnabled bool,
183184
) DNSResolverFunc {
184185
return func(ctx context.Context, request *mDNS.Msg) *mDNS.Msg {
185186
if len(request.Question) > 0 {
186187
question := request.Question[0]
187188
if question.Qtype == mDNS.TypeHTTPS && matchesServerName(question.Name, serverName) {
188189
echConfig := echConfigGetter()
189190
if len(echConfig) > 0 {
190-
return injectECHConfig(request, nil, echConfig)
191+
var alpn []string
192+
if quicEnabled {
193+
alpn = []string{"h3"}
194+
} else {
195+
alpn = []string{"h2"}
196+
}
197+
return injectECHConfig(request, nil, echConfig, alpn)
191198
}
192199

193200
var response *mDNS.Msg
@@ -271,7 +278,7 @@ func matchesServerName(queryName, serverName string) bool {
271278
return false
272279
}
273280

274-
func injectECHConfig(request *mDNS.Msg, response *mDNS.Msg, echConfig []byte) *mDNS.Msg {
281+
func injectECHConfig(request *mDNS.Msg, response *mDNS.Msg, echConfig []byte, alpn []string) *mDNS.Msg {
275282
if response == nil {
276283
response = new(mDNS.Msg)
277284
response.SetReply(request)
@@ -307,6 +314,7 @@ func injectECHConfig(request *mDNS.Msg, response *mDNS.Msg, echConfig []byte) *m
307314
Target: targetName,
308315
},
309316
}
317+
https.Value = append(https.Value, &mDNS.SVCBAlpn{Alpn: alpn})
310318
https.Value = append(https.Value, &mDNS.SVCBECHConfig{ECH: echConfig})
311319
response.Answer = append(response.Answer, https)
312320
}

0 commit comments

Comments
 (0)