Skip to content

Commit

Permalink
Fix AEAD multi-user service not working with packet
Browse files Browse the repository at this point in the history
  • Loading branch information
wwqgtxx authored Jul 5, 2024
1 parent a9d165b commit e3930e4
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion shadowaead/service_multi.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ func (s *MultiService[U]) newPacket(ctx context.Context, conn N.PacketConn, buff
}
var readCipher cipher.AEAD
var err error
decrypted := make([]byte, 0, buffer.Len())
for u, m := range s.methodMap {
key := buf.NewSize(m.keySaltLength)
Kdf(m.key, buffer.To(m.keySaltLength), key)
Expand All @@ -168,13 +169,14 @@ func (s *MultiService[U]) newPacket(ctx context.Context, conn N.PacketConn, buff
return err
}
var packet []byte
packet, err = readCipher.Open(buffer.Index(m.keySaltLength), rw.ZeroBytes[:readCipher.NonceSize()], buffer.From(m.keySaltLength), nil)
packet, err = readCipher.Open(decrypted, rw.ZeroBytes[:readCipher.NonceSize()], buffer.From(m.keySaltLength), nil)
if err != nil {
continue
}

buffer.Advance(m.keySaltLength)
buffer.Truncate(len(packet))
copy(buffer.Bytes(), packet)

user, method = u, m
break
Expand Down

0 comments on commit e3930e4

Please sign in to comment.