├── lib ├── __init__.py ├── en_tx_data_store.py ├── logger.py ├── en_rx_service.py ├── gps_service.py ├── en_crypto.py ├── en_tx_service.py └── en_rx_data_store.py ├── .gitignore ├── output └── .gitignore ├── requirements.txt ├── linux-startup └── exposure-notification.service ├── linux-ble-patch └── keep_ble_advertising_on_when_scanning.patch ├── doc ├── linux-kernel-patching.md └── some_thoughts_on_the_en_concept.md ├── en_beacon.py ├── exposure-notification.py ├── README.md └── LICENSE /lib/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .idea* 2 | __pycache__ 3 | -------------------------------------------------------------------------------- /output/.gitignore: -------------------------------------------------------------------------------- 1 | # Ignore everything in this directory 2 | * 3 | # Except this file 4 | !.gitignore 5 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | git+git://github.com/mh-/pybleno.git@enhancements-for-exposure-notification#egg=pybleno 2 | bluepy 3 | pycryptodome 4 | gps 5 | -------------------------------------------------------------------------------- /linux-startup/exposure-notification.service: -------------------------------------------------------------------------------- 1 | [Unit] 2 | Description=Exposure Notification Service 3 | After=multi-user.target 4 | 5 | [Service] 6 | Type=idle 7 | User=pi 8 | WorkingDirectory=/home/pi/exposure-notification-ble-python 9 | ExecStart=/usr/bin/python3 -u exposure-notification.py --cycletime 2 --scantime 2 --gpsdatetime --gpsposition 10 | 11 | [Install] 12 | WantedBy=multi-user.target 13 | -------------------------------------------------------------------------------- /linux-ble-patch/keep_ble_advertising_on_when_scanning.patch: -------------------------------------------------------------------------------- 1 | --- net/bluetooth/hci_request.c 2 | +++ net/bluetooth/hci_request_patched.c 3 | @@ -2464,7 +2464,8 @@ 4 | 5 | BT_DBG("%s", hdev->name); 6 | 7 | - if (hci_dev_test_flag(hdev, HCI_LE_ADV)) { 8 | + if (false) { 9 | + // if (hci_dev_test_flag(hdev, HCI_LE_ADV)) { 10 | hci_dev_lock(hdev); 11 | 12 | /* Don't let discovery abort an outgoing connection attempt 13 | -------------------------------------------------------------------------------- /lib/en_tx_data_store.py: -------------------------------------------------------------------------------- 1 | import base64 2 | 3 | 4 | class ENTxDataStore: 5 | def __init__(self, tx_raw_data_file_name): 6 | self.tek_data_file = open(tx_raw_data_file_name, 'a') 7 | self.tek_data_file.write("TEK_Roll_Interval_i;TEK;TEK-base64\n") 8 | 9 | def __del__(self): 10 | self.tek_data_file.close() 11 | 12 | def write(self, i, tek): 13 | self.tek_data_file.write("%d;%s;%s\n" % (i, tek.hex(), base64.b64encode(tek).decode(encoding="UTF-8"))) 14 | self.tek_data_file.flush() 15 | -------------------------------------------------------------------------------- /lib/logger.py: -------------------------------------------------------------------------------- 1 | # Singleton Logger 2 | # Suppresses repeating log lines 3 | 4 | # noinspection PyAttributeOutsideInit 5 | 6 | 7 | class Logger(object): 8 | __instance = None 9 | 10 | def __new__(cls): 11 | if Logger.__instance is None: 12 | Logger.__instance = object.__new__(cls) 13 | Logger.__instance.last_logged_line = None 14 | return Logger.__instance 15 | 16 | def log(self, text="", end='\n', flush=False): 17 | if (not text == self.last_logged_line) or (end == ''): 18 | print(text, end=end, flush=flush) 19 | self.last_logged_line = text 20 | -------------------------------------------------------------------------------- /lib/en_rx_service.py: -------------------------------------------------------------------------------- 1 | from bluepy import btle 2 | from bluepy.btle import ScanEntry 3 | from lib.logger import * 4 | log = Logger() 5 | 6 | ''' 7 | This class handles the BLE scanning. 8 | ''' 9 | 10 | 11 | class ENBeaconRx: 12 | def __init__(self, rpi, aem, rssi, bdaddr): 13 | self.rpi = rpi 14 | self.aem = aem 15 | self.rssi = rssi 16 | self.bdaddr = bdaddr 17 | 18 | 19 | class ENRxService: 20 | 21 | def __init__(self, iface=0): 22 | self.scanner = btle.Scanner(iface) 23 | 24 | def scan(self, t=1): 25 | # log.log("BLE: scanning for Exposure Notification beacons (timeout: %ds)..." % t) 26 | scan_entries = self.scanner.scan(t) 27 | received_beacons = [] 28 | for scan_entry in scan_entries: 29 | service = scan_entry.getValueText(ScanEntry.COMPLETE_16B_SERVICES) 30 | if service == "0000fd6f-0000-1000-8000-00805f9b34fb": 31 | data = scan_entry.getValueText(ScanEntry.SERVICE_DATA_16B) 32 | # service data is a hex string: 6ffd 00112233445566778899aabbccddeeff 11223344 (UUID, RPI, AEM) 33 | if len(data) == 44 and int(data[0:2], 16) + int(data[2:4], 16) * 0x100 == 0xfd6f: 34 | rpi = bytes.fromhex(data[4:36]) 35 | aem = bytes.fromhex(data[36:44]) 36 | bdaddr = scan_entry.addr + " (" + scan_entry.addrType + ")" 37 | rssi = scan_entry.rssi 38 | received_beacons.append(ENBeaconRx(rpi, aem, rssi, bdaddr)) 39 | return received_beacons 40 | -------------------------------------------------------------------------------- /lib/gps_service.py: -------------------------------------------------------------------------------- 1 | import threading 2 | import time 3 | import gps 4 | import datetime 5 | 6 | 7 | class GpsMessageHandler(threading.Thread): 8 | 9 | def __init__(self): 10 | threading.Thread.__init__(self) 11 | self.gps_data = gps.gps(mode=gps.WATCH_ENABLE) 12 | self.date_time = None 13 | self.lat = None 14 | self.lon = None 15 | self.altitude = None 16 | self.speed = None 17 | self.daemon = True # stop this thread when the main thread ends 18 | self.start() # now start polling for gpsd messages 19 | 20 | def get_date_time(self): # Note: This could be old. But if it's not None, it was at least previously valid. 21 | return self.date_time 22 | 23 | def get_pos(self): 24 | return self.lat, self.lon, self.altitude 25 | 26 | def get_speed(self): 27 | return self.speed 28 | 29 | def run(self): 30 | try: 31 | while True: 32 | gps_data = self.gps_data.next() 33 | if gps_data: 34 | if "time" in gps_data: 35 | # get time from GPS, add "+0000" to import it as UTC 36 | date_time_utc = datetime.datetime.strptime(gps_data["time"]+"+0000", "%Y-%m-%dT%H:%M:%S.%fZ%z") 37 | # Convert to local time 38 | self.date_time = date_time_utc.astimezone(datetime.datetime.utcnow().astimezone().tzinfo).\ 39 | strftime("%Y-%m-%dT%H:%M:%S.%f%z") 40 | if "lat" in gps_data and "lon" in gps_data: 41 | self.lat = gps_data["lat"] 42 | self.lon = gps_data["lon"] 43 | if "alt" in gps_data: 44 | self.altitude = gps_data["alt"] 45 | else: 46 | self.altitude = None 47 | if "speed" in gps_data: 48 | self.speed = gps_data["speed"] 49 | time.sleep(0.1) 50 | except StopIteration: 51 | pass 52 | 53 | 54 | if __name__ == '__main__': 55 | 56 | gps_handler = GpsMessageHandler() 57 | while True: 58 | # print current values for test purposes 59 | time.sleep(5) 60 | print("Time: %s - LAT, LON, Altitude: %s - Speed: %f" % (gps_handler.get_date_time(), gps_handler.get_pos(), gps_handler.get_speed())) 61 | -------------------------------------------------------------------------------- /lib/en_crypto.py: -------------------------------------------------------------------------------- 1 | from Crypto.Protocol.KDF import HKDF 2 | from Crypto.Hash import SHA256 3 | from Crypto.Random import get_random_bytes 4 | from Crypto.Cipher import AES 5 | import struct, time 6 | from lib.logger import * 7 | log = Logger() 8 | 9 | 10 | class ENCrypto: 11 | 12 | def __init__(self, interval_length_minutes=10, tek_rolling_period=144): 13 | self.tek = bytes([0] * 16) 14 | self.tek_roll_interval_i = 0 15 | self.rpik = bytes([0] * 16) 16 | self.aemk = bytes([0] * 16) 17 | self.rpi = bytes([0] * 16) 18 | self.aem = bytes([0] * 16) 19 | self.interval_length_minutes = interval_length_minutes 20 | self.tek_rolling_period = tek_rolling_period 21 | 22 | @staticmethod 23 | def get_current_unix_epoch_time_seconds(): 24 | return int(time.time()) 25 | 26 | def en_interval_number(self, timestamp_seconds): 27 | return timestamp_seconds // (60 * self.interval_length_minutes) 28 | 29 | def get_encoded_current_en_interval_number(self): 30 | return struct.pack(" self.tek_roll_interval_i 36 | 37 | def roll_tek(self): 38 | self.tek_roll_interval_i = (self.en_interval_number(self.get_current_unix_epoch_time_seconds()) 39 | // self.tek_rolling_period) * self.tek_rolling_period 40 | self.tek = get_random_bytes(16) 41 | log.log("CRYPTO: Rolled TEK at i: %d (hex %s). New TEK: %s" % 42 | (self.tek_roll_interval_i, struct.pack(" RPI: %s" % (padded_data.hex(), self.rpi.hex())) 56 | 57 | def encrypt_aem(self, metadata, rpi): 58 | cipher = AES.new(self.aemk, AES.MODE_CTR, nonce=bytes(0), initial_value=rpi) 59 | self.aem = cipher.encrypt(bytes(metadata)) 60 | log.log("CRYPTO: metadata: %s --> AEM: %s" % (bytes(metadata).hex(), self.aem.hex())) 61 | -------------------------------------------------------------------------------- /lib/en_tx_service.py: -------------------------------------------------------------------------------- 1 | import os, time 2 | from Crypto.Random import get_random_bytes, random 3 | from lib.logger import * 4 | log = Logger() 5 | 6 | ''' 7 | This class handles the BLE Beacon Transmission (TX). 8 | Because after some time of BLE advertising, a restart of the BLE stack (hciconfig hci0 down / up) might be required, 9 | and because the pybleno class can't be shut down and restarted properly, the actual BLE handling has been placed 10 | in a separate python script "en_beacon.py". 11 | ''' 12 | 13 | 14 | class ENTxService: 15 | 16 | def __init__(self, bdaddr_rotation_interval_min_minutes, bdaddr_rotation_interval_max_minutes): 17 | self.random_bdaddr = bytes([0x00] * 6) 18 | self.bdaddr_rotation_interval_min_seconds = bdaddr_rotation_interval_min_minutes * 60 + 1 19 | self.bdaddr_rotation_interval_max_seconds = bdaddr_rotation_interval_max_minutes * 60 - 1 20 | if self.bdaddr_rotation_interval_max_seconds < self.bdaddr_rotation_interval_min_seconds: 21 | self.bdaddr_rotation_interval_max_seconds = self.bdaddr_rotation_interval_min_seconds 22 | self.bdaddr_next_rotation_seconds = 0 23 | 24 | @staticmethod 25 | def get_current_unix_epoch_time_seconds(): 26 | return int(time.time()) 27 | 28 | @staticmethod 29 | def get_advertising_tx_power_level(): 30 | return 12 # in real life, this info should come from the BLE transmitter 31 | 32 | def roll_random_bdaddr(self): 33 | # Create a BLE random "Non-Resolvable Private Address", i.e. the two MSBs must be 0, and not all bits 0 or 1 34 | while True: 35 | self.random_bdaddr = bytearray(get_random_bytes(6)) 36 | self.random_bdaddr[0] = self.random_bdaddr[0] & 0b00111111 37 | self.random_bdaddr = bytes(self.random_bdaddr) 38 | if (self.random_bdaddr.hex() != "000000000000") and (self.random_bdaddr.hex() != "3fffffffffff"): 39 | break 40 | self.bdaddr_next_rotation_seconds = (self.get_current_unix_epoch_time_seconds() 41 | + random.randint(self.bdaddr_rotation_interval_min_seconds, 42 | self.bdaddr_rotation_interval_max_seconds)) 43 | 44 | def bdaddr_should_roll(self): 45 | return self.get_current_unix_epoch_time_seconds() >= self.bdaddr_next_rotation_seconds 46 | 47 | def start_beacon(self, rpi, aem): 48 | while True: 49 | if os.system("python3 en_beacon.py %s %s %s" % (rpi.hex(), aem.hex(), self.random_bdaddr.hex())) == 0: 50 | # return code 0 means: ok, advertising started. 51 | break 52 | log.log() 53 | log.log("ERROR: Could not start advertising! Timestamp: %s" % time.strftime("%H:%M:%S", time.localtime())) 54 | log.log() 55 | # try to recover: 56 | os.system("sudo hciconfig hci0 down; sudo hciconfig hci0 up") 57 | time.sleep(1) 58 | 59 | @staticmethod 60 | def stop_beacon(): 61 | os.system("sudo hciconfig hci0 down; sudo hciconfig hci0 up") 62 | -------------------------------------------------------------------------------- /doc/linux-kernel-patching.md: -------------------------------------------------------------------------------- 1 | Linux Kernel Patching 2 | ===================== 3 | 4 | ### Why should you modify the kernel? 5 | 6 | Bluez, the Linux Bluetooth stack, switches LE Advertising off while scanning for advertisements from other devices. 7 | This can be observed with `sudo btmon`: 8 | ``` 9 | @ MGMT Open: bluepy-helper (privileged) version 1.14 {0x0003} 7.786839 10 | @ MGMT Command: Read Management Version Information (0x0001) plen 0 {0x0003} 7.787706 11 | @ MGMT Event: Command Complete (0x0001) plen 6 {0x0003} 7.787725 12 | Read Management Version Information (0x0001) plen 3 13 | Status: Success (0x00) 14 | Version: 1.14 15 | @ MGMT Command: Start Discovery (0x0023) plen 1 {0x0003} [hci0] 7.788614 16 | Address type: 0x06 17 | LE Public 18 | LE Random 19 | < HCI Command: LE Set Advertise Enable (0x08|0x000a) plen 1 #121 [hci0] 7.788724 20 | Advertising: Disabled (0x00) 21 | > HCI Event: Command Complete (0x0e) plen 4 #122 [hci0] 7.789750 22 | LE Set Advertise Enable (0x08|0x000a) ncmd 1 23 | Status: Success (0x00) 24 | ``` 25 | The first HCI command the `@ MGMT Command: Start Discovery` sends is 26 | `LE Set Advertise Enable` with `Advertising: Disabled`. 27 | 28 | Many BLE chips can however interleave advertising and scanning with a high frequency, so that the probability that two 29 | devices "see" each other during the process is much higher. Therefore I wanted to try to keep advertising on all the time. 30 | 31 | The responsible code is not part of the bluez user space package, but in the kernel space in 32 | `net/bluetooth/hci_request.c`, `active_scan()`. You can view the kernel code e.g. here: 33 | https://elixir.bootlin.com/linux/v4.19.97/source/net/bluetooth/hci_request.c 34 | 35 | The problem is caused here - `__hci_req_disable_advertising()` sends the HCI Request "Disable Advertising": 36 | ``` 37 | static int active_scan(struct hci_request *req, unsigned long opt) 38 | { 39 | uint16_t interval = opt; 40 | struct hci_dev *hdev = req->hdev; 41 | u8 own_addr_type; 42 | int err; 43 | 44 | BT_DBG("%s", hdev->name); 45 | 46 | if (hci_dev_test_flag(hdev, HCI_LE_ADV)) { 47 | hci_dev_lock(hdev); 48 | 49 | /* Don't let discovery abort an outgoing connection attempt 50 | * that's using directed advertising. 51 | */ 52 | if (hci_lookup_le_connect(hdev)) { 53 | hci_dev_unlock(hdev); 54 | return -EBUSY; 55 | } 56 | 57 | cancel_adv_timeout(hdev); 58 | hci_dev_unlock(hdev); 59 | 60 | __hci_req_disable_advertising(req); 61 | } 62 | (...) 63 | ``` 64 | A quick&dirty hack is to simply disable that section, e.g. by replacing `if (hci_dev_test_flag(hdev, HCI_LE_ADV))` by 65 | `if (false)`. 66 | 67 | Another option would be to wait for [kernel version 5.7](https://elixir.bootlin.com/linux/v5.7-rc5/source/net/bluetooth/hci_request.c) 68 | where this is handled differently, and where parallel advertising and scanning will probably work. 69 | But this isn't part of the [Raspberry Pi kernel source tree](https://github.com/raspberrypi/linux) yet. 70 | 71 | ### How to modify the kernel? 72 | 73 | If you feel comfortable applying this hack to a Raspberry Pi setup, here's what you have to do: 74 | 75 | 1. Read the tutorial at https://www.raspberrypi.org/documentation/linux/kernel/building.md 76 | 2. On your Raspberry Pi, do `uname -r`. 77 | For Raspbian Buster, this shows the kernel version `4.19.97-v7+`. 78 | The corresponding git repo is located here , you can clone it with 79 | `git clone --depth=1 --branch rpi-4.19.y https://github.com/raspberrypi/linux` 80 | 2. __Apply the [patch](../linux-ble-patch/keep_ble_advertising_on_when_scanning.patch):__ 81 | `patch -p0 < keep_ble_advertising_on_when_scanning.patch` 82 | 3. Build the kernel as explained in the tutorial. This will take some time. 83 | 4. Deploy the kernel to the Raspberry Pi's SD card. 84 | 85 | 86 | ----- 87 | 88 | _Disclaimer: All views expressed are my own personal opinions. All information is provided "as is", with no guarantee of 89 | completeness, accuracy, timeliness or of the results obtained from the use of this information._ 90 | -------------------------------------------------------------------------------- /lib/en_rx_data_store.py: -------------------------------------------------------------------------------- 1 | from lib.logger import * 2 | log = Logger() 3 | 4 | 5 | class ENRxDataStore: 6 | def __init__(self, rx_raw_data_file_name, rx_processed_data_filename, filter_time_seconds, store_raw_data, 7 | store_gps_position): 8 | self.store_raw_data = store_raw_data 9 | self.store_gps_position = store_gps_position 10 | if self.store_raw_data: 11 | self.rx_raw_data_file = open(rx_raw_data_file_name, 'a') 12 | self.rx_raw_data_file.write("Time;RPI;AEM;RSSI;BDADDR") 13 | if self.store_gps_position: 14 | self.rx_raw_data_file.write(";LAT;LON;Altitude;Speed") 15 | self.rx_raw_data_file.write("\n") 16 | self.rx_data_file = open(rx_processed_data_filename, 'a') 17 | self.rx_data_file.write("StartTime;EndTime;RPI;AEM;MaxRSSI;BDADDR") 18 | if self.store_gps_position: 19 | self.rx_data_file.write(";LAT;LON;Altitude;Speed") 20 | self.rx_data_file.write("\n") 21 | self.rx_dict = dict() 22 | self.filter_time_seconds = filter_time_seconds 23 | 24 | def __del__(self): 25 | if self.store_raw_data: 26 | self.rx_raw_data_file.close() 27 | for key in self.rx_dict: 28 | beacon_values = self.rx_dict[key] 29 | self.write_filtered_list(key, beacon_values) 30 | self.rx_data_file.close() 31 | 32 | def consider_in_rx_list(self, beacon, timestamp, gps_lat=None, gps_lon=None, gps_altitude=None, gps_speed=None): 33 | if beacon.rpi in self.rx_dict: 34 | # Found RPI in list: keep start_timestamp 35 | start_timestamp = self.rx_dict[beacon.rpi][3] 36 | previous_max_rssi = self.rx_dict[beacon.rpi][1] 37 | if not self.store_gps_position: 38 | self.rx_dict[beacon.rpi] = [beacon.aem, max(previous_max_rssi, beacon.rssi), beacon.bdaddr, 39 | start_timestamp, timestamp] 40 | else: 41 | self.rx_dict[beacon.rpi] = [beacon.aem, max(previous_max_rssi, beacon.rssi), beacon.bdaddr, 42 | start_timestamp, timestamp, 43 | gps_lat, gps_lon, gps_altitude, gps_speed] 44 | else: 45 | # New RPI: store now 46 | if not self.store_gps_position: 47 | self.rx_dict[beacon.rpi] = [beacon.aem, beacon.rssi, beacon.bdaddr, timestamp, timestamp] 48 | else: 49 | self.rx_dict[beacon.rpi] = [beacon.aem, beacon.rssi, beacon.bdaddr, timestamp, timestamp, 50 | gps_lat, gps_lon, gps_altitude, gps_speed] 51 | 52 | def filter_rx_list(self, current_timestamp): 53 | old_beacon_keys = [key for (key, value) in self.rx_dict.items() 54 | if current_timestamp - value[4] >= self.filter_time_seconds] 55 | for key in old_beacon_keys: 56 | beacon_values = self.rx_dict.pop(key) 57 | self.write_filtered_list(key, beacon_values) 58 | 59 | def write_filtered_list(self, key, beacon_values): 60 | self.rx_data_file.write("%d;%d;%s;%s;%d;%s" % 61 | (beacon_values[3], beacon_values[4], key.hex(), beacon_values[0].hex(), 62 | beacon_values[1], beacon_values[2])) 63 | if self.store_gps_position: 64 | self.rx_data_file.write(";%s;%s;%s;%s" % 65 | (beacon_values[5], beacon_values[6], beacon_values[7], beacon_values[8])) 66 | self.rx_data_file.write("\n") 67 | self.rx_data_file.flush() 68 | log.log("BLE RX: Beacon was received for %d seconds: RPI: %s, AEM: %s, max. RSSI: %d, BDADDR: %s" % 69 | (beacon_values[4] - beacon_values[3], key.hex(), beacon_values[0].hex(), beacon_values[1], 70 | beacon_values[2])) 71 | 72 | def write(self, beacon, current_timestamp, gps_lat=None, gps_lon=None, gps_altitude=None, gps_speed=None): 73 | if self.store_raw_data: 74 | self.rx_raw_data_file.write("%d;%s;%s;%d;%s" % 75 | (current_timestamp, beacon.rpi.hex(), beacon.aem.hex(), beacon.rssi, beacon.bdaddr)) 76 | if self.store_gps_position: 77 | self.rx_raw_data_file.write(";%s;%s;%s;%s" % (gps_lat, gps_lon, gps_altitude, gps_speed)) 78 | self.rx_raw_data_file.write("\n") 79 | self.consider_in_rx_list(beacon, current_timestamp, 80 | gps_lat=gps_lat, gps_lon=gps_lon, gps_altitude=gps_altitude, gps_speed=gps_speed) 81 | -------------------------------------------------------------------------------- /en_beacon.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | # This script activates an Exposure Notification V1.2 BLE Beacon. 4 | # To disable the beacon again, this can be used: 5 | # os.system("sudo hciconfig hci0 down; sudo hciconfig hci0 up") 6 | 7 | from pybleno import * 8 | from pybleno.hci_socket.BluetoothHCI import * 9 | import struct, sys, time 10 | import argparse 11 | 12 | 13 | class ENBeacon(BlenoPrimaryService): 14 | 15 | def __init__(self, rpi, aem, bdaddr, uuid=0xFD6F): 16 | BlenoPrimaryService.__init__(self, {"uuid":"{:04x}".format(uuid)}) 17 | self.bleno = Bleno() 18 | self.uuid = struct.pack(" 73 | # see also ExposureNotification-FrameworkDocumentationv1.2.pdf "Advertising Payload" 74 | # advertisement_data = bytes.fromhex("020102") + \ 75 | advertisement_data = bytes.fromhex("02011a") + \ 76 | bytes.fromhex("0303") + bytes(uuid) + \ 77 | bytes.fromhex("1716") + bytes(uuid) + bytes(rpi) + bytes(aem) 78 | self.bleno.startAdvertisingWithEIRData(advertisementData=advertisement_data, scanData=[], 79 | callback=None) 80 | 81 | def set_advertising_bdaddr(self): 82 | # print("BLE TX: Setting advertising random bdaddr to %s." % bytes(self.random_bdaddr).hex()) 83 | self.bleno.setRandomAddress(self.random_bdaddr) 84 | 85 | def on_advertising_channel_tx_power_level_update(self, tx_power_level): 86 | print("BLE TX: Read Advertising Channel TX Power Level: %d dBm" % tx_power_level) 87 | self.advertising_tx_power_level = tx_power_level 88 | 89 | 90 | parser = argparse.ArgumentParser(description="Simulate an Exposure Notification V1.2 BLE Beacon.") 91 | parser.add_argument("rpi_string", metavar="RPI", help="the desired RPI value (16 bytes hex string)") 92 | parser.add_argument("aem_string", metavar="AEM", help="the desired AEM value (4 bytes hex string)") 93 | parser.add_argument("bdaddr_string", metavar="BDADDR", help="the random BDADDR (6 bytes hex string)") 94 | 95 | args = parser.parse_args() 96 | 97 | try: 98 | _rpi = bytes.fromhex(args.rpi_string) 99 | if len(_rpi) != 16: 100 | raise ValueError 101 | except ValueError: 102 | parser.error("ERROR: RPI must be exactly 16 bytes!") 103 | try: 104 | _aem = bytes.fromhex(args.aem_string) 105 | if len(_aem) != 4: 106 | raise ValueError 107 | except ValueError: 108 | parser.error("ERROR: AEM must be exactly 4 bytes!") 109 | try: 110 | _bdaddr = bytes.fromhex(args.bdaddr_string) 111 | if len(_bdaddr) != 6: 112 | raise ValueError 113 | except ValueError: 114 | parser.error("ERROR: BDADDR must be exactly 6 bytes!") 115 | # noinspection PyUnboundLocalVariable 116 | if (_bdaddr[0] & 0b11000000) != 0: 117 | parser.error("ERROR: The two MSBs of BDADDR must be 0, because we need a Non-Resolvable Private Address!") 118 | # Note: If the two MSBs are 0b10 (undefined address type), iOS will discard the advertisement! 119 | if (_bdaddr.hex() == "000000000000") or (_bdaddr.hex() == "3fffffffffff"): 120 | parser.error("ERROR: BDADDR must not be all 0 or all 1!") 121 | 122 | print("BLE TX: RPI: %s, AEM: %s, BDADDR: %s" % (args.rpi_string, args.aem_string, args.bdaddr_string)) 123 | # noinspection PyUnboundLocalVariable 124 | beacon = ENBeacon(rpi=_rpi, aem=_aem, bdaddr=_bdaddr) 125 | time.sleep(0.2) 126 | sys.exit(0) 127 | -------------------------------------------------------------------------------- /exposure-notification.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | from lib.en_tx_service import * 3 | from lib.en_tx_data_store import * 4 | from lib.en_rx_service import * 5 | from lib.en_rx_data_store import * 6 | from lib.en_crypto import * 7 | from lib.gps_service import * 8 | import time 9 | import argparse 10 | import os 11 | from lib.logger import * 12 | log = Logger() 13 | 14 | ''' 15 | Exposure Notification BLE Simulator 16 | 17 | This script transmits, and scans for and records 'Exposure Notification' Beacons according to 18 | https://blog.google/inside-google/company-announcements/apple-and-google-partner-covid-19-contact-tracing-technology/ 19 | https://blog.google/documents/70/Exposure_Notification_-_Bluetooth_Specification_v1.2.2.pdf 20 | https://blog.google/documents/69/Exposure_Notification_-_Cryptography_Specification_v1.2.1.pdf 21 | 22 | Transmission is handled in en_tx_service.py. Storing the TEKs is handled in en_tx_data_store.py. 23 | Scanning is handled in en_rx_service.py. Storing the received beacons is handled in en_rx_data_store.py. 24 | Cryptography is handled in en_crypto.py. 25 | ''' 26 | 27 | 28 | def get_current_unix_epoch_time_seconds(): 29 | return int(time.time()) 30 | 31 | 32 | try: 33 | parser = argparse.ArgumentParser(description="Exposure Notification BLE Simulator.") 34 | parser.add_argument("-t", "--triggertx", 35 | help="trigger TX again after RX, if the Linux kernel wasn't patched to allow both in parallel", 36 | action="store_true") 37 | parser.add_argument("-n", "--notx", 38 | help="do not transmit RPI beacons via BLE", 39 | action="store_true") 40 | parser.add_argument("-r", "--storerawdata", 41 | help="store raw RX data after every scan", 42 | action="store_true") 43 | parser.add_argument("-d", "--gpsdatetime", 44 | help="set date and time from GPS", 45 | action="store_true") 46 | parser.add_argument("-g", "--gpsposition", 47 | help="store GPS position with RX data", 48 | action="store_true") 49 | parser.add_argument("-c", "--cycletime", type=int, default=5*60, 50 | help="duration (in seconds) of one cycle") 51 | parser.add_argument("-s", "--scantime", type=int, default=2, 52 | help="duration (in seconds) of the scanning within one cycle") 53 | args = parser.parse_args() 54 | trigger_tx = args.triggertx 55 | tx_allowed = not args.notx 56 | store_raw_rx_data = args.storerawdata 57 | use_gps_date_time = args.gpsdatetime 58 | use_gps_position = args.gpsposition 59 | total_scan_time_seconds = args.scantime 60 | total_cycle_time_seconds = max(args.cycletime, total_scan_time_seconds) 61 | 62 | log.log("Exposure Notification BLE Simulator") 63 | log.log("This script simulates an 'Exposure Notification V1.2'-enabled device.") 64 | if not tx_allowed: 65 | log.log("Warning: --notx option was selected: RPI beacons will not be transmitted.") 66 | 67 | gps_handler = None 68 | if use_gps_date_time or use_gps_position: 69 | gps_handler = GpsMessageHandler() 70 | 71 | if use_gps_date_time: 72 | log.log("\nWaiting for time from GPS...") 73 | date_time = gps_handler.get_date_time() 74 | while not date_time: 75 | time.sleep(0.5) 76 | date_time = gps_handler.get_date_time() 77 | os.system("sudo date -s %s" % date_time) 78 | 79 | one_scan_interval_seconds = 2 80 | num_scan_intervals = -(-total_scan_time_seconds // one_scan_interval_seconds) # ceil division 81 | sleep_time_seconds = max(total_cycle_time_seconds - num_scan_intervals * one_scan_interval_seconds, 0) 82 | rx_list_filter_time_seconds = 2 * total_cycle_time_seconds + 10 83 | log.log("\nFull cycle duration: %ds, thereof scanning duration: %ds" % 84 | (sleep_time_seconds + num_scan_intervals * one_scan_interval_seconds, 85 | num_scan_intervals * one_scan_interval_seconds)) 86 | 87 | rx_data_store = ENRxDataStore("output/rx_raw_data.csv", "output/rx_data.csv", rx_list_filter_time_seconds, 88 | store_raw_rx_data, use_gps_position) 89 | rx_service = ENRxService() 90 | 91 | if tx_allowed: 92 | tx_data_store = ENTxDataStore("output/tek_data.csv") 93 | crypto = ENCrypto(interval_length_minutes=10, tek_rolling_period=144) 94 | tx_service = ENTxService(bdaddr_rotation_interval_min_minutes=10, bdaddr_rotation_interval_max_minutes=20) 95 | ble_advertising_tx_power_level = tx_service.get_advertising_tx_power_level() 96 | 97 | while True: 98 | if tx_allowed: 99 | if crypto.tek_should_roll(): 100 | log.log("\nTX: TEK should roll...") 101 | crypto.roll_tek() 102 | tx_data_store.write(crypto.tek_roll_interval_i, crypto.tek) 103 | crypto.derive_keys() 104 | 105 | if tx_service.bdaddr_should_roll(): 106 | log.log("\nTX: BDADDR should roll...") 107 | tx_service.stop_beacon() 108 | tx_service.roll_random_bdaddr() 109 | # also create new RPI and encrypt metadata again: 110 | crypto.encrypt_rpi() 111 | crypto.encrypt_aem(metadata=[0x40, ble_advertising_tx_power_level, 0x00, 0x00], rpi=crypto.rpi) 112 | tx_service.start_beacon(rpi=crypto.rpi, aem=crypto.aem) 113 | elif trigger_tx: 114 | tx_service.start_beacon(rpi=crypto.rpi, aem=crypto.aem) 115 | 116 | for _ in range(sleep_time_seconds): 117 | # log.log(".", end='', flush=True) 118 | time.sleep(1) 119 | 120 | log.log("\nBLE RX: Now scanning...") 121 | 122 | gps_lat = gps_lon = gps_altitude = gps_speed = None 123 | if use_gps_position: 124 | gps_lat, gps_lon, gps_altitude = gps_handler.get_pos() 125 | gps_speed = gps_handler.get_speed() 126 | 127 | timestamp = get_current_unix_epoch_time_seconds() 128 | for _ in range(num_scan_intervals): 129 | timestamp = get_current_unix_epoch_time_seconds() 130 | scan_result = rx_service.scan(t=one_scan_interval_seconds) 131 | for beacon in scan_result: 132 | rx_data_store.write(beacon, timestamp, 133 | gps_lat=gps_lat, gps_lon=gps_lon, gps_altitude=gps_altitude, gps_speed=gps_speed) 134 | rx_data_store.filter_rx_list(timestamp) 135 | # log.log("BLE RX: Stopped scanning.") 136 | 137 | except KeyboardInterrupt: 138 | log.log("\nKeyboard Interrupt.") 139 | -------------------------------------------------------------------------------- /doc/some_thoughts_on_the_en_concept.md: -------------------------------------------------------------------------------- 1 | Some Thoughts on the Exposure Notification Concept 2 | ================================================== 3 | 4 | Privacy Concerns 5 | ---------------- 6 | 7 | I like this concept a lot: Keeping anonymous data on the users' devices only, and not tracking users' locations, will 8 | help to reach a high degree of acceptance. Of course the fact that it will be supported by the two large smart phone 9 | platforms will also be crucial for the success. 10 | 11 | Starting with version 1.1, there's also no long-term key (previously called Tracing Key) stored on the device anymore, 12 | but only daily random keys (TEK) which are deleted after 14 days. This is optimal for privacy: Even if users were 13 | forced to disclose their key material, they would, as expected, only possess 14 days worth of keys. 14 | 15 | The concept is a good compromise that allows a user to collect anonymous data, which can help to warn of a potential 16 | infection, while making it reasonably difficult to track the user's movements. 17 | It might be possible to track users (e.g. inside a building) even across ENIntervals, because one RPI disappearing 18 | from scans and another one appearing immediately afterwards, with no overlapping, would indicate that the two devices 19 | are the same with a rather high probability. This would require a lot of receivers, though. To this end, it would be 20 | better if all devices changed their RPI and BDADDR synchronously; but to roll out the system quickly, it has to work 21 | with existing BLE stacks. I'd rather have this system activated very soon through a Play Services update, than to wait 22 | for all device manufacturers. 23 | 24 | In summary, I think that this concept offers a very good trade-off regarding privacy in the current situation. 25 | 26 | The recently published [open source reference implementation of an Exposure Notifications 27 | server](https://github.com/google/exposure-notifications-server) includes the use of a "device attestation API", 28 | such as the [SafetyNet Attestation API](https://developer.android.com/training/safetynet/attestation). 29 | The purpose is to validate TEKs, i.e. prevent hacked devices from reporting fake TEKs as Diagnosis Keys. 30 | The [SafetyNet ToS](https://developer.android.com/training/safetynet/attestation#safetynet-tos) state that this 31 | "works by collecting hardware and software information, such as device and application data (...), 32 | and sending that data to Google for analysis". I think that's fine in general, but an actual COVID-19- warning app 33 | should _not_ invoke this API _only_ when a user has been infected, but independently of this - so that the device data 34 | cannot be linked to this sensitive information. 35 | 36 | Another [concern](https://github.com/corona-warn-app/cwa-documentation/issues/76#issuecomment-629996392) would be that 37 | third party apps or services could use BLE scanning to do the same as an official COVID-19 warning app - even on devices 38 | where that warning app is not installed - and could thus make the same estimations about the user's exposure status (using 39 | Diagnosis Keys downloaded from official sources). Therefore it would be better if Android filtered out 0xFD6F beacons from 40 | "normal" BLE scanning responses, unless the user specifically allows this. 41 | Apple seems to have introduced this behavior with iOS 13.5 - the 0xFD6F payload is not reported to "normal" apps anymore 42 | during BLE scanning. 43 | 44 | Also, the non-linkability of published Diagnosis Keys across multiple days only works in geographic regions where 45 | _many users_ report Diagnosis Keys. Otherwise, if only one user reports within a small geographic area, an attacker can link 46 | the received RPIs across multiple days simply based on the geolocation where they were received. 47 | In Germany, the fixed distribution of Transmission Risk Levels over the age of the reported Diagnosis Keys 48 | (see ["Epidemiological Motivation of the Transmission Risk Level"](https://github.com/corona-warn-app/cwa-documentation/blob/master/transmission_risk.pdf) 49 | (only case 4 is used at the moment, see also [here](https://github.com/corona-warn-app/cwa-app-android/issues/678)) 50 | also further helps to link Diagnosis Keys in this scenario. 51 | During the ramp-up phase in the week after the first [app publication in Germany](https://www.coronawarn.app/), 52 | it turned out that the backend did not distribute any Diagnosis Keys at all, presumably because a threshold of 140 keys 53 | had not been reached, see e.g. [here](https://github.com/corona-warn-app/cwa-backlog/issues/2#issuecomment-647088679). 54 | This threshold however means max. ~70 users (if each one has already 2 keys to report), and seems to be completely arbitrary 55 | and useless, because these users are likely spread all over Germany, and each one could be tracked across both days 56 | simply based on the locations where the RPIs were recorded. 57 | 58 | Cryptography on BLE 59 | ------------------- 60 | 61 | I believe the cryptography concept v1.2 will properly protect the users' privacy. 62 | 63 | Evolved from v1.0, it still contains key derivation, although this doesn't really seem to be necessary anymore. 64 | There doesn't seem to be a use case where a user would be willing to release their RPI key, but not their AEM key, 65 | as the AEM key currently only protects the TX power, and this is absolutely required for distance estimation. 66 | One single AES key would be sufficient for the encryption of both ENIntervalNumber and the metadata. 67 | 68 | I could maybe envision a setup where the TX power is instead XORed into one of the RPI byte (which still keeps the 69 | false-positive probability reasonably low), and use the AEM for a longer-term user identifier, which might help users to 70 | better understand their exposure risk. Or the AEM could be used for some other type of data, that some infected users 71 | might - and some others might not - be willing to disclose, and in this context key derivation could be useful. 72 | But this would require only one key derivation, not two. 73 | 74 | Anyway, I believe that the overall security of the concept is strong and adequate. 75 | 76 | Distance Measurement 77 | -------------------- 78 | 79 | Estimating the distance from the RF signal attenuation will unfortunately not yield very precise results. 80 | The measured attenuation depends on the distance, but also on many other factors, e.g. the relative orientation 81 | of the antennas. Even with completely stationary Raspberry Pi devices, I still got large fluctuations in the RSSI 82 | measurements. I don't think it will be possible to distinguish between two people sitting next to each other and 83 | two people sitting in adjacent rooms. 84 | 85 | The best strategy will probably be a frequent scanning, and using the maximum of the RSSI values, hoping that movement of 86 | the devices will yield an optimal transmission at least once. However, this needs to be balanced with battery power 87 | consumption. 88 | 89 | Again, this is a trade-off; even though having UWB support in all devices would make this a lot more accurate, 90 | I'd rather not wait for that. 91 | 92 | ----- 93 | 94 | _Disclaimer: All views expressed are my own personal opinions. All information is provided "as is", with no guarantee of 95 | completeness, accuracy, timeliness or of the results obtained from the use of this information._ 96 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | exposure-notification-ble-python 2 | ================================ 3 | 4 | Exposure Notification BLE Simulator 5 | ----------------------------------- 6 | 7 | This is a Python implementation of the __COVID-19 "Exposure Notification"__ (previously "Contact Tracing") 8 | specifications at . 9 | 10 | The `exposure-notification.py` script transmits Bluetooth Low Energy (BLE) beacons, 11 | and at the same time scans for them and records their contents and signal strength (RSSI). 12 | 13 | The purpose of this is research, particularly regarding the security & privacy implications 14 | of this contact tracing concept, while the actual implementations on smart phones are not yet (publicly) available. 15 | 16 | I wrote down a few thoughts about the concept [here](doc/some_thoughts_on_the_en_concept.md). 17 | 18 | Usage Example 19 | ------------- 20 | 21 | $ python3 exposure-notification.py -c 10 -s 2 22 | Exposure Notification BLE Simulator 23 | This script simulates an 'Exposure Notification V1.2'-enabled device. 24 | 25 | Full cycle duration: 10s, thereof scanning duration: 2s 26 | 27 | TX: TEK should roll... 28 | CRYPTO: Rolled TEK at i: 2649312 (hex e06c2800). New TEK: 7921b817fdb92074df5345594273756f 29 | CRYPTO: RPIK: eae8956644770f952871daf549c0ce7e 30 | CRYPTO: AEMK: a1d0bd6f94b053cf622ca88194e20611 31 | 32 | TX: BDADDR should roll... 33 | CRYPTO: padded data: 454e2d5250490000000000005b6d2800 --> RPI: 5811408cf8d88d2b33f73773a7c6d45f 34 | CRYPTO: metadata: 400c0000 --> AEM: a3e9517f 35 | BLE TX: RPI: 5811408cf8d88d2b33f73773a7c6d45f, AEM: a3e9517f, BDADDR: 3e9a0a0c3d4b 36 | BLE TX: Read Advertising Channel TX Power Level: 12 dBm 37 | BLE TX: Power is on, now starting to advertise... 38 | BLE TX: OK, we are advertising. 39 | ........ 40 | BLE RX: Now scanning... 41 | ........ 42 | BLE RX: Now scanning... 43 | ........ 44 | BLE RX: Now scanning... 45 | ........ 46 | BLE RX: Now scanning... 47 | ........ 48 | BLE RX: Now scanning... 49 | ........ 50 | BLE RX: Now scanning... 51 | 52 | BLE RX: Beacon was received for 20 seconds: RPI: 8c3f2c091ad2f7c5da409a3171b96f6f, AEM: 11c15a1b, max. RSSI: -44, BDADDR: 0c:33:79:93:2c:1a (random) 53 | .... 54 | 55 | The script will create (or append to) these files: 56 | 57 | - `tek_data.csv` contains the daily Temporary Encryption Keys (TEK) that are used for sending beacons. 58 | - `rx_raw_data.csv` contains all the received beacons with timestamp, RSSI and the BDADDR of the sender. 59 | (Only with option `-r` / `--storerawdata`.) 60 | - `rx_data.csv` contains preprocessed data about the received beacons, incl. their max. RSSI. 61 | An entry is generated when a beacon with a specific RPI hasn't been seen anymore for a certain time, which depends 62 | on the selected cycle time. 63 | 64 | Hardware Requirements 65 | --------------------- 66 | 67 | This package has been developed for the __Raspberry Pi__ platform, and has been tested on 68 | Raspberry Pi 3B+ and Raspberry Pi Zero W, using their integrated BLE hardware. 69 | 70 | Software Requirements 71 | --------------------- 72 | 73 | - __Linux__ incl. __bluez__ 74 | (tested with [Raspbian Buster Lite](https://www.raspberrypi.org/downloads/raspbian/), Version Feb. 2020) 75 | - __Python 3__ (tested with Python 3.7.3, which is included in the Raspbian package) 76 | - [__bluepy__](https://github.com/IanHarvey/bluepy) by Ian Harvey, used for scanning for beacons (BLE RX) 77 | - [__pybleno__](https://github.com/Adam-Langley/pybleno) by Adam Langley, used for sending beacons (BLE TX) - 78 | I created a [__fork__](https://github.com/mh-/pybleno/tree/enhancements-for-exposure-notification) with a few 79 | [small enhancements](https://github.com/Adam-Langley/pybleno/compare/master...mh-:enhancements-for-exposure-notification) 80 | to exactly mimic the Exposure Notification specification. 81 | - Because the out-of-the-box Raspberry Pi Linux bluez stack (kernel 4.19.97+) stops sending BLE beacons during BLE 82 | scanning, which is somewhat sub-optimal for the use case and probably not the behavior of real smart phones, I created a 83 | [__kernel patch__](doc/linux-kernel-patching.md). (Actually it's a dirty hack which has been only tested in this one 84 | scenario - kernel 5.7 will probably solve this in a better way, but isn't tested on the Raspberry Pi platform yet). 85 | If you prefer to keep your existing kernel, the script can also simply toggle between transmit-only and scan-only phases. 86 | 87 | Installation 88 | ------------ 89 | 90 | $ git clone https://github.com/mh-/exposure-notification-ble-python 91 | $ cd exposure-notification-ble-python 92 | 93 | $ # Install GPS support, incl. Python library 94 | $ sudo apt install gpsd gpsd-clients 95 | 96 | $ pip3 install -r requirements.txt 97 | 98 | $ # Give Bluetooth access to pybleno --> Python3.7 99 | $ sudo setcap 'cap_net_raw,cap_net_admin+eip' /usr/bin/python3.7 100 | $ # Give Bluetooth access to bluepy --> bluepy-helper 101 | $ sudo setcap 'cap_net_raw,cap_net_admin+eip' /home/pi/.local/lib/python3.7/site-packages/bluepy/bluepy-helper 102 | 103 | Running the Script 104 | ------------------ 105 | 106 | There are two variants: 107 | 108 | a) If you modify the Linux kernel, as explained [here](doc/linux-kernel-patching.md), you can run the script 109 | without parameters: 110 | 111 | $ python3 exposure-notification.py 112 | 113 | b) With the original Linux kernel, advertising the beacon (TX) will be disabled by each scanning (RX), 114 | and you need use the `--triggertx` option: 115 | 116 | $ python3 exposure-notification.py --triggertx 117 | 118 | 119 | Other options: 120 | 121 | You can set the duration of a cycle, and the duration of scanning within a cycle, with these options: 122 | 123 | -c CYCLETIME, --cycletime CYCLETIME 124 | duration (in seconds) of one cycle 125 | -s SCANTIME, --scantime SCANTIME 126 | duration (in seconds) of the scanning within one cycle 127 | 128 | If you do not specify options, the script will use these durations: 129 | 130 | $ python3 exposure-notification.py -c 300 -s 2 131 | 132 | The script will always scan in steps of 2 seconds. 133 | 134 | You can choose to have a raw RX data file created (`rx_raw_data.csv`) with option `-r` / `--storerawdata`: 135 | 136 | $ python3 exposure-notification.py --storerawdata 137 | 138 | You can opt to _not_ advertise your own RPI beacons: 139 | 140 | -n, --notx do not transmit RPI beacons via BLE 141 | 142 | If you have a GPS connected to the Raspberry Pi which is supported by gpsd, you can use these options: 143 | 144 | -d, --gpsdatetime set date and time from GPS 145 | -g, --gpsposition store GPS position with RX data 146 | 147 | Running the Script at Startup 148 | ----------------------------- 149 | 150 | If you want to run the script every time the Raspberry Pi starts up, you can e.g. make __systemd__ run the script 151 | when the boot sequence has finished (and Bluetooth has been activated). 152 | 153 | There's a sample Service Unit file in this repo: 154 | [exposure-notification.service](linux-startup/exposure-notification.service). Modify this with the command line 155 | parameters you need and then: 156 | 157 | $ sudo cp linux-startup/exposure-notification.service /lib/systemd/system/ 158 | $ sudo chmod 644 /lib/systemd/system/exposure-notification.service 159 | $ sudo systemctl daemon-reload 160 | $ sudo systemctl enable exposure-notification.service 161 | $ sudo reboot 162 | 163 | Read the log with 164 | 165 | $ journalctl -e -u exposure-notification.service 166 | 167 | Limitations 168 | ----------- 169 | Our own TX power level is read, but only printed, not used for setting the AEM value. That's not a big deal, 170 | because the value that can be read is always the same (+12 dBm on Raspberry Pi 3B+ and Zero W - which is strange 171 | because the Bluetooth spec lists a maximum of 10dBm). 172 | I initially planned to read and use this value, but then had to split the `ENTxService` object so that a 173 | separate script starts the TX beacon, `pybleno` stops at the end of this script, and we can do `sudo hciconfig hci0 down; 174 | sudo hciconfig hci0 up` when the BLE stack temporarily stops working. 175 | 176 | ----- 177 | 178 | _Disclaimer: All views expressed are my own personal opinions. All information is provided "as is", with no guarantee of 179 | completeness, accuracy, timeliness or of the results obtained from the use of this information._ 180 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | --------------------------------------------------------------------------------