I can pair my FOB with a Nuki 2.0 but when I try to read lock state writing encrypted Request Data command, with Keyturner States command indentifier, to USDIO I don’t receive any indication.
I’m using crypto_secretbox_easy() from libsodium library ( Encryption: XSalsa20 stream cipher and Authentication: Poly1305 MAC)
I don’t now if it’s a issue with the encryption or something else. The problem It’s I don’t receive any error message even though I connect to Keyturner Service and have enable indications for USDIO char.
So your key is 467AADC839A2F63AB58B664EC9848EF208FF738EB1DBD8BEA86094C901FE560C
The message you’re sending is EA3765C4EED6EBC6BC2CCF28B39913A418C4174D7DAB9C65005D34001A00E0B4FC3F60B4FC3F08000000E0B4FC3F60B4FC3F080000002033
This means the nonce is EA3765C4EED6EBC6BC2CCF28B39913A418C4174D7DAB9C65
With your key and the nonce the message fails to decrypt.
Using your nonce and key, the full message you’re sending should look like this: EA3765C4EED6EBC6BC2CCF28B39913A418C4174D7DAB9C65005D34001A00B1E7311B9B3B49B2938487CAC2DCBA3A8117136247FF524C60B4
Unencrypted message: 005D340001000C00
Unencrypted message with CRC: 005D340001000C00572B
Encrypted message: B1E7311B9B3B49B2938487CAC2DCBA3A8117136247FF524C60B4
Encrypted message with authId, length and nonce: EA3765C4EED6EBC6BC2CCF28B39913A418C4174D7DAB9C65005D34001A00B1E7311B9B3B49B2938487CAC2DCBA3A8117136247FF524C60B4
If you’re using libsodium, you may use crypto_secretbox() and crypto_secretbox_open() to encrypt and decrypt.
Note: please also register for indications on GDIO. You’ll receive the “NOT_AUTHORIZED” error there.
Following your advice I’ve changed to crypto_secretbox(), using libsodium library in C++, and also register for indications on GDIO to get the error.
Eventually the result was:
[D][nuki.cpp:155] create_challenge_payload(): CL Request Data 10 bytes (Unencrypted):
00 5D 34 00 01 00 0C 00
57 2B
[D][nuki.cpp:68] encrypt_payload(): client is encrypting payload message 10 bytes...
[D][nuki.cpp:81] encrypt_payload(): crypto_box(c,m,mlen,n,k)
[D][nuki.cpp:82] encrypt_payload(): m :
00 5D 34 00 01 00 0C 00
57 2B
[D][nuki.cpp:84] encrypt_payload(): mlen : 10
[D][nuki.cpp:85] encrypt_payload(): n :
03 19 9B C2 C1 71 4C 6C
00 BA 93 40 A0 3C BB 2C
27 C0 E4 40 D9 98 CE C4
[D][nuki.cpp:87] encrypt_payload(): k :
FD AF DC BF 9B 30 B3 E6
58 C7 59 88 FA 7D 98 D0
24 FA E4 3E E3 97 2D 78
DB 06 D1 79 AD E8 94 34
[D][nuki.cpp:30] current_state(): Request lock state: CL sends 56 bytes.
03 19 9B C2 C1 71 4C 6C
00 BA 93 40 A0 3C BB 2C
27 C0 E4 40 D9 98 CE C4
00 5D 34 00 1A 00 C0 B4
FC 3F 40 B4 FC 3F 08 00
00 00 C0 B4 FC 3F 40 B4
FC 3F 08 00 00 00 20 32
[D][BLERemoteCharacteristic.cpp:554] writeValue(): >> writeValue(), length: 56
[D][FreeRTOS.cpp:164] take(): Semaphore taking: name: WriteCharEvt (0x3ffe9220), owner: <N/A> for writeValue
[D][FreeRTOS.cpp:173] take(): Semaphore taken: name: WriteCharEvt (0x3ffe9220), owner: writeValue
[D][BLEDevice.cpp:152] gattClientEventHandler(): gattClientEventHandler [esp_gatt_if: 5] ... ESP_GATTC_NOTIFY_EVT
[D][BLEClient.cpp:170] gattClientEventHandler(): gattClientEventHandler [esp_gatt_if: 5] ... ESP_GATTC_NOTIFY_EVT
[D][BLERemoteCharacteristic.cpp:170] gattClientEventHandler(): Invoking callback for notification on characteristic Characteristic: uuid: a92ee201-5501-11e4-916c-0800200c9a66, handle:
143 0x8f, props: broadcast: 0, read: 1, write_nr: 0, write: 1, notify: 0, indicate: 1, auth: 0
[D][myBLE.cpp:123] myBLE_notifyCallback(): ******************** Notify callback for characteristic
[D][myBLE.cpp:124] myBLE_notifyCallback(): a92ee201-5501-11e4-916c-0800200c9a66
[D][myBLE.cpp:125] myBLE_notifyCallback(): of data length 9
[D][nuki.cpp:272] processMessage(): client receives 9 bytes.
12 00 20 00 00 C2 C1 B9
17
[E][nuki.cpp:376] get_commandId(): Command Id: ERROR_REPORT >> K_ERROR_NOT_AUTHORIZED.
D][nuki.cpp:278] processMessage(): size of response buffer 9
[D][BLEDevice.cpp:152] gattClientEventHandler(): gattClientEventHandler [esp_gatt_if: 5] ... ESP_GATTC_WRITE_CHAR_EVT
[D][BLEClient.cpp:170] gattClientEventHandler(): gattClientEventHandler [esp_gatt_if: 5] ... ESP_GATTC_WRITE_CHAR_EVT
[D][BLERemoteCharacteristic.cpp:581] writeValue(): << writeValue
[E][myBLE.cpp:79] myBLE_connect(): Failed to connect to the server; there is nothing more we will do.
[D][BLEDevice.cpp:152] gattClientEventHandler(): gattClientEventHandler [esp_gatt_if: 4] ... ESP_GATTC_DISCONNECT_EVT
[D][BLEClient.cpp:170] gattClientEventHandler(): gattClientEventHandler [esp_gatt_if: 4] ... ESP_GATTC_DISCONNECT_EVT
[E][BLEClient.cpp:193] gattClientEventHandler(): disconnect event, reason: 19, connId: 0, my connId: 0, my IF: 4, gattc_if: 4
[D][BLEDevice.cpp:152] gattClientEventHandler(): gattClientEventHandler [esp_gatt_if: 4] ... ESP_GATTC_CLOSE_EVT
[D][BLEClient.cpp:170] gattClientEventHandler(): gattClientEventHandler [esp_gatt_if: 4] ... ESP_GATTC_CLOSE_EVT
[D][BLEDevice.cpp:152] gattClientEventHandler(): gattClientEventHandler [esp_gatt_if: 5] ... ESP_GATTC_DISCONNECT_EVT
[D][BLEClient.cpp:170] gattClientEventHandler(): gattClientEventHandler [esp_gatt_if: 5] ... ESP_GATTC_DISCONNECT_EVT
[E][BLEClient.cpp:193] gattClientEventHandler(): disconnect event, reason: 19, connId: 0, my connId: 0, my IF: 5, gattc_if: 5
[D][BLEDevice.cpp:152] gattClientEventHandler(): gattClientEventHandler [esp_gatt_if: 5] ... ESP_GATTC_CLOSE_EVT
[D][BLEClient.cpp:170] gattClientEventHandler(): gattClientEventHandler [esp_gatt_if: 5] ... ESP_GATTC_CLOSE_EVT
[E][myBLE.cpp:79] myBLE_connect(): Failed to connect to the server; there is nothing more we will do.
I don’t know if the issue It’s because original NaCl crypto_box() API needs for message padding and pointer arithmetic prior to encryption, if I use libsodium library with new wrappers crypto_secretbox_easy() remove this need.
Again I’m using your key FDAFDCBF9B30B3E658C75988FA7D98D024FAE43EE3972D78DB06D179ADE89434 and fail to decrypt your message with it.
Your payload is 03199BC2C1714C6C00BA9340A03CBB2C27C0E440D998CEC4005D34001A00C0B4FC3F40B4FC3F08000000C0B4FC3F40B4FC3F080000002032
So your nonce is 03199BC2C1714C6C00BA9340A03CBB2C27C0E440D998CEC4 and the encrypted message is C0B4FC3F40B4FC3F08000000C0B4FC3F40B4FC3F080000002032.
So if I try to decrypt C0B4FC3F40B4FC3F08000000C0B4FC3F40B4FC3F080000002032 with your key and nonce (and crypto_secretbox_open) the decryption fails.
If I take your unencrypted message 005D340001000C00572B and encrypt it with your nonce and key, the result is CBD33270BB9F810421316E05657BD92417BAB9F43318862D2502, not C0B4FC3F40B4FC3F08000000C0B4FC3F40B4FC3F080000002032.
So the whole message should be: 03199BC2C1714C6C00BA9340A03CBB2C27C0E440D998CEC4 005D3400 1A00 CBD33270BB9F810421316E05657BD92417BAB9F43318862D2502
How to you get the C0B4FC3F40B4FC3F08000000C0B4FC3F40B4FC3F080000002032 message?
It seems to contain the same message twice and a CRC on the end: C0B4FC3F40B4FC3F08000000C0B4FC3F40B4FC3F08000000 2032