Package ghidra.framework.client
Class ClientUtil
java.lang.Object
ghidra.framework.client.ClientUtil
ClientUtil
allows a user to connect to a Repository Server and obtain its handle.-
Method Summary
Modifier and TypeMethodDescriptionstatic void
changePassword
(Component parent, RepositoryServerHandle handle, String serverInfo) Prompt user and change password on server (not initiated by user).static void
checkGhidraServer
(String host, int port, TaskMonitor monitor) Connect to a Ghidra Server and verify compatibility.static void
clearRepositoryAdapter
(String host, int port) Eliminate the specified repository server from the connection cachestatic ClientAuthenticator
Get the currently installed client authenticator.static RepositoryServerAdapter
getRepositoryServer
(String host, int port) Connect to a Repository Server and obtain a handle to it.static RepositoryServerAdapter
getRepositoryServer
(String host, int port, boolean forceConnect) Connect to a Repository Server and obtain a handle to it.static String
Returns default user login name.static void
handleException
(RepositoryAdapter repository, Exception exc, String operation, boolean mustRetry, Component parent) Displays an error dialog appropriate for the given exception.static void
handleException
(RepositoryAdapter repository, Exception exc, String operation, Component parent) Displays an error dialog appropriate for the given exception.static boolean
isConnected
(String host, int port) Determine if a connectedRepositoryServerAdapter
already exists for the specified server.static boolean
static void
promptForReconnect
(RepositoryAdapter repository, Component parent) Prompt the user to reconnect to the Ghidra Server.static void
setClientAuthenticator
(ClientAuthenticator authenticator) Set client authenticator
-
Method Details
-
setClientAuthenticator
Set client authenticator- Parameters:
authenticator
- client authenticator instance
-
getClientAuthenticator
Get the currently installed client authenticator. If one has not been installed, this will trigger the installation of a default instance.- Returns:
- current client authenticator
-
getRepositoryServer
Connect to a Repository Server and obtain a handle to it. Based upon the server authentication requirements, the user may be prompted for a password via a Swing dialog. If a previous connection attempt to this server failed, the adapter may be returned in a disconnected state.- Parameters:
host
- server name or addressport
- server port, 0 indicates that default port should be used.- Returns:
- repository server adapter
-
getRepositoryServer
public static RepositoryServerAdapter getRepositoryServer(String host, int port, boolean forceConnect) Connect to a Repository Server and obtain a handle to it. Based upon the server authentication requirements, the user may be prompted for a password via a Swing dialog.- Parameters:
host
- server name or addressport
- server port, 0 indicates that default port should be used.forceConnect
- if true and the server adapter is disconnected, an attempt will be made to reconnect.- Returns:
- repository server handle
-
isConnected
Determine if a connectedRepositoryServerAdapter
already exists for the specified server.- Parameters:
host
- server name or addressport
- server port, 0 indicates that default port applies.- Returns:
- true if connection already exists, else false
-
clearRepositoryAdapter
Eliminate the specified repository server from the connection cache- Parameters:
host
- host name or IP addressport
- port (0: use default port)
-
getUserName
Returns default user login name. Actual user name used by repository should be obtained from RepositoryServerAdapter.getUser- Returns:
- default user name
-
handleException
public static void handleException(RepositoryAdapter repository, Exception exc, String operation, boolean mustRetry, Component parent) Displays an error dialog appropriate for the given exception. If the exception is a ConnectException or NotConnectedException, a prompt to reconnect to the Ghidra Server is displayed.- Parameters:
repository
- may be null if the exception is not a RemoteExceptionexc
- exception that occurredoperation
- operation that was being done when the exception occurred; this string is be used in the message for the error dialog if one should be displayedmustRetry
- true if the message should state that the user should retry the operation because it may not have succeeded (if the exception was because a RemoteException); there may be cases where the operation succeeded; as a result of the operation, a bad connection to the server was detected (e.g., save a file). Note: this parameter is ignored if the exception is not a ConnectException or NotConnectedException.parent
- parent of the error dialog
-
handleException
public static void handleException(RepositoryAdapter repository, Exception exc, String operation, Component parent) Displays an error dialog appropriate for the given exception. If the exception is a ConnectException or NotConnectedException, a prompt to reconnect to the Ghidra Server is displayed. The message states that the operation may have to be retried due to the failed connection.- Parameters:
repository
- may be null if the exception is not a RemoteExceptionexc
- exception that occurredoperation
- operation that was being done when the exception occurred; this string is be used in the message for the error dialog if one should be displayedparent
- parent of the error dialog
-
promptForReconnect
Prompt the user to reconnect to the Ghidra Server.- Parameters:
repository
- repository to connect toparent
- parent of the dialog
-
checkGhidraServer
public static void checkGhidraServer(String host, int port, TaskMonitor monitor) throws IOException, CancelledException Connect to a Ghidra Server and verify compatibility. This method can be used to effectively "ping" the Ghidra Server to verify the ability to connect. NOTE: Use of this method when PKI authentication is enabled is not supported.- Parameters:
host
- server hostnameport
- first Ghidra Server port (0=use default)monitor
- cancellable monitor- Throws:
IOException
- thrown if an IO Error occurs (e.g., server not found).RemoteException
- if server interface is incompatible or another server-side error occurs.CancelledException
- if connection attempt was cancelled
-
changePassword
public static void changePassword(Component parent, RepositoryServerHandle handle, String serverInfo) throws IOException Prompt user and change password on server (not initiated by user).- Parameters:
parent
- dialog parenthandle
- server handleserverInfo
- server information- Throws:
IOException
- if error occurs while updating password
-
isSSHKeyAvailable
public static boolean isSSHKeyAvailable()
-