mirror of
https://github.com/oxen-io/session-android.git
synced 2024-11-27 20:15:21 +00:00
support mms basic auth
// FREEBIE
This commit is contained in:
parent
5002a749cf
commit
f3f173f653
@ -645,6 +645,8 @@
|
|||||||
<string name="preferences__mmsc_url_required">MMSC URL (Required)</string>
|
<string name="preferences__mmsc_url_required">MMSC URL (Required)</string>
|
||||||
<string name="preferences__mms_proxy_host_optional">MMS Proxy Host (Optional)</string>
|
<string name="preferences__mms_proxy_host_optional">MMS Proxy Host (Optional)</string>
|
||||||
<string name="preferences__mms_proxy_port_optional">MMS Proxy Port (Optional)</string>
|
<string name="preferences__mms_proxy_port_optional">MMS Proxy Port (Optional)</string>
|
||||||
|
<string name="preferences__mmsc_username_optional">MMSC Username (Optional)</string>
|
||||||
|
<string name="preferences__mmsc_password_optional">MMSC Password (Optional)</string>
|
||||||
<string name="preferences__sms_delivery_reports">SMS delivery reports</string>
|
<string name="preferences__sms_delivery_reports">SMS delivery reports</string>
|
||||||
<string name="preferences__request_a_delivery_report_for_each_sms_message_you_send">Request a delivery report for each SMS message you send</string>
|
<string name="preferences__request_a_delivery_report_for_each_sms_message_you_send">Request a delivery report for each SMS message you send</string>
|
||||||
<string name="preferences__automatically_delete_older_messages_once_a_conversation_thread_exceeds_a_specified_length">Automatically delete older messages once a conversation thread exceeds a specified length</string>
|
<string name="preferences__automatically_delete_older_messages_once_a_conversation_thread_exceeds_a_specified_length">Automatically delete older messages once a conversation thread exceeds a specified length</string>
|
||||||
|
@ -20,4 +20,14 @@
|
|||||||
android:title="@string/preferences__mms_proxy_port_optional"
|
android:title="@string/preferences__mms_proxy_port_optional"
|
||||||
android:dependency="pref_enable_manual_mms"
|
android:dependency="pref_enable_manual_mms"
|
||||||
android:inputType="number" />
|
android:inputType="number" />
|
||||||
|
|
||||||
|
<EditTextPreference android:key="pref_apn_mmsc_username"
|
||||||
|
android:title="@string/preferences__mmsc_username_optional"
|
||||||
|
android:dependency="pref_enable_manual_mms"
|
||||||
|
android:inputType="textNoSuggestions" />
|
||||||
|
|
||||||
|
<EditTextPreference android:key="pref_apn_mmsc_password"
|
||||||
|
android:title="@string/preferences__mmsc_password_optional"
|
||||||
|
android:dependency="pref_enable_manual_mms"
|
||||||
|
android:inputType="textVisiblePassword" />
|
||||||
</PreferenceScreen>
|
</PreferenceScreen>
|
@ -65,6 +65,8 @@ public class MmsPreferencesFragment extends PreferenceFragment {
|
|||||||
initializeEditTextSummary((EditTextPreference)this.findPreference(TextSecurePreferences.MMSC_HOST_PREF));
|
initializeEditTextSummary((EditTextPreference)this.findPreference(TextSecurePreferences.MMSC_HOST_PREF));
|
||||||
initializeEditTextSummary((EditTextPreference)this.findPreference(TextSecurePreferences.MMSC_PROXY_HOST_PREF));
|
initializeEditTextSummary((EditTextPreference)this.findPreference(TextSecurePreferences.MMSC_PROXY_HOST_PREF));
|
||||||
initializeEditTextSummary((EditTextPreference)this.findPreference(TextSecurePreferences.MMSC_PROXY_PORT_PREF));
|
initializeEditTextSummary((EditTextPreference)this.findPreference(TextSecurePreferences.MMSC_PROXY_PORT_PREF));
|
||||||
|
initializeEditTextSummary((EditTextPreference)this.findPreference(TextSecurePreferences.MMSC_USERNAME_PREF));
|
||||||
|
initializeEditTextSummary((EditTextPreference)this.findPreference(TextSecurePreferences.MMSC_PASSWORD_PREF));
|
||||||
}
|
}
|
||||||
|
|
||||||
private class OverrideMmsChangeListener implements Preference.OnPreferenceChangeListener {
|
private class OverrideMmsChangeListener implements Preference.OnPreferenceChangeListener {
|
||||||
|
@ -104,8 +104,10 @@ public class ApnDatabase {
|
|||||||
|
|
||||||
String proxy = TextSecurePreferences.getMmscProxy(context);
|
String proxy = TextSecurePreferences.getMmscProxy(context);
|
||||||
String port = TextSecurePreferences.getMmscProxyPort(context);
|
String port = TextSecurePreferences.getMmscProxyPort(context);
|
||||||
|
String user = TextSecurePreferences.getMmscUsername(context);
|
||||||
|
String pass = TextSecurePreferences.getMmscPassword(context);
|
||||||
|
|
||||||
return new Apn(mmsc, proxy, port);
|
return new Apn(mmsc, proxy, port, user, pass);
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new ApnUnavailableException("No locally configured parameters available");
|
throw new ApnUnavailableException("No locally configured parameters available");
|
||||||
@ -151,7 +153,9 @@ public class ApnDatabase {
|
|||||||
if (cursor != null && cursor.moveToFirst()) {
|
if (cursor != null && cursor.moveToFirst()) {
|
||||||
Apn params = new Apn(cursor.getString(cursor.getColumnIndexOrThrow(MMSC_COLUMN)),
|
Apn params = new Apn(cursor.getString(cursor.getColumnIndexOrThrow(MMSC_COLUMN)),
|
||||||
cursor.getString(cursor.getColumnIndexOrThrow(MMS_PROXY_COLUMN)),
|
cursor.getString(cursor.getColumnIndexOrThrow(MMS_PROXY_COLUMN)),
|
||||||
cursor.getString(cursor.getColumnIndexOrThrow(MMS_PORT_COLUMN)));
|
cursor.getString(cursor.getColumnIndexOrThrow(MMS_PORT_COLUMN)),
|
||||||
|
cursor.getString(cursor.getColumnIndexOrThrow(USER_COLUMN)),
|
||||||
|
cursor.getString(cursor.getColumnIndexOrThrow(PASSWORD_COLUMN)));
|
||||||
Log.w(TAG, "Returning preferred APN " + params);
|
Log.w(TAG, "Returning preferred APN " + params);
|
||||||
return params;
|
return params;
|
||||||
}
|
}
|
||||||
|
@ -192,7 +192,7 @@ public class MmsDownloadJob extends MasterSecretJob {
|
|||||||
InvalidMessageException, LegacyMessageException
|
InvalidMessageException, LegacyMessageException
|
||||||
{
|
{
|
||||||
Apn dbApn = MmsConnection.getApn(context, radio.getApnInformation());
|
Apn dbApn = MmsConnection.getApn(context, radio.getApnInformation());
|
||||||
Apn contentApn = new Apn(contentLocation, dbApn.getProxy(), Integer.toString(dbApn.getPort()));
|
Apn contentApn = new Apn(contentLocation, dbApn.getProxy(), Integer.toString(dbApn.getPort()), dbApn.getUsername(), dbApn.getPassword());
|
||||||
IncomingMmsConnection connection = new IncomingMmsConnection(context, contentApn);
|
IncomingMmsConnection connection = new IncomingMmsConnection(context, contentApn);
|
||||||
RetrieveConf retrieved = connection.retrieve(radioEnabled, useProxy);
|
RetrieveConf retrieved = connection.retrieve(radioEnabled, useProxy);
|
||||||
|
|
||||||
|
@ -21,10 +21,14 @@ import android.net.ConnectivityManager;
|
|||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
|
import org.apache.http.auth.AuthScope;
|
||||||
|
import org.apache.http.auth.UsernamePasswordCredentials;
|
||||||
|
import org.apache.http.client.CredentialsProvider;
|
||||||
import org.apache.http.client.config.RequestConfig;
|
import org.apache.http.client.config.RequestConfig;
|
||||||
import org.apache.http.client.methods.CloseableHttpResponse;
|
import org.apache.http.client.methods.CloseableHttpResponse;
|
||||||
import org.apache.http.client.methods.HttpUriRequest;
|
import org.apache.http.client.methods.HttpUriRequest;
|
||||||
import org.apache.http.impl.NoConnectionReuseStrategyHC4;
|
import org.apache.http.impl.NoConnectionReuseStrategyHC4;
|
||||||
|
import org.apache.http.impl.client.BasicCredentialsProvider;
|
||||||
import org.apache.http.impl.client.CloseableHttpClient;
|
import org.apache.http.impl.client.CloseableHttpClient;
|
||||||
import org.apache.http.impl.client.HttpClients;
|
import org.apache.http.impl.client.HttpClients;
|
||||||
import org.apache.http.impl.client.LaxRedirectStrategy;
|
import org.apache.http.impl.client.LaxRedirectStrategy;
|
||||||
@ -39,6 +43,7 @@ import java.io.ByteArrayOutputStream;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
|
import java.net.URL;
|
||||||
|
|
||||||
public abstract class MmsConnection {
|
public abstract class MmsConnection {
|
||||||
private static final String TAG = "MmsCommunication";
|
private static final String TAG = "MmsCommunication";
|
||||||
@ -116,12 +121,21 @@ public abstract class MmsConnection {
|
|||||||
.setMaxRedirects(20)
|
.setMaxRedirects(20)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
|
URL mmsc = new URL(apn.getMmsc());
|
||||||
|
CredentialsProvider credsProvider = new BasicCredentialsProvider();
|
||||||
|
|
||||||
|
if (apn.hasAuthentication()) {
|
||||||
|
credsProvider.setCredentials(new AuthScope(mmsc.getHost(), mmsc.getPort() > -1 ? mmsc.getPort() : mmsc.getDefaultPort()),
|
||||||
|
new UsernamePasswordCredentials(apn.getUsername(), apn.getPassword()));
|
||||||
|
}
|
||||||
|
|
||||||
return HttpClients.custom()
|
return HttpClients.custom()
|
||||||
.setConnectionReuseStrategy(new NoConnectionReuseStrategyHC4())
|
.setConnectionReuseStrategy(new NoConnectionReuseStrategyHC4())
|
||||||
.setRedirectStrategy(new LaxRedirectStrategy())
|
.setRedirectStrategy(new LaxRedirectStrategy())
|
||||||
.setUserAgent("Android-Mms/2.0")
|
.setUserAgent("Android-Mms/2.0")
|
||||||
.setConnectionManager(new BasicHttpClientConnectionManager())
|
.setConnectionManager(new BasicHttpClientConnectionManager())
|
||||||
.setDefaultRequestConfig(config)
|
.setDefaultRequestConfig(config)
|
||||||
|
.setDefaultCredentialsProvider(credsProvider)
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -155,11 +169,15 @@ public abstract class MmsConnection {
|
|||||||
private final String mmsc;
|
private final String mmsc;
|
||||||
private final String proxy;
|
private final String proxy;
|
||||||
private final String port;
|
private final String port;
|
||||||
|
private final String username;
|
||||||
|
private final String password;
|
||||||
|
|
||||||
public Apn(String mmsc, String proxy, String port) {
|
public Apn(String mmsc, String proxy, String port, String username, String password) {
|
||||||
this.mmsc = mmsc;
|
this.mmsc = mmsc;
|
||||||
this.proxy = proxy;
|
this.proxy = proxy;
|
||||||
this.port = port;
|
this.port = port;
|
||||||
|
this.username = username;
|
||||||
|
this.password = password;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasProxy() {
|
public boolean hasProxy() {
|
||||||
@ -178,12 +196,26 @@ public abstract class MmsConnection {
|
|||||||
return TextUtils.isEmpty(port) ? 80 : Integer.parseInt(port);
|
return TextUtils.isEmpty(port) ? 80 : Integer.parseInt(port);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean hasAuthentication() {
|
||||||
|
return !TextUtils.isEmpty(username) || !TextUtils.isEmpty(password);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getUsername() {
|
||||||
|
return username;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPassword() {
|
||||||
|
return password;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return Apn.class.getSimpleName() +
|
return Apn.class.getSimpleName() +
|
||||||
"{ mmsc: \"" + mmsc + "\"" +
|
"{ mmsc: \"" + mmsc + "\"" +
|
||||||
", proxy: " + (proxy == null ? "none" : '"' + proxy + '"') +
|
", proxy: " + (proxy == null ? "none" : '"' + proxy + '"') +
|
||||||
", port: " + (port == null ? "none" : port) + " }";
|
", port: " + (port == null ? "(none)" : port) +
|
||||||
|
", user: " + (username == null ? "none" : '"' + username + '"') +
|
||||||
|
", pass: " + (password == null ? "none" : '"' + password + '"') + " }";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,8 @@ public class TextSecurePreferences {
|
|||||||
public static final String MMSC_HOST_PREF = "pref_apn_mmsc_host";
|
public static final String MMSC_HOST_PREF = "pref_apn_mmsc_host";
|
||||||
public static final String MMSC_PROXY_HOST_PREF = "pref_apn_mms_proxy";
|
public static final String MMSC_PROXY_HOST_PREF = "pref_apn_mms_proxy";
|
||||||
public static final String MMSC_PROXY_PORT_PREF = "pref_apn_mms_proxy_port";
|
public static final String MMSC_PROXY_PORT_PREF = "pref_apn_mms_proxy_port";
|
||||||
|
public static final String MMSC_USERNAME_PREF = "pref_apn_mmsc_username";
|
||||||
|
public static final String MMSC_PASSWORD_PREF = "pref_apn_mmsc_password";
|
||||||
public static final String THREAD_TRIM_LENGTH = "pref_trim_length";
|
public static final String THREAD_TRIM_LENGTH = "pref_trim_length";
|
||||||
public static final String THREAD_TRIM_NOW = "pref_trim_now";
|
public static final String THREAD_TRIM_NOW = "pref_trim_now";
|
||||||
public static final String ENABLE_MANUAL_MMS_PREF = "pref_enable_manual_mms";
|
public static final String ENABLE_MANUAL_MMS_PREF = "pref_enable_manual_mms";
|
||||||
@ -177,6 +179,14 @@ public class TextSecurePreferences {
|
|||||||
return getStringPreference(context, MMSC_PROXY_PORT_PREF, "");
|
return getStringPreference(context, MMSC_PROXY_PORT_PREF, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String getMmscUsername(Context context) {
|
||||||
|
return getStringPreference(context, MMSC_USERNAME_PREF, "");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getMmscPassword(Context context) {
|
||||||
|
return getStringPreference(context, MMSC_PASSWORD_PREF, "");
|
||||||
|
}
|
||||||
|
|
||||||
public static String getIdentityContactUri(Context context) {
|
public static String getIdentityContactUri(Context context) {
|
||||||
return getStringPreference(context, IDENTITY_PREF, null);
|
return getStringPreference(context, IDENTITY_PREF, null);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user