"Fossies" - the Fresh Open Source Software Archive

Member "src/Main/Forms/MountOptionsDialog.cpp" (10 Oct 2018, 7615 Bytes) of package /windows/misc/VeraCrypt_1.23-Hotfix-2_Source.zip:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "MountOptionsDialog.cpp" see the Fossies "Dox" file reference documentation and the last Fossies "Diffs" side-by-side code changes report: 1.22_Source_vs_1.23_Source.

    1 /*
    2  Derived from source code of TrueCrypt 7.1a, which is
    3  Copyright (c) 2008-2012 TrueCrypt Developers Association and which is governed
    4  by the TrueCrypt License 3.0.
    5 
    6  Modifications and additions to the original source code (contained in this file)
    7  and all other portions of this file are Copyright (c) 2013-2017 IDRIX
    8  and are governed by the Apache License 2.0 the full text of which is
    9  contained in the file License.txt included in VeraCrypt binary and source
   10  code distribution packages.
   11 */
   12 
   13 #include "System.h"
   14 #include "Main/Main.h"
   15 #include "Main/GraphicUserInterface.h"
   16 #include "MountOptionsDialog.h"
   17 
   18 namespace VeraCrypt
   19 {
   20 #ifdef TC_MACOSX
   21 
   22     bool MountOptionsDialog::ProcessEvent(wxEvent& event)
   23     {
   24         if(GraphicUserInterface::HandlePasswordEntryCustomEvent (event))
   25             return true;
   26         else
   27             return MountOptionsDialogBase::ProcessEvent(event);
   28     }
   29 #endif
   30 
   31     MountOptionsDialog::MountOptionsDialog (wxWindow *parent, MountOptions &options, const wxString &title, bool disableMountOptions)
   32         : MountOptionsDialogBase (parent, wxID_ANY, wxString()
   33 #ifdef __WXGTK__ // GTK apparently needs wxRESIZE_BORDER to support dynamic resizing
   34         , wxDefaultPosition, wxSize (-1,-1), wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER
   35 #endif
   36         ), Options (options)
   37     {
   38         if (!title.empty())
   39             this->SetTitle (title);
   40         else if (options.Path && !options.Path->IsEmpty())
   41             this->SetTitle (StringFormatter (LangString["ENTER_PASSWORD_FOR"], wstring (*options.Path)));
   42         else
   43             this->SetTitle (LangString["ENTER_TC_VOL_PASSWORD"]);
   44 
   45         if (disableMountOptions)
   46             OptionsButton->Show (false);
   47             
   48 
   49 #ifdef TC_MACOSX
   50         GraphicUserInterface::InstallPasswordEntryCustomKeyboardShortcuts (this);
   51 #endif
   52 
   53         PasswordPanel = new VolumePasswordPanel (this, &options, options.Password, disableMountOptions, options.Keyfiles, !disableMountOptions, true, true, false, true, true);
   54         PasswordPanel->SetCacheCheckBoxValidator (wxGenericValidator (&Options.CachePassword));
   55         
   56         if (options.Path && options.Path->HasTrueCryptExtension() && !disableMountOptions 
   57             && !options.TrueCryptMode && (options.Pim <= 0))
   58         {
   59             PasswordPanel->SetTrueCryptMode (true); 
   60         }
   61 
   62         PasswordSizer->Add (PasswordPanel, 1, wxALL | wxEXPAND);
   63 
   64 #ifdef __WXGTK__
   65         FilesystemOptionsSizer->Remove (FilesystemSpacer);
   66         OptionsPanel->Show (false);
   67         Fit();
   68         Layout();
   69         SetMinSize (GetSize());
   70 #endif
   71 
   72         NoFilesystemCheckBox->SetValidator (wxGenericValidator (&Options.NoFilesystem));
   73         RemovableCheckBox->SetValidator (wxGenericValidator (&Options.Removable));
   74         PartitionInSystemEncryptionScopeCheckBox->SetValidator (wxGenericValidator (&Options.PartitionInSystemEncryptionScope));
   75 
   76         TransferDataToWindow();
   77 
   78         if (Options.MountPoint && !Options.MountPoint->IsEmpty())
   79              MountPointTextCtrl->SetValue (wstring (*Options.MountPoint));
   80 
   81         FilesystemOptionsTextCtrl->SetValue (Options.FilesystemOptions);
   82 
   83         ReadOnlyCheckBox->SetValue (Options.Protection == VolumeProtection::ReadOnly);
   84         BackupHeaderCheckBox->SetValidator (wxGenericValidator (&Options.UseBackupHeaders));
   85         ProtectionCheckBox->SetValue (Options.Protection == VolumeProtection::HiddenVolumeReadOnly);
   86 
   87         OptionsButtonLabel = OptionsButton->GetLabel();
   88         OptionsButton->SetLabel (OptionsButtonLabel + L" >");
   89         OptionsPanel->Show (false);
   90 
   91         ProtectionPasswordPanel = new VolumePasswordPanel (OptionsPanel, &options, options.ProtectionPassword, true, options.ProtectionKeyfiles, false, true, true, false, true, true, _("P&assword to hidden volume:"));
   92         ProtectionPasswordSizer->Add (ProtectionPasswordPanel, 1, wxALL | wxEXPAND);
   93 
   94         UpdateDialog();
   95         Center();
   96     }
   97 
   98     void MountOptionsDialog::OnInitDialog (wxInitDialogEvent& event)
   99     {
  100         PasswordPanel->SetFocusToPasswordTextCtrl();
  101     }
  102 
  103     void MountOptionsDialog::OnMountPointButtonClick (wxCommandEvent& event)
  104     {
  105         DirectoryPath dir = Gui->SelectDirectory (this, wxEmptyString, false);
  106         if (!dir.IsEmpty())
  107             MountPointTextCtrl->SetValue (wstring (dir));
  108     }
  109 
  110     void MountOptionsDialog::OnOKButtonClick (wxCommandEvent& event)
  111     {
  112         bool bUnsupportedKdf = false;
  113 
  114         /* verify that PIM values are valid before continuing*/
  115         int Pim = PasswordPanel->GetVolumePim();
  116         int ProtectionPim = (!ReadOnlyCheckBox->IsChecked() && ProtectionCheckBox->IsChecked())?
  117             ProtectionPasswordPanel->GetVolumePim() : 0;
  118 
  119         /* invalid PIM: set focus to PIM field and stop processing */
  120         if (-1 == Pim || (PartitionInSystemEncryptionScopeCheckBox->IsChecked() && Pim > MAX_BOOT_PIM_VALUE))
  121         {
  122             PasswordPanel->SetFocusToPimTextCtrl();
  123             return;
  124         }
  125 
  126         if (-1 == ProtectionPim || (PartitionInSystemEncryptionScopeCheckBox->IsChecked() && ProtectionPim > MAX_BOOT_PIM_VALUE))
  127         {
  128             ProtectionPasswordPanel->SetFocusToPimTextCtrl();
  129             return;
  130         }
  131 
  132         TransferDataFromWindow();
  133 
  134         try
  135         {
  136             Options.Password = PasswordPanel->GetPassword();
  137         }
  138         catch (PasswordException& e)
  139         {
  140             Gui->ShowWarning (e);
  141             return;
  142         }
  143         Options.Pim = Pim;
  144         Options.Kdf = PasswordPanel->GetPkcs5Kdf(bUnsupportedKdf);
  145         if (bUnsupportedKdf)
  146         {
  147             Gui->ShowWarning (LangString ["ALGO_NOT_SUPPORTED_FOR_TRUECRYPT_MODE"]);
  148             return;
  149         }
  150         Options.TrueCryptMode = PasswordPanel->GetTrueCryptMode();
  151         Options.Keyfiles = PasswordPanel->GetKeyfiles();
  152 
  153         if (ReadOnlyCheckBox->IsChecked())
  154         {
  155             Options.Protection = VolumeProtection::ReadOnly;
  156         }
  157         else if (ProtectionCheckBox->IsChecked())
  158         {
  159             try
  160             {
  161                 Options.ProtectionPassword = ProtectionPasswordPanel->GetPassword();
  162             }
  163             catch (PasswordException& e)
  164             {
  165                 Gui->ShowWarning (e);
  166                 return;
  167             }
  168             Options.Protection = VolumeProtection::HiddenVolumeReadOnly;
  169             Options.ProtectionPim = ProtectionPim;
  170             Options.ProtectionKdf = ProtectionPasswordPanel->GetPkcs5Kdf(Options.TrueCryptMode, bUnsupportedKdf);
  171             if (bUnsupportedKdf)
  172             {
  173                 Gui->ShowWarning (LangString ["ALGO_NOT_SUPPORTED_FOR_TRUECRYPT_MODE"]);
  174                 return;
  175             }
  176             Options.ProtectionKeyfiles = ProtectionPasswordPanel->GetKeyfiles();
  177         }
  178         else
  179         {
  180             Options.Protection = VolumeProtection::None;
  181         }
  182 
  183         wstring mountPoint (MountPointTextCtrl->GetValue());
  184         if (!mountPoint.empty())
  185             Options.MountPoint = make_shared <DirectoryPath> (mountPoint);
  186 
  187         Options.FilesystemOptions = FilesystemOptionsTextCtrl->GetValue();
  188 
  189         EndModal (wxID_OK);
  190     }
  191 
  192     void MountOptionsDialog::OnOptionsButtonClick (wxCommandEvent& event)
  193     {
  194         FreezeScope freeze (this);
  195         OptionsPanel->Show (!OptionsPanel->IsShown());
  196         UpdateDialog();
  197         OptionsButton->SetLabel (OptionsButtonLabel + (OptionsPanel->IsShown() ? L" <" : L" >"));
  198     }
  199 
  200     void MountOptionsDialog::OnProtectionCheckBoxClick (wxCommandEvent& event)
  201     {
  202         FreezeScope freeze (this);
  203         ProtectionPasswordPanel->Show (event.IsChecked());
  204         Fit();
  205         Layout();
  206         ProtectionPasswordPanel->SetFocusToPasswordTextCtrl();
  207     }
  208 
  209     void MountOptionsDialog::OnProtectionHyperlinkClick (wxHyperlinkEvent& event)
  210     {
  211         Gui->OpenHomepageLink (this, L"hiddenvolprotection");
  212     }
  213 
  214     void MountOptionsDialog::UpdateDialog ()
  215     {
  216         FreezeScope freeze (this);
  217 
  218 #ifdef TC_WINDOWS
  219         FilesystemSizer->Show (false);
  220 #else
  221         FilesystemOptionsSizer->Show (!NoFilesystemCheckBox->IsChecked());
  222 
  223 #   ifdef TC_MACOSX
  224         FilesystemOptionsStaticText->Show (false);
  225         FilesystemOptionsTextCtrl->Show (false);
  226 #   endif
  227 
  228         if (!Options.Path || Options.Path->IsEmpty())
  229         {
  230             MountPointTextCtrlStaticText->Show (false);
  231             MountPointTextCtrl->Show (false);
  232             MountPointButton->Show (false);
  233         }
  234         RemovableCheckBox->Show (false);
  235 #endif
  236         ProtectionSizer->Show (!ReadOnlyCheckBox->IsChecked());
  237         ProtectionPasswordPanel->Show (!ReadOnlyCheckBox->IsChecked() && ProtectionCheckBox->IsChecked());
  238 
  239         Fit();
  240         Layout();
  241         MainSizer->Fit( this );
  242     }
  243 }