打包修改
This commit is contained in:
1 parent
752699f480
commit
b4eac30398
2 files changed
+55
-6
No files matched your search
+51
-3
@@ -6,6 +6,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
"unsafe"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -16,13 +17,22 @@ const (
|
|||||||
|
|
||||||
var (
|
var (
|
||||||
modcrypt32 = syscall.NewLazyDLL("crypt32.dll")
|
modcrypt32 = syscall.NewLazyDLL("crypt32.dll")
|
||||||
|
procCertOpenSystemStore = modcrypt32.NewProc("CertOpenSystemStoreW")
|
||||||
|
procCertEnumCertificatesInStore = modcrypt32.NewProc("CertEnumCertificatesInStore")
|
||||||
|
procCertGetNameString = modcrypt32.NewProc("CertGetNameStringW")
|
||||||
|
procCertCloseStore = modcrypt32.NewProc("CertCloseStore")
|
||||||
)
|
)
|
||||||
|
|
||||||
// 安装信任证书
|
// 安装信任证书
|
||||||
func SetupCert() {
|
func SetupCert() {
|
||||||
//获取证书路径
|
CheckCertIsInstalled()
|
||||||
certPath := "/frontend/public/piserver_root.crt" // 替换为您的证书路径
|
|
||||||
|
|
||||||
|
//获取证书路径
|
||||||
|
dir, _ := os.Getwd()
|
||||||
|
certPath := dir+"/piserver_root.crt" // 替换为您的证书路径
|
||||||
|
|
||||||
|
if CheckCertIsInstalled() == "yes"{
|
||||||
|
return
|
||||||
|
}
|
||||||
// 读取证书文件
|
// 读取证书文件
|
||||||
certFile, err := os.ReadFile(certPath)
|
certFile, err := os.ReadFile(certPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -44,8 +54,10 @@ func SetupCert() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// 打开证书存储
|
// 打开证书存储
|
||||||
storeHandle, err := syscall.CertOpenSystemStore(0, syscall.StringToUTF16Ptr("ROOT"))
|
storeHandle, err := syscall.CertOpenSystemStore(0, syscall.StringToUTF16Ptr("ROOT"))
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("无法打开证书存储:", err)
|
fmt.Println("无法打开证书存储:", err)
|
||||||
return
|
return
|
||||||
@@ -76,3 +88,39 @@ func addCertificateToStore(cert []byte, storeHandle syscall.Handle) error {
|
|||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//检测证书是否已经安装了
|
||||||
|
func CheckCertIsInstalled() string {
|
||||||
|
storeName := "Root" // 证书存储名称,这里使用了 "MY" 表示个人证书存储
|
||||||
|
|
||||||
|
storeHandle, _, _ := procCertOpenSystemStore.Call(0, uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(storeName))))
|
||||||
|
if storeHandle == 0 {
|
||||||
|
fmt.Println("Error opening certificate store")
|
||||||
|
return "error"
|
||||||
|
}
|
||||||
|
defer procCertCloseStore.Call(storeHandle, 0)
|
||||||
|
|
||||||
|
var pCertContext uintptr
|
||||||
|
for {
|
||||||
|
pCertContext, _, _ = procCertEnumCertificatesInStore.Call(storeHandle, pCertContext)
|
||||||
|
if pCertContext == 0 {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
res := printCertificateInfo(pCertContext) // 输出证书信息
|
||||||
|
if res == "yes"{
|
||||||
|
return res
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return "no"
|
||||||
|
}
|
||||||
|
//获取证书的信息
|
||||||
|
func printCertificateInfo(pCertContext uintptr) string {
|
||||||
|
var buffer [200]uint16
|
||||||
|
size, _, _ := procCertGetNameString.Call(pCertContext, 5, 0, 0, uintptr(unsafe.Pointer(&buffer)), 200)
|
||||||
|
issuer := syscall.UTF16ToString(buffer[:size])
|
||||||
|
fmt.Println("Certificate Issuer:", issuer)
|
||||||
|
if issuer == "mkcert pi@pi-laptop"{
|
||||||
|
return "yes"
|
||||||
|
}
|
||||||
|
return "no"
|
||||||
|
}
|
||||||
@@ -11,11 +11,12 @@ import (
|
|||||||
func RunPiServerExe() {
|
func RunPiServerExe() {
|
||||||
// 获取当前目录
|
// 获取当前目录
|
||||||
dir, _ := os.Getwd()
|
dir, _ := os.Getwd()
|
||||||
applicationPath := dir + "/frontend/public/piServer"
|
applicationPath := dir + "/piVideo"
|
||||||
//切换到目录
|
// //切换到目录
|
||||||
os.Chdir(applicationPath)
|
os.Chdir(applicationPath)
|
||||||
//执行exe的路径
|
//执行exe的路径
|
||||||
exePath := dir + "/frontend/public/piVideo/piVideo.exe"
|
exePath := dir + "/piVideo/piVideo.exe"
|
||||||
|
fmt.Println("piVide 可执行路径:", exePath)
|
||||||
killPiServerExe()
|
killPiServerExe()
|
||||||
time.Sleep(3 * time.Second)
|
time.Sleep(3 * time.Second)
|
||||||
cmd := exec.Command(exePath) // 替换为您的可执行文件路径
|
cmd := exec.Command(exePath) // 替换为您的可执行文件路径
|
||||||
|
|||||||
Reference in new issue
Block a user