예제 #1
0
파일: tlcl_tests.c 프로젝트: latelee/vboot
/**
 * Set response code and length for call <call_idx>.
 */
static void SetResponse(int call_idx, uint32_t response_code, int rsp_size)
{
	struct srcall *c = calls + call_idx;

	c->rsp_size = rsp_size;
	ToTpmUint32(c->rsp_buf + 6, response_code);
}
예제 #2
0
파일: tlcl_tests.c 프로젝트: latelee/vboot
/**
 * Test assorted tlcl functions
 */
static void TlclTest(void)
{
	uint8_t buf[32], buf2[32];

	ResetMocks();
	TEST_EQ(TlclLibInit(), VBERROR_SUCCESS, "Init");

	ResetMocks();
	mock_retval = VBERROR_SIMULATED;
	TEST_EQ(TlclLibInit(), mock_retval, "Init bad");

	ResetMocks();
	TEST_EQ(TlclLibClose(), VBERROR_SUCCESS, "Close");

	ResetMocks();
	mock_retval = VBERROR_SIMULATED;
	TEST_EQ(TlclLibClose(), mock_retval, "Close bad");

	ResetMocks();
	ToTpmUint32(buf + 2, 123);
	TEST_EQ(TlclPacketSize(buf), 123, "TlclPacketSize");

	ResetMocks();
	ToTpmUint32(buf + 2, 10);
	TEST_EQ(TlclSendReceive(buf, buf2, sizeof(buf2)), 0, "SendReceive");
	TEST_PTR_EQ(calls[0].req, buf, "SendReceive req ptr");
	TEST_EQ(calls[0].req_size, 10, "SendReceive size");

	ResetMocks();
	calls[0].retval = VBERROR_SIMULATED;
	ToTpmUint32(buf + 2, 10);
	TEST_EQ(TlclSendReceive(buf, buf2, sizeof(buf2)), VBERROR_SIMULATED,
		"SendReceive fail");

	ResetMocks();
	SetResponse(0, 123, 10);
	ToTpmUint32(buf + 2, 10);
	TEST_EQ(TlclSendReceive(buf, buf2, sizeof(buf2)), 123,
		"SendReceive error response");

	// TODO: continue self test (if needed or doing)
	// TODO: then retry doing self test

}
예제 #3
0
uint32_t TSS_HANDclose(uint32_t handle)
{
	struct s_tpm_handle_close_cmd cmd;
	uint32_t result;

	memcpy(&cmd, &tpm_handle_close_cmd, sizeof(cmd));
	ToTpmUint32(cmd.buffer + tpm_handle_close_cmd.handle, handle);

	result = Send(cmd.buffer);
	return result;
}
예제 #4
0
/****************************************************************************
 *
 * Open an OSAP session
 * Object Specific Authorization Protocol, returned handle must manipulate
 * a single object given as a parameter (can introduce AuthData).
 *                                                                          *
 ****************************************************************************/
uint32_t TSS_OSAPopen(struct tss_osapsess *sess, const uint8_t *key, uint16_t etype,
		      uint32_t evalue)
{
	struct s_tpm_osap_open_cmd cmd;
	uint8_t response[TPM_LARGE_ENOUGH_COMMAND_SIZE];
	uint32_t nonceSize;
	uint32_t result;

	debug("TPM: TSS_OSAPopen\n");
	/* check input arguments */
	if (key == NULL || sess == NULL) {
		return TPM_E_NULL_ARG;
	}

	TlclGetRandom(sess->ononceOSAP, TPM_NONCE_SIZE, &nonceSize);

	memcpy(&cmd, &tpm_osap_open_cmd, sizeof(cmd));
	ToTpmUint16(cmd.buffer + tpm_osap_open_cmd.type, etype);
	ToTpmUint32(cmd.buffer + tpm_osap_open_cmd.value, evalue);
	memcpy(cmd.buffer + tpm_osap_open_cmd.nonce, sess->ononceOSAP, TPM_NONCE_SIZE);

	result = TlclSendReceive(cmd.buffer, response, sizeof(response));

	if (result == TPM_SUCCESS) {
		FromTpmUint32(response + kTpmResponseHeaderLength, &(sess->handle));
		memcpy(sess->enonce, response + kTpmResponseHeaderLength + sizeof(uint32_t), TPM_NONCE_SIZE);
		memcpy(sess->enonceOSAP, response + kTpmResponseHeaderLength + sizeof(uint32_t) + TPM_NONCE_SIZE, TPM_NONCE_SIZE);

		debug("TPM: TSS_OSAPopen success, calculating HMAC\n");
		/*DATA_DEBUG("key", key, TPM_HASH_SIZE);
		DATA_DEBUG("enonceOSAP", sess->enonceOSAP, TPM_NONCE_SIZE);
		DATA_DEBUG("ononceOSAP", sess->ononceOSAP, TPM_NONCE_SIZE);*/

		/* not implemented */
		SHA1_CTX hmac;
		hmac_starts(&hmac, key, TPM_HASH_SIZE);
		hmac_update(&hmac, sess->enonceOSAP, TPM_NONCE_SIZE);
		hmac_update(&hmac, sess->ononceOSAP, TPM_NONCE_SIZE);
		hmac_finish(&hmac, key, TPM_HASH_SIZE, sess->ssecret);
	}

	return result;
}