Skip to content

Commit

Permalink
Add option to display Master key
Browse files Browse the repository at this point in the history
Signed-off-by: moson-mo <mo-son@mailbox.org>
  • Loading branch information
moson-mo committed Jan 26, 2024
1 parent 6003303 commit 29a0734
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
18 changes: 18 additions & 0 deletions src/Gocrypt.vala
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,24 @@ namespace Cryptor {
}
}

public static string ? get_master_key (string path, string password) throws Error {
string ? standard_output, standard_error;
string[] cmd = { "gocryptfs-xray", "-dumpmasterkey", path + "/gocryptfs.conf" };

var sp = new Subprocess.newv (cmd, SubprocessFlags.STDIN_PIPE | SubprocessFlags.STDERR_PIPE | SubprocessFlags.STDOUT_PIPE);
sp.communicate_utf8 (password + "\n", null, out standard_output, out standard_error);
var status = sp.get_exit_status ();

if (standard_error != null && standard_error != "") {
throw new Error (Quark.from_string ("Cryptor"), status, standard_error);
}
if (status != 0) {
throw new Error (Quark.from_string ("Cryptor"), status, standard_output);
}

return standard_output;
}

private static File write_password_file (string password) throws Error {
FileIOStream ps;
var temp_file = File.new_tmp (null, out ps);
Expand Down
16 changes: 15 additions & 1 deletion src/ui/CryptorWindow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ namespace Cryptor.UI {

public CryptorWindow (Gtk.Application app) {
Object (
application: app
application : app
);

config = new Config ();
Expand Down Expand Up @@ -293,6 +293,19 @@ namespace Cryptor.UI {
edit.activate.connect (() => {
show_vault_window (get_selected_rownumber ());
});
var mkey = Utils.get_image_menu_item ("gtk-justify-fill", _("Show Master key"));
mkey.activate.connect (() => {
var password = Utils.show_password_entry (this, false, false);
if (password == null) {
return;
}
try {
var key = Gocrypt.get_master_key (vault.path, password);
Utils.show_info_textbox (this, _("Master key:"), key.replace ("\n", ""));
} catch (Error e) {
Utils.show_error (this, e.message);
}
});
var remove = Utils.get_image_menu_item ("gtk-remove", _("Remove"));
remove.sensitive = !vault.is_mounted;
remove.activate.connect (() => {
Expand All @@ -301,6 +314,7 @@ namespace Cryptor.UI {
});
menu.add (open);
menu.add (mount);
menu.add (mkey);
menu.add (edit);
menu.add (remove);
menu.show_all ();
Expand Down
13 changes: 13 additions & 0 deletions src/ui/Utils.vala
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,19 @@ namespace Cryptor.UI {
dialog.destroy ();
}

public static void show_info_textbox (Window parent, string title, string message) {
var dialog = new MessageDialog (parent, Gtk.DialogFlags.MODAL, Gtk.MessageType.INFO, Gtk.ButtonsType.OK, "%s", title);
var area = dialog.get_content_area ();
var entry = new Entry ();
entry.editable = false;
entry.width_chars = message.length;
entry.text = message;
area.pack_end (entry, false, false, 0);
dialog.show_all ();
dialog.run ();
dialog.destroy ();
}

public static string ? show_password_entry (Window parent, bool reenter, bool newpw) {
string message;
string ? ret = null;
Expand Down

0 comments on commit 29a0734

Please sign in to comment.