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

Abierto Apto para principiantes
#7 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
76/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Tranquilo
Stack tecnológico
go
Área
networking

Línea de trabajo

Empieza en v3_conn.go, en verifiedConn.WriteVectorised, y compara su orden de actualización del HMAC con los métodos habituales write y WriteBuffer, y con verifyApplicationData. El issue indica las líneas exactas y una reordenación propuesta. Se considera terminado cuando existe una prueba de regresión que alterna llamadas a Write y WriteVectorised, luego lee los registros de vuelta a través de un verifiedConn correspondiente y pasa en ambos órdenes de llamada.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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.

Lenguaje dominante
Go
Estrellas
24
Forks
19
Métricas de merge de PR
Sin PR fusionados en 30 d

Preparar el entorno

Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de SagerNet/sing-shadowtls

Todos los issues de SagerNet/sing-shadowtls

Issues similares

Más issues de Go

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.