You are viewing a plain text version of this content. The canonical link for it is here.
Posted to gitbox@activemq.apache.org by "jbertram (via GitHub)" <gi...@apache.org> on 2025/03/05 21:40:50 UTC

[PR] ARTEMIS-5340 ensure PEM provider is truly optional [activemq-artemis]

jbertram opened a new pull request, #5547:
URL: https://github.com/apache/activemq-artemis/pull/5547

   (no comment)


-- 
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: gitbox-unsubscribe@activemq.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@activemq.apache.org
For additional commands, e-mail: gitbox-help@activemq.apache.org
For further information, visit: https://activemq.apache.org/contact



Re: [PR] ARTEMIS-5340 ensure PEM provider is truly optional [activemq-artemis]

Posted by "gemmellr (via GitHub)" <gi...@apache.org>.
gemmellr commented on code in PR #5547:
URL: https://github.com/apache/activemq-artemis/pull/5547#discussion_r1983756559


##########
artemis-core-client/src/test/java/org/apache/activemq/artemis/core/remoting/impl/netty/PemProviderTest.java:
##########
@@ -0,0 +1,64 @@
+/*
+ * 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.activemq.artemis.core.remoting.impl.netty;
+
+import java.util.Arrays;
+
+import de.dentrassi.crypto.pem.PemKeyStoreProvider;
+import org.apache.activemq.artemis.core.remoting.impl.ssl.SSLSupport;
+import org.junit.jupiter.api.Assumptions;
+import org.junit.jupiter.api.MethodOrderer.OrderAnnotation;
+import org.junit.jupiter.api.Order;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestMethodOrder;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+
+/**
+ * Order is important here because we don't want to load the PEM provider class before we test that it isn't loaded.
+ */
+@TestMethodOrder(OrderAnnotation.class)
+public class PemProviderTest {
+
+   static final String PEM_PROVIDER_PACKAGE = "de.dentrassi.crypto.pem";
+
+   @Test
+   @Order(1)
+   public void testPemProviderNotLoaded() {
+      // ensure the PEM provider wasn't already loaded by some other test
+      Assumptions.assumeFalse(Arrays.stream(ClassLoader.getSystemClassLoader().getDefinedPackages()).anyMatch(pkg -> PEM_PROVIDER_PACKAGE.equals(pkg.getName())));

Review Comment:
   Would be better to make it an _assertion_ and let it fail when it needs to, to serve as notice the two tests are clashing and need to be ordered or isolated from each other to fix the problem.
   
   With an assumption, if some other new test is created and runs first, then this test will just start skipping and the 'dont load it to let it be removed if not used' effect the test verifies could be broken without noticing, unless someone spots the extra skip beginning to occur. Might as well not have a test at that point.
   
   Its a requirement for the test to exist that it be run before the first other test in the module to use it, but its not a reason to optionally run the test or not. We always want to run it, but should check the requirement was satisfied at the start, the same way the test checks it at the end currently.



-- 
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: gitbox-unsubscribe@activemq.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@activemq.apache.org
For additional commands, e-mail: gitbox-help@activemq.apache.org
For further information, visit: https://activemq.apache.org/contact



Re: [PR] ARTEMIS-5340 ensure PEM provider is truly optional [activemq-artemis]

Posted by "gemmellr (via GitHub)" <gi...@apache.org>.
gemmellr commented on code in PR #5547:
URL: https://github.com/apache/activemq-artemis/pull/5547#discussion_r1983217987


##########
artemis-core-client/src/main/java/org/apache/activemq/artemis/core/remoting/impl/ssl/SSLSupport.java:
##########
@@ -352,10 +354,15 @@ public static KeyStore loadKeystore(final String keystoreProvider,
       return ks;
    }
 
-   public static void checkPemProviderLoaded(String keystoreType) {
+   /**
+    * This method uses reflection to load the appropriate java.security.Provider for PEM use-cases. Reflection is used
+    * to avoid a hard dependency on the provider's implementation so that folks who don't use PEM don't have to include
+    * the corresponding dependency.
+    */
+   public static void checkPemProviderLoaded(String keystoreType) throws Exception {
       if (keystoreType != null && keystoreType.startsWith("PEM")) {
          if (Security.getProvider("PEM") == null) {
-            Security.insertProviderAt(new de.dentrassi.crypto.pem.PemKeyStoreProvider(),
+            Security.insertProviderAt((Provider) Class.forName(PEM_PROVIDER).getDeclaredConstructor().newInstance(),

Review Comment:
   You could instead just move the original line (with wrapped next part) into a static method in its own sibling class, e.g PEMSupport.loadProvider() and then call out to it. That should then just work as intended, even without using reflection, because that class would not be initialized unless executing the method and so the related classes/dependency would then also not be referenced.



-- 
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: gitbox-unsubscribe@activemq.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@activemq.apache.org
For additional commands, e-mail: gitbox-help@activemq.apache.org
For further information, visit: https://activemq.apache.org/contact



Re: [PR] ARTEMIS-5340 ensure PEM provider is truly optional [activemq-artemis]

Posted by "jbertram (via GitHub)" <gi...@apache.org>.
jbertram commented on code in PR #5547:
URL: https://github.com/apache/activemq-artemis/pull/5547#discussion_r1983496876


##########
artemis-core-client/src/main/java/org/apache/activemq/artemis/core/remoting/impl/ssl/SSLSupport.java:
##########
@@ -352,10 +354,15 @@ public static KeyStore loadKeystore(final String keystoreProvider,
       return ks;
    }
 
-   public static void checkPemProviderLoaded(String keystoreType) {
+   /**
+    * This method uses reflection to load the appropriate java.security.Provider for PEM use-cases. Reflection is used
+    * to avoid a hard dependency on the provider's implementation so that folks who don't use PEM don't have to include
+    * the corresponding dependency.
+    */
+   public static void checkPemProviderLoaded(String keystoreType) throws Exception {
       if (keystoreType != null && keystoreType.startsWith("PEM")) {
          if (Security.getProvider("PEM") == null) {
-            Security.insertProviderAt(new de.dentrassi.crypto.pem.PemKeyStoreProvider(),
+            Security.insertProviderAt((Provider) Class.forName(PEM_PROVIDER).getDeclaredConstructor().newInstance(),

Review Comment:
   I like that solution, @gemmellr.



-- 
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: gitbox-unsubscribe@activemq.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@activemq.apache.org
For additional commands, e-mail: gitbox-help@activemq.apache.org
For further information, visit: https://activemq.apache.org/contact



Re: [PR] ARTEMIS-5340 ensure PEM provider is truly optional [activemq-artemis]

Posted by "gtully (via GitHub)" <gi...@apache.org>.
gtully commented on code in PR #5547:
URL: https://github.com/apache/activemq-artemis/pull/5547#discussion_r1983152197


##########
artemis-core-client/src/main/java/org/apache/activemq/artemis/core/remoting/impl/ssl/SSLSupport.java:
##########
@@ -352,10 +354,15 @@ public static KeyStore loadKeystore(final String keystoreProvider,
       return ks;
    }
 
-   public static void checkPemProviderLoaded(String keystoreType) {
+   /**
+    * This method uses reflection to load the appropriate java.security.Provider for PEM use-cases. Reflection is used
+    * to avoid a hard dependency on the provider's implementation so that folks who don't use PEM don't have to include
+    * the corresponding dependency.
+    */
+   public static void checkPemProviderLoaded(String keystoreType) throws Exception {
       if (keystoreType != null && keystoreType.startsWith("PEM")) {
          if (Security.getProvider("PEM") == null) {
-            Security.insertProviderAt(new de.dentrassi.crypto.pem.PemKeyStoreProvider(),
+            Security.insertProviderAt((Provider) Class.forName(PEM_PROVIDER).getDeclaredConstructor().newInstance(),

Review Comment:
   it may make sense to use ClassLoadingUtils (with a type check) for consistency here. For some background see: https://issues.apache.org/jira/browse/ARTEMIS-4766



-- 
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: gitbox-unsubscribe@activemq.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@activemq.apache.org
For additional commands, e-mail: gitbox-help@activemq.apache.org
For further information, visit: https://activemq.apache.org/contact



Re: [PR] ARTEMIS-5340 ensure PEM provider is truly optional [activemq-artemis]

Posted by "jbertram (via GitHub)" <gi...@apache.org>.
jbertram commented on code in PR #5547:
URL: https://github.com/apache/activemq-artemis/pull/5547#discussion_r1987683614


##########
artemis-core-client/src/main/java/org/apache/activemq/artemis/core/remoting/impl/ssl/SSLSupport.java:
##########
@@ -352,11 +352,14 @@ public static KeyStore loadKeystore(final String keystoreProvider,
       return ks;
    }
 
-   public static void checkPemProviderLoaded(String keystoreType) {
+   /**
+    * This method calls out to a separate class in order to avoid a hard dependency on the provider's implementation.
+    * This allows folks who don't use PEM to avoid using the corresponding dependency.
+    */
+   public static void checkPemProviderLoaded(String keystoreType) throws Exception {

Review Comment:
   Removed!



-- 
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: gitbox-unsubscribe@activemq.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@activemq.apache.org
For additional commands, e-mail: gitbox-help@activemq.apache.org
For further information, visit: https://activemq.apache.org/contact



Re: [PR] ARTEMIS-5340 ensure PEM provider is truly optional [activemq-artemis]

Posted by "gemmellr (via GitHub)" <gi...@apache.org>.
gemmellr merged PR #5547:
URL: https://github.com/apache/activemq-artemis/pull/5547


-- 
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: gitbox-unsubscribe@activemq.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@activemq.apache.org
For additional commands, e-mail: gitbox-help@activemq.apache.org
For further information, visit: https://activemq.apache.org/contact



Re: [PR] ARTEMIS-5340 ensure PEM provider is truly optional [activemq-artemis]

Posted by "jbertram (via GitHub)" <gi...@apache.org>.
jbertram commented on code in PR #5547:
URL: https://github.com/apache/activemq-artemis/pull/5547#discussion_r1983982929


##########
artemis-core-client/src/test/java/org/apache/activemq/artemis/core/remoting/impl/netty/PemProviderTest.java:
##########
@@ -0,0 +1,64 @@
+/*
+ * 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.activemq.artemis.core.remoting.impl.netty;
+
+import java.util.Arrays;
+
+import de.dentrassi.crypto.pem.PemKeyStoreProvider;
+import org.apache.activemq.artemis.core.remoting.impl.ssl.SSLSupport;
+import org.junit.jupiter.api.Assumptions;
+import org.junit.jupiter.api.MethodOrderer.OrderAnnotation;
+import org.junit.jupiter.api.Order;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestMethodOrder;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+
+/**
+ * Order is important here because we don't want to load the PEM provider class before we test that it isn't loaded.
+ */
+@TestMethodOrder(OrderAnnotation.class)
+public class PemProviderTest {
+
+   static final String PEM_PROVIDER_PACKAGE = "de.dentrassi.crypto.pem";
+
+   @Test
+   @Order(1)
+   public void testPemProviderNotLoaded() {
+      // ensure the PEM provider wasn't already loaded by some other test
+      Assumptions.assumeFalse(Arrays.stream(ClassLoader.getSystemClassLoader().getDefinedPackages()).anyMatch(pkg -> PEM_PROVIDER_PACKAGE.equals(pkg.getName())));
+
+      // use a method from SSLSupport to force the JVM to load it as well as any hard dependencies it has
+      SSLSupport.parseCommaSeparatedListIntoArray("");
+
+      // verify the actual PEM provider class is not loaded; using a literal to avoid loading the actual package/class
+      assertNull(ClassLoader.getSystemClassLoader().getDefinedPackage(PEM_PROVIDER_PACKAGE));
+   }
+
+   /**
+    * This test simply verifies that we're using the right literal for the PEM provider implementation and that it does
+    * actually get loaded when referenced.
+    */
+   @Test
+   @Order(2)
+   public void testPemProviderPackageName() {
+      assertEquals(PEM_PROVIDER_PACKAGE, PemKeyStoreProvider.class.getPackageName());
+      assertNotNull(ClassLoader.getSystemClassLoader().getDefinedPackage(PEM_PROVIDER_PACKAGE));
+   }

Review Comment:
   I added a couple of new tests to verify loading keystores in addition to the static use.



-- 
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: gitbox-unsubscribe@activemq.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@activemq.apache.org
For additional commands, e-mail: gitbox-help@activemq.apache.org
For further information, visit: https://activemq.apache.org/contact



Re: [PR] ARTEMIS-5340 ensure PEM provider is truly optional [activemq-artemis]

Posted by "clebertsuconic (via GitHub)" <gi...@apache.org>.
clebertsuconic commented on PR #5547:
URL: https://github.com/apache/activemq-artemis/pull/5547#issuecomment-2704896632

   LGTM


-- 
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: gitbox-unsubscribe@activemq.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@activemq.apache.org
For additional commands, e-mail: gitbox-help@activemq.apache.org
For further information, visit: https://activemq.apache.org/contact



Re: [PR] ARTEMIS-5340 ensure PEM provider is truly optional [activemq-artemis]

Posted by "gemmellr (via GitHub)" <gi...@apache.org>.
gemmellr commented on code in PR #5547:
URL: https://github.com/apache/activemq-artemis/pull/5547#discussion_r1987060887


##########
artemis-core-client/src/main/java/org/apache/activemq/artemis/core/remoting/impl/ssl/SSLSupport.java:
##########
@@ -352,11 +352,14 @@ public static KeyStore loadKeystore(final String keystoreProvider,
       return ks;
    }
 
-   public static void checkPemProviderLoaded(String keystoreType) {
+   /**
+    * This method calls out to a separate class in order to avoid a hard dependency on the provider's implementation.
+    * This allows folks who don't use PEM to avoid using the corresponding dependency.
+    */
+   public static void checkPemProviderLoaded(String keystoreType) throws Exception {

Review Comment:
   Is the signature reallyneeded anymore, now the reflection is gone?



##########
artemis-core-client/src/main/java/org/apache/activemq/artemis/core/remoting/impl/ssl/SSLSupport.java:
##########
@@ -352,11 +352,14 @@ public static KeyStore loadKeystore(final String keystoreProvider,
       return ks;
    }
 
-   public static void checkPemProviderLoaded(String keystoreType) {
+   /**
+    * This method calls out to a separate class in order to avoid a hard dependency on the provider's implementation.
+    * This allows folks who don't use PEM to avoid using the corresponding dependency.
+    */
+   public static void checkPemProviderLoaded(String keystoreType) throws Exception {

Review Comment:
   Is the signature really needed anymore, now the reflection is gone?



-- 
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: gitbox-unsubscribe@activemq.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@activemq.apache.org
For additional commands, e-mail: gitbox-help@activemq.apache.org
For further information, visit: https://activemq.apache.org/contact



Re: [PR] ARTEMIS-5340 ensure PEM provider is truly optional [activemq-artemis]

Posted by "jbertram (via GitHub)" <gi...@apache.org>.
jbertram commented on code in PR #5547:
URL: https://github.com/apache/activemq-artemis/pull/5547#discussion_r1983496289


##########
artemis-core-client/src/test/java/org/apache/activemq/artemis/core/remoting/impl/netty/PEMProviderTest.java:
##########
@@ -0,0 +1,38 @@
+/*
+ * 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.activemq.artemis.core.remoting.impl.netty;
+
+import java.lang.reflect.Method;
+
+import org.apache.activemq.artemis.core.remoting.impl.ssl.SSLSupport;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertNull;
+
+public class PEMProviderTest {
+
+   @Test
+   public void testPEMProviderNotLoaded() throws Exception {
+      // use a method from SSLSupport to force the JVM to load it as well as any hard dependencies it has
+      SSLSupport.parseCommaSeparatedListIntoArray("");
+
+      // verify the actual PEM provider class is not loaded
+      Method findLoadedClassMethod = ClassLoader.class.getDeclaredMethod("findLoadedClass", String.class);
+      findLoadedClassMethod.setAccessible(true);
+      assertNull(findLoadedClassMethod.invoke(ClassLoader.getSystemClassLoader(), SSLSupport.PEM_PROVIDER));

Review Comment:
   Very nice!



-- 
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: gitbox-unsubscribe@activemq.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@activemq.apache.org
For additional commands, e-mail: gitbox-help@activemq.apache.org
For further information, visit: https://activemq.apache.org/contact



Re: [PR] ARTEMIS-5340 ensure PEM provider is truly optional [activemq-artemis]

Posted by "gemmellr (via GitHub)" <gi...@apache.org>.
gemmellr commented on code in PR #5547:
URL: https://github.com/apache/activemq-artemis/pull/5547#discussion_r1987666390


##########
artemis-core-client/src/main/java/org/apache/activemq/artemis/core/remoting/impl/ssl/SSLSupport.java:
##########
@@ -352,11 +352,14 @@ public static KeyStore loadKeystore(final String keystoreProvider,
       return ks;
    }
 
-   public static void checkPemProviderLoaded(String keystoreType) {
+   /**
+    * This method calls out to a separate class in order to avoid a hard dependency on the provider's implementation.
+    * This allows folks who don't use PEM to avoid using the corresponding dependency.
+    */
+   public static void checkPemProviderLoaded(String keystoreType) throws Exception {

Review Comment:
   Since it wasnt needed beforehand and unlike the earlier reflection based changes adding various bits that throw, nothing seemingly now changes in the method in a way that freshly throws a checked exception?



-- 
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: gitbox-unsubscribe@activemq.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@activemq.apache.org
For additional commands, e-mail: gitbox-help@activemq.apache.org
For further information, visit: https://activemq.apache.org/contact



Re: [PR] ARTEMIS-5340 ensure PEM provider is truly optional [activemq-artemis]

Posted by "gemmellr (via GitHub)" <gi...@apache.org>.
gemmellr commented on code in PR #5547:
URL: https://github.com/apache/activemq-artemis/pull/5547#discussion_r1983756559


##########
artemis-core-client/src/test/java/org/apache/activemq/artemis/core/remoting/impl/netty/PemProviderTest.java:
##########
@@ -0,0 +1,64 @@
+/*
+ * 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.activemq.artemis.core.remoting.impl.netty;
+
+import java.util.Arrays;
+
+import de.dentrassi.crypto.pem.PemKeyStoreProvider;
+import org.apache.activemq.artemis.core.remoting.impl.ssl.SSLSupport;
+import org.junit.jupiter.api.Assumptions;
+import org.junit.jupiter.api.MethodOrderer.OrderAnnotation;
+import org.junit.jupiter.api.Order;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestMethodOrder;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+
+/**
+ * Order is important here because we don't want to load the PEM provider class before we test that it isn't loaded.
+ */
+@TestMethodOrder(OrderAnnotation.class)
+public class PemProviderTest {
+
+   static final String PEM_PROVIDER_PACKAGE = "de.dentrassi.crypto.pem";
+
+   @Test
+   @Order(1)
+   public void testPemProviderNotLoaded() {
+      // ensure the PEM provider wasn't already loaded by some other test
+      Assumptions.assumeFalse(Arrays.stream(ClassLoader.getSystemClassLoader().getDefinedPackages()).anyMatch(pkg -> PEM_PROVIDER_PACKAGE.equals(pkg.getName())));

Review Comment:
   Would be better to make it an _assertion_ and let it fail when it needs to, to serve as notice the two tests are clashing and need to be ordered or isolated from each other to fix the problem.
   
   With an assumption, if some other new test is created and runs first, then this test will just start skipping and the 'dont load it to let it be removed if not used' effect the test verifies could be broken without noticing, unless someone spots the extra skip beginning to occur. Might as well not have a test at that point.
   
   Its a requirement for the test to exist that it be run before the first other test in the module to use it, bit its not a reason to optionally run the test or not. We always want to run it, but should check the requirement was satisfied at the start, the same way the test checks it at the end currently.



##########
artemis-core-client/src/test/java/org/apache/activemq/artemis/core/remoting/impl/netty/PemProviderTest.java:
##########
@@ -0,0 +1,64 @@
+/*
+ * 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.activemq.artemis.core.remoting.impl.netty;
+
+import java.util.Arrays;
+
+import de.dentrassi.crypto.pem.PemKeyStoreProvider;
+import org.apache.activemq.artemis.core.remoting.impl.ssl.SSLSupport;
+import org.junit.jupiter.api.Assumptions;
+import org.junit.jupiter.api.MethodOrderer.OrderAnnotation;
+import org.junit.jupiter.api.Order;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestMethodOrder;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+
+/**
+ * Order is important here because we don't want to load the PEM provider class before we test that it isn't loaded.
+ */
+@TestMethodOrder(OrderAnnotation.class)
+public class PemProviderTest {
+
+   static final String PEM_PROVIDER_PACKAGE = "de.dentrassi.crypto.pem";
+
+   @Test
+   @Order(1)
+   public void testPemProviderNotLoaded() {
+      // ensure the PEM provider wasn't already loaded by some other test
+      Assumptions.assumeFalse(Arrays.stream(ClassLoader.getSystemClassLoader().getDefinedPackages()).anyMatch(pkg -> PEM_PROVIDER_PACKAGE.equals(pkg.getName())));
+
+      // use a method from SSLSupport to force the JVM to load it as well as any hard dependencies it has
+      SSLSupport.parseCommaSeparatedListIntoArray("");
+
+      // verify the actual PEM provider class is not loaded; using a literal to avoid loading the actual package/class
+      assertNull(ClassLoader.getSystemClassLoader().getDefinedPackage(PEM_PROVIDER_PACKAGE));
+   }
+
+   /**
+    * This test simply verifies that we're using the right literal for the PEM provider implementation and that it does
+    * actually get loaded when referenced.
+    */
+   @Test
+   @Order(2)
+   public void testPemProviderPackageName() {
+      assertEquals(PEM_PROVIDER_PACKAGE, PemKeyStoreProvider.class.getPackageName());
+      assertNotNull(ClassLoader.getSystemClassLoader().getDefinedPackage(PEM_PROVIDER_PACKAGE));
+   }

Review Comment:
   I think a better test would be loading the provider the way its normally to be loaded, by using SSLSupport to load a pem keystore (the other test could also load a non-pem keystore to similarly check that does not load the pem provider), instead of just directly loading the class.
   
   The 'check the correct package is looked for' could still be done, just as the last thing the test does as a form of confirmation. Or it could be a third test.



-- 
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: gitbox-unsubscribe@activemq.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@activemq.apache.org
For additional commands, e-mail: gitbox-help@activemq.apache.org
For further information, visit: https://activemq.apache.org/contact



Re: [PR] ARTEMIS-5340 ensure PEM provider is truly optional [activemq-artemis]

Posted by "jbertram (via GitHub)" <gi...@apache.org>.
jbertram commented on code in PR #5547:
URL: https://github.com/apache/activemq-artemis/pull/5547#discussion_r1987446105


##########
artemis-core-client/src/main/java/org/apache/activemq/artemis/core/remoting/impl/ssl/SSLSupport.java:
##########
@@ -352,11 +352,14 @@ public static KeyStore loadKeystore(final String keystoreProvider,
       return ks;
    }
 
-   public static void checkPemProviderLoaded(String keystoreType) {
+   /**
+    * This method calls out to a separate class in order to avoid a hard dependency on the provider's implementation.
+    * This allows folks who don't use PEM to avoid using the corresponding dependency.
+    */
+   public static void checkPemProviderLoaded(String keystoreType) throws Exception {

Review Comment:
   I'm not following. Why wouldn't it be needed?



-- 
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: gitbox-unsubscribe@activemq.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@activemq.apache.org
For additional commands, e-mail: gitbox-help@activemq.apache.org
For further information, visit: https://activemq.apache.org/contact



Re: [PR] ARTEMIS-5340 ensure PEM provider is truly optional [activemq-artemis]

Posted by "brusdev (via GitHub)" <gi...@apache.org>.
brusdev commented on code in PR #5547:
URL: https://github.com/apache/activemq-artemis/pull/5547#discussion_r1982838917


##########
artemis-core-client/src/test/java/org/apache/activemq/artemis/core/remoting/impl/netty/PEMProviderTest.java:
##########
@@ -0,0 +1,38 @@
+/*
+ * 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.activemq.artemis.core.remoting.impl.netty;
+
+import java.lang.reflect.Method;
+
+import org.apache.activemq.artemis.core.remoting.impl.ssl.SSLSupport;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertNull;
+
+public class PEMProviderTest {
+
+   @Test
+   public void testPEMProviderNotLoaded() throws Exception {
+      // use a method from SSLSupport to force the JVM to load it as well as any hard dependencies it has
+      SSLSupport.parseCommaSeparatedListIntoArray("");
+
+      // verify the actual PEM provider class is not loaded
+      Method findLoadedClassMethod = ClassLoader.class.getDeclaredMethod("findLoadedClass", String.class);
+      findLoadedClassMethod.setAccessible(true);
+      assertNull(findLoadedClassMethod.invoke(ClassLoader.getSystemClassLoader(), SSLSupport.PEM_PROVIDER));

Review Comment:
   An alternative to avoid `--add-opens java.base/java.lang=ALL-UNNAMED` is to check for the defined packages, i.e.
   ```suggestion
         assertNull(ClassLoader.getSystemClassLoader().getDefinedPackage("de.dentrassi.crypto.pem"));
   ```



-- 
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: gitbox-unsubscribe@activemq.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@activemq.apache.org
For additional commands, e-mail: gitbox-help@activemq.apache.org
For further information, visit: https://activemq.apache.org/contact



Re: [PR] ARTEMIS-5340 ensure PEM provider is truly optional [activemq-artemis]

Posted by "jbertram (via GitHub)" <gi...@apache.org>.
jbertram commented on code in PR #5547:
URL: https://github.com/apache/activemq-artemis/pull/5547#discussion_r1983982167


##########
artemis-core-client/src/test/java/org/apache/activemq/artemis/core/remoting/impl/netty/PemProviderTest.java:
##########
@@ -0,0 +1,64 @@
+/*
+ * 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.activemq.artemis.core.remoting.impl.netty;
+
+import java.util.Arrays;
+
+import de.dentrassi.crypto.pem.PemKeyStoreProvider;
+import org.apache.activemq.artemis.core.remoting.impl.ssl.SSLSupport;
+import org.junit.jupiter.api.Assumptions;
+import org.junit.jupiter.api.MethodOrderer.OrderAnnotation;
+import org.junit.jupiter.api.Order;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestMethodOrder;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+
+/**
+ * Order is important here because we don't want to load the PEM provider class before we test that it isn't loaded.
+ */
+@TestMethodOrder(OrderAnnotation.class)
+public class PemProviderTest {
+
+   static final String PEM_PROVIDER_PACKAGE = "de.dentrassi.crypto.pem";
+
+   @Test
+   @Order(1)
+   public void testPemProviderNotLoaded() {
+      // ensure the PEM provider wasn't already loaded by some other test
+      Assumptions.assumeFalse(Arrays.stream(ClassLoader.getSystemClassLoader().getDefinedPackages()).anyMatch(pkg -> PEM_PROVIDER_PACKAGE.equals(pkg.getName())));

Review Comment:
   Done.



-- 
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: gitbox-unsubscribe@activemq.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@activemq.apache.org
For additional commands, e-mail: gitbox-help@activemq.apache.org
For further information, visit: https://activemq.apache.org/contact