use less entropy in SASL2 device id

This commit is contained in:
Daniel Gultsch 2023-01-06 12:41:26 +01:00
parent 7af0dda5af
commit 1e0904a48d
No known key found for this signature in database
GPG key ID: F43D18AD2A0982C2
2 changed files with 20 additions and 1 deletions

View file

@ -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<String> getEnabledAccounts(final XmppConnectionService service) {
ArrayList<String> accounts = new ArrayList<>();
for (Account account : service.getAccounts()) {

View file

@ -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));