示例#1
0
lv2test::~lv2test()
{
    DBGFN();
    if (pq     != NULL) {
        PDEB(VVERBOSE) << "delete pq ..." << endl;
        delete pq;
    }
    DBGFNL();
}
示例#2
0
int tpm_load_srk(UI_METHOD *ui, void *cb_data)
{
	TSS_RESULT result;
	UINT32 authusage;
	BYTE *auth;
	UINT32 auth_size;
	UINT32 srk_secret_mode = secret_mode;
	BYTE well_known_secret[] = TSS_WELL_KNOWN_SECRET;

	if (hSRK != NULL_HKEY) {
		DBGFN("SRK is already loaded.");
		return 1;
	}

	if ((result = Tspi_Context_LoadKeyByUUID(hContext, TSS_PS_TYPE_SYSTEM,
						   SRK_UUID, &hSRK))) {
		TSSerr(TPM_F_TPM_LOAD_SRK, TPM_R_REQUEST_FAILED);
		return 0;
	}

	if ((result = Tspi_GetAttribUint32(hSRK, TSS_TSPATTRIB_KEY_INFO,
					     TSS_TSPATTRIB_KEYINFO_AUTHUSAGE,
					     &authusage))) {
		Tspi_Context_CloseObject(hContext, hSRK);
		TSSerr(TPM_F_TPM_LOAD_SRK, TPM_R_REQUEST_FAILED);
		return 0;
	}

	if (!authusage) {
		DBG("SRK has no auth associated with it.");
		return 1;
	}

	/* If hSRKPolicy is non 0, then a policy object for the SRK has already
	 * been set up by engine pre/post commands. Just assign it to the SRK.
	 * Otherwise, we need to get the SRK's implicit policy and prompt for a
	 * secret */
	if (hSRKPolicy) {
		DBG("Found an already initialized SRK policy, using it");
		if ((result = Tspi_Policy_AssignToObject(hSRKPolicy, hSRK))) {
			TSSerr(TPM_F_TPM_LOAD_SRK, TPM_R_REQUEST_FAILED);
			return 0;
		}

		return 1;
	}

	if ((result = Tspi_GetPolicyObject(hSRK, TSS_POLICY_USAGE,
					&hSRKPolicy))) {
		Tspi_Context_CloseObject(hContext, hSRK);
		TSSerr(TPM_F_TPM_LOAD_SRK, TPM_R_REQUEST_FAILED);
		return 0;
	}

	if ((auth = calloc(1, 128)) == NULL) {
		TSSerr(TPM_F_TPM_LOAD_SRK, ERR_R_MALLOC_FAILURE);
		return 0;
	}

	if (!srk_zeroed) {
		if (!tpm_engine_get_auth(ui, (char *)auth, 128, "SRK authorization: ",
					cb_data)) {
			Tspi_Context_CloseObject(hContext, hSRK);
			free(auth);
			TSSerr(TPM_F_TPM_LOAD_SRK, TPM_R_REQUEST_FAILED);
		}
		auth_size = strlen((char *)auth);
	} else {
		auth_size = sizeof(well_known_secret);
		memcpy(auth, well_known_secret, auth_size);
		srk_secret_mode = TSS_SECRET_MODE_SHA1;
	}

	/* secret_mode is a global that may be set by engine ctrl
	 * commands.  By default, its set to TSS_SECRET_MODE_PLAIN */
	if ((result = Tspi_Policy_SetSecret(hSRKPolicy, srk_secret_mode,
					      auth_size, auth))) {
		Tspi_Context_CloseObject(hContext, hSRK);
		free(auth);
		TSSerr(TPM_F_TPM_LOAD_SRK, TPM_R_REQUEST_FAILED);
		return 0;
	}

	free(auth);

	return 1;
}