Bootstrap

GFPS扩展技术原理(九)-FMDN beacon action Write

FMDN

FMDN也就是Find My Device Network,它定义了一种端对端的加密方式来定位跟踪BLE beacon设备,说白了就是一种通过BLE来定位跟踪设备位置的技术,苹果也搞了一个类似的技术叫Find My。要实现这个技术,Provider需要满足FMDN的规范和打开定位功能。

GATT 特征值

Provider会作为BLE beacon发专门为FMDN定制的广播,所以我们需要特意定义一个额外的GATT特征值“beacon action”,UUID为0x1238,定义如下:

Fast Pair Service characteristicEncryptedPermissionsUUID
Beacon actionsNoRead, write and notifyFE2C1238-8366-4814-8EB0-01DE32100BEA

认证

当Seeker需要写Provider的beacon action特征值的时候,我们会通过挑战-响应机制来认证。首先Seeker会去读取beacon action特征值,然后Provider会返回9个字节,一个字节协议版本和8字节的一次性随机数,然后Seeker会利用这个随机数和版本号,account key等参数通过SHA-256产生的结果,取前8个字节生成一个一次性的认证码,Seeker后面发起的写操作,都会带上这个8字节的认证码,Provider需要进行认证,如果认证通过,那么会返回Seeker想要的结果,否则返回认证失败。在操作beacon action特征值时,我们会涉及到以下6个key:

  1. Account key:这个就是我们GFPS定义的账户key。
  2. Owner account key:就是Provider里面存在多个account key的时候,我们需要选择其中的一个account key,在操作beacon action特征值时加密数据。这个account key一般都是第一次配对或者最近使用的account key。
  3. Ephemeral identity key (EIK):这是个临时密钥,用来加密位置信息的,是Seeker在FMDN配置过程中设置的一个32字节随机数,这个密钥不会保存在云端。
  4. Recovery key:这个是保存在云端,万一Seeker在某些情况把EIK给弄丢了,可以通过Seeker发送Recovery key给Provider,Provider把EIK发送给Seeker。它的计算方法是:SHA256(ephemeral identity key || 0x01)的结果取前8个字节。
  5. Ring key:这个是让Provider响铃的key,存储在云端。他的计算方法是:取SHA256(ephemeral identity key || 0x02)结果的前8个字节。
  6. Unwanted tracking protection key:这个key是用来激活unwanted tracking protection mode的,保存在云端。它的计算方法是:取SHA256(ephemeral identity key || 0x03)结果的前8个字节。

beacon action写操作

Seeker写beacon action特征值,我们总共定义了九个命令,根据Data ID来区分,如下:

  1. Read beacon parameters:
字节数据类型描述
0uint8Data ID0x0
1uint8Data length8
2 - 9byte arrayOne-time authentication keyThe first 8 bytes of HMAC-SHA256(account key, protocol major version number || the last nonce read from the characteristic || data ID || data length || additional data)
  1. Read provisioning state:
字节数据类型描述
0uint8Data ID0x1
1uint8Data length8
2 - 9byte arrayOne-time authentication keyThe first 8 bytes of HMAC-SHA256(account key, protocol major version number || the last nonce read from the characteristic || data ID || data length || additional data)
  1. Set ephemeral identity key:
字节数据类型描述
0uint8Data ID0x2
1uint8Data length16或者40
2 - 9byte arrayOne-time authentication keyThe first 8 bytes of HMAC-SHA256(account key, protocol major version number || the last nonce read from the characteristic || data ID || data length || additional data)
10 - 41byte arrayAdditional data32 字节的ephemeral identity key, 利用account key AES-ECB-128方式加密.如果Provider已经存在 ephemeral identity key, 那么就发送 SHA256(current ephemeral identity key || the last nonce read from the characteristic) 的前8个字节。
  1. Clear ephemeral identity key:
字节数据类型描述
0uint8Data ID0x3
1uint8Data length16
2 - 9byte arrayOne-time authentication keyThe first 8 bytes of HMAC-SHA256(account key, protocol major version number || the last nonce read from the characteristic || data ID || data length || additional data)
10 - 17byte arrayAdditional data取 SHA256(current ephemeral identity key || the last nonce read from the characteristic) 结果的前8个字节。
  1. Recovery ephemeral identity key with user consent:
字节数据类型描述
0uint8Data ID0x4
1uint8Data length8
2 - 9byte arrayOne-time authentication keyThe first 8 bytes of HMAC-SHA256(account key, protocol major version number || the last nonce read from the characteristic || data ID || data length || additional data)
  1. Ring:
字节数据类型描述
0uint8Data ID0x5
1uint8Data length12
2 - 9byte arrayOne-time authentication keyThe first 8 bytes of HMAC-SHA256(account key, protocol major version number || the last nonce read from the characteristic || data ID || data length || additional data)
10uint8Ring operationA bitmask having the following values:
Bit 1 (0x01): Ring right
Bit 2 (0x02): Ring left
Bit 3 (0x04): Ring case
0xFF: Ring all components
0x00: Stop ringing
11 - 12uint16TimeoutThe timeout in deciseconds. Must not be zero and must not be greater than the equivalent of 10 minutes.
The Provider uses this value to determine how long it should ring before silencing itself. The timeout overrides the one already in effect if any component of the device is already ringing.If ring operation is set to 0x00, the timeout is ignored.
13uint8Volume0x00: Default
0x01: Low
0x02: Medium
0x03: High
The exact meaning of these values is implementation dependent.
  1. Read ringing state:
字节数据类型描述
0uint8Data ID0x6
1uint8Data length8
2 - 9byte arrayOne-time authentication keyThe first 8 bytes of HMAC-SHA256(account key, protocol major version number || the last nonce read from the characteristic || data ID || data length || additional data)
  1. Activate unwanted tracking protection mode:
字节数据类型描述
0uint8Data ID0x7
1uint8Data length8或者9
2 - 9byte arrayOne-time authentication keyThe first 8 bytes of HMAC-SHA256(account key, protocol major version number || the last nonce read from the characteristic || data ID || data length || additional data)
10uint8Control Flags这是一个可选的字节,0x01: Skip ringing authentication. When set, ringing requests aren’t authenticated while in unwanted tracking protection mode.
  1. Deactivate unwanted tracking protection mode:
字节数据类型描述
0uint8Data ID0x8
1uint8Data length16
2 - 9byte arrayOne-time authentication keyThe first 8 bytes of HMAC-SHA256(account key, protocol major version number || the last nonce read from the characteristic || data ID || data length || additional data)
10 - 17byte arrayAdditional data取 SHA256(current ephemeral identity key || the last nonce read from the characteristic) 结果的前8个字节。
;