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
protected class Attributes: GLib.HashTable<string, string> {
public Attributes() {
base.full(GLib.str_hash, GLib.str_equal, GLib.g_free, GLib.g_free);
- }
+ }
}
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(";"));
}
}
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(";");
id_card.rules = rules;
}
}
-
+
if (store_password != null)
id_card.store_password = (store_password == "yes");
else
id_card.password = null;
-
+
return id_card;
}
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;
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() {
} catch( GLib.Error e) {
stdout.printf("Unable to load ID cards: %s\n", e.message);
}
-
+
}
}
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) {
new_attrs.insert(attribute.name, value);
}
}
-
+
var id_card = deserialize(new_attrs, entry.secret);
-
+
id_card_list.add(id_card);
}
}
/* 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,
} catch(GLib.Error e) {
logger.error(@"Unable to load ID cards: $(e.message)\n");
}
-
+
}
public static bool is_available()
{
return GnomeKeyring.is_available();
}
-
+
}
#endif
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,
* 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,
"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() {
} 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()
if (secret_collection == null) {
secret_collection = find_secret_collection();
}
-
+
return secret_collection != null;
}
-
+
}
#endif