Re: [PATCH BlueZ] mesh: Add remote dev key support and cleanup

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Brian,

On 04/24, Gix, Brian wrote:
> > From: Michał Lowas-Rzechonek [mailto:michal.lowas-rzechonek@xxxxxxxxxxx]
> > > +try_remote:
> > > +	/* Try remote device key if available */
> > > +	dev_key = node_get_remote_device_key(node, src);
> > > +	if (!dev_key)
> > > +		return -1;
> > > +
> > > +	if (mesh_crypto_payload_decrypt(NULL, 0, data, size, szmict, src,
> > > +					dst, key_id, seq, iv_idx, out,
> > dev_key))
> > > +		return APP_IDX_DEV_RMT;
> > > +
> > What's the purpose of APP_IDX_DEV_RMT?
> 
> App Index is an internal way to track which credentials were used to
> decrypt a message.  In theory, if the incoming message used the local
> device key, then the message is addressed to one of the local servers,
> and if the incoming message was decrypted by a *remote* device key it
> should be addressed to a local Client (as a response from a remote
> server).
>
> To enable that, we need to differentiate between the two possible
> device keys.
>
> However, also importantly, if a message that requires a response is
> received on *any* key (local dev, remote dev, or App Key) the response
> is supposed to be sent with the same key.
Right, but I think this is covered by the server/client model behaviour,
so I don't think we need to care if the message was encrypted using a
known remote device key, or our local device key.

This is indeed not explicitly mentioned in the spec, but I think the
consensus is that a server model shall always send responses using a
local device key.

I think this means that the API needs to allow using either local or
remote device key when *sending* a message (i.e. use remote key for
requests and local key for responses), but API for receiving messages
needs only to differentiate between device and application keys.

> When *sending* Dev Key message
> from the Application, we will try the remote nodes device key first,
> and if it does not exist we fall back to the local key.
I'm not sure the key selection should happen automaticall. I'd rather
have an explicit option to use local device key or remote one.

> In any case, these "Magic Numbers" are internal use only, and do not
> show up on the external interface.
Well, at the moment they are visible in Send() call: key_index argument
accepts 0x7fff as a way to indicate that local device key should be
used.

I guess you're refering to the updated doc/mesh-api.txt, so the plain Send()
method will accept only *real* app key indexes?

> > >  #define DEFAULT_CRPL 10
> > > +#define REMOTE_CACHE_LEN 5
> > By the way: why the limits here are set so low (and there doesn't seem to be
> > a way to change them...)?
> When being used as a Config Client, we are just trying to avoid
> reopening the file to fetch the device key to decode the expected
> response.
> (...)
> All the device keys are always available...  they
> just may need to be read into RAM from storage.
Ok, got it.

I was more concerned about the CRPL size. At the moment the limit means
that a node cannot simultaneously talk to more than 10 remote nodes
because of this (mesh/appkey.c:227):

	/* Replay Cache is fixed sized */
	if (l_queue_length(key->replay_cache) >= crpl) {
		int ret = l_queue_foreach_remove(key->replay_cache,
				clean_old_iv_index, L_UINT_TO_PTR(iv_index));

		if (!ret)
			return true;
	}

> > I don't see why the remote key storage should be kept separately (and in
> > binary files?) from the main node json. It makes the implementation much
> > more complicated, as you need to worry about directories etc.
> Again, this creates an open-ended RAM requirement that depends on the
> existence of external resources...
Not necessarily.

I understand that in the current implementation, the storage JSON is
kept in memory as a whole (mesh_node.jconfig), so adding stuff there
indeed increases the memory footprint of a node, but it doesn't need to
be like that.

What are your thoughts on replacing the JSON storage with something
more granular? The main bluetoothd seems to use a directory structure
and INI files, but a key-value store like gdbm might also be an option,
especially for frequently changing values like the sequence number.
A database would allow us to avoid explicit caching and rely on mmap().

regards
-- 
Michał Lowas-Rzechonek <michal.lowas-rzechonek@xxxxxxxxxxx>
Silvair http://silvair.com
Jasnogórska 44, 31-358 Krakow, POLAND



[Index of Archives]     [Bluez Devel]     [Linux Wireless Networking]     [Linux Wireless Personal Area Networking]     [Linux ATH6KL]     [Linux USB Devel]     [Linux Media Drivers]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Big List of Linux Books]

  Powered by Linux