public class ServerConnection extends Object
| Constructor and Description |
|---|
ServerConnection(Socket s)
Creates a new
ServerConnection that will communicate
with the client over the given Socket. |
ServerConnection(Socket s,
DSAPrivateKey dsa_key,
RSAPrivateKey rsa_key)
Creates a new
ServerConnection that will communicate
with the client over the given Socket. |
ServerConnection(Socket s,
String softwareversion) |
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Close the connection to the SSH-2 server.
|
void |
close(Throwable t,
boolean hard) |
void |
connect()
Establish the connection and block until the first handshake has completed.
|
void |
connect(int timeout_milliseconds)
Establish the connection and block until the first handshake has completed.
|
void |
forceKeyExchange()
Force an asynchronous key re-exchange (the call does not block).
|
ConnectionInfo |
getConnectionInfo()
Returns a
ConnectionInfo object containing the details of
the connection. |
Socket |
getSocket()
Retrieve the underlying socket.
|
void |
setAuthenticationCallback(ServerAuthenticationCallback cb)
Callback interface with methods that will be called upon authentication events.
|
void |
setDsaHostKey(DSAPrivateKey dsa_hostkey)
Change the current DSA hostkey.
|
void |
setPEMHostKey(char[] pemdata,
String password)
Utility method that loads a PEM based hostkey (either RSA or DSA based) and
calls either
setRsaHostKey() or setDsaHostKey(). |
void |
setPEMHostKey(File pemFile,
String password)
Utility method that loads a hostkey from a PEM file (either RSA or DSA based) and
calls either
setRsaHostKey() or setDsaHostKey(). |
void |
setRsaHostKey(RSAPrivateKey rsa_hostkey)
Change the current RSA hostkey.
|
void |
setServerConnectionCallback(ServerConnectionCallback cb)
Callback interface with methods that will be called upon events
generated by the client (e.g., client opens a new Session which results in a
ServerSession). |
public ServerConnection(Socket s)
ServerConnection that will communicate
with the client over the given Socket.
Note: you need to call connect() or connect(int) to
perform the initial handshake and establish the encrypted communication.
s - The socketconnect(int)public ServerConnection(Socket s, DSAPrivateKey dsa_key, RSAPrivateKey rsa_key)
ServerConnection that will communicate
with the client over the given Socket.
Note: you need to call connect() or connect(int) to
perform the initial handshake and establish the encrypted communication.
Please read the javadoc for the connect(int) method.
s - The socketdsa_key - The DSA hostkey, may be NULLrsa_key - The RSA hostkey, may be NULLconnect(int)public void connect()
throws IOException
Note: this is a wrapper that calls connect(0) (i.e., connect with no timeout).
Please read the javadoc for the connect(int) method.
IOExceptionconnect(int)public void connect(int timeout_milliseconds)
throws IOException
Note 1: either a DSA or a RSA (or both) hostkey must be set before calling this method.
Note 2: You must set the callbacks for authentication (setAuthenticationCallback(ServerAuthenticationCallback))
and connection events (setServerConnectionCallback(ServerConnectionCallback)).
timeout_milliseconds - Timeout in milliseconds, 0 means no timeout.IOExceptionsetPEMHostKey(char[], String),
setPEMHostKey(File, String),
setRsaHostKey(RSAPrivateKey),
setDsaHostKey(DSAPrivateKey)public Socket getSocket()
public void forceKeyExchange()
throws IOException
Note: This implementation will never start automatically a key exchange (other than the initial one) unless you or the connected SSH-2 client ask for it.
IOException - In case of any failure behind the scenes.public ConnectionInfo getConnectionInfo() throws IOException
ConnectionInfo object containing the details of
the connection. May be called as soon as the first key exchange has been
started. The method blocks in case the first key exchange has not been completed.
Note: upon return of this method, authentication may still be pending.
ConnectionInfo object.IOException - In case of any failure behind the scenes; e.g., first key exchange was aborted.public void setDsaHostKey(DSAPrivateKey dsa_hostkey)
Note: You can change an existing DSA hostkey after the initial kex exchange (the new value will
be used during the next server initiated key exchange), but you cannot remove (i.e., set to null) the
current DSA key, otherwise the next key exchange may fail in case the client supports only DSA hostkeys.
dsa_hostkey - public void setRsaHostKey(RSAPrivateKey rsa_hostkey)
Note: You can change an existing RSA hostkey after the initial kex exchange (the new value will
be used during the next server initiated key exchange), but you cannot remove (i.e., set to null) the
current RSA key, otherwise the next key exchange may fail in case the client supports only RSA hostkeys.
rsa_hostkey - public void setPEMHostKey(char[] pemdata,
String password)
throws IOException
setRsaHostKey() or setDsaHostKey().pemdata - The PEM datapassword - Password, may be null in case the PEM data is not password protectedIOException - In case of any error.public void setPEMHostKey(File pemFile, String password) throws IOException
setRsaHostKey() or setDsaHostKey().pemFile - The PEM filepassword - Password, may be null in case the PEM file is not password protectedIOExceptionpublic void setServerConnectionCallback(ServerConnectionCallback cb)
ServerSession).
Note: This must be set before the first handshake.
cb - The callback implementationpublic void setAuthenticationCallback(ServerAuthenticationCallback cb)
Note: This must be set before the first handshake.
cb - The callback implementationpublic void close()
public void close(Throwable t, boolean hard)
Copyright © 2014. All Rights Reserved.