Skip to content

Commit a7bb5ea

Browse files
committed
fix: prevent copying outer server name in inner
Update ECH outer SNI during ApplyPreset instead of Marshal so that it is not copied multiple times. Do not override server name in config when ECH is enabled.
1 parent c567269 commit a7bb5ea

File tree

3 files changed

+6
-13
lines changed

3 files changed

+6
-13
lines changed

u_conn.go

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -579,18 +579,6 @@ func (uconn *UConn) MarshalClientHello() error {
579579

580580
ech.innerHello = inner
581581

582-
sniExtIdex := slices.IndexFunc(uconn.Extensions, func(ext TLSExtension) bool {
583-
_, ok := ext.(*SNIExtension)
584-
return ok
585-
})
586-
if sniExtIdex < 0 {
587-
return fmt.Errorf("sni extension missing while attempting ECH")
588-
}
589-
590-
uconn.Extensions[sniExtIdex] = &SNIExtension{
591-
ServerName: string(ech.config.PublicName),
592-
}
593-
594582
uconn.computeAndUpdateOuterECHExtension(inner, ech, true)
595583

596584
uconn.echCtx = ech

u_parrots.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2779,6 +2779,9 @@ func (uconn *UConn) ApplyPreset(p *ClientHelloSpec) error {
27792779
if ext.ServerName == "" {
27802780
ext.ServerName = uconn.config.ServerName
27812781
}
2782+
if uconn.config.EncryptedClientHelloConfigList != nil {
2783+
ext.ServerName = string(ech.config.PublicName)
2784+
}
27822785
case *UtlsGREASEExtension:
27832786
switch grease_extensions_seen {
27842787
case 0:

u_tls_extensions.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,9 @@ func (e *SNIExtension) Write(b []byte) (int, error) {
197197
}
198198

199199
func (e *SNIExtension) writeToUConn(uc *UConn) error {
200-
uc.config.ServerName = e.ServerName
200+
if uc.config.EncryptedClientHelloConfigList == nil { // with ech, e.ServerName is the outer public name and should not be copied
201+
uc.config.ServerName = e.ServerName
202+
}
201203
hostName := hostnameInSNI(e.ServerName)
202204
uc.HandshakeState.Hello.ServerName = hostName
203205

0 commit comments

Comments
 (0)