mirror of
https://github.com/ChronosX88/Influence.git
synced 2024-11-09 20:11:01 +00:00
feat: Make more securely storing login credentials
This commit is contained in:
parent
759dd48b86
commit
0297f4b703
@ -86,6 +86,7 @@ dependencies {
|
|||||||
implementation 'org.igniterealtime.smack:smack-experimental:4.3.3'
|
implementation 'org.igniterealtime.smack:smack-experimental:4.3.3'
|
||||||
implementation 'com.github.bumptech.glide:glide:4.9.0'
|
implementation 'com.github.bumptech.glide:glide:4.9.0'
|
||||||
annotationProcessor 'com.github.bumptech.glide:compiler:4.9.0'
|
annotationProcessor 'com.github.bumptech.glide:compiler:4.9.0'
|
||||||
|
implementation "de.adorsys.android:securestoragelibrary:1.0.3"
|
||||||
}
|
}
|
||||||
repositories {
|
repositories {
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
|
@ -17,11 +17,8 @@
|
|||||||
package io.github.chronosx88.influence;
|
package io.github.chronosx88.influence;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.SharedPreferences;
|
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import androidx.preference.PreferenceManager;
|
|
||||||
|
|
||||||
import org.greenrobot.eventbus.EventBus;
|
import org.greenrobot.eventbus.EventBus;
|
||||||
import org.jivesoftware.smack.ConnectionConfiguration;
|
import org.jivesoftware.smack.ConnectionConfiguration;
|
||||||
import org.jivesoftware.smack.ConnectionListener;
|
import org.jivesoftware.smack.ConnectionListener;
|
||||||
@ -40,11 +37,11 @@ import org.jivesoftware.smackx.mam.MamManager;
|
|||||||
import org.jivesoftware.smackx.vcardtemp.VCardManager;
|
import org.jivesoftware.smackx.vcardtemp.VCardManager;
|
||||||
import org.jxmpp.jid.BareJid;
|
import org.jxmpp.jid.BareJid;
|
||||||
import org.jxmpp.jid.EntityBareJid;
|
import org.jxmpp.jid.EntityBareJid;
|
||||||
import org.jxmpp.jid.impl.JidCreate;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
import de.adorsys.android.securestoragelibrary.SecurePreferences;
|
||||||
import io.github.chronosx88.influence.helpers.AppHelper;
|
import io.github.chronosx88.influence.helpers.AppHelper;
|
||||||
import io.github.chronosx88.influence.helpers.NetworkHandler;
|
import io.github.chronosx88.influence.helpers.NetworkHandler;
|
||||||
import io.github.chronosx88.influence.models.appEvents.AuthenticationStatusEvent;
|
import io.github.chronosx88.influence.models.appEvents.AuthenticationStatusEvent;
|
||||||
@ -53,7 +50,6 @@ public class XMPPConnection implements ConnectionListener {
|
|||||||
private final static String LOG_TAG = "XMPPConnection";
|
private final static String LOG_TAG = "XMPPConnection";
|
||||||
private LoginCredentials credentials = new LoginCredentials();
|
private LoginCredentials credentials = new LoginCredentials();
|
||||||
private XMPPTCPConnection connection = null;
|
private XMPPTCPConnection connection = null;
|
||||||
private SharedPreferences prefs;
|
|
||||||
private NetworkHandler networkHandler;
|
private NetworkHandler networkHandler;
|
||||||
private Context context;
|
private Context context;
|
||||||
private Roster roster;
|
private Roster roster;
|
||||||
@ -70,10 +66,9 @@ public class XMPPConnection implements ConnectionListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public XMPPConnection(Context context) {
|
public XMPPConnection(Context context) {
|
||||||
this.prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
|
||||||
this.context = context;
|
this.context = context;
|
||||||
String jid = prefs.getString("chatID", null);
|
String jid = SecurePreferences.getStringValue("jid", null);
|
||||||
String password = prefs.getString("pass", null);
|
String password = SecurePreferences.getStringValue("pass", null);
|
||||||
if(jid != null && password != null) {
|
if(jid != null && password != null) {
|
||||||
String username = jid.split("@")[0];
|
String username = jid.split("@")[0];
|
||||||
String jabberHost = jid.split("@")[1];
|
String jabberHost = jid.split("@")[1];
|
||||||
@ -138,7 +133,7 @@ public class XMPPConnection implements ConnectionListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void disconnect() {
|
public void disconnect() {
|
||||||
prefs.edit().putBoolean("logged_in", false).apply();
|
SecurePreferences.setValue("logged_in", false);
|
||||||
if(connection != null) {
|
if(connection != null) {
|
||||||
connection.disconnect();
|
connection.disconnect();
|
||||||
connection = null;
|
connection = null;
|
||||||
@ -153,7 +148,7 @@ public class XMPPConnection implements ConnectionListener {
|
|||||||
@Override
|
@Override
|
||||||
public void authenticated(org.jivesoftware.smack.XMPPConnection connection, boolean resumed) {
|
public void authenticated(org.jivesoftware.smack.XMPPConnection connection, boolean resumed) {
|
||||||
XMPPConnectionService.SESSION_STATE = SessionState.LOGGED_IN;
|
XMPPConnectionService.SESSION_STATE = SessionState.LOGGED_IN;
|
||||||
prefs.edit().putBoolean("logged_in", true).apply();
|
SecurePreferences.setValue("logged_in", true);
|
||||||
EventBus.getDefault().post(new AuthenticationStatusEvent(AuthenticationStatusEvent.CONNECT_AND_LOGIN_SUCCESSFUL));
|
EventBus.getDefault().post(new AuthenticationStatusEvent(AuthenticationStatusEvent.CONNECT_AND_LOGIN_SUCCESSFUL));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -161,14 +156,14 @@ public class XMPPConnection implements ConnectionListener {
|
|||||||
public void connectionClosed() {
|
public void connectionClosed() {
|
||||||
XMPPConnectionService.CONNECTION_STATE = ConnectionState.DISCONNECTED;
|
XMPPConnectionService.CONNECTION_STATE = ConnectionState.DISCONNECTED;
|
||||||
XMPPConnectionService.SESSION_STATE = SessionState.LOGGED_OUT;
|
XMPPConnectionService.SESSION_STATE = SessionState.LOGGED_OUT;
|
||||||
prefs.edit().putBoolean("logged_in", false).apply();
|
SecurePreferences.setValue("logged_in", false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void connectionClosedOnError(Exception e) {
|
public void connectionClosedOnError(Exception e) {
|
||||||
XMPPConnectionService.CONNECTION_STATE = ConnectionState.DISCONNECTED;
|
XMPPConnectionService.CONNECTION_STATE = ConnectionState.DISCONNECTED;
|
||||||
XMPPConnectionService.SESSION_STATE = SessionState.LOGGED_OUT;
|
XMPPConnectionService.SESSION_STATE = SessionState.LOGGED_OUT;
|
||||||
prefs.edit().putBoolean("logged_in", false).apply();
|
SecurePreferences.setValue("logged_in", false);
|
||||||
Log.e(LOG_TAG, "Connection closed, exception occurred");
|
Log.e(LOG_TAG, "Connection closed, exception occurred");
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
@ -109,7 +109,6 @@ public class XMPPConnectionService extends Service {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDestroy() {
|
public void onDestroy() {
|
||||||
super.onDestroy();
|
|
||||||
onServiceStop();
|
onServiceStop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,6 +33,7 @@ import java.io.IOException;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
import de.adorsys.android.securestoragelibrary.SecurePreferences;
|
||||||
import io.github.chronosx88.influence.LoginCredentials;
|
import io.github.chronosx88.influence.LoginCredentials;
|
||||||
import io.github.chronosx88.influence.XMPPConnection;
|
import io.github.chronosx88.influence.XMPPConnection;
|
||||||
|
|
||||||
@ -89,10 +90,10 @@ public class AppHelper extends MultiDexApplication {
|
|||||||
AppHelper.xmppConnection = xmppConnection;
|
AppHelper.xmppConnection = xmppConnection;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void loadLoginCredentials() {
|
public static void loadLoginCredentials() {
|
||||||
currentLoginCredentials = new LoginCredentials();
|
currentLoginCredentials = new LoginCredentials();
|
||||||
String jid = preferences.getString("chatID", null);
|
String jid = SecurePreferences.getStringValue("jid", null);
|
||||||
String password = preferences.getString("pass", null);
|
String password = SecurePreferences.getStringValue("pass", null);
|
||||||
if(jid != null && password != null) {
|
if(jid != null && password != null) {
|
||||||
String username = jid.split("@")[0];
|
String username = jid.split("@")[0];
|
||||||
String jabberHost = jid.split("@")[1];
|
String jabberHost = jid.split("@")[1];
|
||||||
@ -105,8 +106,9 @@ public class AppHelper extends MultiDexApplication {
|
|||||||
|
|
||||||
public static void resetLoginCredentials() {
|
public static void resetLoginCredentials() {
|
||||||
currentLoginCredentials = new LoginCredentials();
|
currentLoginCredentials = new LoginCredentials();
|
||||||
preferences.edit().remove("chatID").apply();
|
SecurePreferences.removeValue("jid");
|
||||||
preferences.edit().remove("pass").apply();
|
SecurePreferences.removeValue("pass");
|
||||||
|
SecurePreferences.removeValue("logged_in");
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void initTrueTime() {
|
private static void initTrueTime() {
|
||||||
@ -159,4 +161,8 @@ public class AppHelper extends MultiDexApplication {
|
|||||||
public static void setCurrentChatActivity(String currentChatActivity) {
|
public static void setCurrentChatActivity(String currentChatActivity) {
|
||||||
AppHelper.currentChatActivity = currentChatActivity;
|
AppHelper.currentChatActivity = currentChatActivity;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static LoginCredentials getCurrentLoginCredentials() {
|
||||||
|
return currentLoginCredentials;
|
||||||
|
}
|
||||||
}
|
}
|
@ -61,5 +61,8 @@ public class MainLogic implements CoreContracts.IMainLogicContract {
|
|||||||
AppHelper.resetLoginCredentials();
|
AppHelper.resetLoginCredentials();
|
||||||
context.unbindService(AppHelper.getServiceConnection());
|
context.unbindService(AppHelper.getServiceConnection());
|
||||||
context.stopService(new Intent(context, XMPPConnectionService.class));
|
context.stopService(new Intent(context, XMPPConnectionService.class));
|
||||||
|
AppHelper.setXmppConnection(null);
|
||||||
|
AppHelper.setServiceConnection(null);
|
||||||
|
AppHelper.setJid(null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -39,6 +39,7 @@ import org.greenrobot.eventbus.ThreadMode;
|
|||||||
import java.util.Timer;
|
import java.util.Timer;
|
||||||
import java.util.TimerTask;
|
import java.util.TimerTask;
|
||||||
|
|
||||||
|
import de.adorsys.android.securestoragelibrary.SecurePreferences;
|
||||||
import io.github.chronosx88.influence.R;
|
import io.github.chronosx88.influence.R;
|
||||||
import io.github.chronosx88.influence.XMPPConnectionService;
|
import io.github.chronosx88.influence.XMPPConnectionService;
|
||||||
import io.github.chronosx88.influence.contracts.CoreContracts;
|
import io.github.chronosx88.influence.contracts.CoreContracts;
|
||||||
@ -136,11 +137,9 @@ public class LoginActivity extends AppCompatActivity implements CoreContracts.IL
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void saveLoginCredentials() {
|
private void saveLoginCredentials() {
|
||||||
AppHelper.getPreferences().edit()
|
SecurePreferences.setValue("jid", jidEditText.getText().toString());
|
||||||
.putString("chatID", jidEditText.getText().toString())
|
SecurePreferences.setValue("pass", passwordEditText.getText().toString());
|
||||||
.putString("pass", passwordEditText.getText().toString())
|
SecurePreferences.setValue("logged_in", true);
|
||||||
.putBoolean("logged_in", true)
|
|
||||||
.apply();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void doLogin() {
|
private void doLogin() {
|
||||||
|
Loading…
Reference in New Issue
Block a user