b00e2d8955
dcs.MTProxy expects raw secret bytes. Carrying them verbatim through a YAML string field is impossible: real secrets contain bytes >= 0x80 (faketls starts with 0xee, secured with 0xdd) which cannot survive a unicode string round-trip, so the value reached the bridge corrupted or empty (gotd then logged "invalid secret"). Accept the standard hex form printed by mtg/MTProxy tooling (e.g. "ee" + 16-byte secret + cloak domain hex) and decode it before handing the bytes to gotd. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
38 lines
1.0 KiB
Go
38 lines
1.0 KiB
Go
package connector
|
|
|
|
import (
|
|
"bytes"
|
|
"testing"
|
|
)
|
|
|
|
func TestDecodeMTProxySecret(t *testing.T) {
|
|
// faketls secret: 0xee + 16 bytes + cloak domain ("working-name.ru" = 15 bytes)
|
|
hexSecret := "ee971746d927f4c0138b18447bfe1269bc70312e776f726b696e672d6e616d652e7275"
|
|
want := []byte{
|
|
0xee,
|
|
0x97, 0x17, 0x46, 0xd9, 0x27, 0xf4, 0xc0, 0x13,
|
|
0x8b, 0x18, 0x44, 0x7b, 0xfe, 0x12, 0x69, 0xbc,
|
|
0x70, 0x31, 0x2e, 0x77, 0x6f, 0x72, 0x6b, 0x69,
|
|
0x6e, 0x67, 0x2d, 0x6e, 0x61, 0x6d, 0x65, 0x2e,
|
|
0x72, 0x75,
|
|
}
|
|
got, err := decodeMTProxySecret(hexSecret)
|
|
if err != nil {
|
|
t.Fatalf("unexpected error: %v", err)
|
|
}
|
|
if !bytes.Equal(got, want) {
|
|
t.Fatalf("decoded bytes mismatch:\n got=%x\nwant=%x", got, want)
|
|
}
|
|
|
|
if _, err := decodeMTProxySecret(" " + hexSecret + "\n"); err != nil {
|
|
t.Fatalf("whitespace should be tolerated: %v", err)
|
|
}
|
|
|
|
if _, err := decodeMTProxySecret(""); err == nil {
|
|
t.Fatal("expected error for empty secret")
|
|
}
|
|
if _, err := decodeMTProxySecret("not-hex!!"); err == nil {
|
|
t.Fatal("expected error for non-hex secret")
|
|
}
|
|
}
|