Skip to content

Commit 0d711ea

Browse files
committed
GP-6426 Resolved Ghidra Server hostname check issue related to
self-signed certificate (Closes #8940)
1 parent 8cf4319 commit 0d711ea

File tree

2 files changed

+48
-11
lines changed

2 files changed

+48
-11
lines changed

Ghidra/Features/GhidraServer/src/main/java/ghidra/server/remote/GhidraServer.java

Lines changed: 41 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@
2525
import java.rmi.registry.Registry;
2626
import java.rmi.server.*;
2727
import java.security.cert.CertificateException;
28-
import java.util.Enumeration;
29-
import java.util.List;
28+
import java.util.*;
3029

3130
import javax.rmi.ssl.SslRMIClientSocketFactory;
3231
import javax.rmi.ssl.SslRMIServerSocketFactory;
@@ -752,11 +751,49 @@ else if (s.equals("-autoProvision")) {
752751
// Ensure that remote access hostname is properly set for RMI registration
753752
String hostname = initRemoteAccessHostname();
754753

755-
if (DefaultKeyManagerFactory.getPreferredKeyStore() == null) {
754+
log.info("Ghidra Server " + Application.getApplicationVersion());
755+
log.info(" Server remote access address: " + hostname);
756+
if (bindAddress == null) {
757+
log.info(" Server listening on all interfaces");
758+
}
759+
else {
760+
log.info(" Server listening on interface: " + bindAddress.getHostAddress());
761+
}
762+
763+
String preferredKeyStore = DefaultKeyManagerFactory.getPreferredKeyStore();
764+
if (preferredKeyStore == null) {
765+
756766
// keystore has not been identified - use self-signed certificate
767+
log.info(" Generating self-signed certificate...");
768+
log.info(" Subject Alternative Names:");
769+
log.info(" " + hostname);
770+
757771
DefaultKeyManagerFactory.setDefaultIdentity(new X500Principal("CN=GhidraServer"));
758772
DefaultKeyManagerFactory.addSubjectAlternativeName(hostname);
773+
774+
// Collect alternate hostnames for inclusion in certificate
775+
Set<String> altNames = new TreeSet<>();
776+
Enumeration<NetworkInterface> nets = NetworkInterface.getNetworkInterfaces();
777+
while (nets.hasMoreElements()) {
778+
NetworkInterface netint = nets.nextElement();
779+
Enumeration<InetAddress> addrs = netint.getInetAddresses();
780+
while (addrs.hasMoreElements()) {
781+
InetAddress addr = addrs.nextElement();
782+
altNames.add(addr.getHostAddress());
783+
altNames.add(addr.getHostName());
784+
altNames.add(addr.getCanonicalHostName());
785+
}
786+
}
787+
altNames.remove(hostname);
788+
for (String name : altNames) {
789+
log.info(" " + name);
790+
DefaultKeyManagerFactory.addSubjectAlternativeName(name);
791+
}
792+
}
793+
else {
794+
log.info(" Using server certificate keystore: " + preferredKeyStore);
759795
}
796+
760797
if (!DefaultKeyManagerFactory.initialize()) {
761798
log.fatal("Failed to initialize PKI/SSL keystore");
762799
System.exit(0);
@@ -769,14 +806,7 @@ else if (s.equals("-autoProvision")) {
769806
// localhost.getCanonicalHostName() + ":" + classSvrPort + "/";
770807
// System.setProperty(RMI_CODEBASE_PROPERTY, codeBaseProp);
771808

772-
log.info("Ghidra Server " + Application.getApplicationVersion());
773-
log.info(" Server remote access address: " + hostname);
774-
if (bindAddress == null) {
775-
log.info(" Server listening on all interfaces");
776-
}
777-
else {
778-
log.info(" Server listening on interface: " + bindAddress.getHostAddress());
779-
}
809+
780810
log.info(" RMI Registry port: " + ServerPortFactory.getRMIRegistryPort());
781811
log.info(" RMI SSL port: " + ServerPortFactory.getRMISSLPort());
782812
log.info(" Block Stream port: " + ServerPortFactory.getStreamPort());

Ghidra/RuntimeScripts/Common/support/launch.properties

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,13 @@ VMARGS=-Djdk.tls.client.protocols=TLSv1.2,TLSv1.3
5151
#
5252
#VMARGS=-Djavax.net.debug=ssl
5353

54+
# When using Java 21.0.10 or later and connecting to an older Ghidra Server (pre-12.0.3) the following
55+
# connection error may occur.
56+
# ... SSLHandshakeException: (certificate_unknown) No matching <name> found
57+
# If unable to upgrade your Ghidra Server this property setting may be uncommented to disable the
58+
# hostname check.
59+
#VMARGS=-Djdk.rmi.ssl.client.enableEndpointIdentification=false
60+
5461
# The following property will limit the number of processor cores that Ghidra
5562
# will use for thread pools. If not specified, it will use the default number
5663
# of processors returned from Runtime.getRuntime().getAvailableProcessors().

0 commit comments

Comments
 (0)