GT-2685 Improved Ghidra Server interface binding and remote address

identification.  Minor fixes to database cleanup and project conversion.
This commit is contained in:
ghidra1
2019-05-30 19:22:46 -04:00
parent 8495cc68ee
commit 17bb619048
15 changed files with 268 additions and 211 deletions

View File

@@ -217,7 +217,7 @@ public class ClientUtil {
excMsg = exc.toString();
}
if (exc instanceof IOException) {
Msg.showError(ClientUtil.class, parent, title, excMsg);
Msg.showError(ClientUtil.class, parent, title, excMsg, exc);
}
else {
// show the stacktrace for non-IOException

View File

@@ -16,7 +16,6 @@
package ghidra.framework.client;
import java.io.IOException;
import java.net.*;
import java.net.UnknownHostException;
import java.rmi.*;
import java.rmi.registry.LocateRegistry;
@@ -124,15 +123,16 @@ class ServerConnectTask extends Task {
return name;
}
private static void setOutgoingIpAddress(InetAddress destAddr, int serverPort)
throws IOException {
InetSocketAddress sockAddr = new InetSocketAddress(destAddr, serverPort);
Socket s = new Socket();
s.connect(sockAddr, 5000);
String ip = s.getLocalAddress().getHostAddress();
System.setProperty("java.rmi.server.hostname", ip);
s.close();
}
// private static void setOutgoingIpAddress(InetAddress destAddr, int serverPort)
// throws IOException {
// // TODO: this may not be needed since we do not create remote objects on the client
// InetSocketAddress sockAddr = new InetSocketAddress(destAddr, serverPort);
// Socket s = new Socket();
// s.connect(sockAddr, 5000);
// String ip = s.getLocalAddress().getHostAddress();
// System.setProperty("java.rmi.server.hostname", ip);
// s.close();
// }
private static boolean isSSLHandshakeCancelled(SSLHandshakeException e) throws IOException {
if (e.getMessage().indexOf("bad_certificate") > 0) {
@@ -158,9 +158,7 @@ class ServerConnectTask extends Task {
*/
public static GhidraServerHandle getGhidraServerHandle(ServerInfo server) throws IOException {
setOutgoingIpAddress(InetAddress.getByName(server.getServerName()), server.getPortNumber());
Registry reg = LocateRegistry.getRegistry(server.getServerName(), server.getPortNumber());
checkServerBindNames(reg);
// setOutgoingIpAddress(InetAddress.getByName(server.getServerName()), server.getPortNumber());
GhidraServerHandle gsh = null;
try {
@@ -170,6 +168,18 @@ class ServerConnectTask extends Task {
// for their keystore which should cancel any connection attempt
testServerSSLConnection(server);
Registry reg;
try {
// attempt to connect with older Ghidra Server registry without using SSL/TLS
reg = LocateRegistry.getRegistry(server.getServerName(), server.getPortNumber());
checkServerBindNames(reg);
}
catch (IOException e) {
reg = LocateRegistry.getRegistry(server.getServerName(), server.getPortNumber(),
new SslRMIClientSocketFactory());
checkServerBindNames(reg);
}
gsh = (GhidraServerHandle) reg.lookup(GhidraServerHandle.BIND_NAME);
gsh.checkCompatibility(GhidraServerHandle.INTERFACE_VERSION);
}

View File

@@ -229,9 +229,8 @@ public class PrivateDatabase extends Database {
/**
* If a cumulative change files exists, it will be deleted.
* @throws IOException
* @throws CancelledException
*/
public void updateCheckoutCopy() throws CancelledException, IOException {
public void updateCheckoutCopy() throws IOException {
if (!isCheckOutCopy) {
throw new IOException("Database is not a checkout copy");
}

View File

@@ -469,6 +469,21 @@ public class LocalDatabaseItem extends LocalFolderItem implements DatabaseItem {
}
}
@Override
public void clearCheckout() throws IOException {
if (isVersioned) {
throw new UnsupportedOperationException(
"clearCheckout is not applicable to versioned item");
}
if (fileSystem.isReadOnly()) {
throw new ReadOnlyException();
}
synchronized (fileSystem) {
privateDb.updateCheckoutCopy(); // removes change data
super.clearCheckout();
}
}
/*
* @see ghidra.framework.store.local.LocalFolderItem#deleteCurrentVersion()
*/