├── .classpath
├── .gitignore
├── .project
├── .settings
├── org.eclipse.jdt.core.prefs
└── org.eclipse.jdt.ui.prefs
├── AndroidManifest.xml
├── LICENSE
├── README
├── README.md
├── ant.properties
├── assets
└── help
│ ├── About.html
│ ├── Hints.html
│ ├── PhysicalKeyboard.html
│ ├── ScreenGestures.html
│ └── VirtualKeyboard.html
├── build.xml
├── jni
├── Android.mk
├── Application.mk
└── Exec
│ ├── Android.mk
│ ├── com_google_ase_Exec.cpp
│ └── com_google_ase_Exec.h
├── libs
├── armeabi
│ └── libcom_google_ase_Exec.so
└── x86
│ └── libcom_google_ase_Exec.so
├── lint.xml
├── locale
└── .gitignore
├── proguard.cfg
├── proguard
├── dump.txt
├── seeds.txt
└── usage.txt
├── project.properties
├── res
├── anim
│ ├── fade_out_delayed.xml
│ ├── fade_stay_hidden.xml
│ ├── keyboard_fade_in.xml
│ ├── keyboard_fade_out.xml
│ ├── slide_left_in.xml
│ ├── slide_left_out.xml
│ ├── slide_right_in.xml
│ └── slide_right_out.xml
├── color
│ ├── blue.xml
│ ├── green.xml
│ └── red.xml
├── drawable-hdpi
│ ├── icon.png
│ └── notification_icon.png
├── drawable-ldpi
│ ├── icon.png
│ └── notification_icon.png
├── drawable-mdpi
│ ├── button_ctrl.png
│ ├── button_esc.png
│ ├── button_input.png
│ ├── button_keyboard.png
│ ├── button_sym.png
│ ├── file.png
│ ├── folder.png
│ ├── highlight_disabled_pressed.9.png
│ ├── ic_btn_back.png
│ ├── ic_btn_next.png
│ ├── icon.png
│ ├── notification_icon.png
│ ├── pubkey_locked.png
│ └── pubkey_unlocked.png
├── drawable-xhdpi
│ ├── icon.png
│ └── notification_icon.png
├── drawable
│ ├── connected.xml
│ └── pubkey.xml
├── layout-land
│ └── item_host.xml
├── layout-port
│ └── item_host.xml
├── layout
│ ├── act_colors.xml
│ ├── act_console.xml
│ ├── act_generatepubkey.xml
│ ├── act_help.xml
│ ├── act_help_topic.xml
│ ├── act_hostlist.xml
│ ├── act_portforwardlist.xml
│ ├── act_pubkeylist.xml
│ ├── act_wizard.xml
│ ├── dia_changepassword.xml
│ ├── dia_gatherentropy.xml
│ ├── dia_password.xml
│ ├── dia_portforward.xml
│ ├── dia_resize.xml
│ ├── file_dialog_main.xml
│ ├── file_dialog_row.xml
│ ├── item_portforward.xml
│ ├── item_pubkey.xml
│ ├── item_terminal.xml
│ └── wiz_eula.xml
├── raw
│ └── bell.ogg
├── values-af
│ └── strings.xml
├── values-ar
│ └── strings.xml
├── values-be
│ └── strings.xml
├── values-bg
│ └── strings.xml
├── values-ca
│ └── strings.xml
├── values-cs
│ └── strings.xml
├── values-da
│ └── strings.xml
├── values-de
│ └── strings.xml
├── values-el
│ └── strings.xml
├── values-en-rCA
│ └── strings.xml
├── values-en-rGB
│ └── strings.xml
├── values-es
│ └── strings.xml
├── values-eu
│ └── strings.xml
├── values-fa
│ └── strings.xml
├── values-fi
│ └── strings.xml
├── values-fr
│ └── strings.xml
├── values-gl
│ └── strings.xml
├── values-he
│ └── strings.xml
├── values-hr
│ └── strings.xml
├── values-hu
│ └── strings.xml
├── values-id
│ └── strings.xml
├── values-is
│ └── strings.xml
├── values-it
│ └── strings.xml
├── values-ja
│ └── strings.xml
├── values-ko
│ └── strings.xml
├── values-lt
│ └── strings.xml
├── values-lv
│ └── strings.xml
├── values-mk
│ └── strings.xml
├── values-nb
│ └── strings.xml
├── values-nl
│ └── strings.xml
├── values-oc
│ └── strings.xml
├── values-pl
│ └── strings.xml
├── values-pt-rBR
│ └── strings.xml
├── values-pt
│ └── strings.xml
├── values-ro
│ └── strings.xml
├── values-ru
│ └── strings.xml
├── values-sk
│ └── strings.xml
├── values-sl
│ └── strings.xml
├── values-sv
│ └── strings.xml
├── values-tr
│ └── strings.xml
├── values-uk
│ └── strings.xml
├── values-v11
│ └── styles.xml
├── values-v14
│ └── styles.xml
├── values-vi
│ └── strings.xml
├── values-zh-rCN
│ └── strings.xml
├── values-zh-rHK
│ └── strings.xml
├── values-zh-rTW
│ └── strings.xml
├── values
│ ├── arrays.xml
│ ├── notrans.xml
│ ├── strings.xml
│ ├── styles.xml
│ └── version.xml
└── xml
│ ├── host_prefs.xml
│ └── preferences.xml
├── src
├── com
│ ├── google
│ │ └── ase
│ │ │ └── Exec.java
│ ├── jcraft
│ │ └── jzlib
│ │ │ ├── Adler32.java
│ │ │ ├── Deflate.java
│ │ │ ├── InfBlocks.java
│ │ │ ├── InfCodes.java
│ │ │ ├── InfTree.java
│ │ │ ├── Inflate.java
│ │ │ ├── JZlib.java
│ │ │ ├── StaticTree.java
│ │ │ ├── Tree.java
│ │ │ ├── ZInputStream.java
│ │ │ ├── ZOutputStream.java
│ │ │ ├── ZStream.java
│ │ │ └── ZStreamException.java
│ ├── lamerman
│ │ ├── FileDialog.java
│ │ └── SelectionMode.java
│ ├── madgag
│ │ └── ssh
│ │ │ └── android
│ │ │ └── authagent
│ │ │ └── AndroidAuthAgent.java
│ └── trilead
│ │ └── ssh2
│ │ ├── AuthAgentCallback.java
│ │ ├── ChannelCondition.java
│ │ ├── Connection.java
│ │ ├── ConnectionInfo.java
│ │ ├── ConnectionMonitor.java
│ │ ├── DHGexParameters.java
│ │ ├── DebugLogger.java
│ │ ├── DynamicPortForwarder.java
│ │ ├── HTTPProxyData.java
│ │ ├── HTTPProxyException.java
│ │ ├── InteractiveCallback.java
│ │ ├── KnownHosts.java
│ │ ├── LocalPortForwarder.java
│ │ ├── LocalStreamForwarder.java
│ │ ├── ProxyData.java
│ │ ├── SCPClient.java
│ │ ├── SFTPException.java
│ │ ├── SFTPv3Client.java
│ │ ├── SFTPv3DirectoryEntry.java
│ │ ├── SFTPv3FileAttributes.java
│ │ ├── SFTPv3FileHandle.java
│ │ ├── ServerHostKeyVerifier.java
│ │ ├── Session.java
│ │ ├── StreamGobbler.java
│ │ ├── auth
│ │ └── AuthenticationManager.java
│ │ ├── channel
│ │ ├── AuthAgentForwardThread.java
│ │ ├── Channel.java
│ │ ├── ChannelInputStream.java
│ │ ├── ChannelManager.java
│ │ ├── ChannelOutputStream.java
│ │ ├── DynamicAcceptThread.java
│ │ ├── IChannelWorkerThread.java
│ │ ├── LocalAcceptThread.java
│ │ ├── RemoteAcceptThread.java
│ │ ├── RemoteForwardingData.java
│ │ ├── RemoteX11AcceptThread.java
│ │ ├── StreamForwarder.java
│ │ └── X11ServerData.java
│ │ ├── compression
│ │ ├── CompressionFactory.java
│ │ ├── ICompressor.java
│ │ ├── Zlib.java
│ │ └── ZlibOpenSSH.java
│ │ ├── crypto
│ │ ├── Base64.java
│ │ ├── CryptoWishList.java
│ │ ├── KeyMaterial.java
│ │ ├── PEMDecoder.java
│ │ ├── PEMStructure.java
│ │ ├── SimpleDERReader.java
│ │ ├── cipher
│ │ │ ├── AES.java
│ │ │ ├── BlockCipher.java
│ │ │ ├── BlockCipherFactory.java
│ │ │ ├── BlowFish.java
│ │ │ ├── CBCMode.java
│ │ │ ├── CTRMode.java
│ │ │ ├── CipherInputStream.java
│ │ │ ├── CipherOutputStream.java
│ │ │ ├── DES.java
│ │ │ ├── DESede.java
│ │ │ └── NullCipher.java
│ │ ├── dh
│ │ │ ├── DhExchange.java
│ │ │ └── DhGroupExchange.java
│ │ └── digest
│ │ │ ├── Digest.java
│ │ │ ├── HMAC.java
│ │ │ ├── HashForSSH2Types.java
│ │ │ ├── MAC.java
│ │ │ ├── MD5.java
│ │ │ └── SHA1.java
│ │ ├── log
│ │ └── Logger.java
│ │ ├── packets
│ │ ├── PacketChannelAuthAgentReq.java
│ │ ├── PacketChannelOpenConfirmation.java
│ │ ├── PacketChannelOpenFailure.java
│ │ ├── PacketChannelTrileadPing.java
│ │ ├── PacketChannelWindowAdjust.java
│ │ ├── PacketDisconnect.java
│ │ ├── PacketGlobalCancelForwardRequest.java
│ │ ├── PacketGlobalForwardRequest.java
│ │ ├── PacketGlobalTrileadPing.java
│ │ ├── PacketIgnore.java
│ │ ├── PacketKexDHInit.java
│ │ ├── PacketKexDHReply.java
│ │ ├── PacketKexDhGexGroup.java
│ │ ├── PacketKexDhGexInit.java
│ │ ├── PacketKexDhGexReply.java
│ │ ├── PacketKexDhGexRequest.java
│ │ ├── PacketKexDhGexRequestOld.java
│ │ ├── PacketKexInit.java
│ │ ├── PacketNewKeys.java
│ │ ├── PacketOpenDirectTCPIPChannel.java
│ │ ├── PacketOpenSessionChannel.java
│ │ ├── PacketServiceAccept.java
│ │ ├── PacketServiceRequest.java
│ │ ├── PacketSessionExecCommand.java
│ │ ├── PacketSessionPtyRequest.java
│ │ ├── PacketSessionPtyResize.java
│ │ ├── PacketSessionStartShell.java
│ │ ├── PacketSessionSubsystemRequest.java
│ │ ├── PacketSessionX11Request.java
│ │ ├── PacketUserauthBanner.java
│ │ ├── PacketUserauthFailure.java
│ │ ├── PacketUserauthInfoRequest.java
│ │ ├── PacketUserauthInfoResponse.java
│ │ ├── PacketUserauthRequestInteractive.java
│ │ ├── PacketUserauthRequestNone.java
│ │ ├── PacketUserauthRequestPassword.java
│ │ ├── PacketUserauthRequestPublicKey.java
│ │ ├── Packets.java
│ │ ├── TypesReader.java
│ │ └── TypesWriter.java
│ │ ├── sftp
│ │ ├── AttrTextHints.java
│ │ ├── AttribBits.java
│ │ ├── AttribFlags.java
│ │ ├── AttribPermissions.java
│ │ ├── AttribTypes.java
│ │ ├── ErrorCodes.java
│ │ ├── OpenFlags.java
│ │ └── Packet.java
│ │ ├── signature
│ │ ├── DSAPrivateKey.java
│ │ ├── DSAPublicKey.java
│ │ ├── DSASHA1Verify.java
│ │ ├── DSASignature.java
│ │ ├── RSAPrivateKey.java
│ │ ├── RSAPublicKey.java
│ │ ├── RSASHA1Verify.java
│ │ └── RSASignature.java
│ │ ├── transport
│ │ ├── ClientServerHello.java
│ │ ├── KexManager.java
│ │ ├── KexParameters.java
│ │ ├── KexState.java
│ │ ├── MessageHandler.java
│ │ ├── NegotiateException.java
│ │ ├── NegotiatedParameters.java
│ │ ├── TransportConnection.java
│ │ └── TransportManager.java
│ │ └── util
│ │ ├── TimeoutService.java
│ │ └── Tokenizer.java
├── de
│ └── mud
│ │ ├── telnet
│ │ └── TelnetProtocolHandler.java
│ │ └── terminal
│ │ ├── Precomposer.java
│ │ ├── VDUBuffer.java
│ │ ├── VDUDisplay.java
│ │ ├── VDUInput.java
│ │ └── vt320.java
├── net
│ └── sourceforge
│ │ └── jsocks
│ │ ├── Authentication.java
│ │ ├── AuthenticationNone.java
│ │ ├── Proxy.java
│ │ ├── ProxyMessage.java
│ │ ├── ProxyServer.java
│ │ ├── Socks4Message.java
│ │ ├── Socks4Proxy.java
│ │ ├── Socks5DatagramSocket.java
│ │ ├── Socks5Message.java
│ │ ├── Socks5Proxy.java
│ │ ├── SocksException.java
│ │ ├── SocksServerSocket.java
│ │ ├── SocksSocket.java
│ │ ├── UDPEncapsulation.java
│ │ ├── UDPRelayServer.java
│ │ └── server
│ │ ├── ServerAuthenticator.java
│ │ └── ServerAuthenticatorNone.java
├── org
│ ├── apache
│ │ └── harmony
│ │ │ └── niochar
│ │ │ └── charset
│ │ │ └── additional
│ │ │ └── IBM437.java
│ └── openintents
│ │ └── intents
│ │ └── FileManagerIntents.java
└── sk
│ └── vx
│ └── connectbot
│ ├── ActionBarWrapper.java
│ ├── ColorsActivity.java
│ ├── ConsoleActivity.java
│ ├── GeneratePubkeyActivity.java
│ ├── HelpActivity.java
│ ├── HelpTopicActivity.java
│ ├── HostEditorActivity.java
│ ├── HostListActivity.java
│ ├── PortForwardListActivity.java
│ ├── PubkeyListActivity.java
│ ├── SettingsActivity.java
│ ├── StrictModeSetup.java
│ ├── TerminalView.java
│ ├── WizardActivity.java
│ ├── bean
│ ├── AbstractBean.java
│ ├── HostBean.java
│ ├── PortForwardBean.java
│ ├── PubkeyBean.java
│ └── SelectionArea.java
│ ├── service
│ ├── AuthAgentService.java
│ ├── BackupAgent.java
│ ├── BridgeDisconnectedListener.java
│ ├── ConnectionNotifier.java
│ ├── ConnectivityReceiver.java
│ ├── FontSizeChangedListener.java
│ ├── PromptHelper.java
│ ├── Relay.java
│ ├── TerminalBridge.java
│ ├── TerminalKeyListener.java
│ └── TerminalManager.java
│ ├── transport
│ ├── AbsTransport.java
│ ├── Local.java
│ ├── SSH.java
│ ├── Telnet.java
│ └── TransportFactory.java
│ └── util
│ ├── Colors.java
│ ├── Encryptor.java
│ ├── EntropyDialog.java
│ ├── EntropyView.java
│ ├── FileChooser.java
│ ├── FileChooserCallback.java
│ ├── HelpTopicView.java
│ ├── HostDatabase.java
│ ├── OnDbWrittenListener.java
│ ├── OnEntropyGatheredListener.java
│ ├── PreferenceConstants.java
│ ├── PubkeyDatabase.java
│ ├── PubkeyUtils.java
│ ├── RobustSQLiteOpenHelper.java
│ ├── TransferThread.java
│ ├── UberColorPickerDialog.java
│ ├── VolumePreference.java
│ └── XmlBuilder.java
├── tests
├── .classpath
├── .gitignore
├── .project
├── .settings
│ ├── org.eclipse.jdt.core.prefs
│ └── org.eclipse.jdt.ui.prefs
├── AndroidManifest.xml
├── ant.properties
├── build.xml
├── proguard.cfg
├── project.properties
└── src
│ └── sk
│ └── vx
│ └── connectbot
│ ├── HostBeanTest.java
│ ├── HostListActivityTest.java
│ ├── SelectionAreaTest.java
│ ├── SettingsActivityTest.java
│ ├── TerminalBridgeTest.java
│ ├── mock
│ ├── BeanTestCase.java
│ ├── NullOutputStream.java
│ └── NullTransport.java
│ └── util
│ └── PubkeyUtilsTest.java
└── tools
└── google-code-upload.pl
/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
When you have multiple sessions open, you can 'pan' between them by swiping your finger left-to-right or right-to-left over the screen.
7 | 8 |Long-press on your Android desktop to create direct shortcuts to frequently-used SSH hosts.
9 | 10 |Slide your finger up/down on the right-half of the terminal screen to look at the scrollback history. Slide up/down on the left-half to send the page up/down keys.
11 | 12 | 13 | -------------------------------------------------------------------------------- /assets/help/ScreenGestures.html: -------------------------------------------------------------------------------- 1 | 2 | Gestures in ConnectBot allow a user to do several things for 5 | which there's no keyboard equivalent. If the gestures seem 6 | backward, then imagine that you're grabbing the text and moving it 7 | with your finger. 8 |Swiping your finger up and down on the left third of the screen 10 | will send a page up and page down key to the remote host. Many programs 11 | map this to scrolling back into history such as irssi or tinyfugue.
12 |Swiping your finger up on the right side of the screen allows you 15 | to scroll backward and forward in the local terminal buffer history.
16 |Swiping your finger from one side of the screen to the other will 18 | switch between currently connected hosts.
19 | 20 | -------------------------------------------------------------------------------- /jni/Android.mk: -------------------------------------------------------------------------------- 1 | include $(call all-subdir-makefiles) 2 | -------------------------------------------------------------------------------- /jni/Application.mk: -------------------------------------------------------------------------------- 1 | # Build both ARMv5TE and x86-32 machine code. 2 | APP_ABI := armeabi x86 3 | -------------------------------------------------------------------------------- /jni/Exec/Android.mk: -------------------------------------------------------------------------------- 1 | LOCAL_PATH := $(call my-dir) 2 | 3 | include $(CLEAR_VARS) 4 | 5 | LOCAL_MODULE := com_google_ase_Exec 6 | LOCAL_CFLAGS := -Werror 7 | LOCAL_SRC_FILES := com_google_ase_Exec.cpp 8 | LOCAL_LDLIBS := -llog 9 | 10 | include $(BUILD_SHARED_LIBRARY) 11 | -------------------------------------------------------------------------------- /jni/Exec/com_google_ase_Exec.h: -------------------------------------------------------------------------------- 1 | /* DO NOT EDIT THIS FILE - it is machine generated */ 2 | #includeRSAPrivateKey
or DSAPrivateKey
20 | * containing a DSA or RSA private key of
21 | * the user in Trilead object format.
22 | * @param comment comment associated with this key
23 | * @param confirmUse whether to prompt before using this key
24 | * @param lifetime lifetime in seconds for key to be remembered
25 | * @return success or failure
26 | */
27 | boolean addIdentity(Object key, String comment, boolean confirmUse, int lifetime);
28 |
29 | /**
30 | * @param publicKey byte blob containing the OpenSSH-format encoded public key
31 | * @return success or failure
32 | */
33 | boolean removeIdentity(byte[] publicKey);
34 |
35 | /**
36 | * @return success or failure
37 | */
38 | boolean removeAllIdentities();
39 |
40 | /**
41 | * @param publicKey byte blob containing the OpenSSH-format encoded public key
42 | * @return A RSAPrivateKey
or DSAPrivateKey
43 | * containing a DSA or RSA private key of
44 | * the user in Trilead object format.
45 | */
46 | Object getPrivateKey(byte[] publicKey);
47 |
48 | /**
49 | * @return
50 | */
51 | boolean isAgentLocked();
52 |
53 | /**
54 | * @param lockPassphrase
55 | */
56 | boolean setAgentLock(String lockPassphrase);
57 |
58 | /**
59 | * @param unlockPassphrase
60 | * @return
61 | */
62 | boolean requestAgentUnlock(String unlockPassphrase);
63 | }
64 |
--------------------------------------------------------------------------------
/src/com/trilead/ssh2/ChannelCondition.java:
--------------------------------------------------------------------------------
1 |
2 | package com.trilead.ssh2;
3 |
4 | /**
5 | * Contains constants that can be used to specify what conditions to wait for on
6 | * a SSH-2 channel (e.g., represented by a {@link Session}).
7 | *
8 | * @see Session#waitForCondition(int, long)
9 | *
10 | * @author Christian Plattner, plattner@trilead.com
11 | * @version $Id: ChannelCondition.java,v 1.1 2007/10/15 12:49:56 cplattne Exp $
12 | */
13 |
14 | public abstract interface ChannelCondition
15 | {
16 | /**
17 | * A timeout has occurred, none of your requested conditions is fulfilled.
18 | * However, other conditions may be true - therefore, NEVER use the "=="
19 | * operator to test for this (or any other) condition. Always use
20 | * something like ((cond & ChannelCondition.CLOSED) != 0)
.
21 | */
22 | public static final int TIMEOUT = 1;
23 |
24 | /**
25 | * The underlying SSH-2 channel, however not necessarily the whole connection,
26 | * has been closed. This implies EOF
. Note that there may still
27 | * be unread stdout or stderr data in the local window, i.e, STDOUT_DATA
28 | * or/and STDERR_DATA
may be set at the same time.
29 | */
30 | public static final int CLOSED = 2;
31 |
32 | /**
33 | * There is stdout data available that is ready to be consumed.
34 | */
35 | public static final int STDOUT_DATA = 4;
36 |
37 | /**
38 | * There is stderr data available that is ready to be consumed.
39 | */
40 | public static final int STDERR_DATA = 8;
41 |
42 | /**
43 | * EOF on has been reached, no more _new_ stdout or stderr data will arrive
44 | * from the remote server. However, there may be unread stdout or stderr
45 | * data, i.e, STDOUT_DATA
or/and STDERR_DATA
46 | * may be set at the same time.
47 | */
48 | public static final int EOF = 16;
49 |
50 | /**
51 | * The exit status of the remote process is available.
52 | * Some servers never send the exist status, or occasionally "forget" to do so.
53 | */
54 | public static final int EXIT_STATUS = 32;
55 |
56 | /**
57 | * The exit signal of the remote process is available.
58 | */
59 | public static final int EXIT_SIGNAL = 64;
60 |
61 | }
62 |
--------------------------------------------------------------------------------
/src/com/trilead/ssh2/ConnectionInfo.java:
--------------------------------------------------------------------------------
1 |
2 | package com.trilead.ssh2;
3 |
4 | /**
5 | * In most cases you probably do not need the information contained in here.
6 | *
7 | * @author Christian Plattner, plattner@trilead.com
8 | * @version $Id: ConnectionInfo.java,v 1.1 2007/10/15 12:49:56 cplattne Exp $
9 | */
10 | public class ConnectionInfo
11 | {
12 | /**
13 | * The used key exchange (KEX) algorithm in the latest key exchange.
14 | */
15 | public String keyExchangeAlgorithm;
16 |
17 | /**
18 | * The currently used crypto algorithm for packets from to the client to the
19 | * server.
20 | */
21 | public String clientToServerCryptoAlgorithm;
22 | /**
23 | * The currently used crypto algorithm for packets from to the server to the
24 | * client.
25 | */
26 | public String serverToClientCryptoAlgorithm;
27 |
28 | /**
29 | * The currently used MAC algorithm for packets from to the client to the
30 | * server.
31 | */
32 | public String clientToServerMACAlgorithm;
33 | /**
34 | * The currently used MAC algorithm for packets from to the server to the
35 | * client.
36 | */
37 | public String serverToClientMACAlgorithm;
38 |
39 | /**
40 | * The type of the server host key (currently either "ssh-dss" or
41 | * "ssh-rsa").
42 | */
43 | public String serverHostKeyAlgorithm;
44 | /**
45 | * The server host key that was sent during the latest key exchange.
46 | */
47 | public byte[] serverHostKey;
48 |
49 | /**
50 | * Number of kex exchanges performed on this connection so far.
51 | */
52 | public int keyExchangeCounter = 0;
53 | }
54 |
--------------------------------------------------------------------------------
/src/com/trilead/ssh2/ConnectionMonitor.java:
--------------------------------------------------------------------------------
1 |
2 | package com.trilead.ssh2;
3 |
4 | /**
5 | * A ConnectionMonitor
is used to get notified when the
6 | * underlying socket of a connection is closed.
7 | *
8 | * @author Christian Plattner, plattner@trilead.com
9 | * @version $Id: ConnectionMonitor.java,v 1.1 2007/10/15 12:49:56 cplattne Exp $
10 | */
11 |
12 | public interface ConnectionMonitor
13 | {
14 | /**
15 | * This method is called after the connection's underlying
16 | * socket has been closed. E.g., due to the {@link Connection#close()} request of the
17 | * user, if the peer closed the connection, due to a fatal error during connect()
18 | * (also if the socket cannot be established) or if a fatal error occured on
19 | * an established connection.
20 | * 21 | * This is an experimental feature. 22 | *
23 | * You MUST NOT make any assumption about the thread that invokes this method. 24 | *
25 | * Please note: if the connection is not connected (e.g., there was no successful
26 | * connect() call), then the invocation of {@link Connection#close()} will NOT trigger
27 | * this method.
28 | *
29 | * @see Connection#addConnectionMonitor(ConnectionMonitor)
30 | *
31 | * @param reason Includes an indication why the socket was closed.
32 | */
33 | public void connectionLost(Throwable reason);
34 | }
--------------------------------------------------------------------------------
/src/com/trilead/ssh2/DebugLogger.java:
--------------------------------------------------------------------------------
1 | package com.trilead.ssh2;
2 |
3 | /**
4 | * An interface which needs to be implemented if you
5 | * want to capture debugging messages.
6 | *
7 | * @see Connection#enableDebugging(boolean, DebugLogger)
8 | *
9 | * @author Christian Plattner, plattner@trilead.com
10 | * @version $Id: DebugLogger.java,v 1.1 2008/03/03 07:01:36 cplattne Exp $
11 | */
12 | public interface DebugLogger
13 | {
14 |
15 | /**
16 | * Log a debug message.
17 | *
18 | * @param level 0-99, 99 is a the most verbose level
19 | * @param className the class that generated the message
20 | * @param message the debug message
21 | */
22 | public void log(int level, String className, String message);
23 | }
24 |
--------------------------------------------------------------------------------
/src/com/trilead/ssh2/DynamicPortForwarder.java:
--------------------------------------------------------------------------------
1 | /*
2 | * ConnectBot: simple, powerful, open-source SSH client for Android
3 | * Copyright 2007 Kenny Root, Jeffrey Sharkey
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | package com.trilead.ssh2;
19 |
20 | import java.io.IOException;
21 | import java.net.InetSocketAddress;
22 |
23 | import com.trilead.ssh2.channel.ChannelManager;
24 | import com.trilead.ssh2.channel.DynamicAcceptThread;
25 |
26 | /**
27 | * A DynamicPortForwarder
forwards TCP/IP connections to a local
28 | * port via the secure tunnel to another host which is selected via the
29 | * SOCKS protocol. Checkout {@link Connection#createDynamicPortForwarder(int)}
30 | * on how to create one.
31 | *
32 | * @author Kenny Root
33 | * @version $Id: $
34 | */
35 | public class DynamicPortForwarder {
36 | ChannelManager cm;
37 |
38 | DynamicAcceptThread dat;
39 |
40 | DynamicPortForwarder(ChannelManager cm, int local_port)
41 | throws IOException
42 | {
43 | this.cm = cm;
44 |
45 | dat = new DynamicAcceptThread(cm, local_port);
46 | dat.setDaemon(true);
47 | dat.start();
48 | }
49 |
50 | DynamicPortForwarder(ChannelManager cm, InetSocketAddress addr) throws IOException {
51 | this.cm = cm;
52 |
53 | dat = new DynamicAcceptThread(cm, addr);
54 | dat.setDaemon(true);
55 | dat.start();
56 | }
57 |
58 | /**
59 | * Stop TCP/IP forwarding of newly arriving connections.
60 | *
61 | * @throws IOException
62 | */
63 | public void close() throws IOException
64 | {
65 | dat.stopWorking();
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/src/com/trilead/ssh2/HTTPProxyException.java:
--------------------------------------------------------------------------------
1 |
2 | package com.trilead.ssh2;
3 |
4 | import java.io.IOException;
5 |
6 | /**
7 | * May be thrown upon connect() if a HTTP proxy is being used.
8 | *
9 | * @see Connection#connect()
10 | * @see Connection#setProxyData(ProxyData)
11 | *
12 | * @author Christian Plattner, plattner@trilead.com
13 | * @version $Id: HTTPProxyException.java,v 1.1 2007/10/15 12:49:56 cplattne Exp $
14 | */
15 |
16 | public class HTTPProxyException extends IOException
17 | {
18 | private static final long serialVersionUID = 2241537397104426186L;
19 |
20 | public final String httpResponse;
21 | public final int httpErrorCode;
22 |
23 | public HTTPProxyException(String httpResponse, int httpErrorCode)
24 | {
25 | super("HTTP Proxy Error (" + httpErrorCode + " " + httpResponse + ")");
26 | this.httpResponse = httpResponse;
27 | this.httpErrorCode = httpErrorCode;
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/src/com/trilead/ssh2/LocalPortForwarder.java:
--------------------------------------------------------------------------------
1 |
2 | package com.trilead.ssh2;
3 |
4 | import java.io.IOException;
5 | import java.net.InetSocketAddress;
6 |
7 | import com.trilead.ssh2.channel.ChannelManager;
8 | import com.trilead.ssh2.channel.LocalAcceptThread;
9 |
10 |
11 | /**
12 | * A LocalPortForwarder
forwards TCP/IP connections to a local
13 | * port via the secure tunnel to another host (which may or may not be identical
14 | * to the remote SSH-2 server). Checkout {@link Connection#createLocalPortForwarder(int, String, int)}
15 | * on how to create one.
16 | *
17 | * @author Christian Plattner, plattner@trilead.com
18 | * @version $Id: LocalPortForwarder.java,v 1.1 2007/10/15 12:49:56 cplattne Exp $
19 | */
20 | public class LocalPortForwarder
21 | {
22 | ChannelManager cm;
23 |
24 | String host_to_connect;
25 |
26 | int port_to_connect;
27 |
28 | LocalAcceptThread lat;
29 |
30 | LocalPortForwarder(ChannelManager cm, int local_port, String host_to_connect, int port_to_connect)
31 | throws IOException
32 | {
33 | this.cm = cm;
34 | this.host_to_connect = host_to_connect;
35 | this.port_to_connect = port_to_connect;
36 |
37 | lat = new LocalAcceptThread(cm, local_port, host_to_connect, port_to_connect);
38 | lat.setDaemon(true);
39 | lat.start();
40 | }
41 |
42 | LocalPortForwarder(ChannelManager cm, InetSocketAddress addr, String host_to_connect, int port_to_connect)
43 | throws IOException
44 | {
45 | this.cm = cm;
46 | this.host_to_connect = host_to_connect;
47 | this.port_to_connect = port_to_connect;
48 |
49 | lat = new LocalAcceptThread(cm, addr, host_to_connect, port_to_connect);
50 | lat.setDaemon(true);
51 | lat.start();
52 | }
53 |
54 | /**
55 | * Stop TCP/IP forwarding of newly arriving connections.
56 | *
57 | * @throws IOException
58 | */
59 | public void close() throws IOException
60 | {
61 | lat.stopWorking();
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/src/com/trilead/ssh2/ProxyData.java:
--------------------------------------------------------------------------------
1 |
2 | package com.trilead.ssh2;
3 |
4 | /**
5 | * An abstract marker interface implemented by all proxy data implementations.
6 | *
7 | * @see HTTPProxyData
8 | *
9 | * @author Christian Plattner, plattner@trilead.com
10 | * @version $Id: ProxyData.java,v 1.1 2007/10/15 12:49:56 cplattne Exp $
11 | */
12 |
13 | public abstract interface ProxyData
14 | {
15 | }
16 |
--------------------------------------------------------------------------------
/src/com/trilead/ssh2/SFTPv3DirectoryEntry.java:
--------------------------------------------------------------------------------
1 |
2 | package com.trilead.ssh2;
3 |
4 | /**
5 | * A SFTPv3DirectoryEntry
as returned by {@link SFTPv3Client#ls(String)}.
6 | *
7 | * @author Christian Plattner, plattner@trilead.com
8 | * @version $Id: SFTPv3DirectoryEntry.java,v 1.1 2007/10/15 12:49:56 cplattne Exp $
9 | */
10 |
11 | public class SFTPv3DirectoryEntry
12 | {
13 | /**
14 | * A relative name within the directory, without any path components.
15 | */
16 | public String filename;
17 |
18 | /**
19 | * An expanded format for the file name, similar to what is returned by
20 | * "ls -l" on Un*x systems.
21 | *
22 | * The format of this field is unspecified by the SFTP v3 protocol. 23 | * It MUST be suitable for use in the output of a directory listing 24 | * command (in fact, the recommended operation for a directory listing 25 | * command is to simply display this data). However, clients SHOULD NOT 26 | * attempt to parse the longname field for file attributes; they SHOULD 27 | * use the attrs field instead. 28 | *
29 | * The recommended format for the longname field is as follows:
30 | * -rwxr-xr-x 1 mjos staff 348911 Mar 25 14:29 t-filexfer
31 | */
32 | public String longEntry;
33 |
34 | /**
35 | * The attributes of this entry.
36 | */
37 | public SFTPv3FileAttributes attributes;
38 | }
39 |
--------------------------------------------------------------------------------
/src/com/trilead/ssh2/SFTPv3FileHandle.java:
--------------------------------------------------------------------------------
1 |
2 | package com.trilead.ssh2;
3 |
4 | /**
5 | * A SFTPv3FileHandle
.
6 | *
7 | * @author Christian Plattner, plattner@trilead.com
8 | * @version $Id: SFTPv3FileHandle.java,v 1.1 2007/10/15 12:49:56 cplattne Exp $
9 | */
10 |
11 | public class SFTPv3FileHandle
12 | {
13 | final SFTPv3Client client;
14 | final byte[] fileHandle;
15 | boolean isClosed = false;
16 |
17 | /* The constructor is NOT public */
18 |
19 | SFTPv3FileHandle(SFTPv3Client client, byte[] h)
20 | {
21 | this.client = client;
22 | this.fileHandle = h;
23 | }
24 |
25 | /**
26 | * Get the SFTPv3Client instance which created this handle.
27 | *
28 | * @return A SFTPv3Client instance.
29 | */
30 | public SFTPv3Client getClient()
31 | {
32 | return client;
33 | }
34 |
35 | /**
36 | * Check if this handle was closed with the {@link SFTPv3Client#closeFile(SFTPv3FileHandle)} method
37 | * of the SFTPv3Client
instance which created the handle.
38 | *
39 | * @return if the handle is closed.
40 | */
41 | public boolean isClosed()
42 | {
43 | return isClosed;
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/src/com/trilead/ssh2/ServerHostKeyVerifier.java:
--------------------------------------------------------------------------------
1 |
2 | package com.trilead.ssh2;
3 |
4 | /**
5 | * A callback interface used to implement a client specific method of checking
6 | * server host keys.
7 | *
8 | * @author Christian Plattner, plattner@trilead.com
9 | * @version $Id: ServerHostKeyVerifier.java,v 1.1 2007/10/15 12:49:56 cplattne Exp $
10 | */
11 |
12 | public interface ServerHostKeyVerifier
13 | {
14 | /**
15 | * The actual verifier method, it will be called by the key exchange code
16 | * on EVERY key exchange - this can happen several times during the lifetime
17 | * of a connection.
18 | *
19 | * Note: SSH-2 servers are allowed to change their hostkey at ANY time.
20 | *
21 | * @param hostname the hostname used to create the {@link Connection} object
22 | * @param port the remote TCP port
23 | * @param serverHostKeyAlgorithm the public key algorithm (ssh-rsa
or ssh-dss
)
24 | * @param serverHostKey the server's public key blob
25 | * @return if the client wants to accept the server's host key - if not, the
26 | * connection will be closed.
27 | * @throws Exception Will be wrapped with an IOException, extended version of returning false =)
28 | */
29 | public boolean verifyServerHostKey(String hostname, int port, String serverHostKeyAlgorithm, byte[] serverHostKey)
30 | throws Exception;
31 | }
32 |
--------------------------------------------------------------------------------
/src/com/trilead/ssh2/channel/ChannelInputStream.java:
--------------------------------------------------------------------------------
1 |
2 | package com.trilead.ssh2.channel;
3 |
4 | import java.io.IOException;
5 | import java.io.InputStream;
6 |
7 | /**
8 | * ChannelInputStream.
9 | *
10 | * @author Christian Plattner, plattner@trilead.com
11 | * @version $Id: ChannelInputStream.java,v 1.1 2007/10/15 12:49:56 cplattne Exp $
12 | */
13 | public final class ChannelInputStream extends InputStream
14 | {
15 | Channel c;
16 |
17 | boolean isClosed = false;
18 | boolean isEOF = false;
19 | boolean extendedFlag = false;
20 |
21 | ChannelInputStream(Channel c, boolean isExtended)
22 | {
23 | this.c = c;
24 | this.extendedFlag = isExtended;
25 | }
26 |
27 | public int available() throws IOException
28 | {
29 | if (isEOF)
30 | return 0;
31 |
32 | int avail = c.cm.getAvailable(c, extendedFlag);
33 |
34 | /* We must not return -1 on EOF */
35 |
36 | return (avail > 0) ? avail : 0;
37 | }
38 |
39 | public void close() throws IOException
40 | {
41 | isClosed = true;
42 | }
43 |
44 | public int read(byte[] b, int off, int len) throws IOException
45 | {
46 | if (b == null)
47 | throw new NullPointerException();
48 |
49 | if ((off < 0) || (len < 0) || ((off + len) > b.length) || ((off + len) < 0) || (off > b.length))
50 | throw new IndexOutOfBoundsException();
51 |
52 | if (len == 0)
53 | return 0;
54 |
55 | if (isEOF)
56 | return -1;
57 |
58 | int ret = c.cm.getChannelData(c, extendedFlag, b, off, len);
59 |
60 | if (ret == -1)
61 | {
62 | isEOF = true;
63 | }
64 |
65 | return ret;
66 | }
67 |
68 | public int read(byte[] b) throws IOException
69 | {
70 | return read(b, 0, b.length);
71 | }
72 |
73 | public int read() throws IOException
74 | {
75 | /* Yes, this stream is pure and unbuffered, a single byte read() is slow */
76 |
77 | final byte b[] = new byte[1];
78 |
79 | int ret = read(b, 0, 1);
80 |
81 | if (ret != 1)
82 | return -1;
83 |
84 | return b[0] & 0xff;
85 | }
86 | }
87 |
--------------------------------------------------------------------------------
/src/com/trilead/ssh2/channel/ChannelOutputStream.java:
--------------------------------------------------------------------------------
1 | package com.trilead.ssh2.channel;
2 |
3 | import java.io.IOException;
4 | import java.io.OutputStream;
5 |
6 | /**
7 | * ChannelOutputStream.
8 | *
9 | * @author Christian Plattner, plattner@trilead.com
10 | * @version $Id: ChannelOutputStream.java,v 1.1 2007/10/15 12:49:56 cplattne Exp $
11 | */
12 | public final class ChannelOutputStream extends OutputStream
13 | {
14 | Channel c;
15 |
16 | private byte[] writeBuffer;
17 |
18 | boolean isClosed = false;
19 |
20 | ChannelOutputStream(Channel c)
21 | {
22 | this.c = c;
23 | writeBuffer = new byte[1];
24 | }
25 |
26 | public void write(int b) throws IOException
27 | {
28 | writeBuffer[0] = (byte) b;
29 |
30 | write(writeBuffer, 0, 1);
31 | }
32 |
33 | public void close() throws IOException
34 | {
35 | if (isClosed == false)
36 | {
37 | isClosed = true;
38 | c.cm.sendEOF(c);
39 | }
40 | }
41 |
42 | public void flush() throws IOException
43 | {
44 | if (isClosed)
45 | throw new IOException("This OutputStream is closed.");
46 |
47 | /* This is a no-op, since this stream is unbuffered */
48 | }
49 |
50 | public void write(byte[] b, int off, int len) throws IOException
51 | {
52 | if (isClosed)
53 | throw new IOException("This OutputStream is closed.");
54 |
55 | if (b == null)
56 | throw new NullPointerException();
57 |
58 | if ((off < 0) || (len < 0) || ((off + len) > b.length) || ((off + len) < 0) || (off > b.length))
59 | throw new IndexOutOfBoundsException();
60 |
61 | if (len == 0)
62 | return;
63 |
64 | c.cm.sendData(c, b, off, len);
65 | }
66 |
67 | public void write(byte[] b) throws IOException
68 | {
69 | write(b, 0, b.length);
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/src/com/trilead/ssh2/channel/IChannelWorkerThread.java:
--------------------------------------------------------------------------------
1 |
2 | package com.trilead.ssh2.channel;
3 |
4 | /**
5 | * IChannelWorkerThread.
6 | *
7 | * @author Christian Plattner, plattner@trilead.com
8 | * @version $Id: IChannelWorkerThread.java,v 1.1 2007/10/15 12:49:56 cplattne Exp $
9 | */
10 | interface IChannelWorkerThread
11 | {
12 | public void stopWorking();
13 | }
14 |
--------------------------------------------------------------------------------
/src/com/trilead/ssh2/channel/RemoteForwardingData.java:
--------------------------------------------------------------------------------
1 |
2 | package com.trilead.ssh2.channel;
3 |
4 | /**
5 | * RemoteForwardingData. Data about a requested remote forwarding.
6 | *
7 | * @author Christian Plattner, plattner@trilead.com
8 | * @version $Id: RemoteForwardingData.java,v 1.1 2007/10/15 12:49:56 cplattne Exp $
9 | */
10 | public class RemoteForwardingData
11 | {
12 | public String bindAddress;
13 | public int bindPort;
14 |
15 | String targetAddress;
16 | int targetPort;
17 | }
18 |
--------------------------------------------------------------------------------
/src/com/trilead/ssh2/channel/X11ServerData.java:
--------------------------------------------------------------------------------
1 |
2 | package com.trilead.ssh2.channel;
3 |
4 | /**
5 | * X11ServerData. Data regarding an x11 forwarding target.
6 | *
7 | * @author Christian Plattner, plattner@trilead.com
8 | * @version $Id: X11ServerData.java,v 1.1 2007/10/15 12:49:56 cplattne Exp $
9 | *
10 | */
11 | public class X11ServerData
12 | {
13 | public String hostname;
14 | public int port;
15 | public byte[] x11_magic_cookie; /* not the remote (fake) one, the local (real) one */
16 | }
17 |
--------------------------------------------------------------------------------
/src/com/trilead/ssh2/compression/ICompressor.java:
--------------------------------------------------------------------------------
1 | /*
2 | * ConnectBot: simple, powerful, open-source SSH client for Android
3 | * Copyright 2007 Kenny Root, Jeffrey Sharkey
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | package com.trilead.ssh2.compression;
19 |
20 | /**
21 | * @author Kenny Root
22 | *
23 | */
24 | public interface ICompressor {
25 | int getBufferSize();
26 |
27 | int compress(byte[] buf, int start, int len, byte[] output);
28 |
29 | byte[] uncompress(byte[] buf, int start, int[] len);
30 |
31 | boolean canCompressPreauth();
32 | }
33 |
--------------------------------------------------------------------------------
/src/com/trilead/ssh2/compression/ZlibOpenSSH.java:
--------------------------------------------------------------------------------
1 | /*
2 | * ConnectBot: simple, powerful, open-source SSH client for Android
3 | * Copyright 2007 Kenny Root, Jeffrey Sharkey
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | package com.trilead.ssh2.compression;
19 |
20 | /**
21 | * Defines how zlib@openssh.org compression works.
22 | * See
23 | * http://www.openssh.org/txt/draft-miller-secsh-compression-delayed-00.txt
24 | * compression is disabled until userauth has occurred.
25 | *
26 | * @author Matt Johnston
27 | *
28 | */
29 | public class ZlibOpenSSH extends Zlib {
30 |
31 | public boolean canCompressPreauth() {
32 | return false;
33 | }
34 |
35 | }
36 |
--------------------------------------------------------------------------------
/src/com/trilead/ssh2/crypto/CryptoWishList.java:
--------------------------------------------------------------------------------
1 |
2 | package com.trilead.ssh2.crypto;
3 |
4 | import com.trilead.ssh2.compression.CompressionFactory;
5 | import com.trilead.ssh2.crypto.cipher.BlockCipherFactory;
6 | import com.trilead.ssh2.crypto.digest.MAC;
7 | import com.trilead.ssh2.transport.KexManager;
8 |
9 |
10 | /**
11 | * CryptoWishList.
12 | *
13 | * @author Christian Plattner, plattner@trilead.com
14 | * @version $Id: CryptoWishList.java,v 1.1 2007/10/15 12:49:56 cplattne Exp $
15 | */
16 | public class CryptoWishList
17 | {
18 | public String[] kexAlgorithms = KexManager.getDefaultKexAlgorithmList();
19 | public String[] serverHostKeyAlgorithms = KexManager.getDefaultServerHostkeyAlgorithmList();
20 | public String[] c2s_enc_algos = BlockCipherFactory.getDefaultCipherList();
21 | public String[] s2c_enc_algos = BlockCipherFactory.getDefaultCipherList();
22 | public String[] c2s_mac_algos = MAC.getMacList();
23 | public String[] s2c_mac_algos = MAC.getMacList();
24 | public String[] c2s_comp_algos = CompressionFactory.getDefaultCompressorList();
25 | public String[] s2c_comp_algos = CompressionFactory.getDefaultCompressorList();
26 | }
27 |
--------------------------------------------------------------------------------
/src/com/trilead/ssh2/crypto/PEMStructure.java:
--------------------------------------------------------------------------------
1 |
2 | package com.trilead.ssh2.crypto;
3 |
4 | /**
5 | * Parsed PEM structure.
6 | *
7 | * @author Christian Plattner, plattner@trilead.com
8 | * @version $Id: PEMStructure.java,v 1.1 2007/10/15 12:49:56 cplattne Exp $
9 | */
10 |
11 | public class PEMStructure
12 | {
13 | public int pemType;
14 | String dekInfo[];
15 | String procType[];
16 | public byte[] data;
17 | }
--------------------------------------------------------------------------------
/src/com/trilead/ssh2/crypto/cipher/BlockCipher.java:
--------------------------------------------------------------------------------
1 | package com.trilead.ssh2.crypto.cipher;
2 |
3 | /**
4 | * BlockCipher.
5 | *
6 | * @author Christian Plattner, plattner@trilead.com
7 | * @version $Id: BlockCipher.java,v 1.1 2007/10/15 12:49:55 cplattne Exp $
8 | */
9 | public interface BlockCipher
10 | {
11 | public void init(boolean forEncryption, byte[] key);
12 |
13 | public int getBlockSize();
14 |
15 | public void transformBlock(byte[] src, int srcoff, byte[] dst, int dstoff);
16 | }
17 |
--------------------------------------------------------------------------------
/src/com/trilead/ssh2/crypto/cipher/CBCMode.java:
--------------------------------------------------------------------------------
1 | package com.trilead.ssh2.crypto.cipher;
2 |
3 | /**
4 | * CBCMode.
5 | *
6 | * @author Christian Plattner, plattner@trilead.com
7 | * @version $Id: CBCMode.java,v 1.1 2007/10/15 12:49:55 cplattne Exp $
8 | */
9 | public class CBCMode implements BlockCipher
10 | {
11 | BlockCipher tc;
12 | int blockSize;
13 | boolean doEncrypt;
14 |
15 | byte[] cbc_vector;
16 | byte[] tmp_vector;
17 |
18 | public void init(boolean forEncryption, byte[] key)
19 | {
20 | }
21 |
22 | public CBCMode(BlockCipher tc, byte[] iv, boolean doEncrypt)
23 | throws IllegalArgumentException
24 | {
25 | this.tc = tc;
26 | this.blockSize = tc.getBlockSize();
27 | this.doEncrypt = doEncrypt;
28 |
29 | if (this.blockSize != iv.length)
30 | throw new IllegalArgumentException("IV must be " + blockSize
31 | + " bytes long! (currently " + iv.length + ")");
32 |
33 | this.cbc_vector = new byte[blockSize];
34 | this.tmp_vector = new byte[blockSize];
35 | System.arraycopy(iv, 0, cbc_vector, 0, blockSize);
36 | }
37 |
38 | public int getBlockSize()
39 | {
40 | return blockSize;
41 | }
42 |
43 | private void encryptBlock(byte[] src, int srcoff, byte[] dst, int dstoff)
44 | {
45 | for (int i = 0; i < blockSize; i++)
46 | cbc_vector[i] ^= src[srcoff + i];
47 |
48 | tc.transformBlock(cbc_vector, 0, dst, dstoff);
49 |
50 | System.arraycopy(dst, dstoff, cbc_vector, 0, blockSize);
51 | }
52 |
53 | private void decryptBlock(byte[] src, int srcoff, byte[] dst, int dstoff)
54 | {
55 | /* Assume the worst, src and dst are overlapping... */
56 |
57 | System.arraycopy(src, srcoff, tmp_vector, 0, blockSize);
58 |
59 | tc.transformBlock(src, srcoff, dst, dstoff);
60 |
61 | for (int i = 0; i < blockSize; i++)
62 | dst[dstoff + i] ^= cbc_vector[i];
63 |
64 | /* ...that is why we need a tmp buffer. */
65 |
66 | byte[] swap = cbc_vector;
67 | cbc_vector = tmp_vector;
68 | tmp_vector = swap;
69 | }
70 |
71 | public void transformBlock(byte[] src, int srcoff, byte[] dst, int dstoff)
72 | {
73 | if (doEncrypt)
74 | encryptBlock(src, srcoff, dst, dstoff);
75 | else
76 | decryptBlock(src, srcoff, dst, dstoff);
77 | }
78 | }
79 |
--------------------------------------------------------------------------------
/src/com/trilead/ssh2/crypto/cipher/CTRMode.java:
--------------------------------------------------------------------------------
1 |
2 | package com.trilead.ssh2.crypto.cipher;
3 |
4 | /**
5 | * This is CTR mode as described in draft-ietf-secsh-newmodes-XY.txt
6 | *
7 | * @author Christian Plattner, plattner@trilead.com
8 | * @version $Id: CTRMode.java,v 1.1 2007/10/15 12:49:55 cplattne Exp $
9 | */
10 | public class CTRMode implements BlockCipher
11 | {
12 | byte[] X;
13 | byte[] Xenc;
14 |
15 | BlockCipher bc;
16 | int blockSize;
17 | boolean doEncrypt;
18 |
19 | int count = 0;
20 |
21 | public void init(boolean forEncryption, byte[] key)
22 | {
23 | }
24 |
25 | public CTRMode(BlockCipher tc, byte[] iv, boolean doEnc) throws IllegalArgumentException
26 | {
27 | bc = tc;
28 | blockSize = bc.getBlockSize();
29 | doEncrypt = doEnc;
30 |
31 | if (blockSize != iv.length)
32 | throw new IllegalArgumentException("IV must be " + blockSize + " bytes long! (currently " + iv.length + ")");
33 |
34 | X = new byte[blockSize];
35 | Xenc = new byte[blockSize];
36 |
37 | System.arraycopy(iv, 0, X, 0, blockSize);
38 | }
39 |
40 | public final int getBlockSize()
41 | {
42 | return blockSize;
43 | }
44 |
45 | public final void transformBlock(byte[] src, int srcoff, byte[] dst, int dstoff)
46 | {
47 | bc.transformBlock(X, 0, Xenc, 0);
48 |
49 | for (int i = 0; i < blockSize; i++)
50 | {
51 | dst[dstoff + i] = (byte) (src[srcoff + i] ^ Xenc[i]);
52 | }
53 |
54 | for (int i = (blockSize - 1); i >= 0; i--)
55 | {
56 | X[i]++;
57 | if (X[i] != 0)
58 | break;
59 |
60 | }
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/src/com/trilead/ssh2/crypto/cipher/NullCipher.java:
--------------------------------------------------------------------------------
1 | package com.trilead.ssh2.crypto.cipher;
2 |
3 | /**
4 | * NullCipher.
5 | *
6 | * @author Christian Plattner, plattner@trilead.com
7 | * @version $Id: NullCipher.java,v 1.1 2007/10/15 12:49:55 cplattne Exp $
8 | */
9 | public class NullCipher implements BlockCipher
10 | {
11 | private int blockSize = 8;
12 |
13 | public NullCipher()
14 | {
15 | }
16 |
17 | public NullCipher(int blockSize)
18 | {
19 | this.blockSize = blockSize;
20 | }
21 |
22 | public void init(boolean forEncryption, byte[] key)
23 | {
24 | }
25 |
26 | public int getBlockSize()
27 | {
28 | return blockSize;
29 | }
30 |
31 | public void transformBlock(byte[] src, int srcoff, byte[] dst, int dstoff)
32 | {
33 | System.arraycopy(src, srcoff, dst, dstoff, blockSize);
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/src/com/trilead/ssh2/crypto/digest/Digest.java:
--------------------------------------------------------------------------------
1 |
2 | package com.trilead.ssh2.crypto.digest;
3 |
4 | /**
5 | * Digest.
6 | *
7 | * @author Christian Plattner, plattner@trilead.com
8 | * @version $Id: Digest.java,v 1.1 2007/10/15 12:49:57 cplattne Exp $
9 | */
10 | public interface Digest
11 | {
12 | public int getDigestLength();
13 |
14 | public void update(byte b);
15 |
16 | public void update(byte[] b);
17 |
18 | public void update(byte b[], int off, int len);
19 |
20 | public void reset();
21 |
22 | public void digest(byte[] out);
23 |
24 | public void digest(byte[] out, int off);
25 | }
26 |
--------------------------------------------------------------------------------
/src/com/trilead/ssh2/crypto/digest/HMAC.java:
--------------------------------------------------------------------------------
1 |
2 | package com.trilead.ssh2.crypto.digest;
3 |
4 | /**
5 | * HMAC.
6 | *
7 | * @author Christian Plattner, plattner@trilead.com
8 | * @version $Id: HMAC.java,v 1.1 2007/10/15 12:49:57 cplattne Exp $
9 | */
10 | public final class HMAC implements Digest
11 | {
12 | Digest md;
13 | byte[] k_xor_ipad;
14 | byte[] k_xor_opad;
15 |
16 | byte[] tmp;
17 |
18 | int size;
19 |
20 | public HMAC(Digest md, byte[] key, int size)
21 | {
22 | this.md = md;
23 | this.size = size;
24 |
25 | tmp = new byte[md.getDigestLength()];
26 |
27 | final int BLOCKSIZE = 64;
28 |
29 | k_xor_ipad = new byte[BLOCKSIZE];
30 | k_xor_opad = new byte[BLOCKSIZE];
31 |
32 | if (key.length > BLOCKSIZE)
33 | {
34 | md.reset();
35 | md.update(key);
36 | md.digest(tmp);
37 | key = tmp;
38 | }
39 |
40 | System.arraycopy(key, 0, k_xor_ipad, 0, key.length);
41 | System.arraycopy(key, 0, k_xor_opad, 0, key.length);
42 |
43 | for (int i = 0; i < BLOCKSIZE; i++)
44 | {
45 | k_xor_ipad[i] ^= 0x36;
46 | k_xor_opad[i] ^= 0x5C;
47 | }
48 | md.update(k_xor_ipad);
49 | }
50 |
51 | public final int getDigestLength()
52 | {
53 | return size;
54 | }
55 |
56 | public final void update(byte b)
57 | {
58 | md.update(b);
59 | }
60 |
61 | public final void update(byte[] b)
62 | {
63 | md.update(b);
64 | }
65 |
66 | public final void update(byte[] b, int off, int len)
67 | {
68 | md.update(b, off, len);
69 | }
70 |
71 | public final void reset()
72 | {
73 | md.reset();
74 | md.update(k_xor_ipad);
75 | }
76 |
77 | public final void digest(byte[] out)
78 | {
79 | digest(out, 0);
80 | }
81 |
82 | public final void digest(byte[] out, int off)
83 | {
84 | md.digest(tmp);
85 |
86 | md.update(k_xor_opad);
87 | md.update(tmp);
88 |
89 | md.digest(tmp);
90 |
91 | System.arraycopy(tmp, 0, out, off, size);
92 |
93 | md.update(k_xor_ipad);
94 | }
95 | }
96 |
--------------------------------------------------------------------------------
/src/com/trilead/ssh2/crypto/digest/HashForSSH2Types.java:
--------------------------------------------------------------------------------
1 |
2 | package com.trilead.ssh2.crypto.digest;
3 |
4 | import java.math.BigInteger;
5 |
6 | /**
7 | * HashForSSH2Types.
8 | *
9 | * @author Christian Plattner, plattner@trilead.com
10 | * @version $Id: HashForSSH2Types.java,v 1.1 2007/10/15 12:49:57 cplattne Exp $
11 | */
12 | public class HashForSSH2Types
13 | {
14 | Digest md;
15 |
16 | public HashForSSH2Types(Digest md)
17 | {
18 | this.md = md;
19 | }
20 |
21 | public HashForSSH2Types(String type)
22 | {
23 | if (type.equals("SHA1"))
24 | {
25 | md = new SHA1();
26 | }
27 | else if (type.equals("MD5"))
28 | {
29 | md = new MD5();
30 | }
31 | else
32 | throw new IllegalArgumentException("Unknown algorithm " + type);
33 | }
34 |
35 | public void updateByte(byte b)
36 | {
37 | /* HACK - to test it with J2ME */
38 | byte[] tmp = new byte[1];
39 | tmp[0] = b;
40 | md.update(tmp);
41 | }
42 |
43 | public void updateBytes(byte[] b)
44 | {
45 | md.update(b);
46 | }
47 |
48 | public void updateUINT32(int v)
49 | {
50 | md.update((byte) (v >> 24));
51 | md.update((byte) (v >> 16));
52 | md.update((byte) (v >> 8));
53 | md.update((byte) (v));
54 | }
55 |
56 | public void updateByteString(byte[] b)
57 | {
58 | updateUINT32(b.length);
59 | updateBytes(b);
60 | }
61 |
62 | public void updateBigInt(BigInteger b)
63 | {
64 | updateByteString(b.toByteArray());
65 | }
66 |
67 | public void reset()
68 | {
69 | md.reset();
70 | }
71 |
72 | public int getDigestLength()
73 | {
74 | return md.getDigestLength();
75 | }
76 |
77 | public byte[] getDigest()
78 | {
79 | byte[] tmp = new byte[md.getDigestLength()];
80 | getDigest(tmp);
81 | return tmp;
82 | }
83 |
84 | public void getDigest(byte[] out)
85 | {
86 | getDigest(out, 0);
87 | }
88 |
89 | public void getDigest(byte[] out, int off)
90 | {
91 | md.digest(out, off);
92 | }
93 | }
94 |
--------------------------------------------------------------------------------
/src/com/trilead/ssh2/crypto/digest/MAC.java:
--------------------------------------------------------------------------------
1 |
2 | package com.trilead.ssh2.crypto.digest;
3 |
4 | /**
5 | * MAC.
6 | *
7 | * @author Christian Plattner, plattner@trilead.com
8 | * @version $Id: MAC.java,v 1.1 2007/10/15 12:49:57 cplattne Exp $
9 | */
10 | public final class MAC
11 | {
12 | Digest mac;
13 | int size;
14 |
15 | public final static String[] getMacList()
16 | {
17 | /* Higher Priority First */
18 |
19 | return new String[] { "hmac-sha1-96", "hmac-sha1", "hmac-md5-96", "hmac-md5" };
20 | }
21 |
22 | public final static void checkMacList(String[] macs)
23 | {
24 | for (int i = 0; i < macs.length; i++)
25 | getKeyLen(macs[i]);
26 | }
27 |
28 | public final static int getKeyLen(String type)
29 | {
30 | if (type.equals("hmac-sha1"))
31 | return 20;
32 | if (type.equals("hmac-sha1-96"))
33 | return 20;
34 | if (type.equals("hmac-md5"))
35 | return 16;
36 | if (type.equals("hmac-md5-96"))
37 | return 16;
38 | throw new IllegalArgumentException("Unkown algorithm " + type);
39 | }
40 |
41 | public MAC(String type, byte[] key)
42 | {
43 | if (type.equals("hmac-sha1"))
44 | {
45 | mac = new HMAC(new SHA1(), key, 20);
46 | }
47 | else if (type.equals("hmac-sha1-96"))
48 | {
49 | mac = new HMAC(new SHA1(), key, 12);
50 | }
51 | else if (type.equals("hmac-md5"))
52 | {
53 | mac = new HMAC(new MD5(), key, 16);
54 | }
55 | else if (type.equals("hmac-md5-96"))
56 | {
57 | mac = new HMAC(new MD5(), key, 12);
58 | }
59 | else
60 | throw new IllegalArgumentException("Unkown algorithm " + type);
61 |
62 | size = mac.getDigestLength();
63 | }
64 |
65 | public final void initMac(int seq)
66 | {
67 | mac.reset();
68 | mac.update((byte) (seq >> 24));
69 | mac.update((byte) (seq >> 16));
70 | mac.update((byte) (seq >> 8));
71 | mac.update((byte) (seq));
72 | }
73 |
74 | public final void update(byte[] packetdata, int off, int len)
75 | {
76 | mac.update(packetdata, off, len);
77 | }
78 |
79 | public final void getMac(byte[] out, int off)
80 | {
81 | mac.digest(out, off);
82 | }
83 |
84 | public final int size()
85 | {
86 | return size;
87 | }
88 | }
89 |
--------------------------------------------------------------------------------
/src/com/trilead/ssh2/log/Logger.java:
--------------------------------------------------------------------------------
1 |
2 | package com.trilead.ssh2.log;
3 |
4 | import com.trilead.ssh2.DebugLogger;
5 |
6 | /**
7 | * Logger - a very simple logger, mainly used during development.
8 | * Is not based on log4j (to reduce external dependencies).
9 | * However, if needed, something like log4j could easily be
10 | * hooked in.
11 | *
12 | * For speed reasons, the static variables are not protected 13 | * with semaphores. In other words, if you dynamicaly change the 14 | * logging settings, then some threads may still use the old setting. 15 | * 16 | * @author Christian Plattner, plattner@trilead.com 17 | * @version $Id: Logger.java,v 1.2 2008/03/03 07:01:36 cplattne Exp $ 18 | */ 19 | 20 | public class Logger 21 | { 22 | public static boolean enabled = false; 23 | public static DebugLogger logger = null; 24 | 25 | private String className; 26 | 27 | public final static Logger getLogger(Class x) 28 | { 29 | return new Logger(x); 30 | } 31 | 32 | public Logger(Class x) 33 | { 34 | this.className = x.getName(); 35 | } 36 | 37 | public final boolean isEnabled() 38 | { 39 | return enabled; 40 | } 41 | 42 | public final void log(int level, String message) 43 | { 44 | if (!enabled) 45 | return; 46 | 47 | DebugLogger target = logger; 48 | 49 | if (target == null) 50 | return; 51 | 52 | target.log(level, className, message); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/com/trilead/ssh2/packets/PacketChannelAuthAgentReq.java: -------------------------------------------------------------------------------- 1 | package com.trilead.ssh2.packets; 2 | 3 | /** 4 | * PacketGlobalAuthAgent. 5 | * 6 | * @author Kenny Root, kenny@the-b.org 7 | * @version $Id$ 8 | */ 9 | public class PacketChannelAuthAgentReq 10 | { 11 | byte[] payload; 12 | 13 | public int recipientChannelID; 14 | 15 | public PacketChannelAuthAgentReq(int recipientChannelID) 16 | { 17 | this.recipientChannelID = recipientChannelID; 18 | } 19 | 20 | public byte[] getPayload() 21 | { 22 | if (payload == null) 23 | { 24 | TypesWriter tw = new TypesWriter(); 25 | tw.writeByte(Packets.SSH_MSG_CHANNEL_REQUEST); 26 | tw.writeUINT32(recipientChannelID); 27 | tw.writeString("auth-agent-req@openssh.com"); 28 | tw.writeBoolean(true); // want reply 29 | payload = tw.getBytes(); 30 | } 31 | return payload; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/com/trilead/ssh2/packets/PacketChannelOpenConfirmation.java: -------------------------------------------------------------------------------- 1 | package com.trilead.ssh2.packets; 2 | 3 | import java.io.IOException; 4 | 5 | /** 6 | * PacketChannelOpenConfirmation. 7 | * 8 | * @author Christian Plattner, plattner@trilead.com 9 | * @version $Id: PacketChannelOpenConfirmation.java,v 1.1 2007/10/15 12:49:55 cplattne Exp $ 10 | */ 11 | public class PacketChannelOpenConfirmation 12 | { 13 | byte[] payload; 14 | 15 | public int recipientChannelID; 16 | public int senderChannelID; 17 | public int initialWindowSize; 18 | public int maxPacketSize; 19 | 20 | public PacketChannelOpenConfirmation(int recipientChannelID, int senderChannelID, int initialWindowSize, 21 | int maxPacketSize) 22 | { 23 | this.recipientChannelID = recipientChannelID; 24 | this.senderChannelID = senderChannelID; 25 | this.initialWindowSize = initialWindowSize; 26 | this.maxPacketSize = maxPacketSize; 27 | } 28 | 29 | public PacketChannelOpenConfirmation(byte payload[], int off, int len) throws IOException 30 | { 31 | this.payload = new byte[len]; 32 | System.arraycopy(payload, off, this.payload, 0, len); 33 | 34 | TypesReader tr = new TypesReader(payload, off, len); 35 | 36 | int packet_type = tr.readByte(); 37 | 38 | if (packet_type != Packets.SSH_MSG_CHANNEL_OPEN_CONFIRMATION) 39 | throw new IOException( 40 | "This is not a SSH_MSG_CHANNEL_OPEN_CONFIRMATION! (" 41 | + packet_type + ")"); 42 | 43 | recipientChannelID = tr.readUINT32(); 44 | senderChannelID = tr.readUINT32(); 45 | initialWindowSize = tr.readUINT32(); 46 | maxPacketSize = tr.readUINT32(); 47 | 48 | if (tr.remain() != 0) 49 | throw new IOException("Padding in SSH_MSG_CHANNEL_OPEN_CONFIRMATION packet!"); 50 | } 51 | 52 | public byte[] getPayload() 53 | { 54 | if (payload == null) 55 | { 56 | TypesWriter tw = new TypesWriter(); 57 | tw.writeByte(Packets.SSH_MSG_CHANNEL_OPEN_CONFIRMATION); 58 | tw.writeUINT32(recipientChannelID); 59 | tw.writeUINT32(senderChannelID); 60 | tw.writeUINT32(initialWindowSize); 61 | tw.writeUINT32(maxPacketSize); 62 | payload = tw.getBytes(); 63 | } 64 | return payload; 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/com/trilead/ssh2/packets/PacketChannelOpenFailure.java: -------------------------------------------------------------------------------- 1 | package com.trilead.ssh2.packets; 2 | 3 | import java.io.IOException; 4 | 5 | /** 6 | * PacketChannelOpenFailure. 7 | * 8 | * @author Christian Plattner, plattner@trilead.com 9 | * @version $Id: PacketChannelOpenFailure.java,v 1.1 2007/10/15 12:49:55 cplattne Exp $ 10 | */ 11 | public class PacketChannelOpenFailure 12 | { 13 | byte[] payload; 14 | 15 | public int recipientChannelID; 16 | public int reasonCode; 17 | public String description; 18 | public String languageTag; 19 | 20 | public PacketChannelOpenFailure(int recipientChannelID, int reasonCode, String description, 21 | String languageTag) 22 | { 23 | this.recipientChannelID = recipientChannelID; 24 | this.reasonCode = reasonCode; 25 | this.description = description; 26 | this.languageTag = languageTag; 27 | } 28 | 29 | public PacketChannelOpenFailure(byte payload[], int off, int len) throws IOException 30 | { 31 | this.payload = new byte[len]; 32 | System.arraycopy(payload, off, this.payload, 0, len); 33 | 34 | TypesReader tr = new TypesReader(payload, off, len); 35 | 36 | int packet_type = tr.readByte(); 37 | 38 | if (packet_type != Packets.SSH_MSG_CHANNEL_OPEN_FAILURE) 39 | throw new IOException( 40 | "This is not a SSH_MSG_CHANNEL_OPEN_FAILURE! (" 41 | + packet_type + ")"); 42 | 43 | recipientChannelID = tr.readUINT32(); 44 | reasonCode = tr.readUINT32(); 45 | description = tr.readString(); 46 | languageTag = tr.readString(); 47 | 48 | if (tr.remain() != 0) 49 | throw new IOException("Padding in SSH_MSG_CHANNEL_OPEN_FAILURE packet!"); 50 | } 51 | 52 | public byte[] getPayload() 53 | { 54 | if (payload == null) 55 | { 56 | TypesWriter tw = new TypesWriter(); 57 | tw.writeByte(Packets.SSH_MSG_CHANNEL_OPEN_FAILURE); 58 | tw.writeUINT32(recipientChannelID); 59 | tw.writeUINT32(reasonCode); 60 | tw.writeString(description); 61 | tw.writeString(languageTag); 62 | payload = tw.getBytes(); 63 | } 64 | return payload; 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/com/trilead/ssh2/packets/PacketChannelTrileadPing.java: -------------------------------------------------------------------------------- 1 | 2 | package com.trilead.ssh2.packets; 3 | 4 | /** 5 | * PacketChannelTrileadPing. 6 | * 7 | * @author Christian Plattner, plattner@trilead.com 8 | * @version $Id: PacketChannelTrileadPing.java,v 1.1 2008/03/03 07:01:36 9 | * cplattne Exp $ 10 | */ 11 | public class PacketChannelTrileadPing 12 | { 13 | byte[] payload; 14 | 15 | public int recipientChannelID; 16 | 17 | public PacketChannelTrileadPing(int recipientChannelID) 18 | { 19 | this.recipientChannelID = recipientChannelID; 20 | } 21 | 22 | public byte[] getPayload() 23 | { 24 | if (payload == null) 25 | { 26 | TypesWriter tw = new TypesWriter(); 27 | tw.writeByte(Packets.SSH_MSG_CHANNEL_REQUEST); 28 | tw.writeUINT32(recipientChannelID); 29 | tw.writeString("trilead-ping"); 30 | tw.writeBoolean(true); 31 | payload = tw.getBytes(); 32 | } 33 | return payload; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/com/trilead/ssh2/packets/PacketChannelWindowAdjust.java: -------------------------------------------------------------------------------- 1 | package com.trilead.ssh2.packets; 2 | 3 | import java.io.IOException; 4 | 5 | /** 6 | * PacketChannelWindowAdjust. 7 | * 8 | * @author Christian Plattner, plattner@trilead.com 9 | * @version $Id: PacketChannelWindowAdjust.java,v 1.1 2007/10/15 12:49:55 cplattne Exp $ 10 | */ 11 | public class PacketChannelWindowAdjust 12 | { 13 | byte[] payload; 14 | 15 | public int recipientChannelID; 16 | public int windowChange; 17 | 18 | public PacketChannelWindowAdjust(int recipientChannelID, int windowChange) 19 | { 20 | this.recipientChannelID = recipientChannelID; 21 | this.windowChange = windowChange; 22 | } 23 | 24 | public PacketChannelWindowAdjust(byte payload[], int off, int len) throws IOException 25 | { 26 | this.payload = new byte[len]; 27 | System.arraycopy(payload, off, this.payload, 0, len); 28 | 29 | TypesReader tr = new TypesReader(payload, off, len); 30 | 31 | int packet_type = tr.readByte(); 32 | 33 | if (packet_type != Packets.SSH_MSG_CHANNEL_WINDOW_ADJUST) 34 | throw new IOException( 35 | "This is not a SSH_MSG_CHANNEL_WINDOW_ADJUST! (" 36 | + packet_type + ")"); 37 | 38 | recipientChannelID = tr.readUINT32(); 39 | windowChange = tr.readUINT32(); 40 | 41 | if (tr.remain() != 0) 42 | throw new IOException("Padding in SSH_MSG_CHANNEL_WINDOW_ADJUST packet!"); 43 | } 44 | 45 | public byte[] getPayload() 46 | { 47 | if (payload == null) 48 | { 49 | TypesWriter tw = new TypesWriter(); 50 | tw.writeByte(Packets.SSH_MSG_CHANNEL_WINDOW_ADJUST); 51 | tw.writeUINT32(recipientChannelID); 52 | tw.writeUINT32(windowChange); 53 | payload = tw.getBytes(); 54 | } 55 | return payload; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/com/trilead/ssh2/packets/PacketDisconnect.java: -------------------------------------------------------------------------------- 1 | 2 | package com.trilead.ssh2.packets; 3 | 4 | import java.io.IOException; 5 | 6 | /** 7 | * PacketDisconnect. 8 | * 9 | * @author Christian Plattner, plattner@trilead.com 10 | * @version $Id: PacketDisconnect.java,v 1.2 2008/04/01 12:38:09 cplattne Exp $ 11 | */ 12 | public class PacketDisconnect 13 | { 14 | byte[] payload; 15 | 16 | int reason; 17 | String desc; 18 | String lang; 19 | 20 | public PacketDisconnect(byte payload[], int off, int len) throws IOException 21 | { 22 | this.payload = new byte[len]; 23 | System.arraycopy(payload, off, this.payload, 0, len); 24 | 25 | TypesReader tr = new TypesReader(payload, off, len); 26 | 27 | int packet_type = tr.readByte(); 28 | 29 | if (packet_type != Packets.SSH_MSG_DISCONNECT) 30 | throw new IOException("This is not a Disconnect Packet! (" + packet_type + ")"); 31 | 32 | reason = tr.readUINT32(); 33 | desc = tr.readString(); 34 | lang = tr.readString(); 35 | } 36 | 37 | public PacketDisconnect(int reason, String desc, String lang) 38 | { 39 | this.reason = reason; 40 | this.desc = desc; 41 | this.lang = lang; 42 | } 43 | 44 | public byte[] getPayload() 45 | { 46 | if (payload == null) 47 | { 48 | TypesWriter tw = new TypesWriter(); 49 | tw.writeByte(Packets.SSH_MSG_DISCONNECT); 50 | tw.writeUINT32(reason); 51 | tw.writeString(desc); 52 | tw.writeString(lang); 53 | payload = tw.getBytes(); 54 | } 55 | return payload; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/com/trilead/ssh2/packets/PacketGlobalCancelForwardRequest.java: -------------------------------------------------------------------------------- 1 | 2 | package com.trilead.ssh2.packets; 3 | 4 | /** 5 | * PacketGlobalCancelForwardRequest. 6 | * 7 | * @author Christian Plattner, plattner@trilead.com 8 | * @version $Id: PacketGlobalCancelForwardRequest.java,v 1.1 2007/10/15 12:49:55 9 | * cplattne Exp $ 10 | */ 11 | public class PacketGlobalCancelForwardRequest 12 | { 13 | byte[] payload; 14 | 15 | public boolean wantReply; 16 | public String bindAddress; 17 | public int bindPort; 18 | 19 | public PacketGlobalCancelForwardRequest(boolean wantReply, String bindAddress, int bindPort) 20 | { 21 | this.wantReply = wantReply; 22 | this.bindAddress = bindAddress; 23 | this.bindPort = bindPort; 24 | } 25 | 26 | public byte[] getPayload() 27 | { 28 | if (payload == null) 29 | { 30 | TypesWriter tw = new TypesWriter(); 31 | tw.writeByte(Packets.SSH_MSG_GLOBAL_REQUEST); 32 | 33 | tw.writeString("cancel-tcpip-forward"); 34 | tw.writeBoolean(wantReply); 35 | tw.writeString(bindAddress); 36 | tw.writeUINT32(bindPort); 37 | 38 | payload = tw.getBytes(); 39 | } 40 | return payload; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/com/trilead/ssh2/packets/PacketGlobalForwardRequest.java: -------------------------------------------------------------------------------- 1 | 2 | package com.trilead.ssh2.packets; 3 | 4 | /** 5 | * PacketGlobalForwardRequest. 6 | * 7 | * @author Christian Plattner, plattner@trilead.com 8 | * @version $Id: PacketGlobalForwardRequest.java,v 1.1 2007/10/15 12:49:55 cplattne Exp $ 9 | */ 10 | public class PacketGlobalForwardRequest 11 | { 12 | byte[] payload; 13 | 14 | public boolean wantReply; 15 | public String bindAddress; 16 | public int bindPort; 17 | 18 | public PacketGlobalForwardRequest(boolean wantReply, String bindAddress, int bindPort) 19 | { 20 | this.wantReply = wantReply; 21 | this.bindAddress = bindAddress; 22 | this.bindPort = bindPort; 23 | } 24 | 25 | public byte[] getPayload() 26 | { 27 | if (payload == null) 28 | { 29 | TypesWriter tw = new TypesWriter(); 30 | tw.writeByte(Packets.SSH_MSG_GLOBAL_REQUEST); 31 | 32 | tw.writeString("tcpip-forward"); 33 | tw.writeBoolean(wantReply); 34 | tw.writeString(bindAddress); 35 | tw.writeUINT32(bindPort); 36 | 37 | payload = tw.getBytes(); 38 | } 39 | return payload; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/com/trilead/ssh2/packets/PacketGlobalTrileadPing.java: -------------------------------------------------------------------------------- 1 | 2 | package com.trilead.ssh2.packets; 3 | 4 | /** 5 | * PacketGlobalTrileadPing. 6 | * 7 | * @author Christian Plattner, plattner@trilead.com 8 | * @version $Id: PacketGlobalTrileadPing.java,v 1.1 2008/03/03 07:01:36 cplattne Exp $ 9 | */ 10 | public class PacketGlobalTrileadPing 11 | { 12 | byte[] payload; 13 | 14 | public PacketGlobalTrileadPing() 15 | { 16 | } 17 | 18 | public byte[] getPayload() 19 | { 20 | if (payload == null) 21 | { 22 | TypesWriter tw = new TypesWriter(); 23 | tw.writeByte(Packets.SSH_MSG_GLOBAL_REQUEST); 24 | 25 | tw.writeString("trilead-ping"); 26 | tw.writeBoolean(true); 27 | 28 | payload = tw.getBytes(); 29 | } 30 | return payload; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/com/trilead/ssh2/packets/PacketIgnore.java: -------------------------------------------------------------------------------- 1 | 2 | package com.trilead.ssh2.packets; 3 | 4 | import java.io.IOException; 5 | 6 | /** 7 | * PacketIgnore. 8 | * 9 | * @author Christian Plattner, plattner@trilead.com 10 | * @version $Id: PacketIgnore.java,v 1.1 2007/10/15 12:49:55 cplattne Exp $ 11 | */ 12 | public class PacketIgnore 13 | { 14 | byte[] payload; 15 | 16 | byte[] data; 17 | 18 | public void setData(byte[] data) 19 | { 20 | this.data = data; 21 | payload = null; 22 | } 23 | 24 | public PacketIgnore() 25 | { 26 | } 27 | 28 | public PacketIgnore(byte payload[], int off, int len) throws IOException 29 | { 30 | this.payload = new byte[len]; 31 | System.arraycopy(payload, off, this.payload, 0, len); 32 | 33 | TypesReader tr = new TypesReader(payload, off, len); 34 | 35 | int packet_type = tr.readByte(); 36 | 37 | if (packet_type != Packets.SSH_MSG_IGNORE) 38 | throw new IOException("This is not a SSH_MSG_IGNORE packet! (" + packet_type + ")"); 39 | 40 | /* Could parse String body */ 41 | } 42 | 43 | public byte[] getPayload() 44 | { 45 | if (payload == null) 46 | { 47 | TypesWriter tw = new TypesWriter(); 48 | tw.writeByte(Packets.SSH_MSG_IGNORE); 49 | 50 | if (data != null) 51 | tw.writeString(data, 0, data.length); 52 | else 53 | tw.writeString(""); 54 | 55 | payload = tw.getBytes(); 56 | } 57 | return payload; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/com/trilead/ssh2/packets/PacketKexDHInit.java: -------------------------------------------------------------------------------- 1 | package com.trilead.ssh2.packets; 2 | 3 | import java.math.BigInteger; 4 | 5 | /** 6 | * PacketKexDHInit. 7 | * 8 | * @author Christian Plattner, plattner@trilead.com 9 | * @version $Id: PacketKexDHInit.java,v 1.1 2007/10/15 12:49:55 cplattne Exp $ 10 | */ 11 | public class PacketKexDHInit 12 | { 13 | byte[] payload; 14 | 15 | BigInteger e; 16 | 17 | public PacketKexDHInit(BigInteger e) 18 | { 19 | this.e = e; 20 | } 21 | 22 | public byte[] getPayload() 23 | { 24 | if (payload == null) 25 | { 26 | TypesWriter tw = new TypesWriter(); 27 | tw.writeByte(Packets.SSH_MSG_KEXDH_INIT); 28 | tw.writeMPInt(e); 29 | payload = tw.getBytes(); 30 | } 31 | return payload; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/com/trilead/ssh2/packets/PacketKexDHReply.java: -------------------------------------------------------------------------------- 1 | package com.trilead.ssh2.packets; 2 | 3 | import java.io.IOException; 4 | 5 | import java.math.BigInteger; 6 | 7 | /** 8 | * PacketKexDHReply. 9 | * 10 | * @author Christian Plattner, plattner@trilead.com 11 | * @version $Id: PacketKexDHReply.java,v 1.1 2007/10/15 12:49:55 cplattne Exp $ 12 | */ 13 | public class PacketKexDHReply 14 | { 15 | byte[] payload; 16 | 17 | byte[] hostKey; 18 | BigInteger f; 19 | byte[] signature; 20 | 21 | public PacketKexDHReply(byte payload[], int off, int len) throws IOException 22 | { 23 | this.payload = new byte[len]; 24 | System.arraycopy(payload, off, this.payload, 0, len); 25 | 26 | TypesReader tr = new TypesReader(payload, off, len); 27 | 28 | int packet_type = tr.readByte(); 29 | 30 | if (packet_type != Packets.SSH_MSG_KEXDH_REPLY) 31 | throw new IOException("This is not a SSH_MSG_KEXDH_REPLY! (" 32 | + packet_type + ")"); 33 | 34 | hostKey = tr.readByteString(); 35 | f = tr.readMPINT(); 36 | signature = tr.readByteString(); 37 | 38 | if (tr.remain() != 0) throw new IOException("PADDING IN SSH_MSG_KEXDH_REPLY!"); 39 | } 40 | 41 | public BigInteger getF() 42 | { 43 | return f; 44 | } 45 | 46 | public byte[] getHostKey() 47 | { 48 | return hostKey; 49 | } 50 | 51 | public byte[] getSignature() 52 | { 53 | return signature; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/com/trilead/ssh2/packets/PacketKexDhGexGroup.java: -------------------------------------------------------------------------------- 1 | package com.trilead.ssh2.packets; 2 | 3 | import java.io.IOException; 4 | 5 | import java.math.BigInteger; 6 | 7 | /** 8 | * PacketKexDhGexGroup. 9 | * 10 | * @author Christian Plattner, plattner@trilead.com 11 | * @version $Id: PacketKexDhGexGroup.java,v 1.1 2007/10/15 12:49:55 cplattne Exp $ 12 | */ 13 | public class PacketKexDhGexGroup 14 | { 15 | byte[] payload; 16 | 17 | BigInteger p; 18 | BigInteger g; 19 | 20 | public PacketKexDhGexGroup(byte payload[], int off, int len) throws IOException 21 | { 22 | this.payload = new byte[len]; 23 | System.arraycopy(payload, off, this.payload, 0, len); 24 | 25 | TypesReader tr = new TypesReader(payload, off, len); 26 | 27 | int packet_type = tr.readByte(); 28 | 29 | if (packet_type != Packets.SSH_MSG_KEX_DH_GEX_GROUP) 30 | throw new IllegalArgumentException( 31 | "This is not a SSH_MSG_KEX_DH_GEX_GROUP! (" + packet_type 32 | + ")"); 33 | 34 | p = tr.readMPINT(); 35 | g = tr.readMPINT(); 36 | 37 | if (tr.remain() != 0) 38 | throw new IOException("PADDING IN SSH_MSG_KEX_DH_GEX_GROUP!"); 39 | } 40 | 41 | public BigInteger getG() 42 | { 43 | return g; 44 | } 45 | 46 | public BigInteger getP() 47 | { 48 | return p; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/com/trilead/ssh2/packets/PacketKexDhGexInit.java: -------------------------------------------------------------------------------- 1 | package com.trilead.ssh2.packets; 2 | 3 | import java.math.BigInteger; 4 | 5 | /** 6 | * PacketKexDhGexInit. 7 | * 8 | * @author Christian Plattner, plattner@trilead.com 9 | * @version $Id: PacketKexDhGexInit.java,v 1.1 2007/10/15 12:49:55 cplattne Exp $ 10 | */ 11 | public class PacketKexDhGexInit 12 | { 13 | byte[] payload; 14 | 15 | BigInteger e; 16 | 17 | public PacketKexDhGexInit(BigInteger e) 18 | { 19 | this.e = e; 20 | } 21 | 22 | public byte[] getPayload() 23 | { 24 | if (payload == null) 25 | { 26 | TypesWriter tw = new TypesWriter(); 27 | tw.writeByte(Packets.SSH_MSG_KEX_DH_GEX_INIT); 28 | tw.writeMPInt(e); 29 | payload = tw.getBytes(); 30 | } 31 | return payload; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/com/trilead/ssh2/packets/PacketKexDhGexReply.java: -------------------------------------------------------------------------------- 1 | 2 | package com.trilead.ssh2.packets; 3 | 4 | import java.io.IOException; 5 | 6 | import java.math.BigInteger; 7 | 8 | /** 9 | * PacketKexDhGexReply. 10 | * 11 | * @author Christian Plattner, plattner@trilead.com 12 | * @version $Id: PacketKexDhGexReply.java,v 1.1 2007/10/15 12:49:55 cplattne Exp $ 13 | */ 14 | public class PacketKexDhGexReply 15 | { 16 | byte[] payload; 17 | 18 | byte[] hostKey; 19 | BigInteger f; 20 | byte[] signature; 21 | 22 | public PacketKexDhGexReply(byte payload[], int off, int len) throws IOException 23 | { 24 | this.payload = new byte[len]; 25 | System.arraycopy(payload, off, this.payload, 0, len); 26 | 27 | TypesReader tr = new TypesReader(payload, off, len); 28 | 29 | int packet_type = tr.readByte(); 30 | 31 | if (packet_type != Packets.SSH_MSG_KEX_DH_GEX_REPLY) 32 | throw new IOException("This is not a SSH_MSG_KEX_DH_GEX_REPLY! (" + packet_type + ")"); 33 | 34 | hostKey = tr.readByteString(); 35 | f = tr.readMPINT(); 36 | signature = tr.readByteString(); 37 | 38 | if (tr.remain() != 0) 39 | throw new IOException("PADDING IN SSH_MSG_KEX_DH_GEX_REPLY!"); 40 | } 41 | 42 | public BigInteger getF() 43 | { 44 | return f; 45 | } 46 | 47 | public byte[] getHostKey() 48 | { 49 | return hostKey; 50 | } 51 | 52 | public byte[] getSignature() 53 | { 54 | return signature; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/com/trilead/ssh2/packets/PacketKexDhGexRequest.java: -------------------------------------------------------------------------------- 1 | package com.trilead.ssh2.packets; 2 | 3 | import com.trilead.ssh2.DHGexParameters; 4 | 5 | /** 6 | * PacketKexDhGexRequest. 7 | * 8 | * @author Christian Plattner, plattner@trilead.com 9 | * @version $Id: PacketKexDhGexRequest.java,v 1.1 2007/10/15 12:49:55 cplattne Exp $ 10 | */ 11 | public class PacketKexDhGexRequest 12 | { 13 | byte[] payload; 14 | 15 | int min; 16 | int n; 17 | int max; 18 | 19 | public PacketKexDhGexRequest(DHGexParameters para) 20 | { 21 | this.min = para.getMin_group_len(); 22 | this.n = para.getPref_group_len(); 23 | this.max = para.getMax_group_len(); 24 | } 25 | 26 | public byte[] getPayload() 27 | { 28 | if (payload == null) 29 | { 30 | TypesWriter tw = new TypesWriter(); 31 | tw.writeByte(Packets.SSH_MSG_KEX_DH_GEX_REQUEST); 32 | tw.writeUINT32(min); 33 | tw.writeUINT32(n); 34 | tw.writeUINT32(max); 35 | payload = tw.getBytes(); 36 | } 37 | return payload; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/com/trilead/ssh2/packets/PacketKexDhGexRequestOld.java: -------------------------------------------------------------------------------- 1 | 2 | package com.trilead.ssh2.packets; 3 | 4 | import com.trilead.ssh2.DHGexParameters; 5 | 6 | /** 7 | * PacketKexDhGexRequestOld. 8 | * 9 | * @author Christian Plattner, plattner@trilead.com 10 | * @version $Id: PacketKexDhGexRequestOld.java,v 1.1 2007/10/15 12:49:55 cplattne Exp $ 11 | */ 12 | public class PacketKexDhGexRequestOld 13 | { 14 | byte[] payload; 15 | 16 | int n; 17 | 18 | public PacketKexDhGexRequestOld(DHGexParameters para) 19 | { 20 | this.n = para.getPref_group_len(); 21 | } 22 | 23 | public byte[] getPayload() 24 | { 25 | if (payload == null) 26 | { 27 | TypesWriter tw = new TypesWriter(); 28 | tw.writeByte(Packets.SSH_MSG_KEX_DH_GEX_REQUEST_OLD); 29 | tw.writeUINT32(n); 30 | payload = tw.getBytes(); 31 | } 32 | return payload; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/com/trilead/ssh2/packets/PacketNewKeys.java: -------------------------------------------------------------------------------- 1 | package com.trilead.ssh2.packets; 2 | 3 | import java.io.IOException; 4 | 5 | /** 6 | * PacketNewKeys. 7 | * 8 | * @author Christian Plattner, plattner@trilead.com 9 | * @version $Id: PacketNewKeys.java,v 1.1 2007/10/15 12:49:55 cplattne Exp $ 10 | */ 11 | public class PacketNewKeys 12 | { 13 | byte[] payload; 14 | 15 | public PacketNewKeys() 16 | { 17 | } 18 | 19 | public PacketNewKeys(byte payload[], int off, int len) throws IOException 20 | { 21 | this.payload = new byte[len]; 22 | System.arraycopy(payload, off, this.payload, 0, len); 23 | 24 | TypesReader tr = new TypesReader(payload, off, len); 25 | 26 | int packet_type = tr.readByte(); 27 | 28 | if (packet_type != Packets.SSH_MSG_NEWKEYS) 29 | throw new IOException("This is not a SSH_MSG_NEWKEYS! (" 30 | + packet_type + ")"); 31 | 32 | if (tr.remain() != 0) 33 | throw new IOException("Padding in SSH_MSG_NEWKEYS packet!"); 34 | } 35 | 36 | public byte[] getPayload() 37 | { 38 | if (payload == null) 39 | { 40 | TypesWriter tw = new TypesWriter(); 41 | tw.writeByte(Packets.SSH_MSG_NEWKEYS); 42 | payload = tw.getBytes(); 43 | } 44 | return payload; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/com/trilead/ssh2/packets/PacketOpenDirectTCPIPChannel.java: -------------------------------------------------------------------------------- 1 | package com.trilead.ssh2.packets; 2 | 3 | 4 | /** 5 | * PacketOpenDirectTCPIPChannel. 6 | * 7 | * @author Christian Plattner, plattner@trilead.com 8 | * @version $Id: PacketOpenDirectTCPIPChannel.java,v 1.1 2007/10/15 12:49:55 cplattne Exp $ 9 | */ 10 | public class PacketOpenDirectTCPIPChannel 11 | { 12 | byte[] payload; 13 | 14 | int channelID; 15 | int initialWindowSize; 16 | int maxPacketSize; 17 | 18 | String host_to_connect; 19 | int port_to_connect; 20 | String originator_IP_address; 21 | int originator_port; 22 | 23 | public PacketOpenDirectTCPIPChannel(int channelID, int initialWindowSize, int maxPacketSize, 24 | String host_to_connect, int port_to_connect, String originator_IP_address, 25 | int originator_port) 26 | { 27 | this.channelID = channelID; 28 | this.initialWindowSize = initialWindowSize; 29 | this.maxPacketSize = maxPacketSize; 30 | this.host_to_connect = host_to_connect; 31 | this.port_to_connect = port_to_connect; 32 | this.originator_IP_address = originator_IP_address; 33 | this.originator_port = originator_port; 34 | } 35 | 36 | public byte[] getPayload() 37 | { 38 | if (payload == null) 39 | { 40 | TypesWriter tw = new TypesWriter(); 41 | 42 | tw.writeByte(Packets.SSH_MSG_CHANNEL_OPEN); 43 | tw.writeString("direct-tcpip"); 44 | tw.writeUINT32(channelID); 45 | tw.writeUINT32(initialWindowSize); 46 | tw.writeUINT32(maxPacketSize); 47 | tw.writeString(host_to_connect); 48 | tw.writeUINT32(port_to_connect); 49 | tw.writeString(originator_IP_address); 50 | tw.writeUINT32(originator_port); 51 | 52 | payload = tw.getBytes(); 53 | } 54 | return payload; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/com/trilead/ssh2/packets/PacketOpenSessionChannel.java: -------------------------------------------------------------------------------- 1 | package com.trilead.ssh2.packets; 2 | 3 | import java.io.IOException; 4 | 5 | /** 6 | * PacketOpenSessionChannel. 7 | * 8 | * @author Christian Plattner, plattner@trilead.com 9 | * @version $Id: PacketOpenSessionChannel.java,v 1.1 2007/10/15 12:49:55 cplattne Exp $ 10 | */ 11 | public class PacketOpenSessionChannel 12 | { 13 | byte[] payload; 14 | 15 | int channelID; 16 | int initialWindowSize; 17 | int maxPacketSize; 18 | 19 | public PacketOpenSessionChannel(int channelID, int initialWindowSize, 20 | int maxPacketSize) 21 | { 22 | this.channelID = channelID; 23 | this.initialWindowSize = initialWindowSize; 24 | this.maxPacketSize = maxPacketSize; 25 | } 26 | 27 | public PacketOpenSessionChannel(byte payload[], int off, int len) throws IOException 28 | { 29 | this.payload = new byte[len]; 30 | System.arraycopy(payload, off, this.payload, 0, len); 31 | 32 | TypesReader tr = new TypesReader(payload); 33 | 34 | int packet_type = tr.readByte(); 35 | 36 | if (packet_type != Packets.SSH_MSG_CHANNEL_OPEN) 37 | throw new IOException("This is not a SSH_MSG_CHANNEL_OPEN! (" 38 | + packet_type + ")"); 39 | 40 | channelID = tr.readUINT32(); 41 | initialWindowSize = tr.readUINT32(); 42 | maxPacketSize = tr.readUINT32(); 43 | 44 | if (tr.remain() != 0) 45 | throw new IOException("Padding in SSH_MSG_CHANNEL_OPEN packet!"); 46 | } 47 | 48 | public byte[] getPayload() 49 | { 50 | if (payload == null) 51 | { 52 | TypesWriter tw = new TypesWriter(); 53 | tw.writeByte(Packets.SSH_MSG_CHANNEL_OPEN); 54 | tw.writeString("session"); 55 | tw.writeUINT32(channelID); 56 | tw.writeUINT32(initialWindowSize); 57 | tw.writeUINT32(maxPacketSize); 58 | payload = tw.getBytes(); 59 | } 60 | return payload; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/com/trilead/ssh2/packets/PacketServiceAccept.java: -------------------------------------------------------------------------------- 1 | 2 | package com.trilead.ssh2.packets; 3 | 4 | import java.io.IOException; 5 | 6 | /** 7 | * PacketServiceAccept. 8 | * 9 | * @author Christian Plattner, plattner@trilead.com 10 | * @version $Id: PacketServiceAccept.java,v 1.2 2008/04/01 12:38:09 cplattne Exp $ 11 | */ 12 | public class PacketServiceAccept 13 | { 14 | byte[] payload; 15 | 16 | String serviceName; 17 | 18 | public PacketServiceAccept(String serviceName) 19 | { 20 | this.serviceName = serviceName; 21 | } 22 | 23 | public PacketServiceAccept(byte payload[], int off, int len) throws IOException 24 | { 25 | this.payload = new byte[len]; 26 | System.arraycopy(payload, off, this.payload, 0, len); 27 | 28 | TypesReader tr = new TypesReader(payload, off, len); 29 | 30 | int packet_type = tr.readByte(); 31 | 32 | if (packet_type != Packets.SSH_MSG_SERVICE_ACCEPT) 33 | throw new IOException("This is not a SSH_MSG_SERVICE_ACCEPT! (" + packet_type + ")"); 34 | 35 | /* Be clever in case the server is not. Some servers seem to violate RFC4253 */ 36 | 37 | if (tr.remain() > 0) 38 | { 39 | serviceName = tr.readString(); 40 | } 41 | else 42 | { 43 | serviceName = ""; 44 | } 45 | 46 | if (tr.remain() != 0) 47 | throw new IOException("Padding in SSH_MSG_SERVICE_ACCEPT packet!"); 48 | } 49 | 50 | public byte[] getPayload() 51 | { 52 | if (payload == null) 53 | { 54 | TypesWriter tw = new TypesWriter(); 55 | tw.writeByte(Packets.SSH_MSG_SERVICE_ACCEPT); 56 | tw.writeString(serviceName); 57 | payload = tw.getBytes(); 58 | } 59 | return payload; 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/com/trilead/ssh2/packets/PacketServiceRequest.java: -------------------------------------------------------------------------------- 1 | package com.trilead.ssh2.packets; 2 | 3 | import java.io.IOException; 4 | 5 | /** 6 | * PacketServiceRequest. 7 | * 8 | * @author Christian Plattner, plattner@trilead.com 9 | * @version $Id: PacketServiceRequest.java,v 1.1 2007/10/15 12:49:55 cplattne Exp $ 10 | */ 11 | public class PacketServiceRequest 12 | { 13 | byte[] payload; 14 | 15 | String serviceName; 16 | 17 | public PacketServiceRequest(String serviceName) 18 | { 19 | this.serviceName = serviceName; 20 | } 21 | 22 | public PacketServiceRequest(byte payload[], int off, int len) throws IOException 23 | { 24 | this.payload = new byte[len]; 25 | System.arraycopy(payload, off, this.payload, 0, len); 26 | 27 | TypesReader tr = new TypesReader(payload, off, len); 28 | 29 | int packet_type = tr.readByte(); 30 | 31 | if (packet_type != Packets.SSH_MSG_SERVICE_REQUEST) 32 | throw new IOException("This is not a SSH_MSG_SERVICE_REQUEST! (" 33 | + packet_type + ")"); 34 | 35 | serviceName = tr.readString(); 36 | 37 | if (tr.remain() != 0) 38 | throw new IOException("Padding in SSH_MSG_SERVICE_REQUEST packet!"); 39 | } 40 | 41 | public byte[] getPayload() 42 | { 43 | if (payload == null) 44 | { 45 | TypesWriter tw = new TypesWriter(); 46 | tw.writeByte(Packets.SSH_MSG_SERVICE_REQUEST); 47 | tw.writeString(serviceName); 48 | payload = tw.getBytes(); 49 | } 50 | return payload; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/com/trilead/ssh2/packets/PacketSessionExecCommand.java: -------------------------------------------------------------------------------- 1 | package com.trilead.ssh2.packets; 2 | 3 | 4 | /** 5 | * PacketSessionExecCommand. 6 | * 7 | * @author Christian Plattner, plattner@trilead.com 8 | * @version $Id: PacketSessionExecCommand.java,v 1.1 2007/10/15 12:49:55 cplattne Exp $ 9 | */ 10 | public class PacketSessionExecCommand 11 | { 12 | byte[] payload; 13 | 14 | public int recipientChannelID; 15 | public boolean wantReply; 16 | public String command; 17 | 18 | public PacketSessionExecCommand(int recipientChannelID, boolean wantReply, String command) 19 | { 20 | this.recipientChannelID = recipientChannelID; 21 | this.wantReply = wantReply; 22 | this.command = command; 23 | } 24 | 25 | public byte[] getPayload() 26 | { 27 | if (payload == null) 28 | { 29 | TypesWriter tw = new TypesWriter(); 30 | tw.writeByte(Packets.SSH_MSG_CHANNEL_REQUEST); 31 | tw.writeUINT32(recipientChannelID); 32 | tw.writeString("exec"); 33 | tw.writeBoolean(wantReply); 34 | tw.writeString(command); 35 | payload = tw.getBytes(); 36 | } 37 | return payload; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/com/trilead/ssh2/packets/PacketSessionPtyRequest.java: -------------------------------------------------------------------------------- 1 | package com.trilead.ssh2.packets; 2 | 3 | 4 | /** 5 | * PacketSessionPtyRequest. 6 | * 7 | * @author Christian Plattner, plattner@trilead.com 8 | * @version $Id: PacketSessionPtyRequest.java,v 1.1 2007/10/15 12:49:55 cplattne Exp $ 9 | */ 10 | public class PacketSessionPtyRequest 11 | { 12 | byte[] payload; 13 | 14 | public int recipientChannelID; 15 | public boolean wantReply; 16 | public String term; 17 | public int character_width; 18 | public int character_height; 19 | public int pixel_width; 20 | public int pixel_height; 21 | public byte[] terminal_modes; 22 | 23 | public PacketSessionPtyRequest(int recipientChannelID, boolean wantReply, String term, 24 | int character_width, int character_height, int pixel_width, int pixel_height, 25 | byte[] terminal_modes) 26 | { 27 | this.recipientChannelID = recipientChannelID; 28 | this.wantReply = wantReply; 29 | this.term = term; 30 | this.character_width = character_width; 31 | this.character_height = character_height; 32 | this.pixel_width = pixel_width; 33 | this.pixel_height = pixel_height; 34 | this.terminal_modes = terminal_modes; 35 | } 36 | 37 | public byte[] getPayload() 38 | { 39 | if (payload == null) 40 | { 41 | TypesWriter tw = new TypesWriter(); 42 | tw.writeByte(Packets.SSH_MSG_CHANNEL_REQUEST); 43 | tw.writeUINT32(recipientChannelID); 44 | tw.writeString("pty-req"); 45 | tw.writeBoolean(wantReply); 46 | tw.writeString(term); 47 | tw.writeUINT32(character_width); 48 | tw.writeUINT32(character_height); 49 | tw.writeUINT32(pixel_width); 50 | tw.writeUINT32(pixel_height); 51 | tw.writeString(terminal_modes, 0, terminal_modes.length); 52 | 53 | payload = tw.getBytes(); 54 | } 55 | return payload; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/com/trilead/ssh2/packets/PacketSessionPtyResize.java: -------------------------------------------------------------------------------- 1 | package com.trilead.ssh2.packets; 2 | 3 | public class PacketSessionPtyResize { 4 | byte[] payload; 5 | 6 | public int recipientChannelID; 7 | public int width; 8 | public int height; 9 | public int pixelWidth; 10 | public int pixelHeight; 11 | 12 | public PacketSessionPtyResize(int recipientChannelID, int width, int height, int pixelWidth, int pixelHeight) { 13 | this.recipientChannelID = recipientChannelID; 14 | this.width = width; 15 | this.height = height; 16 | this.pixelWidth = pixelWidth; 17 | this.pixelHeight = pixelHeight; 18 | } 19 | 20 | public byte[] getPayload() 21 | { 22 | if (payload == null) 23 | { 24 | TypesWriter tw = new TypesWriter(); 25 | tw.writeByte(Packets.SSH_MSG_CHANNEL_REQUEST); 26 | tw.writeUINT32(recipientChannelID); 27 | tw.writeString("window-change"); 28 | tw.writeBoolean(false); 29 | tw.writeUINT32(width); 30 | tw.writeUINT32(height); 31 | tw.writeUINT32(pixelWidth); 32 | tw.writeUINT32(pixelHeight); 33 | 34 | payload = tw.getBytes(); 35 | } 36 | return payload; 37 | } 38 | } 39 | 40 | 41 | -------------------------------------------------------------------------------- /src/com/trilead/ssh2/packets/PacketSessionStartShell.java: -------------------------------------------------------------------------------- 1 | 2 | package com.trilead.ssh2.packets; 3 | 4 | /** 5 | * PacketSessionStartShell. 6 | * 7 | * @author Christian Plattner, plattner@trilead.com 8 | * @version $Id: PacketSessionStartShell.java,v 1.1 2007/10/15 12:49:55 cplattne Exp $ 9 | */ 10 | public class PacketSessionStartShell 11 | { 12 | byte[] payload; 13 | 14 | public int recipientChannelID; 15 | public boolean wantReply; 16 | 17 | public PacketSessionStartShell(int recipientChannelID, boolean wantReply) 18 | { 19 | this.recipientChannelID = recipientChannelID; 20 | this.wantReply = wantReply; 21 | } 22 | 23 | public byte[] getPayload() 24 | { 25 | if (payload == null) 26 | { 27 | TypesWriter tw = new TypesWriter(); 28 | tw.writeByte(Packets.SSH_MSG_CHANNEL_REQUEST); 29 | tw.writeUINT32(recipientChannelID); 30 | tw.writeString("shell"); 31 | tw.writeBoolean(wantReply); 32 | payload = tw.getBytes(); 33 | } 34 | return payload; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/com/trilead/ssh2/packets/PacketSessionSubsystemRequest.java: -------------------------------------------------------------------------------- 1 | package com.trilead.ssh2.packets; 2 | 3 | 4 | /** 5 | * PacketSessionSubsystemRequest. 6 | * 7 | * @author Christian Plattner, plattner@trilead.com 8 | * @version $Id: PacketSessionSubsystemRequest.java,v 1.1 2007/10/15 12:49:55 cplattne Exp $ 9 | */ 10 | public class PacketSessionSubsystemRequest 11 | { 12 | byte[] payload; 13 | 14 | public int recipientChannelID; 15 | public boolean wantReply; 16 | public String subsystem; 17 | 18 | public PacketSessionSubsystemRequest(int recipientChannelID, boolean wantReply, String subsystem) 19 | { 20 | this.recipientChannelID = recipientChannelID; 21 | this.wantReply = wantReply; 22 | this.subsystem = subsystem; 23 | } 24 | 25 | public byte[] getPayload() 26 | { 27 | if (payload == null) 28 | { 29 | TypesWriter tw = new TypesWriter(); 30 | tw.writeByte(Packets.SSH_MSG_CHANNEL_REQUEST); 31 | tw.writeUINT32(recipientChannelID); 32 | tw.writeString("subsystem"); 33 | tw.writeBoolean(wantReply); 34 | tw.writeString(subsystem); 35 | payload = tw.getBytes(); 36 | tw.getBytes(payload); 37 | } 38 | return payload; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/com/trilead/ssh2/packets/PacketSessionX11Request.java: -------------------------------------------------------------------------------- 1 | 2 | package com.trilead.ssh2.packets; 3 | 4 | /** 5 | * PacketSessionX11Request. 6 | * 7 | * @author Christian Plattner, plattner@trilead.com 8 | * @version $Id: PacketSessionX11Request.java,v 1.1 2007/10/15 12:49:55 cplattne Exp $ 9 | */ 10 | public class PacketSessionX11Request 11 | { 12 | byte[] payload; 13 | 14 | public int recipientChannelID; 15 | public boolean wantReply; 16 | 17 | public boolean singleConnection; 18 | String x11AuthenticationProtocol; 19 | String x11AuthenticationCookie; 20 | int x11ScreenNumber; 21 | 22 | public PacketSessionX11Request(int recipientChannelID, boolean wantReply, boolean singleConnection, 23 | String x11AuthenticationProtocol, String x11AuthenticationCookie, int x11ScreenNumber) 24 | { 25 | this.recipientChannelID = recipientChannelID; 26 | this.wantReply = wantReply; 27 | 28 | this.singleConnection = singleConnection; 29 | this.x11AuthenticationProtocol = x11AuthenticationProtocol; 30 | this.x11AuthenticationCookie = x11AuthenticationCookie; 31 | this.x11ScreenNumber = x11ScreenNumber; 32 | } 33 | 34 | public byte[] getPayload() 35 | { 36 | if (payload == null) 37 | { 38 | TypesWriter tw = new TypesWriter(); 39 | tw.writeByte(Packets.SSH_MSG_CHANNEL_REQUEST); 40 | tw.writeUINT32(recipientChannelID); 41 | tw.writeString("x11-req"); 42 | tw.writeBoolean(wantReply); 43 | 44 | tw.writeBoolean(singleConnection); 45 | tw.writeString(x11AuthenticationProtocol); 46 | tw.writeString(x11AuthenticationCookie); 47 | tw.writeUINT32(x11ScreenNumber); 48 | 49 | payload = tw.getBytes(); 50 | } 51 | return payload; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/com/trilead/ssh2/packets/PacketUserauthBanner.java: -------------------------------------------------------------------------------- 1 | package com.trilead.ssh2.packets; 2 | 3 | import java.io.IOException; 4 | 5 | /** 6 | * PacketUserauthBanner. 7 | * 8 | * @author Christian Plattner, plattner@trilead.com 9 | * @version $Id: PacketUserauthBanner.java,v 1.1 2007/10/15 12:49:55 cplattne Exp $ 10 | */ 11 | public class PacketUserauthBanner 12 | { 13 | byte[] payload; 14 | 15 | String message; 16 | String language; 17 | 18 | public PacketUserauthBanner(String message, String language) 19 | { 20 | this.message = message; 21 | this.language = language; 22 | } 23 | 24 | public String getBanner() 25 | { 26 | return message; 27 | } 28 | 29 | public PacketUserauthBanner(byte payload[], int off, int len) throws IOException 30 | { 31 | this.payload = new byte[len]; 32 | System.arraycopy(payload, off, this.payload, 0, len); 33 | 34 | TypesReader tr = new TypesReader(payload, off, len); 35 | 36 | int packet_type = tr.readByte(); 37 | 38 | if (packet_type != Packets.SSH_MSG_USERAUTH_BANNER) 39 | throw new IOException("This is not a SSH_MSG_USERAUTH_BANNER! (" + packet_type + ")"); 40 | 41 | message = tr.readString("UTF-8"); 42 | language = tr.readString(); 43 | 44 | if (tr.remain() != 0) 45 | throw new IOException("Padding in SSH_MSG_USERAUTH_REQUEST packet!"); 46 | } 47 | 48 | public byte[] getPayload() 49 | { 50 | if (payload == null) 51 | { 52 | TypesWriter tw = new TypesWriter(); 53 | tw.writeByte(Packets.SSH_MSG_USERAUTH_BANNER); 54 | tw.writeString(message); 55 | tw.writeString(language); 56 | payload = tw.getBytes(); 57 | } 58 | return payload; 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/com/trilead/ssh2/packets/PacketUserauthFailure.java: -------------------------------------------------------------------------------- 1 | 2 | package com.trilead.ssh2.packets; 3 | 4 | import java.io.IOException; 5 | 6 | /** 7 | * PacketUserauthBanner. 8 | * 9 | * @author Christian Plattner, plattner@trilead.com 10 | * @version $Id: PacketUserauthFailure.java,v 1.1 2007/10/15 12:49:55 cplattne Exp $ 11 | */ 12 | public class PacketUserauthFailure 13 | { 14 | byte[] payload; 15 | 16 | String[] authThatCanContinue; 17 | boolean partialSuccess; 18 | 19 | public PacketUserauthFailure(String[] authThatCanContinue, boolean partialSuccess) 20 | { 21 | this.authThatCanContinue = authThatCanContinue; 22 | this.partialSuccess = partialSuccess; 23 | } 24 | 25 | public PacketUserauthFailure(byte payload[], int off, int len) throws IOException 26 | { 27 | this.payload = new byte[len]; 28 | System.arraycopy(payload, off, this.payload, 0, len); 29 | 30 | TypesReader tr = new TypesReader(payload, off, len); 31 | 32 | int packet_type = tr.readByte(); 33 | 34 | if (packet_type != Packets.SSH_MSG_USERAUTH_FAILURE) 35 | throw new IOException("This is not a SSH_MSG_USERAUTH_FAILURE! (" + packet_type + ")"); 36 | 37 | authThatCanContinue = tr.readNameList(); 38 | partialSuccess = tr.readBoolean(); 39 | 40 | if (tr.remain() != 0) 41 | throw new IOException("Padding in SSH_MSG_USERAUTH_FAILURE packet!"); 42 | } 43 | 44 | public String[] getAuthThatCanContinue() 45 | { 46 | return authThatCanContinue; 47 | } 48 | 49 | public boolean isPartialSuccess() 50 | { 51 | return partialSuccess; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/com/trilead/ssh2/packets/PacketUserauthInfoRequest.java: -------------------------------------------------------------------------------- 1 | 2 | package com.trilead.ssh2.packets; 3 | 4 | import java.io.IOException; 5 | 6 | /** 7 | * PacketUserauthInfoRequest. 8 | * 9 | * @author Christian Plattner, plattner@trilead.com 10 | * @version $Id: PacketUserauthInfoRequest.java,v 1.1 2007/10/15 12:49:55 cplattne Exp $ 11 | */ 12 | public class PacketUserauthInfoRequest 13 | { 14 | byte[] payload; 15 | 16 | String name; 17 | String instruction; 18 | String languageTag; 19 | int numPrompts; 20 | 21 | String prompt[]; 22 | boolean echo[]; 23 | 24 | public PacketUserauthInfoRequest(byte payload[], int off, int len) throws IOException 25 | { 26 | this.payload = new byte[len]; 27 | System.arraycopy(payload, off, this.payload, 0, len); 28 | 29 | TypesReader tr = new TypesReader(payload, off, len); 30 | 31 | int packet_type = tr.readByte(); 32 | 33 | if (packet_type != Packets.SSH_MSG_USERAUTH_INFO_REQUEST) 34 | throw new IOException("This is not a SSH_MSG_USERAUTH_INFO_REQUEST! (" + packet_type + ")"); 35 | 36 | name = tr.readString(); 37 | instruction = tr.readString(); 38 | languageTag = tr.readString(); 39 | 40 | numPrompts = tr.readUINT32(); 41 | 42 | prompt = new String[numPrompts]; 43 | echo = new boolean[numPrompts]; 44 | 45 | for (int i = 0; i < numPrompts; i++) 46 | { 47 | prompt[i] = tr.readString(); 48 | echo[i] = tr.readBoolean(); 49 | } 50 | 51 | if (tr.remain() != 0) 52 | throw new IOException("Padding in SSH_MSG_USERAUTH_INFO_REQUEST packet!"); 53 | } 54 | 55 | public boolean[] getEcho() 56 | { 57 | return echo; 58 | } 59 | 60 | public String getInstruction() 61 | { 62 | return instruction; 63 | } 64 | 65 | public String getLanguageTag() 66 | { 67 | return languageTag; 68 | } 69 | 70 | public String getName() 71 | { 72 | return name; 73 | } 74 | 75 | public int getNumPrompts() 76 | { 77 | return numPrompts; 78 | } 79 | 80 | public String[] getPrompt() 81 | { 82 | return prompt; 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /src/com/trilead/ssh2/packets/PacketUserauthInfoResponse.java: -------------------------------------------------------------------------------- 1 | 2 | package com.trilead.ssh2.packets; 3 | 4 | /** 5 | * PacketUserauthInfoResponse. 6 | * 7 | * @author Christian Plattner, plattner@trilead.com 8 | * @version $Id: PacketUserauthInfoResponse.java,v 1.1 2007/10/15 12:49:55 cplattne Exp $ 9 | */ 10 | public class PacketUserauthInfoResponse 11 | { 12 | byte[] payload; 13 | 14 | String[] responses; 15 | 16 | public PacketUserauthInfoResponse(String[] responses) 17 | { 18 | this.responses = responses; 19 | } 20 | 21 | public byte[] getPayload() 22 | { 23 | if (payload == null) 24 | { 25 | TypesWriter tw = new TypesWriter(); 26 | tw.writeByte(Packets.SSH_MSG_USERAUTH_INFO_RESPONSE); 27 | tw.writeUINT32(responses.length); 28 | for (int i = 0; i < responses.length; i++) 29 | tw.writeString(responses[i]); 30 | 31 | payload = tw.getBytes(); 32 | } 33 | return payload; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/com/trilead/ssh2/packets/PacketUserauthRequestInteractive.java: -------------------------------------------------------------------------------- 1 | 2 | package com.trilead.ssh2.packets; 3 | 4 | /** 5 | * PacketUserauthRequestInteractive. 6 | * 7 | * @author Christian Plattner, plattner@trilead.com 8 | * @version $Id: PacketUserauthRequestInteractive.java,v 1.1 2007/10/15 12:49:55 cplattne Exp $ 9 | */ 10 | public class PacketUserauthRequestInteractive 11 | { 12 | byte[] payload; 13 | 14 | String userName; 15 | String serviceName; 16 | String[] submethods; 17 | 18 | public PacketUserauthRequestInteractive(String serviceName, String user, String[] submethods) 19 | { 20 | this.serviceName = serviceName; 21 | this.userName = user; 22 | this.submethods = submethods; 23 | } 24 | 25 | public byte[] getPayload() 26 | { 27 | if (payload == null) 28 | { 29 | TypesWriter tw = new TypesWriter(); 30 | tw.writeByte(Packets.SSH_MSG_USERAUTH_REQUEST); 31 | tw.writeString(userName); 32 | tw.writeString(serviceName); 33 | tw.writeString("keyboard-interactive"); 34 | tw.writeString(""); // draft-ietf-secsh-newmodes-04.txt says that 35 | // the language tag should be empty. 36 | tw.writeNameList(submethods); 37 | 38 | payload = tw.getBytes(); 39 | } 40 | return payload; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/com/trilead/ssh2/packets/PacketUserauthRequestNone.java: -------------------------------------------------------------------------------- 1 | package com.trilead.ssh2.packets; 2 | 3 | import java.io.IOException; 4 | 5 | /** 6 | * PacketUserauthRequestPassword. 7 | * 8 | * @author Christian Plattner, plattner@trilead.com 9 | * @version $Id: PacketUserauthRequestNone.java,v 1.1 2007/10/15 12:49:55 cplattne Exp $ 10 | */ 11 | public class PacketUserauthRequestNone 12 | { 13 | byte[] payload; 14 | 15 | String userName; 16 | String serviceName; 17 | 18 | public PacketUserauthRequestNone(String serviceName, String user) 19 | { 20 | this.serviceName = serviceName; 21 | this.userName = user; 22 | } 23 | 24 | public PacketUserauthRequestNone(byte payload[], int off, int len) throws IOException 25 | { 26 | this.payload = new byte[len]; 27 | System.arraycopy(payload, off, this.payload, 0, len); 28 | 29 | TypesReader tr = new TypesReader(payload, off, len); 30 | 31 | int packet_type = tr.readByte(); 32 | 33 | if (packet_type != Packets.SSH_MSG_USERAUTH_REQUEST) 34 | throw new IOException("This is not a SSH_MSG_USERAUTH_REQUEST! (" + packet_type + ")"); 35 | 36 | userName = tr.readString(); 37 | serviceName = tr.readString(); 38 | 39 | String method = tr.readString(); 40 | 41 | if (method.equals("none") == false) 42 | throw new IOException("This is not a SSH_MSG_USERAUTH_REQUEST with type none!"); 43 | 44 | if (tr.remain() != 0) 45 | throw new IOException("Padding in SSH_MSG_USERAUTH_REQUEST packet!"); 46 | } 47 | 48 | public byte[] getPayload() 49 | { 50 | if (payload == null) 51 | { 52 | TypesWriter tw = new TypesWriter(); 53 | tw.writeByte(Packets.SSH_MSG_USERAUTH_REQUEST); 54 | tw.writeString(userName); 55 | tw.writeString(serviceName); 56 | tw.writeString("none"); 57 | payload = tw.getBytes(); 58 | } 59 | return payload; 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/com/trilead/ssh2/packets/PacketUserauthRequestPassword.java: -------------------------------------------------------------------------------- 1 | package com.trilead.ssh2.packets; 2 | 3 | import java.io.IOException; 4 | 5 | /** 6 | * PacketUserauthRequestPassword. 7 | * 8 | * @author Christian Plattner, plattner@trilead.com 9 | * @version $Id: PacketUserauthRequestPassword.java,v 1.1 2007/10/15 12:49:55 cplattne Exp $ 10 | */ 11 | public class PacketUserauthRequestPassword 12 | { 13 | byte[] payload; 14 | 15 | String userName; 16 | String serviceName; 17 | String password; 18 | 19 | public PacketUserauthRequestPassword(String serviceName, String user, String pass) 20 | { 21 | this.serviceName = serviceName; 22 | this.userName = user; 23 | this.password = pass; 24 | } 25 | 26 | public PacketUserauthRequestPassword(byte payload[], int off, int len) throws IOException 27 | { 28 | this.payload = new byte[len]; 29 | System.arraycopy(payload, off, this.payload, 0, len); 30 | 31 | TypesReader tr = new TypesReader(payload, off, len); 32 | 33 | int packet_type = tr.readByte(); 34 | 35 | if (packet_type != Packets.SSH_MSG_USERAUTH_REQUEST) 36 | throw new IOException("This is not a SSH_MSG_USERAUTH_REQUEST! (" + packet_type + ")"); 37 | 38 | userName = tr.readString(); 39 | serviceName = tr.readString(); 40 | 41 | String method = tr.readString(); 42 | 43 | if (method.equals("password") == false) 44 | throw new IOException("This is not a SSH_MSG_USERAUTH_REQUEST with type password!"); 45 | 46 | /* ... */ 47 | 48 | if (tr.remain() != 0) 49 | throw new IOException("Padding in SSH_MSG_USERAUTH_REQUEST packet!"); 50 | } 51 | 52 | public byte[] getPayload() 53 | { 54 | if (payload == null) 55 | { 56 | TypesWriter tw = new TypesWriter(); 57 | tw.writeByte(Packets.SSH_MSG_USERAUTH_REQUEST); 58 | tw.writeString(userName); 59 | tw.writeString(serviceName); 60 | tw.writeString("password"); 61 | tw.writeBoolean(false); 62 | tw.writeString(password); 63 | payload = tw.getBytes(); 64 | } 65 | return payload; 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/com/trilead/ssh2/packets/PacketUserauthRequestPublicKey.java: -------------------------------------------------------------------------------- 1 | package com.trilead.ssh2.packets; 2 | 3 | import java.io.IOException; 4 | 5 | /** 6 | * PacketUserauthRequestPublicKey. 7 | * 8 | * @author Christian Plattner, plattner@trilead.com 9 | * @version $Id: PacketUserauthRequestPublicKey.java,v 1.1 2007/10/15 12:49:55 cplattne Exp $ 10 | */ 11 | public class PacketUserauthRequestPublicKey 12 | { 13 | byte[] payload; 14 | 15 | String userName; 16 | String serviceName; 17 | String password; 18 | String pkAlgoName; 19 | byte[] pk; 20 | byte[] sig; 21 | 22 | public PacketUserauthRequestPublicKey(String serviceName, String user, 23 | String pkAlgorithmName, byte[] pk, byte[] sig) 24 | { 25 | this.serviceName = serviceName; 26 | this.userName = user; 27 | this.pkAlgoName = pkAlgorithmName; 28 | this.pk = pk; 29 | this.sig = sig; 30 | } 31 | 32 | public PacketUserauthRequestPublicKey(byte payload[], int off, int len) throws IOException 33 | { 34 | this.payload = new byte[len]; 35 | System.arraycopy(payload, off, this.payload, 0, len); 36 | 37 | TypesReader tr = new TypesReader(payload, off, len); 38 | 39 | int packet_type = tr.readByte(); 40 | 41 | if (packet_type != Packets.SSH_MSG_USERAUTH_REQUEST) 42 | throw new IOException("This is not a SSH_MSG_USERAUTH_REQUEST! (" 43 | + packet_type + ")"); 44 | 45 | throw new IOException("Not implemented!"); 46 | } 47 | 48 | public byte[] getPayload() 49 | { 50 | if (payload == null) 51 | { 52 | TypesWriter tw = new TypesWriter(); 53 | tw.writeByte(Packets.SSH_MSG_USERAUTH_REQUEST); 54 | tw.writeString(userName); 55 | tw.writeString(serviceName); 56 | tw.writeString("publickey"); 57 | tw.writeBoolean(true); 58 | tw.writeString(pkAlgoName); 59 | tw.writeString(pk, 0, pk.length); 60 | tw.writeString(sig, 0, sig.length); 61 | payload = tw.getBytes(); 62 | } 63 | return payload; 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/com/trilead/ssh2/sftp/AttrTextHints.java: -------------------------------------------------------------------------------- 1 | 2 | package com.trilead.ssh2.sftp; 3 | 4 | /** 5 | * 6 | * Values for the 'text-hint' field in the SFTP ATTRS data type. 7 | * 8 | * @author Christian Plattner, plattner@trilead.com 9 | * @version $Id: AttrTextHints.java,v 1.1 2007/10/15 12:49:55 cplattne Exp $ 10 | * 11 | */ 12 | public class AttrTextHints 13 | { 14 | /** 15 | * The server knows the file is a text file, and should be opened 16 | * using the SSH_FXF_ACCESS_TEXT_MODE flag. 17 | */ 18 | public static final int SSH_FILEXFER_ATTR_KNOWN_TEXT = 0x00; 19 | 20 | /** 21 | * The server has applied a heuristic or other mechanism and 22 | * believes that the file should be opened with the 23 | * SSH_FXF_ACCESS_TEXT_MODE flag. 24 | */ 25 | public static final int SSH_FILEXFER_ATTR_GUESSED_TEXT = 0x01; 26 | 27 | /** 28 | * The server knows the file has binary content. 29 | */ 30 | public static final int SSH_FILEXFER_ATTR_KNOWN_BINARY = 0x02; 31 | 32 | /** 33 | * The server has applied a heuristic or other mechanism and 34 | * believes has binary content, and should not be opened with the 35 | * SSH_FXF_ACCESS_TEXT_MODE flag. 36 | */ 37 | public static final int SSH_FILEXFER_ATTR_GUESSED_BINARY = 0x03; 38 | } 39 | -------------------------------------------------------------------------------- /src/com/trilead/ssh2/sftp/AttribPermissions.java: -------------------------------------------------------------------------------- 1 | 2 | package com.trilead.ssh2.sftp; 3 | 4 | /** 5 | * 6 | * Permissions for the 'permissions' field in the SFTP ATTRS data type. 7 | *
8 | * "The 'permissions' field contains a bit mask specifying file permissions. 9 | * These permissions correspond to the st_mode field of the stat structure 10 | * defined by POSIX [IEEE.1003-1.1996]." 11 | * 12 | * @author Christian Plattner, plattner@trilead.com 13 | * @version $Id: AttribPermissions.java,v 1.1 2007/10/15 12:49:55 cplattne Exp $ 14 | * 15 | */ 16 | public class AttribPermissions 17 | { 18 | /* Octal values! */ 19 | 20 | public static final int S_IRUSR = 0400; 21 | public static final int S_IWUSR = 0200; 22 | public static final int S_IXUSR = 0100; 23 | public static final int S_IRGRP = 0040; 24 | public static final int S_IWGRP = 0020; 25 | public static final int S_IXGRP = 0010; 26 | public static final int S_IROTH = 0004; 27 | public static final int S_IWOTH = 0002; 28 | public static final int S_IXOTH = 0001; 29 | public static final int S_ISUID = 04000; 30 | public static final int S_ISGID = 02000; 31 | public static final int S_ISVTX = 01000; 32 | } 33 | -------------------------------------------------------------------------------- /src/com/trilead/ssh2/sftp/AttribTypes.java: -------------------------------------------------------------------------------- 1 | 2 | package com.trilead.ssh2.sftp; 3 | 4 | /** 5 | * 6 | * Types for the 'type' field in the SFTP ATTRS data type. 7 | *
8 | * "On a POSIX system, these values would be derived from the mode field 9 | * of the stat structure. SPECIAL should be used for files that are of 10 | * a known type which cannot be expressed in the protocol. UNKNOWN 11 | * should be used if the type is not known." 12 | * 13 | * @author Christian Plattner, plattner@trilead.com 14 | * @version $Id: AttribTypes.java,v 1.1 2007/10/15 12:49:55 cplattne Exp $ 15 | * 16 | */ 17 | public class AttribTypes 18 | { 19 | public static final int SSH_FILEXFER_TYPE_REGULAR = 1; 20 | public static final int SSH_FILEXFER_TYPE_DIRECTORY = 2; 21 | public static final int SSH_FILEXFER_TYPE_SYMLINK = 3; 22 | public static final int SSH_FILEXFER_TYPE_SPECIAL = 4; 23 | public static final int SSH_FILEXFER_TYPE_UNKNOWN = 5; 24 | public static final int SSH_FILEXFER_TYPE_SOCKET = 6; 25 | public static final int SSH_FILEXFER_TYPE_CHAR_DEVICE = 7; 26 | public static final int SSH_FILEXFER_TYPE_BLOCK_DEVICE = 8; 27 | public static final int SSH_FILEXFER_TYPE_FIFO = 9; 28 | } 29 | -------------------------------------------------------------------------------- /src/com/trilead/ssh2/sftp/Packet.java: -------------------------------------------------------------------------------- 1 | 2 | package com.trilead.ssh2.sftp; 3 | 4 | /** 5 | * 6 | * SFTP Paket Types 7 | * 8 | * @author Christian Plattner, plattner@trilead.com 9 | * @version $Id: Packet.java,v 1.1 2007/10/15 12:49:55 cplattne Exp $ 10 | * 11 | */ 12 | public class Packet 13 | { 14 | public static final int SSH_FXP_INIT = 1; 15 | public static final int SSH_FXP_VERSION = 2; 16 | public static final int SSH_FXP_OPEN = 3; 17 | public static final int SSH_FXP_CLOSE = 4; 18 | public static final int SSH_FXP_READ = 5; 19 | public static final int SSH_FXP_WRITE = 6; 20 | public static final int SSH_FXP_LSTAT = 7; 21 | public static final int SSH_FXP_FSTAT = 8; 22 | public static final int SSH_FXP_SETSTAT = 9; 23 | public static final int SSH_FXP_FSETSTAT = 10; 24 | public static final int SSH_FXP_OPENDIR = 11; 25 | public static final int SSH_FXP_READDIR = 12; 26 | public static final int SSH_FXP_REMOVE = 13; 27 | public static final int SSH_FXP_MKDIR = 14; 28 | public static final int SSH_FXP_RMDIR = 15; 29 | public static final int SSH_FXP_REALPATH = 16; 30 | public static final int SSH_FXP_STAT = 17; 31 | public static final int SSH_FXP_RENAME = 18; 32 | public static final int SSH_FXP_READLINK = 19; 33 | public static final int SSH_FXP_SYMLINK = 20; 34 | 35 | public static final int SSH_FXP_STATUS = 101; 36 | public static final int SSH_FXP_HANDLE = 102; 37 | public static final int SSH_FXP_DATA = 103; 38 | public static final int SSH_FXP_NAME = 104; 39 | public static final int SSH_FXP_ATTRS = 105; 40 | 41 | public static final int SSH_FXP_EXTENDED = 200; 42 | public static final int SSH_FXP_EXTENDED_REPLY = 201; 43 | } 44 | -------------------------------------------------------------------------------- /src/com/trilead/ssh2/signature/DSAPrivateKey.java: -------------------------------------------------------------------------------- 1 | package com.trilead.ssh2.signature; 2 | 3 | import java.math.BigInteger; 4 | 5 | /** 6 | * DSAPrivateKey. 7 | * 8 | * @author Christian Plattner, plattner@trilead.com 9 | * @version $Id: DSAPrivateKey.java,v 1.1 2007/10/15 12:49:57 cplattne Exp $ 10 | */ 11 | public class DSAPrivateKey 12 | { 13 | private BigInteger p; 14 | private BigInteger q; 15 | private BigInteger g; 16 | private BigInteger x; 17 | private BigInteger y; 18 | 19 | public DSAPrivateKey(BigInteger p, BigInteger q, BigInteger g, 20 | BigInteger y, BigInteger x) 21 | { 22 | this.p = p; 23 | this.q = q; 24 | this.g = g; 25 | this.y = y; 26 | this.x = x; 27 | } 28 | 29 | public BigInteger getP() 30 | { 31 | return p; 32 | } 33 | 34 | public BigInteger getQ() 35 | { 36 | return q; 37 | } 38 | 39 | public BigInteger getG() 40 | { 41 | return g; 42 | } 43 | 44 | public BigInteger getY() 45 | { 46 | return y; 47 | } 48 | 49 | public BigInteger getX() 50 | { 51 | return x; 52 | } 53 | 54 | public DSAPublicKey getPublicKey() 55 | { 56 | return new DSAPublicKey(p, q, g, y); 57 | } 58 | } -------------------------------------------------------------------------------- /src/com/trilead/ssh2/signature/DSAPublicKey.java: -------------------------------------------------------------------------------- 1 | package com.trilead.ssh2.signature; 2 | 3 | import java.math.BigInteger; 4 | 5 | /** 6 | * DSAPublicKey. 7 | * 8 | * @author Christian Plattner, plattner@trilead.com 9 | * @version $Id: DSAPublicKey.java,v 1.1 2007/10/15 12:49:57 cplattne Exp $ 10 | */ 11 | public class DSAPublicKey 12 | { 13 | private BigInteger p; 14 | private BigInteger q; 15 | private BigInteger g; 16 | private BigInteger y; 17 | 18 | public DSAPublicKey(BigInteger p, BigInteger q, BigInteger g, BigInteger y) 19 | { 20 | this.p = p; 21 | this.q = q; 22 | this.g = g; 23 | this.y = y; 24 | } 25 | 26 | public BigInteger getP() 27 | { 28 | return p; 29 | } 30 | 31 | public BigInteger getQ() 32 | { 33 | return q; 34 | } 35 | 36 | public BigInteger getG() 37 | { 38 | return g; 39 | } 40 | 41 | public BigInteger getY() 42 | { 43 | return y; 44 | } 45 | } -------------------------------------------------------------------------------- /src/com/trilead/ssh2/signature/DSASignature.java: -------------------------------------------------------------------------------- 1 | package com.trilead.ssh2.signature; 2 | 3 | import java.math.BigInteger; 4 | 5 | /** 6 | * DSASignature. 7 | * 8 | * @author Christian Plattner, plattner@trilead.com 9 | * @version $Id: DSASignature.java,v 1.1 2007/10/15 12:49:57 cplattne Exp $ 10 | */ 11 | public class DSASignature 12 | { 13 | private BigInteger r; 14 | private BigInteger s; 15 | 16 | public DSASignature(BigInteger r, BigInteger s) 17 | { 18 | this.r = r; 19 | this.s = s; 20 | } 21 | 22 | public BigInteger getR() 23 | { 24 | return r; 25 | } 26 | 27 | public BigInteger getS() 28 | { 29 | return s; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/com/trilead/ssh2/signature/RSAPrivateKey.java: -------------------------------------------------------------------------------- 1 | package com.trilead.ssh2.signature; 2 | 3 | import java.math.BigInteger; 4 | 5 | /** 6 | * RSAPrivateKey. 7 | * 8 | * @author Christian Plattner, plattner@trilead.com 9 | * @version $Id: RSAPrivateKey.java,v 1.1 2007/10/15 12:49:57 cplattne Exp $ 10 | */ 11 | public class RSAPrivateKey 12 | { 13 | private BigInteger d; 14 | private BigInteger e; 15 | private BigInteger n; 16 | 17 | public RSAPrivateKey(BigInteger d, BigInteger e, BigInteger n) 18 | { 19 | this.d = d; 20 | this.e = e; 21 | this.n = n; 22 | } 23 | 24 | public BigInteger getD() 25 | { 26 | return d; 27 | } 28 | 29 | public BigInteger getE() 30 | { 31 | return e; 32 | } 33 | 34 | public BigInteger getN() 35 | { 36 | return n; 37 | } 38 | 39 | public RSAPublicKey getPublicKey() 40 | { 41 | return new RSAPublicKey(e, n); 42 | } 43 | } -------------------------------------------------------------------------------- /src/com/trilead/ssh2/signature/RSAPublicKey.java: -------------------------------------------------------------------------------- 1 | package com.trilead.ssh2.signature; 2 | 3 | import java.math.BigInteger; 4 | 5 | /** 6 | * RSAPublicKey. 7 | * 8 | * @author Christian Plattner, plattner@trilead.com 9 | * @version $Id: RSAPublicKey.java,v 1.1 2007/10/15 12:49:57 cplattne Exp $ 10 | */ 11 | public class RSAPublicKey 12 | { 13 | BigInteger e; 14 | BigInteger n; 15 | 16 | public RSAPublicKey(BigInteger e, BigInteger n) 17 | { 18 | this.e = e; 19 | this.n = n; 20 | } 21 | 22 | public BigInteger getE() 23 | { 24 | return e; 25 | } 26 | 27 | public BigInteger getN() 28 | { 29 | return n; 30 | } 31 | } -------------------------------------------------------------------------------- /src/com/trilead/ssh2/signature/RSASignature.java: -------------------------------------------------------------------------------- 1 | 2 | package com.trilead.ssh2.signature; 3 | 4 | import java.math.BigInteger; 5 | 6 | 7 | /** 8 | * RSASignature. 9 | * 10 | * @author Christian Plattner, plattner@trilead.com 11 | * @version $Id: RSASignature.java,v 1.1 2007/10/15 12:49:57 cplattne Exp $ 12 | */ 13 | 14 | public class RSASignature 15 | { 16 | BigInteger s; 17 | 18 | public BigInteger getS() 19 | { 20 | return s; 21 | } 22 | 23 | public RSASignature(BigInteger s) 24 | { 25 | this.s = s; 26 | } 27 | } -------------------------------------------------------------------------------- /src/com/trilead/ssh2/transport/KexParameters.java: -------------------------------------------------------------------------------- 1 | package com.trilead.ssh2.transport; 2 | 3 | /** 4 | * KexParameters. 5 | * 6 | * @author Christian Plattner, plattner@trilead.com 7 | * @version $Id: KexParameters.java,v 1.1 2007/10/15 12:49:56 cplattne Exp $ 8 | */ 9 | public class KexParameters 10 | { 11 | public byte[] cookie; 12 | public String[] kex_algorithms; 13 | public String[] server_host_key_algorithms; 14 | public String[] encryption_algorithms_client_to_server; 15 | public String[] encryption_algorithms_server_to_client; 16 | public String[] mac_algorithms_client_to_server; 17 | public String[] mac_algorithms_server_to_client; 18 | public String[] compression_algorithms_client_to_server; 19 | public String[] compression_algorithms_server_to_client; 20 | public String[] languages_client_to_server; 21 | public String[] languages_server_to_client; 22 | public boolean first_kex_packet_follows; 23 | public int reserved_field1; 24 | } 25 | -------------------------------------------------------------------------------- /src/com/trilead/ssh2/transport/KexState.java: -------------------------------------------------------------------------------- 1 | package com.trilead.ssh2.transport; 2 | 3 | 4 | import java.math.BigInteger; 5 | 6 | import com.trilead.ssh2.DHGexParameters; 7 | import com.trilead.ssh2.crypto.dh.DhExchange; 8 | import com.trilead.ssh2.crypto.dh.DhGroupExchange; 9 | import com.trilead.ssh2.packets.PacketKexInit; 10 | 11 | /** 12 | * KexState. 13 | * 14 | * @author Christian Plattner, plattner@trilead.com 15 | * @version $Id: KexState.java,v 1.1 2007/10/15 12:49:57 cplattne Exp $ 16 | */ 17 | public class KexState 18 | { 19 | public PacketKexInit localKEX; 20 | public PacketKexInit remoteKEX; 21 | public NegotiatedParameters np; 22 | public int state = 0; 23 | 24 | public BigInteger K; 25 | public byte[] H; 26 | 27 | public byte[] hostkey; 28 | 29 | public DhExchange dhx; 30 | public DhGroupExchange dhgx; 31 | public DHGexParameters dhgexParameters; 32 | } 33 | -------------------------------------------------------------------------------- /src/com/trilead/ssh2/transport/MessageHandler.java: -------------------------------------------------------------------------------- 1 | package com.trilead.ssh2.transport; 2 | 3 | import java.io.IOException; 4 | 5 | /** 6 | * MessageHandler. 7 | * 8 | * @author Christian Plattner, plattner@trilead.com 9 | * @version $Id: MessageHandler.java,v 1.1 2007/10/15 12:49:56 cplattne Exp $ 10 | */ 11 | public interface MessageHandler 12 | { 13 | public void handleMessage(byte[] msg, int msglen) throws IOException; 14 | } 15 | -------------------------------------------------------------------------------- /src/com/trilead/ssh2/transport/NegotiateException.java: -------------------------------------------------------------------------------- 1 | package com.trilead.ssh2.transport; 2 | 3 | /** 4 | * NegotiateException. 5 | * 6 | * @author Christian Plattner, plattner@trilead.com 7 | * @version $Id: NegotiateException.java,v 1.1 2007/10/15 12:49:56 cplattne Exp $ 8 | */ 9 | public class NegotiateException extends Exception 10 | { 11 | private static final long serialVersionUID = 3689910669428143157L; 12 | } 13 | -------------------------------------------------------------------------------- /src/com/trilead/ssh2/transport/NegotiatedParameters.java: -------------------------------------------------------------------------------- 1 | package com.trilead.ssh2.transport; 2 | 3 | /** 4 | * NegotiatedParameters. 5 | * 6 | * @author Christian Plattner, plattner@trilead.com 7 | * @version $Id: NegotiatedParameters.java,v 1.1 2007/10/15 12:49:57 cplattne Exp $ 8 | */ 9 | public class NegotiatedParameters 10 | { 11 | public boolean guessOK; 12 | public String kex_algo; 13 | public String server_host_key_algo; 14 | public String enc_algo_client_to_server; 15 | public String enc_algo_server_to_client; 16 | public String mac_algo_client_to_server; 17 | public String mac_algo_server_to_client; 18 | public String comp_algo_client_to_server; 19 | public String comp_algo_server_to_client; 20 | public String lang_client_to_server; 21 | public String lang_server_to_client; 22 | } 23 | -------------------------------------------------------------------------------- /src/com/trilead/ssh2/util/Tokenizer.java: -------------------------------------------------------------------------------- 1 | 2 | package com.trilead.ssh2.util; 3 | 4 | /** 5 | * Tokenizer. Why? Because StringTokenizer is not available in J2ME. 6 | * 7 | * @author Christian Plattner, plattner@trilead.com 8 | * @version $Id: Tokenizer.java,v 1.1 2007/10/15 12:49:57 cplattne Exp $ 9 | */ 10 | public class Tokenizer 11 | { 12 | /** 13 | * Exists because StringTokenizer is not available in J2ME. 14 | * Returns an array with at least 1 entry. 15 | * 16 | * @param source must be non-null 17 | * @param delimiter 18 | * @return an array of Strings 19 | */ 20 | public static String[] parseTokens(String source, char delimiter) 21 | { 22 | int numtoken = 1; 23 | 24 | for (int i = 0; i < source.length(); i++) 25 | { 26 | if (source.charAt(i) == delimiter) 27 | numtoken++; 28 | } 29 | 30 | String list[] = new String[numtoken]; 31 | int nextfield = 0; 32 | 33 | for (int i = 0; i < numtoken; i++) 34 | { 35 | if (nextfield >= source.length()) 36 | { 37 | list[i] = ""; 38 | } 39 | else 40 | { 41 | int idx = source.indexOf(delimiter, nextfield); 42 | if (idx == -1) 43 | idx = source.length(); 44 | list[i] = source.substring(nextfield, idx); 45 | nextfield = idx + 1; 46 | } 47 | } 48 | 49 | return list; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/de/mud/terminal/VDUDisplay.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of "JTA - Telnet/SSH for the JAVA(tm) platform". 3 | * 4 | * (c) Matthias L. Jugel, Marcus Meißner 1996-2005. All Rights Reserved. 5 | * 6 | * Please visit http://javatelnet.org/ for updates and contact. 7 | * 8 | * --LICENSE NOTICE-- 9 | * This program is free software; you can redistribute it and/or 10 | * modify it under the terms of the GNU General Public License 11 | * as published by the Free Software Foundation; either version 2 12 | * of the License, or (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 22 | * --LICENSE NOTICE-- 23 | * 24 | */ 25 | 26 | package de.mud.terminal; 27 | 28 | /** 29 | * Generic display 30 | */ 31 | public interface VDUDisplay { 32 | public void redraw(); 33 | public void updateScrollBar(); 34 | 35 | public void setVDUBuffer(VDUBuffer buffer); 36 | public VDUBuffer getVDUBuffer(); 37 | 38 | public void setColor(int index, int red, int green, int blue); 39 | public void resetColors(); 40 | } 41 | -------------------------------------------------------------------------------- /src/net/sourceforge/jsocks/Authentication.java: -------------------------------------------------------------------------------- 1 | package net.sourceforge.jsocks; 2 | 3 | /** 4 | The Authentication interface provides for performing method specific 5 | authentication for SOCKS5 connections. 6 | */ 7 | public interface Authentication{ 8 | /** 9 | This method is called when SOCKS5 server have selected a particular 10 | authentication method, for whch an implementaion have been registered. 11 | 12 |
13 | This method should return an array {inputstream,outputstream 14 | [,UDPEncapsulation]}. The reason for that is that SOCKS5 protocol 15 | allows to have method specific encapsulation of data on the socket for 16 | purposes of integrity or security. And this encapsulation should be 17 | performed by those streams returned from the method. It is also possible 18 | to encapsulate datagrams. If authentication method supports such 19 | encapsulation an instance of the UDPEncapsulation interface should be 20 | returned as third element of the array, otherwise either null should be 21 | returned as third element, or array should contain only 2 elements. 22 | 23 | @param methodId Authentication method selected by the server. 24 | @param proxySocket Socket used to conect to the proxy. 25 | @return Two or three element array containing 26 | Input/Output streams which should be used on this connection. 27 | Third argument is optional and should contain an instance 28 | of UDPEncapsulation. It should be provided if the authentication 29 | method used requires any encapsulation to be done on the 30 | datagrams. 31 | */ 32 | Object[] doSocksAuthentication(int methodId,java.net.Socket proxySocket) 33 | throws java.io.IOException; 34 | } 35 | -------------------------------------------------------------------------------- /src/net/sourceforge/jsocks/AuthenticationNone.java: -------------------------------------------------------------------------------- 1 | package net.sourceforge.jsocks; 2 | 3 | /** 4 | SOCKS5 none authentication. Dummy class does almost nothing. 5 | */ 6 | public class AuthenticationNone implements Authentication{ 7 | 8 | public Object[] doSocksAuthentication(int methodId, 9 | java.net.Socket proxySocket) 10 | throws java.io.IOException{ 11 | 12 | if(methodId!=0) return null; 13 | 14 | return new Object[] { proxySocket.getInputStream(), 15 | proxySocket.getOutputStream()}; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/net/sourceforge/jsocks/UDPEncapsulation.java: -------------------------------------------------------------------------------- 1 | package net.sourceforge.jsocks; 2 | /** 3 | This interface provides for datagram encapsulation for SOCKSv5 protocol. 4 |
5 | SOCKSv5 allows for datagrams to be encapsulated for purposes of integrity
6 | and/or authenticity. How it should be done is aggreed during the
7 | authentication stage, and is authentication dependent. This interface is
8 | provided to allow this encapsulation.
9 | @see Authentication
10 | */
11 | public interface UDPEncapsulation{
12 |
13 | /**
14 | This method should provide any authentication depended transformation
15 | on datagrams being send from/to the client.
16 |
17 | @param data Datagram data (including any SOCKS related bytes), to be
18 | encapsulated/decapsulated.
19 | @param out Wether the data is being send out. If true method should
20 | encapsulate/encrypt data, otherwise it should decapsulate/
21 | decrypt data.
22 | @throw IOException if for some reason data can be transformed correctly.
23 | @return Should return byte array containing data after transformation.
24 | It is possible to return same array as input, if transformation
25 | only involves bit mangling, and no additional data is being
26 | added or removed.
27 | */
28 | byte[] udpEncapsulate(byte[] data, boolean out) throws java.io.IOException;
29 | }
30 |
--------------------------------------------------------------------------------
/src/sk/vx/connectbot/HelpTopicActivity.java:
--------------------------------------------------------------------------------
1 | /*
2 | * ConnectBot: simple, powerful, open-source SSH client for Android
3 | * Copyright 2007 Kenny Root, Jeffrey Sharkey
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | package sk.vx.connectbot;
19 |
20 | import sk.vx.connectbot.util.HelpTopicView;
21 | import android.app.Activity;
22 | import android.content.Intent;
23 | import android.os.Bundle;
24 |
25 | /**
26 | * @author Kenny Root
27 | *
28 | */
29 | public class HelpTopicActivity extends Activity {
30 | public final static String TAG = "ConnectBot.HelpActivity";
31 |
32 | @Override
33 | public void onCreate(Bundle icicle) {
34 | super.onCreate(icicle);
35 | setContentView(R.layout.act_help_topic);
36 |
37 | String topic = getIntent().getStringExtra(Intent.EXTRA_TITLE);
38 |
39 | this.setTitle(String.format("%s: %s - %s",
40 | getResources().getText(R.string.app_name),
41 | getResources().getText(R.string.title_help),
42 | topic));
43 |
44 | HelpTopicView helpTopic = (HelpTopicView) findViewById(R.id.topic_text);
45 |
46 | helpTopic.setTopic(topic);
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/src/sk/vx/connectbot/SettingsActivity.java:
--------------------------------------------------------------------------------
1 | /*
2 | * ConnectBot: simple, powerful, open-source SSH client for Android
3 | * Copyright 2007 Kenny Root, Jeffrey Sharkey
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | package sk.vx.connectbot;
19 |
20 | import sk.vx.connectbot.util.PreferenceConstants;
21 | import android.content.SharedPreferences;
22 | import android.os.Bundle;
23 | import android.preference.PreferenceActivity;
24 | import android.preference.PreferenceManager;
25 | import android.util.Log;
26 |
27 | public class SettingsActivity extends PreferenceActivity {
28 | private static final String TAG = "ConnectBot.Settings";
29 |
30 | @Override
31 | protected void onCreate(Bundle savedInstanceState) {
32 | super.onCreate(savedInstanceState);
33 | try {
34 | addPreferencesFromResource(R.xml.preferences);
35 | } catch (ClassCastException e) {
36 | Log.e(TAG, "Shared preferences are corrupt! Resetting to default values.");
37 |
38 | SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
39 |
40 | // Blow away all the preferences
41 | SharedPreferences.Editor editor = preferences.edit();
42 | editor.clear();
43 | editor.commit();
44 |
45 | PreferenceManager.setDefaultValues(this, R.xml.preferences, true);
46 |
47 | // Since they were able to get to the Settings activity, they already agreed to the EULA
48 | editor = preferences.edit();
49 | editor.putBoolean(PreferenceConstants.EULA, true);
50 | editor.commit();
51 |
52 | addPreferencesFromResource(R.xml.preferences);
53 | }
54 | // TODO: add parse checking here to make sure we have integer value for scrollback
55 |
56 | }
57 |
58 | }
59 |
--------------------------------------------------------------------------------
/src/sk/vx/connectbot/StrictModeSetup.java:
--------------------------------------------------------------------------------
1 | /*
2 | * ConnectBot: simple, powerful, open-source SSH client for Android
3 | * Copyright 2007 Kenny Root, Jeffrey Sharkey
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package sk.vx.connectbot;
18 | import android.annotation.TargetApi;
19 | import android.os.StrictMode;
20 | @TargetApi(9)
21 | public class StrictModeSetup {
22 | public static void run() {
23 | StrictMode.setThreadPolicy(StrictMode.ThreadPolicy.LAX);
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/src/sk/vx/connectbot/bean/AbstractBean.java:
--------------------------------------------------------------------------------
1 | /*
2 | * ConnectBot: simple, powerful, open-source SSH client for Android
3 | * Copyright 2007 Kenny Root, Jeffrey Sharkey
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | package sk.vx.connectbot.bean;
19 |
20 | import java.util.Map.Entry;
21 |
22 | import sk.vx.connectbot.util.XmlBuilder;
23 | import android.content.ContentValues;
24 |
25 | /**
26 | * @author Kenny Root
27 | *
28 | */
29 | abstract class AbstractBean {
30 | public abstract ContentValues getValues();
31 | public abstract String getBeanName();
32 |
33 | public String toXML() {
34 | XmlBuilder xml = new XmlBuilder();
35 |
36 | xml.append(String.format("<%s>", getBeanName()));
37 |
38 | ContentValues values = getValues();
39 | for (Entry