just use the keyring for the rest of the authn lmao
This commit is contained in:
parent
ff9bd114ab
commit
6f739fde18
1 changed files with 39 additions and 65 deletions
|
@ -16,10 +16,6 @@ public class Ui.Setup : Adw.PreferencesDialog {
|
||||||
|
|
||||||
public signal void connected (Subsonic api);
|
public signal void connected (Subsonic api);
|
||||||
|
|
||||||
private Sqlite.Database db;
|
|
||||||
private Sqlite.Statement db_get;
|
|
||||||
private Sqlite.Statement db_set;
|
|
||||||
|
|
||||||
private static Secret.Schema secret_schema = new Secret.Schema (
|
private static Secret.Schema secret_schema = new Secret.Schema (
|
||||||
"eu.callcc.audrey",
|
"eu.callcc.audrey",
|
||||||
Secret.SchemaFlags.NONE,
|
Secret.SchemaFlags.NONE,
|
||||||
|
@ -27,30 +23,6 @@ public class Ui.Setup : Adw.PreferencesDialog {
|
||||||
"username", Secret.SchemaAttributeType.STRING
|
"username", Secret.SchemaAttributeType.STRING
|
||||||
);
|
);
|
||||||
|
|
||||||
construct {
|
|
||||||
var app_config_dir = Path.build_filename (Environment.get_user_config_dir (), "audrey");
|
|
||||||
|
|
||||||
try {
|
|
||||||
File.new_build_filename (app_config_dir).make_directory_with_parents ();
|
|
||||||
} catch (Error e) {
|
|
||||||
// just ignore if the directory already existed
|
|
||||||
}
|
|
||||||
|
|
||||||
int ec = Sqlite.Database.open (Path.build_filename (app_config_dir, "config.db"), out this.db);
|
|
||||||
assert (ec == Sqlite.OK);
|
|
||||||
|
|
||||||
ec = this.db.exec ("""
|
|
||||||
CREATE TABLE IF NOT EXISTS Setup (key UNIQUE, value);
|
|
||||||
""", null, null);
|
|
||||||
assert (ec == Sqlite.OK);
|
|
||||||
|
|
||||||
ec = this.db.prepare_v2 ("""SELECT value FROM Setup WHERE key IS ?1""", -1, out this.db_get);
|
|
||||||
assert (ec == Sqlite.OK);
|
|
||||||
|
|
||||||
ec = this.db.prepare_v2 ("""INSERT OR REPLACE INTO Setup VALUES (?1, ?2)""", -1, out this.db_set);
|
|
||||||
assert (ec == Sqlite.OK);
|
|
||||||
}
|
|
||||||
|
|
||||||
[GtkCallback] private void on_authn_changed () {
|
[GtkCallback] private void on_authn_changed () {
|
||||||
this.authn_can_validate = true;
|
this.authn_can_validate = true;
|
||||||
}
|
}
|
||||||
|
@ -87,35 +59,47 @@ public class Ui.Setup : Adw.PreferencesDialog {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void load () {
|
public void load () {
|
||||||
this.db_get.bind_text (1, "server_url");
|
|
||||||
if (this.db_get.step () == Sqlite.ROW) {
|
|
||||||
this.server_url = this.db_get.column_text (0);
|
|
||||||
} else {
|
|
||||||
this.server_url = "";
|
|
||||||
}
|
|
||||||
assert (this.db_get.reset () == Sqlite.OK);
|
|
||||||
|
|
||||||
this.db_get.bind_text (1, "username");
|
|
||||||
if (this.db_get.step () == Sqlite.ROW) {
|
|
||||||
this.username = this.db_get.column_text (0);
|
|
||||||
} else {
|
|
||||||
this.username = "";
|
|
||||||
}
|
|
||||||
assert (this.db_get.reset () == Sqlite.OK);
|
|
||||||
|
|
||||||
this.authn_can_edit = false;
|
this.authn_can_edit = false;
|
||||||
Secret.password_lookup.begin (secret_schema, null, (obj, res) => {
|
Secret.password_searchv.begin (
|
||||||
|
secret_schema,
|
||||||
|
new HashTable<string, string> (null, null),
|
||||||
|
Secret.SearchFlags.NONE,
|
||||||
|
null,
|
||||||
|
(obj, res) => {
|
||||||
try {
|
try {
|
||||||
string? password = Secret.password_lookup.end (res);
|
var list = Secret.password_searchv.end (res);
|
||||||
this.password = password ?? "";
|
if (list == null) {
|
||||||
|
// didn't find shit, leave all empty
|
||||||
|
this.server_url = "";
|
||||||
|
this.username = "";
|
||||||
|
this.password = "";
|
||||||
|
// TODO: onboarding
|
||||||
|
this.authn_can_edit = true;
|
||||||
|
this.authn_can_validate = true;
|
||||||
|
} else {
|
||||||
|
var first = list.data;
|
||||||
|
assert (first != null);
|
||||||
|
|
||||||
|
this.server_url = first.attributes["server-url"];
|
||||||
|
this.username = first.attributes["username"];
|
||||||
|
|
||||||
|
first.retrieve_secret.begin (null, (obj, res) => {
|
||||||
|
try {
|
||||||
|
var value = first.retrieve_secret.end (res);
|
||||||
|
this.password = value.get_text () ?? "";
|
||||||
} catch (Error e) {
|
} catch (Error e) {
|
||||||
error ("could not look up password in keyring: %s", e.message);
|
error ("could not retrieve password from credentials: %s", e.message);
|
||||||
}
|
}
|
||||||
|
|
||||||
// first connection
|
// first connection
|
||||||
this.authn_can_validate = true;
|
this.authn_can_validate = true;
|
||||||
this.on_authn_validate_activated ();
|
this.on_authn_validate_activated ();
|
||||||
}, "server-url", this.server_url, "username", this.username);
|
});
|
||||||
|
}
|
||||||
|
} catch (Error e) {
|
||||||
|
error ("could not search for password in keyring: %s", e.message);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void salt_password (string password, out string token, out string salt) {
|
private void salt_password (string password, out string token, out string salt) {
|
||||||
|
@ -136,16 +120,6 @@ public class Ui.Setup : Adw.PreferencesDialog {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void save () {
|
public void save () {
|
||||||
this.db_set.bind_text (1, "server_url");
|
|
||||||
this.db_set.bind_text (2, this.server_url);
|
|
||||||
assert (this.db_set.step () == Sqlite.DONE);
|
|
||||||
assert (this.db_set.reset () == Sqlite.OK);
|
|
||||||
|
|
||||||
this.db_set.bind_text (1, "username");
|
|
||||||
this.db_set.bind_text (2, this.username);
|
|
||||||
assert (this.db_set.step () == Sqlite.DONE);
|
|
||||||
assert (this.db_set.reset () == Sqlite.OK);
|
|
||||||
|
|
||||||
this.authn_can_edit = false;
|
this.authn_can_edit = false;
|
||||||
Secret.password_store.begin (secret_schema, null, "Subsonic password", this.password, null, (obj, res) => {
|
Secret.password_store.begin (secret_schema, null, "Subsonic password", this.password, null, (obj, res) => {
|
||||||
try {
|
try {
|
||||||
|
|
Loading…
Reference in a new issue