请问,有没有解决方案可以在托管的VM上使用EV代码签名证书?所有证书供应商是否都会向硬件令牌交付此类证书?如何在虚拟环境中使用此类型的证书对MSI进行代码签名?
https://github.com/microsoft/Detours
这些绕路函数非常简单(代码只保留了重要部分,以便理解)。DWORD WINAPI ProcessIdToSessionIdLocal(DWORD dwProcessId, DWORD *pSessionId)
{
OutputDebugString("Detoured ProcessIdToSessionId\r\n");
if (pSessionId)
pSessionId = 0;
return TRUE;
}
BOOL WINAPI WinStationGetCurrentSessionCapabilitiesLocal(DWORD flags, DWORD *pOutBuffer)
{
BOOL bResult;
OutputDebugString("Detoured WinStationGetCurrentSessionCapabilities\r\n");
bResult = TrueGetCurStationCapabilities(flags,pOutBuffer);
if (bResult)
*pOutBuffer = 0;
return bResult;
}
BOOL WINAPI DllMain (haDLL, dwReason, lpReserved)
HANDLE haDLL;
DWORD dwReason;
LPVOID lpReserved;
{
LONG error;
TCHAR cBuffer[160];
wsprintf(cBuffer,"DllMain Entry %08x\r\n",dwReason);
OutputDebugString(cBuffer);
if (DetourIsHelperProcess()) {
return TRUE;
}
if (dwReason == DLL_PROCESS_ATTACH) {
OutputDebugString("Starting Detour API Calls \r\n");
hStaDLL = LoadLibrary("WINSTA.DLL");
TrueGetCurStationCapabilities = GetProcAddress(hStaDLL,"WinStationGetCurrentSessionCapabilities");
DetourRestoreAfterWith();
DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread());
DetourAttach((PVOID*)&TrueProcessIdToSessionId, ProcessIdToSessionIdLocal);
DetourAttach((PVOID*)&TrueGetCurStationCapabilities, WinStationGetCurrentSessionCapabilitiesLocal);
error = DetourTransactionCommit();
if (error == NO_ERROR) {
OutputDebugString("Successfully Detoured API Calls \r\n");
}
else {
return FALSE;
}
}
else if (dwReason == DLL_PROCESS_DETACH) {
DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread());
DetourDetach((PVOID*)&TrueProcessIdToSessionId, ProcessIdToSessionIdLocal);
DetourDetach((PVOID*)&TrueGetCurStationCapabilities, WinStationGetCurrentSessionCapabilitiesLocal);
error = DetourTransactionCommit();
FreeLibrary(hStaDLL);
}
return TRUE;
}
将DLL注入signtool也很容易:只需在IMPORTs部分添加一个新条目,以加载具有重定向函数的DLL。可以使用名为"Lord PE"的工具来完成此操作(适用于32位可执行文件)。
对于其他遇到此问题的人,我们使用了VNC服务器连接了拥有令牌的虚拟机。在RDP上无法工作,只能使用VNC。
显然,对于EV Dongle来说,VNC就像访问控制台一样。
我们使用PFX(文件)支持的标准代码签名证书切换到基于USB令牌支持的EV代码签名证书,整个过程不到15分钟,没有任何问题。
我只需将USB令牌设备设置为连接到VMWare中的客户端操作系统(请参见客户端操作系统窗口底部的设备图标),安装必要的设备驱动程序,设置选项以要求每次会话仅解锁一次密码,然后就可以开始了。
至于如何签名,您只需像使用任何其他证书一样进行签名。如果操作系统的证书存储中没有其他适用的代码签名证书,那么您甚至不需要指定证书的位置。
我曾担心我们会遇到麻烦,但实际上并没有。所以,我认为您也不会遇到问题,也不知道为什么您会遇到问题。
使用EV代码签名证书需要使用特殊硬件来存储私钥。这也是使它们比标准证书更昂贵和更安全的部分原因。我的建议是在主机上使用signtool.exe作为后构建步骤对可执行文件进行签名。
普通代码签名证书没有硬件要求,但它们不像EV证书那样“智能屏幕过滤器友好”。
一些虚拟化软件包括 VMware 允许重定向 USB 设备。