From 7f232c5cf2dddea2a6ce26b05f6b5d739397c606 Mon Sep 17 00:00:00 2001 From: Alexey Khit Date: Mon, 28 Aug 2023 22:29:12 +0300 Subject: [PATCH] Add insecure HTTPS requests to IP addresses --- pkg/tcp/dial.go | 2 +- pkg/tcp/request.go | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/pkg/tcp/dial.go b/pkg/tcp/dial.go index 75d2f7a4..9126190c 100644 --- a/pkg/tcp/dial.go +++ b/pkg/tcp/dial.go @@ -24,7 +24,7 @@ func Dial(u *url.URL, port string, timeout time.Duration) (net.Conn, error) { switch u.Scheme { case "rtsp", "rtmp": case "rtsps", "rtspx", "rtmps", "rtmpx": - if u.Scheme[4] == 'x' || net.ParseIP(hostname) != nil { + if u.Scheme[4] == 'x' || IsIP(hostname) { secure = &tls.Config{InsecureSkipVerify: true} } else { secure = &tls.Config{ServerName: hostname} diff --git a/pkg/tcp/request.go b/pkg/tcp/request.go index 5bcbc48b..401af2eb 100644 --- a/pkg/tcp/request.go +++ b/pkg/tcp/request.go @@ -32,7 +32,7 @@ func Do(req *http.Request) (*http.Response, error) { var client *http.Client - if req.URL.Scheme == "httpx" { + if req.URL.Scheme == "httpx" || (req.URL.Scheme == "https" && IsIP(req.URL.Hostname())) { req.URL.Scheme = "https" if insecureClient == nil { @@ -125,3 +125,7 @@ func Close(res *http.Response) { _ = res.Body.Close() } } + +func IsIP(hostname string) bool { + return net.ParseIP(hostname) != nil +}