Make it work in Centos6
authorAlejandro Perez <alex.perez-mendez@jisc.ac.uk>
Tue, 4 Dec 2018 09:23:44 +0000 (10:23 +0100)
committerAlejandro Perez <alex.perez-mendez@jisc.ac.uk>
Tue, 4 Dec 2018 10:23:58 +0000 (11:23 +0100)
src/moonshot-keyring-store-base.vala
src/moonshot-keyring-store-gnome.vala
src/moonshot-keyring-store-secret.vala

index cdafbe4..c6e5e55 100644 (file)
@@ -40,7 +40,7 @@ public abstract class KeyringStoreBase : Object, IIdentityCardStore {
     internal const string keyring_store_attribute = "Moonshot";
     internal const string keyring_store_version = "1.0";
 
-    /*  
+    /*
      * This class is directly useful for the libsecret implementation.
      * However, we convert the gnome keyring attributes into a HashTable
      * so we can share the serialization code between the two
@@ -50,7 +50,7 @@ public abstract class KeyringStoreBase : Object, IIdentityCardStore {
     protected class Attributes: GLib.HashTable<string, string> {
        public Attributes() {
            base.full(GLib.str_hash, GLib.str_equal, GLib.g_free, GLib.g_free);
-      }
+        }
 
     }
 
@@ -59,17 +59,17 @@ public abstract class KeyringStoreBase : Object, IIdentityCardStore {
     protected static IdCard deserialize(GLib.HashTable<string,string> attrs, string? secret)
     {
        IdCard id_card = new IdCard();
-       unowned string store_password = attrs["StorePassword"];
-       unowned string ca_cert = attrs["CA-Cert"] ?? "";
-       unowned string server_cert = attrs["Server-Cert"] ?? "";
-       unowned string subject = attrs["Subject"] ?? "";
-       unowned string subject_alt = attrs["Subject-Alt"] ?? "";
-       unowned string ta_datetime_added = attrs["TA_DateTime_Added"];
-
-       id_card.issuer = attrs["Issuer"];
-       id_card.username = attrs["Username"];
-       id_card.display_name = attrs["DisplayName"];
-       unowned string services = attrs["Services"];
+       unowned string store_password = attrs.lookup("StorePassword");
+       unowned string ca_cert = attrs.lookup("CA-Cert") ?? "";
+       unowned string server_cert = attrs.lookup("Server-Cert") ?? "";
+       unowned string subject = attrs.lookup("Subject") ?? "";
+       unowned string subject_alt = attrs.lookup("Subject-Alt") ?? "";
+       unowned string ta_datetime_added = attrs.lookup("TA_DateTime_Added");
+
+       id_card.issuer = attrs.lookup("Issuer");
+       id_card.username = attrs.lookup("Username");
+       id_card.display_name = attrs.lookup("DisplayName");
+       unowned string services = attrs.lookup("Services");
        if ((services != null) && services != "") {
            id_card.update_services(services.split(";"));
        }
@@ -79,8 +79,8 @@ public abstract class KeyringStoreBase : Object, IIdentityCardStore {
             }
        id_card.set_trust_anchor_from_store(ta);
 
-       unowned string rules_pattern_all = attrs["Rules-Pattern"];
-       unowned string rules_always_confirm_all = attrs["Rules-AlwaysConfirm"];
+       unowned string rules_pattern_all = attrs.lookup("Rules-Pattern");
+       unowned string rules_always_confirm_all = attrs.lookup("Rules-AlwaysConfirm");
        if ((rules_pattern_all != null) && (rules_always_confirm_all != null)) {
            string[] rules_patterns = rules_pattern_all.split(";");
            string[] rules_always_confirm = rules_always_confirm_all.split(";");
@@ -93,7 +93,7 @@ public abstract class KeyringStoreBase : Object, IIdentityCardStore {
                id_card.rules = rules;
            }
        }
-       
+
        if (store_password != null)
            id_card.store_password = (store_password == "yes");
        else
@@ -105,7 +105,7 @@ public abstract class KeyringStoreBase : Object, IIdentityCardStore {
            id_card.password = null;
 
 
-           
+
 
        return id_card;
     }
@@ -116,7 +116,7 @@ public abstract class KeyringStoreBase : Object, IIdentityCardStore {
        var rules = id_card.rules;
        string[] rules_patterns = new string[rules.length];
        string[] rules_always_conf = new string[rules.length];
-            
+
        for (int i = 0; i < rules.length; i++) {
            rules_patterns[i] = rules[i].pattern;
            rules_always_conf[i] = rules[i].always_confirm;
@@ -186,11 +186,11 @@ public abstract class KeyringStoreBase : Object, IIdentityCardStore {
         return id_card_list;
     }
 
-    protected abstract void clear_keyring();     
+    protected abstract void clear_keyring();
     protected abstract void load_id_cards() throws GLib.Error;
     internal abstract void store_id_cards();
 
-    
+
 
 
     public KeyringStoreBase() {
@@ -200,7 +200,7 @@ public abstract class KeyringStoreBase : Object, IIdentityCardStore {
        } catch( GLib.Error e) {
            stdout.printf("Unable to load ID cards: %s\n", e.message);
        }
-       
+
     }
 }
 
index 100de7c..bf1297b 100644 (file)
@@ -59,7 +59,7 @@ public class KeyringStore : KeyringStoreBase {
         GLib.List<GnomeKeyring.Found> items;
         GnomeKeyring.find_items_sync(item_type, match, out items);
         foreach(unowned GnomeKeyring.Found entry in items) {
-           KeyringStoreBase.Attributes new_attrs = new KeyringStoreBase.Attributes();                  
+           KeyringStoreBase.Attributes new_attrs = new KeyringStoreBase.Attributes();
             for (int i = 0; i < entry.attributes.len; i++) {
                 var attribute = ((GnomeKeyring.Attribute *) entry.attributes.data)[i];
                 if (attribute.type == GnomeKeyring.AttributeType.STRING) {
@@ -67,9 +67,9 @@ public class KeyringStore : KeyringStoreBase {
                    new_attrs.insert(attribute.name, value);
                 }
            }
-           
+
            var id_card = deserialize(new_attrs, entry.secret);
-           
+
             id_card_list.add(id_card);
         }
     }
@@ -81,10 +81,11 @@ public class KeyringStore : KeyringStoreBase {
             /* workaround for Centos vala array property bug: use temp array */
             GnomeKeyring.AttributeList attributes = new GnomeKeyring.AttributeList();
             uint32 item_id;
-           var hash_attrs = serialize(id_card);
-           hash_attrs.foreach((k, v) => {
-                   attributes.append_string(k,v); });
-           
+            var hash_attrs = serialize(id_card);
+               hash_attrs.foreach((k, v) => {
+                attributes.append_string((string) k, (string) v);
+            });
+
             attributes.append_string(keyring_store_attribute, keyring_store_version);
 
             GnomeKeyring.Result result = GnomeKeyring.item_create_sync(null,
@@ -100,14 +101,14 @@ public class KeyringStore : KeyringStoreBase {
        } catch(GLib.Error e) {
            logger.error(@"Unable to load ID cards: $(e.message)\n");
        }
-       
+
     }
 
     public static bool is_available()
     {
        return GnomeKeyring.is_available();
     }
-    
+
 }
 
 #endif
index ad89faf..d76ae74 100644 (file)
@@ -38,7 +38,6 @@ using Secret;
 private Collection? find_secret_collection()
 {
     Collection secret_collection = null;
-    stdout.printf("In find_secret_collection\n");
     try {
        Service service = Service.get_sync(ServiceFlags.OPEN_SESSION);
        secret_collection = Collection.for_alias_sync(service, COLLECTION_DEFAULT,
@@ -54,7 +53,7 @@ public class KeyringStore : KeyringStoreBase {
     * We choose to remain compatible with the way we stored secrets
     * using libgnomekeyring.  As a result, we cannot use our own schema
     * identifier.  Using our own schema might get us a nice icon in
-    * seahorse, but would not save much code. 
+    * seahorse, but would not save much code.
     */
     private const SchemaAttributeType sstring = SchemaAttributeType.STRING;
     private static Schema schema = new Schema("org.freedesktop.Secret.Generic", SchemaFlags.NONE,
@@ -73,8 +72,8 @@ public class KeyringStore : KeyringStoreBase {
                                              "StorePassword", sstring);
     private static Collection? secret_collection = find_secret_collection();
 
-    
-    
+
+
 
     /* clear all keyring-stored ids (in preparation to store current list) */
     protected override void clear_keyring() {
@@ -125,14 +124,14 @@ var attributes = serialize(id_card);
            } catch(GLib.Error e) {
                logger.error(@"Unable to store $(id_card.display_name): $(e.message)\n");
        }
-       
+
         }
         try {
            load_id_cards();
        } catch (GLib.Error e) {
            logger.error(@"Unable to load ID Cards: $(e.message)\n");
        }
-       
+
     }
 
     public static bool is_available()
@@ -140,10 +139,10 @@ var attributes = serialize(id_card);
        if (secret_collection == null) {
            secret_collection = find_secret_collection();
        }
-       
+
        return secret_collection != null;
     }
-    
+
 }
 
 #endif