Add retry prompt for wrong passphrase when unlocking encrypted channels

This commit is contained in:
Stone_Red
2026-07-19 19:24:01 +02:00
parent 41cb57f126
commit ccbeb94aee
2 changed files with 47 additions and 34 deletions
-7
View File
@@ -36,8 +36,6 @@ internal sealed class ChannelService : IChannelService
ChannelJoinResult result = await JoinChannelAsync(serverUrl, channelName, wirePassword);
if (isEncrypted && !HasChannelKey(serverUrl, channelName) && password is not null)
{
try
{
ChannelJoinResult unlockResult = await UnlockRoomKeyAsync(
serverUrl, channelName, password, crypto!.EncryptionSalt!, result.WrappedRoomKey ?? "");
@@ -46,11 +44,6 @@ internal sealed class ChannelService : IChannelService
result = unlockResult;
}
}
catch (Exception ex)
{
Debug.WriteLine($"Unlock failed: {ex.Message}");
}
}
return result;
}
+23 -3
View File
@@ -235,12 +235,17 @@ public sealed class MainWindowViewModel : ViewModelBase
return;
}
string? promptMessage = null;
while (true)
{
try
{
ChannelCryptoDto? crypto = await ChannelService.GetChannelCryptoAsync(serverUrl, channelName);
bool isEncrypted = crypto is not null && crypto.IsEncrypted;
if (isEncrypted && !ChannelService.HasChannelKey(serverUrl, channelName) && password is null)
{
password = await ShowPromptWindowAsync("Unlock Channel", "Enter the passphrase to unlock messages:", "Unlock");
password = await ShowPromptWindowAsync("Unlock Channel", promptMessage ?? "Enter the passphrase to unlock messages:", "Unlock");
if (string.IsNullOrEmpty(password))
{
return;
@@ -263,6 +268,15 @@ public sealed class MainWindowViewModel : ViewModelBase
}
}
}
return;
}
catch (InvalidOperationException ex) when (ex.Message == "Wrong passphrase")
{
password = null;
promptMessage = "Wrong passphrase - try again.";
}
}
};
_commandHandler.OnLeaveChannel += async () =>
@@ -1050,6 +1064,7 @@ public sealed class MainWindowViewModel : ViewModelBase
_ = Task.Run(async () =>
{
string? password = null;
string? promptMessage = null;
while (true)
{
try
@@ -1057,9 +1072,9 @@ public sealed class MainWindowViewModel : ViewModelBase
ChannelCryptoDto? crypto = await ChannelService.GetChannelCryptoAsync(serverUrl, channel.Name);
bool isEncrypted = crypto is not null && crypto.IsEncrypted;
if (isEncrypted && !ChannelService.HasChannelKey(serverUrl, channel.Name) && password is null)
if (isEncrypted && !ChannelService.HasChannelKey(serverUrl, channel.Name))
{
string? passphrase = await ShowPromptWindowAsync("Unlock Channel", "Enter the passphrase to unlock messages:", "Unlock");
string? passphrase = await ShowPromptWindowAsync("Unlock Channel", promptMessage ?? "Enter the passphrase to unlock messages:", "Unlock");
if (string.IsNullOrEmpty(passphrase))
{
Avalonia.Threading.Dispatcher.UIThread.Post(() =>
@@ -1121,6 +1136,11 @@ public sealed class MainWindowViewModel : ViewModelBase
password = pwd;
}
catch (InvalidOperationException ex) when (ex.Message == "Wrong passphrase")
{
password = null;
promptMessage = "Wrong passphrase - try again.";
}
catch
{
Avalonia.Threading.Dispatcher.UIThread.Post(() =>