Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Encryption manager #1127

Closed
wants to merge 29 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
d559303
encryption manager start
molnard Jan 28, 2019
705db59
enable encman if wallet is loaded, gui polish
molnard Feb 1, 2019
c785394
sign message finish
molnard Feb 1, 2019
f46aacc
verifymessage gui wip
molnard Feb 1, 2019
c022935
Verify signature finish
molnard Feb 1, 2019
962b4f8
encrypt decrypt business logic
molnard Feb 2, 2019
b964153
Merge branch 'master' into encmanager
molnard Feb 2, 2019
d0fa77f
pubkeys from addresses
molnard Feb 2, 2019
f84d3d7
Merge branch 'encmanager' of github.com:molnard/WalletWasabi into enc…
molnard Feb 2, 2019
ba8b7d0
create a Pubkey instead of comparing hex strings
molnard Feb 4, 2019
89ae0a3
verify message fix
molnard Feb 4, 2019
c86ccb3
verify fail message fix
molnard Feb 4, 2019
5cf74bb
change text of public key
molnard Feb 4, 2019
f9c7891
search able address browser
molnard Feb 4, 2019
4f57b85
coinlist right click functionality and design impr
molnard Feb 7, 2019
151d561
7 sec warn messages and disposing mechanism
molnard Feb 7, 2019
17f686f
separate the disposal of encmanager due to compatibility
molnard Feb 7, 2019
d9efdb8
Merge branch 'master' into encmanager
molnard Feb 8, 2019
68eccf0
use SelectedCoin.Model.HdPubKey.PubKey
molnard Feb 8, 2019
0b4480b
better variable names, better messages
molnard Feb 8, 2019
1f7bb59
coinList right click set canExecute.
molnard Feb 8, 2019
0a5d07e
Add encman right click functionality to Receive Tab
molnard Feb 8, 2019
47b3afb
Merge branch 'master' into encmanager
molnard Feb 13, 2019
e9d3709
Merge branch 'master' into encmanager
nopara73 Feb 17, 2019
9b89af2
Enable relevant Encryption Manager tabs when wallet is not loaded.
nopara73 Feb 17, 2019
f61f1ba
Merge branch 'master' into pr/1127-encryption-manager
nopara73 Feb 18, 2019
0e609b0
Merge branch 'master' into pr/1127-encryption-manager
nopara73 Feb 18, 2019
5c9ae3f
Organize menu ordering
nopara73 Feb 18, 2019
8b32816
Merge branch 'master' into pr/1127-encryption-manager
nopara73 Feb 20, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
30 changes: 20 additions & 10 deletions WalletWasabi.Gui/Tabs/EncryptionManager/DecryptMessageView.xaml
Expand Up @@ -3,21 +3,31 @@
<controls:GroupBox Title="{Binding Title}" BorderThickness="0" Classes="docTabContainer">
<Grid Classes="content" Margin="0 40 0 0">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<StackPanel Grid.Row="0">
<DockPanel IsVisible="{Binding !IsPublicKeyPresent}" LastChildFill="True">
<Button DockPanel.Dock="Right" Content="Get my public key" Command="{Binding MyPublicKeyCommand}" Width="200" />
<controls:NoparaPasswordBox Password="{Binding Password}" Watermark="Password" UseFloatingWatermark="True" />
</DockPanel>
<controls:ExtendedTextBox IsVisible="{Binding IsPublicKeyPresent}" Text="{Binding MyPublicKey}" Watermark="My public key" TextWrapping="Wrap" IsReadOnly="True" AcceptsReturn="True" UseFloatingWatermark="True" />
</StackPanel>
<controls:ExtendedTextBox Grid.Row="1" Text="{Binding EncryptedMessage}" Watermark="Encrypted message" UseFloatingWatermark="True" TextWrapping="Wrap" AcceptsReturn="True" />
<controls:ExtendedTextBox Grid.Row="2" Text="{Binding DecryptedMessage}" Watermark="Decrypted message" TextWrapping="Wrap" IsReadOnly="True" AcceptsReturn="True" UseFloatingWatermark="True" />
<DockPanel Grid.Row="3" LastChildFill="True">
<ListBox Grid.Row="0" Items="{Binding Addresses}" SelectedItem="{Binding SelectedItem}" MaxHeight="300">
<ListBox.ItemTemplate>
<DataTemplate>
<Grid ColumnDefinitions="* *">
<Grid.Styles>
<Style Selector="TextBlock">
<Setter Property="VerticalAlignment" Value="Center" />
</Style>
</Grid.Styles>
<TextBlock Text="{Binding PubKey}" Grid.Column="0" Margin="10 0" />
<TextBlock Text="{Binding Label}" Grid.Column="1" Margin="10 0" />
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<controls:ExtendedTextBox Grid.Row="1" Text="{Binding MyPublicKey}" Watermark="My public key" TextWrapping="Wrap" IsReadOnly="True" AcceptsReturn="True" UseFloatingWatermark="True" />
<controls:ExtendedTextBox Grid.Row="2" Text="{Binding EncryptedMessage}" Watermark="Encrypted message" UseFloatingWatermark="True" TextWrapping="Wrap" AcceptsReturn="True" />
<controls:ExtendedTextBox Grid.Row="3" Text="{Binding DecryptedMessage}" Watermark="Decrypted message" TextWrapping="Wrap" IsReadOnly="True" AcceptsReturn="True" UseFloatingWatermark="True" />
<DockPanel Grid.Row="4" LastChildFill="True">
<Button DockPanel.Dock="Right" Content="Decrypt" Command="{Binding DecryptCommand}" Width="100" />
<TextBlock Text="{Binding WarningMessage}" Classes="warningMessage" TextWrapping="Wrap" />
</DockPanel>
Expand Down
47 changes: 40 additions & 7 deletions WalletWasabi.Gui/Tabs/EncryptionManager/DecryptMessageViewModel.cs
Expand Up @@ -3,6 +3,8 @@
using ReactiveUI;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using WalletWasabi.Gui.Tabs.EncryptionManager;
using WalletWasabi.Gui.Tabs.WalletManager;
Expand All @@ -20,6 +22,8 @@ internal class DecryptMessageViewModel : CategoryViewModel
private string _myPublicKey;
private string _warningMessage;
private bool _isPublicKeyPresent;
private ObservableCollection<AddressPubKeyViewModel> _addresses;
private AddressPubKeyViewModel _selectedItem;

public string EncryptedMessage
{
Expand Down Expand Up @@ -57,6 +61,18 @@ public bool IsPublicKeyPresent
set => this.RaiseAndSetIfChanged(ref _isPublicKeyPresent, value);
}

public AddressPubKeyViewModel SelectedItem
{
get => _selectedItem;
set => this.RaiseAndSetIfChanged(ref _selectedItem, value);
}

public ObservableCollection<AddressPubKeyViewModel> Addresses
{
get => _addresses;
set => this.RaiseAndSetIfChanged(ref _addresses, value);
}

public ReactiveCommand DecryptCommand { get; }
public ReactiveCommand MyPublicKeyCommand { get; }

Expand All @@ -74,7 +90,7 @@ public DecryptMessageViewModel(EncryptionManagerViewModel owner) : base("Decrypt
() =>
{
WarningMessage = "";
DecryptedMessage = DecryptMessage(EncryptedMessage, Password);
DecryptedMessage = DecryptMessage(EncryptedMessage, MyPublicKey, Password);
},
canDecrypt
);
Expand All @@ -88,22 +104,39 @@ public DecryptMessageViewModel(EncryptionManagerViewModel owner) : base("Decrypt
() =>
{
WarningMessage = "";
MyPublicKey = Global.WalletService.KeyManager.EncryptedSecret.GetSecret(Password).PubKey.ToHex();
IsPublicKeyPresent = true;
}
DecryptedMessage = DecryptMessage(EncryptedMessage, MyPublicKey, Password);
molnard marked this conversation as resolved.
Show resolved Hide resolved
},
canDecrypt
);

MyPublicKeyCommand.ThrownExceptions.Subscribe(ex =>
{
WarningMessage = ex.Message;
});

this.WhenAnyValue(x => x.SelectedItem)
.Subscribe((x) => MyPublicKey = x is null ? "" : x.PubKey);

IEnumerable<HdPubKey> keys = Global.WalletService.KeyManager.GetKeys();

Addresses = new ObservableCollection<AddressPubKeyViewModel>(keys.Select(a => new AddressPubKeyViewModel(a)));
}

private static string DecryptMessage(string message, string password)
private string DecryptMessage(string message, string pubkey, string password)
{
password = Guard.Correct(password);
var bitcoinPrivateKey = Global.WalletService.KeyManager.EncryptedSecret.GetSecret(password);
return bitcoinPrivateKey.PrivateKey.Decrypt(message);
HdPubKey hdPubKey = Global.WalletService.KeyManager.GetKeys().FirstOrDefault(k => k.PubKey.ToHex() == pubkey);
molnard marked this conversation as resolved.
Show resolved Hide resolved
if (hdPubKey == null)
{
throw new InvalidOperationException("Could not fint the corresponting address in your wallet for that public key.");
}

(ExtKey secret, HdPubKey pubKey) secret = Global.WalletService.KeyManager.GetSecretsAndPubKeyPairs(password, hdPubKey.PubKey.ScriptPubKey).FirstOrDefault();
molnard marked this conversation as resolved.
Show resolved Hide resolved
if (secret.Equals(default))
{
throw new InvalidOperationException("Could not fint the corresponting secret in your wallet for that ScriptPubKey");
}
return secret.secret.PrivateKey.Decrypt(message);
}
}
}
55 changes: 55 additions & 0 deletions WalletWasabi.Gui/ViewModels/AddressPubKeyViewModel.cs
@@ -0,0 +1,55 @@
using System;
using System.Collections.Generic;
using System.Reactive.Disposables;
using System.Text;
using NBitcoin;
using WalletWasabi.KeyManagement;

namespace WalletWasabi.Gui.ViewModels
{
public class AddressPubKeyViewModel : ViewModelBase, IDisposable
{
private CompositeDisposable Disposables { get; }
private HdPubKey _hdPubKey;

public string PubKey
{
get => _hdPubKey.PubKey.ToHex();
}

public string Label
{
get => _hdPubKey.Label;
}

public AddressPubKeyViewModel(HdPubKey hdpubkey)
{
_hdPubKey = hdpubkey;
}

#region IDisposable Support

private volatile bool _disposedValue = false; // To detect redundant calls

protected virtual void Dispose(bool disposing)
{
if (!_disposedValue)
{
if (disposing)
{
Disposables?.Dispose();
}
_disposedValue = true;
}
}

// This code added to correctly implement the disposable pattern.
public void Dispose()
{
// Do not change this code. Put cleanup code in Dispose(bool disposing) above.
Dispose(true);
}

#endregion IDisposable Support
}
}