Commit f7e74dd5 authored by Johan Hedberg's avatar Johan Hedberg Committed by Johan Hedberg
Browse files

Bluetooth: Mesh: Fix provisioning with Key Refresh flag set



We should not have any valid key material in key slot 0 if the KR flag
is set, since then the new key/old key information will be incorrect
when network PDUs get decrypted.

Signed-off-by: default avatarJohan Hedberg <johan.hedberg@intel.com>
parent 4492c5d0
Loading
Loading
Loading
Loading
+13 −9
Original line number Diff line number Diff line
@@ -445,10 +445,20 @@ int bt_mesh_net_create(u16_t idx, u8_t flags, const u8_t key[16],

	sub = &bt_mesh.sub[0];

	sub->kr_flag = BT_MESH_KEY_REFRESH(flags);
	if (sub->kr_flag) {
		err = bt_mesh_net_keys_create(&sub->keys[1], key);
		if (err) {
			return -EIO;
		}

		sub->kr_phase = BT_MESH_KR_PHASE_2;
	} else {
		err = bt_mesh_net_keys_create(&sub->keys[0], key);
		if (err) {
			return -EIO;
		}
	}

	bt_mesh.valid = 1;
	sub->net_idx = idx;
@@ -459,12 +469,6 @@ int bt_mesh_net_create(u16_t idx, u8_t flags, const u8_t key[16],
		sub->node_id = BT_MESH_NODE_IDENTITY_NOT_SUPPORTED;
	}

	sub->kr_flag = BT_MESH_KEY_REFRESH(flags);
	if (sub->kr_flag) {
		memcpy(&sub->keys[1], &sub->keys[0], sizeof(sub->keys[0]));
		sub->kr_phase = BT_MESH_KR_PHASE_2;
	}

	bt_mesh.iv_index = iv_index;
	bt_mesh.iv_update = BT_MESH_IV_UPDATE(flags);