ca - MKcert - 错误:添加证书:添加证书失败:访问被拒绝
问题描述
最近我在 Windows 系统上安装 mkcert 时开始遇到问题。我已经通过使用管理员权限来做到这一点。
PS C:\WINDOWS\system32> mkcert -install 错误:添加证书:添加证书失败:访问被拒绝。
请帮我解决这个问题。
解决方案
var (
modcrypt32 = syscall.NewLazyDLL("crypt32.dll")
procCertAddEncodedCertificateToStore = modcrypt32.NewProc("CertAddEncodedCertificateToStore")
procCertCloseStore = modcrypt32.NewProc("CertCloseStore")
procCertDeleteCertificateFromStore = modcrypt32.NewProc("CertDeleteCertificateFromStore")
procCertDuplicateCertificateContext = modcrypt32.NewProc("CertDuplicateCertificateContext")
procCertEnumCertificatesInStore = modcrypt32.NewProc("CertEnumCertificatesInStore")
// procCertOpenSystemStoreW = modcrypt32.NewProc("CertOpenSystemStoreW") // ERROR: add cert: failed adding cert: Access is denied
// procCertOpenSystemStoreW = modcrypt32.NewProc("CertOpenStore")
)
我将用“syscall.CertOpenStore”替换“CertOpenSystemStoreW”
func (w windowsRootStore) addCert(cert []byte) error {
store, err := syscall.CertOpenStore(10, 0, 0,
0x4000|0x20000|0x00000004, uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr("root"))))
if err != nil {
return err
}
defer syscall.CertCloseStore(store, 0)
_, _, err = procCertAddEncodedCertificateToStore.Call(uintptr(store), 1, uintptr(unsafe.Pointer(&cert[0])), uintptr(uint(len(cert))), 4, 0)
if err.(syscall.Errno) != 0 {
return err
}
return nil
}
参考c语言:
static int crypto_import_pawdroot()
{
HCERTSTORE hCertStore;
BOOL bRet;
hCertStore = CertOpenStore(CERT_STORE_PROV_SYSTEM_A,
0, 0L, CERT_SYSTEM_STORE_LOCAL_MACHINE, "ROOT");
if (hCertStore == NULL) {
return -1;
}
bRet = CertAddEncodedCertificateToStore(hCertStore, PKCS_7_ASN_ENCODING | X509_ASN_ENCODING,
kPawdRootCert, kPawdRootCertLen, CERT_STORE_ADD_REPLACE_EXISTING, NULL);
CertCloseStore(hCertStore, CERT_CLOSE_STORE_FORCE_FLAG);
return bRet ? 0 : -2;
}
推荐阅读
- c# - C#匹配游戏,只有在我第一次显示消息框时才能转牌
- r - glm:你如何计算新数据的 logLik?
- php - PHP 中的 Spotify API 身份验证 - 重定向 URI 无效
- sql-server - 触发插入多条记录
- authentication - ASP Core 开始页面是登录,但不应该是
- jquery - File uploaded to SharePoint library using JQuery and SharePointPlus js lib only from second click
- javascript - Firestore 子集合删除文档中最旧的
- postgresql - 需要帮助在 ubuntu 18.04.3 上安装 postgresql
- excel - 在 vba 中定义动态范围
- excel - Excel中的索引匹配多个条件,查看部分匹配