Skip to content
This repository was archived by the owner on May 6, 2024. It is now read-only.

Commit d0b2784

Browse files
author
Ben Schwartz
committed
Switch to UTF-8 for -proxyPrefix
1 parent 10b8873 commit d0b2784

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

outline/electron/main.go

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import (
1818
"flag"
1919
"fmt"
2020
"io"
21-
"net/url"
2221
"os"
2322
"os/signal"
2423
"strings"
@@ -69,7 +68,7 @@ func main() {
6968
args.proxyPort = flag.Int("proxyPort", 0, "Shadowsocks proxy port number")
7069
args.proxyPassword = flag.String("proxyPassword", "", "Shadowsocks proxy password")
7170
args.proxyCipher = flag.String("proxyCipher", "chacha20-ietf-poly1305", "Shadowsocks proxy encryption cipher")
72-
args.proxyPrefix = flag.String("proxyPrefix", "", "Shadowsocks connection prefix, URI-encoded (unsafe)")
71+
args.proxyPrefix = flag.String("proxyPrefix", "", "Shadowsocks connection prefix, UTF8-encoded (unsafe)")
7372
args.logLevel = flag.String("logLevel", "info", "Logging level: debug|info|warn|error|none")
7473
args.dnsFallback = flag.Bool("dnsFallback", false, "Enable DNS fallback over TCP (overrides the UDP handler).")
7574
args.checkConnectivity = flag.Bool("checkConnectivity", false, "Check the proxy TCP and UDP connectivity and exit.")
@@ -99,18 +98,25 @@ func main() {
9998
os.Exit(oss.IllegalConfiguration)
10099
}
101100

102-
prefix, err := url.PathUnescape(*args.proxyPrefix)
103-
if err != nil {
104-
log.Errorf("\"%s\" could not be URI-decoded", *args.proxyPrefix)
105-
os.Exit(oss.IllegalConfiguration)
106-
}
107101
config := oss.Config{
108102
Host: *args.proxyHost,
109103
Port: *args.proxyPort,
110104
Password: *args.proxyPassword,
111105
CipherName: *args.proxyCipher,
112-
Prefix: []byte(prefix),
113106
}
107+
108+
// The prefix is an 8-bit-clean byte sequence, stored in the codepoint
109+
// values of a unicode string, which arrives here encoded in UTF-8.
110+
prefixRunes := []rune(*args.proxyPrefix)
111+
config.Prefix = make([]byte, len(prefixRunes))
112+
for i, r := range prefixRunes {
113+
if (r & 0xFF) != r {
114+
log.Errorf("Character out of range: %r", r)
115+
os.Exit(oss.IllegalConfiguration)
116+
}
117+
config.Prefix[i] = byte(r)
118+
}
119+
114120
client, err := oss.NewClient(&config)
115121
if err != nil {
116122
log.Errorf("Failed to construct Shadowsocks client: %v", err)

0 commit comments

Comments
 (0)