First cut at supporting trust anchors
[moonshot-ui.git] / src / moonshot-identity-management-view.vala
index 35dcd5f..6620ac0 100644 (file)
@@ -151,7 +151,7 @@ public class IdentityManagerView : Window {
                     return true;
             }
             
-            if (id_card.services.length > 0)
+            if (id_card.services.size > 0)
             {
                 foreach (string service in id_card.services)
                 {
@@ -226,6 +226,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)'");
             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) {
@@ -242,7 +243,8 @@ public class IdentityManagerView : Window {
         id_card.username = dialog.username;
         id_card.password = dialog.password;
         id_card.store_password = dialog.store_password;
-        id_card.services = dialog.get_services();
+
+        id_card.update_services_from_list(dialog.get_services());
 
         return id_card;
     }
@@ -322,7 +324,8 @@ public class IdentityManagerView : Window {
         #else
         Gtk.MessageDialog dialog;
         IdCard? prev_id = identities_manager.find_id_card(id_card.nai, force_flat_file_store);
-        logger.trace("add_identity: find_id_card returned " + (prev_id != null ? "non-null" : "null"));
+        logger.trace("add_identity(flat=%s, card='%s'): find_id_card returned %s"
+                     .printf(force_flat_file_store.to_string(), id_card.display_name, (prev_id != null ? "non-null" : "null")));
         if (prev_id!=null) {
             int flags = prev_id.Compare(id_card);
             logger.trace("add_identity: compare returned " + flags.to_string());
@@ -539,14 +542,19 @@ public class IdentityManagerView : Window {
 
     private void send_identity_cb(IdCard id)
     {
-        send_button.set_sensitive(false);
-
-        IdCard identity = id;
         return_if_fail(request_queue.length > 0);
 
-        candidates = null;
+        if (!check_and_confirm_trust_anchor(id)) {
+            // Allow user to pick again
+            return;
+        }
+
         var request = this.request_queue.pop_head();
-        identity = check_add_password(identity, request, identities_manager);
+        var identity = check_add_password(id, request, identities_manager);
+        send_button.set_sensitive(false);
+
+        candidates = null;
+      
         if (this.request_queue.is_empty())
         {
             candidates = null;
@@ -575,6 +583,34 @@ public class IdentityManagerView : Window {
         remember_identity_binding.hide();
     }
 
+    private bool check_and_confirm_trust_anchor(IdCard id)
+    {
+        if (!id.trust_anchor.is_empty() && id.trust_anchor.get_anchor_type() == TrustAnchor.TYPE_ENTERPRISE) {
+            if (get_string_setting("TrustAnchors", id.nai) != id.trust_anchor.server_cert) {
+
+                bool ret = false;
+                int result = ResponseType.CANCEL;
+                var dialog = new TrustAnchorDialog(id, this);
+                while (!dialog.complete)
+                    result = dialog.run();
+
+                switch (result) {
+                case ResponseType.OK:
+                    set_string_setting("TrustAnchors", id.nai, id.trust_anchor.server_cert);
+                    ret = true;
+                    break;
+                default:
+                    break;
+                }
+
+                dialog.destroy();
+                return ret;
+            }
+        }
+        return true;
+    }
+
+
     // private void label_make_bold(Label label)
     // {
     //     var font_desc = new Pango.FontDescription();