Skip to content
subcloakdocs

Devices and runtimes

Java and the JVM

Make Java, Gradle and Android Studio trust Cloak Proxy's certificate and send their traffic through it.

Java keeps its own list of trusted certificates and its own proxy settings, so the macOS proxy and keychain don’t reach it. The Java & JVM page of Device & Runtime Setup has both commands, filled in with your port and your certificate’s path, each with a Copy button.

The Java & JVM page.

The Java & JVM page with the keytool command to trust the certificate and the JVM proxy flags, each with a Copy button

Firefox, Docker, Flutter and Electron have their own pages now: Capturing browser and Electron apps, Docker and Flutter.

In the commands, the certificate path is written as $HOME/Library/Application Support/CloakProxy/cloak-proxy-ca.pem so you can paste it into a shell. The port is the one Cloak Proxy listens on (9090 by default).

Java uses its own trust store, cacerts, and its own proxy settings.

  1. Import the Cloak Proxy certificate into the JDK’s trust store. Copy the command from the Java (JVM, Gradle, Android Studio) section and run it:

    Terminal
    sudo keytool -importcert -noprompt -alias cloak-proxy -cacerts -storepass changeit -file "$HOME/Library/Application Support/CloakProxy/cloak-proxy-ca.pem"

    changeit is the JDK’s default trust store password. -cacerts needs Java 9 or later.

  2. Run your program with the proxy settings:

    Terminal
    java -Dhttps.proxyHost=127.0.0.1 -Dhttps.proxyPort=9090 -Dhttp.proxyHost=127.0.0.1 -Dhttp.proxyPort=9090 -jar app.jar

keytool changes the JDK it belongs to. If you use more than one JDK (Android Studio bundles its own), run the keytool of each JDK that should trust the certificate. A JDK update can replace cacerts, so import again after updating.

To pass the proxy settings without editing a command line, set them in the environment or, for Gradle, in gradle.properties:

Terminal
export JAVA_TOOL_OPTIONS="-Dhttps.proxyHost=127.0.0.1 -Dhttps.proxyPort=9090 -Dhttp.proxyHost=127.0.0.1 -Dhttp.proxyPort=9090"

Undo: remove the certificate and the proxy settings.

Terminal
sudo keytool -delete -alias cloak-proxy -cacerts -storepass changeit

The easiest way is a capturing Firefox: its own profile, already proxied. To use your everyday Firefox instead, trust the certificate on this Mac (Settings › Certificate), then in about:config set security.enterprise_roots.enabled to true and turn on macOS capture. Firefox follows the macOS proxy by default.