|
| 1 | +# -*- mode: python3; indent-tabs-mode: nil; tab-width: 4 -*- |
| 2 | +# exposure_notification.py - Apple/Google Exposure Notification System |
| 3 | +# |
| 4 | +# This file is part of Scapy |
| 5 | +# See http://www.secdev.org/projects/scapy for more information |
| 6 | +# Copyright (C) 2020 Michael Farrell <[email protected]> |
| 7 | +# This program is published under a GPLv2 (or later) license |
| 8 | +# |
| 9 | +# scapy.contrib.description = Apple/Google Exposure Notification System (ENS) |
| 10 | +# scapy.contrib.status = loads |
| 11 | +""" |
| 12 | +Apple/Google Exposure Notification System (ENS), formerly known as |
| 13 | +Privacy-Preserving Contact Tracing Project. |
| 14 | +
|
| 15 | +This module parses the Bluetooth Low Energy beacon payloads used by the system. |
| 16 | +This does **not** yet implement any cryptographic functionality. |
| 17 | +
|
| 18 | +More info: |
| 19 | +
|
| 20 | +* `Apple: Privacy-Preserving Contact Tracing`__ |
| 21 | +* `Google: Exposure Notifications`__ |
| 22 | +* `Wikipedia: Exposure Notification`__ |
| 23 | +
|
| 24 | +__ https://www.apple.com/covid19/contacttracing/ |
| 25 | +__ https://www.google.com/covid19/exposurenotifications/ |
| 26 | +__ https://en.wikipedia.org/wiki/Exposure_Notification |
| 27 | +
|
| 28 | +Bluetooth protocol specifications: |
| 29 | +
|
| 30 | +* `v1.1`_ (April 2020) |
| 31 | +* `v1.2`_ (April 2020) |
| 32 | +
|
| 33 | +.. _v1.1: https://blog.google/documents/58/Contact_Tracing_-_Bluetooth_Specification_v1.1_RYGZbKW.pdf |
| 34 | +.. _v1.2: https://covid19-static.cdn-apple.com/applications/covid19/current/static/contact-tracing/pdf/ExposureNotification-BluetoothSpecificationv1.2.pdf |
| 35 | +""" # noqa: E501 |
| 36 | + |
| 37 | +from scapy.fields import StrFixedLenField |
| 38 | +from scapy.layers.bluetooth import EIR_Hdr, EIR_ServiceData16BitUUID, \ |
| 39 | + EIR_CompleteList16BitServiceUUIDs, LowEnergyBeaconHelper |
| 40 | +from scapy.packet import bind_layers, Packet |
| 41 | + |
| 42 | + |
| 43 | +EXPOSURE_NOTIFICATION_UUID = 0xFD6F |
| 44 | + |
| 45 | + |
| 46 | +class Exposure_Notification_Frame(Packet, LowEnergyBeaconHelper): |
| 47 | + """Apple/Google BLE Exposure Notification broadcast frame.""" |
| 48 | + name = "Exposure Notification broadcast" |
| 49 | + |
| 50 | + fields_desc = [ |
| 51 | + # Rolling Proximity Identifier |
| 52 | + StrFixedLenField("identifier", None, 16), |
| 53 | + # Associated Encrypted Metadata (added in v1.2) |
| 54 | + StrFixedLenField("metadata", None, 4), |
| 55 | + ] |
| 56 | + |
| 57 | + def build_eir(self): |
| 58 | + """Builds a list of EIR messages to wrap this frame.""" |
| 59 | + |
| 60 | + return LowEnergyBeaconHelper.base_eir + [ |
| 61 | + EIR_Hdr() / EIR_CompleteList16BitServiceUUIDs(svc_uuids=[ |
| 62 | + EXPOSURE_NOTIFICATION_UUID]), |
| 63 | + EIR_Hdr() / EIR_ServiceData16BitUUID() / self |
| 64 | + ] |
| 65 | + |
| 66 | + |
| 67 | +bind_layers(EIR_ServiceData16BitUUID, Exposure_Notification_Frame, |
| 68 | + svc_uuid=EXPOSURE_NOTIFICATION_UUID) |
0 commit comments