{"record":{"id":"40438d5ff66f1f47","repo":"AlexxIT/go2rtc","slug":"xiaomi-unsupported-encryption","errorCode":null,"errorMessage":"xiaomi: unsupported encryption","messagePattern":"xiaomi: unsupported encryption","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/xiaomi/legacy/client.go","lineNumber":233,"sourceCode":"\n\treturn fmt.Errorf(\"xiaomi: unsupported model: %s\", c.model)\n}\n\nfunc (c *Client) StopMedia() error {\n\treturn errors.Join(\n\t\tc.WriteCommandJSON(cmdVideoStop, `{}`),\n\t\tc.WriteCommand(cmdVideoStop, make([]byte, 8)),\n\t)\n}\n\nfunc DecodeVideo(data, key []byte) ([]byte, error) {\n\tif string(data[:4]) == \"\\x00\\x00\\x00\\x01\" || data[8] == 0 {\n\t\treturn data, nil\n\t}\n\n\tif data[8] != 1 {\n\t\t// Support could be added, but I haven't seen such cameras.\n\t\treturn nil, fmt.Errorf(\"xiaomi: unsupported encryption\")\n\t}\n\n\tnonce8 := data[:8]\n\ti1 := binary.LittleEndian.Uint32(data[9:])\n\ti2 := binary.LittleEndian.Uint32(data[13:])\n\tdata = data[17:]\n\tsrc := data[i1 : i1+i2]\n\n\tfor i := 32; i+16 < len(src); i += 160 {\n\t\tdst, err := crypto.DecodeNonce(src[i:i+16], nonce8, key)\n\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t\tcopy(src[i:], dst) // copy result in same place\n\t}\n\n\treturn data, nil\n}","sourceCodeStart":215,"sourceCodeEnd":251,"githubUrl":"https://github.com/AlexxIT/go2rtc/blob/c245815e75e2a5fd60b4290f12bfc04e55a984d3/pkg/xiaomi/legacy/client.go#L215-L251","documentation":"DecodeVideo can decrypt the standard encryption variant (data[8]==1) and pass through unencrypted frames, but frames with some other encryption byte are not supported. The library explicitly notes support could be added but such cameras are rare.","triggerScenarios":"Calling DecodeVideo (directly or via ReadPacket) on a video frame whose 9th byte is neither 0 nor 1, indicating an unknown encryption variant.","commonSituations":"Using the library with a camera firmware that encrypts video with a different scheme; decoding streams recorded from a non-standard camera model.","solutions":["Update camera firmware to a version using the supported encryption scheme","Patch DecodeVideo in pkg/xiaomi/legacy/client.go to implement the additional variant (data[8] values other than 0/1)","Use a model/firmware combination known to produce standard frames","Fall back to the camera's non-TUTK stream if available"],"exampleFix":null,"handlingStrategy":"fallback","validationCode":"// inspect frame encryption byte before decoding\nif len(frame) > 8 && frame[8] != 0 && frame[8] != 1 {\n    return errors.New(\"unsupported frame encryption variant\")\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Pin camera firmware to versions using the supported encryption scheme","Handle unknown encryption bytes gracefully by skipping frames","Track upstream support for additional variants"],"tags":["xiaomi","video","encryption"],"backgroundTag":"unsupported-operation","analyzedSha":"c245815e75e2a5fd60b4290f12bfc04e55a984d3","analyzedAt":"2026-09-07T11:47:02.965Z","contentChangedAt":"2026-09-07T11:47:02.965Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}