Organiza tus páginas con colecciones
Guarda y categoriza el contenido según tus preferencias.
Código de autenticación de mensajes
Las transmisiones de mensajes se usan para configurar el cambio de audio. Consulta
Mensajes de cambio de audio: Para estas configuraciones importantes, el proveedor necesita
asegurarte de que el mensaje lo envíe GMSCore (módulo de Vinculación rápida) y no cualquier
otra app en Seeker.
Generar MAC (código de autenticación de mensajes)
FP Seeker agrega un código de autenticación de mensajes para los mensajes de configuración del dispositivo
con HMAC-SHA256. El MAC del mensaje consta de los primeros 8 bytes de lo siguiente:
sha256(concat((K ^ opad), sha256(concat((K ^ ipad), concat(nonce, message)))))
en el que
- K es generado por concat(clave de la cuenta, ceros de 48 bytes).
- message son los datos adicionales de flujo de mensajes.
- nonce se genera por concat(session_nonce, message_nonce); sesión
El nonce y el nonce del mensaje se definen en la siguiente sección.
- opad es un conjunto de 64 bytes de relleno externo, que consta de bytes repetidos valorados.
0x5C
- ipad es un conjunto de 64 bytes de padding interno, que consta de bytes repetidos valorados.
0x36
Nonce de sesión y nonce de mensaje
Para evitar un ataque de repetición, el proveedor debe asegurarse de que no se
repetido. Ya que se mantiene la sincronización del reloj o del contador en ambos proveedores,
y Seeker no es sencillo, el proveedor genera el nonce de sesión
(por conexión), que se comparte con todos los mensajes durante la conexión
mientras que el buscador genera el nonce de mensaje (por mensaje), que se genera de forma aleatoria
que se genera para cada mensaje. El nonce para generar el MAC de cada mensaje se
la combinación del nonce de sesión y el nonce del mensaje, p.ej.,
concat(nonce_sesión, nonce_mensaje).
Agregamos un nonce de sesión al grupo de eventos Información del dispositivo:
Nombre del grupo de mensajes |
Valor |
Evento de información del dispositivo |
0x03 |
Nombre del código del mensaje |
Valor |
Nonce de sesión |
0 × 0 A |
El nonce de sesión se debe generar y enviar al Seeker cuando se use el RFCOMM
conecta:
Octeto |
Tipo de datos |
Descripción |
Valor |
0 |
uint8 |
Evento de información del dispositivo |
0x03 |
1 |
uint8 |
Nonce de sesión |
0 × 0 A |
2 - 3 |
uint16 |
Longitud de los datos adicionales |
0 × 0008 |
4 - 11 |
|
nonce de sesión |
varía |
Para enviar un mensaje cuando se requiere un MAC, el Buscador enviará un nonce de mensaje
y el MAC junto con el mensaje.
Octeto |
Tipo de datos |
Descripción |
Valor |
0 |
uint8 |
Grupo de mensajes |
varía |
1 |
uint8 |
Código de mensaje |
varía |
2 - 3 |
uint16 |
Longitud de los datos adicionales(la longitud de los datos adicionales + 16) |
varía |
4: n |
|
Datos adicionales |
varía |
n + 1 - n + 8 |
|
Nonce del mensaje |
varía |
n + 9 - n + 16 |
|
Código de autenticación de mensajes |
varía |
Verificar MAC (código de autenticación de mensajes)
Cuando recibe un mensaje con el código de autenticación de mensajes, el Proveedor
debes verificarlo con la misma función que la que genera. Es decir,
el MAC recibido debe ser igual a los primeros 8 bytes de
sha256(concat((K ^ opad), sha256(concat((K ^ ipad), concat(section_nonce, message_nonce, message)))))
Donde:
concat(account key, 48-byte ZEROs)
genera K, y el proveedor
debe recorrer todas las claves de cuentas almacenadas para verificar la MAC.
- message son los datos adicionales (excluidos el nonce del mensaje y el MAC) de
el flujo de mensajes.
Si la MAC es correcta, el Proveedor seguirá las instrucciones del
mensaje. De lo contrario, el Proveedor enviará una NAK con el motivo del error, 0x3:
no se permite debido a un código de autenticación de mensajes incorrecto.
Salvo que se indique lo contrario, el contenido de esta página está sujeto a la licencia Atribución 4.0 de Creative Commons, y los ejemplos de código están sujetos a la licencia Apache 2.0. Para obtener más información, consulta las políticas del sitio de Google Developers. Java es una marca registrada de Oracle o sus afiliados.
Última actualización: 2025-08-13 (UTC)
[[["Fácil de comprender","easyToUnderstand","thumb-up"],["Resolvió mi problema","solvedMyProblem","thumb-up"],["Otro","otherUp","thumb-up"]],[["Falta la información que necesito","missingTheInformationINeed","thumb-down"],["Muy complicado o demasiados pasos","tooComplicatedTooManySteps","thumb-down"],["Desactualizado","outOfDate","thumb-down"],["Problema de traducción","translationIssue","thumb-down"],["Problema con las muestras o los códigos","samplesCodeIssue","thumb-down"],["Otro","otherDown","thumb-down"]],["Última actualización: 2025-08-13 (UTC)"],[[["\u003cp\u003eMessage Authentication Codes (MACs) are used to verify that Fast Pair configuration messages originate from Google Mobile Services (GMSCore) and not other apps.\u003c/p\u003e\n"],["\u003cp\u003eMACs are generated using HMAC-SHA256, incorporating session and message nonces to prevent replay attacks.\u003c/p\u003e\n"],["\u003cp\u003eProviders initiate a session nonce upon RFCOMM connection and seekers generate a unique message nonce for each message.\u003c/p\u003e\n"],["\u003cp\u003eTo verify a message, providers compute the MAC using the received data and compare it with the received MAC, using stored account keys for verification.\u003c/p\u003e\n"],["\u003cp\u003eIf MAC verification fails, the provider sends a NAK message indicating an incorrect authentication code.\u003c/p\u003e\n"]]],["Message Authentication Code (MAC) ensures messages originate from GMSCore. The Seeker generates a MAC using HMAC-SHA256, derived from a key (K), nonce, and message data. The nonce combines a per-connection session nonce (Provider-generated) and a per-message nonce (Seeker-generated). The Seeker transmits the message nonce and MAC with each message. The Provider verifies the MAC using the same function and stored keys, acting on the message only if the MAC is correct. If not, a NAK is sent.\n"],null,["Message Authentication Code\n---------------------------\n\n[Message streams](/nearby/fast-pair/specifications/extensions/messagestream#MessageStream \"message stream\") are used to configure Audio switch, see\n[Audio switch messages](/nearby/fast-pair/specifications/extensions/sass#MacOfSassMessages \"MAC of Audio switch Messages\"). For these important configurations, the Provider needs\nto ensure that the message is sent by GMSCore (Fast Pair module) and not any\nother app on the Seeker.\n| **Note:** Google recommends implementing the [Cryptographic Test Cases](/nearby/fast-pair/specifications/appendix/cryptotestcases \"Link to the Cryptographic Test Cases.\") to ease verification of these requirements.\n\n### Generate MAC (message authentication code)\n\nFP Seeker adds a message authentication code for device configuration messages\nusing HMAC-SHA256. The MAC of the message consists of the first 8 bytes of: \n\n sha256(concat((K ^ opad), sha256(concat((K ^ ipad), concat(nonce, message)))))\n\nwhere\n\n1. *K* is generated by concat(account key, 48-byte ZEROs).\n2. *message* is the additional data of Message stream.\n3. *nonce* is generated by concat(session_nonce, message_nonce); session nonce and message nonce are defined in the following section.\n4. *opad* is 64 bytes of outer padding, consisting of repeated bytes valued `0x5C`.\n5. *ipad* is 64 bytes of inner padding, consisting of repeated bytes valued `0x36`.\n\n### Session nonce and message nonce\n\nTo prevent a replay attack, the Provider needs to ensure that a nonce is not\nrepeated. Since maintaining clock or counter synchronization on both Provider\nand Seeker is not straightforward, the Provider generates the session nonce\n(per connection), which is shared with all messages during the connection,\nwhile the Seeker generates the message nonce (per message), which is randomly\ngenerated for each message. The nonce for generating the MAC of each message is\nthe combination of session nonce and message nonce, i.e.\nconcat(session_nonce, message_nonce).\n\nWe add a session nonce to the Device information event group:\n\n| Message Group Name | Value |\n|--------------------------|-------|\n| Device information event | 0x03 |\n\n| Message Code Name | Value |\n|-------------------|-------|\n| Session nonce | 0x0A |\n\nThe session nonce should be generated and sent to the Seeker when RFCOMM\nconnects:\n\n| Octet | Data Type | Description | Value |\n|--------|-----------|--------------------------|----------|\n| 0 | uint8 | Device information event | 0x03 |\n| 1 | uint8 | Session nonce | 0x0A |\n| 2 - 3 | uint16 | Additional data length | 0x0008 |\n| 4 - 11 | | session nonce | *varies* |\n\nTo send a message when a MAC is required, the Seeker will send a message nonce\nand the MAC together with the message.\n\n| Octet | Data Type | Description | Value |\n|----------------|-----------|---------------------------------------------------------|----------|\n| 0 | uint8 | Message group | *varies* |\n| 1 | uint8 | Message code | *varies* |\n| 2 - 3 | uint16 | Additional data length(the additional data length + 16) | *varies* |\n| 4 - n | | Additional data | *varies* |\n| n + 1 - n + 8 | | Message nonce | *varies* |\n| n + 9 - n + 16 | | Message authentication code | *varies* |\n\n### Verify MAC (message authentication code)\n\nUpon receiving a message with the message authentication code, the Provider\nshall verify it by using the same function as the generating function. That is,\nthe received MAC should be equal to the first 8 bytes of \n\n sha256(concat((K ^ opad), sha256(concat((K ^ ipad), concat(section_nonce, message_nonce, message)))))\n\nwhere:\n\n1. *K* is generated by `concat(account key, 48-byte ZEROs)`, and the Provider shall traverse all stored account keys to verify the MAC.\n2. *message* is the additional data (excluding message nonce and MAC) of the Message stream.\n\nIf the MAC is correct, then the Provider shall follow the instruction of the\nmessage. Otherwise, the Provider shall send a NAK with the error reason, 0x3 -\nnot allowed due to incorrect message authentication code."]]