blob: 07d89a31bc9a8fda99d788a960232a55d9fbeae4 [file] [log] [blame]
Hui Pengd885d452023-12-14 22:21:13 -08001# Copyright 2023 Google LLC
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# https://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15import click
16from bumble.colors import color
17from bumble.hci import Address
18from bumble.helpers import generate_irk, verify_rpa_with_irk
19
20
21@click.group()
22def cli():
23 '''
24 This is a tool for generating IRK, RPA,
25 and verifying IRK/RPA pairs
26 '''
27
28
29@click.command()
30def gen_irk() -> None:
31 print(generate_irk().hex())
32
33
34@click.command()
35@click.argument("irk", type=str)
36def gen_rpa(irk: str) -> None:
37 irk_bytes = bytes.fromhex(irk)
38 rpa = Address.generate_private_address(irk_bytes)
39 print(rpa.to_string(with_type_qualifier=False))
40
41
42@click.command()
43@click.argument("irk", type=str)
44@click.argument("rpa", type=str)
45def verify_rpa(irk: str, rpa: str) -> None:
46 address = Address(rpa)
47 irk_bytes = bytes.fromhex(irk)
48 if verify_rpa_with_irk(address, irk_bytes):
49 print(color("Verified", "green"))
50 else:
51 print(color("Not Verified", "red"))
52
53
54def main():
55 cli.add_command(gen_irk)
56 cli.add_command(gen_rpa)
57 cli.add_command(verify_rpa)
58 cli()
59
60
61# -----------------------------------------------------------------------------
62if __name__ == '__main__':
63 main()