Skip to content

Commit

Permalink
Fix issue with saving secrets on imported pads from Aegis
Browse files Browse the repository at this point in the history
  • Loading branch information
jhaygood86 committed Oct 23, 2021
1 parent 00cc4c0 commit 435574f
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 13 deletions.
4 changes: 2 additions & 2 deletions src/MainWindow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Expand All @@ -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);
}

});
Expand Down
23 changes: 19 additions & 4 deletions src/OneTimePad.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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 ();

Expand Down Expand Up @@ -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:
Expand Down
11 changes: 7 additions & 4 deletions src/OneTimePadLibrary.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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 ();

Expand Down
5 changes: 2 additions & 3 deletions src/Widgets/OneTimePadView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 435574f

Please sign in to comment.