Go allows you to pretty easily retrieve the Personal Windows cert store handle for the Current User using the following command:
store, err := syscall.CertOpenSystemStore(0, syscall.StringToUTF16Ptr("MY")) // Personal Certificates
However, when I try to retrieve the Local Machine Personal cert store I always end up with either an empty store handle, and exception or error that the store was not found, CRYPT_E_NOT_FOUND.
Alternatively, you can use this method:
store, err := syscall.CertOpenStore(
windows.CERT_STORE_PROV_SYSTEM,
0,
0,
windows.CERT_SYSTEM_STORE_CURRENT_USER,
uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr("MY"))))
But when I swap out the values for the Local Machine store I start seeing the errors referenced above.
How do you successfully retrieve the Local Machine cert store in Windows using Go?
You do use the following code snippet as mentioned in the comments above to retrieve the certs:
store, err := syscall.CertOpenStore(
windows.CERT_STORE_PROV_SYSTEM,
0,
0,
windows.CERT_SYSTEM_STORE_LOCAL_MACHINE,
uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr("MY"))))
But there were a few things going on here as to why specifically it wasn't working initially: