tile-identity-resolver 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- tile_identity_resolver/__init__.py +6 -0
- tile_identity_resolver/models.py +50 -0
- tile_identity_resolver/py.typed +0 -0
- tile_identity_resolver/resolver.py +110 -0
- tile_identity_resolver-0.1.0.dist-info/METADATA +93 -0
- tile_identity_resolver-0.1.0.dist-info/RECORD +9 -0
- tile_identity_resolver-0.1.0.dist-info/WHEEL +5 -0
- tile_identity_resolver-0.1.0.dist-info/licenses/LICENSE +21 -0
- tile_identity_resolver-0.1.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"""Tile credentials and metadata decoded from a matching payload."""
|
|
2
|
+
|
|
3
|
+
import base64
|
|
4
|
+
from dataclasses import dataclass, field
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def _to_bytes(value: str | bytes) -> bytes:
|
|
8
|
+
"""Accept raw bytes or decode hexadecimal or padded Base64 text."""
|
|
9
|
+
if isinstance(value, bytes):
|
|
10
|
+
return value
|
|
11
|
+
if not isinstance(value, str):
|
|
12
|
+
raise ValueError("Expected raw bytes, hexadecimal, or Base64 text")
|
|
13
|
+
value = value.strip()
|
|
14
|
+
if value.endswith("="):
|
|
15
|
+
return base64.b64decode(value, validate=True)
|
|
16
|
+
return bytes.fromhex(value)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
@dataclass(frozen=True, slots=True)
|
|
20
|
+
class Tile:
|
|
21
|
+
"""Immutable Tile credentials stored as text.
|
|
22
|
+
|
|
23
|
+
The ID is lowercase hex; the key is hex or padded Base64.
|
|
24
|
+
"""
|
|
25
|
+
|
|
26
|
+
tile_id: str
|
|
27
|
+
auth_key: str = field(repr=False)
|
|
28
|
+
|
|
29
|
+
def __post_init__(self) -> None:
|
|
30
|
+
tile_id = _to_bytes(self.tile_id)
|
|
31
|
+
if len(tile_id) != 8 or tile_id.hex() != self.tile_id:
|
|
32
|
+
raise ValueError("Tile ID must be 16 lowercase hexadecimal digits")
|
|
33
|
+
if (
|
|
34
|
+
not isinstance(self.auth_key, str)
|
|
35
|
+
or len(_to_bytes(self.auth_key)) != 16
|
|
36
|
+
):
|
|
37
|
+
raise ValueError("Auth key must decode to sixteen bytes")
|
|
38
|
+
|
|
39
|
+
@dataclass(frozen=True, slots=True)
|
|
40
|
+
class TileInfo:
|
|
41
|
+
"""A registered Tile and metadata from one matching FEED payload.
|
|
42
|
+
|
|
43
|
+
A match does not establish freshness, proximity, or availability.
|
|
44
|
+
Flags are exposed verbatim; their meaning is not interpreted here.
|
|
45
|
+
"""
|
|
46
|
+
|
|
47
|
+
tile: Tile
|
|
48
|
+
counter: int
|
|
49
|
+
version: int
|
|
50
|
+
flags: int
|
|
File without changes
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
"""Register Tile identities and resolve version-2 FEED payloads."""
|
|
2
|
+
|
|
3
|
+
import hashlib
|
|
4
|
+
import hmac
|
|
5
|
+
from collections.abc import Iterable
|
|
6
|
+
|
|
7
|
+
from .models import Tile, TileInfo, _to_bytes
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def _generate_private_ids(tile: Tile) -> dict[bytes, int]:
|
|
11
|
+
tile_id = bytes.fromhex(tile.tile_id)
|
|
12
|
+
auth_key = _to_bytes(tile.auth_key)
|
|
13
|
+
identity_message = tile_id + b"identity" + bytes(16)
|
|
14
|
+
identity_key = hmac.digest(auth_key, identity_message, hashlib.sha256)[:16]
|
|
15
|
+
|
|
16
|
+
private_ids = {}
|
|
17
|
+
for counter in range(8640):
|
|
18
|
+
counter_message = counter.to_bytes(4, "little") + bytes(28)
|
|
19
|
+
private_id = hmac.digest(
|
|
20
|
+
identity_key, counter_message, hashlib.sha256
|
|
21
|
+
)[:8]
|
|
22
|
+
private_ids[private_id] = counter
|
|
23
|
+
return private_ids
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class TileResolver:
|
|
27
|
+
"""Resolve payloads against any number of registered Tiles.
|
|
28
|
+
|
|
29
|
+
Each resolver prepares and owns candidates for its registered Tiles.
|
|
30
|
+
Calls are synchronous; callers must serialize concurrent mutations.
|
|
31
|
+
"""
|
|
32
|
+
|
|
33
|
+
def __init__(self, tiles: Iterable[Tile] = ()) -> None:
|
|
34
|
+
self._tiles: dict[str, Tile] = {}
|
|
35
|
+
self._private_ids: dict[str, list[bytes]] = {}
|
|
36
|
+
self._index: dict[
|
|
37
|
+
bytes, tuple[Tile, int] | dict[str, tuple[Tile, int]]
|
|
38
|
+
] = {}
|
|
39
|
+
for tile in tiles:
|
|
40
|
+
self.add(tile)
|
|
41
|
+
|
|
42
|
+
@property
|
|
43
|
+
def tiles(self) -> tuple[Tile, ...]:
|
|
44
|
+
"""Return a snapshot of Tiles in registration order."""
|
|
45
|
+
return tuple(self._tiles.values())
|
|
46
|
+
|
|
47
|
+
def add(self, tile: Tile) -> None:
|
|
48
|
+
"""Register a Tile and prepare its candidate IDs.
|
|
49
|
+
|
|
50
|
+
Duplicate stable IDs raise ValueError. To change a key, remove
|
|
51
|
+
the existing Tile and add its replacement.
|
|
52
|
+
"""
|
|
53
|
+
if not isinstance(tile, Tile):
|
|
54
|
+
raise TypeError("Expected a Tile")
|
|
55
|
+
if tile.tile_id in self._tiles:
|
|
56
|
+
raise ValueError("Tile ID is already registered")
|
|
57
|
+
private_ids = _generate_private_ids(tile)
|
|
58
|
+
self._tiles[tile.tile_id] = tile
|
|
59
|
+
self._private_ids[tile.tile_id] = list(private_ids)
|
|
60
|
+
for private_id, counter in private_ids.items():
|
|
61
|
+
match = (tile, counter)
|
|
62
|
+
owners = self._index.get(private_id)
|
|
63
|
+
if owners is None:
|
|
64
|
+
self._index[private_id] = match
|
|
65
|
+
elif isinstance(owners, tuple):
|
|
66
|
+
# Allocate an owners dictionary only for collisions.
|
|
67
|
+
self._index[private_id] = {
|
|
68
|
+
owners[0].tile_id: owners,
|
|
69
|
+
tile.tile_id: match,
|
|
70
|
+
}
|
|
71
|
+
else:
|
|
72
|
+
owners[tile.tile_id] = match
|
|
73
|
+
|
|
74
|
+
def remove(self, tile_id: str) -> None:
|
|
75
|
+
"""Remove a Tile by hex ID; raise KeyError if it is unknown."""
|
|
76
|
+
del self._tiles[tile_id]
|
|
77
|
+
private_ids = self._private_ids.pop(tile_id)
|
|
78
|
+
for private_id in private_ids:
|
|
79
|
+
owners = self._index[private_id]
|
|
80
|
+
if isinstance(owners, tuple):
|
|
81
|
+
del self._index[private_id]
|
|
82
|
+
else:
|
|
83
|
+
del owners[tile_id]
|
|
84
|
+
if len(owners) == 1:
|
|
85
|
+
self._index[private_id] = next(iter(owners.values()))
|
|
86
|
+
|
|
87
|
+
def resolve(
|
|
88
|
+
self, payload: bytes | bytearray | memoryview
|
|
89
|
+
) -> TileInfo | None:
|
|
90
|
+
"""Resolve FEED data without UUID or advertising headers.
|
|
91
|
+
|
|
92
|
+
Return None for short, unsupported, unknown, or ambiguous data.
|
|
93
|
+
Allow trailing bytes. Other input types raise TypeError.
|
|
94
|
+
No state is updated by resolving a payload.
|
|
95
|
+
"""
|
|
96
|
+
if not isinstance(payload, (bytes, bytearray, memoryview)):
|
|
97
|
+
raise TypeError("Payload must be bytes, bytearray, or memoryview")
|
|
98
|
+
payload = bytes(payload)
|
|
99
|
+
if len(payload) < 10 or payload[0] != 2:
|
|
100
|
+
return None
|
|
101
|
+
match = self._index.get(payload[2:10])
|
|
102
|
+
if not isinstance(match, tuple):
|
|
103
|
+
return None
|
|
104
|
+
tile, counter = match
|
|
105
|
+
return TileInfo(
|
|
106
|
+
tile=tile,
|
|
107
|
+
counter=counter,
|
|
108
|
+
version=payload[0],
|
|
109
|
+
flags=payload[1],
|
|
110
|
+
)
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: tile-identity-resolver
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Resolve Tile identities from FEED service data without Bluetooth dependencies
|
|
5
|
+
License-Expression: MIT
|
|
6
|
+
Project-URL: Homepage, https://github.com/kbck/tile-identity-resolver
|
|
7
|
+
Project-URL: Repository, https://github.com/kbck/tile-identity-resolver
|
|
8
|
+
Project-URL: Issues, https://github.com/kbck/tile-identity-resolver/issues
|
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
|
10
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
11
|
+
Classifier: Operating System :: OS Independent
|
|
12
|
+
Classifier: Typing :: Typed
|
|
13
|
+
Requires-Python: >=3.10
|
|
14
|
+
Description-Content-Type: text/markdown
|
|
15
|
+
License-File: LICENSE
|
|
16
|
+
Provides-Extra: test
|
|
17
|
+
Requires-Dist: pytest<9,>=8; extra == "test"
|
|
18
|
+
Provides-Extra: dev
|
|
19
|
+
Requires-Dist: pytest<9,>=8; extra == "dev"
|
|
20
|
+
Requires-Dist: ruff<1,>=0.11; extra == "dev"
|
|
21
|
+
Requires-Dist: build<2,>=1; extra == "dev"
|
|
22
|
+
Requires-Dist: mypy<3,>=1.15; extra == "dev"
|
|
23
|
+
Requires-Dist: twine<7,>=6; extra == "dev"
|
|
24
|
+
Requires-Dist: check-wheel-contents<1,>=0.6; extra == "dev"
|
|
25
|
+
Dynamic: license-file
|
|
26
|
+
|
|
27
|
+
# Tile Identity Resolver
|
|
28
|
+
|
|
29
|
+
A dependency-free Python library for identifying registered Tile trackers from
|
|
30
|
+
version-2 FEED service data. Requires Python 3.10 or newer.
|
|
31
|
+
|
|
32
|
+
## Install
|
|
33
|
+
|
|
34
|
+
```sh
|
|
35
|
+
python -m pip install tile-identity-resolver
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## Usage
|
|
39
|
+
|
|
40
|
+
```python
|
|
41
|
+
from tile_identity_resolver import Tile, TileResolver
|
|
42
|
+
|
|
43
|
+
# Replace these example credentials with your Tile's ID and auth key.
|
|
44
|
+
tile = Tile(
|
|
45
|
+
tile_id="0011223344556677",
|
|
46
|
+
auth_key="AAECAwQFBgcICQoLDA0ODw==",
|
|
47
|
+
)
|
|
48
|
+
resolver = TileResolver([tile])
|
|
49
|
+
|
|
50
|
+
# Pass the raw service-data value for UUID 0000feed-0000-1000-8000-00805f9b34fb.
|
|
51
|
+
def handle_feed_payload(payload: bytes) -> None:
|
|
52
|
+
info = resolver.resolve(payload)
|
|
53
|
+
if info is not None:
|
|
54
|
+
print(info.tile.tile_id, info.counter, info.version, info.flags)
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
Tile IDs are eight-byte lowercase hex strings. Auth keys are sixteen-byte hex
|
|
58
|
+
or padded Base64 strings. Invalid credentials raise `ValueError`.
|
|
59
|
+
|
|
60
|
+
## API
|
|
61
|
+
|
|
62
|
+
| API | Behavior |
|
|
63
|
+
| --- | --- |
|
|
64
|
+
| `TileResolver(tiles=())` | Register one or more Tiles |
|
|
65
|
+
| `resolver.add(tile)` | Register a Tile; duplicate IDs raise `ValueError` |
|
|
66
|
+
| `resolver.remove(tile_id)` | Remove a Tile; missing IDs raise `KeyError` |
|
|
67
|
+
| `resolver.tiles` | Immutable snapshot of registered Tiles |
|
|
68
|
+
| `resolver.resolve(payload)` | Return `TileInfo` for an unambiguous match, otherwise `None` |
|
|
69
|
+
|
|
70
|
+
`TileInfo` contains the registered `tile`, `counter`, `version`, and `flags`.
|
|
71
|
+
Remove and re-add a Tile to replace its key.
|
|
72
|
+
|
|
73
|
+
Registration precomputes private IDs and uses memory per Tile. In async apps,
|
|
74
|
+
prepare the resolver in a worker thread and serialize access during mutations.
|
|
75
|
+
The library resolves identities only; it does not track Bluetooth addresses or
|
|
76
|
+
presence, and a match does not prove freshness or proximity.
|
|
77
|
+
|
|
78
|
+
## Development
|
|
79
|
+
|
|
80
|
+
```sh
|
|
81
|
+
python -m pip install -e '.[dev]'
|
|
82
|
+
python tools/check_package.py
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
Runs tests, code checks, and package validation.
|
|
86
|
+
|
|
87
|
+
## Acknowledgements
|
|
88
|
+
|
|
89
|
+
Based on [Security and Privacy Analysis of Tile's Location Tracking Protocol](https://www.usenix.org/conference/usenixsecurity26/presentation/kumar-akshaya)
|
|
90
|
+
by Akshaya Kumar, Anna Raymaker, and Michael A. Specter (USENIX Security 2026).
|
|
91
|
+
|
|
92
|
+
Unofficial; not affiliated with Tile or Life360.
|
|
93
|
+
Licensed under the [MIT License](LICENSE).
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
tile_identity_resolver/__init__.py,sha256=WCc0o5rQyWu746HhfnHk9w5-1fLC5ol-9TnDi8OiUGk,184
|
|
2
|
+
tile_identity_resolver/models.py,sha256=ivtGhI_iwTDDBYGdNzqBdOYbhvMS91LwnoAtbv1sAyI,1528
|
|
3
|
+
tile_identity_resolver/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
4
|
+
tile_identity_resolver/resolver.py,sha256=wX7FHIILKL1H7ONhttxH0De4OCR-DmPsGlkRlEvEebs,4042
|
|
5
|
+
tile_identity_resolver-0.1.0.dist-info/licenses/LICENSE,sha256=eFEuVhg0HsgE6Oyp3GhhpjOmPbqOm0h0MGqjKyQvXLM,1061
|
|
6
|
+
tile_identity_resolver-0.1.0.dist-info/METADATA,sha256=Puee845Ff_-gsP0ZlQoOjzrTC1JCI_aGgIU_cBzLOpc,3288
|
|
7
|
+
tile_identity_resolver-0.1.0.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
|
|
8
|
+
tile_identity_resolver-0.1.0.dist-info/top_level.txt,sha256=ajc8dYW6gQXUkNeAyXz5mPv6Syk9hZOy0FdA7jAAXP0,23
|
|
9
|
+
tile_identity_resolver-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 kbck
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
tile_identity_resolver
|