From 0863924483c09d05948f63d1b1740f107e3e80fe Mon Sep 17 00:00:00 2001 From: Mounir IDRASSI Date: Mon, 8 Feb 2016 01:37:02 +0100 Subject: Linux/MacOSX: add progress bar for mouse collected entropy in GUI for keyfile generator and for random poll enrichment --- src/Main/Forms/Forms.cpp | 28 +++- src/Main/Forms/Forms.h | 4 +- src/Main/Forms/KeyfileGeneratorDialog.cpp | 26 ++- src/Main/Forms/KeyfileGeneratorDialog.h | 2 + src/Main/Forms/RandomPoolEnrichmentDialog.cpp | 26 ++- src/Main/Forms/RandomPoolEnrichmentDialog.h | 2 + src/Main/Forms/TrueCrypt.fbp | 228 +++++++++++++++++++++++++- 7 files changed, 306 insertions(+), 10 deletions(-) diff --git a/src/Main/Forms/Forms.cpp b/src/Main/Forms/Forms.cpp index 3c0db6a7..da2a30ba 100644 --- a/src/Main/Forms/Forms.cpp +++ b/src/Main/Forms/Forms.cpp @@ -1362,13 +1362,25 @@ KeyfileGeneratorDialogBase::KeyfileGeneratorDialogBase( wxWindow* parent, wxWind bSizer147->Add( RandomPoolStaticText, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 ); ShowRandomPoolCheckBox = new wxCheckBox( this, wxID_ANY, _("Show"), wxDefaultPosition, wxDefaultSize, 0 ); - ShowRandomPoolCheckBox->SetValue(true); bSizer147->Add( ShowRandomPoolCheckBox, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 ); sbSizer43->Add( bSizer147, 0, wxEXPAND|wxTOP, 5 ); + sbSizer43->Add( 0, 0, 1, wxEXPAND, 5 ); + + wxStaticBoxSizer* sbSizer45; + sbSizer45 = new wxStaticBoxSizer( new wxStaticBox( this, wxID_ANY, _("Randomness Collected From Mouse Movements") ), wxVERTICAL ); + + CollectedEntropy = new wxGauge( this, wxID_ANY, 2560, wxDefaultPosition, wxDefaultSize, wxGA_HORIZONTAL|wxGA_SMOOTH ); + CollectedEntropy->SetValue( 0 ); + sbSizer45->Add( CollectedEntropy, 1, wxALL|wxEXPAND, 5 ); + + + sbSizer43->Add( sbSizer45, 0, wxBOTTOM|wxEXPAND|wxTOP, 5 ); + + sbSizer43->Add( 0, 0, 1, wxEXPAND, 5 ); MouseStaticText = new wxStaticText( this, wxID_ANY, _("IMPORTANT: Move your mouse as randomly as possible within this window. The longer you move it, the better. This significantly increases the cryptographic strength of the keyfile."), wxDefaultPosition, wxDefaultSize, 0 ); @@ -2315,13 +2327,25 @@ RandomPoolEnrichmentDialogBase::RandomPoolEnrichmentDialogBase( wxWindow* parent bSizer147->Add( RandomPoolStaticText, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 ); ShowRandomPoolCheckBox = new wxCheckBox( this, wxID_ANY, _("Show"), wxDefaultPosition, wxDefaultSize, 0 ); - ShowRandomPoolCheckBox->SetValue(true); bSizer147->Add( ShowRandomPoolCheckBox, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 ); sbSizer43->Add( bSizer147, 0, wxEXPAND|wxTOP, 5 ); + sbSizer43->Add( 0, 0, 1, wxEXPAND, 5 ); + + wxStaticBoxSizer* sbSizer45; + sbSizer45 = new wxStaticBoxSizer( new wxStaticBox( this, wxID_ANY, _("Randomness Collected From Mouse Movements") ), wxVERTICAL ); + + CollectedEntropy = new wxGauge( this, wxID_ANY, 2560, wxDefaultPosition, wxDefaultSize, wxGA_HORIZONTAL|wxGA_SMOOTH ); + CollectedEntropy->SetValue( 0 ); + sbSizer45->Add( CollectedEntropy, 0, wxALL|wxEXPAND, 5 ); + + + sbSizer43->Add( sbSizer45, 0, wxBOTTOM|wxEXPAND|wxTOP, 5 ); + + sbSizer43->Add( 0, 0, 1, wxEXPAND, 5 ); MouseStaticText = new wxStaticText( this, wxID_ANY, _("IMPORTANT: Move your mouse as randomly as possible within this window. The longer you move it, the better. This significantly increases security. When done, click 'Continue'."), wxDefaultPosition, wxDefaultSize, 0 ); diff --git a/src/Main/Forms/Forms.h b/src/Main/Forms/Forms.h index 629519ae..fc3f62d3 100644 --- a/src/Main/Forms/Forms.h +++ b/src/Main/Forms/Forms.h @@ -39,9 +39,9 @@ class WizardPage; #include #include #include +#include #include #include -#include /////////////////////////////////////////////////////////////////////////// @@ -411,6 +411,7 @@ namespace VeraCrypt wxChoice* HashChoice; wxStaticText* RandomPoolStaticText; wxCheckBox* ShowRandomPoolCheckBox; + wxGauge* CollectedEntropy; wxStaticText* MouseStaticText; wxStaticText* m_staticText60; wxSpinCtrl* NumberOfKeyfiles; @@ -639,6 +640,7 @@ namespace VeraCrypt wxChoice* HashChoice; wxStaticText* RandomPoolStaticText; wxCheckBox* ShowRandomPoolCheckBox; + wxGauge* CollectedEntropy; wxStaticText* MouseStaticText; wxButton* ContinueButton; diff --git a/src/Main/Forms/KeyfileGeneratorDialog.cpp b/src/Main/Forms/KeyfileGeneratorDialog.cpp index bc4fb9fd..157f74e5 100644 --- a/src/Main/Forms/KeyfileGeneratorDialog.cpp +++ b/src/Main/Forms/KeyfileGeneratorDialog.cpp @@ -31,7 +31,7 @@ namespace VeraCrypt HashChoice->Select (0); RandomNumberGenerator::SetHash (Gui->GetSelectedData (HashChoice)->GetNew()); - ShowBytes (RandomPoolStaticText, RandomNumberGenerator::PeekPool().GetRange (0, 24)); + HideBytes (RandomPoolStaticText, 24); MouseStaticText->Wrap (Gui->GetCharWidth (MouseStaticText) * 70); MainSizer->SetMinSize (wxSize (-1, Gui->GetCharHeight (this) * 24)); @@ -39,6 +39,8 @@ namespace VeraCrypt Layout(); Fit(); Center(); + + MouseEventsCounter = 0; foreach (wxWindow *c, this->GetChildren()) c->Connect (wxEVT_MOTION, wxMouseEventHandler (KeyfileGeneratorDialog::OnMouseMotion), nullptr, this); @@ -169,12 +171,20 @@ namespace VeraCrypt if (ShowRandomPoolCheckBox->IsChecked()) ShowBytes (RandomPoolStaticText, RandomNumberGenerator::PeekPool().GetRange (0, 24)); + else + HideBytes (RandomPoolStaticText, 24); + + /* conservative estimate: 1 mouse move event brings 1 bit of entropy + * https://security.stackexchange.com/questions/32844/for-how-much-time-should-i-randomly-move-the-mouse-for-generating-encryption-key/32848#32848 + */ + if (MouseEventsCounter < 2560) + CollectedEntropy->SetValue (++MouseEventsCounter); } void KeyfileGeneratorDialog::OnShowRandomPoolCheckBoxClicked (wxCommandEvent& event) { if (!event.IsChecked()) - RandomPoolStaticText->SetLabel (L""); + HideBytes (RandomPoolStaticText, 24); } void KeyfileGeneratorDialog::OnRandomSizeCheckBoxClicked (wxCommandEvent& event) @@ -204,4 +214,16 @@ namespace VeraCrypt str[i] = L'X'; } } + + void KeyfileGeneratorDialog::HideBytes (wxStaticText *textCtrl, size_t len) + { + wxString str; + + for (size_t i = 0; i < len + 1; ++i) + { + str += L"**"; + } + + textCtrl->SetLabel (str.c_str()); + } } diff --git a/src/Main/Forms/KeyfileGeneratorDialog.h b/src/Main/Forms/KeyfileGeneratorDialog.h index 60caf6c7..23c66f08 100644 --- a/src/Main/Forms/KeyfileGeneratorDialog.h +++ b/src/Main/Forms/KeyfileGeneratorDialog.h @@ -31,8 +31,10 @@ namespace VeraCrypt void OnShowRandomPoolCheckBoxClicked (wxCommandEvent& event); void OnRandomSizeCheckBoxClicked( wxCommandEvent& event ); void ShowBytes (wxStaticText *textCtrl, const ConstBufferPtr &buffer, bool appendDots = true); + void HideBytes (wxStaticText *textCtrl, size_t len); HashList Hashes; + int MouseEventsCounter; }; } diff --git a/src/Main/Forms/RandomPoolEnrichmentDialog.cpp b/src/Main/Forms/RandomPoolEnrichmentDialog.cpp index fcfd0767..f8b04d24 100644 --- a/src/Main/Forms/RandomPoolEnrichmentDialog.cpp +++ b/src/Main/Forms/RandomPoolEnrichmentDialog.cpp @@ -33,7 +33,7 @@ namespace VeraCrypt } } - ShowBytes (RandomPoolStaticText, RandomNumberGenerator::PeekPool().GetRange (0, 24)); + HideBytes (RandomPoolStaticText, 24); MouseStaticText->Wrap (Gui->GetCharWidth (MouseStaticText) * 70); MainSizer->SetMinSize (wxSize (-1, Gui->GetCharHeight (this) * 24)); @@ -41,6 +41,8 @@ namespace VeraCrypt Layout(); Fit(); Center(); + + MouseEventsCounter = 0; foreach (wxWindow *c, this->GetChildren()) c->Connect (wxEVT_MOTION, wxMouseEventHandler (RandomPoolEnrichmentDialog::OnMouseMotion), nullptr, this); @@ -68,12 +70,20 @@ namespace VeraCrypt if (ShowRandomPoolCheckBox->IsChecked()) ShowBytes (RandomPoolStaticText, RandomNumberGenerator::PeekPool().GetRange (0, 24)); + else + HideBytes (RandomPoolStaticText, 24); + + /* conservative estimate: 1 mouse move event brings 1 bit of entropy + * https://security.stackexchange.com/questions/32844/for-how-much-time-should-i-randomly-move-the-mouse-for-generating-encryption-key/32848#32848 + */ + if (MouseEventsCounter < 2560) + CollectedEntropy->SetValue (++MouseEventsCounter); } void RandomPoolEnrichmentDialog::OnShowRandomPoolCheckBoxClicked (wxCommandEvent& event) { if (!event.IsChecked()) - RandomPoolStaticText->SetLabel (L""); + HideBytes (RandomPoolStaticText, 24); } void RandomPoolEnrichmentDialog::ShowBytes (wxStaticText *textCtrl, const ConstBufferPtr &buffer) @@ -94,4 +104,16 @@ namespace VeraCrypt str[i] = L'X'; } } + + void RandomPoolEnrichmentDialog::HideBytes (wxStaticText *textCtrl, size_t len) + { + wxString str; + + for (size_t i = 0; i < len + 1; ++i) + { + str += L"**"; + } + + textCtrl->SetLabel (str.c_str()); + } } diff --git a/src/Main/Forms/RandomPoolEnrichmentDialog.h b/src/Main/Forms/RandomPoolEnrichmentDialog.h index 2d55391c..6e113cbe 100644 --- a/src/Main/Forms/RandomPoolEnrichmentDialog.h +++ b/src/Main/Forms/RandomPoolEnrichmentDialog.h @@ -29,8 +29,10 @@ namespace VeraCrypt void OnMouseMotion (wxMouseEvent& event); void OnShowRandomPoolCheckBoxClicked (wxCommandEvent& event); void ShowBytes (wxStaticText *textCtrl, const ConstBufferPtr &buffer); + void HideBytes (wxStaticText *textCtrl, size_t len); HashList Hashes; + int MouseEventsCounter; }; } diff --git a/src/Main/Forms/TrueCrypt.fbp b/src/Main/Forms/TrueCrypt.fbp index 5f5735ab..a993f39f 100644 --- a/src/Main/Forms/TrueCrypt.fbp +++ b/src/Main/Forms/TrueCrypt.fbp @@ -9413,7 +9413,7 @@ 1 0 - 1 + 0 1 1 @@ -9496,6 +9496,117 @@ + 5 + wxBOTTOM|wxEXPAND|wxTOP + 0 + + wxID_ANY + Randomness Collected From Mouse Movements + + sbSizer45 + wxVERTICAL + none + + + 5 + wxALL|wxEXPAND + 1 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + + 0 + + + 0 + + 1 + CollectedEntropy + 1 + + + protected + 1 + + 2560 + Resizable + 1 + + wxGA_HORIZONTAL|wxGA_SMOOTH + + 0 + + + wxFILTER_NONE + wxDefaultValidator + + 0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 5 + wxEXPAND + 1 + + 0 + protected + 0 + + + 5 wxALL|wxALIGN_CENTER_HORIZONTAL 0 @@ -18937,7 +19048,7 @@ 1 0 - 1 + 0 1 1 @@ -19020,6 +19131,117 @@ + 5 + wxBOTTOM|wxEXPAND|wxTOP + 0 + + wxID_ANY + Randomness Collected From Mouse Movements + + sbSizer45 + wxVERTICAL + none + + + 5 + wxALL|wxEXPAND + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + + 0 + + + 0 + + 1 + CollectedEntropy + 1 + + + protected + 1 + + 2560 + Resizable + 1 + + wxGA_HORIZONTAL|wxGA_SMOOTH + + 0 + + + wxFILTER_NONE + wxDefaultValidator + + 0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 5 + wxEXPAND + 1 + + 0 + protected + 0 + + + 5 wxALL|wxALIGN_CENTER_HORIZONTAL 0 @@ -22832,7 +23054,7 @@ 1 0 - 1 + 0 1 1 -- cgit v1.2.3