|
|
1.1 ! root 1: /* ! 2: Copyright (c) 2008 TrueCrypt Foundation. All rights reserved. ! 3: ! 4: Governed by the TrueCrypt License 2.4 the full text of which is contained ! 5: in the file License.txt included in TrueCrypt binary and source code ! 6: distribution packages. ! 7: */ ! 8: ! 9: #include "System.h" ! 10: #include "Main/Main.h" ! 11: #include "Main/GraphicUserInterface.h" ! 12: #include "ChangePasswordDialog.h" ! 13: ! 14: namespace TrueCrypt ! 15: { ! 16: ChangePasswordDialog::ChangePasswordDialog (wxWindow* parent, shared_ptr <VolumePath> volumePath, Mode::Enum mode, shared_ptr <VolumePassword> password, shared_ptr <KeyfileList> keyfiles, shared_ptr <VolumePassword> newPassword, shared_ptr <KeyfileList> newKeyfiles) ! 17: : ChangePasswordDialogBase (parent), DialogMode (mode), Path (volumePath) ! 18: { ! 19: bool enableNewPassword = false; ! 20: bool enableNewKeyfiles = false; ! 21: bool enablePkcs5Prf = false; ! 22: ! 23: switch (mode) ! 24: { ! 25: case Mode::ChangePasswordAndKeyfiles: ! 26: enableNewPassword = true; ! 27: enableNewKeyfiles = true; ! 28: enablePkcs5Prf = true; ! 29: SetTitle (_("Change Volume Password and Keyfiles")); ! 30: break; ! 31: ! 32: case Mode::ChangeKeyfiles: ! 33: enableNewKeyfiles = true; ! 34: SetTitle (_("Add/Remove Keyfiles to/from Volume")); ! 35: break; ! 36: ! 37: case Mode::RemoveAllKeyfiles: ! 38: SetTitle (_("Remove All Keyfiles from Volume")); ! 39: break; ! 40: ! 41: case Mode::ChangePkcs5Prf: ! 42: enablePkcs5Prf = true; ! 43: SetTitle (_("Change Header Key Derivation Algorithm")); ! 44: break; ! 45: ! 46: default: ! 47: throw ParameterIncorrect (SRC_POS); ! 48: } ! 49: ! 50: CurrentPasswordPanel = new VolumePasswordPanel (this, password, keyfiles); ! 51: CurrentPasswordPanel->UpdateEvent.Connect (EventConnector <ChangePasswordDialog> (this, &ChangePasswordDialog::OnPasswordPanelUpdate)); ! 52: CurrentPasswordPanelSizer->Add (CurrentPasswordPanel, 1, wxALL | wxEXPAND); ! 53: ! 54: NewPasswordPanel = new VolumePasswordPanel (this, newPassword, newKeyfiles, false, enableNewPassword, enableNewKeyfiles, enableNewPassword, enablePkcs5Prf); ! 55: NewPasswordPanel->UpdateEvent.Connect (EventConnector <ChangePasswordDialog> (this, &ChangePasswordDialog::OnPasswordPanelUpdate)); ! 56: NewPasswordPanelSizer->Add (NewPasswordPanel, 1, wxALL | wxEXPAND); ! 57: ! 58: if (mode == Mode::RemoveAllKeyfiles) ! 59: NewSizer->Show (false); ! 60: ! 61: Layout(); ! 62: Fit(); ! 63: Center(); ! 64: ! 65: OnPasswordPanelUpdate(); ! 66: CurrentPasswordPanel->SetFocusToPasswordTextCtrl(); ! 67: } ! 68: ! 69: ChangePasswordDialog::~ChangePasswordDialog () ! 70: { ! 71: CurrentPasswordPanel->UpdateEvent.Disconnect (this); ! 72: NewPasswordPanel->UpdateEvent.Disconnect (this); ! 73: } ! 74: ! 75: void ChangePasswordDialog::OnOKButtonClick (wxCommandEvent& event) ! 76: { ! 77: try ! 78: { ! 79: shared_ptr <VolumePassword> newPassword; ! 80: if (DialogMode == Mode::ChangePasswordAndKeyfiles) ! 81: { ! 82: newPassword = NewPasswordPanel->GetPassword(); ! 83: newPassword->CheckPortability(); ! 84: ! 85: if (newPassword->Size() > 0 && newPassword->Size() < VolumePassword::WarningSizeThreshold ! 86: && !Gui->AskYesNo (LangString ["PASSWORD_LENGTH_WARNING"], false, true)) ! 87: { ! 88: NewPasswordPanel->SetFocusToPasswordTextCtrl(); ! 89: return; ! 90: } ! 91: } ! 92: else ! 93: newPassword = CurrentPasswordPanel->GetPassword(); ! 94: ! 95: shared_ptr <KeyfileList> newKeyfiles; ! 96: if (DialogMode == Mode::ChangePasswordAndKeyfiles || DialogMode == Mode::ChangeKeyfiles) ! 97: newKeyfiles = NewPasswordPanel->GetKeyfiles(); ! 98: else if (DialogMode != Mode::RemoveAllKeyfiles) ! 99: newKeyfiles = CurrentPasswordPanel->GetKeyfiles(); ! 100: ! 101: { ! 102: wxBusyCursor busy; ! 103: Core->ChangePassword (Path, Gui->GetPreferences().DefaultMountOptions.PreserveTimestamps, ! 104: CurrentPasswordPanel->GetPassword(), CurrentPasswordPanel->GetKeyfiles(), ! 105: newPassword, newKeyfiles, NewPasswordPanel->GetPkcs5Kdf()); ! 106: } ! 107: ! 108: switch (DialogMode) ! 109: { ! 110: case Mode::ChangePasswordAndKeyfiles: ! 111: Gui->ShowInfo ("PASSWORD_CHANGED"); ! 112: break; ! 113: ! 114: case Mode::ChangeKeyfiles: ! 115: case Mode::RemoveAllKeyfiles: ! 116: Gui->ShowInfo ("KEYFILE_CHANGED"); ! 117: break; ! 118: ! 119: case Mode::ChangePkcs5Prf: ! 120: Gui->ShowInfo ("PKCS5_PRF_CHANGED"); ! 121: break; ! 122: ! 123: default: ! 124: throw ParameterIncorrect (SRC_POS); ! 125: } ! 126: ! 127: EndModal (wxID_OK); ! 128: } ! 129: catch (UnportablePassword &e) ! 130: { ! 131: Gui->ShowError (e); ! 132: NewPasswordPanel->SetFocusToPasswordTextCtrl(); ! 133: } ! 134: catch (PasswordException &e) ! 135: { ! 136: Gui->ShowWarning (e); ! 137: CurrentPasswordPanel->SetFocusToPasswordTextCtrl(); ! 138: } ! 139: catch (exception &e) ! 140: { ! 141: Gui->ShowError (e); ! 142: } ! 143: } ! 144: ! 145: void ChangePasswordDialog::OnPasswordPanelUpdate () ! 146: { ! 147: bool ok = true; ! 148: ! 149: bool passwordEmpty = CurrentPasswordPanel->GetPassword()->IsEmpty(); ! 150: bool keyfilesEmpty = !CurrentPasswordPanel->GetKeyfiles() || CurrentPasswordPanel->GetKeyfiles()->empty(); ! 151: ! 152: if (passwordEmpty && keyfilesEmpty) ! 153: ok = false; ! 154: ! 155: if (DialogMode == Mode::RemoveAllKeyfiles && (passwordEmpty || keyfilesEmpty)) ! 156: ok = false; ! 157: ! 158: if (DialogMode == Mode::ChangePasswordAndKeyfiles || DialogMode == Mode::ChangeKeyfiles) ! 159: { ! 160: bool newKeyfilesEmpty = !NewPasswordPanel->GetKeyfiles() || NewPasswordPanel->GetKeyfiles()->empty(); ! 161: ! 162: if (DialogMode == Mode::ChangeKeyfiles ! 163: && (passwordEmpty && newKeyfilesEmpty || keyfilesEmpty && newKeyfilesEmpty)) ! 164: ok = false; ! 165: ! 166: if (DialogMode == Mode::ChangePasswordAndKeyfiles ! 167: && (NewPasswordPanel->GetPassword()->IsEmpty() && newKeyfilesEmpty || !NewPasswordPanel->PasswordsMatch())) ! 168: ok = false; ! 169: } ! 170: ! 171: OKButton->Enable (ok); ! 172: } ! 173: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.