Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support key sync from Windows to MacOS #18

Open
deed02392 opened this issue Jan 4, 2020 · 14 comments
Open

Support key sync from Windows to MacOS #18

deed02392 opened this issue Jan 4, 2020 · 14 comments

Comments

@deed02392
Copy link

I just did this manually and it was pretty straightforward.

From a paired device in Windows 10 (the Bose 700s, which interestingly support LE but were not paired by LE), I exported the link key data, changed the endianness to MacOS, then replaced this in the Mojave /private/var/root/Library/Preferences/com.apple.bluetoothd.plist (I used a hex editor to find and replace the existing paired key with Windows').

The only gotcha was that I had to not only disable Bluetooth before modifying the plist file, but also perform a system reboot before starting Bluetooth again. Otherwise, something was reverting the key change to the plist file. I tried to see if I could figure out which specific service was doing this but didn't have any luck.

I appreciate that perhaps replacing the key on Windows is easier than the above but wanted to share that it is indeed possible nevertheless.

@roddy20
Copy link

roddy20 commented Jan 14, 2021

try this
#22 (comment)
it converts BTKeys.Reg from Windows to blued.plist for macOS

@deed02392
Copy link
Author

Cool @roddy20. I haven't tested it but how sure are you that the offsets you use with sed are reliable?

@roddy20
Copy link

roddy20 commented Jan 14, 2021

it works for me :)
it is not "ready to release product", just an idea, feеl free to make it better

@roddy20
Copy link

roddy20 commented Jan 14, 2021

about offsets, I think these lines always have equal length
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\BTHPORT\Parameters\Keys*342387feece6*]
"d49a207f0a02"=hex:ec,f3,a6,90,8e,3c,af,50,ff,0b,76,e3,b8,8e,77,75

but I agree, parsing from | to ], from " to " and from : to the end will be better

@roddy20
Copy link

roddy20 commented Jan 14, 2021

we can make it more simple
Mac-addresses of Mouse and BTDongle are exactly the same in Windows and macOS, so we really need this value only
hex:ec,f3,a6,90,8e,3c,af,50,ff,0b,76,e3,b8,8e,77,75

@deed02392
Copy link
Author

What d'you mean by mac addresses? The number on the left before =? I guess that's some kind of device ID?

@roddy20
Copy link

roddy20 commented Jan 14, 2021

What d'you mean by mac addresses? The number on the left before =? I guess that's some kind of device ID?

https://en.wikipedia.org/wiki/MAC_address

"d49a207f0a02" is macaddress for Mouse and 342387feece6 is macadress for BT Dongle, they are constants until you change the hardware

hex:ec,f3,a6,90,8e,3c,af,50,ff,0b,76,e3,b8,8e,77,75 is a pairing key and it is new for each new re-connection
so we need to sync it between all the systems

@deed02392
Copy link
Author

Right. You still need both values - the MAC in order to know which key to update on the other OS.

@roddy20
Copy link

roddy20 commented Jan 14, 2021

Right. You still need both values - the MAC in order to know which key to update on the other OS.

Ok
here it is without sed
maybe it will be better
`cd "$(dirname "$0")"
rm /tmp/temp.plist
/usr/libexec/PlistBuddy -c "Add LinkKeys dict" /tmp/temp.plist
input=BTKeys.reg
while IFS= read -r line
do
if [[ "$line" == 'HKEY_LOCAL_MACHINE' ]]
then
t=$(printf "%s" ${line} | awk -F \ '{print $8}' | tr -d ']')
echo
echo "BT:"$t
/usr/libexec/PlistBuddy -c "Add LinkKeys:$t dict" /tmp/temp.plist
fi

if [[ "$line" == '=hex' ]]
then
key=$(printf "%s" ${line} | awk -F '=' '{print $1}' | tr -d '"')
value=$(printf "%s" ${line} | awk -F ':' '{print $2}' | tr -d ',')
echo $key $value
printf $value | xxd -r -p > /tmp/bin
/usr/libexec/PlistBuddy -c "Import LinkKeys:$t:$key /tmp/bin" /tmp/temp.plist
plutil -convert binary1 /tmp/temp.plist
fi

done < "$input"
echo
mv /tmp/temp.plist ./blued.plist
`

@roddy20
Copy link

roddy20 commented Jan 16, 2021

and the missing part
psexec64 -s reg export HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\BTHPORT\Parameters\Keys C:\BTKeys.reg

@deed02392
Copy link
Author

This is nice @roddy20 :) you could try writing this as Python and submitting a pull request, then you would appear as a contributing author to this repository

@roddy20
Copy link

roddy20 commented Jan 17, 2021

This is nice @roddy20 :) you could try writing this as Python and submitting a pull request, then you would appear as a contributing author to this repository

I understand nothing in Python, so you may use it "as is" or add to main project as some kind of alternative solution
or ask someone else to rewrite to Python or C++ or anything else ))

@roddy20
Copy link

roddy20 commented Jan 17, 2021

This is nice @roddy20 :) you could try writing this as Python and submitting a pull request, then you would appear as a contributing author to this repository

if we have WinClone installed, we can read directly from Window's Registry
/Applications/Winclone.app/Contents/Resources/tools/bin/registry_lookup

Example:
registry_lookup "/Volumes/Bootcamp/Windows/System32/config/SYSTEM" "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\BTHPORT\Parameters\Keys "
but it does not work for me yet

@roddy20
Copy link

roddy20 commented Jan 17, 2021

and one more script for those who has a lot of different macOSes installed
`if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root"
exit 1
fi

if [[ -f "/private/var/root/Library/Preferences/com.apple.bluetoothd.plist" ]]
then
source="/private/var/root/Library/Preferences/com.apple.bluetoothd.plist"
fi

if [[ -f "/private/var/root/Library/Preferences/blued.plist" ]]
then
source="/private/var/root/Library/Preferences/blued.plist"
fi

if [[ $source ]]
then
defaults read $source
else
echo "File not found"
exit
fi

for s in /Volumes/*/private/var/root/Library/Preferences
do

if [[ -f "$s/com.apple.bluetoothd.plist" ]]
then
target="$s/com.apple.bluetoothd.plist"
fi

if [[ -f "$s/blued.plist" ]]
then
target="$s/blued.plist"
fi

cp -v "${source}" "${target}"

done`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants