Skip to content

Commit e1b2ef5

Browse files
committed
Prevented pairing failure when pairing - unpairing - pairing. Refactored checking credentials (not deleting preference key's anymore)
1 parent 0565965 commit e1b2ef5

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## V0.0.10 (2022-11-07)
2+
- Prevented pairing failure when pairing - unpairing - pairing
3+
- Refactored checking credentials (not deleting preference key's anymore)
4+
15
## V0.0.9 (2022-10-04)
26
- Prevented executing action when lock is not present (battery or lock failure) based on advertising heartbeat
37
- Reduced BLE connect retries from 10 to 5

src/NukiBle.cpp

+22-3
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ PairingResult NukiBle::pairNuki(AuthorizationIdType idType) {
8080
PairingResult result = PairingResult::Pairing;
8181

8282
if (pairingServiceAvailable && bleAddress != BLEAddress("")) {
83+
#ifdef DEBUG_NUKI_CONNECT
84+
log_d("Nuki in pairing mode found");
85+
#endif
8386
if (connectBle(bleAddress)) {
8487
crypto_box_keypair(myPublicKey, myPrivateKey);
8588

@@ -108,7 +111,7 @@ PairingResult NukiBle::pairNuki(AuthorizationIdType idType) {
108111
log_d("pairing result %d", result);
109112
#endif
110113

111-
isPaired = result == PairingResult::Success;
114+
isPaired = (result == PairingResult::Success);
112115
return result;
113116
}
114117

@@ -121,6 +124,9 @@ void NukiBle::unPairNuki() {
121124
}
122125

123126
bool NukiBle::connectBle(const BLEAddress bleAddress) {
127+
#ifdef DEBUG_NUKI_CONNECT
128+
log_d("connecting within: %s", pcTaskGetTaskName(xTaskGetCurrentTaskHandle()));
129+
#endif
124130
connecting = true;
125131
bleScanner->enableScanning(false);
126132
if (!pClient->isConnected()) {
@@ -233,6 +239,8 @@ void NukiBle::onResult(BLEAdvertisedDevice* advertisedDevice) {
233239
#endif
234240
bleAddress = advertisedDevice->getAddress();
235241
pairingServiceAvailable = true;
242+
} else {
243+
pairingServiceAvailable = false;
236244
}
237245
}
238246
}
@@ -597,11 +605,18 @@ bool NukiBle::retrieveCredentials() {
597605
log_d("PinCode: %d", pinCode);
598606
#endif
599607

608+
if (secretKeyK[0] == 0x00 || authorizationId[0] == 0x00) {
609+
log_w("secret key OR authorizationId is empty: not paired");
610+
giveNukiBleSemaphore();
611+
return false;
612+
}
613+
600614
if (pinCode == 0) {
601615
log_w("Pincode is 000000");
602616
}
603617

604618
} else {
619+
log_e("Getting data from NVS issue");
605620
giveNukiBleSemaphore();
606621
return false;
607622
}
@@ -613,8 +628,12 @@ bool NukiBle::retrieveCredentials() {
613628

614629
void NukiBle::deleteCredentials() {
615630
if (takeNukiBleSemaphore("del cred")) {
616-
preferences.remove(SECRET_KEY_STORE_NAME);
617-
preferences.remove(AUTH_ID_STORE_NAME);
631+
unsigned char emptySecretKeyK[32] = {0x00};
632+
unsigned char emptyAuthorizationId[4] = {0x00};
633+
preferences.putBytes(SECRET_KEY_STORE_NAME, emptySecretKeyK, 32);
634+
preferences.putBytes(AUTH_ID_STORE_NAME, emptyAuthorizationId, 4);
635+
// preferences.remove(SECRET_KEY_STORE_NAME);
636+
// preferences.remove(AUTH_ID_STORE_NAME);
618637
giveNukiBleSemaphore();
619638
}
620639
#ifdef DEBUG_NUKI_CONNECT

0 commit comments

Comments
 (0)