Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use Netcipher with Retrofit in android?

Netcipher is an Android Library Project that provides multiple means to improve network security in mobile applications. The “Onion” name refers to not only the Onion Routing concept used by Tor (which provides anonymity and resistance to traffic surveillance), but also the idea of multiple layers of security that any application should utilize.

More specifically this library provides:

1. Stronger Sockets: Through support for the right cipher suites, pinning and more, we ensure your encrypted connections are as strong as possible.
2. Proxied Connection Support: HTTP and SOCKS proxy connection support for HTTP and HTTP/S traffic through specific configuration of the Apache HTTPClient library

https://guardianproject.info/code/netcipher/

like image 457
Sanidhya Kumar Avatar asked Jan 10 '23 02:01

Sanidhya Kumar


1 Answers

You need to implement your own Client that will execute Retrofit request on Netcipher http client.

  1. Translate Request to appropriate Netcipher request (copy http method, headers, body)
  2. Execute the translated request on Netcipher http client
  3. Obtain response and translated it to retrofit Response (copy http status code, response, headers)
  4. Return response to be deserialized to type.

Pass your Client to RestAdapter.Builder.

Done.

public class NetcipherClient implements Client{
  private Context mContext;
  public NetcipherClient(Context context){
      mContext = context;
      //As far as I could see from the sample, Netcipher seems to be dependant on application `Context`.

  }
  @Override
    public retrofit.client.Response execute(retrofit.client.Request request) throws IOException {
        //Set up configuration for Netcipher (proxy, timeout etc)
        // Translate Request to Netcipher request 
        // Execute and obtain the response
        // Build Response from response
        return response;
    }


}
like image 105
Nikola Despotoski Avatar answered Jan 31 '23 04:01

Nikola Despotoski