From 435574f50c70fc6cea944176182cd03c008201bf Mon Sep 17 00:00:00 2001 From: Justin Haygood Date: Fri, 22 Oct 2021 20:03:44 -0400 Subject: [PATCH] Fix issue with saving secrets on imported pads from Aegis --- src/MainWindow.vala | 4 ++-- src/OneTimePad.vala | 23 +++++++++++++++++++---- src/OneTimePadLibrary.vala | 11 +++++++---- src/Widgets/OneTimePadView.vala | 5 ++--- 4 files changed, 30 insertions(+), 13 deletions(-) diff --git a/src/MainWindow.vala b/src/MainWindow.vala index f0919ae..f5211bf 100644 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -163,7 +163,7 @@ public class Mauborgne.MainWindow : Hdy.ApplicationWindow { if (vault != null) { foreach (var entry in vault.entries) { var otp = new OneTimePad.from_aegis_vault_entry(entry); - otp_library.add(otp); + otp_library.add.begin(otp); } } } @@ -176,7 +176,7 @@ public class Mauborgne.MainWindow : Hdy.ApplicationWindow { if(qr_code_uri.length > 0){ var otp = new OneTimePad.from_uri(qr_code_uri); - otp_library.add(otp); + otp_library.add.begin(otp); } }); diff --git a/src/OneTimePad.vala b/src/OneTimePad.vala index 7688c7d..2421d6e 100644 --- a/src/OneTimePad.vala +++ b/src/OneTimePad.vala @@ -303,10 +303,7 @@ public class OneTimePad { public async string get_otp_code () { - if (secret != null) { - yield store_secret(secret); - secret = null; - } + yield save_secret (); var secret_value = yield lookup_secret (); @@ -340,6 +337,24 @@ public class OneTimePad { return yield Secret.password_clearv (schema, attributes, null); } + public async void save_secret () { + if (secret != null) { + + print("storing secret using libsecret...\n"); + + var existing_secret = yield lookup_secret(); + + if (existing_secret != null) { + yield clear_secret (); + } + + yield store_secret(secret); + secret = null; + + print("secret stored successfully\n"); + } + } + private static Cotp.Algorithm get_cotp_algorithm(OneTimePadAlgorithm algorithm) { switch (algorithm) { case OneTimePadAlgorithm.SHA1: diff --git a/src/OneTimePadLibrary.vala b/src/OneTimePadLibrary.vala index 247a32d..314e808 100644 --- a/src/OneTimePadLibrary.vala +++ b/src/OneTimePadLibrary.vala @@ -19,14 +19,17 @@ public class OneTimePadLibrary : Object { return _instance; } - public void add(OneTimePad otp) { - pads_set.add(otp); + public async void add(OneTimePad otp) { + pads_set.add (otp); + yield save (otp); changed (); - save(otp); } - public void save(OneTimePad pad) { + public async void save(OneTimePad pad) { if(pads_set.contains(pad)){ + + yield pad.save_secret(); + var file = pad.to_keyfile (); var file_name = pad.get_file_name (); diff --git a/src/Widgets/OneTimePadView.vala b/src/Widgets/OneTimePadView.vala index 7e15b77..f73411a 100644 --- a/src/Widgets/OneTimePadView.vala +++ b/src/Widgets/OneTimePadView.vala @@ -148,14 +148,13 @@ public class OneTimePadView : Gtk.Grid { private void on_pad_set() { + has_pad = pad != null; + if (pad == null) { - has_pad = false; switch_to_welcome_screen (); return; } - has_pad = true; - switch_to_code_display (); title_label.label = pad.account_name;