feat(calls): implement Linux LAN peer calls over SRTP
Reuse existing ChatHub consent and Podcast LibVLC capture for direct bidirectional H.264/AAC media, with embedded call controls and cleanup. Require HTTPS key exchange and reject IP-masking policies for this opt-in LAN/VPN transport. Add native SRTP, signaling and lifecycle tests; document setup and remaining physical-device validation. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
parent
5e48831d6d
commit
cc28ee8b29
20 changed files with 1394 additions and 29 deletions
|
|
@ -1,4 +1,6 @@
|
|||
using System.Security.Claims;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Http.Connections.Features;
|
||||
using Microsoft.AspNetCore.Http.Features;
|
||||
using Microsoft.AspNetCore.SignalR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
|
@ -32,7 +34,8 @@ public sealed class CallHubTests
|
|||
_services = new ServiceCollection().AddLogging().AddLocalization().BuildServiceProvider();
|
||||
Calls = new(Delivery, Options.Create(new AudioVideoCallOptions
|
||||
{
|
||||
Enabled = true, TurnUrls = ["turn:turn.example.test:3478"], TurnSharedSecret = "test-only"
|
||||
Enabled = true, EnableLanCalls = true,
|
||||
TurnUrls = ["turn:turn.example.test:3478"], TurnSharedSecret = "test-only"
|
||||
}), TimeProvider.System, NullLogger<CallSignalingService>.Instance);
|
||||
Db.Users.AddRange(
|
||||
new ApplicationUser { Id = "alice-id", UserName = "alice", Email = "alice@example.test" },
|
||||
|
|
@ -55,6 +58,36 @@ public sealed class CallHubTests
|
|||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Lan_requires_https_at_invitation_acceptance_and_key_exchange()
|
||||
{
|
||||
using var f = new Fixture();
|
||||
using var caller = f.Hub("alice", "alice-1");
|
||||
using var callee = f.Hub("bob", "bob-1");
|
||||
await Assert.ThrowsAsync<HubException>(() => caller.InviteLanCall("General", "bob"));
|
||||
Assert.Empty(f.Delivery.Messages);
|
||||
var http = new DefaultHttpContext();
|
||||
http.Request.Scheme = "https";
|
||||
caller.Context.Features.Set<IHttpContextFeature>(new HttpFeature(http));
|
||||
var call = await caller.InviteLanCall("General", "bob");
|
||||
await Assert.ThrowsAsync<HubException>(() => callee.AcceptCall(call.Id));
|
||||
callee.Context.Features.Set<IHttpContextFeature>(new HttpFeature(http));
|
||||
await callee.AcceptCall(call.Id);
|
||||
var endpoint = new CallSignal("rtp-endpoint",
|
||||
Endpoint: new("192.168.1.2", 5004, new string('a', 32), new string('b', 28)));
|
||||
http.Request.Scheme = "http";
|
||||
await Assert.ThrowsAsync<HubException>(() => caller.SendCallSignal(call.Id, endpoint));
|
||||
Assert.DoesNotContain(f.Delivery.Messages, m => m.Method == CallHubMethods.SignalReceived);
|
||||
http.Request.Scheme = "https";
|
||||
await caller.SendCallSignal(call.Id, endpoint);
|
||||
Assert.Single(f.Delivery.Messages, m => m.Method == CallHubMethods.SignalReceived);
|
||||
}
|
||||
|
||||
private sealed class HttpFeature(HttpContext context) : IHttpContextFeature
|
||||
{
|
||||
public HttpContext? HttpContext { get; set; } = context;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Invitation_requires_existing_accounts_presence_and_the_authenticated_connection()
|
||||
{
|
||||
|
|
|
|||
116
src/test/Yavsc.Server.Tests/CallLanSignalingTests.cs
Normal file
116
src/test/Yavsc.Server.Tests/CallLanSignalingTests.cs
Normal file
|
|
@ -0,0 +1,116 @@
|
|||
using Microsoft.AspNetCore.SignalR;
|
||||
using Microsoft.Extensions.Logging.Abstractions;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Yavsc.Abstract.Chat.Calls;
|
||||
using Yavsc.Services;
|
||||
using Yavsc.Settings;
|
||||
|
||||
namespace Yavsc.Server.Tests;
|
||||
|
||||
public sealed class CallLanSignalingTests
|
||||
{
|
||||
private static LanCallEndpoint Endpoint(string address = "192.168.1.2", int port = 5004) =>
|
||||
new(address, port, new string('a', 32), new string('b', 28));
|
||||
|
||||
private static CallSignalingService Service(RecordingCallHub hub, bool enabled = true) =>
|
||||
new(hub, Options.Create(new AudioVideoCallOptions { Enabled = true, EnableLanCalls = enabled }),
|
||||
TimeProvider.System, NullLogger<CallSignalingService>.Instance);
|
||||
|
||||
[Theory]
|
||||
[InlineData(false, false)]
|
||||
[InlineData(true, true)]
|
||||
public async Task Disabled_lan_or_ip_masking_prevents_invitation(bool enabled, bool relay)
|
||||
{
|
||||
var hub = new RecordingCallHub();
|
||||
using var service = Service(hub, enabled);
|
||||
await Assert.ThrowsAsync<HubException>(() =>
|
||||
service.InviteAsync("General", "alice", "bob", "a", ["b"], relay, CallTransports.LanSrtp));
|
||||
Assert.Empty(hub.Messages);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Ip_masking_activated_before_acceptance_blocks_the_lan_call()
|
||||
{
|
||||
var hub = new RecordingCallHub();
|
||||
using var service = Service(hub);
|
||||
var call = await service.InviteAsync("General", "alice", "bob", "a", ["b"], false, CallTransports.LanSrtp);
|
||||
await Assert.ThrowsAsync<HubException>(() => service.AcceptAsync(call.Id, "bob", "b", true));
|
||||
Assert.DoesNotContain(hub.Messages, m => m.Method == CallHubMethods.Accepted);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Endpoints_are_exchanged_only_once_between_consented_devices_without_ice_credentials()
|
||||
{
|
||||
var hub = new RecordingCallHub();
|
||||
using var service = Service(hub);
|
||||
var call = await service.InviteAsync("General", "alice", "bob", "a", ["b", "other"], false, CallTransports.LanSrtp);
|
||||
Assert.Equal(CallTransports.LanSrtp, call.Transport);
|
||||
var first = new CallSignal("rtp-endpoint", Endpoint: Endpoint());
|
||||
var second = new CallSignal("rtp-endpoint", Endpoint: Endpoint("10.0.0.2"));
|
||||
await Assert.ThrowsAsync<HubException>(() => service.SignalAsync(call.Id, "alice", "a", first));
|
||||
await service.AcceptAsync(call.Id, "bob", "b", false);
|
||||
Assert.Empty(Assert.IsType<CallAccepted>(hub.Messages.Last().Arguments[0]).IceServers);
|
||||
await Assert.ThrowsAsync<HubException>(() => service.SignalAsync(call.Id, "bob", "other", second));
|
||||
await service.SignalAsync(call.Id, "alice", "a", first);
|
||||
await service.SignalAsync(call.Id, "bob", "b", second);
|
||||
var sent = hub.Messages.Where(m => m.Method == CallHubMethods.SignalReceived).ToArray();
|
||||
Assert.Equal(2, sent.Length);
|
||||
Assert.Equal(["b"], sent[0].Targets);
|
||||
Assert.Equal(["a"], sent[1].Targets);
|
||||
await Assert.ThrowsAsync<HubException>(() => service.SignalAsync(call.Id, "alice", "a", first));
|
||||
await service.EndAsync(call.Id, "alice", "a");
|
||||
await Assert.ThrowsAsync<HubException>(() => service.SignalAsync(call.Id, "bob", "b", second));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Lan_transport_rejects_sdp_candidates_and_mixed_endpoint_payloads()
|
||||
{
|
||||
var hub = new RecordingCallHub();
|
||||
using var service = Service(hub);
|
||||
var call = await service.InviteAsync("General", "alice", "bob", "a", ["b"], false, CallTransports.LanSrtp);
|
||||
await service.AcceptAsync(call.Id, "bob", "b", false);
|
||||
CallSignal[] invalid =
|
||||
[
|
||||
new("offer", "v=0\r\nm=audio 9 UDP/TLS/RTP/SAVPF 111\r\n"),
|
||||
new("candidate", Candidate: "candidate:1 1 udp 100 192.168.1.1 5004 typ host"),
|
||||
new("rtp-endpoint"), new("rtp-endpoint", Sdp: "injected", Endpoint: Endpoint()),
|
||||
new("rtp-endpoint", Endpoint: Endpoint() with { Key = new string('x', 32) }),
|
||||
new("rtp-endpoint", Endpoint: Endpoint() with { Salt = "short" }),
|
||||
new("rtp-endpoint", Endpoint: Endpoint("8.8.8.8")),
|
||||
new("rtp-endpoint", Endpoint: Endpoint(port: 5005))
|
||||
];
|
||||
foreach (var signal in invalid)
|
||||
await Assert.ThrowsAsync<HubException>(() => service.SignalAsync(call.Id, "alice", "a", signal));
|
||||
Assert.DoesNotContain(hub.Messages, m => m.Method == CallHubMethods.SignalReceived);
|
||||
Assert.Throws<HubException>(() => CallSignalValidator.Validate(
|
||||
new("offer", "v=0\r\nm=audio 9 UDP/TLS/RTP/SAVPF 111\r\n", Endpoint: Endpoint()), false));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("10.1.2.3", true)]
|
||||
[InlineData("172.16.0.1", true)]
|
||||
[InlineData("172.31.255.254", true)]
|
||||
[InlineData("192.168.1.2", true)]
|
||||
[InlineData("127.0.0.1", true)]
|
||||
[InlineData("172.32.0.1", false)]
|
||||
[InlineData("169.254.169.254", false)]
|
||||
[InlineData("8.8.8.8", false)]
|
||||
[InlineData("224.0.0.1", false)]
|
||||
[InlineData("0.0.0.0", false)]
|
||||
[InlineData("::1", false)]
|
||||
[InlineData("localhost", false)]
|
||||
[InlineData("127.1", false)]
|
||||
[InlineData("192.168.1.2,port=80", false)]
|
||||
public void Only_canonical_private_or_loopback_ipv4_endpoints_are_allowed(string address, bool expected) =>
|
||||
Assert.Equal(expected, Endpoint(address).IsValid());
|
||||
|
||||
[Fact]
|
||||
public void Credentials_are_not_exposed_by_record_diagnostics()
|
||||
{
|
||||
var endpoint = Endpoint();
|
||||
var diagnostic = new CallSignal("rtp-endpoint", Endpoint: endpoint).ToString();
|
||||
Assert.DoesNotContain(endpoint.Key, diagnostic);
|
||||
Assert.DoesNotContain(endpoint.Salt, diagnostic);
|
||||
Assert.DoesNotContain(endpoint.Address, diagnostic);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue