Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 59 additions & 14 deletions docs/post_quantum_cryptography_guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,18 @@ FINE: Selecting JDK with provider SunJSSE version ...
Channels continue to operate normally with classical TLS, but post-quantum protection will be absent.

### 2.4 HTTP/JSON Fallback Behavior
- **Silent Fallback to Standard JDK TLS (`SunJSSE`)**: If Conscrypt native libraries fail to load (or are unavailable on the host platform), `gax-httpjson` catches the linkage error, logs a debug message at `Level.FINE`, and silently defaults to standard JDK TLS (`SunJSSE`):
- **Silent Fallback to Default JVM TLS**: If Conscrypt is unavailable, disabled, or skipped, `gax-httpjson` logs a debug message at `Level.FINE` and falls back to the JVM's default TLS provider. For example, when the native library cannot load:
```text
FINE: Conscrypt native library unavailable. Falling back to default JDK TLS.
```
When disabled via configuration or skipped for a non-default provider, `gax-httpjson` logs the specific flag or provider name instead (see [Section 3.2](#32-verifying-httpjson-connections)).

On a standard JDK, the fallback is the built-in `SunJSSE` provider. If another JSSE provider (such as `BCJSSE`) is configured ahead of `SunJSSE` in the JVM's security provider list, the JVM uses that provider instead. To check which provider your JVM selects for TLS, inspect the `security.provider.<n>` order in `$JAVA_HOME/conf/security/java.security` (or `$JAVA_HOME/jre/lib/security/java.security` on JDK 8, plus any file passed via `-Djava.security.properties`), or check at runtime with `Security.getProviders("SSLContext.TLS")[0].getName()`.

See [Section 3](#3-how-to-verify-pqc-negotiation) for instructions on enabling internal logging or tracing TLS handshakes to verify whether your application is using PQC.
- **Common Host Triggers**:
- **Common Host and Configuration Triggers**:
- **Non-Default Preferred TLS Provider (Auto-Detected, `gax-httpjson` `2.92.0+`)**: If the JVM's preferred `SSLContext.TLS` provider is neither `SunJSSE` nor `Conscrypt` (for example, `BCJSSE` or `IBMJSSE2` on IBM JDK 8), `gax-httpjson` skips Conscrypt and uses the JVM's preferred provider instead. PQC over HTTP/JSON is off in this case unless Conscrypt is configured as the preferred provider. This auto-detection applies only to HTTP/JSON (`gax-httpjson`). gRPC (`grpc-netty-shaded`) does not auto-detect `BCJSSE` and still uses bundled BoringSSL unless `-Dio.grpc.netty.shaded.io.netty.handler.ssl.noOpenSsl=true` is set.
- **Explicit Opt-Out Flag (`gax-httpjson` `2.92.0+`)**: Setting `-Dcom.google.api.gax.httpjson.disableConscrypt=true` or `GOOGLE_SDK_JAVA_DISABLE_CONSCRYPT=true` skips loading Conscrypt globally for HTTP/JSON transports (see [Section 4.2](#42-custom-httpjson-configurations) and [Section 4.3](#43-controlling-the-jvm-security-provider-across-both-transports)).
- **Alpine Linux (`musl` libc)**: Precompiled Conscrypt binaries require `glibc`. On `musl`-based distributions (e.g., `alpine`), Conscrypt cannot load and falls back to classical TLS. Use a `glibc`-compatible base image (such as Debian, Ubuntu, or Wolfi) for PQC.
- **Hardened Filesystems (`noexec /tmp`)**: If `/tmp` is mounted with `noexec` or is read-only, Conscrypt cannot load extracted native libraries. To enable PQC, specify an executable directory via `-Dorg.conscrypt.native.workdir=/path/to/executable/dir`.

Expand All @@ -130,7 +136,7 @@ To confirm whether your application is actively negotiating post-quantum hybrid
| :--- | :--- | :--- | :--- |
| **gRPC** | Shaded Netty BoringSSL (JNI) | `-Dio.grpc.netty.shaded.io.netty.handler.ssl=DEBUG` | Handshake logs showing `HANDSHAKEN: TLS_AES_128_GCM_SHA256` |
| **HTTP/JSON** | Conscrypt BoringSSL (`SSLContext`) | `-Djavax.net.debug=ssl:handshake` | `ClientHello` offering `X25519MLKEM768` (`0x11ec`), `ServerHello` selecting `X25519MLKEM768` |
| **HTTP/JSON** | `gax-httpjson` Provider Bridge | `HttpJsonConscryptUtils` (`Level.FINE`) | Absence of fallback log (`FINE: Conscrypt native library unavailable...`) |
| **HTTP/JSON** | `gax-httpjson` Provider Bridge | `HttpJsonConscryptUtils` (`Level.FINE`) | Absence of any fallback, disabled, or skipped `FINE` log (`Conscrypt native library unavailable...`, `Conscrypt disabled via...`, or `Skipping Conscrypt...`) |

> [!NOTE]
> **Why gRPC ignores `-Djavax.net.debug`**:
Expand Down Expand Up @@ -171,11 +177,17 @@ import java.util.logging.Logger;
Logger.getLogger("com.google.api.gax.httpjson.HttpJsonConscryptUtils").setLevel(Level.FINE);
```

- **When Conscrypt initializes successfully**: No fallback messages appear in the log.
- **When fallback occurs**: You will observe:
- **When Conscrypt initializes successfully**: No fallback, disabled, or skipped messages appear in the log.
- **When fallback occurs**: You will observe a `FINE` log entry with the underlying exception stack trace:
```text
FINE: Conscrypt native library unavailable. Falling back to default JDK TLS.
FINE: Conscrypt initialization failed with exception: java.lang.UnsatisfiedLinkError: ...
java.lang.UnsatisfiedLinkError: ...
```
- **When Conscrypt is disabled or skipped**: You will observe a `FINE` message naming the opt-out flag or the detected preferred TLS provider:
```text
FINE: Conscrypt disabled via system property com.google.api.gax.httpjson.disableConscrypt. Using JVM default TLS provider.
FINE: Conscrypt disabled via environment variable GOOGLE_SDK_JAVA_DISABLE_CONSCRYPT. Using JVM default TLS provider.
FINE: Skipping Conscrypt because preferred JVM TLS provider is BCJSSE.
```

#### Method 2: JVM TLS Handshake Tracing (`-Djavax.net.debug`)
Expand Down Expand Up @@ -295,7 +307,22 @@ try (SecretManagerServiceClient client = SecretManagerServiceClient.create(setti

### 4.2 Custom HTTP/JSON Configurations

#### Option 1: Forcing Classical-Only Key Exchange (Disabling PQC)
#### Option 1: Disabling Conscrypt Globally
Requires `gax-httpjson` `2.92.0+` (`libraries-bom` `26.95.0+`). Older versions silently ignore unknown system properties and environment variables, so verify that Conscrypt is skipped with `FINE` logging (see [Section 3.2](#32-verifying-httpjson-connections)).

To disable Conscrypt across HTTP/JSON transports created by `gax-httpjson` and `google-cloud-core-http` (including handwritten clients, GAPIC REST channels, and mTLS transports) without changing application code, set either the JVM system property or environment variable before creating clients:

```bash
# Via JVM system property (takes precedence if both are set)
java -Dcom.google.api.gax.httpjson.disableConscrypt=true -jar my-application.jar

# Or via environment variable
GOOGLE_SDK_JAVA_DISABLE_CONSCRYPT=true java -jar my-application.jar
```

When enabled, `gax-httpjson` skips loading Conscrypt and leaves TLS to the JVM's default configured security provider. Values are trimmed and matched case-insensitively: `true` disables Conscrypt, `false` leaves default auto-detection active (and overrides `GOOGLE_SDK_JAVA_DISABLE_CONSCRYPT=true` when set via the system property), and unrecognized non-blank values log a warning and are ignored. Note that `google-cloud-bigquery-jdbc` proxy and custom truststore transports are tracked in a separate follow-up and do not yet honor this opt-out.

#### Option 2: Forcing Classical-Only Key Exchange (Disabling PQC)
If you need to use Conscrypt for high-performance TLS but want to explicitly disable post-quantum hybrid groups (see [Common Reasons to Disable PQC](#common-reasons-to-disable-pqc)):

```java
Expand Down Expand Up @@ -332,8 +359,8 @@ try (SecretManagerServiceClient client = SecretManagerServiceClient.create(setti
}
```

#### Option 2: Bypassing Conscrypt to Use Standard JDK JSSE
If your deployment environment prohibits native JNI libraries or you prefer using the JVM's built-in cryptographic engine (`SunJSSE`):
#### Option 3: Bypassing Conscrypt Per Client to Use Standard JDK JSSE
If your deployment environment prohibits native JNI libraries or you prefer using the JVM's built-in cryptographic engine (`SunJSSE`) for a specific client:

```java
// 1. Build a standard NetHttpTransport without Conscrypt configuration
Expand All @@ -356,12 +383,12 @@ try (SecretManagerServiceClient client = SecretManagerServiceClient.create(setti
}
```

#### Option 3: Configuring a Third-Party Security Provider (e.g., Bouncy Castle)
#### Option 4: Configuring a Third-Party Security Provider (e.g., Bouncy Castle)
If your enterprise utilizes an alternative cryptographic provider (such as Bouncy Castle), configure it directly on the `NetHttpTransport.Builder`:

```java
// 1. Instantiate or lookup custom security provider
Provider customProvider = Security.getProvider("BC"); // e.g., BouncyCastleProvider
// 1. Instantiate or lookup custom JSSE security provider
Provider customProvider = Security.getProvider("BCJSSE"); // e.g., BouncyCastleJsseProvider

// 2. Configure NetHttpTransport with the custom provider
NetHttpTransport customTransport =
Expand Down Expand Up @@ -391,6 +418,24 @@ try (SecretManagerServiceClient client = SecretManagerServiceClient.create(setti

---

### 4.3 Controlling the JVM Security Provider Across Both Transports

Requires `gax-httpjson` `2.92.0+` (`libraries-bom` `26.95.0+`) for the HTTP/JSON opt-out and preferred-provider auto-detection.

If you want Google Cloud client TLS connections to use the JVM's configured `java.security` provider instead of bundled BoringSSL engines (for example, to enforce a specific JCA provider or meet compliance requirements such as FIPS), disable native BoringSSL on both transports:

```bash
java \
-Dcom.google.api.gax.httpjson.disableConscrypt=true \
-Dio.grpc.netty.shaded.io.netty.handler.ssl.noOpenSsl=true \
-jar my-application.jar
```

- **HTTP/JSON transport**: When a non-default provider (such as `BCJSSE`) is configured as the JVM's preferred `SSLContext.TLS` provider in `java.security`, `gax-httpjson` detects it automatically and skips Conscrypt. Set `-Dcom.google.api.gax.httpjson.disableConscrypt=true` (or `GOOGLE_SDK_JAVA_DISABLE_CONSCRYPT=true`) whenever you want to guarantee Conscrypt is never loaded, including in environments where `SunJSSE` remains the preferred provider (such as RHEL FIPS mode). Note that `google-cloud-bigquery-jdbc` proxy and custom truststore transports are tracked in a separate follow-up and do not yet honor this opt-out.
- **gRPC transport**: Preferred-provider auto-detection applies only to HTTP/JSON (`gax-httpjson`). For gRPC, `-Dio.grpc.netty.shaded.io.netty.handler.ssl.noOpenSsl=true` is required even when `BCJSSE` is preferred so Netty's shaded BoringSSL provider is disabled and gRPC falls back to the JVM's configured TLS provider.

---

## 5. Environment & Runtime Considerations

Because PQC negotiation relies on native BoringSSL C binaries (bundled in `grpc-netty-shaded` and `conscrypt-openjdk-uber`) loaded over JNI, compatibility depends on the underlying runtime environment. Most standard Linux (`glibc`), macOS, and Windows environments support native execution out of the box.
Expand All @@ -399,7 +444,7 @@ Because PQC negotiation relies on native BoringSSL C binaries (bundled in `grpc-
GraalVM Native Image compilation is supported for applications that include the appropriate reachability metadata and JNI configuration for Netty or Conscrypt native libraries.

### 5.2 Classpath Isolation & Version Skew Warning
If your project uses multiple dependencies that transitively pull in different versions of gRPC Netty components or Conscrypt, JNI ABI mismatches can occur during JVM classloading. Always ensure your build tool resolves compatible versions consistently.
If your project uses multiple dependencies that transitively pull in different versions of gRPC Netty components or Conscrypt, JNI ABI mismatches can occur during JVM classloading. Always ensure your build tool resolves compatible versions consistently. If you hit a Conscrypt JNI mismatch while resolving dependency skew, you can temporarily disable Conscrypt globally via `-Dcom.google.api.gax.httpjson.disableConscrypt=true` or `GOOGLE_SDK_JAVA_DISABLE_CONSCRYPT=true` (see [Section 4.2](#42-custom-httpjson-configurations) and [Section 4.3](#43-controlling-the-jvm-security-provider-across-both-transports)).

We recommend using Google Cloud's `libraries-bom` (version `26.88.0+`), which centrally manages dependency versions and ensures consistent, compatible runtime dependencies across all Google Cloud client libraries.

Expand All @@ -409,7 +454,7 @@ We recommend using Google Cloud's `libraries-bom` (version `26.88.0+`), which ce

The OpenJDK community is integrating standardized post-quantum algorithms directly into the Java platform:
- **[JEP 496](https://openjdk.org/jeps/496) (ML-KEM)**: Introduces native implementations of NIST FIPS 203 (Module-Lattice-Based Key-Encapsulation Mechanism) into OpenJDK's standard security providers (`SunJSSE` and `SunJCE`), targeted for **JDK 27+**.
- **What this means for Google Cloud Java**: On JDK 27+, applications configuring standard JDK security providers (see **Option 2** in Section 4.1 and Section 4.2) will negotiate post-quantum TLS natively using `SunJSSE`, without requiring Conscrypt or JNI native shared libraries.
- **What this means for Google Cloud Java**: On JDK 27+, applications configuring standard JDK security providers (see **Option 2** in Section 4.1 and **Option 1** or **Option 3** in Section 4.2) will negotiate post-quantum TLS natively using `SunJSSE`, without requiring Conscrypt or JNI native shared libraries.

---

Expand Down
Loading
Loading