-
Notifications
You must be signed in to change notification settings - Fork 141
test(showcase): verify PQC transport with TLS in http and grpc #6455
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
suzmue
wants to merge
5
commits into
googleapis:main
Choose a base branch
from
suzmue:showcase-tls-pqc
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
7cc05de
test(showcase): verify PQC X25519MLKEM768 transport with TLS
suzmue 3348744
use new gapic-showcase version
suzmue c7106d3
format
suzmue 99d4096
test(showcase): address PR review comments for PQC test
suzmue 33546cc
add comment
suzmue File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,212 @@ | ||
| // Copyright 2026 Google LLC | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // https://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| //! Post-Quantum Cryptography (PQC) Transport Verification Tests. | ||
| //! | ||
| //! This module verifies that `google-cloud-rust` transports support and negotiate | ||
| //! post-quantum hybrid key exchange algorithms (specifically `X25519MLKEM768`, | ||
| //! IANA group ID `0x11ec` / 4588) when connecting over TLS 1.3. | ||
| //! | ||
| //! # Verification Mechanism | ||
| //! | ||
| //! An isolated instance of `gapic-showcase` is spawned with: | ||
| //! * `--tls`: Enables Auto-TLS, generating in-memory CA and server certificates. | ||
| //! * `--ca-cert-output-file <path>`: Exports the self-signed CA certificate PEM. | ||
| //! * `--tls-groups 0x11ec`: Strictly restricts server-accepted key exchange groups | ||
| //! to `X25519MLKEM768`. | ||
| //! | ||
| //! If the client's TLS stack (`aws-lc-rs` via `rustls`) does not offer and negotiate | ||
| //! `X25519MLKEM768` during the TLS 1.3 `ClientHello`, the server rejects the handshake | ||
| //! with a TLS `HandshakeFailure` alert. | ||
| //! | ||
| //! # Scope of Tests | ||
| //! | ||
| //! 1. **HTTP/REST Unary (`reqwest`)**: Verifies HTTPS unary RPC execution. | ||
| //! 2. **gRPC Streaming (`tonic`)**: Verifies bidirectional streaming RPC execution | ||
| //! over HTTP/2 TLS. | ||
|
|
||
| use super::{Anonymous, NeverRetry}; | ||
| use crate::Result; | ||
| use anyhow::Error; | ||
| use google_cloud_gax::options::RequestOptionsBuilder; | ||
| use google_cloud_gax::retry_policy::{AlwaysRetry, RetryPolicyExt}; | ||
| use google_cloud_showcase_v1beta1::client::{Echo, Testing}; | ||
| #[cfg(google_cloud_unstable_gapic_streaming)] | ||
| use google_cloud_showcase_v1beta1::model::EchoRequest; | ||
| use std::path::PathBuf; | ||
| use std::process::Stdio; | ||
| use std::time::Duration; | ||
| use tokio::process::Command; | ||
|
|
||
| /// Dedicated port for the PQC Showcase server to prevent collisions with the standard | ||
| /// showcase test suite (running concurrently on port `:7469`). | ||
| const PQC_PORT: &str = ":7471"; | ||
| /// Dedicated fallback port to prevent port collisions with the default `:1337`. | ||
| const PQC_FALLBACK_PORT: &str = ":1339"; | ||
| const PQC_ENDPOINT: &str = "https://localhost:7471"; | ||
|
|
||
| /// Main entry point for the PQC integration test suite. | ||
| /// | ||
| /// Spawns an isolated `gapic-showcase` server configured with Auto-TLS and pinned to | ||
| /// `0x11ec` (`X25519MLKEM768`), configures CA trust, and runs transport verifications. | ||
| pub async fn run() -> Result<()> { | ||
| let _guard = google_cloud_test_utils::tracing::enable_tracing(); | ||
|
|
||
| let path = super::install().await?; | ||
| let showcase: PathBuf = [path.as_str(), "bin", "gapic-showcase"].iter().collect(); | ||
|
|
||
| let ca_cert_path = | ||
| std::env::temp_dir().join(format!("showcase_pqc_ca_{}.pem", std::process::id())); | ||
| if ca_cert_path.exists() { | ||
| let _ = std::fs::remove_file(&ca_cert_path); | ||
| } | ||
|
|
||
| tracing::info!("starting {showcase:?} with Auto-TLS (PQC enabled and pinned to 0x11ec)"); | ||
| let child = Command::new(&showcase) | ||
| .args([ | ||
| "run", | ||
| "--port", | ||
| PQC_PORT, | ||
| "--fallback-port", | ||
| PQC_FALLBACK_PORT, | ||
| "--tls", | ||
| "--ca-cert-output-file", | ||
| ca_cert_path | ||
| .to_str() | ||
| .ok_or_else(|| Error::msg("temp dir path is not valid UTF-8"))?, | ||
| "--tls-groups", | ||
| "0x11ec", // X25519MLKEM768 | ||
| ]) | ||
| .stdin(Stdio::null()) | ||
| .kill_on_drop(true) | ||
| .spawn() | ||
| .map_err(anyhow::Error::from)?; | ||
| tracing::info!("started showcase PQC server: {child:?}"); | ||
|
|
||
| // Wait for the Showcase server to write its autogenerated CA certificate and become ready. | ||
| let mut ready = false; | ||
| for _ in 0..50 { | ||
| if let Ok(pem) = std::fs::read(&ca_cert_path) | ||
| && !pem.is_empty() | ||
| { | ||
| // SAFETY: Setting environment variable before issuing network requests in the test process. | ||
| // This configures `rustls-native-certs` to trust the autogenerated Showcase CA. | ||
| unsafe { | ||
| std::env::set_var("SSL_CERT_FILE", &ca_cert_path); | ||
| } | ||
| if wait_until_ready(PQC_ENDPOINT).await.is_ok() { | ||
| ready = true; | ||
| break; | ||
| } | ||
| } | ||
| tokio::time::sleep(std::time::Duration::from_millis(100)).await; | ||
| } | ||
|
|
||
| if !ready { | ||
| return Err(Error::msg(format!( | ||
| "showcase PQC server is not ready: {child:?}" | ||
| ))); | ||
| } | ||
|
suzmue marked this conversation as resolved.
|
||
|
|
||
| tracing::info!("testing PQC transport (HTTP unary)"); | ||
| test_pqc_http().await?; | ||
|
|
||
| #[cfg(google_cloud_unstable_gapic_streaming)] | ||
| { | ||
| tracing::info!("testing PQC transport (gRPC streaming)"); | ||
| test_pqc_grpc().await?; | ||
| } | ||
|
|
||
| Ok(()) | ||
| } | ||
|
|
||
| async fn wait_until_ready(endpoint: &str) -> Result<()> { | ||
| for _ in 0..50 { | ||
| if let Ok(client) = Testing::builder() | ||
| .with_endpoint(endpoint) | ||
| .with_credentials(Anonymous::new().build()) | ||
| .build() | ||
| .await | ||
| && client | ||
| .list_sessions() | ||
| .with_retry_policy(AlwaysRetry.with_attempt_limit(1)) | ||
| .with_attempt_timeout(Duration::from_millis(500)) | ||
| .send() | ||
| .await | ||
| .is_ok() | ||
| { | ||
| return Ok(()); | ||
| } | ||
| tokio::time::sleep(Duration::from_millis(100)).await; | ||
| } | ||
| Err(Error::msg(format!( | ||
| "showcase server at {endpoint} is not ready" | ||
| ))) | ||
| } | ||
|
|
||
| /// Verifies that HTTP unary RPCs (`reqwest`) succeed over a TLS channel requiring `X25519MLKEM768`. | ||
| async fn test_pqc_http() -> Result<()> { | ||
| let client = Echo::builder() | ||
| .with_endpoint(PQC_ENDPOINT) | ||
| .with_credentials(Anonymous::new().build()) | ||
| .with_retry_policy(NeverRetry) | ||
| .with_tracing() | ||
| .build() | ||
| .await?; | ||
|
|
||
| const TEXT: &str = "testing PQC transport compliance (HTTP unary)"; | ||
| let response = client.echo().set_content(TEXT).send().await?; | ||
| assert_eq!(response.content, TEXT); | ||
|
|
||
| tracing::info!("Verified HTTP unary RPC over PQC TLS channel"); | ||
| Ok(()) | ||
| } | ||
|
|
||
| /// Verifies that gRPC bidirectional streaming RPCs (`tonic`) succeed over a TLS channel requiring `X25519MLKEM768`. | ||
| #[cfg(google_cloud_unstable_gapic_streaming)] | ||
| async fn test_pqc_grpc() -> Result<()> { | ||
| let client = Echo::builder() | ||
| .with_endpoint(PQC_ENDPOINT) | ||
| .with_credentials(Anonymous::new().build()) | ||
| .with_retry_policy(NeverRetry) | ||
| .with_tracing() | ||
| .build() | ||
| .await?; | ||
|
|
||
| const TOTAL_MESSAGES: usize = 5; | ||
| let (sender, mut receiver) = client.chat().build(); | ||
|
|
||
| for i in 0..TOTAL_MESSAGES { | ||
| sender | ||
| .send(EchoRequest::new().set_content(format!("pqc-grpc-msg-{i}"))) | ||
| .await?; | ||
| } | ||
| drop(sender); | ||
|
|
||
| let mut received = Vec::new(); | ||
| while let Some(res) = receiver.recv().await { | ||
| received.push(res?.content); | ||
| } | ||
|
|
||
| let expected: Vec<String> = (0..TOTAL_MESSAGES) | ||
| .map(|i| format!("pqc-grpc-msg-{i}")) | ||
| .collect(); | ||
| assert_eq!( | ||
| received, expected, | ||
| "gRPC streaming message exchange over PQC TLS channel must match" | ||
| ); | ||
|
|
||
| tracing::info!("Verified gRPC streaming over PQC TLS channel (0x11ec)"); | ||
| Ok(()) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| // Copyright 2026 Google LLC | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // https://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| #[cfg(all(test, feature = "run-showcase-tests"))] | ||
| mod pqc { | ||
| use google_cloud_test_utils::errors::anydump; | ||
|
|
||
| #[tokio::test] | ||
| async fn run() -> anyhow::Result<()> { | ||
| integration_tests_showcase::pqc::run() | ||
| .await | ||
| .inspect_err(anydump) | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.