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

Commit fa33bde

Browse files
authored
fix: Add TLS option to DialICE (#330)
* fix: Add TLS option to DialICE * Fix DialICE timeout arg
1 parent 8d46612 commit fa33bde

File tree

4 files changed

+35
-12
lines changed

4 files changed

+35
-12
lines changed

internal/cmd/tunnel.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ func (c *tunnneler) start(ctx context.Context) error {
111111
CredentialType: webrtc.ICECredentialTypePassword,
112112
}
113113

114-
err := wsnet.DialICE(server, 0)
114+
err := wsnet.DialICE(server, nil)
115115
if errors.Is(err, wsnet.ErrInvalidCredentials) {
116116
return xerrors.Errorf("failed to authenticate your user for this workspace")
117117
}

wsnet/dial_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ func ExampleDial_basic() {
2020
}}
2121

2222
for _, server := range servers {
23-
err := DialICE(server, 0)
23+
err := DialICE(server, nil)
2424
if errors.Is(err, ErrInvalidCredentials) {
2525
// You could do something...
2626
}

wsnet/rtc.go

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,30 @@ var (
3131
controlChannel = "control"
3232
)
3333

34+
// DialICEOptions provides options for dialing an ICE server.
35+
type DialICEOptions struct {
36+
Timeout time.Duration
37+
// Whether to ignore TLS errors.
38+
InsecureSkipVerify bool
39+
}
40+
3441
// DialICE confirms ICE servers are dialable.
3542
// Timeout defaults to 200ms.
36-
func DialICE(server webrtc.ICEServer, timeout time.Duration) error {
43+
func DialICE(server webrtc.ICEServer, options *DialICEOptions) error {
44+
if options == nil {
45+
options = &DialICEOptions{}
46+
}
47+
3748
for _, rawURL := range server.URLs {
38-
err := dialICEURL(server, rawURL, timeout)
49+
err := dialICEURL(server, rawURL, options)
3950
if err != nil {
4051
return err
4152
}
4253
}
4354
return nil
4455
}
4556

46-
func dialICEURL(server webrtc.ICEServer, rawURL string, timeout time.Duration) error {
57+
func dialICEURL(server webrtc.ICEServer, rawURL string, options *DialICEOptions) error {
4758
url, err := ice.ParseURL(rawURL)
4859
if err != nil {
4960
return err
@@ -69,13 +80,13 @@ func dialICEURL(server webrtc.ICEServer, rawURL string, timeout time.Duration) e
6980
return resErr
7081
}
7182
dconn, dialErr := dtls.Dial("udp4", udpAddr, &dtls.Config{
72-
InsecureSkipVerify: true,
83+
InsecureSkipVerify: options.InsecureSkipVerify,
7384
})
7485
err = dialErr
7586
udpConn = turn.NewSTUNConn(dconn)
7687
case ice.ProtoTypeTCP:
7788
tcpConn, err = tls.Dial("tcp4", turnServerAddr, &tls.Config{
78-
InsecureSkipVerify: true,
89+
InsecureSkipVerify: options.InsecureSkipVerify,
7990
})
8091
}
8192
}
@@ -100,7 +111,7 @@ func dialICEURL(server webrtc.ICEServer, rawURL string, timeout time.Duration) e
100111
Password: pass,
101112
Realm: "",
102113
Conn: udpConn,
103-
RTO: timeout,
114+
RTO: options.Timeout,
104115
})
105116
if err != nil {
106117
return err

wsnet/rtc_test.go

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@ func TestDialICE(t *testing.T) {
2222
Username: "example",
2323
Credential: "test",
2424
CredentialType: webrtc.ICECredentialTypePassword,
25-
}, time.Millisecond)
25+
}, &DialICEOptions{
26+
Timeout: time.Millisecond,
27+
InsecureSkipVerify: true,
28+
})
2629
if err != nil {
2730
t.Error(err)
2831
}
@@ -37,7 +40,10 @@ func TestDialICE(t *testing.T) {
3740
Username: "example",
3841
Credential: "test",
3942
CredentialType: webrtc.ICECredentialTypePassword,
40-
}, time.Millisecond)
43+
}, &DialICEOptions{
44+
Timeout: time.Millisecond,
45+
InsecureSkipVerify: true,
46+
})
4147
if !errors.Is(err, ErrMismatchedProtocol) {
4248
t.Error(err)
4349
}
@@ -52,7 +58,10 @@ func TestDialICE(t *testing.T) {
5258
Username: "example",
5359
Credential: "invalid",
5460
CredentialType: webrtc.ICECredentialTypePassword,
55-
}, time.Millisecond)
61+
}, &DialICEOptions{
62+
Timeout: time.Millisecond,
63+
InsecureSkipVerify: true,
64+
})
5665
if !errors.Is(err, ErrInvalidCredentials) {
5766
t.Error(err)
5867
}
@@ -63,7 +72,10 @@ func TestDialICE(t *testing.T) {
6372

6473
err := DialICE(webrtc.ICEServer{
6574
URLs: []string{"turn:stun.l.google.com:19302"},
66-
}, time.Millisecond)
75+
}, &DialICEOptions{
76+
Timeout: time.Millisecond,
77+
InsecureSkipVerify: true,
78+
})
6779
if !errors.Is(err, ErrMismatchedProtocol) {
6880
t.Error(err)
6981
}

0 commit comments

Comments
 (0)