KeyofBlueS/bt-keys-sync

Bluetooth Low Energy (BLE) devices support

KeyofBlueS opened this issue · 18 comments

Bluetooth Low Energy (BLE) devices pairing keys are managed differently than standard bluetooth devices.
Since I don't own any BLE device I'am unable to add support for them.

If you have a BLE device and you want their support to be implemented, you can help by posting the info i need:

The info file of the BLE device in linux:

sudo cat "/var/lib/bluetooth/${bt_controller_macaddr}/${bt_device_macaddr}/info"

  • where ${bt_controller_macaddr} is the MAC Address of the bluetooth controller and ${bt_device_macaddr} is the MAC Address of the BLE device.

The exported registry file of windows containing the BLE device credentials.

To obtain this file:

  • install chntpw
    sudo apt install chntpw
  • Mount the windows partition
  • Locate the SYSTEM hive file in the windows partition, usually is something like "<windows_mount_point>/Windows/System32/config/SYSTEM"
  • Export the keys
    sudo reged -x "<windows_mount_point>/Windows/System32/config/SYSTEM" "HKEY_LOCAL_MACHINE\SYSTEM" "ControlSet001\Services\BTHPORT\Parameters\Keys" "/tmp/exported_keys.reg"
  • print the exported registry
    cat "/tmp/exported_keys.reg"

I need these in order to compare the formats between the linux info file and the exported windows registry file.

Please do not hesitate to post here for any questions or difficulty you may have about this issue.

Thanks and best regards!

Hi! that link doesn't contain an example of both the info file from linux and an exported registry file from windows of the same BLE device, so it doesn't help me.

Thanks for the suggestion anyway!

I am sorry for bailing out yet again, but perhaps digitalbirdo/BT-LinkkeySync#12 (comment) provides these?

You don't have to apologize, you're trying to help! unfortunately that doesn't have what I need either.

So https://github.com/digitalbirdo/BT-LinkkeySync/files/7692834/8863df8a2d80.zip reads

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\BTHPORT\Parameters\Keys\8863df8a2d80]
"MasterIRK"=hex:89,33,21,51,13,ba,02,8c,f6,ca,f6,5c,70,61,25,e0
"f47335106159"=hex:91,b7,92,af,29,ef,90,c2,e5,b6,58,67,90,2a,64,61
"d06544a8dc1e"=hex:26,68,5b,11,c8,52,f0,4f,f9,15,5c,1f,ae,7b,76,05

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\BTHPORT\Parameters\Keys\8863df8a2d80\eea5434f6491]
"LTK"=hex:ba,3c,a0,d1,fc,05,2c,be,3c,4d,76,2f,3f,4e,79,ff
"KeyLength"=dword:00000010
"ERand"=hex(b):6b,5a,17,42,54,5f,3c,53
"EDIV"=dword:0000dffc
"IRK"=hex:89,33,21,51,13,ba,02,8c,f6,ca,f6,5c,70,61,25,e0
"Address"=hex(b):91,64,4f,43,a5,ee,00,00
"AddressType"=dword:00000001
"MasterIRKStatus"=dword:00000001
"AuthReq"=dword:0000002d

What is missing?

The linux counterpart is missing. As stated in the first post i need both the info file of the BLE device in linux and the exported registry file of windows containing the BLE device credentials.

True, it's for Mac.

Here are the bluetooth keys for a Designer Mouse paired to Linux and Windows:

cat /var/lib/bluetooth/B4:69:21:81:8F:AC/DB:97:6E:1C:E3:C1/info

[General]
Name=Designer Mouse
Appearance=0x03c2
AddressType=static
SupportedTechnologies=LE;
Trusted=true
Blocked=false
Services=00001800-0000-1000-8000-00805f9b34fb;00001801-0000-1000-8000-00805f9b34fb;0000180a-0000-1000-8000-00805f9b34fb;0000180f-0000-1000-8000-00805f9b34fb;00001812-0000-1000-8000-00805f9b34fb;
WakeAllowed=true

[IdentityResolvingKey]
Key=CC4F342A1C010F1A31192CC7838B8842

[LocalSignatureKey]
Key=F1A2B36895473568884501EDD4EB01C3
Counter=0
Authenticated=false

[LongTermKey]
Key=D9168778509DF0EC3CADEEA386657848
Authenticated=0
EncSize=16
EDiv=5033
Rand=9705591926826931727

[DeviceID]
Source=2
Vendor=1118
Product=2053
Version=272

[ConnectionParameters]
MinInterval=6
MaxInterval=6
Latency=60
Timeout=300

cat cat /tmp/exported_keys.reg

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\BTHPORT\Parameters\Keys]

[HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\BTHPORT\Parameters\Keys\207918bba156]

[HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\BTHPORT\Parameters\Keys\b46921818fac]
"MasterIRK"=hex:a4,8b,8d,aa,cf,82,77,5d,ea,95,14,f0,bd,56,b6,8a
"84cfbf9368bf"=hex:7e,ef,f2,7c,57,f8,e0,bd,22,63,03,c8,95,8e,4d,b7
"dc2c26dc9b3e"=hex:50,66,b4,c7,38,6a,62,dc,0c,32,63,31,f9,c7,cd,72
"001b66899e67"=hex:4e,44,86,0b,36,f9,63,82,c6,2b,6d,d6,62,88,03,2e

[HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\BTHPORT\Parameters\Keys\b46921818fac\db976e1ce3c1]
"LTK"=hex:d9,16,87,78,50,9d,f0,ec,3c,ad,ee,a3,86,65,78,48
"KeyLength"=dword:00000010
"ERand"=hex(b):0f,16,6b,5d,6f,30,b1,86
"EDIV"=dword:000013a9
"IRK"=hex:cc,4f,34,2a,1c,01,0f,1a,31,19,2c,c7,83,8b,88,42
"Address"=hex(b):c1,e3,1c,6e,97,db,00,00
"AddressType"=dword:00000001
"CSRK"=hex:f1,a2,b3,68,95,47,35,68,88,45,01,ed,d4,eb,01,c3
"OutboundSignCounter"=dword:00000000
"MasterIRKStatus"=dword:00000001
"AuthReq"=dword:0000002d

[HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\BTHPORT\Parameters\Keys\b46921818fac\e4f030eb3d56]
"LTK"=hex:42,4f,1a,f2,9f,9a,9d,cd,09,69,0c,37,7b,b8,7c,90
"KeyLength"=dword:00000010
"ERand"=hex(b):ec,87,e8,e9,f6,ac,45,96
"EDIV"=dword:0000a596
"IRK"=hex:52,f0,07,c3,9a,c4,41,72,48,b1,72,73,2d,b1,5d,0e
"Address"=hex(b):56,3d,eb,30,f0,e4,00,00
"AddressType"=dword:00000001
"CSRK"=hex:18,28,3b,5f,9f,ed,e2,2f,7f,2d,cc,62,88,d6,d4,39
"OutboundSignCounter"=dword:00000000
"MasterIRKStatus"=dword:00000001
"AuthReq"=dword:0000002d

This is gold, thanks!

It turns out the code i wrote for ble was mostly good.
Are you willing to test it from ble branch? https://github.com/KeyofBlueS/bt-keys-sync/tree/ble
If yes, you could try these different scenarios:

Scenario 1:

  • Pair the device only in windows.
  • Run this script in linux.
  • Expected Results: bluetooth device not found in linux. Please pair this device in linux.

Scenario 2:

  • Pair the device only in linux.
  • Run this script in linux.
  • Expected Results: bluetooth device not found in windows. Please pair this device in windows.

Scenario 3:

  • Pair the device in linux first, then in windows.
  • Run this script in linux.
  • Choose windows when prompted which pairing key you want to use?
  • Expected Results: bluetooth device will connect in both linux and windows.

Scenario 4 ONLY IF YOU ARE WILLING TO TO RISK!:

  • Pair the device in windows first, then in linux.
  • Run this script in linux.
  • Choose linux when prompted which pairing key you want to use?
  • Expected Results: bluetooth device will connect in both linux and windows.

It does not find any devices in Windows. Scenario 2 works thus well, the others not. Instead https://gist.github.com/Mygod/f390aabf53cf1406fc71166a47236ebf/raw/8514b2bd949c1f56a8d922ac284345b489dee871/export-ble-infos.py works perfectly.

Could you please post the output of bt-keys-sync -o?

This is now the keyboard. Using two devices reduces the number of dual boots.

	\- bluetooth device: E4:F1:2F:EC:3D:56 - Designer Keyboard
		* bluetooth device not found in linux. Please pair this device in linux.
		- windows IRK  key is 52F007C39AC4417248B172732DB15D0E
		- windows LSK  key is 5A5ED3F13E3E7E69E16138666A606B79
		- windows LTK  key is B1078E03BC131496C16EA2273919DD20
		- windows ES   key is 16
		- windows EDIV key is 34865
		- windows RAND key is 10342602826845381356

	\- bluetooth device: E4:F2:2E:ED:3D:56 - Designer Keyboard
		- linux   IRK  key is 0E5DB12D7372B1487241C49AC307F052
		- linux   LSK  key is 63A79FE70F2E60240C88415F9D488333
		- linux   LTK  key is 132851C893601A055D68839D500ABD98
		- linux   ES   key is 16
		- linux   EDIV key is 2348
		- linux   RAND key is 17548083212587120452
		* bluetooth device not found in windows. Please pair this device in windows.

It worked fine in Windows though before rebooting into Linux

To pair non-LE bluetooth devices (from Linux to Windows), https://github.com/x2es/bt-dualboot works fine.
Possibly with this branch https://github.com/Simon128/bt-dualboot also that of LE devices.
I wrote a little summary.

Maybe it's worthy of note, though improbable, that this is on Windows 11.

glebm commented

I have an MX Anywhere 3S mouse. Like other Logitech BTLE mice, it increments its MAC address every time it is synced to a new device.

Running from Linux:

- bluetooth controller: C8:8A:9A:C2:41:AF

	\- bluetooth device: DE:BB:D4:7E:E2:2F - MX Anywhere 3S
		* bluetooth device not found in windows. Please pair this device in windows.
		* this device appear to be a Bluetooth Low Energy Device (BLE)
		* support for Bluetooth Low Energy Devices is currently unimplemented
		* please take a look at: https://github.com/KeyofBlueS/bt-keys-sync/issues/13

	\- bluetooth device: DE:BB:D4:7E:E2:30 - MX Anywhere 3S
		* bluetooth device not found in linux. Please pair this device in linux.
		* this device appear to be a Bluetooth Low Energy Device (BLE)
		* support for Bluetooth Low Energy Devices is currently unimplemented
		* please take a look at: https://github.com/KeyofBlueS/bt-keys-sync/issues/13

Linux:

$ cat /var/lib/bluetooth/C8\:8A\:9A\:C2\:41\:AF/DE\:BB\:D4\:7E\:E2\:2F/info
[General]
Name=MX Anywhere 3S
Appearance=0x03c2
AddressType=static
SupportedTechnologies=LE;
Trusted=true
Blocked=false
Services=00001800-0000-1000-8000-00805f9b34fb;00001801-0000-1000-8000-00805f9b34fb;0000180a-0000-1000-8000-00805f9b34fb;0000180f-0000-1000-8000-00805f9b34fb;00001812-0000-1000-8000-00805f9b34fb;0000fd72-0000-1000-8000-00805f9b34fb;00010000-0000-1000-8000-011f2000046d;

[IdentityResolvingKey]
Key=71BFB1193868894C517A12DC20276FD5

[PeripheralLongTermKey]
Key=A25E529EAFE6EC9E16312114741CC912
Authenticated=2
EncSize=16
EDiv=0
Rand=0

[SlaveLongTermKey]
Key=A25E529EAFE6EC9E16312114741CC912
Authenticated=2
EncSize=16
EDiv=0
Rand=0

[ConnectionParameters]
MinInterval=6
MaxInterval=9
Latency=44
Timeout=216

[DeviceID]
Source=2
Vendor=1133
Product=45111
Version=3

Windows:

[HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\BTHPORT\Parameters\Keys\c88a9ac241af\debbd47ee230]
"LTK"=hex:8c,94,fc,c9,bf,03,93,30,a6,a0,3b,48,22,7e,4f,8e
"KeyLength"=dword:00000010
"ERand"=hex(b):00,00,00,00,00,00,00,00
"EDIV"=dword:00000000
"IRK"=hex:3f,52,f2,f3,1f,b5,d9,3f,1c,87,86,b7,b8,bb,60,85
"Address"=hex(b):30,e2,7e,d4,bb,de,00,00
"AddressType"=dword:00000001
"CEntralIRKStatus"=dword:00000001
"AuthReq"=dword:0000002d
glebm commented

I've managed to manually adjust the Linux config to match the Windows one, here it is:

$ cat '/var/lib/bluetooth/C8:8A:9A:C2:41:AF/DE:BB:D4:7E:E2:30/info' 
[General]
Name=MX Anywhere 3S
Appearance=0x03c2
AddressType=static
SupportedTechnologies=LE;
Trusted=true
Blocked=false
Services=00001800-0000-1000-8000-00805f9b34fb;00001801-0000-1000-8000-00805f9b34fb;0000180a-0000-1000-8000-00805f9b34fb;0000180f-0000-1000-8000-00805f9b34fb;00001812-0000-1000-8000-00805f9b34fb;0000fd72-0000-1000-8000-00805f9b34fb;00010000-0000-1000-8000-011f2000046d;

[IdentityResolvingKey]
Key=3F52F2F31FB5D93F1C8786B7B8BB6085

[PeripheralLongTermKey]
Key=8C94FCC9BF039330A6A03B48227E4F8E
Authenticated=2
EncSize=16
EDiv=0
Rand=0

[SlaveLongTermKey]
Key=8C94FCC9BF039330A6A03B48227E4F8E
Authenticated=2
EncSize=16
EDiv=0
Rand=0

[ConnectionParameters]
MinInterval=6
MaxInterval=9
Latency=44
Timeout=216

[DeviceID]
Source=2
Vendor=1133
Product=45111
Version=3

All I did was rename the folder to the new MAC address and set IdentityResolvingKey to IRK, and PeripheralLongTermKey/SlaveLongTermKey to LTK.

Pls help. I also get the BLE error message trying to dual pair ProtoArc EM05NL with the following info and reg setup:

[General]
Name=ProtoArc EM05NL
Appearance=0x03c2
AddressType=static
SupportedTechnologies=LE;
Trusted=true
Blocked=false
WakeAllowed=true
Services=00001800-0000-1000-8000-00805f9b34fb;0000180a-0000-1000-8000-00805f9b34fb;0000180f-0000-1000-8000-00805f9b34fb;00001812-0000-1000-8000-00805f9b34fb;0000fff0-0000-1000-8000-00805f9b34fb;

[IdentityResolvingKey]
Key=AD06BC14F410D8F99096F6DBC7F9A718

[RemoteSignatureKey]
Key=AB85C8FD4BB044BB4F3200BDCD1856D4
Counter=0
Authenticated=false

[LocalSignatureKey]
Key=BBF216E0DE4A88757ECA6964047F5140
Counter=0
Authenticated=false

[LongTermKey]
Key=B95EE0CA3CB18A4025CF0CCBBC97813C
Authenticated=0
EncSize=16
EDiv=47548
Rand=5546830205044200492

[PeripheralLongTermKey]
Key=F26B486D8AD6B547CADE42CDD2722B8C
Authenticated=0
EncSize=16
EDiv=48555
Rand=9659082249239998326

[SlaveLongTermKey]
Key=F26B486D8AD6B547CADE42CDD2722B8C
Authenticated=0
EncSize=16
EDiv=48555
Rand=9659082249239998326

[DeviceID]
Source=2
Vendor=14
Product=13330
Version=1287

[ConnectionParameters]
MinInterval=7
MaxInterval=7
Latency=48
Timeout=300

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\BTHPORT\Parameters\Keys]

[HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\BTHPORT\Parameters\Keys\683e269ad0d9]
"MasterIRK"=hex:75,63,a1,9a,54,5c,b7,32,b5,c7,05,3e,aa,01,b7,03

[HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\BTHPORT\Parameters\Keys\683e269ad0d9\dedb3422e29c]
"LTK"=hex:9e,68,ad,69,db,55,24,38,81,bc,b9,c7,c2,d5,4e,5b
"KeyLength"=dword:00000010
"ERand"=hex(b):c9,93,18,98,bc,7a,ef,92
"EDIV"=dword:0000de90
"IRK"=hex:a2,bb,7c,4a,c0,45,23,20,0d,68,85,ef,96,70,d8,8f
"Address"=hex(b):9c,e2,22,34,db,de,00,00
"AddressType"=dword:00000001
"CSRKInbound"=hex:ed,bc,60,1c,6a,42,e7,59,ff,46,c5,85,7c,0d,7b,d0
"InboundSignCounter"=hex(b):ff,ff,ff,ff,ff,ff,ff,ff
"CSRK"=hex:22,be,a2,ba,02,5d,83,e8,ac,d2,09,bb,a5,f5,c2,7e
"OutboundSignCounter"=dword:00000000
"MasterIRKStatus"=dword:00000001
"AuthReq"=dword:0000002d

Cheers, Tom