Ejemplo n.º 1
0
int utpm_pcr_extend(short pcrnum, char *digest) {
    if (setup_ukey_context() != 0) {
        printf("setup_ukey_context() failed.\n");
        return -1;
    }
    if (Dongle_Open() !=0) {
        printf("Dongle_Open() failed.\n");
        return -1;
    }
    
    short fielid = 0x1;
    char inoutbuf[1020] = {
        0x22, 0x00, 0x00, 0x00, 0x00, 0xc1, 0x00, 0x00,   
        0x00, 0x22, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00,
        0x00, 0x07, 0xff, 0xff, 0xff, 0x23, 0xff, 0xff,   
        0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
        0xff, 0xff, 0xaf, 0x01, 0x34, 0x33
    };
    memcpy(inoutbuf+16, (void *)&pcrnum + 1, 1);
    memcpy(inoutbuf+17, (void *)&pcrnum, 1);
    memcpy(inoutbuf+18, digest, 20);
    /*
    printf("inoutbuf before :\n");
    printf_buffer(inoutbuf, 1020);
    */
    Dongle_RunExeFile(fielid, inoutbuf, 1020);
    memcpy(digest, inoutbuf+18, 20);

    /*
    printf("inoutbuf after :\n");
    printf_buffer(inoutbuf, 1020);
    */

    close_ukey_context();

    return 0;

}
Ejemplo n.º 2
0
int _tmain(int argc, _TCHAR* argv[])
{
	DWORD dwRet = 0;
	int nCount = 0;
	int i = 0;
	char AdminPin[32] = { 0 };
	int KeyLen = 32;
	int nRemainCount = 255;

	DONGLE_HANDLE hDongle = NULL;
	RSA_PUBLIC_KEY  rsaPub;
	RSA_PRIVATE_KEY rsaPri;
	PRIKEY_FILE_ATTR priAttr;
	WORD wPriID = 0x1111;

	dwRet = Dongle_Enum(NULL, &nCount);
	printf("Enum %d Dongle ARM. \n", nCount);

	dwRet = Dongle_Open(&hDongle, 0);
	printf("Open Dongle ARM. Return : 0x%08X . \n", dwRet);

	while (1)
	{
		printf("Please Input Admin PIN:");
		scanf_s("%s", AdminPin, KeyLen);
		dwRet = Dongle_VerifyPIN(hDongle, FLAG_ADMINPIN, AdminPin, &nRemainCount);
		if (dwRet != DONGLE_SUCCESS)
		{
			printf("Verify Admin PIN. failure Return: 0x%08X\n", dwRet);
		}
		else
		{
			printf("Verify Admin PIN. OK Return: 0x%08X\n", dwRet);
			break;
		}
	}
				
	priAttr.m_Size = 1024;
	priAttr.m_Type = FILE_PRIKEY_RSA;
	priAttr.m_Lic.m_Count = 0xFFFFFFFF;
	priAttr.m_Lic.m_IsDecOnRAM = FALSE;
	priAttr.m_Lic.m_IsReset = FALSE;
	priAttr.m_Lic.m_Priv = 2;

	dwRet = Dongle_CreateFile(hDongle, FILE_PRIKEY_RSA, wPriID, (void*)&priAttr);
	printf("Create RSA private key file. Return: 0x%08X\n", dwRet);
	if (DONGLE_SUCCESS != dwRet)
	{
		printf("RSA pri_key file is existing!\n");
	}

	dwRet = Dongle_RsaGenPubPriKey(hDongle, wPriID, &rsaPub, &rsaPri);
	printf("Gen RSA Public key and private key. Return: 0x%08X\n", dwRet);
	if (DONGLE_SUCCESS != dwRet)
	{
		printf("RSA pri_key and pub_key is existing!\n");
	}

	FILE* fp = NULL;
	fopen_s(&fp, "D://code//ukey//PublicKey//1111.Rsapub", "wb");
	fwrite(&rsaPub, 1, sizeof(RSA_PUBLIC_KEY), fp);
	fclose(fp);
	fp = NULL;

	dwRet = Dongle_Close(hDongle);
	printf("Close Dongle ARM. Return: 0x%08X\n", dwRet);


	return 0;
}