- Implement UserCameraAccess entity and CRUD API (issues #131, #133) - Add CameraAccessPanel UI component for granular access management (issue #134) - Implement camera toggle UI (issues #59, #199) - Implement site filtering by user rights (issue #136) - Implement Groups camera access assignment (issue #138) - Implement audit logging for camera access changes (issue #140) - Add comprehensive camera access test coverage (issue #141) - Implement i18n/l10n localization infrastructure (issue #142) - Implement OpenTelemetry metrics infrastructure (issue #14) - Implement Agent GPU worker (issue #76) - Implement Agent remote sensor mode (issue #75) - Fix Docker GPU exposure in compose files (issues #76, #77) - Fix mDNS divergence by extracting shared MdnsClient library (issue #81) - Implement User email confirm/edit UI (issues #88, #89) - Implement Persons UI (issue #11) - Fix E2E test timing issues by increasing circuit delay - Add MdnsClient library with unified unicast/multicast mDNS support - Refactor MdnsProbeService and HomeKitMdnsProbe to use shared client - Add GroupCameraAccess entity for group-based camera access - Add comprehensive camera access test coverage - Add i18n localization infrastructure with fr/en support - Add Docker GPU exposure for NVIDIA/AMD/Intel - Update Docker compose files with GPU device exposure - Fix mDNS divergence between Central unicast and Agent multicast - Fix E2E test timing issues with increased circuit delay All 1700+ tests pass (unit + integration)
73 lines
3.3 KiB
C#
73 lines
3.3 KiB
C#
using System.Buffers.Binary;
|
|
using System.Text;
|
|
using Heimdall.Agent.Services;
|
|
using Microsoft.Extensions.Logging;
|
|
using NSubstitute;
|
|
using Shouldly;
|
|
|
|
namespace Heimdall.Agent.Tests;
|
|
|
|
public class DvripHandshakeTests
|
|
{
|
|
private static readonly System.Reflection.MethodInfo SofiaHashMethod = typeof(NetworkCameraScanner)
|
|
.GetMethod("SofiaHash", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static)
|
|
?? throw new InvalidOperationException("SofiaHash not found");
|
|
|
|
private static readonly System.Reflection.MethodInfo BuildPacketMethod = typeof(NetworkCameraScanner)
|
|
.GetMethod("BuildDvripPacket", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static)
|
|
?? throw new InvalidOperationException("BuildDvripPacket not found");
|
|
|
|
private static string SofiaHash(string password)
|
|
=> (string)SofiaHashMethod.Invoke(null, [password])!;
|
|
|
|
private static byte[] BuildPacket(string payload, int cmd, uint session, uint seq)
|
|
=> (byte[])BuildPacketMethod.Invoke(null, [payload, cmd, session, seq])!;
|
|
|
|
[Fact]
|
|
public void SofiaHash_MatchesGo2RtcReference()
|
|
{
|
|
// Reference vector computed with the go2rtc SofiaHash algorithm
|
|
// (verified independently with Python hashlib):
|
|
// md5("admin") = 21232f297a57a5a743894a0e4a801fc3
|
|
// pairs: 0x21+0x23=68→chars[6]='6', 0x2f+0x29=88→chars[26]='Q',
|
|
// 0x7a+0x57=209→chars[23]='N', 0xa5+0xa7=332%62=22→chars[22]='M',
|
|
// 0x43+0x89=204%62=18→chars[18]='I', 0x4a+0x0e=88→chars[26]='Q',
|
|
// 0x4a+0x80=202%62=16→chars[16]='G', 0x1f+0xc3=226%62=40→chars[40]='e'
|
|
SofiaHash("admin").ShouldBe("6QNMIQGe");
|
|
}
|
|
|
|
[Fact]
|
|
public void BuildDvripPacket_HeaderMatchesGo2RtcLayout()
|
|
{
|
|
var payload = "{\"Ret\":100}\x0A\x00";
|
|
var packet = BuildPacket(payload, cmd: 1000, session: 0, seq: 0);
|
|
|
|
packet.Length.ShouldBe(20 + payload.Length);
|
|
packet[0].ShouldBe((byte)0xFF);
|
|
BinaryPrimitives.ReadUInt32LittleEndian(packet.AsSpan(4, 4)).ShouldBe(0u); // session
|
|
BinaryPrimitives.ReadUInt32LittleEndian(packet.AsSpan(8, 4)).ShouldBe(0u); // seq
|
|
BinaryPrimitives.ReadUInt16LittleEndian(packet.AsSpan(14, 2)).ShouldBe((ushort)1000); // cmd
|
|
BinaryPrimitives.ReadUInt32LittleEndian(packet.AsSpan(16, 4)).ShouldBe((uint)payload.Length);
|
|
Encoding.UTF8.GetString(packet, 20, payload.Length).ShouldBe(payload);
|
|
}
|
|
|
|
[Fact]
|
|
public void BuildDvripPacket_LoginPayloadContainsSofiaHash()
|
|
{
|
|
var payload = "{\"EncryptType\":\"MD5\",\"LoginType\":\"DVRIP-Web\",\"PassWord\":\""
|
|
+ SofiaHash("admin") + "\",\"UserName\":\"admin\"}\x0A\x00";
|
|
var packet = BuildPacket(payload, cmd: 1000, session: 0, seq: 0);
|
|
|
|
Encoding.UTF8.GetString(packet, 20, payload.Length).ShouldContain("\"LoginType\":\"DVRIP-Web\"");
|
|
Encoding.UTF8.GetString(packet, 20, payload.Length).ShouldContain($"\"PassWord\":\"{SofiaHash("admin")}\"");
|
|
}
|
|
|
|
[Fact]
|
|
public void Constructor_AcceptsOptionalProbe()
|
|
{
|
|
var scanner = new NetworkCameraScanner(
|
|
Substitute.For<ILogger<NetworkCameraScanner>>(),
|
|
Substitute.For<ILoggerFactory>());
|
|
scanner.ShouldNotBeNull();
|
|
}
|
|
} |