├── manifest.mf
├── src
├── respite
│ └── http
│ │ └── injector
│ │ ├── download.png
│ │ ├── Config.java
│ │ ├── SavedData.java
│ │ └── GradientButton.java
├── com
│ ├── trilead
│ │ └── ssh2
│ │ │ ├── channel
│ │ │ ├── IChannelWorkerThread.java
│ │ │ ├── RemoteForwardingData.java
│ │ │ ├── X11ServerData.java
│ │ │ ├── ChannelOutputStream.java
│ │ │ ├── ChannelInputStream.java
│ │ │ ├── StreamForwarder.java
│ │ │ ├── RemoteAcceptThread.java
│ │ │ └── LocalAcceptThread.java
│ │ │ ├── ProxyData.java
│ │ │ ├── crypto
│ │ │ ├── PEMStructure.java
│ │ │ ├── cipher
│ │ │ │ ├── BlockCipher.java
│ │ │ │ ├── NullCipher.java
│ │ │ │ ├── CTRMode.java
│ │ │ │ ├── CBCMode.java
│ │ │ │ ├── DESede.java
│ │ │ │ ├── CipherInputStream.java
│ │ │ │ ├── CipherOutputStream.java
│ │ │ │ └── BlockCipherFactory.java
│ │ │ ├── digest
│ │ │ │ ├── Digest.java
│ │ │ │ ├── HashForSSH2Types.java
│ │ │ │ ├── HMAC.java
│ │ │ │ └── MAC.java
│ │ │ ├── CryptoWishList.java
│ │ │ ├── KeyMaterial.java
│ │ │ ├── dh
│ │ │ │ └── DhGroupExchange.java
│ │ │ ├── Base64.java
│ │ │ └── SimpleDERReader.java
│ │ │ ├── transport
│ │ │ ├── MessageHandler.java
│ │ │ ├── NegotiateException.java
│ │ │ ├── NegotiatedParameters.java
│ │ │ ├── KexState.java
│ │ │ ├── KexParameters.java
│ │ │ └── ClientServerHello.java
│ │ │ ├── signature
│ │ │ ├── RSASignature.java
│ │ │ ├── RSAPublicKey.java
│ │ │ ├── DSASignature.java
│ │ │ ├── RSAPrivateKey.java
│ │ │ ├── DSAPublicKey.java
│ │ │ └── DSAPrivateKey.java
│ │ │ ├── packets
│ │ │ ├── PacketKexDHInit.java
│ │ │ ├── PacketGlobalTrileadPing.java
│ │ │ ├── PacketKexDhGexInit.java
│ │ │ ├── PacketChannelAuthAgentReq.java
│ │ │ ├── PacketKexDhGexRequestOld.java
│ │ │ ├── PacketChannelTrileadPing.java
│ │ │ ├── PacketUserauthInfoResponse.java
│ │ │ ├── PacketSessionStartShell.java
│ │ │ ├── PacketKexDhGexRequest.java
│ │ │ ├── PacketGlobalForwardRequest.java
│ │ │ ├── PacketSessionExecCommand.java
│ │ │ ├── PacketSessionPtyResize.java
│ │ │ ├── PacketGlobalCancelForwardRequest.java
│ │ │ ├── PacketSessionSubsystemRequest.java
│ │ │ ├── PacketNewKeys.java
│ │ │ ├── PacketUserauthRequestInteractive.java
│ │ │ ├── PacketKexDhGexGroup.java
│ │ │ ├── PacketKexDHReply.java
│ │ │ ├── PacketIgnore.java
│ │ │ ├── PacketKexDhGexReply.java
│ │ │ ├── PacketServiceRequest.java
│ │ │ ├── PacketDisconnect.java
│ │ │ ├── PacketUserauthFailure.java
│ │ │ ├── PacketServiceAccept.java
│ │ │ ├── PacketUserauthBanner.java
│ │ │ ├── PacketSessionX11Request.java
│ │ │ ├── PacketOpenDirectTCPIPChannel.java
│ │ │ ├── PacketChannelWindowAdjust.java
│ │ │ ├── PacketSessionPtyRequest.java
│ │ │ ├── PacketOpenSessionChannel.java
│ │ │ ├── PacketUserauthRequestNone.java
│ │ │ ├── PacketUserauthRequestPublicKey.java
│ │ │ ├── PacketUserauthInfoRequest.java
│ │ │ ├── PacketUserauthRequestPassword.java
│ │ │ ├── PacketChannelOpenFailure.java
│ │ │ ├── PacketChannelOpenConfirmation.java
│ │ │ └── TypesWriter.java
│ │ │ ├── DebugLogger.java
│ │ │ ├── HTTPProxyException.java
│ │ │ ├── SFTPv3FileHandle.java
│ │ │ ├── compression
│ │ │ ├── ICompressor.java
│ │ │ ├── ZlibOpenSSH.java
│ │ │ └── CompressionFactory.java
│ │ │ ├── sftp
│ │ │ ├── AttribPermissions.java
│ │ │ ├── AttribTypes.java
│ │ │ ├── AttrTextHints.java
│ │ │ ├── Packet.java
│ │ │ └── AttribFlags.java
│ │ │ ├── util
│ │ │ ├── Tokenizer.java
│ │ │ └── TimeoutService.java
│ │ │ ├── log
│ │ │ └── Logger.java
│ │ │ ├── ConnectionMonitor.java
│ │ │ ├── SFTPv3DirectoryEntry.java
│ │ │ ├── ServerHostKeyVerifier.java
│ │ │ ├── ConnectionInfo.java
│ │ │ ├── LocalPortForwarder.java
│ │ │ ├── AuthAgentCallback.java
│ │ │ ├── DynamicPortForwarder.java
│ │ │ ├── ChannelCondition.java
│ │ │ ├── SFTPException.java
│ │ │ ├── LocalStreamForwarder.java
│ │ │ ├── InteractiveCallback.java
│ │ │ ├── HTTPProxyData.java
│ │ │ └── DHGexParameters.java
│ └── jcraft
│ │ └── jzlib
│ │ ├── ZStreamException.java
│ │ ├── JZlib.java
│ │ └── Adler32.java
├── net
│ └── sourceforge
│ │ └── jsocks
│ │ ├── AuthenticationNone.java
│ │ ├── UDPEncapsulation.java
│ │ ├── Authentication.java
│ │ ├── SocksException.java
│ │ ├── ProxyMessage.java
│ │ └── Socks4Proxy.java
└── respiteinjector
│ ├── GlobalVars.java
│ ├── Loggable.java
│ ├── Embaralhador.java
│ ├── CesarCifer.java
│ └── ConnectMaker.java
├── .idea
├── misc.xml
├── modules.xml
└── Respite HTTP Injector.iml
├── nbproject
├── genfiles.properties
├── project.xml
└── project.properties
├── README.md
├── user.data
└── LICENSE.txt
/manifest.mf:
--------------------------------------------------------------------------------
1 | Manifest-Version: 1.0
2 | X-COMMENT: Main-Class will be added automatically by build
3 |
4 |
--------------------------------------------------------------------------------
/src/respite/http/injector/download.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AlizerUncaged/HTTP-Injector/HEAD/src/respite/http/injector/download.png
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 | “As we've come to realize, the idea that security starts and ends with the purchase of a prepackaged firewall is simply misguided.”
7 |SFTPv3FileHandle.
5 | *
6 | * @author Christian Plattner, plattner@trilead.com
7 | * @version $Id: SFTPv3FileHandle.java,v 1.1 2007/10/15 12:49:56 cplattne Exp $
8 | */
9 |
10 | public class SFTPv3FileHandle {
11 | final SFTPv3Client client;
12 | final byte[] fileHandle;
13 | boolean isClosed = false;
14 |
15 | /* The constructor is NOT public */
16 |
17 | SFTPv3FileHandle(SFTPv3Client client, byte[] h) {
18 | this.client = client;
19 | this.fileHandle = h;
20 | }
21 |
22 | /**
23 | * Get the SFTPv3Client instance which created this handle.
24 | *
25 | * @return A SFTPv3Client instance.
26 | */
27 | public SFTPv3Client getClient() {
28 | return client;
29 | }
30 |
31 | /**
32 | * Check if this handle was closed with the
33 | * {@link SFTPv3Client#closeFile(SFTPv3FileHandle)} method of the
34 | * SFTPv3Client instance which created the handle.
35 | *
36 | * @return if the handle is closed.
37 | */
38 | public boolean isClosed() {
39 | return isClosed;
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/src/com/trilead/ssh2/compression/ICompressor.java:
--------------------------------------------------------------------------------
1 | /*
2 | * ConnectBot: simple, powerful, open-source SSH client for Android
3 | * Copyright 2007 Kenny Root, Jeffrey Sharkey
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | package com.trilead.ssh2.compression;
19 |
20 | /**
21 | * @author Kenny Root
22 | *
23 | */
24 | public interface ICompressor {
25 | boolean canCompressPreauth();
26 |
27 | int compress(byte[] buf, int start, int len, byte[] output);
28 |
29 | int getBufferSize();
30 |
31 | byte[] uncompress(byte[] buf, int start, int[] len);
32 | }
33 |
--------------------------------------------------------------------------------
/src/com/trilead/ssh2/packets/PacketGlobalCancelForwardRequest.java:
--------------------------------------------------------------------------------
1 | package com.trilead.ssh2.packets;
2 |
3 | /**
4 | * PacketGlobalCancelForwardRequest.
5 | *
6 | * @author Christian Plattner, plattner@trilead.com
7 | * @version $Id: PacketGlobalCancelForwardRequest.java,v 1.1 2007/10/15 12:49:55
8 | * cplattne Exp $
9 | */
10 | public class PacketGlobalCancelForwardRequest {
11 | byte[] payload;
12 |
13 | public boolean wantReply;
14 | public String bindAddress;
15 | public int bindPort;
16 |
17 | public PacketGlobalCancelForwardRequest(boolean wantReply,
18 | String bindAddress, int bindPort) {
19 | this.wantReply = wantReply;
20 | this.bindAddress = bindAddress;
21 | this.bindPort = bindPort;
22 | }
23 |
24 | public byte[] getPayload() {
25 | if (payload == null) {
26 | TypesWriter tw = new TypesWriter();
27 | tw.writeByte(Packets.SSH_MSG_GLOBAL_REQUEST);
28 |
29 | tw.writeString("cancel-tcpip-forward");
30 | tw.writeBoolean(wantReply);
31 | tw.writeString(bindAddress);
32 | tw.writeUINT32(bindPort);
33 |
34 | payload = tw.getBytes();
35 | }
36 | return payload;
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/LICENSE.txt:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2021 Michael Kross
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
--------------------------------------------------------------------------------
/src/com/trilead/ssh2/crypto/CryptoWishList.java:
--------------------------------------------------------------------------------
1 | package com.trilead.ssh2.crypto;
2 |
3 | import com.trilead.ssh2.compression.CompressionFactory;
4 | import com.trilead.ssh2.crypto.cipher.BlockCipherFactory;
5 | import com.trilead.ssh2.crypto.digest.MAC;
6 | import com.trilead.ssh2.transport.KexManager;
7 |
8 | /**
9 | * CryptoWishList.
10 | *
11 | * @author Christian Plattner, plattner@trilead.com
12 | * @version $Id: CryptoWishList.java,v 1.1 2007/10/15 12:49:56 cplattne Exp $
13 | */
14 | public class CryptoWishList {
15 | public String[] kexAlgorithms = KexManager.getDefaultKexAlgorithmList();
16 | public String[] serverHostKeyAlgorithms = KexManager
17 | .getDefaultServerHostkeyAlgorithmList();
18 | public String[] c2s_enc_algos = BlockCipherFactory.getDefaultCipherList();
19 | public String[] s2c_enc_algos = BlockCipherFactory.getDefaultCipherList();
20 | public String[] c2s_mac_algos = MAC.getMacList();
21 | public String[] s2c_mac_algos = MAC.getMacList();
22 | public String[] c2s_comp_algos = CompressionFactory
23 | .getDefaultCompressorList();
24 | public String[] s2c_comp_algos = CompressionFactory
25 | .getDefaultCompressorList();
26 | }
27 |
--------------------------------------------------------------------------------
/src/com/trilead/ssh2/packets/PacketSessionSubsystemRequest.java:
--------------------------------------------------------------------------------
1 | package com.trilead.ssh2.packets;
2 |
3 | /**
4 | * PacketSessionSubsystemRequest.
5 | *
6 | * @author Christian Plattner, plattner@trilead.com
7 | * @version $Id: PacketSessionSubsystemRequest.java,v 1.1 2007/10/15 12:49:55
8 | * cplattne Exp $
9 | */
10 | public class PacketSessionSubsystemRequest {
11 | byte[] payload;
12 |
13 | public int recipientChannelID;
14 | public boolean wantReply;
15 | public String subsystem;
16 |
17 | public PacketSessionSubsystemRequest(int recipientChannelID,
18 | boolean wantReply, String subsystem) {
19 | this.recipientChannelID = recipientChannelID;
20 | this.wantReply = wantReply;
21 | this.subsystem = subsystem;
22 | }
23 |
24 | public byte[] getPayload() {
25 | if (payload == null) {
26 | TypesWriter tw = new TypesWriter();
27 | tw.writeByte(Packets.SSH_MSG_CHANNEL_REQUEST);
28 | tw.writeUINT32(recipientChannelID);
29 | tw.writeString("subsystem");
30 | tw.writeBoolean(wantReply);
31 | tw.writeString(subsystem);
32 | payload = tw.getBytes();
33 | tw.getBytes(payload);
34 | }
35 | return payload;
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/src/com/trilead/ssh2/sftp/AttribPermissions.java:
--------------------------------------------------------------------------------
1 | package com.trilead.ssh2.sftp;
2 |
3 | /**
4 | *
5 | * Permissions for the 'permissions' field in the SFTP ATTRS data type.
6 | * 7 | * "The 'permissions' field contains a bit mask specifying file permissions. 8 | * These permissions correspond to the st_mode field of the stat structure 9 | * defined by POSIX [IEEE.1003-1.1996]." 10 | * 11 | * @author Christian Plattner, plattner@trilead.com 12 | * @version $Id: AttribPermissions.java,v 1.1 2007/10/15 12:49:55 cplattne Exp $ 13 | * 14 | */ 15 | public class AttribPermissions { 16 | /* Octal values! */ 17 | 18 | public static final int S_IRUSR = 0400; 19 | public static final int S_IWUSR = 0200; 20 | public static final int S_IXUSR = 0100; 21 | public static final int S_IRGRP = 0040; 22 | public static final int S_IWGRP = 0020; 23 | public static final int S_IXGRP = 0010; 24 | public static final int S_IROTH = 0004; 25 | public static final int S_IWOTH = 0002; 26 | public static final int S_IXOTH = 0001; 27 | public static final int S_ISUID = 04000; 28 | public static final int S_ISGID = 02000; 29 | public static final int S_ISVTX = 01000; 30 | } 31 | -------------------------------------------------------------------------------- /src/com/trilead/ssh2/sftp/AttribTypes.java: -------------------------------------------------------------------------------- 1 | package com.trilead.ssh2.sftp; 2 | 3 | /** 4 | * 5 | * Types for the 'type' field in the SFTP ATTRS data type. 6 | *
7 | * "On a POSIX system, these values would be derived from the mode field of
8 | * the stat structure. SPECIAL should be used for files that are of a known type
9 | * which cannot be expressed in the protocol. UNKNOWN should be used if the type
10 | * is not known."
11 | *
12 | * @author Christian Plattner, plattner@trilead.com
13 | * @version $Id: AttribTypes.java,v 1.1 2007/10/15 12:49:55 cplattne Exp $
14 | *
15 | */
16 | public class AttribTypes {
17 | public static final int SSH_FILEXFER_TYPE_REGULAR = 1;
18 | public static final int SSH_FILEXFER_TYPE_DIRECTORY = 2;
19 | public static final int SSH_FILEXFER_TYPE_SYMLINK = 3;
20 | public static final int SSH_FILEXFER_TYPE_SPECIAL = 4;
21 | public static final int SSH_FILEXFER_TYPE_UNKNOWN = 5;
22 | public static final int SSH_FILEXFER_TYPE_SOCKET = 6;
23 | public static final int SSH_FILEXFER_TYPE_CHAR_DEVICE = 7;
24 | public static final int SSH_FILEXFER_TYPE_BLOCK_DEVICE = 8;
25 | public static final int SSH_FILEXFER_TYPE_FIFO = 9;
26 | }
27 |
--------------------------------------------------------------------------------
/src/com/trilead/ssh2/packets/PacketNewKeys.java:
--------------------------------------------------------------------------------
1 | package com.trilead.ssh2.packets;
2 |
3 | import java.io.IOException;
4 |
5 | /**
6 | * PacketNewKeys.
7 | *
8 | * @author Christian Plattner, plattner@trilead.com
9 | * @version $Id: PacketNewKeys.java,v 1.1 2007/10/15 12:49:55 cplattne Exp $
10 | */
11 | public class PacketNewKeys {
12 | byte[] payload;
13 |
14 | public PacketNewKeys() {
15 | }
16 |
17 | public PacketNewKeys(byte payload[], int off, int len) throws IOException {
18 | this.payload = new byte[len];
19 | System.arraycopy(payload, off, this.payload, 0, len);
20 |
21 | TypesReader tr = new TypesReader(payload, off, len);
22 |
23 | int packet_type = tr.readByte();
24 |
25 | if (packet_type != Packets.SSH_MSG_NEWKEYS)
26 | throw new IOException("This is not a SSH_MSG_NEWKEYS! ("
27 | + packet_type + ")");
28 |
29 | if (tr.remain() != 0)
30 | throw new IOException("Padding in SSH_MSG_NEWKEYS packet!");
31 | }
32 |
33 | public byte[] getPayload() {
34 | if (payload == null) {
35 | TypesWriter tw = new TypesWriter();
36 | tw.writeByte(Packets.SSH_MSG_NEWKEYS);
37 | payload = tw.getBytes();
38 | }
39 | return payload;
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/src/com/trilead/ssh2/sftp/AttrTextHints.java:
--------------------------------------------------------------------------------
1 | package com.trilead.ssh2.sftp;
2 |
3 | /**
4 | *
5 | * Values for the 'text-hint' field in the SFTP ATTRS data type.
6 | *
7 | * @author Christian Plattner, plattner@trilead.com
8 | * @version $Id: AttrTextHints.java,v 1.1 2007/10/15 12:49:55 cplattne Exp $
9 | *
10 | */
11 | public class AttrTextHints {
12 | /**
13 | * The server knows the file is a text file, and should be opened using the
14 | * SSH_FXF_ACCESS_TEXT_MODE flag.
15 | */
16 | public static final int SSH_FILEXFER_ATTR_KNOWN_TEXT = 0x00;
17 |
18 | /**
19 | * The server has applied a heuristic or other mechanism and believes that
20 | * the file should be opened with the SSH_FXF_ACCESS_TEXT_MODE flag.
21 | */
22 | public static final int SSH_FILEXFER_ATTR_GUESSED_TEXT = 0x01;
23 |
24 | /**
25 | * The server knows the file has binary content.
26 | */
27 | public static final int SSH_FILEXFER_ATTR_KNOWN_BINARY = 0x02;
28 |
29 | /**
30 | * The server has applied a heuristic or other mechanism and believes has
31 | * binary content, and should not be opened with the
32 | * SSH_FXF_ACCESS_TEXT_MODE flag.
33 | */
34 | public static final int SSH_FILEXFER_ATTR_GUESSED_BINARY = 0x03;
35 | }
36 |
--------------------------------------------------------------------------------
/src/com/trilead/ssh2/packets/PacketUserauthRequestInteractive.java:
--------------------------------------------------------------------------------
1 | package com.trilead.ssh2.packets;
2 |
3 | /**
4 | * PacketUserauthRequestInteractive.
5 | *
6 | * @author Christian Plattner, plattner@trilead.com
7 | * @version $Id: PacketUserauthRequestInteractive.java,v 1.1 2007/10/15 12:49:55
8 | * cplattne Exp $
9 | */
10 | public class PacketUserauthRequestInteractive {
11 | byte[] payload;
12 |
13 | String userName;
14 | String serviceName;
15 | String[] submethods;
16 |
17 | public PacketUserauthRequestInteractive(String serviceName, String user,
18 | String[] submethods) {
19 | this.serviceName = serviceName;
20 | this.userName = user;
21 | this.submethods = submethods;
22 | }
23 |
24 | public byte[] getPayload() {
25 | if (payload == null) {
26 | TypesWriter tw = new TypesWriter();
27 | tw.writeByte(Packets.SSH_MSG_USERAUTH_REQUEST);
28 | tw.writeString(userName);
29 | tw.writeString(serviceName);
30 | tw.writeString("keyboard-interactive");
31 | tw.writeString(""); // draft-ietf-secsh-newmodes-04.txt says that
32 | // the language tag should be empty.
33 | tw.writeNameList(submethods);
34 |
35 | payload = tw.getBytes();
36 | }
37 | return payload;
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/src/com/trilead/ssh2/compression/ZlibOpenSSH.java:
--------------------------------------------------------------------------------
1 | /*
2 | * ConnectBot: simple, powerful, open-source SSH client for Android
3 | * Copyright 2007 Kenny Root, Jeffrey Sharkey
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | package com.trilead.ssh2.compression;
19 |
20 | /**
21 | * Defines how zlib@openssh.org compression works. See
22 | * http://www.openssh.org/txt/draft-miller-secsh-compression-delayed-00.txt
23 | * compression is disabled until userauth has occurred.
24 | *
25 | * @author Matt Johnston
26 | *
27 | */
28 | public class ZlibOpenSSH extends Zlib {
29 |
30 | @Override
31 | public boolean canCompressPreauth() {
32 | return false;
33 | }
34 |
35 | }
36 |
--------------------------------------------------------------------------------
/src/com/trilead/ssh2/packets/PacketKexDhGexGroup.java:
--------------------------------------------------------------------------------
1 | package com.trilead.ssh2.packets;
2 |
3 | import java.io.IOException;
4 | import java.math.BigInteger;
5 |
6 | /**
7 | * PacketKexDhGexGroup.
8 | *
9 | * @author Christian Plattner, plattner@trilead.com
10 | * @version $Id: PacketKexDhGexGroup.java,v 1.1 2007/10/15 12:49:55 cplattne Exp
11 | * $
12 | */
13 | public class PacketKexDhGexGroup {
14 | byte[] payload;
15 |
16 | BigInteger p;
17 | BigInteger g;
18 |
19 | public PacketKexDhGexGroup(byte payload[], int off, int len)
20 | throws IOException {
21 | this.payload = new byte[len];
22 | System.arraycopy(payload, off, this.payload, 0, len);
23 |
24 | TypesReader tr = new TypesReader(payload, off, len);
25 |
26 | int packet_type = tr.readByte();
27 |
28 | if (packet_type != Packets.SSH_MSG_KEX_DH_GEX_GROUP)
29 | throw new IllegalArgumentException(
30 | "This is not a SSH_MSG_KEX_DH_GEX_GROUP! (" + packet_type
31 | + ")");
32 |
33 | p = tr.readMPINT();
34 | g = tr.readMPINT();
35 |
36 | if (tr.remain() != 0)
37 | throw new IOException("PADDING IN SSH_MSG_KEX_DH_GEX_GROUP!");
38 | }
39 |
40 | public BigInteger getG() {
41 | return g;
42 | }
43 |
44 | public BigInteger getP() {
45 | return p;
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/src/com/trilead/ssh2/util/Tokenizer.java:
--------------------------------------------------------------------------------
1 | package com.trilead.ssh2.util;
2 |
3 | /**
4 | * Tokenizer. Why? Because StringTokenizer is not available in J2ME.
5 | *
6 | * @author Christian Plattner, plattner@trilead.com
7 | * @version $Id: Tokenizer.java,v 1.1 2007/10/15 12:49:57 cplattne Exp $
8 | */
9 | public class Tokenizer {
10 | /**
11 | * Exists because StringTokenizer is not available in J2ME. Returns an array
12 | * with at least 1 entry.
13 | *
14 | * @param source
15 | * must be non-null
16 | * @param delimiter
17 | * @return an array of Strings
18 | */
19 | public static String[] parseTokens(String source, char delimiter) {
20 | int numtoken = 1;
21 |
22 | for (int i = 0; i < source.length(); i++) {
23 | if (source.charAt(i) == delimiter)
24 | numtoken++;
25 | }
26 |
27 | String list[] = new String[numtoken];
28 | int nextfield = 0;
29 |
30 | for (int i = 0; i < numtoken; i++) {
31 | if (nextfield >= source.length()) {
32 | list[i] = "";
33 | } else {
34 | int idx = source.indexOf(delimiter, nextfield);
35 | if (idx == -1)
36 | idx = source.length();
37 | list[i] = source.substring(nextfield, idx);
38 | nextfield = idx + 1;
39 | }
40 | }
41 |
42 | return list;
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/src/respite/http/injector/SavedData.java:
--------------------------------------------------------------------------------
1 | /*
2 | * To change this license header, choose License Headers in Project Properties.
3 | * To change this template file, choose Tools | Templates
4 | * and open the template in the editor.
5 | */
6 | package respite.http.injector;
7 |
8 | import java.util.Hashtable;
9 |
10 | /**
11 | *
12 | * @author user
13 | */
14 | public class SavedData {
15 | public double Version = 2020.3;
16 | public String Payload = "CONNECT [host_port] HTTP/1.1[crlf][crlf]";
17 | public String Proxy = "";
18 | public String SSH_Host = "";
19 | public String SSH_Port = "";
20 | public String SSH_Username = "";
21 | public String SSH_Password = "";
22 | public String LocalProxyInterface_Host = "";
23 | public String LocalProxyInterface_Port = "";
24 | public String LocalSSHInterface_Host = "";
25 | public String LocalSSHInterface_Port = "";
26 | public boolean AllowSSH = true;
27 | public String PayloadHost = "";
28 | public Hashtable
10 | * For speed reasons, the static variables are not protected with semaphores. In
11 | * other words, if you dynamicaly change the logging settings, then some threads
12 | * may still use the old setting.
13 | *
14 | * @author Christian Plattner, plattner@trilead.com
15 | * @version $Id: Logger.java,v 1.2 2008/03/03 07:01:36 cplattne Exp $
16 | */
17 |
18 | public class Logger {
19 | public static boolean enabled = false;
20 | public static DebugLogger logger = null;
21 |
22 | public final static Logger getLogger(Class x) {
23 | return new Logger(x);
24 | }
25 |
26 | private String className;
27 |
28 | public Logger(Class x) {
29 | this.className = x.getName();
30 | }
31 |
32 | public final boolean isEnabled() {
33 | return enabled;
34 | }
35 |
36 | public final void log(int level, String message) {
37 | if (!enabled)
38 | return;
39 |
40 | DebugLogger target = logger;
41 |
42 | if (target == null)
43 | return;
44 |
45 | target.log(level, className, message);
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/src/com/trilead/ssh2/packets/PacketKexDHReply.java:
--------------------------------------------------------------------------------
1 | package com.trilead.ssh2.packets;
2 |
3 | import java.io.IOException;
4 | import java.math.BigInteger;
5 |
6 | /**
7 | * PacketKexDHReply.
8 | *
9 | * @author Christian Plattner, plattner@trilead.com
10 | * @version $Id: PacketKexDHReply.java,v 1.1 2007/10/15 12:49:55 cplattne Exp $
11 | */
12 | public class PacketKexDHReply {
13 | byte[] payload;
14 |
15 | byte[] hostKey;
16 | BigInteger f;
17 | byte[] signature;
18 |
19 | public PacketKexDHReply(byte payload[], int off, int len)
20 | throws IOException {
21 | this.payload = new byte[len];
22 | System.arraycopy(payload, off, this.payload, 0, len);
23 |
24 | TypesReader tr = new TypesReader(payload, off, len);
25 |
26 | int packet_type = tr.readByte();
27 |
28 | if (packet_type != Packets.SSH_MSG_KEXDH_REPLY)
29 | throw new IOException("This is not a SSH_MSG_KEXDH_REPLY! ("
30 | + packet_type + ")");
31 |
32 | hostKey = tr.readByteString();
33 | f = tr.readMPINT();
34 | signature = tr.readByteString();
35 |
36 | if (tr.remain() != 0)
37 | throw new IOException("PADDING IN SSH_MSG_KEXDH_REPLY!");
38 | }
39 |
40 | public BigInteger getF() {
41 | return f;
42 | }
43 |
44 | public byte[] getHostKey() {
45 | return hostKey;
46 | }
47 |
48 | public byte[] getSignature() {
49 | return signature;
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/src/com/trilead/ssh2/packets/PacketIgnore.java:
--------------------------------------------------------------------------------
1 | package com.trilead.ssh2.packets;
2 |
3 | import java.io.IOException;
4 |
5 | /**
6 | * PacketIgnore.
7 | *
8 | * @author Christian Plattner, plattner@trilead.com
9 | * @version $Id: PacketIgnore.java,v 1.1 2007/10/15 12:49:55 cplattne Exp $
10 | */
11 | public class PacketIgnore {
12 | byte[] payload;
13 |
14 | byte[] data;
15 |
16 | public PacketIgnore() {
17 | }
18 |
19 | public PacketIgnore(byte payload[], int off, int len) throws IOException {
20 | this.payload = new byte[len];
21 | System.arraycopy(payload, off, this.payload, 0, len);
22 |
23 | TypesReader tr = new TypesReader(payload, off, len);
24 |
25 | int packet_type = tr.readByte();
26 |
27 | if (packet_type != Packets.SSH_MSG_IGNORE)
28 | throw new IOException("This is not a SSH_MSG_IGNORE packet! ("
29 | + packet_type + ")");
30 |
31 | /* Could parse String body */
32 | }
33 |
34 | public byte[] getPayload() {
35 | if (payload == null) {
36 | TypesWriter tw = new TypesWriter();
37 | tw.writeByte(Packets.SSH_MSG_IGNORE);
38 |
39 | if (data != null)
40 | tw.writeString(data, 0, data.length);
41 | else
42 | tw.writeString("");
43 |
44 | payload = tw.getBytes();
45 | }
46 | return payload;
47 | }
48 |
49 | public void setData(byte[] data) {
50 | this.data = data;
51 | payload = null;
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/src/com/trilead/ssh2/ConnectionMonitor.java:
--------------------------------------------------------------------------------
1 | package com.trilead.ssh2;
2 |
3 | /**
4 | * A
19 | * This is an experimental feature.
20 | *
21 | * You MUST NOT make any assumption about the thread that invokes this
22 | * method.
23 | *
24 | * Please note: if the connection is not connected (e.g., there was no
25 | * successful connect() call), then the invocation of
26 | * {@link Connection#close()} will NOT trigger this method.
27 | *
28 | * @see Connection#addConnectionMonitor(ConnectionMonitor)
29 | *
30 | * @param reason
31 | * Includes an indication why the socket was closed.
32 | */
33 | public void connectionLost(Throwable reason);
34 | }
--------------------------------------------------------------------------------
/src/com/trilead/ssh2/SFTPv3DirectoryEntry.java:
--------------------------------------------------------------------------------
1 | package com.trilead.ssh2;
2 |
3 | /**
4 | * A
22 | * The format of this field is unspecified by the SFTP v3 protocol. It MUST
23 | * be suitable for use in the output of a directory listing command (in
24 | * fact, the recommended operation for a directory listing command is to
25 | * simply display this data). However, clients SHOULD NOT attempt to parse
26 | * the longname field for file attributes; they SHOULD use the attrs field
27 | * instead.
28 | *
29 | * The recommended format for the longname field is as follows:
6 | * SOCKSv5 allows for datagrams to be encapsulated for purposes of integrity
7 | * and/or authenticity. How it should be done is aggreed during the
8 | * authentication stage, and is authentication dependent. This interface is
9 | * provided to allow this encapsulation.
10 | *
11 | * @see Authentication
12 | */
13 | public interface UDPEncapsulation {
14 |
15 | /**
16 | * This method should provide any authentication depended transformation on
17 | * datagrams being send from/to the client.
18 | *
19 | * @param data
20 | * Datagram data (including any SOCKS related bytes), to be
21 | * encapsulated/decapsulated.
22 | * @param out
23 | * Wether the data is being send out. If true method should
24 | * encapsulate/encrypt data, otherwise it should decapsulate/
25 | * decrypt data.
26 | * @throw IOException if for some reason data can be transformed correctly.
27 | * @return Should return byte array containing data after transformation. It
28 | * is possible to return same array as input, if transformation only
29 | * involves bit mangling, and no additional data is being added or
30 | * removed.
31 | */
32 | byte[] udpEncapsulate(byte[] data, boolean out) throws java.io.IOException;
33 | }
34 |
--------------------------------------------------------------------------------
/src/com/trilead/ssh2/ServerHostKeyVerifier.java:
--------------------------------------------------------------------------------
1 | package com.trilead.ssh2;
2 |
3 | /**
4 | * A callback interface used to implement a client specific method of checking
5 | * server host keys.
6 | *
7 | * @author Christian Plattner, plattner@trilead.com
8 | * @version $Id: ServerHostKeyVerifier.java,v 1.1 2007/10/15 12:49:56 cplattne
9 | * Exp $
10 | */
11 |
12 | public interface ServerHostKeyVerifier {
13 | /**
14 | * The actual verifier method, it will be called by the key exchange code on
15 | * EVERY key exchange - this can happen several times during the lifetime of
16 | * a connection.
17 | *
18 | * Note: SSH-2 servers are allowed to change their hostkey at ANY time.
19 | *
20 | * @param hostname
21 | * the hostname used to create the {@link Connection} object
22 | * @param port
23 | * the remote TCP port
24 | * @param serverHostKeyAlgorithm
25 | * the public key algorithm (
13 | * This method should return an array {inputstream,outputstream
14 | * [,UDPEncapsulation]}. The reason for that is that SOCKS5 protocol allows
15 | * to have method specific encapsulation of data on the socket for purposes
16 | * of integrity or security. And this encapsulation should be performed by
17 | * those streams returned from the method. It is also possible to
18 | * encapsulate datagrams. If authentication method supports such
19 | * encapsulation an instance of the UDPEncapsulation interface should be
20 | * returned as third element of the array, otherwise either null should be
21 | * returned as third element, or array should contain only 2 elements.
22 | *
23 | * @param methodId
24 | * Authentication method selected by the server.
25 | * @param proxySocket
26 | * Socket used to conect to the proxy.
27 | * @return Two or three element array containing Input/Output streams which
28 | * should be used on this connection. Third argument is optional and
29 | * should contain an instance of UDPEncapsulation. It should be
30 | * provided if the authentication method used requires any
31 | * encapsulation to be done on the datagrams.
32 | */
33 | Object[] doSocksAuthentication(int methodId, java.net.Socket proxySocket)
34 | throws java.io.IOException;
35 | }
36 |
--------------------------------------------------------------------------------
/src/com/trilead/ssh2/crypto/digest/HashForSSH2Types.java:
--------------------------------------------------------------------------------
1 | package com.trilead.ssh2.crypto.digest;
2 |
3 | import java.math.BigInteger;
4 |
5 | /**
6 | * HashForSSH2Types.
7 | *
8 | * @author Christian Plattner, plattner@trilead.com
9 | * @version $Id: HashForSSH2Types.java,v 1.1 2007/10/15 12:49:57 cplattne Exp $
10 | */
11 | public class HashForSSH2Types {
12 | Digest md;
13 |
14 | public HashForSSH2Types(Digest md) {
15 | this.md = md;
16 | }
17 |
18 | public HashForSSH2Types(String type) {
19 | if (type.equals("SHA1")) {
20 | md = new SHA1();
21 | } else if (type.equals("MD5")) {
22 | md = new MD5();
23 | } else
24 | throw new IllegalArgumentException("Unknown algorithm " + type);
25 | }
26 |
27 | public byte[] getDigest() {
28 | byte[] tmp = new byte[md.getDigestLength()];
29 | getDigest(tmp);
30 | return tmp;
31 | }
32 |
33 | public void getDigest(byte[] out) {
34 | getDigest(out, 0);
35 | }
36 |
37 | public void getDigest(byte[] out, int off) {
38 | md.digest(out, off);
39 | }
40 |
41 | public int getDigestLength() {
42 | return md.getDigestLength();
43 | }
44 |
45 | public void reset() {
46 | md.reset();
47 | }
48 |
49 | public void updateBigInt(BigInteger b) {
50 | updateByteString(b.toByteArray());
51 | }
52 |
53 | public void updateByte(byte b) {
54 | /* HACK - to test it with J2ME */
55 | byte[] tmp = new byte[1];
56 | tmp[0] = b;
57 | md.update(tmp);
58 | }
59 |
60 | public void updateBytes(byte[] b) {
61 | md.update(b);
62 | }
63 |
64 | public void updateByteString(byte[] b) {
65 | updateUINT32(b.length);
66 | updateBytes(b);
67 | }
68 |
69 | public void updateUINT32(int v) {
70 | md.update((byte) (v >> 24));
71 | md.update((byte) (v >> 16));
72 | md.update((byte) (v >> 8));
73 | md.update((byte) (v));
74 | }
75 | }
76 |
--------------------------------------------------------------------------------
/src/com/trilead/ssh2/packets/PacketOpenSessionChannel.java:
--------------------------------------------------------------------------------
1 | package com.trilead.ssh2.packets;
2 |
3 | import java.io.IOException;
4 |
5 | /**
6 | * PacketOpenSessionChannel.
7 | *
8 | * @author Christian Plattner, plattner@trilead.com
9 | * @version $Id: PacketOpenSessionChannel.java,v 1.1 2007/10/15 12:49:55
10 | * cplattne Exp $
11 | */
12 | public class PacketOpenSessionChannel {
13 | byte[] payload;
14 |
15 | int channelID;
16 | int initialWindowSize;
17 | int maxPacketSize;
18 |
19 | public PacketOpenSessionChannel(byte payload[], int off, int len)
20 | throws IOException {
21 | this.payload = new byte[len];
22 | System.arraycopy(payload, off, this.payload, 0, len);
23 |
24 | TypesReader tr = new TypesReader(payload);
25 |
26 | int packet_type = tr.readByte();
27 |
28 | if (packet_type != Packets.SSH_MSG_CHANNEL_OPEN)
29 | throw new IOException("This is not a SSH_MSG_CHANNEL_OPEN! ("
30 | + packet_type + ")");
31 |
32 | channelID = tr.readUINT32();
33 | initialWindowSize = tr.readUINT32();
34 | maxPacketSize = tr.readUINT32();
35 |
36 | if (tr.remain() != 0)
37 | throw new IOException("Padding in SSH_MSG_CHANNEL_OPEN packet!");
38 | }
39 |
40 | public PacketOpenSessionChannel(int channelID, int initialWindowSize,
41 | int maxPacketSize) {
42 | this.channelID = channelID;
43 | this.initialWindowSize = initialWindowSize;
44 | this.maxPacketSize = maxPacketSize;
45 | }
46 |
47 | public byte[] getPayload() {
48 | if (payload == null) {
49 | TypesWriter tw = new TypesWriter();
50 | tw.writeByte(Packets.SSH_MSG_CHANNEL_OPEN);
51 | tw.writeString("session");
52 | tw.writeUINT32(channelID);
53 | tw.writeUINT32(initialWindowSize);
54 | tw.writeUINT32(maxPacketSize);
55 | payload = tw.getBytes();
56 | }
57 | return payload;
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/src/com/trilead/ssh2/packets/PacketUserauthRequestNone.java:
--------------------------------------------------------------------------------
1 | package com.trilead.ssh2.packets;
2 |
3 | import java.io.IOException;
4 |
5 | /**
6 | * PacketUserauthRequestPassword.
7 | *
8 | * @author Christian Plattner, plattner@trilead.com
9 | * @version $Id: PacketUserauthRequestNone.java,v 1.1 2007/10/15 12:49:55
10 | * cplattne Exp $
11 | */
12 | public class PacketUserauthRequestNone {
13 | byte[] payload;
14 |
15 | String userName;
16 | String serviceName;
17 |
18 | public PacketUserauthRequestNone(byte payload[], int off, int len)
19 | throws IOException {
20 | this.payload = new byte[len];
21 | System.arraycopy(payload, off, this.payload, 0, len);
22 |
23 | TypesReader tr = new TypesReader(payload, off, len);
24 |
25 | int packet_type = tr.readByte();
26 |
27 | if (packet_type != Packets.SSH_MSG_USERAUTH_REQUEST)
28 | throw new IOException("This is not a SSH_MSG_USERAUTH_REQUEST! ("
29 | + packet_type + ")");
30 |
31 | userName = tr.readString();
32 | serviceName = tr.readString();
33 |
34 | String method = tr.readString();
35 |
36 | if (method.equals("none") == false)
37 | throw new IOException(
38 | "This is not a SSH_MSG_USERAUTH_REQUEST with type none!");
39 |
40 | if (tr.remain() != 0)
41 | throw new IOException("Padding in SSH_MSG_USERAUTH_REQUEST packet!");
42 | }
43 |
44 | public PacketUserauthRequestNone(String serviceName, String user) {
45 | this.serviceName = serviceName;
46 | this.userName = user;
47 | }
48 |
49 | public byte[] getPayload() {
50 | if (payload == null) {
51 | TypesWriter tw = new TypesWriter();
52 | tw.writeByte(Packets.SSH_MSG_USERAUTH_REQUEST);
53 | tw.writeString(userName);
54 | tw.writeString(serviceName);
55 | tw.writeString("none");
56 | payload = tw.getBytes();
57 | }
58 | return payload;
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/src/com/trilead/ssh2/packets/PacketUserauthRequestPublicKey.java:
--------------------------------------------------------------------------------
1 | package com.trilead.ssh2.packets;
2 |
3 | import java.io.IOException;
4 |
5 | /**
6 | * PacketUserauthRequestPublicKey.
7 | *
8 | * @author Christian Plattner, plattner@trilead.com
9 | * @version $Id: PacketUserauthRequestPublicKey.java,v 1.1 2007/10/15 12:49:55
10 | * cplattne Exp $
11 | */
12 | public class PacketUserauthRequestPublicKey {
13 | byte[] payload;
14 |
15 | String userName;
16 | String serviceName;
17 | String password;
18 | String pkAlgoName;
19 | byte[] pk;
20 | byte[] sig;
21 |
22 | public PacketUserauthRequestPublicKey(byte payload[], int off, int len)
23 | throws IOException {
24 | this.payload = new byte[len];
25 | System.arraycopy(payload, off, this.payload, 0, len);
26 |
27 | TypesReader tr = new TypesReader(payload, off, len);
28 |
29 | int packet_type = tr.readByte();
30 |
31 | if (packet_type != Packets.SSH_MSG_USERAUTH_REQUEST)
32 | throw new IOException("This is not a SSH_MSG_USERAUTH_REQUEST! ("
33 | + packet_type + ")");
34 |
35 | throw new IOException("Not implemented!");
36 | }
37 |
38 | public PacketUserauthRequestPublicKey(String serviceName, String user,
39 | String pkAlgorithmName, byte[] pk, byte[] sig) {
40 | this.serviceName = serviceName;
41 | this.userName = user;
42 | this.pkAlgoName = pkAlgorithmName;
43 | this.pk = pk;
44 | this.sig = sig;
45 | }
46 |
47 | public byte[] getPayload() {
48 | if (payload == null) {
49 | TypesWriter tw = new TypesWriter();
50 | tw.writeByte(Packets.SSH_MSG_USERAUTH_REQUEST);
51 | tw.writeString(userName);
52 | tw.writeString(serviceName);
53 | tw.writeString("publickey");
54 | tw.writeBoolean(true);
55 | tw.writeString(pkAlgoName);
56 | tw.writeString(pk, 0, pk.length);
57 | tw.writeString(sig, 0, sig.length);
58 | payload = tw.getBytes();
59 | }
60 | return payload;
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/src/com/trilead/ssh2/LocalPortForwarder.java:
--------------------------------------------------------------------------------
1 | package com.trilead.ssh2;
2 |
3 | import java.io.IOException;
4 | import java.net.InetSocketAddress;
5 |
6 | import com.trilead.ssh2.channel.ChannelManager;
7 | import com.trilead.ssh2.channel.LocalAcceptThread;
8 |
9 | /**
10 | * A
29 | * Tries to look up message which corresponds to this error code.
30 | *
31 | * @param errCode
32 | * Error code for this exception.
33 | */
34 | public SocksException(int errCode) {
35 | this.errCode = errCode;
36 | if ((errCode >> 16) == 0) {
37 | // Server reply error message
38 | errString = errCode <= serverReplyMessage.length ? serverReplyMessage[errCode]
39 | : UNASSIGNED_ERROR_MESSAGE;
40 | } else {
41 | // Local error
42 | errCode = (errCode >> 16) - 1;
43 | errString = errCode <= localErrorMessage.length ? localErrorMessage[errCode]
44 | : UNASSIGNED_ERROR_MESSAGE;
45 | }
46 | }
47 |
48 | /**
49 | * Constructs a SocksException with given error code and message.
50 | *
51 | * @param errCode
52 | * Error code.
53 | * @param errString
54 | * Error Message.
55 | */
56 | public SocksException(int errCode, String errString) {
57 | this.errCode = errCode;
58 | this.errString = errString;
59 | }
60 |
61 | /**
62 | * Get the error code associated with this exception.
63 | *
64 | * @return Error code associated with this exception.
65 | */
66 | public int getErrorCode() {
67 | return errCode;
68 | }
69 | /**
70 | * Get human readable representation of this exception.
71 | *
72 | * @return String represntation of this exception.
73 | */
74 | @Override
75 | public String toString() {
76 | return errString;
77 | }
78 |
79 | }// End of SocksException class
80 |
81 |
--------------------------------------------------------------------------------
/src/com/trilead/ssh2/LocalStreamForwarder.java:
--------------------------------------------------------------------------------
1 | package com.trilead.ssh2;
2 |
3 | import java.io.IOException;
4 | import java.io.InputStream;
5 | import java.io.OutputStream;
6 |
7 | import com.trilead.ssh2.channel.Channel;
8 | import com.trilead.ssh2.channel.ChannelManager;
9 | import com.trilead.ssh2.channel.LocalAcceptThread;
10 |
11 | /**
12 | * A
23 | * Some copy-paste information from the standard: a command line interface
24 | * (CLI) client SHOULD print the name and instruction (if non-empty), adding
25 | * newlines. Then for each prompt in turn, the client SHOULD display the
26 | * prompt and read the user input. The name and instruction fields MAY be
27 | * empty strings, the client MUST be prepared to handle this correctly. The
28 | * prompt field(s) MUST NOT be empty strings.
29 | *
30 | * Please refer to draft-ietf-secsh-auth-kbdinteract-XX.txt for the details.
31 | *
32 | * Note: clients SHOULD use control character filtering as discussed in
33 | * RFC4251 to avoid attacks by including terminal control characters in the
34 | * fields to be displayed.
35 | *
36 | * @param name
37 | * the name String sent by the server.
38 | * @param instruction
39 | * the instruction String sent by the server.
40 | * @param numPrompts
41 | * number of prompts - may be zero (in this case, you should just
42 | * return a String array of length zero).
43 | * @param prompt
44 | * an array (length
62 | * Please note: if you want to use basic authentication, then both
63 | *
65 | * Here is an example:
66 | *
67 | *
13 | * Implemented having large scale programs in mind: if you open many concurrent
14 | * SSH connections that rely on timeouts, then there will be only one timeout
15 | * thread. Once all timeouts have expired/are cancelled, the thread will (sooner
16 | * or later) exit. Only after new timeouts arrive a new thread (singleton) will
17 | * be instantiated.
18 | *
19 | * @author Christian Plattner, plattner@trilead.com
20 | * @version $Id: TimeoutService.java,v 1.1 2007/10/15 12:49:57 cplattne Exp $
21 | */
22 | public class TimeoutService {
23 | private static class TimeoutThread extends Thread {
24 | @Override
25 | public void run() {
26 | synchronized (todolist) {
27 | while (true) {
28 | if (todolist.size() == 0) {
29 | timeoutThread = null;
30 | return;
31 | }
32 |
33 | long now = System.currentTimeMillis();
34 |
35 | TimeoutToken tt = (TimeoutToken) todolist.getFirst();
36 |
37 | if (tt.runTime > now) {
38 | /* Not ready yet, sleep a little bit */
39 |
40 | try {
41 | todolist.wait(tt.runTime - now);
42 | } catch (InterruptedException e) {
43 | }
44 |
45 | /*
46 | * We cannot simply go on, since it could be that the
47 | * token was removed (cancelled) or another one has been
48 | * inserted in the meantime.
49 | */
50 |
51 | continue;
52 | }
53 |
54 | todolist.removeFirst();
55 |
56 | try {
57 | tt.handler.run();
58 | } catch (Exception e) {
59 | StringWriter sw = new StringWriter();
60 | e.printStackTrace(new PrintWriter(sw));
61 | log.log(20,
62 | "Exeception in Timeout handler:"
63 | + e.getMessage() + "(" + sw.toString()
64 | + ")");
65 | }
66 | }
67 | }
68 | }
69 | }
70 |
71 | public static class TimeoutToken implements Comparable {
72 | private long runTime;
73 | private Runnable handler;
74 |
75 | private TimeoutToken(long runTime, Runnable handler) {
76 | this.runTime = runTime;
77 | this.handler = handler;
78 | }
79 |
80 | @Override
81 | public int compareTo(Object o) {
82 | TimeoutToken t = (TimeoutToken) o;
83 | if (runTime > t.runTime)
84 | return 1;
85 | if (runTime == t.runTime)
86 | return 0;
87 | return -1;
88 | }
89 | }
90 |
91 | private static final Logger log = Logger.getLogger(TimeoutService.class);
92 |
93 | /* The list object is also used for locking purposes */
94 | private static final LinkedList todolist = new LinkedList();
95 |
96 | private static Thread timeoutThread = null;
97 |
98 | /**
99 | * It is assumed that the passed handler will not execute for a long time.
100 | *
101 | * @param runTime
102 | * @param handler
103 | * @return a TimeoutToken that can be used to cancel the timeout.
104 | */
105 | public static final TimeoutToken addTimeoutHandler(long runTime,
106 | Runnable handler) {
107 | TimeoutToken token = new TimeoutToken(runTime, handler);
108 |
109 | synchronized (todolist) {
110 | todolist.add(token);
111 | Collections.sort(todolist);
112 |
113 | if (timeoutThread != null)
114 | timeoutThread.interrupt();
115 | else {
116 | timeoutThread = new TimeoutThread();
117 | timeoutThread.setDaemon(true);
118 | timeoutThread.start();
119 | }
120 | }
121 |
122 | return token;
123 | }
124 |
125 | public static final void cancelTimeoutHandler(TimeoutToken token) {
126 | synchronized (todolist) {
127 | todolist.remove(token);
128 |
129 | if (timeoutThread != null)
130 | timeoutThread.interrupt();
131 | }
132 | }
133 |
134 | }
135 |
--------------------------------------------------------------------------------
/src/com/trilead/ssh2/DHGexParameters.java:
--------------------------------------------------------------------------------
1 | package com.trilead.ssh2;
2 |
3 | /**
4 | * A
7 | * Depending on which constructor is used, either the use of a
8 | *
55 | * Note: older OpenSSH servers don't understand this request, in which case
56 | * you should use the {@link #DHGexParameters(int)} constructor.
57 | *
58 | * All values have to be >= 1024 and <= 8192. Furthermore,
59 | * min_group_len <= pref_group_len <= max_group_len.
60 | *
61 | * @param min_group_len
62 | * @param pref_group_len
63 | * @param max_group_len
64 | */
65 | public DHGexParameters(int min_group_len, int pref_group_len,
66 | int max_group_len) {
67 | if ((min_group_len < MIN_ALLOWED) || (min_group_len > MAX_ALLOWED))
68 | throw new IllegalArgumentException("min_group_len out of range!");
69 |
70 | if ((pref_group_len < MIN_ALLOWED) || (pref_group_len > MAX_ALLOWED))
71 | throw new IllegalArgumentException("pref_group_len out of range!");
72 |
73 | if ((max_group_len < MIN_ALLOWED) || (max_group_len > MAX_ALLOWED))
74 | throw new IllegalArgumentException("max_group_len out of range!");
75 |
76 | if ((pref_group_len < min_group_len)
77 | || (pref_group_len > max_group_len))
78 | throw new IllegalArgumentException(
79 | "pref_group_len is incompatible with min and max!");
80 |
81 | if (max_group_len < min_group_len)
82 | throw new IllegalArgumentException(
83 | "max_group_len must not be smaller than min_group_len!");
84 |
85 | this.min_group_len = min_group_len;
86 | this.pref_group_len = pref_group_len;
87 | this.max_group_len = max_group_len;
88 | }
89 |
90 | /**
91 | * Get the maximum group length.
92 | *
93 | * @return the maximum group length, may be ConnectionMonitor is used to get notified when the underlying
5 | * socket of a connection is closed.
6 | *
7 | * @author Christian Plattner, plattner@trilead.com
8 | * @version $Id: ConnectionMonitor.java,v 1.1 2007/10/15 12:49:56 cplattne Exp $
9 | */
10 |
11 | public interface ConnectionMonitor {
12 | /**
13 | * This method is called after the connection's underlying socket has been
14 | * closed. E.g., due to the {@link Connection#close()} request of the user,
15 | * if the peer closed the connection, due to a fatal error during connect()
16 | * (also if the socket cannot be established) or if a fatal error occured on
17 | * an established connection.
18 | * SFTPv3DirectoryEntry as returned by
5 | * {@link SFTPv3Client#ls(String)}.
6 | *
7 | * @author Christian Plattner, plattner@trilead.com
8 | * @version $Id: SFTPv3DirectoryEntry.java,v 1.1 2007/10/15 12:49:56 cplattne
9 | * Exp $
10 | */
11 |
12 | public class SFTPv3DirectoryEntry {
13 | /**
14 | * A relative name within the directory, without any path components.
15 | */
16 | public String filename;
17 |
18 | /**
19 | * An expanded format for the file name, similar to what is returned by
20 | * "ls -l" on Un*x systems.
21 | *
30 | * -rwxr-xr-x 1 mjos staff 348911 Mar 25 14:29 t-filexfer
31 | */
32 | public String longEntry;
33 |
34 | /**
35 | * The attributes of this entry.
36 | */
37 | public SFTPv3FileAttributes attributes;
38 | }
39 |
--------------------------------------------------------------------------------
/src/com/trilead/ssh2/packets/PacketKexDhGexReply.java:
--------------------------------------------------------------------------------
1 | package com.trilead.ssh2.packets;
2 |
3 | import java.io.IOException;
4 | import java.math.BigInteger;
5 |
6 | /**
7 | * PacketKexDhGexReply.
8 | *
9 | * @author Christian Plattner, plattner@trilead.com
10 | * @version $Id: PacketKexDhGexReply.java,v 1.1 2007/10/15 12:49:55 cplattne Exp
11 | * $
12 | */
13 | public class PacketKexDhGexReply {
14 | byte[] payload;
15 |
16 | byte[] hostKey;
17 | BigInteger f;
18 | byte[] signature;
19 |
20 | public PacketKexDhGexReply(byte payload[], int off, int len)
21 | throws IOException {
22 | this.payload = new byte[len];
23 | System.arraycopy(payload, off, this.payload, 0, len);
24 |
25 | TypesReader tr = new TypesReader(payload, off, len);
26 |
27 | int packet_type = tr.readByte();
28 |
29 | if (packet_type != Packets.SSH_MSG_KEX_DH_GEX_REPLY)
30 | throw new IOException("This is not a SSH_MSG_KEX_DH_GEX_REPLY! ("
31 | + packet_type + ")");
32 |
33 | hostKey = tr.readByteString();
34 | f = tr.readMPINT();
35 | signature = tr.readByteString();
36 |
37 | if (tr.remain() != 0)
38 | throw new IOException("PADDING IN SSH_MSG_KEX_DH_GEX_REPLY!");
39 | }
40 |
41 | public BigInteger getF() {
42 | return f;
43 | }
44 |
45 | public byte[] getHostKey() {
46 | return hostKey;
47 | }
48 |
49 | public byte[] getSignature() {
50 | return signature;
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/src/respite/http/injector/GradientButton.java:
--------------------------------------------------------------------------------
1 | /*
2 | * To change this license header, choose License Headers in Project Properties.
3 | * To change this template file, choose Tools | Templates
4 | * and open the template in the editor.
5 | */
6 | package respite.http.injector;
7 |
8 | import java.awt.Color;
9 | import java.awt.GradientPaint;
10 | import java.awt.Graphics;
11 | import java.awt.Graphics2D;
12 | import java.awt.Point;
13 | import javax.swing.JButton;
14 |
15 | /**
16 | *
17 | * @author user
18 | */
19 | public class GradientButton extends JButton {
20 | private GradientButton() {
21 | super("Gradient Button");
22 | setContentAreaFilled(false);
23 | setFocusPainted(false); // used for demonstration
24 | }
25 |
26 | @Override
27 | protected void paintComponent(Graphics g) {
28 | final Graphics2D g2 = (Graphics2D) g.create();
29 | g2.setPaint(new GradientPaint(
30 | new Point(0, 0),
31 | Color.WHITE,
32 | new Point(0, getHeight()),
33 | Color.PINK.darker()));
34 | g2.fillRect(0, 0, getWidth(), getHeight());
35 | g2.dispose();
36 |
37 | super.paintComponent(g);
38 | }
39 |
40 | public static GradientButton newInstance() {
41 | return new GradientButton();
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/src/com/trilead/ssh2/packets/PacketServiceRequest.java:
--------------------------------------------------------------------------------
1 | package com.trilead.ssh2.packets;
2 |
3 | import java.io.IOException;
4 |
5 | /**
6 | * PacketServiceRequest.
7 | *
8 | * @author Christian Plattner, plattner@trilead.com
9 | * @version $Id: PacketServiceRequest.java,v 1.1 2007/10/15 12:49:55 cplattne
10 | * Exp $
11 | */
12 | public class PacketServiceRequest {
13 | byte[] payload;
14 |
15 | String serviceName;
16 |
17 | public PacketServiceRequest(byte payload[], int off, int len)
18 | throws IOException {
19 | this.payload = new byte[len];
20 | System.arraycopy(payload, off, this.payload, 0, len);
21 |
22 | TypesReader tr = new TypesReader(payload, off, len);
23 |
24 | int packet_type = tr.readByte();
25 |
26 | if (packet_type != Packets.SSH_MSG_SERVICE_REQUEST)
27 | throw new IOException("This is not a SSH_MSG_SERVICE_REQUEST! ("
28 | + packet_type + ")");
29 |
30 | serviceName = tr.readString();
31 |
32 | if (tr.remain() != 0)
33 | throw new IOException("Padding in SSH_MSG_SERVICE_REQUEST packet!");
34 | }
35 |
36 | public PacketServiceRequest(String serviceName) {
37 | this.serviceName = serviceName;
38 | }
39 |
40 | public byte[] getPayload() {
41 | if (payload == null) {
42 | TypesWriter tw = new TypesWriter();
43 | tw.writeByte(Packets.SSH_MSG_SERVICE_REQUEST);
44 | tw.writeString(serviceName);
45 | payload = tw.getBytes();
46 | }
47 | return payload;
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/src/com/trilead/ssh2/packets/PacketDisconnect.java:
--------------------------------------------------------------------------------
1 | package com.trilead.ssh2.packets;
2 |
3 | import java.io.IOException;
4 |
5 | /**
6 | * PacketDisconnect.
7 | *
8 | * @author Christian Plattner, plattner@trilead.com
9 | * @version $Id: PacketDisconnect.java,v 1.2 2008/04/01 12:38:09 cplattne Exp $
10 | */
11 | public class PacketDisconnect {
12 | byte[] payload;
13 |
14 | int reason;
15 | String desc;
16 | String lang;
17 |
18 | public PacketDisconnect(byte payload[], int off, int len)
19 | throws IOException {
20 | this.payload = new byte[len];
21 | System.arraycopy(payload, off, this.payload, 0, len);
22 |
23 | TypesReader tr = new TypesReader(payload, off, len);
24 |
25 | int packet_type = tr.readByte();
26 |
27 | if (packet_type != Packets.SSH_MSG_DISCONNECT)
28 | throw new IOException("This is not a Disconnect Packet! ("
29 | + packet_type + ")");
30 |
31 | reason = tr.readUINT32();
32 | desc = tr.readString();
33 | lang = tr.readString();
34 | }
35 |
36 | public PacketDisconnect(int reason, String desc, String lang) {
37 | this.reason = reason;
38 | this.desc = desc;
39 | this.lang = lang;
40 | }
41 |
42 | public byte[] getPayload() {
43 | if (payload == null) {
44 | TypesWriter tw = new TypesWriter();
45 | tw.writeByte(Packets.SSH_MSG_DISCONNECT);
46 | tw.writeUINT32(reason);
47 | tw.writeString(desc);
48 | tw.writeString(lang);
49 | payload = tw.getBytes();
50 | }
51 | return payload;
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/src/net/sourceforge/jsocks/UDPEncapsulation.java:
--------------------------------------------------------------------------------
1 | package net.sourceforge.jsocks;
2 |
3 | /**
4 | * This interface provides for datagram encapsulation for SOCKSv5 protocol.
5 | * ssh-rsa or
26 | * ssh-dss)
27 | * @param serverHostKey
28 | * the server's public key blob
29 | * @return if the client wants to accept the server's host key - if not, the
30 | * connection will be closed.
31 | * @throws Exception
32 | * Will be wrapped with an IOException, extended version of
33 | * returning false =)
34 | */
35 | public boolean verifyServerHostKey(String hostname, int port,
36 | String serverHostKeyAlgorithm, byte[] serverHostKey)
37 | throws Exception;
38 | }
39 |
--------------------------------------------------------------------------------
/src/com/trilead/ssh2/packets/PacketUserauthFailure.java:
--------------------------------------------------------------------------------
1 | package com.trilead.ssh2.packets;
2 |
3 | import java.io.IOException;
4 |
5 | /**
6 | * PacketUserauthBanner.
7 | *
8 | * @author Christian Plattner, plattner@trilead.com
9 | * @version $Id: PacketUserauthFailure.java,v 1.1 2007/10/15 12:49:55 cplattne
10 | * Exp $
11 | */
12 | public class PacketUserauthFailure {
13 | byte[] payload;
14 |
15 | String[] authThatCanContinue;
16 | boolean partialSuccess;
17 |
18 | public PacketUserauthFailure(byte payload[], int off, int len)
19 | throws IOException {
20 | this.payload = new byte[len];
21 | System.arraycopy(payload, off, this.payload, 0, len);
22 |
23 | TypesReader tr = new TypesReader(payload, off, len);
24 |
25 | int packet_type = tr.readByte();
26 |
27 | if (packet_type != Packets.SSH_MSG_USERAUTH_FAILURE)
28 | throw new IOException("This is not a SSH_MSG_USERAUTH_FAILURE! ("
29 | + packet_type + ")");
30 |
31 | authThatCanContinue = tr.readNameList();
32 | partialSuccess = tr.readBoolean();
33 |
34 | if (tr.remain() != 0)
35 | throw new IOException("Padding in SSH_MSG_USERAUTH_FAILURE packet!");
36 | }
37 |
38 | public PacketUserauthFailure(String[] authThatCanContinue,
39 | boolean partialSuccess) {
40 | this.authThatCanContinue = authThatCanContinue;
41 | this.partialSuccess = partialSuccess;
42 | }
43 |
44 | public String[] getAuthThatCanContinue() {
45 | return authThatCanContinue;
46 | }
47 |
48 | public boolean isPartialSuccess() {
49 | return partialSuccess;
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/src/com/trilead/ssh2/ConnectionInfo.java:
--------------------------------------------------------------------------------
1 | package com.trilead.ssh2;
2 |
3 | /**
4 | * In most cases you probably do not need the information contained in here.
5 | *
6 | * @author Christian Plattner, plattner@trilead.com
7 | * @version $Id: ConnectionInfo.java,v 1.1 2007/10/15 12:49:56 cplattne Exp $
8 | */
9 | public class ConnectionInfo {
10 | /**
11 | * The used key exchange (KEX) algorithm in the latest key exchange.
12 | */
13 | public String keyExchangeAlgorithm;
14 |
15 | /**
16 | * The currently used crypto algorithm for packets from to the client to the
17 | * server.
18 | */
19 | public String clientToServerCryptoAlgorithm;
20 | /**
21 | * The currently used crypto algorithm for packets from to the server to the
22 | * client.
23 | */
24 | public String serverToClientCryptoAlgorithm;
25 |
26 | /**
27 | * The currently used MAC algorithm for packets from to the client to the
28 | * server.
29 | */
30 | public String clientToServerMACAlgorithm;
31 | /**
32 | * The currently used MAC algorithm for packets from to the server to the
33 | * client.
34 | */
35 | public String serverToClientMACAlgorithm;
36 |
37 | /**
38 | * The type of the server host key (currently either "ssh-dss" or
39 | * "ssh-rsa").
40 | */
41 | public String serverHostKeyAlgorithm;
42 | /**
43 | * The server host key that was sent during the latest key exchange.
44 | */
45 | public byte[] serverHostKey;
46 |
47 | /**
48 | * Number of kex exchanges performed on this connection so far.
49 | */
50 | public int keyExchangeCounter = 0;
51 | }
52 |
--------------------------------------------------------------------------------
/src/com/trilead/ssh2/crypto/cipher/CTRMode.java:
--------------------------------------------------------------------------------
1 | package com.trilead.ssh2.crypto.cipher;
2 |
3 | /**
4 | * This is CTR mode as described in draft-ietf-secsh-newmodes-XY.txt
5 | *
6 | * @author Christian Plattner, plattner@trilead.com
7 | * @version $Id: CTRMode.java,v 1.1 2007/10/15 12:49:55 cplattne Exp $
8 | */
9 | public class CTRMode implements BlockCipher {
10 | byte[] X;
11 | byte[] Xenc;
12 |
13 | BlockCipher bc;
14 | int blockSize;
15 | boolean doEncrypt;
16 |
17 | int count = 0;
18 |
19 | public CTRMode(BlockCipher tc, byte[] iv, boolean doEnc)
20 | throws IllegalArgumentException {
21 | bc = tc;
22 | blockSize = bc.getBlockSize();
23 | doEncrypt = doEnc;
24 |
25 | if (blockSize != iv.length)
26 | throw new IllegalArgumentException("IV must be " + blockSize
27 | + " bytes long! (currently " + iv.length + ")");
28 |
29 | X = new byte[blockSize];
30 | Xenc = new byte[blockSize];
31 |
32 | System.arraycopy(iv, 0, X, 0, blockSize);
33 | }
34 |
35 | @Override
36 | public final int getBlockSize() {
37 | return blockSize;
38 | }
39 |
40 | @Override
41 | public void init(boolean forEncryption, byte[] key) {
42 | }
43 |
44 | @Override
45 | public final void transformBlock(byte[] src, int srcoff, byte[] dst,
46 | int dstoff) {
47 | bc.transformBlock(X, 0, Xenc, 0);
48 |
49 | for (int i = 0; i < blockSize; i++) {
50 | dst[dstoff + i] = (byte) (src[srcoff + i] ^ Xenc[i]);
51 | }
52 |
53 | for (int i = (blockSize - 1); i >= 0; i--) {
54 | X[i]++;
55 | if (X[i] != 0)
56 | break;
57 |
58 | }
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/src/com/trilead/ssh2/packets/PacketServiceAccept.java:
--------------------------------------------------------------------------------
1 | package com.trilead.ssh2.packets;
2 |
3 | import java.io.IOException;
4 |
5 | /**
6 | * PacketServiceAccept.
7 | *
8 | * @author Christian Plattner, plattner@trilead.com
9 | * @version $Id: PacketServiceAccept.java,v 1.2 2008/04/01 12:38:09 cplattne Exp
10 | * $
11 | */
12 | public class PacketServiceAccept {
13 | byte[] payload;
14 |
15 | String serviceName;
16 |
17 | public PacketServiceAccept(byte payload[], int off, int len)
18 | throws IOException {
19 | this.payload = new byte[len];
20 | System.arraycopy(payload, off, this.payload, 0, len);
21 |
22 | TypesReader tr = new TypesReader(payload, off, len);
23 |
24 | int packet_type = tr.readByte();
25 |
26 | if (packet_type != Packets.SSH_MSG_SERVICE_ACCEPT)
27 | throw new IOException("This is not a SSH_MSG_SERVICE_ACCEPT! ("
28 | + packet_type + ")");
29 |
30 | /*
31 | * Be clever in case the server is not. Some servers seem to violate
32 | * RFC4253
33 | */
34 |
35 | if (tr.remain() > 0) {
36 | serviceName = tr.readString();
37 | } else {
38 | serviceName = "";
39 | }
40 |
41 | if (tr.remain() != 0)
42 | throw new IOException("Padding in SSH_MSG_SERVICE_ACCEPT packet!");
43 | }
44 |
45 | public PacketServiceAccept(String serviceName) {
46 | this.serviceName = serviceName;
47 | }
48 |
49 | public byte[] getPayload() {
50 | if (payload == null) {
51 | TypesWriter tw = new TypesWriter();
52 | tw.writeByte(Packets.SSH_MSG_SERVICE_ACCEPT);
53 | tw.writeString(serviceName);
54 | payload = tw.getBytes();
55 | }
56 | return payload;
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/src/com/trilead/ssh2/packets/PacketUserauthBanner.java:
--------------------------------------------------------------------------------
1 | package com.trilead.ssh2.packets;
2 |
3 | import java.io.IOException;
4 |
5 | /**
6 | * PacketUserauthBanner.
7 | *
8 | * @author Christian Plattner, plattner@trilead.com
9 | * @version $Id: PacketUserauthBanner.java,v 1.1 2007/10/15 12:49:55 cplattne
10 | * Exp $
11 | */
12 | public class PacketUserauthBanner {
13 | byte[] payload;
14 |
15 | String message;
16 | String language;
17 |
18 | public PacketUserauthBanner(byte payload[], int off, int len)
19 | throws IOException {
20 | this.payload = new byte[len];
21 | System.arraycopy(payload, off, this.payload, 0, len);
22 |
23 | TypesReader tr = new TypesReader(payload, off, len);
24 |
25 | int packet_type = tr.readByte();
26 |
27 | if (packet_type != Packets.SSH_MSG_USERAUTH_BANNER)
28 | throw new IOException("This is not a SSH_MSG_USERAUTH_BANNER! ("
29 | + packet_type + ")");
30 |
31 | message = tr.readString("UTF-8");
32 | language = tr.readString();
33 |
34 | if (tr.remain() != 0)
35 | throw new IOException("Padding in SSH_MSG_USERAUTH_REQUEST packet!");
36 | }
37 |
38 | public PacketUserauthBanner(String message, String language) {
39 | this.message = message;
40 | this.language = language;
41 | }
42 |
43 | public String getBanner() {
44 | return message;
45 | }
46 |
47 | public byte[] getPayload() {
48 | if (payload == null) {
49 | TypesWriter tw = new TypesWriter();
50 | tw.writeByte(Packets.SSH_MSG_USERAUTH_BANNER);
51 | tw.writeString(message);
52 | tw.writeString(language);
53 | payload = tw.getBytes();
54 | }
55 | return payload;
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/src/com/trilead/ssh2/sftp/Packet.java:
--------------------------------------------------------------------------------
1 | package com.trilead.ssh2.sftp;
2 |
3 | /**
4 | *
5 | * SFTP Paket Types
6 | *
7 | * @author Christian Plattner, plattner@trilead.com
8 | * @version $Id: Packet.java,v 1.1 2007/10/15 12:49:55 cplattne Exp $
9 | *
10 | */
11 | public class Packet {
12 | public static final int SSH_FXP_INIT = 1;
13 | public static final int SSH_FXP_VERSION = 2;
14 | public static final int SSH_FXP_OPEN = 3;
15 | public static final int SSH_FXP_CLOSE = 4;
16 | public static final int SSH_FXP_READ = 5;
17 | public static final int SSH_FXP_WRITE = 6;
18 | public static final int SSH_FXP_LSTAT = 7;
19 | public static final int SSH_FXP_FSTAT = 8;
20 | public static final int SSH_FXP_SETSTAT = 9;
21 | public static final int SSH_FXP_FSETSTAT = 10;
22 | public static final int SSH_FXP_OPENDIR = 11;
23 | public static final int SSH_FXP_READDIR = 12;
24 | public static final int SSH_FXP_REMOVE = 13;
25 | public static final int SSH_FXP_MKDIR = 14;
26 | public static final int SSH_FXP_RMDIR = 15;
27 | public static final int SSH_FXP_REALPATH = 16;
28 | public static final int SSH_FXP_STAT = 17;
29 | public static final int SSH_FXP_RENAME = 18;
30 | public static final int SSH_FXP_READLINK = 19;
31 | public static final int SSH_FXP_SYMLINK = 20;
32 |
33 | public static final int SSH_FXP_STATUS = 101;
34 | public static final int SSH_FXP_HANDLE = 102;
35 | public static final int SSH_FXP_DATA = 103;
36 | public static final int SSH_FXP_NAME = 104;
37 | public static final int SSH_FXP_ATTRS = 105;
38 |
39 | public static final int SSH_FXP_EXTENDED = 200;
40 | public static final int SSH_FXP_EXTENDED_REPLY = 201;
41 | }
42 |
--------------------------------------------------------------------------------
/src/com/trilead/ssh2/packets/PacketSessionX11Request.java:
--------------------------------------------------------------------------------
1 | package com.trilead.ssh2.packets;
2 |
3 | /**
4 | * PacketSessionX11Request.
5 | *
6 | * @author Christian Plattner, plattner@trilead.com
7 | * @version $Id: PacketSessionX11Request.java,v 1.1 2007/10/15 12:49:55 cplattne
8 | * Exp $
9 | */
10 | public class PacketSessionX11Request {
11 | byte[] payload;
12 |
13 | public int recipientChannelID;
14 | public boolean wantReply;
15 |
16 | public boolean singleConnection;
17 | String x11AuthenticationProtocol;
18 | String x11AuthenticationCookie;
19 | int x11ScreenNumber;
20 |
21 | public PacketSessionX11Request(int recipientChannelID, boolean wantReply,
22 | boolean singleConnection, String x11AuthenticationProtocol,
23 | String x11AuthenticationCookie, int x11ScreenNumber) {
24 | this.recipientChannelID = recipientChannelID;
25 | this.wantReply = wantReply;
26 |
27 | this.singleConnection = singleConnection;
28 | this.x11AuthenticationProtocol = x11AuthenticationProtocol;
29 | this.x11AuthenticationCookie = x11AuthenticationCookie;
30 | this.x11ScreenNumber = x11ScreenNumber;
31 | }
32 |
33 | public byte[] getPayload() {
34 | if (payload == null) {
35 | TypesWriter tw = new TypesWriter();
36 | tw.writeByte(Packets.SSH_MSG_CHANNEL_REQUEST);
37 | tw.writeUINT32(recipientChannelID);
38 | tw.writeString("x11-req");
39 | tw.writeBoolean(wantReply);
40 |
41 | tw.writeBoolean(singleConnection);
42 | tw.writeString(x11AuthenticationProtocol);
43 | tw.writeString(x11AuthenticationCookie);
44 | tw.writeUINT32(x11ScreenNumber);
45 |
46 | payload = tw.getBytes();
47 | }
48 | return payload;
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/src/com/trilead/ssh2/packets/PacketOpenDirectTCPIPChannel.java:
--------------------------------------------------------------------------------
1 | package com.trilead.ssh2.packets;
2 |
3 | /**
4 | * PacketOpenDirectTCPIPChannel.
5 | *
6 | * @author Christian Plattner, plattner@trilead.com
7 | * @version $Id: PacketOpenDirectTCPIPChannel.java,v 1.1 2007/10/15 12:49:55
8 | * cplattne Exp $
9 | */
10 | public class PacketOpenDirectTCPIPChannel {
11 | byte[] payload;
12 |
13 | int channelID;
14 | int initialWindowSize;
15 | int maxPacketSize;
16 |
17 | String host_to_connect;
18 | int port_to_connect;
19 | String originator_IP_address;
20 | int originator_port;
21 |
22 | public PacketOpenDirectTCPIPChannel(int channelID, int initialWindowSize,
23 | int maxPacketSize, String host_to_connect, int port_to_connect,
24 | String originator_IP_address, int originator_port) {
25 | this.channelID = channelID;
26 | this.initialWindowSize = initialWindowSize;
27 | this.maxPacketSize = maxPacketSize;
28 | this.host_to_connect = host_to_connect;
29 | this.port_to_connect = port_to_connect;
30 | this.originator_IP_address = originator_IP_address;
31 | this.originator_port = originator_port;
32 | }
33 |
34 | public byte[] getPayload() {
35 | if (payload == null) {
36 | TypesWriter tw = new TypesWriter();
37 |
38 | tw.writeByte(Packets.SSH_MSG_CHANNEL_OPEN);
39 | tw.writeString("direct-tcpip");
40 | tw.writeUINT32(channelID);
41 | tw.writeUINT32(initialWindowSize);
42 | tw.writeUINT32(maxPacketSize);
43 | tw.writeString(host_to_connect);
44 | tw.writeUINT32(port_to_connect);
45 | tw.writeString(originator_IP_address);
46 | tw.writeUINT32(originator_port);
47 |
48 | payload = tw.getBytes();
49 | }
50 | return payload;
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/src/com/trilead/ssh2/packets/PacketChannelWindowAdjust.java:
--------------------------------------------------------------------------------
1 | package com.trilead.ssh2.packets;
2 |
3 | import java.io.IOException;
4 |
5 | /**
6 | * PacketChannelWindowAdjust.
7 | *
8 | * @author Christian Plattner, plattner@trilead.com
9 | * @version $Id: PacketChannelWindowAdjust.java,v 1.1 2007/10/15 12:49:55
10 | * cplattne Exp $
11 | */
12 | public class PacketChannelWindowAdjust {
13 | byte[] payload;
14 |
15 | public int recipientChannelID;
16 | public int windowChange;
17 |
18 | public PacketChannelWindowAdjust(byte payload[], int off, int len)
19 | throws IOException {
20 | this.payload = new byte[len];
21 | System.arraycopy(payload, off, this.payload, 0, len);
22 |
23 | TypesReader tr = new TypesReader(payload, off, len);
24 |
25 | int packet_type = tr.readByte();
26 |
27 | if (packet_type != Packets.SSH_MSG_CHANNEL_WINDOW_ADJUST)
28 | throw new IOException(
29 | "This is not a SSH_MSG_CHANNEL_WINDOW_ADJUST! ("
30 | + packet_type + ")");
31 |
32 | recipientChannelID = tr.readUINT32();
33 | windowChange = tr.readUINT32();
34 |
35 | if (tr.remain() != 0)
36 | throw new IOException(
37 | "Padding in SSH_MSG_CHANNEL_WINDOW_ADJUST packet!");
38 | }
39 |
40 | public PacketChannelWindowAdjust(int recipientChannelID, int windowChange) {
41 | this.recipientChannelID = recipientChannelID;
42 | this.windowChange = windowChange;
43 | }
44 |
45 | public byte[] getPayload() {
46 | if (payload == null) {
47 | TypesWriter tw = new TypesWriter();
48 | tw.writeByte(Packets.SSH_MSG_CHANNEL_WINDOW_ADJUST);
49 | tw.writeUINT32(recipientChannelID);
50 | tw.writeUINT32(windowChange);
51 | payload = tw.getBytes();
52 | }
53 | return payload;
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/src/com/trilead/ssh2/channel/ChannelOutputStream.java:
--------------------------------------------------------------------------------
1 | package com.trilead.ssh2.channel;
2 |
3 | import java.io.IOException;
4 | import java.io.OutputStream;
5 |
6 | /**
7 | * ChannelOutputStream.
8 | *
9 | * @author Christian Plattner, plattner@trilead.com
10 | * @version $Id: ChannelOutputStream.java,v 1.1 2007/10/15 12:49:56 cplattne Exp
11 | * $
12 | */
13 | public final class ChannelOutputStream extends OutputStream {
14 | Channel c;
15 |
16 | private byte[] writeBuffer;
17 |
18 | boolean isClosed = false;
19 |
20 | ChannelOutputStream(Channel c) {
21 | this.c = c;
22 | writeBuffer = new byte[1];
23 | }
24 |
25 | @Override
26 | public void close() throws IOException {
27 | if (isClosed == false) {
28 | isClosed = true;
29 | c.cm.sendEOF(c);
30 | }
31 | }
32 |
33 | @Override
34 | public void flush() throws IOException {
35 | if (isClosed)
36 | throw new IOException("This OutputStream is closed.");
37 |
38 | /* This is a no-op, since this stream is unbuffered */
39 | }
40 |
41 | @Override
42 | public void write(byte[] b) throws IOException {
43 | write(b, 0, b.length);
44 | }
45 |
46 | @Override
47 | public void write(byte[] b, int off, int len) throws IOException {
48 | if (isClosed)
49 | throw new IOException("This OutputStream is closed.");
50 |
51 | if (b == null)
52 | throw new NullPointerException();
53 |
54 | if ((off < 0) || (len < 0) || ((off + len) > b.length)
55 | || ((off + len) < 0) || (off > b.length))
56 | throw new IndexOutOfBoundsException();
57 |
58 | if (len == 0)
59 | return;
60 |
61 | c.cm.sendData(c, b, off, len);
62 | }
63 |
64 | @Override
65 | public void write(int b) throws IOException {
66 | writeBuffer[0] = (byte) b;
67 |
68 | write(writeBuffer, 0, 1);
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/src/com/trilead/ssh2/packets/PacketSessionPtyRequest.java:
--------------------------------------------------------------------------------
1 | package com.trilead.ssh2.packets;
2 |
3 | /**
4 | * PacketSessionPtyRequest.
5 | *
6 | * @author Christian Plattner, plattner@trilead.com
7 | * @version $Id: PacketSessionPtyRequest.java,v 1.1 2007/10/15 12:49:55 cplattne
8 | * Exp $
9 | */
10 | public class PacketSessionPtyRequest {
11 | byte[] payload;
12 |
13 | public int recipientChannelID;
14 | public boolean wantReply;
15 | public String term;
16 | public int character_width;
17 | public int character_height;
18 | public int pixel_width;
19 | public int pixel_height;
20 | public byte[] terminal_modes;
21 |
22 | public PacketSessionPtyRequest(int recipientChannelID, boolean wantReply,
23 | String term, int character_width, int character_height,
24 | int pixel_width, int pixel_height, byte[] terminal_modes) {
25 | this.recipientChannelID = recipientChannelID;
26 | this.wantReply = wantReply;
27 | this.term = term;
28 | this.character_width = character_width;
29 | this.character_height = character_height;
30 | this.pixel_width = pixel_width;
31 | this.pixel_height = pixel_height;
32 | this.terminal_modes = terminal_modes;
33 | }
34 |
35 | public byte[] getPayload() {
36 | if (payload == null) {
37 | TypesWriter tw = new TypesWriter();
38 | tw.writeByte(Packets.SSH_MSG_CHANNEL_REQUEST);
39 | tw.writeUINT32(recipientChannelID);
40 | tw.writeString("pty-req");
41 | tw.writeBoolean(wantReply);
42 | tw.writeString(term);
43 | tw.writeUINT32(character_width);
44 | tw.writeUINT32(character_height);
45 | tw.writeUINT32(pixel_width);
46 | tw.writeUINT32(pixel_height);
47 | tw.writeString(terminal_modes, 0, terminal_modes.length);
48 |
49 | payload = tw.getBytes();
50 | }
51 | return payload;
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/src/net/sourceforge/jsocks/Authentication.java:
--------------------------------------------------------------------------------
1 | package net.sourceforge.jsocks;
2 |
3 | /**
4 | * The Authentication interface provides for performing method specific
5 | * authentication for SOCKS5 connections.
6 | */
7 | public interface Authentication {
8 | /**
9 | * This method is called when SOCKS5 server have selected a particular
10 | * authentication method, for whch an implementaion have been registered.
11 | *
12 | * LocalPortForwarder forwards TCP/IP connections to a local port
11 | * via the secure tunnel to another host (which may or may not be identical to
12 | * the remote SSH-2 server). Checkout
13 | * {@link Connection#createLocalPortForwarder(int, String, int)} on how to
14 | * create one.
15 | *
16 | * @author Christian Plattner, plattner@trilead.com
17 | * @version $Id: LocalPortForwarder.java,v 1.1 2007/10/15 12:49:56 cplattne Exp
18 | * $
19 | */
20 | public class LocalPortForwarder {
21 | ChannelManager cm;
22 |
23 | String host_to_connect;
24 |
25 | int port_to_connect;
26 |
27 | LocalAcceptThread lat;
28 |
29 | LocalPortForwarder(ChannelManager cm, InetSocketAddress addr,
30 | String host_to_connect, int port_to_connect) throws IOException {
31 | this.cm = cm;
32 | this.host_to_connect = host_to_connect;
33 | this.port_to_connect = port_to_connect;
34 |
35 | lat = new LocalAcceptThread(cm, addr, host_to_connect, port_to_connect);
36 | lat.setDaemon(true);
37 | lat.start();
38 | }
39 |
40 | LocalPortForwarder(ChannelManager cm, int local_port,
41 | String host_to_connect, int port_to_connect) throws IOException {
42 | this.cm = cm;
43 | this.host_to_connect = host_to_connect;
44 | this.port_to_connect = port_to_connect;
45 |
46 | lat = new LocalAcceptThread(cm, local_port, host_to_connect,
47 | port_to_connect);
48 | lat.setDaemon(true);
49 | lat.start();
50 | }
51 |
52 | /**
53 | * Stop TCP/IP forwarding of newly arriving connections.
54 | *
55 | * @throws IOException
56 | */
57 | public void close() throws IOException {
58 | lat.stopWorking();
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/src/com/trilead/ssh2/AuthAgentCallback.java:
--------------------------------------------------------------------------------
1 | package com.trilead.ssh2;
2 |
3 | import java.util.Map;
4 |
5 | /**
6 | * AuthAgentCallback.
7 | *
8 | * @author Kenny Root
9 | * @version $Id$
10 | */
11 | public interface AuthAgentCallback {
12 |
13 | /**
14 | * @param key
15 | * A RSAPrivateKey or DSAPrivateKey
16 | * containing a DSA or RSA private key of the user in Trilead
17 | * object format.
18 | * @param comment
19 | * comment associated with this key
20 | * @param confirmUse
21 | * whether to prompt before using this key
22 | * @param lifetime
23 | * lifetime in seconds for key to be remembered
24 | * @return success or failure
25 | */
26 | boolean addIdentity(Object key, String comment, boolean confirmUse,
27 | int lifetime);
28 |
29 | /**
30 | * @param publicKey
31 | * byte blob containing the OpenSSH-format encoded public key
32 | * @return A RSAPrivateKey or DSAPrivateKey
33 | * containing a DSA or RSA private key of the user in Trilead object
34 | * format.
35 | */
36 | Object getPrivateKey(byte[] publicKey);
37 |
38 | /**
39 | * @return
40 | */
41 | boolean isAgentLocked();
42 |
43 | /**
44 | * @return success or failure
45 | */
46 | boolean removeAllIdentities();
47 |
48 | /**
49 | * @param publicKey
50 | * byte blob containing the OpenSSH-format encoded public key
51 | * @return success or failure
52 | */
53 | boolean removeIdentity(byte[] publicKey);
54 |
55 | /**
56 | * @param unlockPassphrase
57 | * @return
58 | */
59 | boolean requestAgentUnlock(String unlockPassphrase);
60 |
61 | /**
62 | * @return array of blobs containing the OpenSSH-format encoded public keys
63 | */
64 | MapDynamicPortForwarder forwards TCP/IP connections to a local
28 | * port via the secure tunnel to another host which is selected via the SOCKS
29 | * protocol. Checkout {@link Connection#createDynamicPortForwarder(int)} on how
30 | * to create one.
31 | *
32 | * @author Kenny Root
33 | * @version $Id: $
34 | */
35 | public class DynamicPortForwarder {
36 | ChannelManager cm;
37 |
38 | DynamicAcceptThread dat;
39 |
40 | DynamicPortForwarder(ChannelManager cm, InetSocketAddress addr)
41 | throws IOException {
42 | this.cm = cm;
43 |
44 | dat = new DynamicAcceptThread(cm, addr);
45 | dat.setDaemon(true);
46 | dat.start();
47 | }
48 |
49 | DynamicPortForwarder(ChannelManager cm, int local_port) throws IOException {
50 | this.cm = cm;
51 |
52 | dat = new DynamicAcceptThread(cm, local_port);
53 | dat.setDaemon(true);
54 | dat.start();
55 | }
56 |
57 | /**
58 | * Stop TCP/IP forwarding of newly arriving connections.
59 | *
60 | * @throws IOException
61 | */
62 | public void close() throws IOException {
63 | dat.stopWorking();
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/src/com/trilead/ssh2/packets/PacketChannelOpenConfirmation.java:
--------------------------------------------------------------------------------
1 | package com.trilead.ssh2.packets;
2 |
3 | import java.io.IOException;
4 |
5 | /**
6 | * PacketChannelOpenConfirmation.
7 | *
8 | * @author Christian Plattner, plattner@trilead.com
9 | * @version $Id: PacketChannelOpenConfirmation.java,v 1.1 2007/10/15 12:49:55
10 | * cplattne Exp $
11 | */
12 | public class PacketChannelOpenConfirmation {
13 | byte[] payload;
14 |
15 | public int recipientChannelID;
16 | public int senderChannelID;
17 | public int initialWindowSize;
18 | public int maxPacketSize;
19 |
20 | public PacketChannelOpenConfirmation(byte payload[], int off, int len)
21 | throws IOException {
22 | this.payload = new byte[len];
23 | System.arraycopy(payload, off, this.payload, 0, len);
24 |
25 | TypesReader tr = new TypesReader(payload, off, len);
26 |
27 | int packet_type = tr.readByte();
28 |
29 | if (packet_type != Packets.SSH_MSG_CHANNEL_OPEN_CONFIRMATION)
30 | throw new IOException(
31 | "This is not a SSH_MSG_CHANNEL_OPEN_CONFIRMATION! ("
32 | + packet_type + ")");
33 |
34 | recipientChannelID = tr.readUINT32();
35 | senderChannelID = tr.readUINT32();
36 | initialWindowSize = tr.readUINT32();
37 | maxPacketSize = tr.readUINT32();
38 |
39 | if (tr.remain() != 0)
40 | throw new IOException(
41 | "Padding in SSH_MSG_CHANNEL_OPEN_CONFIRMATION packet!");
42 | }
43 |
44 | public PacketChannelOpenConfirmation(int recipientChannelID,
45 | int senderChannelID, int initialWindowSize, int maxPacketSize) {
46 | this.recipientChannelID = recipientChannelID;
47 | this.senderChannelID = senderChannelID;
48 | this.initialWindowSize = initialWindowSize;
49 | this.maxPacketSize = maxPacketSize;
50 | }
51 |
52 | public byte[] getPayload() {
53 | if (payload == null) {
54 | TypesWriter tw = new TypesWriter();
55 | tw.writeByte(Packets.SSH_MSG_CHANNEL_OPEN_CONFIRMATION);
56 | tw.writeUINT32(recipientChannelID);
57 | tw.writeUINT32(senderChannelID);
58 | tw.writeUINT32(initialWindowSize);
59 | tw.writeUINT32(maxPacketSize);
60 | payload = tw.getBytes();
61 | }
62 | return payload;
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/src/com/trilead/ssh2/crypto/cipher/CBCMode.java:
--------------------------------------------------------------------------------
1 | package com.trilead.ssh2.crypto.cipher;
2 |
3 | /**
4 | * CBCMode.
5 | *
6 | * @author Christian Plattner, plattner@trilead.com
7 | * @version $Id: CBCMode.java,v 1.1 2007/10/15 12:49:55 cplattne Exp $
8 | */
9 | public class CBCMode implements BlockCipher {
10 | BlockCipher tc;
11 | int blockSize;
12 | boolean doEncrypt;
13 |
14 | byte[] cbc_vector;
15 | byte[] tmp_vector;
16 |
17 | public CBCMode(BlockCipher tc, byte[] iv, boolean doEncrypt)
18 | throws IllegalArgumentException {
19 | this.tc = tc;
20 | this.blockSize = tc.getBlockSize();
21 | this.doEncrypt = doEncrypt;
22 |
23 | if (this.blockSize != iv.length)
24 | throw new IllegalArgumentException("IV must be " + blockSize
25 | + " bytes long! (currently " + iv.length + ")");
26 |
27 | this.cbc_vector = new byte[blockSize];
28 | this.tmp_vector = new byte[blockSize];
29 | System.arraycopy(iv, 0, cbc_vector, 0, blockSize);
30 | }
31 |
32 | private void decryptBlock(byte[] src, int srcoff, byte[] dst, int dstoff) {
33 | /* Assume the worst, src and dst are overlapping... */
34 |
35 | System.arraycopy(src, srcoff, tmp_vector, 0, blockSize);
36 |
37 | tc.transformBlock(src, srcoff, dst, dstoff);
38 |
39 | for (int i = 0; i < blockSize; i++)
40 | dst[dstoff + i] ^= cbc_vector[i];
41 |
42 | /* ...that is why we need a tmp buffer. */
43 |
44 | byte[] swap = cbc_vector;
45 | cbc_vector = tmp_vector;
46 | tmp_vector = swap;
47 | }
48 |
49 | private void encryptBlock(byte[] src, int srcoff, byte[] dst, int dstoff) {
50 | for (int i = 0; i < blockSize; i++)
51 | cbc_vector[i] ^= src[srcoff + i];
52 |
53 | tc.transformBlock(cbc_vector, 0, dst, dstoff);
54 |
55 | System.arraycopy(dst, dstoff, cbc_vector, 0, blockSize);
56 | }
57 |
58 | @Override
59 | public int getBlockSize() {
60 | return blockSize;
61 | }
62 |
63 | @Override
64 | public void init(boolean forEncryption, byte[] key) {
65 | }
66 |
67 | @Override
68 | public void transformBlock(byte[] src, int srcoff, byte[] dst, int dstoff) {
69 | if (doEncrypt)
70 | encryptBlock(src, srcoff, dst, dstoff);
71 | else
72 | decryptBlock(src, srcoff, dst, dstoff);
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/src/com/trilead/ssh2/ChannelCondition.java:
--------------------------------------------------------------------------------
1 | package com.trilead.ssh2;
2 |
3 | /**
4 | * Contains constants that can be used to specify what conditions to wait for on
5 | * a SSH-2 channel (e.g., represented by a {@link Session}).
6 | *
7 | * @see Session#waitForCondition(int, long)
8 | *
9 | * @author Christian Plattner, plattner@trilead.com
10 | * @version $Id: ChannelCondition.java,v 1.1 2007/10/15 12:49:56 cplattne Exp $
11 | */
12 |
13 | public abstract interface ChannelCondition {
14 | /**
15 | * A timeout has occurred, none of your requested conditions is fulfilled.
16 | * However, other conditions may be true - therefore, NEVER use the "=="
17 | * operator to test for this (or any other) condition. Always use something
18 | * like ((cond & ChannelCondition.CLOSED) != 0).
19 | */
20 | public static final int TIMEOUT = 1;
21 |
22 | /**
23 | * The underlying SSH-2 channel, however not necessarily the whole
24 | * connection, has been closed. This implies EOF. Note that
25 | * there may still be unread stdout or stderr data in the local window, i.e,
26 | * STDOUT_DATA or/and STDERR_DATA may be set at
27 | * the same time.
28 | */
29 | public static final int CLOSED = 2;
30 |
31 | /**
32 | * There is stdout data available that is ready to be consumed.
33 | */
34 | public static final int STDOUT_DATA = 4;
35 |
36 | /**
37 | * There is stderr data available that is ready to be consumed.
38 | */
39 | public static final int STDERR_DATA = 8;
40 |
41 | /**
42 | * EOF on has been reached, no more _new_ stdout or stderr data will arrive
43 | * from the remote server. However, there may be unread stdout or stderr
44 | * data, i.e, STDOUT_DATA or/and STDERR_DATA may
45 | * be set at the same time.
46 | */
47 | public static final int EOF = 16;
48 |
49 | /**
50 | * The exit status of the remote process is available. Some servers never
51 | * send the exist status, or occasionally "forget" to do so.
52 | */
53 | public static final int EXIT_STATUS = 32;
54 |
55 | /**
56 | * The exit signal of the remote process is available.
57 | */
58 | public static final int EXIT_SIGNAL = 64;
59 |
60 | }
61 |
--------------------------------------------------------------------------------
/src/com/trilead/ssh2/channel/StreamForwarder.java:
--------------------------------------------------------------------------------
1 | package com.trilead.ssh2.channel;
2 |
3 | import java.io.IOException;
4 | import java.io.InputStream;
5 | import java.io.OutputStream;
6 | import java.net.Socket;
7 |
8 | /**
9 | * A StreamForwarder forwards data between two given streams. If two
10 | * StreamForwarder threads are used (one for each direction) then one can be
11 | * configured to shutdown the underlying channel/socket if both threads have
12 | * finished forwarding (EOF).
13 | *
14 | * @author Christian Plattner, plattner@trilead.com
15 | * @version $Id: StreamForwarder.java,v 1.1 2007/10/15 12:49:56 cplattne Exp $
16 | */
17 | public class StreamForwarder extends Thread {
18 | OutputStream os;
19 | InputStream is;
20 | byte[] buffer = new byte[Channel.CHANNEL_BUFFER_SIZE];
21 | Channel c;
22 | StreamForwarder sibling;
23 | Socket s;
24 | String mode;
25 |
26 | StreamForwarder(Channel c, StreamForwarder sibling, Socket s,
27 | InputStream is, OutputStream os, String mode) throws IOException {
28 | this.is = is;
29 | this.os = os;
30 | this.mode = mode;
31 | this.c = c;
32 | this.sibling = sibling;
33 | this.s = s;
34 | }
35 |
36 | @Override
37 | public void run() {
38 | try {
39 | while (true) {
40 | int len = is.read(buffer);
41 | if (len <= 0)
42 | break;
43 | os.write(buffer, 0, len);
44 | os.flush();
45 | }
46 | } catch (IOException ignore) {
47 | try {
48 | c.cm.closeChannel(c,
49 | "Closed due to exception in StreamForwarder (" + mode
50 | + "): " + ignore.getMessage(), true);
51 | } catch (IOException e) {
52 | }
53 | } finally {
54 | try {
55 | os.close();
56 | } catch (IOException e1) {
57 | }
58 | try {
59 | is.close();
60 | } catch (IOException e2) {
61 | }
62 |
63 | if (sibling != null) {
64 | while (sibling.isAlive()) {
65 | try {
66 | sibling.join();
67 | } catch (InterruptedException e) {
68 | }
69 | }
70 |
71 | try {
72 | c.cm.closeChannel(c, "StreamForwarder (" + mode
73 | + ") is cleaning up the connection", true);
74 | } catch (IOException e3) {
75 | }
76 |
77 | try {
78 | if (s != null)
79 | s.close();
80 | } catch (IOException e1) {
81 | }
82 | }
83 | }
84 | }
85 | }
--------------------------------------------------------------------------------
/src/com/trilead/ssh2/SFTPException.java:
--------------------------------------------------------------------------------
1 | package com.trilead.ssh2;
2 |
3 | import java.io.IOException;
4 |
5 | import com.trilead.ssh2.sftp.ErrorCodes;
6 |
7 | /**
8 | * Used in combination with the SFTPv3Client. This exception wraps error
9 | * messages sent by the SFTP server.
10 | *
11 | * @author Christian Plattner, plattner@trilead.com
12 | * @version $Id: SFTPException.java,v 1.1 2007/10/15 12:49:56 cplattne Exp $
13 | */
14 |
15 | public class SFTPException extends IOException {
16 | private static final long serialVersionUID = 578654644222421811L;
17 |
18 | private static String constructMessage(String s, int errorCode) {
19 | String[] detail = ErrorCodes.getDescription(errorCode);
20 |
21 | if (detail == null)
22 | return s + " (UNKNOW SFTP ERROR CODE)";
23 |
24 | return s + " (" + detail[0] + ": " + detail[1] + ")";
25 | }
26 | private final String sftpErrorMessage;
27 |
28 | private final int sftpErrorCode;
29 |
30 | SFTPException(String msg, int errorCode) {
31 | super(constructMessage(msg, errorCode));
32 | sftpErrorMessage = msg;
33 | sftpErrorCode = errorCode;
34 | }
35 |
36 | /**
37 | * Get the error code sent by the server.
38 | *
39 | * @return an error code as defined in the SFTP specs.
40 | */
41 | public int getServerErrorCode() {
42 | return sftpErrorCode;
43 | }
44 |
45 | /**
46 | * Get the symbolic name of the error code as given in the SFTP specs.
47 | *
48 | * @return e.g., "SSH_FX_INVALID_FILENAME".
49 | */
50 | public String getServerErrorCodeSymbol() {
51 | String[] detail = ErrorCodes.getDescription(sftpErrorCode);
52 |
53 | if (detail == null)
54 | return "UNKNOW SFTP ERROR CODE " + sftpErrorCode;
55 |
56 | return detail[0];
57 | }
58 |
59 | /**
60 | * Get the description of the error code as given in the SFTP specs.
61 | *
62 | * @return e.g., "The filename is not valid."
63 | */
64 | public String getServerErrorCodeVerbose() {
65 | String[] detail = ErrorCodes.getDescription(sftpErrorCode);
66 |
67 | if (detail == null)
68 | return "The error code " + sftpErrorCode + " is unknown.";
69 |
70 | return detail[1];
71 | }
72 |
73 | /**
74 | * Get the error message sent by the server. Often, this message does not
75 | * help a lot (e.g., "failure").
76 | *
77 | * @return the plain string as sent by the server.
78 | */
79 | public String getServerErrorMessage() {
80 | return sftpErrorMessage;
81 | }
82 | }
83 |
--------------------------------------------------------------------------------
/src/net/sourceforge/jsocks/SocksException.java:
--------------------------------------------------------------------------------
1 | package net.sourceforge.jsocks;
2 |
3 | /**
4 | * Exception thrown by various socks classes to indicate errors with protocol or
5 | * unsuccessful server responses.
6 | */
7 | public class SocksException extends java.io.IOException {
8 | private static final long serialVersionUID = 6141184566248512277L;
9 |
10 | static final String UNASSIGNED_ERROR_MESSAGE = "Unknown error message";
11 |
12 | static final String serverReplyMessage[] = { "Succeeded",
13 | "General SOCKS server failure",
14 | "Connection not allowed by ruleset", "Network unreachable",
15 | "Host unreachable", "Connection refused", "TTL expired",
16 | "Command not supported", "Address type not supported" };
17 |
18 | static final String localErrorMessage[] = { "SOCKS server not specified",
19 | "Unable to contact SOCKS server", "IO error",
20 | "None of Authentication methods are supported",
21 | "Authentication failed", "General SOCKS fault" };
22 |
23 | String errString;
24 |
25 | public int errCode;
26 | /**
27 | * Construct a SocksException with given error code.
28 | * LocalStreamForwarder forwards an Input- and Outputstream pair
13 | * via the secure tunnel to another host (which may or may not be identical to
14 | * the remote SSH-2 server).
15 | *
16 | * @author Christian Plattner, plattner@trilead.com
17 | * @version $Id: LocalStreamForwarder.java,v 1.1 2007/10/15 12:49:56 cplattne
18 | * Exp $
19 | */
20 | public class LocalStreamForwarder {
21 | ChannelManager cm;
22 |
23 | String host_to_connect;
24 | int port_to_connect;
25 | LocalAcceptThread lat;
26 |
27 | Channel cn;
28 |
29 | LocalStreamForwarder(ChannelManager cm, String host_to_connect,
30 | int port_to_connect) throws IOException {
31 | this.cm = cm;
32 | this.host_to_connect = host_to_connect;
33 | this.port_to_connect = port_to_connect;
34 |
35 | cn = cm.openDirectTCPIPChannel(host_to_connect, port_to_connect,
36 | "127.0.0.1", 0);
37 | }
38 |
39 | /**
40 | * Close the underlying SSH forwarding channel and free up resources. You
41 | * can also use this method to force the shutdown of the underlying
42 | * forwarding channel. Pending output (OutputStream not flushed) will NOT be
43 | * sent. Pending input (InputStream) can still be read. If the shutdown
44 | * operation is already in progress (initiated from either side), then this
45 | * call is a no-op.
46 | *
47 | * @throws IOException
48 | */
49 | public void close() throws IOException {
50 | cm.closeChannel(cn, "Closed due to user request.", true);
51 | }
52 |
53 | /**
54 | * @return An InputStream object.
55 | * @throws IOException
56 | */
57 | public InputStream getInputStream() throws IOException {
58 | return cn.getStdoutStream();
59 | }
60 |
61 | /**
62 | * Get the OutputStream. Please be aware that the implementation MAY use an
63 | * internal buffer. To make sure that the buffered data is sent over the
64 | * tunnel, you have to call the flush method of the
65 | * OutputStream. To signal EOF, please use the
66 | * close method of the OutputStream.
67 | *
68 | * @return An OutputStream object.
69 | * @throws IOException
70 | */
71 | public OutputStream getOutputStream() throws IOException {
72 | return cn.getStdinStream();
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/src/com/trilead/ssh2/InteractiveCallback.java:
--------------------------------------------------------------------------------
1 | package com.trilead.ssh2;
2 |
3 | /**
4 | * An InteractiveCallback is used to respond to challenges sent by
5 | * the server if authentication mode "keyboard-interactive" is selected.
6 | *
7 | * @see Connection#authenticateWithKeyboardInteractive(String, String[],
8 | * InteractiveCallback)
9 | *
10 | * @author Christian Plattner, plattner@trilead.com
11 | * @version $Id: InteractiveCallback.java,v 1.1 2007/10/15 12:49:56 cplattne Exp
12 | * $
13 | */
14 |
15 | public interface InteractiveCallback {
16 | /**
17 | * This callback interface is used during a "keyboard-interactive"
18 | * authentication. Every time the server sends a set of challenges (however,
19 | * most often just one challenge at a time), this callback function will be
20 | * called to give your application a chance to talk to the user and to
21 | * determine the response(s).
22 | * numPrompts) of Strings
45 | * @param echo
46 | * an array (length numPrompts) of booleans. For
47 | * each prompt, the corresponding echo field indicates whether or
48 | * not the user input should be echoed as characters are typed.
49 | * @return an array of reponses - the array size must match the parameter
50 | * numPrompts.
51 | */
52 | public String[] replyToChallenge(String name, String instruction,
53 | int numPrompts, String[] prompt, boolean[] echo) throws Exception;
54 | }
55 |
--------------------------------------------------------------------------------
/src/respiteinjector/Embaralhador.java:
--------------------------------------------------------------------------------
1 | /*
2 | * To change this license header, choose License Headers in Project Properties.
3 | * To change this template file, choose Tools | Templates
4 | * and open the template in the editor.
5 | */
6 | package respiteinjector;
7 |
8 | /**
9 | *
10 | * @author user
11 | */
12 | public class Embaralhador {
13 | public Embaralhador() {}
14 |
15 | public static byte[] embaralhar(byte[] bytes) { int deslocEsquerda = generateDeslocamentoEsquerda();
16 | int deslocDireita = generateDeslocamentoDireita();
17 |
18 | byte[] base64 = Base64.toBase64(bytes, 0, bytes.length);
19 |
20 | int meio = base64.length / 2;
21 |
22 | StringBuilder builder = new StringBuilder();
23 |
24 | builder.append(String.format("%03d", new Object[] { Integer.valueOf(deslocEsquerda) }));
25 | builder.append(CesarCifer.criptografa(new String(base64, 0, meio), deslocEsquerda, CesarCifer.ALFABETO_BASE64));
26 | builder.append('-');
27 | builder.append(CesarCifer.criptografa(new String(base64, meio, base64.length - meio), deslocDireita, CesarCifer.ALFABETO_BASE64));
28 | builder.append(String.format("%03d", new Object[] { Integer.valueOf(deslocDireita) }));
29 |
30 | return builder.toString().getBytes();
31 | }
32 |
33 | public static byte[] desembaralhar(byte[] bytes) {
34 | String str = new String(bytes);
35 |
36 | int deslocEsquerda = Integer.parseInt(str.substring(0, 3));
37 | int deslocDireita = Integer.parseInt(str.substring(str.length() - 3, str.length()));
38 |
39 | String[] lados = str.substring(3, str.length() - 3).split("-");
40 |
41 | StringBuilder builder = new StringBuilder();
42 | builder.append(CesarCifer.descriptografa(lados[0], deslocEsquerda, CesarCifer.ALFABETO_BASE64));
43 | builder.append(CesarCifer.descriptografa(lados[1], deslocDireita, CesarCifer.ALFABETO_BASE64));
44 |
45 | return Base64.fromBase64(builder.toString()).getBytes();
46 | }
47 |
48 | private static int generateDeslocamentoEsquerda()
49 | {
50 | String str =Long.toString( System.currentTimeMillis()) ;
51 |
52 | int val = parseInt(str, str.length() - 4, str.length() - 1);
53 |
54 | return val == 0 ? 1 : val;
55 | }
56 |
57 | private static int generateDeslocamentoDireita() {
58 | String str =Double.toString( Math.random());
59 |
60 | int val = parseInt(str, str.length() - 4, str.length() - 1);
61 |
62 | return val == 0 ? 1 : val;
63 | }
64 |
65 | private static int parseInt(String str, int indexI, int indexF) {
66 | return Integer.parseInt(str.substring(indexI, indexF));
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/src/com/trilead/ssh2/channel/RemoteAcceptThread.java:
--------------------------------------------------------------------------------
1 | package com.trilead.ssh2.channel;
2 |
3 | import java.io.IOException;
4 | import java.net.Socket;
5 |
6 | import com.trilead.ssh2.log.Logger;
7 |
8 | /**
9 | * RemoteAcceptThread.
10 | *
11 | * @author Christian Plattner, plattner@trilead.com
12 | * @version $Id: RemoteAcceptThread.java,v 1.1 2007/10/15 12:49:56 cplattne Exp
13 | * $
14 | */
15 | public class RemoteAcceptThread extends Thread {
16 | private static final Logger log = Logger
17 | .getLogger(RemoteAcceptThread.class);
18 |
19 | Channel c;
20 |
21 | String remoteConnectedAddress;
22 | int remoteConnectedPort;
23 | String remoteOriginatorAddress;
24 | int remoteOriginatorPort;
25 | String targetAddress;
26 | int targetPort;
27 |
28 | Socket s;
29 |
30 | public RemoteAcceptThread(Channel c, String remoteConnectedAddress,
31 | int remoteConnectedPort, String remoteOriginatorAddress,
32 | int remoteOriginatorPort, String targetAddress, int targetPort) {
33 | this.c = c;
34 | this.remoteConnectedAddress = remoteConnectedAddress;
35 | this.remoteConnectedPort = remoteConnectedPort;
36 | this.remoteOriginatorAddress = remoteOriginatorAddress;
37 | this.remoteOriginatorPort = remoteOriginatorPort;
38 | this.targetAddress = targetAddress;
39 | this.targetPort = targetPort;
40 |
41 | if (log.isEnabled())
42 | log.log(20, "RemoteAcceptThread: " + remoteConnectedAddress + "/"
43 | + remoteConnectedPort + ", R: " + remoteOriginatorAddress
44 | + "/" + remoteOriginatorPort);
45 | }
46 |
47 | @Override
48 | public void run() {
49 | try {
50 | c.cm.sendOpenConfirmation(c);
51 |
52 | s = new Socket(targetAddress, targetPort);
53 |
54 | StreamForwarder r2l = new StreamForwarder(c, null, null,
55 | c.getStdoutStream(), s.getOutputStream(), "RemoteToLocal");
56 | StreamForwarder l2r = new StreamForwarder(c, null, null,
57 | s.getInputStream(), c.getStdinStream(), "LocalToRemote");
58 |
59 | /*
60 | * No need to start two threads, one can be executed in the current
61 | * thread
62 | */
63 |
64 | r2l.setDaemon(true);
65 | r2l.start();
66 | l2r.run();
67 |
68 | while (r2l.isAlive()) {
69 | try {
70 | r2l.join();
71 | } catch (InterruptedException e) {
72 | }
73 | }
74 |
75 | /* If the channel is already closed, then this is a no-op */
76 |
77 | c.cm.closeChannel(c, "EOF on both streams reached.", true);
78 | s.close();
79 | } catch (IOException e) {
80 | log.log(50, "IOException in proxy code: " + e.getMessage());
81 |
82 | try {
83 | c.cm.closeChannel(c,
84 | "IOException in proxy code (" + e.getMessage() + ")",
85 | true);
86 | } catch (IOException e1) {
87 | }
88 | try {
89 | if (s != null)
90 | s.close();
91 | } catch (IOException e1) {
92 | }
93 | }
94 | }
95 | }
96 |
--------------------------------------------------------------------------------
/src/com/trilead/ssh2/compression/CompressionFactory.java:
--------------------------------------------------------------------------------
1 | /*
2 | * ConnectBot: simple, powerful, open-source SSH client for Android
3 | * Copyright 2007 Kenny Root, Jeffrey Sharkey
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | package com.trilead.ssh2.compression;
19 |
20 | import java.util.Vector;
21 |
22 | /**
23 | * @author Kenny Root
24 | *
25 | */
26 | public class CompressionFactory {
27 | static class CompressorEntry {
28 | String type;
29 | String compressorClass;
30 |
31 | public CompressorEntry(String type, String compressorClass) {
32 | this.type = type;
33 | this.compressorClass = compressorClass;
34 | }
35 | }
36 |
37 | static VectorHTTPProxyData object is used to specify the needed connection
5 | * data to connect through a HTTP proxy.
6 | *
7 | * @see Connection#setProxyData(ProxyData)
8 | *
9 | * @author Christian Plattner, plattner@trilead.com
10 | * @version $Id: HTTPProxyData.java,v 1.1 2007/10/15 12:49:56 cplattne Exp $
11 | */
12 |
13 | public class HTTPProxyData implements ProxyData {
14 | public final String proxyHost;
15 | public final int proxyPort;
16 | public final String proxyUser;
17 | public final String proxyPass;
18 | public final String[] requestHeaderLines;
19 |
20 | /**
21 | * Same as calling {@link #HTTPProxyData(String, int, String, String)
22 | * HTTPProxyData(proxyHost, proxyPort, null, null
23 | * )}
24 | *
25 | * @param proxyHost
26 | * Proxy hostname.
27 | * @param proxyPort
28 | * Proxy port.
29 | */
30 | public HTTPProxyData(String proxyHost, int proxyPort) {
31 | this(proxyHost, proxyPort, null, null);
32 | }
33 |
34 | /**
35 | * Same as calling
36 | * {@link #HTTPProxyData(String, int, String, String, String[])
37 | * HTTPProxyData(proxyHost, proxyPort, null, null,
38 | * null)}
39 | *
40 | * @param proxyHost
41 | * Proxy hostname.
42 | * @param proxyPort
43 | * Proxy port.
44 | * @param proxyUser
45 | * Username for basic authentication (null if no
46 | * authentication is needed).
47 | * @param proxyPass
48 | * Password for basic authentication (null if no
49 | * authentication is needed).
50 | */
51 | public HTTPProxyData(String proxyHost, int proxyPort, String proxyUser,
52 | String proxyPass) {
53 | this(proxyHost, proxyPort, proxyUser, proxyPass, null);
54 | }
55 |
56 | /**
57 | * Connection data for a HTTP proxy. It is possible to specify a username
58 | * and password if the proxy requires basic authentication. Also, additional
59 | * request header lines can be specified (e.g.,
60 | * "User-Agent: CERN-LineMode/2.15 libwww/2.17b3").
61 | * proxyUser and proxyPass must be non-null.
64 | *
68 | * new HTTPProxyData("192.168.1.1", "3128", "proxyuser", "secret", new String[] {"User-Agent: TrileadBasedClient/1.0", "X-My-Proxy-Option: something"});
69 | *
70 | *
71 | * @param proxyHost
72 | * Proxy hostname.
73 | * @param proxyPort
74 | * Proxy port.
75 | * @param proxyUser
76 | * Username for basic authentication (null if no
77 | * authentication is needed).
78 | * @param proxyPass
79 | * Password for basic authentication (null if no
80 | * authentication is needed).
81 | * @param requestHeaderLines
82 | * An array with additional request header lines (without
83 | * end-of-line markers) that have to be sent to the server. May
84 | * be null.
85 | */
86 |
87 | public HTTPProxyData(String proxyHost, int proxyPort, String proxyUser,
88 | String proxyPass, String[] requestHeaderLines) {
89 | if (proxyHost == null)
90 | throw new IllegalArgumentException("proxyHost must be non-null");
91 |
92 | if (proxyPort < 0)
93 | throw new IllegalArgumentException("proxyPort must be non-negative");
94 |
95 | this.proxyHost = proxyHost;
96 | this.proxyPort = proxyPort;
97 | this.proxyUser = proxyUser;
98 | this.proxyPass = proxyPass;
99 | this.requestHeaderLines = requestHeaderLines;
100 | }
101 | }
102 |
--------------------------------------------------------------------------------
/src/com/jcraft/jzlib/Adler32.java:
--------------------------------------------------------------------------------
1 | /* -*-mode:java; c-basic-offset:2; -*- */
2 | /*
3 | Copyright (c) 2000,2001,2002,2003 ymnk, JCraft,Inc. All rights reserved.
4 |
5 | Redistribution and use in source and binary forms, with or without
6 | modification, are permitted provided that the following conditions are met:
7 |
8 | 1. Redistributions of source code must retain the above copyright notice,
9 | this list of conditions and the following disclaimer.
10 |
11 | 2. Redistributions in binary form must reproduce the above copyright
12 | notice, this list of conditions and the following disclaimer in
13 | the documentation and/or other materials provided with the distribution.
14 |
15 | 3. The names of the authors may not be used to endorse or promote products
16 | derived from this software without specific prior written permission.
17 |
18 | THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
19 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
20 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
21 | INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
22 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
24 | OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
25 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
26 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
27 | EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 | */
29 | /*
30 | * This program is based on zlib-1.1.3, so all credit should go authors
31 | * Jean-loup Gailly(jloup@gzip.org) and Mark Adler(madler@alumni.caltech.edu)
32 | * and contributors of zlib.
33 | */
34 |
35 | package com.jcraft.jzlib;
36 |
37 | final class Adler32 {
38 |
39 | // largest prime smaller than 65536
40 | static final private int BASE = 65521;
41 | // NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1
42 | static final private int NMAX = 5552;
43 |
44 | long adler32(long adler, byte[] buf, int index, int len) {
45 | if (buf == null) {
46 | return 1L;
47 | }
48 |
49 | long s1 = adler & 0xffff;
50 | long s2 = (adler >> 16) & 0xffff;
51 | int k;
52 |
53 | while (len > 0) {
54 | k = len < NMAX ? len : NMAX;
55 | len -= k;
56 | while (k >= 16) {
57 | s1 += buf[index++] & 0xff;
58 | s2 += s1;
59 | s1 += buf[index++] & 0xff;
60 | s2 += s1;
61 | s1 += buf[index++] & 0xff;
62 | s2 += s1;
63 | s1 += buf[index++] & 0xff;
64 | s2 += s1;
65 | s1 += buf[index++] & 0xff;
66 | s2 += s1;
67 | s1 += buf[index++] & 0xff;
68 | s2 += s1;
69 | s1 += buf[index++] & 0xff;
70 | s2 += s1;
71 | s1 += buf[index++] & 0xff;
72 | s2 += s1;
73 | s1 += buf[index++] & 0xff;
74 | s2 += s1;
75 | s1 += buf[index++] & 0xff;
76 | s2 += s1;
77 | s1 += buf[index++] & 0xff;
78 | s2 += s1;
79 | s1 += buf[index++] & 0xff;
80 | s2 += s1;
81 | s1 += buf[index++] & 0xff;
82 | s2 += s1;
83 | s1 += buf[index++] & 0xff;
84 | s2 += s1;
85 | s1 += buf[index++] & 0xff;
86 | s2 += s1;
87 | s1 += buf[index++] & 0xff;
88 | s2 += s1;
89 | k -= 16;
90 | }
91 | if (k != 0) {
92 | do {
93 | s1 += buf[index++] & 0xff;
94 | s2 += s1;
95 | } while (--k != 0);
96 | }
97 | s1 %= BASE;
98 | s2 %= BASE;
99 | }
100 | return (s2 << 16) | s1;
101 | }
102 |
103 | /*
104 | * private java.util.zip.Adler32 adler=new java.util.zip.Adler32(); long
105 | * adler32(long value, byte[] buf, int index, int len){ if(value==1)
106 | * {adler.reset();} if(buf==null) {adler.reset();} else{adler.update(buf,
107 | * index, len);} return adler.getValue(); }
108 | */
109 | }
110 |
--------------------------------------------------------------------------------
/src/com/trilead/ssh2/util/TimeoutService.java:
--------------------------------------------------------------------------------
1 | package com.trilead.ssh2.util;
2 |
3 | import java.io.PrintWriter;
4 | import java.io.StringWriter;
5 | import java.util.Collections;
6 | import java.util.LinkedList;
7 |
8 | import com.trilead.ssh2.log.Logger;
9 |
10 | /**
11 | * TimeoutService (beta). Here you can register a timeout.
12 | * DHGexParameters object can be used to specify parameters for
5 | * the diffie-hellman group exchange.
6 | * SSH_MSG_KEX_DH_GEX_REQUEST or
9 | * SSH_MSG_KEX_DH_GEX_REQUEST_OLD can be forced.
10 | *
11 | * @see Connection#setDHGexParameters(DHGexParameters)
12 | * @author Christian Plattner, plattner@trilead.com
13 | * @version $Id: DHGexParameters.java,v 1.1 2007/10/15 12:49:56 cplattne Exp $
14 | */
15 |
16 | public class DHGexParameters {
17 | private final int min_group_len;
18 | private final int pref_group_len;
19 | private final int max_group_len;
20 |
21 | private static final int MIN_ALLOWED = 1024;
22 | private static final int MAX_ALLOWED = 8192;
23 |
24 | /**
25 | * Same as calling {@link #DHGexParameters(int, int, int)
26 | * DHGexParameters(1024, 1024, 4096)}. This is also the default used by the
27 | * Connection class.
28 | *
29 | */
30 | public DHGexParameters() {
31 | this(1024, 1024, 4096);
32 | }
33 |
34 | /**
35 | * This constructor can be used to force the sending of a
36 | * SSH_MSG_KEX_DH_GEX_REQUEST_OLD request. Internally, the
37 | * minimum and maximum group lengths will be set to zero.
38 | *
39 | * @param pref_group_len
40 | * has to be >= 1024 and <= 8192
41 | */
42 | public DHGexParameters(int pref_group_len) {
43 | if ((pref_group_len < MIN_ALLOWED) || (pref_group_len > MAX_ALLOWED))
44 | throw new IllegalArgumentException("pref_group_len out of range!");
45 |
46 | this.pref_group_len = pref_group_len;
47 | this.min_group_len = 0;
48 | this.max_group_len = 0;
49 | }
50 |
51 | /**
52 | * This constructor can be used to force the sending of a
53 | * SSH_MSG_KEX_DH_GEX_REQUEST request.
54 | * zero if
94 | * SSH_MSG_KEX_DH_GEX_REQUEST_OLD should be requested
95 | */
96 | public int getMax_group_len() {
97 | return max_group_len;
98 | }
99 |
100 | /**
101 | * Get the minimum group length.
102 | *
103 | * @return minimum group length, may be zero if
104 | * SSH_MSG_KEX_DH_GEX_REQUEST_OLD should be requested
105 | */
106 | public int getMin_group_len() {
107 | return min_group_len;
108 | }
109 |
110 | /**
111 | * Get the preferred group length.
112 | *
113 | * @return the preferred group length
114 | */
115 | public int getPref_group_len() {
116 | return pref_group_len;
117 | }
118 | }
119 |
--------------------------------------------------------------------------------
/src/respiteinjector/ConnectMaker.java:
--------------------------------------------------------------------------------
1 | /*
2 | * To change this license header, choose License Headers in Project Properties.
3 | * To change this template file, choose Tools | Templates
4 | * and open the template in the editor.
5 | */
6 | package respiteinjector;
7 |
8 | import java.io.IOException;
9 | import java.io.InputStream;
10 | import java.io.OutputStream;
11 | import java.net.Socket;
12 |
13 | /**
14 | *
15 | * @author user
16 | */
17 | public class ConnectMaker implements Loggable
18 | {
19 | private int id;
20 | private int tamBufferEnvio = 4096;
21 | private int tamBufferRecepcao = 4096;
22 | private Host destino;
23 | private Host cliente;
24 | private boolean isThread1Closed;
25 | private boolean isThread2Closed;
26 |
27 | public ConnectMaker() {}
28 |
29 | public ConnectMaker(Host destino, Host cliente) throws IOException
30 | {
31 | this.cliente = cliente;
32 | this.destino = destino;
33 | }
34 |
35 | public int getTamBufferEnvio() {
36 | return tamBufferEnvio;
37 | }
38 |
39 | public void setTamBufferEnvio(int tamBufferEnvio) {
40 | this.tamBufferEnvio = tamBufferEnvio;
41 | }
42 |
43 | public int getTamBufferRecepcao() {
44 | return tamBufferRecepcao;
45 | }
46 |
47 | public void setTamBufferRecepcao(int tamBufferRecepcao) {
48 | this.tamBufferRecepcao = tamBufferRecepcao;
49 | }
50 |
51 | public Host getDestino() {
52 | return destino;
53 | }
54 |
55 | public void setDestino(Host destino) {
56 | this.destino = destino;
57 | }
58 |
59 | public Host getCliente() {
60 | return cliente;
61 | }
62 |
63 | public void setCliente(Host cliente) {
64 | this.cliente = cliente;
65 | }
66 |
67 | public int getId() {
68 | return id;
69 | }
70 |
71 | public void setId(int id) {
72 | this.id = id;
73 | }
74 |
75 |
76 | public void run()
77 | {
78 | run(cliente, destino, tamBufferEnvio);
79 |
80 | run(destino, cliente, tamBufferRecepcao);
81 | }
82 | private void run(final Host hostIn, final Host hostOut, final int tamBuffer)
83 | {
84 | new Thread(new Runnable()
85 | {
86 | public void run()
87 | {
88 | try
89 | {
90 | InputStream in = hostIn.getIn();
91 | OutputStream out = hostOut.getOut();
92 | Socket inSocket = hostIn.getSocket();
93 | Socket outSocket = hostOut.getSocket();
94 |
95 | byte[] buffer = new byte[tamBuffer];
96 | int len = in.read(buffer);
97 |
98 | while ((len != -1) && (!inSocket.isOutputShutdown())) {
99 | out.write(buffer, 0, len);
100 | out.flush();
101 | len = in.read(buffer);
102 | }
103 |
104 | if ((len == -1) || (inSocket.isOutputShutdown())) {
105 | if (!isThread1Closed) {
106 | isThread1Closed = true;
107 | } else {
108 | isThread2Closed = true;
109 | }
110 | inSocket.shutdownInput();
111 | outSocket.shutdownOutput();
112 | }
113 | } catch (IOException e) {
114 | new GlobalVars().logThis("[INJ] Thread " + getId() + ": error in data transfer. " + e.getMessage(), -1);
115 |
116 | } finally {
117 | if (isThread2Closed) {
118 | try {
119 | destino.close();
120 | cliente.close();
121 | } catch (IOException e) {
122 | new GlobalVars().logThis("[INJ] Thread " + getId() + ": error in closing communication. " + e.getMessage(), -1);
123 |
124 | }
125 | new GlobalVars().logThis("<-> Thread " + getId() + ": connection terminated.");
126 |
127 | }
128 | }
129 | }
130 | })
131 |
132 |
133 |
134 |
135 |
136 |
137 |
138 |
139 |
140 |
141 |
142 |
143 |
144 |
145 |
146 |
147 |
148 |
149 |
150 |
151 |
152 |
153 |
154 |
155 |
156 |
157 |
158 |
159 |
160 |
161 |
162 |
163 |
164 |
165 |
166 |
167 |
168 |
169 |
170 |
171 | .start();
172 | }
173 |
174 | public void onLogReceived(String log, int level, Exception e) {}
175 | }
176 |
--------------------------------------------------------------------------------