Commits

Qaatloz committed d97334f

Added Keyfile functionality

  • Participants
  • Parent commits 78539ba

Comments (0)

Files changed (5)

File src/KeepassTrueCryptMount/EntryStrings.cs

 
         public const string Volume = "truecrypt.container";
 
+        public const string KeyFiles = "truecrypt.keyfiles";
+
         public const string Readonly = "truecrypt.option.readonly";
 
         public const string Removable = "truecrypt.option.removable";

File src/KeepassTrueCryptMount/Properties/AssemblyInfo.cs

 // by using the '*' as shown below:
 // [assembly: AssemblyVersion("1.0.*")]
 [assembly: AssemblyVersion("2.2.1.*")]
-[assembly: AssemblyFileVersion("2.2.1.0")]
+[assembly: AssemblyFileVersion("2.2.1.1")]

File src/KeepassTrueCryptMount/PwEntryExtension.cs

                 }
             }
 
+            // Keyfiles
+            {
+                var keyFilesString = entry.Strings.GetSafe(EntryStrings.KeyFiles).ReadString();
+                String[] keyFiles = keyFilesString.Split(';');
+                for (int i = 0; i < (keyFiles.Length - 1); i++ )
+                {
+                    arguments.Append(" /k ");
+                    if (keyFiles[i].Contains(" ") && !keyFiles[i].StartsWith("\"") && !keyFiles[i].EndsWith("\""))
+                    {
+                        arguments.AppendFormat("\"{0}\"", keyFiles[i]);
+                    }
+                    else
+                    {
+                        arguments.Append(keyFiles[i]);
+                    }
+
+                }
+               
+            }
+
             // ask for password or set password directly
             {
                 var askForPasswordString = entry.Strings.GetSafe(EntryStrings.AskForPassword).ReadString();
                     arguments.AppendFormat("\"{0}\"", pwd);
                 }
             }
+
             
             return arguments.ToString();
         }

File src/KeepassTrueCryptMount/TrueCryptMountForm.Designer.cs

             this.askPasswordCheckBox = new System.Windows.Forms.CheckBox();
             this.volumeTextBox = new System.Windows.Forms.TextBox();
             this.label1 = new System.Windows.Forms.Label();
-            this.label2 = new System.Windows.Forms.Label();
+            this.label3 = new System.Windows.Forms.Label();
             this.driveComboBox = new System.Windows.Forms.ComboBox();
             this.tipInfo = new System.Windows.Forms.ToolTip(this.components);
             this.btnReloadDrives = new System.Windows.Forms.Button();
+            this.hideDialogCheckBox = new System.Windows.Forms.CheckBox();
             this.toolStripStatusLabel1 = new System.Windows.Forms.ToolStripStatusLabel();
             this.stateToolStripLabel = new System.Windows.Forms.ToolStripStatusLabel();
             this.btnApply = new System.Windows.Forms.Button();
-            this.hideDialogCheckBox = new System.Windows.Forms.CheckBox();
             this.tipWarning = new System.Windows.Forms.ToolTip(this.components);
             this.button1 = new System.Windows.Forms.Button();
+            this.keyFilesTextBox = new System.Windows.Forms.TextBox();
+            this.button2 = new System.Windows.Forms.Button();
+            this.label2 = new System.Windows.Forms.Label();
             this.mountOptionsGroupBox.SuspendLayout();
             this.mountOptionsLayoutPanel.SuspendLayout();
             this.SuspendLayout();
             // m_lblSeparator
             // 
             this.m_lblSeparator.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
-            this.m_lblSeparator.Location = new System.Drawing.Point(0, 279);
+            this.m_lblSeparator.Location = new System.Drawing.Point(3, 322);
             this.m_lblSeparator.Name = "m_lblSeparator";
             this.m_lblSeparator.Size = new System.Drawing.Size(475, 2);
             this.m_lblSeparator.TabIndex = 7;
             // btnCancel
             // 
             this.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
-            this.btnCancel.Location = new System.Drawing.Point(393, 284);
+            this.btnCancel.Location = new System.Drawing.Point(396, 327);
             this.btnCancel.Name = "btnCancel";
             this.btnCancel.Size = new System.Drawing.Size(75, 23);
             this.btnCancel.TabIndex = 6;
             // btnOK
             // 
             this.btnOK.DialogResult = System.Windows.Forms.DialogResult.OK;
-            this.btnOK.Location = new System.Drawing.Point(312, 284);
+            this.btnOK.Location = new System.Drawing.Point(315, 327);
             this.btnOK.Name = "btnOK";
             this.btnOK.Size = new System.Drawing.Size(75, 23);
             this.btnOK.TabIndex = 5;
             // mountOptionsGroupBox
             // 
             this.mountOptionsGroupBox.Controls.Add(this.mountOptionsLayoutPanel);
-            this.mountOptionsGroupBox.Location = new System.Drawing.Point(0, 190);
+            this.mountOptionsGroupBox.Location = new System.Drawing.Point(3, 233);
             this.mountOptionsGroupBox.Name = "mountOptionsGroupBox";
             this.mountOptionsGroupBox.Size = new System.Drawing.Size(468, 79);
             this.mountOptionsGroupBox.TabIndex = 8;
             this.label1.TabIndex = 10;
             this.label1.Text = "Volume File | Partition | Harddrive";
             // 
-            // label2
+            // label3
             // 
-            this.label2.AutoSize = true;
-            this.label2.Location = new System.Drawing.Point(3, 138);
-            this.label2.Name = "label2";
-            this.label2.Size = new System.Drawing.Size(58, 13);
-            this.label2.TabIndex = 12;
-            this.label2.Text = "Drive letter";
+            this.label3.AutoSize = true;
+            this.label3.Location = new System.Drawing.Point(6, 181);
+            this.label3.Name = "label3";
+            this.label3.Size = new System.Drawing.Size(58, 13);
+            this.label3.TabIndex = 12;
+            this.label3.Text = "Drive letter";
             // 
             // driveComboBox
             // 
             this.driveComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
             this.driveComboBox.FormattingEnabled = true;
-            this.driveComboBox.Location = new System.Drawing.Point(6, 154);
+            this.driveComboBox.Location = new System.Drawing.Point(9, 197);
             this.driveComboBox.Name = "driveComboBox";
             this.driveComboBox.Size = new System.Drawing.Size(121, 21);
             this.driveComboBox.TabIndex = 13;
             // 
             this.btnReloadDrives.BackgroundImage = global::KeePassTrueCryptMount.Resources.B16x16_Button_Reload;
             this.btnReloadDrives.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Center;
-            this.btnReloadDrives.Location = new System.Drawing.Point(133, 152);
+            this.btnReloadDrives.Location = new System.Drawing.Point(136, 195);
             this.btnReloadDrives.Name = "btnReloadDrives";
             this.btnReloadDrives.Size = new System.Drawing.Size(35, 24);
             this.btnReloadDrives.TabIndex = 17;
             this.btnReloadDrives.UseVisualStyleBackColor = true;
             this.btnReloadDrives.Click += new System.EventHandler(this.OnReloadDrivesButtonClicked);
             // 
+            // hideDialogCheckBox
+            // 
+            this.hideDialogCheckBox.AutoSize = true;
+            this.hideDialogCheckBox.Location = new System.Drawing.Point(97, 331);
+            this.hideDialogCheckBox.Name = "hideDialogCheckBox";
+            this.hideDialogCheckBox.Size = new System.Drawing.Size(124, 17);
+            this.hideDialogCheckBox.TabIndex = 16;
+            this.hideDialogCheckBox.Text = "Hide dialog next time";
+            this.tipInfo.SetToolTip(this.hideDialogCheckBox, "By check this option the next mount operation starts without\r\nshowing this dialog" +
+        ". To show it again, hold the SHIFT key by\r\nclick the \"Mount volume\" menu item.");
+            this.hideDialogCheckBox.UseVisualStyleBackColor = true;
+            this.hideDialogCheckBox.CheckedChanged += new System.EventHandler(this.OnAnyOptionChanged);
+            // 
             // toolStripStatusLabel1
             // 
             this.toolStripStatusLabel1.Name = "toolStripStatusLabel1";
             // 
             // btnApply
             // 
-            this.btnApply.Location = new System.Drawing.Point(6, 284);
+            this.btnApply.Location = new System.Drawing.Point(9, 327);
             this.btnApply.Name = "btnApply";
             this.btnApply.Size = new System.Drawing.Size(80, 23);
             this.btnApply.TabIndex = 15;
             this.btnApply.Text = "&Apply";
             this.btnApply.UseVisualStyleBackColor = true;
             // 
-            // hideDialogCheckBox
-            // 
-            this.hideDialogCheckBox.AutoSize = true;
-            this.hideDialogCheckBox.Location = new System.Drawing.Point(94, 288);
-            this.hideDialogCheckBox.Name = "hideDialogCheckBox";
-            this.hideDialogCheckBox.Size = new System.Drawing.Size(124, 17);
-            this.hideDialogCheckBox.TabIndex = 16;
-            this.hideDialogCheckBox.Text = "Hide dialog next time";
-            this.tipInfo.SetToolTip(this.hideDialogCheckBox, "By check this option the next mount operation starts without\r\nshowing this dialog" +
-        ". To show it again, hold the SHIFT key by\r\nclick the \"Mount volume\" menu item.");
-            this.hideDialogCheckBox.UseVisualStyleBackColor = true;
-            this.hideDialogCheckBox.CheckedChanged += new System.EventHandler(this.OnAnyOptionChanged);
-            // 
             // tipWarning
             // 
             this.tipWarning.AutoPopDelay = 30000;
             this.button1.UseVisualStyleBackColor = true;
             this.button1.Click += new System.EventHandler(this.OnFileOpenDialogButtonClicked);
             // 
+            // keyFilesTextBox
+            // 
+            this.keyFilesTextBox.Location = new System.Drawing.Point(6, 150);
+            this.keyFilesTextBox.Name = "keyFilesTextBox";
+            this.keyFilesTextBox.Size = new System.Drawing.Size(421, 20);
+            this.keyFilesTextBox.TabIndex = 18;
+            this.keyFilesTextBox.TextChanged += new System.EventHandler(this.OnAnyOptionChanged);
+            // 
+            // button2
+            // 
+            this.button2.Image = global::KeePassTrueCryptMount.Resources.B16x16_Folder_Yellow_Open;
+            this.button2.Location = new System.Drawing.Point(433, 147);
+            this.button2.Name = "button2";
+            this.button2.Size = new System.Drawing.Size(35, 24);
+            this.button2.TabIndex = 19;
+            this.button2.UseVisualStyleBackColor = true;
+            this.button2.Click += new System.EventHandler(this.OnFileOpenDialogButtonClicked);
+            // 
+            // label2
+            // 
+            this.label2.AutoSize = true;
+            this.label2.Location = new System.Drawing.Point(6, 132);
+            this.label2.Name = "label2";
+            this.label2.Size = new System.Drawing.Size(52, 13);
+            this.label2.TabIndex = 20;
+            this.label2.Text = "KeyFile(s)";
+            // 
             // TrueCryptMountForm
             // 
             this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
             this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
-            this.ClientSize = new System.Drawing.Size(480, 314);
+            this.ClientSize = new System.Drawing.Size(480, 359);
+            this.Controls.Add(this.label2);
+            this.Controls.Add(this.button2);
+            this.Controls.Add(this.keyFilesTextBox);
             this.Controls.Add(this.btnReloadDrives);
             this.Controls.Add(this.hideDialogCheckBox);
             this.Controls.Add(this.btnApply);
             this.Controls.Add(this.driveComboBox);
-            this.Controls.Add(this.label2);
+            this.Controls.Add(this.label3);
             this.Controls.Add(this.button1);
             this.Controls.Add(this.label1);
             this.Controls.Add(this.volumeTextBox);
         private System.Windows.Forms.TextBox volumeTextBox;
         private System.Windows.Forms.Label label1;
         private System.Windows.Forms.Button button1;
-        private System.Windows.Forms.Label label2;
+        private System.Windows.Forms.Label label3;
         private System.Windows.Forms.ComboBox driveComboBox;
         private System.Windows.Forms.ToolTip tipInfo;
         private System.Windows.Forms.CheckBox silentCheckBox;
         private System.Windows.Forms.CheckBox askPasswordCheckBox;
         private System.Windows.Forms.Button btnReloadDrives;
         private System.Windows.Forms.ToolTip tipWarning;
+        private System.Windows.Forms.TextBox keyFilesTextBox;
+        private System.Windows.Forms.Button button2;
+        private System.Windows.Forms.Label label2;
     }
 }

File src/KeepassTrueCryptMount/TrueCryptMountForm.cs

             get { return this.volumeTextBox.Text; }
         }
 
+        public string KeyFiles
+        {
+            get { return this.keyFilesTextBox.Text; }
+        }
+
         public string DriveLetter
         {
             get
             var containerString = entry.Strings.GetSafe(EntryStrings.Volume);
             this.volumeTextBox.Text = containerString != null ? containerString.ReadString() : string.Empty;
 
+            // KeyFiles
+            var KeyFilesString = entry.Strings.GetSafe(EntryStrings.KeyFiles);
+            this.keyFilesTextBox.Text = KeyFilesString != null ? KeyFilesString.ReadString() : string.Empty;
+
             // drive
             this.driveComboBox.SelectedIndex = 0;
 
         public TrueCryptMountForm WriteTo(PwEntry entry)
         {
             entry.Strings.Set(EntryStrings.Volume, new ProtectedString(false, this.ContainerVolume));
+            entry.Strings.Set(EntryStrings.KeyFiles, new ProtectedString(false, this.KeyFiles));
             entry.Strings.Set(EntryStrings.DriveLetter, new ProtectedString(false, this.DriveLetter));
             entry.Strings.Set(EntryStrings.Enabled, new ProtectedString(false, true.ToString()));
             entry.Strings.Set(EntryStrings.MountWithoutDialog, new ProtectedString(false, this.HideForEntry.ToString()));
         private void OnFileOpenDialogButtonClicked(object sender, EventArgs e)
         {
             var dialog = new OpenFileDialog();
-            dialog.Multiselect = false;
-            
-            if (dialog.ShowDialog(this) == DialogResult.OK && dialog.CheckFileExists)
+            if (sender.Equals(button2))
             {
-                this.volumeTextBox.Text = dialog.FileName;
+                dialog.Multiselect = true;
+                if (dialog.ShowDialog(this) == DialogResult.OK && dialog.CheckFileExists)
+                {
+                    var keyFiles = new StringBuilder();
+                    foreach (string i in dialog.FileNames)
+                    {
+                        keyFiles.Append(i + ";");
+                    }
+                    this.keyFilesTextBox.Text = keyFiles.ToString();
+                }
+            }else if(sender.Equals(button1))
+            {
+                dialog.Multiselect = false;
+            
+                if (dialog.ShowDialog(this) == DialogResult.OK && dialog.CheckFileExists)
+                {
+                    this.volumeTextBox.Text = dialog.FileNames.ToString();
+                }
             }
         }