public class NetCipher
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static java.net.Proxy |
ORBOT_HTTP_PROXY |
static java.net.Proxy |
ORBOT_SOCKS_PROXY |
Modifier and Type | Method and Description |
---|---|
static void |
clearProxy()
Clear the global HTTP proxy for all new
HttpURLConnection s and
HttpsURLConnection s that are created after this is called. |
static javax.net.ssl.HttpsURLConnection |
getCompatibleHttpsURLConnection(java.net.URL url)
Get a
HttpsURLConnection from a URL using a more
compatible, but less strong, suite of ciphers. |
static java.net.HttpURLConnection |
getCompatibleHttpURLConnection(java.net.URL url)
Get a
HttpURLConnection from a URL . |
static javax.net.ssl.HttpsURLConnection |
getHttpsURLConnection(java.lang.String urlString)
Get a
HttpsURLConnection from a URL String using the best
TLS configuration available on the device. |
static javax.net.ssl.HttpsURLConnection |
getHttpsURLConnection(android.net.Uri uri)
Get a
HttpsURLConnection from a Uri using the best TLS
configuration available on the device. |
static javax.net.ssl.HttpsURLConnection |
getHttpsURLConnection(java.net.URI uri)
Get a
HttpsURLConnection from a URI using the best TLS
configuration available on the device. |
static javax.net.ssl.HttpsURLConnection |
getHttpsURLConnection(java.net.URL url)
Get a
HttpsURLConnection from a URL using the best TLS
configuration available on the device. |
static javax.net.ssl.HttpsURLConnection |
getHttpsURLConnection(java.net.URL url,
boolean compatible)
Get a
HttpsURLConnection from a URL , and specify whether
it should use a more compatible, but less strong, suite of ciphers. |
static java.net.HttpURLConnection |
getHttpURLConnection(java.lang.String urlString)
Get a
HttpURLConnection from a URL String . |
static java.net.HttpURLConnection |
getHttpURLConnection(android.net.Uri uri)
Get a
HttpURLConnection from a Uri . |
static java.net.HttpURLConnection |
getHttpURLConnection(java.net.URI uri)
Get a
HttpURLConnection from a URI . |
static java.net.HttpURLConnection |
getHttpURLConnection(java.net.URL url)
Get a
HttpURLConnection from a URL . |
static java.net.HttpURLConnection |
getHttpURLConnection(java.net.URL url,
boolean compatible)
Get a
HttpURLConnection from a URL , and specify whether
it should use a more compatible, but less strong, suite of ciphers. |
static java.net.Proxy |
getProxy()
Get the currently active global HTTP
Proxy . |
static TlsOnlySocketFactory |
getTlsOnlySocketFactory()
Get a
TlsOnlySocketFactory from NetCipher. |
static TlsOnlySocketFactory |
getTlsOnlySocketFactory(boolean compatible)
Get a
TlsOnlySocketFactory from NetCipher, and specify whether
it should use a more compatible, but less strong, suite of ciphers. |
static boolean |
isNetCipherGetHttpURLConnectionUsingTor() |
static boolean |
isURLConnectionUsingTor()
Makes a connection to
check.torproject.org to read its results
of whether the connection came via Tor or not. |
static void |
setProxy(java.net.Proxy proxy)
Set the global HTTP proxy for all new
HttpURLConnection s and
HttpsURLConnection s that are created after this is called. |
static void |
setProxy(java.lang.String host,
int port)
Set the global HTTP proxy for all new
HttpURLConnection s and
HttpsURLConnection s that are created after this is called. |
static void |
useGlobalProxy()
Call this method in
Application.onCreate() to enable NetCipher
to control the proxying. |
static void |
useGlobalProxyWithDNSLeaksOnAndroid7x()
Deprecated.
|
static void |
useTor()
Set Orbot as the global HTTP proxy for all new
HttpURLConnection
s and HttpsURLConnection s that are created after this is called. |
public static final java.net.Proxy ORBOT_HTTP_PROXY
public static final java.net.Proxy ORBOT_SOCKS_PROXY
public static void setProxy(java.lang.String host, int port)
HttpURLConnection
s and
HttpsURLConnection
s that are created after this is called.
useTor()
will override this setting. Traffic must be directed
to Tor using the proxy settings, and Orbot has its own proxy settings
for connections that need proxies to work. So if "use Tor" is enabled,
as tested by looking for the static instance of Proxy, then no other
proxy settings are allowed to override the current Tor proxy.
host
- the IP address for the HTTP proxy to use globallyport
- the port number for the HTTP proxy to use globallysetProxy(Proxy)
,
clearProxy()
public static void setProxy(java.net.Proxy proxy)
HttpURLConnection
s and
HttpsURLConnection
s that are created after this is called.
useTor()
will override this setting. Traffic must be directed
to Tor using the proxy settings, and Orbot has its own proxy settings
for connections that need proxies to work. So if "use Tor" is enabled,
as tested by looking for the static instance of Proxy, then no other
proxy settings are allowed to override the current Tor proxy.
proxy
- the HTTP proxy to use globallysetProxy(String, int)
,
clearProxy()
public static java.net.Proxy getProxy()
Proxy
.Proxy
public static void clearProxy()
HttpURLConnection
s and
HttpsURLConnection
s that are created after this is called. This
returns things to the default, proxy-less state.public static void useTor()
HttpURLConnection
s and HttpsURLConnection
s that are created after this is called.
This overrides all future calls to setProxy(Proxy)
, except to
clear the proxy, e.g. #setProxy(null)
or clearProxy()
.
Traffic must be directed to Tor using the proxy settings, and Orbot has its own proxy settings for connections that need proxies to work. So if "use Tor" is enabled, as tested by looking for the static instance of Proxy, then no other proxy settings are allowed to override the current Tor proxy.
clearProxy()
,
useGlobalProxy()
public static boolean isURLConnectionUsingTor()
check.torproject.org
to read its results
of whether the connection came via Tor or not.check.torproject.org
says connection is via Tor, false if not or on errorpublic static boolean isNetCipherGetHttpURLConnectionUsingTor()
public static void useGlobalProxy()
Application.onCreate()
to enable NetCipher
to control the proxying. This only works on
Android 8.0 Oreo
or newer. There needs to
be a separate call to setProxy(Proxy)
or useTor()
for
proxying to actually be enabled. clearProxy()
will then remove
the proxying when the global proxy control is in place, but the
URLStreamHandlerFactory
will stay in place until app restart.useTor()
,
setProxy(Proxy)
,
setProxy(String, int)
,
clearProxy()
,
URL.setURLStreamHandlerFactory(URLStreamHandlerFactory)
@Deprecated public static void useGlobalProxyWithDNSLeaksOnAndroid7x()
useGlobalProxy()
except that it can run on
Android 7.x (SDK 24 and 25). The global proxying leaks DNS on Android 7.x,
so this is not suitable for a privacy proxy. It will make access proxying
work. It can also be used as a failsafe to help prevent leaks when the
proxying is configured per-connection.useGlobalProxy()
,
useTor()
,
setProxy(Proxy)
,
setProxy(String, int)
,
clearProxy()
,
URL.setURLStreamHandlerFactory(URLStreamHandlerFactory)
public static TlsOnlySocketFactory getTlsOnlySocketFactory()
TlsOnlySocketFactory
from NetCipher.HttpsURLConnection.setDefaultSSLSocketFactory(SSLSocketFactory)
public static TlsOnlySocketFactory getTlsOnlySocketFactory(boolean compatible)
TlsOnlySocketFactory
from NetCipher, and specify whether
it should use a more compatible, but less strong, suite of ciphers.HttpsURLConnection.setDefaultSSLSocketFactory(SSLSocketFactory)
public static java.net.HttpURLConnection getHttpURLConnection(java.net.URL url, boolean compatible) throws java.io.IOException
HttpURLConnection
from a URL
, and specify whether
it should use a more compatible, but less strong, suite of ciphers.
If useGlobalProxy()
is called, this method will use the global
proxy settings. For .onion
addresses, this will still directly
configure the proxy, but that should be the same exact settings.
url
- compatible
- url
in an instance of HttpURLConnection
java.io.IOException
java.lang.IllegalArgumentException
- if the proxy or TLS setup is incorrectpublic static javax.net.ssl.HttpsURLConnection getHttpsURLConnection(java.lang.String urlString) throws java.io.IOException
HttpsURLConnection
from a URL String
using the best
TLS configuration available on the device.urlString
- HttpsURLConnection
java.io.IOException
java.lang.IllegalArgumentException
- if the proxy or TLS setup is incorrect,
or if an HTTP URL is given that does not support HTTPSpublic static javax.net.ssl.HttpsURLConnection getHttpsURLConnection(android.net.Uri uri) throws java.io.IOException
HttpsURLConnection
from a Uri
using the best TLS
configuration available on the device.uri
- uri
in an instance of HttpsURLConnection
java.io.IOException
java.lang.IllegalArgumentException
- if the proxy or TLS setup is incorrect,
or if an HTTP URL is given that does not support HTTPSpublic static javax.net.ssl.HttpsURLConnection getHttpsURLConnection(java.net.URI uri) throws java.io.IOException
HttpsURLConnection
from a URI
using the best TLS
configuration available on the device.uri
- uri
in an instance of HttpsURLConnection
java.io.IOException
java.lang.IllegalArgumentException
- if the proxy or TLS setup is incorrect,
or if an HTTP URL is given that does not support HTTPSpublic static javax.net.ssl.HttpsURLConnection getHttpsURLConnection(java.net.URL url) throws java.io.IOException
HttpsURLConnection
from a URL
using the best TLS
configuration available on the device.url
- url
in an instance of HttpsURLConnection
java.io.IOException
java.lang.IllegalArgumentException
- if the proxy or TLS setup is incorrect,
or if an HTTP URL is given that does not support HTTPSpublic static javax.net.ssl.HttpsURLConnection getCompatibleHttpsURLConnection(java.net.URL url) throws java.io.IOException
HttpsURLConnection
from a URL
using a more
compatible, but less strong, suite of ciphers.url
- url
in an instance of HttpsURLConnection
java.io.IOException
java.lang.IllegalArgumentException
- if the proxy or TLS setup is incorrect,
or if an HTTP URL is given that does not support HTTPSpublic static javax.net.ssl.HttpsURLConnection getHttpsURLConnection(java.net.URL url, boolean compatible) throws java.io.IOException
HttpsURLConnection
from a URL
, and specify whether
it should use a more compatible, but less strong, suite of ciphers.url
- compatible
- url
in an instance of HttpsURLConnection
java.io.IOException
java.lang.IllegalArgumentException
- if the proxy or TLS setup is incorrect,
or if an HTTP URL is given that does not support HTTPSpublic static java.net.HttpURLConnection getCompatibleHttpURLConnection(java.net.URL url) throws java.io.IOException
HttpURLConnection
from a URL
. If the connection is
https://
, it will use a more compatible, but less strong, TLS
configuration.url
- url
in an instance of HttpsURLConnection
java.io.IOException
java.lang.IllegalArgumentException
- if the proxy or TLS setup is incorrectpublic static java.net.HttpURLConnection getHttpURLConnection(java.lang.String urlString) throws java.io.IOException
HttpURLConnection
from a URL String
. If it is an
https://
link, then this will use the best TLS configuration
available on the device.urlString
- HttpURLConnection
java.io.IOException
java.lang.IllegalArgumentException
- if the proxy or TLS setup is incorrectpublic static java.net.HttpURLConnection getHttpURLConnection(android.net.Uri uri) throws java.io.IOException
HttpURLConnection
from a Uri
. If it is an
https://
link, then this will use the best TLS configuration
available on the device.uri
- uri
in an instance of HttpURLConnection
java.io.IOException
java.lang.IllegalArgumentException
- if the proxy or TLS setup is incorrectpublic static java.net.HttpURLConnection getHttpURLConnection(java.net.URI uri) throws java.io.IOException
HttpURLConnection
from a URI
. If it is an
https://
link, then this will use the best TLS configuration
available on the device.uri
- uri
in an instance of HttpURLConnection
java.io.IOException
java.lang.IllegalArgumentException
- if the proxy or TLS setup is incorrectpublic static java.net.HttpURLConnection getHttpURLConnection(java.net.URL url) throws java.io.IOException
HttpURLConnection
from a URL
. If it is an
https://
link, then this will use the best TLS configuration
available on the device.url
- url
in an instance of HttpURLConnection
java.io.IOException
java.lang.IllegalArgumentException
- if the proxy or TLS setup is incorrect