当前位置: 首页>>代码示例>>C++>>正文


C++ Tspi_Context_Close函数代码示例

本文整理汇总了C++中Tspi_Context_Close函数的典型用法代码示例。如果您正苦于以下问题:C++ Tspi_Context_Close函数的具体用法?C++ Tspi_Context_Close怎么用?C++ Tspi_Context_Close使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了Tspi_Context_Close函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: main_v1_1

int
main_v1_1( void )
{
	char		*function = "Tspi_TPM_KillMaintenanceFeature01";
	TSS_HCONTEXT	hContext;
	TSS_HTPM	hTPM;
	TSS_HPOLICY	hTPMPolicy;
	TSS_RESULT	result;
	UINT32		exitCode = 0;

	print_begin_test( function );

		// Create Context
	result = Tspi_Context_Create( &hContext );
	if ( result != TSS_SUCCESS )
	{
		print_error( "Tspi_Context_Create", result );
		exit( result );
	}

		// Connect to Context
	result = Tspi_Context_Connect( hContext, get_server(GLOBALSERVER) );
	if ( result != TSS_SUCCESS )
	{
		print_error( "Tspi_Context_Connect", result );
		Tspi_Context_FreeMemory( hContext, NULL );
		Tspi_Context_Close( hContext );
		exit( result );
	}

		// Retrieve TPM object of context
	result = Tspi_Context_GetTpmObject( hContext, &hTPM );
	if ( result != TSS_SUCCESS )
	{
		print_error( "Tspi_Context_GetTpmObject", result );
		Tspi_Context_FreeMemory( hContext, NULL );
		Tspi_Context_Close( hContext );
		exit( result );
	}

		//Insert the owner auth into the TPM's policy
	result = Tspi_GetPolicyObject(hTPM, TSS_POLICY_USAGE, &hTPMPolicy);
	if (result != TSS_SUCCESS) {
		print_error("Tspi_GetPolicyObject", result);
		Tspi_Context_FreeMemory( hContext, NULL );
		Tspi_Context_Close( hContext );
		exit(result);
	}

	result = Tspi_Policy_SetSecret(hTPMPolicy, TESTSUITE_OWNER_SECRET_MODE,
				       TESTSUITE_OWNER_SECRET_LEN, TESTSUITE_OWNER_SECRET);
	if (result != TSS_SUCCESS) {
		print_error("Tspi_Policy_SetSecret", result);
		Tspi_Context_FreeMemory( hContext, NULL );
		Tspi_Context_Close( hContext );
		exit(result);
	}

		//Get random number
	result = Tspi_TPM_KillMaintenanceFeature( hTPM );
	if ( result != TSS_SUCCESS && TSS_ERROR_CODE(result) != TCPA_E_INACTIVE)
	{
		if( !(checkNonAPI(result)) )
		{
			print_error( function, result );
		}
		else
		{
			print_error_nonapi( function, result );
		}
		exitCode = result;
	}
	else
	{
		print_success( function, result );
	}

	print_end_test( function );
	Tspi_Context_FreeMemory( hContext, NULL );
	Tspi_Context_Close( hContext );
	exit( exitCode );
}
开发者ID:juliarahmawati,项目名称:testsuite,代码行数:82,代码来源:Tspi_TPM_KillMaintenanceFeature01.c

示例2: main_v1_2

int
main_v1_2( char version )
{
	char *			function = "Tspi_TPM_Delegate_UpdateVerificationCount-trans03";
	TSS_HCONTEXT		hContext;
	TSS_HKEY		hSRK, hWrappingKey;
	TSS_HTPM		hTPM;
	TSS_HPOLICY		hTPMPolicy;
	TSS_HPOLICY		hDelegation1 = NULL_HPOLICY;
	TSS_HPOLICY		hDelegation2 = NULL_HPOLICY;
	TSS_HDELFAMILY		hFamily = NULL_HDELFAMILY;
	TSS_RESULT		result;

	print_begin_test( function );

	result = connect_load_all(&hContext, &hSRK, &hTPM);
	if ( result != TSS_SUCCESS )
	{
		print_error( "connect_load_all", (result) );
		goto done;
	}

	result = Testsuite_Transport_Init(hContext, hSRK, hTPM, TRUE, TRUE, &hWrappingKey,
					  NULL);
	if (result != TSS_SUCCESS) {
		print_error("Testsuite_Transport_Init", result);
		Tspi_Context_Close(hContext);
		exit(result);
	}

	result = Tspi_GetPolicyObject( hTPM, TSS_POLICY_USAGE, &hTPMPolicy );
	if ( result != TSS_SUCCESS )
	{
		print_error( "Tspi_GetPolicyObject", result );
		goto done;
	}

	result = Tspi_Policy_SetSecret( hTPMPolicy, TESTSUITE_OWNER_SECRET_MODE,
					TESTSUITE_OWNER_SECRET_LEN, TESTSUITE_OWNER_SECRET );
	if ( result != TSS_SUCCESS )
	{
		print_error( "Tspi_Policy_SetSecret", result );
		goto done;
	}

	result = Tspi_Context_CreateObject(hContext, TSS_OBJECT_TYPE_POLICY, TSS_POLICY_USAGE, &hDelegation1);
	if ( result != TSS_SUCCESS )
	{
		print_error( "Tspi_Context_CreateObject", (result) );
		goto done;
	}

	result = Tspi_Policy_SetSecret( hDelegation1, TESTSUITE_DELEGATE_SECRET_MODE,
					TESTSUITE_DELEGATE_SECRET_LEN, TESTSUITE_DELEGATE_SECRET );
	if ( result != TSS_SUCCESS )
	{
		print_error( "Tspi_Policy_SetSecret", result );
		goto done;
	}

	result = Tspi_SetAttribUint32(hDelegation1, TSS_TSPATTRIB_POLICY_DELEGATION_INFO,
			TSS_TSPATTRIB_POLDEL_TYPE, TSS_DELEGATIONTYPE_OWNER);
	if ( result != TSS_SUCCESS )
	{
		print_error( "Tspi_SetAttribUint32", (result) );
		goto done;
	}

	result = Tspi_SetAttribUint32(hDelegation1, TSS_TSPATTRIB_POLICY_DELEGATION_INFO,
			TSS_TSPATTRIB_POLDEL_PER1, 0);
	if ( result != TSS_SUCCESS )
	{
		print_error( "Tspi_SetAttribUint32", (result) );
		goto done;
	}

	result = Tspi_SetAttribUint32(hDelegation1, TSS_TSPATTRIB_POLICY_DELEGATION_INFO,
			TSS_TSPATTRIB_POLDEL_PER2, 0);
	if ( result != TSS_SUCCESS )
	{
		print_error( "Tspi_SetAttribUint32", (result) );
		goto done;
	}

	result = Tspi_TPM_Delegate_AddFamily(hTPM, 'a', &hFamily);
	if ( result != TSS_SUCCESS )
	{
		print_error( "Tspi_TPM_Delegate_AddFamily", (result) );
		goto done;
	}

	result = Tspi_TPM_Delegate_CreateDelegation(hTPM, 'b', 0, NULL_HPCRS, hFamily, hDelegation1);
	if ( result != TSS_SUCCESS )
	{
		print_error( "Tspi_TPM_Delegate_CreateDelegation", (result) );
		goto done;
	}

	result = Tspi_Context_CreateObject(hContext, TSS_OBJECT_TYPE_POLICY, TSS_POLICY_USAGE, &hDelegation2);
	if ( result != TSS_SUCCESS )
//.........这里部分代码省略.........
开发者ID:juliarahmawati,项目名称:testsuite,代码行数:101,代码来源:Tspi_TPM_Delegate_UpdateVerificationCount-trans03.c

示例3: main_v1_2

main_v1_2(char version)
{
	TSS_HCONTEXT hContext;
	TSS_HKEY hSRK;
	TSS_HTPM hTPM;
	TSS_HPOLICY hTpmUsagePolicy;
	TSS_FLAG initFlags;
	TSS_HKEY hSrcKey;
	TSS_HKEY hDestKey;
	TSS_HKEY hMaKey[MA_KEY_COUNT];
	TSS_HKEY hCmkKey;
	TSS_HMIGDATA hMigData;
	TSS_HHASH hHash;
	UINT32 blobSize;
	BYTE *blob;
	int i;
	TSS_RESULT result;


	print_begin_test(nameOfFunction);

	result = connect_load_all(&hContext, &hSRK, &hTPM);
	if ( result != TSS_SUCCESS )
	{
		print_error( "connect_load_all", result );
		exit(result);
	}

	//Get TPM Policy Object
	result = Tspi_GetPolicyObject(hTPM, TSS_POLICY_USAGE, &hTpmUsagePolicy);
	if (result != TSS_SUCCESS) {
		print_error("Tspi_GetPolicyObject", result);
		print_error_exit(nameOfFunction, err_string(result));
		Tspi_Context_Close(hContext);
		exit(result);
	}

	//Set Secret
	result = Tspi_Policy_SetSecret(hTpmUsagePolicy, TESTSUITE_OWNER_SECRET_MODE,
			TESTSUITE_OWNER_SECRET_LEN, TESTSUITE_OWNER_SECRET);
	if (result != TSS_SUCCESS) {
		print_error("Tspi_Policy_SetSecret", result);
		print_error_exit(nameOfFunction, err_string(result));
		Tspi_Context_Close(hContext);
		exit(result);
	}

	/*****  Create Overall Source Parent key *****/
	initFlags = TSS_KEY_STRUCT_KEY12 | TSS_KEY_TYPE_STORAGE | TSS_KEY_SIZE_2048 |
			TSS_KEY_VOLATILE | TSS_KEY_AUTHORIZATION;
	tc_create_object(hContext, TSS_OBJECT_TYPE_RSAKEY, initFlags, &hSrcKey);
	tc_create_key(hContext, hSrcKey, hSRK, initFlags);
	tc_load_key(hContext, hSrcKey, hSRK);

	/*****  Create Overall Destination Parent key *****/
	initFlags = TSS_KEY_STRUCT_KEY12 | TSS_KEY_TYPE_STORAGE | TSS_KEY_SIZE_2048 |
			TSS_KEY_VOLATILE | TSS_KEY_AUTHORIZATION;
	tc_create_object(hContext, TSS_OBJECT_TYPE_RSAKEY, initFlags, &hDestKey);
	tc_create_key(hContext, hDestKey, hSRK, initFlags);
	tc_load_key(hContext, hDestKey, hSRK);

	/*****  Create MAs and MSA list *****/
	//Create MigData Object
	tc_create_object(hContext, TSS_OBJECT_TYPE_MIGDATA, 0, &hMigData);

	for (i = 0; i < MA_KEY_COUNT; i++) {
		//Create Key Object
		initFlags = TSS_KEY_STRUCT_KEY12 | TSS_KEY_TYPE_SIGNING | TSS_KEY_SIZE_2048 |
				TSS_KEY_VOLATILE | TSS_KEY_AUTHORIZATION;
		tc_create_object(hContext, TSS_OBJECT_TYPE_RSAKEY, initFlags, &hMaKey[i]);
		tc_create_key(hContext, hMaKey[i], hSrcKey, initFlags);

		//Get PubKey Blob
		tc_get_attribdata(hContext, hMaKey[i], TSS_TSPATTRIB_KEY_BLOB,
			TSS_TSPATTRIB_KEYBLOB_PUBLIC_KEY, &blobSize, &blob);

		//Add PubKey Blob to the MSA list
		tc_set_attribdata(hContext, hMigData, TSS_MIGATTRIB_MIGRATIONBLOB,
			TSS_MIGATTRIB_MIG_MSALIST_PUBKEY_BLOB, blobSize, blob);
	}

	//Grant Owner Approval of MAs
	result = Tspi_TPM_CMKApproveMA(hTPM, hMigData);
	if (result != TSS_SUCCESS) {
		print_error("Tspi_TPM_CMKApproveMA", result);
		print_error_exit(nameOfFunction, err_string(result));
		Tspi_Context_Close(hContext);
		exit(result);
	}

	/*****  Create a CMK  ****/
	initFlags = TSS_KEY_STRUCT_KEY12 | TSS_KEY_TYPE_SIGNING | TSS_KEY_SIZE_2048 |
			TSS_KEY_VOLATILE | TSS_KEY_AUTHORIZATION |
			TSS_KEY_MIGRATABLE | TSS_KEY_CERTIFIED_MIGRATABLE;
	tc_create_object(hContext, TSS_OBJECT_TYPE_RSAKEY, initFlags, &hCmkKey);

	//Get and Assign MA/MSA information
	tc_get_attribdata(hContext, hMigData, TSS_MIGATTRIB_AUTHORITY_DATA,
		TSS_MIGATTRIB_AUTHORITY_DIGEST, &blobSize, &blob);
	tc_set_attribdata(hContext, hCmkKey, TSS_TSPATTRIB_KEY_CMKINFO,
//.........这里部分代码省略.........
开发者ID:juliarahmawati,项目名称:testsuite,代码行数:101,代码来源:Tspi_TPM_CMKCreateTicket01.c

示例4: main_v1_2

int
main_v1_2(char version)
{
    char		*function = "Tspi_Key_GetPubKey-trans02";
    TSS_HCONTEXT	hContext;
    TSS_HKEY	hSRK;
    TSS_HKEY	hKey, hWrappingKey, hSigningKey;
    TSS_UUID	SRKUUID			= {0,0,0,0,0,0,0,0,0,0,1};
    TSS_UUID	migratableSignUUID	= {1,2,3,4,5,6,7,8,9,10,2};
    TSS_UUID	uuid;
    TSS_RESULT	result;
    UINT32		ulPubKeyLength;
    BYTE		*rgbPubKey;
    TSS_HPOLICY	srkUsagePolicy;
    TSS_HTPM	hTPM;
    TSS_FLAG	initFlags = TSS_KEY_TYPE_SIGNING | TSS_KEY_SIZE_2048  |
                            TSS_KEY_VOLATILE | TSS_KEY_NO_AUTHORIZATION |
                            TSS_KEY_NOT_MIGRATABLE;

    print_begin_test( function );

    result = connect_load_all(&hContext, &hSRK, &hTPM);
    if (result != TSS_SUCCESS) {
        print_error("Tspi_Context_Create ", result);
        exit(result);
    }

    result = Testsuite_Transport_Init(hContext, hSRK, hTPM, TRUE, TRUE, &hWrappingKey,
                                      &hSigningKey);
    if (result != TSS_SUCCESS) {
        print_error("Testsuite_Transport_Init", result);
        Tspi_Context_Close(hContext);
        exit(result);
    }
    //Create Signing Key
    result = Tspi_Context_CreateObject( hContext, TSS_OBJECT_TYPE_RSAKEY,
                                        initFlags, &hKey );
    if ( result != TSS_SUCCESS )
    {
        print_error( "Tspi_Context_CreateObject (hKey)", result );
        Tspi_Context_FreeMemory( hContext, NULL );
        Tspi_Context_Close( hContext );
        exit( result );
    }

    result = Tspi_Key_CreateKey( hKey, hSRK, 0 );
    if ( result != TSS_SUCCESS )
    {
        print_error( "Tspi_Key_CreateKey (hKey)", result );
        Tspi_Context_FreeMemory( hContext, NULL );
        Tspi_Context_Close( hContext );
        exit( result );
    }

    result = Tspi_Key_LoadKey( hKey, hSRK );
    if ( result != TSS_SUCCESS )
    {
        print_error( "Tspi_Key_LoadKey (hKey)", result );
        Tspi_Context_FreeMemory( hContext, NULL );
        Tspi_Context_Close( hContext );
        exit( result );
    }

    // Get Pub Key
    result = Tspi_Key_GetPubKey( hKey, &ulPubKeyLength, &rgbPubKey );
    if ( result != TSS_SUCCESS )
    {
        print_error( "Tspi_Key_GetPubKey", result );
        Tspi_Context_FreeMemory( hContext, NULL );
        Tspi_Context_Close( hContext );
        exit( result );
    }

    result = Testsuite_Transport_Final(hContext, hSigningKey);
    if ( result != TSS_SUCCESS )
    {
        if( !(checkNonAPI(result)) )
        {
            print_error( function, result );
        }
        else
        {
            print_error_nonapi( function, result );
        }
    }
    else
    {
        result = Tspi_Context_FreeMemory(hContext, rgbPubKey);
        if (result != TSS_SUCCESS) {
            print_error("Tspi_Context_FreeMemory ", result);
            Tspi_Context_Close(hContext);
            exit(result);
        }
        print_success( function, result );
    }

    print_end_test( function );
    Tspi_Context_FreeMemory( hContext, NULL );
    Tspi_Context_Close( hContext );
    exit( result );
//.........这里部分代码省略.........
开发者ID:srajiv,项目名称:testsuite,代码行数:101,代码来源:Tspi_Key_GetPubKey-trans02.c

示例5: main_v1_1

int
main_v1_1( void )
{
	char		*function = "Tspi_Context_LoadKeyByBlob03";
	TSS_HCONTEXT	hContext;
	TSS_HKEY	hSRK;
	TSS_HKEY	hMSigningKey;
	BYTE*		migratableSignKeyBlob;
	UINT32		blobLength;
	TSS_RESULT	result;
	TSS_HPOLICY	srkUsagePolicy;
	UINT32		exitCode = 0;

	print_begin_test( function );

		// Create Context
	result = Tspi_Context_Create( &hContext );
	if ( result != TSS_SUCCESS )
	{
		print_error( "Tspi_Context_Create", result );
		exit( result );
	}

		// Connect to Context
	result = Tspi_Context_Connect( hContext, get_server(GLOBALSERVER) );
	if ( result != TSS_SUCCESS )
	{
		print_error( "Tspi_Context_Connect", result );
		Tspi_Context_FreeMemory( hContext, NULL );
		Tspi_Context_Close( hContext );
		exit( result );
	}

		//Load Key By UUID
	result = Tspi_Context_LoadKeyByUUID( hContext, TSS_PS_TYPE_SYSTEM,
						SRK_UUID, &hSRK );
	if ( result != TSS_SUCCESS )
	{
		print_error( "Tspi_Context_LoadKeyByUUID (hSRK)", result );
		Tspi_Context_FreeMemory( hContext, NULL );
		Tspi_Context_Close( hContext );
		exit( result );
	}

#ifndef TESTSUITE_NOAUTH_SRK
		//Get Policy Object
	result = Tspi_GetPolicyObject( hSRK, TSS_POLICY_USAGE,
					&srkUsagePolicy );
	if ( result != TSS_SUCCESS )
	{
		print_error( "Tspi_GetPolicyObject", result );
		Tspi_Context_FreeMemory( hContext, NULL );
		Tspi_Context_Close( hContext );
		exit( result );
	}

		//Set Secret
	result = Tspi_Policy_SetSecret( srkUsagePolicy, TESTSUITE_SRK_SECRET_MODE,
				TESTSUITE_SRK_SECRET_LEN, TESTSUITE_SRK_SECRET );
	if ( result != TSS_SUCCESS )
	{
		print_error( "Tspi_Policy_SetSecret (1)", result );
		Tspi_Context_FreeMemory( hContext, NULL );
		Tspi_Context_Close( hContext );
		exit( result );
	}
#endif

		//Create Signing Key
	result = Tspi_Context_CreateObject( hContext, TSS_OBJECT_TYPE_RSAKEY,
						TSS_KEY_SIZE_2048 |
						TSS_KEY_TYPE_SIGNING,
						&hMSigningKey );
	if ( result != TSS_SUCCESS )
	{
		print_error( "Tspi_CreateObject (signing key)", result );
		Tspi_Context_FreeMemory( hContext, NULL );
		Tspi_Context_Close( hContext );
		exit( result );
	}

	result = Tspi_Key_CreateKey( hMSigningKey, hSRK, 0 );
	if ( result != TSS_SUCCESS )
	{
		print_error( "Tspi_Key_CreateKey (Signing Key)", result );
		Tspi_Context_FreeMemory( hContext, NULL );
		Tspi_Context_Close( hContext );
		exit( result );
	}

		// get blob
	result = Tspi_GetAttribData( hMSigningKey, TSS_TSPATTRIB_KEY_BLOB,
					TSS_TSPATTRIB_KEYBLOB_BLOB,
					&blobLength, &migratableSignKeyBlob );
	if ( result != TSS_SUCCESS )
	{
		print_error( "Tspi_GetAttribData", result );
		Tspi_Context_FreeMemory( hContext, NULL );
		Tspi_Context_Close( hContext );
		exit( result );
//.........这里部分代码省略.........
开发者ID:juliarahmawati,项目名称:testsuite,代码行数:101,代码来源:Tspi_Context_LoadKeyByBlob03.c

示例6: main_v1_2

main_v1_2(char version){

	char		*nameOfFunction = "Tspi_TPM_KeyControlOwner01";
	TSS_RESULT	result;
	TSS_HCONTEXT	hContext;
	TSS_HTPM	hTPM;
	TSS_FLAG	initFlags;
	TSS_HKEY	hSRK;
	TSS_HKEY	hKey;
	TSS_HKEY	hTargetPubKey;
	TSS_HPOLICY	hTpmPolicy, hSrkPolicy;
	TSS_UUID	Uuid;

	print_begin_test(nameOfFunction);

		//Create Context
	result = Tspi_Context_Create(&hContext);
	if (result != TSS_SUCCESS) {
		print_error("Tspi_Context_Create", result);
		exit(result);
	}
		//Connect Context
	result = Tspi_Context_Connect(hContext, get_server(GLOBALSERVER));
	if (result != TSS_SUCCESS) {
		print_error("Tspi_Context_Connect", result);
		Tspi_Context_FreeMemory( hContext, NULL );
		exit(result);
	}

		//Create Object
	result = Tspi_Context_CreateObject(hContext, TSS_OBJECT_TYPE_RSAKEY,
					   TSS_KEY_SIZE_2048 |
					   TSS_KEY_TYPE_SIGNING, &hKey);
	if (result != TSS_SUCCESS) {
		print_error("Tspi_Context_CreateObject", result);
		Tspi_Context_FreeMemory( hContext, NULL );
		Tspi_Context_Close(hContext);
		exit(result);
	}

		//Get TPM Object
	result = Tspi_Context_GetTpmObject(hContext, &hTPM);
	if (result != TSS_SUCCESS) {
		print_error("Tspi_Context_GetTpmObject", result);
		Tspi_Context_FreeMemory( hContext, NULL );
		Tspi_Context_Close(hContext);
		exit(result);
	}

		//Requires Owner auth - get policy
	result = Tspi_GetPolicyObject(hTPM, TSS_POLICY_USAGE, &hTpmPolicy);
	if (result != TSS_SUCCESS) {
		print_error("Tspi_GetPolicyObject ", result);
		Tspi_Context_FreeMemory( hContext, NULL );
		Tspi_Context_Close(hContext);
		exit(result);
	}

		//Set Owner Secret
	result = Tspi_Policy_SetSecret(hTpmPolicy, TESTSUITE_OWNER_SECRET_MODE,
				       TESTSUITE_OWNER_SECRET_LEN,
				       TESTSUITE_OWNER_SECRET );
	if ( result != TSS_SUCCESS )
	{
		print_error("Tspi_Policy_SetSecret (Owner)", result);
		Tspi_Context_FreeMemory( hContext, NULL );
		Tspi_Context_Close(hContext);
		exit(result);
	}

		//Get SRK Key
	result = Tspi_Context_LoadKeyByUUID(hContext, TSS_PS_TYPE_SYSTEM, SRK_UUID, &hSRK);
	if (result != TSS_SUCCESS) {
		print_error("Tspi_Context_LoadKeyByUUID ", result);
		Tspi_Context_FreeMemory( hContext, NULL );
		Tspi_Context_Close(hContext);
		exit(result);
	}

		//Requires SRK auth - get policy
	result = Tspi_GetPolicyObject(hSRK, TSS_POLICY_USAGE, &hSrkPolicy);
	if (result != TSS_SUCCESS) {
		print_error("Tspi_GetPolicyObject ", result);
		Tspi_Context_FreeMemory( hContext, NULL );
		Tspi_Context_Close(hContext);
		exit(result);
	}

		//Set SRK Secret
	result = Tspi_Policy_SetSecret(hSrkPolicy, TESTSUITE_SRK_SECRET_MODE,
				       TESTSUITE_SRK_SECRET_LEN, TESTSUITE_SRK_SECRET );
	if ( result != TSS_SUCCESS )
	{
		print_error("Tspi_Policy_SetSecret (Owner)", result);
		Tspi_Context_FreeMemory( hContext, NULL );
		Tspi_Context_Close(hContext);
		exit(result);
	}

		//Create Key
//.........这里部分代码省略.........
开发者ID:wy461132,项目名称:repository,代码行数:101,代码来源:Tspi_TPM_KeyControlOwner01.c

示例7: main_v1_2

int
main_v1_2( char version )
{
	char		*function = "Tspi_DecodeBER_TssBlob01";
	TSS_HCONTEXT	hContext;
	TSS_HKEY	hSRK;
	TSS_HPOLICY	hSrkPolicy;
	TSS_HKEY	hKey;
	BYTE*		rgbBlob;
	UINT32		ulBlobLength;
	BYTE*		rgbEncBlob = NULL;
	UINT32		ulEncBlobLength;
	UINT32		ulBlobType;
	BYTE*		rgbDecBlob = NULL;
	UINT32		ulDecBlobLength;
	TSS_RESULT	result;

	print_begin_test( function );

	result = connect_load_srk(&hContext, &hSRK);
	if ( result != TSS_SUCCESS )
	{
		print_error( "connect_load_srk", result );
		Tspi_Context_FreeMemory( hContext, NULL );
		Tspi_Context_Close( hContext );
		exit( result );
	}

	result = create_key(hContext, TSS_KEY_TYPE_BIND, hSRK, &hKey);
	if ( result != TSS_SUCCESS )
	{
		print_error( "create_key", result );
		Tspi_Context_FreeMemory( hContext, NULL );
		Tspi_Context_Close( hContext );
		exit( result );
	}

		//Call GetAttribData
	result = Tspi_GetAttribData(hKey,
			TSS_TSPATTRIB_KEY_BLOB,
			TSS_TSPATTRIB_KEYBLOB_BLOB,
			&ulBlobLength, &rgbBlob);
	if ( result != TSS_SUCCESS )
	{
		print_error( "Tspi_GetAttribData", result );
		Tspi_Context_FreeMemory( hContext, NULL );
		Tspi_Context_Close( hContext );
		exit( result );
	}

		// EncodeDER_TssBlob (32 bytes extra is enough for the encoding)
	ulEncBlobLength = ulBlobLength + 32;
	rgbEncBlob = calloc(1, ulEncBlobLength);
	result = Tspi_EncodeDER_TssBlob( ulBlobLength, rgbBlob, TSS_BLOB_TYPE_KEY, &ulEncBlobLength, rgbEncBlob );
	if ( result != TSS_SUCCESS )
	{
		print_error( "Tspi_EncodeDER_TssBlob", result );
		free(rgbEncBlob);
		Tspi_Context_FreeMemory( hContext, NULL );
		Tspi_Context_Close( hContext );
		exit( result );
	}

		// DecodeBER_TssBlob (determine length first)
	ulDecBlobLength = 0;
	rgbDecBlob = NULL;
	result = Tspi_DecodeBER_TssBlob( ulEncBlobLength, rgbEncBlob, &ulBlobType, &ulDecBlobLength, rgbDecBlob );
	if ( result != TSS_SUCCESS )
	{
		if( !(checkNonAPI(result)) )
		{
			print_error( function, result );
		}
		else
		{
			print_error_nonapi( function, result );
		}

		free(rgbEncBlob);
		Tspi_Context_FreeMemory( hContext, NULL );
		Tspi_Context_Close( hContext );
		exit( result );
	}

		// DecodeBER_TssBlob
	rgbDecBlob = calloc(1, ulDecBlobLength);
	result = Tspi_DecodeBER_TssBlob( ulEncBlobLength, rgbEncBlob, &ulBlobType, &ulDecBlobLength, rgbDecBlob );
	if ( result != TSS_SUCCESS )
	{
		if( !(checkNonAPI(result)) )
		{
			print_error( function, result );
		}
		else
		{
			print_error_nonapi( function, result );
		}

		free(rgbEncBlob);
		free(rgbDecBlob);
//.........这里部分代码省略.........
开发者ID:juliarahmawati,项目名称:testsuite,代码行数:101,代码来源:Tspi_DecodeBER_TssBlob01.c

示例8: load_tpm_key


//.........这里部分代码省略.........
				     Trspi_Error_String(err));
			goto out_srkpol;
		}

		free(pass);

		/* ... we get it here instead. */
		err = Tspi_Context_LoadKeyByBlob(vpninfo->tpm_context, vpninfo->srk,
						 tss_len, asn1.data + ofs,
						 &vpninfo->tpm_key);
		if (!err)
			break;

		if (pass)
			vpn_progress(vpninfo, PRG_ERR,
				     _("Failed to load TPM key blob: %s\n"),
				     Trspi_Error_String(err));

		if (err != TPM_E_AUTHFAIL)
			goto out_srkpol;

		err = request_passphrase(vpninfo, "openconnect_tpm_srk",
					 &pass, _("Enter TPM SRK PIN:"));
		if (err)
			goto out_srkpol;
	}

#ifdef HAVE_GNUTLS_CERTIFICATE_SET_KEY
	gnutls_privkey_init(pkey);
	/* This would be nicer if there was a destructor callback. I could
	   allocate a data structure with the TPM handles and the vpninfo
	   pointer, and destroy that properly when the key is destroyed. */
	gnutls_privkey_import_ext(*pkey, GNUTLS_PK_RSA, vpninfo, tpm_sign_fn, NULL, 0);
#else
	*pkey = OPENCONNECT_TPM_PKEY;
#endif

 retry_sign:
	err = sign_dummy_data(vpninfo, *pkey, fdata, pkey_sig);
	if (err == GNUTLS_E_INSUFFICIENT_CREDENTIALS) {
		if (!vpninfo->tpm_key_policy) {
			err = Tspi_Context_CreateObject(vpninfo->tpm_context,
							TSS_OBJECT_TYPE_POLICY,
							TSS_POLICY_USAGE,
							&vpninfo->tpm_key_policy);
			if (err) {
				vpn_progress(vpninfo, PRG_ERR,
					     _("Failed to create key policy object: %s\n"),
					     Trspi_Error_String(err));
				goto out_key;
			}
			err = Tspi_Policy_AssignToObject(vpninfo->tpm_key_policy,
							 vpninfo->tpm_key);
			if (err) {
				vpn_progress(vpninfo, PRG_ERR,
					     _("Failed to assign policy to key: %s\n"),
					     Trspi_Error_String(err));
				goto out_key_policy;
			}
		}
		err = request_passphrase(vpninfo, "openconnect_tpm_key",
					 &pass, _("Enter TPM key PIN:"));
		if (err)
			goto out_key_policy;

		err = Tspi_Policy_SetSecret(vpninfo->tpm_key_policy,
					    TSS_SECRET_MODE_PLAIN,
					    strlen(pass), (void *)pass);
		free(pass);

		if (err) {
			vpn_progress(vpninfo, PRG_ERR,
				     _("Failed to set key PIN: %s\n"),
				     Trspi_Error_String(err));
			goto out_key_policy;
		}
		goto retry_sign;
	}

	free(asn1.data);
	return 0;
 out_key_policy:
	Tspi_Context_CloseObject(vpninfo->tpm_context, vpninfo->tpm_key_policy);
	vpninfo->tpm_key_policy = 0;
 out_key:
	Tspi_Context_CloseObject(vpninfo->tpm_context, vpninfo->tpm_key);
	vpninfo->tpm_key = 0;
 out_srkpol:
	Tspi_Context_CloseObject(vpninfo->tpm_context, vpninfo->srk_policy);
	vpninfo->srk_policy = 0;
 out_srk:
	Tspi_Context_CloseObject(vpninfo->tpm_context, vpninfo->srk);
	vpninfo->srk = 0;
 out_context:
	Tspi_Context_Close(vpninfo->tpm_context);
	vpninfo->tpm_context = 0;
 out_blob:
	free(asn1.data);
	return -EIO;
}
开发者ID:shahrdad1,项目名称:openconnect,代码行数:101,代码来源:gnutls_tpm.c

示例9: main_v1_2

int
main_v1_2(char version)
{
	char	     *nameOfFunction    = "Tspi_nv_WriteValue-trans02";
	
	TSS_HCONTEXT hContext           = NULL_HCONTEXT;
	TSS_HNVSTORE hNVStore           = 0;//NULL_HNVSTORE
	TSS_HOBJECT  hPolObject         = NULL_HOBJECT;
	TSS_HPOLICY  hPolicy            = NULL_HPOLICY;
	TSS_HTPM     hTPM               = NULL_HTPM;
      	BYTE         *auth              = "123456";
	UINT32       auth_length        = 6;
	BYTE         *data              = "1234567890";
	TSS_RESULT   result;
	TSS_HKEY     hSigningKey, hWrappingKey, hSRK;

	print_begin_test(nameOfFunction);

	result = connect_load_all(&hContext, &hSRK, &hTPM);
	if (result != TSS_SUCCESS) {
		print_error("Tspi_Context_Create ", result);
		exit(result);
	}

	result = Testsuite_Transport_Init(hContext, hSRK, hTPM, TRUE, TRUE, &hWrappingKey,
					  &hSigningKey);
	if (result != TSS_SUCCESS) {
		print_error("Testsuite_Transport_Init", result);
		Tspi_Context_Close(hContext);
		exit(result);
	}

	/* Create TPM NV object */
	result = Tspi_Context_CreateObject(hContext, TSS_OBJECT_TYPE_NV, 0,&hNVStore);
	if (result != TSS_SUCCESS)
	{
		print_error("Tspi_Context_CreateObject", result);
		Tspi_Context_FreeMemory(hContext, NULL);
		Tspi_Context_Close(hContext);
		exit(result);
	}

		/* Create policy object for the NV object*/
	result = Tspi_Context_CreateObject(hContext, TSS_OBJECT_TYPE_POLICY, TSS_POLICY_USAGE, &hPolObject);
	if (result != TSS_SUCCESS)
	{
		print_error("Tspi_Context_CreateObject", result);
		Tspi_Context_FreeMemory(hContext, NULL);
		Tspi_Context_Close(hContext);
		exit(result);
	}

		/* Set password */
	result = Tspi_Policy_SetSecret(hPolObject, TSS_SECRET_MODE_PLAIN, auth_length, auth);
	if (result != TSS_SUCCESS)
	{
		print_error("Tspi_Policy_SetSecret", result);
		Tspi_Context_FreeMemory(hContext, NULL);
		Tspi_Context_Close(hContext);
		exit(result);
	}

		/* Set password */
	result = Tspi_Policy_AssignToObject(hPolObject, hNVStore);
	if (result != TSS_SUCCESS)
	{
		print_error("Tspi_Policy_AssignToObject", result);
		Tspi_Context_FreeMemory(hContext, NULL);
		Tspi_Context_Close(hContext);
		exit(result);
	}

	/* Set the index to be defined. */
	result = Tspi_SetAttribUint32(hNVStore, TSS_TSPATTRIB_NV_INDEX, 0,0x00011131);
	if (result != TSS_SUCCESS)
	{
		print_error("Tspi_SetAttribUint32 for setting NV index", result);
		Tspi_Context_FreeMemory(hContext, NULL);
		Tspi_Context_Close(hContext);
		exit(result);
	}


	/* Set the permission for the index. */
	result = Tspi_SetAttribUint32(hNVStore, TSS_TSPATTRIB_NV_PERMISSIONS, 0, 0x4);
	if (result != TSS_SUCCESS)
	{
		print_error("Tspi_SetAttribUint32 for setting permission", result);
		Tspi_Context_FreeMemory(hContext, NULL);
		Tspi_Context_Close(hContext);
		exit(result);	
       }


	/* Set the data size to be defined. */
	result = Tspi_SetAttribUint32(hNVStore, TSS_TSPATTRIB_NV_DATASIZE, 0, 0xa);
	if (result != TSS_SUCCESS)
	{
		print_error("Tspi_SetAttribUint32 for setting data size", result);
		Tspi_Context_FreeMemory(hContext, NULL);
//.........这里部分代码省略.........
开发者ID:juliarahmawati,项目名称:testsuite,代码行数:101,代码来源:Tspi_NV_WriteValue-trans02.c

示例10: main_v1_2

int
main_v1_2( char version )
{
	char *		function = "Tspi_SetAttribUint3208";
	TSS_HCONTEXT	hContext;
	TSS_HKEY	hSRK;
	TSS_HTPM	hTPM;
	TSS_HPOLICY	hTpmPolicy;
	UINT32		ordinal = TPM_ORD_CreateWrapKey, subCap, pulRespLen;
	TSS_RESULT	result;
	BYTE*		prgbRespData;

	print_begin_test( function );

	result = connect_load_all(&hContext, &hSRK, &hTPM);
	if ( result != TSS_SUCCESS )
	{
		print_error( "connect_load_all", result );
		Tspi_Context_FreeMemory( hContext, NULL );
		Tspi_Context_Close( hContext );
		exit( result );
	}

	result = Tspi_Context_CreateObject(hContext, TSS_OBJECT_TYPE_POLICY, TSS_POLICY_USAGE, &hTpmPolicy);
	if ( result != TSS_SUCCESS )
	{
		print_error( "Tspi_Context_createObject", result );
		Tspi_Context_FreeMemory( hContext, NULL );
		Tspi_Context_Close( hContext );
		exit( result );
	}

	result = Tspi_Policy_SetSecret(hTpmPolicy, TESTSUITE_OWNER_SECRET_MODE,
					TESTSUITE_OWNER_SECRET_LEN, TESTSUITE_OWNER_SECRET);
	if ( result != TSS_SUCCESS )
	{
		print_error( "Tspi_Policy_SetSecret", result );
		Tspi_Context_FreeMemory( hContext, NULL );
		Tspi_Context_Close( hContext );
		exit( result );
	}

	result = Tspi_Policy_AssignToObject(hTpmPolicy, hTPM);
	if ( result != TSS_SUCCESS )
	{
		print_error( "Tspi_Policy_AssignToObject", result );
		Tspi_Context_FreeMemory( hContext, NULL );
		Tspi_Context_Close( hContext );
		exit( result );
	}

	/* Check if ordinal auditing is supported on this TPM */
	result = Testsuite_Is_Ordinal_Supported(hTPM, TPM_ORD_SetOrdinalAuditStatus);
	if (result != TSS_SUCCESS) {
		fprintf(stderr, "%s: TPM doesn't support auditing, returning success\n", __FILE__);
		print_success( function, TSS_SUCCESS );
		print_end_test( function );
		Tspi_Context_FreeMemory( hContext, NULL );
		Tspi_Context_Close( hContext );
		exit( 0 );
	}

		//Call SetAttribUint32
	result = Tspi_SetAttribUint32(hTPM,
			TSS_TSPATTRIB_TPM_ORDINAL_AUDIT_STATUS,
			TPM_CAP_PROP_TPM_SET_ORDINAL_AUDIT,
			ordinal);
	if ( result != TSS_SUCCESS )
	{
		print_error( "Tspi_SetAttribUint32", result );
		Tspi_Context_FreeMemory( hContext, NULL );
		Tspi_Context_Close( hContext );
		exit( result );
	}

		//Call SetAttribUint32
	result = Tspi_SetAttribUint32(hTPM,
			TSS_TSPATTRIB_TPM_ORDINAL_AUDIT_STATUS,
			TPM_CAP_PROP_TPM_CLEAR_ORDINAL_AUDIT,
			ordinal);
	if ( result != TSS_SUCCESS )
	{
		print_error( "Tspi_SetAttribUint32", result );
		Tspi_Context_FreeMemory( hContext, NULL );
		Tspi_Context_Close( hContext );
		exit( result );
	}
	else
	{
		print_success( function, result );
	}

	print_end_test( function );
	Tspi_Context_FreeMemory( hContext, NULL );
	Tspi_Context_Close( hContext );
	exit( 0 );
}
开发者ID:juliarahmawati,项目名称:testsuite,代码行数:97,代码来源:Tspi_SetAttribUint3208.c

示例11: main_v1_1

main_v1_1(void){

	char		*nameOfFunction = "Tspi_ChangeAuth04";
	TSS_HKEY	hKey;
	TSS_HKEY	hSRK;
	TSS_HPOLICY	hPolicy;
	TSS_HKEY	hMStorageKey;
	TSS_HCONTEXT	hContext;
	TSS_RESULT	result;
	TSS_FLAG	initFlags;
	initFlags	= TSS_KEY_TYPE_SIGNING | TSS_KEY_SIZE_2048  |
			TSS_KEY_VOLATILE | TSS_KEY_NO_AUTHORIZATION |
			TSS_KEY_NOT_MIGRATABLE;
	TSS_HPOLICY	srkUsagePolicy;

	print_begin_test(nameOfFunction);

		//Create Context
	result = Tspi_Context_Create(&hContext);
	if (result != TSS_SUCCESS) {
		print_error("Tspi_Context_Create ", result);
		exit(result);
	}
		//Connect Context
	result = Tspi_Context_Connect(hContext, get_server(GLOBALSERVER));
	if (result != TSS_SUCCESS) {
		print_error("Tspi_Context_Connect", result);
		Tspi_Context_Close(hContext);
		exit(result);
	}
		//Create hKey
	result = Tspi_Context_CreateObject(hContext,
			TSS_OBJECT_TYPE_RSAKEY,
			initFlags, &hKey);
	if (result != TSS_SUCCESS) {
		print_error("Tspi_Context_CreateObject", result);
		Tspi_Context_Close(hContext);
		exit(result);
	}
		//Load Key By UUID
	result = Tspi_Context_LoadKeyByUUID(hContext,
			TSS_PS_TYPE_SYSTEM,
			SRK_UUID, &hSRK);
	if (result != TSS_SUCCESS) {
		print_error("Tspi_Context_LoadKeyByUUID for hSRK", result);
		Tspi_Context_CloseObject(hContext, hKey);
		Tspi_Context_Close(hContext);
		exit(result);
	}
#ifndef TESTSUITE_NOAUTH_SRK
		//Get Policy Object
	result = Tspi_GetPolicyObject(hSRK, TSS_POLICY_USAGE, &srkUsagePolicy);
	if (result != TSS_SUCCESS) {
		print_error("Tspi_GetPolicyObject", result);
		Tspi_Context_CloseObject(hContext, hKey);
		Tspi_Context_Close(hContext);
		exit(result);
	}
		//Set Secret
	result = Tspi_Policy_SetSecret(srkUsagePolicy, TESTSUITE_SRK_SECRET_MODE,
				TESTSUITE_SRK_SECRET_LEN, TESTSUITE_SRK_SECRET);
	if (result != TSS_SUCCESS) {
		print_error("Tspi_Policy_SetSecret", result);
		Tspi_Context_CloseObject(hContext, hKey);
		Tspi_Context_Close(hContext);
		exit(result);
	}
#endif
		//Create Storage Key
	result = Tspi_Context_CreateObject(hContext, 
			TSS_OBJECT_TYPE_RSAKEY,
			TSS_KEY_SIZE_2048 |TSS_KEY_TYPE_SIGNING, &hMStorageKey);
	if (result != TSS_SUCCESS) {
		print_error("Tspi_Context_CreateObject", result);
		Tspi_Context_CloseObject(hContext, hKey);
		Tspi_Context_Close(hContext);
		exit(result);
	}
	result = Tspi_Key_CreateKey(hMStorageKey, hSRK, 0);
	if (result != TSS_SUCCESS) {
		print_error("Tspi_Key_CreateKey", result);
		Tspi_Context_CloseObject(hContext, hMStorageKey);
		Tspi_Context_CloseObject(hContext, hKey);
		Tspi_Context_Close(hContext);
		exit(result);
	}
		//Call Change Auth
	result = Tspi_ChangeAuth(0xffffffff, hMStorageKey, hPolicy);
	if (TSS_ERROR_CODE(result) != TSS_E_INVALID_HANDLE) {
		if(!checkNonAPI(result)){
			print_error(nameOfFunction, result);
			print_end_test(nameOfFunction);
			Tspi_Context_FreeMemory(hContext, NULL);
			Tspi_Context_CloseObject(hContext, hMStorageKey);
			Tspi_Context_CloseObject(hContext, hKey);
			Tspi_Context_Close(hContext);
			exit(result);
		}
		else{
			print_error_nonapi(nameOfFunction, result);
//.........这里部分代码省略.........
开发者ID:juliarahmawati,项目名称:testsuite,代码行数:101,代码来源:Tspi_ChangeAuth04.c

示例12: main_v1_1

main_v1_1(void) {

    char		*nameOfFunction = "Tspi_ChangeAuthAsym02";
    TSS_HKEY	hKey;
    TSS_HKEY	hSRK;
    TSS_HPOLICY	hPolicy;
    TSS_UUID	migratableStorageUUID = {1,2,3,4,5,6,7,8,9,10,5};
    TSS_UUID	migratableSignUUID = {1,2,3,4,5,6,7,8,9,10,8};
    TSS_UUID	AIKUUID = {1,2,3,4,5,6,7,8,9,10,6};
    TSS_HKEY	hAIK;
    TSS_HKEY	hMSigningKey;
    TSS_HKEY	hMStorageKey;
    TSS_HCONTEXT	hContext;
    TSS_RESULT	result;
    TSS_FLAG	initFlags;
    initFlags	= TSS_KEY_TYPE_SIGNING | TSS_KEY_SIZE_2048  |
                  TSS_KEY_VOLATILE | TSS_KEY_NO_AUTHORIZATION |
                  TSS_KEY_NOT_MIGRATABLE;
    TSS_HPOLICY	srkUsagePolicy;

    print_begin_test(nameOfFunction);

    //Create Context
    result = Tspi_Context_Create(&hContext);
    if (result != TSS_SUCCESS) {
        print_error("Tspi_Context_Create", result);
        exit(result);
    }
    //Connect Context
    result = Tspi_Context_Connect(hContext, get_server(GLOBALSERVER));
    if (result != TSS_SUCCESS) {
        print_error("Tspi_Context_Connect", result);
        Tspi_Context_Close(hContext);
        exit(result);
    }
    //Create hKey
    result = Tspi_Context_CreateObject(hContext,
                                       TSS_OBJECT_TYPE_RSAKEY,
                                       initFlags, &hKey);
    if (result != TSS_SUCCESS) {
        print_error("Tspi_Context_CreateObject", result);
        Tspi_Context_Close(hContext);
        exit(result);
    }
    //Load Key By UUID
    result = Tspi_Context_LoadKeyByUUID(hContext,
                                        TSS_PS_TYPE_SYSTEM,
                                        SRK_UUID, &hSRK);
    if (result != TSS_SUCCESS) {
        print_error("Tspi_Context_LoadKeyByUUID ", result);
        Tspi_Context_CloseObject(hContext, hKey);
        Tspi_Context_Close(hContext);
        exit(result);
    }
#ifndef TESTSUITE_NOAUTH_SRK
    //Get Policy Object
    result = Tspi_GetPolicyObject(hSRK, TSS_POLICY_USAGE, &srkUsagePolicy);
    if (result != TSS_SUCCESS) {
        print_error("Tspi_GetPolicyObject", result);
        Tspi_Context_CloseObject(hContext, hKey);
        Tspi_Context_Close(hContext);
        exit(result);
    }
    //Set Secret
    result = Tspi_Policy_SetSecret(srkUsagePolicy, TESTSUITE_SRK_SECRET_MODE,
                                   TESTSUITE_SRK_SECRET_LEN, TESTSUITE_SRK_SECRET);
    if (result != TSS_SUCCESS) {
        print_error("Tspi_Policy_SetSecret", result);
        Tspi_Context_CloseObject(hContext, hKey);
        Tspi_Context_Close(hContext);
        exit(result);
    }
#endif
    //Create Object for the hAIK Key
    result = Tspi_Context_CreateObject(hContext,
                                       TSS_OBJECT_TYPE_RSAKEY,
                                       TSS_KEY_SIZE_2048 |TSS_KEY_TYPE_SIGNING, &hAIK);
    if (result != TSS_SUCCESS) {
        print_error("Tspi_Context_CreateObject", result);
        Tspi_Context_CloseObject(hContext, hKey);
        Tspi_Context_Close(hContext);
        exit(result);
    }
    //Create the hAIK Key
    result = Tspi_Key_CreateKey(hAIK, hSRK, 0);
    if (result != TSS_SUCCESS) {
        print_error("Tspi_Key_CreateKey", result);
        Tspi_Context_CloseObject(hContext, hAIK);
        Tspi_Context_CloseObject(hContext, hKey);
        Tspi_Context_Close(hContext);
        exit(result);
    }
    // Load hAIK Key
    result = Tspi_Key_LoadKey(hAIK, hSRK);
    if (result != TSS_SUCCESS) {
        print_error("Tspi_Context_CreateObject", result);
        Tspi_Context_CloseObject(hContext, hAIK);
        Tspi_Context_CloseObject(hContext, hKey);
        Tspi_Context_Close(hContext);
        exit(result);
//.........这里部分代码省略.........
开发者ID:srajiv,项目名称:testsuite,代码行数:101,代码来源:Tspi_ChangeAuthAsym02.c

示例13: main_v1_1

int
main_v1_1(void){

	char		*nameOfFunction = "Tspi_Context_GetRegisteredKeysByUUID03";
	TSS_HCONTEXT	hContext;
	TSS_HTPM	hTPM;
	TSS_FLAG	initFlags;
	TSS_HKEY	hKey;
	TSS_HKEY	hSRK;
	TSS_RESULT	result;
	TSS_UUID	migratableSignUUID={1, 2, 3, 4, 5, {6, 7, 8, 9, 10, 2}};
	TSS_HPOLICY	srkUsagePolicy;

	UINT32			pulKeyHierarchySize;
	TSS_KM_KEYINFO*		ppKeyHierarchy;

	initFlags	= TSS_KEY_TYPE_SIGNING | TSS_KEY_SIZE_512  |
			TSS_KEY_VOLATILE | TSS_KEY_NO_AUTHORIZATION |
			TSS_KEY_NOT_MIGRATABLE;

	print_begin_test(nameOfFunction);

		//Create
	result = Tspi_Context_Create(&hContext);
	if (result != TSS_SUCCESS) {
		print_error("Tspi_Context_Create ", result);
		exit(result);
	}
		//Connect
	result = Tspi_Context_Connect(hContext, get_server(GLOBALSERVER));
	if (result != TSS_SUCCESS) {
		print_error("Tspi_Context_Connect ", result);
		Tspi_Context_Close(hContext);
		exit(result);
	}
		//Get TPM Object
	result = Tspi_Context_GetTpmObject(hContext, &hTPM);
	if (result != TSS_SUCCESS) {
		print_error("Tspi_Context_GetTpmObject ", result);
		Tspi_Context_Close(hContext);
		exit(result);
	}
		//Create Object
	result = Tspi_Context_CreateObject(hContext,
				TSS_OBJECT_TYPE_RSAKEY,
				initFlags, &hKey);
	if (result != TSS_SUCCESS) {
		print_error("Tspi_Context_CreateObject ", result);
		Tspi_Context_Close(hContext);
		exit(result);
	}
		//Load Key by UUID
	result = Tspi_Context_LoadKeyByUUID(hContext, TSS_PS_TYPE_SYSTEM, 
					SRK_UUID, &hSRK);
	if (result != TSS_SUCCESS) {
		print_error("Tspi_Context_LoadKeyByUUID ", result);
		Tspi_Context_CloseObject(hContext, hKey);
		Tspi_Context_Close(hContext);
		exit(result);
	}
#ifndef TESTSUITE_NOAUTH_SRK
		//Get Policy Object for the srkUsagePolicy
	result = Tspi_GetPolicyObject(hSRK, TSS_POLICY_USAGE, &srkUsagePolicy);
	if (result != TSS_SUCCESS) {
		print_error("Tspi_GetPolicyObject ", result);
		Tspi_Context_CloseObject(hContext, hKey);
		Tspi_Context_Close(hContext);
		exit(result);
	}
		//Set Secret for the srkUsagePolicy
	result = Tspi_Policy_SetSecret(srkUsagePolicy, TESTSUITE_SRK_SECRET_MODE,
			TESTSUITE_SRK_SECRET_LEN, TESTSUITE_SRK_SECRET);
	if (result != TSS_SUCCESS) {
		print_error("Tspi_Policy_SetSecret ", result);
		Tspi_Context_CloseObject(hContext, hKey);
		Tspi_Context_Close(hContext);
		exit(result);
	}
#endif
		//Create the hKey with the hSRK wrapping key
	result = Tspi_Key_CreateKey(hKey, hSRK, 0);
	if (result != TSS_SUCCESS) {
		print_error("Tspi_Key_CreateKey", result);
		Tspi_Context_CloseObject(hContext, hKey);
		Tspi_Context_Close(hContext);
		exit(result);
	}
		//Register the hKey
	result = Tspi_Context_RegisterKey(hContext,
				hKey, TSS_PS_TYPE_SYSTEM, migratableSignUUID,
				TSS_PS_TYPE_SYSTEM, SRK_UUID);
	if (result != TSS_SUCCESS && TSS_ERROR_CODE(result) != TSS_E_KEY_ALREADY_REGISTERED) {
		print_error("Tspi_Context_RegisterKey ", result);
		Tspi_Context_CloseObject(hContext, hKey);
		Tspi_Context_Close(hContext);
		exit(result);
	}
		//Get Registered Keys By UUID
	result = Tspi_Context_GetRegisteredKeysByUUID(hContext, 
			-1, &migratableSignUUID,
//.........这里部分代码省略.........
开发者ID:juliarahmawati,项目名称:testsuite,代码行数:101,代码来源:Tspi_Context_GetRegisteredKeysByUUID03.c

示例14: main_v1_1

int main_v1_1(void)
{
	char *function = "Tspi_Hash_Sign03";
	TSS_HCONTEXT hContext;
	TSS_HKEY hSRK;
	TSS_HKEY hMSigningKey;
	TSS_HKEY hKey;
	TSS_UUID SRKUUID = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 };
	TSS_UUID migratableSignUUID = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 2 };
	TSS_HHASH hHash;
	BYTE *prgbSignature;
//      UINT32          pulSignatureLength;
	TSS_RESULT result;
	TSS_HPOLICY srkUsagePolicy;
	TSS_FLAG initFlags = TSS_KEY_TYPE_SIGNING | TSS_KEY_SIZE_2048 |
	    TSS_KEY_VOLATILE | TSS_KEY_NO_AUTHORIZATION |
	    TSS_KEY_NOT_MIGRATABLE;
	UINT32 exitCode = 0;

	print_begin_test(function);

	// Create Context
	result = Tspi_Context_Create(&hContext);
	if (result != TSS_SUCCESS) {
		print_error("Tspi_Context_Create", result);
		exit(result);
	}
	// Connect to Context
	result = Tspi_Context_Connect(hContext, get_server(GLOBALSERVER));
	if (result != TSS_SUCCESS) {
		print_error("Tspi_Context_Connect", result);
		Tspi_Context_FreeMemory(hContext, NULL);
		Tspi_Context_Close(hContext);
		exit(result);
	}
	// create hKey
	result = Tspi_Context_CreateObject(hContext,
					   TSS_OBJECT_TYPE_RSAKEY,
					   initFlags, &hKey);
	if (result != TSS_SUCCESS) {
		print_error("Tspi_Context_CreateObject (hKey)", result);
		Tspi_Context_FreeMemory(hContext, NULL);
		Tspi_Context_Close(hContext);
		exit(result);
	}
	//Load Key By UUID
	result = Tspi_Context_LoadKeyByUUID(hContext, TSS_PS_TYPE_SYSTEM,
					    SRK_UUID, &hSRK);
	if (result != TSS_SUCCESS) {
		print_error("Tspi_Context_LoadKeyByUUID (hSRK)", result);
		Tspi_Context_FreeMemory(hContext, NULL);
		Tspi_Context_Close(hContext);
		exit(result);
	}
#ifndef TESTSUITE_NOAUTH_SRK
	//Get Policy Object
	result = Tspi_GetPolicyObject(hSRK, TSS_POLICY_USAGE,
				      &srkUsagePolicy);
	if (result != TSS_SUCCESS) {
		print_error("Tspi_GetPolicyObject", result);
		Tspi_Context_FreeMemory(hContext, NULL);
		Tspi_Context_Close(hContext);
		exit(result);
	}
	//Set Secret
	result =
	    Tspi_Policy_SetSecret(srkUsagePolicy,
				  TESTSUITE_SRK_SECRET_MODE,
				  TESTSUITE_SRK_SECRET_LEN,
				  TESTSUITE_SRK_SECRET);
	if (result != TSS_SUCCESS) {
		print_error("Tspi_Policy_SetSecret", result);
		Tspi_Context_FreeMemory(hContext, NULL);
		Tspi_Context_Close(hContext);
		exit(result);
	}
#endif
	//Create Signing Key
	result =
	    Tspi_Context_CreateObject(hContext, TSS_OBJECT_TYPE_RSAKEY,
				      TSS_KEY_SIZE_2048 |
				      TSS_KEY_TYPE_SIGNING, &hMSigningKey);
	if (result != TSS_SUCCESS) {
		print_error("Tspi_Context_CreateObject (signing key)",
			    result);
		Tspi_Context_FreeMemory(hContext, NULL);
		Tspi_Context_Close(hContext);
		exit(result);
	}

	result = Tspi_Key_CreateKey(hMSigningKey, hSRK, 0);
	if (result != TSS_SUCCESS) {
		print_error("Tspi_Key_CreateKey (signing key)",
			    result);
		Tspi_Context_FreeMemory(hContext, NULL);
		Tspi_Context_Close(hContext);
		exit(result);
	}

	result = Tspi_Context_RegisterKey(hContext, hMSigningKey,
//.........这里部分代码省略.........
开发者ID:juliarahmawati,项目名称:testsuite,代码行数:101,代码来源:Tspi_Hash_Sign03.c

示例15: main_v1_2

int
main_v1_2( char version )
{
	char			*function = "Tspi_TPM_GetCapability18";
	UINT32			pulRespDataLength;
	BYTE			*pRetData;
	UINT32			subCap, subCapLength, numPcrs;
	TSS_HCONTEXT		hContext;
	TSS_HTPM		hTPM;
	TSS_RESULT		result;
	UINT32			exitCode;

	print_begin_test( function );

		// Create Context
	result = Tspi_Context_Create( &hContext );
	if ( result != TSS_SUCCESS )
	{
		print_error( "Tspi_Context_Create", result );
		exit( result );
	}

		// Connect to Context
	result = Tspi_Context_Connect( hContext, get_server(GLOBALSERVER) );
	if ( result != TSS_SUCCESS )
	{
		print_error( "Tspi_Context_Connect", result );
		Tspi_Context_FreeMemory( hContext, NULL );
		Tspi_Context_Close( hContext );
		exit( result );
	}

		// Retrieve TPM object of context
	result = Tspi_Context_GetTpmObject( hContext, &hTPM );
	if ( result != TSS_SUCCESS )
	{
		print_error( "Tspi_Context_GetTpmObject", result );
		Tspi_Context_FreeMemory( hContext, NULL );
		Tspi_Context_Close( hContext );
		exit( result );
	}

	subCap = TSS_TPMCAP_PROP_SESSIONS;
	subCapLength = sizeof(UINT32);

	result = Tspi_TPM_GetCapability( hTPM, TSS_TPMCAP_PROPERTY,
						subCapLength, (BYTE *)&subCap,
						&pulRespDataLength,
						&pRetData );
	if ( result != TSS_SUCCESS )
	{
		if( !(checkNonAPI(result)) )
		{
			print_error( function, result );
			exitCode = 1;
		}
		else
		{
			print_error_nonapi( function, result );
			exitCode = 1;
		}
	}
	else
	{
		print_success( function, result );
		exitCode = 0;

		if (pulRespDataLength == sizeof(UINT32))
			fprintf(stderr, "\tThere are %u available sessions in the pool\n\n",
				*(UINT32 *)pRetData );
	}

	print_end_test( function );
	Tspi_Context_FreeMemory( hContext, NULL );
	Tspi_Context_Close( hContext );
	exit( exitCode );
}
开发者ID:juliarahmawati,项目名称:testsuite,代码行数:77,代码来源:Tspi_TPM_GetCapability18.c


注:本文中的Tspi_Context_Close函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。