Package com.jcraft.jsch
Class Session
java.lang.Object
com.jcraft.jsch.Session
- All Implemented Interfaces:
Runnable
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate classprivate class -
Field Summary
FieldsModifier and TypeFieldDescription(package private) boolean(package private) int(package private) Buffer(package private) static final intprivate Cipherprivate intprivate MAC(package private) int[]private Hashtableprivate Threadprotected booleanprivate Compressionprivate byte[]private byte[]private Session.GlobalRequestReply(package private) String[](package private) Stringprivate HostKeyprivate Stringprivate HostKeyRepositoryprivate byte[]private byte[]private IdentityRepository(package private) InputStreamprivate booleanprivate booleanprivate Compressionprivate IOprivate booleanprivate booleanprivate byte[]private byte[](package private) JSchprivate byte[]private static final byte[]private longprivate Objectprivate byte[]private byte[](package private) intprivate static final byte[](package private) String(package private) OutputStream(package private) Packetprivate static final int(package private) byte[](package private) intprivate Proxy(package private) static Randomprivate Cipherprivate intprivate MACprivate byte[]private byte[]private intprivate intprivate intprivate intprivate byte[]private Socket(package private) SocketFactory(package private) static final int(package private) static final int(package private) static final int(package private) static final int(package private) static final int(package private) static final int(package private) static final int(package private) static final int(package private) static final int(package private) static final int(package private) static final int(package private) static final int(package private) static final int(package private) static final int(package private) static final int(package private) static final int(package private) static final int(package private) static final int(package private) static final int(package private) static final int(package private) static final int(package private) static final int(package private) static final int(package private) static final int(package private) static final int(package private) static final int(package private) static final int(package private) static final int(package private) Runnableprivate int(package private) int[]private UserInfo(package private) Stringprivate byte[]private byte[](package private) boolean -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate int_setPortForwardingR(String bind_address, int rport) private void(package private) voidaddChannel(Channel channel) private voidprivate voidapplyConfigChannel(ChannelSession channel) (package private) static booleancheckCipher(String cipher) private String[]checkCiphers(String ciphers) private voidcheckConfig(ConfigRepository.Config config, String key) private voidcheckHost(String chost, int port, KeyExchange kex) (package private) static booleanprivate String[]checkKexes(String kexes) private String[]checkSignatures(String sigs) voidconnect()voidconnect(int connectTimeout) voiddelPortForwardingL(int lport) Cancels the local port forwarding assigned at local TCP portlporton loopback interface.voiddelPortForwardingL(String bind_address, int lport) Cancels the local port forwarding assigned at local TCP portlportonbind_addressinterface.voiddelPortForwardingR(int rport) Cancels the remote port forwarding assigned at remote TCP portrport.voiddelPortForwardingR(String bind_address, int rport) Cancels the remote port forwarding assigned at remote TCP portrportbound on the interface atbind_address.voidvoidprivate byte[]getHost()Gets the hostkeyRepository.(package private) IdentityRepositoryGets the identityRepository.intgetPort()String[]Lists the registered local port forwarding.String[]Lists the registered remote port forwarding.intReturns setting for the threshold to send keep-alive messages.intReturns setting for the interval to send a keep-alive message.(package private) byte[]getStreamForwarder(String host, int port) Instantiates an instance of stream-forwarder tohost:port.intprivate voidinitDeflater(String method) private voidinitInflater(String method) booleanvoidopenChannel(String type) private Session.ForwardingparseForwarding(String conf) The given argument may be "[bind_address:]port:host:hostport" or "[bind_address:]port host:hostport", which is from LocalForward command of ~/.ssh/config .private KeyExchangereceive_kexinit(Buffer buf) private voidreceive_newkeys(Buffer buf, KeyExchange kex) voidrekey()private voidvoidrun()private voidprivate voidvoidvoidvoidvoidvoidvoidsetConfig(Properties newconf) voidsetDaemonThread(boolean enable) voidvoidsetHostKeyAlias(String hostKeyAlias) voidsetHostKeyRepository(HostKeyRepository hostkeyRepository) Sets the hostkeyRepository, which will be referred in checking host keys.voidsetIdentityRepository(IdentityRepository identityRepository) Sets the identityRepository, which will be referred in the public key authentication.voidvoidvoidsetPassword(byte[] password) voidsetPassword(String password) voidsetPort(int port) intsetPortForwardingL(int lport, String host, int rport) Registers the local port forwarding for loop-back interface.intsetPortForwardingL(String conf) Registers the local port forwarding.intsetPortForwardingL(String bind_address, int lport, String host, int rport) Registers the local port forwarding.intsetPortForwardingL(String bind_address, int lport, String host, int rport, ServerSocketFactory ssf) Registers the local port forwarding.intsetPortForwardingL(String bind_address, int lport, String host, int rport, ServerSocketFactory ssf, int connectTimeout) Registers the local port forwarding.voidsetPortForwardingR(int rport, String daemon) Registers the remote port forwarding for the loopback interface of the remote.voidsetPortForwardingR(int rport, String host, int lport) Registers the remote port forwarding for the loopback interface of the remote.voidsetPortForwardingR(int rport, String host, int lport, SocketFactory sf) Registers the remote port forwarding for the loopback interface of the remote.voidsetPortForwardingR(int rport, String daemon, Object[] arg) Registers the remote port forwarding for the loopback interface of the remote.intsetPortForwardingR(String conf) Registers the remote port forwarding.voidsetPortForwardingR(String bind_address, int rport, String host, int lport) Registers the remote port forwarding.voidsetPortForwardingR(String bind_address, int rport, String host, int lport, SocketFactory sf) Registers the remote port forwarding.voidsetPortForwardingR(String bind_address, int rport, String daemon, Object[] arg) Registers the remote port forwarding.voidvoidsetServerAliveCountMax(int count) Sets the number of keep-alive messages which may be sent without receiving any messages back from the server.voidsetServerAliveInterval(int interval) Sets the interval to send a keep-alive message.voidsetSocketFactory(SocketFactory sfactory) voidsetTimeout(int timeout) voidsetUserInfo(UserInfo userinfo) (package private) voidsetUserName(String username) voidsetX11Cookie(String cookie) voidsetX11Host(String host) voidsetX11Port(int port) private voidstart_discard(Buffer buf, Cipher cipher, MAC mac, int packet_length, int discard) private voidupdateKeys(KeyExchange kex) void(package private) void
-
Field Details
-
SSH_MSG_DISCONNECT
static final int SSH_MSG_DISCONNECT- See Also:
-
SSH_MSG_IGNORE
static final int SSH_MSG_IGNORE- See Also:
-
SSH_MSG_UNIMPLEMENTED
static final int SSH_MSG_UNIMPLEMENTED- See Also:
-
SSH_MSG_DEBUG
static final int SSH_MSG_DEBUG- See Also:
-
SSH_MSG_SERVICE_REQUEST
static final int SSH_MSG_SERVICE_REQUEST- See Also:
-
SSH_MSG_SERVICE_ACCEPT
static final int SSH_MSG_SERVICE_ACCEPT- See Also:
-
SSH_MSG_KEXINIT
static final int SSH_MSG_KEXINIT- See Also:
-
SSH_MSG_NEWKEYS
static final int SSH_MSG_NEWKEYS- See Also:
-
SSH_MSG_KEXDH_INIT
static final int SSH_MSG_KEXDH_INIT- See Also:
-
SSH_MSG_KEXDH_REPLY
static final int SSH_MSG_KEXDH_REPLY- See Also:
-
SSH_MSG_KEX_DH_GEX_GROUP
static final int SSH_MSG_KEX_DH_GEX_GROUP- See Also:
-
SSH_MSG_KEX_DH_GEX_INIT
static final int SSH_MSG_KEX_DH_GEX_INIT- See Also:
-
SSH_MSG_KEX_DH_GEX_REPLY
static final int SSH_MSG_KEX_DH_GEX_REPLY- See Also:
-
SSH_MSG_KEX_DH_GEX_REQUEST
static final int SSH_MSG_KEX_DH_GEX_REQUEST- See Also:
-
SSH_MSG_GLOBAL_REQUEST
static final int SSH_MSG_GLOBAL_REQUEST- See Also:
-
SSH_MSG_REQUEST_SUCCESS
static final int SSH_MSG_REQUEST_SUCCESS- See Also:
-
SSH_MSG_REQUEST_FAILURE
static final int SSH_MSG_REQUEST_FAILURE- See Also:
-
SSH_MSG_CHANNEL_OPEN
static final int SSH_MSG_CHANNEL_OPEN- See Also:
-
SSH_MSG_CHANNEL_OPEN_CONFIRMATION
static final int SSH_MSG_CHANNEL_OPEN_CONFIRMATION- See Also:
-
SSH_MSG_CHANNEL_OPEN_FAILURE
static final int SSH_MSG_CHANNEL_OPEN_FAILURE- See Also:
-
SSH_MSG_CHANNEL_WINDOW_ADJUST
static final int SSH_MSG_CHANNEL_WINDOW_ADJUST- See Also:
-
SSH_MSG_CHANNEL_DATA
static final int SSH_MSG_CHANNEL_DATA- See Also:
-
SSH_MSG_CHANNEL_EXTENDED_DATA
static final int SSH_MSG_CHANNEL_EXTENDED_DATA- See Also:
-
SSH_MSG_CHANNEL_EOF
static final int SSH_MSG_CHANNEL_EOF- See Also:
-
SSH_MSG_CHANNEL_CLOSE
static final int SSH_MSG_CHANNEL_CLOSE- See Also:
-
SSH_MSG_CHANNEL_REQUEST
static final int SSH_MSG_CHANNEL_REQUEST- See Also:
-
SSH_MSG_CHANNEL_SUCCESS
static final int SSH_MSG_CHANNEL_SUCCESS- See Also:
-
SSH_MSG_CHANNEL_FAILURE
static final int SSH_MSG_CHANNEL_FAILURE- See Also:
-
PACKET_MAX_SIZE
private static final int PACKET_MAX_SIZE- See Also:
-
V_S
private byte[] V_S -
V_C
private byte[] V_C -
I_C
private byte[] I_C -
I_S
private byte[] I_S -
K_S
private byte[] K_S -
session_id
private byte[] session_id -
IVc2s
private byte[] IVc2s -
IVs2c
private byte[] IVs2c -
Ec2s
private byte[] Ec2s -
Es2c
private byte[] Es2c -
MACc2s
private byte[] MACc2s -
MACs2c
private byte[] MACs2c -
seqi
private int seqi -
seqo
private int seqo -
guess
String[] guess -
s2ccipher
-
c2scipher
-
s2cmac
-
c2smac
-
s2cmac_result1
private byte[] s2cmac_result1 -
s2cmac_result2
private byte[] s2cmac_result2 -
deflater
-
inflater
-
io
-
socket
-
timeout
private int timeout -
isConnected
private volatile boolean isConnected -
isAuthed
private boolean isAuthed -
connectThread
-
lock
-
x11_forwarding
boolean x11_forwarding -
agent_forwarding
boolean agent_forwarding -
in
InputStream in -
out
OutputStream out -
random
-
buf
Buffer buf -
packet
Packet packet -
socket_factory
SocketFactory socket_factory -
buffer_margin
static final int buffer_margin- See Also:
-
config
-
proxy
-
userinfo
-
hostKeyAlias
-
serverAliveInterval
private int serverAliveInterval -
serverAliveCountMax
private int serverAliveCountMax -
identityRepository
-
hostkeyRepository
-
daemon_thread
protected boolean daemon_thread -
kex_start_time
private long kex_start_time -
max_auth_tries
int max_auth_tries -
auth_failures
int auth_failures -
host
String host -
org_host
String org_host -
port
int port -
username
String username -
password
byte[] password -
jsch
JSch jsch -
in_kex
private volatile boolean in_kex -
in_prompt
private volatile boolean in_prompt -
uncompress_len
int[] uncompress_len -
compress_len
int[] compress_len -
s2ccipher_size
private int s2ccipher_size -
c2scipher_size
private int c2scipher_size -
thread
Runnable thread -
grr
-
keepalivemsg
private static final byte[] keepalivemsg -
nomoresessions
private static final byte[] nomoresessions -
hostkey
-
-
Constructor Details
-
Session
Session(JSch jsch, String username, String host, int port) throws JSchException - Throws:
JSchException
-
-
Method Details
-
connect
- Throws:
JSchException
-
connect
- Throws:
JSchException
-
receive_kexinit
- Throws:
Exception
-
rekey
- Throws:
Exception
-
send_kexinit
- Throws:
Exception
-
send_newkeys
- Throws:
Exception
-
checkHost
- Throws:
JSchException
-
openChannel
- Throws:
JSchException
-
encode
- Throws:
Exception
-
read
- Throws:
Exception
-
start_discard
private void start_discard(Buffer buf, Cipher cipher, MAC mac, int packet_length, int discard) throws JSchException, IOException - Throws:
JSchExceptionIOException
-
getSessionId
byte[] getSessionId() -
receive_newkeys
- Throws:
Exception
-
updateKeys
- Throws:
Exception
-
expandKey
private byte[] expandKey(Buffer buf, byte[] K, byte[] H, byte[] key, HASH hash, int required_length) throws Exception - Throws:
Exception
-
write
- Throws:
Exception
-
write
- Throws:
Exception
-
_write
- Throws:
Exception
-
run
public void run() -
disconnect
public void disconnect() -
setPortForwardingL
Registers the local port forwarding for loop-back interface. Iflportis0, the tcp port will be allocated.- Parameters:
lport- local port for local port forwardinghost- host address for local port forwardingrport- remote port number for local port forwarding- Returns:
- an allocated local TCP port number
- Throws:
JSchException- See Also:
-
setPortForwardingL
public int setPortForwardingL(String bind_address, int lport, String host, int rport) throws JSchException Registers the local port forwarding. Ifbind_addressis an empty string or '*', the port should be available from all interfaces. Ifbind_addressis"localhost"ornull, the listening port will be bound for local use only. Iflportis0, the tcp port will be allocated.- Parameters:
bind_address- bind address for local port forwardinglport- local port for local port forwardinghost- host address for local port forwardingrport- remote port number for local port forwarding- Returns:
- an allocated local TCP port number
- Throws:
JSchException- See Also:
-
setPortForwardingL
public int setPortForwardingL(String bind_address, int lport, String host, int rport, ServerSocketFactory ssf) throws JSchException Registers the local port forwarding. Ifbind_addressis an empty string or"*", the port should be available from all interfaces. Ifbind_addressis"localhost"ornull, the listening port will be bound for local use only. Iflportis0, the tcp port will be allocated.- Parameters:
bind_address- bind address for local port forwardinglport- local port for local port forwardinghost- host address for local port forwardingrport- remote port number for local port forwardingssf- socket factory- Returns:
- an allocated local TCP port number
- Throws:
JSchException- See Also:
-
setPortForwardingL
public int setPortForwardingL(String bind_address, int lport, String host, int rport, ServerSocketFactory ssf, int connectTimeout) throws JSchException Registers the local port forwarding. Ifbind_addressis an empty string or"*", the port should be available from all interfaces. Ifbind_addressis"localhost"ornull, the listening port will be bound for local use only. Iflportis0, the tcp port will be allocated.- Parameters:
bind_address- bind address for local port forwardinglport- local port for local port forwardinghost- host address for local port forwardingrport- remote port number for local port forwardingssf- socket factoryconnectTimeout- timeout for establishing port connection- Returns:
- an allocated local TCP port number
- Throws:
JSchException
-
delPortForwardingL
Cancels the local port forwarding assigned at local TCP portlporton loopback interface.- Parameters:
lport- local TCP port- Throws:
JSchException
-
delPortForwardingL
Cancels the local port forwarding assigned at local TCP portlportonbind_addressinterface.- Parameters:
bind_address- bind_address of network interfaceslport- local TCP port- Throws:
JSchException
-
getPortForwardingL
Lists the registered local port forwarding.- Returns:
- a list of "lport:host:hostport"
- Throws:
JSchException
-
setPortForwardingR
Registers the remote port forwarding for the loopback interface of the remote.- Parameters:
rport- remote porthost- host addresslport- local port- Throws:
JSchException- See Also:
-
setPortForwardingR
public void setPortForwardingR(String bind_address, int rport, String host, int lport) throws JSchException Registers the remote port forwarding. Ifbind_addressis an empty string or"*", the port should be available from all interfaces. Ifbind_addressis"localhost"or is not given, the listening port will be bound for local use only. Note that ifGatewayPortsis"no"on the remote,"localhost"is always used as a bind_address.- Parameters:
bind_address- bind addressrport- remote porthost- host addresslport- local port- Throws:
JSchException- See Also:
-
setPortForwardingR
public void setPortForwardingR(int rport, String host, int lport, SocketFactory sf) throws JSchException Registers the remote port forwarding for the loopback interface of the remote.- Parameters:
rport- remote porthost- host addresslport- local portsf- socket factory- Throws:
JSchException- See Also:
-
setPortForwardingR
public void setPortForwardingR(String bind_address, int rport, String host, int lport, SocketFactory sf) throws JSchException Registers the remote port forwarding. Ifbind_addressis an empty string or"*", the port should be available from all interfaces. Ifbind_addressis"localhost"or is not given, the listening port will be bound for local use only. Note that ifGatewayPortsis"no"on the remote,"localhost"is always used as a bind_address. Ifrportis0, the TCP port will be allocated on the remote.- Parameters:
bind_address- bind addressrport- remote porthost- host addresslport- local portsf- socket factory- Throws:
JSchException
-
setPortForwardingR
Registers the remote port forwarding for the loopback interface of the remote. The TCP connection torporton the remote will be forwarded to an instance of the classdaemon. The class specified bydaemonmust implementForwardedTCPIPDaemon.- Parameters:
rport- remote portdaemon- class name, which implements "ForwardedTCPIPDaemon"- Throws:
JSchException- See Also:
-
setPortForwardingR
Registers the remote port forwarding for the loopback interface of the remote. The TCP connection torporton the remote will be forwarded to an instance of the classdaemonwith the argumentarg. The class specified bydaemonmust implementForwardedTCPIPDaemon.- Parameters:
rport- remote portdaemon- class name, which implements "ForwardedTCPIPDaemon"arg- arguments for "daemon"- Throws:
JSchException- See Also:
-
setPortForwardingR
public void setPortForwardingR(String bind_address, int rport, String daemon, Object[] arg) throws JSchException Registers the remote port forwarding. Ifbind_addressis an empty string or"*", the port should be available from all interfaces. Ifbind_addressis"localhost"or is not given, the listening port will be bound for local use only. Note that ifGatewayPortsis"no"on the remote,"localhost"is always used as a bind_address. The TCP connection torporton the remote will be forwarded to an instance of the classdaemonwith the argumentarg. The class specified bydaemonmust implementForwardedTCPIPDaemon.- Parameters:
bind_address- bind addressrport- remote portdaemon- class name, which implements "ForwardedTCPIPDaemon"arg- arguments for "daemon"- Throws:
JSchException- See Also:
-
getPortForwardingR
Lists the registered remote port forwarding.- Returns:
- a list of "rport:host:hostport"
- Throws:
JSchException
-
parseForwarding
The given argument may be "[bind_address:]port:host:hostport" or "[bind_address:]port host:hostport", which is from LocalForward command of ~/.ssh/config .- Throws:
JSchException
-
setPortForwardingL
Registers the local port forwarding. The argument should be in the format like "[bind_address:]port:host:hostport". Ifbind_addressis an empty string or"*", the port should be available from all interfaces. Ifbind_addressis"localhost"or is not given, the listening port will be bound for local use only.- Parameters:
conf- configuration of local port forwarding- Returns:
- an assigned port number
- Throws:
JSchException- See Also:
-
setPortForwardingR
Registers the remote port forwarding. The argument should be in the format like "[bind_address:]port:host:hostport". If the bind_address is not given, the default is to only bind to loopback addresses. If the bind_address is"*"or an empty string, then the forwarding is requested to listen on all interfaces. Note that ifGatewayPortsis"no"on the remote,"localhost"is always used for bind_address. If the specified remote is"0", the TCP port will be allocated on the remote.- Parameters:
conf- configuration of remote port forwarding- Returns:
- an allocated TCP port on the remote.
- Throws:
JSchException- See Also:
-
getStreamForwarder
Instantiates an instance of stream-forwarder tohost:port. Set I/O stream to the given channel, and then invoke Channel#connect() method.- Parameters:
host- remote host, which the given stream will be plugged to.port- remote port, which the given stream will be plugged to.- Throws:
JSchException
-
_setPortForwardingR
- Throws:
JSchException
-
delPortForwardingR
Cancels the remote port forwarding assigned at remote TCP portrport.- Parameters:
rport- remote TCP port- Throws:
JSchException
-
delPortForwardingR
Cancels the remote port forwarding assigned at remote TCP portrportbound on the interface atbind_address.- Parameters:
bind_address- bind address of the interface on the remoterport- remote TCP port- Throws:
JSchException
-
initDeflater
- Throws:
JSchException
-
initInflater
- Throws:
JSchException
-
addChannel
-
setProxy
-
setHost
-
setPort
public void setPort(int port) -
setUserName
-
setUserInfo
-
getUserInfo
-
setInputStream
-
setOutputStream
-
setX11Host
-
setX11Port
public void setX11Port(int port) -
setX11Cookie
-
setPassword
-
setPassword
public void setPassword(byte[] password) -
setConfig
-
setConfig
-
setConfig
-
getConfig
-
setSocketFactory
-
isConnected
public boolean isConnected() -
getTimeout
public int getTimeout() -
setTimeout
- Throws:
JSchException
-
getServerVersion
-
getClientVersion
-
setClientVersion
-
sendIgnore
- Throws:
Exception
-
sendKeepAliveMsg
- Throws:
Exception
-
noMoreSessionChannels
- Throws:
Exception
-
getHostKey
-
getHost
-
getUserName
-
getPort
public int getPort() -
setHostKeyAlias
-
getHostKeyAlias
-
setServerAliveInterval
Sets the interval to send a keep-alive message. If zero is specified, any keep-alive message must not be sent. The default interval is zero.- Parameters:
interval- the specified interval, in milliseconds.- Throws:
JSchException- See Also:
-
getServerAliveInterval
public int getServerAliveInterval()Returns setting for the interval to send a keep-alive message.- See Also:
-
setServerAliveCountMax
public void setServerAliveCountMax(int count) Sets the number of keep-alive messages which may be sent without receiving any messages back from the server. If this threshold is reached while keep-alive messages are being sent, the connection will be disconnected. The default value is one.- Parameters:
count- the specified count- See Also:
-
getServerAliveCountMax
public int getServerAliveCountMax()Returns setting for the threshold to send keep-alive messages.- See Also:
-
setDaemonThread
public void setDaemonThread(boolean enable) -
checkCiphers
-
checkCipher
-
checkKexes
-
checkKex
-
checkSignatures
-
setIdentityRepository
Sets the identityRepository, which will be referred in the public key authentication. The default value isnull.- Parameters:
identityRepository-- See Also:
-
getIdentityRepository
IdentityRepository getIdentityRepository()Gets the identityRepository. If this.identityRepository isnull, JSch#getIdentityRepository() will be invoked.- See Also:
-
setHostKeyRepository
Sets the hostkeyRepository, which will be referred in checking host keys.- Parameters:
hostkeyRepository-- See Also:
-
getHostKeyRepository
Gets the hostkeyRepository. If this.hostkeyRepository isnull, JSch#getHostKeyRepository() will be invoked.- See Also:
-
applyConfig
- Throws:
JSchException
-
applyConfigChannel
- Throws:
JSchException
-
requestPortForwarding
- Throws:
JSchException
-
checkConfig
-