Skip to content
This repository has been archived by the owner on Sep 2, 2021. It is now read-only.

Commit

Permalink
remove shadowsocks, move to port forwarding for advanced networking
Browse files Browse the repository at this point in the history
  • Loading branch information
iamironrabbit committed Jun 21, 2018
1 parent 3a9b004 commit ed7606f
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 18 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def getVersionName = { ->
}
return stdout.toString().trim()
}

1

configurations {
all*.exclude group: 'xpp3', module: 'xpp3'
Expand All @@ -22,7 +22,7 @@ android {

defaultConfig {
applicationId 'im.zom.messenger'
versionCode 1560014
versionCode 1560015
versionName getVersionName()
archivesBaseName = "Zom-$versionName"
minSdkVersion project.ext.minSdkVersion
Expand Down
Binary file removed app/src/main/assets/transports/ss
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ public Omemo (XMPPTCPConnection connection, BareJid user) {

}

public void purgeDeviceKeys ()
{
mOmemoStore.purgeOwnDeviceKeys(mOmemoManager);
}

private OmemoManager initOMemoManager(XMPPTCPConnection conn, BareJid altUser) {
BareJid user;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1717,10 +1717,8 @@ public void setProxy(String type, String host, int port) {
if (type == null) {
mProxyInfo = null;
} else {

ProxyInfo.ProxyType pType = ProxyInfo.ProxyType.valueOf(type);
mProxyInfo = new ProxyInfo(pType, host, port, null, null);

}
}

Expand Down Expand Up @@ -2002,8 +2000,73 @@ private AbstractXMPPConnection initConnection(Imps.ProviderSettings.QueryMap pro
}
else if (doAdvancedNetworking)
{
RemoteImService.activateAdvancedNetworking(mContext);
setProxy("SOCKS5","127.0.0.1",31059);
/**
//if we don't use DNS lookup, see if we have info from the server json
Server serverConfig = Server.getServer(mContext,domain);
if (serverConfig != null)
{
if (serverConfig.ip != null)
server = serverConfig.ip;
else
server = serverConfig.server;
serverPort = serverConfig.port;
mConfig.setHost(server);
mConfig.setPort(serverPort);
try {
String[] addressParts = server.split("\\.");
if (Integer.parseInt(addressParts[0]) != -1) {
byte[] parts = new byte[addressParts.length];
for (int i = 0; i < 4; i++)
parts[i] = (byte) Integer.parseInt(addressParts[i]);
byte[] ipAddr = new byte[]{parts[0], parts[1], parts[2], parts[3]};
InetAddress addr = InetAddress.getByAddress(ipAddr);
mConfig.setHostAddress(addr);
} else {
mConfig.setHostAddress(InetAddress.getByName(server));
}
} catch (Exception e) {
debug(TAG, "error parsing server as IP address; using as hostname instead");
mConfig.setHostAddress(InetAddress.getByName(server));
}
}**/

// RemoteImService.activateAdvancedNetworking(mContext);
// setProxy(AdvancedNetworking.DEFAULT_PROXY_TYPE,AdvancedNetworking.DEFAULT_SERVER,AdvancedNetworking.DEFAULT_PORT);

server = AdvancedNetworking.DEFAULT_SERVER;
serverPort = AdvancedNetworking.DEFAULT_PORT;
mConfig.setHost(server);

mConfig.setPort(serverPort);
try {

String[] addressParts = server.split("\\.");
if (Integer.parseInt(addressParts[0]) != -1) {
byte[] parts = new byte[addressParts.length];
for (int i = 0; i < 4; i++)
parts[i] = (byte) Integer.parseInt(addressParts[i]);

byte[] ipAddr = new byte[]{parts[0], parts[1], parts[2], parts[3]};
InetAddress addr = InetAddress.getByAddress(ipAddr);
mConfig.setHostAddress(addr);

} else {
mConfig.setHostAddress(InetAddress.getByName(server));
}
} catch (Exception e) {
debug(TAG, "error parsing server as IP address; using as hostname instead");
mConfig.setHostAddress(InetAddress.getByName(server));

}
}
else {
mProxyInfo = null;
Expand Down Expand Up @@ -2106,7 +2169,6 @@ else if (domain.contains("google.com")||domain.contains("gmail.com")) //if not g

while (true) {
try {

if (Build.VERSION.SDK_INT >= 20) {

sslContext.getDefaultSSLParameters().setCipherSuites(XMPPCertPins.SSL_IDEAL_CIPHER_SUITES_API_20);
Expand Down Expand Up @@ -2163,7 +2225,7 @@ else if (domain.contains("google.com")||domain.contains("gmail.com")) //if not g
mConfig.setCustomSSLContext(sslContext);
mConfig.setSecurityMode(ConnectionConfiguration.SecurityMode.required);
mConfig.setHostnameVerifier(
mMemTrust.wrapHostnameVerifier(new org.apache.http.conn.ssl.StrictHostnameVerifier()));
mMemTrust.wrapHostnameVerifier(new org.apache.http.conn.ssl.StrictHostnameVerifier()));

mConfig.setSendPresence(true);

Expand Down Expand Up @@ -2820,6 +2882,7 @@ public void sendMessageAsync(ChatSession session, final Message message) {

org.jivesoftware.smack.packet.Message msgEncrypted
= getOmemo().getManager().encrypt(muc, msgXmpp.getBody());

msgEncrypted.addExtension(new DeliveryReceiptRequest());
msgEncrypted.setStanzaId(msgXmpp.getStanzaId());
String deliveryReceiptId = DeliveryReceiptRequest.addTo(msgEncrypted);
Expand Down Expand Up @@ -5125,7 +5188,7 @@ private String uploadFile(long fileSize, InputStream fis, Slot slot, UploadProgr

if (!isReachable(putUrl.getHost(),putUrl.getPort()))
useAdvancedNetworking = true;

//urlconnection socks proxying only works on SDK 23+
if (!TextUtils.isEmpty(Preferences.getProxyServerHost()))
{
Expand All @@ -5134,8 +5197,8 @@ private String uploadFile(long fileSize, InputStream fis, Slot slot, UploadProgr
}
else if (useAdvancedNetworking) {
//setProxy("SOCKS5","127.0.0.1",31059);
java.net.Proxy proxy =new java.net.Proxy(java.net.Proxy.Type.SOCKS,new InetSocketAddress("127.0.0.1",31059));
urlConnection = (HttpURLConnection) putUrl.openConnection(proxy);
// java.net.Proxy proxy =new java.net.Proxy(java.net.Proxy.Type.SOCKS,new InetSocketAddress(AdvancedNetworking.DEFAULT_SERVER,AdvancedNetworking.DEFAULT_PORT));
// urlConnection = (HttpURLConnection) putUrl.openConnection(proxy);
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,25 @@ public class AdvancedNetworking {
private File mFileTransport = null;
private Thread mTransportThread = null;

public void installTransport (Context context, String assetKey)
public final static String TRANSPORT_SS2 = "ss2";

public final static String DEFAULT_PROXY_TYPE = "SOCKS5";
public final static String DEFAULT_SERVER = "172.104.48.102";
public final static int DEFAULT_PORT = 80;

public boolean installTransport (Context context, String assetKey)
{
BinaryInstaller bi = new BinaryInstaller(context,context.getFilesDir());
try {
mFileTransport = bi.installResource("transports", assetKey, false);
mFileTransport = bi.installResource("transports", assetKey, true);
return mFileTransport.exists();
}
catch (Exception ioe)
{
debug("Couldn't install transport: " + ioe);
}

return false;
}

public void startTransport ()
Expand Down Expand Up @@ -58,22 +67,32 @@ private void startTransportSync ()
{

String serverAddress = "172.104.48.102";
String serverPort = "443";
String serverPort = "80";
String serverPassword = "zomzom123";
String serverCipher = "aes-128-cfb";
String serverCipher = "AEAD_CHACHA20_POLY1305";//"aes-128-cfb";
String localAddress = "127.0.0.1";
String localPort = "31059";

StringBuffer cmd = new StringBuffer();
cmd.append(mFileTransport.getCanonicalPath()).append(' ');

/**
cmd.append("-s ").append(serverAddress).append(' ');
cmd.append("-p ").append(serverPort).append(' ');
cmd.append("-k ").append(serverPassword).append(' ');
cmd.append("-m ").append(serverCipher).append(' ');
cmd.append("-b ").append(localAddress).append(' ');
cmd.append("-l ").append(localPort).append(' ');
**/

cmd.append(" -c ").append("'ss://").append(serverCipher).append(":");
cmd.append(serverPassword).append("@");
cmd.append(serverAddress).append(":").append(serverPort).append("'");
cmd.append(" -socks :").append(localPort);

//disable for now
// exec(cmd.toString(), false);

exec(cmd.toString(), false);
}
}
catch (Exception ioe)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@
import info.guardianproject.cacheword.CacheWordHandler;
import info.guardianproject.cacheword.ICacheWordSubscriber;

import static org.awesomeapp.messenger.service.AdvancedNetworking.TRANSPORT_SS2;


public class RemoteImService extends Service implements ImService, ICacheWordSubscriber {

Expand Down Expand Up @@ -623,7 +625,7 @@ public static void installTransports (Context context)
}

aNetworking = new AdvancedNetworking();
aNetworking.installTransport(context,"ss");
aNetworking.installTransport(context,AdvancedNetworking.TRANSPORT_SS2);
aNetworking.startTransport();

}
Expand Down Expand Up @@ -807,7 +809,7 @@ public static void activateAdvancedNetworking (Context context)
else
{
aNetworking = new AdvancedNetworking();
aNetworking.installTransport(context,"ss");
aNetworking.installTransport(context,TRANSPORT_SS2);
}

aNetworking.startTransport();
Expand Down

0 comments on commit ed7606f

Please sign in to comment.