Skip to contentSkip to conversation

mesh: Add key storage

PATCH In review Brian Gix 2 participants 2 messages May 7, 2019 – May 8, 2019

Subsystems (2)
lore
Share & tools
lore

Brian Gix

author
#0 lore raw

PATCH v4 1/1 mesh: Add key storage

This implements internal key storage add/delete/fetch for the three basic key types managed in Mesh: Network, Application and Device.

This key storage is separate from keys assigned to nodes within the mesh, and are used to support Configuration Client functionality.

---
 Makefile.mesh  |   1 +
 mesh/README    |  35 ++++++-
 mesh/keyring.c | 315 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 mesh/keyring.h |  49 +++++++++
 mesh/node.c    |  17 +++-
 mesh/node.h    |   2 +
 mesh/storage.c |  95 ++++++++++++-----
 mesh/storage.h |   2 +
 8 files changed, 485 insertions(+), 31 deletions(-)
 create mode 100644 mesh/keyring.c
 create mode 100644 mesh/keyring.h
Makefile.mesh +1 -0
index 61fb40936..cefb72aed 100644
@@ -25,6 +25,7 @@ mesh_sources = mesh/mesh.h mesh/mesh.c \
 				mesh/agent.h mesh/agent.c \
 				mesh/prov-acceptor.c mesh/prov-initiator.c \
 				mesh/pb-adv.h mesh/pb-adv.c \
+				mesh/keyring.h mesh/keyring.c \
 				mesh/mesh-defs.h
 libexec_PROGRAMS += mesh/bluetooth-meshd
 
mesh/README +33 -2
index 151a1e6a1..029e45068 100644
@@ -37,8 +37,39 @@ Each subdirectory contains the following files:
 		provisioner/configuration client
 	- node.json.bak:
 		a backup that the last known good node configuration.
+	- seq_num:
+		File containing next sequence number to use
+	- seq_num.bak:
+		Backup of the Sequence number. This may be larger than the
+		actual sequence number being used at runtime, to prevent re-use 		of sequence numbers in the event of an unexpected restart.
+	- ./rpl/:
+		Directory to store the sequence numbers of remote nodes, as
+		required by Replay Protection List (RPL) parameters.
+		- xxxx:
+			Files named for remote Unicast addresses, and contain
+			last received iv_index + seq_num from each SRC address.
+	- ./dev_keys/:
+		Directory to store remote Device keys. This is only created/used
+		by Configuration Client (Network administration) nodes.
+		- xxxx:
+			Files named for remote Unicast addresses, and contains
+			16 octet key.
+	- ./net_keys/:
+		Directory to store network subnet keys. This is only
+		created/used by Configuration Client (Network administration)
+		nodes.
+		- xxx:
+			Files named for subnet index, and contains key refresh
+			phase, and old/new versions of the key.
+	- ./app_keys/:
+		Directory to store application keys. This is only created/used
+		by Configuration Client (Network administration) nodes.
+		- xxx:
+			Files named for application index, and contains bound
+			subnet index, and old/new versions of the key.
 
-The files are in JSON format.
+The node.json and node.json.bak are in JSON format. All other files are stored
+in little endian binary format.
 
 Information
 ===========
@@ -47,4 +78,4 @@ Mailing lists:
 	[email protected]
 
 For additional information about the project visit BlueZ web site:
-	http://www.bluez.org
\ No newline at end of file
+	http://www.bluez.org
mesh/keyring.c new file +315 -0

315 lines not on this page · raw message

mesh/keyring.h new file +49 -0

49 lines not on this page · raw message

mesh/node.c +16 -1
index 774d03d45..dc09a11f7 100644
@@ -79,6 +79,7 @@ struct mesh_node {
 	char *path;
 	void *jconfig;
 	char *cfg_file;
+	char *node_path;
 	uint32_t disc_watch;
 	time_t upd_sec;
 	uint32_t seq_number;
@@ -235,6 +236,8 @@ static void free_node_resources(void *data)
 	l_free(node->comp);
 	l_free(node->app_path);
 	l_free(node->owner);
+	l_free(node->cfg_file);
+	l_free(node->node_path);
 
 	if (node->disc_watch)
 		l_dbus_remove_watch(dbus_get_bus(), node->disc_watch);
@@ -1875,7 +1878,8 @@ void *node_jconfig_get(struct mesh_node *node)
 
 void node_cfg_file_set(struct mesh_node *node, char *cfg)
 {
-	node->cfg_file = cfg;
+	l_free(node->cfg_file);
+	node->cfg_file = l_strdup(cfg);
 }
 
 char *node_cfg_file_get(struct mesh_node *node)
@@ -1883,6 +1887,17 @@ char *node_cfg_file_get(struct mesh_node *node)
 	return node->cfg_file;
 }
 
+void node_path_set(struct mesh_node *node, char *path)
+{
+	l_free(node->node_path);
+	node->node_path = l_strdup(path);
+}
+
+char *node_path_get(struct mesh_node *node)
+{
+	return node->node_path;
+}
+
 struct mesh_net *node_get_net(struct mesh_node *node)
 {
 	return node->net;
mesh/node.h +2 -0
index 20b60099e..d6a4cd96c 100644
@@ -97,3 +97,5 @@ void node_jconfig_set(struct mesh_node *node, void *jconfig);
 void *node_jconfig_get(struct mesh_node *node);
 void node_cfg_file_set(struct mesh_node *node, char *cfg);
 char *node_cfg_file_get(struct mesh_node *node);
+void node_path_set(struct mesh_node *node, char *path);
+char *node_path_get(struct mesh_node *node);
mesh/storage.c +67 -28

139 lines not on this page · raw message

mesh/storage.h +2 -0
index d71d11b8e..4cfeaa7f4 100644
@@ -49,3 +49,5 @@ bool storage_set_device_key(struct mesh_node *node, uint8_t dev_key[16]);
 bool storage_set_unicast(struct mesh_node *node, uint16_t unicast);
 bool storage_set_key_refresh_phase(struct mesh_net *net, uint16_t net_idx,
 								uint8_t phase);
+int storage_create_dir(const char *dirname);
+char *storage_path_get(struct mesh_node *node);
Signature · 1 line
2.14.5
#1 lore raw

Hi Brian,

Review

Quoted 2 lines · Brian Gix
(quoted diff) +2 -0
+	fd = open(key_file, O_WRONLY | O_CREAT | O_TRUNC);
+	if (fd) {

I think these should check for fd >= 0

regards

Signature · 3 lines
Michał Lowas-Rzechonek <[email protected]>
Silvair http://silvair.com
Jasnogórska 44, 31-358 Krakow, POLAND