return true;
}
- private bool remove_duplicates(IdCard new_card)
+ private bool remove_duplicates(IdCard new_card, out ArrayList<IdCard>? old_duplicates)
{
- bool duplicate_found = false;
- bool found = false;
- do {
- var cards = this.store.get_card_list();
- found = false;
- foreach (IdCard id_card in cards) {
- 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;
- }
+ ArrayList<IdCard> dups = new ArrayList<IdCard>();
+ var cards = this.store.get_card_list();
+ foreach (IdCard id_card in cards) {
+ if ((new_card != id_card) && (id_card.nai == new_card.nai)) {
+ dups.add(id_card);
+ }
+ }
+
+ foreach (IdCard id_card in dups) {
+ logger.trace("removing duplicate id for '%s'\n".printf(new_card.nai));
+ remove_card_internal(id_card);
+
+ 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;
}
- } while (found);
- return duplicate_found;
+ }
+
+ if (&old_duplicates != null) {
+ old_duplicates = dups;
+ }
+
+ return (dups.size > 0);
}
public IdCard? find_id_card(string nai, bool force_flat_file_store) {
return retval;
}
- public void add_card(IdCard card, bool force_flat_file_store) {
+ public void add_card(IdCard card, bool force_flat_file_store, out ArrayList<IdCard>? old_duplicates=null) {
if (card.temporary) {
logger.trace("add_card: card is temporary; returning.");
return;
if (force_flat_file_store)
set_store_type(IIdentityCardStore.StoreType.FLAT_FILE);
- remove_duplicates(card);
+ remove_duplicates(card, out old_duplicates);
if (!display_name_is_valid(card.display_name, out candidate))
{
this.send_button.set_sensitive(false);
}
- public bool add_identity(IdCard id_card, bool force_flat_file_store)
+ public bool add_identity(IdCard id_card, bool force_flat_file_store, out ArrayList<IdCard>? old_duplicates=null)
{
#if OS_MACOS
/*
int flags = prev_id.Compare(id_card);
logger.trace("add_identity: compare returned " + flags.to_string());
if (flags == 0) {
+ if (&old_duplicates != null) {
+ old_duplicates = new ArrayList<IdCard>();
+ }
+
return false; // no changes, no need to update
} else if ((flags & (1 << IdCard.DiffFlags.DISPLAY_NAME)) != 0) {
dialog = new Gtk.MessageDialog(this,
#endif
if (ret == Gtk.ResponseType.YES) {
- this.identities_manager.add_card(id_card, force_flat_file_store);
+ this.identities_manager.add_card(id_card, force_flat_file_store, out old_duplicates);
return true;
}
- return false;
+ else {
+ if (&old_duplicates != null) {
+ old_duplicates = new ArrayList<IdCard>();
+ }
+ return false;
+ }
}
private void add_identity_cb()
this,
FileChooserAction.OPEN,
_("Cancel"),ResponseType.CANCEL,
- _("Save"), ResponseType.ACCEPT,
+ _("Open"), ResponseType.ACCEPT,
null);
if (import_directory != null) {
continue;
}
+ if (!card.trust_anchor.is_empty()) {
+ string ta_datetime_added = TrustAnchor.format_datetime_now();
+ card.trust_anchor.set_datetime_added(ta_datetime_added);
+ logger.trace("import_identities_cb : Set ta_datetime_added for '%s' to '%s'; ca_cert='%s'; server_cert='%s'"
+ .printf(card.display_name, ta_datetime_added, card.trust_anchor.ca_cert, card.trust_anchor.server_cert));
+ }
+
+
bool result = add_identity(card, use_flat_file_store);
if (result) {
logger.trace(@"import_identities_cb: Added or updated '$(card.display_name)'");
msg_dialog.run();
msg_dialog.destroy();
}
+ dialog.destroy();
}
}
#endif
}
- public bool add_identity(IdCard id, bool force_flat_file_store) {
+ public bool add_identity(IdCard id, bool force_flat_file_store, out ArrayList<IdCard>? old_duplicates=null) {
if (view != null)
{
logger.trace("add_identity: calling view.add_identity");
- return view.add_identity(id, force_flat_file_store);
+ return view.add_identity(id, force_flat_file_store, out old_duplicates);
+ }
+ else {
+ logger.trace("add_identity: calling model.add_card");
+ model.add_card(id, force_flat_file_store, out old_duplicates);
+ return true;
}
-
- logger.trace("add_identity: calling model.add_card");
- model.add_card(id, force_flat_file_store);
- return true;
}
public void select_identity(IdentityRequest request) {
id_card_list.add(id_card);
}
catch (Error e) {
+ logger.error("load_id_cards: Error while loading keyfile: %s\n".printf(e.message));
stdout.printf("Error: %s\n", e.message);
}
}
ta_subject,
ta_subject_alt,
false);
- if (!ta.is_empty()) {
- string ta_datetime_added = TrustAnchor.format_datetime_now();
- ta.set_datetime_added(ta_datetime_added);
- logger.trace("end_element_func : Set ta_datetime_added for '%s' to '%s'".printf(card.display_name, ta_datetime_added));
- card.set_trust_anchor_from_store(ta);
- }
-
+ // Set the datetime_added in moonshot-server.vala, since it doesn't get sent via IPC
card.set_trust_anchor_from_store(ta);
}
}
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
+
+using Gee;
+
#if IPC_DBUS
[DBus (name = "org.janet.Moonshot")]
idcard.update_services(services);
var ta = new TrustAnchor(ca_cert, server_cert, subject, subject_alt, false);
+ if (!ta.is_empty()) {
+ // We have to set the datetime_added here, because it isn't delivered via IPC.
+ string ta_datetime_added = TrustAnchor.format_datetime_now();
+ ta.set_datetime_added(ta_datetime_added);
+ logger.trace("install_id_card : Set ta_datetime_added for '%s' to '%s'; ca_cert='%s'; server_cert='%s'".printf(idcard.display_name, ta.datetime_added, ta.ca_cert, ta.server_cert));
+ }
+ idcard.set_trust_anchor_from_store(ta);
+
logger.trace("install_id_card: Card '%s' has services: '%s'"
.printf(idcard.display_name, idcard.get_services_string("; ")));
+ logger.trace(@"Installing IdCard named '$(idcard.display_name)'; ca_cert='$(idcard.trust_anchor.ca_cert)'; server_cert='$(idcard.trust_anchor.server_cert)'");
+
+
if (rules_patterns.length == rules_always_confirm.length)
{
/* workaround Centos vala array property bug: use temp array */
idcard.rules = rules;
}
- return parent_app.add_identity(idcard, force_flat_file_store!=0);
+ ArrayList<IdCard>? old_duplicates = null;
+ var ret = parent_app.add_identity(idcard, (force_flat_file_store != 0), out old_duplicates);
+
+ if (old_duplicates != null) {
+ // Printing to stdout here is ugly behavior; but it's old behavior that
+ // may be expected. (TODO: Do we need to keep this?)
+ foreach (IdCard id_card in old_duplicates) {
+ stdout.printf("removed duplicate id for '%s'\n", id_card.nai);
+ }
+ }
+ return ret;
}
mutex.lock();
+ ArrayList<IdCard>? old_duplicates = null;
// Defer addition to the main loop thread.
Idle.add(() => {
mutex.lock();
- success = parent_app.add_identity(idcard, force_flat_file_store);
+ success = parent_app.add_identity(idcard, force_flat_file_store, out old_duplicates);
+ foreach (IdCard id_card in old_duplicates) {
+ stdout.printf("removing duplicate id for '%s'\n", new_card.nai);
+ }
cond.signal();
mutex.unlock();
return false;
public static int main(string[] args)
{
- logger = new MoonshotLogger("WebProvisioning");
+ logger = new MoonshotLogger("WebProvisioning (WebpParser)");
int arg_index = -1;
int force_flat_file_store = 0;