• Stars
    star
    661
  • Rank 68,192 (Top 2 %)
  • Language
    Java
  • License
    Apache License 2.0
  • Created about 12 years ago
  • Updated almost 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

mirror of https://gitlab.com/guardianproject/NetCipher/

NetCipher: Secured Networking for Android

Better TLS and Tor App Integration

NetCipher is a library for Android that provides multiple means to improve network security in mobile applications. It provides best practices TLS settings using the standard Android HTTP methods, HttpURLConnection and Apache HTTP Client, provides simple Tor integration, makes it easy to configure proxies for HTTP connections and WebView instances.

More specifically this library provides:

  • Hardening of TLS protocol support and cipher suites, especially on older versions of Android (e.g. 4.4 and older)
  • Proxied Connection Support: HTTP and SOCKS proxy connection support for HTTP and HTTPS traffic through specific configuration
  • OrbotHelper: a utility class to support application integration with Orbot (Tor for Android). Check if its installed, automatically start it, etc.
  • Optional, custom certificate store based on the open Debian root CA trust store, which is built with Mozilla's CA collection.

IT MUST BE NOTED, that you can use this library without using Orbot/Tor, but obviously we think using strong TLS/SSL connections over Tor is just about the best thing in the world.

Developers can create their own CACert store using the information provided by our CACertMan project: https://github.com/guardianproject/cacert

It can be used in combination with the MemorizingTrustManager, to support user prompted override for non-validating certificates.

Proxied Connections (aka Orlib)

Once Orbot connects successfully to the Tor network, it offers two proxy servers running on localhost that applications can route their traffic through.

HTTP Proxy: localhost:8118 SOCKS 4/5 Proxy: localhost:9050

The sample project shows the basics of how to use this library to open sockets and make HTTP requests via the SOCKS and HTTP proxies available from Orbot. The standard HttpURLConnection and Apache HTTP Client libraries provide calls to setup proxying. This sample code demonstrates that. All applications using the SOCKS proxy should not resolve their DNS locally, and instead should pass the hostnames through the SOCKS proxy.

Orbot Helper

Provides simple helper to check if Orbot is installed, and whether it is currently running or not. Allows your app to request Orbot to start (user is optionally prompted whether to start or not). Finally, it can show a user prompt to install Orbot, either from Google Play, F-Droid, or via direct APK download as a last resort.

For apps with on-device servers, it can also assists in requesting a Tor Hidden Service from Orbot, and discovering the assigned .onion address.

Downloads

The binary jar, source jar, and javadoc jar are all available on jcenter(), and they all include GPG signatures. To include this library using gradle, add this line to your build.gradle:

implementation 'info.guardianproject.netcipher:netcipher:2.1.0'

Otherwise, the files can also be downloaded directly from bintray.com.

The Strong Builders

The simplest way to use NetCipher to integrate with Tor via Orbot is to use the StrongBuilder implementations. There is one of these for each of the four most popular HTTP client APIs for Android:

HTTP Client API StrongBuilder Implementation
HttpUrlConnection StrongConnectionBuilder
OkHttp3 StrongOkHttpClientBuilder
Volley StrongVolleyQueueBuilder
Apache HttpClient StrongHttpClientBuilder

(HttpClient is supported by means of the cz.msebera.android:httpclient artifact, not the discontinued HttpClient implementation in the Android SDK)

Requesting the Dependency

You will need up to three dependencies to pull in the right bits for your project.

At minimum, you will need the netcipher base artifact. The StrongBuilder classes are in 2.1.0 and higher:

implementation 'info.guardianproject.netcipher:netcipher:2.1.0'

If you are planning on using HttpURLConnection and StrongConnectionBuilder, that is all you need.

If you plan on using one of the other supported HTTP client APIs and its associated builder, you need to also request the appropriate artifact in addition to requesting the netcipher artifact:

HTTP Client API NetCipher Artifact
OkHttp3 info.guardianproject.netcipher:netcipher-okhttp3
HttpClient info.guardianproject.netcipher:netcipher-httpclient
Volley info.guardianproject.netcipher:netcipher-volley

Plus, you will need whatever artifact contains your HTTP client API:

HTTP Client API Library Module
OkHttp3 com.squareup.okhttp3:okhttp:3.4.2
HttpClient cz.msebera.android:httpclient:4.4.1.2
Volley com.android.volley:volley:1.0.0

So, for example, a project wishing to use OkHttp3 and NetCipher together would have these dependencies, in addition to any others that the project needs:

implementation 'info.guardianproject.netcipher:netcipher:2.1.0'
implementation 'info.guardianproject.netcipher:netcipher-okhttp3:2.1.0'
implementation 'com.squareup.okhttp3:okhttp:3.4.2'

Creating the OrbotHelper

OrbotHelper is a singleton that manages a lot of the asynchronous communication between your app and Orbot. It is designed to be initialized fairly early on in your app's lifecycle. One likely candidate is to have a custom Application subclass, where you override onCreate() and set up OrbotHelper.

So, you might have something like this:

public class SampleApplication extends Application {
  @Override
  public void onCreate() {
    super.onCreate();

    OrbotHelper.get(this).init();
  }
}

SampleApplication would need to be registered in your manifest via the <application> tag:

<application
    android:name=".SampleApplication"
    ...
    >

Creating a Builder

Each of the four builder classes has a public constructor, taking a Context as a parameter, that you could use.

A better choice is to call the static forMaxSecurity() method, which also takes a Context as a parameter:

StrongOkHttpClientBuilder builder=StrongOkHttpClientBuilder.forMaxSecurity(this)

(assuming that this is a Context, such as an Activity)

Note that the StrongBuilder classes will hold onto the Application context to avoid memory leaks, so you do not have to worry about that yourself.

The forMaxSecurity() method will ensure that your builder is configured with defaults that maximize security. In particular, it pre-configures the builder with withBestProxy(), described below.

Configuring the Builder

If you want, you can call a series of methods on the builder to further configure its behavior. As the name suggests, methods on these builder classes return the builder object itself, implementing a builder-style API.

The key methods are:

  • withBestProxy(), which chooses either the HTTP or the SOCKS proxy offered by Orbot, based on which is available for use by the HTTP client API you are trying to use (e.g., OkHttp3 does not support SOCKS)

  • withHttpProxy() or withSocksProxy(), if you are really sure that you want to not use withBestProxy()

  • withTrustManagers(), if you have a TrustManager[] that you wish to use to tailor the behavior of any SSL connections made through the HTTP client API

  • withWeakCiphers(), if you are running into compatibility issues with the stock selection of supported ciphers

  • withTorValidation(), if you want to confirm that not only we use Orbot, but that the communications via Orbot appear to be happening over Tor itself

Of these, withTrustManagers() is the most likely one to be used, and then only if you are implementing special SSL handling (e.g., certificate pinning).

In addition, if you are using HttpURLConnection, you need to call connectTo(), passing in the URL that you wish to connect to (either as a String or a URL). This pre-configuration of the URL is not required for the other three builders, making them much more flexible and reusable.

Requesting a Connection

To get a connection, call build() on the builder. This takes a StrongBuilder.Callback<C> parameter, where C depends on which of the four HTTP client APIs you are using:

HTTP Client API StrongBuilder Implementation Callback Type
HttpUrlConnection StrongConnectionBuilder StrongBuilder.Callback<HttpURLConnection>
OkHttp3 StrongOkHttpClientBuilder StrongBuilder.Callback<OkHttpClient>
Volley StrongVolleyQueueBuilder StrongBuilder.Callback<RequestQueue>
Apache HttpClient StrongHttpClientBuilder StrongBuilder.Callback<HttpClient>

Your Callback needs to implement four methods.

The big one is void onConnected(C client), where you are handed an instance of your designated HTTP API connection (e.g., an OkHttpClient for OkHttp3). At this point, the client object is set up to communicate through Tor by means of Orbot, and you are free to start using it for your HTTP requests. However, do not make any assumptions about the thread on which onConnected() is called; please do your HTTP I/O on your own background thread.

You also need to implement:

  • void onConnectionException(Exception e), which is called if we ran into some problem, so you can report it to the user, log it to your crash reporting server, etc.

  • void onTimeout(), which is called if we were unable to talk to Orbot within 30 seconds

  • void onInvalid(), which is called if you requested that we validate the Tor connection and that test failed

Note that build() itself may throw an Exception as well, which you will need to address. Otherwise, build() is asynchronous; you will find out the results via your Callback. Note that the Callback methods may be invoked on any thread β€” do not assume that the methods will be called on any particular thread.

For example, assuming that this implements StrongBuilder.Callback<OkHttpClient>, you could have code like:

private void doThatHttpThing() {
  try {
    StrongOkHttpClientBuilder
      .forMaxSecurity(this)
      .build(this);
  }
  catch (Exception e) {
    // do something useful
  }
}

@Override
public void onConnected(final OkHttpClient client) {
  // use the OkHttpClient on a background thread
}

@Override
public void onConnectionException(Exception e) {
  // do something useful
}

@Override
public void onTimeout() {
  // do something useful
}

WebView

NetCipher also comes with a helper library which makes it trivial to proxy settings for WebViews. It is also packaged with maven:

dependencies {

    implementation 'info.guardianproject.netcipher:netcipher-webkit:2.0.0-alpha1'

}

On Android 5.0 (API level 21) or newer the simplest way to use WebkitProxy is by initializing it on App start. WebView proxying works globally.

class App extends Application {

    public void onCreate() {
        try {
            WebkitProxy.setProxy(SampleApplication.class.getName(), this.getApplicationContext(), null, "localhost", 8118);
        } catch (Exception e) {
            Log.e(TAG, "Could not start WebkitProxy", e);
        }
    }
}

If you want to support older Android versions you'll also need to pass a reference of your WebView when calling WebkitProxy.setProxy().

Sample Apps

This project contains a sample app for each of the four HTTP client APIs:

HTTP Client API Sample App
HttpUrlConnection sample-hurl
OkHttp3 sample-okhttp3
Volley sample-volley
Apache HttpClient sample-httpclient
WebView sample-webkit

Each of the four apps does the same thing: request the latest Stack Overflow android questions and show them in a list. What differs between the samples is which dependency and HTTP client API that they use.

Get help

Do not hesitate to contact us with any questions. The best place to start is our community forums and https://devsq.net. To send a direct message, email [email protected]

We want your feedback! Please report any problems, bugs or feature requests to our issue tracker:

More Repositories

1

haven

Haven is for people who need a way to protect their personal spaces and possessions without compromising their own privacy, through an Android app and on-device sensors
Java
6,626
star
2

orbot

The Github home of Orbot: Tor on Android (Also available on gitlab!)
Java
2,121
star
3

ChatSecureAndroid

This project has ended, but ChatSecure iOS continues. For Android, please use Conversations or Zom instead
Java
1,074
star
4

android-ffmpeg

a system for building custom ffmpeg binaries for Android
Shell
966
star
5

libsqlfs

a library that implements a POSIX style filesystem on top of an SQLite database
C
560
star
6

android-ffmpeg-java

Android Java wrapper around ffmpeg command line binary
Java
553
star
7

ObscuraCam

Photo and Video Filtering App for Privacy
Java
300
star
8

gnupg-for-android

A port of gnupg to Android (UNMAINTAINED!)
Java
297
star
9

lildebi

UNMAINTAINED please adopt! we can no longer maintain this
Java
228
star
10

tor-android

Tor binary and library for Android
Java
211
star
11

ripple

A "panic button" app for triggering a "ripple effect" across apps that are set up to respond to panic events
Java
209
star
12

proofmode-android

THIS REPOSITORY IS MIRROR OF: https://gitlab.com/guardianproject/proofmode/proofmode-android
Java
198
star
13

orbot-apple

Orbot VPN app for iOS
Swift
197
star
14

PixelKnot

Image stego app using the F5 algorithm
Java
188
star
15

IOCipher

make non-root mountable encrypted disk shares
Java
139
star
16

OSTel

Open Secure Telephony platform (no longer maintained)
JavaScript
117
star
17

notecipher

a simple notepad with all stored encrypted using SQLCipher and Cacheword
Java
104
star
18

Orweb

We are EOL this project. Please use Lightning Browser or wait for Orfox instead
Java
91
star
19

LUKS

no longer maintained, check the forks for maintained versions
Shell
91
star
20

OrbotVPN

THIS IS A DEPRECATED PROJECT AND CLOSED! SEE WEBSITE LINK FOR LATEST ORBOT WITH VPN SUPPORT!
Java
85
star
21

CameraV

CameraV: InformaCam Default Android App
Java
85
star
22

keysync

convert OTR keystores into other keystore formats for moving keys into a new IM app
Python
85
star
23

fdroid-repo

a mirror of https://guardianproject.info/fdroid, usable in F-Droid.
CSS
82
star
24

cacheword

a password caching and management service for Android
Java
81
star
25

TrustedIntents

library for flexible trusted interactions between Android apps
Java
77
star
26

cacert

A slightly more vetted version of the Android CACert keystore
Java
69
star
27

LocationPrivacy

a transparent filter for all of the various ways of sharing location
Java
67
star
28

InformaCore

InformaCam Android Core Service Library
Java
46
star
29

PanicKit

a framework for providing trusted connections between panic button apps and other apps that should be triggered by them
Java
46
star
30

checkey

moved to https://gitlab.com/guardianproject/checkey
Java
43
star
31

ProxyMob

THIS PROJECT IS DEPRECATED. PLEASE SEE ORFOX (TOR BROWSER FOR ANDROID)
JavaScript
39
star
32

open-mobile-developers-guide

Our effort to create a general, broad developers guide for open-source mobile security and our SDKs
Shell
38
star
33

GuardianProjectPublic

Guardian Project's Public SparkleShare
Java
34
star
34

pluto

Pluggable Library (for) Using Traffic Obfuscation: DEPRECATED - SEE LINK FOR NEW PROJECT
Java
29
star
35

AndroidPluggableTransports

Android Pluggable Transports (aka PLUTO2)
Java
28
star
36

OtRChat

UPDATE 2011/2/15: WE ARE NOT USING THIS REPO ANYMORE. FIND THE NEW REPO AT THE LINK BELOW.
Java
28
star
37

SSCVideoProto

This project has been merged into ObscuraCam v2 which you can find at the link below
Java
28
star
38

jtorctl

deprecated fork of Java Tor Control Library
Java
28
star
39

OpenCircle

Open-source Circle of 6 with improved security and privacy features. PLEASE NOTE: For the new Circulo app please visit: https://gitlab.com/circuloapp/circulo-android
Java
28
star
40

linphone-ios-secure

A build of Linphone with all security features enabled (ZRTP, TLS)
C
26
star
41

OrfoxGeckoView

THIS PROJECT IS NOW DEPRECATED IN FAVOR OF OUR NEW TOR-BROWSER BASED REPO
Java
26
star
42

wind

Wind general project repo
24
star
43

Orlib

THIS LIBRARY IS DEPRECATED. PLEASE USE NETCIPHER.
Java
23
star
44

fdroid-repo-tools

scripts for maintaining our F-Droid repos
Shell
19
star
45

viento

Viento or "Wind": Off-Grid and Constrained Computing Optimization Effort
15
star
46

OrbotTalk

Experimental Tor-based P2P Messaging and File Exchange
Java
15
star
47

securereader

Java
13
star
48

network-utils

setup to build a collection of command line network utils for Android
Shell
13
star
49

securereaderlibrary

Core Engine for the Guardian Project Secure Reader platform
Java
13
star
50

securereader_ios

Secure Tor-enabled RSS reader for iOS devices.
Objective-C
13
star
51

CamCipher

Camera Cipher Library for encrypted photo and video capture based on IOCipher
Java
12
star
52

info

our website (mirror of https://gitlab.com/guardianproject/info)
CSS
12
star
53

smartcard-apk-signing

scratchpad for working out a full paranoid Android APK/Jar signing procedure
Shell
12
star
54

binary_transparency_log

A binary transparency log of all Android apps that we release.
10
star
55

courier

Courier, a secure, private news reader
Java
10
star
56

wind-repo

mirror of https://gitlab.com/guardianproject/wind-repo
Python
9
star
57

torservices

mirror of https://gitlab.com/guardianproject/torservices
Java
9
star
58

poe

POE Tor Onboarding Library
Swift
8
star
59

haven-nightly

Nightly builds for Haven app.
8
star
60

luksunlock

Minimal UI for LUKS encryption on the Wildfire
C
8
star
61

IOCipherExample

example file browser app built with IOCipher
Java
8
star
62

guardianproject.github.com

8
star
63

gpmaven

Maven Repository for Gradle-based projects using Guardian Project CipherKit Libraries
8
star
64

orbotkit

Orbot client library for iOS
Swift
7
star
65

OReport

secure citizen journalism
Java
7
star
66

pgpbenchmark

Android app for comparing performance of different OpenPGP implementations.
Java
7
star
67

Activate

Guardian Project Android Installer
Java
7
star
68

tormobiledev

Tor Mobile Developer Guide
7
star
69

cleanroom

Utilities for using TAILS as a distro for managing offline keys
6
star
70

powerup

tool for activating, installing, configuring new apps and capabilities on Android phones
6
star
71

ostn

Open Secure Telephony Network
6
star
72

GuardianProjectPressKit

Guardian Project Press Kit
5
star
73

android-support-library

A github clone of https://android.googlesource.com/platform/frameworks/support/
Java
5
star
74

pinentry

password entry system for GnuPG
C
5
star
75

InformaRepo

InformaCam Storage, Analytics, Dashboard system
5
star
76

FakePanicResponder

an example app to demonstrate receiving triggers from the panic framework
Java
4
star
77

tutorial-gibberbot

An interactive tutorial on how to chat securely on Android mobile with Gchat, Facebook, XMPP & more via OTR encryption using the Guardian Project app, Gibberbot.
4
star
78

StoryMakerLessons

StoryMaker Lesson Curriculum
JavaScript
4
star
79

android-database-sqlcipher

android-database-sqlcipher has moved to the SQLCipher org repo. You can update your local clone to point to the new remote/------------------------------------------------------> git remote set-url origin [email protected]:sqlcipher/android-database-sqlcipher.git
4
star
80

gnupg-for-android-tests

tests for the GnuPrivacyGuard suite for Android
Java
3
star
81

fastlane-hugo-theme

A Hugo theme for generating localized sites based on Fastlane metadata for Android apps.
HTML
3
star
82

fdroid-metadata

collection of our apps that are built with fdroidserver
CSS
3
star
83

ChatSecurePluginOpenEmoji

"Phantom" Open Emoji Plugin for ChatSecure
Java
3
star
84

Adios

The fastest way to remove all sensitive, personal, private data on your Android device
3
star
85

jitsi-monitor

mirror of https://gitlab.com/guardianproject/jitsi-monitor
Python
3
star
86

FakePanicButton

example app for the Panic Framework
Java
2
star
87

JustPayPhone

Java
2
star
88

tutorial-portal

What do you want to do on your Android today?
JavaScript
2
star
89

openwrtfilternet

OpenWRT-based simple "FilterNet" configuration
2
star
90

securereaderlibrary_ios

2
star
91

IOCipherServer

https / webdav server for accessing IOCipher shares
Java
2
star
92

informacam-guide

Trainer and end-user guide to using InformaCam and CameraV app
HTML
2
star
93

ecvrs-guides

Our work on best practices for security electronic civil registration and vital statistics services
2
star
94

f-droid.org_binary_transparency_log

a binary transparency log of https://f-droid.org
2
star
95

.github

default community health files
2
star
96

IOCipherTests

tests for the IOCipher library
Java
2
star
97

nptornews

NPToR News: an OnionKit-enabled version of the NPR News app. Sample project to demonstrate media stream proxying.
Java
2
star
98

ODKFormParser

quick-and-dirty android library for OpenDataKit/JavaRosa forms. Only supports input text and selections so far, but it's a work in progress
Java
1
star
99

milton-iocipher

Repository for core milton modules
Java
1
star
100

InformaCam-Server-DEPRECATED

THIS REPO IS NOW DEPRECATED DO NOT USE
JavaScript
1
star