Skip to content

Commit

Permalink
Raise link error when SNI supplied on unsupported link type
Browse files Browse the repository at this point in the history
Closes #1196
  • Loading branch information
neilalexander committed Oct 27, 2024
1 parent ff0ef7f commit eef6139
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/core/link.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ const ErrLinkPinnedKeyInvalid = linkError("pinned public key is invalid")
const ErrLinkPasswordInvalid = linkError("invalid password supplied")
const ErrLinkUnrecognisedSchema = linkError("link schema unknown")
const ErrLinkMaxBackoffInvalid = linkError("max backoff duration invalid")
const ErrLinkSNINotSupported = linkError("SNI not supported on this link type")

func (l *links) add(u *url.URL, sintf string, linkType linkType) error {
var retErr error
Expand Down
3 changes: 3 additions & 0 deletions src/core/link_socks.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ func (l *links) newLinkSOCKS() *linkSOCKS {
}

func (l *linkSOCKS) dial(_ context.Context, url *url.URL, info linkInfo, options linkOptions) (net.Conn, error) {
if url.Scheme != "sockstls" && options.tlsSNI != "" {
return nil, ErrLinkSNINotSupported
}
var proxyAuth *proxy.Auth
if url.User != nil && url.User.Username() != "" {
proxyAuth = &proxy.Auth{
Expand Down
3 changes: 3 additions & 0 deletions src/core/link_tcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ func (l *linkTCP) dialersFor(url *url.URL, info linkInfo) ([]*tcpDialer, error)
}

func (l *linkTCP) dial(ctx context.Context, url *url.URL, info linkInfo, options linkOptions) (net.Conn, error) {
if options.tlsSNI != "" {
return nil, ErrLinkSNINotSupported
}
dialers, err := l.dialersFor(url, info)
if err != nil {
return nil, err
Expand Down
3 changes: 3 additions & 0 deletions src/core/link_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ func (l *links) newLinkUNIX() *linkUNIX {
}

func (l *linkUNIX) dial(ctx context.Context, url *url.URL, info linkInfo, options linkOptions) (net.Conn, error) {
if options.tlsSNI != "" {
return nil, ErrLinkSNINotSupported
}
addr, err := net.ResolveUnixAddr("unix", url.Path)
if err != nil {
return nil, err
Expand Down
3 changes: 3 additions & 0 deletions src/core/link_ws.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ func (l *links) newLinkWS() *linkWS {
}

func (l *linkWS) dial(ctx context.Context, url *url.URL, info linkInfo, options linkOptions) (net.Conn, error) {
if options.tlsSNI != "" {
return nil, ErrLinkSNINotSupported
}
wsconn, _, err := websocket.Dial(ctx, url.String(), &websocket.DialOptions{
Subprotocols: []string{"ygg-ws"},
})
Expand Down
3 changes: 3 additions & 0 deletions src/core/link_wss.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ func (l *links) newLinkWSS() *linkWSS {
}

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

0 comments on commit eef6139

Please sign in to comment.