Skip to content

Commit 9d25674

Browse files
ssl bug fix and tests
1 parent 8c9f410 commit 9d25674

File tree

6 files changed

+53
-8
lines changed

6 files changed

+53
-8
lines changed

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jdk/JmxClientFeature.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,8 @@ private static void configureReflection(BeforeAnalysisAccess access) {
6161
RuntimeReflection.register(access.findClassByName("com.sun.jndi.url.rmi.rmiURLContextFactory"));
6262
RuntimeReflection.register(access.findClassByName("sun.rmi.server.UnicastRef"));
6363

64-
RuntimeReflection.register(access.findClassByName("sun.rmi.server.UnicastRef").getMethods());
65-
6664
RuntimeReflection.register(access.findClassByName("com.sun.jndi.url.rmi.rmiURLContextFactory").getConstructors());
6765
RuntimeReflection.register(access.findClassByName("sun.rmi.server.UnicastRef").getConstructors());
66+
RuntimeReflection.register(access.findClassByName("sun.rmi.server.UnicastRef2").getConstructors());
6867
}
6968
}

substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jmx/JmxTest.java

Lines changed: 45 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import static org.junit.Assert.assertTrue;
2929
import static org.junit.Assume.assumeTrue;
3030

31+
import java.io.File;
3132
import java.io.IOException;
3233
import java.lang.management.ClassLoadingMXBean;
3334
import java.lang.management.ManagementFactory;
@@ -39,9 +40,13 @@
3940
import java.lang.management.GarbageCollectorMXBean;
4041
import java.lang.management.MemoryPoolMXBean;
4142
import java.lang.management.MemoryUsage;
43+
import java.nio.file.Files;
44+
import java.nio.file.attribute.PosixFilePermission;
4245
import java.util.HashMap;
43-
import java.util.List;
46+
import java.util.HashSet;
4447
import java.util.Map;
48+
import java.util.Set;
49+
import java.util.List;
4550

4651
import jdk.management.jfr.FlightRecorderMXBean;
4752
import org.graalvm.nativeimage.ImageInfo;
@@ -58,24 +63,55 @@
5863
import javax.management.remote.JMXConnector;
5964
import javax.management.remote.JMXConnectorFactory;
6065
import javax.management.remote.JMXServiceURL;
66+
import javax.rmi.ssl.SslRMIClientSocketFactory;
67+
6168
import org.junit.Assert;
6269

6370
@AddExports("jdk.management.agent/jdk.internal.agent")
6471
public class JmxTest {
6572
static final String PORT_PROPERTY = "com.sun.management.jmxremote.port";
73+
static final String RMI_PORT_PROPERTY = "com.sun.management.jmxremote.rmi.port";
6674
static final String AUTH_PROPERTY = "com.sun.management.jmxremote.authenticate";
75+
static final String CLIENT_AUTH_PROPERTY = "com.sun.management.jmxremote.ssl.need.client.auth";
76+
static final String ACCESS_PROPERTY = "com.sun.management.jmxremote.access.file";
77+
static final String PASSWORD_PROPERTY = "com.sun.management.jmxremote.password.file";
6778
static final String SSL_PROPERTY = "com.sun.management.jmxremote.ssl";
79+
static final String KEYSTORE_PROPERTY = "javax.net.ssl.keyStore";
80+
static final String KEYSTORE_PASSWORD_PROPERTY = "javax.net.ssl.keyStorePassword";
81+
static final String TRUSTSTORE_PROPERTY = "javax.net.ssl.trustStore";
82+
static final String TRUSTSTORE_PASSWORD_PROPERTY = "javax.net.ssl.trustStorePassword";
83+
static final String REGISTRY_SSL_PROPERTY = "com.sun.management.jmxremote.registry.ssl";
6884
static final String TEST_PORT = "12345";
69-
static final String FALSE = "false";
85+
static final String TRUE = "true";
86+
static final String JMX_REMOTE_RESOURCES = "src/com.oracle.svm.test/src/com/oracle/svm/test/jmx/jmxremoteresources";
7087

7188
@BeforeClass
72-
public static void checkForJFR() {
89+
public static void checkForJFR() throws IOException {
7390
assumeTrue("skipping JMX tests", !ImageInfo.inImageCode() ||
7491
(VMInspectionOptions.hasJmxClientSupport() && VMInspectionOptions.hasJmxServerSupport()));
7592

7693
System.setProperty(PORT_PROPERTY, TEST_PORT);
77-
System.setProperty(AUTH_PROPERTY, FALSE);
78-
System.setProperty(SSL_PROPERTY, FALSE);
94+
System.setProperty(RMI_PORT_PROPERTY, TEST_PORT);
95+
System.setProperty(AUTH_PROPERTY, TRUE);
96+
System.setProperty(CLIENT_AUTH_PROPERTY, TRUE);
97+
System.setProperty(SSL_PROPERTY, TRUE);
98+
System.setProperty(REGISTRY_SSL_PROPERTY, TRUE);
99+
// The following are dummy password access, and SSL files required for testing
100+
// authentication and SSL.
101+
System.setProperty(ACCESS_PROPERTY, JMX_REMOTE_RESOURCES + "/jmxremote.access");
102+
System.setProperty(PASSWORD_PROPERTY, JMX_REMOTE_RESOURCES + "/jmxremote.password");
103+
System.setProperty(KEYSTORE_PROPERTY, JMX_REMOTE_RESOURCES + "/clientkeystore");
104+
System.setProperty(KEYSTORE_PASSWORD_PROPERTY, "clientpass");
105+
System.setProperty(TRUSTSTORE_PROPERTY, JMX_REMOTE_RESOURCES + "/servertruststore");
106+
System.setProperty(TRUSTSTORE_PASSWORD_PROPERTY, "servertrustpass");
107+
108+
// Password file must have restricted access.
109+
File file = new File(JMX_REMOTE_RESOURCES + "/jmxremote.password");
110+
Set<PosixFilePermission> perms = new HashSet<>();
111+
perms.add(PosixFilePermission.OWNER_READ);
112+
perms.add(PosixFilePermission.OWNER_WRITE);
113+
Files.setPosixFilePermissions(file.toPath(), perms);
114+
79115
try {
80116
// We need to rerun the startup hook with the correct properties set.
81117
ManagementAgentStartupHook startupHook = new ManagementAgentStartupHook();
@@ -89,7 +125,10 @@ private static MBeanServerConnection getLocalMBeanServerConnectionStatic() {
89125
try {
90126
JMXServiceURL jmxUrl = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://" + "localhost" + ":" + TEST_PORT + "/jmxrmi");
91127
Map<String, Object> env = new HashMap<>();
92-
128+
String[] credentials = {"myrole", "MYP@SSWORD"}; // dummy password for testing
129+
env.put(JMXConnector.CREDENTIALS, credentials);
130+
// Include below if protecting registry with SSL
131+
env.put("com.sun.jndi.rmi.factory.socket", new SslRMIClientSocketFactory());
93132
JMXConnector connector = JMXConnectorFactory.connect(jmxUrl, env);
94133
return connector.getMBeanServerConnection();
95134
} catch (IOException e) {
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
myrole readwrite
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# The passwords in this file are hashed.
2+
# In order to change the password for a role, replace the hashed password entry
3+
# with a clear text password or a new hashed password. If the new password is in clear,
4+
# it will be replaced with its hash when a new login attempt is made.
5+
6+
myrole GfD4DqNr5DUGl/kAREAAInPST5FKFI5i8lRpkscwOLC/sf5U25M8zn5ppOJGOAE6cOMPrgy3o+9f2PyL2PkE7w== m4maFV8JvmL1kByz6gLLiWSdYgtb1ezEfPseDllMwnGmWFBT6jquuxqa9pqrSmpBdMGfxa9gYdCecffS29XSXQ== SHA3-512

0 commit comments

Comments
 (0)