From c7e7d005128b973c2a400a92f6cb1265ee508e5c Mon Sep 17 00:00:00 2001 From: cyberta Date: Wed, 30 Oct 2019 12:40:14 +0100 Subject: [PATCH 1/4] implement certificate check settings for imap/smtp (#1047) --- res/layout/registration_activity.xml | 23 +++++++++++++++++-- res/values/arrays.xml | 7 ++++++ res/values/strings.xml | 1 + .../securesms/RegistrationActivity.java | 8 +++++++ 4 files changed, 37 insertions(+), 2 deletions(-) diff --git a/res/layout/registration_activity.xml b/res/layout/registration_activity.xml index 27341517c..8e5639a6a 100644 --- a/res/layout/registration_activity.xml +++ b/res/layout/registration_activity.xml @@ -90,7 +90,7 @@ android:layout_height="wrap_content" android:visibility="gone" 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, view_log_button" /> + 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" /> + + + + + app:layout_constraintTop_toBottomOf="@id/cert_check" /> 1 + + @string/automatic + @string/strict + @string/accept_invalid_hostnames + @string/accept_invalid_certificates + + diff --git a/res/values/strings.xml b/res/values/strings.xml index a388eaaf7..73ed75d54 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -339,6 +339,7 @@ Cannot login as \"%1$s\". Please check if the email-address and the password are correct. Response from %1$s: %2$s\n\nSome providers place additional information in your inbox; you can check them it eg. in the web frontend. Consult your provider or friends if you run into problems. + IMAP/SMTP certificate checks Accept invalid hostnames diff --git a/src/org/thoughtcrime/securesms/RegistrationActivity.java b/src/org/thoughtcrime/securesms/RegistrationActivity.java index 1b70e566a..80d3a2a09 100644 --- a/src/org/thoughtcrime/securesms/RegistrationActivity.java +++ b/src/org/thoughtcrime/securesms/RegistrationActivity.java @@ -67,6 +67,7 @@ public class RegistrationActivity extends BaseActionBarActivity implements DcEve Spinner imapSecurity; Spinner smtpSecurity; Spinner authMethod; + Spinner certCheck; @Override public void onCreate(Bundle bundle) { @@ -89,6 +90,7 @@ 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); ActionBar actionBar = getSupportActionBar(); if (actionBar != null) { @@ -149,6 +151,9 @@ public class RegistrationActivity extends BaseActionBarActivity implements DcEve sel = 0; if((server_flags&DcContext.DC_LP_AUTH_OAUTH2)!=0) sel = 1; authMethod.setSelection(sel); + + int certCheckFlags = DcHelper.getInt(this, "imap_certificate_checks"); + certCheck.setSelection(certCheckFlags); } DcHelper.getContext(this).eventCenter.addObserver(this, DcContext.DC_EVENT_CONFIGURE_PROGRESS); @@ -434,6 +439,9 @@ public class RegistrationActivity extends BaseActionBarActivity implements DcEve if(authMethod.getSelectedItemPosition()==1) server_flags |= DcContext.DC_LP_AUTH_OAUTH2; DcHelper.getContext(this).setConfigInt("server_flags", server_flags); + DcHelper.getContext(this).setConfigInt("smtp_certificate_checks", certCheck.getSelectedItemPosition()); + DcHelper.getContext(this).setConfigInt("imap_certificate_checks", certCheck.getSelectedItemPosition()); + // calling configure() results in // receiving multiple DC_EVENT_CONFIGURE_PROGRESS events DcHelper.getContext(this).captureNextError(); From eb26c5c27598d6009e0b89d02971541517a4e8e3 Mon Sep 17 00:00:00 2001 From: cyberta Date: Wed, 30 Oct 2019 12:41:55 +0100 Subject: [PATCH 2/4] fix deprecation warning in RegistrationActivity --- src/org/thoughtcrime/securesms/RegistrationActivity.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/org/thoughtcrime/securesms/RegistrationActivity.java b/src/org/thoughtcrime/securesms/RegistrationActivity.java index 80d3a2a09..7bc3bcae5 100644 --- a/src/org/thoughtcrime/securesms/RegistrationActivity.java +++ b/src/org/thoughtcrime/securesms/RegistrationActivity.java @@ -156,7 +156,7 @@ public class RegistrationActivity extends BaseActionBarActivity implements DcEve certCheck.setSelection(certCheckFlags); } - DcHelper.getContext(this).eventCenter.addObserver(this, DcContext.DC_EVENT_CONFIGURE_PROGRESS); + DcHelper.getContext(this).eventCenter.addObserver(DcContext.DC_EVENT_CONFIGURE_PROGRESS, this); } @Override From 5c22c2f8db908e5b28391f48ac19b953cfb0d0ed Mon Sep 17 00:00:00 2001 From: cyberta Date: Wed, 30 Oct 2019 12:43:08 +0100 Subject: [PATCH 3/4] use camelCase for java variables --- .../securesms/RegistrationActivity.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/org/thoughtcrime/securesms/RegistrationActivity.java b/src/org/thoughtcrime/securesms/RegistrationActivity.java index 7bc3bcae5..80d8faeb7 100644 --- a/src/org/thoughtcrime/securesms/RegistrationActivity.java +++ b/src/org/thoughtcrime/securesms/RegistrationActivity.java @@ -134,22 +134,22 @@ public class RegistrationActivity extends BaseActionBarActivity implements DcEve smtpServerInput.setText(DcHelper.get(this, CONFIG_SEND_SERVER)); smtpPortInput.setText(DcHelper.get(this, CONFIG_SEND_PORT)); - int server_flags = DcHelper.getInt(this, "server_flags", 0); + int serverFlags = DcHelper.getInt(this, "server_flags", 0); int sel = 0; - if((server_flags&DcContext.DC_LP_IMAP_SOCKET_SSL)!=0) sel = 1; - if((server_flags&DcContext.DC_LP_IMAP_SOCKET_STARTTLS)!=0) sel = 2; - if((server_flags&DcContext.DC_LP_IMAP_SOCKET_PLAIN)!=0) sel = 3; + if((serverFlags&DcContext.DC_LP_IMAP_SOCKET_SSL)!=0) sel = 1; + if((serverFlags&DcContext.DC_LP_IMAP_SOCKET_STARTTLS)!=0) sel = 2; + if((serverFlags&DcContext.DC_LP_IMAP_SOCKET_PLAIN)!=0) sel = 3; imapSecurity.setSelection(sel); sel = 0; - if((server_flags&DcContext.DC_LP_SMTP_SOCKET_SSL)!=0) sel = 1; - if((server_flags&DcContext.DC_LP_SMTP_SOCKET_STARTTLS)!=0) sel = 2; - if((server_flags&DcContext.DC_LP_SMTP_SOCKET_PLAIN)!=0) sel = 3; + if((serverFlags&DcContext.DC_LP_SMTP_SOCKET_SSL)!=0) sel = 1; + if((serverFlags&DcContext.DC_LP_SMTP_SOCKET_STARTTLS)!=0) sel = 2; + if((serverFlags&DcContext.DC_LP_SMTP_SOCKET_PLAIN)!=0) sel = 3; smtpSecurity.setSelection(sel); sel = 0; - if((server_flags&DcContext.DC_LP_AUTH_OAUTH2)!=0) sel = 1; + if((serverFlags&DcContext.DC_LP_AUTH_OAUTH2)!=0) sel = 1; authMethod.setSelection(sel); int certCheckFlags = DcHelper.getInt(this, "imap_certificate_checks"); From da8c3c50f84616a0e8714d682618683aa34f37fe Mon Sep 17 00:00:00 2001 From: "B. Petersen" Date: Fri, 1 Nov 2019 01:19:25 +0100 Subject: [PATCH 4/4] wording --- res/values/strings.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/res/values/strings.xml b/res/values/strings.xml index 73ed75d54..3e6d1b7c1 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -328,6 +328,7 @@ Continue with simplified setup? The entered e-mail-address supports a simplified setup (OAuth2).\n\nIn the next step, please allow Delta Chat to act as your Chat with E-Mail app.\n\nThere are no Delta Chat servers, your data stays on your device! For GMail Accounts you need to create an App-Password if you have 2FA enabled. If this setting is not available, you need to enable Less Secure Apps. + Certificate checks Please enter a valid email address Please enter a valid server / IP address Please enter a valid port (1–65535) @@ -339,7 +340,6 @@ Cannot login as \"%1$s\". Please check if the email-address and the password are correct. Response from %1$s: %2$s\n\nSome providers place additional information in your inbox; you can check them it eg. in the web frontend. Consult your provider or friends if you run into problems. - IMAP/SMTP certificate checks Accept invalid hostnames