1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-29 13:26:50 +01:00

Mi Band 6: Make new auth protocol a setting for now

This commit is contained in:
Andreas Shimokawa 2021-08-26 10:33:33 +02:00
parent 2c06e5d39c
commit 44fcd454a0
4 changed files with 9 additions and 6 deletions

View File

@ -254,7 +254,7 @@ public class HuamiSupport extends AbstractBTLEDeviceSupport {
needsAuth = false;
characteristicChunked2021Write = getCharacteristic(HuamiService.UUID_CHARACTERISTIC_CHUNKEDTRANSFER_2021_WRITE);
characteristicChunked2021Read = getCharacteristic(HuamiService.UUID_CHARACTERISTIC_CHUNKEDTRANSFER_2021_READ);
if (characteristicChunked2021Write != null) {
if (characteristicChunked2021Write != null && GBApplication.getDeviceSpecificSharedPrefs(gbDevice.getAddress()).getBoolean("force_new_protocol", false)) {
new InitOperation2021(authenticate, authFlags, cryptFlags, this, builder).perform();
} else {
new InitOperation(authenticate, authFlags, cryptFlags, this, builder).perform();

View File

@ -146,7 +146,7 @@ public class InitOperation2021 extends InitOperation {
huamiSupport.setInitialized(builder);
huamiSupport.performImmediately(builder);
} catch (Exception e) {
LOG.error("faild initializing device", e);
LOG.error("failed initializing device", e);
}
return true;
} else {
@ -161,17 +161,13 @@ public class InitOperation2021 extends InitOperation {
lastSequenceNumber = sequenceNumber;
if (reassembleBuffer_pointer == reassembleBuffer_expectedBytes) {
System.arraycopy(reassembleBuffer, 0, remoteRandom, 0, 16);
LOG.info("remoteRandom: " + GB.hexdump(remoteRandom));
System.arraycopy(reassembleBuffer, 16, remotePublicEC, 0, 48);
LOG.info("remotePublicEC: " + GB.hexdump(remotePublicEC));
sharedEC = ecdh_generate_shared(privateEC, remotePublicEC);
LOG.info("sharedEC: " + GB.hexdump(sharedEC));
byte[] secretKey = getSecretKey();
for (int i = 0; i < 16; i++) {
finalSharedSessionAES[i] = (byte) (sharedEC[i + 8] ^ secretKey[i]);
}
LOG.info("sharedSessionAES: " + GB.hexdump(finalSharedSessionAES));
try {
byte[] encryptedRandom1 = encryptAES(remoteRandom, secretKey);
byte[] encryptedRandom2 = encryptAES(remoteRandom, finalSharedSessionAES);

View File

@ -219,6 +219,8 @@
<string name="pref_display_add_device_fab">Connect new device button</string>
<string name="pref_display_add_device_fab_on">Always visible</string>
<string name="pref_display_add_device_fab_off">Visible only if no device is added</string>
<string name="pref_title_huami_force_new_protocol">New Auth Protocol</string>
<string name="pref_summary_huami_force_new_protocol">Enable if your device no longer connects after a firmware upgrade</string>
<!-- HPlus Preferences -->
<string name="pref_title_unit_system">Units</string>
<string name="pref_title_timeformat">Time format</string>

View File

@ -28,4 +28,9 @@
android:key="language"
android:summary="%s"
android:title="@string/pref_title_language" />
<SwitchPreference
android:defaultValue="false"
android:key="force_new_protocol"
android:summary="@string/pref_summary_huami_force_new_protocol"
android:title="@string/pref_title_huami_force_new_protocol" />
</androidx.preference.PreferenceScreen>