sanidhya09 sanidhya09 - 3 months ago 35
Android Question

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


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.


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`.

    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;