@d-healey We have a third party plugin developer who did this, with the following code.
Does this help?
#if JUCE_WINDOWS
#include <windows.h>
#include <wincrypt.h>
#include <Softpub.h>
#include <iostream>
#pragma comment(lib, "crypt32.lib")
#pragma comment(lib, "wintrust.lib")
bool VerifyMixcraftIsHost()
{
const std::string expectedName = "Acoustica, Inc";
wchar_t path[MAX_PATH];
GetModuleFileNameW(nullptr, path, MAX_PATH);
juce::File hostExeFile = juce::File(juce::CharPointer_UTF16(path));
WINTRUST_FILE_INFO fileInfo = {};
fileInfo.cbStruct = sizeof(WINTRUST_FILE_INFO);
fileInfo.pcwszFilePath = hostExeFile.getFullPathName().toWideCharPointer();
WINTRUST_DATA winTrustData = {};
winTrustData.cbStruct = sizeof(WINTRUST_DATA);
winTrustData.pPolicyCallbackData = nullptr;
winTrustData.pSIPClientData = nullptr;
winTrustData.dwUIChoice = WTD_UI_NONE;
winTrustData.fdwRevocationChecks = WTD_REVOKE_NONE;
winTrustData.dwUnionChoice = WTD_CHOICE_FILE;
winTrustData.pFile = &fileInfo;
winTrustData.dwStateAction = WTD_STATEACTION_VERIFY;
winTrustData.dwProvFlags = WTD_CACHE_ONLY_URL_RETRIEVAL;
GUID policyGUID = WINTRUST_ACTION_GENERIC_VERIFY_V2;
LONG status = WinVerifyTrust(nullptr, &policyGUID, &winTrustData);
if (status != ERROR_SUCCESS) {
std::wcout << L"WinVerifyTrust failed with status: " << status << std::endl;
return false;
}
// Access the certificate
CRYPT_PROVIDER_DATA* providerData = WTHelperProvDataFromStateData(winTrustData.hWVTStateData);
if (!providerData) return false;
CRYPT_PROVIDER_SGNR* signer = WTHelperGetProvSignerFromChain(providerData, 0, FALSE, 0);
if (!signer) return false;
PCCERT_CONTEXT certContext = signer->pasCertChain[0].pCert;
if (!certContext) return false;
// Extract the name
char nameBuffer[512];
DWORD nameLen = CertGetNameStringA(certContext, CERT_NAME_SIMPLE_DISPLAY_TYPE, 0, nullptr, nameBuffer, sizeof(nameBuffer));
if (nameLen > 0) {
std::cout << "Certificate name: " << nameBuffer << std::endl;
return expectedName == std::string(nameBuffer);
}
return false;
}
#endif