Package com.sshtools.j2ssh.transport
Class TransportProtocolCommon
- java.lang.Object
-
- com.sshtools.j2ssh.transport.TransportProtocolCommon
-
- All Implemented Interfaces:
TransportProtocol,java.lang.Runnable
- Direct Known Subclasses:
TransportProtocolClient,TransportProtocolServer
public abstract class TransportProtocolCommon extends java.lang.Object implements TransportProtocol, java.lang.Runnable
- Version:
- $Revision: 1.2 $
- Author:
- $author$
-
-
Field Summary
Fields Modifier and Type Field Description protected TransportProtocolAlgorithmSyncalgorithmsInprotected TransportProtocolAlgorithmSyncalgorithmsOutprotected java.lang.StringclientIdentprotected SshMsgKexInitclientKexInitprotected java.lang.BooleancompleteOnNewKeysstatic intEOL_CRLFstatic intEOL_LFprotected byte[]hostKeyprotected HostKeyVerificationhostsprotected java.math.BigIntegerkprotected java.util.Mapkexsprotected static org.apache.commons.logging.Loglogprotected SshMessageStoremessageStoreprotected SshConnectionPropertiespropertiesstatic java.lang.StringPROTOCOL_VERSIONprotected java.lang.StringserverIdentprotected SshMsgKexInitserverKexInitprotected byte[]sessionIdentifierprotected byte[]signaturestatic java.lang.StringSOFTWARE_VERSION_COMMENTSprotected com.sshtools.j2ssh.transport.TransportProtocolInputStreamsshInprotected com.sshtools.j2ssh.transport.TransportProtocolOutputStreamsshOutprotected TransportProtocolStatestate
-
Constructor Summary
Constructors Constructor Description TransportProtocolCommon()Creates a new TransportProtocolCommon object.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidaddEventHandler(TransportProtocolEventHandler eventHandler)voidaddMessageStore(SshMessageStore store)protected voidbeginKeyExchange()protected voidcompleteKeyExchange()protected SshMsgKexInitcreateLocalKexInit()protected java.lang.StringdetermineAlgorithm(java.util.List clientAlgorithms, java.util.List serverAlgorithms)voiddisconnect(java.lang.String description)intgetConnectionId()protected abstract java.lang.StringgetDecryptionAlgorithm()protected abstract java.lang.StringgetEncryptionAlgorithm()protected java.util.ListgetEventHandlers()longgetIncomingByteCount()protected abstract java.lang.StringgetInputStreamCompAlgortihm()protected abstract java.lang.StringgetInputStreamMacAlgorithm()protected java.lang.StringgetKexAlgorithm()abstract java.lang.StringgetLocalId()protected abstract SshMsgKexInitgetLocalKexInit()longgetOutgoingByteCount()protected abstract java.lang.StringgetOutputStreamCompAlgorithm()protected abstract java.lang.StringgetOutputStreamMacAlgorithm()SshConnectionPropertiesgetProperties()intgetRemoteEOL()abstract java.lang.StringgetRemoteId()protected abstract SshMsgKexInitgetRemoteKexInit()byte[]getSessionIdentifier()TransportProtocolStategetState()java.lang.StringgetUnderlyingProviderDetail()booleanisConnected()protected voidonCorruptMac()protected abstract voidonDisconnect()protected abstract voidonMessageReceived(SshMessage msg)protected abstract voidonStartTransportProtocol()protected abstract voidperformKeyExchange(SshKeyExchange kex)protected SshMessageprocessMessages()SshMessagereadMessage(int[] filter)abstract voidregisterTransportMessages()voidremoveMessageStore(SshMessageStore ms)voidrun()protected voidsendDisconnect(int reason, java.lang.String description)protected voidsendDisconnect(int reason, java.lang.String description, java.io.IOException error)protected voidsendKeyExchangeInit()voidsendMessage(SshMessage msg, java.lang.Object sender)protected voidsendNewKeys()voidsetKexTimeout(long seconds)voidsetKexTransferLimit(long kilobytes)protected abstract voidsetLocalIdent()protected abstract voidsetLocalKexInit(SshMsgKexInit msg)protected abstract voidsetRemoteIdent(java.lang.String ident)protected abstract voidsetRemoteKexInit(SshMsgKexInit msg)voidsetSendIgnore(boolean sendIgnore)protected abstract voidsetupNewKeys(byte[] encryptCSKey, byte[] encryptCSIV, byte[] encryptSCKey, byte[] encryptSCIV, byte[] macCSKey, byte[] macSCKey)protected voidstartBinaryPacketProtocol()voidstartTransportProtocol(TransportProvider provider, SshConnectionProperties properties)protected voidstop()voidunregisterMessage(java.lang.Integer messageId, SshMessageStore store)
-
-
-
Field Detail
-
log
protected static org.apache.commons.logging.Log log
-
EOL_CRLF
public static final int EOL_CRLF
- See Also:
- Constant Field Values
-
EOL_LF
public static final int EOL_LF
- See Also:
- Constant Field Values
-
PROTOCOL_VERSION
public static final java.lang.String PROTOCOL_VERSION
- See Also:
- Constant Field Values
-
SOFTWARE_VERSION_COMMENTS
public static java.lang.String SOFTWARE_VERSION_COMMENTS
-
k
protected java.math.BigInteger k
-
completeOnNewKeys
protected java.lang.Boolean completeOnNewKeys
-
hosts
protected HostKeyVerification hosts
-
kexs
protected java.util.Map kexs
-
properties
protected SshConnectionProperties properties
-
messageStore
protected SshMessageStore messageStore
-
clientKexInit
protected SshMsgKexInit clientKexInit
-
serverKexInit
protected SshMsgKexInit serverKexInit
-
clientIdent
protected java.lang.String clientIdent
-
serverIdent
protected java.lang.String serverIdent
-
algorithmsIn
protected TransportProtocolAlgorithmSync algorithmsIn
-
algorithmsOut
protected TransportProtocolAlgorithmSync algorithmsOut
-
state
protected TransportProtocolState state
-
sessionIdentifier
protected byte[] sessionIdentifier
-
hostKey
protected byte[] hostKey
-
signature
protected byte[] signature
-
sshIn
protected com.sshtools.j2ssh.transport.TransportProtocolInputStream sshIn
-
sshOut
protected com.sshtools.j2ssh.transport.TransportProtocolOutputStream sshOut
-
-
Method Detail
-
getConnectionId
public int getConnectionId()
- Specified by:
getConnectionIdin interfaceTransportProtocol- Returns:
-
getRemoteEOL
public int getRemoteEOL()
- Returns:
-
getState
public TransportProtocolState getState()
- Specified by:
getStatein interfaceTransportProtocol- Returns:
-
getProperties
public SshConnectionProperties getProperties()
- Returns:
-
onDisconnect
protected abstract void onDisconnect()
-
disconnect
public void disconnect(java.lang.String description)
- Specified by:
disconnectin interfaceTransportProtocol- Parameters:
description-
-
setSendIgnore
public void setSendIgnore(boolean sendIgnore)
- Parameters:
sendIgnore-
-
setKexTimeout
public void setKexTimeout(long seconds) throws TransportProtocolException- Parameters:
seconds-- Throws:
TransportProtocolException
-
setKexTransferLimit
public void setKexTransferLimit(long kilobytes) throws TransportProtocolException- Parameters:
kilobytes-- Throws:
TransportProtocolException
-
getOutgoingByteCount
public long getOutgoingByteCount()
-
getIncomingByteCount
public long getIncomingByteCount()
- Returns:
-
addEventHandler
public void addEventHandler(TransportProtocolEventHandler eventHandler)
- Parameters:
eventHandler-
-
registerTransportMessages
public abstract void registerTransportMessages() throws MessageAlreadyRegisteredException
-
getSessionIdentifier
public byte[] getSessionIdentifier()
- Specified by:
getSessionIdentifierin interfaceTransportProtocol- Returns:
-
run
public void run()
- Specified by:
runin interfacejava.lang.Runnable
-
sendMessage
public void sendMessage(SshMessage msg, java.lang.Object sender) throws java.io.IOException
- Specified by:
sendMessagein interfaceTransportProtocol- Parameters:
msg-sender-- Throws:
java.io.IOExceptionTransportProtocolException
-
onStartTransportProtocol
protected abstract void onStartTransportProtocol() throws java.io.IOException- Throws:
java.io.IOException
-
startTransportProtocol
public void startTransportProtocol(TransportProvider provider, SshConnectionProperties properties) throws java.io.IOException
- Parameters:
provider-properties-- Throws:
java.io.IOException
-
getUnderlyingProviderDetail
public java.lang.String getUnderlyingProviderDetail()
- Specified by:
getUnderlyingProviderDetailin interfaceTransportProtocol- Returns:
-
unregisterMessage
public void unregisterMessage(java.lang.Integer messageId, SshMessageStore store) throws MessageNotRegisteredException- Parameters:
messageId-store-- Throws:
MessageNotRegisteredException
-
getDecryptionAlgorithm
protected abstract java.lang.String getDecryptionAlgorithm() throws AlgorithmNotAgreedException- Returns:
- Throws:
AlgorithmNotAgreedException
-
getEncryptionAlgorithm
protected abstract java.lang.String getEncryptionAlgorithm() throws AlgorithmNotAgreedException- Returns:
- Throws:
AlgorithmNotAgreedException
-
getInputStreamCompAlgortihm
protected abstract java.lang.String getInputStreamCompAlgortihm() throws AlgorithmNotAgreedException- Returns:
- Throws:
AlgorithmNotAgreedException
-
getInputStreamMacAlgorithm
protected abstract java.lang.String getInputStreamMacAlgorithm() throws AlgorithmNotAgreedException- Returns:
- Throws:
AlgorithmNotAgreedException
-
setLocalIdent
protected abstract void setLocalIdent()
-
getLocalId
public abstract java.lang.String getLocalId()
- Returns:
-
setLocalKexInit
protected abstract void setLocalKexInit(SshMsgKexInit msg)
- Parameters:
msg-
-
getLocalKexInit
protected abstract SshMsgKexInit getLocalKexInit()
- Returns:
-
getOutputStreamCompAlgorithm
protected abstract java.lang.String getOutputStreamCompAlgorithm() throws AlgorithmNotAgreedException- Returns:
- Throws:
AlgorithmNotAgreedException
-
getOutputStreamMacAlgorithm
protected abstract java.lang.String getOutputStreamMacAlgorithm() throws AlgorithmNotAgreedException- Returns:
- Throws:
AlgorithmNotAgreedException
-
setRemoteIdent
protected abstract void setRemoteIdent(java.lang.String ident)
- Parameters:
ident-
-
getRemoteId
public abstract java.lang.String getRemoteId()
- Returns:
-
setRemoteKexInit
protected abstract void setRemoteKexInit(SshMsgKexInit msg)
- Parameters:
msg-
-
getRemoteKexInit
protected abstract SshMsgKexInit getRemoteKexInit()
- Returns:
-
performKeyExchange
protected abstract void performKeyExchange(SshKeyExchange kex) throws java.io.IOException, KeyExchangeException
- Parameters:
kex-- Throws:
java.io.IOExceptionKeyExchangeException
-
getKexAlgorithm
protected java.lang.String getKexAlgorithm() throws AlgorithmNotAgreedException- Returns:
- Throws:
AlgorithmNotAgreedException
-
isConnected
public boolean isConnected()
- Specified by:
isConnectedin interfaceTransportProtocol
-
beginKeyExchange
protected void beginKeyExchange() throws java.io.IOException, KeyExchangeException- Throws:
java.io.IOExceptionKeyExchangeException
-
createLocalKexInit
protected SshMsgKexInit createLocalKexInit() throws java.io.IOException
- Returns:
- Throws:
java.io.IOException
-
onCorruptMac
protected void onCorruptMac()
-
onMessageReceived
protected abstract void onMessageReceived(SshMessage msg) throws java.io.IOException
- Parameters:
msg-- Throws:
java.io.IOException
-
sendDisconnect
protected void sendDisconnect(int reason, java.lang.String description)- Parameters:
reason-description-
-
sendDisconnect
protected void sendDisconnect(int reason, java.lang.String description, java.io.IOException error)- Parameters:
reason-description-error-
-
sendKeyExchangeInit
protected void sendKeyExchangeInit() throws java.io.IOException- Throws:
java.io.IOException
-
sendNewKeys
protected void sendNewKeys() throws java.io.IOException- Throws:
java.io.IOException
-
setupNewKeys
protected abstract void setupNewKeys(byte[] encryptCSKey, byte[] encryptCSIV, byte[] encryptSCKey, byte[] encryptSCIV, byte[] macCSKey, byte[] macSCKey) throws AlgorithmNotAgreedException, AlgorithmOperationException, AlgorithmNotSupportedException, AlgorithmInitializationException- Parameters:
encryptCSKey-encryptCSIV-encryptSCKey-encryptSCIV-macCSKey-macSCKey-- Throws:
AlgorithmNotAgreedExceptionAlgorithmOperationExceptionAlgorithmNotSupportedExceptionAlgorithmInitializationException
-
completeKeyExchange
protected void completeKeyExchange() throws java.io.IOException- Throws:
java.io.IOExceptionTransportProtocolException
-
getEventHandlers
protected java.util.List getEventHandlers()
- Returns:
-
determineAlgorithm
protected java.lang.String determineAlgorithm(java.util.List clientAlgorithms, java.util.List serverAlgorithms) throws AlgorithmNotAgreedException- Parameters:
clientAlgorithms-serverAlgorithms-- Returns:
- Throws:
AlgorithmNotAgreedException
-
startBinaryPacketProtocol
protected void startBinaryPacketProtocol() throws java.io.IOException- Throws:
java.io.IOException
-
stop
protected final void stop()
-
readMessage
public SshMessage readMessage(int[] filter) throws java.io.IOException
- Specified by:
readMessagein interfaceTransportProtocol- Parameters:
filter-- Returns:
- Throws:
java.io.IOException
-
processMessages
protected SshMessage processMessages() throws java.io.IOException
- Returns:
- Throws:
java.io.IOException
-
addMessageStore
public void addMessageStore(SshMessageStore store) throws MessageAlreadyRegisteredException
- Specified by:
addMessageStorein interfaceTransportProtocol- Parameters:
store-- Throws:
MessageAlreadyRegisteredException
-
removeMessageStore
public void removeMessageStore(SshMessageStore ms)
- Parameters:
ms-
-
-