use bind 2 tag and sasl 2 user-agent

This commit is contained in:
Daniel Gultsch 2022-09-15 14:28:51 +02:00
parent bf15070fef
commit 5a3cca9554
2 changed files with 58 additions and 29 deletions

View file

@ -18,13 +18,17 @@ public class PhoneHelper {
} }
public static Uri getProfilePictureUri(Context context) { public static Uri getProfilePictureUri(Context context) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && context.checkSelfPermission(Manifest.permission.READ_CONTACTS) != PackageManager.PERMISSION_GRANTED) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M
&& context.checkSelfPermission(Manifest.permission.READ_CONTACTS)
!= PackageManager.PERMISSION_GRANTED) {
return null; return null;
} }
final String[] projection = new String[]{Profile._ID, Profile.PHOTO_URI}; final String[] projection = new String[] {Profile._ID, Profile.PHOTO_URI};
final Cursor cursor; final Cursor cursor;
try { try {
cursor = context.getContentResolver().query(Profile.CONTENT_URI, projection, null, null, null); cursor =
context.getContentResolver()
.query(Profile.CONTENT_URI, projection, null, null, null);
} catch (Throwable e) { } catch (Throwable e) {
return null; return null;
} }
@ -35,4 +39,24 @@ public class PhoneHelper {
cursor.close(); cursor.close();
return uri == null ? null : Uri.parse(uri); return uri == null ? null : Uri.parse(uri);
} }
public static boolean isEmulator() {
return (Build.BRAND.startsWith("generic") && Build.DEVICE.startsWith("generic"))
|| Build.FINGERPRINT.startsWith("generic")
|| Build.FINGERPRINT.startsWith("unknown")
|| Build.HARDWARE.contains("goldfish")
|| Build.HARDWARE.contains("ranchu")
|| Build.MODEL.contains("google_sdk")
|| Build.MODEL.contains("Emulator")
|| Build.MODEL.contains("Android SDK built for x86")
|| Build.MANUFACTURER.contains("Genymotion")
|| Build.PRODUCT.contains("sdk_google")
|| Build.PRODUCT.contains("google_sdk")
|| Build.PRODUCT.contains("sdk")
|| Build.PRODUCT.contains("sdk_x86")
|| Build.PRODUCT.contains("sdk_gphone64_arm64")
|| Build.PRODUCT.contains("vbox86p")
|| Build.PRODUCT.contains("emulator")
|| Build.PRODUCT.contains("simulator");
}
} }

View file

@ -5,6 +5,7 @@ import static eu.siacs.conversations.utils.Random.SECURE_RANDOM;
import android.content.Context; import android.content.Context;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.BitmapFactory; import android.graphics.BitmapFactory;
import android.os.Build;
import android.os.SystemClock; import android.os.SystemClock;
import android.security.KeyChain; import android.security.KeyChain;
import android.util.Base64; import android.util.Base64;
@ -59,6 +60,7 @@ import javax.net.ssl.SSLSocketFactory;
import javax.net.ssl.X509KeyManager; import javax.net.ssl.X509KeyManager;
import javax.net.ssl.X509TrustManager; import javax.net.ssl.X509TrustManager;
import eu.siacs.conversations.BuildConfig;
import eu.siacs.conversations.Config; import eu.siacs.conversations.Config;
import eu.siacs.conversations.R; import eu.siacs.conversations.R;
import eu.siacs.conversations.crypto.XmppDomainVerifier; import eu.siacs.conversations.crypto.XmppDomainVerifier;
@ -77,6 +79,7 @@ import eu.siacs.conversations.services.NotificationService;
import eu.siacs.conversations.services.XmppConnectionService; import eu.siacs.conversations.services.XmppConnectionService;
import eu.siacs.conversations.utils.CryptoHelper; import eu.siacs.conversations.utils.CryptoHelper;
import eu.siacs.conversations.utils.Patterns; import eu.siacs.conversations.utils.Patterns;
import eu.siacs.conversations.utils.PhoneHelper;
import eu.siacs.conversations.utils.Resolver; import eu.siacs.conversations.utils.Resolver;
import eu.siacs.conversations.utils.SSLSocketHelper; import eu.siacs.conversations.utils.SSLSocketHelper;
import eu.siacs.conversations.utils.SocksSocketFactory; import eu.siacs.conversations.utils.SocksSocketFactory;
@ -1292,6 +1295,14 @@ public class XmppConnection implements Runnable {
if (!Strings.isNullOrEmpty(firstMessage)) { if (!Strings.isNullOrEmpty(firstMessage)) {
authenticate.addChild("initial-response").setContent(firstMessage); authenticate.addChild("initial-response").setContent(firstMessage);
} }
final Element userAgent = authenticate.addChild("user-agent");
userAgent.setAttribute("id", account.getUuid());
userAgent.addChild("software").setContent(mXmppConnectionService.getString(R.string.app_name));
if (!PhoneHelper.isEmulator()) {
userAgent
.addChild("device")
.setContent(String.format("%s %s", Build.MANUFACTURER, Build.MODEL));
}
final Element inline = this.streamFeatures.findChild("inline", Namespace.SASL_2); final Element inline = this.streamFeatures.findChild("inline", Namespace.SASL_2);
final boolean inlineStreamManagement = final boolean inlineStreamManagement =
inline != null && inline.hasChild("sm", "urn:xmpp:sm:3"); inline != null && inline.hasChild("sm", "urn:xmpp:sm:3");
@ -1330,9 +1341,7 @@ public class XmppConnection implements Runnable {
private Element generateBindRequest(final Collection<String> bindFeatures) { private Element generateBindRequest(final Collection<String> bindFeatures) {
Log.d(Config.LOGTAG, "inline bind features: " + bindFeatures); Log.d(Config.LOGTAG, "inline bind features: " + bindFeatures);
final Element bind = new Element("bind", Namespace.BIND2); final Element bind = new Element("bind", Namespace.BIND2);
final Element clientId = bind.addChild("client-id"); bind.addChild("tag").setContent(mXmppConnectionService.getString(R.string.app_name));
clientId.setAttribute("tag", mXmppConnectionService.getString(R.string.app_name));
clientId.setContent(account.getUuid());
final Element features = bind.addChild("features"); final Element features = bind.addChild("features");
if (bindFeatures.contains(Namespace.CARBONS)) { if (bindFeatures.contains(Namespace.CARBONS)) {
features.addChild("enable", Namespace.CARBONS); features.addChild("enable", Namespace.CARBONS);
@ -1343,10 +1352,6 @@ public class XmppConnection implements Runnable {
return bind; return bind;
} }
private static Collection<String> extractMechanisms(final Element stream) {
return Collections2.transform(stream.getChildren(), c -> c == null ? null : c.getContent());
}
private void register() { private void register() {
final String preAuth = account.getKey(Account.KEY_PRE_AUTH_REGISTRATION_TOKEN); final String preAuth = account.getKey(Account.KEY_PRE_AUTH_REGISTRATION_TOKEN);
if (preAuth != null && features.invite()) { if (preAuth != null && features.invite()) {