Skip to content

Privacy #151

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 34 commits into from
Jun 4, 2018
Merged

Privacy #151

merged 34 commits into from
Jun 4, 2018

Conversation

paul-szczepanek-arm
Copy link
Member

No description provided.

@@ -0,0 +1 @@
https://github.com/ARMmbed/mbed-os/#f9ee4e849f8cbd64f1ec5fdd4ad256585a208360
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's mbed OS 5.8.2 (does that work?), please make it point to mbed OS 5.9 RC1 :) (6817dc43f9f5216cbe077059fc561fa89a766dc9 )

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, thank you

printf("Whitelist failed to generate.\r\n");
}

/* this callback transfer memory ownership to us so we have to dispose of it */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually we have ownership of it during the whole process.

Copy link
Member Author

@paul-szczepanek-arm paul-szczepanek-arm May 29, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we hand it over with generateWhitelistFromBondTable(whitelist) after which we are not allowed to delete it before the callback happens and we do not store a pointer to it so effectively we are handing it over

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should look into using shared_ptr-type abstractions (which exist in mbed OS) when it makes sense - but that's a separate topic. Looking at the doc for generateWhitelistFromBondTable(), it's not very clear what the object lifetime should be.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will now seemingly backtrack on what I said: lifetime is decided by the user, the whitelist could be statically allocated, in my example I relinquish control but the doc doesn't require that: the only requirement is that you do not access the whitelist when callback is pending.

}
};

/** advertise and filer based on known devices */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

filer --> filter

printf("Whitelist failed to generate.\r\n");
}

/* this callback transfer memory ownership to us so we have to dispose of it */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should look into using shared_ptr-type abstractions (which exist in mbed OS) when it makes sense - but that's a separate topic. Looking at the doc for generateWhitelistFromBondTable(), it's not very clear what the object lifetime should be.

* byte 1: The key, it is the type of the data
* byte [2..N] The value. N is equal to byte0 - 1 */

const uint8_t record_length = params->advertisingData[i];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need a length check: Fail if i + 2 + record_length >= params->advertisingDataLen otherwise we're vulnerable to buffer overflow attacks.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

...in which case I should also not trust that the string is well formatted.

What we really need is the on_scan callback to return a typed list of items and not having the user look at bytes.

Copy link
Contributor

@donatieng donatieng Jun 3, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's different: Badly formatted buffer: we get garbage that we can ignore; String with length flag set to an invalid value (which is a specific case of the former): undefined behaviour.

Agreed that in the long run which should do that parsing ourselves.

}
{
printf("\r\n * Device is a central *\r\n\r\n");
PrivacyCentral peripheral(ble, queue);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be called central 😄

@paul-szczepanek-arm
Copy link
Member Author

addressed your comments

Copy link
Member

@pan- pan- left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good example, it works quite well with all the fixes.
I wouldn't use the white list at all as it is a feature orthogonal to privacy.

"target.features_add": ["BLE"],
"target.extra_labels_add": ["ST_BLUENRG"]
},
"NUCLEO_F401RE": {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The cordio driver is not public.
I would remove st support as st own implementation doesn't implement the security manager.

@@ -0,0 +1,15 @@
{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be removed as we don't care of yotta anymore.

@@ -0,0 +1 @@
https://github.com/ARMmbed/cordio-ble-x-nucleo-idb0xa1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This repository is not public; This file can be removed for now; please see my comment above.

_bonded = true;

/* provide memory for the generated whitelist */
Gap::Whitelist_t* whitelist = new Gap::Whitelist_t;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe the white list can go into a member variable that would makes the whole code a bit more readable.


/* for use by tools we print out own address and also use it
* to seed RNG as the address is unique */
print_local_address();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Printing the local address is useless as privacy is enabled few lines below.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we use it in our tools and I use it as seed and it shows the identity address which we will later see on the other side

Copy link
Member

@pan- pan- Jun 1, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We use it in our tools to identify the device advertising unfortunately this won't work this time as the address is private. I would suggest to add a random vendor specific field in the advertising payload and print it so we can identify the device advertising.

Note: this is not a blocker for this to get in but it will be once we add tests for this example.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is harmless and it does show the identity address before the privacy is enabled so you can see that you're connecting to the right device - connections is based on name

}
};

/* TODO: remove this, pairing should be done by the strategy automatically */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove this as it should be done by the strategy.

virtual ~PrivacyDevice()
{
if (_ble.hasInitialized()) {
_ble.shutdown();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldn't initialize and shutdown the ble instance as the process is still instable on Cordio as there is not enough stack support.
Initialization the stack once and leave it active would be better.

ble_error_t error;

/* to show we're running we'll blink every 500ms */
_event_queue.call_every(500, this, &PrivacyDevice::blink);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This event must be removed at destruction.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

queue now is recreated

GapAdvertisingData advertising_data;

/* add advertising flags */
advertising_data.addFlags(GapAdvertisingData::LE_GENERAL_DISCOVERABLE
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you intend to use the whitelist then remove the discoverable flag.


if (record_length < 2) {
/* malformed record */
} else if ((type == GapAdvertisingData::FLAGS)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This bit must be removed if the flag is not set in advertising data.

@paul-szczepanek-arm
Copy link
Member Author

paul-szczepanek-arm commented May 31, 2018

This still requires fixing gap so that restarting scanning works
worked around the problem by not using the set timeout call, it's good to go now

Copy link
Member

@pan- pan- left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is still an issue with the event queue and ble signaling. As it is now it may operates with dead objects as the function onEventsToProcess is not replaced in the PrivacyDevice destructor.

@paul-szczepanek-arm
Copy link
Member Author

thanks, fixed

Copy link
Member

@pan- pan- left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the change to the signaling strategy but it is not enough as ble may continue to report events after a PrivacyDevice destruction.

@paul-szczepanek-arm
Copy link
Member Author

thank you

Copy link
Member

@pan- pan- left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM; what do you think @donatieng ?

* byte 1: The key, it is the type of the data
* byte [2..N] The value. N is equal to byte0 - 1 */

const uint8_t record_length = params->advertisingData[i];
Copy link
Contributor

@donatieng donatieng Jun 3, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's different: Badly formatted buffer: we get garbage that we can ignore; String with length flag set to an invalid value (which is a specific case of the former): undefined behaviour.

Agreed that in the long run which should do that parsing ourselves.

@paul-szczepanek-arm paul-szczepanek-arm merged commit 9985858 into ARMmbed:master Jun 4, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants