davsclaus commented on code in PR #28106:
URL: https://github.com/apache/camel/pull/28106#discussion_r4313848493
##########
components/camel-pqc/src/main/java/org/apache/camel/component/pqc/PQCParameterSpecResolver.java:
##########
@@ -120,6 +122,10 @@ private static AlgorithmParameterSpec doResolve(String
algorithm, String paramet
return MLDSAParameterSpec.fromName(parameterSpec);
case "SPHINCSPLUS":
return SLHDSAParameterSpec.fromName(parameterSpec);
+ case "MAYO":
+ return MayoParameterSpec.fromName(parameterSpec);
+ case "SNOVA":
Review Comment:
This lookup gets the name after `parameterSpec.replace('_', '-')`, so a
SNOVA name never matches. BC's SNOVA names keep their underscores
(`SNOVA_24_5_5_SHAKE_SSK`), and the dashed form returns `null`, which then
fails as "Unknown parameterSpec".
##########
components/camel-pqc/src/test/java/org/apache/camel/component/pqc/PQCMaterialConsistencyTest.java:
##########
@@ -0,0 +1,126 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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
+ *
+ * http://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.
+ */
+package org.apache.camel.component.pqc;
+
+import java.io.IOException;
+import java.net.URISyntaxException;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.security.spec.AlgorithmParameterSpec;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.stream.Stream;
+
+import org.bouncycastle.pqc.jcajce.spec.MayoParameterSpec;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.CsvSource;
+import org.junit.jupiter.params.provider.ValueSource;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+/**
+ * Guards the consistency rules the sibling key material classes are meant to
follow but drifted away from, so the next
+ * clone-and-tweak does not reintroduce the divergence.
+ */
+class PQCMaterialConsistencyTest {
+
+ private static Path materialSourceRoot() throws URISyntaxException {
+ // the tests run from the module directory, so the sources sit at a
fixed relative path
+ Path root =
Paths.get("src/main/java/org/apache/camel/component/pqc/crypto");
+ assertTrue(Files.isDirectory(root), "cannot locate the key material
sources at " + root.toAbsolutePath());
+ return root;
+ }
+
+ private static List<Path> materialSources() throws Exception {
+ List<Path> sources = new ArrayList<>();
+ try (Stream<Path> files = Files.walk(materialSourceRoot())) {
+ files.filter(p ->
p.getFileName().toString().startsWith("PQCDefault"))
+ .filter(p ->
p.getFileName().toString().endsWith("Material.java"))
+ .forEach(sources::add);
+ }
+ assertFalse(sources.isEmpty(), "no key material sources found");
+ return sources;
+ }
+
+ @Test
+ void everyKeyMaterialSeedsItsGeneratorWithSecureRandomHelper() throws
Exception {
+ List<String> offenders = new ArrayList<>();
+ for (Path source : materialSources()) {
+ String text = Files.readString(source, StandardCharsets.UTF_8);
+ if (!text.contains("SecureRandomHelper.getSecureRandom()")) {
+ offenders.add(source.getFileName().toString());
+ }
+ }
+
+ assertTrue(offenders.isEmpty(),
+ "these key material classes fall back to the provider default
RNG instead of the shared"
+ + " SecureRandomHelper: " + offenders);
+ }
+
+ @ParameterizedTest
+ @ValueSource(strings = { "MAYO", "SNOVA" })
+ void mayoAndSnovaAcceptANamedParameterSet(String algorithm) {
Review Comment:
`isSupported` passes for SNOVA, but no test resolves a SNOVA name, which is
why the underscore mapping in `resolve()` went unnoticed. A `SNOVA` row in the
`@CsvSource` test would catch it.
--
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]