Don't assume that DoH servers use port 443
This commit is contained in:
parent
0983a86b40
commit
7f221afeff
|
@ -64,7 +64,7 @@ func ReadPrefixed(conn *net.TCPConn) ([]byte, error) {
|
|||
}
|
||||
}
|
||||
if pos >= 2+packetLength {
|
||||
return buf[2:2+packetLength], nil
|
||||
return buf[2 : 2+packetLength], nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -124,3 +124,13 @@ func StringQuote(str string) string {
|
|||
str = strconv.QuoteToGraphic(str)
|
||||
return str[1 : len(str)-1]
|
||||
}
|
||||
|
||||
func ExtractPort(str string, defaultPort int) int {
|
||||
port := defaultPort
|
||||
if idx := strings.LastIndex(str, ":"); idx >= 0 && idx < len(str)-1 {
|
||||
if portX, err := strconv.Atoi(str[idx+1:]); err == nil {
|
||||
port = portX
|
||||
}
|
||||
}
|
||||
return port
|
||||
}
|
||||
|
|
|
@ -7,7 +7,6 @@ import (
|
|||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
|
@ -311,10 +310,10 @@ func (config *Config) printRegisteredServers(proxy *Proxy, jsonOutput bool) {
|
|||
var summary []ServerSummary
|
||||
for _, registeredServer := range proxy.registeredServers {
|
||||
addrStr, port := registeredServer.stamp.serverAddrStr, DefaultPort
|
||||
if idx := strings.LastIndex(addrStr, ":"); idx >= 0 && idx < len(addrStr)-1 {
|
||||
if portX, err := strconv.Atoi(addrStr[idx+1:]); err == nil {
|
||||
port = portX
|
||||
}
|
||||
port = ExtractPort(addrStr, port)
|
||||
if registeredServer.stamp.proto == StampProtoTypeDoH && len(registeredServer.stamp.providerName) > 0 {
|
||||
providerName := registeredServer.stamp.providerName
|
||||
port = ExtractPort(providerName, port)
|
||||
}
|
||||
serverSummary := ServerSummary{
|
||||
Name: registeredServer.name,
|
||||
|
|
|
@ -143,9 +143,6 @@ func newDoHServerStamp(bin []byte) (ServerStamp, error) {
|
|||
pos++
|
||||
stamp.serverAddrStr = string(bin[pos : pos+len])
|
||||
pos += len
|
||||
if net.ParseIP(strings.TrimRight(strings.TrimLeft(stamp.serverAddrStr, "["), "]")) != nil {
|
||||
stamp.serverAddrStr = fmt.Sprintf("%s:%d", stamp.serverAddrStr, DefaultPort)
|
||||
}
|
||||
|
||||
for {
|
||||
vlen := int(bin[pos])
|
||||
|
@ -182,6 +179,11 @@ func newDoHServerStamp(bin []byte) (ServerStamp, error) {
|
|||
if pos != binLen {
|
||||
return stamp, errors.New("Invalid stamp (garbage after end)")
|
||||
}
|
||||
|
||||
if net.ParseIP(strings.TrimRight(strings.TrimLeft(stamp.serverAddrStr, "["), "]")) != nil {
|
||||
stamp.serverAddrStr = fmt.Sprintf("%s:%d", stamp.serverAddrStr, DefaultPort)
|
||||
}
|
||||
|
||||
return stamp, nil
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue