From 9ef2d32a3e1240eaeaba6a4c5730fb9c87a852ca Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Sat, 12 May 2018 17:23:37 +0200 Subject: [PATCH] changed jid of push server --- .../java/eu/siacs/conversations/generator/IqGenerator.java | 2 +- .../conversations/services/XmppConnectionService.java | 2 +- .../java/eu/siacs/conversations/utils/CryptoHelper.java | 6 +++--- .../java/eu/siacs/conversations/utils/PhoneHelper.java | 7 +++++++ .../conversations/services/PushManagementService.java | 7 ++++--- 5 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/generator/IqGenerator.java b/src/main/java/eu/siacs/conversations/generator/IqGenerator.java index 304e962b3..0e895b46b 100644 --- a/src/main/java/eu/siacs/conversations/generator/IqGenerator.java +++ b/src/main/java/eu/siacs/conversations/generator/IqGenerator.java @@ -387,7 +387,7 @@ public class IqGenerator extends AbstractGenerator { command.setAttribute("action","execute"); Data data = new Data(); data.put("token", token); - data.put("device-id", deviceId); + data.put("android-id", deviceId); data.submit(); command.addChild(data); return packet; diff --git a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java index 1648988d4..7d1c78c0f 100644 --- a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java @@ -667,7 +667,7 @@ public class XmppConnectionService extends Service { pingNow |= processAccountState(account, interactive, "ui".equals(action), - CryptoHelper.getAccountFingerprint(account).equals(pushedAccountHash), + CryptoHelper.getAccountFingerprint(account,PhoneHelper.getAndroidId(this)).equals(pushedAccountHash), pingCandidates); } if (pingNow) { diff --git a/src/main/java/eu/siacs/conversations/utils/CryptoHelper.java b/src/main/java/eu/siacs/conversations/utils/CryptoHelper.java index 540c0b9ca..426e63b86 100644 --- a/src/main/java/eu/siacs/conversations/utils/CryptoHelper.java +++ b/src/main/java/eu/siacs/conversations/utils/CryptoHelper.java @@ -222,13 +222,13 @@ public final class CryptoHelper { return prettifyFingerprintCert(bytesToHex(fingerprint)); } - public static String getAccountFingerprint(Account account) { - return getFingerprint(account.getJid().asBareJid().toString()); + public static String getAccountFingerprint(Account account, String androidId) { + return getFingerprint(account.getJid().asBareJid().toEscapedString()+"\00"+androidId); } public static String getFingerprint(String value) { try { - MessageDigest md = MessageDigest.getInstance("SHA-256"); + MessageDigest md = MessageDigest.getInstance("SHA-1"); return bytesToHex(md.digest(value.getBytes("UTF-8"))); } catch (Exception e) { return ""; diff --git a/src/main/java/eu/siacs/conversations/utils/PhoneHelper.java b/src/main/java/eu/siacs/conversations/utils/PhoneHelper.java index e217cf6e9..65aba4c39 100644 --- a/src/main/java/eu/siacs/conversations/utils/PhoneHelper.java +++ b/src/main/java/eu/siacs/conversations/utils/PhoneHelper.java @@ -1,6 +1,7 @@ package eu.siacs.conversations.utils; import android.Manifest; +import android.annotation.SuppressLint; import android.content.Context; import android.content.CursorLoader; import android.content.pm.PackageManager; @@ -10,6 +11,7 @@ import android.os.Build; import android.os.Bundle; import android.provider.ContactsContract; import android.provider.ContactsContract.Profile; +import android.provider.Settings; import java.util.ArrayList; import java.util.List; @@ -17,6 +19,11 @@ import java.util.concurrent.RejectedExecutionException; public class PhoneHelper { + @SuppressLint("HardwareIds") + public static String getAndroidId(Context context) { + return Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID); + } + public static void loadPhoneContacts(Context context, final OnPhoneContactsLoadedListener listener) { final List phoneContacts = new ArrayList<>(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M diff --git a/src/playstore/java/eu/siacs/conversations/services/PushManagementService.java b/src/playstore/java/eu/siacs/conversations/services/PushManagementService.java index c5358f5db..a22ac0750 100644 --- a/src/playstore/java/eu/siacs/conversations/services/PushManagementService.java +++ b/src/playstore/java/eu/siacs/conversations/services/PushManagementService.java @@ -11,6 +11,7 @@ import com.google.android.gms.iid.InstanceID; import eu.siacs.conversations.Config; import eu.siacs.conversations.R; import eu.siacs.conversations.entities.Account; +import eu.siacs.conversations.utils.PhoneHelper; import eu.siacs.conversations.xml.Element; import eu.siacs.conversations.xml.Namespace; import eu.siacs.conversations.xmpp.XmppConnection; @@ -20,7 +21,7 @@ import rocks.xmpp.addr.Jid; public class PushManagementService { - private static final Jid APP_SERVER = Jid.of("push.siacs.eu"); + private static final Jid APP_SERVER = Jid.of("p2.siacs.eu"); protected final XmppConnectionService mXmppConnectionService; @@ -31,8 +32,8 @@ public class PushManagementService { void registerPushTokenOnServer(final Account account) { Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": has push support"); retrieveGcmInstanceToken(token -> { - final String deviceId = Settings.Secure.getString(mXmppConnectionService.getContentResolver(), Settings.Secure.ANDROID_ID); - IqPacket packet = mXmppConnectionService.getIqGenerator().pushTokenToAppServer(APP_SERVER, token, deviceId); + final String androidId = PhoneHelper.getAndroidId(mXmppConnectionService); + IqPacket packet = mXmppConnectionService.getIqGenerator().pushTokenToAppServer(APP_SERVER, token, androidId); mXmppConnectionService.sendIqPacket(account, packet, (a, p) -> { Element command = p.findChild("command", "http://jabber.org/protocol/commands"); if (p.getType() == IqPacket.TYPE.RESULT && command != null) {