Add setting to server config to allow self-signed certificates.

It is disabled by default.

Signed-off-by: Yahor Berdnikau <egorr.berd@gmail.com>
This commit is contained in:
Yahor Berdnikau 2017-12-25 13:04:27 +01:00
parent 1333534988
commit 592ab16b94
10 changed files with 31 additions and 4 deletions

View File

@ -37,6 +37,7 @@ public class ServerSettingsFragment extends PreferenceFragment
private EditTextPreference serverPasswordPref;
private CheckBoxPreference equalizerPref;
private CheckBoxPreference jukeboxPref;
private CheckBoxPreference allowSelfSignedCertificatePref;
private Preference removeServerPref;
private Preference testConnectionPref;
@ -74,6 +75,8 @@ public class ServerSettingsFragment extends PreferenceFragment
jukeboxPref = (CheckBoxPreference) findPreference(getString(R.string.jukebox_is_default));
removeServerPref = findPreference(getString(R.string.settings_server_remove_server));
testConnectionPref = findPreference(getString(R.string.settings_test_connection_title));
allowSelfSignedCertificatePref = (CheckBoxPreference) findPreference(
getString(R.string.settings_allow_self_signed_certificate));
setupPreferencesValues();
setupPreferencesListeners();
@ -132,6 +135,11 @@ public class ServerSettingsFragment extends PreferenceFragment
.putBoolean(Constants.PREFERENCES_KEY_JUKEBOX_BY_DEFAULT + serverId, (Boolean) newValue)
.apply();
return true;
} else if (preference == allowSelfSignedCertificatePref) {
sharedPreferences.edit()
.putBoolean(Constants.PREFERENCES_KEY_ALLOW_SELF_SIGNED_CERTIFICATE + serverId, (Boolean) newValue)
.apply();
return true;
}
return false;
}
@ -164,6 +172,9 @@ public class ServerSettingsFragment extends PreferenceFragment
jukeboxPref.setChecked(sharedPreferences
.getBoolean(Constants.PREFERENCES_KEY_JUKEBOX_BY_DEFAULT + serverId, false));
allowSelfSignedCertificatePref.setChecked(sharedPreferences
.getBoolean(Constants.PREFERENCES_KEY_ALLOW_SELF_SIGNED_CERTIFICATE + serverId, false));
}
private void updatePassword() {
@ -201,6 +212,7 @@ public class ServerSettingsFragment extends PreferenceFragment
serverPasswordPref.setOnPreferenceChangeListener(this);
equalizerPref.setOnPreferenceChangeListener(this);
jukeboxPref.setOnPreferenceChangeListener(this);
allowSelfSignedCertificatePref.setOnPreferenceChangeListener(this);
removeServerPref.setOnPreferenceClickListener(this);
testConnectionPref.setOnPreferenceClickListener(this);
@ -262,6 +274,7 @@ public class ServerSettingsFragment extends PreferenceFragment
.remove(Constants.PREFERENCES_KEY_PASSWORD + serverId)
.remove(Constants.PREFERENCES_KEY_SERVER_ENABLED + serverId)
.remove(Constants.PREFERENCES_KEY_JUKEBOX_BY_DEFAULT + serverId)
.remove(Constants.PREFERENCES_KEY_ALLOW_SELF_SIGNED_CERTIFICATE + serverId)
.apply();
if (serverId < activeServers) {

View File

@ -84,6 +84,8 @@ public class MusicServiceFactory {
String serverUrl = preferences.getString(Constants.PREFERENCES_KEY_SERVER_URL + instance, null);
String username = preferences.getString(Constants.PREFERENCES_KEY_USERNAME + instance, null);
String password = preferences.getString(Constants.PREFERENCES_KEY_PASSWORD + instance, null);
boolean allowSelfSignedCertificate = preferences
.getBoolean(Constants.PREFERENCES_KEY_ALLOW_SELF_SIGNED_CERTIFICATE + instance, false);
if (serverUrl == null ||
username == null ||
@ -91,11 +93,11 @@ public class MusicServiceFactory {
Log.i("MusicServiceFactory", "Server credentials is not available");
return new SubsonicAPIClient("http://localhost", "", "",
SubsonicAPIVersions.fromApiVersion(Constants.REST_PROTOCOL_VERSION),
Constants.REST_CLIENT_ID, BuildConfig.DEBUG);
Constants.REST_CLIENT_ID, allowSelfSignedCertificate, BuildConfig.DEBUG);
}
return new SubsonicAPIClient(serverUrl, username, password,
SubsonicAPIVersions.fromApiVersion(Constants.REST_PROTOCOL_VERSION),
Constants.REST_CLIENT_ID, BuildConfig.DEBUG);
Constants.REST_CLIENT_ID, allowSelfSignedCertificate, BuildConfig.DEBUG);
}
}

View File

@ -72,11 +72,11 @@ public final class Constants
public static final String PREFERENCES_KEY_SERVER_URL = "serverUrl";
public static final String PREFERENCES_KEY_SERVERS_KEY = "serversKey";
public static final String PREFERENCES_KEY_ADD_SERVER = "addServer";
public static final String PREFERENCES_KEY_REMOVE_SERVER = "removeServer";
public static final String PREFERENCES_KEY_ACTIVE_SERVERS = "activeServers";
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_ALLOW_SELF_SIGNED_CERTIFICATE = "allowSSCertificate";
public static final String PREFERENCES_KEY_INSTALL_TIME = "installTime";
public static final String PREFERENCES_KEY_THEME = "theme";
public static final String PREFERENCES_KEY_DISPLAY_BITRATE_WITH_ARTIST = "displayBitrateWithArtist";
@ -109,7 +109,6 @@ public final class Constants
public static final String PREFERENCES_KEY_GAPLESS_PLAYBACK = "gaplessPlayback";
public static final String PREFERENCES_KEY_PLAYBACK_CONTROL_SETTINGS = "playbackControlSettings";
public static final String PREFERENCES_KEY_CLEAR_SEARCH_HISTORY = "clearSearchHistory";
public static final String PREFERENCES_KEY_TEST_CONNECTION = "testConnection";
public static final String PREFERENCES_KEY_DOWNLOAD_TRANSITION = "transitionToDownloadOnPlay";
public static final String PREFERENCES_KEY_INCREMENT_TIME = "incrementTime";
public static final String PREFERENCES_KEY_ID3_TAGS = "useId3Tags";

View File

@ -300,6 +300,7 @@
<string name="settings.theme_dark">Oscuro</string>
<string name="settings.theme_light">Claro</string>
<string name="settings.theme_title">Tema</string>
<string name="settings.title.allow_self_signed_certificate">Permita el certificado HTTPS autofirmado</string>
<string name="settings.use_folder_for_album_artist">Usar carpetas para el nombre del artista</string>
<string name="settings.use_folder_for_album_artist_summary">Se asume que la carpeta en el nivel mal alto es el nombre del artista del álbum</string>
<string name="settings.use_id3">Navegar usando las etiquetas ID3</string>

View File

@ -300,6 +300,7 @@
<string name="settings.theme_dark">Sombre</string>
<string name="settings.theme_light">Clair</string>
<string name="settings.theme_title">Thème</string>
<string name="settings.title.allow_self_signed_certificate">Autoriser le certificat HTTPS auto-signé</string>
<string name="settings.use_folder_for_album_artist">Utilisez des dossiers pour les noms d\'artistes</string>
<string name="settings.use_folder_for_album_artist_summary">Dossier de niveau supérieur devient le nom de l\'artiste de l\'album</string>
<string name="settings.use_id3">Naviguer en utilisant ID3 Tags</string>

View File

@ -300,6 +300,7 @@
<string name="settings.theme_dark">Sötét</string>
<string name="settings.theme_light">Világos</string>
<string name="settings.theme_title">Téma</string>
<string name="settings.title.allow_self_signed_certificate">Engedélyezze az önaláírt HTTPS tanúsítványt</string>
<string name="settings.use_folder_for_album_artist">Mappanevek használata az előadók neveként</string>
<string name="settings.use_folder_for_album_artist_summary">Feltételezi, hogy a legfelső szintű mappa az előadó neve.</string>
<string name="settings.use_id3">Böngészés ID3 Tag használatával</string>

View File

@ -303,6 +303,7 @@
<string name="settings.theme_dark">Escuro</string>
<string name="settings.theme_light">Claro</string>
<string name="settings.theme_title">Tema</string>
<string name="settings.title.allow_self_signed_certificate">Permitir o certificado HTTPS auto-assinado</string>
<string name="settings.use_folder_for_album_artist">Pasta para Nome do Artista</string>
<string name="settings.use_folder_for_album_artist_summary">Assume que a pasta mais acima é o nome do artista</string>
<string name="settings.use_id3">Navegar Usando Etiquetas ID3</string>

View File

@ -303,6 +303,7 @@
<string name="settings.theme_dark">Escuro</string>
<string name="settings.theme_light">Claro</string>
<string name="settings.theme_title">Tema</string>
<string name="settings.title.allow_self_signed_certificate">Permitir o certificado HTTPS auto-assinado</string>
<string name="settings.use_folder_for_album_artist">Pasta para Nome do Artista</string>
<string name="settings.use_folder_for_album_artist_summary">Assume que a pasta mais acima é o nome do artista</string>
<string name="settings.use_id3">Navegar Usando Etiquetas ID3</string>

View File

@ -146,6 +146,7 @@
<string name="select_genre.empty">No genres found</string>
<string name="select_playlist.empty">No saved playlists on server</string>
<string name="service.connecting">Contacting server, please wait.</string>
<string name="settings.allow_self_signed_certificate" translatable="false">allowSelfSignedCertificate</string>
<string name="settings.appearance_title">Appearance</string>
<string name="settings.buffer_length">Buffer Length</string>
<string name="settings.buffer_length_0">Disabled</string>
@ -303,6 +304,7 @@
<string name="settings.theme_dark">Dark</string>
<string name="settings.theme_light">Light</string>
<string name="settings.theme_title">Theme</string>
<string name="settings.title.allow_self_signed_certificate">Allow self-signed HTTPS certificate</string>
<string name="settings.use_folder_for_album_artist">Use Folders For Artist Name</string>
<string name="settings.use_folder_for_album_artist_summary">Assume top-level folder is the name of the album artist</string>
<string name="settings.use_id3">Browse Using ID3 Tags</string>

View File

@ -38,6 +38,12 @@
android:defaultValue="true"
android:title="@string/equalizer.enabled"
/>
<CheckBoxPreference
android:key="@string/settings.allow_self_signed_certificate"
android:persistent="false"
android:defaultValue="false"
android:title="@string/settings.title.allow_self_signed_certificate"
/>
<CheckBoxPreference
android:key="@string/jukebox.is_default"
android:persistent="false"