Skip to content

Instantly share code, notes, and snippets.

@Baael
Created October 10, 2024 14:50
Show Gist options
  • Save Baael/e90cace542e040a43d110b2d6d3cba57 to your computer and use it in GitHub Desktop.
Save Baael/e90cace542e040a43d110b2d6d3cba57 to your computer and use it in GitHub Desktop.
node red, recognize Apple watch by mac address
[
{
"id":"49fa25707cf3cc77",
"type":"subflow",
"name":"IOS Device recognizer",
"info":"As paylaod it takes public random mac address of apple watch in format: '000000000000'\r\nReturns payload true or false\r\n",
"category":"",
"in":[
{
"x":120,
"y":180,
"wires":[
{
"id":"109002fdb83ae811"
}
]
}
],
"out":[
{
"x":440,
"y":180,
"wires":[
{
"id":"109002fdb83ae811",
"port":0
}
]
}
],
"env":[
{
"name":"IRK",
"type":"cred",
"ui":{
"icon":"font-awesome/fa-lock",
"label":{
"en-US":"IRK"
},
"type":"input",
"opts":{
"types":[
"cred"
]
}
}
}
],
"meta":{
"author":"Wojciech Zieliński"
},
"color":"#DDAA99"
},
{
"id":"109002fdb83ae811",
"type":"function",
"z":"49fa25707cf3cc77",
"name":"function 329",
"func":"const irk = Buffer.from(env.get(\"IRK\"), 'base64').reverse()\nconst cipher = crypto.createCipheriv('aes-128-ecb', irk, null);\n\nfunction bleTrackerCb(_addr) {\n\n const addrBytes = Buffer.from(_addr, 'hex');\n const pt = Buffer.alloc(16, 0);\n\n pt[15] = addrBytes[2];\n pt[14] = addrBytes[1];\n pt[13] = addrBytes[0];\n\n const encrypted = cipher.update(pt);\n\n return (encrypted[15] === addrBytes[5] && encrypted[14] === addrBytes[4] && encrypted[13] === addrBytes[3])\n}\n\n\nreturn {\n payload: bleTrackerCb(msg.payload)\n}\n",
"outputs":1,
"timeout":0,
"noerr":0,
"initialize":"",
"finalize":"",
"libs":[
{
"var":"crypto",
"module":"crypto"
}
],
"x":290,
"y":180,
"wires":[
[
]
]
},
{
"id":"72cf0a8f2300e542",
"type":"subflow:49fa25707cf3cc77",
"z":"0f74c4179fdeaf10",
"name":"Watch recognizer",
"env":[
{
"name":"IRK",
"type":"cred"
},
{
"name":"RETURN_VALUE",
"value":"true",
"type":"bool"
}
],
"x":1240,
"y":340,
"wires":[
[
]
]
},
{
"id":"4b89db7aae5047e9",
"type":"comment",
"z":"0f74c4179fdeaf10",
"name":"Packet data",
"info":"Packet data:\nAn example of the Nearby Info message (in hex) split for easier reading: 4c00 10 05 01 98 86b356, where\n\n4c00 is Apple's manufacturer identifier. All Apple BLE broadcasts start with this 16-bit number\n10 identifies the Nearby Info message\n05 is the length: 5 bytes to follow\n01 is the status flags and action code. Appears to be in the range 01 .. 0F\n98 the Data flags. If the watch is unlocked it is 98, and if locked (e.g. on night stand, not on wrist) then it is 18\n86b356 is 3 byte Authentication tag. There is no useful info here as it changes continuously",
"x":1210,
"y":300,
"wires":[
]
}
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment