This project builds the Google WebRTC libaries for Android, and includes extensions to supply 256-bit AES CTR encryption to the frame data for end-to-end privacy. While most AES256 encryption uses CBC and not CTR, CBC requires padding and that can impact streaming video performance, so the no-padding CTR option is used instead.
Before you do so, consider just using the prebuilt components, downloadable from here: https://github.com/blspeiser/webrtc-extension/tree/main/prebuilt/ubuntu-20.04/ndk-26.3.11579264/arm64-v8a/android-32
You can read about how I did this here: https://medium.com/@sbaruch/compiling-google-webrtc-extensions-for-android-1669db71e0e6
If you are feeling particularly adventurous, you can follow the steps below in order.
Prerequisites:
Open a bash terminal in webrtc-build folder.
sh build.sh
to build the Docker container that will be used to build libwebrtc.a sh terminal.sh
to run the container and open a terminal.ls
to determine that you have two script files, checkout.sh and compile.shsh checkout.sh
to download the code for libwebtrc. It will take a very long time - possibly even overnight, maybe even longer. Don't expect it to finish any time soon. sh compile.sh
and the build should complete successfully. Open a bash terminal in boringssl folder.
sh fetch.sh
to get the code. ~/android-ndk-r26d
, if your NDK installation is located somewhere else, you will need to adjust this line.sh build.sh
to compile the code. Assuming you have successfully completed the above components sections, open a bash terminal in extension folder.
~/android-ndk-r26d
, if your NDK installation is located somewhere else, you will need to adjust this line.sh build.sh
to compile the code. Most likely, you intend to use the Google WebRTC Java libraries, and so you will require the Java-based components. Open a terminal in the jni folder.
mvn clean package
to build the jar file. The android-example folder contains a full Android Studio project showcasing how to use the components, as well as a test case that validates the frame encryptor and decryptor.
I tested on an emulated Pixel 6 with Android 32.
Note the contents of android-example/app/src/main/jar and android-example/app/src/main/jniLibs. You will need these files in your workspace so that they can be referenced by your gradle build.
peerConnection?.senders?.filterNotNull()?.forEach {
it.setFrameEncryptor( Aes256FrameEncryptor(key, ivHex) )
}
peerConnection?.receivers?.filterNotNull()?.forEach {
it.setFrameDecryptor( Aes256FrameDecryptor(key, ivHex) )
}
These two test cases can be executed to test the native frame encryption/decryption. However, the encrypt and decrypt methods on these classes are not intended for general use; they exist only for the sake of testing. During real usage, the native implementation methods are called directly by the Google WebRTC code.