|
15 | 15 | */
|
16 | 16 |
|
17 | 17 | #include <stdint.h>
|
| 18 | +#include "platform/mbed_assert.h" |
18 | 19 | #include "nRF5xPalSecurityManager.h"
|
19 | 20 | #include "nRF5xn.h"
|
20 | 21 | #include "ble/Gap.h"
|
@@ -80,11 +81,6 @@ struct nRF5xSecurityManager::pairing_control_block_t {
|
80 | 81 | ble_gap_id_key_t peer_id_key;
|
81 | 82 | ble_gap_sign_info_t peer_sign_key;
|
82 | 83 | ble_gap_lesc_p256_pk_t peer_pk;
|
83 |
| - |
84 |
| - // flag required to help DHKey computation/process; should be removed with |
85 |
| - // later versions of the softdevice |
86 |
| - uint8_t own_oob:1; |
87 |
| - uint8_t peer_oob:1; |
88 | 84 | };
|
89 | 85 |
|
90 | 86 | nRF5xSecurityManager::nRF5xSecurityManager()
|
@@ -662,26 +658,37 @@ ble_error_t nRF5xSecurityManager::secure_connections_oob_request_reply(
|
662 | 658 | const oob_lesc_value_t &peer_random,
|
663 | 659 | const oob_confirm_t &peer_confirm
|
664 | 660 | ) {
|
| 661 | + bool have_oob_own; |
| 662 | + bool have_oob_peer; |
| 663 | + const oob_lesc_value_t zerokey; |
| 664 | + ble_gap_lesc_oob_data_t oob_own; |
| 665 | + ble_gap_lesc_oob_data_t oob_peer; |
| 666 | + |
665 | 667 | pairing_control_block_t* pairing_cb = get_pairing_cb(connection);
|
666 | 668 | if (!pairing_cb) {
|
667 | 669 | return BLE_ERROR_INVALID_STATE;
|
668 | 670 | }
|
669 | 671 |
|
670 |
| - ble_gap_lesc_oob_data_t oob_own; |
671 |
| - ble_gap_lesc_oob_data_t oob_peer; |
672 |
| - |
673 |
| - // is own address important ? |
674 |
| - memcpy(oob_own.r, local_random.data(), local_random.size()); |
675 |
| - // FIXME: What to do with local confirm ??? |
| 672 | + have_oob_own = false; |
| 673 | + if (local_random != zerokey) { |
| 674 | + have_oob_own = true; |
| 675 | + // is own address important ? |
| 676 | + memcpy(oob_own.r, local_random.data(), local_random.size()); |
| 677 | + // FIXME: What to do with local confirm ??? |
| 678 | + } |
676 | 679 |
|
677 |
| - // is peer address important ? |
678 |
| - memcpy(oob_peer.r, peer_random.data(), peer_random.size()); |
679 |
| - memcpy(oob_peer.c, peer_confirm.data(), peer_confirm.size()); |
| 680 | + have_oob_peer = false; |
| 681 | + if (peer_random != zerokey && peer_confirm != zerokey) { |
| 682 | + have_oob_peer = true; |
| 683 | + // is peer address important ? |
| 684 | + memcpy(oob_peer.r, peer_random.data(), peer_random.size()); |
| 685 | + memcpy(oob_peer.c, peer_confirm.data(), peer_confirm.size()); |
| 686 | + } |
680 | 687 |
|
681 | 688 | uint32_t err = sd_ble_gap_lesc_oob_data_set(
|
682 | 689 | connection,
|
683 |
| - pairing_cb->own_oob ? &oob_own : NULL, |
684 |
| - pairing_cb->peer_oob ? &oob_peer : NULL |
| 690 | + have_oob_own ? &oob_own : NULL, |
| 691 | + have_oob_peer ? &oob_peer : NULL |
685 | 692 | );
|
686 | 693 |
|
687 | 694 | return convert_sd_error(err);
|
@@ -734,7 +741,9 @@ ble_error_t nRF5xSecurityManager::generate_secure_connections_oob()
|
734 | 741 | ble_gap_lesc_p256_pk_t own_secret;
|
735 | 742 | ble_gap_lesc_oob_data_t oob_data;
|
736 | 743 |
|
737 |
| - memcpy(own_secret.pk, secret.data(), secret.size()); |
| 744 | + MBED_ASSERT(sizeof(own_secret.pk) >= X.size() + Y.size()); |
| 745 | + memcpy(own_secret.pk, X.data(), X.size()); |
| 746 | + memcpy(own_secret.pk + X.size(), Y.data(), Y.size()); |
738 | 747 |
|
739 | 748 | uint32_t err = sd_ble_gap_lesc_oob_data_get(
|
740 | 749 | BLE_CONN_HANDLE_INVALID,
|
|
0 commit comments