├── .gitignore
├── .idea
├── assetWizardSettings.xml
├── codeStyles
│ └── Project.xml
├── encodings.xml
├── gradle.xml
├── misc.xml
├── runConfigurations.xml
└── vcs.xml
├── README.md
├── app
├── .gitignore
├── build.gradle
├── libs
│ └── jsch-0.1.55.jar
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── smiskol
│ │ └── phantom
│ │ └── ExampleInstrumentedTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── ic_add_symbol-web.png
│ ├── ic_launcher-web.png
│ ├── ic_phantom_logo-web.png
│ ├── ic_phantom_logo_test-web.png
│ ├── java
│ │ └── com
│ │ │ ├── ethz
│ │ │ └── ssh2
│ │ │ │ ├── ChannelCondition.java
│ │ │ │ ├── Connection.java
│ │ │ │ ├── ConnectionInfo.java
│ │ │ │ ├── ConnectionMonitor.java
│ │ │ │ ├── DHGexParameters.java
│ │ │ │ ├── HTTPProxyData.java
│ │ │ │ ├── HTTPProxyException.java
│ │ │ │ ├── InteractiveCallback.java
│ │ │ │ ├── KnownHosts.java
│ │ │ │ ├── LocalPortForwarder.java
│ │ │ │ ├── LocalStreamForwarder.java
│ │ │ │ ├── PacketListener.java
│ │ │ │ ├── ProxyData.java
│ │ │ │ ├── SCPClient.java
│ │ │ │ ├── SCPInputStream.java
│ │ │ │ ├── SCPOutputStream.java
│ │ │ │ ├── SFTPException.java
│ │ │ │ ├── SFTPInputStream.java
│ │ │ │ ├── SFTPOutputStream.java
│ │ │ │ ├── SFTPv3Client.java
│ │ │ │ ├── SFTPv3DirectoryEntry.java
│ │ │ │ ├── SFTPv3FileAttributes.java
│ │ │ │ ├── SFTPv3FileHandle.java
│ │ │ │ ├── ServerHostKeyVerifier.java
│ │ │ │ ├── Session.java
│ │ │ │ ├── StreamGobbler.java
│ │ │ │ ├── Version.java
│ │ │ │ ├── auth
│ │ │ │ └── AuthenticationManager.java
│ │ │ │ ├── channel
│ │ │ │ ├── Channel.java
│ │ │ │ ├── ChannelClosedException.java
│ │ │ │ ├── ChannelInputStream.java
│ │ │ │ ├── ChannelManager.java
│ │ │ │ ├── ChannelOutputStream.java
│ │ │ │ ├── IChannelWorkerThread.java
│ │ │ │ ├── LocalAcceptThread.java
│ │ │ │ ├── RemoteAcceptThread.java
│ │ │ │ ├── RemoteForwardingData.java
│ │ │ │ ├── RemoteX11AcceptThread.java
│ │ │ │ ├── StreamForwarder.java
│ │ │ │ └── X11ServerData.java
│ │ │ │ ├── crypto
│ │ │ │ ├── Base64.java
│ │ │ │ ├── CryptoWishList.java
│ │ │ │ ├── KeyMaterial.java
│ │ │ │ ├── PEMDecoder.java
│ │ │ │ ├── PEMDecryptException.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
│ │ │ │ ├── PacketChannelOpenConfirmation.java
│ │ │ │ ├── PacketChannelOpenFailure.java
│ │ │ │ ├── PacketChannelWindowAdjust.java
│ │ │ │ ├── PacketDisconnect.java
│ │ │ │ ├── PacketGlobalCancelForwardRequest.java
│ │ │ │ ├── PacketGlobalForwardRequest.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
│ │ │ │ ├── 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
│ │ │ │ ├── StringEncoder.java
│ │ │ │ ├── TimeoutService.java
│ │ │ │ └── Tokenizer.java
│ │ │ └── smiskol
│ │ │ └── phantom
│ │ │ ├── CenterSeekBar.java
│ │ │ ├── ControlsFragment.java
│ │ │ ├── MainActivity.java
│ │ │ ├── SSHClass.java
│ │ │ ├── ViewPagerAdapter.java
│ │ │ └── WelcomeFragment.java
│ └── res
│ │ ├── anim
│ │ └── shake.xml
│ │ ├── drawable-v24
│ │ └── ic_launcher_foreground.xml
│ │ ├── drawable
│ │ ├── hold_animation.xml
│ │ ├── hold_disable_gradient.xml
│ │ ├── hold_enable_gradient.xml
│ │ ├── hold_ripple.xml
│ │ ├── ic_launcher_background.xml
│ │ ├── ic_plus.xml
│ │ ├── ic_sub.xml
│ │ ├── round_button_plus.xml
│ │ └── round_button_sub.xml
│ │ ├── font
│ │ ├── product.xml
│ │ ├── product_bold.ttf
│ │ └── product_regular.ttf
│ │ ├── layout
│ │ ├── activity_main.xml
│ │ ├── fragment_controls.xml
│ │ ├── fragment_welcome.xml
│ │ └── toolbar_layout.xml
│ │ ├── mipmap-anydpi-v26
│ │ ├── ic_launcher.xml
│ │ └── ic_launcher_round.xml
│ │ ├── mipmap-hdpi
│ │ ├── ic_launcher.png
│ │ ├── ic_launcher_foreground.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-mdpi
│ │ ├── ic_launcher.png
│ │ ├── ic_launcher_foreground.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xhdpi
│ │ ├── ic_launcher.png
│ │ ├── ic_launcher_foreground.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxhdpi
│ │ ├── ic_launcher.png
│ │ ├── ic_launcher_foreground.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxxhdpi
│ │ ├── ic_launcher.png
│ │ ├── ic_launcher_foreground.png
│ │ └── ic_launcher_round.png
│ │ └── values
│ │ ├── colors.xml
│ │ ├── ic_launcher_background.xml
│ │ ├── strings.xml
│ │ └── styles.xml
│ └── test
│ └── java
│ └── com
│ └── smiskol
│ └── phantom
│ └── ExampleUnitTest.java
├── build.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── phantom-app.apk
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/caches/build_file_checksums.ser
5 | /.idea/libraries
6 | /.idea/modules.xml
7 | /.idea/workspace.xml
8 | .DS_Store
9 | /build
10 | /captures
11 | .externalNativeBuild
12 | gradle_models.ser
--------------------------------------------------------------------------------
/.idea/codeStyles/Project.xml:
--------------------------------------------------------------------------------
1 |
9 |
17 |
22 |
29 | ((cond & ChannelCondition.CLOSED) != 0)
.
24 | */
25 | public static final int TIMEOUT = 1;
26 |
27 | /**
28 | * The underlying SSH-2 channel, however not necessarily the whole connection,
29 | * has been closed. This implies EOF
. Note that there may still
30 | * be unread stdout or stderr data in the local window, i.e, STDOUT_DATA
31 | * or/and STDERR_DATA
may be set at the same time.
32 | */
33 | public static final int CLOSED = 2;
34 |
35 | /**
36 | * There is stdout data available that is ready to be consumed.
37 | */
38 | public static final int STDOUT_DATA = 4;
39 |
40 | /**
41 | * There is stderr data available that is ready to be consumed.
42 | */
43 | public static final int STDERR_DATA = 8;
44 |
45 | /**
46 | * EOF on has been reached, no more _new_ stdout or stderr data will arrive
47 | * from the remote server. However, there may be unread stdout or stderr
48 | * data, i.e, STDOUT_DATA
or/and STDERR_DATA
49 | * may be set at the same time.
50 | */
51 | public static final int EOF = 16;
52 |
53 | /**
54 | * The exit status of the remote process is available.
55 | * Some servers never send the exist status, or occasionally "forget" to do so.
56 | */
57 | public static final int EXIT_STATUS = 32;
58 |
59 | /**
60 | * The exit signal of the remote process is available.
61 | */
62 | public static final int EXIT_SIGNAL = 64;
63 |
64 | }
65 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ethz/ssh2/ConnectionInfo.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2006-2011 Christian Plattner. All rights reserved.
3 | * Please refer to the LICENSE.txt for licensing details.
4 | */
5 | package ch.ethz.ssh2;
6 |
7 | /**
8 | * In most cases you probably do not need the information contained in here.
9 | *
10 | * @author Christian Plattner
11 | * @version 2.50, 03/15/10
12 | */
13 | public class ConnectionInfo
14 | {
15 | /**
16 | * The used key exchange (KEX) algorithm in the latest key exchange.
17 | */
18 | public String keyExchangeAlgorithm;
19 |
20 | /**
21 | * The currently used crypto algorithm for packets from to the client to the
22 | * server.
23 | */
24 | public String clientToServerCryptoAlgorithm;
25 | /**
26 | * The currently used crypto algorithm for packets from to the server to the
27 | * client.
28 | */
29 | public String serverToClientCryptoAlgorithm;
30 |
31 | /**
32 | * The currently used MAC algorithm for packets from to the client to the
33 | * server.
34 | */
35 | public String clientToServerMACAlgorithm;
36 | /**
37 | * The currently used MAC algorithm for packets from to the server to the
38 | * client.
39 | */
40 | public String serverToClientMACAlgorithm;
41 |
42 | /**
43 | * The type of the server host key (currently either "ssh-dss" or
44 | * "ssh-rsa").
45 | */
46 | public String serverHostKeyAlgorithm;
47 | /**
48 | * The server host key that was sent during the latest key exchange.
49 | */
50 | public byte[] serverHostKey;
51 |
52 | /**
53 | * Number of kex exchanges performed on this connection so far.
54 | */
55 | public int keyExchangeCounter = 0;
56 | }
57 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ethz/ssh2/ConnectionMonitor.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2006-2011 Christian Plattner. All rights reserved.
3 | * Please refer to the LICENSE.txt for licensing details.
4 | */
5 | package ch.ethz.ssh2;
6 |
7 | /**
8 | * A ConnectionMonitor
is used to get notified when the
9 | * underlying socket of a connection is closed.
10 | *
11 | * @author Christian Plattner
12 | * @version 2.50, 03/15/10
13 | */
14 |
15 | public interface ConnectionMonitor
16 | {
17 | /**
18 | * This method is called after the connection's underlying
19 | * socket has been closed. E.g., due to the {@link Connection#close()} request of the
20 | * user, if the peer closed the connection, due to a fatal error during connect()
21 | * (also if the socket cannot be established) or if a fatal error occured on
22 | * an established connection.
23 | *
24 | * This is an experimental feature. 25 | *
26 | * You MUST NOT make any assumption about the thread that invokes this method. 27 | *
28 | * Please note: if the connection is not connected (e.g., there was no successful
29 | * connect() call), then the invocation of {@link Connection#close()} will NOT trigger
30 | * this method.
31 | *
32 | * @see Connection#addConnectionMonitor(ConnectionMonitor)
33 | *
34 | * @param reason Includes an indication why the socket was closed.
35 | */
36 | public void connectionLost(Throwable reason);
37 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/ethz/ssh2/HTTPProxyData.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2006-2011 Christian Plattner. All rights reserved.
3 | * Please refer to the LICENSE.txt for licensing details.
4 | */
5 | package ch.ethz.ssh2;
6 |
7 | /**
8 | * A HTTPProxyData
object is used to specify the needed connection data
9 | * to connect through a HTTP proxy.
10 | *
11 | * @see Connection#setProxyData(ProxyData)
12 | *
13 | * @author Christian Plattner
14 | * @version 2.50, 03/15/10
15 | */
16 |
17 | public class HTTPProxyData implements ProxyData
18 | {
19 | public final String proxyHost;
20 | public final int proxyPort;
21 | public final String proxyUser;
22 | public final String proxyPass;
23 | public final String[] requestHeaderLines;
24 |
25 | /**
26 | * Same as calling {@link #HTTPProxyData(String, int, String, String) HTTPProxyData(proxyHost, proxyPort, null
, null
)}
27 | *
28 | * @param proxyHost Proxy hostname.
29 | * @param proxyPort Proxy port.
30 | */
31 | public HTTPProxyData(String proxyHost, int proxyPort)
32 | {
33 | this(proxyHost, proxyPort, null, null);
34 | }
35 |
36 | /**
37 | * Same as calling {@link #HTTPProxyData(String, int, String, String, String[]) HTTPProxyData(proxyHost, proxyPort, null
, null
, null
)}
38 | *
39 | * @param proxyHost Proxy hostname.
40 | * @param proxyPort Proxy port.
41 | * @param proxyUser Username for basic authentication (null
if no authentication is needed).
42 | * @param proxyPass Password for basic authentication (null
if no authentication is needed).
43 | */
44 | public HTTPProxyData(String proxyHost, int proxyPort, String proxyUser, String proxyPass)
45 | {
46 | this(proxyHost, proxyPort, proxyUser, proxyPass, null);
47 | }
48 |
49 | /**
50 | * Connection data for a HTTP proxy. It is possible to specify a username and password
51 | * if the proxy requires basic authentication. Also, additional request header lines can
52 | * be specified (e.g., "User-Agent: CERN-LineMode/2.15 libwww/2.17b3").
53 | *
54 | * Please note: if you want to use basic authentication, then both proxyUser
55 | * and proxyPass
must be non-null.
56 | *
57 | * Here is an example: 58 | *
59 | *
60 | * new HTTPProxyData("192.168.1.1", "3128", "proxyuser", "secret", new String[] {"User-Agent: GanymedBasedClient/1.0", "X-My-Proxy-Option: something"});
61 | *
62 | *
63 | * @param proxyHost Proxy hostname.
64 | * @param proxyPort Proxy port.
65 | * @param proxyUser Username for basic authentication (null
if no authentication is needed).
66 | * @param proxyPass Password for basic authentication (null
if no authentication is needed).
67 | * @param requestHeaderLines An array with additional request header lines (without end-of-line markers)
68 | * that have to be sent to the server. May be null
.
69 | */
70 |
71 | public HTTPProxyData(String proxyHost, int proxyPort, String proxyUser, String proxyPass,
72 | String[] requestHeaderLines)
73 | {
74 | if (proxyHost == null)
75 | throw new IllegalArgumentException("proxyHost must be non-null");
76 |
77 | if (proxyPort < 0)
78 | throw new IllegalArgumentException("proxyPort must be non-negative");
79 |
80 | this.proxyHost = proxyHost;
81 | this.proxyPort = proxyPort;
82 | this.proxyUser = proxyUser;
83 | this.proxyPass = proxyPass;
84 | this.requestHeaderLines = requestHeaderLines;
85 | }
86 | }
87 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ethz/ssh2/HTTPProxyException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2006-2011 Christian Plattner. All rights reserved.
3 | * Please refer to the LICENSE.txt for licensing details.
4 | */
5 | package ch.ethz.ssh2;
6 |
7 | import java.io.IOException;
8 |
9 | /**
10 | * May be thrown upon connect() if a HTTP proxy is being used.
11 | *
12 | * @see Connection#connect()
13 | * @see Connection#setProxyData(ProxyData)
14 | *
15 | * @author Christian Plattner
16 | * @version 2.50, 03/15/10
17 | */
18 |
19 | public class HTTPProxyException extends IOException
20 | {
21 | private static final long serialVersionUID = 2241537397104426186L;
22 |
23 | public final String httpResponse;
24 | public final int httpErrorCode;
25 |
26 | public HTTPProxyException(String httpResponse, int httpErrorCode)
27 | {
28 | super("HTTP Proxy Error (" + httpErrorCode + " " + httpResponse + ")");
29 | this.httpResponse = httpResponse;
30 | this.httpErrorCode = httpErrorCode;
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ethz/ssh2/InteractiveCallback.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2006-2011 Christian Plattner. All rights reserved.
3 | * Please refer to the LICENSE.txt for licensing details.
4 | */
5 | package ch.ethz.ssh2;
6 |
7 | /**
8 | * An InteractiveCallback
is used to respond to challenges sent
9 | * by the server if authentication mode "keyboard-interactive" is selected.
10 | *
11 | * @see Connection#authenticateWithKeyboardInteractive(String,
12 | * String[], InteractiveCallback)
13 | *
14 | * @author Christian Plattner
15 | * @version 2.50, 03/15/10
16 | */
17 |
18 | public interface InteractiveCallback
19 | {
20 | /**
21 | * This callback interface is used during a "keyboard-interactive"
22 | * authentication. Every time the server sends a set of challenges (however,
23 | * most often just one challenge at a time), this callback function will be
24 | * called to give your application a chance to talk to the user and to
25 | * determine the response(s).
26 | *
27 | * Some copy-paste information from the standard: a command line interface 28 | * (CLI) client SHOULD print the name and instruction (if non-empty), adding 29 | * newlines. Then for each prompt in turn, the client SHOULD display the 30 | * prompt and read the user input. The name and instruction fields MAY be 31 | * empty strings, the client MUST be prepared to handle this correctly. The 32 | * prompt field(s) MUST NOT be empty strings. 33 | *
34 | * Please refer to draft-ietf-secsh-auth-kbdinteract-XX.txt for the details. 35 | *
36 | * Note: clients SHOULD use control character filtering as discussed in
37 | * RFC4251 to avoid attacks by including
38 | * terminal control characters in the fields to be displayed.
39 | *
40 | * @param name
41 | * the name String sent by the server.
42 | * @param instruction
43 | * the instruction String sent by the server.
44 | * @param numPrompts
45 | * number of prompts - may be zero (in this case, you should just
46 | * return a String array of length zero).
47 | * @param prompt
48 | * an array (length numPrompts
) of Strings
49 | * @param echo
50 | * an array (length numPrompts
) of booleans. For
51 | * each prompt, the corresponding echo field indicates whether or
52 | * not the user input should be echoed as characters are typed.
53 | * @return an array of reponses - the array size must match the parameter
54 | * numPrompts
.
55 | */
56 | public String[] replyToChallenge(String name, String instruction, int numPrompts, String[] prompt, boolean[] echo)
57 | throws Exception;
58 | }
59 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ethz/ssh2/LocalPortForwarder.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2006-2011 Christian Plattner. All rights reserved.
3 | * Please refer to the LICENSE.txt for licensing details.
4 | */
5 | package ch.ethz.ssh2;
6 |
7 | import java.io.IOException;
8 | import java.net.InetSocketAddress;
9 |
10 | import ch.ethz.ssh2.channel.ChannelManager;
11 | import ch.ethz.ssh2.channel.LocalAcceptThread;
12 |
13 | /**
14 | * A LocalPortForwarder
forwards TCP/IP connections to a local
15 | * port via the secure tunnel to another host (which may or may not be identical
16 | * to the remote SSH-2 server). Checkout {@link Connection#createLocalPortForwarder(int, String, int)}
17 | * on how to create one.
18 | *
19 | * @author Christian Plattner
20 | * @version 2.50, 03/15/10
21 | */
22 | public class LocalPortForwarder
23 | {
24 | ChannelManager cm;
25 |
26 | String host_to_connect;
27 |
28 | int port_to_connect;
29 |
30 | LocalAcceptThread lat;
31 |
32 | LocalPortForwarder(ChannelManager cm, int local_port, String host_to_connect, int port_to_connect)
33 | throws IOException
34 | {
35 | this.cm = cm;
36 | this.host_to_connect = host_to_connect;
37 | this.port_to_connect = port_to_connect;
38 |
39 | lat = new LocalAcceptThread(cm, local_port, host_to_connect, port_to_connect);
40 | lat.setDaemon(true);
41 | lat.start();
42 | }
43 |
44 | LocalPortForwarder(ChannelManager cm, InetSocketAddress addr, String host_to_connect, int port_to_connect)
45 | throws IOException
46 | {
47 | this.cm = cm;
48 | this.host_to_connect = host_to_connect;
49 | this.port_to_connect = port_to_connect;
50 |
51 | lat = new LocalAcceptThread(cm, addr, host_to_connect, port_to_connect);
52 | lat.setDaemon(true);
53 | lat.start();
54 | }
55 |
56 | /**
57 | * Stop TCP/IP forwarding of newly arriving connections.
58 | *
59 | * @throws IOException
60 | */
61 | public void close() throws IOException
62 | {
63 | lat.stopWorking();
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ethz/ssh2/LocalStreamForwarder.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2006-2011 Christian Plattner. All rights reserved.
3 | * Please refer to the LICENSE.txt for licensing details.
4 | */
5 | package ch.ethz.ssh2;
6 |
7 | import java.io.IOException;
8 | import java.io.InputStream;
9 | import java.io.OutputStream;
10 | import java.net.InetAddress;
11 |
12 | import ch.ethz.ssh2.channel.Channel;
13 | import ch.ethz.ssh2.channel.ChannelManager;
14 |
15 | /**
16 | * A LocalStreamForwarder
forwards an Input- and Outputstream
17 | * pair via the secure tunnel to another host (which may or may not be identical
18 | * to the remote SSH-2 server).
19 | *
20 | * @author Christian Plattner
21 | * @version 2.50, 03/15/10
22 | */
23 | public class LocalStreamForwarder
24 | {
25 | private ChannelManager cm;
26 |
27 | private Channel cn;
28 |
29 | LocalStreamForwarder(ChannelManager cm, String host_to_connect, int port_to_connect) throws IOException
30 | {
31 | this.cm = cm;
32 | cn = cm.openDirectTCPIPChannel(host_to_connect, port_to_connect,
33 | InetAddress.getLocalHost().getHostAddress(), 0);
34 | }
35 |
36 | /**
37 | * @return An InputStream
object.
38 | * @throws IOException
39 | */
40 | public InputStream getInputStream() throws IOException
41 | {
42 | return cn.getStdoutStream();
43 | }
44 |
45 | /**
46 | * Get the OutputStream. Please be aware that the implementation MAY use an
47 | * internal buffer. To make sure that the buffered data is sent over the
48 | * tunnel, you have to call the flush
method of the
49 | * OutputStream
. To signal EOF, please use the
50 | * close
method of the OutputStream
.
51 | *
52 | * @return An OutputStream
object.
53 | * @throws IOException
54 | */
55 | public OutputStream getOutputStream() throws IOException
56 | {
57 | return cn.getStdinStream();
58 | }
59 |
60 | /**
61 | * Close the underlying SSH forwarding channel and free up resources.
62 | * You can also use this method to force the shutdown of the underlying
63 | * forwarding channel. Pending output (OutputStream not flushed) will NOT
64 | * be sent. Pending input (InputStream) can still be read. If the shutdown
65 | * operation is already in progress (initiated from either side), then this
66 | * call is a no-op.
67 | *
68 | * @throws IOException
69 | */
70 | public void close() throws IOException
71 | {
72 | cm.closeChannel(cn, "Closed due to user request.", true);
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ethz/ssh2/PacketListener.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2011 David Kocher. All rights reserved.
3 | * Please refer to the LICENSE.txt for licensing details.
4 | */
5 | package ch.ethz.ssh2;
6 |
7 | /**
8 | * @version $Id:$
9 | */
10 | public interface PacketListener {
11 | void read(String packet);
12 |
13 | void write(String packet);
14 | }
15 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ethz/ssh2/ProxyData.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2006-2011 Christian Plattner. All rights reserved.
3 | * Please refer to the LICENSE.txt for licensing details.
4 | */
5 | package ch.ethz.ssh2;
6 |
7 | /**
8 | * An abstract marker interface implemented by all proxy data implementations.
9 | *
10 | * @see HTTPProxyData
11 | *
12 | * @author Christian Plattner
13 | * @version 2.50, 03/15/10
14 | */
15 |
16 | public abstract interface ProxyData
17 | {
18 | }
19 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ethz/ssh2/SCPInputStream.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2011 David Kocher. All rights reserved.
3 | * Please refer to the LICENSE.txt for licensing details.
4 | */
5 | package ch.ethz.ssh2;
6 |
7 | import java.io.BufferedInputStream;
8 | import java.io.BufferedOutputStream;
9 | import java.io.IOException;
10 | import java.io.OutputStream;
11 |
12 | /**
13 | * @version $Id:$
14 | */
15 | public class SCPInputStream extends BufferedInputStream
16 | {
17 | private Session session;
18 |
19 | /**
20 | * Bytes remaining to be read from the stream
21 | */
22 | private long remaining;
23 |
24 | public SCPInputStream(SCPClient client, Session session) throws IOException
25 | {
26 | super(session.getStdout());
27 |
28 | this.session = session;
29 |
30 | OutputStream os = new BufferedOutputStream(session.getStdin(), 512);
31 |
32 | os.write(0x0);
33 | os.flush();
34 |
35 | final SCPClient.LenNamePair lnp;
36 |
37 | while (true)
38 | {
39 | int c = session.getStdout().read();
40 | if (c < 0)
41 | {
42 | throw new IOException("Remote scp terminated unexpectedly.");
43 | }
44 |
45 | String line = client.receiveLine(session.getStdout());
46 |
47 | if (c == 'T')
48 | {
49 | /* Ignore modification times */
50 | continue;
51 | }
52 |
53 | if ((c == 1) || (c == 2))
54 | {
55 | throw new IOException("Remote SCP error: " + line);
56 | }
57 |
58 | if (c == 'C')
59 | {
60 | lnp = client.parseCLine(line);
61 | break;
62 |
63 | }
64 | throw new IOException("Remote SCP error: " + ((char) c) + line);
65 | }
66 |
67 | os.write(0x0);
68 | os.flush();
69 |
70 | this.remaining = lnp.length;
71 | }
72 |
73 | @Override
74 | public int read() throws IOException
75 | {
76 | if (!(remaining > 0))
77 | {
78 | return -1;
79 | }
80 |
81 | int read = super.read();
82 | if (read < 0)
83 | {
84 | throw new IOException("Remote scp terminated connection unexpectedly");
85 | }
86 |
87 | remaining -= read;
88 |
89 | return read;
90 | }
91 |
92 | @Override
93 | public int read(byte b[], int off, int len) throws IOException
94 | {
95 | if (!(remaining > 0))
96 | {
97 | return -1;
98 | }
99 |
100 | int trans = (int) remaining;
101 | if (remaining > len)
102 | {
103 | trans = len;
104 | }
105 |
106 | int read = super.read(b, off, trans);
107 | if (read < 0)
108 | {
109 | throw new IOException("Remote scp terminated connection unexpectedly");
110 | }
111 |
112 | remaining -= read;
113 |
114 | return read;
115 | }
116 |
117 | @Override
118 | public void close() throws IOException
119 | {
120 | try
121 | {
122 | session.getStdin().write(0x0);
123 | session.getStdin().flush();
124 | }
125 | finally
126 | {
127 | if (session != null)
128 | {
129 | session.close();
130 | }
131 | }
132 | }
133 | }
134 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ethz/ssh2/SCPOutputStream.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2011 David Kocher. All rights reserved.
3 | * Please refer to the LICENSE.txt for licensing details.
4 | */
5 | package ch.ethz.ssh2;
6 |
7 | import java.io.BufferedInputStream;
8 | import java.io.BufferedOutputStream;
9 | import java.io.IOException;
10 | import java.io.InputStream;
11 |
12 | import ch.ethz.ssh2.util.StringEncoder;
13 |
14 | /**
15 | * @version $Id:$
16 | */
17 | public class SCPOutputStream extends BufferedOutputStream
18 | {
19 |
20 | private Session session;
21 |
22 | private SCPClient scp;
23 |
24 | public SCPOutputStream(SCPClient client, Session session, final String remoteFile, long length, String mode) throws IOException
25 | {
26 | super(session.getStdin(), 40000);
27 | this.session = session;
28 | this.scp = client;
29 |
30 | InputStream is = new BufferedInputStream(session.getStdout(), 512);
31 |
32 | scp.readResponse(is);
33 |
34 | String cline = "C" + mode + " " + length + " " + remoteFile + "\n";
35 |
36 | super.write(StringEncoder.GetBytes(cline));
37 | this.flush();
38 |
39 | scp.readResponse(is);
40 | }
41 |
42 | @Override
43 | public void close() throws IOException
44 | {
45 | try
46 | {
47 | this.write(0);
48 | this.flush();
49 |
50 | scp.readResponse(session.getStdout());
51 |
52 | this.write(StringEncoder.GetBytes("E\n"));
53 | this.flush();
54 | }
55 | finally
56 | {
57 | if (session != null)
58 | session.close();
59 | }
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ethz/ssh2/SFTPException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2006-2011 Christian Plattner. All rights reserved.
3 | * Please see the LICENSE.txt for licensing details.
4 | */
5 | package ch.ethz.ssh2;
6 |
7 | import java.io.IOException;
8 |
9 | import ch.ethz.ssh2.sftp.ErrorCodes;
10 |
11 | /**
12 | * Used in combination with the SFTPv3Client. This exception wraps
13 | * error messages sent by the SFTP server.
14 | *
15 | * @author Christian Plattner
16 | * @version 2.50, 03/15/10
17 | */
18 |
19 | public class SFTPException extends IOException
20 | {
21 | private static final long serialVersionUID = 578654644222421811L;
22 |
23 | private final String sftpErrorMessage;
24 | private final int sftpErrorCode;
25 |
26 | private static String constructMessage(String s, int errorCode)
27 | {
28 | String[] detail = ErrorCodes.getDescription(errorCode);
29 |
30 | if (detail == null)
31 | return s + " (UNKNOWN SFTP ERROR CODE)";
32 |
33 | return s + " (" + detail[0] + ": " + detail[1] + ")";
34 | }
35 |
36 | SFTPException(String msg, int errorCode)
37 | {
38 | super(constructMessage(msg, errorCode));
39 | sftpErrorMessage = msg;
40 | sftpErrorCode = errorCode;
41 | }
42 |
43 | /**
44 | * Get the error message sent by the server. Often, this
45 | * message does not help a lot (e.g., "failure").
46 | *
47 | * @return the plain string as sent by the server.
48 | */
49 | public String getServerErrorMessage()
50 | {
51 | return sftpErrorMessage;
52 | }
53 |
54 | /**
55 | * Get the error code sent by the server.
56 | *
57 | * @return an error code as defined in the SFTP specs.
58 | */
59 | public int getServerErrorCode()
60 | {
61 | return sftpErrorCode;
62 | }
63 |
64 | /**
65 | * Get the symbolic name of the error code as given in the SFTP specs.
66 | *
67 | * @return e.g., "SSH_FX_INVALID_FILENAME".
68 | */
69 | public String getServerErrorCodeSymbol()
70 | {
71 | String[] detail = ErrorCodes.getDescription(sftpErrorCode);
72 |
73 | if (detail == null)
74 | return "UNKNOWN SFTP ERROR CODE " + sftpErrorCode;
75 |
76 | return detail[0];
77 | }
78 |
79 | /**
80 | * Get the description of the error code as given in the SFTP specs.
81 | *
82 | * @return e.g., "The filename is not valid."
83 | */
84 | public String getServerErrorCodeVerbose()
85 | {
86 | String[] detail = ErrorCodes.getDescription(sftpErrorCode);
87 |
88 | if (detail == null)
89 | return "The error code " + sftpErrorCode + " is unknown.";
90 |
91 | return detail[1];
92 | }
93 | }
94 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ethz/ssh2/SFTPInputStream.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2011 David Kocher. All rights reserved.
3 | * Please refer to the LICENSE.txt for licensing details.
4 | */
5 | package ch.ethz.ssh2;
6 |
7 | import java.io.IOException;
8 | import java.io.InputStream;
9 |
10 | /**
11 | * @version $Id:$
12 | */
13 | public class SFTPInputStream extends InputStream
14 | {
15 |
16 | private SFTPv3FileHandle handle;
17 |
18 | /**
19 | * Offset (in bytes) in the file to read
20 | */
21 | private long readOffset = 0;
22 |
23 | public SFTPInputStream(SFTPv3FileHandle handle) {
24 | this.handle = handle;
25 | }
26 |
27 | /**
28 | * Reads up to len
bytes of data from the input stream into
29 | * an array of bytes. An attempt is made to read as many as
30 | * len
bytes, but a smaller number may be read, possibly
31 | * zero. The number of bytes actually read is returned as an integer.
32 | *
33 | * @see SFTPv3Client#read(SFTPv3FileHandle,long,byte[],int,int)
34 | */
35 | @Override
36 | public int read(byte[] buffer, int offset, int len) throws IOException
37 | {
38 | int read = handle.getClient().read(handle, readOffset, buffer, offset, len);
39 | if(read > 0) {
40 | readOffset += read;
41 | }
42 | return read;
43 | }
44 |
45 | /**
46 | * Reads the next byte of data from the input stream. The value byte is
47 | * returned as an int
in the range 0
to
48 | * 255
. If no byte is available because the end of the stream
49 | * has been reached, the value -1
is returned. This method
50 | * blocks until input data is available, the end of the stream is detected,
51 | * or an exception is thrown.
52 | *
A subclass must provide an implementation of this method.
54 | *
55 | * @return the next byte of data, or -1
if the end of the
56 | * stream is reached.
57 | * @throws IOException if an I/O error occurs.
58 | */
59 | @Override
60 | public int read() throws IOException {
61 | byte[] buffer = new byte[1];
62 | int read = handle.getClient().read(handle, readOffset, buffer, 0, 1);
63 | if(read > 0) {
64 | readOffset += read;
65 | }
66 | return read;
67 | }
68 |
69 | /**
70 | * Skips over and discards n
bytes of data from this input
71 | * stream.
72 | *
73 | * @param n the number of bytes to be skipped.
74 | * @return the actual number of bytes skipped.
75 | */
76 | @Override
77 | public long skip(long n) {
78 | readOffset += n;
79 | return n;
80 | }
81 |
82 | @Override
83 | public void close() throws IOException {
84 | handle.getClient().closeFile(handle);
85 | }
86 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/ethz/ssh2/SFTPOutputStream.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2011 David Kocher. All rights reserved.
3 | * Please refer to the LICENSE.txt for licensing details.
4 | */
5 | package ch.ethz.ssh2;
6 |
7 | import java.io.IOException;
8 | import java.io.OutputStream;
9 |
10 | /**
11 | * @version $Id:$
12 | */
13 | public class SFTPOutputStream extends OutputStream
14 | {
15 |
16 | private SFTPv3FileHandle handle;
17 |
18 | /**
19 | * Offset (in bytes) in the file to write
20 | */
21 | private long writeOffset = 0;
22 |
23 | public SFTPOutputStream(SFTPv3FileHandle handle) {
24 | this.handle = handle;
25 | }
26 |
27 | /**
28 | * Writes len
bytes from the specified byte array
29 | * starting at offset off
to this output stream.
30 | * The general contract for write(b, off, len)
is that
31 | * some of the bytes in the array b
are written to the
32 | * output stream in order; element b[off]
is the first
33 | * byte written and b[off+len-1]
is the last byte written
34 | * by this operation.
35 | *
36 | * @see SFTPv3Client#write(SFTPv3FileHandle,long,byte[],int,int)
37 | */
38 | @Override
39 | public void write(byte[] buffer, int offset, int len) throws IOException
40 | {
41 | // We can just blindly write the whole buffer at once.
42 | // if len
> 32768, then the write operation will
43 | // be split into multiple writes in SFTPv3Client#write.
44 | handle.getClient().write(handle, writeOffset, buffer, offset, len);
45 |
46 | writeOffset += len;
47 | }
48 |
49 | @Override
50 | public void write(int b) throws IOException {
51 | byte[] buffer = new byte[1];
52 | buffer[0] = (byte) b;
53 | handle.getClient().write(handle, writeOffset, buffer, 0, 1);
54 |
55 | writeOffset += 1;
56 | }
57 |
58 | public long skip(long n) {
59 | writeOffset += n;
60 | return n;
61 | }
62 |
63 | @Override
64 | public void close() throws IOException {
65 | handle.getClient().closeFile(handle);
66 | }
67 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/ethz/ssh2/SFTPv3DirectoryEntry.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2006-2011 Christian Plattner. All rights reserved.
3 | * Please refer to the LICENSE.txt for licensing details.
4 | */
5 | package ch.ethz.ssh2;
6 |
7 | /**
8 | * A SFTPv3DirectoryEntry
as returned by {@link SFTPv3Client#ls(String)}.
9 | *
10 | * @author Christian Plattner
11 | * @version 2.50, 03/15/10
12 | */
13 |
14 | public class SFTPv3DirectoryEntry
15 | {
16 | /**
17 | * A relative name within the directory, without any path components.
18 | */
19 | public String filename;
20 |
21 | /**
22 | * An expanded format for the file name, similar to what is returned by
23 | * "ls -l" on Un*x systems.
24 | *
25 | * The format of this field is unspecified by the SFTP v3 protocol. 26 | * It MUST be suitable for use in the output of a directory listing 27 | * command (in fact, the recommended operation for a directory listing 28 | * command is to simply display this data). However, clients SHOULD NOT 29 | * attempt to parse the longname field for file attributes; they SHOULD 30 | * use the attrs field instead. 31 | *
32 | * The recommended format for the longname field is as follows:
33 | * -rwxr-xr-x 1 mjos staff 348911 Mar 25 14:29 t-filexfer
34 | */
35 | public String longEntry;
36 |
37 | /**
38 | * The attributes of this entry.
39 | */
40 | public SFTPv3FileAttributes attributes;
41 | }
42 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ethz/ssh2/SFTPv3FileHandle.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2006-2011 Christian Plattner. All rights reserved.
3 | * Please refer to the LICENSE.txt for licensing details.
4 | */
5 | package ch.ethz.ssh2;
6 |
7 | /**
8 | * A SFTPv3FileHandle
.
9 | *
10 | * @author Christian Plattner
11 | * @version 2.50, 03/15/10
12 | */
13 |
14 | public class SFTPv3FileHandle
15 | {
16 | protected final SFTPv3Client client;
17 | protected final byte[] fileHandle;
18 | protected boolean isClosed;
19 |
20 | protected SFTPv3FileHandle(SFTPv3Client client, byte[] h)
21 | {
22 | this.client = client;
23 | this.fileHandle = h;
24 | }
25 |
26 | /**
27 | * Get the SFTPv3Client instance which created this handle.
28 | *
29 | * @return A SFTPv3Client instance.
30 | */
31 | public SFTPv3Client getClient()
32 | {
33 | return client;
34 | }
35 |
36 | /**
37 | * Check if this handle was closed with the {@link SFTPv3Client#closeFile(SFTPv3FileHandle)} method
38 | * of the SFTPv3Client
instance which created the handle.
39 | *
40 | * @return if the handle is closed.
41 | */
42 | public boolean isClosed()
43 | {
44 | return isClosed;
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ethz/ssh2/ServerHostKeyVerifier.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2006-2011 Christian Plattner. All rights reserved.
3 | * Please refer to the LICENSE.txt for licensing details.
4 | */
5 | package ch.ethz.ssh2;
6 |
7 | /**
8 | * A callback interface used to implement a client specific method of checking
9 | * server host keys.
10 | *
11 | * @author Christian Plattner
12 | * @version 2.50, 03/15/10
13 | */
14 |
15 | public interface ServerHostKeyVerifier
16 | {
17 | /**
18 | * The actual verifier method, it will be called by the key exchange code
19 | * on EVERY key exchange - this can happen several times during the lifetime
20 | * of a connection.
21 | *
22 | * Note: SSH-2 servers are allowed to change their hostkey at ANY time.
23 | *
24 | * @param hostname the hostname used to create the {@link Connection} object
25 | * @param port the remote TCP port
26 | * @param serverHostKeyAlgorithm the public key algorithm (
11 | * "The 'permissions' field contains a bit mask specifying file permissions.
12 | * These permissions correspond to the st_mode field of the stat structure
13 | * defined by POSIX [IEEE.1003-1.1996]."
14 | *
15 | * @author Christian Plattner
16 | * @version 2.50, 03/15/10
17 | *
18 | */
19 | public class AttribPermissions
20 | {
21 | /* Octal values! */
22 |
23 | public static final int S_IRUSR = 0400;
24 | public static final int S_IWUSR = 0200;
25 | public static final int S_IXUSR = 0100;
26 | public static final int S_IRGRP = 0040;
27 | public static final int S_IWGRP = 0020;
28 | public static final int S_IXGRP = 0010;
29 | public static final int S_IROTH = 0004;
30 | public static final int S_IWOTH = 0002;
31 | public static final int S_IXOTH = 0001;
32 | public static final int S_ISUID = 04000;
33 | public static final int S_ISGID = 02000;
34 | public static final int S_ISVTX = 01000;
35 | }
36 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ethz/ssh2/sftp/AttribTypes.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2006-2011 Christian Plattner. All rights reserved.
3 | * Please refer to the LICENSE.txt for licensing details.
4 | */
5 | package ch.ethz.ssh2.sftp;
6 |
7 | /**
8 | *
9 | * Types for the 'type' field in the SFTP ATTRS data type.
10 | *
11 | * "On a POSIX system, these values would be derived from the mode field
12 | * of the stat structure. SPECIAL should be used for files that are of
13 | * a known type which cannot be expressed in the protocol. UNKNOWN
14 | * should be used if the type is not known."
15 | *
16 | * @author Christian Plattner
17 | * @version 2.50, 03/15/10
18 | *
19 | */
20 | public class AttribTypes
21 | {
22 | public static final int SSH_FILEXFER_TYPE_REGULAR = 1;
23 | public static final int SSH_FILEXFER_TYPE_DIRECTORY = 2;
24 | public static final int SSH_FILEXFER_TYPE_SYMLINK = 3;
25 | public static final int SSH_FILEXFER_TYPE_SPECIAL = 4;
26 | public static final int SSH_FILEXFER_TYPE_UNKNOWN = 5;
27 | public static final int SSH_FILEXFER_TYPE_SOCKET = 6;
28 | public static final int SSH_FILEXFER_TYPE_CHAR_DEVICE = 7;
29 | public static final int SSH_FILEXFER_TYPE_BLOCK_DEVICE = 8;
30 | public static final int SSH_FILEXFER_TYPE_FIFO = 9;
31 | }
32 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ethz/ssh2/sftp/Packet.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2006-2011 Christian Plattner. All rights reserved.
3 | * Please refer to the LICENSE.txt for licensing details.
4 | */
5 | package ch.ethz.ssh2.sftp;
6 |
7 | /**
8 | *
9 | * SFTP Paket Types
10 | *
11 | * @author Christian Plattner
12 | * @version 2.50, 03/15/10
13 | *
14 | */
15 | public class Packet
16 | {
17 | public static final int SSH_FXP_INIT = 1;
18 | public static final int SSH_FXP_VERSION = 2;
19 | public static final int SSH_FXP_OPEN = 3;
20 | public static final int SSH_FXP_CLOSE = 4;
21 | public static final int SSH_FXP_READ = 5;
22 | public static final int SSH_FXP_WRITE = 6;
23 | public static final int SSH_FXP_LSTAT = 7;
24 | public static final int SSH_FXP_FSTAT = 8;
25 | public static final int SSH_FXP_SETSTAT = 9;
26 | public static final int SSH_FXP_FSETSTAT = 10;
27 | public static final int SSH_FXP_OPENDIR = 11;
28 | public static final int SSH_FXP_READDIR = 12;
29 | public static final int SSH_FXP_REMOVE = 13;
30 | public static final int SSH_FXP_MKDIR = 14;
31 | public static final int SSH_FXP_RMDIR = 15;
32 | public static final int SSH_FXP_REALPATH = 16;
33 | public static final int SSH_FXP_STAT = 17;
34 | public static final int SSH_FXP_RENAME = 18;
35 | public static final int SSH_FXP_READLINK = 19;
36 | public static final int SSH_FXP_SYMLINK = 20;
37 |
38 | public static final int SSH_FXP_STATUS = 101;
39 | public static final int SSH_FXP_HANDLE = 102;
40 | public static final int SSH_FXP_DATA = 103;
41 | public static final int SSH_FXP_NAME = 104;
42 | public static final int SSH_FXP_ATTRS = 105;
43 |
44 | public static final int SSH_FXP_EXTENDED = 200;
45 | public static final int SSH_FXP_EXTENDED_REPLY = 201;
46 |
47 | public static String forName(int type) {
48 | switch(type) {
49 | case SSH_FXP_INIT:
50 | return "SSH_FXP_INIT";
51 | case SSH_FXP_VERSION:
52 | return "SSH_FXP_VERSION";
53 | case SSH_FXP_OPEN:
54 | return "SSH_FXP_OPEN";
55 | case SSH_FXP_CLOSE:
56 | return "SSH_FXP_CLOSE";
57 | case SSH_FXP_READ:
58 | return "SSH_FXP_READ";
59 | case SSH_FXP_WRITE:
60 | return "SSH_FXP_WRITE";
61 | case SSH_FXP_LSTAT:
62 | return "SSH_FXP_LSTAT";
63 | case SSH_FXP_FSTAT:
64 | return "SSH_FXP_FSTAT";
65 | case SSH_FXP_SETSTAT:
66 | return "SSH_FXP_SETSTAT";
67 | case SSH_FXP_FSETSTAT:
68 | return "SSH_FXP_FSETSTAT";
69 | case SSH_FXP_OPENDIR:
70 | return "SSH_FXP_OPENDIR";
71 | case SSH_FXP_READDIR:
72 | return "SSH_FXP_READDIR";
73 | case SSH_FXP_REMOVE:
74 | return "SSH_FXP_REMOVE";
75 | case SSH_FXP_MKDIR:
76 | return "SSH_FXP_MKDIR";
77 | case SSH_FXP_RMDIR:
78 | return "SSH_FXP_RMDIR";
79 | case SSH_FXP_REALPATH:
80 | return "SSH_FXP_REALPATH";
81 | case SSH_FXP_STAT:
82 | return "SSH_FXP_STAT";
83 | case SSH_FXP_RENAME:
84 | return "SSH_FXP_RENAME";
85 | case SSH_FXP_READLINK:
86 | return "SSH_FXP_READLINK";
87 | case SSH_FXP_SYMLINK:
88 | return "SSH_FXP_SYMLINK";
89 | case SSH_FXP_STATUS:
90 | return "SSH_FXP_STATUS";
91 | case SSH_FXP_HANDLE:
92 | return "SSH_FXP_HANDLE";
93 | case SSH_FXP_DATA:
94 | return "SSH_FXP_DATA";
95 | case SSH_FXP_NAME:
96 | return "SSH_FXP_NAME";
97 | case SSH_FXP_ATTRS:
98 | return "SSH_FXP_ATTRS";
99 | case SSH_FXP_EXTENDED:
100 | return "SSH_FXP_EXTENDED";
101 | case SSH_FXP_EXTENDED_REPLY:
102 | return "SSH_FXP_EXTENDED_REPLY";
103 | }
104 | return null;
105 | }
106 | }
107 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ethz/ssh2/signature/DSAPrivateKey.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2006-2011 Christian Plattner. All rights reserved.
3 | * Please refer to the LICENSE.txt for licensing details.
4 | */
5 | package ch.ethz.ssh2.signature;
6 |
7 | import java.math.BigInteger;
8 |
9 | /**
10 | * DSAPrivateKey.
11 | *
12 | * @author Christian Plattner
13 | * @version 2.50, 03/15/10
14 | */
15 | public class DSAPrivateKey
16 | {
17 | private BigInteger p;
18 | private BigInteger q;
19 | private BigInteger g;
20 | private BigInteger x;
21 | private BigInteger y;
22 |
23 | public DSAPrivateKey(BigInteger p, BigInteger q, BigInteger g,
24 | BigInteger y, BigInteger x)
25 | {
26 | this.p = p;
27 | this.q = q;
28 | this.g = g;
29 | this.y = y;
30 | this.x = x;
31 | }
32 |
33 | public BigInteger getP()
34 | {
35 | return p;
36 | }
37 |
38 | public BigInteger getQ()
39 | {
40 | return q;
41 | }
42 |
43 | public BigInteger getG()
44 | {
45 | return g;
46 | }
47 |
48 | public BigInteger getY()
49 | {
50 | return y;
51 | }
52 |
53 | public BigInteger getX()
54 | {
55 | return x;
56 | }
57 |
58 | public DSAPublicKey getPublicKey()
59 | {
60 | return new DSAPublicKey(p, q, g, y);
61 | }
62 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/ethz/ssh2/signature/DSAPublicKey.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2006-2011 Christian Plattner. All rights reserved.
3 | * Please refer to the LICENSE.txt for licensing details.
4 | */
5 | package ch.ethz.ssh2.signature;
6 |
7 | import java.math.BigInteger;
8 |
9 | /**
10 | * DSAPublicKey.
11 | *
12 | * @author Christian Plattner
13 | * @version 2.50, 03/15/10
14 | */
15 | public class DSAPublicKey
16 | {
17 | private BigInteger p;
18 | private BigInteger q;
19 | private BigInteger g;
20 | private BigInteger y;
21 |
22 | public DSAPublicKey(BigInteger p, BigInteger q, BigInteger g, BigInteger y)
23 | {
24 | this.p = p;
25 | this.q = q;
26 | this.g = g;
27 | this.y = y;
28 | }
29 |
30 | public BigInteger getP()
31 | {
32 | return p;
33 | }
34 |
35 | public BigInteger getQ()
36 | {
37 | return q;
38 | }
39 |
40 | public BigInteger getG()
41 | {
42 | return g;
43 | }
44 |
45 | public BigInteger getY()
46 | {
47 | return y;
48 | }
49 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/ethz/ssh2/signature/DSASignature.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2006-2011 Christian Plattner. All rights reserved.
3 | * Please refer to the LICENSE.txt for licensing details.
4 | */
5 | package ch.ethz.ssh2.signature;
6 |
7 | import java.math.BigInteger;
8 |
9 | /**
10 | * DSASignature.
11 | *
12 | * @author Christian Plattner
13 | * @version 2.50, 03/15/10
14 | */
15 | public class DSASignature
16 | {
17 | private BigInteger r;
18 | private BigInteger s;
19 |
20 | public DSASignature(BigInteger r, BigInteger s)
21 | {
22 | this.r = r;
23 | this.s = s;
24 | }
25 |
26 | public BigInteger getR()
27 | {
28 | return r;
29 | }
30 |
31 | public BigInteger getS()
32 | {
33 | return s;
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ethz/ssh2/signature/RSAPrivateKey.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2006-2011 Christian Plattner. All rights reserved.
3 | * Please refer to the LICENSE.txt for licensing details.
4 | */
5 | package ch.ethz.ssh2.signature;
6 |
7 | import java.math.BigInteger;
8 |
9 | /**
10 | * RSAPrivateKey.
11 | *
12 | * @author Christian Plattner
13 | * @version 2.50, 03/15/10
14 | */
15 | public class RSAPrivateKey
16 | {
17 | private BigInteger d;
18 | private BigInteger e;
19 | private BigInteger n;
20 |
21 | public RSAPrivateKey(BigInteger d, BigInteger e, BigInteger n)
22 | {
23 | this.d = d;
24 | this.e = e;
25 | this.n = n;
26 | }
27 |
28 | public BigInteger getD()
29 | {
30 | return d;
31 | }
32 |
33 | public BigInteger getE()
34 | {
35 | return e;
36 | }
37 |
38 | public BigInteger getN()
39 | {
40 | return n;
41 | }
42 |
43 | public RSAPublicKey getPublicKey()
44 | {
45 | return new RSAPublicKey(e, n);
46 | }
47 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/ethz/ssh2/signature/RSAPublicKey.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2006-2011 Christian Plattner. All rights reserved.
3 | * Please refer to the LICENSE.txt for licensing details.
4 | */
5 | package ch.ethz.ssh2.signature;
6 |
7 | import java.math.BigInteger;
8 |
9 | /**
10 | * RSAPublicKey.
11 | *
12 | * @author Christian Plattner
13 | * @version 2.50, 03/15/10
14 | */
15 | public class RSAPublicKey
16 | {
17 | BigInteger e;
18 | BigInteger n;
19 |
20 | public RSAPublicKey(BigInteger e, BigInteger n)
21 | {
22 | this.e = e;
23 | this.n = n;
24 | }
25 |
26 | public BigInteger getE()
27 | {
28 | return e;
29 | }
30 |
31 | public BigInteger getN()
32 | {
33 | return n;
34 | }
35 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/ethz/ssh2/signature/RSASignature.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2006-2011 Christian Plattner. All rights reserved.
3 | * Please refer to the LICENSE.txt for licensing details.
4 | */
5 | package ch.ethz.ssh2.signature;
6 |
7 | import java.math.BigInteger;
8 |
9 |
10 | /**
11 | * RSASignature.
12 | *
13 | * @author Christian Plattner
14 | * @version 2.50, 03/15/10
15 | */
16 |
17 | public class RSASignature
18 | {
19 | BigInteger s;
20 |
21 | public BigInteger getS()
22 | {
23 | return s;
24 | }
25 |
26 | public RSASignature(BigInteger s)
27 | {
28 | this.s = s;
29 | }
30 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/ethz/ssh2/transport/ClientServerHello.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2006-2011 Christian Plattner. All rights reserved.
3 | * Please refer to the LICENSE.txt for licensing details.
4 | */
5 | package ch.ethz.ssh2.transport;
6 |
7 | import java.io.IOException;
8 | import java.io.InputStream;
9 | import java.io.OutputStream;
10 |
11 | import ch.ethz.ssh2.util.StringEncoder;
12 |
13 | /**
14 | * ClientServerHello.
15 | *
16 | * @author Christian Plattner
17 | * @version $Id$
18 | */
19 | public class ClientServerHello
20 | {
21 | String server_line;
22 | String client_line;
23 |
24 | String server_versioncomment;
25 |
26 | public static int readLineRN(InputStream is, byte[] buffer) throws IOException
27 | {
28 | int pos = 0;
29 | boolean need10 = false;
30 | int len = 0;
31 | while (true)
32 | {
33 | int c = is.read();
34 | if (c == -1)
35 | throw new IOException("Premature connection close");
36 |
37 | buffer[pos++] = (byte) c;
38 |
39 | if (c == 13)
40 | {
41 | need10 = true;
42 | continue;
43 | }
44 |
45 | if (c == 10)
46 | break;
47 |
48 | if (need10 == true)
49 | throw new IOException("Malformed line sent by the server, the line does not end correctly.");
50 |
51 | len++;
52 | if (pos >= buffer.length)
53 | throw new IOException("The server sent a too long line.");
54 | }
55 |
56 | return len;
57 | }
58 |
59 | public ClientServerHello(String identification, InputStream bi, OutputStream bo) throws IOException
60 | {
61 | client_line = "SSH-2.0-" + identification;
62 |
63 | bo.write(StringEncoder.GetBytes(client_line + "\r\n"));
64 | bo.flush();
65 |
66 | //In some cases connection to server fails, because server line is too long
67 | byte[] serverVersion = new byte[1024];
68 |
69 | for (int i = 0; i < 50; i++)
70 | {
71 | int len = readLineRN(bi, serverVersion);
72 |
73 | server_line = StringEncoder.GetString(serverVersion, 0, len);
74 |
75 | if (server_line.startsWith("SSH-"))
76 | break;
77 | }
78 |
79 | if (server_line.startsWith("SSH-") == false)
80 | throw new IOException(
81 | "Malformed server identification string. There was no line starting with 'SSH-' amongst the first 50 lines.");
82 |
83 | if (server_line.startsWith("SSH-1.99-"))
84 | server_versioncomment = server_line.substring(9);
85 | else if (server_line.startsWith("SSH-2.0-"))
86 | server_versioncomment = server_line.substring(8);
87 | else
88 | throw new IOException("Server uses incompatible protocol, it is not SSH-2 compatible.");
89 | }
90 |
91 | /**
92 | * @return Returns the client_versioncomment.
93 | */
94 | public byte[] getClientString()
95 | {
96 | return StringEncoder.GetBytes(client_line);
97 | }
98 |
99 | /**
100 | * @return Returns the server_versioncomment.
101 | */
102 | public byte[] getServerString()
103 | {
104 | return StringEncoder.GetBytes(server_line);
105 | }
106 | }
107 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ethz/ssh2/transport/KexParameters.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2006-2011 Christian Plattner. All rights reserved.
3 | * Please refer to the LICENSE.txt for licensing details.
4 | */
5 | package ch.ethz.ssh2.transport;
6 |
7 | /**
8 | * KexParameters.
9 | *
10 | * @author Christian Plattner
11 | * @version 2.50, 03/15/10
12 | */
13 | public class KexParameters
14 | {
15 | public byte[] cookie;
16 | public String[] kex_algorithms;
17 | public String[] server_host_key_algorithms;
18 | public String[] encryption_algorithms_client_to_server;
19 | public String[] encryption_algorithms_server_to_client;
20 | public String[] mac_algorithms_client_to_server;
21 | public String[] mac_algorithms_server_to_client;
22 | public String[] compression_algorithms_client_to_server;
23 | public String[] compression_algorithms_server_to_client;
24 | public String[] languages_client_to_server;
25 | public String[] languages_server_to_client;
26 | public boolean first_kex_packet_follows;
27 | public int reserved_field1;
28 | }
29 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ethz/ssh2/transport/KexState.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2006-2011 Christian Plattner. All rights reserved.
3 | * Please refer to the LICENSE.txt for licensing details.
4 | */
5 | package ch.ethz.ssh2.transport;
6 |
7 | import ch.ethz.ssh2.DHGexParameters;
8 | import ch.ethz.ssh2.crypto.dh.DhExchange;
9 | import ch.ethz.ssh2.crypto.dh.DhGroupExchange;
10 | import java.math.BigInteger;
11 | import ch.ethz.ssh2.packets.PacketKexInit;
12 |
13 | /**
14 | * KexState.
15 | *
16 | * @author Christian Plattner
17 | * @version 2.50, 03/15/10
18 | */
19 | public class KexState
20 | {
21 | public PacketKexInit localKEX;
22 | public PacketKexInit remoteKEX;
23 | public NegotiatedParameters np;
24 | public int state = 0;
25 |
26 | public BigInteger K;
27 | public byte[] H;
28 |
29 | public byte[] hostkey;
30 |
31 | public DhExchange dhx;
32 | public DhGroupExchange dhgx;
33 | public DHGexParameters dhgexParameters;
34 | }
35 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ethz/ssh2/transport/MessageHandler.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2006-2011 Christian Plattner. All rights reserved.
3 | * Please refer to the LICENSE.txt for licensing details.
4 | */
5 | package ch.ethz.ssh2.transport;
6 |
7 | import java.io.IOException;
8 |
9 | /**
10 | * MessageHandler.
11 | *
12 | * @author Christian Plattner
13 | * @version 2.50, 03/15/10
14 | */
15 | public interface MessageHandler
16 | {
17 | public void handleMessage(byte[] msg, int msglen) throws IOException;
18 | }
19 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ethz/ssh2/transport/NegotiateException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2006-2011 Christian Plattner. All rights reserved.
3 | * Please refer to the LICENSE.txt for licensing details.
4 | */
5 | package ch.ethz.ssh2.transport;
6 |
7 | /**
8 | * NegotiateException.
9 | *
10 | * @author Christian Plattner
11 | * @version 2.50, 03/15/10
12 | */
13 | public class NegotiateException extends Exception
14 | {
15 | private static final long serialVersionUID = 3689910669428143157L;
16 | }
17 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ethz/ssh2/transport/NegotiatedParameters.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2006-2011 Christian Plattner. All rights reserved.
3 | * Please refer to the LICENSE.txt for licensing details.
4 | */
5 | package ch.ethz.ssh2.transport;
6 |
7 | /**
8 | * NegotiatedParameters.
9 | *
10 | * @author Christian Plattner
11 | * @version 2.50, 03/15/10
12 | */
13 | public class NegotiatedParameters
14 | {
15 | public boolean guessOK;
16 | public String kex_algo;
17 | public String server_host_key_algo;
18 | public String enc_algo_client_to_server;
19 | public String enc_algo_server_to_client;
20 | public String mac_algo_client_to_server;
21 | public String mac_algo_server_to_client;
22 | public String comp_algo_client_to_server;
23 | public String comp_algo_server_to_client;
24 | public String lang_client_to_server;
25 | public String lang_server_to_client;
26 | }
27 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ethz/ssh2/util/StringEncoder.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2006-2011 Christian Plattner.
3 | * All rights reserved.
4 | * Please refer to the LICENSE.txt for licensing details.
5 | */
6 | package ch.ethz.ssh2.util;
7 |
8 | import java.io.UnsupportedEncodingException;
9 |
10 | /**
11 | * @author Christian Plattner
12 | * @version $Id$
13 | */
14 | public class StringEncoder
15 | {
16 | public static byte[] GetBytes(String data)
17 | {
18 | try {
19 | return data.getBytes("UTF-8");
20 | }
21 | catch(UnsupportedEncodingException e) {
22 | throw new RuntimeException(e);
23 | }
24 | }
25 |
26 | public static String GetString(byte[] data)
27 | {
28 | return GetString(data, 0, data.length);
29 | }
30 |
31 | public static String GetString(byte[] data, int off, int len)
32 | {
33 | try {
34 | return new String(data, off, len, "UTF-8");
35 | }
36 | catch(UnsupportedEncodingException e) {
37 | throw new RuntimeException(e);
38 | }
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ethz/ssh2/util/Tokenizer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2006-2011 Christian Plattner. All rights reserved.
3 | * Please refer to the LICENSE.txt for licensing details.
4 | */
5 | package ch.ethz.ssh2.util;
6 |
7 | /**
8 | * Tokenizer. Why? Because StringTokenizer is not available in J2ME.
9 | *
10 | * @author Christian Plattner
11 | * @version 2.50, 03/15/10
12 | */
13 | public class Tokenizer
14 | {
15 | /**
16 | * Exists because StringTokenizer is not available in J2ME.
17 | * Returns an array with at least 1 entry.
18 | *
19 | * @param source must be non-null
20 | * @param delimiter
21 | * @return an array of Strings
22 | */
23 | public static String[] parseTokens(String source, char delimiter)
24 | {
25 | int numtoken = 1;
26 |
27 | for (int i = 0; i < source.length(); i++)
28 | {
29 | if (source.charAt(i) == delimiter)
30 | numtoken++;
31 | }
32 |
33 | String list[] = new String[numtoken];
34 | int nextfield = 0;
35 |
36 | for (int i = 0; i < numtoken; i++)
37 | {
38 | if (nextfield >= source.length())
39 | {
40 | list[i] = "";
41 | }
42 | else
43 | {
44 | int idx = source.indexOf(delimiter, nextfield);
45 | if (idx == -1)
46 | idx = source.length();
47 | list[i] = source.substring(nextfield, idx);
48 | nextfield = idx + 1;
49 | }
50 | }
51 |
52 | return list;
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/app/src/main/java/com/smiskol/phantom/CenterSeekBar.java:
--------------------------------------------------------------------------------
1 | package com.smiskol.phantom;
2 |
3 | import android.content.Context;
4 | import android.graphics.Canvas;
5 | import android.graphics.Color;
6 | import android.graphics.Paint;
7 | import android.graphics.Rect;
8 | import android.support.v4.content.ContextCompat;
9 | import android.support.v7.widget.AppCompatSeekBar;
10 | import android.util.AttributeSet;
11 |
12 | public class CenterSeekBar extends AppCompatSeekBar {
13 |
14 | private Rect rect;
15 | private Paint paint;
16 | private int seekbar_height;
17 |
18 | public CenterSeekBar(Context context) {
19 | super(context);
20 |
21 | }
22 |
23 | public CenterSeekBar(Context context, AttributeSet attrs) {
24 |
25 | super(context, attrs);
26 | rect = new Rect();
27 | paint = new Paint();
28 | seekbar_height = 36;
29 |
30 | }
31 |
32 | public CenterSeekBar(Context context, AttributeSet attrs, int defStyle) {
33 | super(context, attrs, defStyle);
34 | }
35 |
36 | @Override
37 | protected synchronized void onDraw(Canvas canvas) {
38 | getThumb().mutate().setAlpha(0);
39 | rect.set(getThumbOffset() + 5,
40 | (getHeight() / 2) - (seekbar_height / 2) + 1,
41 | getWidth() - getThumbOffset() - 5,
42 | (getHeight() / 2) + (seekbar_height / 2));
43 |
44 | paint.setColor(Color.parseColor("#FFFFFF"));
45 | canvas.drawRect(rect, paint);
46 |
47 | if (this.getProgress() > getMax() / 2) {
48 | rect.set(getWidth() / 2,
49 | (getHeight() / 2) - (seekbar_height / 2) + 1,
50 | interp(getProgress(), getMax()/2, getMax(), getWidth()/2, getWidth()-25),
51 | getHeight() / 2 + (seekbar_height / 2));
52 |
53 | paint.setColor(ContextCompat.getColor(getContext(), R.color.colorAccent));
54 | canvas.drawRect(rect, paint);
55 | }
56 |
57 | if (this.getProgress() < getMax() / 2) {
58 | rect.set(interp(getProgress(), getMax()/2, 0, getWidth()/2, 25),
59 | (getHeight() / 2) - (seekbar_height / 2) + 1,
60 | getWidth() / 2,
61 | getHeight() / 2 + (seekbar_height / 2));
62 |
63 | paint.setColor(ContextCompat.getColor(getContext(), R.color.colorAccent));
64 | canvas.drawRect(rect, paint);
65 | }
66 |
67 | super.onDraw(canvas);
68 | }
69 | public Integer interp(int value, int from1, int to1, int from2, int to2) {
70 | return (int) Math.round(((Double.valueOf(value)) - (Double.valueOf(from1))) / ((Double.valueOf(to1)) - (Double.valueOf(from1))) * ((Double.valueOf(to2)) - (Double.valueOf(from2))) + (Double.valueOf(from2)));
71 | }
72 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/smiskol/phantom/ViewPagerAdapter.java:
--------------------------------------------------------------------------------
1 | package com.smiskol.phantom;
2 |
3 | import android.support.annotation.Nullable;
4 | import android.support.v4.app.Fragment;
5 | import android.support.v4.app.FragmentManager;
6 | import android.support.v4.app.FragmentPagerAdapter;
7 |
8 | public class ViewPagerAdapter extends FragmentPagerAdapter {
9 | private int viewCount = 1;
10 |
11 | public void setViewCount(int N) {
12 | viewCount = N;
13 | notifyDataSetChanged();
14 | }
15 |
16 | public ViewPagerAdapter(FragmentManager fm) {
17 | super(fm);
18 | }
19 |
20 | @Override
21 | public Fragment getItem(int position) {
22 | switch (position) {
23 | case 0:
24 | return new WelcomeFragment();
25 | case 1:
26 | return new ControlsFragment();
27 | }
28 | return null;
29 | }
30 |
31 | @Override
32 | public int getCount() {
33 | return viewCount;
34 | }
35 |
36 | @Nullable
37 | @Override
38 | public CharSequence getPageTitle(int position) {
39 | switch (position) {
40 | case 0:
41 | return "Connect";
42 | case 1:
43 | return "Controls";
44 | }
45 |
46 | return null;
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/app/src/main/res/anim/shake.xml:
--------------------------------------------------------------------------------
1 |
2 | ssh-rsa
or ssh-dss
)
27 | * @param serverHostKey the server's public key blob
28 | * @return if the client wants to accept the server's host key - if not, the
29 | * connection will be closed.
30 | * @throws Exception Will be wrapped with an IOException, extended version of returning false =)
31 | */
32 | public boolean verifyServerHostKey(String hostname, int port, String serverHostKeyAlgorithm, byte[] serverHostKey)
33 | throws Exception;
34 | }
35 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ethz/ssh2/Version.java:
--------------------------------------------------------------------------------
1 | package ch.ethz.ssh2;
2 |
3 | /**
4 | * Provides version information from the manifest.
5 | *
6 | * @version $Id:$
7 | */
8 | public class Version
9 | {
10 | public static String getSpecification()
11 | {
12 | Package pkg = Version.class.getPackage();
13 | return (pkg == null) ? null : pkg.getSpecificationVersion();
14 | }
15 |
16 | public static String getImplementation()
17 | {
18 | Package pkg = Version.class.getPackage();
19 | return (pkg == null) ? null : pkg.getImplementationVersion();
20 | }
21 |
22 | /**
23 | * A simple main method that prints the version and exits
24 | */
25 | public static void main(String[] args)
26 | {
27 | System.out.println("Version: " + getSpecification());
28 | System.out.println("Implementation: " + getImplementation());
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ethz/ssh2/channel/ChannelClosedException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2011 David Kocher. All rights reserved.
3 | * Please refer to the LICENSE.txt for licensing details.
4 | */
5 |
6 | package ch.ethz.ssh2.channel;
7 |
8 | import java.io.IOException;
9 |
10 | /**
11 | * @version $Id: ChannelClosedException.java 3183 2007-07-30 19:22:34Z dkocher $
12 | */
13 | public class ChannelClosedException extends IOException
14 | {
15 |
16 | /**
17 | *
18 | */
19 | private static final long serialVersionUID = 1L;
20 |
21 | public ChannelClosedException(String s)
22 | {
23 | super(s);
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ethz/ssh2/channel/ChannelInputStream.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2006-2011 Christian Plattner. All rights reserved.
3 | * Please refer to the LICENSE.txt for licensing details.
4 | */
5 | package ch.ethz.ssh2.channel;
6 |
7 | import java.io.IOException;
8 | import java.io.InputStream;
9 |
10 | /**
11 | * ChannelInputStream.
12 | *
13 | * @author Christian Plattner
14 | * @version 2.50, 03/15/10
15 | */
16 | public final class ChannelInputStream extends InputStream
17 | {
18 | Channel c;
19 |
20 | boolean isClosed = false;
21 | boolean isEOF = false;
22 | boolean extendedFlag = false;
23 |
24 | ChannelInputStream(Channel c, boolean isExtended)
25 | {
26 | this.c = c;
27 | this.extendedFlag = isExtended;
28 | }
29 |
30 | @Override
31 | public int available() throws IOException
32 | {
33 | if (isEOF)
34 | return 0;
35 |
36 | int avail = c.cm.getAvailable(c, extendedFlag);
37 |
38 | /* We must not return -1 on EOF */
39 |
40 | return (avail > 0) ? avail : 0;
41 | }
42 |
43 | @Override
44 | public void close() throws IOException
45 | {
46 | isClosed = true;
47 | }
48 |
49 | @Override
50 | public int read(byte[] b, int off, int len) throws IOException
51 | {
52 | if (b == null)
53 | throw new NullPointerException();
54 |
55 | if ((off < 0) || (len < 0) || ((off + len) > b.length) || ((off + len) < 0) || (off > b.length))
56 | throw new IndexOutOfBoundsException();
57 |
58 | if (len == 0)
59 | return 0;
60 |
61 | if (isEOF)
62 | return -1;
63 |
64 | int ret = c.cm.getChannelData(c, extendedFlag, b, off, len);
65 |
66 | if (ret == -1)
67 | {
68 | isEOF = true;
69 | }
70 |
71 | return ret;
72 | }
73 |
74 | @Override
75 | public int read(byte[] b) throws IOException
76 | {
77 | return read(b, 0, b.length);
78 | }
79 |
80 | @Override
81 | public int read() throws IOException
82 | {
83 | /* Yes, this stream is pure and unbuffered, a single byte read() is slow */
84 |
85 | final byte b[] = new byte[1];
86 |
87 | int ret = read(b, 0, 1);
88 |
89 | if (ret != 1)
90 | return -1;
91 |
92 | return b[0] & 0xff;
93 | }
94 | }
95 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ethz/ssh2/channel/ChannelOutputStream.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2006-2011 Christian Plattner. All rights reserved.
3 | * Please refer to the LICENSE.txt for licensing details.
4 | */
5 | package ch.ethz.ssh2.channel;
6 |
7 | import java.io.IOException;
8 | import java.io.OutputStream;
9 |
10 | /**
11 | * ChannelOutputStream.
12 | *
13 | * @author Christian Plattner
14 | * @version 2.50, 03/15/10
15 | */
16 | public final class ChannelOutputStream extends OutputStream
17 | {
18 | Channel c;
19 |
20 | boolean isClosed = false;
21 |
22 | ChannelOutputStream(Channel c)
23 | {
24 | this.c = c;
25 | }
26 |
27 | @Override
28 | public void write(int b) throws IOException
29 | {
30 | byte[] buff = new byte[1];
31 |
32 | buff[0] = (byte) b;
33 |
34 | write(buff, 0, 1);
35 | }
36 |
37 | @Override
38 | public void close() throws IOException
39 | {
40 | if (isClosed == false)
41 | {
42 | isClosed = true;
43 | c.cm.sendEOF(c);
44 | }
45 | }
46 |
47 | @Override
48 | public void flush() throws IOException
49 | {
50 | if (isClosed)
51 | throw new IOException("This OutputStream is closed.");
52 |
53 | /* This is a no-op, since this stream is unbuffered */
54 | }
55 |
56 | @Override
57 | public void write(byte[] b, int off, int len) throws IOException
58 | {
59 | if (isClosed)
60 | throw new IOException("This OutputStream is closed.");
61 |
62 | if (b == null)
63 | throw new NullPointerException();
64 |
65 | if ((off < 0) || (len < 0) || ((off + len) > b.length) || ((off + len) < 0) || (off > b.length))
66 | throw new IndexOutOfBoundsException();
67 |
68 | if (len == 0)
69 | return;
70 |
71 | c.cm.sendData(c, b, off, len);
72 | }
73 |
74 | @Override
75 | public void write(byte[] b) throws IOException
76 | {
77 | write(b, 0, b.length);
78 | }
79 | }
80 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ethz/ssh2/channel/IChannelWorkerThread.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2006-2011 Christian Plattner. All rights reserved.
3 | * Please refer to the LICENSE.txt for licensing details.
4 | */
5 | package ch.ethz.ssh2.channel;
6 |
7 | /**
8 | * IChannelWorkerThread.
9 | *
10 | * @author Christian Plattner
11 | * @version 2.50, 03/15/10
12 | */
13 | interface IChannelWorkerThread
14 | {
15 | public void stopWorking();
16 | }
17 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ethz/ssh2/channel/LocalAcceptThread.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2006-2011 Christian Plattner. All rights reserved.
3 | * Please refer to the LICENSE.txt for licensing details.
4 | */
5 | package ch.ethz.ssh2.channel;
6 |
7 | import java.io.IOException;
8 | import java.net.InetSocketAddress;
9 | import java.net.ServerSocket;
10 | import java.net.Socket;
11 |
12 | /**
13 | * LocalAcceptThread.
14 | *
15 | * @author Christian Plattner
16 | * @version 2.50, 03/15/10
17 | */
18 | public class LocalAcceptThread extends Thread implements IChannelWorkerThread
19 | {
20 | ChannelManager cm;
21 | String host_to_connect;
22 | int port_to_connect;
23 |
24 | final ServerSocket ss;
25 |
26 | public LocalAcceptThread(ChannelManager cm, int local_port, String host_to_connect, int port_to_connect)
27 | throws IOException
28 | {
29 | this.cm = cm;
30 | this.host_to_connect = host_to_connect;
31 | this.port_to_connect = port_to_connect;
32 |
33 | ss = new ServerSocket(local_port);
34 | }
35 |
36 | public LocalAcceptThread(ChannelManager cm, InetSocketAddress localAddress, String host_to_connect,
37 | int port_to_connect) throws IOException
38 | {
39 | this.cm = cm;
40 | this.host_to_connect = host_to_connect;
41 | this.port_to_connect = port_to_connect;
42 |
43 | ss = new ServerSocket();
44 | ss.bind(localAddress);
45 | }
46 |
47 | @Override
48 | public void run()
49 | {
50 | try
51 | {
52 | cm.registerThread(this);
53 | }
54 | catch (IOException e)
55 | {
56 | stopWorking();
57 | return;
58 | }
59 |
60 | while (true)
61 | {
62 | Socket s = null;
63 |
64 | try
65 | {
66 | s = ss.accept();
67 | }
68 | catch (IOException e)
69 | {
70 | stopWorking();
71 | return;
72 | }
73 |
74 | Channel cn = null;
75 | StreamForwarder r2l = null;
76 | StreamForwarder l2r = null;
77 |
78 | try
79 | {
80 | /* This may fail, e.g., if the remote port is closed (in optimistic terms: not open yet) */
81 |
82 | cn = cm.openDirectTCPIPChannel(host_to_connect, port_to_connect, s.getInetAddress().getHostAddress(), s
83 | .getPort());
84 |
85 | }
86 | catch (IOException e)
87 | {
88 | /* Simply close the local socket and wait for the next incoming connection */
89 |
90 | try
91 | {
92 | s.close();
93 | }
94 | catch (IOException ignore)
95 | {
96 | }
97 |
98 | continue;
99 | }
100 |
101 | try
102 | {
103 | r2l = new StreamForwarder(cn, null, null, cn.stdoutStream, s.getOutputStream(), "RemoteToLocal");
104 | l2r = new StreamForwarder(cn, r2l, s, s.getInputStream(), cn.stdinStream, "LocalToRemote");
105 | }
106 | catch (IOException e)
107 | {
108 | try
109 | {
110 | /* This message is only visible during debugging, since we discard the channel immediatelly */
111 | cn.cm.closeChannel(cn, "Weird error during creation of StreamForwarder (" + e.getMessage() + ")",
112 | true);
113 | }
114 | catch (IOException ignore)
115 | {
116 | }
117 |
118 | continue;
119 | }
120 |
121 | r2l.setDaemon(true);
122 | l2r.setDaemon(true);
123 | r2l.start();
124 | l2r.start();
125 | }
126 | }
127 |
128 | public void stopWorking()
129 | {
130 | try
131 | {
132 | /* This will lead to an IOException in the ss.accept() call */
133 | ss.close();
134 | }
135 | catch (IOException ignored)
136 | {
137 | }
138 | }
139 | }
140 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ethz/ssh2/channel/RemoteAcceptThread.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2006-2011 Christian Plattner. All rights reserved.
3 | * Please refer to the LICENSE.txt for licensing details.
4 | */
5 | package ch.ethz.ssh2.channel;
6 |
7 | import java.io.IOException;
8 | import java.net.Socket;
9 |
10 | import ch.ethz.ssh2.log.Logger;
11 |
12 | /**
13 | * RemoteAcceptThread.
14 | *
15 | * @author Christian Plattner
16 | * @version $Id$
17 | */
18 | public class RemoteAcceptThread extends Thread
19 | {
20 | private static final Logger log = Logger.getLogger(RemoteAcceptThread.class);
21 |
22 | Channel c;
23 |
24 | String remoteConnectedAddress;
25 | int remoteConnectedPort;
26 | String remoteOriginatorAddress;
27 | int remoteOriginatorPort;
28 | String targetAddress;
29 | int targetPort;
30 |
31 | Socket s;
32 |
33 | public RemoteAcceptThread(Channel c, String remoteConnectedAddress, int remoteConnectedPort,
34 | String remoteOriginatorAddress, int remoteOriginatorPort, String targetAddress, int targetPort)
35 | {
36 | this.c = c;
37 | this.remoteConnectedAddress = remoteConnectedAddress;
38 | this.remoteConnectedPort = remoteConnectedPort;
39 | this.remoteOriginatorAddress = remoteOriginatorAddress;
40 | this.remoteOriginatorPort = remoteOriginatorPort;
41 | this.targetAddress = targetAddress;
42 | this.targetPort = targetPort;
43 |
44 | log.debug("RemoteAcceptThread: " + remoteConnectedAddress + "/" + remoteConnectedPort + ", R: "
45 | + remoteOriginatorAddress + "/" + remoteOriginatorPort);
46 | }
47 |
48 | @Override
49 | public void run()
50 | {
51 | try
52 | {
53 | c.cm.sendOpenConfirmation(c);
54 |
55 | s = new Socket(targetAddress, targetPort);
56 |
57 | StreamForwarder r2l = new StreamForwarder(c, null, null, c.getStdoutStream(), s.getOutputStream(),
58 | "RemoteToLocal");
59 | StreamForwarder l2r = new StreamForwarder(c, null, null, s.getInputStream(), c.getStdinStream(),
60 | "LocalToRemote");
61 |
62 | /* No need to start two threads, one can be executed in the current thread */
63 |
64 | r2l.setDaemon(true);
65 | r2l.start();
66 | l2r.run();
67 |
68 | while (r2l.isAlive())
69 | {
70 | try
71 | {
72 | r2l.join();
73 | }
74 | catch (InterruptedException ignored)
75 | {
76 | }
77 | }
78 |
79 | /* If the channel is already closed, then this is a no-op */
80 |
81 | c.cm.closeChannel(c, "EOF on both streams reached.", true);
82 | s.close();
83 | }
84 | catch (IOException e)
85 | {
86 | log.warning("IOException in proxy code: " + e.getMessage());
87 |
88 | try
89 | {
90 | c.cm.closeChannel(c, "IOException in proxy code (" + e.getMessage() + ")", true);
91 | }
92 | catch (IOException ignored)
93 | {
94 | }
95 | try
96 | {
97 | if (s != null)
98 | s.close();
99 | }
100 | catch (IOException ignored)
101 | {
102 | }
103 | }
104 | }
105 | }
106 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ethz/ssh2/channel/RemoteForwardingData.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2006-2011 Christian Plattner. All rights reserved.
3 | * Please refer to the LICENSE.txt for licensing details.
4 | */
5 | package ch.ethz.ssh2.channel;
6 |
7 | /**
8 | * RemoteForwardingData. Data about a requested remote forwarding.
9 | *
10 | * @author Christian Plattner
11 | * @version 2.50, 03/15/10
12 | */
13 | public class RemoteForwardingData
14 | {
15 | public String bindAddress;
16 | public int bindPort;
17 |
18 | String targetAddress;
19 | int targetPort;
20 | }
21 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ethz/ssh2/channel/StreamForwarder.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2006-2011 Christian Plattner. All rights reserved.
3 | * Please refer to the LICENSE.txt for licensing details.
4 | */
5 | package ch.ethz.ssh2.channel;
6 |
7 | import java.io.IOException;
8 | import java.io.InputStream;
9 | import java.io.OutputStream;
10 | import java.net.Socket;
11 |
12 | /**
13 | * A StreamForwarder forwards data between two given streams.
14 | * If two StreamForwarder threads are used (one for each direction)
15 | * then one can be configured to shutdown the underlying channel/socket
16 | * if both threads have finished forwarding (EOF).
17 | *
18 | * @author Christian Plattner
19 | * @version 2.50, 03/15/10
20 | */
21 | public class StreamForwarder extends Thread
22 | {
23 | OutputStream os;
24 | InputStream is;
25 | byte[] buffer = new byte[Channel.CHANNEL_BUFFER_SIZE];
26 | Channel c;
27 | StreamForwarder sibling;
28 | Socket s;
29 | String mode;
30 |
31 | StreamForwarder(Channel c, StreamForwarder sibling, Socket s, InputStream is, OutputStream os, String mode)
32 | throws IOException
33 | {
34 | this.is = is;
35 | this.os = os;
36 | this.mode = mode;
37 | this.c = c;
38 | this.sibling = sibling;
39 | this.s = s;
40 | }
41 |
42 | @Override
43 | public void run()
44 | {
45 | try
46 | {
47 | while (true)
48 | {
49 | int len = is.read(buffer);
50 | if (len <= 0)
51 | break;
52 | os.write(buffer, 0, len);
53 | os.flush();
54 | }
55 | }
56 | catch (IOException ignore)
57 | {
58 | try
59 | {
60 | c.cm.closeChannel(c, "Closed due to exception in StreamForwarder (" + mode + "): "
61 | + ignore.getMessage(), true);
62 | }
63 | catch (IOException ignored)
64 | {
65 | }
66 | }
67 | finally
68 | {
69 | try
70 | {
71 | os.close();
72 | }
73 | catch (IOException ignored)
74 | {
75 | }
76 | try
77 | {
78 | is.close();
79 | }
80 | catch (IOException ignored)
81 | {
82 | }
83 |
84 | if (sibling != null)
85 | {
86 | while (sibling.isAlive())
87 | {
88 | try
89 | {
90 | sibling.join();
91 | }
92 | catch (InterruptedException ignored)
93 | {
94 | }
95 | }
96 |
97 | try
98 | {
99 | c.cm.closeChannel(c, "StreamForwarder (" + mode + ") is cleaning up the connection", true);
100 | }
101 | catch (IOException ignored)
102 | {
103 | }
104 |
105 | try
106 | {
107 | if (s != null)
108 | s.close();
109 | }
110 | catch (IOException ignored)
111 | {
112 | }
113 | }
114 | }
115 | }
116 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/ethz/ssh2/channel/X11ServerData.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2006-2011 Christian Plattner. All rights reserved.
3 | * Please refer to the LICENSE.txt for licensing details.
4 | */
5 | package ch.ethz.ssh2.channel;
6 |
7 | /**
8 | * X11ServerData. Data regarding an x11 forwarding target.
9 | *
10 | * @author Christian Plattner
11 | * @version 2.50, 03/15/10
12 | *
13 | */
14 | public class X11ServerData
15 | {
16 | public String hostname;
17 | public int port;
18 | public byte[] x11_magic_cookie; /* not the remote (fake) one, the local (real) one */
19 | }
20 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ethz/ssh2/crypto/Base64.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2006-2011 Christian Plattner. All rights reserved.
3 | * Please refer to the LICENSE.txt for licensing details.
4 | */
5 | package ch.ethz.ssh2.crypto;
6 |
7 | import java.io.CharArrayWriter;
8 | import java.io.IOException;
9 |
10 | /**
11 | * Basic Base64 Support.
12 | *
13 | * @author Christian Plattner
14 | * @version 2.50, 03/15/10
15 | */
16 | public class Base64
17 | {
18 | static final char[] alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".toCharArray();
19 |
20 | public static char[] encode(byte[] content)
21 | {
22 | CharArrayWriter cw = new CharArrayWriter((4 * content.length) / 3);
23 |
24 | int idx = 0;
25 |
26 | int x = 0;
27 |
28 | for (int i = 0; i < content.length; i++)
29 | {
30 | if (idx == 0)
31 | x = (content[i] & 0xff) << 16;
32 | else if (idx == 1)
33 | x = x | ((content[i] & 0xff) << 8);
34 | else
35 | x = x | (content[i] & 0xff);
36 |
37 | idx++;
38 |
39 | if (idx == 3)
40 | {
41 | cw.write(alphabet[x >> 18]);
42 | cw.write(alphabet[(x >> 12) & 0x3f]);
43 | cw.write(alphabet[(x >> 6) & 0x3f]);
44 | cw.write(alphabet[x & 0x3f]);
45 |
46 | idx = 0;
47 | }
48 | }
49 |
50 | if (idx == 1)
51 | {
52 | cw.write(alphabet[x >> 18]);
53 | cw.write(alphabet[(x >> 12) & 0x3f]);
54 | cw.write('=');
55 | cw.write('=');
56 | }
57 |
58 | if (idx == 2)
59 | {
60 | cw.write(alphabet[x >> 18]);
61 | cw.write(alphabet[(x >> 12) & 0x3f]);
62 | cw.write(alphabet[(x >> 6) & 0x3f]);
63 | cw.write('=');
64 | }
65 |
66 | return cw.toCharArray();
67 | }
68 |
69 | public static byte[] decode(char[] message) throws IOException
70 | {
71 | byte buff[] = new byte[4];
72 | byte dest[] = new byte[message.length];
73 |
74 | int bpos = 0;
75 | int destpos = 0;
76 |
77 | for (int i = 0; i < message.length; i++)
78 | {
79 | int c = message[i];
80 |
81 | if ((c == '\n') || (c == '\r') || (c == ' ') || (c == '\t'))
82 | continue;
83 |
84 | if ((c >= 'A') && (c <= 'Z'))
85 | {
86 | buff[bpos++] = (byte) (c - 'A');
87 | }
88 | else if ((c >= 'a') && (c <= 'z'))
89 | {
90 | buff[bpos++] = (byte) ((c - 'a') + 26);
91 | }
92 | else if ((c >= '0') && (c <= '9'))
93 | {
94 | buff[bpos++] = (byte) ((c - '0') + 52);
95 | }
96 | else if (c == '+')
97 | {
98 | buff[bpos++] = 62;
99 | }
100 | else if (c == '/')
101 | {
102 | buff[bpos++] = 63;
103 | }
104 | else if (c == '=')
105 | {
106 | buff[bpos++] = 64;
107 | }
108 | else
109 | {
110 | throw new IOException("Illegal char in base64 code.");
111 | }
112 |
113 | if (bpos == 4)
114 | {
115 | bpos = 0;
116 |
117 | if (buff[0] == 64)
118 | break;
119 |
120 | if (buff[1] == 64)
121 | throw new IOException("Unexpected '=' in base64 code.");
122 |
123 | if (buff[2] == 64)
124 | {
125 | int v = (((buff[0] & 0x3f) << 6) | ((buff[1] & 0x3f)));
126 | dest[destpos++] = (byte) (v >> 4);
127 | break;
128 | }
129 | else if (buff[3] == 64)
130 | {
131 | int v = (((buff[0] & 0x3f) << 12) | ((buff[1] & 0x3f) << 6) | ((buff[2] & 0x3f)));
132 | dest[destpos++] = (byte) (v >> 10);
133 | dest[destpos++] = (byte) (v >> 2);
134 | break;
135 | }
136 | else
137 | {
138 | int v = (((buff[0] & 0x3f) << 18) | ((buff[1] & 0x3f) << 12) | ((buff[2] & 0x3f) << 6) | ((buff[3] & 0x3f)));
139 | dest[destpos++] = (byte) (v >> 16);
140 | dest[destpos++] = (byte) (v >> 8);
141 | dest[destpos++] = (byte) (v);
142 | }
143 | }
144 | }
145 |
146 | byte[] res = new byte[destpos];
147 | System.arraycopy(dest, 0, res, 0, destpos);
148 |
149 | return res;
150 | }
151 | }
152 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ethz/ssh2/crypto/CryptoWishList.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2006-2011 Christian Plattner. All rights reserved.
3 | * Please refer to the LICENSE.txt for licensing details.
4 | */
5 | package ch.ethz.ssh2.crypto;
6 |
7 | import ch.ethz.ssh2.crypto.cipher.BlockCipherFactory;
8 | import ch.ethz.ssh2.crypto.digest.MAC;
9 | import ch.ethz.ssh2.transport.KexManager;
10 |
11 | /**
12 | * CryptoWishList.
13 | *
14 | * @author Christian Plattner
15 | * @version 2.50, 03/15/10
16 | */
17 | public class CryptoWishList
18 | {
19 | public String[] kexAlgorithms = KexManager.getDefaultKexAlgorithmList();
20 | public String[] serverHostKeyAlgorithms = KexManager.getDefaultServerHostkeyAlgorithmList();
21 | public String[] c2s_enc_algos = BlockCipherFactory.getDefaultCipherList();
22 | public String[] s2c_enc_algos = BlockCipherFactory.getDefaultCipherList();
23 | public String[] c2s_mac_algos = MAC.getMacList();
24 | public String[] s2c_mac_algos = MAC.getMacList();
25 | }
26 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ethz/ssh2/crypto/KeyMaterial.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2006-2011 Christian Plattner. All rights reserved.
3 | * Please refer to the LICENSE.txt for licensing details.
4 | */
5 | package ch.ethz.ssh2.crypto;
6 |
7 | import ch.ethz.ssh2.crypto.digest.HashForSSH2Types;
8 | import java.math.BigInteger;
9 |
10 | /**
11 | * Establishes key material for iv/key/mac (both directions).
12 | *
13 | * @author Christian Plattner
14 | * @version 2.50, 03/15/10
15 | */
16 | public class KeyMaterial
17 | {
18 | public byte[] initial_iv_client_to_server;
19 | public byte[] initial_iv_server_to_client;
20 | public byte[] enc_key_client_to_server;
21 | public byte[] enc_key_server_to_client;
22 | public byte[] integrity_key_client_to_server;
23 | public byte[] integrity_key_server_to_client;
24 |
25 | private static byte[] calculateKey(HashForSSH2Types sh, BigInteger K, byte[] H, byte type, byte[] SessionID,
26 | int keyLength)
27 | {
28 | byte[] res = new byte[keyLength];
29 |
30 | int dglen = sh.getDigestLength();
31 | int numRounds = (keyLength + dglen - 1) / dglen;
32 |
33 | byte[][] tmp = new byte[numRounds][];
34 |
35 | sh.reset();
36 | sh.updateBigInt(K);
37 | sh.updateBytes(H);
38 | sh.updateByte(type);
39 | sh.updateBytes(SessionID);
40 |
41 | tmp[0] = sh.getDigest();
42 |
43 | int off = 0;
44 | int produced = Math.min(dglen, keyLength);
45 |
46 | System.arraycopy(tmp[0], 0, res, off, produced);
47 |
48 | keyLength -= produced;
49 | off += produced;
50 |
51 | for (int i = 1; i < numRounds; i++)
52 | {
53 | sh.updateBigInt(K);
54 | sh.updateBytes(H);
55 |
56 | for (int j = 0; j < i; j++)
57 | sh.updateBytes(tmp[j]);
58 |
59 | tmp[i] = sh.getDigest();
60 |
61 | produced = Math.min(dglen, keyLength);
62 | System.arraycopy(tmp[i], 0, res, off, produced);
63 | keyLength -= produced;
64 | off += produced;
65 | }
66 |
67 | return res;
68 | }
69 |
70 | public static KeyMaterial create(String hashType, byte[] H, BigInteger K, byte[] SessionID, int keyLengthCS,
71 | int blockSizeCS, int macLengthCS, int keyLengthSC, int blockSizeSC, int macLengthSC)
72 | throws IllegalArgumentException
73 | {
74 | KeyMaterial km = new KeyMaterial();
75 |
76 | HashForSSH2Types sh = new HashForSSH2Types(hashType);
77 |
78 | km.initial_iv_client_to_server = calculateKey(sh, K, H, (byte) 'A', SessionID, blockSizeCS);
79 |
80 | km.initial_iv_server_to_client = calculateKey(sh, K, H, (byte) 'B', SessionID, blockSizeSC);
81 |
82 | km.enc_key_client_to_server = calculateKey(sh, K, H, (byte) 'C', SessionID, keyLengthCS);
83 |
84 | km.enc_key_server_to_client = calculateKey(sh, K, H, (byte) 'D', SessionID, keyLengthSC);
85 |
86 | km.integrity_key_client_to_server = calculateKey(sh, K, H, (byte) 'E', SessionID, macLengthCS);
87 |
88 | km.integrity_key_server_to_client = calculateKey(sh, K, H, (byte) 'F', SessionID, macLengthSC);
89 |
90 | return km;
91 | }
92 | }
93 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ethz/ssh2/crypto/PEMDecryptException.java:
--------------------------------------------------------------------------------
1 |
2 | package ch.ethz.ssh2.crypto;
3 |
4 | /*
5 | * Copyright (c) 2002-2010 David Kocher. All rights reserved.
6 | *
7 | * http://cyberduck.ch/
8 | *
9 | * This program is free software; you can redistribute it and/or modify
10 | * it under the terms of the GNU General Public License as published by
11 | * the Free Software Foundation; either version 2 of the License, or
12 | * (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 | * Bug fixes, suggestions and comments should be sent to:
20 | * dkocher@cyberduck.ch
21 | */
22 |
23 | import java.io.IOException;
24 |
25 | /**
26 | * @version $Id: PEMDecryptException.java 5865 2010-03-27 03:28:11Z dkocher $
27 | */
28 | public class PEMDecryptException extends IOException
29 | {
30 | /**
31 | *
32 | */
33 | private static final long serialVersionUID = 1L;
34 |
35 | public PEMDecryptException(String message)
36 | {
37 | super(message);
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ethz/ssh2/crypto/PEMStructure.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2006-2011 Christian Plattner. All rights reserved.
3 | * Please refer to the LICENSE.txt for licensing details.
4 | */
5 | package ch.ethz.ssh2.crypto;
6 |
7 | /**
8 | * Parsed PEM structure.
9 | *
10 | * @author Christian Plattner
11 | * @version 2.50, 03/15/10
12 | */
13 |
14 | public class PEMStructure
15 | {
16 | int pemType;
17 | String dekInfo[];
18 | String procType[];
19 | byte[] data;
20 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/ethz/ssh2/crypto/SimpleDERReader.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2006-2011 Christian Plattner. All rights reserved.
3 | * Please refer to the LICENSE.txt for licensing details.
4 | */
5 | package ch.ethz.ssh2.crypto;
6 |
7 | import java.io.IOException;
8 |
9 | import java.math.BigInteger;
10 |
11 | /**
12 | * SimpleDERReader.
13 | *
14 | * @author Christian Plattner
15 | * @version 2.50, 03/15/10
16 | */
17 | public class SimpleDERReader
18 | {
19 | byte[] buffer;
20 | int pos;
21 | int count;
22 |
23 | public SimpleDERReader(byte[] b)
24 | {
25 | resetInput(b);
26 | }
27 |
28 | public SimpleDERReader(byte[] b, int off, int len)
29 | {
30 | resetInput(b, off, len);
31 | }
32 |
33 | public void resetInput(byte[] b)
34 | {
35 | resetInput(b, 0, b.length);
36 | }
37 |
38 | public void resetInput(byte[] b, int off, int len)
39 | {
40 | buffer = b;
41 | pos = off;
42 | count = len;
43 | }
44 |
45 | private byte readByte() throws IOException
46 | {
47 | if (count <= 0)
48 | throw new IOException("DER byte array: out of data");
49 | count--;
50 | return buffer[pos++];
51 | }
52 |
53 | private byte[] readBytes(int len) throws IOException
54 | {
55 | if (len > count)
56 | throw new IOException("DER byte array: out of data");
57 |
58 | byte[] b = new byte[len];
59 |
60 | System.arraycopy(buffer, pos, b, 0, len);
61 |
62 | pos += len;
63 | count -= len;
64 |
65 | return b;
66 | }
67 |
68 | public int available()
69 | {
70 | return count;
71 | }
72 |
73 | private int readLength() throws IOException
74 | {
75 | int len = readByte() & 0xff;
76 |
77 | if ((len & 0x80) == 0)
78 | return len;
79 |
80 | int remain = len & 0x7F;
81 |
82 | if (remain == 0)
83 | return -1;
84 |
85 | len = 0;
86 |
87 | while (remain > 0)
88 | {
89 | len = len << 8;
90 | len = len | (readByte() & 0xff);
91 | remain--;
92 | }
93 |
94 | return len;
95 | }
96 |
97 | public int ignoreNextObject() throws IOException
98 | {
99 | int type = readByte() & 0xff;
100 |
101 | int len = readLength();
102 |
103 | if ((len < 0) || len > available())
104 | throw new IOException("Illegal len in DER object (" + len + ")");
105 |
106 | readBytes(len);
107 |
108 | return type;
109 | }
110 |
111 | public BigInteger readInt() throws IOException
112 | {
113 | int type = readByte() & 0xff;
114 |
115 | if (type != 0x02)
116 | throw new IOException("Expected DER Integer, but found type " + type);
117 |
118 | int len = readLength();
119 |
120 | if ((len < 0) || len > available())
121 | throw new IOException("Illegal len in DER object (" + len + ")");
122 |
123 | byte[] b = readBytes(len);
124 |
125 | return new BigInteger(b);
126 | }
127 |
128 | public byte[] readSequenceAsByteArray() throws IOException
129 | {
130 | int type = readByte() & 0xff;
131 |
132 | if (type != 0x30)
133 | throw new IOException("Expected DER Sequence, but found type " + type);
134 |
135 | int len = readLength();
136 |
137 | if ((len < 0) || len > available())
138 | throw new IOException("Illegal len in DER object (" + len + ")");
139 |
140 | return readBytes(len);
141 | }
142 |
143 | public byte[] readOctetString() throws IOException
144 | {
145 | int type = readByte() & 0xff;
146 |
147 | if (type != 0x04)
148 | throw new IOException("Expected DER Octetstring, but found type " + type);
149 |
150 | int len = readLength();
151 |
152 | if ((len < 0) || len > available())
153 | throw new IOException("Illegal len in DER object (" + len + ")");
154 |
155 | return readBytes(len);
156 | }
157 |
158 | }
159 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ethz/ssh2/crypto/cipher/BlockCipher.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2006-2011 Christian Plattner. All rights reserved.
3 | * Please refer to the LICENSE.txt for licensing details.
4 | */
5 | package ch.ethz.ssh2.crypto.cipher;
6 |
7 | /**
8 | * BlockCipher.
9 | *
10 | * @author Christian Plattner
11 | * @version 2.50, 03/15/10
12 | */
13 | public interface BlockCipher
14 | {
15 | public void init(boolean forEncryption, byte[] key);
16 |
17 | public int getBlockSize();
18 |
19 | public void transformBlock(byte[] src, int srcoff, byte[] dst, int dstoff);
20 | }
21 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ethz/ssh2/crypto/cipher/BlockCipherFactory.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2006-2011 Christian Plattner. All rights reserved.
3 | * Please refer to the LICENSE.txt for licensing details.
4 | */
5 | package ch.ethz.ssh2.crypto.cipher;
6 |
7 | import java.util.ArrayList;
8 | import java.util.List;
9 | import java.util.Vector;
10 |
11 | /**
12 | * BlockCipherFactory.
13 | *
14 | * @author Christian Plattner
15 | * @version $Id$
16 | */
17 | public class BlockCipherFactory
18 | {
19 | private static final class CipherEntry
20 | {
21 | String type;
22 | int blocksize;
23 | int keysize;
24 | String cipherClass;
25 |
26 | public CipherEntry(String type, int blockSize, int keySize, String cipherClass)
27 | {
28 | this.type = type;
29 | this.blocksize = blockSize;
30 | this.keysize = keySize;
31 | this.cipherClass = cipherClass;
32 | }
33 | }
34 |
35 | private static final List