Skip to content

Commit

Permalink
chore: swtich RtlGetNtVersionNumbers to RtlGetVersion
Browse files Browse the repository at this point in the history
  • Loading branch information
wwqgtxx committed May 12, 2024
1 parent 7df1c26 commit a50339b
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 7 deletions.
5 changes: 2 additions & 3 deletions component/ca/fix_windows.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
package ca

import (
"golang.org/x/sys/windows"
"github.com/metacubex/mihomo/constant/features"
)

func init() {
majorVersion, _, _ := windows.RtlGetNtVersionNumbers()
// crypto/x509: certificate validation in Windows fails to validate IP in SAN
// https://github.com/golang/go/issues/37176
// As far as I can tell this is still the case on most older versions of Windows (but seems to be fixed in 10)
if majorVersion < 10 && len(_CaCertificates) > 0 {
if features.WindowsMajorVersion < 10 && len(_CaCertificates) > 0 {
DisableSystemCa = true
}
}
5 changes: 5 additions & 0 deletions constant/features/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package features

var WindowsMajorVersion uint32
var WindowsMinorVersion uint32
var WindowsBuildNumber uint32
10 changes: 10 additions & 0 deletions constant/features/version_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package features

import "golang.org/x/sys/windows"

func init() {
version := windows.RtlGetVersion()
WindowsMajorVersion = version.MajorVersion
WindowsMinorVersion = version.MinorVersion
WindowsBuildNumber = version.MinorVersion
}
6 changes: 2 additions & 4 deletions listener/sing_tun/server_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@ package sing_tun
import (
"time"

"github.com/metacubex/mihomo/constant/features"
"github.com/metacubex/mihomo/log"

tun "github.com/metacubex/sing-tun"

"golang.org/x/sys/windows"
)

func tunNew(options tun.Options) (tunIf tun.Tun, err error) {
Expand All @@ -30,8 +29,7 @@ func tunNew(options tun.Options) (tunIf tun.Tun, err error) {
func init() {
tun.TunnelType = InterfaceName

majorVersion, _, _ := windows.RtlGetNtVersionNumbers()
if majorVersion < 10 {
if features.WindowsMajorVersion < 10 {
// to resolve "bind: The requested address is not valid in its context"
EnforceBindInterface = true
}
Expand Down

0 comments on commit a50339b

Please sign in to comment.