Nuki Unlock App : strange size of first answer to Request Data command with Challenge

Using : ESP32 and Nuki Bluetooth API with Nuki firmware : 1.7.3
I succeeded in the first step of pairing (got a User, a AuthID, a SharedKy, all get during pairing step…)
Now trying to run Unlock sketch.
When I send the first request (Request Data + Challenge), I got an answer in 220 chars (from BLE readData).
In the first 30 chars I found a nonce, an authID different than the one I sent, & a 66 chars length data.
My Decrypt function return an error, unless I checked 20 times the datas to decrypt buffer built with the 16 x 0 Bytes first (required by crypto_secretbox_open()) followed by the 66 encrypted chars…
I saw that the message length 2 Bytes are switch in your exemple (low byte first, hi byte seconde).
I also check my decrypt function with the datas of your exemple with success.
Thank you for your help.

I guess that my error comes from the fact I try to get Nuki answer with a pRemoteCharacteristic.readValue() while I don’t get any notifications for indication on the USDIO characteristic… I tried to but it doesn’t work. I use pRemoteCharacteristic->registerForNotify(notifyCallback, false) for registry… it works well with the GDIO a92ee201-5501-11e4-916c-0800200c9a66, not with USDIO a92ee202-5501-11e4-916c-0800200c9a66…

I’m still freeze at the same step. I really need some help.

Here are some added informations about :

  • using : // The remote service & characteristic AFTER pairing step
    static BLEUUID serviceUUIDPaired(“a92ee200-5501-11e4-916c-0800200c9a66”);//Nuki Keyturner Service
    static BLEUUID charUSDIO (“a92ee202-5501-11e4-916c-0800200c9a66”);// USDIO characteristic

  • register for indications :
    pRemoteCharacteristic->registerForNotify(notifyCallback, false); //false = indication, true = notification

_____ datas :
SharedKey :E4C954A2F53F9F5E03352B1C44664B8BE61F38E62BA352859026910E8C2A2093
authorizationID : 100C0000

_____ Challenge command
Unencrypted : 0100C00000100040091E4
Encrypted : aData : 0E1072ADE09E7D13A78CD32EEBFA912E88D83A22AF55AC9E100C00001A00
pData : 8B2F276FA893222A48CADFA0A4FDD45D06A1D147C25A04AE3CB3
____ std::string value = pRemoteCharacteristic->readValue(); -> 150 chars string


if I check the encrypted length in this answer (pos 28/29) = 6789 -> length of decrypted read in aData: 35175

I found the issue. For getting registered for indications with the USDIO char, you need to add the true parameter when you call pRemoteCharacteristic->writeValue(message, sizeofmessage, true); !!! hope this can help others… it took me so long time to find it

1 Like