How google/conscrypt works
Project type and purpose
• Conscrypt is a multi‐module, multi‐platform Java security provider library (JSP).
• It implements JCE (Java Cryptography Extension) and JSSE (Java Secure Sockets) using BoringSSL via JNI.
• It targets Android (API ≥19) and OpenJDK (Java 8+) and ships as platform‐specific and uber JARs.
• It also provides stubs (android‐stub, libcore‐stub) for compilation, doc generation (api‐doclet), benchmarks (Caliper & JMH), constants generation, testing, and release automation.
File structure
• Top-level Gradle build files and settings define a multi-project build.
• Key modules:
• common – core Java engine, JNI bindings, native C++ glue, BoringSSL calls
• android, platform, openjdk – platform-specific wrappers and provider implementations
• android‐stub, libcore-stub – compile-only stubs for Android framework classes
• openjdk-uber – aggregator that packages all native libs
• api-doclet – Kotlin doclet generating API HTML
• constants – C++ generator for compile-time constants
• benchmark-* – Caliper & JMH benchmarks, graph generator
• testing – test utilities and VeryBasicHttpServer for integration tests
• release – Dockerfiles and scripts for packaging
README for additional insights
• Confirms use of BoringSSL for cryptographic primitives and TLS.
• Describes Maven/Gradle usage, native classifiers, and uber-jar packaging.
• Points to BUILDING.md for build instructions.
a. Main components
1. Application layer: Java applications on Android/OpenJDK
2. Security API (JCE/JSSE): standard Java calls (e.g., SSLContext.getInstance)
3. Conscrypt Provider modules:
– common (AbstractConscryptEngine, OpenSSLProvider, etc.)
– android/platform/openjdk wrappers (NativeCryptoJni, Platform classes)
4. JNI glue (jniutil, jniload in common/src/jni)
5. Native BoringSSL library (built via CMake in common/src/jni/main/cpp)
6. Stub modules (android-stub, libcore-stub) – compile‐time placeholders
7. Build & packaging (Gradle, release scripts, constants generator)
8. Documentation & tooling:
– api-doclet (Kotlin doclet)
– benchmarks (Caliper/JMH modules)
– testing modules
b. Relationships & interactions
• Provider classes invoke JNI methods → JNI glue → BoringSSL native library
• Platform modules depend on common; openjdk-uber packages all native libs for distribution
• Stubs feed into android/platform modules at compile time only
• Gradle orchestrates multi‐module build; constants module generates C++ header data used by native code
• api-doclet reads Java sources → emits HTML docs
• benchmark modules depend on provider and testing utilities
• release module assembles artifacts and Docker images
c. Architectural patterns & design principles
• Layered design: API → provider implementation → native backend
• Modular Gradle multi‐project (separation of concerns per module)
• Adapter/Provider pattern for JSSE/JCE (Provider classes register algorithms and SSL context)
• JNI as the boundary crossing from managed Java to native C++ (BoringSSL)
• Stub modules as ports for framework dependence injection
d. Key technologies/frameworks
• Java (JCE, JSSE SPI), Kotlin (api-doclet)
• JNI/C++ (BoringSSL integration), CMake for native build
• Gradle multiproject build, os-detector plugins
• Caliper & JMH for benchmarks
• Docker for release images
• Traditional Gradle/Wrapping for Android AAR