Add missing MSISDN headers to MMS send request

Fixes #1935
Fixes #2451
Closes #2605

// FREEBIE
This commit is contained in:
Jake McGinty 2015-03-06 13:57:00 -08:00 committed by Moxie Marlinspike
parent 0b8430ff43
commit b998c5f86c
5 changed files with 39 additions and 5 deletions

View File

@ -24,6 +24,7 @@ import org.thoughtcrime.securesms.transport.InsecureFallbackApprovalException;
import org.thoughtcrime.securesms.transport.UndeliverableMessageException;
import org.thoughtcrime.securesms.util.Hex;
import org.thoughtcrime.securesms.util.NumberUtil;
import org.thoughtcrime.securesms.util.TelephonyUtil;
import org.whispersystems.jobqueue.JobParameters;
import org.whispersystems.jobqueue.requirements.NetworkRequirement;
import org.whispersystems.libaxolotl.NoSessionException;
@ -146,7 +147,7 @@ public class MmsSendJob extends SendJob {
boolean usingMmsRadio, boolean useProxy)
throws IOException, UndeliverableMessageException, InsecureFallbackApprovalException
{
String number = ((TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE)).getLine1Number();
String number = TelephonyUtil.getManager(context).getLine1Number();
boolean upgradedSecure = false;
prepareMessageMedia(masterSecret, message, MediaConstraints.MMS_CONSTRAINTS, true);

View File

@ -20,6 +20,7 @@ import android.content.Context;
import android.net.Uri;
import android.util.Log;
import org.apache.http.Header;
import org.apache.http.HttpHost;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.HttpGetHC4;
@ -41,7 +42,9 @@ public class IncomingMmsConnection extends MmsConnection {
@Override
protected HttpUriRequest constructRequest(boolean useProxy) throws IOException {
HttpGetHC4 request = new HttpGetHC4(apn.getMmsc());
request.addHeader("Accept", "*/*, application/vnd.wap.mms-message, application/vnd.wap.sic");
for (Header header : getBaseHeaders()) {
request.addHeader(header);
}
if (useProxy) {
HttpHost proxy = new HttpHost(apn.getProxy(), apn.getPort());
request.setConfig(RequestConfig.custom().setProxy(proxy).build());

View File

@ -21,6 +21,7 @@ import android.net.ConnectivityManager;
import android.text.TextUtils;
import android.util.Log;
import org.apache.http.Header;
import org.apache.http.auth.AuthScope;
import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.client.CredentialsProvider;
@ -33,6 +34,7 @@ import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.impl.client.LaxRedirectStrategy;
import org.apache.http.impl.conn.BasicHttpClientConnectionManager;
import org.apache.http.message.BasicHeader;
import org.thoughtcrime.securesms.database.ApnDatabase;
import org.thoughtcrime.securesms.util.TelephonyUtil;
import org.thoughtcrime.securesms.util.Conversions;
@ -45,6 +47,8 @@ import java.io.IOException;
import java.io.InputStream;
import java.net.InetAddress;
import java.net.URL;
import java.util.LinkedList;
import java.util.List;
public abstract class MmsConnection {
private static final String TAG = "MmsCommunication";
@ -168,6 +172,22 @@ public abstract class MmsConnection {
protected abstract HttpUriRequest constructRequest(boolean useProxy) throws IOException;
protected List<Header> getBaseHeaders() {
final String number = TelephonyUtil.getManager(context).getLine1Number();
return new LinkedList<Header>() {{
add(new BasicHeader("Accept", "*/*, application/vnd.wap.mms-message, application/vnd.wap.sic"));
add(new BasicHeader("x-wap-profile", "http://www.google.com/oha/rdf/ua-profile-kila.xml"));
add(new BasicHeader("Content-Type", "application/vnd.wap.mms-message"));
add(new BasicHeader("x-carrier-magic", "http://magic.google.com"));
if (!TextUtils.isEmpty(number)) {
add(new BasicHeader("x-up-calling-line-id", number));
add(new BasicHeader("X-MDN", number));
}
}};
}
public static class Apn {
public static Apn EMPTY = new Apn("", "", "", "", "");

View File

@ -20,13 +20,18 @@ import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.Uri;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
import android.util.Log;
import org.apache.http.Header;
import org.apache.http.HttpHost;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.HttpPostHC4;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.entity.ByteArrayEntityHC4;
import org.thoughtcrime.securesms.util.TelephonyUtil;
import org.thoughtcrime.securesms.util.Util;
import java.io.IOException;
@ -49,9 +54,10 @@ public class OutgoingMmsConnection extends MmsConnection {
{
try {
HttpPostHC4 request = new HttpPostHC4(apn.getMmsc());
request.addHeader("Accept", "*/*, application/vnd.wap.mms-message, application/vnd.wap.sic");
request.addHeader("x-wap-profile", "http://www.google.com/oha/rdf/ua-profile-kila.xml");
request.addHeader("Content-Type", "application/vnd.wap.mms-message");
for (Header header : getBaseHeaders()) {
request.addHeader(header);
}
request.setEntity(new ByteArrayEntityHC4(mms));
if (useProxy) {
HttpHost proxy = new HttpHost(apn.getProxy(), apn.getPort());

View File

@ -9,6 +9,10 @@ import android.util.Log;
public class TelephonyUtil {
private static final String TAG = TelephonyUtil.class.getSimpleName();
public static TelephonyManager getManager(final Context context) {
return (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
}
public static String getMccMnc(final Context context) {
final TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
final int configMcc = context.getResources().getConfiguration().mcc;