From 8b84367198d6b30c9c24ce81cfad2e9ec7f48ecb Mon Sep 17 00:00:00 2001 From: Dan Breslau Date: Fri, 19 Aug 2016 14:23:19 -0400 Subject: [PATCH] Fixed bugs in tracking TrustAnchor datetime-added --- src/moonshot-id.vala | 13 +++++++------ src/moonshot-identities-manager.vala | 16 +++++++++++----- src/moonshot-identity-management-view.vala | 2 +- src/moonshot-keyring-store.vala | 4 ++-- src/moonshot-local-flat-file-store.vala | 8 +++++--- 5 files changed, 26 insertions(+), 17 deletions(-) diff --git a/src/moonshot-id.vala b/src/moonshot-id.vala index dcf4bc9..051d15d 100644 --- a/src/moonshot-id.vala +++ b/src/moonshot-id.vala @@ -125,23 +125,24 @@ public class TrustAnchor : Object public int Compare(TrustAnchor other) { if (this.ca_cert != other.ca_cert) { + // IdCard.logger.trace("TrustAnchor.Compare: this.ca_cert='%s'; other.ca_cert='%s'".printf(this.ca_cert, other.ca_cert)); return 1; } if (this.subject != other.subject) { + // IdCard.logger.trace("TrustAnchor.Compare: this.subject='%s'; other.subject='%s'".printf(this.subject, other.subject)); return 1; } if (this.subject_alt != other.subject_alt) { + // IdCard.logger.trace("TrustAnchor.Compare: this.subject_alt='%s'; other.subject_alt='%s'".printf(this.subject_alt, other.subject_alt)); return 1; } if (this.server_cert != other.server_cert) { + // IdCard.logger.trace("TrustAnchor.Compare: this.server_cert=%s'; other.server_cert='%s'".printf(this.server_cert, other.server_cert)); return 1; } - if (this.user_verified != other.user_verified) { - return 1; - } - // if (!is_empty() && this.datetime_added != other.datetime_added) { - // return 1; - // } + + // Do not compare the user_verified and datetime_added fields; they are not essential. + return 0; } diff --git a/src/moonshot-identities-manager.vala b/src/moonshot-identities-manager.vala index a1cac6b..6ef9de6 100644 --- a/src/moonshot-identities-manager.vala +++ b/src/moonshot-identities-manager.vala @@ -142,7 +142,7 @@ public class IdentityManagerModel : Object { return true; } - private bool remove_duplicates(IdCard card) + private bool remove_duplicates(IdCard new_card) { bool duplicate_found = false; bool found = false; @@ -150,11 +150,17 @@ public class IdentityManagerModel : Object { var cards = this.store.get_card_list(); found = false; foreach (IdCard id_card in cards) { - if ((card != id_card) && (id_card.nai == card.nai)) { - stdout.printf("removing duplicate id for '%s'\n", card.nai); - logger.trace("removing duplicate id for '%s'\n".printf(card.nai)); + if ((new_card != id_card) && (id_card.nai == new_card.nai)) { + stdout.printf("removing duplicate id for '%s'\n", new_card.nai); + logger.trace("removing duplicate id for '%s'\n".printf(new_card.nai)); remove_card_internal(id_card); found = duplicate_found = true; + + if (new_card.trust_anchor.Compare(id_card.trust_anchor) == 0) { + logger.trace("Old and new cards have same trust anchor. Re-using the datetime_added and user_verified fields from the old card."); + new_card.trust_anchor.set_datetime_added(id_card.trust_anchor.datetime_added); + new_card.trust_anchor.user_verified = id_card.trust_anchor.user_verified; + } break; } } @@ -203,7 +209,7 @@ public class IdentityManagerModel : Object { if (!card.store_password) password_table.CachePassword(card, store); - logger.trace("add_card: Storing card '%s' with services: '%s'" + logger.trace("add_card: Adding card '%s' with services: '%s'" .printf(card.display_name, card.get_services_string("; "))); store.add_card(card); diff --git a/src/moonshot-identity-management-view.vala b/src/moonshot-identity-management-view.vala index fae10f0..b516f9f 100644 --- a/src/moonshot-identity-management-view.vala +++ b/src/moonshot-identity-management-view.vala @@ -231,7 +231,7 @@ public class IdentityManagerView : Window { } foreach (IdCard id_card in card_list) { - logger.trace(@"load_id_cards: Adding card with display name '$(id_card.display_name)'"); + logger.trace(@"load_id_cards: Loading card with display name '$(id_card.display_name)'"); add_id_card_data(id_card); IdCardWidget id_card_widget = add_id_card_widget(id_card); if (id_card_widget.id_card.nai == current_idcard_nai) { diff --git a/src/moonshot-keyring-store.vala b/src/moonshot-keyring-store.vala index d32fc71..fca2371 100644 --- a/src/moonshot-keyring-store.vala +++ b/src/moonshot-keyring-store.vala @@ -142,7 +142,7 @@ public class KeyringStore : Object, IIdentityCardStore { subject_alt = value; } else if (attribute.name == "StorePassword") { store_password = value; - } else if (attribute.name == "CACert_User_Verified") { + } else if (attribute.name == "TA_User_Verified") { user_verified = (value == "true"); } else if (attribute.name == "TA_DateTime_Added") { ta_datetime_added = value; @@ -212,7 +212,7 @@ public class KeyringStore : Object, IIdentityCardStore { attributes.append_string("Server-Cert", id_card.trust_anchor.server_cert); attributes.append_string("Subject", id_card.trust_anchor.subject); attributes.append_string("Subject-Alt", id_card.trust_anchor.subject_alt); - attributes.append_string("CACert_User_Verified", id_card.trust_anchor.user_verified ? "true" : "false"); + attributes.append_string("TA_User_Verified", id_card.trust_anchor.user_verified ? "true" : "false"); attributes.append_string("TA_DateTime_Added", id_card.trust_anchor.datetime_added); attributes.append_string("StorePassword", id_card.store_password ? "yes" : "no"); diff --git a/src/moonshot-local-flat-file-store.vala b/src/moonshot-local-flat-file-store.vala index b3784f2..9654682 100644 --- a/src/moonshot-local-flat-file-store.vala +++ b/src/moonshot-local-flat-file-store.vala @@ -121,7 +121,7 @@ public class LocalFlatFileStore : Object, IIdentityCardStore { string server_cert = key_file.get_string(identity, "ServerCert"); string subject = key_file.get_string(identity, "Subject"); string subject_alt = key_file.get_string(identity, "SubjectAlt"); - bool user_verified = get_bool_setting(identity, "TA_DateTime_Added", false, key_file); + bool user_verified = get_bool_setting(identity, "TA_User_Verified", false, key_file); var ta = new TrustAnchor(ca_cert, server_cert, subject, subject_alt, user_verified); string ta_datetime_added = get_string_setting(identity, "TA_DateTime_Added", "", key_file); if (ta_datetime_added != "") { @@ -191,8 +191,10 @@ public class LocalFlatFileStore : Object, IIdentityCardStore { key_file.set_string(id_card.display_name, "Subject", id_card.trust_anchor.subject); key_file.set_string(id_card.display_name, "SubjectAlt", id_card.trust_anchor.subject_alt); key_file.set_string(id_card.display_name, "ServerCert", id_card.trust_anchor.server_cert); - key_file.set_string(id_card.display_name, "TA_DateTime_Added", id_card.trust_anchor.datetime_added); - key_file.set_boolean(id_card.display_name, "CACert_User_Verified", id_card.trust_anchor.user_verified); + if (id_card.trust_anchor.datetime_added != "") { + key_file.set_string(id_card.display_name, "TA_DateTime_Added", id_card.trust_anchor.datetime_added); + } + key_file.set_boolean(id_card.display_name, "TA_User_Verified", id_card.trust_anchor.user_verified); logger.trace(@"store_id_cards: Stored '$(id_card.display_name)'"); } -- 2.1.4