Ð޸´ȫÏîĿÉó²éÎÊÌⲢ·¢²¼ v1.1.9

¸ÄÓñ¾»ú¶ÀÁ¢ CA£¬»ָ´ CLI TLS УÑ飬±£»¤ƾ¾ÝÓëÅäÖò¢·¢±£´档
Ð޸´ Cursor Êý¾ݡ¢»Ự·¾¶¡¢´úÀíÉúÃüÖÜÆڡ¢ģÐÍÇëÇóÓë Skills Îļþ²Ù×÷¡£
Ϊ¶ÀÁ¢ Tab ·þÎñÔö¼ӿͻ§¶˼øȨ£¬Éý¼¶ÒÀÀµÓ빤¾ßÁ´£¬ÍêÉƷ¢²¼ԪÐÅϢͬ²½¡£

Ñé֤£ºÁ½¸ö Go ģ¿éµIJâÊÔ/vet¡¢¹ؼüģ¿é race¡¢ǰ¶˲âÊÔ/Éú²ú¹¹½¨/Éó¼ơ¢
Go ¿ɴï©¶´ɨÃèÓë macOS/Linux ¿ÉÐÐģ¿齻²æ±àÒë¾ùͨ¹ý¡£
Windows ¸ôÀëÆô¶¯ͨ¹ý£»δÍê³ɵĵã»÷ðÑ̺ÍԭÉúƽ̨Ñé֤¼ûÉó²鱨¸档
This commit is contained in:
FuDie0915
2026-11-10 09:59:34 +08:00
parent db73cf5a39
commit 188225fae6
98 changed files with 3324 additions and 930 deletions

View File

@@ -5,12 +5,16 @@ package cursor
import (
"crypto/sha1"
"crypto/x509"
"cursor/internal/certs"
"encoding/base64"
"encoding/binary"
"encoding/pem"
"errors"
"fmt"
"os/exec"
"strings"
"syscall"
"unicode/utf16"
"cursor/internal/logger"
)
@@ -147,16 +151,62 @@ func installCACertToWindowsStore(certPEM []byte, certPath string) error {
// EnsureCACertInstalled 确保证书已安装到 Windows 系统信任存储。
func EnsureCACertInstalled(certPEM []byte, certPath string) error {
installed, err := isCACertInstalled(certPEM)
if err != nil {
return fmt.Errorf("检查系统证书安装状态失败: %w", err)
}
if installed {
logger.Infof("ensureCACertInstalled: cert already installed in system store, skipping")
return migrateCATrust(certPEM, isCAInstalledAnyStore, func() error {
thumb, err := getCertThumbprint(certPEM)
if err != nil {
return err
}
legacy, err := getCertThumbprint(certs.EmbeddedCACertPEM())
if err != nil {
return err
}
body := windowsCAMigrationBody(certPath, thumb, legacy)
units := utf16.Encode([]rune(body))
bytes := make([]byte, len(units)*2)
for i, u := range units {
binary.LittleEndian.PutUint16(bytes[i*2:], u)
}
encoded := base64.StdEncoding.EncodeToString(bytes)
outer := "$p=Start-Process -FilePath 'powershell.exe' -ArgumentList @('-NoProfile','-NonInteractive','-EncodedCommand','" + encoded + "') -Verb RunAs -WindowStyle Hidden -Wait -PassThru; exit $p.ExitCode"
cmd := exec.Command(windowsPowerShellExe, "-NoProfile", "-NonInteractive", "-Command", outer)
cmd.SysProcAttr = hideWindow()
if err := cmd.Run(); err != nil {
return fmt.Errorf("安装证书授权失败或已取消,请重试: %w", err)
}
cleanup := fmt.Sprintf("$ErrorActionPreference='Stop'; $s=New-Object System.Security.Cryptography.X509Certificates.X509Store('Root','CurrentUser'); try { $s.Open('ReadWrite'); foreach($c in @($s.Certificates.Find('FindByThumbprint',%s,$false))) { $s.Remove($c) } } finally { $s.Close() }", quotePowerShellLiteral(legacy))
originalUser := exec.Command(windowsPowerShellExe, "-NoProfile", "-NonInteractive", "-Command", cleanup)
originalUser.SysProcAttr = hideWindow()
if err := originalUser.Run(); err != nil {
return fmt.Errorf("移除当前用户的旧共享证书失败: %w", err)
}
return nil
}
logger.Infof("ensureCACertInstalled: cert not installed in system store, installing...")
return installCACertToWindowsStore(certPEM, certPath)
})
}
func isCAInstalledAnyStore(certPEM []byte) (bool, error) {
thumb, err := getCertThumbprint(certPEM)
if err != nil {
return false, err
}
script := "$ErrorActionPreference='Stop'; (Test-Path " + quotePowerShellLiteral(`Cert:\LocalMachine\Root\`+thumb) + ") -or (Test-Path " + quotePowerShellLiteral(`Cert:\CurrentUser\Root\`+thumb) + ")"
cmd := exec.Command(windowsPowerShellExe, "-NoProfile", "-NonInteractive", "-Command", script)
cmd.SysProcAttr = hideWindow()
out, err := cmd.Output()
if err != nil {
return false, err
}
return strings.EqualFold(strings.TrimSpace(string(out)), "True"), nil
}
func windowsCAMigrationBody(certPath, thumb, legacy string) string {
return fmt.Sprintf(`$ErrorActionPreference='Stop'
$c = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2(%s)
if ($c.Thumbprint -ne %s) { throw 'CA fingerprint mismatch' }
$s = New-Object System.Security.Cryptography.X509Certificates.X509Store('Root','LocalMachine')
try {
$s.Open('ReadWrite'); $s.Add($c)
if ($s.Certificates.Find('FindByThumbprint',%s,$false).Count -eq 0) { throw 'CA installation failed' }
foreach ($old in @($s.Certificates.Find('FindByThumbprint',%s,$false))) { $s.Remove($old) }
} finally { $s.Close() }
`, quotePowerShellLiteral(certPath), quotePowerShellLiteral(thumb), quotePowerShellLiteral(thumb), quotePowerShellLiteral(legacy))
}