Quantcast
Channel: Windows Desktop Development for Accessibility and Automation forum
Viewing all articles
Browse latest Browse all 585

Bluetooth pairing with SSP (Secure Simple Pairing) Just Works and no MITM (Man In The Middle)

$
0
0

Hello All,
I have problem with pairing on a Bluetooth Device using SSP (Secure Simple Pairing) Just Works (NoInputNoOutput) and no MITM protection.
From a c++ program I have to discover and pair the bluetooth device.
I can discover the device and I do the pair.

But if I research the device the attribute fAuthenticated on the BLUETOOTH_DEVICE_INFO_STRUCT is FALSE.

This is my code:

BOOL CALLBACK auth_callback_ex_ssp(LPVOID pvParam, PBLUETOOTH_AUTHENTICATION_CALLBACK_PARAMS authParams)
{
	BLUETOOTH_AUTHENTICATE_RESPONSE response = { sizeof(BLUETOOTH_AUTHENTICATE_RESPONSE) };

	response.authMethod = authParams->authenticationMethod; // BLUETOOTH_AUTHENTICATION_METHOD_NUMERIC_COMPARISON
	response.bthAddressRemote = authParams->deviceInfo.Address;
	response.negativeResponse = FALSE;

	// Respond with numerical value for Just Works pairing
	response.numericCompInfo.NumericValue = 1;

	DWORD retVal = BluetoothSendAuthenticationResponseEx(0, &response);

	if (ERROR_SUCCESS != retVal)
	{
		TRACE(_T("BluetoothSendAuthenticationResponseEx() failed! %s"), MsBt7_ErrorDisp(retVal));

		return (FALSE);
	}

	return (TRUE);
}

HBLUETOOTH_AUTHENTICATION_REGISTRATION authCallbackHandleSSP = NULL;

BOOL MsBt7_ExecAuthenticateDeviceEx(PBYTE address)
{
	DWORD dwRes;
	BLUETOOTH_DEVICE_INFO_STRUCT deviceInfo = { sizeof(BLUETOOTH_DEVICE_INFO_STRUCT) };
	HBLUETOOTH_RADIO_FIND hFind;
	HANDLE hRadio;

	hFind = BluetoothFindFirstRadio(&btfrp, &hRadio);

	if (NULL == hFind)
	{
		return (FALSE);
	}

	BLUETOOTH_RADIO_INFO radioInfo = { sizeof(BLUETOOTH_RADIO_INFO) };
	if (ERROR_SUCCESS != BluetoothGetRadioInfo(hRadio, &radioInfo))
	{
		return FALSE;
	}

	CopyMemory(&deviceInfo.Address.rgBytes, address, sizeof(deviceInfo.Address.rgBytes));

	dwRes = BluetoothRegisterForAuthenticationEx(&deviceInfo, &authCallbackHandleSSP, (PFN_AUTHENTICATION_CALLBACK_EX)auth_callback_ex_ssp, hRadio);
	if (ERROR_SUCCESS != dwRes)
	{
		CloseHandle(hRadio);
		BluetoothFindRadioClose(hFind);
		return FALSE;
	}

	deviceInfo.fAuthenticated = 0;
	dwRes = BluetoothAuthenticateDeviceEx(NULL, hRadio, &deviceInfo, NULL, MITMProtectionNotRequired);

	if (ERROR_SUCCESS != dwRes)
	{
		CloseHandle(hRadio);
		BluetoothFindRadioClose(hFind);
		return (FALSE);
	}

	GUID pServiceGuid = SerialPortServiceClass_UUID;
	dwRes = BluetoothSetServiceState(hRadio, &deviceInfo, &pServiceGuid, BLUETOOTH_SERVICE_ENABLE);

	if (ERROR_SUCCESS != dwRes)
	{
		CloseHandle(hRadio);
		BluetoothFindRadioClose(hFind);
		return (FALSE);
	}

	// ... some code to get the com port

	CloseHandle(hRadio);
	BluetoothFindRadioClose(hFind);
	return TRUE;
}

The BluetoothAuthenticatedDeviceEx result is ERROR_SUCCESS and after that the fAuthenticated is TRUE.
I can also get the com port.
But if i try another search the fAuthenticated is FALSE again.

Instead if I do the pairing from the Windows user interface (add bluetooth device ...), I get fAuthenticated = TRUE.

Can someone help me?



Viewing all articles
Browse latest Browse all 585

Trending Articles