So, I'm trying to get my app to work with .onion domains, but all I get is a 405 error for a response. I have tried everything, my code seems to work when I try http://check.torproject.org
it says that its connected.
https://github.com/guardianproject/NetCipher
My gradle contains these dependencies.
compile 'info.guardianproject.netcipher:netcipher:2.0.0-alpha1'
compile 'info.guardianproject.netcipher:netcipher-okhttp3:2.0.0-alpha1'
compile 'com.squareup.okhttp3:okhttp:3.4.2'
compile 'org.apache.httpcomponents:httpcore:4.4.1'
I'm running this code to start orbot and connect the app to it.
OrbotHelper.get(activity).statusTimeout(60000).addStatusCallback(new StatusCallback(){
@Override
public void onEnabled(Intent intent){
new StrongBuild();
}
@Override
public void onStarting(){
}
@Override
public void onStopping(){
}
@Override
public void onDisabled(){
}
@Override
public void onStatusTimeout(){
}
@Override
public void onNotYetInstalled(){
}
}).init();
This is the StrongBuild file.
import android.util.Log;
import javax.net.ssl.TrustManager;
import info.guardianproject.netcipher.client.StrongBuilder;
import info.guardianproject.netcipher.client.StrongOkHttpClientBuilder;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
public class StrongBuild implements StrongBuilder.Callback<OkHttpClient> {
public StrongBuild(){
Log.e("info", "Starting Strong Builder");
try{
StrongOkHttpClientBuilder.
forMaxSecurity(activity).
//withTrustManagers(new TrustManager[] { new MyTrustManager() }).
withTorValidation().
withBestProxy().
build(StrongBuild.this);
}catch(Exception e){
e.printStackTrace();
Log.e("info", "ERROR");
}
}
@Override
public void onConnected(final OkHttpClient okHttpClient){
Log.e("info" , "CONNECTED Strong Builder");
new Thread(new Runnable(){
@Override
public void run(){
try{
Request request = new Request.Builder().url("http://******.onion/").build();
Response response = okHttpClient.newCall(request).execute();
Log.e("info", "RESPONSE: "+response.toString());
Log.e("info", response.body().string());
}catch(Exception e){
e.printStackTrace();
Log.e("info", "ERROR - ATTEMPTING CONNECTION TO ONION DOMAIN");
}
}
}).start();
}
@Override
public void onConnectionException(Exception e){
Log.e("info" , "Exception");
}
@Override
public void onTimeout(){
Log.e("info" , "Timeout");
}
@Override
public void onInvalid(){
Log.e("info" , "Invalid");
}
}
Stack Trace:
RESPONSE: Response{protocol=http/1.0, code=405, message=Method Not Allowed, url=http://********.onion/}
All help is appreciated!
Alright, I figured out the issue, I'll post the answer for anyone else wondering!
Change this:
StrongOkHttpClientBuilder.
forMaxSecurity(activity).
//withTrustManagers(new TrustManager[] { new MyTrustManager() }).
withTorValidation().
withBestProxy().
build(StrongBuild.this);
To this:
StrongOkHttpClientBuilder.
forMaxSecurity(activity).
withTrustManagers(new TrustManager[] { new MyTrustManager() }).
withTorValidation().
withSocksProxy().
withHttpProxy().
build(StrongBuild.this);