Skip to content

Commit eef6139

Browse files
committed
Raise link error when SNI supplied on unsupported link type
Closes yggdrasil-network#1196
1 parent ff0ef7f commit eef6139

File tree

6 files changed

+16
-0
lines changed

6 files changed

+16
-0
lines changed

src/core/link.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ const ErrLinkPinnedKeyInvalid = linkError("pinned public key is invalid")
126126
const ErrLinkPasswordInvalid = linkError("invalid password supplied")
127127
const ErrLinkUnrecognisedSchema = linkError("link schema unknown")
128128
const ErrLinkMaxBackoffInvalid = linkError("max backoff duration invalid")
129+
const ErrLinkSNINotSupported = linkError("SNI not supported on this link type")
129130

130131
func (l *links) add(u *url.URL, sintf string, linkType linkType) error {
131132
var retErr error

src/core/link_socks.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ func (l *links) newLinkSOCKS() *linkSOCKS {
2323
}
2424

2525
func (l *linkSOCKS) dial(_ context.Context, url *url.URL, info linkInfo, options linkOptions) (net.Conn, error) {
26+
if url.Scheme != "sockstls" && options.tlsSNI != "" {
27+
return nil, ErrLinkSNINotSupported
28+
}
2629
var proxyAuth *proxy.Auth
2730
if url.User != nil && url.User.Username() != "" {
2831
proxyAuth = &proxy.Auth{

src/core/link_tcp.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ func (l *linkTCP) dialersFor(url *url.URL, info linkInfo) ([]*tcpDialer, error)
6767
}
6868

6969
func (l *linkTCP) dial(ctx context.Context, url *url.URL, info linkInfo, options linkOptions) (net.Conn, error) {
70+
if options.tlsSNI != "" {
71+
return nil, ErrLinkSNINotSupported
72+
}
7073
dialers, err := l.dialersFor(url, info)
7174
if err != nil {
7275
return nil, err

src/core/link_unix.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ func (l *links) newLinkUNIX() *linkUNIX {
3131
}
3232

3333
func (l *linkUNIX) dial(ctx context.Context, url *url.URL, info linkInfo, options linkOptions) (net.Conn, error) {
34+
if options.tlsSNI != "" {
35+
return nil, ErrLinkSNINotSupported
36+
}
3437
addr, err := net.ResolveUnixAddr("unix", url.Path)
3538
if err != nil {
3639
return nil, err

src/core/link_ws.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,9 @@ func (l *links) newLinkWS() *linkWS {
8787
}
8888

8989
func (l *linkWS) dial(ctx context.Context, url *url.URL, info linkInfo, options linkOptions) (net.Conn, error) {
90+
if options.tlsSNI != "" {
91+
return nil, ErrLinkSNINotSupported
92+
}
9093
wsconn, _, err := websocket.Dial(ctx, url.String(), &websocket.DialOptions{
9194
Subprotocols: []string{"ygg-ws"},
9295
})

src/core/link_wss.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ func (l *links) newLinkWSS() *linkWSS {
2727
}
2828

2929
func (l *linkWSS) dial(ctx context.Context, url *url.URL, info linkInfo, options linkOptions) (net.Conn, error) {
30+
if options.tlsSNI != "" {
31+
return nil, ErrLinkSNINotSupported
32+
}
3033
wsconn, _, err := websocket.Dial(ctx, url.String(), &websocket.DialOptions{
3134
Subprotocols: []string{"ygg-ws"},
3235
})

0 commit comments

Comments
 (0)