Android Orbot malformed reply from SOCKS server - android

I am trying to enable TOR support on my own XMPP app in android. I am using orbot as TOR proxy and I have the following code to connect app socket:
socket = new Socket(new Proxy(Proxy.Type.SOCKS, new InetSocketAddress("127.0.0.1", 9050)));
socket.connect(addr, Config.SOCKET_TIMEOUT * 1000);
but I am getting Malformed reply from SOCKS server even that my Orbot is up and running. I believe that this error is thrown when app cant access proxy server or mentioned server is not SOCKS proxy.
I have also tried to use jsocks:
Socks5Proxy sProxy = new Socks5Proxy("127.0.0.1", 9050);
sProxy.resolveAddrLocally(false);
String host = account.getServer().toString();
int port = 5222;
System.out.println(host + ":" + port);
try {
socket = new SocksSocket(sProxy, host, port);
}catch(SocksException sock_ex){
System.err.println("SocksException:"+sock_ex);
}
System.out.println("here we are");
where host is "jabbim.com"
But I never get to "here we are" println so it looks like my app hangs somewhere on creating SocksSocket but I am not getting any errors either. When I debug it it hangs on impl.getInputStream somewhere in jsocks (PlainSocketImpl I believe)
Any idea how to fix this?
Thanks in forward

I solved this using
compile "org.igniterealtime.smack:smack-android-extensions:4.1.4"
compile "org.igniterealtime.smack:smack-tcp:4.1.4"
and then connecting using this code:
final Random rndForTorCircuits = new Random();
String user = rndForTorCircuits.nextInt(100000) + "";
String pass = rndForTorCircuits.nextInt(100000) + "";
ProxyInfo proxyInfo = new ProxyInfo(ProxyInfo.ProxyType.SOCKS5, "127.0.0.1", 9050, user, pass);
socket = proxyInfo.getSocketFactory().createSocket(addr.getHostName(), addr.getPort());
by using this you get socket that is already connected to proxy.

Related

Register pjsip account using Tls setting in pjsua

I am using Pjusa for Voip, I have done communication through UDP and TCP but could not communitcate through TLS setting`
TlsConfig tlsConfig = new TlsConfig();
File cacheDir = new File(ctx.getCacheDir(), "ca");
InputStream input = ctx.getResources().openRawResource(R.raw.ca);
tlsConfig.setCaListFile(cacheDir.getPath());
input = ctx.getResources().openRawResource(R.raw.secure);
cacheDir = new File(ctx.getCacheDir(), "secure");
tlsConfig.setCertFile(cacheDir.getPath());
tlsConfig.setMethod(pjsip_ssl_method.PJSIP_SSLV23_METHOD);`
I have attached CaListFile and setCertFile files like that method and that setting working but When I establish a call then I found error like that
tlsc0x9e7db014 TLS connect() error: Connection refused [code=120111]
tsx0x9d945864 Failed to send Request msg INVITE/cseq=25416 (tdta0x9d991000)! err=120111 (Connection refused)
In IOS I found some more setting for TLS , but could not implement in PJSUA
any one can help me out how to use that piece of code in android in PJSUA library
pj_sockaddr_in remote;
pjsip_transport *transport;
remote.sin_family = pj_AF_INET();
remote.sin_zero_len = 0;
remote.sin_addr.s_addr = pj_inet_addr(#"xxx.xx.xx.xx").s_addr;
remote.sin_addr.s_addr = INADDR_ANY;
bzero(&(remote.sin_zero),sizeof(remote.sin_zero));
app_config->cfg.use_srtp = PJMEDIA_SRTP_MANDATORY;
app_config->cfg.srtp_secure_signaling = 1;
thanks in advance
TlsConfig tlsConfig = new TlsConfig();
tlsConfig.setCertFile(certFile);
sipTpConfig.setTlsConfig(tlsConfig);
tlsConfig.setCaListFile(caListFile);
I did R&D from web searching and reading document of SIP and PJSIP, then I find the sluotion for accountConfig for PJMEDIA_SRTP_MANDATORY and setSrtpSecureSignaling(1) by that way provided below
accCfg.getMediaConfig().setSrtpUse(pjmedia_srtp_use.PJMEDIA_SRTP_MANDATORY);
accCfg.getMediaConfig().setSrtpSecureSignaling(1);
Hence TLS working with CAListFile and CertificateFile

Android / Socket.io client - How to send a cookie while handshaking with the server?

I'm trying (unsuccessfully) to connect with a socket.io server, but I keep getting the same errors :
io.socket.SocketIOException: Error while handshaking caused by java.net.ConnectException: failed to connect to my.domain.name.com (port 8080) after 10000ms: isConnected failed: ECONNREFUSED (Connection refused).
I just discovered that I'm supposed to send a cookie with the following values when handshaking : the domain, the path, the name and the value. After trying several potential ways to do it (based on this and this), I ended up with that piece of code, but it still not working :
String cookieString = "domain=" + "my.domain.name.com" + ";path=" + "/" + ";name=" + "auth" + ";value=" + "XXXXXtokenXXXXX";
CookieManager.getInstance().setCookie("http://my.domain.name.com:8080/", cookieString);
String header = CookieManager.getInstance().getCookie("my.domain.name.com:8080/");
final SocketIO socket = new SocketIO("my.domain.name.com:8080/");
socket.addHeader("Cookie", header);
socket.connect(new IOCallback()
{
...
}
CookieManager.getInstance().getCookie(...) keeps returning null and the connection is still failing.
Could anybody help me add a cookie to the header please?
And for the record, I don't know what it could change, but I'm using this lib : https://github.com/Gottox/socket.io-java-client
Thanks in advance for your help !
Mathieu
Ok, just in case anybody would need the solution, I finally fixed this.
It's actually pretty simple :
String cookie = "domain=\"http://my.domain.name.com:80\";path=\"/\";name=\"auth\";value=\"XXXXtokenXXXX\"";
socket = new SocketIO("http://my.domain.name.com:80/");
socket.addHeader("Cookie", cookie);
socket.connect(new IOCallback()
{
...
}
So you just have to create a string of the form "key1=value1;key2=value2..." and to add it as a header to the socket with the method addHeader("Cookie", youCookieString);.
And for the record, I kept getting the error ECONNREFUSED because I was trying to connect on the WRONG PORT (8080 instead of 80)...

UDP from AndroidEmulator (--Genymotion--) to localhost Server(10.0.2.2) does not work?

I simply try to send and receive data between MonodroidApp(AndroidEmulator) and a localDevServer. I understand localhost is specially mapped to "10.0.2.2" on AndroidEmulator, so I did the following, but the app does not respond.
System.Text.Encoding enc = System.Text.Encoding.UTF8;
string sendMsg = "testtest";
byte[] sendBytes = enc.GetBytes(sendMsg);
int localPort = 39000;
var udp = new System.Net.Sockets.UdpClient(localPort);
//send data
string remoteHost = "10.0.2.2";//"127.0.0.1";
int remotePort = 15000;
udp.Send(sendBytes, sendBytes.Length,
remoteHost, remotePort);
//receive data
System.Net.IPEndPoint remoteEP = null;
byte[] rcvBytes = udp.Receive(ref remoteEP);
string rcvMsg = enc.GetString(rcvBytes);
Console.WriteLine("received data:{0}", rcvMsg);
Console.WriteLine("sender address:{0}/port:{1}",
remoteEP.Address, remoteEP.Port);
This code is verified to work with Mono for Mac and the localDevServer with the pointer: remoteHost = "127.0.0.1"
so,
remoteHost = "10.0.2.2" pattern does not work.
What do I miss? Anyone, any thought?
Thank you.
Ok, one important thing I forgot to mention is
The emulator I use for android is Genymotion.
So, it appears to be that "10.0.2.2" does not point localhost as default.
http://blog.zeezonline.com/2013/11/access-localhost-from-genymotion/
In my environment(OSX 10.9) with Genymotion,the localhost address from the emulator is
"10.0.3.2", and the code works.

Create websocket server using nodejs that can be used to communicate with Android App

I have created a websocket server from my localhost machine that can be used to communicate with an android app.
The server is written in Node.js and hosted on my machine
var HOST = "192.168.0.15";
var PORT = 6969;
var Sock = net.Socket();
net.createServer(function(sock) {
Sock = sock;
// We have a connection - a socket object is assigned to the connection automatically
console.log('CONNECTED: ' + sock.remoteAddress +':'+ sock.remotePort);
// Add a 'data' event handler to this instance of socket
sock.on('data', function(data) {
console.log('DATA ' + sock.remoteAddress + ': ' + data);
// Write the data back to the socket, the client will receive it as data from the server
var jsonStr = JSON.stringify(data);
sock.write(jsonStr);
var buffer = "";
});
// Add a 'close' event handler to this instance of socket
sock.on('close', function(data) {
console.log('CLOSED: ' + sock.remoteAddress +' '+ sock.remotePort);
});
}).listen(PORT, HOST);
io.sockets.on('connection', function(socket){
socket.on('send message', function(data){
Sock.emit("data", data);
});
});
And my Android app uses Java Websocket with
socket = new Socket("192.168.0.15", 6969);
commsThread = new CommsThread(socket);
commsThread.start();
My Android device used to test my app and my server runs in the same network so they work fine.
However, when I deploy it in Heroku, it gives me an error.
NOTE: I have tried changing the HOST address and PORT address but to no avail.
I was told that Heroku doesn't support TCP socket server.
I am not sure if the example above is an TCP socket server.
If not, why are some of the alternatives I can use.
Cheers,
Dennis
Why don't you use socket.io-java-client along with the socket.io module for Node.js?
Did you enable websockets in Heroku?
$ heroku labs:enable websockets

Connexion to ftp server with android

i'm newbie on android,
I'm trying to upload file from sdcard to ftp server using android, the code seems to be correct. While debbuging it says that my connet and upload functions to the server can not access the classes given by org.appache.commons.net (no source found in those classes), knowing that i have this org.appache.commons.net jar in the libs foldre, the project build path and the user libraries.
Should i use another librarie or, is there any other work to do ?
The code
public boolean ftpConnect(String host, String username,String password, int port){
try {
mFTPClient = new FTPClient();
mFTPClient.connect(host, port);
mFTPClient.enterLocalPassiveMode();
if (FTPReply.isPositiveCompletion(mFTPClient.getReplyCode())) {
// login using username & password
boolean status = mFTPClient.login(username, password);
Log.w("into the ftpUpload","!!");
mFTPClient.setFileType(FTP.BINARY_FILE_TYPE);
mFTPClient.enterLocalPassiveMode();
Log.w("into the ftpUpload","!!");
return status;
}
} catch(Exception e) {
Log.d(TAG, "Error: could not connect to host " + host );
}
return false;}
call this methode in another class using
FtpClient FTP = new FtpClient();
FTP.ftpConnect("..*.", "", "*", 21);
I'm doing it juste like several posts propose it, concerning the lib i added the org.apache.commons.net jar to the lib file and to the java build path..
The exception is given exactly here: mFTPClient.connect(host, port); (btw there are no logs).. Does anybody have an idea what can be the problem with that? I tried lot of codes that works for others but it fail to connect to the ftp server every time. Thanks for your responses.

Categories

Resources