From 1e0904a48db4fd85c02381c07062042cba1a765a Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Fri, 6 Jan 2023 12:41:26 +0100 Subject: [PATCH] use less entropy in SASL2 device id --- .../conversations/utils/AccountUtils.java | 18 ++++++++++++++++++ .../conversations/xmpp/XmppConnection.java | 3 ++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/main/java/eu/siacs/conversations/utils/AccountUtils.java b/src/main/java/eu/siacs/conversations/utils/AccountUtils.java index 8f0453218..b8f4855d0 100644 --- a/src/main/java/eu/siacs/conversations/utils/AccountUtils.java +++ b/src/main/java/eu/siacs/conversations/utils/AccountUtils.java @@ -8,6 +8,7 @@ import android.widget.Toast; import java.util.ArrayList; import java.util.List; +import java.util.UUID; import eu.siacs.conversations.Config; import eu.siacs.conversations.R; @@ -34,6 +35,23 @@ public class AccountUtils { return false; } + public static String publicDeviceId(final Account account) { + final UUID uuid; + try { + uuid = UUID.fromString(account.getUuid()); + } catch (final IllegalArgumentException e) { + return account.getUuid(); + } + final UUID publicDeviceId = getUuid(uuid.getLeastSignificantBits(), uuid.getLeastSignificantBits()); + return publicDeviceId.toString(); + } + + protected static UUID getUuid(final long msb, final long lsb) { + final long msb0 = (msb & 0xffffffffffff0fffL) | 4; // set version + final long lsb0 = (lsb & 0x3fffffffffffffffL) | 0x8000000000000000L; // set variant + return new UUID(msb0, lsb0); + } + public static List getEnabledAccounts(final XmppConnectionService service) { ArrayList accounts = new ArrayList<>(); for (Account account : service.getAccounts()) { diff --git a/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java b/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java index a47613895..010cb76c7 100644 --- a/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java +++ b/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java @@ -77,6 +77,7 @@ import eu.siacs.conversations.services.MemorizingTrustManager; import eu.siacs.conversations.services.MessageArchiveService; import eu.siacs.conversations.services.NotificationService; import eu.siacs.conversations.services.XmppConnectionService; +import eu.siacs.conversations.utils.AccountUtils; import eu.siacs.conversations.utils.CryptoHelper; import eu.siacs.conversations.utils.Patterns; import eu.siacs.conversations.utils.PhoneHelper; @@ -1534,7 +1535,7 @@ public class XmppConnection implements Runnable { authenticate.addChild("initial-response").setContent(firstMessage); } final Element userAgent = authenticate.addChild("user-agent"); - userAgent.setAttribute("id", account.getUuid()); + userAgent.setAttribute("id", AccountUtils.publicDeviceId(account)); userAgent .addChild("software") .setContent(mXmppConnectionService.getString(R.string.app_name));