Zadbaj o dobrą organizację dzięki kolekcji
Zapisuj i kategoryzuj treści zgodnie ze swoimi preferencjami.
Kod uwierzytelniania wiadomości
Strumienie wiadomości służą do konfigurowania przełącznika dźwięku, patrz sekcja
Komunikaty dotyczące przełączania dźwięku. W przypadku tych ważnych konfiguracji dostawca potrzebuje
aby upewnić się, że wiadomość została wysłana przez GMSCore (moduł Szybkiego parowania), a nie przez
innej aplikacji na stronie Seeker.
Wygeneruj MAC (kod uwierzytelniania wiadomości)
FP Seeker dodaje kod uwierzytelniania wiadomości do wiadomości o konfiguracji urządzenia
z zastosowaniem algorytmu HMAC-SHA256. Adres MAC wiadomości składa się z pierwszych 8 bajtów:
sha256(concat((K ^ opad), sha256(concat((K ^ ipad), concat(nonce, message)))))
gdzie
- K jest generowany przez funkcję concat(klucz konta, 48-bajtowy ZERO).
- Atrybut message to dodatkowe dane strumienia wiadomości.
- Parametr nonce jest generowany przez parametr concat(session_nonce, message_nonce); sesja
Liczba jednorazowa i liczba jednorazowa z wiadomością są zdefiniowane w następnej sekcji.
- opad to 64 bajty zewnętrznego dopełnienia, na które składają się powtórzone bajty o określonej wartości.
0x5C
- ipad to 64 bajty wewnętrznego dopełnienia, z którego powtórzono wartości w bajtach.
0x36
Liczba jednorazowa sesji i jednorazowa z wiadomością
Aby zapobiec ponownemu atakowi, Dostawca musi sprawdzić, czy liczba jednorazowa nie jest
powtórzenia. Ponieważ synchronizacja zegara lub licznika odbywa się u obu dostawców
a Poszukiwacz nie jest prosty, Dostawca generuje liczbę jednorazową sesji
(na połączenie), która jest udostępniana wszystkim wiadomościom podczas połączenia,
natomiast Searchker generuje liczbę jednorazową (dla każdej wiadomości), która jest losowa.
generowanej dla każdej wiadomości. Liczba jednorazowa do wygenerowania MAC każdej wiadomości to
kombinację liczby jednorazowej sesji i jednorazowej wiadomości, tj.
concat(session_nonce, message_nonce).
Do grupy zdarzeń Informacje o urządzeniu dodajemy liczbę jednorazową sesji:
Nazwa grupy wiadomości |
Wartość |
Zdarzenie dotyczące informacji o urządzeniu |
0x03 |
Nazwa kodu wiadomości |
Wartość |
Liczba jednorazowa sesji |
0x0A |
Jednorazowa sesja powinna zostać wygenerowana i wysłana do Seekera, gdy RFCOMM
łączy:
Oktet |
Typ danych |
Opis |
Wartość |
0 |
uint8 |
Zdarzenie z informacjami o urządzeniu |
0x03 |
1 |
uint8 |
Liczba jednorazowa sesji |
0x0A |
2–3 |
uint16 |
Dodatkowa długość danych |
0x0008 |
4–11 |
|
liczba jednorazowa w sesji |
różni się |
Aby wysłać wiadomość, gdy wymagany jest adres MAC, Seeker wysyła wiadomość jednorazową
i MAC oraz wiadomości.
Oktet |
Typ danych |
Opis |
Wartość |
0 |
uint8 |
Grupa wiadomości |
różni się |
1 |
uint8 |
Kod wiadomości |
różni się |
2–3 |
uint16 |
Dodatkowa długość danych(dodatkowa długość danych + 16) |
różni się |
4–n |
|
Dodatkowe dane |
różni się |
N + 1 – n + 8 |
|
Liczba jednorazowa z wiadomości |
różni się |
n + 9 – n + 16 |
|
Kod uwierzytelniania wiadomości |
różni się |
Weryfikacja MAC (kodu uwierzytelniania wiadomości)
Po otrzymaniu wiadomości z kodem uwierzytelniającym
powinien ją zweryfikować za pomocą tej samej funkcji co funkcja generująca. To znaczy,
odebrany adres MAC powinien być równy pierwszych 8 bajtach
sha256(concat((K ^ opad), sha256(concat((K ^ ipad), concat(section_nonce, message_nonce, message)))))
gdzie:
- K jest generowane przez firmę
concat(account key, 48-byte ZEROs)
, a Dostawca
powinno przejrzeć wszystkie przechowywane klucze konta, aby zweryfikować adres MAC.
- Atrybut message to dodatkowe dane (z wyłączeniem liczby jednorazowej wiadomości i adresu MAC)
w strumieniu wiadomości.
Jeśli adres MAC jest poprawny, Dostawca musi postępować zgodnie z instrukcjami
. W przeciwnym razie Dostawca wyśle NAK z przyczyną błędu (0x3) –
niedozwolone z powodu nieprawidłowego kodu uwierzytelniania wiadomości.
O ile nie stwierdzono inaczej, treść tej strony jest objęta licencją Creative Commons – uznanie autorstwa 4.0, a fragmenty kodu są dostępne na licencji Apache 2.0. Szczegółowe informacje na ten temat zawierają zasady dotyczące witryny Google Developers. Java jest zastrzeżonym znakiem towarowym firmy Oracle i jej podmiotów stowarzyszonych.
Ostatnia aktualizacja: 2025-08-13 UTC.
[[["Łatwo zrozumieć","easyToUnderstand","thumb-up"],["Rozwiązało to mój problem","solvedMyProblem","thumb-up"],["Inne","otherUp","thumb-up"]],[["Brak potrzebnych mi informacji","missingTheInformationINeed","thumb-down"],["Zbyt skomplikowane / zbyt wiele czynności do wykonania","tooComplicatedTooManySteps","thumb-down"],["Nieaktualne treści","outOfDate","thumb-down"],["Problem z tłumaczeniem","translationIssue","thumb-down"],["Problem z przykładami/kodem","samplesCodeIssue","thumb-down"],["Inne","otherDown","thumb-down"]],["Ostatnia aktualizacja: 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."]]