You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by GitBox <gi...@apache.org> on 2020/09/17 15:44:45 UTC

[GitHub] [camel-quarkus] ppalaga commented on a change in pull request #1802: feat(ssh): promoting native extension

ppalaga commented on a change in pull request #1802:
URL: https://github.com/apache/camel-quarkus/pull/1802#discussion_r490348655



##########
File path: extensions/ssh/deployment/src/main/java/org/apache/camel/quarkus/component/ssh/deployment/SshProcessor.java
##########
@@ -0,0 +1,99 @@
+/*
+ * 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.quarkus.component.ssh.deployment;
+
+import java.security.KeyFactory;
+import java.security.KeyPairGenerator;
+import java.security.Signature;
+import java.util.Arrays;
+
+import javax.crypto.KeyAgreement;
+import javax.crypto.Mac;
+
+import io.quarkus.deployment.annotations.BuildProducer;
+import io.quarkus.deployment.annotations.BuildStep;
+import io.quarkus.deployment.builditem.FeatureBuildItem;
+import io.quarkus.deployment.builditem.nativeimage.NativeImageProxyDefinitionBuildItem;
+import io.quarkus.deployment.builditem.nativeimage.NativeImageResourceBuildItem;
+import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem;
+import io.quarkus.deployment.builditem.nativeimage.RuntimeInitializedClassBuildItem;
+import io.quarkus.deployment.builditem.nativeimage.RuntimeReinitializedClassBuildItem;
+import org.apache.sshd.common.channel.ChannelListener;
+import org.apache.sshd.common.forward.PortForwardingEventListener;
+import org.apache.sshd.common.io.nio2.Nio2ServiceFactoryFactory;
+import org.apache.sshd.common.session.SessionListener;
+import org.apache.sshd.common.util.security.eddsa.EdDSASecurityProviderUtils;
+
+class SshProcessor {
+
+    private static final String FEATURE = "camel-ssh";
+
+    @BuildStep
+    FeatureBuildItem feature() {
+        return new FeatureBuildItem(FEATURE);
+    }
+
+    @BuildStep
+    void secureRandomConfiguration(BuildProducer<RuntimeReinitializedClassBuildItem> reinitialized) {
+        for (String s : Arrays.asList(
+                "java.security.SecureRandom",
+                "org.bouncycastle.crypto.CryptoServicesRegistrar",
+                "org.bouncycastle.jcajce.provider.drbg.DRBG$NonceAndIV",
+                "org.bouncycastle.jcajce.provider.drbg.DRBG$Default")) {
+            reinitialized.produce(new RuntimeReinitializedClassBuildItem(s));
+        }
+    }
+
+    @BuildStep
+    RuntimeInitializedClassBuildItem delayEdDSAConfiguration() {
+        return new RuntimeInitializedClassBuildItem(EdDSASecurityProviderUtils.class.getCanonicalName());
+    }
+
+    @BuildStep
+    void registerForReflection(BuildProducer<ReflectiveClassBuildItem> reflectiveClasses) {
+        reflectiveClasses.produce(
+                new ReflectiveClassBuildItem(
+                        true,
+                        false,
+                        KeyPairGenerator.class.getCanonicalName(),

Review comment:
       Please prefer `class.getName()` here and also in other methods of this class. It works also for inner classes and is a safer choice for people copying from here.

##########
File path: extensions/ssh/runtime/src/main/java/org/apache/camel/quarkus/component/ssh/runtime/SubstituteSecurityUtils.java
##########
@@ -0,0 +1,65 @@
+/*
+ * 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.quarkus.component.ssh.runtime;
+
+import java.security.GeneralSecurityException;
+import java.security.PrivateKey;
+import java.security.PublicKey;
+
+import com.oracle.svm.core.annotate.Substitute;
+import com.oracle.svm.core.annotate.TargetClass;
+import org.apache.sshd.common.util.buffer.Buffer;
+import org.apache.sshd.common.util.security.SecurityUtils;
+
+/**
+ * We're substituting those offending methods that would require the presence of
+ * net.i2p.crypto:eddsa library which is not supported by Camel SSH component

Review comment:
       Is this documented somewhere? I am not finding any mention of eddsa on https://camel.apache.org/components/latest/ssh-component.html Shouldn't we file a documentation issue?

##########
File path: extensions/ssh/deployment/src/main/java/org/apache/camel/quarkus/component/ssh/deployment/SshProcessor.java
##########
@@ -0,0 +1,99 @@
+/*
+ * 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.quarkus.component.ssh.deployment;
+
+import java.security.KeyFactory;
+import java.security.KeyPairGenerator;
+import java.security.Signature;
+import java.util.Arrays;
+
+import javax.crypto.KeyAgreement;
+import javax.crypto.Mac;
+
+import io.quarkus.deployment.annotations.BuildProducer;
+import io.quarkus.deployment.annotations.BuildStep;
+import io.quarkus.deployment.builditem.FeatureBuildItem;
+import io.quarkus.deployment.builditem.nativeimage.NativeImageProxyDefinitionBuildItem;
+import io.quarkus.deployment.builditem.nativeimage.NativeImageResourceBuildItem;
+import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem;
+import io.quarkus.deployment.builditem.nativeimage.RuntimeInitializedClassBuildItem;
+import io.quarkus.deployment.builditem.nativeimage.RuntimeReinitializedClassBuildItem;
+import org.apache.sshd.common.channel.ChannelListener;
+import org.apache.sshd.common.forward.PortForwardingEventListener;
+import org.apache.sshd.common.io.nio2.Nio2ServiceFactoryFactory;
+import org.apache.sshd.common.session.SessionListener;
+import org.apache.sshd.common.util.security.eddsa.EdDSASecurityProviderUtils;
+
+class SshProcessor {
+
+    private static final String FEATURE = "camel-ssh";
+
+    @BuildStep
+    FeatureBuildItem feature() {
+        return new FeatureBuildItem(FEATURE);
+    }
+
+    @BuildStep
+    void secureRandomConfiguration(BuildProducer<RuntimeReinitializedClassBuildItem> reinitialized) {
+        for (String s : Arrays.asList(
+                "java.security.SecureRandom",
+                "org.bouncycastle.crypto.CryptoServicesRegistrar",
+                "org.bouncycastle.jcajce.provider.drbg.DRBG$NonceAndIV",
+                "org.bouncycastle.jcajce.provider.drbg.DRBG$Default")) {
+            reinitialized.produce(new RuntimeReinitializedClassBuildItem(s));
+        }
+    }

Review comment:
       I think `org.apache.camel.quarkus.support.bouncycastle.deployment.BouncycastleSupportProcessor` would be the right home for this BuildStep. 

##########
File path: integration-tests/ssh/src/test/java/org/apache/camel/quarkus/component/ssh/it/SshTest.java
##########
@@ -0,0 +1,55 @@
+/*
+ * 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.quarkus.component.ssh.it;
+
+import io.quarkus.test.common.QuarkusTestResource;
+import io.quarkus.test.junit.QuarkusTest;
+import io.restassured.RestAssured;
+import io.restassured.http.ContentType;
+import org.bouncycastle.jce.provider.BouncyCastleProvider;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+@QuarkusTest
+@QuarkusTestResource(SshTestResource.class)
+class SshTest {
+
+    @Test
+    public void testWriteToSSHAndReadFromSSH() {
+        final String fileContent = "Hello Camel Quarkus SSH";
+        BouncyCastleProvider x;

Review comment:
       Can't we remove this line?




----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org