Source code reading and implementation learning
Shadowsocks Go
Eric-Guo Github
@ericguo Ruby-China
@ecguo Twiter
2017-06-20
What’s Shadowsocks
❖ https://shadowsocks.org/en/spec/Protocol.html
❖ Shadowsocks is a secure split proxy loosely based on SOCKS5.
❖ client <---> ss-local <--[encrypted]--> ss-remote <---> target
Shadowsocks vs …
❖ StrongSwan
❖ OpenVPN
❖ PPTP
❖ sshuttle
SS is abbreviation of ShadowSocks
SS vs SSR
https://github.com/shadowsocks/shadowsocks
https://www.zybuluo.com/yiranphp/note/632579
https://github.com/shadowsocksr/shadowsocksr
https://github.com/breakwa11/shadowsocks-
rss/issues/38#issuecomment-243106134
Shadowsocks Implementation
❖ https://shadowsocks.org/en/spec/Implementations.html
❖ Python
❖ C
❖ Node.js
❖ Go
❖ Ruby
❖ Erlang
Shadowsocks Enhance
❖ DNS (UDP) relay
❖ OTA
❖ AEAD
❖ kcptun
❖ obfsplugin
Shadowsocks Go
❖ Client & Server
❖ Original SS
❖ OTA (deprecated)
❖ UDP relay on server side support
Code Reading - server main
❖ cmd/shadowsocks-server/server.go:312 run(port, password string)
❖ To listen the incoming link from ss client
❖ cmd/shadowsocks-server/server.go:111 handleConnection(conn *ss.Conn)
❖ Parse incoming conn, Dial to remote, Pipe line both conn and remote
❖ cmd/shadowsocks-server/server.go:18 PipeThenClose(src, dst net.Conn)
❖ Read src and Write to dst
Code Reading - parse incoming conn
❖ Three type of typeIPv4, typeIPv6 and typeDm.
❖ typeDm used in browser
Code Reading - ss.NewConn
❖ shadowsocks-go/shadowsocks/conn.go
❖ shadowsocks-go/shadowsocks/encrypt.go

Shadowsocks Go

  • 1.
    Source code readingand implementation learning Shadowsocks Go Eric-Guo Github @ericguo Ruby-China @ecguo Twiter 2017-06-20
  • 2.
    What’s Shadowsocks ❖ https://shadowsocks.org/en/spec/Protocol.html ❖Shadowsocks is a secure split proxy loosely based on SOCKS5. ❖ client <---> ss-local <--[encrypted]--> ss-remote <---> target
  • 3.
    Shadowsocks vs … ❖StrongSwan ❖ OpenVPN ❖ PPTP ❖ sshuttle
  • 4.
    SS is abbreviationof ShadowSocks SS vs SSR https://github.com/shadowsocks/shadowsocks https://www.zybuluo.com/yiranphp/note/632579 https://github.com/shadowsocksr/shadowsocksr https://github.com/breakwa11/shadowsocks- rss/issues/38#issuecomment-243106134
  • 5.
  • 6.
    Shadowsocks Enhance ❖ DNS(UDP) relay ❖ OTA ❖ AEAD ❖ kcptun ❖ obfsplugin
  • 7.
    Shadowsocks Go ❖ Client& Server ❖ Original SS ❖ OTA (deprecated) ❖ UDP relay on server side support
  • 8.
    Code Reading -server main ❖ cmd/shadowsocks-server/server.go:312 run(port, password string) ❖ To listen the incoming link from ss client ❖ cmd/shadowsocks-server/server.go:111 handleConnection(conn *ss.Conn) ❖ Parse incoming conn, Dial to remote, Pipe line both conn and remote ❖ cmd/shadowsocks-server/server.go:18 PipeThenClose(src, dst net.Conn) ❖ Read src and Write to dst
  • 9.
    Code Reading -parse incoming conn ❖ Three type of typeIPv4, typeIPv6 and typeDm. ❖ typeDm used in browser
  • 10.
    Code Reading -ss.NewConn ❖ shadowsocks-go/shadowsocks/conn.go ❖ shadowsocks-go/shadowsocks/encrypt.go