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;
}
return true;
}
- private bool remove_duplicates(IdCard card)
+ private bool remove_duplicates(IdCard new_card)
{
bool duplicate_found = false;
bool found = false;
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;
}
}
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);
}
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) {
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;
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");
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 != "") {
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)'");
}