From 4254c8ad9f733edcfe14dc82a0095432b2c41db2 Mon Sep 17 00:00:00 2001
From: dddddd-mmmmmm <36978885+dddddd-mmmmmm@users.noreply.github.com>
Date: Mon, 13 Jan 2020 21:51:07 +1100
Subject: [PATCH 1/3] Add authMethod preference
---
.../net/nullsum/audinaut/fragments/SettingsFragment.java | 8 ++++++++
.../main/java/net/nullsum/audinaut/util/Constants.java | 1 +
app/src/main/res/values/strings.xml | 2 ++
3 files changed, 11 insertions(+)
diff --git a/app/src/main/java/net/nullsum/audinaut/fragments/SettingsFragment.java b/app/src/main/java/net/nullsum/audinaut/fragments/SettingsFragment.java
index 2747e8e..f5638ee 100644
--- a/app/src/main/java/net/nullsum/audinaut/fragments/SettingsFragment.java
+++ b/app/src/main/java/net/nullsum/audinaut/fragments/SettingsFragment.java
@@ -28,6 +28,7 @@ import android.preference.ListPreference;
import android.preference.Preference;
import android.preference.PreferenceCategory;
import android.preference.PreferenceScreen;
+import android.preference.SwitchPreference;
import android.text.InputType;
import android.util.Log;
import android.view.View;
@@ -469,6 +470,12 @@ public class SettingsFragment extends PreferenceCompatFragment implements Shared
serverPasswordPreference.setSummary("***");
serverPasswordPreference.setTitle(R.string.settings_server_password);
+ final SwitchPreference authMethodPreference = new SwitchPreference(context);
+ authMethodPreference.setKey(Constants.PREFERENCES_KEY_AUTH_METHOD + instance);
+ authMethodPreference.setSummary(R.string.settings_auth_summary);
+ authMethodPreference.setDefaultValue(true); // use Token/Salt by default
+ authMethodPreference.setTitle(R.string.settings_auth_method);
+
final Preference serverOpenBrowser = new Preference(context);
serverOpenBrowser.setKey(Constants.PREFERENCES_KEY_OPEN_BROWSER);
serverOpenBrowser.setPersistent(false);
@@ -529,6 +536,7 @@ public class SettingsFragment extends PreferenceCompatFragment implements Shared
screen.addPreference(serverLocalNetworkSSIDPreference);
screen.addPreference(serverUsernamePreference);
screen.addPreference(serverPasswordPreference);
+ screen.addPreference(authMethodPreference);
screen.addPreference(serverTestConnectionPreference);
screen.addPreference(serverOpenBrowser);
screen.addPreference(serverRemoveServerPreference);
diff --git a/app/src/main/java/net/nullsum/audinaut/util/Constants.java b/app/src/main/java/net/nullsum/audinaut/util/Constants.java
index 5675fe6..84d09c7 100644
--- a/app/src/main/java/net/nullsum/audinaut/util/Constants.java
+++ b/app/src/main/java/net/nullsum/audinaut/util/Constants.java
@@ -71,6 +71,7 @@ public final class Constants {
public static final String PREFERENCES_KEY_MUSIC_FOLDER_ID = "musicFolderId";
public static final String PREFERENCES_KEY_USERNAME = "username";
public static final String PREFERENCES_KEY_PASSWORD = "password";
+ public static final String PREFERENCES_KEY_AUTH_METHOD = "authMethod";
public static final String PREFERENCES_KEY_THEME = "theme";
public static final String PREFERENCES_KEY_FULL_SCREEN = "fullScreen";
public static final String PREFERENCES_KEY_DISPLAY_TRACK = "displayTrack";
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 521e807..56845cf 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -135,6 +135,8 @@
Local network address
Username
Password
+ Authentication Method
+ Use token/salt authentication?
Open in browser
Music cache
Songs to preload (Wifi)
From 5141eb6e81929229a5204b00d72cd8c5bf016be6 Mon Sep 17 00:00:00 2001
From: dddddd-mmmmmm <36978885+dddddd-mmmmmm@users.noreply.github.com>
Date: Mon, 13 Jan 2020 22:08:01 +1100
Subject: [PATCH 2/3] Use p= authentication parameter when authMethod is false.
---
.../java/net/nullsum/audinaut/util/Util.java | 26 ++++++++++++-------
1 file changed, 16 insertions(+), 10 deletions(-)
diff --git a/app/src/main/java/net/nullsum/audinaut/util/Util.java b/app/src/main/java/net/nullsum/audinaut/util/Util.java
index 62580ef..60e80fe 100644
--- a/app/src/main/java/net/nullsum/audinaut/util/Util.java
+++ b/app/src/main/java/net/nullsum/audinaut/util/Util.java
@@ -323,18 +323,24 @@ public final class Util {
builder.addPathSegment("rest");
builder.addPathSegment(method + ".view");
- int hash = (username + password).hashCode();
- Pair values = tokens.get(hash);
- if (values == null) {
- String salt = new BigInteger(130, getRandom()).toString(32);
- String token = md5Hex(password + salt);
- values = new Pair<>(salt, token);
- tokens.put(hash, values);
+ builder.addQueryParameter("u", username);
+
+ if (prefs.getBoolean(Constants.PREFERENCES_KEY_AUTH_METHOD, true)) {
+ int hash = (username + password).hashCode();
+ Pair values = tokens.get(hash);
+ if (values == null) {
+ String salt = new BigInteger(130, getRandom()).toString(32);
+ String token = md5Hex(password + salt);
+ values = new Pair<>(salt, token);
+ tokens.put(hash, values);
+ }
+
+ builder.addQueryParameter("s", values.getFirst());
+ builder.addQueryParameter("t", values.getSecond());
+ } else {
+ builder.addQueryParameter("p", password);
}
- builder.addQueryParameter("u", username);
- builder.addQueryParameter("s", values.getFirst());
- builder.addQueryParameter("t", values.getSecond());
builder.addQueryParameter("v", Constants.REST_PROTOCOL_VERSION_SUBSONIC);
builder.addQueryParameter("c", Constants.REST_CLIENT_ID);
From 2ed89ab72f5d1eabef3ba7eac936d73feed20b12 Mon Sep 17 00:00:00 2001
From: dddddd-mmmmmm <36978885+dddddd-mmmmmm@users.noreply.github.com>
Date: Tue, 14 Jan 2020 09:14:32 +1100
Subject: [PATCH 3/3] Fix authMethod preference check
---
app/src/main/java/net/nullsum/audinaut/util/Util.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/app/src/main/java/net/nullsum/audinaut/util/Util.java b/app/src/main/java/net/nullsum/audinaut/util/Util.java
index 60e80fe..a72f6a8 100644
--- a/app/src/main/java/net/nullsum/audinaut/util/Util.java
+++ b/app/src/main/java/net/nullsum/audinaut/util/Util.java
@@ -325,7 +325,7 @@ public final class Util {
builder.addQueryParameter("u", username);
- if (prefs.getBoolean(Constants.PREFERENCES_KEY_AUTH_METHOD, true)) {
+ if (prefs.getBoolean(Constants.PREFERENCES_KEY_AUTH_METHOD + instance, true)) {
int hash = (username + password).hashCode();
Pair values = tokens.get(hash);
if (values == null) {