Mit Sammlungen den Überblick behalten
Sie können Inhalte basierend auf Ihren Einstellungen speichern und kategorisieren.
Authentifizierungscode der Nachricht
Mit Nachrichtenstreams wird der Audio-Wechsel konfiguriert, siehe
Nachrichten beim Audiowechsel: Für diese wichtigen Konfigurationen muss der Anbieter
um sicherzustellen, dass die Nachricht über GMSCore (Modul für schnelles Pairing) und nicht über
anderen App auf dem Seeker.
MAC (Nachrichtenauthentifizierungscode) generieren
FP Seeker fügt einen Nachrichtenauthentifizierungscode für Gerätekonfigurationsnachrichten hinzu
mit HMAC-SHA256. Der MAC der Nachricht besteht aus den ersten 8 Byte der folgenden Elemente:
sha256(concat((K ^ opad), sha256(concat((K ^ ipad), concat(nonce, message)))))
Bitte wo?
- K wird durch concat(Kontoschlüssel, 48-Byte-NULL-Werte) generiert.
- message sind die zusätzlichen Daten des Nachrichtenstreams.
- nonce wird generiert von concat(session_nonce, message_nonce); Sitzung
Nonce- und Nachrichten-Nonce werden im folgenden Abschnitt definiert.
- opad entspricht 64 Byte des äußeren Paddings, bestehend aus wiederkehrenden Byte mit dem Wert
0x5C
- ipad umfasst 64 Byte für das innere Padding, bestehend aus wiederholten, bewerteten Byte
0x36
Sitzungs-Nonce und -Nachrichten-Nonce
Um einen Replay-Angriff zu verhindern, muss der Provider dafür sorgen, dass eine Nonce nicht
wiederholt. Da die Uhr- oder Zählersynchronisierung
bei beiden Providern läuft,
und Seeker nicht einfach ist, generiert der Anbieter die Sitzungs-Nonce.
(pro Verbindung), die während der Verbindung mit allen Nachrichten geteilt wird,
während der Seeker die Nonce (pro Nachricht) generiert.
die für jede Nachricht generiert werden. Die Nonce zum Generieren der MAC-Adresse jeder Nachricht ist
die Kombination aus Sitzungs-Nonce und Nachrichten-Nonce, d.h.
concat(session_nonce; message_nonce).
Wir fügen der Ereignisgruppe „Geräteinformationen“ eine Sitzungs-Nonce hinzu:
Name der Nachrichtengruppe |
Wert |
Ereignis „Geräteinformationen“ |
0x03 |
Name des Nachrichtencodes |
Wert |
Sitzungs-Nonce |
0x0A |
Die Sitzungs-Nonce sollte generiert und an den Seeker gesendet werden, wenn RFCOMM
verbindet:
Oktett |
Datentyp |
Beschreibung |
Wert |
0 |
uint8 |
Ereignis „Geräteinformationen“ |
0x03 |
1 |
uint8 |
Sitzungs-Nonce |
0x0A |
2–3 |
uint16 |
Zusätzliche Datenlänge |
0x0008 |
4–11 |
|
Sitzungs-Nonce |
variiert |
Zum Senden einer Nachricht, wenn ein MAC erforderlich ist, sendet der Seeker eine Nachrichten-Nonce
und den MAC zusammen mit der Nachricht.
Oktett |
Datentyp |
Beschreibung |
Wert |
0 |
uint8 |
Nachrichtengruppe |
variiert |
1 |
uint8 |
Nachrichtencode |
variiert |
2–3 |
uint16 |
Zusätzliche Datenlänge(die zusätzliche Datenlänge + 16) |
variiert |
4–n |
|
Zusätzliche Daten |
variiert |
n + 1 – n + 8 |
|
Nachrichten-Nonce |
variiert |
n + 9 – n + 16 |
|
Authentifizierungscode der Nachricht |
variiert |
MAC (Message Authentication Code) prüfen
Nach dem Empfang einer Nachricht mit dem Nachrichtenauthentifizierungscode
soll es mit derselben Funktion wie die Generierungsfunktion überprüfen. Das heißt:
muss der empfangene MAC den ersten 8 Bytes der
sha256(concat((K ^ opad), sha256(concat((K ^ ipad), concat(section_nonce, message_nonce, message)))))
Dabei gilt:
- K wird von
concat(account key, 48-byte ZEROs)
und dem Anbieter generiert
alle gespeicherten Kontoschlüssel zur Verifizierung des MAC durchlaufen müssen.
- message sind die zusätzlichen Daten (ohne Nachrichten-Nonce und MAC) von
Nachrichtenstreams an.
Wenn der MAC korrekt ist, folgt der Anbieter den Anweisungen der
angezeigt. Andernfalls sendet der Anbieter ein NAK mit dem Fehlergrund, 0x3 -
nicht zulässig aufgrund eines falschen Nachrichtenauthentifizierungscodes.
Sofern nicht anders angegeben, sind die Inhalte dieser Seite unter der Creative Commons Attribution 4.0 License und Codebeispiele unter der Apache 2.0 License lizenziert. Weitere Informationen finden Sie in den Websiterichtlinien von Google Developers. Java ist eine eingetragene Marke von Oracle und/oder seinen Partnern.
Zuletzt aktualisiert: 2025-08-13 (UTC).
[[["Leicht verständlich","easyToUnderstand","thumb-up"],["Mein Problem wurde gelöst","solvedMyProblem","thumb-up"],["Sonstiges","otherUp","thumb-up"]],[["Benötigte Informationen nicht gefunden","missingTheInformationINeed","thumb-down"],["Zu umständlich/zu viele Schritte","tooComplicatedTooManySteps","thumb-down"],["Nicht mehr aktuell","outOfDate","thumb-down"],["Problem mit der Übersetzung","translationIssue","thumb-down"],["Problem mit Beispielen/Code","samplesCodeIssue","thumb-down"],["Sonstiges","otherDown","thumb-down"]],["Zuletzt aktualisiert: 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."]]