ramu11 commented on PR #30945:
URL: https://github.com/apache/camel/pull/30945#issuecomment-7276646686

   > This is well-engineered and genuinely security-conscious work. I read the 
resilience layer and the stateful-key path closely, and the design holds up. A 
few things stand out as done right:
   > 
   > * Capability detection is **typed linkage probing with lazily loaded 
nested classes**, not reflection. `BouncyCastleProductionImportFenceTest` 
confines every `org.bouncycastle.*` import to the three support classes and 
forbids reflection in production, which is a much cleaner and type-safe way to 
stay resilient to BC package moves than the usual `Class.forName` dance.
   > * The fail-closed contract for stateful keys is real and tested: under 
`UNAVAILABLE`, `getStatefulKeyRemaining`/`getStatefulKeyIndex` throw for 
LMS/HSS/XMSS/XMSSMT rather than returning a sentinel, and 
`unavailableStatefulApiFailsClosedForStatefulKeys` locks that in.
   > * Provider registration never replaces an installed provider, adds at 
lowest precedence, validates the constructed provider, uses double-checked 
locking, and throws if neither BC nor BCPQC can be installed. The 
embedding-runtime (Quarkus pre-registered provider) case is handled.
   > * The hand-rolled `Hkdf` is RFC 5869-correct on the parts that matter: 
empty T(0), counter bounded so the block count cannot exceed 255, output capped 
at 255*HashLen, and PRK/blocks/IKM zeroized in a `finally`. The KEM path makes 
defensive copies on every boundary and throws rather than falling back to 
anything weaker when a provider exposes neither KeyGenerator nor KEM.
   > * The compatibility workflow is not a CI foot-gun: PR runs use 
`--skip-latest` so an unrelated camel-pqc PR never depends on the moving Maven 
Central "latest" BC, the moving-latest check is weekly-schedule only and gated 
to `apache/camel`, permissions are `contents: read`, and action SHAs are pinned.
   > 
   > Two robustness items worth considering, both squarely in the spirit of 
"resilient to Bouncy Castle changes" and neither reachable on BC 1.86/1.87 (so 
not blocking, and CI is green):
   > 
   > 1. **`detectApi()` catches only `LinkageError`** 
(`BouncyCastlePqcCompatibility.java`, around lines 81-90). The 
`verifyAvailable()` probes it calls (lines 176-186 for 1.87, 257-267 for 1.86) 
actively construct parameter specs, for example 
`lmsKeyGenParameterSpec("lms_sha256_n32_h5", ...)` and `xmssParameterSpec(2, 
"SHA256")`. A future BC that keeps the classes and methods but changes a probe 
to reject one of those names would throw an `IllegalArgumentException` rather 
than a `LinkageError`. That escapes the catch, escapes the `ApiHolder` static 
initializer (so later `ApiHolder.API` access throws `NoClassDefFoundError`), 
and a `RuntimeException` from the 1.87 probe also prevents the 1.86 fallback 
from being tried. Catching `Throwable` (or `LinkageError | RuntimeException`) 
per tier would let a misbehaving probe degrade to the next tier or to 
`UNAVAILABLE`, which already fails closed cleanly. This is exactly the failure 
mode the PR is built to absorb, so it seems worth closing.
   > 2. **A latent fail-open in the stateful remaining/index path.** 
`isStatefulKey` keys off the algorithm string (`LMS`/`HSS`/`XMSS`/`XMSSMT`, 
lines 158-166), but `Bc187Access.getStatefulKeyRemaining` (line 237, and the 
1.86 twin at 318) returns `-1` when no BC `instanceof` matches. 
`PQCProducer.checkStatefulKeyBeforeSign` then treats `remaining < 0` as "not a 
stateful key" and returns without running the exhaustion guard 
(`PQCProducer.java` lines 1452-1455). So a `PrivateKey` that reports 
`getAlgorithm() == "XMSS"` without implementing BC's interface would skip the 
one-time-key exhaustion check, which is the dangerous direction for a stateful 
scheme where index reuse is catastrophic. The `UNAVAILABLE` branch already 
throws for exactly this shape (lines 133-134), so making the available-API 
branch symmetric (throw when `isStatefulKey` is true but no `instanceof` 
matches, instead of returning the sentinel) would keep the contract consistent. 
This is defense-in-depth rather than a re
 achable bug on provider-generated keys, since a BC key implements the matching 
interface.
   > 
   > Minor and informational:
   > 
   > * The PR description lists removing the 
`camel-pqc-bc-compat-api/-186/-187` modules and the ServiceLoader discovery, 
but the diff against main contains no removed files. Those bullets look like 
they describe the branch's own earlier iterations rather than net changes, and 
I confirmed nothing on main needed removing (no dangling module references, 
`components/pom.xml` untouched). Worth trimming the description so a reviewer 
is not hunting for deletions that are not there.
   > * `pqc.json` widens the KEM-operation `javaType` from 
`org.bouncycastle.jcajce.SecretKeyWithEncapsulation` to 
`javax.crypto.SecretKey`. The real impact on existing BC users looks minimal 
(the default KeyGenerator path still returns the concrete BC type; only the new 
JDK `KEM` fallback yields a different type), but since it is a documented-type 
change you may want a one-line upgrade-guide note per the API/contract-change 
policy.
   > * `components/camel-pqc/pom.xml` has three consecutive blank lines left 
after the comment reword (purely cosmetic).
   > 
   > Two things I could not fully verify and would ask you to confirm: that the 
`KYBER` to `ML-KEM-{512,768,1024}` normalization in `PQCParameterSpecResolver` 
is strictly behavior-identical to the prior KYBER handling (both plausibly 
resolve to ML-KEM in BC, but I did not diff the old path), and that a bare 
`NamedParameterSpec("mceliece460896")` for CMCE stays valid on future BC 
releases (it works on 1.86/1.87 per the passing test, but CMCE is not 
FIPS-named the way ML-DSA/ML-KEM are). I reasoned about the 1.86 behavior from 
the code and the interop script rather than running it on a real 1.86 classpath.
   > 
   > Nice piece of work overall. The resilience approach is the right one.
   > 
   > _Claude Code on behalf of oscerd_
   
   Thanks for the detailed review and for the positive feedback on the 
compatibility architecture.
   
   I've addressed the two additional robustness points in commit `29f5830d6ef2`:
   
   1. **Capability detection:** Updated `ApiHolder.detectApi()` to catch both 
`LinkageError` and `RuntimeException` independently for the BC 1.87 and 1.86 
probes. A runtime failure while probing one API layout now allows the fallback 
layout to be tested, and otherwise resolves to `UNAVAILABLE` without leaving 
class initialization in an erroneous state.
   
   2. **Stateful-key type validation:** Updated both `Bc187Access` and 
`Bc186Access` so that a key declaring LMS, HSS, XMSS, or XMSSMT but not 
implementing the expected Bouncy Castle private-key interface fails explicitly. 
It no longer returns `-1` or `0` for these stateful algorithms. Added 
regression coverage for all four algorithms.
   
   Also addressed the related observations:
   
   - Expanded KYBER tests to verify that `kyber512`, `kyber768`, and 
`kyber1024` resolve to `ML-KEM-512`, `ML-KEM-768`, and `ML-KEM-1024`, 
respectively, and initialize the corresponding provider key-pair generators.
   - The upgrade guide already documents the KEM body metadata change to 
`javax.crypto.SecretKey`, including that the runtime may still return Bouncy 
Castle's concrete encapsulation-carrying implementation.
   - Retained `NamedParameterSpec` for CMCE, which is validated by the 
supported Bouncy Castle 1.86/1.87 test matrix. I cannot guarantee behavior in 
future BC releases, but the compatibility checks will help detect a change.
   - Cleaned up the extra blank lines in `components/camel-pqc/pom.xml`.
   - The PR description is being aligned with the actual diff against `main`, 
rather than listing historical intermediate-branch changes.
   
   **Validation passed:**
   - PQC test suite: **477 tests, 0 failures, 0 errors, 0 skipped**.
   - `python3 etc/scripts/camel-pqc-bouncycastle-compatibility.py 
--skip-latest`: **CAMEL-PQC BOUNCY CASTLE COMPATIBILITY CHECK PASSED**.
   
   The changes are pushed to the existing PR branch. Thanks again for the 
thorough review.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to