Encryption Sent, Encrpytion Decoded, Offer Sent, Offer Recieved, JS -> C# / C# -> JS Broke (some disconnect here) SendRtcSignalToJsAsync
This commit is contained in:
@@ -122,6 +122,27 @@ public class ChatSocketBehavior : WebSocketBehavior
|
||||
return;
|
||||
}
|
||||
|
||||
string plainText;
|
||||
|
||||
try
|
||||
{
|
||||
plainText = E2EeHelper.DecryptForRecipient(
|
||||
new EncryptedPayload
|
||||
{
|
||||
CipherText = clientPayload.CipherText,
|
||||
Nonce = clientPayload.Nonce,
|
||||
Tag = clientPayload.Tag,
|
||||
EncryptedKey = clientPayload.EncryptedKey
|
||||
},
|
||||
ServerPrivateKey
|
||||
);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"Failed to decrypt RTC signal: {ex.Message}");
|
||||
return;
|
||||
}
|
||||
|
||||
var sessionIds = RtcChannelPresenceService.GetSessionsInChannel(clientPayload.ChannelId);
|
||||
|
||||
foreach (var sessionId in sessionIds)
|
||||
@@ -129,7 +150,28 @@ public class ChatSocketBehavior : WebSocketBehavior
|
||||
if (sessionId == ID)
|
||||
continue;
|
||||
|
||||
Sessions.SendTo(JsonSerializer.Serialize(clientPayload), sessionId);
|
||||
var username = RtcChannelPresenceService.GetUsernameForSession(sessionId);
|
||||
if (string.IsNullOrWhiteSpace(username))
|
||||
continue;
|
||||
|
||||
var clientKey = GetClientPublicKeyByUsernameSync(username);
|
||||
if (clientKey is null)
|
||||
continue;
|
||||
|
||||
var encrypted = E2EeHelper.EncryptForRecipient(plainText, clientKey.PublicKey);
|
||||
|
||||
var outbound = new SocketRtcSignalMessage
|
||||
{
|
||||
Type = SignalType.EncryptedSignal,
|
||||
SenderUsername = clientPayload.SenderUsername,
|
||||
ChannelId = clientPayload.ChannelId,
|
||||
CipherText = encrypted.CipherText,
|
||||
Nonce = encrypted.Nonce,
|
||||
Tag = encrypted.Tag,
|
||||
EncryptedKey = encrypted.EncryptedKey
|
||||
};
|
||||
|
||||
Sessions.SendTo(JsonSerializer.Serialize(outbound), sessionId);
|
||||
}
|
||||
|
||||
Console.WriteLine($"Forwarded encrypted RTC signal from {clientPayload.SenderUsername} to channel {clientPayload.ChannelId}");
|
||||
|
||||
@@ -57,4 +57,11 @@ public static class RtcChannelPresenceService
|
||||
return SessionToChannel.TryGetValue(sessionId, out var currentChannel) &&
|
||||
string.Equals(currentChannel, channelId, StringComparison.Ordinal);
|
||||
}
|
||||
|
||||
public static string? GetUsernameForSession(string sessionId)
|
||||
{
|
||||
return SessionToUsername.TryGetValue(sessionId, out var username)
|
||||
? username
|
||||
: null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user