ShadowTLS v3: incorrect HMAC ordering in WriteVectorised causes connections to fail during downloads

Aperta Adatta ai principianti
#7 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
76/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Tranquilla
Stack tecnologico
go
Ambito
networking

Direzione di ricerca

Inizia da v3_conn.go, in verifiedConn.WriteVectorised, e confronta l'ordine di aggiornamento dell'HMAC con i metodi ordinari write e WriteBuffer e con verifyApplicationData. La issue indica le righe esatte e un riordino proposto. Il lavoro è completo quando un test di regressione alterna chiamate a Write e WriteVectorised, rilegge poi i record tramite un verifiedConn corrispondente e passa in entrambi gli ordini di chiamata.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Description

SS2022 over ShadowTLS v3 connections initially work, but downloads are interrupted. The client reports:

connection: connection download closed: application data verification failed

Browsers also report ERR_CONTENT_LENGTH_MISMATCH.

Disabling vectorised writes on the server's authenticated ShadowTLS connection resolves the issue.

Environment
  • Server: custom sing-box fork
  • sing-shadowtls dependency: v0.2.2-0.20260928201441-a9c0127d5c99
  • Clients tested: mihomo v1.19.32 and sing-box v1.14.3
  • Protocol: Shadowsocks 2022 (2022-blake3-aes-128-gcm) over ShadowTLS v3
  • The server forwards the inner Shadowsocks stream to Xray over local TCP.
Root cause

In v3_conn.go, verifiedConn.WriteVectorised advances the HMAC state before obtaining the authentication tag that is sent:

c.hmacAdd.Write(c.hmacAdd.Sum(nil)[:hmacSize])
hmacHash := c.hmacAdd.Sum(nil)[:hmacSize]

The receiver's verifyApplicationData computes the expected tag before advancing the state. Consequently, a frame produced by WriteVectorised fails verification.

The ordinary write and WriteBuffer methods use the correct ordering.

Proposed fix
- c.hmacAdd.Write(c.hmacAdd.Sum(nil)[:hmacSize])
  hmacHash := c.hmacAdd.Sum(nil)[:hmacSize]
+ c.hmacAdd.Write(hmacHash)
Reproduction and validation

A regression test alternates ordinary Write and WriteVectorised calls, then reads the generated records through another verifiedConn with matching initial HMAC state.

Both sequences fail before the fix:

  • Vectorised write first.
  • Ordinary write first, followed by vectorised write.

Both sequences pass after correcting the ordering.

In the deployed server, wrapping the ShadowTLS connection to make CreateVectorisedWriter return (nil, false) also eliminates the observed download failures.

Why connections initially work

The sing copy implementation can switch to vectorised reads/writes after transferring 512,000 bytes in one direction, provided both ends support the required interfaces. This explains why small transfers can succeed while larger downloads fail.

Lingua principale
Go
Stelle
24
Fork
19
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di SagerNet/sing-shadowtls

Tutte le issue di SagerNet/sing-shadowtls

Issue simili

Altre issue su Go

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.