This is an automated email from the ASF dual-hosted git repository.

ppalaga pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-quarkus.git


The following commit(s) were added to refs/heads/main by this push:
     new 353dc4ca1c camel-quarkus-crypto: Added test to sign/verify raw keys 
Removed unused dependency on javassist from bouncycastle-support Removed 
javassist from enforcer rules
353dc4ca1c is described below

commit 353dc4ca1cb03ea1c892712c78627ecb019e4290
Author: Darren Coleman <[email protected]>
AuthorDate: Tue May 30 08:54:21 2023 +0100

    camel-quarkus-crypto: Added test to sign/verify raw keys
    Removed unused dependency on javassist from bouncycastle-support
    Removed javassist from enforcer rules
    
    Fixes #4979
---
 extensions-support/bouncycastle/runtime/pom.xml       |  4 ----
 .../quarkus/component/crypto/it/CryptoResource.java   | 11 +++++++----
 .../quarkus/component/crypto/it/CryptoRoutes.java     | 19 ++++++++++++++++++-
 .../camel/quarkus/component/crypto/it/CryptoTest.java |  5 ++++-
 .../enforcer-rules/quarkus-banned-dependencies.xsl    |  2 +-
 5 files changed, 30 insertions(+), 11 deletions(-)

diff --git a/extensions-support/bouncycastle/runtime/pom.xml 
b/extensions-support/bouncycastle/runtime/pom.xml
index 3072490ba4..28ed2a2e6a 100644
--- a/extensions-support/bouncycastle/runtime/pom.xml
+++ b/extensions-support/bouncycastle/runtime/pom.xml
@@ -55,10 +55,6 @@
             <groupId>org.bouncycastle</groupId>
             <artifactId>bcpkix-jdk18on</artifactId>
         </dependency>
-        <dependency>
-            <groupId>org.javassist</groupId>
-            <artifactId>javassist</artifactId>
-        </dependency>
     </dependencies>
 
     <build>
diff --git 
a/integration-tests/crypto/src/main/java/org/apache/camel/quarkus/component/crypto/it/CryptoResource.java
 
b/integration-tests/crypto/src/main/java/org/apache/camel/quarkus/component/crypto/it/CryptoResource.java
index 1143bf3ec5..6667b52175 100644
--- 
a/integration-tests/crypto/src/main/java/org/apache/camel/quarkus/component/crypto/it/CryptoResource.java
+++ 
b/integration-tests/crypto/src/main/java/org/apache/camel/quarkus/component/crypto/it/CryptoResource.java
@@ -29,6 +29,7 @@ import jakarta.ws.rs.Consumes;
 import jakarta.ws.rs.POST;
 import jakarta.ws.rs.Path;
 import jakarta.ws.rs.Produces;
+import jakarta.ws.rs.QueryParam;
 import jakarta.ws.rs.core.MediaType;
 import jakarta.ws.rs.core.Response;
 import org.apache.camel.Exchange;
@@ -50,8 +51,9 @@ public class CryptoResource {
 
     @Path("/signature/sign")
     @POST
-    public byte[] sign() {
-        Exchange exchange = producerTemplate.request("direct:sign", new 
Processor() {
+    public byte[] sign(@QueryParam("raw") boolean raw) {
+        final String endpoint = "direct:sign" + (raw ? "-raw" : "");
+        Exchange exchange = producerTemplate.request(endpoint, new Processor() 
{
             @Override
             public void process(Exchange exchange) throws Exception {
                 exchange.getMessage().setBody(MESSAGE);
@@ -64,8 +66,9 @@ public class CryptoResource {
     @Path("/signature/verify")
     @POST
     @Consumes(MediaType.TEXT_PLAIN)
-    public Response verify(String signature) {
-        Exchange exchange = producerTemplate.send("direct:verify", new 
Processor() {
+    public Response verify(@QueryParam("raw") boolean raw, String signature) {
+        final String endpoint = "direct:verify" + (raw ? "-raw" : "");
+        Exchange exchange = producerTemplate.send(endpoint, new Processor() {
             @Override
             public void process(Exchange exchange) throws Exception {
                 Message message = exchange.getMessage();
diff --git 
a/integration-tests/crypto/src/main/java/org/apache/camel/quarkus/component/crypto/it/CryptoRoutes.java
 
b/integration-tests/crypto/src/main/java/org/apache/camel/quarkus/component/crypto/it/CryptoRoutes.java
index da7cef1f7f..7004ee6e35 100644
--- 
a/integration-tests/crypto/src/main/java/org/apache/camel/quarkus/component/crypto/it/CryptoRoutes.java
+++ 
b/integration-tests/crypto/src/main/java/org/apache/camel/quarkus/component/crypto/it/CryptoRoutes.java
@@ -16,11 +16,14 @@
  */
 package org.apache.camel.quarkus.component.crypto.it;
 
+import java.security.KeyPair;
+import java.security.KeyPairGenerator;
 import java.security.NoSuchAlgorithmException;
 
 import javax.crypto.KeyGenerator;
 
 import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.crypto.DigitalSignatureConstants;
 import org.apache.camel.converter.crypto.CryptoDataFormat;
 
 public class CryptoRoutes extends RouteBuilder {
@@ -28,7 +31,17 @@ public class CryptoRoutes extends RouteBuilder {
     @Override
     public void configure() throws Exception {
 
-        // Crypto component
+        // Crypto component using raw keys
+        final KeyPair keys = getKeyPair();
+        from("direct:sign-raw")
+                .setHeader(DigitalSignatureConstants.SIGNATURE_PRIVATE_KEY, 
constant(keys.getPrivate()))
+                .to("crypto:sign:raw");
+
+        from("direct:verify-raw")
+                
.setHeader(DigitalSignatureConstants.SIGNATURE_PUBLIC_KEY_OR_CERT, 
constant(keys.getPublic()))
+                .to("crypto:verify:raw");
+
+        // Crypto component using keys from a keystore
         from("direct:sign")
                 
.to("crypto:sign:basic?privateKey=#myPrivateKey&algorithm=SHA1withDSA&provider=SUN&secureRandom=#customSecureRandom");
 
@@ -56,4 +69,8 @@ public class CryptoRoutes extends RouteBuilder {
         return new CryptoDataFormat("DES", generator.generateKey());
     }
 
+    private KeyPair getKeyPair() throws NoSuchAlgorithmException {
+        return KeyPairGenerator.getInstance("RSA").generateKeyPair();
+    }
+
 }
diff --git 
a/integration-tests/crypto/src/test/java/org/apache/camel/quarkus/component/crypto/it/CryptoTest.java
 
b/integration-tests/crypto/src/test/java/org/apache/camel/quarkus/component/crypto/it/CryptoTest.java
index bfac55cb0c..7f0d553455 100644
--- 
a/integration-tests/crypto/src/test/java/org/apache/camel/quarkus/component/crypto/it/CryptoTest.java
+++ 
b/integration-tests/crypto/src/test/java/org/apache/camel/quarkus/component/crypto/it/CryptoTest.java
@@ -22,6 +22,8 @@ import io.quarkus.test.junit.QuarkusTest;
 import io.restassured.RestAssured;
 import org.apache.commons.codec.binary.Base64;
 import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.ValueSource;
 
 import static 
org.apache.camel.quarkus.component.crypto.it.CryptoResource.MESSAGE;
 import static org.hamcrest.Matchers.is;
@@ -31,7 +33,8 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
 @QuarkusTest
 class CryptoTest {
 
-    @Test
+    @ParameterizedTest
+    @ValueSource(booleans = { false, true })
     public void signAndVerifySignature() {
         // Encrypt message
         byte[] signatureBytes = RestAssured.given()
diff --git a/tooling/enforcer-rules/quarkus-banned-dependencies.xsl 
b/tooling/enforcer-rules/quarkus-banned-dependencies.xsl
index 94da6908e2..a6a82e45aa 100644
--- a/tooling/enforcer-rules/quarkus-banned-dependencies.xsl
+++ b/tooling/enforcer-rules/quarkus-banned-dependencies.xsl
@@ -30,5 +30,5 @@
     <!-- This is to remove some entries from -->
     <!-- 
https://github.com/quarkusio/quarkus/blob/main/independent-projects/enforcer-rules/src/main/resources/enforcer-rules/quarkus-banned-dependencies.xml
 -->
     <!-- before passing it to Maven enforcer plugin -->
-    <xsl:template match="//bannedDependencies/excludes/exclude[text() = 
'org.javassist:javassist' or contains(text(), 'org.springframework:spring-')]"/>
+    <xsl:template 
match="//bannedDependencies/excludes/exclude[contains(text(), 
'org.springframework:spring-')]"/>
 </xsl:stylesheet>

Reply via email to