Пример #1
0
void check_fail(char *msg, int cin)
{
	int in = TSS_ERROR_CODE(cin);
	printf("%s: ", msg);
	if(in == TSS_SUCCESS) {
		printf("TSS_SUCCESS\n");
		return;
	} else if(in == TSS_E_INVALID_HANDLE)
		printf("TSS_E_INVALID_HANDLE\n");
	else if(in == TSS_E_INTERNAL_ERROR)
		printf("TSS_E_INTERNAL_ERROR\n");
	else if(in == TSS_E_BAD_PARAMETER)
		printf("TSS_E_BAD_PARAMETER\n");
	else if(in == TSS_E_HASH_INVALID_LENGTH)
		printf("TSS_E_HASH_INVALID_LENGTH\n");
	else if(in == TSS_E_HASH_NO_DATA)
		printf("TSS_E_HASH_NO_DATA\n");
	else if(in == TSS_E_INVALID_SIGSCHEME)
		printf("TSS_E_INVALID_SIGSCHEME\n");
	else if(in == TSS_E_HASH_NO_IDENTIFIER)
		printf("TSS_E_HASH_NO_IDENTIFIER\n");
	else if(in == TSS_E_PS_KEY_NOTFOUND)
		printf("TSS_E_PS_KEY_NOTFOUND\n");
	else if(in == TSS_E_BAD_PARAMETER)
		printf("TSS_E_BAD_PARAMETER\n");
	else if(in == TSS_E_PS_KEY_NOTFOUND)
		printf("TSS_E_P_KEY_NOTFOUND\n");
	else
		printf("Not here: 0x%x\n", in);
	exit(EXIT_FAILURE);
}
Пример #2
0
void check(char *msg, int cin)
{
	int in = TSS_ERROR_CODE(cin);
	printf("%s: ", msg);
	if(in == TSS_SUCCESS) {
		printf("TSS_SUCCESS\n");
		return;
	} else if(in == TSS_E_INVALID_HANDLE)
		printf("\t\tTSS_E_INVALID_HANDLE\n");
	else if(in == TSS_E_INTERNAL_ERROR)
		printf("\t\tTSS_E_INTERNAL_ERROR\n");
	else if(in == TSS_E_BAD_PARAMETER)
		printf("\t\tTSS_E_BAD_PARAMETER\n");
	else if(in == TSS_E_HASH_INVALID_LENGTH)
		printf("\t\tTSS_E_HASH_INVALID_LENGTH\n");
	else if(in == TSS_E_HASH_NO_DATA)
		printf("\t\tTSS_E_HASH_NO_DATA\n");
	else if(in == TSS_E_INVALID_SIGSCHEME)
		printf("\t\tTSS_E_INVALID_SIGSCHEME\n");
	else if(in == TSS_E_HASH_NO_IDENTIFIER)
		printf("\t\tTSS_E_HASH_NO_IDENTIFIER\n");
	else if(in == TSS_E_PS_KEY_NOTFOUND)
		printf("\t\tTSS_E_PS_KEY_NOTFOUND\n");
	else if(in == TSS_E_BAD_PARAMETER)
		printf("\t\tTSS_E_BAD_PARAMETER\n");
	else
		printf("\t\tNot here: 0x%x\n", in);

	Tspi_Context_FreeMemory(hContext, NULL);
	Tspi_Context_Close(hContext);

	exit(1);
}
main_v1_1(void){
	char		*nameOfFunction = "Tspi_GetAttribData07";
	TSS_HKEY	hKey;
	TSS_HCONTEXT	hContext;
	TSS_RESULT	result;
	BYTE*		BLOB;
	UINT32		BlobLength;

	print_begin_test(nameOfFunction);

		//Call GetAttribData
	result = Tspi_GetAttribData(hKey,
			TSS_TSPATTRIB_KEY_BLOB,
			TSS_TSPATTRIB_KEYBLOB_BLOB,
			&BlobLength, &BLOB);
	if (TSS_ERROR_CODE(result) != TSS_E_INVALID_HANDLE) {
		if(!checkNonAPI(result)){
			print_error(nameOfFunction, result);
			print_end_test(nameOfFunction);
			exit(result);
		}
		else{
			print_error_nonapi(nameOfFunction, result);
			print_end_test(nameOfFunction);
			exit(result);
		}
	}
	else{
		print_success(nameOfFunction, result);
		print_end_test(nameOfFunction);
		exit(0);
	}
}
main_v1_1(void){

	char		*nameOfFunction = "Tspi_GetAttribData09";
	TSS_HCONTEXT	hContext;
	TSS_RESULT	result;
	TSS_HKEY	hSRK;
	BYTE*		BLOB;
	UINT32		BlobLength;

	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);
	}
		//Load Key by UUID for SRK
	result = Tspi_Context_LoadKeyByUUID(hContext, TSS_PS_TYPE_SYSTEM,
				SRK_UUID, &hSRK);
	if (result != TSS_SUCCESS) {
		print_error("Tspi_Context_LoadKeyByUUID", result);
		Tspi_Context_Close(hContext);
		exit(result);
	}
		//Call GetAttribData
	result = Tspi_GetAttribData(hSRK, TSS_TSPATTRIB_KEY_BLOB, TSS_TSPATTRIB_KEYBLOB_PUBLIC_KEY,
				    &BlobLength, &BLOB);
	if (TSS_ERROR_CODE(result) != TSS_E_BAD_PARAMETER) {
		if(!checkNonAPI(result)){
			print_error(nameOfFunction, result);
			print_end_test(nameOfFunction);
			Tspi_Context_FreeMemory(hContext, NULL);
			Tspi_Context_Close(hContext);
			exit(result);
		}
		else{
			print_error_nonapi(nameOfFunction, result);
			print_end_test(nameOfFunction);
			Tspi_Context_FreeMemory(hContext, NULL);
			Tspi_Context_Close(hContext);
			exit(result);
		}
	}
	else{
		print_success(nameOfFunction, result);
		print_end_test(nameOfFunction);
		Tspi_Context_FreeMemory(hContext, NULL);
		Tspi_Context_Close(hContext);
		exit(0);
	}
}
/* create and store keys with the uuids in the @uuids parameter. Unregister
 * any keys in the PS that are already stored. hParentKey should already be
 * loaded and will become the parent of the key stored with uuids[0] */
TSS_RESULT
store_keys(TSS_HCONTEXT hContext, TSS_HKEY hParentKey, TSS_UUID *uuidParent0,
	   TSS_UUID **uuids)
{
	int i;
	TSS_RESULT result;
	TSS_UUID *uuidParent;
	TSS_HKEY hKey;
	TSS_FLAG initFlags;

	for (i = 0; uuids[i]; i++) {
		/* unregister any keys in the PS that are in the way */
		if ((result = Tspi_Context_UnregisterKey(hContext,
							 TSS_PS_TYPE_SYSTEM,
							 *uuids[i], &hKey)) &&
		    (TSS_ERROR_CODE(result) != TSS_E_PS_KEY_NOTFOUND)) {
			print_error("Tspi_Context_UnregisterKey", result);
			return result;
		}
	}

	initFlags = TSS_KEY_SIZE_2048 | TSS_KEY_TYPE_STORAGE |
		    TSS_KEY_NO_AUTHORIZATION;
	uuidParent = uuidParent0;
	for (i = 0; uuids[i]; i++) {
		/* create the keys and register them */
		if ((result = Tspi_Context_CreateObject(hContext,
							TSS_OBJECT_TYPE_RSAKEY,
							initFlags, &hKey))) {
			print_error("Tspi_Context_CreateObject", result);
			return result;
		}

		if ((result = Tspi_Key_CreateKey(hKey, hParentKey, 0))) {
			print_error("Tspi_Key_CreateKey", result);
			return result;
		}

		/* load key so that the child can be created */
		if ((result = Tspi_Key_LoadKey(hKey, hParentKey))) {
			print_error("Tspi_Key_LoadKey", result);
			return result;
		}

		/* register the new key */
		if ((result = Tspi_Context_RegisterKey(hContext, hKey,
						       TSS_PS_TYPE_SYSTEM,
						       *uuids[i],
						       TSS_PS_TYPE_SYSTEM,
						       *uuidParent))) {
			print_error("Tspi_Context_RegisterKey", result);
			return result;
		}
		hParentKey = hKey;
		uuidParent = uuids[i];
	}

	return TSS_SUCCESS;
}
int
main_v1_1( void )
{
	char			*function = "Tspi_TPM_StirRandom02";
	BYTE			entropy;
	TSS_HCONTEXT		hContext;
	TSS_HTPM		whTPM = -1;
	TSS_RESULT		result;
	UINT32			exitCode = 0;

	print_begin_test( function );

		// seed entropy with time
	srand( time(0) );

		// 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 );
	}

	entropy = ( rand() % 100 );

		//Get random number
	result = Tspi_TPM_StirRandom( whTPM, 16, &entropy );
	if ( TSS_ERROR_CODE(result) != TSS_E_INVALID_HANDLE )
	{
		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 );
}
int
main_v1_2( char version )
{
	char *			function = "Tspi_TPM_Delegate_UpdateVerificationCount03";
	TSS_HCONTEXT		hContext;
	TSS_HKEY		hSRK;
	TSS_HTPM		hTPM;
	TSS_HPOLICY		hTPMPolicy;
	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 = 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_TPM_Delegate_UpdateVerificationCount(hTPM, -1);
	if (TSS_ERROR_CODE(result) != TSS_E_INVALID_HANDLE)
	{
		print_error( function, result );
		result = 1;
		goto done;
	}
	else
	{
		print_success( function, result );
		result = 0;
	}

done:
	
	Tspi_Context_FreeMemory( hContext, NULL );
	Tspi_Context_Close( hContext );

	print_end_test( function );
	exit( result );
}
main_v1_1(void){

	char		*nameOfFunction = "Tspi_TPM_SelfTestFull02";
	TSS_HCONTEXT	hContext;
	TSS_RESULT	result;
	TSS_HTPM	hTPM;
	
	print_begin_test(nameOfFunction);

		//Create Result
	result = Tspi_Context_Create(&hContext);
	if (result != TSS_SUCCESS) {
		print_error("Tspi_Context_Create ", result);
		exit(result);
	}
		//Connect Result
	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);
	}
		//Self Test
	result = Tspi_TPM_SelfTestFull(-1);
	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_Close(hContext);
			exit(result);
		}
		else{
			print_error_nonapi(nameOfFunction, result);
			print_end_test(nameOfFunction);
			Tspi_Context_FreeMemory(hContext, NULL);
			Tspi_Context_Close(hContext);
			exit(result);
		}
	}
	else{
		print_success(nameOfFunction, result);
		print_end_test(nameOfFunction);
		Tspi_Context_FreeMemory(hContext, NULL);
		Tspi_Context_Close(hContext);
		exit(0);
	}
}
int
main_v1_1(void){

	char		*nameOfFunction = "Tspi_Context_CreateObject02";
	TSS_HCONTEXT	hContext;
	TSS_HKEY	hSignatureKey;
	TSS_RESULT	result;

	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 Object
	result = Tspi_Context_CreateObject(hContext, TSS_OBJECT_TYPE_HASH,
				TSS_KEY_SIZE_2048 | TSS_KEY_TYPE_SIGNING |
				TSS_KEY_MIGRATABLE, &hSignatureKey);
	if (TSS_ERROR_CODE(result) != TSS_E_INVALID_OBJECT_INITFLAG){
		if(!checkNonAPI(result)){
			print_error(nameOfFunction, result);
			print_end_test(nameOfFunction);
			Tspi_Context_FreeMemory(hContext, NULL);
			Tspi_Context_CloseObject(hContext, hSignatureKey);
			Tspi_Context_Close(hContext);
			exit(result);
		}
		else{
			print_error_nonapi(nameOfFunction, result);
			print_end_test(nameOfFunction);
			Tspi_Context_FreeMemory(hContext, NULL);
			Tspi_Context_CloseObject(hContext, hSignatureKey);
			Tspi_Context_Close(hContext);
			exit(result);
		}
	}
	else{
		print_success(nameOfFunction, result);
		print_end_test(nameOfFunction);
		Tspi_Context_FreeMemory(hContext, NULL);
		Tspi_Context_CloseObject(hContext, hSignatureKey);
		Tspi_Context_Close(hContext);
		exit(0);
	}
}
int main_v1_1(void)
{
	char *function = "Tspi_Hash_GetHashValue04";
	TSS_HCONTEXT hContext;
	TSS_HHASH hHash;
	UINT32 ulHashValueLength, exitCode = 0;
	BYTE *rgbHashValue, hashBuf[20];
	TSS_RESULT result;

	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);
	}

	result = Tspi_Context_CreateObject(hContext, TSS_OBJECT_TYPE_HASH,
					   TSS_HASH_SHA1, &hHash);
	if (result != TSS_SUCCESS) {
		print_error("Tspi_Context_CreateObject (hash)", result);
		Tspi_Context_FreeMemory(hContext, NULL);
		Tspi_Context_Close(hContext);
		exit(result);
	}

	result = Tspi_Hash_GetHashValue(hHash, &ulHashValueLength,
					&rgbHashValue);
	if (TSS_ERROR_CODE(result) != TSS_E_HASH_NO_DATA) {
		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);
}
main_v1_2(char version)
{
	char		*nameOfFunction = "Tspi_TPM_ReadCounter03";
	TSS_HCONTEXT	hContext;
	TSS_HTPM	hTPM;
	TSS_RESULT	result;

	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);
		exit(result);
	}
		//GetTPM Object
	result = Tspi_Context_GetTpmObject(hContext, &hTPM);
	if (result != TSS_SUCCESS) {
		print_error("Tspi_Context_GetTPMObject", result);
		exit(result);
	}
		// Read Counter
	result = Tspi_TPM_ReadCounter(hTPM, NULL);
	if (TSS_ERROR_CODE(result) != TSS_E_BAD_PARAMETER) {
		if(!checkNonAPI(result)){
			print_error(nameOfFunction, result);
			print_end_test(nameOfFunction);
			Tspi_Context_FreeMemory(hContext, NULL);
			Tspi_Context_Close(hContext);
			exit(result);
		}
		else{
			print_error_nonapi(nameOfFunction, result);
			print_end_test(nameOfFunction);
			Tspi_Context_FreeMemory(hContext, NULL);
			Tspi_Context_Close(hContext);
			exit(result);
		}
	}
	else{
		print_success(nameOfFunction, result);
		print_end_test(nameOfFunction);
		Tspi_Context_FreeMemory(hContext, NULL);
		Tspi_Context_Close(hContext);
		exit(0);
	}
}
int
main_v1_1( void )
{
	char			*function = "Tspi_Context_FreeMemory02";
	BYTE			random;
	TSS_HCONTEXT		hContext;
	TSS_HCONTEXT		whContext = -1;
	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_Close( hContext );
		exit( result );
	}

		// Free selected memory
	result = Tspi_Context_FreeMemory( whContext, &random );
	if ( TSS_ERROR_CODE(result) != TSS_E_INVALID_HANDLE )
	{
		if( !(checkNonAPI(result)) )
		{
			print_error( function, result );
			exitCode = result;
		}
		else
		{
			print_error_nonapi( function, result );
			exitCode = result;
		}
	}
	else
	{
		print_success( function, result );
	}

	print_end_test( function );
	Tspi_Context_Close( hContext );
	exit( exitCode );
}
main_v1_1(void){
	char		*nameOfFunction = "Tspi_TPM_GetEvents03";
	TSS_HCONTEXT	hContext;
	TSS_RESULT	result;
	TSS_HTPM	hTPM;
	TSS_PCR_EVENT*	prgPcrEvents;

	print_begin_test(nameOfFunction);

		//Create Result
	result = Tspi_Context_Create(&hContext);
	if (result != TSS_SUCCESS) {
		print_error("Tspi_Context_Create ", result);
		exit(result);
	}
		//Connect Result
	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);
	}
		//Get Events
	result = Tspi_TPM_GetEvents(-1, -1, -1, &hContext, &prgPcrEvents);
	if (TSS_ERROR_CODE(result) != TSS_E_INVALID_HANDLE) {
		if(!checkNonAPI(result)){
			print_error(nameOfFunction, result);
			print_end_test(nameOfFunction);
			Tspi_Context_Close(hContext);
			exit(result);
		}
		else{
			print_error_nonapi(nameOfFunction, result);
			print_end_test(nameOfFunction);
			Tspi_Context_Close(hContext);
			exit(result);
		}
	}
	else{
		print_success(nameOfFunction, result);
		print_end_test(nameOfFunction);
		Tspi_Context_Close(hContext);
		exit(0);
	}
}
main_v1_2(char version){

	char		*nameOfFunction = "Tspi_TPM_OwnerGetSRKPubKey02";
	TSS_RESULT	result;
	TSS_HCONTEXT	hContext;
	TSS_HKEY	hSRK;
	TSS_HPOLICY	hPolicy;
	UINT32          pulPubKeyLength;
	BYTE            *prgbPubKey;

	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);
		exit(result);
	}

		//Get SRK Public Key
	result = Tspi_TPM_OwnerGetSRKPubKey(0xffffffff, &pulPubKeyLength, &prgbPubKey);
	if (TSS_ERROR_CODE(result) != TSS_E_INVALID_HANDLE) {
		if(!checkNonAPI(result)){
			print_error(nameOfFunction, result);
			print_end_test(nameOfFunction);
			Tspi_Context_Close(hContext);
			exit(result);
		} else {
			print_success(nameOfFunction, result);
			print_end_test(nameOfFunction);
			Tspi_Context_Close(hContext);
		exit(result);}
	} else {
		print_success(nameOfFunction, result);
		print_end_test(nameOfFunction);
		Tspi_Context_Close(hContext);
		exit(0);
	}
}
int main_v1_1(void)
{
	char *function = "Tspi_Hash_UpdateHashValue02";
	TSS_HCONTEXT hContext;
	TSS_HHASH whHash = -1;
	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);
	}

	result = Tspi_Hash_UpdateHashValue(whHash, 24,
					   "Je pense, danc je suis.");

	if (TSS_ERROR_CODE(result) != TSS_E_INVALID_HANDLE) {
		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);
}
int
main_v1_1(void){

	char		*nameOfFunction = "Tspi_Context_Close03";
	TSS_HCONTEXT	hContext;
	TSS_RESULT	result; 

	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);
	}
		//Close Context
	result = Tspi_Context_Close(-1);
	if (TSS_ERROR_CODE(result) != TSS_E_INVALID_HANDLE) {
		if(!checkNonAPI(result)){
			print_error(nameOfFunction, result);
			print_end_test(nameOfFunction);
			Tspi_Context_Close(hContext);
			exit(result);
		}
		else{
			print_error_nonapi(nameOfFunction, result);
			print_end_test(nameOfFunction);
			Tspi_Context_Close(hContext);
			exit(result);
		}
	}
	else{
		print_success(nameOfFunction, result);
		print_end_test(nameOfFunction);
		exit(0);
	}
}
int
main_v1_1(void){

	char		*nameOfFunction = "Tspi_Context_LoadKeyByUUID02";
	TSS_HCONTEXT	hContext;
	TSS_RESULT	result;
	TSS_HKEY	hSRK;

	print_begin_test(nameOfFunction);

		//Create Result
	result = Tspi_Context_Create(&hContext);
	if (result != TSS_SUCCESS) {
		print_error("Tspi_Context_Create ", result);
		exit(result);
	}
		//Load Key By UUID 
	result = Tspi_Context_LoadKeyByUUID(-1,
		TSS_PS_TYPE_SYSTEM, SRK_UUID, &hSRK);
	if (TSS_ERROR_CODE(result) != TSS_E_INVALID_HANDLE) {
		if(!checkNonAPI(result)){
			print_error(nameOfFunction, result);
			print_end_test(nameOfFunction);
			Tspi_Context_Close(hContext);
			exit(result);
		}
		else{
			print_error_nonapi(nameOfFunction, result);
			print_end_test(nameOfFunction);
			Tspi_Context_Close(hContext);
			exit(result);
		}
	}
	else{
		print_success(nameOfFunction, result);
		print_end_test(nameOfFunction);
		Tspi_Context_Close(hContext);
		exit(0);
	}
}
int
main_v1_2(char version)
{
	char		*nameOfFunction = "Tspi_TPM_GetTestResults-trans03";
	TSS_HCONTEXT	hContext;
	TSS_RESULT	result;
	TSS_HTPM	hTPM;
	UINT32		TestResultLength;
	BYTE*		prgbTestResult;
	TSS_HKEY	hSRK, hWrappingKey;

	print_begin_test(nameOfFunction);

	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 = 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);
	}
		//Get Test Result
	result = Tspi_TPM_GetTestResult(hTPM, &TestResultLength, &prgbTestResult);
	if (result != TSS_SUCCESS) {
		print_error("Testsuite_Transport_Init", result);
		Tspi_Context_Close(hContext);
		exit(result);
	}

	result = Testsuite_Transport_Final(hContext, 0);
	if (result != TSS_SUCCESS) {
		if((TSS_ERROR_CODE(result) == TSS_E_INVALID_HANDLE) ||
			(TSS_ERROR_CODE(result) == TSS_E_INTERNAL_ERROR) ||
			(TSS_ERROR_CODE(result) == TSS_E_BAD_PARAMETER) ||
			(TSS_ERROR_CODE(result) == TSS_E_KEY_NO_MIGRATION_POLICY) ||
			(TSS_ERROR_CODE(result) == TSS_E_FAIL) ||
			(TSS_ERROR_CODE(result) == TSS_E_NOTIMPL) ||
			(TSS_ERROR_CODE(result) == TSS_E_PS_KEY_NOTFOUND) ||
			(TSS_ERROR_CODE(result) == TSS_E_KEY_ALREADY_REGISTERED) ||
			(TSS_ERROR_CODE(result) == TSS_E_CANCELED) ||
			(TSS_ERROR_CODE(result) == TSS_E_TIMEOUT) ||
			(TSS_ERROR_CODE(result) == TSS_E_OUTOFMEMORY) ||
			(TSS_ERROR_CODE(result) == TSS_E_TPM_UNEXPECTED) ||
			(TSS_ERROR_CODE(result) == TSS_E_COMM_FAILURE) ||
			(TSS_ERROR_CODE(result) == TSS_E_TPM_UNSUPPORTED_FEATURE)){

			print_error(nameOfFunction, result);
			print_end_test(nameOfFunction);
			Tspi_Context_Close(hContext);
			exit(result);
		}
		else{
			print_error_nonapi(nameOfFunction, result);
			print_end_test(nameOfFunction);
			Tspi_Context_Close(hContext);
			exit(result);
		}
	}
	else{
		result = Tspi_Context_FreeMemory(hContext, prgbTestResult);
		if (result != TSS_SUCCESS) {
			print_error("Tspi_Context_FreeMemory ", result);
			Tspi_Context_Close(hContext);
			exit(result);
		}
		print_success(nameOfFunction, result);
		print_end_test(nameOfFunction);
		Tspi_Context_Close(hContext);
		exit(0);
	}
}
main_v1_1(void)
{

	char *nameOfFunction = "Tspi_Key_CreateKey02";
	TSS_HCONTEXT hContext;
	TSS_HTPM hTPM;
	TSS_FLAG initFlags;
	TSS_HKEY hKey;
	TSS_HKEY hSRK;
	TSS_RESULT result;
	TSS_UUID uuid;
	BYTE *randomData;
	TSS_HPOLICY srkUsagePolicy, keyUsagePolicy;
	initFlags = TSS_KEY_TYPE_SIGNING | TSS_KEY_SIZE_2048 |
	    TSS_KEY_VOLATILE | TSS_KEY_NO_AUTHORIZATION |
	    TSS_KEY_NOT_MIGRATABLE;
	BYTE well_known_secret[20] = TSS_WELL_KNOWN_SECRET;

	print_begin_test(nameOfFunction);

	//Create Context
	result = Tspi_Context_Create(&hContext);
	if (result != TSS_SUCCESS) {
		print_error("Tspi_Context_Create", result);
		print_error_exit(nameOfFunction, err_string(result));
		exit(result);
	}
	//Connect Context
	result = Tspi_Context_Connect(hContext, get_server(GLOBALSERVER));
	if (result != TSS_SUCCESS) {
		print_error("Tspi_Context_Connect", result);
		print_error_exit(nameOfFunction, err_string(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);
		print_error_exit(nameOfFunction, err_string(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);
		print_error_exit(nameOfFunction, err_string(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);
		print_error_exit(nameOfFunction, err_string(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);
		print_error_exit(nameOfFunction, err_string(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);
		print_error_exit(nameOfFunction, err_string(result));
		Tspi_Context_CloseObject(hContext, hKey);
		Tspi_Context_Close(hContext);
		exit(result);
	}
#endif
	//Get Policy Object
	result =
	    Tspi_GetPolicyObject(hKey, TSS_POLICY_USAGE, &keyUsagePolicy);
	if (result != TSS_SUCCESS) {
		print_error("Tspi_GetPolicyObject", result);
		print_error_exit(nameOfFunction, err_string(result));
		Tspi_Context_CloseObject(hContext, hKey);
		Tspi_Context_Close(hContext);
		exit(result);
	}
	//Create Key
	result = Tspi_Key_CreateKey(hKey, -1, 0);
	if (TSS_ERROR_CODE(result) != TSS_E_INVALID_HANDLE) {
		if (!checkNonAPI(result)) {
			print_error(nameOfFunction, result);
			print_end_test(nameOfFunction);
			Tspi_Context_CloseObject(hContext, hKey);
			Tspi_Context_Close(hContext);
			exit(result);
		} else {
			print_error_nonapi(nameOfFunction, result);
			print_end_test(nameOfFunction);
			Tspi_Context_CloseObject(hContext, hKey);
			Tspi_Context_Close(hContext);
			exit(result);
		}
	} else {
		print_success(nameOfFunction, result);
		print_end_test(nameOfFunction);
		Tspi_Context_CloseObject(hContext, hKey);
		Tspi_Context_Close(hContext);
		exit(0);
	}
}
Пример #20
0
int
main_v1_1( void )
{
    char			*function = "Tspi_TPM_SetStatus02";
    TSS_HCONTEXT		hContext;
    TSS_HTPM		hTPM;
    TSS_HTPM		whTPM = -1;
    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 );
    }

    //Get random number
    result = Tspi_TPM_SetStatus( whTPM, TSS_TPMSTATUS_SETOWNERINSTALL,
                                 TRUE );
    if ( TSS_ERROR_CODE(result) != TSS_E_INVALID_HANDLE )
    {
        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 );
}
main_v1_1(void){

	char		*nameOfFunction = "Tspi_Key_CreateMigrationBlob03";
	TSS_HCONTEXT	hContext;
	TSS_HKEY	hSRK;
	TSS_HKEY	hKey;
	UINT32		TargetPubKeyLength;
	BYTE		*TargetPublicKeyData;
	BYTE		*MigTicket;
	UINT32		TicketLength;
	BYTE		*randomData;
	UINT32		randomLength;
	UINT32		migBlobLength;
	BYTE		*migBlob;
	UINT32		blobLength;
	TSS_RESULT	result;
	TSS_HTPM	hTPM;
	TSS_HPOLICY	srkUsagePolicy, keyUsagePolicy, keyMigPolicy,
			tpmUsagePolicy;

	print_begin_test(nameOfFunction);

			//Create Context
	result = Tspi_Context_Create(&hContext);
	if (result != TSS_SUCCESS) {
		print_error("Tspi_Context_Create ", result);
		print_error_exit(nameOfFunction, err_string(result));
		exit(result);
	}
		//Connect Context
	result = Tspi_Context_Connect(hContext, get_server(GLOBALSERVER));
	if (result != TSS_SUCCESS) {
		print_error("Tspi_Context_Connect", result);
		print_error_exit(nameOfFunction, err_string(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);
		print_error_exit(nameOfFunction, err_string(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);
		print_error_exit(nameOfFunction, err_string(result));
		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);
		print_error_exit(nameOfFunction, err_string(result));
		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);
		print_error_exit(nameOfFunction, err_string(result));
		Tspi_Context_Close(hContext);
		exit(result);
	}
#endif
		//Get Policy Object
	result = Tspi_GetPolicyObject(hTPM, TSS_POLICY_USAGE, &tpmUsagePolicy);
	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(tpmUsagePolicy, 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 Object
	result = Tspi_Context_CreateObject(hContext, TSS_OBJECT_TYPE_RSAKEY,
				TSS_KEY_TYPE_BIND | TSS_KEY_SIZE_2048 |
				TSS_KEY_NO_AUTHORIZATION | TSS_KEY_NOT_MIGRATABLE,
				&hKey);
	if (result != TSS_SUCCESS) {
		print_error("Tspi_Context_CreateObject", result);
		print_error_exit(nameOfFunction, err_string(result));
		Tspi_Context_Close(hContext);
		exit(result);
	}
		//Create Signing Key
	result = Tspi_Key_CreateKey(hKey, hSRK, 0);
	if (result != TSS_SUCCESS)
	{
		print_error("Tspi_Key_CreateKey", result);
		print_error_exit(nameOfFunction, err_string(result));
		Tspi_Context_Close(hContext);
		Tspi_Context_CloseObject(hContext, hKey);
		exit(result);
	}
		//Authorize Migration Ticket
	result = Tspi_TPM_AuthorizeMigrationTicket(hTPM, hKey,
			TSS_MS_REWRAP, &TicketLength, &MigTicket);
	if (result != TSS_SUCCESS)
	{
		print_error("Tpsi_TPM_AuthorizeMigrationTicket ", result);
		print_error_exit(nameOfFunction, err_string(result));
		Tspi_Context_Close(hContext);
		Tspi_Context_CloseObject(hContext, hKey);
		exit(result);
	}
		//Create Migration Blob
	result = Tspi_Key_CreateMigrationBlob(-1, hSRK,
				TicketLength, MigTicket, &randomLength,
				&randomData, &migBlobLength, &migBlob);
	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, hKey);
			Tspi_Context_Close(hContext);
			exit(result);
		}
		else{
			print_error_nonapi(nameOfFunction, result);
			print_end_test(nameOfFunction);
			Tspi_Context_FreeMemory(hContext, NULL);
			Tspi_Context_CloseObject(hContext, hKey);
			Tspi_Context_Close(hContext);
			exit(result);
		}
	}
	else{
		print_success(nameOfFunction, result);
		print_end_test(nameOfFunction);
		Tspi_Context_FreeMemory(hContext, NULL);
		Tspi_Context_CloseObject(hContext, hKey);
		Tspi_Context_Close(hContext);
		exit(0);
	}
}
int
main_v1_2( char version )
{
	char *			function = "Tspi_TPM_Delegate_GetFamily05";
	TSS_HCONTEXT		hContext;
	TSS_HKEY		hSRK;
	TSS_HTPM 		hTPM, hTPM2;
	TSS_HPOLICY		hTPMPolicy;
	TSS_HDELFAMILY  	hFamily = NULL_HDELFAMILY, hFamily2;
	UINT32                  familyID, returnedID;
	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 = 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_TPM_Delegate_AddFamily(hTPM, 'a', &hFamily);
	if ( result != TSS_SUCCESS )
	{
		print_error( "Tspi_TPM_Delegate_AddFamily", result );
		goto done;
	}

	result = Tspi_GetAttribUint32(hFamily, TSS_TSPATTRIB_DELFAMILY_INFO,
			TSS_TSPATTRIB_DELFAMILYINFO_FAMILYID, &familyID);
	if ( result != TSS_SUCCESS )
	{
		if( !(checkNonAPI(result)) )
		{
			print_error( "Tspi_TPM_GetAttribUint32", result );
		}
		else
		{
			print_error_nonapi( "Tspi_TPM_GetAttribUint32", result );
		}
		goto done;
	}

	/* Keep hTPM to invalidate family and then set it to NULL */
	hTPM2 = hTPM;
	hTPM = NULL_HTPM;

	/* Keep family address */
	hFamily2 = hFamily;

	result = Tspi_TPM_Delegate_GetFamily(hTPM, familyID, &hFamily);
	if (TSS_ERROR_CODE(result) != TSS_E_INVALID_HANDLE)
	{
		Tspi_TPM_Delegate_InvalidateFamily(hTPM2, hFamily2);
		print_error( function, result );
		result = 1;
		goto done;
	}
	else
	{
		Tspi_TPM_Delegate_InvalidateFamily(hTPM2, hFamily2);

		print_success( function, result );
		result = 0;
	}

done:
	/* Invalidate the family to avoid resource exhaustion */
	if (hFamily != NULL_HDELFAMILY)
		Tspi_TPM_Delegate_InvalidateFamily(hTPM, hFamily);
	Tspi_Context_FreeMemory( hContext, NULL );
	Tspi_Context_Close( hContext );

	print_end_test( function );
	exit( result );
}
int
main_v1_2(char version)
{
	char	     *nameOfFunction    = "Tspi_Nv_ReadValue-trans03";

	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         *policyData;
	UINT32       read_space         = 10;
	TSS_RESULT   result;
	TSS_HKEY     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,
					  NULL);
	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);
	}

#ifdef NV_LOCKED
		/* 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);
	}

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

		/* Set password */
	result = Tspi_Policy_SetSecret(hPolicy, 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);
	}
#endif

		/* 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,0x00011141);
	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, 0x42000);
	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);
		Tspi_Context_Close(hContext);
		exit(result);
     	}

	/*Define NV space*/
	result = Tspi_NV_DefineSpace(hNVStore, 0, 0);



		//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,NULL);
	if (result != TSS_SUCCESS) {
		print_error("Tspi_Context_Connect", result);
		Tspi_Context_FreeMemory(hContext, NULL);      
		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);
	}

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

	result = Tspi_NV_ReadValue(hNVStore,/*read_offset*/0, &read_space, &policyData);

#ifdef CLEAR_TEST_INDEX
	Tspi_Context_GetTpmObject(hContext, &hTPM);
	Tspi_GetPolicyObject(hTPM, TSS_POLICY_USAGE, &hPolicy);
	Tspi_Policy_SetSecret(hPolicy, TESTSUITE_OWNER_SECRET_MODE,
			TESTSUITE_OWNER_SECRET_LEN, TESTSUITE_OWNER_SECRET);
	Tspi_NV_ReleaseSpace(hNVStore);
#endif

#ifdef NV_LOCKED
       if (TSS_ERROR_CODE(result) != TPM_E_AUTH_CONFLICT)
#else
       if (result != TSS_SUCCESS)
#endif
	{
		print_error("Tspi_NV_ReadValue", result);
		Tspi_Context_FreeMemory(hContext, NULL);
		Tspi_Context_Close(hContext);
		exit(result);
	}

       result = Testsuite_Transport_Final(hContext, 0);
	if (result == TSS_SUCCESS)
       {
		print_success(nameOfFunction, result);
		print_end_test(nameOfFunction);
		Tspi_Context_FreeMemory(hContext, NULL);
		Tspi_Context_Close(hContext);
		exit(0);
       } else {
		print_error(nameOfFunction, result);
		print_end_test(nameOfFunction);
		Tspi_Context_FreeMemory(hContext, NULL);
		Tspi_Context_Close(hContext);
		if ( result == TSS_SUCCESS )
			exit(-1);
		exit(result);
	}
}
int
main_v1_1( void )
{
	char			*function = "Tspi_Context_CreateObject";
	TSS_RESULT		result;
	TSS_HCONTEXT		hContext;
	TSS_HOBJECT		hObject;

	print_begin_test( function );

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

	/* ==== TEST 1 ==== */

	/* create a default hash obj */
	result = Tspi_Context_CreateObject(hContext, TSS_OBJECT_TYPE_HASH,
					   TSS_HASH_DEFAULT, &hObject);
	if ( result == TSS_SUCCESS )
	{
		print_success( function, result );
	}
	else
	{
		print_error( "Tspi_Context_CreateObject", result );
	}
	/* close the object, test done */
	result = Tspi_Context_CloseObject(hContext, hObject);
	if (result != TSS_SUCCESS)
	{
		print_error( "Tspi_Context_CreateObject", result );
		Tspi_Context_FreeMemory( hContext, NULL );
		Tspi_Context_Close( hContext );
		exit( result );
	}

	/* ==== TEST 2 ==== */

	/* create a hash sha1 obj */
	result = Tspi_Context_CreateObject(hContext, TSS_OBJECT_TYPE_HASH,
					   TSS_HASH_SHA1, &hObject);
	if ( result == TSS_SUCCESS )
	{
		print_success( function, result );
	}
	else
	{
		print_error( "Tspi_Context_CreateObject", result );
	}
	/* close the object, test done */
	result = Tspi_Context_CloseObject(hContext, hObject);
	if (result != TSS_SUCCESS)
	{
		print_error( "Tspi_Context_CreateObject", result );
		Tspi_Context_FreeMemory( hContext, NULL );
		Tspi_Context_Close( hContext );
		exit( result );
	}

	/* ==== TEST 3 ==== */

	/* create a hash other obj */
	result = Tspi_Context_CreateObject(hContext, TSS_OBJECT_TYPE_HASH,
					   TSS_HASH_OTHER, &hObject);
	if ( result == TSS_SUCCESS )
	{
		print_success( function, result );
	}
	else
	{
		print_error( "Tspi_Context_CreateObject", result );
	}
	/* close the object, test done */
	result = Tspi_Context_CloseObject(hContext, hObject);
	if (result != TSS_SUCCESS)
	{
		print_error( "Tspi_Context_CreateObject", result );
		Tspi_Context_FreeMemory( hContext, NULL );
		Tspi_Context_Close( hContext );
		exit( result );
	}

	/* ==== TEST 4 ==== */

	/* create an invalid hash obj */
	result = Tspi_Context_CreateObject(hContext, TSS_OBJECT_TYPE_HASH,
					   0xffddeeff, &hObject);
	if ( TSS_ERROR_CODE(result) == TSS_E_INVALID_OBJECT_INITFLAG )
	{
		print_success( function, result );
	}
	else
	{
		if (result == TSS_SUCCESS)
			Tspi_Context_CloseObject(hContext, hObject);
		print_error( "Tspi_Context_CreateObject", result );
	}

	/* ==== TEST 5 ==== */

	/* create an ambiguous hash obj */
	result = Tspi_Context_CreateObject(hContext, TSS_OBJECT_TYPE_HASH,
					   0x15151551, &hObject);
	if ( TSS_ERROR_CODE(result) == TSS_E_INVALID_OBJECT_INITFLAG )
	{
		print_success( function, result );
	}
	else
	{
		if (result == TSS_SUCCESS)
			Tspi_Context_CloseObject(hContext, hObject);
		print_error( "Tspi_Context_CreateObject", result );
	}

	print_end_test( function );
	Tspi_Context_FreeMemory( hContext, NULL );
	Tspi_Context_Close( hContext );
	exit( 0 );
}
int
main_v1_1( void )
{
	char		*function = "Tspi_Context_LoadKeyByBlob04";
	TSS_HCONTEXT	hContext;
	TSS_HKEY	hSRK, hSigningKey, hBindingKey;
	TSS_HPOLICY	hPolicy;
	TSS_RESULT	result;
	UINT32		exitCode, attrib;
	TSS_FLAG	initFlags;
	BYTE		*signBlob, *bindBlob;
	UINT32		signBlobLen, bindBlobLen;

	print_begin_test( function );

		// Create Context
	if ((result = connect_load_srk(&hContext, &hSRK))) {
		print_error( "connect_load_srk", result );
		exit( result );
	}

		// create a no-auth, signing key
	initFlags = TSS_KEY_TYPE_SIGNING | TSS_KEY_SIZE_2048 |
		    TSS_KEY_NO_AUTHORIZATION;
	if ((result = create_load_key(hContext, initFlags, hSRK, &hSigningKey))) {
		print_error( "create_load_key(Signing Key)", result );
		Tspi_Context_Close( hContext );
		exit( result );
	}
	print_success("Signing key created successfully", TSS_SUCCESS);

		// get blob
	result = Tspi_GetAttribData( hSigningKey, TSS_TSPATTRIB_KEY_BLOB,
					TSS_TSPATTRIB_KEYBLOB_BLOB,
					&signBlobLen, &signBlob );
	if ( result != TSS_SUCCESS )
	{
		print_error( "Tspi_GetAttribData", result );
		Tspi_Context_Close( hContext );
		exit( result );
	}

		// create a auth, binding key
	initFlags = TSS_KEY_TYPE_BIND | TSS_KEY_SIZE_2048 |
		    TSS_KEY_AUTHORIZATION;
	if ((result = create_load_key(hContext, initFlags, hSRK, &hBindingKey))) {
		print_error( "create_load_key(Binding Key)", result );
		Tspi_Context_Close( hContext );
		exit( result );
	}
	print_success("Binding key created successfully", TSS_SUCCESS);

		// get blob
	result = Tspi_GetAttribData( hBindingKey, TSS_TSPATTRIB_KEY_BLOB,
					TSS_TSPATTRIB_KEYBLOB_BLOB,
					&bindBlobLen, &bindBlob );
	if ( result != TSS_SUCCESS )
	{
		print_error( "Tspi_GetAttribData", result );
		Tspi_Context_Close( hContext );
		exit( result );
	}

	// verify attribs before we close the context
	if ((result = verify_sign_attribs(hSigningKey))) {
		print_error( "verify_sign_attribs", result );
		Tspi_Context_Close( hContext );
		exit( result );
	}

	// verify attribs before we close the context
	if ((result = verify_bind_attribs(hBindingKey))) {
		print_error( "verify_bind_attribs", result );
		Tspi_Context_Close( hContext );
		exit( result );
	}

		// close context, to get rid of all context state
	if ((result = Tspi_Context_Close(hContext))) {
		print_error( "Tspi_Context_Close", result );
		exit( result );
	}

		// re-connect
	if ((result = connect_load_srk(&hContext, &hSRK))) {
		print_error( "connect_load_srk", result );
		Tspi_Context_Close( hContext );
		exit( result );
	}

		// Load both Keys by blob
	if ((result = Tspi_Context_LoadKeyByBlob( hContext, hSRK,
						signBlobLen,
						signBlob,
						&hSigningKey ))) {
		print_error( "Tspi_Context_LoadKeyByBlob", result );
		Tspi_Context_Close( hContext );
		exit( result );
	}
	if ((result = Tspi_Context_LoadKeyByBlob( hContext, hSRK,
						bindBlobLen,
						bindBlob,
						&hBindingKey ))) {
		print_error( "Tspi_Context_LoadKeyByBlob", result );
		Tspi_Context_Close( hContext );
		exit( result );
	}

	// verify attribs after we've re-loaded by blob
	if ((result = verify_sign_attribs(hSigningKey))) {
		print_error( "verify_sign_attribs", result );
		Tspi_Context_Close( hContext );
		exit( result );
	}

	// verify attribs after we've re-loaded by blob
	if ((result = verify_bind_attribs(hBindingKey))) {
		print_error( "verify_bind_attribs", result );
		Tspi_Context_Close( hContext );
		exit( result );
	}


	// Do a sign/verify test
	if ((result = sign_and_verify(hContext, hSigningKey))) {
		print_error( "sign_and_verify", result );
		Tspi_Context_Close( hContext );
		exit( result );
	}


	// Do a bind/unbind test
	result = bind_and_unbind(hContext, hBindingKey);
	if (TSS_ERROR_CODE(result) != TSS_E_POLICY_NO_SECRET) {
		print_verifyerr("bind and unbind", TSS_E_POLICY_NO_SECRET, result);
		print_error( function, result );
		Tspi_Context_Close( hContext );
		exit( result );
	}

	// set up policies
	if ((result = set_secret(hContext, hBindingKey, &hPolicy))) {
		print_error("set_secret", result);
		Tspi_Context_Close( hContext );
		exit( result );
	}

	if ((result = bind_and_unbind(hContext, hBindingKey))) {
		print_error( "bind_and_unbind", result );
		Tspi_Context_Close( hContext );
		exit( result );
	}

	exitCode = 0;
	print_success(function, TSS_SUCCESS);
	print_end_test( function );
	Tspi_Context_Close( hContext );
	exit( exitCode );
}
Пример #26
0
main_v1_1(void){

	char		*nameOfFunction = "policy_no_secret";
	TSS_HCONTEXT	hContext;
	TSS_HTPM	hTPM;
	TSS_FLAG	initFlags;
	TSS_HKEY	hKey;
	TSS_HKEY	hSRK;
	TSS_RESULT	result;
	TSS_BOOL	allowMaint = FALSE;
	BYTE		*randomData;
	TSS_HPOLICY	srkUsagePolicy, tpmUsagePolicy;

	print_begin_test(nameOfFunction);

#ifdef TESTSUITE_NOAUTH_SRK
	print_NA();
	print_end_test(nameOfFunction);
	exit(0);
#endif
		//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);
	}

		//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);
	}
		//Create Policy Object
	result = Tspi_Context_CreateObject(hContext, TSS_OBJECT_TYPE_POLICY, TSS_POLICY_USAGE,
					   &srkUsagePolicy);
	if (result != TSS_SUCCESS) {
		print_error("Tspi_Context_CreateObject", result);
		Tspi_Context_Close(hContext);
		exit(result);
	}
		//Set Secret mode to none
	result = Tspi_Policy_SetSecret(srkUsagePolicy, TSS_SECRET_MODE_NONE, 0, NULL);
	if (result != TSS_SUCCESS) {
		print_error("Tspi_Policy_SetSecret", result);
		Tspi_Context_CloseObject(hContext, hKey);
		Tspi_Context_Close(hContext);
		exit(result);
	}
		//Assign new policy w/o secret to the SRK object
	result = Tspi_Policy_AssignToObject(srkUsagePolicy, hSRK);
	if (result != TSS_SUCCESS) {
		print_error("Tspi_Policy_AssignToObject", result);
		Tspi_Context_Close(hContext);
		exit(result);
	}
		//Create child key Object
	result = Tspi_Context_CreateObject(hContext, TSS_OBJECT_TYPE_RSAKEY,
					   TSS_KEY_SIZE_512|TSS_KEY_TYPE_BIND|
					   TSS_KEY_NO_AUTHORIZATION, &hKey);
	if (result != TSS_SUCCESS) {
		print_error("Tspi_Context_CreateObject", result);
		Tspi_Context_Close(hContext);
		exit(result);
	}

		// Attempt to use the SRK w/o putting a secret in its policy
	result = Tspi_Key_CreateKey(hKey, hSRK, 0);
	if (TSS_ERROR_CODE(result) != TSS_E_POLICY_NO_SECRET) {
		print_error("Key creation w/o parent secret set", result);
		print_error(nameOfFunction, result);
		Tspi_Context_Close(hContext);
		exit(result);
	} else {
		print_success("Key creation w/o parent secret set", 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);
	}

		// With a secret set, this should work OK
	result = Tspi_Key_CreateKey(hKey, hSRK, 0);
	if (result != TSS_SUCCESS) {
		print_error("Tspi_Key_CreateKey", result);
		Tspi_Context_Close(hContext);
		exit(result);
	}

		// Try an owner auth'd command w/o secret
	result = Tspi_Context_GetTpmObject(hContext, &hTPM);
	if (result != TSS_SUCCESS) {
		print_error("Tspi_Context_GetTpmObject", result);
		Tspi_Context_Close(hContext);
		exit(result);
	}

		//Get Policy Object
	result = Tspi_GetPolicyObject(hTPM, TSS_POLICY_USAGE, &tpmUsagePolicy);
	if (result != TSS_SUCCESS) {
		print_error("Tspi_GetPolicyObject", result);
		Tspi_Context_CloseObject(hContext, hKey);
		Tspi_Context_Close(hContext);
		exit(result);
	}
		//Set Secret mode to none
	result = Tspi_Policy_SetSecret(tpmUsagePolicy, TSS_SECRET_MODE_NONE, 0, NULL);
	if (result != TSS_SUCCESS) {
		print_error("Tspi_Policy_SetSecret", result);
		Tspi_Context_CloseObject(hContext, hKey);
		Tspi_Context_Close(hContext);
		exit(result);
	}

	result = Tspi_TPM_GetStatus(hTPM, TSS_TPMSTATUS_ALLOWMAINTENANCE, &allowMaint);
	if (TSS_ERROR_CODE(result) != TSS_E_POLICY_NO_SECRET) {
		print_error("Tspi_TPM_GetStatus w/o owner secret set", result);
		Tspi_Context_Close(hContext);
		exit(result);
	} else {
		print_success("TPM_GetStatus w/o owner secret set", result);
	}

		//Set Secret
	result = Tspi_Policy_SetSecret(tpmUsagePolicy, TESTSUITE_OWNER_SECRET_MODE,
				       TESTSUITE_OWNER_SECRET_LEN, TESTSUITE_OWNER_SECRET);
	if (result != TSS_SUCCESS) {
		print_error("Tspi_Policy_SetSecret", result);
		Tspi_Context_CloseObject(hContext, hKey);
		Tspi_Context_Close(hContext);
		exit(result);
	}
	result = Tspi_TPM_GetStatus(hTPM, TSS_TPMSTATUS_ALLOWMAINTENANCE, &allowMaint);
	if (result != TSS_SUCCESS) {
		print_error("Tspi_TPM_GetStatus", result);
		Tspi_Context_Close(hContext);
		exit(result);
	}

	print_success(nameOfFunction, result);
	print_end_test(nameOfFunction);
	Tspi_Context_Close(hContext);
	exit(result);
}
int
main_v1_2( char version )
{
	char *			function = "Tspi_TPM_Delegate_ReadTables06";
	TSS_HCONTEXT		hContext;
	TSS_HKEY		hSRK;
	TSS_HTPM		hTPM;
	TSS_HPOLICY		hTPMPolicy;
	TSS_HDELFAMILY		hFamily = NULL_HDELFAMILY;
	UINT32			familyTableSize, delegateTableSize;
	TSS_FAMILY_TABLE_ENTRY	*familyTable;
	TSS_RESULT		result;

	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_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_TPM_Delegate_AddFamily(hTPM, 'a', &hFamily);
	if ( result != TSS_SUCCESS )
	{
		print_error( "Tspi_TPM_Delegate_AddFamily", result );
		goto done;
	}

	result = Tspi_TPM_Delegate_ReadTables(hContext, &familyTableSize, &familyTable,
			&delegateTableSize, NULL);
	if (TSS_ERROR_CODE(result) != TSS_E_BAD_PARAMETER)
	{
		print_error( function, result );
		result = 1;
		goto done;
	}
	else
	{
		print_success( function, result );
		result = 0;
	}

done:
	/* Invalidate the family to avoid resource exhaustion */
	if (hFamily != NULL_HDELFAMILY)
		Tspi_TPM_Delegate_InvalidateFamily(hTPM, hFamily);
	Tspi_Context_FreeMemory( hContext, NULL );
	Tspi_Context_Close( hContext );
	
	print_end_test( function );
	exit( result );
}
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 );
	}

		//Load Key Blob
	result = Tspi_Context_LoadKeyByBlob( hContext, hSRK,
						blobLength,
						NULL,
						&hMSigningKey );
	if ( TSS_ERROR_CODE(result) != TSS_E_BAD_PARAMETER )
	{
		if( !(checkNonAPI(result)) )
		{
			print_error( function, result );
			exitCode = 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 );
}
int
main_v1_2( char version )
{
	char *			function = "Tspi_TPM_Delegate_CreateDelegation02";
	TSS_HCONTEXT		hContext;
	TSS_HKEY		hSRK;
	TSS_HTPM		hTPM;
	TSS_HPOLICY		hTPMPolicy;
	TSS_HPOLICY		hDelegation = 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 = 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, &hDelegation);
	if ( result != TSS_SUCCESS )
	{
		print_error( "Tspi_Context_CreateObject", result );
		goto done;
	}

	result = Tspi_Policy_SetSecret( hDelegation, 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(hDelegation, 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(hDelegation, TSS_TSPATTRIB_POLICY_DELEGATION_INFO,
			TSS_TSPATTRIB_POLDEL_PER1, 0);
	if ( result != TSS_SUCCESS )
	{
		print_error( "Tspi_SetAttribUint32", result );
		goto done;
	}

	result = Tspi_SetAttribUint32(hDelegation, 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(0xffffffff, 'b', 0, NULL_HPCRS, hFamily, hDelegation);
	if (TSS_ERROR_CODE(result) != TSS_E_INVALID_HANDLE)
	{
		print_error( function, result );
		result = 1;
		goto done;
	}
	else
	{
		print_success( function, result );
		result = 0;
	}

done:
	/* Invalidate the family to avoid resource exhaustion */
	if (hFamily != NULL_HDELFAMILY)
		Tspi_TPM_Delegate_InvalidateFamily(hTPM, hFamily);
	Tspi_Context_FreeMemory( hContext, NULL );
	Tspi_Context_Close( hContext );

	print_end_test( function );
	exit( result );
}
main_v1_1(void){

	char		*nameOfFunction = "Tspi_GetAttribData19";
	TSS_FLAG	initFlags;
	TSS_HKEY	hKey;
	TSS_HCONTEXT	hContext;
	TSS_RESULT	result;
	TSS_HKEY	hSRK;
	BYTE*		uuid;
	UINT32		uuidLength;
	int		rc;
	TSS_UUID	null_uuid, key_uuid;
	initFlags	= TSS_KEY_TYPE_SIGNING | TSS_KEY_SIZE_2048  |
			TSS_KEY_VOLATILE | TSS_KEY_NO_AUTHORIZATION |
			TSS_KEY_NOT_MIGRATABLE;

	memset(&null_uuid, 0, sizeof(TSS_UUID));
	memset(&key_uuid, 0x7f, sizeof(TSS_UUID));

	print_begin_test(nameOfFunction);

		//Create Context and connect
	result = connect_load_srk(&hContext, &hSRK);
	if (result != TSS_SUCCESS) {
		print_error("connect_load_srk", result);
		print_error_exit(nameOfFunction, err_string(result));
		exit(result);
	}
		//Create Key Object
	result = Tspi_Context_CreateObject(hContext,
					   TSS_OBJECT_TYPE_RSAKEY,
					   initFlags, &hKey);
	if (result != TSS_SUCCESS) {
		print_error("Tspi_Context_CreateObject", result);
		print_error_exit(nameOfFunction, err_string(result));
		Tspi_Context_Close(hContext);
		exit(result);
	}
		//Create Key in the TPM
	result = Tspi_Key_CreateKey(hKey, hSRK, 0);
	if (result != TSS_SUCCESS) {
		print_error("Tspi_Key_CreateKey", result);
		print_error_exit(nameOfFunction, err_string(result));
		Tspi_Context_Close(hContext);
		exit(result);
	}
		//Call GetAttribData, uuid should be all 0's
	result = Tspi_GetAttribData(hKey,
				    TSS_TSPATTRIB_KEY_UUID, 0,
				    &uuidLength, &uuid);
	if (result != TSS_SUCCESS) {
		print_error("Tspi_GetAttribData", result);
		print_error_exit(nameOfFunction, err_string(result));
		Tspi_Context_Close(hContext);
		exit(result);
	}

		//Check length and data
	if (uuidLength != sizeof(TSS_UUID)) {
		print_verifyerr("uuid length from Tspi_GetAttribData", 0, 1);
		print_error("uuid length from Tspi_GetAttribData", TSS_E_FAIL);
		Tspi_Context_Close(hContext);
		exit(result);
	}
	if ((rc = memcmp(uuid, &null_uuid, uuidLength))) {
		print_verifyerr("a null uuid from Tspi_GetAttribData", 0, rc);
		print_hex(uuid, sizeof(TSS_UUID));
		print_error("uuid NULL from Tspi_GetAttribData", TSS_E_FAIL);
		Tspi_Context_Close(hContext);
		exit(result);
	}

	Tspi_Context_FreeMemory(hContext, uuid);

register_key:
		//Register Key
	result = Tspi_Context_RegisterKey(hContext, hKey, TSS_PS_TYPE_SYSTEM,
					  key_uuid, TSS_PS_TYPE_SYSTEM,
					  SRK_UUID);
	if (TSS_ERROR_CODE(result) == TSS_E_KEY_ALREADY_REGISTERED) {
		result = Tspi_Context_UnregisterKey(hContext,
						    TSS_PS_TYPE_SYSTEM,
						    key_uuid, &hKey);
		if (result != TSS_SUCCESS) {
			print_error("Tspi_Context_UnregisterKey", result);
			print_error_exit(nameOfFunction, err_string(result));
			Tspi_Context_CloseObject(hContext, hKey);
			Tspi_Context_Close(hContext);
			exit(result);
		}
		goto register_key;
	} else if (result != TSS_SUCCESS) {
		print_error("Tspi_Context_RegisterKey", result);
		print_error_exit(nameOfFunction, err_string(result));
		Tspi_Context_CloseObject(hContext, hKey);
		Tspi_Context_Close(hContext);
		exit(result);
	}

		//Close the object
	result = Tspi_Context_CloseObject(hContext, hKey);
	if (result != TSS_SUCCESS) {
		print_error("Tspi_Context_CloseObject", result);
		print_error_exit(nameOfFunction, err_string(result));
		Tspi_Context_CloseObject(hContext, hKey);
		Tspi_Context_Close(hContext);
		exit(result);
	}
	hKey = 0;
		//Load the key by UUID from PS
	result = Tspi_Context_LoadKeyByUUID(hContext, TSS_PS_TYPE_SYSTEM,
					    key_uuid, &hKey);
	if (result != TSS_SUCCESS) {
		print_error("Tspi_Context_LoadKeyByUUID", result);
		print_error_exit(nameOfFunction, err_string(result));
		Tspi_Context_CloseObject(hContext, hKey);
		Tspi_Context_Close(hContext);
		exit(result);
	}

		//Call GetAttribData, uuid should be equal to key_uuid
	result = Tspi_GetAttribData(hKey, TSS_TSPATTRIB_KEY_UUID, 0,
				    &uuidLength, &uuid);
	if (result != TSS_SUCCESS) {
		print_error("Tspi_GetAttribData", result);
		print_error_exit(nameOfFunction, err_string(result));
		Tspi_Context_Close(hContext);
		exit(result);
	}
		//Check length and data
	if (uuidLength != sizeof(TSS_UUID)) {
		print_verifyerr("uuid length from Tspi_GetAttribData", 0, 1);
		print_error("uuid length from Tspi_GetAttribData", TSS_E_FAIL);
		Tspi_Context_Close(hContext);
		exit(result);
	}
	if ((rc = memcmp(uuid, &key_uuid, uuidLength))) {
		print_verifyerr("key's uuid from Tspi_GetAttribData", 0, rc);
		print_hex((BYTE *)&key_uuid, sizeof(TSS_UUID));
		print_error("key's uuid from Tspi_GetAttribData", TSS_E_FAIL);
		Tspi_Context_Close(hContext);
		exit(result);
	}

	print_success(nameOfFunction, result);
	print_end_test(nameOfFunction);
	Tspi_Context_Close(hContext);
	exit(0);
}