├── 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 | 3 | 4 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /src/com/trilead/ssh2/channel/IChannelWorkerThread.java: -------------------------------------------------------------------------------- 1 | package com.trilead.ssh2.channel; 2 | 3 | /** 4 | * IChannelWorkerThread. 5 | * 6 | * @author Christian Plattner, plattner@trilead.com 7 | * @version $Id: IChannelWorkerThread.java,v 1.1 2007/10/15 12:49:56 cplattne 8 | * Exp $ 9 | */ 10 | interface IChannelWorkerThread { 11 | public void stopWorking(); 12 | } 13 | -------------------------------------------------------------------------------- /.idea/Respite HTTP Injector.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /src/com/trilead/ssh2/ProxyData.java: -------------------------------------------------------------------------------- 1 | package com.trilead.ssh2; 2 | 3 | /** 4 | * An abstract marker interface implemented by all proxy data implementations. 5 | * 6 | * @see HTTPProxyData 7 | * 8 | * @author Christian Plattner, plattner@trilead.com 9 | * @version $Id: ProxyData.java,v 1.1 2007/10/15 12:49:56 cplattne Exp $ 10 | */ 11 | 12 | public abstract interface ProxyData { 13 | } 14 | -------------------------------------------------------------------------------- /src/com/trilead/ssh2/crypto/PEMStructure.java: -------------------------------------------------------------------------------- 1 | package com.trilead.ssh2.crypto; 2 | 3 | /** 4 | * Parsed PEM structure. 5 | * 6 | * @author Christian Plattner, plattner@trilead.com 7 | * @version $Id: PEMStructure.java,v 1.1 2007/10/15 12:49:56 cplattne Exp $ 8 | */ 9 | 10 | public class PEMStructure { 11 | public int pemType; 12 | String dekInfo[]; 13 | String procType[]; 14 | public byte[] data; 15 | } -------------------------------------------------------------------------------- /src/com/trilead/ssh2/transport/MessageHandler.java: -------------------------------------------------------------------------------- 1 | package com.trilead.ssh2.transport; 2 | 3 | import java.io.IOException; 4 | 5 | /** 6 | * MessageHandler. 7 | * 8 | * @author Christian Plattner, plattner@trilead.com 9 | * @version $Id: MessageHandler.java,v 1.1 2007/10/15 12:49:56 cplattne Exp $ 10 | */ 11 | public interface MessageHandler { 12 | public void handleMessage(byte[] msg, int msglen) throws IOException; 13 | } 14 | -------------------------------------------------------------------------------- /src/com/trilead/ssh2/transport/NegotiateException.java: -------------------------------------------------------------------------------- 1 | package com.trilead.ssh2.transport; 2 | 3 | /** 4 | * NegotiateException. 5 | * 6 | * @author Christian Plattner, plattner@trilead.com 7 | * @version $Id: NegotiateException.java,v 1.1 2007/10/15 12:49:56 cplattne Exp 8 | * $ 9 | */ 10 | public class NegotiateException extends Exception { 11 | private static final long serialVersionUID = 3689910669428143157L; 12 | } 13 | -------------------------------------------------------------------------------- /src/com/trilead/ssh2/crypto/cipher/BlockCipher.java: -------------------------------------------------------------------------------- 1 | package com.trilead.ssh2.crypto.cipher; 2 | 3 | /** 4 | * BlockCipher. 5 | * 6 | * @author Christian Plattner, plattner@trilead.com 7 | * @version $Id: BlockCipher.java,v 1.1 2007/10/15 12:49:55 cplattne Exp $ 8 | */ 9 | public interface BlockCipher { 10 | public int getBlockSize(); 11 | 12 | public void init(boolean forEncryption, byte[] key); 13 | 14 | public void transformBlock(byte[] src, int srcoff, byte[] dst, int dstoff); 15 | } 16 | -------------------------------------------------------------------------------- /src/com/trilead/ssh2/signature/RSASignature.java: -------------------------------------------------------------------------------- 1 | package com.trilead.ssh2.signature; 2 | 3 | import java.math.BigInteger; 4 | 5 | /** 6 | * RSASignature. 7 | * 8 | * @author Christian Plattner, plattner@trilead.com 9 | * @version $Id: RSASignature.java,v 1.1 2007/10/15 12:49:57 cplattne Exp $ 10 | */ 11 | 12 | public class RSASignature { 13 | BigInteger s; 14 | 15 | public RSASignature(BigInteger s) { 16 | this.s = s; 17 | } 18 | 19 | public BigInteger getS() { 20 | return s; 21 | } 22 | } -------------------------------------------------------------------------------- /nbproject/genfiles.properties: -------------------------------------------------------------------------------- 1 | build.xml.data.CRC32=a9d89046 2 | build.xml.script.CRC32=c14487ac 3 | build.xml.stylesheet.CRC32=8064a381@1.80.1.48 4 | # This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. 5 | # Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. 6 | nbproject/build-impl.xml.data.CRC32=a9d89046 7 | nbproject/build-impl.xml.script.CRC32=13419ecc 8 | nbproject/build-impl.xml.stylesheet.CRC32=830a3534@1.80.1.48 9 | -------------------------------------------------------------------------------- /src/com/trilead/ssh2/channel/RemoteForwardingData.java: -------------------------------------------------------------------------------- 1 | package com.trilead.ssh2.channel; 2 | 3 | /** 4 | * RemoteForwardingData. Data about a requested remote forwarding. 5 | * 6 | * @author Christian Plattner, plattner@trilead.com 7 | * @version $Id: RemoteForwardingData.java,v 1.1 2007/10/15 12:49:56 cplattne 8 | * Exp $ 9 | */ 10 | public class RemoteForwardingData { 11 | public String bindAddress; 12 | public int bindPort; 13 | 14 | String targetAddress; 15 | int targetPort; 16 | } 17 | -------------------------------------------------------------------------------- /src/com/trilead/ssh2/channel/X11ServerData.java: -------------------------------------------------------------------------------- 1 | package com.trilead.ssh2.channel; 2 | 3 | /** 4 | * X11ServerData. Data regarding an x11 forwarding target. 5 | * 6 | * @author Christian Plattner, plattner@trilead.com 7 | * @version $Id: X11ServerData.java,v 1.1 2007/10/15 12:49:56 cplattne Exp $ 8 | * 9 | */ 10 | public class X11ServerData { 11 | public String hostname; 12 | public int port; 13 | public byte[] x11_magic_cookie; /* 14 | * not the remote (fake) one, the local 15 | * (real) one 16 | */ 17 | } 18 | -------------------------------------------------------------------------------- /src/net/sourceforge/jsocks/AuthenticationNone.java: -------------------------------------------------------------------------------- 1 | package net.sourceforge.jsocks; 2 | 3 | /** 4 | * SOCKS5 none authentication. Dummy class does almost nothing. 5 | */ 6 | public class AuthenticationNone implements Authentication { 7 | 8 | @Override 9 | public Object[] doSocksAuthentication(int methodId, 10 | java.net.Socket proxySocket) throws java.io.IOException { 11 | 12 | if (methodId != 0) 13 | return null; 14 | 15 | return new Object[] { proxySocket.getInputStream(), 16 | proxySocket.getOutputStream() }; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /nbproject/project.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | org.netbeans.modules.java.j2seproject 4 | 5 | 6 | Respite HTTP Injector 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /src/com/trilead/ssh2/crypto/digest/Digest.java: -------------------------------------------------------------------------------- 1 | package com.trilead.ssh2.crypto.digest; 2 | 3 | /** 4 | * Digest. 5 | * 6 | * @author Christian Plattner, plattner@trilead.com 7 | * @version $Id: Digest.java,v 1.1 2007/10/15 12:49:57 cplattne Exp $ 8 | */ 9 | public interface Digest { 10 | public void digest(byte[] out); 11 | 12 | public void digest(byte[] out, int off); 13 | 14 | public int getDigestLength(); 15 | 16 | public void reset(); 17 | 18 | public void update(byte b); 19 | 20 | public void update(byte b[], int off, int len); 21 | 22 | public void update(byte[] b); 23 | } 24 | -------------------------------------------------------------------------------- /src/respiteinjector/GlobalVars.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 respite.http.injector.MainForm; 9 | 10 | /** 11 | * 12 | * @author user 13 | */ 14 | public class GlobalVars { 15 | 16 | public void logThis(String log) { 17 | MainForm.Log(log, 0); 18 | } 19 | 20 | public void logThis(String log, int verb) { 21 | MainForm.Log(log, verb); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/com/trilead/ssh2/signature/RSAPublicKey.java: -------------------------------------------------------------------------------- 1 | package com.trilead.ssh2.signature; 2 | 3 | import java.math.BigInteger; 4 | 5 | /** 6 | * RSAPublicKey. 7 | * 8 | * @author Christian Plattner, plattner@trilead.com 9 | * @version $Id: RSAPublicKey.java,v 1.1 2007/10/15 12:49:57 cplattne Exp $ 10 | */ 11 | public class RSAPublicKey { 12 | BigInteger e; 13 | BigInteger n; 14 | 15 | public RSAPublicKey(BigInteger e, BigInteger n) { 16 | this.e = e; 17 | this.n = n; 18 | } 19 | 20 | public BigInteger getE() { 21 | return e; 22 | } 23 | 24 | public BigInteger getN() { 25 | return n; 26 | } 27 | } -------------------------------------------------------------------------------- /src/com/trilead/ssh2/signature/DSASignature.java: -------------------------------------------------------------------------------- 1 | package com.trilead.ssh2.signature; 2 | 3 | import java.math.BigInteger; 4 | 5 | /** 6 | * DSASignature. 7 | * 8 | * @author Christian Plattner, plattner@trilead.com 9 | * @version $Id: DSASignature.java,v 1.1 2007/10/15 12:49:57 cplattne Exp $ 10 | */ 11 | public class DSASignature { 12 | private BigInteger r; 13 | private BigInteger s; 14 | 15 | public DSASignature(BigInteger r, BigInteger s) { 16 | this.r = r; 17 | this.s = s; 18 | } 19 | 20 | public BigInteger getR() { 21 | return r; 22 | } 23 | 24 | public BigInteger getS() { 25 | return s; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/respiteinjector/Loggable.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 abstract interface Loggable 13 | { 14 | public static final int LOG_LEVEL_DEBUG = 2; 15 | public static final int LOG_LEVEL_INFO = 1; 16 | public static final int LOG_LEVEL_ATENTION = 0; 17 | public static final int LOG_LEVEL_CRITICAL = -1; 18 | 19 | public abstract void onLogReceived(String paramString, int paramInt, Exception paramException); 20 | } 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 |
3 | LoveLetter 4 |
5 |

respite HTTP injector

6 |

“As we've come to realize, the idea that security starts and ends with the purchase of a prepackaged firewall is simply misguided.”

7 |
8 | 9 | [![](https://img.shields.io/sourceforge/dw/http-injector-plus.svg)](https://sourceforge.net/projects/http-injector-plus/files/latest/download) 10 | 11 | # Description 12 | a powerful but simple tool to modify HTTP Proxy CONNECT requests and response to bypass ISP censorship and firewalls, purely coded in Java. 13 | 14 | Free to use but comes with no warranty. 15 | -------------------------------------------------------------------------------- /src/com/trilead/ssh2/packets/PacketKexDHInit.java: -------------------------------------------------------------------------------- 1 | package com.trilead.ssh2.packets; 2 | 3 | import java.math.BigInteger; 4 | 5 | /** 6 | * PacketKexDHInit. 7 | * 8 | * @author Christian Plattner, plattner@trilead.com 9 | * @version $Id: PacketKexDHInit.java,v 1.1 2007/10/15 12:49:55 cplattne Exp $ 10 | */ 11 | public class PacketKexDHInit { 12 | byte[] payload; 13 | 14 | BigInteger e; 15 | 16 | public PacketKexDHInit(BigInteger e) { 17 | this.e = e; 18 | } 19 | 20 | public byte[] getPayload() { 21 | if (payload == null) { 22 | TypesWriter tw = new TypesWriter(); 23 | tw.writeByte(Packets.SSH_MSG_KEXDH_INIT); 24 | tw.writeMPInt(e); 25 | payload = tw.getBytes(); 26 | } 27 | return payload; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/com/trilead/ssh2/packets/PacketGlobalTrileadPing.java: -------------------------------------------------------------------------------- 1 | package com.trilead.ssh2.packets; 2 | 3 | /** 4 | * PacketGlobalTrileadPing. 5 | * 6 | * @author Christian Plattner, plattner@trilead.com 7 | * @version $Id: PacketGlobalTrileadPing.java,v 1.1 2008/03/03 07:01:36 cplattne 8 | * Exp $ 9 | */ 10 | public class PacketGlobalTrileadPing { 11 | byte[] payload; 12 | 13 | public PacketGlobalTrileadPing() { 14 | } 15 | 16 | public byte[] getPayload() { 17 | if (payload == null) { 18 | TypesWriter tw = new TypesWriter(); 19 | tw.writeByte(Packets.SSH_MSG_GLOBAL_REQUEST); 20 | 21 | tw.writeString("trilead-ping"); 22 | tw.writeBoolean(true); 23 | 24 | payload = tw.getBytes(); 25 | } 26 | return payload; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/com/trilead/ssh2/packets/PacketKexDhGexInit.java: -------------------------------------------------------------------------------- 1 | package com.trilead.ssh2.packets; 2 | 3 | import java.math.BigInteger; 4 | 5 | /** 6 | * PacketKexDhGexInit. 7 | * 8 | * @author Christian Plattner, plattner@trilead.com 9 | * @version $Id: PacketKexDhGexInit.java,v 1.1 2007/10/15 12:49:55 cplattne Exp 10 | * $ 11 | */ 12 | public class PacketKexDhGexInit { 13 | byte[] payload; 14 | 15 | BigInteger e; 16 | 17 | public PacketKexDhGexInit(BigInteger e) { 18 | this.e = e; 19 | } 20 | 21 | public byte[] getPayload() { 22 | if (payload == null) { 23 | TypesWriter tw = new TypesWriter(); 24 | tw.writeByte(Packets.SSH_MSG_KEX_DH_GEX_INIT); 25 | tw.writeMPInt(e); 26 | payload = tw.getBytes(); 27 | } 28 | return payload; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/com/trilead/ssh2/DebugLogger.java: -------------------------------------------------------------------------------- 1 | package com.trilead.ssh2; 2 | 3 | /** 4 | * An interface which needs to be implemented if you want to capture debugging 5 | * messages. 6 | * 7 | * @see Connection#enableDebugging(boolean, DebugLogger) 8 | * 9 | * @author Christian Plattner, plattner@trilead.com 10 | * @version $Id: DebugLogger.java,v 1.1 2008/03/03 07:01:36 cplattne Exp $ 11 | */ 12 | public interface DebugLogger { 13 | 14 | /** 15 | * Log a debug message. 16 | * 17 | * @param level 18 | * 0-99, 99 is a the most verbose level 19 | * @param className 20 | * the class that generated the message 21 | * @param message 22 | * the debug message 23 | */ 24 | public void log(int level, String className, String message); 25 | } 26 | -------------------------------------------------------------------------------- /src/com/trilead/ssh2/transport/NegotiatedParameters.java: -------------------------------------------------------------------------------- 1 | package com.trilead.ssh2.transport; 2 | 3 | /** 4 | * NegotiatedParameters. 5 | * 6 | * @author Christian Plattner, plattner@trilead.com 7 | * @version $Id: NegotiatedParameters.java,v 1.1 2007/10/15 12:49:57 cplattne 8 | * Exp $ 9 | */ 10 | public class NegotiatedParameters { 11 | public boolean guessOK; 12 | public String kex_algo; 13 | public String server_host_key_algo; 14 | public String enc_algo_client_to_server; 15 | public String enc_algo_server_to_client; 16 | public String mac_algo_client_to_server; 17 | public String mac_algo_server_to_client; 18 | public String comp_algo_client_to_server; 19 | public String comp_algo_server_to_client; 20 | public String lang_client_to_server; 21 | public String lang_server_to_client; 22 | } 23 | -------------------------------------------------------------------------------- /user.data: -------------------------------------------------------------------------------- 1 | {"Version":2020.3,"Payload":"CONNECT [host_port]@clients3.google.com [protocol][crlf] Host: clients3.google.com[crlf][crlf]","Proxy":"sg3-private.tcpvpn.com:81","SSH_Host":"sg3-private.tcpvpn.com","SSH_Port":"22","SSH_Username":"tcpvpn.com-alizer","SSH_Password":"alizer","LocalProxyInterface_Host":"127.0.0.1","LocalProxyInterface_Port":"5085","LocalSSHInterface_Host":"","LocalSSHInterface_Port":"8080","AllowSSH":true,"PayloadHost":"","PayloadCheckBoxes":{"Real Data":false,"X-Forwarded-For":false,"X-Online-Host":false,"User-Agent":false,"Split":false,"X-Forwarded-Host":false,"Keep-Alive":false,"Dual Connect":false,"":false},"RadioButtons":{"Front Query":false,"Back Query":true,"[cr]":false,"[crlf]":true,"None / Middle Query":false,"[lf]":false},"TextFields":{"host":"clients3.google.com"},"Comboboxes":{"reqmeth":0,"injmeth":2}} -------------------------------------------------------------------------------- /src/com/trilead/ssh2/crypto/cipher/NullCipher.java: -------------------------------------------------------------------------------- 1 | package com.trilead.ssh2.crypto.cipher; 2 | 3 | /** 4 | * NullCipher. 5 | * 6 | * @author Christian Plattner, plattner@trilead.com 7 | * @version $Id: NullCipher.java,v 1.1 2007/10/15 12:49:55 cplattne Exp $ 8 | */ 9 | public class NullCipher implements BlockCipher { 10 | private int blockSize = 8; 11 | 12 | public NullCipher() { 13 | } 14 | 15 | public NullCipher(int blockSize) { 16 | this.blockSize = blockSize; 17 | } 18 | 19 | @Override 20 | public int getBlockSize() { 21 | return blockSize; 22 | } 23 | 24 | @Override 25 | public void init(boolean forEncryption, byte[] key) { 26 | } 27 | 28 | @Override 29 | public void transformBlock(byte[] src, int srcoff, byte[] dst, int dstoff) { 30 | System.arraycopy(src, srcoff, dst, dstoff, blockSize); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/com/trilead/ssh2/packets/PacketChannelAuthAgentReq.java: -------------------------------------------------------------------------------- 1 | package com.trilead.ssh2.packets; 2 | 3 | /** 4 | * PacketGlobalAuthAgent. 5 | * 6 | * @author Kenny Root, kenny@the-b.org 7 | * @version $Id$ 8 | */ 9 | public class PacketChannelAuthAgentReq { 10 | byte[] payload; 11 | 12 | public int recipientChannelID; 13 | 14 | public PacketChannelAuthAgentReq(int recipientChannelID) { 15 | this.recipientChannelID = recipientChannelID; 16 | } 17 | 18 | public byte[] getPayload() { 19 | if (payload == null) { 20 | TypesWriter tw = new TypesWriter(); 21 | tw.writeByte(Packets.SSH_MSG_CHANNEL_REQUEST); 22 | tw.writeUINT32(recipientChannelID); 23 | tw.writeString("auth-agent-req@openssh.com"); 24 | tw.writeBoolean(true); // want reply 25 | payload = tw.getBytes(); 26 | } 27 | return payload; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/com/trilead/ssh2/packets/PacketKexDhGexRequestOld.java: -------------------------------------------------------------------------------- 1 | package com.trilead.ssh2.packets; 2 | 3 | import com.trilead.ssh2.DHGexParameters; 4 | 5 | /** 6 | * PacketKexDhGexRequestOld. 7 | * 8 | * @author Christian Plattner, plattner@trilead.com 9 | * @version $Id: PacketKexDhGexRequestOld.java,v 1.1 2007/10/15 12:49:55 10 | * cplattne Exp $ 11 | */ 12 | public class PacketKexDhGexRequestOld { 13 | byte[] payload; 14 | 15 | int n; 16 | 17 | public PacketKexDhGexRequestOld(DHGexParameters para) { 18 | this.n = para.getPref_group_len(); 19 | } 20 | 21 | public byte[] getPayload() { 22 | if (payload == null) { 23 | TypesWriter tw = new TypesWriter(); 24 | tw.writeByte(Packets.SSH_MSG_KEX_DH_GEX_REQUEST_OLD); 25 | tw.writeUINT32(n); 26 | payload = tw.getBytes(); 27 | } 28 | return payload; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/com/trilead/ssh2/signature/RSAPrivateKey.java: -------------------------------------------------------------------------------- 1 | package com.trilead.ssh2.signature; 2 | 3 | import java.math.BigInteger; 4 | 5 | /** 6 | * RSAPrivateKey. 7 | * 8 | * @author Christian Plattner, plattner@trilead.com 9 | * @version $Id: RSAPrivateKey.java,v 1.1 2007/10/15 12:49:57 cplattne Exp $ 10 | */ 11 | public class RSAPrivateKey { 12 | private BigInteger d; 13 | private BigInteger e; 14 | private BigInteger n; 15 | 16 | public RSAPrivateKey(BigInteger d, BigInteger e, BigInteger n) { 17 | this.d = d; 18 | this.e = e; 19 | this.n = n; 20 | } 21 | 22 | public BigInteger getD() { 23 | return d; 24 | } 25 | 26 | public BigInteger getE() { 27 | return e; 28 | } 29 | 30 | public BigInteger getN() { 31 | return n; 32 | } 33 | 34 | public RSAPublicKey getPublicKey() { 35 | return new RSAPublicKey(e, n); 36 | } 37 | } -------------------------------------------------------------------------------- /src/com/trilead/ssh2/signature/DSAPublicKey.java: -------------------------------------------------------------------------------- 1 | package com.trilead.ssh2.signature; 2 | 3 | import java.math.BigInteger; 4 | 5 | /** 6 | * DSAPublicKey. 7 | * 8 | * @author Christian Plattner, plattner@trilead.com 9 | * @version $Id: DSAPublicKey.java,v 1.1 2007/10/15 12:49:57 cplattne Exp $ 10 | */ 11 | public class DSAPublicKey { 12 | private BigInteger p; 13 | private BigInteger q; 14 | private BigInteger g; 15 | private BigInteger y; 16 | 17 | public DSAPublicKey(BigInteger p, BigInteger q, BigInteger g, BigInteger y) { 18 | this.p = p; 19 | this.q = q; 20 | this.g = g; 21 | this.y = y; 22 | } 23 | 24 | public BigInteger getG() { 25 | return g; 26 | } 27 | 28 | public BigInteger getP() { 29 | return p; 30 | } 31 | 32 | public BigInteger getQ() { 33 | return q; 34 | } 35 | 36 | public BigInteger getY() { 37 | return y; 38 | } 39 | } -------------------------------------------------------------------------------- /src/com/trilead/ssh2/transport/KexState.java: -------------------------------------------------------------------------------- 1 | package com.trilead.ssh2.transport; 2 | 3 | import java.math.BigInteger; 4 | 5 | import com.trilead.ssh2.DHGexParameters; 6 | import com.trilead.ssh2.crypto.dh.DhExchange; 7 | import com.trilead.ssh2.crypto.dh.DhGroupExchange; 8 | import com.trilead.ssh2.packets.PacketKexInit; 9 | 10 | /** 11 | * KexState. 12 | * 13 | * @author Christian Plattner, plattner@trilead.com 14 | * @version $Id: KexState.java,v 1.1 2007/10/15 12:49:57 cplattne Exp $ 15 | */ 16 | public class KexState { 17 | public PacketKexInit localKEX; 18 | public PacketKexInit remoteKEX; 19 | public NegotiatedParameters np; 20 | public int state = 0; 21 | 22 | public BigInteger K; 23 | public byte[] H; 24 | 25 | public byte[] hostkey; 26 | 27 | public DhExchange dhx; 28 | public DhGroupExchange dhgx; 29 | public DHGexParameters dhgexParameters; 30 | } 31 | -------------------------------------------------------------------------------- /src/com/trilead/ssh2/packets/PacketChannelTrileadPing.java: -------------------------------------------------------------------------------- 1 | package com.trilead.ssh2.packets; 2 | 3 | /** 4 | * PacketChannelTrileadPing. 5 | * 6 | * @author Christian Plattner, plattner@trilead.com 7 | * @version $Id: PacketChannelTrileadPing.java,v 1.1 2008/03/03 07:01:36 8 | * cplattne Exp $ 9 | */ 10 | public class PacketChannelTrileadPing { 11 | byte[] payload; 12 | 13 | public int recipientChannelID; 14 | 15 | public PacketChannelTrileadPing(int recipientChannelID) { 16 | this.recipientChannelID = recipientChannelID; 17 | } 18 | 19 | public byte[] getPayload() { 20 | if (payload == null) { 21 | TypesWriter tw = new TypesWriter(); 22 | tw.writeByte(Packets.SSH_MSG_CHANNEL_REQUEST); 23 | tw.writeUINT32(recipientChannelID); 24 | tw.writeString("trilead-ping"); 25 | tw.writeBoolean(true); 26 | payload = tw.getBytes(); 27 | } 28 | return payload; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/com/trilead/ssh2/HTTPProxyException.java: -------------------------------------------------------------------------------- 1 | package com.trilead.ssh2; 2 | 3 | import java.io.IOException; 4 | 5 | /** 6 | * May be thrown upon connect() if a HTTP proxy is being used. 7 | * 8 | * @see Connection#connect() 9 | * @see Connection#setProxyData(ProxyData) 10 | * 11 | * @author Christian Plattner, plattner@trilead.com 12 | * @version $Id: HTTPProxyException.java,v 1.1 2007/10/15 12:49:56 cplattne Exp 13 | * $ 14 | */ 15 | 16 | public class HTTPProxyException extends IOException { 17 | private static final long serialVersionUID = 2241537397104426186L; 18 | 19 | public final String httpResponse; 20 | public final int httpErrorCode; 21 | 22 | public HTTPProxyException(String httpResponse, int httpErrorCode) { 23 | super("HTTP Proxy Error (" + httpErrorCode + " " + httpResponse + ")"); 24 | this.httpResponse = httpResponse; 25 | this.httpErrorCode = httpErrorCode; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/com/trilead/ssh2/packets/PacketUserauthInfoResponse.java: -------------------------------------------------------------------------------- 1 | package com.trilead.ssh2.packets; 2 | 3 | /** 4 | * PacketUserauthInfoResponse. 5 | * 6 | * @author Christian Plattner, plattner@trilead.com 7 | * @version $Id: PacketUserauthInfoResponse.java,v 1.1 2007/10/15 12:49:55 8 | * cplattne Exp $ 9 | */ 10 | public class PacketUserauthInfoResponse { 11 | byte[] payload; 12 | 13 | String[] responses; 14 | 15 | public PacketUserauthInfoResponse(String[] responses) { 16 | this.responses = responses; 17 | } 18 | 19 | public byte[] getPayload() { 20 | if (payload == null) { 21 | TypesWriter tw = new TypesWriter(); 22 | tw.writeByte(Packets.SSH_MSG_USERAUTH_INFO_RESPONSE); 23 | tw.writeUINT32(responses.length); 24 | for (int i = 0; i < responses.length; i++) 25 | tw.writeString(responses[i]); 26 | 27 | payload = tw.getBytes(); 28 | } 29 | return payload; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/respite/http/injector/Config.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 | /** 9 | * 10 | * @author user 11 | */ 12 | public class Config { 13 | public double Version = 2020.3; 14 | public String Payload = ""; // base 64, encrypted 15 | public String Proxy = ""; 16 | public String SSH_Host = ""; 17 | public String SSH_Port = ""; 18 | public String SSH_Username = ""; 19 | public String SSH_Password = ""; 20 | public String LocalProxyInterface_Host = ""; 21 | public String LocalProxyInterface_Port = ""; 22 | public String LocalSSHInterface_Host = ""; 23 | public String LocalSSHInterface_Port = ""; 24 | public boolean AllowSSH = true; 25 | public boolean Encrypted = false; 26 | } 27 | -------------------------------------------------------------------------------- /src/com/trilead/ssh2/transport/KexParameters.java: -------------------------------------------------------------------------------- 1 | package com.trilead.ssh2.transport; 2 | 3 | /** 4 | * KexParameters. 5 | * 6 | * @author Christian Plattner, plattner@trilead.com 7 | * @version $Id: KexParameters.java,v 1.1 2007/10/15 12:49:56 cplattne Exp $ 8 | */ 9 | public class KexParameters { 10 | public byte[] cookie; 11 | public String[] kex_algorithms; 12 | public String[] server_host_key_algorithms; 13 | public String[] encryption_algorithms_client_to_server; 14 | public String[] encryption_algorithms_server_to_client; 15 | public String[] mac_algorithms_client_to_server; 16 | public String[] mac_algorithms_server_to_client; 17 | public String[] compression_algorithms_client_to_server; 18 | public String[] compression_algorithms_server_to_client; 19 | public String[] languages_client_to_server; 20 | public String[] languages_server_to_client; 21 | public boolean first_kex_packet_follows; 22 | public int reserved_field1; 23 | } 24 | -------------------------------------------------------------------------------- /src/com/trilead/ssh2/packets/PacketSessionStartShell.java: -------------------------------------------------------------------------------- 1 | package com.trilead.ssh2.packets; 2 | 3 | /** 4 | * PacketSessionStartShell. 5 | * 6 | * @author Christian Plattner, plattner@trilead.com 7 | * @version $Id: PacketSessionStartShell.java,v 1.1 2007/10/15 12:49:55 cplattne 8 | * Exp $ 9 | */ 10 | public class PacketSessionStartShell { 11 | byte[] payload; 12 | 13 | public int recipientChannelID; 14 | public boolean wantReply; 15 | 16 | public PacketSessionStartShell(int recipientChannelID, boolean wantReply) { 17 | this.recipientChannelID = recipientChannelID; 18 | this.wantReply = wantReply; 19 | } 20 | 21 | public byte[] getPayload() { 22 | if (payload == null) { 23 | TypesWriter tw = new TypesWriter(); 24 | tw.writeByte(Packets.SSH_MSG_CHANNEL_REQUEST); 25 | tw.writeUINT32(recipientChannelID); 26 | tw.writeString("shell"); 27 | tw.writeBoolean(wantReply); 28 | payload = tw.getBytes(); 29 | } 30 | return payload; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/com/trilead/ssh2/packets/PacketKexDhGexRequest.java: -------------------------------------------------------------------------------- 1 | package com.trilead.ssh2.packets; 2 | 3 | import com.trilead.ssh2.DHGexParameters; 4 | 5 | /** 6 | * PacketKexDhGexRequest. 7 | * 8 | * @author Christian Plattner, plattner@trilead.com 9 | * @version $Id: PacketKexDhGexRequest.java,v 1.1 2007/10/15 12:49:55 cplattne 10 | * Exp $ 11 | */ 12 | public class PacketKexDhGexRequest { 13 | byte[] payload; 14 | 15 | int min; 16 | int n; 17 | int max; 18 | 19 | public PacketKexDhGexRequest(DHGexParameters para) { 20 | this.min = para.getMin_group_len(); 21 | this.n = para.getPref_group_len(); 22 | this.max = para.getMax_group_len(); 23 | } 24 | 25 | public byte[] getPayload() { 26 | if (payload == null) { 27 | TypesWriter tw = new TypesWriter(); 28 | tw.writeByte(Packets.SSH_MSG_KEX_DH_GEX_REQUEST); 29 | tw.writeUINT32(min); 30 | tw.writeUINT32(n); 31 | tw.writeUINT32(max); 32 | payload = tw.getBytes(); 33 | } 34 | return payload; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/com/trilead/ssh2/packets/PacketGlobalForwardRequest.java: -------------------------------------------------------------------------------- 1 | package com.trilead.ssh2.packets; 2 | 3 | /** 4 | * PacketGlobalForwardRequest. 5 | * 6 | * @author Christian Plattner, plattner@trilead.com 7 | * @version $Id: PacketGlobalForwardRequest.java,v 1.1 2007/10/15 12:49:55 8 | * cplattne Exp $ 9 | */ 10 | public class PacketGlobalForwardRequest { 11 | byte[] payload; 12 | 13 | public boolean wantReply; 14 | public String bindAddress; 15 | public int bindPort; 16 | 17 | public PacketGlobalForwardRequest(boolean wantReply, String bindAddress, 18 | 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("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 | -------------------------------------------------------------------------------- /src/com/trilead/ssh2/packets/PacketSessionExecCommand.java: -------------------------------------------------------------------------------- 1 | package com.trilead.ssh2.packets; 2 | 3 | /** 4 | * PacketSessionExecCommand. 5 | * 6 | * @author Christian Plattner, plattner@trilead.com 7 | * @version $Id: PacketSessionExecCommand.java,v 1.1 2007/10/15 12:49:55 8 | * cplattne Exp $ 9 | */ 10 | public class PacketSessionExecCommand { 11 | byte[] payload; 12 | 13 | public int recipientChannelID; 14 | public boolean wantReply; 15 | public String command; 16 | 17 | public PacketSessionExecCommand(int recipientChannelID, boolean wantReply, 18 | String command) { 19 | this.recipientChannelID = recipientChannelID; 20 | this.wantReply = wantReply; 21 | this.command = command; 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("exec"); 30 | tw.writeBoolean(wantReply); 31 | tw.writeString(command); 32 | payload = tw.getBytes(); 33 | } 34 | return payload; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/com/trilead/ssh2/signature/DSAPrivateKey.java: -------------------------------------------------------------------------------- 1 | package com.trilead.ssh2.signature; 2 | 3 | import java.math.BigInteger; 4 | 5 | /** 6 | * DSAPrivateKey. 7 | * 8 | * @author Christian Plattner, plattner@trilead.com 9 | * @version $Id: DSAPrivateKey.java,v 1.1 2007/10/15 12:49:57 cplattne Exp $ 10 | */ 11 | public class DSAPrivateKey { 12 | private BigInteger p; 13 | private BigInteger q; 14 | private BigInteger g; 15 | private BigInteger x; 16 | private BigInteger y; 17 | 18 | public DSAPrivateKey(BigInteger p, BigInteger q, BigInteger g, 19 | BigInteger y, BigInteger x) { 20 | this.p = p; 21 | this.q = q; 22 | this.g = g; 23 | this.y = y; 24 | this.x = x; 25 | } 26 | 27 | public BigInteger getG() { 28 | return g; 29 | } 30 | 31 | public BigInteger getP() { 32 | return p; 33 | } 34 | 35 | public DSAPublicKey getPublicKey() { 36 | return new DSAPublicKey(p, q, g, y); 37 | } 38 | 39 | public BigInteger getQ() { 40 | return q; 41 | } 42 | 43 | public BigInteger getX() { 44 | return x; 45 | } 46 | 47 | public BigInteger getY() { 48 | return y; 49 | } 50 | } -------------------------------------------------------------------------------- /src/com/trilead/ssh2/packets/PacketSessionPtyResize.java: -------------------------------------------------------------------------------- 1 | package com.trilead.ssh2.packets; 2 | 3 | public class PacketSessionPtyResize { 4 | byte[] payload; 5 | 6 | public int recipientChannelID; 7 | public int width; 8 | public int height; 9 | public int pixelWidth; 10 | public int pixelHeight; 11 | 12 | public PacketSessionPtyResize(int recipientChannelID, int width, 13 | int height, int pixelWidth, int pixelHeight) { 14 | this.recipientChannelID = recipientChannelID; 15 | this.width = width; 16 | this.height = height; 17 | this.pixelWidth = pixelWidth; 18 | this.pixelHeight = pixelHeight; 19 | } 20 | 21 | public byte[] getPayload() { 22 | if (payload == null) { 23 | TypesWriter tw = new TypesWriter(); 24 | tw.writeByte(Packets.SSH_MSG_CHANNEL_REQUEST); 25 | tw.writeUINT32(recipientChannelID); 26 | tw.writeString("window-change"); 27 | tw.writeBoolean(false); 28 | tw.writeUINT32(width); 29 | tw.writeUINT32(height); 30 | tw.writeUINT32(pixelWidth); 31 | tw.writeUINT32(pixelHeight); 32 | 33 | payload = tw.getBytes(); 34 | } 35 | return payload; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/com/trilead/ssh2/SFTPv3FileHandle.java: -------------------------------------------------------------------------------- 1 | package com.trilead.ssh2; 2 | 3 | /** 4 | * A 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 PayloadCheckBoxes = new Hashtable(); 29 | public Hashtable RadioButtons = new Hashtable(); 30 | public Hashtable TextFields = new Hashtable(); 31 | public Hashtable Comboboxes = new Hashtable(); 32 | } 33 | -------------------------------------------------------------------------------- /src/com/trilead/ssh2/log/Logger.java: -------------------------------------------------------------------------------- 1 | package com.trilead.ssh2.log; 2 | 3 | import com.trilead.ssh2.DebugLogger; 4 | 5 | /** 6 | * Logger - a very simple logger, mainly used during development. Is not based 7 | * on log4j (to reduce external dependencies). However, if needed, something 8 | * like log4j could easily be hooked in. 9 | *

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 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 | *

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 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 | *

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:
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 | *

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 (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 | *

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 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 | Map retrieveIdentities(); 65 | 66 | /** 67 | * @param lockPassphrase 68 | */ 69 | boolean setAgentLock(String lockPassphrase); 70 | } 71 | -------------------------------------------------------------------------------- /src/com/trilead/ssh2/crypto/digest/HMAC.java: -------------------------------------------------------------------------------- 1 | package com.trilead.ssh2.crypto.digest; 2 | 3 | /** 4 | * HMAC. 5 | * 6 | * @author Christian Plattner, plattner@trilead.com 7 | * @version $Id: HMAC.java,v 1.1 2007/10/15 12:49:57 cplattne Exp $ 8 | */ 9 | public final class HMAC implements Digest { 10 | Digest md; 11 | byte[] k_xor_ipad; 12 | byte[] k_xor_opad; 13 | 14 | byte[] tmp; 15 | 16 | int size; 17 | 18 | public HMAC(Digest md, byte[] key, int size) { 19 | this.md = md; 20 | this.size = size; 21 | 22 | tmp = new byte[md.getDigestLength()]; 23 | 24 | final int BLOCKSIZE = 64; 25 | 26 | k_xor_ipad = new byte[BLOCKSIZE]; 27 | k_xor_opad = new byte[BLOCKSIZE]; 28 | 29 | if (key.length > BLOCKSIZE) { 30 | md.reset(); 31 | md.update(key); 32 | md.digest(tmp); 33 | key = tmp; 34 | } 35 | 36 | System.arraycopy(key, 0, k_xor_ipad, 0, key.length); 37 | System.arraycopy(key, 0, k_xor_opad, 0, key.length); 38 | 39 | for (int i = 0; i < BLOCKSIZE; i++) { 40 | k_xor_ipad[i] ^= 0x36; 41 | k_xor_opad[i] ^= 0x5C; 42 | } 43 | md.update(k_xor_ipad); 44 | } 45 | 46 | @Override 47 | public final void digest(byte[] out) { 48 | digest(out, 0); 49 | } 50 | 51 | @Override 52 | public final void digest(byte[] out, int off) { 53 | md.digest(tmp); 54 | 55 | md.update(k_xor_opad); 56 | md.update(tmp); 57 | 58 | md.digest(tmp); 59 | 60 | System.arraycopy(tmp, 0, out, off, size); 61 | 62 | md.update(k_xor_ipad); 63 | } 64 | 65 | @Override 66 | public final int getDigestLength() { 67 | return size; 68 | } 69 | 70 | @Override 71 | public final void reset() { 72 | md.reset(); 73 | md.update(k_xor_ipad); 74 | } 75 | 76 | @Override 77 | public final void update(byte b) { 78 | md.update(b); 79 | } 80 | 81 | @Override 82 | public final void update(byte[] b) { 83 | md.update(b); 84 | } 85 | 86 | @Override 87 | public final void update(byte[] b, int off, int len) { 88 | md.update(b, off, len); 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /src/com/trilead/ssh2/packets/PacketUserauthInfoRequest.java: -------------------------------------------------------------------------------- 1 | package com.trilead.ssh2.packets; 2 | 3 | import java.io.IOException; 4 | 5 | /** 6 | * PacketUserauthInfoRequest. 7 | * 8 | * @author Christian Plattner, plattner@trilead.com 9 | * @version $Id: PacketUserauthInfoRequest.java,v 1.1 2007/10/15 12:49:55 10 | * cplattne Exp $ 11 | */ 12 | public class PacketUserauthInfoRequest { 13 | byte[] payload; 14 | 15 | String name; 16 | String instruction; 17 | String languageTag; 18 | int numPrompts; 19 | 20 | String prompt[]; 21 | boolean echo[]; 22 | 23 | public PacketUserauthInfoRequest(byte payload[], int off, int len) 24 | throws IOException { 25 | this.payload = new byte[len]; 26 | System.arraycopy(payload, off, this.payload, 0, len); 27 | 28 | TypesReader tr = new TypesReader(payload, off, len); 29 | 30 | int packet_type = tr.readByte(); 31 | 32 | if (packet_type != Packets.SSH_MSG_USERAUTH_INFO_REQUEST) 33 | throw new IOException( 34 | "This is not a SSH_MSG_USERAUTH_INFO_REQUEST! (" 35 | + packet_type + ")"); 36 | 37 | name = tr.readString(); 38 | instruction = tr.readString(); 39 | languageTag = tr.readString(); 40 | 41 | numPrompts = tr.readUINT32(); 42 | 43 | prompt = new String[numPrompts]; 44 | echo = new boolean[numPrompts]; 45 | 46 | for (int i = 0; i < numPrompts; i++) { 47 | prompt[i] = tr.readString(); 48 | echo[i] = tr.readBoolean(); 49 | } 50 | 51 | if (tr.remain() != 0) 52 | throw new IOException( 53 | "Padding in SSH_MSG_USERAUTH_INFO_REQUEST packet!"); 54 | } 55 | 56 | public boolean[] getEcho() { 57 | return echo; 58 | } 59 | 60 | public String getInstruction() { 61 | return instruction; 62 | } 63 | 64 | public String getLanguageTag() { 65 | return languageTag; 66 | } 67 | 68 | public String getName() { 69 | return name; 70 | } 71 | 72 | public int getNumPrompts() { 73 | return numPrompts; 74 | } 75 | 76 | public String[] getPrompt() { 77 | return prompt; 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /src/com/trilead/ssh2/packets/PacketUserauthRequestPassword.java: -------------------------------------------------------------------------------- 1 | package com.trilead.ssh2.packets; 2 | 3 | import java.io.IOException; 4 | 5 | /** 6 | * PacketUserauthRequestPassword. 7 | * 8 | * @author Christian Plattner, plattner@trilead.com 9 | * @version $Id: PacketUserauthRequestPassword.java,v 1.1 2007/10/15 12:49:55 10 | * cplattne Exp $ 11 | */ 12 | public class PacketUserauthRequestPassword { 13 | byte[] payload; 14 | 15 | String userName; 16 | String serviceName; 17 | String password; 18 | 19 | public PacketUserauthRequestPassword(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_USERAUTH_REQUEST) 29 | throw new IOException("This is not a SSH_MSG_USERAUTH_REQUEST! (" 30 | + packet_type + ")"); 31 | 32 | userName = tr.readString(); 33 | serviceName = tr.readString(); 34 | 35 | String method = tr.readString(); 36 | 37 | if (method.equals("password") == false) 38 | throw new IOException( 39 | "This is not a SSH_MSG_USERAUTH_REQUEST with type password!"); 40 | 41 | /* ... */ 42 | 43 | if (tr.remain() != 0) 44 | throw new IOException("Padding in SSH_MSG_USERAUTH_REQUEST packet!"); 45 | } 46 | 47 | public PacketUserauthRequestPassword(String serviceName, String user, 48 | String pass) { 49 | this.serviceName = serviceName; 50 | this.userName = user; 51 | this.password = pass; 52 | } 53 | 54 | public byte[] getPayload() { 55 | if (payload == null) { 56 | TypesWriter tw = new TypesWriter(); 57 | tw.writeByte(Packets.SSH_MSG_USERAUTH_REQUEST); 58 | tw.writeString(userName); 59 | tw.writeString(serviceName); 60 | tw.writeString("password"); 61 | tw.writeBoolean(false); 62 | tw.writeString(password); 63 | payload = tw.getBytes(); 64 | } 65 | return payload; 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/com/trilead/ssh2/channel/ChannelInputStream.java: -------------------------------------------------------------------------------- 1 | package com.trilead.ssh2.channel; 2 | 3 | import java.io.IOException; 4 | import java.io.InputStream; 5 | 6 | /** 7 | * ChannelInputStream. 8 | * 9 | * @author Christian Plattner, plattner@trilead.com 10 | * @version $Id: ChannelInputStream.java,v 1.1 2007/10/15 12:49:56 cplattne Exp 11 | * $ 12 | */ 13 | public final class ChannelInputStream extends InputStream { 14 | Channel c; 15 | 16 | boolean isClosed = false; 17 | boolean isEOF = false; 18 | boolean extendedFlag = false; 19 | 20 | ChannelInputStream(Channel c, boolean isExtended) { 21 | this.c = c; 22 | this.extendedFlag = isExtended; 23 | } 24 | 25 | @Override 26 | public int available() throws IOException { 27 | if (isEOF) 28 | return 0; 29 | 30 | int avail = c.cm.getAvailable(c, extendedFlag); 31 | 32 | /* We must not return -1 on EOF */ 33 | 34 | return (avail > 0) ? avail : 0; 35 | } 36 | 37 | @Override 38 | public void close() throws IOException { 39 | isClosed = true; 40 | } 41 | 42 | @Override 43 | public int read() throws IOException { 44 | /* Yes, this stream is pure and unbuffered, a single byte read() is slow */ 45 | 46 | final byte b[] = new byte[1]; 47 | 48 | int ret = read(b, 0, 1); 49 | 50 | if (ret != 1) 51 | return -1; 52 | 53 | return b[0] & 0xff; 54 | } 55 | 56 | @Override 57 | public int read(byte[] b) throws IOException { 58 | return read(b, 0, b.length); 59 | } 60 | 61 | @Override 62 | public int read(byte[] b, int off, int len) throws IOException { 63 | if (b == null) 64 | throw new NullPointerException(); 65 | 66 | if ((off < 0) || (len < 0) || ((off + len) > b.length) 67 | || ((off + len) < 0) || (off > b.length)) 68 | throw new IndexOutOfBoundsException(); 69 | 70 | if (len == 0) 71 | return 0; 72 | 73 | if (isEOF) 74 | return -1; 75 | 76 | int ret = c.cm.getChannelData(c, extendedFlag, b, off, len); 77 | 78 | if (ret == -1) { 79 | isEOF = true; 80 | } 81 | 82 | return ret; 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /src/com/trilead/ssh2/packets/PacketChannelOpenFailure.java: -------------------------------------------------------------------------------- 1 | package com.trilead.ssh2.packets; 2 | 3 | import java.io.IOException; 4 | 5 | /** 6 | * PacketChannelOpenFailure. 7 | * 8 | * @author Christian Plattner, plattner@trilead.com 9 | * @version $Id: PacketChannelOpenFailure.java,v 1.1 2007/10/15 12:49:55 10 | * cplattne Exp $ 11 | */ 12 | public class PacketChannelOpenFailure { 13 | byte[] payload; 14 | 15 | public int recipientChannelID; 16 | public int reasonCode; 17 | public String description; 18 | public String languageTag; 19 | 20 | public PacketChannelOpenFailure(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_FAILURE) 30 | throw new IOException( 31 | "This is not a SSH_MSG_CHANNEL_OPEN_FAILURE! (" 32 | + packet_type + ")"); 33 | 34 | recipientChannelID = tr.readUINT32(); 35 | reasonCode = tr.readUINT32(); 36 | description = tr.readString(); 37 | languageTag = tr.readString(); 38 | 39 | if (tr.remain() != 0) 40 | throw new IOException( 41 | "Padding in SSH_MSG_CHANNEL_OPEN_FAILURE packet!"); 42 | } 43 | 44 | public PacketChannelOpenFailure(int recipientChannelID, int reasonCode, 45 | String description, String languageTag) { 46 | this.recipientChannelID = recipientChannelID; 47 | this.reasonCode = reasonCode; 48 | this.description = description; 49 | this.languageTag = languageTag; 50 | } 51 | 52 | public byte[] getPayload() { 53 | if (payload == null) { 54 | TypesWriter tw = new TypesWriter(); 55 | tw.writeByte(Packets.SSH_MSG_CHANNEL_OPEN_FAILURE); 56 | tw.writeUINT32(recipientChannelID); 57 | tw.writeUINT32(reasonCode); 58 | tw.writeString(description); 59 | tw.writeString(languageTag); 60 | payload = tw.getBytes(); 61 | } 62 | return payload; 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/com/trilead/ssh2/crypto/digest/MAC.java: -------------------------------------------------------------------------------- 1 | package com.trilead.ssh2.crypto.digest; 2 | 3 | /** 4 | * MAC. 5 | * 6 | * @author Christian Plattner, plattner@trilead.com 7 | * @version $Id: MAC.java,v 1.1 2007/10/15 12:49:57 cplattne Exp $ 8 | */ 9 | public final class MAC { 10 | public final static void checkMacList(String[] macs) { 11 | for (int i = 0; i < macs.length; i++) 12 | getKeyLen(macs[i]); 13 | } 14 | public final static int getKeyLen(String type) { 15 | if (type.equals("hmac-sha1")) 16 | return 20; 17 | if (type.equals("hmac-sha1-96")) 18 | return 20; 19 | if (type.equals("hmac-md5")) 20 | return 16; 21 | if (type.equals("hmac-md5-96")) 22 | return 16; 23 | throw new IllegalArgumentException("Unkown algorithm " + type); 24 | } 25 | 26 | public final static String[] getMacList() { 27 | /* Higher Priority First */ 28 | 29 | return new String[] { "hmac-sha1-96", "hmac-sha1", "hmac-md5-96", 30 | "hmac-md5" }; 31 | } 32 | 33 | Digest mac; 34 | 35 | int size; 36 | 37 | public MAC(String type, byte[] key) { 38 | if (type.equals("hmac-sha1")) { 39 | mac = new HMAC(new SHA1(), key, 20); 40 | } else if (type.equals("hmac-sha1-96")) { 41 | mac = new HMAC(new SHA1(), key, 12); 42 | } else if (type.equals("hmac-md5")) { 43 | mac = new HMAC(new MD5(), key, 16); 44 | } else if (type.equals("hmac-md5-96")) { 45 | mac = new HMAC(new MD5(), key, 12); 46 | } else 47 | throw new IllegalArgumentException("Unkown algorithm " + type); 48 | 49 | size = mac.getDigestLength(); 50 | } 51 | 52 | public final void getMac(byte[] out, int off) { 53 | mac.digest(out, off); 54 | } 55 | 56 | public final void initMac(int seq) { 57 | mac.reset(); 58 | mac.update((byte) (seq >> 24)); 59 | mac.update((byte) (seq >> 16)); 60 | mac.update((byte) (seq >> 8)); 61 | mac.update((byte) (seq)); 62 | } 63 | 64 | public final int size() { 65 | return size; 66 | } 67 | 68 | public final void update(byte[] packetdata, int off, int len) { 69 | mac.update(packetdata, off, len); 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /src/com/jcraft/jzlib/ZStreamException.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 | public class ZStreamException extends java.io.IOException { 38 | public ZStreamException() { 39 | super(); 40 | } 41 | 42 | public ZStreamException(String s) { 43 | super(s); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/com/trilead/ssh2/DynamicPortForwarder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * ConnectBot: simple, powerful, open-source SSH client for Android 3 | * Copyright 2007 Kenny Root, Jeffrey Sharkey 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package com.trilead.ssh2; 19 | 20 | import java.io.IOException; 21 | import java.net.InetSocketAddress; 22 | 23 | import com.trilead.ssh2.channel.ChannelManager; 24 | import com.trilead.ssh2.channel.DynamicAcceptThread; 25 | 26 | /** 27 | * A DynamicPortForwarder forwards TCP/IP connections to a local 28 | * port via the secure tunnel to another host which is selected via the 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 | *

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 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 | *

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 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 Vector compressors = new Vector(); 38 | 39 | static { 40 | /* Higher Priority First */ 41 | 42 | compressors.addElement(new CompressorEntry("zlib", 43 | "com.trilead.ssh2.compression.Zlib")); 44 | compressors.addElement(new CompressorEntry("zlib@openssh.com", 45 | "com.trilead.ssh2.compression.ZlibOpenSSH")); 46 | compressors.addElement(new CompressorEntry("none", "")); 47 | } 48 | 49 | public static void checkCompressorList(String[] compressorCandidates) { 50 | for (int i = 0; i < compressorCandidates.length; i++) 51 | getEntry(compressorCandidates[i]); 52 | } 53 | 54 | public static ICompressor createCompressor(String type) { 55 | try { 56 | CompressorEntry ce = getEntry(type); 57 | if ("".equals(ce.compressorClass)) 58 | return null; 59 | 60 | Class cc = Class.forName(ce.compressorClass); 61 | ICompressor cmp = (ICompressor) cc.newInstance(); 62 | 63 | return cmp; 64 | } catch (Exception e) { 65 | throw new IllegalArgumentException("Cannot instantiate " + type); 66 | } 67 | } 68 | 69 | public static String[] getDefaultCompressorList() { 70 | String list[] = new String[compressors.size()]; 71 | for (int i = 0; i < compressors.size(); i++) { 72 | CompressorEntry ce = compressors.elementAt(i); 73 | list[i] = new String(ce.type); 74 | } 75 | return list; 76 | } 77 | 78 | private static CompressorEntry getEntry(String type) { 79 | for (int i = 0; i < compressors.size(); i++) { 80 | CompressorEntry ce = compressors.elementAt(i); 81 | if (ce.type.equals(type)) 82 | return ce; 83 | } 84 | throw new IllegalArgumentException("Unkown algorithm " + type); 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /src/com/trilead/ssh2/crypto/KeyMaterial.java: -------------------------------------------------------------------------------- 1 | package com.trilead.ssh2.crypto; 2 | 3 | import java.math.BigInteger; 4 | 5 | import com.trilead.ssh2.crypto.digest.HashForSSH2Types; 6 | 7 | /** 8 | * Establishes key material for iv/key/mac (both directions). 9 | * 10 | * @author Christian Plattner, plattner@trilead.com 11 | * @version $Id: KeyMaterial.java,v 1.1 2007/10/15 12:49:56 cplattne Exp $ 12 | */ 13 | public class KeyMaterial { 14 | private static byte[] calculateKey(HashForSSH2Types sh, BigInteger K, 15 | byte[] H, byte type, byte[] SessionID, int keyLength) { 16 | byte[] res = new byte[keyLength]; 17 | 18 | int dglen = sh.getDigestLength(); 19 | int numRounds = (keyLength + dglen - 1) / dglen; 20 | 21 | byte[][] tmp = new byte[numRounds][]; 22 | 23 | sh.reset(); 24 | sh.updateBigInt(K); 25 | sh.updateBytes(H); 26 | sh.updateByte(type); 27 | sh.updateBytes(SessionID); 28 | 29 | tmp[0] = sh.getDigest(); 30 | 31 | int off = 0; 32 | int produced = Math.min(dglen, keyLength); 33 | 34 | System.arraycopy(tmp[0], 0, res, off, produced); 35 | 36 | keyLength -= produced; 37 | off += produced; 38 | 39 | for (int i = 1; i < numRounds; i++) { 40 | sh.updateBigInt(K); 41 | sh.updateBytes(H); 42 | 43 | for (int j = 0; j < i; j++) 44 | sh.updateBytes(tmp[j]); 45 | 46 | tmp[i] = sh.getDigest(); 47 | 48 | produced = Math.min(dglen, keyLength); 49 | System.arraycopy(tmp[i], 0, res, off, produced); 50 | keyLength -= produced; 51 | off += produced; 52 | } 53 | 54 | return res; 55 | } 56 | public static KeyMaterial create(String hashType, byte[] H, BigInteger K, 57 | byte[] SessionID, int keyLengthCS, int blockSizeCS, 58 | int macLengthCS, int keyLengthSC, int blockSizeSC, int macLengthSC) 59 | throws IllegalArgumentException { 60 | KeyMaterial km = new KeyMaterial(); 61 | 62 | HashForSSH2Types sh = new HashForSSH2Types(hashType); 63 | 64 | km.initial_iv_client_to_server = calculateKey(sh, K, H, (byte) 'A', 65 | SessionID, blockSizeCS); 66 | 67 | km.initial_iv_server_to_client = calculateKey(sh, K, H, (byte) 'B', 68 | SessionID, blockSizeSC); 69 | 70 | km.enc_key_client_to_server = calculateKey(sh, K, H, (byte) 'C', 71 | SessionID, keyLengthCS); 72 | 73 | km.enc_key_server_to_client = calculateKey(sh, K, H, (byte) 'D', 74 | SessionID, keyLengthSC); 75 | 76 | km.integrity_key_client_to_server = calculateKey(sh, K, H, (byte) 'E', 77 | SessionID, macLengthCS); 78 | 79 | km.integrity_key_server_to_client = calculateKey(sh, K, H, (byte) 'F', 80 | SessionID, macLengthSC); 81 | 82 | return km; 83 | } 84 | public byte[] initial_iv_client_to_server; 85 | public byte[] initial_iv_server_to_client; 86 | public byte[] enc_key_client_to_server; 87 | public byte[] enc_key_server_to_client; 88 | 89 | public byte[] integrity_key_client_to_server; 90 | 91 | public byte[] integrity_key_server_to_client; 92 | } 93 | -------------------------------------------------------------------------------- /src/com/trilead/ssh2/crypto/dh/DhGroupExchange.java: -------------------------------------------------------------------------------- 1 | package com.trilead.ssh2.crypto.dh; 2 | 3 | import java.math.BigInteger; 4 | import java.security.SecureRandom; 5 | 6 | import com.trilead.ssh2.DHGexParameters; 7 | import com.trilead.ssh2.crypto.digest.HashForSSH2Types; 8 | 9 | /** 10 | * DhGroupExchange. 11 | * 12 | * @author Christian Plattner, plattner@trilead.com 13 | * @version $Id: DhGroupExchange.java,v 1.1 2007/10/15 12:49:57 cplattne Exp $ 14 | */ 15 | public class DhGroupExchange { 16 | /* Given by the standard */ 17 | 18 | private BigInteger p; 19 | private BigInteger g; 20 | 21 | /* Client public and private */ 22 | 23 | private BigInteger e; 24 | private BigInteger x; 25 | 26 | /* Server public */ 27 | 28 | private BigInteger f; 29 | 30 | /* Shared secret */ 31 | 32 | private BigInteger k; 33 | 34 | public DhGroupExchange(BigInteger p, BigInteger g) { 35 | this.p = p; 36 | this.g = g; 37 | } 38 | 39 | public byte[] calculateH(byte[] clientversion, byte[] serverversion, 40 | byte[] clientKexPayload, byte[] serverKexPayload, byte[] hostKey, 41 | DHGexParameters para) { 42 | HashForSSH2Types hash = new HashForSSH2Types("SHA1"); 43 | 44 | hash.updateByteString(clientversion); 45 | hash.updateByteString(serverversion); 46 | hash.updateByteString(clientKexPayload); 47 | hash.updateByteString(serverKexPayload); 48 | hash.updateByteString(hostKey); 49 | if (para.getMin_group_len() > 0) 50 | hash.updateUINT32(para.getMin_group_len()); 51 | hash.updateUINT32(para.getPref_group_len()); 52 | if (para.getMax_group_len() > 0) 53 | hash.updateUINT32(para.getMax_group_len()); 54 | hash.updateBigInt(p); 55 | hash.updateBigInt(g); 56 | hash.updateBigInt(e); 57 | hash.updateBigInt(f); 58 | hash.updateBigInt(k); 59 | 60 | return hash.getDigest(); 61 | } 62 | 63 | /** 64 | * @return Returns the e. 65 | */ 66 | public BigInteger getE() { 67 | if (e == null) 68 | throw new IllegalStateException("Not initialized!"); 69 | 70 | return e; 71 | } 72 | 73 | /** 74 | * @return Returns the shared secret k. 75 | */ 76 | public BigInteger getK() { 77 | if (k == null) 78 | throw new IllegalStateException( 79 | "Shared secret not yet known, need f first!"); 80 | 81 | return k; 82 | } 83 | 84 | public void init(SecureRandom rnd) { 85 | k = null; 86 | 87 | x = new BigInteger(p.bitLength() - 1, rnd); 88 | e = g.modPow(x, p); 89 | } 90 | 91 | /** 92 | * Sets f and calculates the shared secret. 93 | */ 94 | public void setF(BigInteger f) { 95 | if (e == null) 96 | throw new IllegalStateException("Not initialized!"); 97 | 98 | BigInteger zero = BigInteger.valueOf(0); 99 | 100 | if (zero.compareTo(f) >= 0 || p.compareTo(f) <= 0) 101 | throw new IllegalArgumentException("Invalid f specified!"); 102 | 103 | this.f = f; 104 | this.k = f.modPow(x, p); 105 | } 106 | } 107 | -------------------------------------------------------------------------------- /src/com/jcraft/jzlib/JZlib.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 public class JZlib { 38 | private static final String version = "1.0.2"; 39 | 40 | // compression levels 41 | static final public int Z_NO_COMPRESSION = 0; 42 | 43 | static final public int Z_BEST_SPEED = 1; 44 | static final public int Z_BEST_COMPRESSION = 9; 45 | static final public int Z_DEFAULT_COMPRESSION = (-1); 46 | // compression strategy 47 | static final public int Z_FILTERED = 1; 48 | 49 | static final public int Z_HUFFMAN_ONLY = 2; 50 | static final public int Z_DEFAULT_STRATEGY = 0; 51 | static final public int Z_NO_FLUSH = 0; 52 | 53 | static final public int Z_PARTIAL_FLUSH = 1; 54 | static final public int Z_SYNC_FLUSH = 2; 55 | static final public int Z_FULL_FLUSH = 3; 56 | static final public int Z_FINISH = 4; 57 | static final public int Z_OK = 0; 58 | 59 | static final public int Z_STREAM_END = 1; 60 | static final public int Z_NEED_DICT = 2; 61 | static final public int Z_ERRNO = -1; 62 | static final public int Z_STREAM_ERROR = -2; 63 | static final public int Z_DATA_ERROR = -3; 64 | static final public int Z_MEM_ERROR = -4; 65 | static final public int Z_BUF_ERROR = -5; 66 | static final public int Z_VERSION_ERROR = -6; 67 | public static String version() { 68 | return version; 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/respiteinjector/CesarCifer.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 CesarCifer { 13 | 14 | public static final String ALFABETO = "abcdefghijklmnopqrstuvwxyz"; 15 | public static final String ALFABETO_BASE64 = new String(); 16 | 17 | 18 | 19 | public CesarCifer() {} 20 | 21 | 22 | public static String criptografa(String mensagem, int deslocamento, String alfabeto) 23 | { 24 | char[] array = new char[mensagem.length()]; 25 | mensagem.getChars(0, mensagem.length(), array, 0); 26 | 27 | for (int cont = 0; cont < array.length; cont++) { char c; 28 | if ((c = getCharDeslocamento(deslocamento, array[cont], alfabeto)) != 0) 29 | array[cont] = c; 30 | } 31 | return String.valueOf(array); 32 | } 33 | 34 | 35 | 36 | 37 | 38 | public static String descriptografa(String mensagem, int deslocamento, String alfabeto) 39 | { 40 | return criptografa(mensagem, deslocamento * -1, alfabeto); 41 | } 42 | 43 | 44 | 45 | private static char getCharDeslocamento(int deslocamento, char caracter, String alfabeto) 46 | { 47 | int posicao; 48 | 49 | 50 | int tam = 65; 51 | 52 | 53 | if (alfabeto == ALFABETO_BASE64) { 54 | 55 | posicao = getPosicaoCharAlfabetoBase64(caracter); 56 | } else { 57 | tam = alfabeto.length(); 58 | if ((posicao = getPosicaoChar(caracter, alfabeto)) == -1) { 59 | return '\000'; 60 | } 61 | } 62 | if ((deslocamento > tam) || (deslocamento < tam * -1)) { 63 | deslocamento %= tam; 64 | } 65 | posicao += deslocamento; 66 | 67 | if (posicao > tam - 1) { 68 | posicao -= tam; 69 | } 70 | else if (posicao < 0) { 71 | posicao += tam; 72 | } 73 | return alfabeto == ALFABETO_BASE64 ? getCharAlfabetoBase64(posicao) : alfabeto.charAt(posicao); 74 | } 75 | 76 | 77 | 78 | 79 | private static int getPosicaoChar(char c, String str) 80 | { 81 | return str.indexOf(c); 82 | } 83 | 84 | private static int getPosicaoCharAlfabetoBase64(char c) 85 | { 86 | if (Character.isLetter(c)) 87 | return Character.isUpperCase(c) ? c - 'A' : c - 'a' + 26; 88 | if (Character.isDigit(c)) 89 | return c - '0' + 52; 90 | if (c == '/') 91 | return 62; 92 | if (c == '+') { 93 | return 63; 94 | } 95 | return 64; 96 | } 97 | 98 | 99 | private static char getCharAlfabetoBase64(int posicao) 100 | { 101 | if (posicao < 26) 102 | return (char)(65 + posicao); 103 | if (posicao < 52) 104 | return (char)(97 + posicao - 26); 105 | if (posicao < 62) 106 | return (char)(48 + posicao - 52); 107 | if (posicao == 62) 108 | return '/'; 109 | if (posicao == 63) { 110 | return '+'; 111 | } 112 | return '='; 113 | } 114 | } 115 | -------------------------------------------------------------------------------- /src/com/trilead/ssh2/transport/ClientServerHello.java: -------------------------------------------------------------------------------- 1 | package com.trilead.ssh2.transport; 2 | 3 | import java.io.IOException; 4 | import java.io.InputStream; 5 | import java.io.OutputStream; 6 | import java.io.UnsupportedEncodingException; 7 | 8 | import com.trilead.ssh2.Connection; 9 | 10 | /** 11 | * ClientServerHello. 12 | * 13 | * @author Christian Plattner, plattner@trilead.com 14 | * @version $Id: ClientServerHello.java,v 1.2 2008/04/01 12:38:09 cplattne Exp $ 15 | */ 16 | public class ClientServerHello { 17 | public final static int readLineRN(InputStream is, byte[] buffer) 18 | throws IOException { 19 | int pos = 0; 20 | boolean need10 = false; 21 | int len = 0; 22 | while (true) { 23 | int c = is.read(); 24 | if (c == -1) 25 | throw new IOException("Premature connection close"); 26 | 27 | buffer[pos++] = (byte) c; 28 | 29 | if (c == 13) { 30 | need10 = true; 31 | continue; 32 | } 33 | 34 | if (c == 10) 35 | break; 36 | 37 | if (need10 == true) 38 | throw new IOException( 39 | "Malformed line sent by the server, the line does not end correctly."); 40 | 41 | len++; 42 | if (pos >= buffer.length) 43 | throw new IOException("The server sent a too long line."); 44 | } 45 | 46 | return len; 47 | } 48 | String server_line; 49 | 50 | String client_line; 51 | 52 | String server_versioncomment; 53 | 54 | public ClientServerHello(InputStream bi, OutputStream bo) 55 | throws IOException { 56 | client_line = "SSH-2.0-" + Connection.identification; 57 | 58 | bo.write((client_line + "\r\n").getBytes("ISO-8859-1")); 59 | bo.flush(); 60 | 61 | byte[] serverVersion = new byte[512]; 62 | 63 | for (int i = 0; i < 50; i++) { 64 | int len = readLineRN(bi, serverVersion); 65 | 66 | server_line = new String(serverVersion, 0, len, "ISO-8859-1"); 67 | 68 | if (server_line.startsWith("SSH-")) 69 | break; 70 | } 71 | 72 | if (server_line.startsWith("SSH-") == false) 73 | throw new IOException( 74 | "Malformed server identification string. There was no line starting with 'SSH-' amongst the first 50 lines."); 75 | 76 | if (server_line.startsWith("SSH-1.99-")) 77 | server_versioncomment = server_line.substring(9); 78 | else if (server_line.startsWith("SSH-2.0-")) 79 | server_versioncomment = server_line.substring(8); 80 | else 81 | throw new IOException( 82 | "Server uses incompatible protocol, it is not SSH-2 compatible."); 83 | } 84 | 85 | /** 86 | * @return Returns the client_versioncomment. 87 | */ 88 | public byte[] getClientString() { 89 | byte[] result; 90 | 91 | try { 92 | result = client_line.getBytes("ISO-8859-1"); 93 | } catch (UnsupportedEncodingException ign) { 94 | result = client_line.getBytes(); 95 | } 96 | 97 | return result; 98 | } 99 | 100 | /** 101 | * @return Returns the server_versioncomment. 102 | */ 103 | public byte[] getServerString() { 104 | byte[] result; 105 | 106 | try { 107 | result = server_line.getBytes("ISO-8859-1"); 108 | } catch (UnsupportedEncodingException ign) { 109 | result = server_line.getBytes(); 110 | } 111 | 112 | return result; 113 | } 114 | } 115 | -------------------------------------------------------------------------------- /src/com/trilead/ssh2/crypto/cipher/DESede.java: -------------------------------------------------------------------------------- 1 | package com.trilead.ssh2.crypto.cipher; 2 | 3 | /* 4 | This file was shamelessly taken (and modified) from the Bouncy Castle Crypto package. 5 | Their licence file states the following: 6 | 7 | Copyright (c) 2000 - 2004 The Legion Of The Bouncy Castle 8 | (http://www.bouncycastle.org) 9 | 10 | Permission is hereby granted, free of charge, to any person obtaining a copy 11 | of this software and associated documentation files (the "Software"), to deal 12 | in the Software without restriction, including without limitation the rights 13 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 14 | copies of the Software, and to permit persons to whom the Software is 15 | furnished to do so, subject to the following conditions: 16 | 17 | The above copyright notice and this permission notice shall be included in 18 | all copies or substantial portions of the Software. 19 | 20 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 21 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 22 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 23 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 24 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 25 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 26 | THE SOFTWARE. 27 | */ 28 | 29 | /** 30 | * DESede. 31 | * 32 | * @author See comments in the source file 33 | * @version $Id: DESede.java,v 1.1 2007/10/15 12:49:55 cplattne Exp $ 34 | * 35 | */ 36 | public class DESede extends DES { 37 | private int[] key1 = null; 38 | private int[] key2 = null; 39 | private int[] key3 = null; 40 | 41 | private boolean encrypt; 42 | 43 | /** 44 | * standard constructor. 45 | */ 46 | public DESede() { 47 | } 48 | 49 | @Override 50 | public String getAlgorithmName() { 51 | return "DESede"; 52 | } 53 | 54 | @Override 55 | public int getBlockSize() { 56 | return 8; 57 | } 58 | 59 | /** 60 | * initialise a DES cipher. 61 | * 62 | * @param encrypting 63 | * whether or not we are for encryption. 64 | * @param key 65 | * the parameters required to set up the cipher. 66 | * @exception IllegalArgumentException 67 | * if the params argument is inappropriate. 68 | */ 69 | @Override 70 | public void init(boolean encrypting, byte[] key) { 71 | key1 = generateWorkingKey(encrypting, key, 0); 72 | key2 = generateWorkingKey(!encrypting, key, 8); 73 | key3 = generateWorkingKey(encrypting, key, 16); 74 | 75 | encrypt = encrypting; 76 | } 77 | 78 | @Override 79 | public void reset() { 80 | } 81 | 82 | @Override 83 | public void transformBlock(byte[] in, int inOff, byte[] out, int outOff) { 84 | if (key1 == null) { 85 | throw new IllegalStateException("DESede engine not initialised!"); 86 | } 87 | 88 | if (encrypt) { 89 | desFunc(key1, in, inOff, out, outOff); 90 | desFunc(key2, out, outOff, out, outOff); 91 | desFunc(key3, out, outOff, out, outOff); 92 | } else { 93 | desFunc(key3, in, inOff, out, outOff); 94 | desFunc(key2, out, outOff, out, outOff); 95 | desFunc(key1, out, outOff, out, outOff); 96 | } 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /src/com/trilead/ssh2/channel/LocalAcceptThread.java: -------------------------------------------------------------------------------- 1 | package com.trilead.ssh2.channel; 2 | 3 | import java.io.IOException; 4 | import java.net.InetSocketAddress; 5 | import java.net.ServerSocket; 6 | import java.net.Socket; 7 | 8 | /** 9 | * LocalAcceptThread. 10 | * 11 | * @author Christian Plattner, plattner@trilead.com 12 | * @version $Id: LocalAcceptThread.java,v 1.1 2007/10/15 12:49:56 cplattne Exp $ 13 | */ 14 | public class LocalAcceptThread extends Thread implements IChannelWorkerThread { 15 | ChannelManager cm; 16 | String host_to_connect; 17 | int port_to_connect; 18 | 19 | final ServerSocket ss; 20 | 21 | public LocalAcceptThread(ChannelManager cm, InetSocketAddress localAddress, 22 | String host_to_connect, int port_to_connect) throws IOException { 23 | this.cm = cm; 24 | this.host_to_connect = host_to_connect; 25 | this.port_to_connect = port_to_connect; 26 | 27 | ss = new ServerSocket(); 28 | ss.bind(localAddress); 29 | } 30 | 31 | public LocalAcceptThread(ChannelManager cm, int local_port, 32 | String host_to_connect, int port_to_connect) throws IOException { 33 | this.cm = cm; 34 | this.host_to_connect = host_to_connect; 35 | this.port_to_connect = port_to_connect; 36 | 37 | ss = new ServerSocket(local_port); 38 | } 39 | 40 | @Override 41 | public void run() { 42 | try { 43 | cm.registerThread(this); 44 | } catch (IOException e) { 45 | stopWorking(); 46 | return; 47 | } 48 | 49 | while (true) { 50 | Socket s = null; 51 | 52 | try { 53 | s = ss.accept(); 54 | } catch (IOException e) { 55 | stopWorking(); 56 | return; 57 | } 58 | 59 | Channel cn = null; 60 | StreamForwarder r2l = null; 61 | StreamForwarder l2r = null; 62 | 63 | try { 64 | /* 65 | * This may fail, e.g., if the remote port is closed (in 66 | * optimistic terms: not open yet) 67 | */ 68 | cn = cm.openDirectTCPIPChannel(host_to_connect, 69 | port_to_connect, s.getInetAddress().getHostAddress(), 70 | s.getPort()); 71 | } catch (IOException e) { 72 | /* 73 | * Simply close the local socket and wait for the next incoming 74 | * connection 75 | */ 76 | 77 | try { 78 | s.close(); 79 | } catch (IOException ignore) { 80 | } 81 | 82 | continue; 83 | } 84 | 85 | try { 86 | r2l = new StreamForwarder(cn, null, null, cn.stdoutStream, 87 | s.getOutputStream(), "RemoteToLocal"); 88 | l2r = new StreamForwarder(cn, r2l, s, s.getInputStream(), 89 | cn.stdinStream, "LocalToRemote"); 90 | } catch (IOException e) { 91 | try { 92 | /* 93 | * This message is only visible during debugging, since we 94 | * discard the channel immediatelly 95 | */ 96 | cn.cm.closeChannel(cn, 97 | "Weird error during creation of StreamForwarder (" 98 | + e.getMessage() + ")", true); 99 | } catch (IOException ignore) { 100 | } 101 | 102 | continue; 103 | } 104 | 105 | r2l.setDaemon(true); 106 | l2r.setDaemon(true); 107 | r2l.start(); 108 | l2r.start(); 109 | } 110 | } 111 | 112 | @Override 113 | public void stopWorking() { 114 | try { 115 | /* This will lead to an IOException in the ss.accept() call */ 116 | ss.close(); 117 | } catch (IOException e) { 118 | } 119 | } 120 | } 121 | -------------------------------------------------------------------------------- /src/com/trilead/ssh2/crypto/Base64.java: -------------------------------------------------------------------------------- 1 | package com.trilead.ssh2.crypto; 2 | 3 | import java.io.CharArrayWriter; 4 | import java.io.IOException; 5 | 6 | /** 7 | * Basic Base64 Support. 8 | * 9 | * @author Christian Plattner, plattner@trilead.com 10 | * @version $Id: Base64.java,v 1.1 2007/10/15 12:49:56 cplattne Exp $ 11 | */ 12 | public class Base64 { 13 | static final char[] alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/" 14 | .toCharArray(); 15 | 16 | public static byte[] decode(char[] message) throws IOException { 17 | byte buff[] = new byte[4]; 18 | byte dest[] = new byte[message.length]; 19 | 20 | int bpos = 0; 21 | int destpos = 0; 22 | 23 | for (int i = 0; i < message.length; i++) { 24 | int c = message[i]; 25 | 26 | if ((c == '\n') || (c == '\r') || (c == ' ') || (c == '\t')) 27 | continue; 28 | 29 | if ((c >= 'A') && (c <= 'Z')) { 30 | buff[bpos++] = (byte) (c - 'A'); 31 | } else if ((c >= 'a') && (c <= 'z')) { 32 | buff[bpos++] = (byte) ((c - 'a') + 26); 33 | } else if ((c >= '0') && (c <= '9')) { 34 | buff[bpos++] = (byte) ((c - '0') + 52); 35 | } else if (c == '+') { 36 | buff[bpos++] = 62; 37 | } else if (c == '/') { 38 | buff[bpos++] = 63; 39 | } else if (c == '=') { 40 | buff[bpos++] = 64; 41 | } else { 42 | throw new IOException("Illegal char in base64 code."); 43 | } 44 | 45 | if (bpos == 4) { 46 | bpos = 0; 47 | 48 | if (buff[0] == 64) 49 | break; 50 | 51 | if (buff[1] == 64) 52 | throw new IOException("Unexpected '=' in base64 code."); 53 | 54 | if (buff[2] == 64) { 55 | int v = (((buff[0] & 0x3f) << 6) | ((buff[1] & 0x3f))); 56 | dest[destpos++] = (byte) (v >> 4); 57 | break; 58 | } else if (buff[3] == 64) { 59 | int v = (((buff[0] & 0x3f) << 12) | ((buff[1] & 0x3f) << 6) | ((buff[2] & 0x3f))); 60 | dest[destpos++] = (byte) (v >> 10); 61 | dest[destpos++] = (byte) (v >> 2); 62 | break; 63 | } else { 64 | int v = (((buff[0] & 0x3f) << 18) 65 | | ((buff[1] & 0x3f) << 12) 66 | | ((buff[2] & 0x3f) << 6) | ((buff[3] & 0x3f))); 67 | dest[destpos++] = (byte) (v >> 16); 68 | dest[destpos++] = (byte) (v >> 8); 69 | dest[destpos++] = (byte) (v); 70 | } 71 | } 72 | } 73 | 74 | byte[] res = new byte[destpos]; 75 | System.arraycopy(dest, 0, res, 0, destpos); 76 | 77 | return res; 78 | } 79 | 80 | public static char[] encode(byte[] content) { 81 | CharArrayWriter cw = new CharArrayWriter((4 * content.length) / 3); 82 | 83 | int idx = 0; 84 | 85 | int x = 0; 86 | 87 | for (int i = 0; i < content.length; i++) { 88 | if (idx == 0) 89 | x = (content[i] & 0xff) << 16; 90 | else if (idx == 1) 91 | x = x | ((content[i] & 0xff) << 8); 92 | else 93 | x = x | (content[i] & 0xff); 94 | 95 | idx++; 96 | 97 | if (idx == 3) { 98 | cw.write(alphabet[x >> 18]); 99 | cw.write(alphabet[(x >> 12) & 0x3f]); 100 | cw.write(alphabet[(x >> 6) & 0x3f]); 101 | cw.write(alphabet[x & 0x3f]); 102 | 103 | idx = 0; 104 | } 105 | } 106 | 107 | if (idx == 1) { 108 | cw.write(alphabet[x >> 18]); 109 | cw.write(alphabet[(x >> 12) & 0x3f]); 110 | cw.write('='); 111 | cw.write('='); 112 | } 113 | 114 | if (idx == 2) { 115 | cw.write(alphabet[x >> 18]); 116 | cw.write(alphabet[(x >> 12) & 0x3f]); 117 | cw.write(alphabet[(x >> 6) & 0x3f]); 118 | cw.write('='); 119 | } 120 | 121 | return cw.toCharArray(); 122 | } 123 | } 124 | -------------------------------------------------------------------------------- /src/com/trilead/ssh2/crypto/cipher/CipherInputStream.java: -------------------------------------------------------------------------------- 1 | package com.trilead.ssh2.crypto.cipher; 2 | 3 | import java.io.IOException; 4 | import java.io.InputStream; 5 | 6 | /** 7 | * CipherInputStream. 8 | * 9 | * @author Christian Plattner, plattner@trilead.com 10 | * @version $Id: CipherInputStream.java,v 1.1 2007/10/15 12:49:55 cplattne Exp $ 11 | */ 12 | public class CipherInputStream { 13 | BlockCipher currentCipher; 14 | InputStream bi; 15 | byte[] buffer; 16 | byte[] enc; 17 | int blockSize; 18 | int pos; 19 | 20 | /* 21 | * We cannot use java.io.BufferedInputStream, since that is not available in 22 | * J2ME. Everything could be improved alot here. 23 | */ 24 | 25 | final int BUFF_SIZE = 2048; 26 | byte[] input_buffer = new byte[BUFF_SIZE]; 27 | int input_buffer_pos = 0; 28 | int input_buffer_size = 0; 29 | 30 | public CipherInputStream(BlockCipher tc, InputStream bi) { 31 | this.bi = bi; 32 | changeCipher(tc); 33 | } 34 | 35 | public void changeCipher(BlockCipher bc) { 36 | this.currentCipher = bc; 37 | blockSize = bc.getBlockSize(); 38 | buffer = new byte[blockSize]; 39 | enc = new byte[blockSize]; 40 | pos = blockSize; 41 | } 42 | 43 | private int fill_buffer() throws IOException { 44 | input_buffer_pos = 0; 45 | input_buffer_size = bi.read(input_buffer, 0, BUFF_SIZE); 46 | return input_buffer_size; 47 | } 48 | 49 | private void getBlock() throws IOException { 50 | int n = 0; 51 | while (n < blockSize) { 52 | int len = internal_read(enc, n, blockSize - n); 53 | if (len < 0) 54 | throw new IOException("Cannot read full block, EOF reached."); 55 | n += len; 56 | } 57 | 58 | try { 59 | currentCipher.transformBlock(enc, 0, buffer, 0); 60 | } catch (Exception e) { 61 | throw new IOException("Error while decrypting block."); 62 | } 63 | pos = 0; 64 | } 65 | 66 | private int internal_read(byte[] b, int off, int len) throws IOException { 67 | if (input_buffer_size < 0) 68 | return -1; 69 | 70 | if (input_buffer_pos >= input_buffer_size) { 71 | if (fill_buffer() <= 0) 72 | return -1; 73 | } 74 | 75 | int avail = input_buffer_size - input_buffer_pos; 76 | int thiscopy = (len > avail) ? avail : len; 77 | 78 | System.arraycopy(input_buffer, input_buffer_pos, b, off, thiscopy); 79 | input_buffer_pos += thiscopy; 80 | 81 | return thiscopy; 82 | } 83 | 84 | public int read() throws IOException { 85 | if (pos >= blockSize) { 86 | getBlock(); 87 | } 88 | return buffer[pos++] & 0xff; 89 | } 90 | 91 | public int read(byte[] dst) throws IOException { 92 | return read(dst, 0, dst.length); 93 | } 94 | 95 | public int read(byte[] dst, int off, int len) throws IOException { 96 | int count = 0; 97 | 98 | while (len > 0) { 99 | if (pos >= blockSize) 100 | getBlock(); 101 | 102 | int avail = blockSize - pos; 103 | int copy = Math.min(avail, len); 104 | System.arraycopy(buffer, pos, dst, off, copy); 105 | pos += copy; 106 | off += copy; 107 | len -= copy; 108 | count += copy; 109 | } 110 | return count; 111 | } 112 | 113 | public int readPlain(byte[] b, int off, int len) throws IOException { 114 | if (pos != blockSize) 115 | throw new IOException( 116 | "Cannot read plain since crypto buffer is not aligned."); 117 | int n = 0; 118 | while (n < len) { 119 | int cnt = internal_read(b, off + n, len - n); 120 | if (cnt < 0) 121 | throw new IOException("Cannot fill buffer, EOF reached."); 122 | n += cnt; 123 | } 124 | return n; 125 | } 126 | } 127 | -------------------------------------------------------------------------------- /src/com/trilead/ssh2/crypto/SimpleDERReader.java: -------------------------------------------------------------------------------- 1 | package com.trilead.ssh2.crypto; 2 | 3 | import java.io.IOException; 4 | import java.math.BigInteger; 5 | 6 | /** 7 | * SimpleDERReader. 8 | * 9 | * @author Christian Plattner, plattner@trilead.com 10 | * @version $Id: SimpleDERReader.java,v 1.1 2007/10/15 12:49:56 cplattne Exp $ 11 | */ 12 | public class SimpleDERReader { 13 | byte[] buffer; 14 | int pos; 15 | int count; 16 | 17 | public SimpleDERReader(byte[] b) { 18 | resetInput(b); 19 | } 20 | 21 | public SimpleDERReader(byte[] b, int off, int len) { 22 | resetInput(b, off, len); 23 | } 24 | 25 | public int available() { 26 | return count; 27 | } 28 | 29 | public int ignoreNextObject() throws IOException { 30 | int type = readByte() & 0xff; 31 | 32 | int len = readLength(); 33 | 34 | if ((len < 0) || len > available()) 35 | throw new IOException("Illegal len in DER object (" + len + ")"); 36 | 37 | readBytes(len); 38 | 39 | return type; 40 | } 41 | 42 | private byte readByte() throws IOException { 43 | if (count <= 0) 44 | throw new IOException("DER byte array: out of data"); 45 | count--; 46 | return buffer[pos++]; 47 | } 48 | 49 | private byte[] readBytes(int len) throws IOException { 50 | if (len > count) 51 | throw new IOException("DER byte array: out of data"); 52 | 53 | byte[] b = new byte[len]; 54 | 55 | System.arraycopy(buffer, pos, b, 0, len); 56 | 57 | pos += len; 58 | count -= len; 59 | 60 | return b; 61 | } 62 | 63 | public BigInteger readInt() throws IOException { 64 | int type = readByte() & 0xff; 65 | 66 | if (type != 0x02) 67 | throw new IOException("Expected DER Integer, but found type " 68 | + type); 69 | 70 | int len = readLength(); 71 | 72 | if ((len < 0) || len > available()) 73 | throw new IOException("Illegal len in DER object (" + len + ")"); 74 | 75 | byte[] b = readBytes(len); 76 | 77 | BigInteger bi = new BigInteger(b); 78 | 79 | return bi; 80 | } 81 | 82 | private int readLength() throws IOException { 83 | int len = readByte() & 0xff; 84 | 85 | if ((len & 0x80) == 0) 86 | return len; 87 | 88 | int remain = len & 0x7F; 89 | 90 | if (remain == 0) 91 | return -1; 92 | 93 | len = 0; 94 | 95 | while (remain > 0) { 96 | len = len << 8; 97 | len = len | (readByte() & 0xff); 98 | remain--; 99 | } 100 | 101 | return len; 102 | } 103 | 104 | public byte[] readOctetString() throws IOException { 105 | int type = readByte() & 0xff; 106 | 107 | if (type != 0x04) 108 | throw new IOException("Expected DER Octetstring, but found type " 109 | + type); 110 | 111 | int len = readLength(); 112 | 113 | if ((len < 0) || len > available()) 114 | throw new IOException("Illegal len in DER object (" + len + ")"); 115 | 116 | byte[] b = readBytes(len); 117 | 118 | return b; 119 | } 120 | 121 | public byte[] readSequenceAsByteArray() throws IOException { 122 | int type = readByte() & 0xff; 123 | 124 | if (type != 0x30) 125 | throw new IOException("Expected DER Sequence, but found type " 126 | + type); 127 | 128 | int len = readLength(); 129 | 130 | if ((len < 0) || len > available()) 131 | throw new IOException("Illegal len in DER object (" + len + ")"); 132 | 133 | byte[] b = readBytes(len); 134 | 135 | return b; 136 | } 137 | 138 | public void resetInput(byte[] b) { 139 | resetInput(b, 0, b.length); 140 | } 141 | 142 | public void resetInput(byte[] b, int off, int len) { 143 | buffer = b; 144 | pos = off; 145 | count = len; 146 | } 147 | 148 | } 149 | -------------------------------------------------------------------------------- /src/com/trilead/ssh2/crypto/cipher/CipherOutputStream.java: -------------------------------------------------------------------------------- 1 | package com.trilead.ssh2.crypto.cipher; 2 | 3 | import java.io.IOException; 4 | import java.io.OutputStream; 5 | 6 | /** 7 | * CipherOutputStream. 8 | * 9 | * @author Christian Plattner, plattner@trilead.com 10 | * @version $Id: CipherOutputStream.java,v 1.1 2007/10/15 12:49:55 cplattne Exp 11 | * $ 12 | */ 13 | public class CipherOutputStream { 14 | BlockCipher currentCipher; 15 | OutputStream bo; 16 | byte[] buffer; 17 | byte[] enc; 18 | int blockSize; 19 | int pos; 20 | 21 | /* 22 | * We cannot use java.io.BufferedOutputStream, since that is not available 23 | * in J2ME. Everything could be improved here alot. 24 | */ 25 | 26 | final int BUFF_SIZE = 2048; 27 | byte[] out_buffer = new byte[BUFF_SIZE]; 28 | int out_buffer_pos = 0; 29 | 30 | public CipherOutputStream(BlockCipher tc, OutputStream bo) { 31 | this.bo = bo; 32 | changeCipher(tc); 33 | } 34 | 35 | public void changeCipher(BlockCipher bc) { 36 | this.currentCipher = bc; 37 | blockSize = bc.getBlockSize(); 38 | buffer = new byte[blockSize]; 39 | enc = new byte[blockSize]; 40 | pos = 0; 41 | } 42 | 43 | public void flush() throws IOException { 44 | if (pos != 0) 45 | throw new IOException( 46 | "FATAL: cannot flush since crypto buffer is not aligned."); 47 | 48 | if (out_buffer_pos > 0) { 49 | bo.write(out_buffer, 0, out_buffer_pos); 50 | out_buffer_pos = 0; 51 | } 52 | bo.flush(); 53 | } 54 | 55 | private void internal_write(byte[] src, int off, int len) 56 | throws IOException { 57 | while (len > 0) { 58 | int space = BUFF_SIZE - out_buffer_pos; 59 | int copy = (len > space) ? space : len; 60 | 61 | System.arraycopy(src, off, out_buffer, out_buffer_pos, copy); 62 | 63 | off += copy; 64 | out_buffer_pos += copy; 65 | len -= copy; 66 | 67 | if (out_buffer_pos >= BUFF_SIZE) { 68 | bo.write(out_buffer, 0, BUFF_SIZE); 69 | out_buffer_pos = 0; 70 | } 71 | } 72 | } 73 | 74 | private void internal_write(int b) throws IOException { 75 | out_buffer[out_buffer_pos++] = (byte) b; 76 | if (out_buffer_pos >= BUFF_SIZE) { 77 | bo.write(out_buffer, 0, BUFF_SIZE); 78 | out_buffer_pos = 0; 79 | } 80 | } 81 | 82 | public void write(byte[] src, int off, int len) throws IOException { 83 | while (len > 0) { 84 | int avail = blockSize - pos; 85 | int copy = Math.min(avail, len); 86 | 87 | System.arraycopy(src, off, buffer, pos, copy); 88 | pos += copy; 89 | off += copy; 90 | len -= copy; 91 | 92 | if (pos >= blockSize) 93 | writeBlock(); 94 | } 95 | } 96 | 97 | public void write(int b) throws IOException { 98 | buffer[pos++] = (byte) b; 99 | if (pos >= blockSize) 100 | writeBlock(); 101 | } 102 | 103 | private void writeBlock() throws IOException { 104 | try { 105 | currentCipher.transformBlock(buffer, 0, enc, 0); 106 | } catch (Exception e) { 107 | throw (IOException) new IOException("Error while decrypting block.") 108 | .initCause(e); 109 | } 110 | 111 | internal_write(enc, 0, blockSize); 112 | pos = 0; 113 | } 114 | 115 | public void writePlain(byte[] b, int off, int len) throws IOException { 116 | if (pos != 0) 117 | throw new IOException( 118 | "Cannot write plain since crypto buffer is not aligned."); 119 | internal_write(b, off, len); 120 | } 121 | 122 | public void writePlain(int b) throws IOException { 123 | if (pos != 0) 124 | throw new IOException( 125 | "Cannot write plain since crypto buffer is not aligned."); 126 | internal_write(b); 127 | } 128 | } 129 | -------------------------------------------------------------------------------- /src/net/sourceforge/jsocks/ProxyMessage.java: -------------------------------------------------------------------------------- 1 | package net.sourceforge.jsocks; 2 | 3 | import java.io.IOException; 4 | import java.io.InputStream; 5 | import java.io.OutputStream; 6 | import java.net.InetAddress; 7 | import java.net.UnknownHostException; 8 | 9 | /** 10 | * Abstract class which describes SOCKS4/5 response/request. 11 | */ 12 | public abstract class ProxyMessage { 13 | static final String bytes2IPV4(byte[] addr, int offset) { 14 | String hostName = "" + (addr[offset] & 0xFF); 15 | for (int i = offset + 1; i < offset + 4; ++i) 16 | hostName += "." + (addr[i] & 0xFF); 17 | return hostName; 18 | } 19 | static final String bytes2IPV6(byte[] addr, int offset) { 20 | // Have no idea how they look like! 21 | return null; 22 | } 23 | /** Host as an IP address */ 24 | public InetAddress ip = null; 25 | /** SOCKS version, or version of the response for SOCKS4 */ 26 | public int version; 27 | /** Port field of the request/response */ 28 | public int port; 29 | /** Request/response code as an int */ 30 | public int command; 31 | 32 | /** Host as string. */ 33 | public String host = null; 34 | 35 | /** User field for SOCKS4 request messages */ 36 | public String user = null; 37 | 38 | ProxyMessage() { 39 | } 40 | 41 | ProxyMessage(int command, InetAddress ip, int port) { 42 | this.command = command; 43 | this.ip = ip; 44 | this.port = port; 45 | } 46 | 47 | /** 48 | * Get the Address field of this message as InetAddress object. 49 | * 50 | * @return Host address or null, if one can't be determined. 51 | */ 52 | public InetAddress getInetAddress() throws UnknownHostException { 53 | return ip; 54 | } 55 | 56 | /** 57 | * Initialises Message from the stream. Reads server response from given 58 | * stream. 59 | * 60 | * @param in 61 | * Input stream to read response from. 62 | * @throws SocksException 63 | * If server response code is not SOCKS_SUCCESS(0), or if any 64 | * error with protocol occurs. 65 | * @throws IOException 66 | * If any error happens with I/O. 67 | */ 68 | public abstract void read(InputStream in) throws SocksException, 69 | IOException; 70 | 71 | /** 72 | * Initialises Message from the stream. Reads server response or client 73 | * request from given stream. 74 | * 75 | * @param in 76 | * Input stream to read response from. 77 | * @param clinetMode 78 | * If true read server response, else read client request. 79 | * @throws SocksException 80 | * If server response code is not SOCKS_SUCCESS(0) and reading 81 | * in client mode, or if any error with protocol occurs. 82 | * @throws IOException 83 | * If any error happens with I/O. 84 | */ 85 | public abstract void read(InputStream in, boolean client_mode) 86 | throws SocksException, IOException; 87 | 88 | // Package methods 89 | // //////////////// 90 | 91 | /** 92 | * Get string representaion of this message. 93 | * 94 | * @return string representation of this message. 95 | */ 96 | @Override 97 | public String toString() { 98 | return "Proxy Message:\n" + "Version:" + version + "\n" + "Command:" 99 | + command + "\n" + "IP: " + ip + "\n" + "Port: " + port 100 | + "\n" + "User: " + user + "\n"; 101 | } 102 | 103 | /** 104 | * Writes the message to the stream. 105 | * 106 | * @param out 107 | * Output stream to which message should be written. 108 | */ 109 | public abstract void write(OutputStream out) throws SocksException, 110 | IOException; 111 | 112 | } 113 | -------------------------------------------------------------------------------- /nbproject/project.properties: -------------------------------------------------------------------------------- 1 | annotation.processing.enabled=true 2 | annotation.processing.enabled.in.editor=false 3 | annotation.processing.processor.options= 4 | annotation.processing.processors.list= 5 | annotation.processing.run.all.processors=true 6 | annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output 7 | build.classes.dir=${build.dir}/classes 8 | build.classes.excludes=**/*.java,**/*.form 9 | # This directory is removed when the project is cleaned: 10 | build.dir=build 11 | build.generated.dir=${build.dir}/generated 12 | build.generated.sources.dir=${build.dir}/generated-sources 13 | # Only compile against the classpath explicitly listed here: 14 | build.sysclasspath=ignore 15 | build.test.classes.dir=${build.dir}/test/classes 16 | build.test.results.dir=${build.dir}/test/results 17 | # Uncomment to specify the preferred debugger connection transport: 18 | #debug.transport=dt_socket 19 | debug.classpath=\ 20 | ${run.classpath} 21 | debug.test.classpath=\ 22 | ${run.test.classpath} 23 | # Files in build.classes.dir which should be excluded from distribution jar 24 | dist.archive.excludes= 25 | # This directory is removed when the project is cleaned: 26 | dist.dir=dist 27 | dist.jar=${dist.dir}/Respite_HTTP_Injector.jar 28 | dist.javadoc.dir=${dist.dir}/javadoc 29 | excludes= 30 | file.reference.com.fasterxml.jackson.databind-2.10.3.LIFERAY-PATCHED-1.jar=C:\\Users\\user\\Desktop\\com.fasterxml.jackson.databind-2.10.3.LIFERAY-PATCHED-1.jar 31 | file.reference.darcula-1.0.0.jar=C:\\Users\\user\\Desktop\\darcula-1.0.0.jar 32 | file.reference.eddsa-0.3.0.jar=C:\\Users\\user\\Desktop\\eddsa-0.3.0.jar 33 | file.reference.jackson-annotations-2.11.1.jar=C:\\Users\\user\\Desktop\\jackson-annotations-2.11.1.jar 34 | file.reference.jackson-core-2.11.1.jar=C:\\Users\\user\\Desktop\\jackson-core-2.11.1.jar 35 | file.reference.jbcrypt-0.4.jar=C:\\Users\\user\\Desktop\\jbcrypt-0.4.jar 36 | includes=** 37 | jar.compress=false 38 | javac.classpath=\ 39 | ${libs.absolutelayout.classpath}:\ 40 | ${file.reference.com.fasterxml.jackson.databind-2.10.3.LIFERAY-PATCHED-1.jar}:\ 41 | ${file.reference.jackson-core-2.11.1.jar}:\ 42 | ${file.reference.jackson-annotations-2.11.1.jar}:\ 43 | ${file.reference.darcula-1.0.0.jar}:\ 44 | ${file.reference.eddsa-0.3.0.jar}:\ 45 | ${file.reference.jbcrypt-0.4.jar} 46 | # Space-separated list of extra javac options 47 | javac.compilerargs= 48 | javac.deprecation=false 49 | javac.external.vm=true 50 | javac.processorpath=\ 51 | ${javac.classpath} 52 | javac.source=1.8 53 | javac.target=1.8 54 | javac.test.classpath=\ 55 | ${javac.classpath}:\ 56 | ${build.classes.dir} 57 | javac.test.processorpath=\ 58 | ${javac.test.classpath} 59 | javadoc.additionalparam= 60 | javadoc.author=false 61 | javadoc.encoding=${source.encoding} 62 | javadoc.noindex=false 63 | javadoc.nonavbar=false 64 | javadoc.notree=false 65 | javadoc.private=false 66 | javadoc.splitindex=true 67 | javadoc.use=true 68 | javadoc.version=false 69 | javadoc.windowtitle= 70 | main.class=respite.http.injector.MainForm 71 | manifest.file=manifest.mf 72 | meta.inf.dir=${src.dir}/META-INF 73 | mkdist.disabled=false 74 | platform.active=default_platform 75 | run.classpath=\ 76 | ${javac.classpath}:\ 77 | ${build.classes.dir} 78 | # Space-separated list of JVM arguments used when running the project. 79 | # You may also define separate properties like run-sys-prop.name=value instead of -Dname=value. 80 | # To set system properties for unit tests define test-sys-prop.name=value: 81 | run.jvmargs= 82 | run.test.classpath=\ 83 | ${javac.test.classpath}:\ 84 | ${build.test.classes.dir} 85 | source.encoding=UTF-8 86 | src.dir=src 87 | test.src.dir=test 88 | -------------------------------------------------------------------------------- /src/com/trilead/ssh2/sftp/AttribFlags.java: -------------------------------------------------------------------------------- 1 | package com.trilead.ssh2.sftp; 2 | 3 | /** 4 | * 5 | * Attribute Flags. The 'valid-attribute-flags' field in the SFTP ATTRS data 6 | * type specifies which of the fields are actually present. 7 | * 8 | * @author Christian Plattner, plattner@trilead.com 9 | * @version $Id: AttribFlags.java,v 1.1 2007/10/15 12:49:55 cplattne Exp $ 10 | * 11 | */ 12 | public class AttribFlags { 13 | /** 14 | * Indicates that the 'allocation-size' field is present. 15 | */ 16 | public static final int SSH_FILEXFER_ATTR_SIZE = 0x00000001; 17 | 18 | /** 19 | * Protocol version 6: 0x00000002 was used in a previous version of this 20 | * protocol. It is now a reserved value and MUST NOT appear in the mask. 21 | * Some future version of this protocol may reuse this value. 22 | */ 23 | public static final int SSH_FILEXFER_ATTR_V3_UIDGID = 0x00000002; 24 | 25 | /** 26 | * Indicates that the 'permissions' field is present. 27 | */ 28 | public static final int SSH_FILEXFER_ATTR_PERMISSIONS = 0x00000004; 29 | 30 | /** 31 | * Indicates that the 'atime' and 'mtime' field are present (protocol v3). 32 | */ 33 | public static final int SSH_FILEXFER_ATTR_V3_ACMODTIME = 0x00000008; 34 | 35 | /** 36 | * Indicates that the 'atime' field is present. 37 | */ 38 | public static final int SSH_FILEXFER_ATTR_ACCESSTIME = 0x00000008; 39 | 40 | /** 41 | * Indicates that the 'createtime' field is present. 42 | */ 43 | public static final int SSH_FILEXFER_ATTR_CREATETIME = 0x00000010; 44 | 45 | /** 46 | * Indicates that the 'mtime' field is present. 47 | */ 48 | public static final int SSH_FILEXFER_ATTR_MODIFYTIME = 0x00000020; 49 | 50 | /** 51 | * Indicates that the 'acl' field is present. 52 | */ 53 | public static final int SSH_FILEXFER_ATTR_ACL = 0x00000040; 54 | 55 | /** 56 | * Indicates that the 'owner' and 'group' fields are present. 57 | */ 58 | public static final int SSH_FILEXFER_ATTR_OWNERGROUP = 0x00000080; 59 | 60 | /** 61 | * Indicates that additionally to the 'atime', 'createtime', 'mtime' and 62 | * 'ctime' fields (if present), there is also 'atime-nseconds', 63 | * 'createtime-nseconds', 'mtime-nseconds' and 'ctime-nseconds'. 64 | */ 65 | public static final int SSH_FILEXFER_ATTR_SUBSECOND_TIMES = 0x00000100; 66 | 67 | /** 68 | * Indicates that the 'attrib-bits' and 'attrib-bits-valid' fields are 69 | * present. 70 | */ 71 | public static final int SSH_FILEXFER_ATTR_BITS = 0x00000200; 72 | 73 | /** 74 | * Indicates that the 'allocation-size' field is present. 75 | */ 76 | public static final int SSH_FILEXFER_ATTR_ALLOCATION_SIZE = 0x00000400; 77 | 78 | /** 79 | * Indicates that the 'text-hint' field is present. 80 | */ 81 | public static final int SSH_FILEXFER_ATTR_TEXT_HINT = 0x00000800; 82 | 83 | /** 84 | * Indicates that the 'mime-type' field is present. 85 | */ 86 | public static final int SSH_FILEXFER_ATTR_MIME_TYPE = 0x00001000; 87 | 88 | /** 89 | * Indicates that the 'link-count' field is present. 90 | */ 91 | public static final int SSH_FILEXFER_ATTR_LINK_COUNT = 0x00002000; 92 | 93 | /** 94 | * Indicates that the 'untranslated-name' field is present. 95 | */ 96 | public static final int SSH_FILEXFER_ATTR_UNTRANSLATED_NAME = 0x00004000; 97 | 98 | /** 99 | * Indicates that the 'ctime' field is present. 100 | */ 101 | public static final int SSH_FILEXFER_ATTR_CTIME = 0x00008000; 102 | 103 | /** 104 | * Indicates that the 'extended-count' field (and probablby some 105 | * 'extensions') is present. 106 | */ 107 | public static final int SSH_FILEXFER_ATTR_EXTENDED = 0x80000000; 108 | } 109 | -------------------------------------------------------------------------------- /src/net/sourceforge/jsocks/Socks4Proxy.java: -------------------------------------------------------------------------------- 1 | package net.sourceforge.jsocks; 2 | 3 | import java.io.IOException; 4 | import java.io.InputStream; 5 | import java.net.InetAddress; 6 | import java.net.UnknownHostException; 7 | 8 | /** 9 | * Proxy which describes SOCKS4 proxy. 10 | */ 11 | 12 | public class Socks4Proxy extends Proxy implements Cloneable { 13 | 14 | // Data members 15 | String user; 16 | 17 | // Public Constructors 18 | // ==================== 19 | 20 | /** 21 | * Creates the SOCKS4 proxy 22 | * 23 | * @param proxyIP 24 | * Address of the proxy server. 25 | * @param proxyPort 26 | * Port of the proxy server 27 | * @param user 28 | * User name to use for identification purposes. 29 | */ 30 | public Socks4Proxy(InetAddress proxyIP, int proxyPort, String user) { 31 | this(null, proxyIP, proxyPort, user); 32 | } 33 | 34 | /** 35 | * Creates the SOCKS4 proxy 36 | * 37 | * @param p 38 | * Proxy to use to connect to this proxy, allows proxy chaining. 39 | * @param proxyIP 40 | * Address of the proxy server. 41 | * @param proxyPort 42 | * Port of the proxy server 43 | * @param user 44 | * User name to use for identification purposes. 45 | */ 46 | public Socks4Proxy(Proxy p, InetAddress proxyIP, int proxyPort, String user) { 47 | super(p, proxyIP, proxyPort); 48 | this.user = new String(user); 49 | version = 4; 50 | } 51 | 52 | /** 53 | * Creates the SOCKS4 proxy 54 | * 55 | * @param p 56 | * Proxy to use to connect to this proxy, allows proxy chaining. 57 | * @param proxyHost 58 | * Address of the proxy server. 59 | * @param proxyPort 60 | * Port of the proxy server 61 | * @param user 62 | * User name to use for identification purposes. 63 | * @throws UnknownHostException 64 | * If proxyHost can't be resolved. 65 | */ 66 | public Socks4Proxy(String proxyHost, int proxyPort, String user) 67 | throws UnknownHostException { 68 | super(proxyHost, proxyPort); 69 | this.user = new String(user); 70 | version = 4; 71 | } 72 | 73 | // Public instance methods 74 | // ======================== 75 | 76 | /** 77 | * Creates a clone of this proxy. Changes made to the clone should not 78 | * affect this object. 79 | */ 80 | @Override 81 | public Object clone() { 82 | Socks4Proxy newProxy = new Socks4Proxy(proxyIP, proxyPort, user); 83 | newProxy.chainProxy = chainProxy; 84 | return newProxy; 85 | } 86 | 87 | // Public Static(Class) Methods 88 | // ============================== 89 | 90 | // Protected Methods 91 | // ================= 92 | 93 | @Override 94 | protected Proxy copy() { 95 | Socks4Proxy copy = new Socks4Proxy(proxyIP, proxyPort, user); 96 | copy.chainProxy = chainProxy; 97 | return copy; 98 | } 99 | 100 | @Override 101 | protected ProxyMessage formMessage(InputStream in) throws SocksException, 102 | IOException { 103 | return new Socks4Message(in, true); 104 | } 105 | 106 | @Override 107 | protected ProxyMessage formMessage(int cmd, InetAddress ip, int port) { 108 | switch (cmd) { 109 | case SOCKS_CMD_CONNECT: 110 | cmd = Socks4Message.REQUEST_CONNECT; 111 | break; 112 | case SOCKS_CMD_BIND: 113 | cmd = Socks4Message.REQUEST_BIND; 114 | break; 115 | default: 116 | return null; 117 | } 118 | return new Socks4Message(cmd, ip, port, user); 119 | } 120 | 121 | @Override 122 | protected ProxyMessage formMessage(int cmd, String host, int port) 123 | throws UnknownHostException { 124 | return formMessage(cmd, InetAddress.getByName(host), port); 125 | } 126 | 127 | } 128 | -------------------------------------------------------------------------------- /src/com/trilead/ssh2/crypto/cipher/BlockCipherFactory.java: -------------------------------------------------------------------------------- 1 | package com.trilead.ssh2.crypto.cipher; 2 | 3 | import java.util.Vector; 4 | 5 | /** 6 | * BlockCipherFactory. 7 | * 8 | * @author Christian Plattner, plattner@trilead.com 9 | * @version $Id: BlockCipherFactory.java,v 1.2 2008/04/01 12:38:09 cplattne Exp 10 | * $ 11 | */ 12 | public class BlockCipherFactory { 13 | static class CipherEntry { 14 | String type; 15 | int blocksize; 16 | int keysize; 17 | String cipherClass; 18 | 19 | public CipherEntry(String type, int blockSize, int keySize, 20 | String cipherClass) { 21 | this.type = type; 22 | this.blocksize = blockSize; 23 | this.keysize = keySize; 24 | this.cipherClass = cipherClass; 25 | } 26 | } 27 | 28 | static Vector ciphers = new Vector(); 29 | 30 | static { 31 | /* Higher Priority First */ 32 | 33 | ciphers.addElement(new CipherEntry("aes256-cbc", 16, 32, 34 | "com.trilead.ssh2.crypto.cipher.AES")); 35 | ciphers.addElement(new CipherEntry("aes192-cbc", 16, 24, 36 | "com.trilead.ssh2.crypto.cipher.AES")); 37 | ciphers.addElement(new CipherEntry("aes128-cbc", 16, 16, 38 | "com.trilead.ssh2.crypto.cipher.AES")); 39 | ciphers.addElement(new CipherEntry("blowfish-cbc", 8, 16, 40 | "com.trilead.ssh2.crypto.cipher.BlowFish")); 41 | 42 | ciphers.addElement(new CipherEntry("aes256-ctr", 16, 32, 43 | "com.trilead.ssh2.crypto.cipher.AES")); 44 | ciphers.addElement(new CipherEntry("aes192-ctr", 16, 24, 45 | "com.trilead.ssh2.crypto.cipher.AES")); 46 | ciphers.addElement(new CipherEntry("aes128-ctr", 16, 16, 47 | "com.trilead.ssh2.crypto.cipher.AES")); 48 | ciphers.addElement(new CipherEntry("blowfish-ctr", 8, 16, 49 | "com.trilead.ssh2.crypto.cipher.BlowFish")); 50 | 51 | ciphers.addElement(new CipherEntry("3des-ctr", 8, 24, 52 | "com.trilead.ssh2.crypto.cipher.DESede")); 53 | ciphers.addElement(new CipherEntry("3des-cbc", 8, 24, 54 | "com.trilead.ssh2.crypto.cipher.DESede")); 55 | } 56 | 57 | public static void checkCipherList(String[] cipherCandidates) { 58 | for (int i = 0; i < cipherCandidates.length; i++) 59 | getEntry(cipherCandidates[i]); 60 | } 61 | 62 | public static BlockCipher createCipher(String type, boolean encrypt, 63 | byte[] key, byte[] iv) { 64 | try { 65 | CipherEntry ce = getEntry(type); 66 | Class cc = Class.forName(ce.cipherClass); 67 | BlockCipher bc = (BlockCipher) cc.newInstance(); 68 | 69 | if (type.endsWith("-cbc")) { 70 | bc.init(encrypt, key); 71 | return new CBCMode(bc, iv, encrypt); 72 | } else if (type.endsWith("-ctr")) { 73 | bc.init(true, key); 74 | return new CTRMode(bc, iv, encrypt); 75 | } 76 | throw new IllegalArgumentException("Cannot instantiate " + type); 77 | } catch (Exception e) { 78 | throw new IllegalArgumentException("Cannot instantiate " + type); 79 | } 80 | } 81 | 82 | public static int getBlockSize(String type) { 83 | CipherEntry ce = getEntry(type); 84 | return ce.blocksize; 85 | } 86 | 87 | public static String[] getDefaultCipherList() { 88 | String list[] = new String[ciphers.size()]; 89 | for (int i = 0; i < ciphers.size(); i++) { 90 | CipherEntry ce = ciphers.elementAt(i); 91 | list[i] = new String(ce.type); 92 | } 93 | return list; 94 | } 95 | 96 | private static CipherEntry getEntry(String type) { 97 | for (int i = 0; i < ciphers.size(); i++) { 98 | CipherEntry ce = ciphers.elementAt(i); 99 | if (ce.type.equals(type)) 100 | return ce; 101 | } 102 | throw new IllegalArgumentException("Unkown algorithm " + type); 103 | } 104 | 105 | public static int getKeySize(String type) { 106 | CipherEntry ce = getEntry(type); 107 | return ce.keysize; 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /src/com/trilead/ssh2/packets/TypesWriter.java: -------------------------------------------------------------------------------- 1 | package com.trilead.ssh2.packets; 2 | 3 | import java.io.UnsupportedEncodingException; 4 | import java.math.BigInteger; 5 | 6 | /** 7 | * TypesWriter. 8 | * 9 | * @author Christian Plattner, plattner@trilead.com 10 | * @version $Id: TypesWriter.java,v 1.2 2008/04/01 12:38:09 cplattne Exp $ 11 | */ 12 | public class TypesWriter { 13 | byte arr[]; 14 | int pos; 15 | 16 | public TypesWriter() { 17 | arr = new byte[256]; 18 | pos = 0; 19 | } 20 | 21 | public byte[] getBytes() { 22 | byte[] dst = new byte[pos]; 23 | System.arraycopy(arr, 0, dst, 0, pos); 24 | return dst; 25 | } 26 | 27 | public void getBytes(byte dst[]) { 28 | System.arraycopy(arr, 0, dst, 0, pos); 29 | } 30 | 31 | public int length() { 32 | return pos; 33 | } 34 | 35 | private void resize(int len) { 36 | byte new_arr[] = new byte[len]; 37 | System.arraycopy(arr, 0, new_arr, 0, arr.length); 38 | arr = new_arr; 39 | } 40 | 41 | public void writeBoolean(boolean v) { 42 | if ((pos + 1) > arr.length) 43 | resize(arr.length + 32); 44 | 45 | arr[pos++] = v ? (byte) 1 : (byte) 0; 46 | } 47 | 48 | public void writeByte(int v) { 49 | writeByte(v, pos); 50 | pos++; 51 | } 52 | 53 | public void writeByte(int v, int off) { 54 | if ((off + 1) > arr.length) 55 | resize(off + 32); 56 | 57 | arr[off] = (byte) v; 58 | } 59 | 60 | public void writeBytes(byte[] buff) { 61 | writeBytes(buff, 0, buff.length); 62 | } 63 | 64 | public void writeBytes(byte[] buff, int off, int len) { 65 | if ((pos + len) > arr.length) 66 | resize(arr.length + len + 32); 67 | 68 | System.arraycopy(buff, off, arr, pos, len); 69 | pos += len; 70 | } 71 | 72 | public void writeMPInt(BigInteger b) { 73 | byte raw[] = b.toByteArray(); 74 | 75 | if ((raw.length == 1) && (raw[0] == 0)) 76 | writeUINT32(0); /* String with zero bytes of data */ 77 | else 78 | writeString(raw, 0, raw.length); 79 | } 80 | 81 | public void writeNameList(String v[]) { 82 | StringBuffer sb = new StringBuffer(); 83 | for (int i = 0; i < v.length; i++) { 84 | if (i > 0) 85 | sb.append(','); 86 | sb.append(v[i]); 87 | } 88 | writeString(sb.toString()); 89 | } 90 | 91 | public void writeString(byte[] buff, int off, int len) { 92 | writeUINT32(len); 93 | writeBytes(buff, off, len); 94 | } 95 | 96 | public void writeString(String v) { 97 | byte[] b; 98 | 99 | try { 100 | /* All Java JVMs must support ISO-8859-1 */ 101 | b = v.getBytes("ISO-8859-1"); 102 | } catch (UnsupportedEncodingException ignore) { 103 | b = v.getBytes(); 104 | } 105 | 106 | writeUINT32(b.length); 107 | writeBytes(b, 0, b.length); 108 | } 109 | 110 | public void writeString(String v, String charsetName) 111 | throws UnsupportedEncodingException { 112 | byte[] b = (charsetName == null) ? v.getBytes() : v 113 | .getBytes(charsetName); 114 | 115 | writeUINT32(b.length); 116 | writeBytes(b, 0, b.length); 117 | } 118 | 119 | public void writeUINT32(int val) { 120 | writeUINT32(val, pos); 121 | pos += 4; 122 | } 123 | 124 | public void writeUINT32(int val, int off) { 125 | if ((off + 4) > arr.length) 126 | resize(off + 32); 127 | 128 | arr[off++] = (byte) (val >> 24); 129 | arr[off++] = (byte) (val >> 16); 130 | arr[off++] = (byte) (val >> 8); 131 | arr[off++] = (byte) val; 132 | } 133 | 134 | public void writeUINT64(long val) { 135 | if ((pos + 8) > arr.length) 136 | resize(arr.length + 32); 137 | 138 | arr[pos++] = (byte) (val >> 56); 139 | arr[pos++] = (byte) (val >> 48); 140 | arr[pos++] = (byte) (val >> 40); 141 | arr[pos++] = (byte) (val >> 32); 142 | arr[pos++] = (byte) (val >> 24); 143 | arr[pos++] = (byte) (val >> 16); 144 | arr[pos++] = (byte) (val >> 8); 145 | arr[pos++] = (byte) val; 146 | } 147 | } 148 | -------------------------------------------------------------------------------- /src/com/trilead/ssh2/HTTPProxyData.java: -------------------------------------------------------------------------------- 1 | package com.trilead.ssh2; 2 | 3 | /** 4 | * A HTTPProxyData 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 | *

62 | * Please note: if you want to use basic authentication, then both 63 | * proxyUser and proxyPass must be non-null. 64 | *

65 | * Here is an example: 66 | *

67 | * 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 | *

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 DHGexParameters object can be used to specify parameters for 5 | * the diffie-hellman group exchange. 6 | *

7 | * Depending on which constructor is used, either the use of a 8 | * 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 | *

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 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 | --------------------------------------------------------------------------------