[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [pluggable-transports/snowflake] 03/03: Filter out non stun: server addresses in ParseIceServers



This is an automated email from the git hooks/post-receive script.

itchyonion pushed a commit to branch main
in repository pluggable-transports/snowflake.

commit 990fcb41274f8d983c23b035636a22e4491290d8
Author: itchyonion <itchyonion@xxxxxxxxxxxxxx>
AuthorDate: Wed Jan 4 15:25:52 2023 -0800

    Filter out non stun: server addresses in ParseIceServers
---
 client/lib/lib_test.go  | 17 ++++-------------
 client/lib/snowflake.go | 21 +++++++++++++++++----
 2 files changed, 21 insertions(+), 17 deletions(-)

diff --git a/client/lib/lib_test.go b/client/lib/lib_test.go
index 93fe0ad..d53482c 100644
--- a/client/lib/lib_test.go
+++ b/client/lib/lib_test.go
@@ -190,22 +190,13 @@ func TestICEServerParser(t *testing.T) {
 			length int
 		}{
 			{
-				[]string{"stun:stun.l.google.com:19302"},
-				[][]string{[]string{"stun:stun.l.google.com:19302"}},
-				1,
-			},
-			{
-				[]string{"stun:stun.l.google.com", "stuns:stun.ekiga.net"},
-				[][]string{[]string{"stun:stun.l.google.com:3478"}, []string{"stuns:stun.ekiga.net:5349"}},
-				2,
-			},
-			{
-				[]string{"stuns:stun.l.google.com:19302", "turn:relay.metered.ca:80"},
-				[][]string{[]string{"stuns:stun.l.google.com:19302"}, []string{"turn:relay.metered.ca:80?transport=udp"}},
+				[]string{"stun:stun.l.google.com:19302", "stun:stun.ekiga.net"},
+				[][]string{[]string{"stun:stun.l.google.com:19302"}, []string{"stun:stun.ekiga.net:3478"}},
 				2,
 			},
 			{
-				[]string{"stun:stun1.l.google.com:19302", "stun.ekiga.net", "stun:stun.example.com:1234/path?query", "https://example.com"},
+				[]string{"stun:stun1.l.google.com:19302", "stun.ekiga.net", "stun:stun.example.com:1234/path?query",
+					"https://example.com";, "turn:relay.metered.ca:80?transport=udp"},
 				[][]string{[]string{"stun:stun1.l.google.com:19302"}},
 				1,
 			},
diff --git a/client/lib/snowflake.go b/client/lib/snowflake.go
index 5d19c55..cc0005c 100644
--- a/client/lib/snowflake.go
+++ b/client/lib/snowflake.go
@@ -31,6 +31,7 @@ import (
 	"log"
 	"math/rand"
 	"net"
+	"net/url"
 	"strings"
 	"time"
 
@@ -268,13 +269,25 @@ func parseIceServers(addresses []string) []webrtc.ICEServer {
 	if len(addresses) == 0 {
 		return nil
 	}
-	for _, url := range addresses {
-		url = strings.TrimSpace(url)
+	for _, address := range addresses {
+		address = strings.TrimSpace(address)
+
+		// ice.ParseURL recognizes many types of ICE servers,
+		// but we only support stun over UDP currently
+		u, err := url.Parse(address)
+		if err != nil {
+			log.Printf("Warning: Parsing ICE server %v resulted in error: %v, skipping", address, err)
+			continue
+		}
+		if u.Scheme != "stun" {
+			log.Printf("Warning: Only stun: (STUN over UDP) servers are supported currently, skipping %v", address)
+			continue
+		}
 
 		// add default port, other sanity checks
-		parsedURL, err := ice.ParseURL(url)
+		parsedURL, err := ice.ParseURL(address)
 		if err != nil {
-			log.Printf("Warning: Parsing ICE server %v resulted in error: %v, skipping", url, err)
+			log.Printf("Warning: Parsing ICE server %v resulted in error: %v, skipping", address, err)
 			continue
 		}
 

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits