Skip to content
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

Add randomize bdaddr implementation #28

Merged
merged 3 commits into from
Jul 8, 2020
Merged

Add randomize bdaddr implementation #28

merged 3 commits into from
Jul 8, 2020

Conversation

stefanos1316
Copy link

@stefanos1316 stefanos1316 commented Jul 5, 2020

Issue: #12

Copy link
Collaborator

@dspinellis dspinellis left a comment

Choose a reason for hiding this comment

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

Thank you! A few changes are required.

@@ -72,6 +75,11 @@ def process_packet(socket):
if packet[13:25] != BLE_PACKET:
return

# Print sender's bdaddr
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please change to Bluetooth MAC address

Copy link
Author

Choose a reason for hiding this comment

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

OK

# Print sender's bdaddr
bdaddr = packet[7:13]
bdaddr = bdaddr[::-1].hex().upper()
logger.info(f"Received packet from {':'.join(bdaddr[i:i+2] for i in range(0, len(bdaddr), 2))}")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Make this .debug; we don't want it in production.

Copy link
Author

Choose a reason for hiding this comment

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

OK

def generate_random_bdaddr():
bdaddr = secrets.token_hex(6)
bdaddr = list(bdaddr)
locally_administer_elements = ['2', '6', 'a', 'e']
Copy link
Collaborator

Choose a reason for hiding this comment

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

administered

Copy link
Author

Choose a reason for hiding this comment

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

OK

bdaddr = list(bdaddr)
locally_administer_elements = ['2', '6', 'a', 'e']

# The above values denote that the bdaddr is locally administared
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please comment before the line you comment.

Copy link
Author

Choose a reason for hiding this comment

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

OK

locally_administer_elements = ['2', '6', 'a', 'e']

# The above values denote that the bdaddr is locally administared
bdaddr[1] = secrets.choice(locally_administer_elements)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please comment each line with an example of what bdaddr will contain.

Copy link
Author

Choose a reason for hiding this comment

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

I have added an example and comments to each line of this function.

@@ -84,6 +85,17 @@ def set_transmit(interface, ephid, rssi):
run_command(cmd)


def generate_random_bdaddr():
bdaddr = secrets.token_hex(6)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Would mac_addr be more appropriate?

Copy link
Author

Choose a reason for hiding this comment

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

MAC address is used for both Ethernet and Bluetooth technologies.
I have selected bdaddr because it stands for the Bluetooth device address.
Maybe, we can also use bd_addr, but if you insist we can change it to mac_addr

Copy link
Collaborator

Choose a reason for hiding this comment

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

OK. Then add a function comment, documenting what the function does and explaining that it returns a random "Bluetooth Device (MAC) Address (bdaddr)".

@@ -151,6 +163,18 @@ def main():
transmitter.check_advance_day(now)
ephid = transmitter.get_ephid_for_time(now)
if ephid != current_ephid:
# Stop advetising before chaning bdaddr
Copy link
Collaborator

Choose a reason for hiding this comment

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

changing

Copy link
Author

Choose a reason for hiding this comment

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

OK

bdaddr = generate_random_bdaddr()

# Change local device bdaddr and reset
run_command(["sudo", "bdaddr", "-i", interface, "-r", bdaddr])
Copy link
Collaborator

Choose a reason for hiding this comment

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

No need for sudo, because we run as root.

Copy link
Author

Choose a reason for hiding this comment

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

OK

dspinellis and others added 3 commits July 6, 2020 09:31
author stefanos1316 <stefanos1316@gmail.com> 1593980395 +0100
committer stefanos1316 <stefanos1316@gmail.com> 1594024287 +0100

Add randomize Bluetooth address implementation
@dspinellis dspinellis merged commit b12bf50 into eellak:master Jul 8, 2020
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.

2 participants