Reputation: 3138
I follow this thread to create TPM Vistual Smnart Card, after run the app the virtual smart card created and could see in Device Manager, but when I try to insert the PIN 123456789
to authenticate show the PIN is not correct
#include "Tpmvscmgr.h"
#include "StrSafe.h"
#pragma comment (lib, "Vscmgr.lib")
#include <Windows.h>
HRESULT CoCreateInstanceAsAdmin(HWND hwnd, REFCLSID rclsid, REFIID riid, __out void ** ppv)
{
BIND_OPTS3 bo;
WCHAR wszCLSID[50];
WCHAR wszMonikerName[300];
StringFromGUID2(rclsid, wszCLSID, sizeof(wszCLSID) / sizeof(wszCLSID[0]));
HRESULT hr = StringCchPrintfW(wszMonikerName, sizeof(wszMonikerName) / sizeof(wszMonikerName[0]), L"Elevation:Administrator!new:%s", wszCLSID);
if (FAILED(hr))
return hr;
memset(&bo, 0, sizeof(bo));
bo.cbStruct = sizeof(bo);
bo.hwnd = hwnd;
bo.dwClassContext = CLSCTX_LOCAL_SERVER;
return CoGetObject(wszMonikerName, &bo, riid, ppv);
}
int main()
{
HRESULT hr = S_OK;
HWND hwnd = NULL;
ITpmVirtualSmartCardManager *pObj = NULL;
CoInitialize(NULL);
hr = CoCreateInstanceAsAdmin(
hwnd,
CLSID_TpmVirtualSmartCardManager,
IID_ITpmVirtualSmartCardManager,
(void**)&pObj);
//ITpmVirtualSmartCardManager *pObj = NULL;
LPWSTR friendly = L"Friendly";
LPWSTR out = L"";
BYTE pin[] = "123456789";
DWORD size = sizeof(pin);
BOOL boot;
hr = pObj->CreateVirtualSmartCard(friendly, TPMVSC_DEFAULT_ADMIN_ALGORITHM_ID, pin, size, NULL, 0, pin, size, pin, size, false, NULL, &out, &boot);
return 0;
}
Any one has any idea what the problem?
Upvotes: 0
Views: 254
Reputation: 11020
CreateVirtualSmartCard()
must be 24. It shouldn't be the same thing as PIN anyway.sizeof(pin)
will return 10 in this case, because the null terminator is included in computing the size. Is this what TpmVscMgr does as well?Upvotes: 1