Ejemplo n.º 1
0
static TPM_RESULT execute_TPM_OIAP(TPM_REQUEST *req, TPM_RESPONSE *rsp)
{
    BYTE *ptr;
    UINT32 len;
    TPM_AUTHHANDLE authHandle;
    TPM_NONCE nonceEven;
    TPM_RESULT res;
    /* execute command */
    res = TPM_OIAP(&authHandle, &nonceEven);
    if (res != TPM_SUCCESS) return res;
    /* marshal output */
    rsp->paramSize = len = 4 + 20;
    rsp->param = ptr = malloc(len);
    if (ptr == NULL
            || tpm_marshal_TPM_AUTHHANDLE(&ptr, &len, authHandle)
            || tpm_marshal_TPM_NONCE(&ptr, &len, &nonceEven)) {
        free(rsp->param);
        res = TPM_FAIL;
    }
    return res;
}
Ejemplo n.º 2
0
int TPM_disk_unseal(void *dst, size_t size, const struct disk_seal_entry *src)
{
	uint32_t rc;
	TPM_STORED_DATA12 in;
	TPM_AUTH_SESSION oiap = TPM_AUTH_SESSION_INIT;
	TPM_AUTHDATA auth;
	uint32_t outSize = 0;
	uint8_t *out = NULL;

	printk("Calling TPM_disk_unseal\n");

	rc = TPM_OIAP(&oiap);
	if (rc) abort();

	memset(auth, 0, 20);

	in.tag = TPM_TAG_STORED_DATA12;
	in.et = 0;
	//in.sealInfoLongSize = sizeof_TPM_PCR_INFO_LONG(&in.sealInfoLong);
	in.sealInfoLongSize = 2 + 1 + 1 + 2 + 3 + 2 + 3 + 20 + 20;
	in.sealInfoLong.tag = TPM_TAG_PCR_INFO_LONG;
	in.sealInfoLong.localityAtCreation = 1 << vtpm_globals.hw_locality;
	in.sealInfoLong.localityAtRelease = 1 << vtpm_globals.hw_locality;
	in.sealInfoLong.creationPCRSelection.sizeOfSelect = 3;
	in.sealInfoLong.creationPCRSelection.pcrSelect = (void*)&src->pcr_selection;
	in.sealInfoLong.releasePCRSelection.sizeOfSelect = 3;
	in.sealInfoLong.releasePCRSelection.pcrSelect = (void*)&src->pcr_selection;
	memcpy(&in.sealInfoLong.digestAtCreation, &src->digest_at_seal, 20);
	memcpy(&in.sealInfoLong.digestAtRelease, &src->digest_release, 20);
	in.encDataSize = 256;
	in.encData = (void*)src->sealed_data;

#ifdef DEBUG_SEAL_OPS
	uint8_t buf[512];
	uint8_t *start = buf;
	uint8_t *end = pack_TPM_STORED_DATA12(buf, &in);
	printk("stored_data:");
	while (start != end) {
		printk(" %02x", *start);
		start++;
	}
	printk("\n");
#endif

	rc = TPM_Unseal(TPM_SRK_KEYHANDLE, &in, &outSize, &out,
			(void*)&vtpm_globals.srk_auth, (void*)&auth, &vtpm_globals.oiap, &oiap);

	TPM_TerminateHandle(oiap.AuthHandle);

#ifdef DEBUG_SEAL_OPS
	printk("TPM_Unseal rc=%d outSize=%d size=%d\n", rc, outSize, size);
#endif
	if (!rc) {
		memcpy(dst, out, size);
#ifdef DEBUG_SEAL_OPS
		printk("unsealed:");
		int i;
		for(i=0; i < size; i++)
			printk(" %02x", ((uint8_t*)dst)[i]);
		printk("\n");
#endif
	}

	free(out);

	return rc;
}