Hello,
I always get the Error Message 12 00 11 05 00 73 da after sending the authorization authenticator command.
The strange thing is, I have tried the values from the example in the API description and with this values I got the expected results. So I dont know what is the problem here.
I am using the ESP-3.0 and the libsodium library for encryption and hashing.
Here is my LOG:
I (3993) NUKI_PAIRING: Start pairing
I (4003) Prepare Write: : 01 00 03 00 27 a7
I (4023) GATTC_DEMO: write descr success
I (4053) GATTC_DEMO: ESP_GATTC_PREP_WRITE_EVT, write prepare event
I (4053) Execute Write: : execute write command function called
I (4083) GATTC_DEMO: ESPGATTC_EXEC_EVT, write executed event
I (4203) GATTC_DEMO: ESP_GATTC_NOTIFY_EVT, receive indicate value:
I (4203) GATTC_DEMO: 03 00 39 e7 5f b9 4b be c0 31 7f 8c fb 88 09 eb
I (4213) GATTC_DEMO: 50 97 51 45
I (4233) GATTC_DEMO: ESP_GATTC_NOTIFY_EVT, receive indicate value:
I (4233) GATTC_DEMO: 29 83 35 c0 e1 26 cd 48 cb 64 b5 7c 8c 26 53 53
I (4503) NUKI_PAIRING: Received public key from smartlock
I (5003) Prepare Write: : 03 00 8c aa 54 67 23 07 bf fd f5 ea 18 3f c6 07
I (5003) Prepare Write: : 15 8d 20 11 d0 08 ec a6 a1 08 86 14 ff 08 53 a5
I (5003) Prepare Write: : aa 07 b4 9e
I (5033) GATTC_DEMO: ESP_GATTC_PREP_WRITE_EVT, write prepare event
I (5033) Execute Write: : execute write command function called
I (5063) GATTC_DEMO: ESP_GATTC_NOTIFY_EVT, receive indicate value:
I (5063) GATTC_DEMO: 04 00 e8 8d f6 06 0d 05 72 71 ec 70 27 90 c7 77
I (5063) GATTC_DEMO: 0c f5 a1 a4
I (5063) GATTC_DEMO: ESPGATTC_EXEC_EVT, write executed event
I (5093) GATTC_DEMO: ESP_GATTC_NOTIFY_EVT, receive indicate value:
I (5093) GATTC_DEMO: 56 68 e1 c2 6d b3 fd 2e 50 bd 2c 25 6b fb a6 33
I (5513) NUKI_PAIRING: Received challenge for authorization authenticator
I (5563) PUBLIC KEY FOB: : 8c aa 54 67 23 07 bf fd f5 ea 18 3f c6 07 15 8d
I (5563) PUBLIC KEY FOB: : 20 11 d0 08 ec a6 a1 08 86 14 ff 08 53 a5 aa 07
I (5573) PUBLIC KEY NUKI: : 39 e7 5f b9 4b be c0 31 7f 8c fb 88 09 eb 50 97
I (5573) PUBLIC KEY NUKI: : 51 45 29 83 35 c0 e1 26 cd 48 cb 64 b5 7c 8c 26
I (5583) NONCE: : e8 8d f6 06 0d 05 72 71 ec 70 27 90 c7 77 0c f5
I (5593) NONCE: : a1 a4 56 68 e1 c2 6d b3 fd 2e 50 bd 2c 25 6b fb
I (5603) r: : 8c aa 54 67 23 07 bf fd f5 ea 18 3f c6 07 15 8d
I (5603) r: : 20 11 d0 08 ec a6 a1 08 86 14 ff 08 53 a5 aa 07
I (5613) r: : 39 e7 5f b9 4b be c0 31 7f 8c fb 88 09 eb 50 97
I (5623) r: : 51 45 29 83 35 c0 e1 26 cd 48 cb 64 b5 7c 8c 26
I (5623) r: : e8 8d f6 06 0d 05 72 71 ec 70 27 90 c7 77 0c f5
I (5633) r: : a1 a4 56 68 e1 c2 6d b3 fd 2e 50 bd 2c 25 6b fb
I (5643) AUTHENTICATOR: : cf 43 b0 31 c2 7b c5 09 84 84 5f e8 c8 7f 72 49
I (5643) AUTHENTICATOR: : ae fb 74 b3 4f 44 c6 c7 ca 0b e9 e6 c7 91 74 29
I (6153) Prepare Write: : 05 00 cf 43 b0 31 c2 7b c5 09 84 84 5f e8 c8 7f
I (6153) Prepare Write: : 72 49 ae fb 74 b3 4f 44 c6 c7 ca 0b e9 e6 c7 91
I (6153) Prepare Write: : 74 29 10 3b
I (6183) GATTC_DEMO: ESP_GATTC_PREP_WRITE_EVT, write prepare event
I (6183) Execute Write: : execute write command function called
I (6213) GATTC_DEMO: ESPGATTC_EXEC_EVT, write executed event
I (6333) GATTC_DEMO: ESP_GATTC_NOTIFY_EVT, receive indicate value:
I (6333) GATTC_DEMO: 12 00 11 05 00 73 da
Here is my Code:
static uint8_t public_key_fob[32] = {0x8C, 0xAA, 0x54, 0x67, 0x23, 0x07, 0xBF, 0xFD, 0xF5, 0xEA, 0x18, 0x3F, 0xC6, 0x07, 0x15, 0x8D, 0x20, 0x11, 0xD0, 0x08, 0xEC, 0xA6, 0xA1, 0x08, 0x86, 0x14, 0xFF, 0x08, 0x53, 0xA5, 0xAA, 0x07};
static uint8_t private_key_fob[32] = {0xF8, 0x81, 0x27, 0xCC, 0xF4, 0x80, 0x23, 0xB5, 0xCB, 0xE9, 0x10, 0x1D, 0x24, 0xBA, 0xA8, 0xA3, 0x68, 0xDA, 0x94, 0xE8, 0xC2, 0xE3, 0xCD, 0xE2, 0xDE, 0xD2, 0x9C, 0xE9, 0x6A, 0xB5, 0x0C, 0x15};
static void calculate_authenticator(uint8_t* output_buffer, uint8_t* message, uint16_t message_length) {
crypto_auth_hmacsha256(output_buffer, message, message_length, pairing_ctx.shared_secret);
}
uint16_t create_authorization_authenticator_payload(uint8_t* output_buffer, uint8_t* received_data)
{
uint8_t* nonce = &received_data[2];
uint16_t command_length = 36;
write_uint16LE(output_buffer, authorization_authenticator_cmd, 0);
//Shared key calculation
uint8_t dh_key[32]; //crypto_scalarmult_BYTES
int ret = crypto_scalarmult_curve25519(dh_key, private_key_fob, public_key_nuki);
if(ret == -1)
{
ESP_LOGE("NUKI Authorization", "Error in Crypto Scalarmult");
return 0;
}
unsigned char _0[16];
memset(_0, 0, 16);
const unsigned char sigma[16] = "expand 32-byte k";
crypto_core_hsalsa20(pairing_ctx.shared_secret, _0, dh_key, sigma);
const uint16_t r_length = 32 + 32 + PAIRING_NONCEBYTES;
uint8_t r[32 + 32 + PAIRING_NONCEBYTES];
memcpy(r, public_key_fob, 32);
memcpy(&r[32], public_key_nuki, 32);
memcpy(&r[32 + 32], nonce, PAIRING_NONCEBYTES);
uint8_t authenticator[32];
calculate_authenticator(authenticator, r, r_length);
memcpy(&output_buffer[2], authenticator, 32);
crc_payload(output_buffer, command_length);
esp_log_buffer_hex("PUBLIC KEY FOB: ", public_key_fob, 32);
esp_log_buffer_hex("PUBLIC KEY NUKI: ", public_key_nuki, 32);
esp_log_buffer_hex("NONCE: ", nonce, 32);
esp_log_buffer_hex("r: ", r, r_length);
esp_log_buffer_hex("AUTHENTICATOR: ", authenticator, 32);
return command_length;
}
What could be the problem here?
Thanks for your Help!