分布式“无网络”传感器|由Apple AirTag对未来物联网的展望

无论从世界局势还是技术革新等层面,当今世界正在经历百年未有之大变局,移动互联的底层技术、算法,数学世界微妙的定理,可知世界那些看不见的事物,却往往成为现代社会不可替代的数字化和信息化互联网的基石。

从ESP8266自组织网络谈起 ESP-WIFI-MESH

ESP-WIFI-MESH 是一种无线通信网络,采用树状拓扑结构,其节点具有乐鑫 SoC 的 AP-STA 特性。ESP-WIFI-MESH 能够提供一个易于部署、自动组网并自我修复的网络。它无需部署 Wi-Fi 基础设施,就能在更大范围内部署节点,基于这种网络拓扑结构,它最多可以扩展到 1000 个节点。这样一来,ESP-WIFI-MESH 也可用于在家庭部署中覆盖 Wi-Fi 信号无法到达的盲点。

esp8266,wifi模块,玩嵌入式的应该都不陌生,一个esp8266作为一个node,可以部署一个自组织的网络,此网络少数node掉线不会影响整个网络的通信,设备能够根据节点信号的强度值自动连接信号强的节点,在网络故障时仍保证网络的稳定性,这也是ESP-WIFI-MESH的自我修复特性。

分布式、去中心化、共识

在计算机技术领域,去中心化结构使用分布式核算和存储,不存在中心化的节点,任意节点的权利和义务都是均等的,系统中的数据块由整个系统中具有维护功能的节点来共同维护,任一节点停止工作都不会影响系统整体的运作。
去中心化是分布式网络结构中的一种,所有的去中心化都是采用分布式网络结构的,而分布式网络结构可能是“中心化”也可能是“去中心化”的

1.png

去中心化和共识是两个不同的概念,两者结合才是真正意义上的“去中心化”,去中心化有了共识才具备了完全的可信度,否则只是狭义概念的数据共享,没人知道这些共享的数据是否真实,或者被集体认可,仅仅只是拥有这些信息;共识有了去中心化,就具备了安全性,系统很难被攻破,信息也难被篡改;再加上特殊的数据结构,而这一切的实现就是区块链。

Apple Find my:一种更广泛的分布式位置网络

Overnight, Apple has turned its hundreds-of­million-device ecosystem into the world’s largest crowd­sourced location tracking network called offine finding (OF). OF leverages online finder devices to detect the presence of missing onine devices using Bluetooth and report an approximate location back to the owner via the Internet. While OF is not the first system of its kind, it is the first to commit to strong privacy goals. In particular, OF aims to ensure finder anonymity, un­trackability of owner devices, and confidentiality of lo­cation reports.

熟悉苹果设备和苹果生态的朋友,应该对“查找”这一功能并不陌生,只要是使用同一 Apple ID 登录的设备,当你不慎将其丢失或遗忘位置时,即可使用“查找”对其定位或发出声响,特殊情况下还可以选择抹除资料避免信息泄露。

得益于全世界苹果设备的保有量(全球活跃约18亿台,截至2022年1月28日),以及全球的广泛分布¹, 苹果的Find My已经作为icloud基础设施使用,利用庞大的用户量、广泛分布的苹果设备,用户可以获得比Android等其他移动设备更好的设备查找和定位体验。

AirTag是苹果公司于2021年4月21日凌晨在2021苹果春季新品发布会上推出的一款蓝牙跟踪设备。

Airtag的离线查找恰好利用了Find My网络,可以在世界任意角落找到你丢失的Airtag(理论上)

Apple的查找(Find My)网络工作原理

德国达姆施塔特的公立大学(Technical University of Darmstadt)的移动网络安全实验室(Secure Mobile Networking Lab)在2019年6月开始对苹果的Find My 进行逆向工程和安全分析,大部分研究结果在2021年3月公开,期间发现的最严重的一个漏洞CVE-2020-9986 (允许恶意软件访问位置数据)已经被苹果修复

在发布论文的时候,他们开源了一个叫做OpenHaystack的项目,这个开源项目可以让你创建自己的配件,被苹果的Find My网络跟踪

openhaystack mac端

苹果的“查找”功能利用蓝牙广播,公钥加密技术以及中心加密的位置报告数据库,基于椭圆曲线加密算法(Elliptic Curve Cryptography)的安全性, 私钥在用户手中,苹果声称位置报告、查找设备标志 被加密和隐藏了,并且蓝牙广播无法直接用于跟踪用户,安全性和隐私性没有任何问题。

简单介绍一下椭圆曲线加密算法

对称加密和非对称加密

对称加密(Symmetric-key algorithm)指加密和解密使用相同密钥的加密算法。常见的对称加密算法有DES、3DES、AES

非对称加密(public-key cryptography OR asymmetric cryptography)是加密和解密使用不同密钥,使用公钥/私钥对中的公钥来加密明文,然后使用对应的私钥来解密密文的过程。RSA、Elgamal、背包算法、Rabin、Diffie-Hellman、ECC属于非对此加密,使用最广泛的是RSA算法

椭圆曲线加密算法(Elliptic Curve Cryptography)

椭圆曲线加密算法,简称ECC,是基于椭圆曲线数学理论实现的一种非对称加密算法。相比RSA,ECC优势是可以使用更短的密钥,来实现与RSA相当或更高的安全,RSA加密算法也是一种非对称加密算法,在公开密钥加密和电子商业中RSA被广泛使用。RSA算法是当前最流行也是最明了的公钥密码学系统。它的安全性基于因式分解的缓慢和乘法的快速的事实上。

什么是椭圆曲线?

Wolfram MathWorld(线上数学百科全书,http://mathworld.wolfram.com) 给出了非常精准的定义:
一条椭圆曲线就是一组被 y2=x3+ax+b定义的且满足 4a3+27b20 的点集。

4a3+27b20 这个限定条件是为了保证曲线不包含奇点(在数学中是指曲线上任意一点都存在切线)。

阿贝尔群(abelian group)

阿贝尔群的概念是抽象代数的基本概念之一,是一种代数结构,由一个集合以及一个二元运算所组成。
如果一个集合或者运算是群的话,就必须满足以下条件(+ 表示二元运算):

  1. 封闭性(closure),如果a和b被包含于群,那么a+b也一定是群的元素;
  2. 结合律(associativity);
  3. 存在一个单位元(identity element)0,0与任意元素运算不改变其值的元素,即 a+0=0+a=a
  4. 每个元素都存在一个逆元(inverse);
  5. 交换律(commutativity),即 a+b=b+a

椭圆曲线中的阿贝尔群

我们可以在椭圆曲线上定义一个群:

  1. 群中的元素就是椭圆曲线上的点;
  2. 单位元就是无穷处的点0;
  3. 相反数P,是关于X轴对称的另一边的点;
  4. 二元运算规则定义如下:取一条直线上的三点(这条直线和椭圆曲线相交的三点),P, Q, R(皆非零),他们的总和等于0,P+Q+R=0

可以证明,椭圆曲线符合阿贝尔群。

因为在安全性、加解密性能、网络消耗方面有较大优势,ECC加密算法大有取代RSA成为下一代主流加密算法的趋势。如今ECC应用范围很广,在TLS、区块链(比特币、以太坊等等)、SM2国密算法、证书、银行政府机构等许多方面都有大量应用。

椭圆曲线算法涉及阿贝尔群、有限群等群论知识,密钥交换涉及伽罗瓦域,具体的细节比较复杂,这里就不过多展开了,详细可以参考这篇论文:ECIES

椭圆曲线加解密算法原理

设私钥、公钥分别为d、Q,即Q=dG,其中G为基点,椭圆曲线上的已知G和dG,求d是非常困难的,也就是说已知公钥和基点,想要算出私钥是非常困难的。
公钥加密:选择随机数r,将消息M生成密文C,该密文是一个点对,C=rG,M+rQ,其中Q为公钥。
私钥解密:
M+rQd(rG)=M+r(dG)d(rG)=M,其中d、Q分别为私钥、公钥。

Find My 工作原理

  1. AirTag跟苹果设备配对的时候,保留在AirTag上的公钥和用于生成滚动公钥的共享密钥一起生成椭圆曲线密钥对
  2. 每2秒,AirTag用上一步的共享密钥(这个每15分钟会更新一次),发送一个以公钥为内容的低功耗蓝牙广播
  3. 附近的iphone,macbook之类的可是识别Find My广播的设备,对搜索他当前的位置,然后用广播的公钥加密位置信息,然后上传这个加密的位置报告
  4. 在搜索设备的时候,这个设备的配对多有着,会生成AirTag这几天用的滚动公钥列表,并且查询苹果服务来获得他的SHA256哈希值,苹果的后台就会返回所请求密钥的加密位置报告
    那么设备的所有者就可以解密位置报告并且显示大致的位置

这种做法有一些安全上的特性:

  • 滚动公钥可以保护附近的设备
  • 苹果官方无法访问用户位置

苹果是不知道哪些公钥是属于你的AirTag设备的,因此他也不知道哪些位置报告是你的,所以你去请求特定密钥的位置报告,是不需要授权的,知道密钥就可以直接要。同时位置报告通过了加密,所以就只能用存在配对的所有者设备上的私钥要解密。

OF(offline finding) employs elliptic curve cryptography (ECC) for en­crypting location reports. ECC is a public-key encryp­tion scheme that uses operations on elliptic curve (EC) over finite fields. An EC is a curve over a finite field that contains a known generator (or base point) G. A private key in ECC is a random number in the finite field of the used curve. The public key is the result of the point multiplication of the generator G with the pri­vate key. The result is an X–Y coordinate on the curve. The NIST P-224 curve [39], which is used by OF [6], provides a security level of 112 bit.

使用Apple Find My在“无网络”环境发送任意文本数据

原文地址

Send My: Arbitrary data transmission via Apple’s Find My network

With the recent release of Apple’s AirTags, I was curious whether Find My’s Offline Finding network could be (ab)used to upload arbitrary data to the Internet, from devices that are not connected to WiFi or mobile internet. The data would be broadcasted via Bluetooth Low Energy and picked up by nearby Apple devices, that, once they are connected to the Internet, forward the data to Apple servers where it could later be retrieved from. Such a technique could be employed by small sensors in uncontrolled environments to avoid the cost and power-consumption of mobile internet. It could also be interesting for exfiltrating data from Faraday-shielded sites that are occasionally visited by iPhone users.

作者在Openhaystack的基础上进行二次开发

通过给附近的苹果设备发送Find My蓝牙广播,可以让没有互联网连接的设备上传数据

用ESP32做了一个上传数据的网关,并且还写了一个macOS的程序来接收数据,ESP32固件以及macOS程序在github上开源

大概是怎么实现的呢?

编码发送

To send a full message, the program simply loops over its bits and sends out one advertisement per bit with the public key that encodes its index and value.

  1. 假设有一个message需要发送
  2. 每次取出这个message的第index位比特值value
  3. 用index和value,以及消息ID和补充的0位,构成一个公钥
  4. 用蓝牙将这个公钥广播出去
  5. 一直循环直到这个message的所有比特位都全部发送完成就好了

接收解码

When fetching data, the receiving application will generate the same 28-byte arrays (two per bit, for the possible bit values 0 and 1) and query the Apple service with the SHA256 hashes of those “public keys”. Only one of the two key ids should have location reports attached, which can then be interpreted (e.g. bit at index 0 equals 1).

  1. 假设我们要接受一个message,我们需要确定这个message每个比特位是0还是1
  2. 按照index顺序,生成跟上一步一样的公钥,但是我们不知道最后的比特位是0还是1,这是我们要最终接收的目标数据,因此最后的比特位,按照0生成一个公钥,按照1生成一个公钥
  3. 用这个公钥的SHA256值去苹果的服务上查,看一下哪些公钥是能查到位置报告的
  4. 有位置报告的公钥,就是有效的,没有位置报告的公钥就是无效
  5. 将有效的公钥按照index排列最后的比特位,即可得到数据

性能

The sending rate on the microcontroller is currently ~3 bytes/second

the receiving rate was limited by slow Mac hardware. Retrieving 16 bytes within one request takes ~5 seconds

The latency is usually between 1 and 60 minutes depending on how many devices are around and other random factors.

发送速率大概3字节/秒,接收16字节大概需要5秒,跟人说话速率差不多,不过如果用于环境传感器(温湿度气压)数据的话,这个速率可以接受

延迟大概1~60分钟不等,取决于周围苹果设备的数量。

实际的应用与网络安全防范

技术永远是把双刃剑,这个在未来信息化和数字化的时代会越来越凸显。

最大的应用场景就是没有网络的物联网设备LOT,没有手机SIM卡,没有蜂窝数据,没有Wifi的低功耗嵌入式设备

物理隔离的环境,法拉第笼屏蔽电磁的环境,某些保密要害部位,这些地方就算安全也可能泄密,因为访客的苹果设备可能会将信息泄漏出去,因为这些地方就算没有互联网或者手机信号,也有可能被访客的苹果设备缓存在设备中,直到这些设备再次连接互联网后,缓存的信息就会被发送出去。

这也是保密要害部位和一些物理隔离的重要涉密场所不让带手机进入的重要原因,某些重点保密单位不让使用苹果设备的原因也是如此,因为这些技术目前没有特定的解决方案,只能防范,毕竟国家安全至上,保守国家秘密是每个公民的基本义务。

While I was mostly just curious about whether it would be possible, I would imagine the most common use case to be uploading sensor readings or any data from IoT devices without a broadband modem, SIM card, data plan or Wifi connectivity. With Amazon running a similar network called Sidewalk that uses Echo devices there might very well be demand for it. Since the Finding devices cache received broadcasts until they have an Internet connection, the sensors can even send out data from areas without mobile coverage as long as people pass the area.

In the world of high-security networks, where combining lasers and scanners seems to be a noteworthy technique to bridge the airgap, the visitor’s Apple devices might also become feasible intermediaries to exfiltrate data from certain airgapped systems or Faraday caged rooms.

It also seems like the Offline Finding protocol could be used to deplete nearby iPhone’s mobile data plans. With the number of location reports from a Finder device being limited (to 255 reports/submission due to a 1 byte count value) and each report being over 100 byte, broadcasting many unique public keys should result in an amplified amount of mobile traffic sent by the phone. While I haven’t noticed any rate limiting on the number of location reports sent out, I also haven’t tested how much data this would consume.

最新的项目进展

This project uses OpenHaystack to upload sensor data from a device without internet connection by (ab)using Apple’s Find My network. The data is broadcasted via Bluetooth Low Energy and forwarded by nearby Apple devices.

The application is based on the Send My project and runs on the real-time operating system Zephyr. Because this firmware is based on Zephyr, you can create your own sensor boards with one of the many Bluetooth Low Energy devices that Zephyr supports.

After flashing the firmware to your device, it sends out Bluetooth Low Energy advertisements with sensor data that will be visible in Send My’s DataFetcher application in macOS.

https://github.com/koenvervloesem/send-my-sensor

这个开源项目实现的是Zephyr设备发送“无网络”传感器数据,目前还在开发阶段,基本固件已经完成。

截至2022-2-13,已经实现了一个低功耗嵌入式设备传输气压传感器的数据了,通信协议是i2c,源码修改之后就能适应各种传感器了

未来的物联网传感器网络发展方向

如上文所示,如果要自主建立这样一个分布式传感器网络,基础设施是很重要的,如果能有一个像苹果Find My的软硬件生态的话,当然更好,通过物联网从网络基础设施的接入,可以大大降低传感器网络的成本,实现大范围部署传感器网络.

展望一下未来,超低功耗MESH工业物联网,户外接入设备无需高功耗的通信协议,通过蓝牙BLE接入互联网的应用层,这层物联网直接不依赖于经典的OSI 参考7层模型,或者TCP/IP 5层协议栈,通过这些分布式的AC(acess point)接入互联网,实现万物互联。

参考文献及资料(References)

[1] Alexander Heinrich, Milan Stute, Tim Kornhuber, Matthias Hollick. Who Can Find My Devices? Security and Privacy of Apple’s Crowd-Sourced Bluetooth Location Tracking System. Proceedings on Privacy Enhancing Technologies (PoPETs), 2021. doi:10.2478/popets-2021-0045 📄 Paper 📄 Preprint.

[2] Apple Inc. Find My Network Accessory Specification – Developer Preview – Release R3. 2020. 📄 Download.

[3] 椭圆曲线加密算法原理解析(ECC)https://segmentfault.com/a/1190000019172260

[4] ESP-WIFI-MESH 概览| 乐鑫科技 https://www.espressif.com/zh-hans/products/sdks/esp-wifi-mesh/overview

[5] OpenHaystack project https://github.com/seemoo-lab/openhaystack

[6] FABIAN BRÄUNLEIN , Positive Security. send my: arbitrary data transmission via apple’s find my network. https://positive.security/blog/send-my