From c178e325b807258199ae45b2c50c265b4d7ce7af Mon Sep 17 00:00:00 2001 From: Mounir IDRASSI Date: Tue, 30 Dec 2014 17:01:49 +0100 Subject: Linux/MacOSX: Implement TrueCrypt conversion and loading support. Correct many GTK issues linked to multi-threaded origine of events by implementing an automatic mechanism for handling such requests in the main thread. --- src/Main/Forms/ChangePasswordDialog.cpp | 14 +++- src/Main/Forms/Forms.cpp | 5 +- src/Main/Forms/Forms.h | 1 + src/Main/Forms/MainFrame.cpp | 4 +- src/Main/Forms/MountOptionsDialog.cpp | 12 ++- src/Main/Forms/TrueCrypt.fbp | 93 ++++++++++++++++++++- src/Main/Forms/VolumeCreationWizard.cpp | 4 +- src/Main/Forms/VolumePasswordPanel.cpp | 12 ++- src/Main/Forms/VolumePasswordPanel.h | 3 +- src/Main/Forms/VolumePasswordWizardPage.cpp | 2 +- src/Main/Forms/VolumePropertiesDialog.cpp | 2 +- src/Main/Forms/WaitDialog.cpp | 11 ++- src/Main/Forms/WaitDialog.h | 122 +++++++++++++++++++++++++++- 13 files changed, 264 insertions(+), 21 deletions(-) mode change 100755 => 100644 src/Main/Forms/ChangePasswordDialog.cpp mode change 100755 => 100644 src/Main/Forms/Forms.cpp mode change 100755 => 100644 src/Main/Forms/Forms.h mode change 100755 => 100644 src/Main/Forms/MountOptionsDialog.cpp mode change 100755 => 100644 src/Main/Forms/TrueCrypt.fbp mode change 100755 => 100644 src/Main/Forms/VolumePasswordPanel.cpp mode change 100755 => 100644 src/Main/Forms/VolumePasswordPanel.h mode change 100755 => 100644 src/Main/Forms/VolumePasswordWizardPage.cpp mode change 100755 => 100644 src/Main/Forms/WaitDialog.cpp mode change 100755 => 100644 src/Main/Forms/WaitDialog.h (limited to 'src/Main/Forms') diff --git a/src/Main/Forms/ChangePasswordDialog.cpp b/src/Main/Forms/ChangePasswordDialog.cpp old mode 100755 new mode 100644 index 75fe717c..1bde4bee --- a/src/Main/Forms/ChangePasswordDialog.cpp +++ b/src/Main/Forms/ChangePasswordDialog.cpp @@ -48,11 +48,11 @@ namespace VeraCrypt throw ParameterIncorrect (SRC_POS); } - CurrentPasswordPanel = new VolumePasswordPanel (this, password, keyfiles, false, true, true, false, true, true); + CurrentPasswordPanel = new VolumePasswordPanel (this, password, false, keyfiles, false, true, true, false, true, true); CurrentPasswordPanel->UpdateEvent.Connect (EventConnector (this, &ChangePasswordDialog::OnPasswordPanelUpdate)); CurrentPasswordPanelSizer->Add (CurrentPasswordPanel, 1, wxALL | wxEXPAND); - NewPasswordPanel = new VolumePasswordPanel (this, newPassword, newKeyfiles, false, enableNewPassword, enableNewKeyfiles, enableNewPassword, enablePkcs5Prf); + NewPasswordPanel = new VolumePasswordPanel (this, newPassword, true, newKeyfiles, false, enableNewPassword, enableNewKeyfiles, enableNewPassword, enablePkcs5Prf); NewPasswordPanel->UpdateEvent.Connect (EventConnector (this, &ChangePasswordDialog::OnPasswordPanelUpdate)); NewPasswordPanelSizer->Add (NewPasswordPanel, 1, wxALL | wxEXPAND); @@ -81,6 +81,14 @@ namespace VeraCrypt try { + shared_ptr currentKdf = CurrentPasswordPanel->GetPkcs5Kdf(); + if (currentKdf && CurrentPasswordPanel->GetTrueCryptMode() && (currentKdf->GetName() == L"HMAC-SHA-256")) + { + Gui->ShowWarning (LangString ["ALGO_NOT_SUPPORTED_FOR_TRUECRYPT_MODE"]); + event.Skip(); + return; + } + shared_ptr newPassword; if (DialogMode == Mode::ChangePasswordAndKeyfiles) { @@ -126,7 +134,7 @@ namespace VeraCrypt #endif wxBusyCursor busy; ChangePasswordThreadRoutine routine(Path, Gui->GetPreferences().DefaultMountOptions.PreserveTimestamps, - CurrentPasswordPanel->GetPassword(), CurrentPasswordPanel->GetPkcs5Kdf(), CurrentPasswordPanel->GetKeyfiles(), + CurrentPasswordPanel->GetPassword(), CurrentPasswordPanel->GetPkcs5Kdf(), CurrentPasswordPanel->GetTrueCryptMode(),CurrentPasswordPanel->GetKeyfiles(), newPassword, newKeyfiles, NewPasswordPanel->GetPkcs5Kdf(), NewPasswordPanel->GetHeaderWipeCount()); WaitDialog dlg(this, LangString["IDT_STATIC_MODAL_WAIT_DLG_INFO"], &routine); dlg.Run(); diff --git a/src/Main/Forms/Forms.cpp b/src/Main/Forms/Forms.cpp old mode 100755 new mode 100644 index 80a177df..5e28afdb --- a/src/Main/Forms/Forms.cpp +++ b/src/Main/Forms/Forms.cpp @@ -3209,7 +3209,10 @@ VolumePasswordPanelBase::VolumePasswordPanelBase( wxWindow* parent, wxWindowID i int Pkcs5PrfChoiceNChoices = sizeof( Pkcs5PrfChoiceChoices ) / sizeof( wxString ); Pkcs5PrfChoice = new wxChoice( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, Pkcs5PrfChoiceNChoices, Pkcs5PrfChoiceChoices, 0 ); Pkcs5PrfChoice->SetSelection( 0 ); - GridBagSizer->Add( Pkcs5PrfChoice, wxGBPosition( 7, 1 ), wxGBSpan( 1, 2 ), wxALIGN_CENTER_VERTICAL|wxLEFT, 5 ); + GridBagSizer->Add( Pkcs5PrfChoice, wxGBPosition( 7, 1 ), wxGBSpan( 1, 1 ), wxALIGN_CENTER_VERTICAL|wxLEFT, 5 ); + + TrueCryptModeCheckBox = new wxCheckBox( this, wxID_ANY, _("TrueCrypt Mode"), wxDefaultPosition, wxDefaultSize, 0 ); + GridBagSizer->Add( TrueCryptModeCheckBox, wxGBPosition( 7, 2 ), wxGBSpan( 1, 1 ), wxALIGN_CENTER_VERTICAL|wxLEFT, 5 ); HeaderWipeCountText = new wxStaticText( this, wxID_ANY, _("Header Wipe:"), wxDefaultPosition, wxDefaultSize, 0 ); HeaderWipeCountText->Wrap( -1 ); diff --git a/src/Main/Forms/Forms.h b/src/Main/Forms/Forms.h old mode 100755 new mode 100644 index b0579219..9e8a02b0 --- a/src/Main/Forms/Forms.h +++ b/src/Main/Forms/Forms.h @@ -962,6 +962,7 @@ namespace VeraCrypt wxBoxSizer* Pkcs5PrfSizer; wxStaticText* Pkcs5PrfStaticText; wxChoice* Pkcs5PrfChoice; + wxCheckBox* TrueCryptModeCheckBox; wxStaticText* HeaderWipeCountText; wxChoice* HeaderWipeCount; wxBoxSizer* PasswordPlaceholderSizer; diff --git a/src/Main/Forms/MainFrame.cpp b/src/Main/Forms/MainFrame.cpp index fbf20537..ca4d7d63 100644 --- a/src/Main/Forms/MainFrame.cpp +++ b/src/Main/Forms/MainFrame.cpp @@ -39,6 +39,7 @@ namespace VeraCrypt DEFINE_EVENT_TYPE(wxEVT_COMMAND_UPDATE_VOLUME_LIST) DEFINE_EVENT_TYPE(wxEVT_COMMAND_PREF_UPDATED) DEFINE_EVENT_TYPE(wxEVT_COMMAND_OPEN_VOLUME_REQUEST) + DEFINE_EVENT_TYPE(wxEVT_COMMAND_SHOW_WARNING) MainFrame::MainFrame (wxWindow* parent) : MainFrameBase (parent), ListItemRightClickEventPending (false), @@ -1495,6 +1496,7 @@ namespace VeraCrypt } VolumeInfoList protectionTriggeredVolumes; + SlotListCtrl->SetColumnWidth(0, wxLIST_AUTOSIZE); // Update list long prevItemIndex = -1; @@ -1516,7 +1518,7 @@ namespace VeraCrypt #endif fields[ColumnPath] = volume->Path; fields[ColumnSize] = Gui->SizeToString (volume->Size); - fields[ColumnType] = Gui->VolumeTypeToString (volume->Type, volume->Protection); + fields[ColumnType] = Gui->VolumeTypeToString (volume->Type, volume->TrueCryptMode, volume->Protection); if (volume->HiddenVolumeProtectionTriggered) { diff --git a/src/Main/Forms/MountOptionsDialog.cpp b/src/Main/Forms/MountOptionsDialog.cpp old mode 100755 new mode 100644 index 1ddb7793..d4c78cb6 --- a/src/Main/Forms/MountOptionsDialog.cpp +++ b/src/Main/Forms/MountOptionsDialog.cpp @@ -30,7 +30,7 @@ namespace VeraCrypt if (disableMountOptions) OptionsButton->Show (false); - PasswordPanel = new VolumePasswordPanel (this, options.Password, options.Keyfiles, !disableMountOptions, true, true, false, true, true); + PasswordPanel = new VolumePasswordPanel (this, options.Password, disableMountOptions, options.Keyfiles, !disableMountOptions, true, true, false, true, true); PasswordPanel->SetCacheCheckBoxValidator (wxGenericValidator (&Options.CachePassword)); PasswordSizer->Add (PasswordPanel, 1, wxALL | wxEXPAND); @@ -61,7 +61,7 @@ namespace VeraCrypt OptionsButton->SetLabel (OptionsButtonLabel + L" >"); OptionsPanel->Show (false); - ProtectionPasswordPanel = new VolumePasswordPanel (OptionsPanel, options.ProtectionPassword, options.ProtectionKeyfiles, false, true, true, false, true, true, _("P&assword to hidden volume:")); + ProtectionPasswordPanel = new VolumePasswordPanel (OptionsPanel, options.ProtectionPassword, true, options.ProtectionKeyfiles, false, true, true, false, true, true, _("P&assword to hidden volume:")); ProtectionPasswordSizer->Add (ProtectionPasswordPanel, 1, wxALL | wxEXPAND); UpdateDialog(); @@ -86,6 +86,7 @@ namespace VeraCrypt Options.Password = PasswordPanel->GetPassword(); Options.Kdf = PasswordPanel->GetPkcs5Kdf(); + Options.TrueCryptMode = PasswordPanel->GetTrueCryptMode(); Options.Keyfiles = PasswordPanel->GetKeyfiles(); if (ReadOnlyCheckBox->IsChecked()) @@ -119,6 +120,13 @@ namespace VeraCrypt { Gui->ShowWarning (LangString ["UNSUPPORTED_CHARS_IN_PWD_RECOM"]); } + + if (Options.TrueCryptMode && Options.Kdf && (Options.Kdf->GetName() == L"HMAC-SHA-256")) + { + Gui->ShowWarning (LangString ["ALGO_NOT_SUPPORTED_FOR_TRUECRYPT_MODE"]); + event.Skip(); + return; + } EndModal (wxID_OK); } diff --git a/src/Main/Forms/TrueCrypt.fbp b/src/Main/Forms/TrueCrypt.fbp old mode 100755 new mode 100644 index e2fc1ed4..c03beab9 --- a/src/Main/Forms/TrueCrypt.fbp +++ b/src/Main/Forms/TrueCrypt.fbp @@ -26014,7 +26014,7 @@ 5 - 2 + 1 1 wxALIGN_CENTER_VERTICAL|wxLEFT 7 @@ -26104,6 +26104,97 @@ + 5 + 1 + 2 + wxALIGN_CENTER_VERTICAL|wxLEFT + 7 + 1 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + TrueCrypt Mode + + 0 + + + 0 + + 1 + TrueCryptModeCheckBox + 1 + + + protected + 1 + + Resizable + 1 + + + + 0 + + + wxFILTER_NONE + wxDefaultValidator + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 5 1 0 diff --git a/src/Main/Forms/VolumeCreationWizard.cpp b/src/Main/Forms/VolumeCreationWizard.cpp index 01fa8450..99231a96 100644 --- a/src/Main/Forms/VolumeCreationWizard.cpp +++ b/src/Main/Forms/VolumeCreationWizard.cpp @@ -863,7 +863,7 @@ namespace VeraCrypt options->Quick = QuickFormatEnabled; options->Size = VolumeSize; options->Type = OuterVolume ? VolumeType::Normal : SelectedVolumeType; - options->VolumeHeaderKdf = Pkcs5Kdf::GetAlgorithm (*SelectedHash); + options->VolumeHeaderKdf = Pkcs5Kdf::GetAlgorithm (*SelectedHash, false); Creator.reset (new VolumeCreator); VolumeCreatorThreadRoutine routine(options, Creator); @@ -941,7 +941,7 @@ namespace VeraCrypt }); #endif - shared_ptr outerVolume = Core->OpenVolume (make_shared (SelectedVolumePath), true, Password, Kdf, Keyfiles, VolumeProtection::ReadOnly); + shared_ptr outerVolume = Core->OpenVolume (make_shared (SelectedVolumePath), true, Password, Kdf, false, Keyfiles, VolumeProtection::ReadOnly); MaxHiddenVolumeSize = Core->GetMaxHiddenVolumeSize (outerVolume); // Add a reserve (in case the user mounts the outer volume and creates new files diff --git a/src/Main/Forms/VolumePasswordPanel.cpp b/src/Main/Forms/VolumePasswordPanel.cpp old mode 100755 new mode 100644 index 50f3eca2..e4582763 --- a/src/Main/Forms/VolumePasswordPanel.cpp +++ b/src/Main/Forms/VolumePasswordPanel.cpp @@ -14,7 +14,7 @@ namespace VeraCrypt { - VolumePasswordPanel::VolumePasswordPanel (wxWindow* parent, shared_ptr password, shared_ptr keyfiles, bool enableCache, bool enablePassword, bool enableKeyfiles, bool enableConfirmation, bool enablePkcs5Prf, bool isMountPassword, const wxString &passwordLabel) + VolumePasswordPanel::VolumePasswordPanel (wxWindow* parent, shared_ptr password, bool disableTruecryptMode, shared_ptr keyfiles, bool enableCache, bool enablePassword, bool enableKeyfiles, bool enableConfirmation, bool enablePkcs5Prf, bool isMountPassword, const wxString &passwordLabel) : VolumePasswordPanelBase (parent), Keyfiles (new KeyfileList) { if (keyfiles) @@ -63,6 +63,7 @@ namespace VeraCrypt Pkcs5PrfStaticText->Show (enablePkcs5Prf); Pkcs5PrfChoice->Show (enablePkcs5Prf); + TrueCryptModeCheckBox->Show (!disableTruecryptMode); HeaderWipeCountText->Show (enablePkcs5Prf && !isMountPassword); HeaderWipeCount->Show (enablePkcs5Prf && !isMountPassword); @@ -74,7 +75,7 @@ namespace VeraCrypt Pkcs5PrfChoice->Delete (0); Pkcs5PrfChoice->Append (LangString["AUTODETECTION"]); } - foreach_ref (const Pkcs5Kdf &kdf, Pkcs5Kdf::GetAvailableAlgorithms()) + foreach_ref (const Pkcs5Kdf &kdf, Pkcs5Kdf::GetAvailableAlgorithms(false)) { if (!kdf.IsDeprecated() || isMountPassword) Pkcs5PrfChoice->Append (kdf.GetName()); @@ -190,7 +191,7 @@ namespace VeraCrypt { try { - return Pkcs5Kdf::GetAlgorithm (wstring (Pkcs5PrfChoice->GetStringSelection())); + return Pkcs5Kdf::GetAlgorithm (wstring (Pkcs5PrfChoice->GetStringSelection()), GetTrueCryptMode()); } catch (ParameterIncorrect&) { @@ -198,6 +199,11 @@ namespace VeraCrypt } } + bool VolumePasswordPanel::GetTrueCryptMode () const + { + return TrueCryptModeCheckBox->GetValue (); + } + int VolumePasswordPanel::GetHeaderWipeCount () const { try diff --git a/src/Main/Forms/VolumePasswordPanel.h b/src/Main/Forms/VolumePasswordPanel.h old mode 100755 new mode 100644 index 465a430a..c3e59da1 --- a/src/Main/Forms/VolumePasswordPanel.h +++ b/src/Main/Forms/VolumePasswordPanel.h @@ -18,13 +18,14 @@ namespace VeraCrypt class VolumePasswordPanel : public VolumePasswordPanelBase { public: - VolumePasswordPanel (wxWindow* parent, shared_ptr password, shared_ptr keyfiles, bool enableCache = false, bool enablePassword = true, bool enableKeyfiles = true, bool enableConfirmation = false, bool enablePkcs5Prf = false, bool isMountPassword = false, const wxString &passwordLabel = wxString()); + VolumePasswordPanel (wxWindow* parent, shared_ptr password, bool disableTruecryptMode, shared_ptr keyfiles, bool enableCache = false, bool enablePassword = true, bool enableKeyfiles = true, bool enableConfirmation = false, bool enablePkcs5Prf = false, bool isMountPassword = false, const wxString &passwordLabel = wxString()); virtual ~VolumePasswordPanel (); void AddKeyfile (shared_ptr keyfile); shared_ptr GetKeyfiles () const { return UseKeyfilesCheckBox->IsChecked() ? Keyfiles : shared_ptr (); } shared_ptr GetPassword () const; shared_ptr GetPkcs5Kdf () const; + bool GetTrueCryptMode () const; int GetHeaderWipeCount () const; void SetCacheCheckBoxValidator (const wxGenericValidator &validator) { CacheCheckBox->SetValidator (validator); } void SetFocusToPasswordTextCtrl () { PasswordTextCtrl->SetSelection (-1, -1); PasswordTextCtrl->SetFocus(); } diff --git a/src/Main/Forms/VolumePasswordWizardPage.cpp b/src/Main/Forms/VolumePasswordWizardPage.cpp old mode 100755 new mode 100644 index 61ff999f..0f80ce8d --- a/src/Main/Forms/VolumePasswordWizardPage.cpp +++ b/src/Main/Forms/VolumePasswordWizardPage.cpp @@ -15,7 +15,7 @@ namespace VeraCrypt VolumePasswordWizardPage::VolumePasswordWizardPage (wxPanel* parent, shared_ptr password, shared_ptr keyfiles, bool enableConfirmation) : VolumePasswordWizardPageBase (parent), ConfirmationMode (enableConfirmation) { - PasswordPanel = new VolumePasswordPanel (this, password, keyfiles, false, true, true, enableConfirmation, !enableConfirmation, !enableConfirmation); + PasswordPanel = new VolumePasswordPanel (this, password, true, keyfiles, false, true, true, enableConfirmation, !enableConfirmation, !enableConfirmation); PasswordPanel->UpdateEvent.Connect (EventConnector (this, &VolumePasswordWizardPage::OnPasswordPanelUpdate)); PasswordPanelSizer->Add (PasswordPanel, 1, wxALL | wxEXPAND); diff --git a/src/Main/Forms/VolumePropertiesDialog.cpp b/src/Main/Forms/VolumePropertiesDialog.cpp index c9956187..9d17f04b 100644 --- a/src/Main/Forms/VolumePropertiesDialog.cpp +++ b/src/Main/Forms/VolumePropertiesDialog.cpp @@ -32,7 +32,7 @@ namespace VeraCrypt AppendToList ("VIRTUAL_DEVICE", wstring (volumeInfo.VirtualDevice)); #endif AppendToList ("SIZE", Gui->SizeToString (volumeInfo.Size)); - AppendToList ("TYPE", Gui->VolumeTypeToString (volumeInfo.Type, volumeInfo.Protection)); + AppendToList ("TYPE", Gui->VolumeTypeToString (volumeInfo.Type, volumeInfo.TrueCryptMode, volumeInfo.Protection)); AppendToList ("READ_ONLY", LangString [volumeInfo.Protection == VolumeProtection::ReadOnly ? "UISTR_YES" : "UISTR_NO"]); wxString protection; diff --git a/src/Main/Forms/WaitDialog.cpp b/src/Main/Forms/WaitDialog.cpp old mode 100755 new mode 100644 index a8290d10..a60c5e45 --- a/src/Main/Forms/WaitDialog.cpp +++ b/src/Main/Forms/WaitDialog.cpp @@ -15,11 +15,12 @@ namespace VeraCrypt { DEFINE_EVENT_TYPE(wxEVT_COMMAND_WAITDIALOGTHREAD_COMPLETED) + DEFINE_EVENT_TYPE(wxEVT_COMMAND_WAITDIALOG_ADMIN_PASSWORD) + DEFINE_EVENT_TYPE(wxEVT_COMMAND_WAITDIALOG_PIN) + DEFINE_EVENT_TYPE(wxEVT_COMMAND_WAITDIALOG_SHOW_MSG) wxThread::ExitCode WaitThread::Entry() - { - wxCommandEvent finishEvent( wxEVT_COMMAND_WAITDIALOGTHREAD_COMPLETED,0); - + { m_pRoutine->Execute(); wxQueueEvent (m_pHandler, new wxCommandEvent( wxEVT_COMMAND_WAITDIALOGTHREAD_COMPLETED,0)); return (wxThread::ExitCode)0; // success @@ -88,7 +89,9 @@ namespace VeraCrypt VC_CONVERT_EXCEPTION (InvalidSecurityTokenKeyfilePath); VC_CONVERT_EXCEPTION (SecurityTokenLibraryNotInitialized); VC_CONVERT_EXCEPTION (SecurityTokenKeyfileAlreadyExists); - VC_CONVERT_EXCEPTION (SecurityTokenKeyfileNotFound); + VC_CONVERT_EXCEPTION (SecurityTokenKeyfileNotFound); + VC_CONVERT_EXCEPTION (UnsupportedAlgoInTrueCryptMode); + VC_CONVERT_EXCEPTION (UnsupportedTrueCryptFormat); throw *ex; } } diff --git a/src/Main/Forms/WaitDialog.h b/src/Main/Forms/WaitDialog.h old mode 100755 new mode 100644 index c9e0d56e..b12ad028 --- a/src/Main/Forms/WaitDialog.h +++ b/src/Main/Forms/WaitDialog.h @@ -11,11 +11,16 @@ #include "Forms.h" #include "Main/Main.h" +#include "Main/Application.h" +#include namespace VeraCrypt { DECLARE_LOCAL_EVENT_TYPE(wxEVT_COMMAND_WAITDIALOGTHREAD_COMPLETED, -1); + DECLARE_LOCAL_EVENT_TYPE(wxEVT_COMMAND_WAITDIALOG_ADMIN_PASSWORD, -1); + DECLARE_LOCAL_EVENT_TYPE(wxEVT_COMMAND_WAITDIALOG_PIN, -1); + DECLARE_LOCAL_EVENT_TYPE(wxEVT_COMMAND_WAITDIALOG_SHOW_MSG, -1); class WaitDialog; @@ -50,6 +55,10 @@ namespace VeraCrypt GetSizer()->Fit( this ); Centre( wxBOTH ); Connect( wxID_ANY, wxEVT_COMMAND_WAITDIALOGTHREAD_COMPLETED, wxCommandEventHandler( WaitDialog::OnThreadCompletion ) ); + Connect( wxID_ANY, wxEVT_COMMAND_WAITDIALOG_ADMIN_PASSWORD, wxCommandEventHandler( WaitDialog::OnAdminPasswordRequest ) ); + Connect( wxID_ANY, wxEVT_COMMAND_WAITDIALOG_PIN, wxCommandEventHandler( WaitDialog::OnPinRequest ) ); + Connect( wxID_ANY, wxEVT_COMMAND_WAITDIALOG_SHOW_MSG, wxCommandEventHandler( WaitDialog::OnShowMsg ) ); + Connect( wxEVT_TIMER, wxTimerEventHandler( WaitDialog::OnProgressTimer ), NULL, this ); m_thread = new WaitThread(this, pRoutine); } @@ -58,6 +67,9 @@ namespace VeraCrypt { Disconnect( wxEVT_TIMER, wxTimerEventHandler( WaitDialog::OnProgressTimer )); Disconnect( wxID_ANY, wxEVT_COMMAND_WAITDIALOGTHREAD_COMPLETED, wxCommandEventHandler( WaitDialog::OnThreadCompletion ) ); + Disconnect( wxID_ANY, wxEVT_COMMAND_WAITDIALOG_ADMIN_PASSWORD, wxCommandEventHandler( WaitDialog::OnAdminPasswordRequest ) ); + Disconnect( wxID_ANY, wxEVT_COMMAND_WAITDIALOG_PIN, wxCommandEventHandler( WaitDialog::OnPinRequest ) ); + Disconnect( wxID_ANY, wxEVT_COMMAND_WAITDIALOG_SHOW_MSG, wxCommandEventHandler( WaitDialog::OnShowMsg ) ); } virtual void OnWaitDialogInit( wxInitDialogEvent& event ) @@ -65,12 +77,119 @@ namespace VeraCrypt m_thread->Run(); m_timer.Start(100); } + + int GetCharWidth (wxWindow *window) const + { + int width; + int height; + window->GetTextExtent (L"a", &width, &height); + + if (width < 1) + return 7; + + return width; + } + + class ShowMessageParam + { + public: + wxString m_message; + wxString m_caption; + long m_style; + bool m_topMost; + ShowMessageParam(const wxString &message, const wxString &caption,long style, bool topMost) + : m_message(message), m_caption(caption), m_style(style), m_topMost(topMost) + {} + }; + + int RequestShowMessage (const wxString &message, const wxString &caption,long style, bool topMost) + { + long lResult = -1; + if (m_queue.IsOk()) + { + wxString sResult; + ShowMessageParam* pParam = new ShowMessageParam(message, caption, style, topMost); + wxCommandEvent* pEvent = new wxCommandEvent( wxEVT_COMMAND_WAITDIALOG_SHOW_MSG,0); + pEvent->SetClientData (pParam); + wxQueueEvent (this, pEvent); + m_queue.Receive (sResult); + sResult.ToLong(&lResult); + } + return (int) lResult; + } + + void RequestAdminPassword (wxString& adminPassword) + { + if (m_queue.IsOk()) + { + wxQueueEvent (this, new wxCommandEvent( wxEVT_COMMAND_WAITDIALOG_ADMIN_PASSWORD,0)); + if (wxMSGQUEUE_NO_ERROR != m_queue.Receive (adminPassword)) + adminPassword = wxT(""); + } + else + adminPassword = wxT(""); + } + + void RequestPin (wxString& pin) + { + if (m_queue.IsOk()) + { + wxCommandEvent* pEvent = new wxCommandEvent( wxEVT_COMMAND_WAITDIALOG_PIN,0); + pEvent->SetString (pin); + wxQueueEvent (this, pEvent); + if (wxMSGQUEUE_NO_ERROR != m_queue.Receive (pin)) + pin = wxT(""); + } + else + pin = wxT(""); + } // virtual void OnWaitDialogClose( wxCloseEvent& event ) { } void OnThreadCompletion(wxCommandEvent &) { + m_queue.Clear(); EndModal(0); } + + void OnAdminPasswordRequest(wxCommandEvent &) + { + + wxPasswordEntryDialog dialog (this, _("Enter your user password or administrator password:"), _("Administrator privileges required")); + if (dialog.ShowModal() != wxID_OK) + m_queue.Post(wxT("")); + else + m_queue.Post(dialog.GetValue()); + } + + + + void OnPinRequest(wxCommandEvent &e) + { + + wxPasswordEntryDialog dialog (this, wxString::Format (LangString["ENTER_TOKEN_PASSWORD"], e.GetString()), LangString["IDD_TOKEN_PASSWORD"]); + dialog.SetSize (wxSize (GetCharWidth (&dialog) * 50, -1)); + + if (dialog.ShowModal() != wxID_OK) + m_queue.Post(wxT("")); + else + m_queue.Post(dialog.GetValue()); + } + + void OnShowMsg(wxCommandEvent &e) + { + ShowMessageParam* pParam = (ShowMessageParam*) e.GetClientData(); + if (pParam->m_topMost) + { + if (!IsActive()) + RequestUserAttention (wxUSER_ATTENTION_ERROR); + + pParam->m_style |= wxSTAY_ON_TOP; + } + + int iResult = wxMessageBox (pParam->m_message, pParam->m_caption, pParam->m_style, this); + delete pParam; + m_queue.Post(wxString::Format(wxT("%d"), iResult)); + } void OnProgressTimer(wxTimerEvent& event) { @@ -83,7 +202,8 @@ namespace VeraCrypt protected: WaitThread* m_thread; - wxTimer m_timer; + wxTimer m_timer; + wxMessageQueue m_queue; }; } -- cgit v1.2.3