From 65bdd91005e5a6c53399025f6bc6a8a346d425de Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Sun, 15 Mar 2015 11:35:48 -0700 Subject: tools: Generate the Security Manager TK Value if requested --- tools/oobtest.c | 57 +++++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 37 insertions(+), 20 deletions(-) (limited to 'tools/oobtest.c') diff --git a/tools/oobtest.c b/tools/oobtest.c index 720006245..2a4ae2bee 100644 --- a/tools/oobtest.c +++ b/tools/oobtest.c @@ -34,6 +34,7 @@ #include "src/shared/mainloop.h" #include "src/shared/util.h" #include "src/shared/mgmt.h" +#include "src/shared/crypto.h" static bool use_bredr = false; static bool use_le = false; @@ -52,6 +53,7 @@ static uint16_t index1 = MGMT_INDEX_NONE; static uint16_t index2 = MGMT_INDEX_NONE; static bdaddr_t bdaddr1; static bdaddr_t bdaddr2; +static uint8_t oob_tk[16]; static void pin_code_request_event(uint16_t index, uint16_t len, const void *param, void *user_data) @@ -367,7 +369,11 @@ static void read_oob_ext_data_complete(uint8_t status, uint16_t len, eir_len = le16_to_cpu(rp->eir_len); printf(" OOB data len: %u\n", eir_len); - tk = NULL; + if (provide_tk) + tk = oob_tk; + else + tk = NULL; + hash256 = NULL; rand256 = NULL; @@ -388,16 +394,6 @@ static void read_oob_ext_data_complete(uint8_t status, uint16_t len, if (parsed > eir_len) break; - /* Security Manager TK Value */ - if (eir[1] == 0x10) { - tk = eir + 2; - - printf(" TK Value: "); - for (i = 0; i < 16; i++) - printf("%02x", tk[i]); - printf("\n"); - } - /* LE Secure Connections Confirmation Value */ if (eir[1] == 0x22) { hash256 = eir + 2; @@ -421,14 +417,6 @@ static void read_oob_ext_data_complete(uint8_t status, uint16_t len, eir += field_len + 1; } - if (!provide_tk) - tk = NULL; - - if (!provide_p256) { - hash256 = NULL; - rand256 = NULL; - } - done: if (index == index1) add_remote_oob_data(index2, &bdaddr1, @@ -476,7 +464,7 @@ static void set_powered_complete(uint8_t status, uint16_t len, mgmt_send(mgmt, MGMT_OP_READ_LOCAL_OOB_DATA, index, 0, NULL, read_oob_data_complete, UINT_TO_PTR(index), NULL); - } else if (use_le && (provide_tk || provide_p256)) { + } else if (use_le && provide_p256) { uint8_t type = (1 << BDADDR_LE_PUBLIC) | (1 << BDADDR_LE_RANDOM); @@ -484,6 +472,15 @@ static void set_powered_complete(uint8_t status, uint16_t len, sizeof(type), &type, read_oob_ext_data_complete, UINT_TO_PTR(index), NULL); + } else if (use_le && provide_tk) { + const uint8_t *tk = oob_tk; + + if (index == index1) + add_remote_oob_data(index2, &bdaddr1, + tk, NULL, NULL, NULL); + else if (index == index2) + add_remote_oob_data(index1, &bdaddr2, + tk, NULL, NULL, NULL); } else { if (index == index1) add_remote_oob_data(index2, &bdaddr1, @@ -611,6 +608,16 @@ static void read_info(uint8_t status, uint16_t len, const void *param, return; } + if (provide_tk) { + const uint8_t *tk = oob_tk; + int i; + + printf(" TK Value: "); + for (i = 0; i < 16; i++) + printf("%02x", tk[i]); + printf("\n"); + } + mgmt_register(mgmt, MGMT_EV_PIN_CODE_REQUEST, index, pin_code_request_event, UINT_TO_PTR(index), NULL); @@ -747,6 +754,16 @@ static void read_index_list(uint8_t status, uint16_t len, const void *param, printf("Selecting index %u for initiator\n", index1); printf("Selecting index %u for acceptor\n", index2); + if (provide_tk) { + struct bt_crypto *crypto; + + printf("Generating Security Manager TK Value\n"); + + crypto = bt_crypto_new(); + bt_crypto_random_bytes(crypto, oob_tk, 16); + bt_crypto_unref(crypto); + } + mgmt_send(mgmt, MGMT_OP_READ_INFO, index1, 0, NULL, read_info, UINT_TO_PTR(index1), NULL); mgmt_send(mgmt, MGMT_OP_READ_INFO, index2, 0, NULL, -- cgit v1.2.1