Allow self-signed certs when using a SAMv3 dialer, disallow non-I2P hosts

This commit is contained in:
eyedeekay 2023-11-20 19:00:14 -05:00
parent b9c605abf0
commit 05816a206b

View file

@ -17,7 +17,9 @@ package main
import ( import (
"bytes" "bytes"
"context" "context"
"crypto/tls"
"embed" "embed"
"fmt"
"net" "net"
"net/http" "net/http"
"net/url" "net/url"
@ -58,13 +60,7 @@ func Dial(network, addr string) (net.Conn, error) {
if strings.HasSuffix(url.Host, ".i2p") { if strings.HasSuffix(url.Host, ".i2p") {
return sam.Dial(network, addr) return sam.Dial(network, addr)
} }
ip := net.ParseIP(url.Host) return nil, fmt.Errorf("unknown network %s or address %s", network, url)
if ip != nil {
if ip.IsLoopback() {
return net.Dial(network, addr)
}
}
return net.Dial(network, addr)
} }
//go:embed static/*.gotmpl //go:embed static/*.gotmpl
@ -81,6 +77,9 @@ func SetupAndServeHTTPS(
httpClient := &http.Client{ httpClient := &http.Client{
Transport: &http.Transport{ Transport: &http.Transport{
Dial: Dial, Dial: Dial,
TLSClientConfig: &tls.Config{
InsecureSkipVerify: true,
},
}, },
} }