קל לארגן דפים בעזרת אוספים
אפשר לשמור ולסווג תוכן על סמך ההעדפות שלך.
קוד אימות הודעה
שידורי הודעות משמשים להגדרת החלפת האודיו.
הודעות על החלפת אודיו. בשביל ההגדרות החשובות האלה, הספק צריך
כדי לוודא שההודעה נשלחת על ידי GMSCore (מודול התאמה מהירה) ולא על ידי
אפליקציה אחרת ב-Seeker.
יצירת MAC (קוד אימות הודעה)
שירות FP לחיפוש מוסיף קוד אימות להודעות לגבי הגדרות המכשיר
באמצעות HMAC-SHA256. ה-MAC של ההודעה מכיל את 8 הבייטים הראשונים של:
sha256(concat((K ^ opad), sha256(concat((K ^ ipad), concat(nonce, message)))))
איפה
- הערך K נוצר באמצעות concat(account key, 48-byte ZEROs).
- הפרמטר message הוא הנתונים הנוספים של מקור ההודעות.
- הפרמטר nonce נוצר על ידי concat(session_nonce, message_nonce); חיבור
צופן חד-פעמי (nonce) ו-מסר של הודעה מוגדרים בקטע הבא.
- הפרמטר opad מכיל 64 בייטים של המרווח הפנימי החיצוני, שמורכב מבייטים חוזרים.
0x5C
.
- ל-ipad יש 64 בייטים של מרווח פנימי פנימי שמורכב מבייטים חוזרים.
0x36
.
צופן חד-פעמי (nonce) של סשן
כדי למנוע התקפת הפעלה חוזרת, הספק צריך לוודא שלא
שחוזרת על עצמה. מאז תחזוקת השעון או סנכרון המונה אצל שני הספק
והמחפש לא פשוט, הספק יוצר את הסשן צופן חד-פעמי
(לכל חיבור), שמשותף עם כל ההודעות במהלך החיבור,
בזמן שה-Finder יוצר את ההודעה (nonce) באופן אקראי
שנוצר לכל הודעה. ה-nonce ליצירת ה-MAC של כל הודעה הוא
את השילוב של צופן חד-פעמי (nonce) ו-מסר של הודעה (nonce), כלומר
concat(session_nonce, message_nonce).
אנחנו מוסיפים צופן סשן לקבוצת האירועים של פרטי המכשיר:
שם קבוצת ההודעות |
ערך |
אירוע של פרטי מכשיר |
0x03 |
שם קוד ההודעה |
ערך |
צופן חד-פעמי (nonce) |
0x0A |
יש ליצור את הצופן החד-פעמי (nonce) של הסשן ולשלוח אותו ל-Finder כאשר RFCOMM
מחברת:
אוקטט |
סוג הנתונים |
תיאור |
ערך |
0 |
uint8 |
אירוע של פרטי מכשיר |
0x03 |
1 |
uint8 |
צופן חד-פעמי (nonce) |
0x0A |
2 - 3 |
uint16 |
אורך נתונים נוסף |
0x0,008 |
4 - 11 |
|
צופן חד-פעמי (nonce) |
משתנה |
כדי לשלוח הודעה כשיש צורך ב-MAC, המחפש ישלח הודעה צופן חד-פעמי
וה-MAC יחד עם ההודעה.
אוקטט |
סוג הנתונים |
תיאור |
ערך |
0 |
uint8 |
קבוצה של הודעות |
משתנה |
1 |
uint8 |
קוד הודעה |
משתנה |
2 - 3 |
uint16 |
אורך נתונים נוספים(אורך הנתונים הנוספים + 16) |
משתנה |
4 - n |
|
נתונים נוספים |
משתנה |
n + 1 - n + 8 |
|
הודעה חד-פעמית |
משתנה |
n + 9 - n + 16 |
|
קוד אימות להודעות |
משתנה |
אימות ה-MAC (קוד אימות ההודעה)
עם קבלת הודעה עם קוד אימות ההודעה, הספק
יאמת אותו באמצעות אותה פונקציה כמו פונקציית היצירה. כלומר,
כתובת ה-MAC שהתקבלה צריכה להיות שווה ל-8 הבייטים הראשונים של
sha256(concat((K ^ opad), sha256(concat((K ^ ipad), concat(section_nonce, message_nonce, message)))))
איפה:
- הערך K נוצר על ידי
concat(account key, 48-byte ZEROs)
, והספק
יצטרך לעבור את כל מפתחות החשבון המאוחסנים כדי לאמת את ה-MAC.
- message הוא הנתונים הנוספים (לא כולל הודעות צופן חד-פעמי (nonce) ו-MAC) של
בזרם ההודעות.
אם ה-MAC נכון, הספק יפעל לפי ההוראות
הודעה. אחרת, הספק ישלח מספר NAK עם סיבת השגיאה, 0x3 -
אין הרשאה בגלל קוד אימות שגוי של הודעה.
אלא אם צוין אחרת, התוכן של דף זה הוא ברישיון Creative Commons Attribution 4.0 ודוגמאות הקוד הן ברישיון Apache 2.0. לפרטים, ניתן לעיין במדיניות האתר Google Developers. Java הוא סימן מסחרי רשום של חברת Oracle ו/או של השותפים העצמאיים שלה.
עדכון אחרון: 2025-08-13 (שעון UTC).
[[["התוכן קל להבנה","easyToUnderstand","thumb-up"],["התוכן עזר לי לפתור בעיה","solvedMyProblem","thumb-up"],["סיבה אחרת","otherUp","thumb-up"]],[["חסרים לי מידע או פרטים","missingTheInformationINeed","thumb-down"],["התוכן מורכב מדי או עם יותר מדי שלבים","tooComplicatedTooManySteps","thumb-down"],["התוכן לא עדכני","outOfDate","thumb-down"],["בעיה בתרגום","translationIssue","thumb-down"],["בעיה בדוגמאות/בקוד","samplesCodeIssue","thumb-down"],["סיבה אחרת","otherDown","thumb-down"]],["עדכון אחרון: 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."]]