First pass at supporting date/time added for Trust Anchors
[moonshot-ui.git] / src / moonshot-server.vala
index bb26dc0..7c95ff7 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011-2014, JANET(UK)
+ * Copyright (c) 2011-2016, JANET(UK)
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -117,7 +117,7 @@ public class MoonshotServer : Object {
             if (subject_alt_name_constraint == null)
                 subject_alt_name_constraint = "";
 
-            logger.trace("MoonshotServer.get_identity: returning true");
+            logger.trace(@"MoonshotServer.get_identity: returning with nai_out=$nai_out");
 
             return true;
         }
@@ -197,11 +197,17 @@ public class MoonshotServer : Object {
         if ((password != null) && (password != ""))
             idcard.store_password = true;
         idcard.issuer = realm;
-        idcard.services = services;
-        idcard.trust_anchor.ca_cert = ca_cert;
-        idcard.trust_anchor.subject = subject;
-        idcard.trust_anchor.subject_alt = subject_alt;
-        idcard.trust_anchor.server_cert = server_cert;
+        idcard.update_services(services);
+        var ta = new TrustAnchor(ca_cert, server_cert, subject, subject_alt, false);
+        if (!ta.is_empty()) {
+            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'".printf(idcard.display_name, ta_datetime_added));
+            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("; ")));
 
         if (rules_patterns.length == rules_always_confirm.length)
         {
@@ -227,7 +233,7 @@ public class MoonshotServer : Object {
         webp.parse();
         bool result = false;
         int installed_cards = 0;
-        foreach (IdCard card in WebProvisioning.cards)
+        foreach (IdCard card in webp.cards)
         {
             string[] rules_patterns = {};
             string[] rules_always_confirm = {};
@@ -245,13 +251,25 @@ public class MoonshotServer : Object {
                 }
             } 
 
+
+            // prevent a crash by holding the reference to otherwise
+            // unowned array(?)
+
+            // string[] svcs = card.services.to_array();
+            // string[] svcs = card.services.to_array()[:];
+            string[] svcs = new string[card.services.size];
+            for (int i = 0; i < card.services.size; i++) {
+                svcs[i] = card.services[i];
+            }
+
+            logger.trace(@"install_from_file: Adding card with display name '$(card.display_name)'");
             result = install_id_card(card.display_name,
                                      card.username,
                                      card.password,
                                      card.issuer,
                                      rules_patterns,
                                      rules_always_confirm,
-                                     card.services,
+                                     svcs,
                                      card.trust_anchor.ca_cert,
                                      card.trust_anchor.subject,
                                      card.trust_anchor.subject_alt,