ta/wallet_ta.c
/**
  * Change the encryption key of a wallet.
  * \param session_data A data pointer to a session context.
  * \param param_types The types of the four parameters.
  * \param params A pointer to an array of four parameters.
  * \return TEE_SUCCESS in case of success otherwise returns the result
  *         received from the failed operation. The information about all
  *         possible returns is present in TEE Client API Specification - 4.4.2
  *         published by GlobalPlatform.
  */
Change the encryption key of a wallet.
\param session_data A data pointer to a session context.
\param param_types The types of the four parameters.
\param params A pointer to an array of four parameters.
\return TEE_SUCCESS in case of success otherwise returns the result
received from the failed operation. The information about all
possible returns is present in TEE Client API Specification - 4.4.2
published by GlobalPlatform.
Change the encryption key of a wallet . \ param session_data A data pointer to a session context . \ param param_types The types of the four parameters . \ param params A pointer to an array of four parameters . \ return TEE_SUCCESS in case of success otherwise returns the result received from the failed operation . The information about all possible returns is present in TEE Client API Specification - 4 . 4 . 2 published by GlobalPlatform .
static TEE_Result change_encryption_key(Session_data * session_data, uint32_t param_types, TEE_Param params[4])
{
	WalletErrors wallet_error = WALLET_NO_ERROR;
	TEE_Result result = TEE_SUCCESS;
	uint32_t exp_param_types;
	TEE_Param dasec_params[4];
	uint32_t dasec_param_types;
	uint32_t uwv_param_types;
	TEE_Param wcwr_params[4];
	uint32_t wcwr_param_types;
	exp_param_types = TEE_PARAM_TYPES(
							TEE_PARAM_TYPE_MEMREF_INPUT,
							TEE_PARAM_TYPE_VALUE_OUTPUT,
							TEE_PARAM_TYPE_NONE,
							TEE_PARAM_TYPE_NONE);
	dasec_param_types = TEE_PARAM_TYPES(
							TEE_PARAM_TYPE_MEMREF_INPUT,
							TEE_PARAM_TYPE_MEMREF_INPUT,
							TEE_PARAM_TYPE_NONE,
							TEE_PARAM_TYPE_NONE);
	uwv_param_types = TEE_PARAM_TYPES(
							TEE_PARAM_TYPE_NONE,
							TEE_PARAM_TYPE_NONE,
							TEE_PARAM_TYPE_NONE,
							TEE_PARAM_TYPE_NONE);
	wcwr_param_types = TEE_PARAM_TYPES(
							TEE_PARAM_TYPE_VALUE_INPUT,
							TEE_PARAM_TYPE_NONE,
							TEE_PARAM_TYPE_NONE,
							TEE_PARAM_TYPE_NONE);
	if (param_types != exp_param_types || params[0].memref.buffer == NULL)
		return TEE_ERROR_BAD_PARAMETERS;
	if (!(session_data->wallet_loaded))
	{
		result = TEE_ERROR_BAD_STATE;
		wallet_error = WALLET_NOT_LOADED;
		goto cleanup1;
	}
	dasec_params[0].memref.buffer = (uint8_t*)&(session_data->current_wallet->unencrypted.uuid);
    dasec_params[0].memref.size = (size_t)UUID_LENGTH;
    dasec_params[1].memref.buffer = (uint8_t*)(params[0].memref.buffer);
    dasec_params[1].memref.size = (size_t)(params[0].memref.size);
	result = derive_and_set_encryption_key(session_data,
										dasec_param_types,
										dasec_params);
	if(result != TEE_SUCCESS)
	{
		#ifdef OP_TEE_TA
		DMSG("Failed to do derive_and_set_encryption_key operation : 0x%x", result);
		#endif
		wallet_error = WALLET_INVALID_OPERATION;
		goto cleanup1;
	}
	if (!(session_data->is_hidden_wallet))
	{
		result = update_wallet_version(session_data, uwv_param_types, NULL);
		if(result != TEE_SUCCESS)
		{
			#ifdef OP_TEE_TA
			DMSG("Failed to do update_wallet_version operation : 0x%x", result);
			#endif
			wallet_error = WALLET_INVALID_OPERATION;
			goto cleanup1;
		}
	}
	result = calculate_wallet_checksum_internal(
							session_data,
							session_data->current_wallet->encrypted.checksum);
	if(result != TEE_SUCCESS)
	{
		#ifdef OP_TEE_TA
		DMSG("Failed to do calculate_wallet_checksum_internal operation : 0x%x", result);
		#endif
		wallet_error = WALLET_INVALID_OPERATION;
		goto cleanup1;
	}
	wcwr_params[0].value.a = session_data->wallet_nv_address;
	result = write_current_wallet_record(session_data,
										wcwr_param_types,
										wcwr_params);
	if(result != TEE_SUCCESS)
	{
		#ifdef OP_TEE_TA
		DMSG("Failed to do write_current_wallet_record operation : 0x%x", result);
		#endif
		wallet_error = WALLET_WRITE_ERROR;
		goto cleanup1;
	}
	cleanup1:
		params[1].value.a = (uint32_t)wallet_error;
		return result;
}
static TEE_Result change_encryption_key ( Session_data * session_data , uint32_t param_types , TEE_Param params [ 4 ] ) { WalletErrors wallet_error = WALLET_NO_ERROR ; TEE_Result result = TEE_SUCCESS ; uint32_t exp_param_types ; TEE_Param dasec_params [ 4 ] ; uint32_t dasec_param_types ; uint32_t uwv_param_types ; TEE_Param wcwr_params [ 4 ] ; uint32_t wcwr_param_types ; exp_param_types = TEE_PARAM_TYPES ( TEE_PARAM_TYPE_MEMREF_INPUT , TEE_PARAM_TYPE_VALUE_OUTPUT , TEE_PARAM_TYPE_NONE , TEE_PARAM_TYPE_NONE ) ; dasec_param_types = TEE_PARAM_TYPES ( TEE_PARAM_TYPE_MEMREF_INPUT , TEE_PARAM_TYPE_MEMREF_INPUT , TEE_PARAM_TYPE_NONE , TEE_PARAM_TYPE_NONE ) ; uwv_param_types = TEE_PARAM_TYPES ( TEE_PARAM_TYPE_NONE , TEE_PARAM_TYPE_NONE , TEE_PARAM_TYPE_NONE , TEE_PARAM_TYPE_NONE ) ; wcwr_param_types = TEE_PARAM_TYPES ( TEE_PARAM_TYPE_VALUE_INPUT , TEE_PARAM_TYPE_NONE , TEE_PARAM_TYPE_NONE , TEE_PARAM_TYPE_NONE ) ; if ( param_types != exp_param_types || params [ 0 ] . memref . buffer == NULL ) return TEE_ERROR_BAD_PARAMETERS ; if ( ! ( session_data -> wallet_loaded ) ) { result = TEE_ERROR_BAD_STATE ; wallet_error = WALLET_NOT_LOADED ; goto cleanup1 ; } dasec_params [ 0 ] . memref . buffer = ( uint8_t * ) & ( session_data -> current_wallet -> unencrypted . uuid ) ; dasec_params [ 0 ] . memref . size = ( size_t ) UUID_LENGTH ; dasec_params [ 1 ] . memref . buffer = ( uint8_t * ) ( params [ 0 ] . memref . buffer ) ; dasec_params [ 1 ] . memref . size = ( size_t ) ( params [ 0 ] . memref . size ) ; result = derive_and_set_encryption_key ( session_data , dasec_param_types , dasec_params ) ; if ( result != TEE_SUCCESS ) { #ifdef OP_TEE_TA DMSG ( " " , result ) ; #endif wallet_error = WALLET_INVALID_OPERATION ; goto cleanup1 ; } if ( ! ( session_data -> is_hidden_wallet ) ) { result = update_wallet_version ( session_data , uwv_param_types , NULL ) ; if ( result != TEE_SUCCESS ) { #ifdef OP_TEE_TA DMSG ( " " , result ) ; #endif wallet_error = WALLET_INVALID_OPERATION ; goto cleanup1 ; } } result = calculate_wallet_checksum_internal ( session_data , session_data -> current_wallet -> encrypted . checksum ) ; if ( result != TEE_SUCCESS ) { #ifdef OP_TEE_TA DMSG ( " " , result ) ; #endif wallet_error = WALLET_INVALID_OPERATION ; goto cleanup1 ; } wcwr_params [ 0 ] . value . a = session_data -> wallet_nv_address ; result = write_current_wallet_record ( session_data , wcwr_param_types , wcwr_params ) ; if ( result != TEE_SUCCESS ) { #ifdef OP_TEE_TA DMSG ( " " , result ) ; #endif wallet_error = WALLET_WRITE_ERROR ; goto cleanup1 ; } cleanup1 : params [ 1 ] . value . a = ( uint32_t ) wallet_error ; return result ; }
Change the encryption key of a wallet.
Change the encryption key of a wallet .
/* Declare deriveAndSetEncryptionKey operation parameters */ /* Declare updateWalletVerison operation parameters */ /* Declare writeCurrentWallet operation parameters */ /*
	 * Expected:
	 * [IN]  params[0].memref.buffer -> Password.
	 * [IN]  params[0].memref.size   -> Length of the password.
	 * [OUT] params[1].value.a       -> Wallet last error.
	 */ /*
	 * deriveAndSetEncryptionKey parameters:
	 * [IN]  params[0].memref.buffer -> UUID.
	 * [IN]  params[0].memref.size   -> Length of the UUID.
	 * [IN]  params[1].memref.buffer -> Password.
	 * [IN]  params[1].memref.size   -> Length of the password.
	 */ /*
	 * writeCurrentWallet parameters:
	 * [IN]  params[0].value.a    -> Address to write the current wallet record.
	 */ /* Some sanity checks */ /* Check if the wallet is loaded */ /*
		 * Here the return should be return TEE_ERROR_ITEM_NOT_FOUND;
		 * but as this will be treated as an error by the CA the most safest way
		 * is to set as TEE_ERROR_BAD_STATE to signal an operation that failed
		 * but without the needing to exit the program
		 */ /* Define deriveAndSetEncryptionKey parameters */ /*
		 * Here we needed an wallet_error because otherwise even if the operation
		 * failed it would say that there wasn't any error (because the default
		 * value is WALLET_NO_ERROR) so the value chosen was invalid operation
		 */ /* Updating the version field for a hidden wallet would reveal where it is, do don't do it */ /*
			 * Here we are assuming that only reason that the update_wallet_version_
			 * could fail is because the parameters were invalid (as the other
			 * reason is already checked in the first if) but those were set here
			 * so this situation should never occur and as such the wallet_error
			 * value does matter that much here so we will leave it as an invalid
			 * operation
			 */ /* Calculate the wallet checksum */ /*
		 * Here we needed an wallet_error because otherwise even if the operation
		 * failed it would say that there wasn't any error (because the default
		 * value is WALLET_NO_ERROR) so the value chosen was invalid operation
		 */ /* Write the current wallet record into the storage */ /* Resources cleanup */