Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b39f0c30ef | ||
|
|
c1753a6d19 | ||
|
|
8f384eaac4 | ||
|
|
1a29ab0046 | ||
|
|
0ffec7df7f | ||
|
|
876b2d2588 |
@@ -31,7 +31,12 @@
|
||||
|
||||
|
||||
# 更新日志
|
||||
|
||||
- 2026-03-27 v0.26.32
|
||||
- 修复:
|
||||
- 客户端注册参数未正确处理[快捷启动命令]和[TLS快捷启动命令] [#303](https://github.com/yisier/nps/issues/303)
|
||||
- 修复https反向代理bug,感谢[okawao](https://github.com/okawao) 的 PR
|
||||
|
||||
|
||||
- 2026-03-23 v0.26.31
|
||||
- 新增:
|
||||
- 域名解析记录开关功能 [#314](https://github.com/yisier/nps/issues/314)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#/bash/sh
|
||||
export VERSION=0.26.31
|
||||
export VERSION=0.26.32
|
||||
export GOPROXY=direct
|
||||
|
||||
sudo apt-get update
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
},
|
||||
"info": {
|
||||
"productName": "NPS Client",
|
||||
"productVersion": "0.26.31",
|
||||
"productVersion": "0.26.32",
|
||||
"companyName": "NPS",
|
||||
"copyright": "Copyright © 2026 NPS"
|
||||
},
|
||||
|
||||
+6
-1
@@ -410,8 +410,13 @@ func systemService(flag string) {
|
||||
|
||||
for _, item := range cmdArray {
|
||||
array := strings.Fields(item)
|
||||
// tls
|
||||
|
||||
tls := "false"
|
||||
if len(array) > 2 {
|
||||
tls = array[2]
|
||||
}
|
||||
// tls
|
||||
if tls == "-tls_enable=true" || tls == "true" {
|
||||
systemPro(flag, array[0], array[1], true)
|
||||
} else {
|
||||
systemPro(flag, array[0], array[1], false)
|
||||
|
||||
@@ -377,6 +377,13 @@ func (s *DbUtils) GetInfoByHost(host string, r *http.Request) (h *Host, err erro
|
||||
if v.Location == "" {
|
||||
v.Location = "/"
|
||||
}
|
||||
// "*" means SNI-based HTTPS lookup where actual URI is unknown, skip location filter
|
||||
if r.RequestURI == "*" {
|
||||
if h == nil || (len(v.Location) > len(h.Location)) {
|
||||
h = v
|
||||
}
|
||||
continue
|
||||
}
|
||||
if strings.Index(r.RequestURI, v.Location) == 0 {
|
||||
if h == nil || (len(v.Location) > len(h.Location)) {
|
||||
h = v
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package version
|
||||
|
||||
const VERSION = "0.26.31"
|
||||
const VERSION = "0.26.32"
|
||||
|
||||
// Compulsory minimum version, Minimum downward compatibility to this version
|
||||
func GetVersion() string {
|
||||
|
||||
+61
-13
@@ -1,6 +1,7 @@
|
||||
package proxy
|
||||
|
||||
import (
|
||||
"io"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/url"
|
||||
@@ -38,10 +39,14 @@ func (https *HttpsServer) Start() error {
|
||||
|
||||
conn.Accept(https.listener, func(c net.Conn) {
|
||||
serverName, rb := GetServerNameFromClientHello(c)
|
||||
if serverName == "" {
|
||||
serverName = getFallbackServerName()
|
||||
logs.Debug("https fallback server name result, remote addr %s, server name %q", c.RemoteAddr().String(), serverName)
|
||||
}
|
||||
r := buildHttpsRequest(serverName)
|
||||
if host, err := file.GetDb().GetInfoByHost(serverName, r); err != nil {
|
||||
c.Close()
|
||||
logs.Debug("the url %s can't be parsed!,remote addr %s", serverName, c.RemoteAddr().String())
|
||||
logs.Debug("https host lookup failed, server name %q, remote addr %s, error %v", serverName, c.RemoteAddr().String(), err)
|
||||
return
|
||||
} else {
|
||||
if host.CertFilePath == "" || host.KeyFilePath == "" {
|
||||
@@ -140,6 +145,35 @@ func (https *HttpsServer) Start() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func getFallbackServerName() string {
|
||||
global := file.GetDb().GetGlobal()
|
||||
if global == nil {
|
||||
return ""
|
||||
}
|
||||
serverName := strings.TrimSpace(global.ServerUrl)
|
||||
if serverName == "" {
|
||||
return ""
|
||||
}
|
||||
if strings.Contains(serverName, "://") {
|
||||
if u, err := url.Parse(serverName); err == nil && u.Host != "" {
|
||||
serverName = u.Host
|
||||
}
|
||||
}
|
||||
if i := strings.Index(serverName, "/"); i >= 0 {
|
||||
serverName = serverName[:i]
|
||||
}
|
||||
serverName = common.GetIpByAddr(serverName)
|
||||
serverName = strings.TrimSpace(serverName)
|
||||
if serverName == "" {
|
||||
return ""
|
||||
}
|
||||
ip := net.ParseIP(serverName)
|
||||
if ip != nil && ip.IsUnspecified() {
|
||||
return ""
|
||||
}
|
||||
return serverName
|
||||
}
|
||||
|
||||
func (https *HttpsServer) cert(host *file.Host, c net.Conn, rb []byte, certFileUrl string, keyFileUrl string) {
|
||||
var l *HttpsListener
|
||||
i := 0
|
||||
@@ -300,27 +334,41 @@ func (httpsListener *HttpsListener) Addr() net.Addr {
|
||||
return httpsListener.parentListener.Addr()
|
||||
}
|
||||
|
||||
// get server name from connection by read client hello bytes
|
||||
// get server name from connection by read full client hello bytes
|
||||
func GetServerNameFromClientHello(c net.Conn) (string, []byte) {
|
||||
buf := make([]byte, 4096)
|
||||
data := make([]byte, 4096)
|
||||
n, err := c.Read(buf)
|
||||
header := make([]byte, 5)
|
||||
headerN, err := io.ReadFull(c, header)
|
||||
if err != nil {
|
||||
return "", nil
|
||||
return "", header[:headerN]
|
||||
}
|
||||
if n < 42 {
|
||||
return "", nil
|
||||
if header[0] != 0x16 {
|
||||
return "", header
|
||||
}
|
||||
copy(data, buf[:n])
|
||||
recordLen := int(header[3])<<8 | int(header[4])
|
||||
if recordLen <= 0 {
|
||||
return "", header
|
||||
}
|
||||
|
||||
body := make([]byte, recordLen)
|
||||
bodyN, err := io.ReadFull(c, body)
|
||||
if err != nil {
|
||||
return "", append(header, body[:bodyN]...)
|
||||
}
|
||||
|
||||
rawBytes := append(header, body...)
|
||||
clientHello := new(crypt.ClientHelloMsg)
|
||||
clientHello.Unmarshal(data[5:n])
|
||||
return clientHello.GetServerName(), buf[:n]
|
||||
if !clientHello.Unmarshal(body) {
|
||||
return "", rawBytes
|
||||
}
|
||||
return clientHello.GetServerName(), rawBytes
|
||||
}
|
||||
|
||||
// build https request
|
||||
// build https request for SNI-based host lookup.
|
||||
// RequestURI is set to "*" to skip Location filtering in GetInfoByHost,
|
||||
// because at TLS handshake stage the actual HTTP request path is unknown.
|
||||
func buildHttpsRequest(hostName string) *http.Request {
|
||||
r := new(http.Request)
|
||||
r.RequestURI = "/"
|
||||
r.RequestURI = "*"
|
||||
r.URL = new(url.URL)
|
||||
r.URL.Scheme = "https"
|
||||
r.Host = hostName
|
||||
|
||||
Reference in New Issue
Block a user