Conscrypt Documentation

repository·master·Indexed 23 days ago

https://github.com/google/conscrypt

A Java Security Provider that uses BoringSSL to provide high-performance cryptographic primitives and TLS support for Android and OpenJDK applications. It implements parts of the Java Cryptography Extension (JCE) and Java Secure Socket Extension (JSSE), supporting TLS versions 1.0 through 1.3.

Tokens
6K
Snippets
14
Records
33
Agent score
80%

What's inside Conscrypt

  1. What is Conscrypt?

    master
    Conscrypt is a Java Security Provider (JSP) that implements parts of the Java Cryptography Extension (JCE) and Java Secure Socket Extension (JSSE). It uses BoringSSL to provide cryptographic primitives and Transport Layer Security (TLS) for Java applications on Android and OpenJDK. It is designed for high performance, borrowing design patterns from the Netty project.
  2. Handle AEAD Cipher input buffering

    master

    Conscrypt's AEAD ciphers do not support incremental processing. Calls to update() will always return null, and input is only processed when doFinal() is called.

    Requirement: You must buffer the entire input for each operation before calling doFinal(). For large inputs, you may need to split the data into chunks. Refer to the BoringSSL documentation for safety considerations when chunking AEAD inputs.

  3. View Code Coverage Reports

    master

    To generate and view code coverage numbers, run the tests followed by the jacocoTestReport rule:

    ./gradlew check jacocoTestReport

    The HTML report will be generated at: openjdk/build/reports/jacoco/test/html/index.html

  4. Ensure compatibility with OAEP ciphers

    master

    Conscrypt's OAEP ciphers (e.g., RSA/ECB/OAEPWithSHA-256AndMGF1Padding) use the specified named digest for both the main digest and the MGF1 digest. This differs from OpenJDK, which uses SHA-1 for the MGF1 digest.

    To ensure maximum compatibility with other providers, use RSA/ECB/OAEPPadding and initialize it with an OAEPParameterSpec to explicitly define the digests.

  5. Install Conscrypt for OpenJDK (non-Android) via Maven

    master

    Conscrypt OpenJDK artifacts are platform-dependent because they embed a native library. To manage this, use the os-maven-plugin to automatically detect the correct classifier for your operating system and architecture.

    Supported platforms include:

    • linux-x86_64 (Linux x86_64)
    • linux-aarch_64 (Linux aarch_64)
    • osx-x86_64 (Mac x86_64)
    • osx-aarch_64 (Mac aarch_64)
    • windows-x86_64 (Windows x86_64)
    <build>
      <extensions>
        <extension>
          <groupId>kr.motd.maven</groupId>
          <artifactId>os-maven-plugin</artifactId>
          <version>1.4.1.Final</version>
        </extension>
      </extensions>
    </build>
    
    <dependency>
      <groupId>org.conscrypt</groupId>
      <artifactId>conscrypt-openjdk</artifactId>
      <version>2.6.0</version>
      <classifier>${os.detected.classifier}</classifier>
    </dependency>
  6. Build Conscrypt

    master

    To build Conscrypt from the source repository, use the Gradle wrapper.

    To perform a standard build, run:

    ./gradlew build

    To publish the resulting artifacts to your local Maven repository (allowing you to use them as dependencies in your own projects), run:

    ./gradlew publishToMavenLocal
  7. Prerequisites for building Conscrypt

    master

    Building Conscrypt requires the following environment configuration:

    Java

    • Runtime: You must have Java 11 installed to run Gradle.
    • Compiler: Conscrypt is compiled using Java 8 via Gradle's toolchain support. If Java 8 is not present, Gradle may attempt to install it automatically depending on your OS.

    Android SDK

    • Install the latest Android SDK.
    • Set the ANDROID_HOME environment variable to the root of your SDK installation.
      • Example: export ANDROID_HOME=/usr/local/me/Android/Sdk

    BoringSSL

    • You must first set up the BoringSSL prerequisites.
    • Clone BoringSSL and set the BORINGSSL_HOME environment variable to the installation directory.
  8. Use RSA OAEP Padding with maximum compatibility

    master

    Conscrypt's OAEP ciphers (e.g., RSA/ECB/OAEPWithSHA-256AndMGF1Padding) use the named digest for both the main digest and the MGF1 digest. This differs from some OpenJDK providers that always use SHA-1 for the MGF1 digest.

    To ensure maximum compatibility with other providers, use RSA/ECB/OAEPPadding and initialize it with an OAEPParameterSpec.

  9. Format C++, Java, and C files in Conscrypt

    master

    When modifying .java, .cc, .h, .cpp, or .c files within the Conscrypt directory (specifically under third_party/java/conscrypt/main_src/), you must use the project's custom formatting script instead of standard global formatters.

    Requirements:

    • The script only processes files that are currently opened for edit in your version control system (e.g., via g4 edit or hg edit).
    • You must run the formatter after making changes but before creating a CL, uploading, or submitting your work.
    python3 third_party/java/conscrypt/main_src/fix_format.py
  10. Build BoringSSL

    master

    Before building Conscrypt, you must build BoringSSL. Follow these steps based on your operating system.

    1. Download and Setup

    Clone the repository and set the BORINGSSL_HOME environment variable:

    git clone https://boringssl.googlesource.com/boringssl
    cd boringssl
    export BORINGSSL_HOME=$PWD

    2. Platform Specific Builds

    Linux (64-bit)

    mkdir build64
    cd build64
    cmake -DCMAKE_POSITION_INDEPENDENT_CODE=TRUE \
          -DCMAKE_BUILD_TYPE=Release \
          -DCMAKE_ASM_FLAGS=-Wa,--noexecstack \
          -GNinja ..
    ninja

    macOS Note: You must build separate libraries for x86 and ARM architectures.

    x86_64 version:

    mkdir build.x86
    cd build.x86
    cmake -DCMAKE_POSITION_INDEPENDENT_CODE=TRUE \
          -DCMAKE_BUILD_TYPE=Release \
          -DCMAKE_ASM_FLAGS=-Wa,--noexecstack \
          -DCMAKE_OSX_ARCHITECTURES=x86_64 \
          -GNinja ..
    ninja

    arm64 version:

    mkdir build.arm
    cd build.arm
    cmake -DCMAKE_POSITION_INDEPENDENT_CODE=TRUE \
          -DCMAKE_BUILD_TYPE=Release \
          -DCMAKE_ASM_FLAGS=-Wa,--noexecstack \
          -DCMAKE_OSX_ARCHITECTURES=arm64 \
          -GNinja ..
    ninja

    Windows (64-bit) Requires Microsoft Visual Studio 2017 with Windows 8.1 and 10 SDKs. 32-bit mode is not supported.

    call "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvarsall.bat" x86_amd64
    mkdir build64
    cd build64
    cmake -DCMAKE_POSITION_INDEPENDENT_CODE=TRUE ^
          -DCMAKE_BUILD_TYPE=Release ^
          -DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded ^
          -GNinja ..
    ninja
  11. Use the Conscrypt OpenJDK Uber JAR

    master

    If you want to simplify dependency management and avoid platform-specific classifiers, you can use the conscrypt-openjdk-uber artifact. This Uber JAR contains the shared libraries for all published platforms. Note that the JAR size will be larger than the platform-specific version.

    ##### Maven
    ```xml
    <dependency>
      <groupId>org.conscrypt</groupId>
      <artifactId>conscrypt-openjdk-uber</artifactId>
      <version>2.6.0</version>
    </dependency>
    Gradle
    dependencies {
      compile 'org.conscrypt:conscrypt-openjdk-uber:2.6.0'
    }