Skip to contentSkip to conversation

mesh: Fix Remote/Local dev key usage

PATCH In review Brian Gix 2 participants 10 messages Sep 26, 2019 – Oct 1, 2019 Bluetooth drivers

lore
Share & tools
lore

Brian Gix

author
#0 lore raw

v3 cover mesh: Fix Remote/Local dev key usage

V3: By popular demand, the name "remote" is now used for both DevKeySend() and DevKeyMessageReceived().

In DevKeySend(), setting remote == true means that the Key Ring *must* be used to encrypt the outgoing message, and a failure will be returned if the requested destination address does not include a device key in the local key ring. For remote == false requests, the request will be rejected if the destination is an element on the local node.

In DevKeyMessageReceived(), the remote boolean will be set == true if it required the key ring to decrypot the message. If remote == false, this means that the local nodes Device Key successfully decrypted the message, and the message may be used to change or query privileged states.

Brian Gix (3):
mesh: Add local/remote bools to DevKey transactions
mesh: Use explicit Local vs Remote Device key usage
mesh: Fix Key Ring permissions for local nodes

 doc/mesh-api.txt | 17 ++++++++++++++---
 mesh/manager.c   |  5 -----
 mesh/model.c     | 11 +++++++----
 mesh/node.c      | 40 +++++++++++++++-------------------------
 4 files changed, 36 insertions(+), 37 deletions(-)
Signature · 1 line
2.21.0
author
#1 lore raw

PATCH v3 1/3 mesh: Add remote boolean to DevKey transactions

DevKey operations require authorization on the part of the applications making the requests. Messages to state changing Servers should use device keys from the remote (destination) to demonstrate authorization.

---
 doc/mesh-api.txt | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)
doc/mesh-api.txt +14 -3
index 9b9f4e3de..a589616eb 100644
@@ -245,7 +245,7 @@ Methods:
 			org.bluez.mesh.Error.InvalidArguments
 			org.bluez.mesh.Error.NotFound
 
-	void DevKeySend(object element_path, uint16 destination,
+	void DevKeySend(object element_path, uint16 destination, boolean remote,
 					uint16 net_index, array{byte} data)
 
 		This method is used to send a message originated by a local
@@ -259,6 +259,12 @@ Methods:
 		destination must be a uint16 to a unicast address, or a well
 		known group address.
 
+		The remote parameter, if true, looks up the device key by the
+		destination address in the key database to encrypt the message.
+		If remote is true, but requested key does not exist, a NotFound
+		error will be returned. If set to false, the local node's
+		device key is used.
+
 		The net_index parameter is the subnet index of the network on
 		which the message is to be sent.
 
@@ -782,8 +788,8 @@ Methods:
 
 		The data parameter is the incoming message.
 
-	void DevKeyMessageReceived(uint16 source, uint16 net_index,
-							array{byte} data)
+	void DevKeyMessageReceived(uint16 source, boolean remote,
+					uint16 net_index, array{byte} data)
 
 		This method is called by meshd daemon when a message arrives
 		addressed to the application, which was sent with the remote
@@ -792,6 +798,11 @@ Methods:
 		The source parameter is unicast address of the remote
 		node-element that sent the message.
 
+		The remote parameter if true indicates that the device key
+		used to decrypt the message was from the sender. False
+		indicates that the local nodes device key was used, and the
+		message has permissions to modify local states.
+
 		The net_index parameter indicates what subnet the message was
 		received on, and if a response is required, the same subnet
 		must be used to send the response.
Signature · 1 line
2.21.0
author
#2 lore raw

PATCH v3 2/3 mesh: Explicit Remote/Local Device key usage

In reply to Brian Gix

When sending or receiving Device Key (privileged) mesh messages, the remote vs local device key must be specified. This allows Apps to specify Key Ring stored device keys, and sanity checks that the correct key exists before allowing the transmission. Loopback messages to local servers *must* use keys from the Key Ring to indicate privilege has been granted.

---
 mesh/model.c | 11 +++++++----
 mesh/node.c  | 25 +++++++++++++++----------
 2 files changed, 22 insertions(+), 14 deletions(-)
mesh/model.c +7 -4
index a06b684a5..e9b346102 100644
@@ -735,14 +735,16 @@ static int add_sub(struct mesh_net *net, struct mesh_model *mod,
 }
 
 static void send_dev_key_msg_rcvd(struct mesh_node *node, uint8_t ele_idx,
-					uint16_t src, uint16_t net_idx,
-					uint16_t size, const uint8_t *data)
+					uint16_t src, uint16_t app_idx,
+					uint16_t net_idx, uint16_t size,
+					const uint8_t *data)
 {
 	struct l_dbus *dbus = dbus_get_bus();
 	struct l_dbus_message *msg;
 	struct l_dbus_message_builder *builder;
 	const char *owner;
 	const char *path;
+	bool remote = (app_idx != APP_IDX_DEV_LOCAL);
 
 	owner = node_get_owner(node);
 	path = node_get_element_path(node, ele_idx);
@@ -758,6 +760,7 @@ static void send_dev_key_msg_rcvd(struct mesh_node *node, uint8_t ele_idx,
 	builder = l_dbus_message_builder_new(msg);
 
 	l_dbus_message_builder_append_basic(builder, 'q', &src);
+	l_dbus_message_builder_append_basic(builder, 'b', &remote);
 	l_dbus_message_builder_append_basic(builder, 'q', &net_idx);
 	dbus_append_byte_array(builder, data, size);
 
@@ -936,8 +939,8 @@ bool mesh_model_rx(struct mesh_node *node, bool szmict, uint32_t seq0,
 			else if (decrypt_idx == APP_IDX_DEV_REMOTE ||
 				(decrypt_idx == APP_IDX_DEV_LOCAL &&
 				 mesh_net_is_local_address(net, src, 1)))
-				send_dev_key_msg_rcvd(node, i, src, 0,
-						forward.size, forward.data);
+				send_dev_key_msg_rcvd(node, i, src, decrypt_idx,
+						0, forward.size, forward.data);
 		}
 
 		/*
mesh/node.c +15 -10
index b6824f505..833377e99 100644
@@ -1976,7 +1976,8 @@ static struct l_dbus_message *dev_key_send_call(struct l_dbus *dbus,
 	const char *sender, *ele_path;
 	struct l_dbus_message_iter iter_data;
 	struct node_element *ele;
-	uint16_t dst, net_idx, src;
+	uint16_t dst, app_idx, net_idx, src;
+	bool remote;
 	uint8_t *data;
 	uint32_t len;
 
@@ -1987,8 +1988,12 @@ static struct l_dbus_message *dev_key_send_call(struct l_dbus *dbus,
 	if (strcmp(sender, node->owner))
 		return dbus_error(msg, MESH_ERROR_NOT_AUTHORIZED, NULL);
 
-	if (!l_dbus_message_get_arguments(msg, "oqqay", &ele_path, &dst,
-							&net_idx, &iter_data))
+	if (!l_dbus_message_get_arguments(msg, "oqbqay", &ele_path, &dst,
+						&remote, &net_idx, &iter_data))
+		return dbus_error(msg, MESH_ERROR_INVALID_ARGS, NULL);
+
+	/* Loopbacks to local servers must use *remote* addressing */
+	if (!remote && mesh_net_is_local_address(node->net, dst, 1))
 		return dbus_error(msg, MESH_ERROR_INVALID_ARGS, NULL);
 
 	ele = l_queue_find(node->elements, match_element_path, ele_path);
@@ -1999,13 +2004,13 @@ static struct l_dbus_message *dev_key_send_call(struct l_dbus *dbus,
 	src = node_get_primary(node) + ele->idx;
 
 	if (!l_dbus_message_iter_get_fixed_array(&iter_data, &data, &len) ||
-					!len || len > MAX_MSG_LEN)
+						!len || len > MAX_MSG_LEN)
 		return dbus_error(msg, MESH_ERROR_INVALID_ARGS,
 							"Incorrect data");
 
-	/* TODO: use net_idx */
-	if (!mesh_model_send(node, src, dst, APP_IDX_DEV_REMOTE, net_idx,
-							DEFAULT_TTL, data, len))
+	app_idx = remote ? APP_IDX_DEV_REMOTE : APP_IDX_DEV_LOCAL;
+	if (!mesh_model_send(node, src, dst, app_idx, net_idx, DEFAULT_TTL,
+								data, len))
 		return dbus_error(msg, MESH_ERROR_NOT_FOUND, NULL);
 
 	return l_dbus_message_new_method_return(msg);
@@ -2226,9 +2231,9 @@ static void setup_node_interface(struct l_dbus_interface *iface)
 						"element_path", "destination",
 						"key_index", "data");
 	l_dbus_interface_method(iface, "DevKeySend", 0, dev_key_send_call,
-						"", "oqqay", "element_path",
-						"destination", "net_index",
-						"data");
+						"", "oqbqay", "element_path",
+						"destination", "remote",
+						"net_index", "data");
 	l_dbus_interface_method(iface, "Publish", 0, publish_call, "", "oqay",
 					"element_path", "model_id", "data");
 	l_dbus_interface_method(iface, "VendorPublish", 0, vendor_publish_call,
Signature · 1 line
2.21.0
#3 lore raw

Re: [PATCH BlueZ v3 2/3] mesh: Explicit Remote/Local Device key usage

Hi Brian,

Quoted 125 lines · Brian Gix

When sending or receiving Device Key (privileged) mesh messages, the remote vs local device key must be specified. This allows Apps to specify Key Ring stored device keys, and sanity checks that the correct
key exists before allowing the transmission. Loopback messages to local
servers *must* use keys from the Key Ring to indicate privilege has been
granted.

---
 mesh/model.c | 11 +++++++----
 mesh/node.c  | 25 +++++++++++++++----------
 2 files changed, 22 insertions(+), 14 deletions(-)
mesh/model.c +6 -4
index a06b684a5..e9b346102 100644
@@ -735,14 +735,16 @@ static int add_sub(struct mesh_net *net, struct
 mesh_model *mod,
 }
 
 static void send_dev_key_msg_rcvd(struct mesh_node *node, uint8_t
 ele_idx,
-					uint16_t src, uint16_t net_idx,
-					uint16_t size, const uint8_t
 *data)
+					uint16_t src, uint16_t app_idx,
+					uint16_t net_idx, uint16_t
 size,
+					const uint8_t *data)
 {
 	struct l_dbus *dbus = dbus_get_bus();
 	struct l_dbus_message *msg;
 	struct l_dbus_message_builder *builder;
 	const char *owner;
 	const char *path;
+	bool remote = (app_idx != APP_IDX_DEV_LOCAL);
 
 	owner = node_get_owner(node);
 	path = node_get_element_path(node, ele_idx);
@@ -758,6 +760,7 @@ static void send_dev_key_msg_rcvd(struct
 mesh_node *node, uint8_t ele_idx,
 	builder = l_dbus_message_builder_new(msg);
 
 	l_dbus_message_builder_append_basic(builder, 'q', &src);
+	l_dbus_message_builder_append_basic(builder, 'b', &remote);
 	l_dbus_message_builder_append_basic(builder, 'q', &net_idx);
 	dbus_append_byte_array(builder, data, size);
@@ -936,8 +939,8 @@ bool mesh_model_rx(struct mesh_node *node, bool
 szmict, uint32_t seq0,
 			else if (decrypt_idx == APP_IDX_DEV_REMOTE ||
 				(decrypt_idx == APP_IDX_DEV_LOCAL &&
 				 mesh_net_is_local_address(net, src,
 1)))
-				send_dev_key_msg_rcvd(node, i, src, 0,
-						forward.size,
 forward.data);
+				send_dev_key_msg_rcvd(node, i, src,

decrypt_idx,

mesh/model.c +1 -0
+						0, forward.size,

forward.data);

mesh/model.c +0 -0
 		}
 
 		/*
mesh/node.c +2 -3
index b6824f505..833377e99 100644
@@ -1976,7 +1976,8 @@ static struct l_dbus_message
 *dev_key_send_call(struct l_dbus *dbus,
 	const char *sender, *ele_path;
 	struct l_dbus_message_iter iter_data;
 	struct node_element *ele;
-	uint16_t dst, net_idx, src;
+	uint16_t dst, app_idx, net_idx, src;
+	bool remote;
 	uint8_t *data;
 	uint32_t len;
@@ -1987,8 +1988,12 @@ static struct l_dbus_message
 *dev_key_send_call(struct l_dbus *dbus,
 	if (strcmp(sender, node->owner))
 		return dbus_error(msg, MESH_ERROR_NOT_AUTHORIZED,
 NULL);
 
-	if (!l_dbus_message_get_arguments(msg, "oqqay", &ele_path,
 &dst,
-							&net_idx,

&iter_data))

mesh/node.c +1 -0
+	if (!l_dbus_message_get_arguments(msg, "oqbqay", &ele_path,

&dst,

mesh/node.c +1 -0
+						&remote, &net_idx,

&iter_data))

mesh/node.c +4 -0
+		return dbus_error(msg, MESH_ERROR_INVALID_ARGS, NULL);
+
+	/* Loopbacks to local servers must use *remote* addressing */
+	if (!remote && mesh_net_is_local_address(node->net, dst, 1))
 		return dbus_error(msg, MESH_ERROR_INVALID_ARGS, NULL);
 
 	ele = l_queue_find(node->elements, match_element_path,

ele_path);

mesh/node.c +0 -0
@@ -1999,13 +2004,13 @@ static struct l_dbus_message
 *dev_key_send_call(struct l_dbus *dbus,
 	src = node_get_primary(node) + ele->idx;
 
 	if (!l_dbus_message_iter_get_fixed_array(&iter_data, &data,

&len) ||

mesh/node.c +1 -1
-					!len || len > MAX_MSG_LEN)
+						!len || len >

MAX_MSG_LEN)

mesh/node.c +0 -0
 		return dbus_error(msg, MESH_ERROR_INVALID_ARGS,
 							"Incorrect

data");

mesh/node.c +0 -2
-	/* TODO: use net_idx */
-	if (!mesh_model_send(node, src, dst, APP_IDX_DEV_REMOTE,

net_idx,

mesh/node.c +0 -1
-							DEFAULT_TTL,

data, len))

mesh/node.c +2 -0
+	app_idx = remote ? APP_IDX_DEV_REMOTE : APP_IDX_DEV_LOCAL;
+	if (!mesh_model_send(node, src, dst, app_idx, net_idx,

DEFAULT_TTL,

mesh/node.c +1 -0
+								data,
Quoted 2 lines

len))
return dbus_error(msg, MESH_ERROR_NOT_FOUND, NULL);

I think that mesh_model_send() should be modified to return an error code (int) instead of boolean. Otherwise, it may fail for a different reason than a mismatch in device key and the returned error is misleading.
In fact, the Send() call returns D-Bus "Failed" error upon getting "false" from mesh_model_send() and this is not documented in the API doc.

This probably should go a separate fix.

Quoted 25 lines
mesh/node.c +0 -2
 	return l_dbus_message_new_method_return(msg);
@@ -2226,9 +2231,9 @@ static void setup_node_interface(struct
 l_dbus_interface *iface)
 						"element_path",
 "destination",
 						"key_index", "data");
 	l_dbus_interface_method(iface, "DevKeySend", 0,
 dev_key_send_call,
-						"", "oqqay",
 "element_path",
-						"destination",

"net_index",

mesh/node.c +1 -1
-						"data");
+						"", "oqbqay",

"element_path",

mesh/node.c +1 -0
+						"destination",

"remote",

mesh/node.c +1 -0
+						"net_index", "data");
 	l_dbus_interface_method(iface, "Publish", 0, publish_call, "",

"oqay",
"element_path", "model_id",
"data");
l_dbus_interface_method(iface, "VendorPublish", 0,
vendor_publish_call,

author
#4 lore raw

PATCH v3 3/3 mesh: Fix Key Ring permissions for local nodes

In reply to Brian Gix

We do *not* automatically create populated key rings for imported or joined nodes, but we also do not *forbid* any node from adding a key in it's possesion to the local key ring.

---
 mesh/manager.c |  5 -----
 mesh/node.c    | 15 ---------------
 2 files changed, 20 deletions(-)
mesh/manager.c +0 -5
index 501ec10fe..633597659 100644
@@ -282,7 +282,6 @@ static struct l_dbus_message *import_node_call(struct l_dbus *dbus,
 						void *user_data)
 {
 	struct mesh_node *node = user_data;
-	struct mesh_net *net = node_get_net(node);
 	struct l_dbus_message_iter iter_key;
 	uint16_t primary;
 	uint8_t num_ele;
@@ -298,10 +297,6 @@ static struct l_dbus_message *import_node_call(struct l_dbus *dbus,
 		return dbus_error(msg, MESH_ERROR_INVALID_ARGS,
 							"Bad device key");
 
-	if (mesh_net_is_local_address(net, primary, num_ele))
-		return dbus_error(msg, MESH_ERROR_INVALID_ARGS,
-					"Cannot overwrite local device key");
-
 	if (!keyring_put_remote_dev_key(node, primary, num_ele, key))
 		return dbus_error(msg, MESH_ERROR_FAILED, NULL);
 
mesh/node.c +0 -15
index 833377e99..af45a6130 100644
@@ -1681,7 +1681,6 @@ static void get_managed_objects_cb(struct l_dbus_message *msg, void *user_data)
 
 	} else if (req->type == REQUEST_TYPE_IMPORT) {
 		struct node_import *import = req->import;
-		struct keyring_net_key net_key;
 
 		if (!create_node_config(node, node->uuid))
 			goto fail;
@@ -1692,23 +1691,9 @@ static void get_managed_objects_cb(struct l_dbus_message *msg, void *user_data)
 					import->net_idx, import->net_key))
 			goto fail;
 
-		memcpy(net_key.old_key, import->net_key, 16);
-		net_key.net_idx = import->net_idx;
-		if (import->flags.kr)
-			net_key.phase = KEY_REFRESH_PHASE_TWO;
-		else
-			net_key.phase = KEY_REFRESH_PHASE_NONE;
-
 		/* Initialize directory for storing keyring info */
 		init_storage_dir(node);
 
-		if (!keyring_put_remote_dev_key(node, import->unicast,
-						num_ele, import->dev_key))
-			goto fail;
-
-		if (!keyring_put_net_key(node, import->net_idx, &net_key))
-			goto fail;
-
 	} else {
 		/* Callback for create node request */
 		struct keyring_net_key net_key;
Signature · 1 line
2.21.0
#5 lore raw

Re: [PATCH BlueZ v3 3/3] mesh: Fix Key Ring permissions for local nodes

Hi Brian,

Quoted 2 lines · Brian Gix

We do *not* automatically create populated key rings for imported or joined nodes,

Why not for Import()? Since both the DevKey and NetKey are in the possesion of the node...

Quoted 75 lines

but we also do not *forbid* any node from adding a key in it's possesion to the local key ring.

---
 mesh/manager.c |  5 -----
 mesh/node.c    | 15 ---------------
 2 files changed, 20 deletions(-)
mesh/manager.c +0 -1
index 501ec10fe..633597659 100644
@@ -282,7 +282,6 @@ static struct l_dbus_message
 *import_node_call(struct l_dbus *dbus,
 						void *user_data)
 {
 	struct mesh_node *node = user_data;
-	struct mesh_net *net = node_get_net(node);
 	struct l_dbus_message_iter iter_key;
 	uint16_t primary;
mesh/manager.c +0 -4
 	uint8_t num_ele;
@@ -298,10 +297,6 @@ static struct l_dbus_message
 *import_node_call(struct l_dbus *dbus,
 		return dbus_error(msg, MESH_ERROR_INVALID_ARGS,
 							"Bad device
 key");
 
-	if (mesh_net_is_local_address(net, primary, num_ele))
-		return dbus_error(msg, MESH_ERROR_INVALID_ARGS,
-					"Cannot overwrite local device
 key");
-
mesh/manager.c +0 -0
 	if (!keyring_put_remote_dev_key(node, primary, num_ele, key))
 		return dbus_error(msg, MESH_ERROR_FAILED, NULL);
mesh/node.c +0 -1
index 833377e99..af45a6130 100644
@@ -1681,7 +1681,6 @@ static void get_managed_objects_cb(struct
 l_dbus_message *msg, void *user_data)
 
 	} else if (req->type == REQUEST_TYPE_IMPORT) {
 		struct node_import *import = req->import;
-		struct keyring_net_key net_key;
 
 		if (!create_node_config(node, node->uuid))
mesh/node.c +0 -12
 			goto fail;
@@ -1692,23 +1691,9 @@ static void get_managed_objects_cb(struct
 l_dbus_message *msg, void *user_data)
 					import->net_idx, import-
 >net_key))
 			goto fail;
 
-		memcpy(net_key.old_key, import->net_key, 16);
-		net_key.net_idx = import->net_idx;
-		if (import->flags.kr)
-			net_key.phase = KEY_REFRESH_PHASE_TWO;
-		else
-			net_key.phase = KEY_REFRESH_PHASE_NONE;
-
 		/* Initialize directory for storing keyring info */
 		init_storage_dir(node);
 
-		if (!keyring_put_remote_dev_key(node, import->unicast,
-						num_ele, import-
 >dev_key))
-			goto fail;
-
-		if (!keyring_put_net_key(node, import->net_idx,

&net_key))

mesh/node.c +0 -2
-			goto fail;
-
 	} else {
 		/* Callback for create node request */
 		struct keyring_net_key net_key;
author
#6 lore raw

Re: [PATCH BlueZ v3 3/3] mesh: Fix Key Ring permissions for local nodes

Quoted 8 lines · Inga

Hi Brian,

Quoted 2 lines · Brian Gix

We do *not* automatically create populated key rings for imported or joined nodes,

Why not for Import()? Since both the DevKey and NetKey are in the possesion of the node...

There are two (known) use cases for Import()

1. Node previously existed on a different physical piece of hardware, and is being migrated to this daemon.

2. Node was newly provisioned Out-Of-Band, and this is the net result of the provisioning.

In *neither* case is it a given that the Node should be able to provision another node (the effect of adding the Net Key to the key ring). In neither case is it a given that the Node should be able to modify it's own Config Server states (the effect of adding it's Device Key to the key ring).

However, if it *is* the case that one or more of these operations should be available to the Node, the Application that performed the Import may call the ImportSubnet() and/or the ImportRemoteNode() methods. In actuality, if this was the intent (particularily on a Node being migrated) a key-ring of some sort should have existed on the other physical piece of hardware.

The point of this larger patch-set is to no longer assume that every Node has the ability to use it's own network keys to provision other nodes, or use it's own Device Key to change it's own Config Server states.

Yes, that can still happen (as it can with non BlueZ nodes) but it should be by a deliberate mechanism, not as a "time saving default".

Quoted 77 lines
Quoted 75 lines

but we also do not *forbid* any node from adding a key in it's possesion to the local key ring.

---
 mesh/manager.c |  5 -----
 mesh/node.c    | 15 ---------------
 2 files changed, 20 deletions(-)
mesh/manager.c +0 -1
index 501ec10fe..633597659 100644
@@ -282,7 +282,6 @@ static struct l_dbus_message
 *import_node_call(struct l_dbus *dbus,
 						void *user_data)
 {
 	struct mesh_node *node = user_data;
-	struct mesh_net *net = node_get_net(node);
 	struct l_dbus_message_iter iter_key;
 	uint16_t primary;
mesh/manager.c +0 -4
 	uint8_t num_ele;
@@ -298,10 +297,6 @@ static struct l_dbus_message
 *import_node_call(struct l_dbus *dbus,
 		return dbus_error(msg, MESH_ERROR_INVALID_ARGS,
 							"Bad device
 key");
 
-	if (mesh_net_is_local_address(net, primary, num_ele))
-		return dbus_error(msg, MESH_ERROR_INVALID_ARGS,
-					"Cannot overwrite local device
 key");
-
mesh/manager.c +0 -0
 	if (!keyring_put_remote_dev_key(node, primary, num_ele, key))
 		return dbus_error(msg, MESH_ERROR_FAILED, NULL);
mesh/node.c +0 -1
index 833377e99..af45a6130 100644
@@ -1681,7 +1681,6 @@ static void get_managed_objects_cb(struct
 l_dbus_message *msg, void *user_data)
 
 	} else if (req->type == REQUEST_TYPE_IMPORT) {
 		struct node_import *import = req->import;
-		struct keyring_net_key net_key;
 
 		if (!create_node_config(node, node->uuid))
mesh/node.c +0 -12
 			goto fail;
@@ -1692,23 +1691,9 @@ static void get_managed_objects_cb(struct
 l_dbus_message *msg, void *user_data)
 					import->net_idx, import-
 > net_key))
 			goto fail;
 
-		memcpy(net_key.old_key, import->net_key, 16);
-		net_key.net_idx = import->net_idx;
-		if (import->flags.kr)
-			net_key.phase = KEY_REFRESH_PHASE_TWO;
-		else
-			net_key.phase = KEY_REFRESH_PHASE_NONE;
-
 		/* Initialize directory for storing keyring info */
 		init_storage_dir(node);
 
-		if (!keyring_put_remote_dev_key(node, import->unicast,
-						num_ele, import-
 > dev_key))
-			goto fail;
-
-		if (!keyring_put_net_key(node, import->net_idx,

&net_key))

mesh/node.c +0 -2
-			goto fail;
-
 	} else {
 		/* Callback for create node request */
 		struct keyring_net_key net_key;
#7 lore raw

Re: [PATCH BlueZ v3 3/3] mesh: Fix Key Ring permissions for local nodes

Hi Brian,

Quoted 35 lines · Brian
Quoted 9 lines · Inga

Hi Brian,

Quoted 3 lines · Brian Gix

We do *not* automatically create populated key rings for imported or
joined nodes,

Why not for Import()? Since both the DevKey and NetKey are in the possesion of the node...

There are two (known) use cases for Import()

1. Node previously existed on a different physical piece of hardware, and is being migrated to this daemon.

2. Node was newly provisioned Out-Of-Band, and this is the net result of the provisioning.

In *neither* case is it a given that the Node should be able to provision another node (the effect of adding
the Net Key to the key ring). In neither case is it a given that the Node should be able to modify it's own
Config Server states (the effect of adding it's Device Key to the key ring).

However, if it *is* the case that one or more of these operations should be available to the Node, the
Application that performed the Import may call the ImportSubnet() and/or the ImportRemoteNode() methods. In
actuality, if this was the intent (particularily on a Node being migrated) a key-ring of some sort should have
existed on the other physical piece of hardware.

Quoted 11 lines

The point of this larger patch-set is to no longer assume that every Node has the ability to use it's own
network keys to provision other nodes, or use it's own Device Key to change it's own Config Server states.

Yes, that can still happen (as it can with non BlueZ nodes) but it should be by a deliberate mechanism, not as
a "time saving default".

Sounds good. Could you please add this description to the commit message?

Quoted 75 lines
Quoted 75 lines
Quoted 75 lines

but we also do not *forbid* any node from adding a key in it's possesion to the local key ring.

---
 mesh/manager.c |  5 -----
 mesh/node.c    | 15 ---------------
 2 files changed, 20 deletions(-)
mesh/manager.c +0 -1
index 501ec10fe..633597659 100644
@@ -282,7 +282,6 @@ static struct l_dbus_message
 *import_node_call(struct l_dbus *dbus,
 void *user_data)
 {
 struct mesh_node *node = user_data;
-struct mesh_net *net = node_get_net(node);
 struct l_dbus_message_iter iter_key;
 uint16_t primary;

uint8_t num_ele;

mesh/manager.c +0 -4
@@ -298,10 +297,6 @@ static struct l_dbus_message
 *import_node_call(struct l_dbus *dbus,
 return dbus_error(msg, MESH_ERROR_INVALID_ARGS,
 "Bad device
 key");
 
-if (mesh_net_is_local_address(net, primary, num_ele))
-return dbus_error(msg, MESH_ERROR_INVALID_ARGS,
-"Cannot overwrite local device
 key");
-

if (!keyring_put_remote_dev_key(node, primary, num_ele, key)) return dbus_error(msg, MESH_ERROR_FAILED, NULL);

mesh/node.c +0 -1
index 833377e99..af45a6130 100644
@@ -1681,7 +1681,6 @@ static void get_managed_objects_cb(struct
 l_dbus_message *msg, void *user_data)
 
 } else if (req->type == REQUEST_TYPE_IMPORT) {
 struct node_import *import = req->import;
-struct keyring_net_key net_key;
 
 if (!create_node_config(node, node->uuid))

goto fail;

mesh/node.c +0 -12
@@ -1692,23 +1691,9 @@ static void get_managed_objects_cb(struct
 l_dbus_message *msg, void *user_data)
 import->net_idx, import-
 > net_key))
 goto fail;
 
-memcpy(net_key.old_key, import->net_key, 16);
-net_key.net_idx = import->net_idx;
-if (import->flags.kr)
-net_key.phase = KEY_REFRESH_PHASE_TWO;
-else
-net_key.phase = KEY_REFRESH_PHASE_NONE;
-
 /* Initialize directory for storing keyring info */
 init_storage_dir(node);
 
-if (!keyring_put_remote_dev_key(node, import->unicast,
-num_ele, import-
 > dev_key))
-goto fail;
-
-if (!keyring_put_net_key(node, import->net_idx,

&net_key))

mesh/node.c +0 -2
-goto fail;
-
 } else {
 /* Callback for create node request */
 struct keyring_net_key net_key;
#8 lore raw
In reply to Brian Gix

Hi Brian,

Quoted 23 lines · Brian Gix

V3: By popular demand, the name "remote" is now used for both DevKeySend()
and DevKeyMessageReceived().

In DevKeySend(), setting remote == true means that the Key Ring *must* be
used to encrypt the outgoing message, and a failure will be returned if
the requested destination address does not include a device key in the
local key ring. For remote == false requests, the request will be rejected
if the destination is an element on the local node.

In DevKeyMessageReceived(), the remote boolean will be set == true if it
required the key ring to decrypot the message. If remote == false, this
means that the local nodes Device Key successfully decrypted the message,
and the message may be used to change or query privileged states.

Quoted 4 lines

Brian Gix (3):
mesh: Add local/remote bools to DevKey transactions
mesh: Use explicit Local vs Remote Device key usage

The two patches above are fine IMO (see some comments for #2, but these can be addressed in a separate patch)

Quoted 1 line

mesh: Fix Key Ring permissions for local nodes

This patch may require some explanation?

Quoted 7 lines
 doc/mesh-api.txt | 17 ++++++++++++++---
 mesh/manager.c   |  5 -----
 mesh/model.c     | 11 +++++++----
 mesh/node.c      | 40 +++++++++++++++-------------------------
 4 files changed, 36 insertions(+), 37 deletions(-)
author
#9 lore raw
In reply to Brian Gix

Applied patch set with commit message changes

Quoted 26 lines · Brian Gix

V3: By popular demand, the name "remote" is now used for both DevKeySend() and DevKeyMessageReceived().

In DevKeySend(), setting remote == true means that the Key Ring *must* be used to encrypt the outgoing message, and a failure will be returned if the requested destination address does not include a device key in the local key ring. For remote == false requests, the request will be rejected if the destination is an element on the local node.

In DevKeyMessageReceived(), the remote boolean will be set == true if it required the key ring to decrypot the message. If remote == false, this means that the local nodes Device Key successfully decrypted the message, and the message may be used to change or query privileged states.

Brian Gix (3):
mesh: Add local/remote bools to DevKey transactions
mesh: Use explicit Local vs Remote Device key usage
mesh: Fix Key Ring permissions for local nodes

 doc/mesh-api.txt | 17 ++++++++++++++---
 mesh/manager.c   |  5 -----
 mesh/model.c     | 11 +++++++----
 mesh/node.c      | 40 +++++++++++++++-------------------------
 4 files changed, 36 insertions(+), 37 deletions(-)