From 91cc79d395463fa170eaae5b7bad99f235fd217b Mon Sep 17 00:00:00 2001 From: adbenitez Date: Thu, 30 Oct 2025 23:35:10 +0100 Subject: [PATCH 1/4] remove deprecated oauth code --- .../securesms/RegistrationActivity.java | 160 +----------------- src/main/res/layout/registration_activity.xml | 24 +-- 2 files changed, 5 insertions(+), 179 deletions(-) diff --git a/src/main/java/org/thoughtcrime/securesms/RegistrationActivity.java b/src/main/java/org/thoughtcrime/securesms/RegistrationActivity.java index 7d1012408..cc81b9298 100644 --- a/src/main/java/org/thoughtcrime/securesms/RegistrationActivity.java +++ b/src/main/java/org/thoughtcrime/securesms/RegistrationActivity.java @@ -94,7 +94,6 @@ public class RegistrationActivity extends BaseActionBarActivity implements DcEve Spinner imapSecurity; Spinner smtpSecurity; - Spinner authMethod; Spinner certCheck; private SwitchCompat proxySwitch; @@ -125,7 +124,6 @@ public class RegistrationActivity extends BaseActionBarActivity implements DcEve imapSecurity = findViewById(R.id.imap_security); smtpSecurity = findViewById(R.id.smtp_security); - authMethod = findViewById(R.id.auth_method); certCheck = findViewById(R.id.cert_check); proxySwitch = findViewById(R.id.proxy_settings); @@ -216,21 +214,6 @@ public class RegistrationActivity extends BaseActionBarActivity implements DcEve smtpSecurity.setSelection(ViewUtil.checkBounds(intVal, smtpSecurity)); expandAdvanced = expandAdvanced || intVal != 0; - int serverFlags = DcHelper.getInt(this, CONFIG_SERVER_FLAGS); - int sel = 0; - if((serverFlags&DcContext.DC_LP_AUTH_OAUTH2)!=0) { - sel = 1; - - // remove gmail oauth2 - if (DcHelper.getContext(this).isGmailOauth2Addr(email)) { // this is a blocking call, not perfect, but as rarely used and temporary, good enough - sel = 0; - updateProviderInfo(); // we refer to the hints in the device message, show them immediately - } - // /remove gmail oauth2 - } - authMethod.setSelection(ViewUtil.checkBounds(sel, authMethod)); - expandAdvanced = expandAdvanced || sel != 0; - int imapCertificateChecks = DcHelper.getInt(this, "imap_certificate_checks"); if (imapCertificateChecks == 3) { imapCertificateChecks = 2; // 3 is a deprecated alias for 2 @@ -287,7 +270,8 @@ public class RegistrationActivity extends BaseActionBarActivity implements DcEve int id = item.getItemId(); if (id == R.id.do_register) { - do_register(); + updateProviderInfo(); + onLogin(); return true; } else if (id == android.R.id.home) { // handle close button click here @@ -297,26 +281,6 @@ public class RegistrationActivity extends BaseActionBarActivity implements DcEve return super.onOptionsItemSelected(item); } - private void do_register() { - // "log in" button clicked - even if oauth2DeclinedByUser is true, - // we will ask for oauth2 to allow reverting the decision. - checkOauth2start().addListener(new ListenableFuture.Listener() { - @Override - public void onSuccess(Boolean oauth2started) { - if(!oauth2started) { - updateProviderInfo(); - onLogin(); - } - } - - @Override - public void onFailure(ExecutionException e) { - updateProviderInfo(); - onLogin(); - } - }); - } - @Override public void onDestroy() { super.onDestroy(); @@ -335,23 +299,7 @@ public class RegistrationActivity extends BaseActionBarActivity implements DcEve switch (type) { case EMAIL: verifyEmail(inputEditText); - if (!oauth2DeclinedByUser) { - checkOauth2start().addListener(new ListenableFuture.Listener() { - @Override - public void onSuccess(Boolean oauth2started) { - if (!oauth2started) { - updateProviderInfo(); - } - } - - @Override - public void onFailure(ExecutionException e) { - updateProviderInfo(); - } - }); - } else { - updateProviderInfo(); - } + updateProviderInfo(); break; case SERVER: verifyServer(inputEditText); @@ -363,86 +311,6 @@ public class RegistrationActivity extends BaseActionBarActivity implements DcEve } } - private long oauth2Requested = 0; - - // this flag is set, if the user has declined oauth2 at some point; - // if so, we won't bother em on focus changes again, - // however, to allow reverting the decision, we will always ask on clicking the login button. - private boolean oauth2DeclinedByUser = false; - - // this function checks if oauth2 is available for a given email address - // and and asks the user if one wants to start oauth2. - // the function returns the future "true" if oauth2 was started and "false" otherwise. - private ListenableFuture checkOauth2start() { - SettableFuture oauth2started = new SettableFuture<>(); - - String email = emailInput.getText().toString(); - if (!TextUtils.isEmpty(email) ) { - new PrecheckOauth2AsyncTask(this, email, oauth2started).execute(); - } - else { - oauth2started.set(false); - } - - return oauth2started; - } - - private static class PrecheckOauth2AsyncTask extends AsyncTask { - private final WeakReference activityWeakReference; - private final String email; - private final SettableFuture oauth2started; - private final DcContext dcContext; - private @NonNull String oauth2url = ""; - - public PrecheckOauth2AsyncTask(RegistrationActivity activity, String email, SettableFuture oauth2started) { - super(); - this.activityWeakReference = new WeakReference<>(activity); - this.email = email; - this.oauth2started = oauth2started; - this.dcContext = DcHelper.getContext(activity); - } - @Override - protected Void doInBackground(Void... voids) { - // the redirect-uri is also used as intent-filter in the manifest - // and should be whitelisted by the supported oauth2 services - String redirectUrl = "chat.delta:/"+BuildConfig.APPLICATION_ID+"/auth"; - oauth2url = dcContext.getOauth2Url(email, redirectUrl); - - // remove gmail oauth2 - if (dcContext.isGmailOauth2Url(oauth2url)) { - oauth2url = null; - } - // /remove gmail oauth2 - - return null; - } - - @Override - protected void onPostExecute(Void result) { - super.onPostExecute(result); - RegistrationActivity activity = activityWeakReference.get(); - if (activity!=null && !TextUtils.isEmpty(oauth2url)) { - new AlertDialog.Builder(activity) - .setTitle(R.string.login_info_oauth2_title) - .setMessage(R.string.login_info_oauth2_text) - .setNegativeButton(R.string.cancel, (dialog, which)->{ - activity.oauth2DeclinedByUser = true; - oauth2started.set(false); - }) - .setPositiveButton(R.string.perm_continue, (dialog, which)-> { - // pass control to browser, we'll be back in business at (**) - activity.oauth2Requested = System.currentTimeMillis(); - IntentUtils.showInBrowser(activity, oauth2url); - oauth2started.set(true); - }) - .setCancelable(false) - .show(); - } else { - oauth2started.set(false); - } - } - } - private void updateProviderInfo() { Util.runOnBackground(() -> { provider = getContext(this).getProviderFromEmailWithDns(emailInput.getText().toString()); @@ -495,27 +363,6 @@ public class RegistrationActivity extends BaseActionBarActivity implements DcEve } } - @Override - protected void onNewIntent(Intent intent) { - super.onNewIntent(intent); - if(Intent.ACTION_VIEW.equals(intent.getAction())) { - Uri uri = intent.getData(); - String path = uri.getPath(); - if(!(path.startsWith("/"+BuildConfig.APPLICATION_ID)||path.startsWith("/auth")) - || System.currentTimeMillis()-oauth2Requested > 3*60*60*1000) { - return; // timeout after some hours or a request belonging to a bad path. - } - - // back in business after we passed control to the browser in (**) - String code = uri.getQueryParameter("code"); - if(!TextUtils.isEmpty(code)) { - passwordInput.setText(code); - authMethod.setSelection(1/*OAuth2*/); - onLogin(); - } - } - } - private void verifyEmail(TextInputEditText view) { String error = getString(R.string.login_error_mail); String email = view.getText().toString(); @@ -634,7 +481,6 @@ public class RegistrationActivity extends BaseActionBarActivity implements DcEve param.smtpUser = getParam(R.id.smtp_login_text, false); param.smtpPassword = getParam(R.id.smtp_password_text, false); param.certificateChecks = certificateChecksFromInt(certCheck.getSelectedItemPosition()); - param.oauth2 = authMethod.getSelectedItemPosition() == 1; new Thread(() -> { Rpc rpc = DcHelper.getRpc(this); diff --git a/src/main/res/layout/registration_activity.xml b/src/main/res/layout/registration_activity.xml index 500387aae..e254e6d07 100644 --- a/src/main/res/layout/registration_activity.xml +++ b/src/main/res/layout/registration_activity.xml @@ -131,7 +131,7 @@ android:visibility="gone" tools:visibility="visible" app:constraint_referenced_ids="inbox, imap_login, imap_server, imap_port, imap_security_label, imap_security, outbox_view_spacer_top, - outbox, smtp_login, smtp_password, smtp_server, smtp_port, smtp_security_label, smtp_security, auth_method_label, auth_method, cert_check_label, cert_check, view_log_button, proxy_settings" /> + outbox, smtp_login, smtp_password, smtp_server, smtp_port, smtp_security_label, smtp_security, cert_check_label, cert_check, view_log_button, proxy_settings" /> - - - - + app:layout_constraintTop_toBottomOf="@id/smtp_security" /> Date: Thu, 30 Oct 2025 23:39:30 +0100 Subject: [PATCH 2/4] mark strings as deprecated --- src/main/res/values/strings.xml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml index 9ab1b0489..c6f0c9c4a 100644 --- a/src/main/res/values/strings.xml +++ b/src/main/res/values/strings.xml @@ -654,6 +654,7 @@ SMTP Server SMTP Port SMTP Security + Authorization Method Proxy @@ -669,7 +670,9 @@ Your friends can add this proxy by scanning the QR code. Share Link + Continue with simplified setup? + The entered address supports a simplified setup (OAuth 2.0).\n\nIn the next step, please allow Delta Chat to send and receive messages.\n\nDelta Chat does not collect user data, everything stays on your device. Certificate Checks Please enter a valid e-mail address From 69b0e953affac3dc548b4519d7742aff4dd9f629 Mon Sep 17 00:00:00 2001 From: adbenitez Date: Thu, 30 Oct 2025 23:39:50 +0100 Subject: [PATCH 3/4] remove oauth2 url redirection handling --- src/main/AndroidManifest.xml | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/src/main/AndroidManifest.xml b/src/main/AndroidManifest.xml index 702cdadbd..241079c7e 100644 --- a/src/main/AndroidManifest.xml +++ b/src/main/AndroidManifest.xml @@ -239,18 +239,6 @@ android:windowSoftInputMode="stateUnchanged" android:configChanges="touchscreen|keyboard|keyboardHidden|orientation|screenLayout|screenSize" android:exported="true"> - - - - - - - - - - - Date: Thu, 30 Oct 2025 23:44:16 +0100 Subject: [PATCH 4/4] remove oauth code from DcContext --- src/main/java/com/b44t/messenger/DcContext.java | 13 ------------- .../securesms/ConversationListActivity.java | 13 ------------- 2 files changed, 26 deletions(-) diff --git a/src/main/java/com/b44t/messenger/DcContext.java b/src/main/java/com/b44t/messenger/DcContext.java index df91fe82e..d358ff54d 100644 --- a/src/main/java/com/b44t/messenger/DcContext.java +++ b/src/main/java/com/b44t/messenger/DcContext.java @@ -71,9 +71,6 @@ public class DcContext { public final static int DC_QR_REVIVE_VERIFYGROUP = 512; public final static int DC_QR_LOGIN = 520; - public final static int DC_LP_AUTH_OAUTH2 = 0x2; - public final static int DC_LP_AUTH_NORMAL = 0x4; - public final static int DC_SOCKET_AUTO = 0; public final static int DC_SOCKET_SSL = 1; public final static int DC_SOCKET_STARTTLS = 2; @@ -145,7 +142,6 @@ public class DcContext { public native String getInfo (); public native int getConnectivity (); public native String getConnectivityHtml (); - public native String getOauth2Url (String addr, String redirectUrl); public native String initiateKeyTransfer (); public native void imex (int what, String dir); public native String imexHasBackup (String dir); @@ -246,15 +242,6 @@ public class DcContext { setConfigInt("is_muted", muted? 1 : 0); } - public boolean isGmailOauth2Addr(String addr) { - final String oauth2url = getOauth2Url(addr, "chat.delta:/foo"); - return isGmailOauth2Url(oauth2url); - } - - public boolean isGmailOauth2Url(String oauth2url) { - return oauth2url.startsWith("https://accounts.google.com/"); - } - public void restartIo() { stopIo(); startIo(); diff --git a/src/main/java/org/thoughtcrime/securesms/ConversationListActivity.java b/src/main/java/org/thoughtcrime/securesms/ConversationListActivity.java index 5106f0f8d..3a0cca84e 100644 --- a/src/main/java/org/thoughtcrime/securesms/ConversationListActivity.java +++ b/src/main/java/org/thoughtcrime/securesms/ConversationListActivity.java @@ -133,19 +133,6 @@ public class ConversationListActivity extends PassphraseRequiredActionBarActivit Prefs.setStringPreference(this, Prefs.LAST_DEVICE_MSG_LABEL, deviceMsgLabel); } - // remove gmail oauth2 - final int serverFlags = dcContext.getConfigInt(CONFIG_SERVER_FLAGS); - if ((serverFlags & DcContext.DC_LP_AUTH_OAUTH2)!=0) { - Util.runOnAnyBackgroundThread(() -> { - if (dcContext.isGmailOauth2Addr(dcContext.getConfig(CONFIG_ADDRESS))) { - final DcMsg msg = new DcMsg(dcContext, DcMsg.DC_MSG_TEXT); - msg.setText("⚠️ GMail Users: If you have problems using GMail, go to \"Settings / Advanced / Password and Account\".\n\nThere, login again using an \"App Password\"."); - dcContext.addDeviceMsg("info_about_gmail_oauth2_removal8", msg); - } - }); - } - // /remove gmail oauth2 - } catch(Exception e) { e.printStackTrace(); }