Remove SharpSSH

This commit is contained in:
Hylke Bons 2010-07-23 01:25:09 +01:00
parent 5e854fa7dc
commit 6881fbe793
134 changed files with 0 additions and 22558 deletions

View file

@ -1,58 +0,0 @@
using System.Reflection;
using System.Runtime.CompilerServices;
//
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
//
[assembly: AssemblyTitle("SharpSSH")]
[assembly: AssemblyDescription("SSH library for .NET")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("tamirgal.com")]
[assembly: AssemblyProduct("SharpSSH")]
[assembly: AssemblyCopyright("Tamir Gal (c) 2007 and jcraft.com")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
//
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Revision and Build Numbers
// by using the '*' as shown below:
[assembly: AssemblyVersion("1.1.1.13")]
//
// In order to sign your assembly you must specify a key to use. Refer to the
// Microsoft .NET Framework documentation for more information on assembly signing.
//
// Use the attributes below to control which key is used for signing.
//
// Notes:
// (*) If no key is specified, the assembly is not signed.
// (*) KeyName refers to a key that has been installed in the Crypto Service
// Provider (CSP) on your machine. KeyFile refers to a file which contains
// a key.
// (*) If the KeyFile and the KeyName values are both specified, the
// following processing occurs:
// (1) If the KeyName can be found in the CSP, that key is used.
// (2) If the KeyName does not exist and the KeyFile does exist, the key
// in the KeyFile is installed into the CSP and used.
// (*) In order to create a KeyFile, you can use the sn.exe (Strong Name) utility.
// When specifying the KeyFile, the location of the KeyFile should be
// relative to the project output directory which is
// %Project Directory%\obj\<configuration>. For example, if your KeyFile is
// located in the project directory, you would specify the AssemblyKeyFile
// attribute as [assembly: AssemblyKeyFile("..\\..\\mykey.snk")]
// (*) Delay Signing is an advanced option - see the Microsoft .NET Framework
// documentation for more information on this.
//
[assembly: AssemblyDelaySign(false)]
[assembly: AssemblyKeyFile("")]
[assembly: AssemblyKeyName("")]

View file

@ -1,43 +0,0 @@
using System;
using Tamir.SharpSsh.jsch;
using System.Collections;
using System.IO;
namespace Tamir.SharpSsh
{
/// <summary>
/// Summary description for ExecTest.
/// </summary>
public class ExecTest
{
public static void Run()
{
JSch jsch=new JSch();
Session session=jsch.getSession("root", "rhmanage", 22);
session.setPassword( "cisco" );
Hashtable config=new Hashtable();
config.Add("StrictHostKeyChecking", "no");
session.setConfig(config);
session.connect();
Channel channel=session.openChannel("exec");
((ChannelExec)channel).setCommand("ifconfig");
StreamReader sr = new StreamReader( channel.getInputStream() );
channel.connect();
string line;
while( (line=sr.ReadLine()) != null )
{
Console.WriteLine( line );
}
channel.disconnect();
session.disconnect();
}
}
}

View file

@ -1,61 +0,0 @@
using System;
/*
* ITransferProtocol.cs
*
* Copyright (c) 2006 Tamir Gal, http://www.tamirgal.com, All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the distribution.
*
* 3. The names of the authors may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR
* *OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
**/
namespace Tamir.SharpSsh
{
/// <summary>
/// Summary description for ITransferProtocol.
/// </summary>
public interface ITransferProtocol
{
void Connect();
void Close();
void Cancel();
void Get(string fromFilePath, string toFilePath);
void Put(string fromFilePath, string toFilePath);
void Mkdir(string directory);
/// <summary>
/// Triggered when protocol transfer is starting
/// </summary>
event FileTransferEvent OnTransferStart;
/// <summary>
/// Triggered when protocol transfer ends
/// </summary>
event FileTransferEvent OnTransferEnd;
/// <summary>
/// Triggered on every interval with the transfer progress iformation.
/// </summary>
event FileTransferEvent OnTransferProgress;
}
public delegate void FileTransferEvent(string src, string dst, int transferredBytes, int totalBytes, string message);
}

View file

@ -1,372 +0,0 @@
using System;
using System.IO;
using Tamir.Streams;
using Tamir.SharpSsh.jsch;
using Tamir.SharpSsh.jsch.examples;
namespace Tamir
{
/// <summary>
/// Summary description for Main.
/// </summary>
public class MainClass
{
public static void Main()
{
Console.WriteLine("sharpSsh 1.0");
//testSsh();
//test();
//testSig();
//testSig2();
//testSigFromJava();
//testDump();
//testDumpBase64();
//testHMacMD5();
testExamples();
//jarAndScp();
}
public static void test()
{
JSch jsch = new JSch();
DH dh1 = null;
DH dh2 = null;
try
{
Type t=Type.GetType(jsch.getConfig("dh"));
dh1=(DH)(Activator.CreateInstance(t));
dh1.init();
dh2=(DH)(Activator.CreateInstance(t));
dh2.init();
}
catch(Exception ee)
{
Console.WriteLine(ee);
}
dh1.setP(DHG1.p);
dh1.setG(DHG1.g);
dh2.setP(DHG1.p);
dh2.setG(DHG1.g);
// The client responds with:
// byte SSH_MSG_KEXDH_INIT(30)
// mpint e <- g^x mod p
// x is a random number (1 < x < (p-1)/2)
byte[] e=dh1.getE();
byte[] f=dh2.getE();
Console.WriteLine("Private1 = {0}", hex(e));
Console.WriteLine();
Console.WriteLine("Private2 = {0}", hex(f));
Console.WriteLine();
dh1.setF(f);
dh2.setF(e);
byte[] k1 = dh1.getK();
byte[] k2 = dh2.getK();
Console.WriteLine("Public1 = {0}", hex(k1));
Console.WriteLine();
Console.WriteLine("Public2 = {0}", hex(k2));
Console.WriteLine();
}
public static void testSig()
{
byte[] hash = Util.getBytes( "Tamir" );
Tamir.SharpSsh.jsch.jce.SignatureRSA enc_rsa = new Tamir.SharpSsh.jsch.jce.SignatureRSA();
Tamir.SharpSsh.jsch.jce.SignatureRSA dec_rsa = new Tamir.SharpSsh.jsch.jce.SignatureRSA();
Tamir.SharpSsh.jsch.jce.KeyPairGenRSA gen = new Tamir.SharpSsh.jsch.jce.KeyPairGenRSA();
gen.init(512);
enc_rsa.init();
enc_rsa.setPrvKey(gen.KeyInfo);
enc_rsa.update(hash);
byte[] sig = enc_rsa.sign();
dump(gen.getE(), gen.getN(), sig, hash);
dec_rsa.init();
dec_rsa.setPubKey(gen.getE(), gen.getN());
dec_rsa.update(hash);
Console.WriteLine( dec_rsa.verify(sig) );
}
public static void testSigFromJava()
{
FileStream fs = File.OpenRead("e.bin");
byte[] e = new byte[fs.Length];
fs.Read(e, 0, e.Length);
fs.Close();
fs = File.OpenRead("n.bin");
byte[] n = new byte[fs.Length];
fs.Read(n, 0, n.Length);
fs.Close();
fs = File.OpenRead("sig.bin");
byte[] sig = new byte[fs.Length];
fs.Read(sig, 0, sig.Length);
fs.Close();
Console.Write("E: ");
Console.WriteLine( hex(e) );
Console.Write("N: ");
Console.WriteLine( hex(n) );
Console.Write("SIG: ");
Console.WriteLine( hex(sig) );
byte[] hash = Util.getBytes( "Tamir" );
Tamir.SharpSsh.jsch.jce.SignatureRSA dec_rsa = new Tamir.SharpSsh.jsch.jce.SignatureRSA();
dec_rsa.init();
dec_rsa.setPubKey(e, n);
dec_rsa.update(hash);
Console.WriteLine( dec_rsa.verify(sig) );
}
public static void dump(byte[] e, byte[] n, byte[] sig, byte[] hash)
{
String fname = "e.bin";
if(File.Exists(fname)) File.Delete(fname);
FileStream fs = File.OpenWrite(fname);
fs.Write(e, 0, e.Length);
fs.Close();
fname = "n.bin";
if(File.Exists(fname)) File.Delete(fname);
fs = File.OpenWrite(fname);
fs.Write(n, 0, n.Length);
fs.Close();
fname = "sig.bin";
if(File.Exists(fname)) File.Delete(fname);
fs = File.OpenWrite(fname);
fs.Write(sig, 0, sig.Length);
fs.Close();
fname = "hash.bin";
if(File.Exists(fname)) File.Delete(fname);
fs = File.OpenWrite(fname);
fs.Write(hash, 0, hash.Length);
fs.Close();
Console.Write("E: ");
Console.WriteLine( hex(e) );
Console.WriteLine();
Console.Write("N: ");
Console.WriteLine( hex(n) );
Console.WriteLine();
Console.Write("SIG: ");
Console.WriteLine( hex(sig) );
Console.WriteLine();
Console.Write("HASH: ");
Console.WriteLine( hex(hash) );
Console.WriteLine();
}
public static void testDump()
{
String fname = "e.bin";
FileStream fs = File.OpenRead(fname);
byte[] e = new byte[fs.Length];
fs.Read(e, 0, e.Length);
fs.Close();
fname = "n.bin";
fs = File.OpenRead(fname);
byte[] n = new byte[fs.Length];
fs.Read(n, 0, n.Length);
fs.Close();
fname = "sig.bin";
fs = File.OpenRead(fname);
byte[] sig = new byte[fs.Length];
fs.Read(sig, 0, sig.Length);
fs.Close();
fname = "hash.bin";
fs = File.OpenRead(fname);
byte[] hash = new byte[fs.Length];
fs.Read(hash, 0, hash.Length);
fs.Close();
print("E", e);
print("N", n);
print("SIG", sig);
print("HASH", hash);
Tamir.SharpSsh.jsch.jce.SignatureRSA dec_rsa = new Tamir.SharpSsh.jsch.jce.SignatureRSA();
dec_rsa.init();
dec_rsa.setPubKey(e, n);
dec_rsa.update(hash);
Console.WriteLine( dec_rsa.verify(sig) );
Console.WriteLine();
}
public static void testDumpBase64()
{
String fname = "e.bin";
StreamReader fs = File.OpenText(fname);
string base64 = fs.ReadToEnd();
byte[] e = Convert.FromBase64String( base64 );
fs.Close();
fname = "n.bin";
fs = File.OpenText(fname);
base64 = fs.ReadToEnd();
byte[] n = Convert.FromBase64String( base64 );
fs.Close();
fname = "sig.bin";
fs = File.OpenText(fname);
base64 = fs.ReadToEnd();
byte[] sig = Convert.FromBase64String( base64 );
fs.Close();
fname = "hash.bin";
fs = File.OpenText(fname);
base64 = fs.ReadToEnd();
byte[] hash = Convert.FromBase64String( base64 );
fs.Close();
print("E", e);
print("N", n);
print("SIG", sig);
print("HASH", hash);
Tamir.SharpSsh.jsch.jce.SignatureRSA dec_rsa = new Tamir.SharpSsh.jsch.jce.SignatureRSA();
dec_rsa.init();
dec_rsa.setPubKey(e, n);
dec_rsa.update(hash);
Console.WriteLine( dec_rsa.verify(sig) );
Console.WriteLine();
}
public static void testHMacMD5()
{
byte[] msg = Util.getBytes("Tamir");
byte[] key = new byte[]{1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6};
Tamir.SharpSsh.jsch.jce.HMACMD5 md5 = new Tamir.SharpSsh.jsch.jce.HMACMD5();
md5.init( key );
md5.update(msg, 0, msg.Length);
byte[] hash = md5.doFinal();
Console.WriteLine(hex(hash));
}
public static void testExamples()
{
//String[] arg = new string[]{"rsa", "key", "sharpSSH"};
//KeyGen.RunExample(arg);
// String[] arg = new string[]{"key"};
// ChangePassphrase.RunExample(arg);
//UserAuthPubKey.RunExample(null);
Tamir.SharpSsh.jsch.examples.KnownHosts.RunExample(null);
// String[] arg = new string[]{"C:\\untitled.db", "root@rhclient8:/root/mng/tamir/file"};
// Tamir.SharpSsh.jsch.examples.ScpTo.RunExample(arg);
// String[] arg = new string[]{"root@rhclient8:/root/mng/tamir/file", "file.txt"};
// Tamir.SharpSsh.jsch.examples.ScpFrom.RunExample(arg);
// Tamir.SharpSsh.jsch.examples.Sftp.RunExample(null);
}
public static void jarAndScp()
{
TextReader r = File.OpenText( "jarAndScp.txt" );
string dir = r.ReadLine();
string host = r.ReadLine();
string path = r.ReadLine();
string user = r.ReadLine();
string pass = r.ReadLine();
r.Close();
string file = dir+".jar";
string jarFile = "\""+dir+".jar\"";
//dir = "\""+dir+"\"";
System.Diagnostics.ProcessStartInfo p = new System.Diagnostics.ProcessStartInfo(@"D:\Program Files\Java\jdk1.5.0_03\bin\jar.exe");
p.WorkingDirectory = Directory.GetParent(dir).FullName;
p.Arguments = "-cf "+jarFile+" "+ Path.GetFileName(dir);
p.UseShellExecute = false;
// p.RedirectStandardOutput = true;
// p.RedirectStandardError = true;
System.Diagnostics.Process.Start(p);
System.Diagnostics.Process pr = new System.Diagnostics.Process();
pr.StartInfo = p;
pr.Start();
pr.WaitForExit();
String[] arg = new string[]{file, user+"@"+host+":"+path+Path.GetFileName(file)};
//Tamir.SharpSsh.Scp.To(file, host, path+Path.GetFileName(file), user, pass);
}
public static void print(string name, byte[] data)
{
Console.WriteLine();
Console.Write(name+": ");
Console.WriteLine( hex(data) );
Console.WriteLine();
}
public static string hex(byte[] arr)
{
string hex = "0x";
for(int i=0;i<arr.Length; i++)
{
string mbyte = arr[i].ToString("X");
if (mbyte.Length == 1)
mbyte = "0"+mbyte;
hex += mbyte;
}
return hex;
}
public static byte[] reverse(byte[] arr)
{
byte[] tmp = new byte[arr.Length];
for(int i=0; i<arr.Length; i++)
{
tmp[i] = arr[ arr.Length-1-i];
}
return tmp;
}
/**
* Utility method to delete the leading zeros from the modulus.
* @param a modulus
* @return modulus
*/
public static byte[] stripLeadingZeros(byte[] a)
{
int lastZero = -1;
for (int i = 0; i < a.Length; i++)
{
if (a[i] == 0)
{
lastZero = i;
}
else
{
break;
}
}
lastZero++;
byte[] result = new byte[a.Length - lastZero];
Array.Copy(a, lastZero, result, 0, result.Length);
return result;
}
}
}

View file

@ -1,606 +0,0 @@
using System;
using Tamir.SharpSsh.jsch;
using System.IO;
using System.Text;
using System.Collections;
/*
* Scp.cs
*
* Copyright (c) 2006 Tamir Gal, http://www.tamirgal.com, All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the distribution.
*
* 3. The names of the authors may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR
* *OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
**/
namespace Tamir.SharpSsh
{
/// <summary>
/// Class for handling SCP file transfers over SSH connection.
/// </summary>
public class Scp : SshTransferProtocolBase
{
private bool m_recursive = false;
private bool m_verbos = false;
private bool m_cancelled = false;
public Scp(string host, string user, string password)
: base(host, user, password)
{
}
public Scp(string host, string user)
: base(host, user)
{
}
protected override string ChannelType
{
get { return "exec"; }
}
/// <summary>
///This function is empty, so no channel is connected
///on session connect
/// </summary>
protected override void ConnectChannel()
{
}
/// <summary>
/// Gets or sets a value indicating the default recursive transfer behaviour
/// </summary>
public bool Recursive
{
get{return m_recursive;}
set{m_recursive=value;}
}
/// <summary>
/// Gets or sets a value indicating whether trace information should be printed
/// </summary>
public bool Verbos
{
get{return m_verbos;}
set{m_verbos=value;}
}
public override void Cancel()
{
m_cancelled = true;
}
/// <summary>
/// Creates a directory on the remot server
/// </summary>
/// <param name="dir">The new directory</param>
public override void Mkdir(string dir)
{
SCP_CheckConnectivity();
Channel channel=null;
Stream server = null;
m_cancelled=false;
SCP_ConnectTo(out channel, out server, dir, true);
SCP_EnterIntoDir(server, dir);
channel.disconnect();
}
public override void Put(string fromFilePath, string toFilePath)
{
this.To(fromFilePath, toFilePath);
}
public override void Get(string fromFilePath, string toFilePath)
{
this.From(fromFilePath, toFilePath);
}
/// <summary>
/// Copies a file from local machine to a remote SSH machine.
/// </summary>
/// <param name="localPath">The local file path.</param>
/// <param name="remotePath">The path of the remote file.</param>
public void To(string localPath, string remotePath)
{
this.To(localPath, remotePath, Recursive);
}
/// <summary>
/// Copies a file from local machine to a remote SSH machine.
/// </summary>
/// <param name="localPath">The local file path.</param>
/// <param name="remotePath">The path of the remote file.</param>
public void To(string localPath, string remotePath, bool _recursive)
{
SCP_CheckConnectivity();
Channel channel=null;
Stream server = null;
m_cancelled=false;
try
{
//if we are sending a single file
if(File.Exists(localPath))
{
SCP_ConnectTo(out channel, out server, remotePath, _recursive);
SCP_SendFile(server, localPath, remotePath);
channel.disconnect();
}
//else, if we are sending a local directory
else if(Directory.Exists(localPath))
{
if(!_recursive)
{
throw new SshTransferException(Path.GetFileName("'"+localPath)+"' is a directory, you should use recursive transfer.");
}
SCP_ConnectTo(out channel, out server, remotePath, true);
ToRecursive(server, localPath, remotePath);
channel.disconnect();
}
else
{
throw new SshTransferException("File not found: "+localPath);
}
}
catch(Exception e)
{
if(Verbos)
Console.WriteLine("Error: "+e.Message);
//SendEndMessage(remoteFile, localFile, filesize,filesize, "Transfer ended with an error.");
try{channel.disconnect();}
catch{}
throw e;
}
}
/// <summary>
/// Copies files and directories from local machine to a remote SSH machine using SCP.
/// </summary>
/// <param name="server">I/O Stream for the remote server</param>
/// <param name="src">Source to copy</param>
/// <param name="dst">Destination path</param>
private void ToRecursive(Stream server, string src, string dst)
{
if(Directory.Exists(src))
{
SCP_EnterIntoDir(server, Path.GetFileName(dst));
foreach(string file in Directory.GetFiles(src))
{
SCP_SendFile(server, file, Path.GetFileName( file));
}
if(m_cancelled)
{
return;
}
foreach(string dir in Directory.GetDirectories(src))
{
ToRecursive(server, dir, Path.GetFileName(dir));
}
SCP_EnterIntoParent(server);
}
else if(File.Exists(src))
{
SCP_SendFile(server, src, Path.GetFileName(src));
}
else
{
throw new SshTransferException("File not found: "+src);
}
}
/// <summary>
/// Copies a file from a remote SSH machine to the local machine using SCP.
/// </summary>
/// <param name="remoteFile">The remmote file name</param>
/// <param name="localPath">The local destination path</param>
public void From(string remoteFile, string localPath)
{
this.From(remoteFile, localPath, Recursive);
}
/// <summary>
/// Copies a file from a remote SSH machine to the local machine using SCP.
/// </summary>
/// <param name="remoteFile">The remmote file name</param>
/// <param name="localPath">The local destination path</param>
/// <param name="recursive">Value indicating whether a recursive transfer should take place</param>
public void From(string remoteFile, string localPath, bool _recursive)
{
SCP_CheckConnectivity();
Channel channel=null;
Stream server = null;
m_cancelled=false;
int filesize=0;
String filename=null;
string cmd = null;
try
{
String dir=null;
if(Directory.Exists(localPath))
{
dir= Path.GetFullPath( localPath );
}
SCP_ConnectFrom(out channel, out server, remoteFile, _recursive);
byte[] buf=new byte[1024];
// send '\0'
SCP_SendAck(server);
int c=SCP_CheckAck(server);
//parse scp commands
while((c=='D')||(c=='C')||(c=='E'))
{
if(m_cancelled)
break;
cmd = ""+(char)c;
if(c=='E')
{
c=SCP_CheckAck(server);
dir = Path.GetDirectoryName(dir);
if(Verbos) Console.WriteLine("E");
//send '\0'
SCP_SendAck(server);
c=(char)SCP_CheckAck(server);
continue;
}
// read '0644 ' or '0755 '
server.Read(buf, 0, 5);
for(int i=0;i<5;i++)
cmd+=(char)buf[i];
//reading file size
filesize=0;
while(true)
{
server.Read(buf, 0, 1);
if(buf[0]==' ')break;
filesize=filesize*10+(buf[0]-'0');
}
//reading file name
for(int i=0;;i++)
{
server.Read(buf, i, 1);
if(buf[i]==(byte)0x0a)
{
filename=Util.getString(buf, 0, i);
break;
}
}
cmd += " "+filesize+" "+filename;
// send '\0'
SCP_SendAck(server);
//Receive file
if(c=='C')
{
if(Verbos) Console.WriteLine("Sending file modes: "+cmd);
SCP_ReceiveFile(server, remoteFile,
dir==null?localPath:dir+"/"+filename,
filesize);
if(m_cancelled)
break;
// send '\0'
SCP_SendAck(server);
}
//Enter directory
else if(c=='D')
{
if(dir==null)
{
if(File.Exists(localPath)) throw new SshTransferException("'"+localPath+"' is not a directory");
dir = localPath;
Directory.CreateDirectory(dir);
}
if(Verbos) Console.WriteLine("Entering directory: "+cmd);
dir += "/"+filename;
Directory.CreateDirectory(dir);
}
c=SCP_CheckAck(server);
}
channel.disconnect();
}
catch(Exception e)
{
if(Verbos)
Console.WriteLine("Error: "+e.Message);
try
{
channel.disconnect();
}
catch{}
throw e;
}
}
#region SCP private functions
/// <summary>
/// Checks is a channel is already connected by this instance
/// </summary>
protected void SCP_CheckConnectivity()
{
if(!Connected)
throw new Exception("Channel is down.");
}
/// <summary>
/// Connect a channel to the remote server using the 'SCP TO' command ('scp -t')
/// </summary>
/// <param name="channel">Will contain the new connected channel</param>
/// <param name="server">Will contaun the new connected server I/O stream</param>
/// <param name="rfile">The remote path on the server</param>
/// <param name="recursive">Idicate a recursive scp transfer</param>
protected void SCP_ConnectTo(out Channel channel, out Stream server, string rfile, bool recursive)
{
string scpCommand = "scp -p -t ";
if(recursive) scpCommand += "-r ";
scpCommand += "\""+rfile+"\"";
channel = (ChannelExec)m_session.openChannel(ChannelType);
((ChannelExec)channel).setCommand(scpCommand);
server =
new Tamir.Streams.CombinedStream
(channel.getInputStream(), channel.getOutputStream());
channel.connect();
SCP_CheckAck(server);
}
/// <summary>
/// Connect a channel to the remote server using the 'SCP From' command ('scp -f')
/// </summary>
/// <param name="channel">Will contain the new connected channel</param>
/// <param name="server">Will contaun the new connected server I/O stream</param>
/// <param name="rfile">The remote path on the server</param>
/// <param name="recursive">Idicate a recursive scp transfer</param>
protected void SCP_ConnectFrom(out Channel channel, out Stream server, string rfile, bool recursive)
{
string scpCommand = "scp -f ";
if(recursive) scpCommand += "-r ";
scpCommand += "\""+rfile+"\"";
channel = (ChannelExec)m_session.openChannel(ChannelType);
((ChannelExec)channel).setCommand(scpCommand);
server =
new Tamir.Streams.CombinedStream
(channel.getInputStream(), channel.getOutputStream());
channel.connect();
//SCP_CheckAck(server);
}
/// <summary>
/// Transfer a file to the remote server
/// </summary>
/// <param name="server">A connected server I/O stream</param>
/// <param name="src">The source file to copy</param>
/// <param name="dst">The remote destination path</param>
protected void SCP_SendFile(Stream server, string src, string dst)
{
int filesize = 0;
int copied = 0;
filesize=(int)(new FileInfo(src)).Length;
byte[] tmp=new byte[1];
// send "C0644 filesize filename", where filename should not include '/'
string command="C0644 "+filesize+" "+Path.GetFileName(dst)+"\n";
if(Verbos) Console.WriteLine("Sending file modes: "+command);
SendStartMessage(src, dst, filesize, "Starting transfer.");
byte[] buff = Util.getBytes(command);
server.Write(buff, 0, buff.Length); server.Flush();
if(SCP_CheckAck(server)!=0)
{
throw new SshTransferException("Error openning communication channel.");
}
// send a content of lfile
SendProgressMessage(src, dst, copied, filesize, "Transferring...");
FileStream fis=File.OpenRead(src);
byte[] buf=new byte[1024*10*2];
while(!m_cancelled)
{
int len=fis.Read(buf, 0, buf.Length);
if(len<=0) break;
server.Write(buf, 0, len); server.Flush();
copied += len;
SendProgressMessage(src, dst, copied, filesize, "Transferring...");
}
fis.Close();
if(m_cancelled)
return;
// send '\0'
buf[0]=0; server.Write(buf, 0, 1); server.Flush();
SendProgressMessage(src, dst, copied, filesize, "Verifying transfer...");
if(SCP_CheckAck(server)!=0)
{
SendEndMessage(src, dst,copied,filesize, "Transfer ended with an error.");
throw new SshTransferException("Unknow error during file transfer.");
}
SendEndMessage(src, dst, copied, filesize, "Transfer completed successfuly ("+copied+" bytes).");
}
/// <summary>
/// Transfer a file from the remote server
/// </summary>
/// <param name="server">A connected server I/O stream</param>
/// <param name="rfile">The remote file to copy</param>
/// <param name="lfile">The local destination path</param>
protected void SCP_ReceiveFile(Stream server, string rfile, string lfile, int size)
{
int copied = 0;
SendStartMessage(rfile, lfile, size, "Connected, starting transfer.");
// read a content of lfile
FileStream fos=File.OpenWrite(lfile);
int foo;
int filesize=size;
byte[] buf = new byte[1024];
while(!m_cancelled)
{
if(buf.Length<filesize) foo=buf.Length;
else foo=filesize;
int len=server.Read(buf, 0, foo);
copied += len;
fos.Write(buf, 0, foo);
SendProgressMessage(rfile, lfile, copied, size, "Transferring...");
filesize-=foo;
if(filesize==0) break;
}
fos.Close();
if(m_cancelled)
return;
SCP_CheckAck(server);
SendEndMessage(rfile, lfile, copied, size, "Transfer completed successfuly ("+filesize+" bytes).");
}
/// <summary>
/// Instructs the remote server to enter into a directory
/// </summary>
/// <param name="server">A connected server I/O stream</param>
/// <param name="dir">The directory name/param>
protected void SCP_EnterIntoDir(Stream server, string dir)
{
try
{
byte[] tmp=new byte[1];
// send "C0644 filesize filename", where filename should not include '/'
string command="D0755 0 "+Path.GetFileName(dir)+"\n";
if(Verbos) Console.WriteLine("Enter directory: "+command);
byte[] buff = Util.getBytes(command);
server.Write(buff, 0, buff.Length); server.Flush();
if(SCP_CheckAck(server)!=0)
{
throw new SshTransferException("Error openning communication channel.");
}
}
catch{}
}
/// <summary>
/// Instructs the remote server to go up one level
/// </summary>
/// <param name="server">A connected server I/O stream</param>
protected void SCP_EnterIntoParent(Stream server)
{
try
{
byte[] tmp=new byte[1];
// send "C0644 filesize filename", where filename should not include '/'
string command="E\n";
if(Verbos) Console.WriteLine(command);
byte[] buff = Util.getBytes(command);
server.Write(buff, 0, buff.Length); server.Flush();
if(SCP_CheckAck(server)!=0)
{
throw new SshTransferException("Error openning communication channel.");
}
}
catch{}
}
/// <summary>
/// Gets server acknowledgment
/// </summary>
/// <param name="ins">A connected server I/O stream</param>
private int SCP_CheckAck(Stream ins)
{
int b=ins.ReadByte();
// b may be 0 for success,
// 1 for error,
// 2 for fatal error,
// -1
if(b==0) return b;
if(b==-1) return b;
if(b==1 || b==2)
{
StringBuilder sb=new StringBuilder();
int c;
do
{
c=ins.ReadByte();
sb.Append((char)c);
}
while(c!='\n');
if(b==1)
{ // error
//Console.WriteLine(sb.ToString());
throw new SshTransferException(sb.ToString());
}
if(b==2)
{ // fatal error
//Console.WriteLine(sb.ToString());
throw new SshTransferException(sb.ToString());
}
}
return b;
}
/// <summary>
/// Sends acknowledgment to remote server
/// </summary>
/// <param name="server">A connected server I/O stream</param>
private void SCP_SendAck(Stream server)
{
server.WriteByte(0);
server.Flush();
}
#endregion SCP private functions
}
}

View file

@ -1,354 +0,0 @@
//using System;
//using Tamir.SharpSsh.jsch;
//using System.IO;
//using System.Windows.Forms;
//using System.Text;
//using System.Collections;
//
///*
// * Scp.cs
// *
// * THIS SOURCE CODE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
// * KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
// * IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR
// * PURPOSE.
// *
// * Copyright (C) 2005 Tamir Gal, tamirgal@myrealbox.com.
// */
//
//namespace Tamir.SharpSsh
//{
// /// <summary>
// /// Class for handling SCP file transfers over SSH connection.
// /// </summary>
// public class Scp
// {
// /// <summary>
// /// Triggered when this SCP object starts connecting to the remote server.
// /// </summary>
// public event FileTansferEvent OnConnecting;
// /// <summary>
// /// Triggered when this SCP object starts the file transfer process.
// /// </summary>
// public event FileTansferEvent OnStart;
// /// <summary>
// /// Triggered when this SCP object ends the file transfer process.
// /// </summary>
// public event FileTansferEvent OnEnd;
// /// <summary>
// /// Triggered on every interval with the transfer progress iformation.
// /// </summary>
// public event FileTansferEvent OnProgress;
//
// /// <summary>
// /// The default value of the progress update interval.
// /// </summary>
// private int m_interval = 250;
//
// /// <summary>
// /// Copies a file from local machine to a remote SSH machine.
// /// </summary>
// /// <param name="localFile">The local file path.</param>
// /// <param name="remoteHost">The remote machine's hostname or IP address</param>
// /// <param name="remoteFile">The path of the remote file.</param>
// /// <param name="user">The username for the connection.</param>
// /// <param name="pass">The password for the connection.</param>
// public void To(string localFile, string remoteHost,string remoteFile, string user, string pass)
// {
// Channel channel=null;
// int filesize=0;
// int copied=0;
// try
// {
// double progress=0;
// SendConnectingMessage("Connecting to "+remoteHost+"...");
//
// JSch jsch=new JSch();
// Session session=jsch.getSession(user, remoteHost, 22);
// session.setPassword( pass );
//
// Hashtable config=new Hashtable();
// config.Add("StrictHostKeyChecking", "no");
// session.setConfig(config);
//
// session.connect();
//
// // exec 'scp -t rfile' remotely
// String command="scp -p -t \""+remoteFile+"\"";
// channel=session.openChannel("exec");
// ((ChannelExec)channel).setCommand(command);
//
// // get I/O streams for remote scp
// Stream outs=channel.getOutputStream();
// Stream ins=channel.getInputStream();
//
// channel.connect();
//
// SendStartMessage("Connected, starting transfer.");
//
// byte[] tmp=new byte[1];
//
// if(checkAck(ins)!=0)
// {
// throw new Exception("Error openning communication channel.");
// }
//
// // send "C0644 filesize filename", where filename should not include '/'
//
// filesize=(int)(new FileInfo(localFile)).Length;
// command="C0644 "+filesize+" ";
// if(localFile.LastIndexOf('/')>0)
// {
// command+=localFile.Substring(localFile.LastIndexOf('/')+1);
// }
// else
// {
// command+=localFile;
// }
// command+="\n";
// byte[] buff = Util.getBytes(command);
// outs.Write(buff, 0, buff.Length); outs.Flush();
//
// if(checkAck(ins)!=0)
// {
// throw new Exception("Error openning communication channel.");
// }
//
// // send a content of lfile
// SendProgressMessage(0, filesize, "Transferring...");
// FileStream fis=File.OpenRead(localFile);
// byte[] buf=new byte[1024];
// copied = 0;
// while(true)
// {
// int len=fis.Read(buf, 0, buf.Length);
// if(len<=0) break;
// outs.Write(buf, 0, len); outs.Flush();
// copied += len;
// progress = (copied*100.0/filesize);
// SendProgressMessage(copied, filesize, "Transferring...");
// }
// fis.Close();
//
// // send '\0'
// buf[0]=0; outs.Write(buf, 0, 1); outs.Flush();
//
// SendProgressMessage(copied, filesize, "Verifying transfer...");
// if(checkAck(ins)!=0)
// {
// throw new Exception("Unknow error during file transfer.");
// }
// SendEndMessage(copied, filesize, "Transfer completed successfuly ("+copied+" bytes).");
// try{channel.close();}
// catch{}
// }
// catch(Exception e)
// {
// SendEndMessage(copied,filesize, "Transfer ended with an error.");
// try{channel.close();}
// catch{}
// throw e;
// }
// }
//
// /// <summary>
// /// Copies a file from a remote SSH machine to the local machine.
// /// </summary>
// /// <param name="remoteHost">The remote machine's hosname or IP address.</param>
// /// <param name="remoteFile">The remote file path.</param>
// /// <param name="user">The username or the connection.</param>
// /// <param name="pass">The password for the connection.</param>
// /// <param name="localFile">The local file path.</param>
// public void From(string remoteHost,string remoteFile, string user, string pass, string localFile)
// {
// Channel channel=null;
// int filesize=0;
// int copied=0;
// try
// {
// String prefix=null;
// if(Directory.Exists(localFile))
// {
// prefix=localFile+Path.DirectorySeparatorChar;
// }
//
// double progress=0;
// SendConnectingMessage("Connecting to "+remoteHost+"...");
//
// JSch jsch=new JSch();
// Session session=jsch.getSession(user, remoteHost, 22);
// session.setPassword( pass );
//
// Hashtable config=new Hashtable();
// config.Add("StrictHostKeyChecking", "no");
// session.setConfig(config);
//
// session.connect();
//
// // exec 'scp -f rfile' remotely
// String command="scp -f \""+remoteFile + "\"";
// channel=session.openChannel("exec");
// ((ChannelExec)channel).setCommand(command);
//
// // get I/O streams for remote scp
// Stream outs=channel.getOutputStream();
// Stream ins=channel.getInputStream();
//
// channel.connect();
//
// SendStartMessage("Connected, starting transfer.");
//
// byte[] buf=new byte[1024];
//
// // send '\0'
// buf[0]=0; outs.Write(buf, 0, 1); outs.Flush();
// int c=checkAck(ins);
// if(c!='C')
// {
// throw new Exception("Error openning communication channel.");
// }
//
// // read '0644 '
// ins.Read(buf, 0, 5);
//
// filesize=0;
// while(true)
// {
// ins.Read(buf, 0, 1);
// if(buf[0]==' ')break;
// filesize=filesize*10+(buf[0]-'0');
// }
//
// String file=null;
// for(int i=0;;i++)
// {
// ins.Read(buf, i, 1);
// if(buf[i]==(byte)0x0a)
// {
// file=Util.getString(buf, 0, i);
// break;
// }
// }
//
// // send '\0'
// buf[0]=0; outs.Write(buf, 0, 1); outs.Flush();
//
// // read a content of lfile
// FileStream fos=File.OpenWrite(prefix==null ?
// localFile :
// prefix+file);
// int foo;
// int size=filesize;
// copied=0;
// while(true)
// {
// if(buf.Length<filesize) foo=buf.Length;
// else foo=filesize;
// int len=ins.Read(buf, 0, foo);
// copied += len;
// fos.Write(buf, 0, foo);
// progress += (len*100.0/size);
// SendProgressMessage(copied, size, "Transferring...");
// filesize-=foo;
// if(filesize==0) break;
// }
// fos.Close();
//
// byte[] tmp=new byte[1];
//
// SendProgressMessage(copied, size, "Verifying transfer...");
// if(checkAck(ins)!=0)
// {
// throw new Exception("Unknow error during file transfer.");
// }
//
// // send '\0'
// buf[0]=0; outs.Write(buf, 0, 1); outs.Flush();
// SendEndMessage(copied, size, "Transfer completed successfuly ("+copied+" bytes).");
// }
// catch(Exception e)
// {
// SendEndMessage(copied,filesize, "Transfer ended with an error.");
// try{channel.close();}
// catch{}
// throw e;
// }
// }
//
// private int checkAck(Stream ins)
// {
// int b=ins.ReadByte();
// // b may be 0 for success,
// // 1 for error,
// // 2 for fatal error,
// // -1
// if(b==0) return b;
// if(b==-1) return b;
//
// if(b==1 || b==2)
// {
// StringBuilder sb=new StringBuilder();
// int c;
// do
// {
// c=ins.ReadByte();
// sb.Append((char)c);
// }
// while(c!='\n');
// if(b==1)
// { // error
// throw new Exception(sb.ToString());
// }
// if(b==2)
// { // fatal error
// throw new Exception(sb.ToString());
// }
// }
// return b;
// }
//
// private void SendConnectingMessage(string msg)
// {
// if(OnConnecting != null)
// OnConnecting(-1, 0, msg);
// }
//
// private void SendStartMessage(string msg)
// {
// if(OnStart != null)
// OnStart(-1, 0, msg);
// }
//
// private void SendEndMessage(int transferredBytes, int totalBytes, string msg)
// {
// if(OnEnd != null)
// OnEnd(transferredBytes, totalBytes, msg);
// }
//
// DateTime lastUpdate = DateTime.Now;
// private void SendProgressMessage(int transferredBytes, int totalBytes, string msg)
// {
// if(OnProgress != null)
// {
// TimeSpan diff = DateTime.Now-lastUpdate;
//
// if(diff.Milliseconds>ProgressUpdateInterval)
// {
// OnProgress(transferredBytes,totalBytes, msg);
// lastUpdate=DateTime.Now;
// }
// }
// }
//
// /// <summary>
// /// Gets or sets the progress update interval in milliseconds
// /// </summary>
// public int ProgressUpdateInterval
// {
// get{return m_interval;}
// set{m_interval=value;}
// }
// }
//
// public delegate void FileTansferEvent(int transferredBytes, int totalBytes, string message);
//}

View file

@ -1,17 +0,0 @@
using System;
namespace Tamir.SharpSsh
{
/// <summary>
/// Summary description for SecureShell.
/// </summary>
public class SecureShell
{
public SecureShell()
{
//
// TODO: Add constructor logic here
//
}
}
}

View file

@ -1,219 +0,0 @@
using System;
using Tamir.SharpSsh.jsch;
using System.Collections;
/*
* Sftp.cs
*
* Copyright (c) 2006 Tamir Gal, http://www.tamirgal.com, All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the distribution.
*
* 3. The names of the authors may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR
* *OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
**/
namespace Tamir.SharpSsh
{
public class Sftp : SshTransferProtocolBase
{
private MyProgressMonitor m_monitor;
private bool cancelled = false;
public Sftp(string sftpHost, string user, string password)
: base(sftpHost, user, password)
{
Init();
}
public Sftp(string sftpHost, string user)
: base(sftpHost, user)
{
Init();
}
private void Init()
{
m_monitor = new MyProgressMonitor(this);
}
protected override string ChannelType
{
get { return "sftp"; }
}
private ChannelSftp SftpChannel
{
get { return (ChannelSftp)m_channel; }
}
public override void Cancel()
{
cancelled = true;
}
//Get
public void Get(string fromFilePath)
{
Get(fromFilePath, ".");
}
public void Get(string[] fromFilePaths)
{
for (int i = 0; i < fromFilePaths.Length; i++)
{
Get(fromFilePaths[i]);
}
}
public void Get(string[] fromFilePaths, string toDirPath)
{
for (int i = 0; i < fromFilePaths.Length; i++)
{
Get(fromFilePaths[i], toDirPath);
}
}
public override void Get(string fromFilePath, string toFilePath)
{
cancelled=false;
SftpChannel.get(fromFilePath, toFilePath, m_monitor, ChannelSftp.OVERWRITE);
}
//Put
public void Put(string fromFilePath)
{
Put(fromFilePath, ".");
}
public void Put(string[] fromFilePaths)
{
for (int i = 0; i < fromFilePaths.Length; i++)
{
Put(fromFilePaths[i]);
}
}
public void Put(string[] fromFilePaths, string toDirPath)
{
for (int i = 0; i < fromFilePaths.Length; i++)
{
Put(fromFilePaths[i], toDirPath);
}
}
public override void Put(string fromFilePath, string toFilePath)
{
cancelled=false;
SftpChannel.put(fromFilePath, toFilePath, m_monitor, ChannelSftp.OVERWRITE);
}
//MkDir
public override void Mkdir(string directory)
{
SftpChannel.mkdir(directory);
}
//Ls
public ArrayList GetFileList(string path)
{
ArrayList list = new ArrayList();
foreach(Tamir.SharpSsh.jsch.ChannelSftp.LsEntry entry in SftpChannel.ls(path))
{
list.Add(entry.getFilename().ToString());
}
return list;
}
#region ProgressMonitor Implementation
private class MyProgressMonitor : SftpProgressMonitor
{
private long transferred = 0;
private long total = 0;
private int elapsed = -1;
private Sftp m_sftp;
private string src;
private string dest;
System.Timers.Timer timer;
public MyProgressMonitor(Sftp sftp)
{
m_sftp = sftp;
}
public override void init(int op, String src, String dest, long max)
{
this.src=src;
this.dest=dest;
this.elapsed = 0;
this.total = max;
timer = new System.Timers.Timer(1000);
timer.Start();
timer.Elapsed += new System.Timers.ElapsedEventHandler(timer_Elapsed);
string note;
if (op.Equals(GET))
{
note = "Downloading " + System.IO.Path.GetFileName( src ) + "...";
}
else
{
note = "Uploading " + System.IO.Path.GetFileName( src ) + "...";
}
m_sftp.SendStartMessage(src, dest, (int)total, note);
}
public override bool count(long c)
{
this.transferred += c;
string note = ("Transfering... [Elapsed time: " + elapsed + "]");
m_sftp.SendProgressMessage(src, dest, (int)transferred, (int)total, note);
return !m_sftp.cancelled;
}
public override void end()
{
timer.Stop();
timer.Dispose();
string note = ("Done in " + elapsed + " seconds!");
m_sftp.SendEndMessage(src, dest, (int)transferred, (int)total, note);
transferred = 0;
total = 0;
elapsed = -1;
src=null;
dest=null;
}
private void timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
this.elapsed++;
}
}
#endregion ProgressMonitor Implementation
}
}

View file

@ -1,199 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>8.0.50727</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{BB50B7E2-4622-4D8B-B7FF-5E5D8F02D91F}</ProjectGuid>
<OutputType>Library</OutputType>
<RootNamespace>Tamir.SharpSsh</RootNamespace>
<AssemblyName>Tamir.SharpSSH</AssemblyName>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>..\bin\Debug\</OutputPath>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<RunWithWarnings>false</RunWithWarnings>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>none</DebugType>
<Optimize>false</Optimize>
<OutputPath>..\bin\Release\</OutputPath>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<RunWithWarnings>false</RunWithWarnings>
</PropertyGroup>
<ItemGroup>
<Content Include="App.ico" />
<Content Include="jsch\examples\README.txt" />
</ItemGroup>
<ItemGroup>
<Compile Include="AssemblyInfo.cs" />
<Compile Include="ITransferProtocol.cs" />
<Compile Include="Scp.cs" />
<Compile Include="Sftp.cs" />
<Compile Include="SshBase.cs" />
<Compile Include="SshExe.cs" />
<Compile Include="SshShell.cs" />
<Compile Include="SshStream.cs" />
<Compile Include="SshTransferException.cs" />
<Compile Include="SshTransferProtocolBase.cs" />
<Compile Include="java\Exception.cs" />
<Compile Include="java\Platform.cs" />
<Compile Include="java\RuntimeException.cs" />
<Compile Include="java\String.cs" />
<Compile Include="java\System.cs" />
<Compile Include="java\io\File.cs" />
<Compile Include="java\io\FileInputStream.cs" />
<Compile Include="java\io\FileOutputStream.cs" />
<Compile Include="java\io\InputStream.cs" />
<Compile Include="java\io\InputStreamWrapper.cs" />
<Compile Include="java\io\JStream.cs" />
<Compile Include="java\io\OutputStream.cs" />
<Compile Include="java\lang\Class.cs" />
<Compile Include="java\lang\Integer.cs" />
<Compile Include="java\lang\Runnable.cs" />
<Compile Include="java\lang\StringBuffer.cs" />
<Compile Include="java\lang\Thread.cs" />
<Compile Include="java\net\InetAddress.cs" />
<Compile Include="java\net\ServerSocket.cs" />
<Compile Include="java\net\Socket.cs" />
<Compile Include="java\util\Arrays.cs" />
<Compile Include="java\util\Enumeration.cs" />
<Compile Include="java\util\Hashtable.cs" />
<Compile Include="java\util\JavaString.cs" />
<Compile Include="java\util\Vector.cs" />
<Compile Include="jsch\Buffer.cs" />
<Compile Include="jsch\Channel.cs" />
<Compile Include="jsch\Channel.old.cs" />
<Compile Include="jsch\ChannelDirectTCPIP.cs" />
<Compile Include="jsch\ChannelExec.cs" />
<Compile Include="jsch\ChannelForwardedTCPIP.cs" />
<Compile Include="jsch\ChannelSession.cs" />
<Compile Include="jsch\ChannelSftp.cs" />
<Compile Include="jsch\ChannelSftpStreamGet.cs" />
<Compile Include="jsch\ChannelSftpStreamPut.cs" />
<Compile Include="jsch\ChannelShell.cs" />
<Compile Include="jsch\ChannelSubsystem.cs" />
<Compile Include="jsch\ChannelX11.cs" />
<Compile Include="jsch\Cipher.cs" />
<Compile Include="jsch\Compression.cs" />
<Compile Include="jsch\DH.cs" />
<Compile Include="jsch\DHG1.cs" />
<Compile Include="jsch\DHGEX.cs" />
<Compile Include="jsch\ForwardedTCPIPDaemon.cs" />
<Compile Include="jsch\HASH.cs" />
<Compile Include="jsch\HostKey.cs" />
<Compile Include="jsch\HostKeyRepository.cs" />
<Compile Include="jsch\Identity.cs" />
<Compile Include="jsch\IdentityFile.cs" />
<Compile Include="jsch\IO.cs" />
<Compile Include="jsch\JSch.cs" />
<Compile Include="jsch\JSchAuthCancelException.cs" />
<Compile Include="jsch\JSchException.cs" />
<Compile Include="jsch\JSchPartialAuthException.cs" />
<Compile Include="jsch\KeyExchange.cs" />
<Compile Include="jsch\KeyPair.cs" />
<Compile Include="jsch\KeyPairDSA.cs" />
<Compile Include="jsch\KeyPairGenDSA.cs" />
<Compile Include="jsch\KeyPairGenRSA.cs" />
<Compile Include="jsch\KeyPairRSA.cs" />
<Compile Include="jsch\KnownHosts.cs" />
<Compile Include="jsch\MAC.cs" />
<Compile Include="jsch\Packet.cs" />
<Compile Include="jsch\PortWatcher.cs" />
<Compile Include="jsch\Proxy.cs" />
<Compile Include="jsch\ProxyHTTP.cs" />
<Compile Include="jsch\Random.cs" />
<Compile Include="jsch\Request.cs" />
<Compile Include="jsch\RequestExec.cs" />
<Compile Include="jsch\RequestPtyReq.cs" />
<Compile Include="jsch\RequestSftp.cs" />
<Compile Include="jsch\RequestShell.cs" />
<Compile Include="jsch\RequestSignal.cs" />
<Compile Include="jsch\RequestSubsystem.cs" />
<Compile Include="jsch\RequestWindowChange.cs" />
<Compile Include="jsch\RequestX11.cs" />
<Compile Include="jsch\ServerSocketFactory.cs" />
<Compile Include="jsch\Session.cs" />
<Compile Include="jsch\SftpATTRS.cs" />
<Compile Include="jsch\SftpException.cs" />
<Compile Include="jsch\SftpProgressMonitor.cs" />
<Compile Include="jsch\SignatureDSA.cs" />
<Compile Include="jsch\SignatureRSA.cs" />
<Compile Include="jsch\SocketFactory.cs" />
<Compile Include="jsch\UIKeyboardInteractive.cs" />
<Compile Include="jsch\UserAuth.cs" />
<Compile Include="jsch\UserAuthKeyboardInteractive.cs" />
<Compile Include="jsch\UserAuthNone.cs" />
<Compile Include="jsch\UserAuthPassword.cs" />
<Compile Include="jsch\UserAuthPublicKey.cs" />
<Compile Include="jsch\UserInfo.cs" />
<Compile Include="jsch\Util.cs" />
<Compile Include="jsch\examples\AES.cs" />
<Compile Include="jsch\examples\ChangePassphrase.cs" />
<Compile Include="jsch\examples\KeyGen.cs" />
<Compile Include="jsch\examples\KnownHosts.cs" />
<Compile Include="jsch\examples\PortForwardingL.cs" />
<Compile Include="jsch\examples\PortForwardingR.cs" />
<Compile Include="jsch\examples\ScpFrom.cs" />
<Compile Include="jsch\examples\ScpTo.cs" />
<Compile Include="jsch\examples\Sftp.cs" />
<Compile Include="jsch\examples\Shell.cs" />
<Compile Include="jsch\examples\StreamForwarding.cs" />
<Compile Include="jsch\examples\UserAuthPubKey.cs" />
<Compile Include="jsch\examples\util\ConsoleProgressBar.cs" />
<Compile Include="jsch\examples\util\InputForm.cs" />
<Compile Include="jsch\jce\AES128CBC.cs" />
<Compile Include="jsch\jce\BlowfishCBC.cs" />
<Compile Include="jsch\jce\DH.cs" />
<Compile Include="jsch\jce\HMACMD5.cs" />
<Compile Include="jsch\jce\HMACMD596.cs" />
<Compile Include="jsch\jce\HMACSHA1.cs" />
<Compile Include="jsch\jce\HMACSHA196.cs" />
<Compile Include="jsch\jce\KeyPairGenDSA.cs" />
<Compile Include="jsch\jce\KeyPairGenRSA.cs" />
<Compile Include="jsch\jce\MD5.cs" />
<Compile Include="jsch\jce\Random.cs" />
<Compile Include="jsch\jce\SHA1.cs" />
<Compile Include="jsch\jce\SignatureDSA.cs" />
<Compile Include="jsch\jce\SignatureRSA.cs" />
<Compile Include="jsch\jce\TripleDESCBC.cs" />
<Compile Include="Streams\CombinedStream.cs" />
<Compile Include="Streams\InputStream.cs" />
<Compile Include="Streams\OutputStream.cs" />
<Compile Include="Streams\PipedInputStream.cs" />
<Compile Include="Streams\PipedOutputStream.cs" />
<Compile Include="Streams\ProtectedConsoleStream.cs" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="jsch\examples\util\InputForm.resx">
<DependentUpon>InputForm.cs</DependentUpon>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Drawing" />
<Reference Include="DiffieHellman, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
<SpecificVersion>False</SpecificVersion>
<HintPath>lib\DiffieHellman.dll</HintPath>
</Reference>
<Reference Include="Org.Mentalis.Security, Version=1.0.13.715, Culture=neutral, PublicKeyToken=null">
<SpecificVersion>False</SpecificVersion>
<HintPath>lib\Org.Mentalis.Security.dll</HintPath>
</Reference>
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<ProjectExtensions>
<MonoDevelop>
<Properties InternalTargetFrameworkVersion="3.5" />
</MonoDevelop>
</ProjectExtensions>
</Project>

View file

@ -1,48 +0,0 @@
<VisualStudioProject>
<CSHARP LastOpenVersion = "7.10.3077" >
<Build>
<Settings ReferencePath = "C:\Documents and Settings\tgal\My Documents\Docs\CVS\SharpSSH\SharpSSH\lib\" >
<Config
Name = "Debug"
EnableASPDebugging = "false"
EnableASPXDebugging = "false"
EnableUnmanagedDebugging = "false"
EnableSQLServerDebugging = "false"
RemoteDebugEnabled = "false"
RemoteDebugMachine = ""
StartAction = "Project"
StartArguments = ""
StartPage = ""
StartProgram = ""
StartURL = ""
StartWorkingDirectory = ""
StartWithIE = "true"
/>
<Config
Name = "Release"
EnableASPDebugging = "false"
EnableASPXDebugging = "false"
EnableUnmanagedDebugging = "false"
EnableSQLServerDebugging = "false"
RemoteDebugEnabled = "false"
RemoteDebugMachine = ""
StartAction = "Project"
StartArguments = ""
StartPage = ""
StartProgram = ""
StartURL = ""
StartWorkingDirectory = ""
StartWithIE = "false"
/>
</Settings>
</Build>
<OtherProjectSettings
CopyProjectDestinationFolder = ""
CopyProjectUncPath = ""
CopyProjectOption = "0"
ProjectView = "ProjectFiles"
ProjectTrust = "0"
/>
</CSHARP>
</VisualStudioProject>

View file

@ -1,167 +0,0 @@
<Project name="SharpSSH" fileversion="2.0" DefaultNamespace="Tamir.SharpSsh" language="C#" targetFramework="3.5" ctype="DotNetProject">
<Configurations>
<Configuration name="Debug" ctype="DotNetProjectConfiguration">
<Output directory="../bin/Debug/" assembly="Tamir.SharpSSH" />
<Build debugmode="True" target="Library" />
<Execution consolepause="True" runwithwarnings="False" runtime="MsNet" />
<CodeGeneration compiler="Mcs" warninglevel="4" optimize="False" unsafecodeallowed="False" generateoverflowchecks="False" generatexmldocumentation="False" ctype="CSharpCompilerParameters" />
</Configuration>
<Configuration name="Release" ctype="DotNetProjectConfiguration">
<Output directory="../bin/Release/" assembly="Tamir.SharpSSH" />
<Build debugmode="False" target="Library" />
<Execution consolepause="True" runwithwarnings="False" runtime="MsNet" />
<CodeGeneration compiler="Mcs" warninglevel="4" optimize="False" unsafecodeallowed="False" generateoverflowchecks="False" generatexmldocumentation="False" ctype="CSharpCompilerParameters" />
</Configuration>
</Configurations>
<Contents>
<File subtype="Code" buildaction="Exclude" name="App.ico" />
<File subtype="Code" buildaction="Compile" name="AssemblyInfo.cs" />
<File subtype="Code" buildaction="Compile" name="ITransferProtocol.cs" />
<File subtype="Code" buildaction="Compile" name="Scp.cs" />
<File subtype="Code" buildaction="Compile" name="Sftp.cs" />
<File subtype="Code" buildaction="Compile" name="SshBase.cs" />
<File subtype="Code" buildaction="Compile" name="SshExe.cs" />
<File subtype="Code" buildaction="Compile" name="SshShell.cs" />
<File subtype="Code" buildaction="Compile" name="SshStream.cs" />
<File subtype="Code" buildaction="Compile" name="SshTransferException.cs" />
<File subtype="Code" buildaction="Compile" name="SshTransferProtocolBase.cs" />
<File subtype="Code" buildaction="Compile" name="java/Exception.cs" />
<File subtype="Code" buildaction="Compile" name="java/Platform.cs" />
<File subtype="Code" buildaction="Compile" name="java/RuntimeException.cs" />
<File subtype="Code" buildaction="Compile" name="java/String.cs" />
<File subtype="Code" buildaction="Compile" name="java/System.cs" />
<File subtype="Code" buildaction="Compile" name="java/io/File.cs" />
<File subtype="Code" buildaction="Compile" name="java/io/FileInputStream.cs" />
<File subtype="Code" buildaction="Compile" name="java/io/FileOutputStream.cs" />
<File subtype="Code" buildaction="Compile" name="java/io/InputStream.cs" />
<File subtype="Code" buildaction="Compile" name="java/io/InputStreamWrapper.cs" />
<File subtype="Code" buildaction="Compile" name="java/io/JStream.cs" />
<File subtype="Code" buildaction="Compile" name="java/io/OutputStream.cs" />
<File subtype="Code" buildaction="Compile" name="java/lang/Class.cs" />
<File subtype="Code" buildaction="Compile" name="java/lang/Integer.cs" />
<File subtype="Code" buildaction="Compile" name="java/lang/Runnable.cs" />
<File subtype="Code" buildaction="Compile" name="java/lang/StringBuffer.cs" />
<File subtype="Code" buildaction="Compile" name="java/lang/Thread.cs" />
<File subtype="Code" buildaction="Compile" name="java/net/InetAddress.cs" />
<File subtype="Code" buildaction="Compile" name="java/net/ServerSocket.cs" />
<File subtype="Code" buildaction="Compile" name="java/net/Socket.cs" />
<File subtype="Code" buildaction="Compile" name="java/util/Arrays.cs" />
<File subtype="Code" buildaction="Compile" name="java/util/Enumeration.cs" />
<File subtype="Code" buildaction="Compile" name="java/util/Hashtable.cs" />
<File subtype="Code" buildaction="Compile" name="java/util/JavaString.cs" />
<File subtype="Code" buildaction="Compile" name="java/util/Vector.cs" />
<File subtype="Code" buildaction="Compile" name="jsch/Buffer.cs" />
<File subtype="Code" buildaction="Compile" name="jsch/Channel.cs" />
<File subtype="Code" buildaction="Compile" name="jsch/Channel.old.cs" />
<File subtype="Code" buildaction="Compile" name="jsch/ChannelDirectTCPIP.cs" />
<File subtype="Code" buildaction="Compile" name="jsch/ChannelExec.cs" />
<File subtype="Code" buildaction="Compile" name="jsch/ChannelForwardedTCPIP.cs" />
<File subtype="Code" buildaction="Compile" name="jsch/ChannelSession.cs" />
<File subtype="Code" buildaction="Compile" name="jsch/ChannelSftp.cs" />
<File subtype="Code" buildaction="Compile" name="jsch/ChannelSftpStreamGet.cs" />
<File subtype="Code" buildaction="Compile" name="jsch/ChannelSftpStreamPut.cs" />
<File subtype="Code" buildaction="Compile" name="jsch/ChannelShell.cs" />
<File subtype="Code" buildaction="Compile" name="jsch/ChannelSubsystem.cs" />
<File subtype="Code" buildaction="Compile" name="jsch/ChannelX11.cs" />
<File subtype="Code" buildaction="Compile" name="jsch/Cipher.cs" />
<File subtype="Code" buildaction="Compile" name="jsch/Compression.cs" />
<File subtype="Code" buildaction="Compile" name="jsch/DH.cs" />
<File subtype="Code" buildaction="Compile" name="jsch/DHG1.cs" />
<File subtype="Code" buildaction="Compile" name="jsch/DHGEX.cs" />
<File subtype="Code" buildaction="Compile" name="jsch/ForwardedTCPIPDaemon.cs" />
<File subtype="Code" buildaction="Compile" name="jsch/HASH.cs" />
<File subtype="Code" buildaction="Compile" name="jsch/HostKey.cs" />
<File subtype="Code" buildaction="Compile" name="jsch/HostKeyRepository.cs" />
<File subtype="Code" buildaction="Compile" name="jsch/Identity.cs" />
<File subtype="Code" buildaction="Compile" name="jsch/IdentityFile.cs" />
<File subtype="Code" buildaction="Compile" name="jsch/IO.cs" />
<File subtype="Code" buildaction="Compile" name="jsch/JSch.cs" />
<File subtype="Code" buildaction="Compile" name="jsch/JSchAuthCancelException.cs" />
<File subtype="Code" buildaction="Compile" name="jsch/JSchException.cs" />
<File subtype="Code" buildaction="Compile" name="jsch/JSchPartialAuthException.cs" />
<File subtype="Code" buildaction="Compile" name="jsch/KeyExchange.cs" />
<File subtype="Code" buildaction="Compile" name="jsch/KeyPair.cs" />
<File subtype="Code" buildaction="Compile" name="jsch/KeyPairDSA.cs" />
<File subtype="Code" buildaction="Compile" name="jsch/KeyPairGenDSA.cs" />
<File subtype="Code" buildaction="Compile" name="jsch/KeyPairGenRSA.cs" />
<File subtype="Code" buildaction="Compile" name="jsch/KeyPairRSA.cs" />
<File subtype="Code" buildaction="Compile" name="jsch/KnownHosts.cs" />
<File subtype="Code" buildaction="Compile" name="jsch/MAC.cs" />
<File subtype="Code" buildaction="Compile" name="jsch/Packet.cs" />
<File subtype="Code" buildaction="Compile" name="jsch/PortWatcher.cs" />
<File subtype="Code" buildaction="Compile" name="jsch/Proxy.cs" />
<File subtype="Code" buildaction="Compile" name="jsch/ProxyHTTP.cs" />
<File subtype="Code" buildaction="Compile" name="jsch/Random.cs" />
<File subtype="Code" buildaction="Compile" name="jsch/Request.cs" />
<File subtype="Code" buildaction="Compile" name="jsch/RequestExec.cs" />
<File subtype="Code" buildaction="Compile" name="jsch/RequestPtyReq.cs" />
<File subtype="Code" buildaction="Compile" name="jsch/RequestSftp.cs" />
<File subtype="Code" buildaction="Compile" name="jsch/RequestShell.cs" />
<File subtype="Code" buildaction="Compile" name="jsch/RequestSignal.cs" />
<File subtype="Code" buildaction="Compile" name="jsch/RequestSubsystem.cs" />
<File subtype="Code" buildaction="Compile" name="jsch/RequestWindowChange.cs" />
<File subtype="Code" buildaction="Compile" name="jsch/RequestX11.cs" />
<File subtype="Code" buildaction="Compile" name="jsch/ServerSocketFactory.cs" />
<File subtype="Code" buildaction="Compile" name="jsch/Session.cs" />
<File subtype="Code" buildaction="Compile" name="jsch/SftpATTRS.cs" />
<File subtype="Code" buildaction="Compile" name="jsch/SftpException.cs" />
<File subtype="Code" buildaction="Compile" name="jsch/SftpProgressMonitor.cs" />
<File subtype="Code" buildaction="Compile" name="jsch/SignatureDSA.cs" />
<File subtype="Code" buildaction="Compile" name="jsch/SignatureRSA.cs" />
<File subtype="Code" buildaction="Compile" name="jsch/SocketFactory.cs" />
<File subtype="Code" buildaction="Compile" name="jsch/UIKeyboardInteractive.cs" />
<File subtype="Code" buildaction="Compile" name="jsch/UserAuth.cs" />
<File subtype="Code" buildaction="Compile" name="jsch/UserAuthKeyboardInteractive.cs" />
<File subtype="Code" buildaction="Compile" name="jsch/UserAuthNone.cs" />
<File subtype="Code" buildaction="Compile" name="jsch/UserAuthPassword.cs" />
<File subtype="Code" buildaction="Compile" name="jsch/UserAuthPublicKey.cs" />
<File subtype="Code" buildaction="Compile" name="jsch/UserInfo.cs" />
<File subtype="Code" buildaction="Compile" name="jsch/Util.cs" />
<File subtype="Code" buildaction="Compile" name="jsch/examples/AES.cs" />
<File subtype="Code" buildaction="Compile" name="jsch/examples/ChangePassphrase.cs" />
<File subtype="Code" buildaction="Compile" name="jsch/examples/KeyGen.cs" />
<File subtype="Code" buildaction="Compile" name="jsch/examples/KnownHosts.cs" />
<File subtype="Code" buildaction="Compile" name="jsch/examples/PortForwardingL.cs" />
<File subtype="Code" buildaction="Compile" name="jsch/examples/PortForwardingR.cs" />
<File subtype="Code" buildaction="Exclude" name="jsch/examples/README.txt" />
<File subtype="Code" buildaction="Compile" name="jsch/examples/ScpFrom.cs" />
<File subtype="Code" buildaction="Compile" name="jsch/examples/ScpTo.cs" />
<File subtype="Code" buildaction="Compile" name="jsch/examples/Sftp.cs" />
<File subtype="Code" buildaction="Compile" name="jsch/examples/Shell.cs" />
<File subtype="Code" buildaction="Compile" name="jsch/examples/StreamForwarding.cs" />
<File subtype="Code" buildaction="Compile" name="jsch/examples/UserAuthPubKey.cs" />
<File subtype="Code" buildaction="Compile" name="jsch/examples/util/ConsoleProgressBar.cs" />
<File subtype="Code" buildaction="Compile" name="jsch/examples/util/InputForm.cs" />
<File subtype="Code" buildaction="EmbedAsResource" name="jsch/examples/util/InputForm.resx" dependson="/home/hbons/github/SparkleShare/SharpSSH/jsch/examples/util/InputForm.cs" resource_id="Tamir.SharpSsh.jsch.examples.util.InputForm.resources" />
<File subtype="Code" buildaction="Compile" name="jsch/jce/AES128CBC.cs" />
<File subtype="Code" buildaction="Compile" name="jsch/jce/BlowfishCBC.cs" />
<File subtype="Code" buildaction="Compile" name="jsch/jce/DH.cs" />
<File subtype="Code" buildaction="Compile" name="jsch/jce/HMACMD5.cs" />
<File subtype="Code" buildaction="Compile" name="jsch/jce/HMACMD596.cs" />
<File subtype="Code" buildaction="Compile" name="jsch/jce/HMACSHA1.cs" />
<File subtype="Code" buildaction="Compile" name="jsch/jce/HMACSHA196.cs" />
<File subtype="Code" buildaction="Compile" name="jsch/jce/KeyPairGenDSA.cs" />
<File subtype="Code" buildaction="Compile" name="jsch/jce/KeyPairGenRSA.cs" />
<File subtype="Code" buildaction="Compile" name="jsch/jce/MD5.cs" />
<File subtype="Code" buildaction="Compile" name="jsch/jce/Random.cs" />
<File subtype="Code" buildaction="Compile" name="jsch/jce/SHA1.cs" />
<File subtype="Code" buildaction="Compile" name="jsch/jce/SignatureDSA.cs" />
<File subtype="Code" buildaction="Compile" name="jsch/jce/SignatureRSA.cs" />
<File subtype="Code" buildaction="Compile" name="jsch/jce/TripleDESCBC.cs" />
<File subtype="Code" buildaction="Compile" name="Streams/CombinedStream.cs" />
<File subtype="Code" buildaction="Compile" name="Streams/InputStream.cs" />
<File subtype="Code" buildaction="Compile" name="Streams/OutputStream.cs" />
<File subtype="Code" buildaction="Compile" name="Streams/PipedInputStream.cs" />
<File subtype="Code" buildaction="Compile" name="Streams/PipedOutputStream.cs" />
<File subtype="Code" buildaction="Compile" name="Streams/ProtectedConsoleStream.cs" />
</Contents>
<References>
<ProjectReference type="Gac" localcopy="True" refto="System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<ProjectReference type="Gac" localcopy="True" refto="System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<ProjectReference type="Gac" localcopy="True" refto="System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<ProjectReference type="Gac" localcopy="True" refto="System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<ProjectReference type="Gac" localcopy="True" refto="System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<ProjectReference type="Assembly" localcopy="True" specificVersion="False" refto="lib/DiffieHellman.dll" />
<ProjectReference type="Assembly" localcopy="True" specificVersion="False" refto="lib/Org.Mentalis.Security.dll" />
</References>
</Project>

View file

@ -1,335 +0,0 @@
using System;
using System.Collections;
using Tamir.SharpSsh.jsch;
/*
* SshBase.cs
*
* Copyright (c) 2006 Tamir Gal, http://www.tamirgal.com, All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the distribution.
*
* 3. The names of the authors may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR
* *OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
**/
namespace Tamir.SharpSsh
{
/// <summary>
/// A wrapper class for JSch's SSH channel
/// </summary>
public abstract class SshBase
{
protected string m_host;
protected string m_user;
protected string m_pass;
protected JSch m_jsch;
protected Session m_session;
protected Channel m_channel;
/// <summary>
/// Default TCP port of SSH protocol
/// </summary>
private static int SSH_TCP_PORT = 22;
/// <summary>
/// Constructs a new SSH instance
/// </summary>
/// <param name="sftpHost">The remote SSH host</param>
/// <param name="user">The login username</param>
/// <param name="password">The login password</param>
public SshBase(string sftpHost, string user, string password)
{
this.m_host = sftpHost;
this.m_user = user;
this.Password = password;
m_jsch = new JSch();
}
/// <summary>
/// Constructs a new SSH instance
/// </summary>
/// <param name="sftpHost">The remote SSH host</param>
/// <param name="user">The login username</param>
public SshBase(string sftpHost, string user)
: this(sftpHost, user, null)
{
}
/// <summary>
/// Adds identity file for publickey user authentication
/// </summary>
/// <param name="privateKeyFile">The path to the private key file</param>
public virtual void AddIdentityFile(string privateKeyFile)
{
m_jsch.addIdentity(privateKeyFile);
}
/// <summary>
/// Adds identity file for publickey user authentication
/// </summary>
/// <param name="privateKeyFile">The path to the private key file</param>
/// <param name="passphrase">A passphrase for decrypting the private key file</param>
public virtual void AddIdentityFile(string privateKeyFile, string passphrase)
{
m_jsch.addIdentity(privateKeyFile, passphrase);
}
protected abstract string ChannelType{get;}
/// <summary>
/// Connect to remote SSH server
/// </summary>
public virtual void Connect()
{
this.Connect(SSH_TCP_PORT);
}
/// <summary>
/// Connect to remote SSH server
/// </summary>
/// <param name="tcpPort">The destination TCP port for this connection</param>
public virtual void Connect(int tcpPort)
{
this.ConnectSession(tcpPort);
this.ConnectChannel();
}
protected virtual void ConnectSession(int tcpPort)
{
m_session = m_jsch.getSession(m_user, m_host, tcpPort);
if (Password != null)
m_session.setUserInfo(new KeyboardInteractiveUserInfo(Password));
Hashtable config = new Hashtable();
config.Add("StrictHostKeyChecking", "no");
m_session.setConfig(config);
m_session.connect();
}
protected virtual void ConnectChannel()
{
m_channel = m_session.openChannel(ChannelType);
this.OnChannelReceived();
m_channel.connect();
this.OnConnected();
}
protected virtual void OnConnected()
{
}
protected virtual void OnChannelReceived()
{
}
/// <summary>
/// Closes the SSH subsystem
/// </summary>
public virtual void Close()
{
if (m_channel != null)
{
m_channel.disconnect();
m_channel = null;
}
if (m_session != null)
{
m_session.disconnect();
m_session = null;
}
}
/// <summary>
/// Return true if the SSH subsystem is connected
/// </summary>
public virtual bool Connected
{
get
{
if (m_session != null)
return m_session.isConnected();
return false;
}
}
/// <summary>
/// Gets the Cipher algorithm name used in this SSH connection.
/// </summary>
public string Cipher
{
get
{
CheckConnected();
return m_session.getCipher();
}
}
/// <summary>
/// Gets the MAC algorithm name used in this SSH connection.
/// </summary>
public string Mac
{
get
{
CheckConnected();
return m_session.getMac();
}
}
/// <summary>
/// Gets the server SSH version string.
/// </summary>
public string ServerVersion
{
get
{
CheckConnected();
return m_session.getServerVersion();
}
}
/// <summary>
/// Gets the client SSH version string.
/// </summary>
public string ClientVersion
{
get
{
CheckConnected();
return m_session.getClientVersion();
}
}
public string Host
{
get
{
CheckConnected();
return m_session.getHost();
}
}
public HostKey HostKey
{
get
{
CheckConnected();
return m_session.getHostKey();
}
}
public int Port
{
get
{
CheckConnected();
return m_session.getPort();
}
}
/// <summary>
/// The password string of the SSH subsystem
/// </summary>
public string Password
{
get { return m_pass; }
set { m_pass = value; }
}
public string Username
{
get { return m_user; }
}
public static Version Version
{
get
{
System.Reflection.Assembly asm
= System.Reflection.Assembly.GetAssembly(typeof(Tamir.SharpSsh.SshBase));
return asm.GetName().Version;
}
}
private void CheckConnected()
{
if(!Connected)
{
throw new Exception("SSH session is not connected.");
}
}
/// <summary>
/// For password and KI auth modes
/// </summary>
protected class KeyboardInteractiveUserInfo : UserInfo, UIKeyboardInteractive
{
string _password;
public KeyboardInteractiveUserInfo(string password)
{
_password = password;
}
#region UIKeyboardInteractive Members
public string[] promptKeyboardInteractive(string destination, string name, string instruction, string[] prompt, bool[] echo)
{
return new string[] { _password };
}
#endregion
#region UserInfo Members
public bool promptYesNo(string message)
{
return true;
}
public bool promptPassword(string message)
{
return true;
}
public string getPassword()
{
return _password;
}
public bool promptPassphrase(string message)
{
return true;
}
public string getPassphrase()
{
return null;
}
public void showMessage(string message)
{
}
#endregion
}
}
}

View file

@ -1,121 +0,0 @@
using System;
using Tamir.SharpSsh.jsch;
using System.Text;
/*
* SshExe.cs
*
* Copyright (c) 2006 Tamir Gal, http://www.tamirgal.com, All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the distribution.
*
* 3. The names of the authors may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR
* *OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
**/
namespace Tamir.SharpSsh
{
/// <summary>
/// Summary description for SshExe.
/// </summary>
public class SshExec : SshBase
{
public SshExec(string host, string user, string password)
: base(host, user, password)
{
}
public SshExec(string host, string user)
: base(host, user)
{
}
protected override string ChannelType
{
get { return "exec"; }
}
/// <summary>
///This function is empty, so no channel is connected
///on session connect
/// </summary>
protected override void ConnectChannel()
{
}
protected ChannelExec GetChannelExec(string command)
{
ChannelExec exeChannel = (ChannelExec)m_session.openChannel("exec");
exeChannel.setCommand(command);
return exeChannel;
}
public string RunCommand(string command)
{
m_channel = GetChannelExec(command);
System.IO.Stream s = m_channel.getInputStream();
m_channel.connect();
byte[] buff = new byte[1024];
StringBuilder res = new StringBuilder();
int c = 0;
while(true)
{
c = s.Read(buff, 0, buff.Length);
if(c==-1) break;
res.Append( Encoding.ASCII.GetString(buff, 0, c) );
//Console.WriteLine(res);
}
m_channel.disconnect();
return res.ToString();
}
public int RunCommand(string command, ref string StdOut, ref string StdErr)
{
StdOut = "";
StdErr = "";
m_channel = GetChannelExec(command);
System.IO.Stream stdout = m_channel.getInputStream();
System.IO.Stream stderr = ((ChannelExec)m_channel).getErrStream();
m_channel.connect();
byte[] buff = new byte[1024];
StringBuilder sbStdOut = new StringBuilder();
StringBuilder sbStdErr = new StringBuilder();
int o=0; int e=0;
while(true)
{
if(o!=-1) o = stdout.Read(buff, 0, buff.Length);
if(o!=-1) StdOut += sbStdOut.Append(Encoding.ASCII.GetString(buff, 0, o));
if(e!=-1) e = stderr.Read(buff, 0, buff.Length);
if(e!=-1) StdErr += sbStdErr.Append(Encoding.ASCII.GetString(buff, 0, e));
if((o==-1)&&(e==-1)) break;
}
m_channel.disconnect();
return m_channel.getExitStatus();
}
public ChannelExec ChannelExec
{
get{return (ChannelExec)this.m_channel;}
}
}
}

View file

@ -1,220 +0,0 @@
using System.IO;
using System.Collections;
using Tamir.SharpSsh.jsch;
using Tamir.Streams;
using System.Text;
namespace Tamir
{
public class SshHelper
{
private StreamReader reader;
private PipedOutputStream writer_po;
private Session session;
private ChannelShell channel;
private string host;
public SshHelper(string host, string username, string password)
{
this.host = host;
JSch jsch=new JSch();
Session session=jsch.getSession(username, host, 22);
session.setPassword( password );
Hashtable config=new Hashtable();
config.Add("StrictHostKeyChecking", "no");
session.setConfig(config);
session.connect();
channel=(ChannelShell)session.openChannel("shell");
writer_po = new PipedOutputStream();
PipedInputStream writer_pi = new PipedInputStream( writer_po );
PipedInputStream reader_pi = new PipedInputStream();
PipedOutputStream reader_po = new PipedOutputStream( reader_pi );
reader = new StreamReader (reader_pi,Encoding.UTF8);
channel.setInputStream( writer_pi );
channel.setOutputStream( reader_po );
channel.connect();
channel.setPtySize(132, 132, 1024, 768);
}
public void Write(string data)
{
data += "\n";
writer_po.write( Util.getBytes(data ));
}
public string WriteAndRead(string data)
{
Write( data );
return ReadResponse();
}
public void SendCtrlC()
{
byte ASCII_CTRL_C = 3;
byte[] ctrlc = { ASCII_CTRL_C };
writer_po.write( ctrlc );
}
public void SendCtrlZ()
{
byte ASCII_CTRL_Z = 26;
byte[] ctrlz = { ASCII_CTRL_Z };
writer_po.write( ctrlz );
}
public string ReadResponse()
{
// return ReadLine();
return ReadTest();
}
public string ReadBuffer(int size)
{
string res = "";
int buff;
try
{
buff = reader.Read();
while( ((char)buff != '#') && (size != 0) )
{
res += (char)buff;
size--;
if (res.EndsWith("More--"))
writer_po.write(Util.getBytes( " ") );
buff = reader.Read();
}
if(buff != '\n')
res += (char)buff;
}
catch//(Exception exc)
{
}
res = RemoveJunk( res );
return res;
}
public void Close()
{
channel.disconnect();
writer_po.close();
reader.Close();
}
// private string ReadLine()
// {
// string res = "";
// int buff;
// try
// {
// buff = reader.ReadByte();
// while((char)buff != '#')
// {
// res += (char)buff;
// if (res.EndsWith("More--"))
// writer_po.write( Util.getBytes(" ") );
// buff = reader.ReadByte();
// }
// if(buff != '\n')
// res += (char)buff;
// }
// catch//Exception exc)
// {
// }
// res = RemoveJunk( res );
// return res;
// }
private string ReadTest()
{
StringBuilder res = new StringBuilder();
char[] buff = new char[1024];
int count = 0;
try
{
count = reader.Read(buff, 0, buff.Length);
//ArrayList lstBuff = new ArrayList(java.util.Arrays.asList(buff));
while(!Util.ArrayContains(buff, '#', count))
{
// while(buff[count-2]!='#' ){
res.Append( buff, 0, count );
if ( (res.ToString().EndsWith("More--"))||(res.ToString().EndsWith("More--")))
writer_po.write( Util.getBytes( " ") );
count = reader.Read(buff, 0, buff.Length);
count++;
count--;
//lstBuff = new ArrayList(java.util.Arrays.asList(buff));
}
if(buff[count-1] != '\n')
res.Append( buff, 0, count );
else
res.Append( buff, 0, count-1 );
}
catch//(Exception exc)
{
}
return RemoveJunk( res ).ToString();
}
private static string RemoveJunk(string str)
{
string[] junk = new string[]{"", "", "", "", "", " \b", "--More--", "\r", "\n "};
for( int i=0; i<junk.Length; i++ )
{
string match = junk[i];
if (match=="\n ")
str = Replace(str, match, " ");
else
str = Replace(str, match, "");
}
return str;
}
private static StringBuilder RemoveJunk(StringBuilder str)
{
string[] junk = new string[]{"", "", "", "", "", " \b", "--More--", "\n "};
for( int i=0; i<junk.Length; i++ )
{
string match = junk[i];
if (match=="\n ")
str = Replace(str, match, " ");
else
str = Replace(str, match, "");
}
return str;
}
private static string Replace(string str, string toReplace, string replcaeWith)
{
int index = (str.IndexOf( toReplace ));
while (index != -1)
{
string pre = str.Substring(0, index);
string post = str.Substring(index+toReplace.Length, str.Length-index-toReplace.Length);
str = pre + replcaeWith + post;
index = (str.IndexOf( toReplace ));
}
return str;
}
private static StringBuilder Replace(StringBuilder str, string toReplace, string replcaeWith)
{
return str.Replace(toReplace, replcaeWith);
}
}
}

View file

@ -1,256 +0,0 @@
using System;
using System.IO;
using Tamir.SharpSsh.jsch;
using Tamir.Streams;
using System.Text;
using System.Text.RegularExpressions;
/*
* SshShell.cs
*
* Copyright (c) 2006 Tamir Gal, http://www.tamirgal.com, All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the distribution.
*
* 3. The names of the authors may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR
* *OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
**/
namespace Tamir.SharpSsh
{
/// <summary>
/// Summary description for SshShell.
/// </summary>
public class SshShell : SshBase
{
private Stream m_sshIO = null;
private Regex m_expectPattern;
private bool m_removeTerminalChars = false;
private bool m_redirectToConsole = false;
private static string escapeCharsPattern = "\\[[0-9;?]*[^0-9;]";
public SshShell(string host, string user, string password)
: base(host, user, password)
{
Init();
}
public SshShell(string host, string user)
: base(host, user)
{
Init();
}
protected void Init()
{
ExpectPattern = "";
m_removeTerminalChars = false;
}
protected override void OnChannelReceived()
{
base.OnChannelReceived ();
if(m_redirectToConsole)
{
SetStream(Console.OpenStandardInput(), Console.OpenStandardOutput());
}
else
{
m_sshIO = GetStream();
}
}
protected override string ChannelType
{
get { return "shell"; }
}
public Stream IO
{
get
{
// if(m_sshIO == null)
// {
// m_sshIO = GetStream();
// }
return m_sshIO;
}
}
public void WriteLine(string data)
{
Write( data+"\r" );
}
public void Write(string data)
{
Write( Encoding.Default.GetBytes( data ) );
}
/// <summary>
/// Writes a sequence of bytes to the current stream and advances the current position within this stream by the number of bytes written.
/// </summary>
/// <param name="buffer">An array of bytes. This method copies count bytes from buffer to the current stream. </param>
public virtual void Write(byte[] buffer)
{
Write(buffer, 0, buffer.Length);
}
/// <summary>
/// Writes a sequence of bytes to the current stream and advances the current position within this stream by the number of bytes written.
/// </summary>
/// <param name="buffer">An array of bytes. This method copies count bytes from buffer to the current stream. </param>
/// <param name="offset">The zero-based byte offset in buffer at which to begin copying bytes to the current stream.</param>
/// <param name="count">The number of bytes to be written to the current stream. </param>
public virtual void Write(byte[] buffer, int offset, int count)
{
IO.Write(buffer, offset, count);
IO.Flush();
}
/// <summary>
/// Creates a new I/O stream of communication with this SSH shell connection
/// </summary>
public Stream GetStream()
{
return new CombinedStream(m_channel.getInputStream(), m_channel.getOutputStream());;
}
public void SetStream(Stream inputStream, Stream outputStream)
{
m_channel.setInputStream(inputStream);
m_channel.setOutputStream(outputStream);
}
public void SetStream(Stream s)
{
SetStream(s, s);
}
public void RedirectToConsole()
{
m_redirectToConsole = true;
}
public virtual bool ShellOpened
{
get
{
if(m_channel != null)
{
return !m_channel.isClosed();
}
return false;
}
}
public virtual bool ShellConnected
{
get
{
if(m_channel != null)
{
return m_channel.isConnected();
}
return false;
}
}
/// <summary>
/// Gets or sets a value indicating wether this Steam sould remove the terminal emulation's escape sequence characters from the response String.
/// </summary>
public bool RemoveTerminalEmulationCharacters
{
get{return m_removeTerminalChars;}
set{m_removeTerminalChars=value;}
}
/// <summary>
/// A regular expression pattern string to match when reading the resonse using the ReadResponse() method. The default prompt value is "\n" which makes the ReadRespons() method return one line of response.
/// </summary>
public string ExpectPattern
{
get{return m_expectPattern.ToString();}
set{m_expectPattern = new Regex(value, RegexOptions.Singleline);}
}
/// <summary>
/// Reads a response string from the SSH channel. This method will block until the pattern in the 'Prompt' property is matched in the response.
/// </summary>
/// <returns>A response string from the SSH server.</returns>
public string Expect()
{
return Expect(m_expectPattern);
}
/// <summary>
/// Reads a response string from the SSH channel. This method will block until the pattern in the 'Prompt' property is matched in the response.
/// </summary>
/// <returns>A response string from the SSH server.</returns>
public string Expect(string pattern)
{
return Expect( new Regex( pattern, RegexOptions.Singleline ));
}
/// <summary>
/// Reads a response string from the SSH channel. This method will block until the pattern in the 'Prompt' property is matched in the response.
/// </summary>
/// <returns>A response string from the SSH server.</returns>
public string Expect(Regex pattern)
{
int readCount;
StringBuilder resp = new StringBuilder();
byte[] buff = new byte[1024];
Match match;
do
{
readCount = IO.Read(buff, 0, buff.Length);
if(readCount == -1) break;
string tmp = System.Text.Encoding.Default.GetString(buff, 0, readCount);
resp.Append( tmp, 0, readCount);
string s = resp.ToString();
match = pattern.Match( s );
}while(!match.Success);
string result = resp.ToString();
if(RemoveTerminalEmulationCharacters)
result = HandleTerminalChars(result);
return result;
}
/// <summary>
/// Removes escape sequence characters from the input string.
/// </summary>
public static string HandleTerminalChars(string str)
{
str = str.Replace("(B)0", "");
str = Regex.Replace(str, escapeCharsPattern, "");
str = str.Replace(((char)15).ToString(), "");
str = Regex.Replace(str, ((char)27)+"=*", "");
//str = Regex.Replace(str, "\\s*\r\n", "\r\n");
return str;
}
}
}

View file

@ -1,325 +0,0 @@
using System;
using System.IO;
using System.Collections;
using Tamir.SharpSsh.jsch;
using Tamir.Streams;
using System.Text;
using System.Text.RegularExpressions;
/*
* SshStream.cs
*
* THIS SOURCE CODE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
* KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR
* PURPOSE.
*
* Copyright (C) 2005 Tamir Gal, tamirgal@myrealbox.com.
*/
namespace Tamir.SharpSsh
{
/// <summary>
/// A Stream based SSH class
/// </summary>
public class SshStream : Stream
{
private Stream m_in;
private Stream m_out;
private ChannelShell m_channel;
private string m_host;
private Regex m_prompt;
private string m_escapeCharPattern;
private bool m_removeTerminalChars = false;
private Session m_session;
/// <summary>
/// Constructs a new SSH stream.
/// </summary>
/// <param name="host">The hostname or IP address of the remote SSH machine</param>
/// <param name="username">The name of the user connecting to the remote machine</param>
/// <param name="password">The password of the user connecting to the remote machine</param>
public SshStream(string host, string username, string password)
{
this.m_host = host;
JSch jsch=new JSch();
m_session=jsch.getSession(username, host, 22);
m_session.setPassword( password );
Hashtable config=new Hashtable();
config.Add("StrictHostKeyChecking", "no");
m_session.setConfig(config);
m_session.connect();
m_channel=(ChannelShell)m_session.openChannel("shell");
m_in = m_channel.getInputStream();
m_out = m_channel.getOutputStream();
m_channel.connect();
m_channel.setPtySize(80, 132, 1024, 768);
Prompt = "\n";
m_escapeCharPattern = "\\[[0-9;?]*[^0-9;]";
}
/// <summary>
/// Reads a sequence of bytes from the current stream and advances the position within the stream by the number of bytes read.
/// </summary>
/// <param name="buffer">An array of bytes. When this method returns, the buffer contains the specified byte array with the values between offset and (offset + count- 1) replaced by the bytes read from the current source.</param>
/// <param name="offset">The zero-based byte offset in buffer at which to begin storing the data read from the current stream. </param>
/// <param name="count">The maximum number of bytes to be read from the current stream. </param>
/// <returns>The total number of bytes read into the buffer. This can be less than the number of bytes requested if that many bytes are not currently available, or zero (0) if the end of the stream has been reached.</returns>
public override int Read(byte[] buffer, int offset, int count)
{
return m_in.Read(buffer, offset, count);
}
/// <summary>
/// Reads a sequence of bytes from the current stream and advances the position within the stream by the number of bytes read.
/// </summary>
/// <param name="buffer">An array of bytes. When this method returns, the buffer contains the specified byte array with the values between offset and (offset + count- 1) replaced by the bytes read from the current source.</param>
/// <returns>The total number of bytes read into the buffer. This can be less than the number of bytes requested if that many bytes are not currently available, or zero (0) if the end of the stream has been reached.</returns>
public virtual int Read(byte[] buffer)
{
return Read(buffer, 0, buffer.Length);
}
/// <summary>
/// Reads a byte from the stream and advances the position within the stream by one byte, or returns -1 if at the end of the stream.
/// </summary>
/// <returns>The unsigned byte cast to an Int32, or -1 if at the end of the stream.</returns>
public override int ReadByte()
{
return m_in.ReadByte();
}
/// <summary>
/// Writes a byte to the current position in the stream and advances the position within the stream by one byte.
/// </summary>
/// <param name="value">The byte to write to the stream. </param>
public override void WriteByte(byte value)
{
m_out.WriteByte(value);
}
/// <summary>
/// Writes a sequence of bytes to the current stream and advances the current position within this stream by the number of bytes written.
/// </summary>
/// <param name="buffer">An array of bytes. This method copies count bytes from buffer to the current stream. </param>
/// <param name="offset">The zero-based byte offset in buffer at which to begin copying bytes to the current stream.</param>
/// <param name="count">The number of bytes to be written to the current stream. </param>
public override void Write(byte[] buffer, int offset, int count)
{
m_out.Write(buffer, offset, count);
}
/// <summary>
/// Writes a sequence of bytes to the current stream and advances the current position within this stream by the number of bytes written.
/// </summary>
/// <param name="buffer">An array of bytes. This method copies count bytes from buffer to the current stream. </param>
public virtual void Write(byte[] buffer)
{
Write(buffer, 0, buffer.Length);
}
/// <summary>
/// Writes a String into the SSH channel. This method appends an 'end of line' character to the input string.
/// </summary>
/// <param name="data">The String to write to the SSH channel.</param>
public void Write(String data)
{
data += "\r";
Write( Encoding.Default.GetBytes( data ) );
Flush();
}
/// <summary>
/// Closes the current stream and releases any resources (such as sockets and file handles) associated with the current stream.
/// </summary>
public override void Close()
{
try
{
base.Close ();
m_in.Close();
m_out.Close();
m_channel.close();
m_channel.disconnect();
m_session.disconnect();
}
catch{}
}
/// <summary>
/// Gets a value indicating whether the current stream supports reading.
/// </summary>
public override bool CanRead
{
get
{
return m_in.CanRead;
}
}
/// <summary>
/// Gets a value indicating whether the current stream supports writing.
/// </summary>
public override bool CanWrite
{
get
{
return m_out.CanWrite;
}
}
/// <summary>
/// Gets a value indicating whether the current stream supports seeking. This stream cannot seek, and will always return false.
/// </summary>
public override bool CanSeek
{
get
{
return false;
}
}
/// <summary>
/// Clears all buffers for this stream and causes any buffered data to be written to the underlying device.
/// </summary>
public override void Flush()
{
m_out.Flush();
}
/// <summary>
/// Gets the length in bytes of the stream.
/// </summary>
public override long Length
{
get
{
return 0;
}
}
/// <summary>
/// Gets or sets the position within the current stream. This Stream cannot seek. This property has no effect on the Stream and will always return 0.
/// </summary>
public override long Position
{
get
{
return 0;
}
set
{
}
}
/// <summary>
/// This method has no effect on the Stream.
/// </summary>
public override void SetLength(long value)
{
}
/// <summary>
/// This method has no effect on the Stream.
/// </summary>
public override long Seek(long offset, SeekOrigin origin)
{
return 0;
}
/// <summary>
/// A regular expression pattern string to match when reading the resonse using the ReadResponse() method. The default prompt value is "\n" which makes the ReadRespons() method return one line of response.
/// </summary>
public string Prompt
{
get{return m_prompt.ToString();}
set{m_prompt = new Regex(value, RegexOptions.Singleline);}
}
/// <summary>
/// Gets or sets a value indicating wether this Steam sould remove the terminal emulation's escape sequence characters from the response String.
/// </summary>
public bool RemoveTerminalEmulationCharacters
{
get{return m_removeTerminalChars;}
set{m_removeTerminalChars=value;}
}
/// <summary>
/// Gets the Cipher algorithm name used in this SSH connection.
/// </summary>
public string Cipher
{
get{return m_session.getCipher();}
}
/// <summary>
/// Gets the MAC algorithm name used in this SSH connection.
/// </summary>
public string Mac
{
get{return m_session.getMac();}
}
/// <summary>
/// Gets the server SSH version string.
/// </summary>
public string ServerVersion
{
get{return m_session.getServerVersion();}
}
/// <summary>
/// Gets the client SSH version string.
/// </summary>
public string ClientVersion
{
get{return m_session.getClientVersion();}
}
/// <summary>
/// Reads a response string from the SSH channel. This method will block until the pattern in the 'Prompt' property is matched in the response.
/// </summary>
/// <returns>A response string from the SSH server.</returns>
public string ReadResponse()
{
int readCount;
StringBuilder resp = new StringBuilder();
byte[] buff = new byte[1024];
Match match;
do
{
readCount = this.Read(buff);
resp.Append( System.Text.Encoding.Default.GetString( buff), 0, readCount);
string s = resp.ToString();
match = m_prompt.Match( s );
}while(!match.Success);
return HandleTerminalChars( resp.ToString() );
}
/// <summary>
/// Removes escape sequence characters from the input string.
/// </summary>
/// <param name="str"></param>
/// <returns></returns>
private string HandleTerminalChars(string str)
{
if(RemoveTerminalEmulationCharacters)
{
str = str.Replace("(B)0", "");
str = Regex.Replace(str, m_escapeCharPattern, "");
str = str.Replace(((char)15).ToString(), "");
str = Regex.Replace(str, ((char)27).ToString()+"=*", "");
//str = Regex.Replace(str, "\\s*\r\n", "\r\n");
}
return str;
}
}
}

View file

@ -1,44 +0,0 @@
using System;
/*
* SshTransferException.cs
*
* Copyright (c) 2006 Tamir Gal, http://www.tamirgal.com, All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the distribution.
*
* 3. The names of the authors may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR
* *OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
**/
namespace Tamir.SharpSsh
{
/// <summary>
/// Summary description for SshTransferException.
/// </summary>
public class SshTransferException : Exception
{
public SshTransferException(string msg):base(msg)
{
}
}
}

View file

@ -1,114 +0,0 @@
using System;
/*
* SshTransferProtocolBase.cs
*
* Copyright (c) 2006 Tamir Gal, http://www.tamirgal.com, All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the distribution.
*
* 3. The names of the authors may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR
* *OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
**/
namespace Tamir.SharpSsh
{
/// <summary>
/// Summary description for SshTransferProtocolBase.
/// </summary>
public abstract class SshTransferProtocolBase : SshBase, ITransferProtocol
{
public SshTransferProtocolBase(string host, string user, string password)
: base(host, user, password)
{
}
public SshTransferProtocolBase(string host, string user)
: base(host, user)
{
}
#region ITransferProtocol Members
public abstract void Get(string fromFilePath, string toFilePath);
public abstract void Put(string fromFilePath, string toFilePath);
public abstract void Mkdir(string directory);
public abstract void Cancel();
/// <summary>
/// Triggered when transfer is starting
/// </summary>
public event FileTransferEvent OnTransferStart;
/// <summary>
/// Triggered when transfer ends
/// </summary>
public event FileTransferEvent OnTransferEnd;
/// <summary>
/// Triggered on every interval with the transfer progress iformation.
/// </summary>
public event FileTransferEvent OnTransferProgress;
/// <summary>
/// Sends a notification that a file transfer has started
/// </summary>
/// <param name="src">The source file to transferred</param>
/// <param name="dst">Transfer destination</param>
/// <param name="totalBytes">Total bytes to transfer</param>
/// <param name="msg">A transfer message</param>
protected void SendStartMessage(string src, string dst, int totalBytes, string msg)
{
if (OnTransferStart != null)
OnTransferStart(src, dst, 0, totalBytes, msg);
}
/// <summary>
/// Sends a notification that a file transfer has ended
/// </summary>
/// <param name="src">The source file to transferred</param>
/// <param name="dst">Transfer destination</param>
/// <param name="transferredBytes">Transferred Bytes</param>
/// <param name="totalBytes">Total bytes to transfer</param>
/// <param name="msg">A transfer message</param>
protected void SendEndMessage(string src, string dst, int transferredBytes, int totalBytes, string msg)
{
if (OnTransferEnd != null)
OnTransferEnd(src, dst, transferredBytes, totalBytes, msg);
}
/// <summary>
/// Sends a transfer progress notification
/// </summary>
/// <param name="src">The source file to transferred</param>
/// <param name="dst">Transfer destination</param>
/// <param name="transferredBytes">Transferred Bytes</param>
/// <param name="totalBytes">Total bytes to transfer</param>
/// <param name="msg">A transfer message</param>
protected void SendProgressMessage(string src, string dst, int transferredBytes, int totalBytes, string msg)
{
if (OnTransferProgress != null)
{
OnTransferProgress(src, dst, transferredBytes, totalBytes, msg);
}
}
#endregion
}
}

View file

@ -1,206 +0,0 @@
using System;
using System.IO;
/*
* CombinedStream.cs
*
* Copyright (c) 2006 Tamir Gal, http://www.tamirgal.com, All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the distribution.
*
* 3. The names of the authors may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR
* *OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
**/
namespace Tamir.Streams
{
/// <summary>
/// Summary description for CombinedStream.
/// </summary>
public class CombinedStream : Stream
{
private Stream m_in;
private Stream m_out;
public CombinedStream(Stream inputStream, Stream outputStream)
{
this.m_in=inputStream;
this.m_out=outputStream;
}
/// <summary>
/// Reads a sequence of bytes from the current stream and advances the position within the stream by the number of bytes read.
/// </summary>
/// <param name="buffer">An array of bytes. When this method returns, the buffer contains the specified byte array with the values between offset and (offset + count- 1) replaced by the bytes read from the current source.</param>
/// <param name="offset">The zero-based byte offset in buffer at which to begin storing the data read from the current stream. </param>
/// <param name="count">The maximum number of bytes to be read from the current stream. </param>
/// <returns>The total number of bytes read into the buffer. This can be less than the number of bytes requested if that many bytes are not currently available, or zero (0) if the end of the stream has been reached.</returns>
public override int Read(byte[] buffer, int offset, int count)
{
return m_in.Read(buffer, offset, count);
}
/// <summary>
/// Reads a sequence of bytes from the current stream and advances the position within the stream by the number of bytes read.
/// </summary>
/// <param name="buffer">An array of bytes. When this method returns, the buffer contains the specified byte array with the values between offset and (offset + count- 1) replaced by the bytes read from the current source.</param>
/// <returns>The total number of bytes read into the buffer. This can be less than the number of bytes requested if that many bytes are not currently available, or zero (0) if the end of the stream has been reached.</returns>
public virtual int Read(byte[] buffer)
{
return Read(buffer, 0, buffer.Length);
}
/// <summary>
/// Reads a byte from the stream and advances the position within the stream by one byte, or returns -1 if at the end of the stream.
/// </summary>
/// <returns>The unsigned byte cast to an Int32, or -1 if at the end of the stream.</returns>
public override int ReadByte()
{
return m_in.ReadByte();
}
/// <summary>
/// Writes a byte to the current position in the stream and advances the position within the stream by one byte.
/// </summary>
/// <param name="value">The byte to write to the stream. </param>
public override void WriteByte(byte value)
{
m_out.WriteByte(value);
}
/// <summary>
/// Writes a sequence of bytes to the current stream and advances the current position within this stream by the number of bytes written.
/// </summary>
/// <param name="buffer">An array of bytes. This method copies count bytes from buffer to the current stream. </param>
/// <param name="offset">The zero-based byte offset in buffer at which to begin copying bytes to the current stream.</param>
/// <param name="count">The number of bytes to be written to the current stream. </param>
public override void Write(byte[] buffer, int offset, int count)
{
m_out.Write(buffer, offset, count);
}
/// <summary>
/// Writes a sequence of bytes to the current stream and advances the current position within this stream by the number of bytes written.
/// </summary>
/// <param name="buffer">An array of bytes. This method copies count bytes from buffer to the current stream. </param>
public virtual void Write(byte[] buffer)
{
Write(buffer, 0, buffer.Length);
}
/// <summary>
/// Closes the current stream and releases any resources (such as sockets and file handles) associated with the current stream.
/// </summary>
public override void Close()
{
try
{
base.Close ();
m_in.Close();
m_out.Close();
}
catch{}
}
/// <summary>
/// Gets a value indicating whether the current stream supports reading.
/// </summary>
public override bool CanRead
{
get
{
return m_in.CanRead;
}
}
/// <summary>
/// Gets a value indicating whether the current stream supports writing.
/// </summary>
public override bool CanWrite
{
get
{
return m_out.CanWrite;
}
}
/// <summary>
/// Gets a value indicating whether the current stream supports seeking. This stream cannot seek, and will always return false.
/// </summary>
public override bool CanSeek
{
get
{
return false;
}
}
/// <summary>
/// Clears all buffers for this stream and causes any buffered data to be written to the underlying device.
/// </summary>
public override void Flush()
{
m_out.Flush();
}
/// <summary>
/// Gets the length in bytes of the stream.
/// </summary>
public override long Length
{
get
{
return 0;
}
}
/// <summary>
/// Gets or sets the position within the current stream. This Stream cannot seek. This property has no effect on the Stream and will always return 0.
/// </summary>
public override long Position
{
get
{
return 0;
}
set
{
}
}
/// <summary>
/// This method has no effect on the Stream.
/// </summary>
public override void SetLength(long value)
{
}
/// <summary>
/// This method has no effect on the Stream.
/// </summary>
public override long Seek(long offset, SeekOrigin origin)
{
return 0;
}
}
}

View file

@ -1,69 +0,0 @@
//using System;
//using System.IO;
//
//namespace Tamir.Streams
//{
// /// <summary>
// /// Summary description for InputStream.
// /// </summary>
// public abstract class InputStream : Stream
// {
// public override void WriteByte(byte value)
// {
// }
//
// public override void Write(byte[] buffer, int offset, int count)
// {
// }
//
// public override bool CanRead
// {
// get
// {
// return true;
// }
// }
// public override bool CanWrite
// {
// get
// {
// return false;
// }
// }
// public override bool CanSeek
// {
// get
// {
// return false;
// }
// }
// public override void Flush()
// {
//
// }
// public override long Length
// {
// get
// {
// return 0;
// }
// }
// public override long Position
// {
// get
// {
// return 0;
// }
// set
// {
// }
// }
// public override void SetLength(long value)
// {
// }
// public override long Seek(long offset, SeekOrigin origin)
// {
// return 0;
// }
// }
//}

View file

@ -1,70 +0,0 @@
//using System;
//using System.IO;
//
//namespace Tamir.Streams
//{
// /// <summary>
// /// Summary description for OutputStream.
// /// </summary>
// public abstract class OutputStream : Stream
// {
// public override int Read(byte[] buffer, int offset, int count)
// {
// return 0;
// }
//
// public override int ReadByte()
// {
// return 0;
// }
//
// public override bool CanRead
// {
// get
// {
// return false;
// }
// }
// public override bool CanWrite
// {
// get
// {
// return true;
// }
// }
// public override bool CanSeek
// {
// get
// {
// return false;
// }
// }
// public override void Flush()
// {
// }
// public override long Length
// {
// get
// {
// return 0;
// }
// }
// public override long Position
// {
// get
// {
// return 0;
// }
// set
// {
// }
// }
// public override void SetLength(long value)
// {
// }
// public override long Seek(long offset, SeekOrigin origin)
// {
// return 0;
// }
// }
//}

View file

@ -1,517 +0,0 @@
using System;
using System.IO;
using System.Runtime.CompilerServices;
using System.Threading;
namespace Tamir.Streams
{
/*
* @(#)PipedInputStream.java 1.35 03/12/19
*
* Copyright 2004 Sun Microsystems, Inc. All rights reserved.
* SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
*/
/**
* A piped input stream should be connected
* to a piped output stream; the piped input
* stream then provides whatever data bytes
* are written to the piped output stream.
* Typically, data is read from a <code>PipedInputStream</code>
* object by one thread and data is written
* to the corresponding <code>PipedOutputStream</code>
* by some other thread. Attempting to use
* both objects from a single thread is not
* recommended, as it may deadlock the thread.
* The piped input stream contains a buffer,
* decoupling read operations from write operations,
* within limits.
*
* @author James Gosling
* @version 1.35, 12/19/03
* @see java.io.PipedOutputStream
* @since JDK1.0
*/
public class PipedInputStream : Tamir.SharpSsh.java.io.InputStream
{
internal bool closedByWriter = false;
internal volatile bool closedByReader = false;
internal bool connected = false;
/* REMIND: identification of the read and write sides needs to be
more sophisticated. Either using thread groups (but what about
pipes within a thread?) or using finalization (but it may be a
long time until the next GC). */
internal Thread readSide;
internal Thread writeSide;
/**
* The size of the pipe's circular input buffer.
* @since JDK1.1
*/
internal const int PIPE_SIZE = 1024;
/**
* The circular buffer into which incoming data is placed.
* @since JDK1.1
*/
internal byte[] buffer = new byte[PIPE_SIZE];
/**
* The index of the position in the circular buffer at which the
* next byte of data will be stored when received from the connected
* piped output stream. <code>in&lt;0</code> implies the buffer is empty,
* <code>in==out</code> implies the buffer is full
* @since JDK1.1
*/
internal int m_in = -1;
/**
* The index of the position in the circular buffer at which the next
* byte of data will be read by this piped input stream.
* @since JDK1.1
*/
internal int m_out = 0;
/**
* Creates a <code>PipedInputStream</code> so
* that it is connected to the piped output
* stream <code>src</code>. Data bytes written
* to <code>src</code> will then be available
* as input from this stream.
*
* @param src the stream to connect to.
* @exception IOException if an I/O error occurs.
*/
public PipedInputStream(PipedOutputStream src)
{
connect(src);
}
/**
* Creates a <code>PipedInputStream</code> so
* that it is not yet connected. It must be
* connected to a <code>PipedOutputStream</code>
* before being used.
*
* @see java.io.PipedInputStream#connect(java.io.PipedOutputStream)
* @see java.io.PipedOutputStream#connect(java.io.PipedInputStream)
*/
public PipedInputStream()
{
int i = 0;
}
/**
* Causes this piped input stream to be connected
* to the piped output stream <code>src</code>.
* If this object is already connected to some
* other piped output stream, an <code>IOException</code>
* is thrown.
* <p>
* If <code>src</code> is an
* unconnected piped output stream and <code>snk</code>
* is an unconnected piped input stream, they
* may be connected by either the call:
* <p>
* <pre><code>snk.connect(src)</code> </pre>
* <p>
* or the call:
* <p>
* <pre><code>src.connect(snk)</code> </pre>
* <p>
* The two
* calls have the same effect.
*
* @param src The piped output stream to connect to.
* @exception IOException if an I/O error occurs.
*/
public virtual void connect(PipedOutputStream src)
{
src.connect(this);
}
/**
* Receives a byte of data. This method will block if no input is
* available.
* @param b the byte being received
* @exception IOException If the pipe is broken.
* @since JDK1.1
*/
[MethodImpl(MethodImplOptions.Synchronized)]
internal void receive(int b)
{
checkStateForReceive();
writeSide = Thread.CurrentThread;
if (m_in == m_out)
awaitSpace();
if (m_in < 0)
{
m_in = 0;
m_out = 0;
}
buffer[m_in++] = (byte)(b & 0xFF);
if (m_in >= buffer.Length)
{
m_in = 0;
}
}
/**
* Receives data into an array of bytes. This method will
* block until some input is available.
* @param b the buffer into which the data is received
* @param off the start offset of the data
* @param len the maximum number of bytes received
* @exception IOException If an I/O error has occurred.
*/
[MethodImpl(MethodImplOptions.Synchronized)]
internal void receive(byte[] b, int off, int len)
{
checkStateForReceive();
writeSide = Thread.CurrentThread;
int bytesToTransfer = len;
while (bytesToTransfer > 0)
{
if (m_in == m_out)
awaitSpace();
int nextTransferAmount = 0;
if (m_out < m_in)
{
nextTransferAmount = buffer.Length - m_in;
}
else if (m_in < m_out)
{
if (m_in == -1)
{
m_in = m_out = 0;
nextTransferAmount = buffer.Length - m_in;
}
else
{
nextTransferAmount = m_out - m_in;
}
}
if (nextTransferAmount > bytesToTransfer)
nextTransferAmount = bytesToTransfer;
assert(nextTransferAmount > 0);
Array.Copy(b, off, buffer, m_in, nextTransferAmount);
bytesToTransfer -= nextTransferAmount;
off += nextTransferAmount;
m_in += nextTransferAmount;
if (m_in >= buffer.Length)
{
m_in = 0;
}
}
}
private void checkStateForReceive()
{
if (!connected)
{
throw new IOException("Pipe not connected");
}
else if (closedByWriter || closedByReader)
{
throw new IOException("Pipe closed");
}
else if (readSide != null && !readSide.IsAlive)
{
throw new IOException("Read end dead");
}
}
private void awaitSpace()
{
while (m_in == m_out)
{
if ((readSide != null) && !readSide.IsAlive)
{
throw new IOException("Pipe broken");
}
/* full: kick any waiting readers */
//java: notifyAll();
Monitor.PulseAll(this);
try
{
//java: wait(1000);
Monitor.Wait(this, 1000);
}
catch (ThreadInterruptedException ex)
{
throw ex;
}
}
}
/**
* Notifies all waiting threads that the last byte of data has been
* received.
*/
[MethodImpl(MethodImplOptions.Synchronized)]
internal void receivedLast()
{
closedByWriter = true;
//notifyAll();
Monitor.PulseAll(this);
}
/**
* Reads the next byte of data from this piped input stream. The
* value byte is returned as an <code>int</code> in the range
* <code>0</code> to <code>255</code>. If no byte is available
* because the end of the stream has been reached, the value
* <code>-1</code> is returned. This method blocks until input data
* is available, the end of the stream is detected, or an exception
* is thrown.
* If a thread was providing data bytes
* to the connected piped output stream, but
* the thread is no longer alive, then an
* <code>IOException</code> is thrown.
*
* @return the next byte of data, or <code>-1</code> if the end of the
* stream is reached.
* @exception IOException if the pipe is broken.
*/
[MethodImpl(MethodImplOptions.Synchronized)]
public virtual int read()
{
if (!connected)
{
throw new IOException("Pipe not connected");
}
else if (closedByReader)
{
throw new IOException("Pipe closed");
}
else if (writeSide != null && !writeSide.IsAlive
&& !closedByWriter && (m_in < 0))
{
throw new IOException("Write end dead");
}
readSide = Thread.CurrentThread;
int trials = 2;
while (m_in < 0)
{
if (closedByWriter)
{
/* closed by writer, return EOF */
return -1;
}
if ((writeSide != null) && (!writeSide.IsAlive) && (--trials < 0))
{
throw new IOException("Pipe broken");
}
/* might be a writer waiting */
Monitor.PulseAll(this);
try
{
Monitor.Wait(this, 1000);
}
catch (ThreadInterruptedException ex)
{
throw ex;
}
}
int ret = buffer[m_out++] & 0xFF;
if (m_out >= buffer.Length)
{
m_out = 0;
}
if (m_in == m_out)
{
/* now empty */
m_in = -1;
}
return ret;
}
/**
* Reads up to <code>len</code> bytes of data from this piped input
* stream into an array of bytes. Less than <code>len</code> bytes
* will be read if the end of the data stream is reached. This method
* blocks until at least one byte of input is available.
* If a thread was providing data bytes
* to the connected piped output stream, but
* the thread is no longer alive, then an
* <code>IOException</code> is thrown.
*
* @param b the buffer into which the data is read.
* @param off the start offset of the data.
* @param len the maximum number of bytes read.
* @return the total number of bytes read into the buffer, or
* <code>-1</code> if there is no more data because the end of
* the stream has been reached.
* @exception IOException if an I/O error occurs.
*/
[MethodImpl(MethodImplOptions.Synchronized)]
public override int read(byte[] b, int off, int len)
{
if (b == null)
{
throw new NullReferenceException();
}
else if ((off < 0) || (off > b.Length) || (len < 0) ||
((off + len) > b.Length) || ((off + len) < 0))
{
throw new IndexOutOfRangeException();
}
else if (len == 0)
{
return 0;
}
/* possibly wait on the first character */
int c = read();
if (c < 0)
{
return -1;
}
b[off] = (byte) c;
int rlen = 1;
while ((m_in >= 0) && (--len > 0))
{
b[off + rlen] = buffer[m_out++];
rlen++;
if (m_out >= buffer.Length)
{
m_out = 0;
}
if (m_in == m_out)
{
/* now empty */
m_in = -1;
}
}
return rlen;
}
/**
* Returns the number of bytes that can be read from this input
* stream without blocking. This method overrides the <code>available</code>
* method of the parent class.
*
* @return the number of bytes that can be read from this input stream
* without blocking.
* @exception IOException if an I/O error occurs.
* @since JDK1.0.2
*/
[MethodImpl(MethodImplOptions.Synchronized)]
public virtual int available()
{
if(m_in < 0)
return 0;
else if(m_in == m_out)
return buffer.Length;
else if (m_in > m_out)
return m_in - m_out;
else
return m_in + buffer.Length - m_out;
}
/**
* Closes this piped input stream and releases any system resources
* associated with the stream.
*
* @exception IOException if an I/O error occurs.
*/
public override void close()
{
closedByReader = true;
lock (this)
{
m_in = -1;
}
}
private void assert(bool exp)
{
if (!exp)
throw new Exception("Assertion failed!");
}
///////////////////////////////////////
public override int Read(byte[] buffer, int offset, int count)
{
return this.read(buffer, offset, count);
}
public override int ReadByte()
{
return this.read();
}
public override void WriteByte(byte value)
{
}
public override void Write(byte[] buffer, int offset, int count)
{
}
public override void Close()
{
base.Close ();
this.close();
}
public override bool CanRead
{
get
{
return true;
}
}
public override bool CanWrite
{
get
{
return false;
}
}
public override bool CanSeek
{
get
{
return false;
}
}
public override void Flush()
{
}
public override long Length
{
get
{
if(m_in > m_out)
return (m_in - m_out);
else
{
return (buffer.Length -m_out+m_in);
}
}
}
public override long Position
{
get
{
return m_out;
}
set
{
throw new IOException("Setting the position of this stream is not supported");
}
}
public override void SetLength(long value)
{
throw new IOException("Setting the length of this stream is not supported");
}
public override long Seek(long offset, SeekOrigin origin)
{
return 0;
}
}
}

View file

@ -1,276 +0,0 @@
using System;
using System.IO;
using System.Runtime.CompilerServices;
namespace Tamir.Streams
{
/*
* @(#)PipedOutputStream.java 1.26 03/12/19
*
* Copyright 2004 Sun Microsystems, Inc. All rights reserved.
* SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
*/
/**
* A piped output stream can be connected to a piped input stream
* to create a communications pipe. The piped output stream is the
* sending end of the pipe. Typically, data is written to a
* <code>PipedOutputStream</code> object by one thread and data is
* read from the connected <code>PipedInputStream</code> by some
* other thread. Attempting to use both objects from a single thread
* is not recommended as it may deadlock the thread.
*
* @author James Gosling
* @version 1.26, 12/19/03
* @see java.io.PipedInputStream
* @since JDK1.0
*/
public class PipedOutputStream : Tamir.SharpSsh.java.io.OutputStream
{
/* REMIND: identification of the read and write sides needs to be
more sophisticated. Either using thread groups (but what about
pipes within a thread?) or using finalization (but it may be a
long time until the next GC). */
private PipedInputStream sink;
/**
* Creates a piped output stream connected to the specified piped
* input stream. Data bytes written to this stream will then be
* available as input from <code>snk</code>.
*
* @param snk The piped input stream to connect to.
* @exception IOException if an I/O error occurs.
*/
public PipedOutputStream(PipedInputStream snk)
{
connect(snk);
}
/**
* Creates a piped output stream that is not yet connected to a
* piped input stream. It must be connected to a piped input stream,
* either by the receiver or the sender, before being used.
*
* @see java.io.PipedInputStream#connect(java.io.PipedOutputStream)
* @see java.io.PipedOutputStream#connect(java.io.PipedInputStream)
*/
public PipedOutputStream()
{
}
/**
* Connects this piped output stream to a receiver. If this object
* is already connected to some other piped input stream, an
* <code>IOException</code> is thrown.
* <p>
* If <code>snk</code> is an unconnected piped input stream and
* <code>src</code> is an unconnected piped output stream, they may
* be connected by either the call:
* <blockquote><pre>
* src.connect(snk)</pre></blockquote>
* or the call:
* <blockquote><pre>
* snk.connect(src)</pre></blockquote>
* The two calls have the same effect.
*
* @param snk the piped input stream to connect to.
* @exception IOException if an I/O error occurs.
*/
[MethodImpl(MethodImplOptions.Synchronized)]
public virtual void connect(PipedInputStream snk)
{
if (snk == null)
{
throw new NullReferenceException();
}
else if (sink != null || snk.connected)
{
throw new IOException("Already connected");
}
sink = snk;
snk.m_in = -1;
snk.m_out = 0;
snk.connected = true;
int t=0;
}
/**
* Writes the specified <code>byte</code> to the piped output stream.
* If a thread was reading data bytes from the connected piped input
* stream, but the thread is no longer alive, then an
* <code>IOException</code> is thrown.
* <p>
* Implements the <code>write</code> method of <code>OutputStream</code>.
*
* @param b the <code>byte</code> to be written.
* @exception IOException if an I/O error occurs.
*/
public virtual void write(int b)
{
if (sink == null)
{
throw new IOException("Pipe not connected");
}
sink.receive(b);
}
/**
* Writes <code>len</code> bytes from the specified byte array
* starting at offset <code>off</code> to this piped output stream.
* If a thread was reading data bytes from the connected piped input
* stream, but the thread is no longer alive, then an
* <code>IOException</code> is thrown.
*
* @param b the data.
* @param off the start offset in the data.
* @param len the number of bytes to write.
* @exception IOException if an I/O error occurs.
*/
public override void write(byte[] b, int off, int len)
{
if (sink == null)
{
throw new IOException("Pipe not connected");
}
else if (b == null)
{
throw new NullReferenceException();
}
else if ((off < 0) || (off > b.Length) || (len < 0) ||
((off + len) > b.Length) || ((off + len) < 0))
{
throw new IndexOutOfRangeException();
}
else if (len == 0)
{
return;
}
sink.receive(b, off, len);
}
public virtual void write(byte[] b)
{
write(b, 0, b.Length);
}
/**
* Flushes this output stream and forces any buffered output bytes
* to be written out.
* This will notify any readers that bytes are waiting in the pipe.
*
* @exception IOException if an I/O error occurs.
*/
[MethodImpl(MethodImplOptions.Synchronized)]
public override void flush()
{
if (sink != null)
{
lock (sink)
{
//sink.notifyAll();
System.Threading.Monitor.PulseAll(sink);
}
}
}
/**
* Closes this piped output stream and releases any system resources
* associated with this stream. This stream may no longer be used for
* writing bytes.
*
* @exception IOException if an I/O error occurs.
*/
public override void close()
{
if (sink != null)
{
sink.receivedLast();
}
}
///////////////////////////////////////
public override int Read(byte[] buffer, int offset, int count)
{
return 0;
}
public override int ReadByte()
{
return 0;
}
public override void WriteByte(byte value)
{
this.write(value);
}
public override void Write(byte[] buffer, int offset, int count)
{
this.write(buffer, offset, count);
}
public virtual void Write(byte[] buffer)
{
this.Write(buffer, 0, buffer.Length);
}
public override void Close()
{
base.Close ();
this.close();
}
public override bool CanRead
{
get
{
return false;
}
}
public override bool CanWrite
{
get
{
return true;
}
}
public override bool CanSeek
{
get
{
return false;
}
}
public override void Flush()
{
this.flush();
}
public override long Length
{
get
{
return sink.Length;
}
}
public override long Position
{
get
{
return sink.m_in;
}
set
{
throw new IOException("Setting the position of this stream is not supported");
}
}
public override void SetLength(long value)
{
throw new IOException("Setting the length of this stream is not supported");
}
public override long Seek(long offset, SeekOrigin origin)
{
return 0;
}
}
}

View file

@ -1,97 +0,0 @@
using System;
using System.IO;
namespace Tamir.Streams
{
/// <summary>
/// Summary description for PipedStream.
/// </summary>
public class PipedStream : Stream
{
PipedInputStream pins;
PipedOutputStream pouts;
public PipedStream(PipedInputStream pins, PipedOutputStream pouts)
{
this.pins = pins;
this.pouts = pouts;
}
public override int Read(byte[] buffer, int offset, int count)
{
return pins.read(buffer, offset, count);
}
public override int ReadByte()
{
return pins.read();
}
public override void WriteByte(byte value)
{
pouts.write(value);
}
public override void Write(byte[] buffer, int offset, int count)
{
pouts.write(buffer, offset, count);
}
public override void Close()
{
base.Close ();
pins.close();
pouts.close();
}
public override bool CanRead
{
get
{
return true;
}
}
public override bool CanWrite
{
get
{
return true;
}
}
public override bool CanSeek
{
get
{
return false;
}
}
public override void Flush()
{
}
public override long Length
{
get
{
return 0;
}
}
public override long Position
{
get
{
return 0;
}
set
{
}
}
public override void SetLength(long value)
{
}
public override long Seek(long offset, SeekOrigin origin)
{
return 0;
}
}
}

View file

@ -1,174 +0,0 @@
using System;
using System.IO;
/*
* ProtectedConsoleStream.cs
*
* Copyright (c) 2006 Tamir Gal, http://www.tamirgal.com, All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the distribution.
*
* 3. The names of the authors may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR
* *OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
**/
namespace Tamir.Streams
{
/// <summary>
/// This class provide access to the console stream obtained by calling the
/// Console.OpenStandardInput() and Console.OpenStandardOutput(), and prevents reading
/// into buffers to large for the Console Stream
/// </summary>
public class ProtectedConsoleStream : System.IO.Stream
{
Stream s;
public ProtectedConsoleStream(Stream s)
{
if((s.GetType() != Type.GetType("System.IO.__ConsoleStream"))&&
(s.GetType() != Type.GetType("System.IO.FileStream")))//for mono
{
throw new ArgumentException("Not ConsoleStream");
}
this.s=s;
}
// public static Stream Protect(Stream s)
// {
// if(s.GetType() == Console.
// }
public override int Read(byte[] buffer, int offset, int count)
{
if(count > 256)
count = 256;
return s.Read(buffer, offset, count);
}
public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback callback, object state)
{
return s.BeginRead (buffer, offset, count, callback, state);
}
public override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback callback, object state)
{
return s.BeginWrite (buffer, offset, count, callback, state);
}
public override bool CanRead
{
get
{
return s.CanRead;
}
}
public override bool CanSeek
{
get
{
return s.CanSeek;
}
}
public override bool CanWrite
{
get
{
return s.CanWrite;
}
}
public override void Close()
{
s.Close ();
}
public override System.Runtime.Remoting.ObjRef CreateObjRef(Type requestedType)
{
return s.CreateObjRef (requestedType);
}
public override int EndRead(IAsyncResult asyncResult)
{
return s.EndRead (asyncResult);
}
public override void EndWrite(IAsyncResult asyncResult)
{
s.EndWrite (asyncResult);
}
public override bool Equals(object obj)
{
return s.Equals (obj);
}
public override void Flush()
{
s.Flush();
}
public override int GetHashCode()
{
return s.GetHashCode ();
}
public override object InitializeLifetimeService()
{
return s.InitializeLifetimeService ();
}
public override long Length
{
get
{
return s.Length;
}
}
public override long Position
{
get
{
return s.Position;
}
set
{
s.Position = value;
}
}
public override int ReadByte()
{
return s.ReadByte ();
}
public override long Seek(long offset, SeekOrigin origin)
{
return s.Seek(offset, origin);
}
public override void SetLength(long value)
{
s.SetLength(value);
}
public override string ToString()
{
return s.ToString ();
}
public override void Write(byte[] buffer, int offset, int count)
{
s.Write(buffer, offset, count);
}
public override void WriteByte(byte value)
{
s.WriteByte (value);
}
}
}

View file

@ -1,22 +0,0 @@
using Ex = System.Exception;
namespace Tamir.SharpSsh.java
{
/// <summary>
/// Summary description for Exception.
/// </summary>
public class Exception : Ex
{
public Exception() : base()
{
}
public Exception(string msg) : base(msg)
{
}
public virtual string toString()
{
return ToString();
}
}
}

View file

@ -1,18 +0,0 @@
using System;
namespace Tamir.SharpSsh.java
{
/// <summary>
/// Summary description for Platform.
/// </summary>
public class Platform
{
public static bool Windows
{
get
{
return Environment.OSVersion.Platform.ToString().StartsWith("Win");
}
}
}
}

View file

@ -1,17 +0,0 @@
using System;
namespace Tamir.SharpSsh.java
{
/// <summary>
/// Summary description for RuntimeException.
/// </summary>
public class RuntimeException : Exception
{
public RuntimeException()
{
//
// TODO: Add constructor logic here
//
}
}
}

View file

@ -1,177 +0,0 @@
using System;
using Text = System.Text;
using Str = System.String;
namespace Tamir.SharpSsh.java
{
/// <summary>
/// Summary description for String.
/// </summary>
public class String
{
string s;
public String(string s)
{
this.s=s;
}
public String(object o):this(o.ToString())
{
}
public String(byte[] arr):this(getString(arr))
{
}
public String(byte[] arr, int offset, int len):this(getString(arr, offset, len))
{
}
public static implicit operator String (string s1)
{
if(s1==null) return null;
return new String(s1);
}
public static implicit operator Str (String s1)
{
if(s1==null) return null;
return s1.ToString();
}
public static Tamir.SharpSsh.java.String operator+(Tamir.SharpSsh.java.String s1, Tamir.SharpSsh.java.String s2)
{
return new Tamir.SharpSsh.java.String(s1.ToString()+s2.ToString());
}
public byte[] getBytes()
{
return String.getBytes(this);
}
public override string ToString()
{
return s;
}
public String toLowerCase()
{
return this.ToString().ToLower();
}
public bool startsWith(string prefix)
{
return this.ToString().StartsWith(prefix);
}
public int indexOf(string sub)
{
return this.ToString().IndexOf(sub);
}
public int indexOf(char sub)
{
return this.ToString().IndexOf(sub);
}
public int indexOf(char sub, int i)
{
return this.ToString().IndexOf(sub, i);
}
public char charAt(int i)
{
return s[i];
}
public String substring(int start, int end)
{
int len = end - start;
return this.ToString().Substring(start, len);
}
public String subString(int start, int len)
{
return substring(start, len);
}
public String substring(int len)
{
return this.ToString().Substring(len);
}
public String subString(int len)
{
return substring(len);
}
public int Length()
{
return this.ToString().Length;
}
public int length()
{
return Length();
}
public bool endsWith(string str)
{
return s.EndsWith(str);
}
public int lastIndexOf(string str)
{
return s.LastIndexOf(str);
}
public int lastIndexOf(char c)
{
return s.LastIndexOf(c);
}
public bool equals(object o)
{
return this.ToString().Equals(o.ToString());
}
public override bool Equals(object obj)
{
return this.equals (obj);
}
public override int GetHashCode()
{
return s.GetHashCode ();
}
public static string getString(byte[] arr)
{
return getString(arr, 0, arr.Length);
}
public static string getString(byte[] arr, int offset, int len)
{
return Text.Encoding.Default.GetString(arr, offset, len);
}
public static string getStringUTF8(byte[] arr)
{
return getStringUTF8(arr, 0, arr.Length);
}
public static string getStringUTF8(byte[] arr, int offset, int len)
{
return Text.Encoding.UTF8.GetString(arr, offset, len);
}
public static byte[] getBytes(string str)
{
return getBytesUTF8( str );
}
public static byte[] getBytesUTF8(string str)
{
return Text.Encoding.UTF8.GetBytes( str );
}
}
}

View file

@ -1,43 +0,0 @@
using System;
namespace Tamir.SharpSsh.java
{
/// <summary>
/// Summary description for System.
/// </summary>
public class System
{
public static Out Out = new Out();
public static Err err = new Err();
public static void arraycopy(Array a1, long sourceIndex, Array a2, long destIndex, long len)
{
Array.Copy(a1, sourceIndex, a2, destIndex, len);
}
}
public class Out
{
public void print(string v)
{
Console.Write(v);
}
public void println(string v)
{
Console.WriteLine(v);
}
}
public class Err
{
public void print(string v)
{
Console.Error.Write(v);
}
public void println(string v)
{
Console.Error.WriteLine(v);
}
}
}

View file

@ -1,71 +0,0 @@
using System;
using System.IO;
namespace Tamir.SharpSsh.java.io
{
/// <summary>
/// Summary description for File.
/// </summary>
public class File
{
string file;
internal FileInfo info;
public File(string file)
{
this.file = file;
info = new FileInfo(file);
}
public string getCanonicalPath()
{
return Path.GetFullPath(file);
}
public bool isDirectory()
{
return Directory.Exists(file);
}
public long Length()
{
return info.Length;
}
public long length()
{
return Length();
}
public bool isAbsolute()
{
return Path.IsPathRooted(file);
}
public java.String[] list()
{
string [] dirs = Directory.GetDirectories(file);
string [] files = Directory.GetFiles(file);
java.String[] _list = new java.String[dirs.Length+files.Length];
System.arraycopy(dirs, 0, _list, 0, dirs.Length);
System.arraycopy(files, 0, _list, dirs.Length, files.Length);
return _list;
}
public static string separator
{
get
{
return Path.DirectorySeparatorChar.ToString();
}
}
public static char separatorChar
{
get
{
return Path.DirectorySeparatorChar;
}
}
}
}

View file

@ -1,45 +0,0 @@
using System;
using IO = System.IO;
namespace Tamir.SharpSsh.java.io
{
/// <summary>
/// Summary description for FileInputStream.
/// </summary>
public class FileInputStream : InputStream
{
IO.FileStream fs;
public FileInputStream(string file)
{
fs = IO.File.OpenRead(file);
}
public FileInputStream(File file):this(file.info.Name)
{
}
public override void Close()
{
fs.Close();
}
public override int Read(byte[] buffer, int offset, int count)
{
return fs.Read(buffer, offset, count);
}
public override bool CanSeek
{
get
{
return fs.CanSeek;
}
}
public override long Seek(long offset, IO.SeekOrigin origin)
{
return fs.Seek(offset, origin);
}
}
}

View file

@ -1,60 +0,0 @@
using System;
using IO = System.IO;
namespace Tamir.SharpSsh.java.io
{
/// <summary>
/// Summary description for FileInputStream.
/// </summary>
public class FileOutputStream : OutputStream
{
IO.FileStream fs;
public FileOutputStream(string file):this(file, false)
{
}
public FileOutputStream(File file):this(file.info.Name, false)
{
}
public FileOutputStream(string file, bool append)
{
if(append)
fs = new IO.FileStream(file, IO.FileMode.Append); // append
else
fs = new IO.FileStream(file, IO.FileMode.Create);
}
public FileOutputStream(File file, bool append):this(file.info.Name)
{
}
public override void Write(byte[] buffer, int offset, int count)
{
fs.Write(buffer, offset, count);
}
public override void Flush()
{
fs.Flush();
}
public override void Close()
{
fs.Close();
}
public override bool CanSeek
{
get
{
return fs.CanSeek;
}
}
public override long Seek(long offset, IO.SeekOrigin origin)
{
return fs.Seek(offset, origin);
}
}
}

View file

@ -1,110 +0,0 @@
using System;
using IO = System.IO;
namespace Tamir.SharpSsh.java.io
{
/// <summary>
/// Summary description for InputStream.
/// </summary>
public abstract class InputStream : IO.Stream
{
public virtual int read(byte[] buffer, int offset, int count)
{
return this.Read(buffer, offset, count);
}
public virtual int read(byte[] buffer)
{
return this.Read(buffer, 0, buffer.Length);
}
public virtual int read()
{
return this.ReadByte();
}
public virtual void close()
{
Close();
}
public override void WriteByte(byte value)
{
}
public override void Write(byte[] buffer, int offset, int count)
{
}
public override bool CanRead
{
get
{
return true;
}
}
public override bool CanWrite
{
get
{
return false;
}
}
public override bool CanSeek
{
get
{
return false;
}
}
public override void Flush()
{
}
public override long Length
{
get
{
return 0;
}
}
public override long Position
{
get
{
return 0;
}
set
{
}
}
public override void SetLength(long value)
{
}
public override long Seek(long offset, IO.SeekOrigin origin)
{
return 0;
}
public long skip(long len)
{
//Seek doesn't work
//return Seek(offset, IO.SeekOrigin.Current);
int i=0;
int count = 0;
byte[] buf = new byte[len];
while(len>0)
{
i=Read(buf, count, (int)len);//tamir: possible lost of pressision
if(i<=0)
{
throw new Exception("inputstream is closed");
//return (s-foo)==0 ? i : s-foo;
}
count+=i;
len-=i;
}
return count;
}
}
}

View file

@ -1,21 +0,0 @@
using Tamir.SharpSsh.java.io;
namespace Tamir.Streams
{
/// <summary>
/// Summary description for InputStreamWrapper.
/// </summary>
public class InputStreamWrapper : InputStream
{
System.IO.Stream s;
public InputStreamWrapper(System.IO.Stream s)
{
this.s = s;
}
public override int Read(byte[] buffer, int offset, int count)
{
return s.Read(buffer, offset, count);
}
}
}

View file

@ -1,156 +0,0 @@
using System;
using IO = System.IO;
namespace Tamir.SharpSsh.java.io
{
/// <summary>
/// Summary description for Stream.
/// </summary>
public class JStream : IO.Stream
{
internal IO.Stream s;
public JStream(IO.Stream s)
{
this.s = s;
}
public override int Read(byte[] buffer, int offset, int count)
{
return s.Read(buffer, offset, count);
}
public override int ReadByte()
{
return s.ReadByte();
}
public int read(byte[] buffer, int offset, int count)
{
return Read(buffer, offset, count);
}
public int read(byte[] buffer)
{
return Read(buffer, 0, buffer.Length);
}
public int read()
{
return ReadByte();
}
public void close()
{
this.Close();
}
public override void Close()
{
s.Close ();
}
public override void WriteByte(byte value)
{
s.WriteByte(value);
}
public override void Write(byte[] buffer, int offset, int count)
{
s.Write(buffer, offset, count);
}
public void write(byte[] buffer, int offset, int count)
{
Write(buffer, offset, count);
}
public void write(byte[] buffer)
{
Write(buffer, 0, buffer.Length);
}
public override bool CanRead
{
get {return s.CanRead;}
}
public override bool CanWrite
{
get
{
return s.CanWrite;
}
}
public override bool CanSeek
{
get
{
return s.CanSeek;
}
}
public override void Flush()
{
s.Flush();
}
public override long Length
{
get
{
return s.Length;
}
}
public override long Position
{
get
{
return s.Position;
}
set
{
s.Position = value;
}
}
public override void SetLength(long value)
{
s.SetLength(value);
}
public override long Seek(long offset, IO.SeekOrigin origin)
{
return s.Seek(offset, origin);
}
public long skip(long len)
{
//Seek doesn't work
//return Seek(offset, IO.SeekOrigin.Current);
int i=0;
int count = 0;
byte[] buf = new byte[len];
while(len>0)
{
i=Read(buf, count, (int)len);//tamir: possible lost of pressision
if(i<=0)
{
throw new Exception("inputstream is closed");
//return (s-foo)==0 ? i : s-foo;
}
count+=i;
len-=i;
}
return count;
}
public int available()
{
if(s is Tamir.Streams.PipedInputStream)
{
return ((Tamir.Streams.PipedInputStream)s).available();
}
throw new Exception("JStream.available() -- Method not implemented");
}
public void flush()
{
s.Flush();
}
}
}

View file

@ -1,85 +0,0 @@
using System;
using System.IO;
namespace Tamir.SharpSsh.java.io
{
/// <summary>
/// Summary description for InputStream.
/// </summary>
public abstract class OutputStream : Stream
{
public override int Read(byte[] buffer, int offset, int count)
{
return 0;
}
public override int ReadByte()
{
return 0;
}
public virtual void write(byte[] buffer, int offset, int count)
{
Write(buffer, offset, count);
}
public virtual void close()
{
Close();
}
public virtual void flush()
{
Flush();
}
public override bool CanRead
{
get
{
return false;
}
}
public override bool CanWrite
{
get
{
return true;
}
}
public override bool CanSeek
{
get
{
return false;
}
}
public override void Flush()
{
}
public override long Length
{
get
{
return 0;
}
}
public override long Position
{
get
{
return 0;
}
set
{
}
}
public override void SetLength(long value)
{
}
public override long Seek(long offset, SeekOrigin origin)
{
return 0;
}
}
}

View file

@ -1,28 +0,0 @@
using System;
namespace Tamir.SharpSsh.java.lang
{
/// <summary>
/// Summary description for Class.
/// </summary>
public class Class
{
Type t;
private Class(Type t)
{
this.t=t;
}
private Class(string typeName) : this(Type.GetType(typeName))
{
}
public static Class forName(string name)
{
return new Class(name);
}
public object newInstance()
{
return Activator.CreateInstance(t);
}
}
}

View file

@ -1,24 +0,0 @@
using System;
namespace Tamir.SharpSsh.java.lang
{
/// <summary>
/// Summary description for Integer.
/// </summary>
public class Integer
{
private int i;
public Integer(int i)
{
this.i = i;
}
public int intValue()
{
return i;
}
public static int parseInt(string s)
{
return int.Parse(s);
}
}
}

View file

@ -1,12 +0,0 @@
using System;
namespace Tamir.SharpSsh.java.lang
{
/// <summary>
/// Summary description for Runnable.
/// </summary>
public interface Runnable
{
void run();
}
}

View file

@ -1,64 +0,0 @@
using System;
using System.Text;
namespace Tamir.SharpSsh.java.lang
{
/// <summary>
/// Summary description for StringBuffer.
/// </summary>
public class StringBuffer
{
StringBuilder sb;
public StringBuffer()
{
sb = new StringBuilder();
}
public StringBuffer(string s)
{
sb = new StringBuilder(s);
}
public StringBuffer(StringBuilder sb):this(sb.ToString())
{
}
public StringBuffer(Tamir.SharpSsh.java.String s):this(s.ToString())
{
}
public StringBuffer append(string s)
{
sb.Append(s);
return this;
}
public StringBuffer append(char s)
{
sb.Append(s);
return this;
}
public StringBuffer append(Tamir.SharpSsh.java.String s)
{
return append(s.ToString());
}
public StringBuffer delete(int start, int end)
{
sb.Remove(start, end-start);
return this;
}
public override string ToString()
{
return sb.ToString();
}
public string toString()
{
return ToString();
}
}
}

View file

@ -1,75 +0,0 @@
using System;
using System.Threading;
using Threading = System.Threading;
namespace Tamir.SharpSsh.java.lang
{
/// <summary>
/// Summary description for Thread.
/// </summary>
public class Thread
{
Threading.Thread t;
public Thread(Threading.Thread t)
{
this.t=t;
}
public Thread(ThreadStart ts):this(new Threading.Thread(ts))
{
}
public Thread(Runnable r):this(new ThreadStart(r.run))
{
}
public void setName(string name)
{
t.Name=name;
}
public void start()
{
t.Start();
}
public bool isAlive()
{
return t.IsAlive;
}
public void yield()
{
}
public void interrupt()
{
try
{
t.Interrupt();
}catch
{
}
}
public void notifyAll()
{
Monitor.PulseAll(this);
}
public static void Sleep(int t)
{
Threading.Thread.Sleep(t);
}
public static void sleep(int t)
{
Sleep(t);
}
public static Thread currentThread()
{
return new Thread( Threading.Thread.CurrentThread );
}
}
}

View file

@ -1,61 +0,0 @@
using System;
using System.Net;
namespace Tamir.SharpSsh.java.net
{
/// <summary>
/// Summary description for InetAddress.
/// </summary>
public class InetAddress
{
internal IPAddress addr;
public InetAddress(string addr)
{
this.addr = IPAddress.Parse(addr);
}
public InetAddress(IPAddress addr)
{
this.addr = addr;
}
public bool isAnyLocalAddress()
{
return IPAddress.IsLoopback(addr);
}
public bool equals(InetAddress addr)
{
return addr.ToString().Equals( addr.ToString());
}
public bool equals(string addr)
{
return addr.ToString().Equals( addr.ToString());
}
public override string ToString()
{
return addr.ToString ();
}
public override bool Equals(object obj)
{
return equals (obj.ToString());
}
public string getHostAddress()
{
return ToString();
}
public override int GetHashCode()
{
return base.GetHashCode ();
}
public static InetAddress getByName(string name)
{
return new InetAddress( Dns.GetHostByName(name).AddressList[0] );
}
}
}

View file

@ -1,27 +0,0 @@
using System;
using System.Net;
using System.Net.Sockets;
namespace Tamir.SharpSsh.java.net
{
/// <summary>
/// Summary description for ServerSocket.
/// </summary>
public class ServerSocket : TcpListener
{
public ServerSocket(int port, int arg, InetAddress addr) : base(addr.addr, port)
{
this.Start();
}
public Tamir.SharpSsh.java.net.Socket accept()
{
return new Tamir.SharpSsh.java.net.Socket( this.AcceptSocket() );
}
public void close()
{
this.Stop();
}
}
}

View file

@ -1,95 +0,0 @@
using System;
using System.IO;
using System.Net;
using System.Net.Sockets;
using Net = System.Net;
using Sock = System.Net.Sockets.Socket;
namespace Tamir.SharpSsh.java.net
{
/// <summary>
/// Summary description for Socket.
/// </summary>
public class Socket
{
internal Sock sock;
protected void SetSocketOption(SocketOptionLevel level, SocketOptionName name, int val)
{
try
{
sock.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.NoDelay, val);
}
catch
{
}
}
// public Socket(AddressFamily af, SocketType st, ProtocolType pt)
// {
// this.sock = new Sock(af, st, pt);
// this.sock.Connect();
// }
public Socket(string host, int port)
{
IPEndPoint ep = new IPEndPoint(Dns.GetHostByName(host).AddressList[0], port);
this.sock = new Sock(ep.AddressFamily,
SocketType.Stream, ProtocolType.Tcp);
this.sock.Connect(ep);
}
public Socket(Sock sock)
{
this.sock = sock;
}
public Stream getInputStream()
{
return new Net.Sockets.NetworkStream(sock);
}
public Stream getOutputStream()
{
return new Net.Sockets.NetworkStream(sock);
}
public bool isConnected()
{
return sock.Connected;
}
public void setTcpNoDelay(bool b)
{
if(b)
{
SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.NoDelay, 1);
}
else
{
SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.NoDelay, 0);
}
}
public void setSoTimeout(int t)
{
SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReceiveTimeout, t);
SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.SendTimeout, t);
}
public void close()
{
sock.Close();
}
public InetAddress getInetAddress()
{
return new InetAddress( ((IPEndPoint) sock.RemoteEndPoint).Address );
}
public int getPort()
{
return ((IPEndPoint) sock.RemoteEndPoint).Port;
}
}
}

View file

@ -1,19 +0,0 @@
using System;
namespace Tamir.SharpSsh.java.util
{
/// <summary>
/// Summary description for Arrays.
/// </summary>
public class Arrays
{
internal static bool equals(byte[] foo, byte[] bar)
{
int i=foo.Length;
if(i!=bar.Length) return false;
for(int j=0; j<i; j++){ if(foo[j]!=bar[j]) return false; }
//try{while(true){i--; if(foo[i]!=bar[i])return false;}}catch(Exception e){}
return true;
}
}
}

View file

@ -1,31 +0,0 @@
using System;
using System.Collections;
namespace Tamir.SharpSsh.java.util
{
/// <summary>
/// Summary description for Enumeration.
/// </summary>
public class Enumeration
{
private IEnumerator e;
private bool hasMore;
public Enumeration(IEnumerator e)
{
this.e=e;
hasMore = e.MoveNext();
}
public bool hasMoreElements()
{
return hasMore;
}
public object nextElement()
{
object o = e.Current;
hasMore = e.MoveNext();
return o;
}
}
}

View file

@ -1,43 +0,0 @@
using System;
using Collections = System.Collections;
namespace Tamir.SharpSsh.java.util
{
/// <summary>
/// Summary description for Hashtable.
/// </summary>
public class Hashtable
{
internal Collections.Hashtable h;
public Hashtable()
{
h= new Collections.Hashtable();
}
public Hashtable(Collections.Hashtable h)
{
this.h=h;
}
public void put(object key, object item)
{
h.Add(key, item);
}
public object get(object key)
{
return h[key];
}
public Enumeration keys()
{
return new Enumeration( h.Keys.GetEnumerator() );
}
public object this[object key]
{
get{return get(key);}
set{h[key]=value;}
}
}
}

View file

@ -1,27 +0,0 @@
using System;
namespace Tamir.SharpSsh.java.util
{
/// <summary>
/// Summary description for JavaString.
/// </summary>
public class JavaString : Tamir.SharpSsh.java.String
{
public JavaString(string s) : base(s)
{
}
public JavaString(object o):base(o)
{
}
public JavaString(byte[] arr):base(arr)
{
}
public JavaString(byte[] arr, int offset, int len):base(arr, offset, len)
{
}
}
}

View file

@ -1,57 +0,0 @@
using System;
using System.Collections;
namespace Tamir.SharpSsh.java.util
{
/// <summary>
/// Summary description for Vector.
/// </summary>
public class Vector : ArrayList
{
public int size()
{
return this.Count;
}
public void addElement(object o)
{
this.Add(o);
}
public void add(object o)
{
addElement(o);
}
public void removeElement(object o)
{
this.Remove(o);
}
public bool remove(object o)
{
this.Remove(o);
return true;
}
public object elementAt(int i)
{
return this[i];
}
public object get(int i)
{
return elementAt(i);;
}
public void clear()
{
this.Clear();
}
public string toString()
{
return ToString();
}
}
}

View file

@ -1,262 +0,0 @@
using System;
namespace Tamir.SharpSsh.jsch
{
/* -*-mode:java; c-basic-offset:2; -*- */
/*
Copyright (c) 2002,2003,2004 ymnk, JCraft,Inc. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the distribution.
3. The names of the authors may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
public class Buffer
{
static byte[] tmp=new byte[4];
internal byte[] buffer;
internal int index;
internal int s;
public Buffer(int size)
{
buffer=new byte[size];
index=0;
s=0;
}
public Buffer(byte[] buffer)
{
this.buffer=buffer;
index=0;
s=0;
}
public Buffer():this(1024*10*2){ }
public void putByte(byte foo)
{
buffer[index++]=foo;
}
public void putByte(byte[] foo)
{
putByte(foo, 0, foo.Length);
}
public void putByte(byte[] foo, int begin, int length)
{
Array.Copy(foo, begin, buffer, index, length);
index+=length;
}
public void putString(byte[] foo)
{
putString(foo, 0, foo.Length);
}
public void putString(byte[] foo, int begin, int length)
{
putInt(length);
putByte(foo, begin, length);
}
public void putInt(int v)
{
uint val = (uint)v;
tmp[0]=(byte)(val >> 24);
tmp[1]=(byte)(val >> 16);
tmp[2]=(byte)(val >> 8);
tmp[3]=(byte)(val);
Array.Copy(tmp, 0, buffer, index, 4);
index+=4;
}
public void putLong(long v)
{
ulong val = (ulong)v;
tmp[0]=(byte)(val >> 56);
tmp[1]=(byte)(val >> 48);
tmp[2]=(byte)(val >>40);
tmp[3]=(byte)(val >> 32);
Array.Copy(tmp, 0, buffer, index, 4);
tmp[0]=(byte)(val >> 24);
tmp[1]=(byte)(val >> 16);
tmp[2]=(byte)(val >> 8);
tmp[3]=(byte)(val);
Array.Copy(tmp, 0, buffer, index+4, 4);
index+=8;
}
internal void skip(int n)
{
index+=n;
}
internal void putPad(int n)
{
while(n>0)
{
buffer[index++]=(byte)0;
n--;
}
}
public void putMPInt(byte[] foo)
{
int i=foo.Length;
if((foo[0]&0x80)!=0)
{
i++;
putInt(i);
putByte((byte)0);
}
else
{
putInt(i);
}
putByte(foo);
}
public int getLength()
{
return index-s;
}
public int getOffSet()
{
return s;
}
public void setOffSet(int s)
{
this.s=s;
}
public long getLong()
{
long foo = getInt()&0xffffffffL;
foo = ((foo<<32)) | (getInt()&0xffffffffL);
return foo;
}
public int getInt()
{
uint foo = (uint) getShort();
foo = ((foo<<16)&0xffff0000) | ((uint)getShort()&0xffff);
return (int)foo;
}
internal int getShort()
{
int foo = getByte();
foo = ((foo<<8)&0xff00)|(getByte()&0xff);
return foo;
}
public int getByte()
{
return (buffer[s++]&0xff);
}
public void getByte(byte[] foo)
{
getByte(foo, 0, foo.Length);
}
void getByte(byte[] foo, int start, int len)
{
Array.Copy(buffer, s, foo, start, len);
s+=len;
}
public int getByte(int len)
{
int foo=s;
s+=len;
return foo;
}
public byte[] getMPInt()
{
int i=getInt();
byte[] foo=new byte[i];
getByte(foo, 0, i);
return foo;
}
public byte[] getMPIntBits()
{
int bits=getInt();
int bytes=(bits+7)/8;
byte[] foo=new byte[bytes];
getByte(foo, 0, bytes);
if((foo[0]&0x80)!=0)
{
byte[] bar=new byte[foo.Length+1];
bar[0]=0; // ??
Array.Copy(foo, 0, bar, 1, foo.Length);
foo=bar;
}
return foo;
}
public byte[] getString()
{
int i=getInt();
byte[] foo=new byte[i];
getByte(foo, 0, i);
return foo;
}
internal byte[] getString(int[]start, int[]len)
{
int i=getInt();
start[0]=getByte(i);
len[0]=i;
return buffer;
}
public void reset()
{
index=0;
s=0;
}
public void shift()
{
if(s==0)return;
Array.Copy(buffer, s, buffer, 0, index-s);
index=index-s;
s=0;
}
internal void rewind()
{
s=0;
}
/*
static String[] chars={
"0","1","2","3","4","5","6","7","8","9", "a","b","c","d","e","f"
};
static void dump_buffer(){
int foo;
for(int i=0; i<tmp_buffer_index; i++){
foo=tmp_buffer[i]&0xff;
System.out.print(chars[(foo>>>4)&0xf]);
System.out.print(chars[foo&0xf]);
if(i%16==15){
System.out.println("");
continue;
}
if(i>0 && i%2==1){
System.out.print(" ");
}
}
System.out.println("");
}
static void dump(byte[] b){
dump(b, 0, b.length);
}
static void dump(byte[] b, int s, int l){
for(int i=s; i<s+l; i++){
System.out.print(Integer.toHexString(b[i]&0xff)+":");
}
System.out.println("");
}
*/
}
}

View file

@ -1,547 +0,0 @@
using System;
using System.Net;
using System.IO;
using Tamir.Streams;
using System.Runtime.CompilerServices;
using Tamir.SharpSsh.java.lang;
using Str = Tamir.SharpSsh.java.String;
namespace Tamir.SharpSsh.jsch
{
/* -*-mode:java; c-basic-offset:2; -*- */
/*
Copyright (c) 2002,2003,2004 ymnk, JCraft,Inc. All rights reserved.
Redistribution and use In source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions In binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer In
the documentation and/or other materials provided with the distribution.
3. The names of the authors may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
public abstract class Channel : Tamir.SharpSsh.java.lang.Runnable
{
internal static int index=0;
private static java.util.Vector pool=new java.util.Vector();
internal static Channel getChannel(String type)
{
if(type.Equals("session"))
{
return new ChannelSession();
}
if(type.Equals("shell"))
{
return new ChannelShell();
}
if(type.Equals("exec"))
{
return new ChannelExec();
}
if(type.Equals("x11"))
{
return new ChannelX11();
}
if(type.Equals("direct-tcpip"))
{
return new ChannelDirectTCPIP();
}
if(type.Equals("forwarded-tcpip"))
{
return new ChannelForwardedTCPIP();
}
if(type.Equals("sftp"))
{
return new ChannelSftp();
}
if(type.Equals("subsystem"))
{
return new ChannelSubsystem();
}
return null;
}
internal static Channel getChannel(int id, Session session)
{
lock(pool)
{
for(int i=0; i<pool.size(); i++)
{
Channel c=(Channel)(pool.elementAt(i));
if(c.id==id && c.session==session) return c;
}
}
return null;
}
internal static void del(Channel c)
{
lock(pool)
{
pool.removeElement(c);
}
}
internal int id;
internal int recipient=-1;
internal byte[] type=new Str("foo").getBytes();
internal int lwsize_max=0x100000;
internal int lwsize=0x100000; // local initial window size
internal int lmpsize=0x4000; // local maximum packet size
internal int rwsize=0; // remote initial window size
internal int rmpsize=0; // remote maximum packet size
internal IO io=null;
internal Thread thread=null;
internal bool eof_local=false;
internal bool _eof_remote=false;
internal bool _close=false;
internal bool connected=false;
internal int exitstatus=-1;
internal int reply=0;
internal Session session;
internal Channel()
{
lock(pool)
{
id=index++;
pool.addElement(this);
}
}
internal virtual void setRecipient(int foo)
{
this.recipient=foo;
}
internal virtual int getRecipient()
{
return recipient;
}
public virtual void init()
{
}
public virtual void connect()
{
if(!session.isConnected())
{
throw new JSchException("session is down");
}
try
{
Buffer buf=new Buffer(100);
Packet packet=new Packet(buf);
// send
// byte SSH_MSG_CHANNEL_OPEN(90)
// string channel type //
// uint32 sender channel // 0
// uint32 initial window size // 0x100000(65536)
// uint32 maxmum packet size // 0x4000(16384)
packet.reset();
buf.putByte((byte)90);
buf.putString(this.type);
buf.putInt(this.id);
buf.putInt(this.lwsize);
buf.putInt(this.lmpsize);
session.write(packet);
int retry=1000;
while(this.getRecipient()==-1 &&
session.isConnected() &&
retry>0)
{
try{Thread.sleep(50);}
catch(Exception ee){}
retry--;
}
if(!session.isConnected())
{
throw new JSchException("session is down");
}
if(retry==0)
{
throw new JSchException("channel is not opened.");
}
connected=true;
start();
}
catch(Exception e)
{
connected=false;
if(e is JSchException) throw (JSchException)e;
}
}
public virtual void setXForwarding(bool foo)
{
}
public virtual void start(){}
public bool isEOF() {return _eof_remote;}
internal virtual void getData(Buffer buf)
{
setRecipient(buf.getInt());
setRemoteWindowSize(buf.getInt());
setRemotePacketSize(buf.getInt());
}
public virtual void setInputStream(Stream In)
{
io.setInputStream(In, false);
}
public virtual void setInputStream(Stream In, bool dontclose)
{
io.setInputStream(In, dontclose);
}
public virtual void setOutputStream(Stream Out)
{
io.setOutputStream(Out, false);
}
public virtual void setOutputStream(Stream Out, bool dontclose)
{
io.setOutputStream(Out, dontclose);
}
public virtual void setExtOutputStream(Stream Out)
{
io.setExtOutputStream(Out, false);
}
public virtual void setExtOutputStream(Stream Out, bool dontclose)
{
io.setExtOutputStream(Out, dontclose);
}
public virtual java.io.InputStream getInputStream()
{
PipedInputStream In=
new MyPipedInputStream(
32*1024 // this value should be customizable.
);
io.setOutputStream(new PassiveOutputStream(In), false);
return In;
}
public virtual java.io.InputStream getExtInputStream()
{
PipedInputStream In=
new MyPipedInputStream(
32*1024 // this value should be customizable.
);
io.setExtOutputStream(new PassiveOutputStream(In), false);
return In;
}
public virtual Stream getOutputStream()
{
PipedOutputStream Out=new PipedOutputStream();
io.setInputStream(new PassiveInputStream(Out
, 32*1024
), false);
// io.setInputStream(new PassiveInputStream(Out), false);
return Out;
}
internal class MyPipedInputStream : PipedInputStream
{
internal MyPipedInputStream():base() { ; }
internal MyPipedInputStream(int size) :base()
{
buffer=new byte[size];
}
internal MyPipedInputStream(PipedOutputStream Out):base(Out) { }
internal MyPipedInputStream(PipedOutputStream Out, int size):base(Out)
{
buffer=new byte[size];
}
}
internal virtual void setLocalWindowSizeMax(int foo){ this.lwsize_max=foo; }
internal virtual void setLocalWindowSize(int foo){ this.lwsize=foo; }
internal virtual void setLocalPacketSize(int foo){ this.lmpsize=foo; }
[System.Runtime.CompilerServices.MethodImpl(MethodImplOptions.Synchronized)]
internal virtual void setRemoteWindowSize(int foo){ this.rwsize=foo; }
[System.Runtime.CompilerServices.MethodImpl(MethodImplOptions.Synchronized)]
internal virtual void addRemoteWindowSize(int foo){ this.rwsize+=foo; }
internal virtual void setRemotePacketSize(int foo){ this.rmpsize=foo; }
public virtual void run()
{
}
internal virtual void write(byte[] foo)
{
write(foo, 0, foo.Length);
}
internal virtual void write(byte[] foo, int s, int l)
{
try
{
// if(io.outs!=null)
io.put(foo, s, l);
}
catch(NullReferenceException e){}
}
internal virtual void write_ext(byte[] foo, int s, int l)
{
try
{
// if(io.out_ext!=null)
io.put_ext(foo, s, l);
}
catch(NullReferenceException e){}
}
internal virtual void eof_remote()
{
_eof_remote=true;
try
{
if(io.outs!=null)
{
io.outs.Close();
io.outs=null;
}
}
catch(NullReferenceException e){}
catch(IOException e){}
}
internal virtual void eof()
{
//System.Out.println("EOF!!!! "+this);
//Thread.dumpStack();
if(_close)return;
if(eof_local)return;
eof_local=true;
//close=eof;
try
{
Buffer buf=new Buffer(100);
Packet packet=new Packet(buf);
packet.reset();
buf.putByte((byte)Session.SSH_MSG_CHANNEL_EOF);
buf.putInt(getRecipient());
session.write(packet);
}
catch(Exception e)
{
//System.Out.println("Channel.eof");
//e.printStackTrace();
}
/*
if(!isConnected()){ disconnect(); }
*/
}
/*
http://www1.ietf.org/internet-drafts/draft-ietf-secsh-connect-24.txt
5.3 Closing a Channel
When a party will no longer send more data to a channel, it SHOULD
send SSH_MSG_CHANNEL_EOF.
byte SSH_MSG_CHANNEL_EOF
uint32 recipient_channel
No explicit response is sent to this message. However, the
application may send EOF to whatever is at the other end of the
channel. Note that the channel remains open after this message, and
more data may still be sent In the other direction. This message
does not consume window space and can be sent even if no window space
is available.
When either party wishes to terminate the channel, it sends
SSH_MSG_CHANNEL_CLOSE. Upon receiving this message, a party MUST
send back a SSH_MSG_CHANNEL_CLOSE unless it has already sent this
message for the channel. The channel is considered closed for a
party when it has both sent and received SSH_MSG_CHANNEL_CLOSE, and
the party may then reuse the channel number. A party MAY send
SSH_MSG_CHANNEL_CLOSE without having sent or received
SSH_MSG_CHANNEL_EOF.
byte SSH_MSG_CHANNEL_CLOSE
uint32 recipient_channel
This message does not consume window space and can be sent even if no
window space is available.
It is recommended that any data sent before this message is delivered
to the actual destination, if possible.
*/
internal virtual void close()
{
//System.Out.println("close!!!!");
if(_close)return;
_close=true;
try
{
Buffer buf=new Buffer(100);
Packet packet=new Packet(buf);
packet.reset();
buf.putByte((byte)Session.SSH_MSG_CHANNEL_CLOSE);
buf.putInt(getRecipient());
session.write(packet);
}
catch(Exception e)
{
//e.printStackTrace();
}
}
public virtual bool isClosed()
{
return _close;
}
internal static void disconnect(Session session)
{
Channel[] channels=null;
int count=0;
lock(pool)
{
channels=new Channel[pool.size()];
for(int i=0; i<pool.size(); i++)
{
try
{
Channel c=((Channel)(pool.elementAt(i)));
if(c.session==session)
{
channels[count++]=c;
}
}
catch(Exception e)
{
}
}
}
for(int i=0; i<count; i++)
{
channels[i].disconnect();
}
}
/*
public void finalize() throws Throwable{
disconnect();
super.finalize();
session=null;
}
*/
public virtual void disconnect()
{
//System.Out.println(this+":disconnect "+io+" "+io.in);
if(!connected)
{
return;
}
connected=false;
close();
_eof_remote=eof_local=true;
thread=null;
try
{
if(io!=null)
{
io.close();
}
}
catch(Exception e)
{
//e.printStackTrace();
}
io=null;
Channel.del(this);
}
public virtual bool isConnected()
{
if(this.session!=null)
{
return session.isConnected() && connected;
}
return false;
}
public virtual void sendSignal(String foo)
{
RequestSignal request=new RequestSignal();
request.setSignal(foo);
request.request(session, this);
}
// public String toString(){
// return "Channel: type="+new String(type)+",id="+id+",recipient="+recipient+",window_size="+window_size+",packet_size="+packet_size;
// }
/*
class OutputThread extends Thread{
Channel c;
OutputThread(Channel c){ this.c=c;}
public void run(){c.output_thread();}
}
*/
internal class PassiveInputStream : MyPipedInputStream
{
internal PipedOutputStream Out;
internal PassiveInputStream(PipedOutputStream Out, int size) :base(Out, size)
{
this.Out=Out;
}
internal PassiveInputStream(PipedOutputStream Out):base(Out)
{
this.Out=Out;
}
public override void close()
{
if(Out!=null)
{
this.Out.close();
}
Out=null;
}
}
internal class PassiveOutputStream : PipedOutputStream
{
internal PassiveOutputStream(PipedInputStream In) :base(In)
{
}
}
internal virtual void setExitStatus(int foo){ exitstatus=foo; }
public virtual int getExitStatus(){ return exitstatus; }
internal virtual void setSession(Session session)
{
this.session=session;
}
public virtual Session getSession(){ return session; }
public virtual int getId(){ return id; }
//public int getRecipientId(){ return getRecipient(); }
}
}

View file

@ -1,472 +0,0 @@
//using System;
//using System.Net;
//using System.IO;
//using Tamir.Streams;
//
//namespace Tamir.SharpSsh.jsch
//{
// /* -*-mode:java; c-basic-offset:2; -*- */
// /*
// Copyright (c) 2002,2003,2004 ymnk, JCraft,Inc. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in
// the documentation and/or other materials provided with the distribution.
//
// 3. The names of the authors may not be used to endorse or promote products
// derived from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
// FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
// INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
// OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
// EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// */
//
//
// public abstract class Channel
// {
// internal static int index=0;
// private static System.Collections.ArrayList pool=new System.Collections.ArrayList();
// internal static Channel getChannel(String type)
// {
// if(type.Equals("session"))
// {
// return new ChannelSession();
// }
// if(type.Equals("shell"))
// {
// return new ChannelShell();
// }
// if(type.Equals("exec"))
// {
// return new ChannelExec();
// }
// if(type.Equals("x11"))
// {
// return new ChannelX11();
// }
// if(type.Equals("direct-tcpip"))
// {
// return new ChannelDirectTCPIP();
// }
// if(type.Equals("forwarded-tcpip"))
// {
// return new ChannelForwardedTCPIP();
// }
// if(type.Equals("sftp"))
// {
// return new ChannelSftp();
// }
// return null;
// }
// internal static Channel getChannel(int id, Session session)
// {
// lock(pool)
// {
// for(int i=0; i<pool.Count; i++)
// {
// Channel c=(Channel)(pool[i]);
// if(c.id==id && c.session==session) return c;
// }
// }
// return null;
// }
// internal static void del(Channel c)
// {
// lock(pool)
// {
// pool.Remove(c);
// }
// }
//
// internal int id;
// internal int recipient=-1;
// internal byte[] type= Util.getBytes( "foo" );
// internal int lwsize_max=0x100000;
// internal int lwsize=0x100000; // local initial window size
// internal int lmpsize=0x4000; // local maximum packet size
//
// internal int rwsize=0; // remote initial window size
// internal int rmpsize=0; // remote maximum packet size
//
// internal IO io=null;
// internal System.Threading.Thread thread=null;
//
// internal bool eof_local=false;
// internal bool eof_remote=false;
//
// internal bool _close=false;
//
// internal int exitstatus=-1;
//
// internal int reply=0;
//
// internal Session session;
//
// internal Channel()
// {
// lock(pool)
// {
// id=index++;
// pool.Add(this);
// }
// }
// internal void setRecipient(int foo)
// {
// this.recipient=foo;
// }
// internal virtual int getRecipient()
// {
// return recipient;
// }
//
// public virtual void init()
// {
// }
//
// public virtual void connect()
// {
// if(!isConnected())
// {
// throw new JSchException("session is down");
// }
// try
// {
// Buffer buf=new Buffer(100);
// Packet packet=new Packet(buf);
// // send
// // byte SSH_MSG_CHANNEL_OPEN(90)
// // string channel type //
// // uint32 sender channel // 0
// // uint32 initial window size // 0x100000(65536)
// // uint32 maxmum packet size // 0x4000(16384)
// packet.reset();
// buf.putByte((byte)90);
// buf.putString(this.type);
// buf.putInt(this.id);
// buf.putInt(this.lwsize);
// buf.putInt(this.lmpsize);
// session.write(packet);
//
// int retry=1000;
// while(this.getRecipient()==-1 &&
// session.IsConnected() &&
// retry>0)
// {
// try{System.Threading.Thread.Sleep(50);}
// catch{}
// retry--;
// }
// if(!session.IsConnected())
// {
// throw new JSchException("session is down");
// }
// if(retry==0)
// {
// throw new JSchException("channel is not opened.");
// }
// start();
// }
// catch(Exception e)
// {
// if(e is JSchException) throw (JSchException)e;
// }
// }
//
// public virtual void setXForwarding(bool foo)
// {
// }
//
// public virtual void start() {}
//
// public bool isEOF() {return eof_remote;}
//
// internal virtual void getData(Buffer buf)
// {
// setRecipient(buf.getInt());
// setRemoteWindowSize(buf.getInt());
// setRemotePacketSize(buf.getInt());
// }
//
// public RequestWindowChange getRequestWindowChange()
// {
// return new RequestWindowChange();
// }
//
// public virtual void setInputStream(Stream ins)
// {
// io.setInputStream(ins);
// }
// public virtual void setOutputStream(Stream outs)
// {
// io.setOutputStream(outs);
// }
// public virtual void setExtOutputStream(Stream outs)
// {
// io.setExtOutputStream(outs);
// }
// public virtual Stream getInputStream()
// {
// PipedInputStream ins=
// new MyPipedInputStream(
// 32*1024 // this value should be customizable.
// );
// io.setOutputStream(new PassiveOutputStream(ins));
// return ins;
// }
// public virtual Stream getExtInputStream()
// {
// PipedInputStream ins=
// new MyPipedInputStream(
// 32*1024 // this value should be customizable.
// );
// io.setExtOutputStream(new PassiveOutputStream(ins));
// return ins;
// }
// public virtual Stream getOutputStream()
// {
// PipedOutputStream outs=new PipedOutputStream();
// io.setInputStream(new PassiveInputStream(outs));
// return outs;
// }
//
// internal void setLocalWindowSizeMax(int foo){ this.lwsize_max=foo; }
// internal void setLocalWindowSize(int foo){ this.lwsize=foo; }
// internal void setLocalPacketSize(int foo){ this.lmpsize=foo; }
// internal void setRemoteWindowSize(int foo){ this.rwsize=foo; }
// internal void addRemoteWindowSize(int foo){ this.rwsize+=foo; }
// internal void setRemotePacketSize(int foo){ this.rmpsize=foo; }
//
// public virtual void run()
// {
// }
//
// internal virtual void write(byte[] foo)
// {
// write(foo, 0, foo.Length);
// }
// internal virtual void write(byte[] foo, int s, int l)
// {
// //if(eof_remote)return;
// if(io.outs!=null)
// io.put(foo, s, l);
// }
// internal void write_ext(byte[] foo, int s, int l)
// {
// //if(eof_remote)return;
// if(io.out_ext!=null)
// io.put_ext(foo, s, l);
// }
//
// internal void eof()
// {
// //System.out.println("EOF!!!! "+this);
// //Thread.dumpStack();
// if(eof_local)return;
// eof_local=true;
// //close=eof;
// try
// {
// Buffer buf=new Buffer(100);
// Packet packet=new Packet(buf);
// packet.reset();
// buf.putByte((byte)Session.SSH_MSG_CHANNEL_EOF);
// buf.putInt(getRecipient());
// session.write(packet);
// }
// catch
// {
// //System.out.println("Channel.eof");
// //e.printStackTrace();
// }
// if(!isConnected())
// {
// disconnect();
// }
// }
//
// internal void close()
// {
// //System.out.println("close!!!!");
// if(_close)return;
// _close=true;
// try
// {
// Buffer buf=new Buffer(100);
// Packet packet=new Packet(buf);
// packet.reset();
// buf.putByte((byte)Session.SSH_MSG_CHANNEL_CLOSE);
// buf.putInt(getRecipient());
// session.write(packet);
// session.disconnect();
// }
// catch
// {
// //e.printStackTrace();
// }
// }
// internal static void eof(Session session)
// {
// Channel[] channels=null;
// int count=0;
// lock(pool)
// {
// channels=new Channel[pool.Count];
// for(int i=0; i<pool.Count; i++)
// {
// try
// {
// Channel c=((Channel)(pool[i]));
// if(c.session==session)
// {
// channels[count++]=c;
// }
// }
// catch
// {
// }
// }
// }
// for(int i=0; i<count; i++)
// {
// channels[i].eof();
// }
// }
//
// //public void finalize() {
// public virtual void finalize()
// {
// disconnect();
// //super.finalize();
// session=null;
// }
//
// public virtual void disconnect()
// {
// //System.out.println(this+":disconnect "+((ChannelExec)this).command+" "+io.in);
// //System.out.println(this+":disconnect "+io+" "+io.in);
// close();
// //System.out.println("$1");
//
// thread=null;
// try
// {
// if(io!=null)
// {
// try
// {
// //System.out.println(" io.in="+io.in);
// if(io.ins!=null &&
// (io.ins is PassiveInputStream)
// )
// io.ins.Close();
// }
// catch{}
// try
// {
// //System.out.println(" io.out="+io.out);
// if(io.outs!=null &&
// (io.outs is PassiveOutputStream)
// )
// io.outs.Close();
// }
// catch{}
// }
// }
// catch
// {
// //e.printStackTrace();
// }
// //System.out.println("$2");
// io=null;
// Channel.del(this);
// }
//
// public bool isConnected()
// {
// if(this.session!=null)
// {
// return session.IsConnected();
// }
// return false;
// }
//
// public void sendSignal(String foo)
// {
// RequestSignal request=new RequestSignal();
// request.setSignal(foo);
// request.request(session, this);
// }
//
// // public String toString(){
// // return "Channel: type="+new String(type)+",id="+id+",recipient="+recipient+",window_size="+window_size+",packet_size="+packet_size;
// // }
//
// /*
// class OutputThread extends Thread{
// Channel c;
// OutputThread(Channel c){ this.c=c;}
// public void run(){c.output_thread();}
// }
// */
//
// internal class PassiveInputStream : PipedInputStream
// {
// PipedOutputStream outs;
// internal PassiveInputStream(PipedOutputStream outs) :base(outs)
// {
// this.outs=outs;
// }
// public override void close()
// {
// if(outs!=null)
// {
// this.outs.close();
// }
// outs=null;
// }
// }
// internal class PassiveOutputStream : PipedOutputStream
// {
// internal PassiveOutputStream(PipedInputStream ins):base(ins)
// {
//
// }
// }
//
// internal void setExitStatus(int foo){ exitstatus=foo; }
// public int getExitStatus(){ return exitstatus; }
//
// internal void setSession(Session session)
// {
// this.session=session;
// }
// }
//
// public class MyPipedInputStream : Tamir.Streams.PipedInputStream
// {
// public MyPipedInputStream():base(){}
//
// public MyPipedInputStream(int size):base()
// {
// buffer=new byte[size];
// }
// public MyPipedInputStream(PipedOutputStream outs):base(outs) { }
// public MyPipedInputStream(PipedOutputStream outs, int size):base(outs)
// {
// buffer=new byte[size];
// }
// }
//}

View file

@ -1,213 +0,0 @@
using System;
using System.IO;
using Tamir.SharpSsh.java.lang;
namespace Tamir.SharpSsh.jsch
{
/* -*-mode:java; c-basic-offset:2; -*- */
/*
Copyright (c) 2002,2003,2004 ymnk, JCraft,Inc. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the distribution.
3. The names of the authors may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
public class ChannelDirectTCPIP : Channel
{
private const int LOCAL_WINDOW_SIZE_MAX=0x20000;
private const int LOCAL_MAXIMUM_PACKET_SIZE=0x4000;
internal String host;
internal int port;
internal String originator_IP_address="127.0.0.1";
internal int originator_port=0;
internal ChannelDirectTCPIP() : base()
{
setLocalWindowSizeMax(LOCAL_WINDOW_SIZE_MAX);
setLocalWindowSize(LOCAL_WINDOW_SIZE_MAX);
setLocalPacketSize(LOCAL_MAXIMUM_PACKET_SIZE);
}
public override void init ()
{
try
{
io=new IO();
}
catch(Exception e)
{
Console.WriteLine(e);
}
}
public override void connect()
{
try
{
if(!session.isConnected())
{
throw new JSchException("session is down");
}
Buffer buf=new Buffer(150);
Packet packet=new Packet(buf);
// send
// byte SSH_MSG_CHANNEL_OPEN(90)
// string channel type //
// uint32 sender channel // 0
// uint32 initial window size // 0x100000(65536)
// uint32 maxmum packet size // 0x4000(16384)
packet.reset();
buf.putByte((byte)90);
buf.putString(Util.getBytes("direct-tcpip"));
buf.putInt(id);
buf.putInt(lwsize);
buf.putInt(lmpsize);
buf.putString(Util.getBytes(host));
buf.putInt(port);
buf.putString(Util.getBytes(originator_IP_address));
buf.putInt(originator_port);
session.write(packet);
int retry=1000;
try
{
while(this.getRecipient()==-1 &&
session.isConnected() &&
retry>0 &&
!_eof_remote)
{
//Thread.sleep(500);
Thread.Sleep(50);
retry--;
}
}
catch
{
}
if(!session.isConnected())
{
throw new JSchException("session is down");
}
if(retry==0 || this._eof_remote)
{
throw new JSchException("channel is not opened.");
}
/*
if(this.eof_remote){ // failed to open
disconnect();
return;
}
*/
connected=true;
thread=new Thread(this);
thread.start();
}
catch(Exception e)
{
io.close();
io=null;
Channel.del(this);
if (e is JSchException)
{
throw (JSchException) e;
}
}
}
public override void run()
{
// thread=Thread.currentThread();
//System.out.println("rmpsize: "+rmpsize+", lmpsize: "+lmpsize);
Buffer buf=new Buffer(rmpsize);
// Buffer buf=new Buffer(lmpsize);
Packet packet=new Packet(buf);
int i=0;
try
{
while(isConnected() &&
thread!=null &&
io!=null &&
io.ins!=null)
{
i=io.ins.Read(buf.buffer,
14,
buf.buffer.Length-14
-32 -20 // padding and mac
);
if(i<=0)
{
eof();
break;
}
if(_close)break;
packet.reset();
buf.putByte((byte)Session.SSH_MSG_CHANNEL_DATA);
buf.putInt(recipient);
buf.putInt(i);
buf.skip(i);
session.write(packet, this, i);
}
}
catch
{
}
disconnect();
//System.out.println("connect end");
/*
try{
packet.reset();
buf.putByte((byte)Session.SSH_MSG_CHANNEL_EOF);
buf.putInt(recipient);
session.write(packet);
}
catch(Exception e){
}
*/
// close();
}
public override void setInputStream(Stream ins)
{
io.setInputStream(ins);
}
public override void setOutputStream(Stream outs)
{
io.setOutputStream(outs);
}
public void setHost(String host){this.host=host;}
public void setPort(int port){this.port=port;}
public void setOrgIPAddress(String foo){this.originator_IP_address=foo;}
public void setOrgPort(int foo){this.originator_port=foo;}
}
}

View file

@ -1,98 +0,0 @@
using System;
using System.Net;
using System.Net.Sockets;
using System.IO;
using Tamir.SharpSsh.java.lang;
namespace Tamir.SharpSsh.jsch
{
/* -*-mode:java; c-basic-offset:2; -*- */
/*
Copyright (c) 2002,2003,2004 ymnk, JCraft,Inc. All rights reserved.
Redistribution and use ins source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions ins binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer ins
the documentation and/or other materials provided with the distribution.
3. The names of the authors may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
public class ChannelExec : ChannelSession
{
bool xforwading=false;
bool pty=false;
String command="";
/*
ChannelExec(){
super();
type="session".getBytes();
io=new IO();
}
*/
public override void setXForwarding(bool foo){ xforwading=foo; }
public void setPty(bool foo){ pty=foo; }
public override void start()
{
try
{
Request request;
if(xforwading)
{
request=new RequestX11();
request.request(session, this);
}
if(pty)
{
request=new RequestPtyReq();
request.request(session, this);
}
request=new RequestExec(command);
request.request(session, this);
}
catch(Exception e)
{
throw new JSchException("ChannelExec");
}
thread=new Thread(this);
thread.setName("Exec thread "+session.getHost());
thread.start();
}
public void setCommand(String foo){ command=foo;}
public override void init()
{
io.setInputStream(session.In);
io.setOutputStream(session.Out);
}
//public void finalize() throws java.lang.Throwable{ super.finalize(); }
public void setErrStream(Stream Out)
{
setExtOutputStream(Out);
}
public Stream getErrStream()
{
return getExtInputStream();
}
}
}

View file

@ -1,310 +0,0 @@
using System;
using System.IO;
using Tamir.SharpSsh.java.util;
using Tamir.SharpSsh.java.net;
using Tamir.SharpSsh.java.lang;
using Str = Tamir.SharpSsh.java.String;
namespace Tamir.SharpSsh.jsch
{
/* -*-mode:java; c-basic-offset:2; -*- */
/*
Copyright (c) 2002,2003,2004 ymnk, JCraft,Inc. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the distribution.
3. The names of the authors may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
public class ChannelForwardedTCPIP : Channel
{
internal static java.util.Vector pool=new java.util.Vector();
// static private final int LOCAL_WINDOW_SIZE_MAX=0x20000;
static private int LOCAL_WINDOW_SIZE_MAX=0x100000;
static private int LOCAL_MAXIMUM_PACKET_SIZE=0x4000;
internal SocketFactory factory=null;
internal String target;
internal int lport;
internal int rport;
internal ChannelForwardedTCPIP() : base()
{
setLocalWindowSizeMax(LOCAL_WINDOW_SIZE_MAX);
setLocalWindowSize(LOCAL_WINDOW_SIZE_MAX);
setLocalPacketSize(LOCAL_MAXIMUM_PACKET_SIZE);
}
public override void init ()
{
try
{
io=new IO();
if(lport==-1)
{
Class c=Class.forName(target);
ForwardedTCPIPDaemon daemon=(ForwardedTCPIPDaemon)c.newInstance();
daemon.setChannel(this);
Object[] foo=getPort(session, rport);
daemon.setArg((Object[])foo[3]);
new Thread(daemon).start();
connected=true;
return;
}
else
{
Socket socket=(factory==null) ?
new Socket(target, lport) :
factory.createSocket(target, lport);
socket.setTcpNoDelay(true);
io.setInputStream(socket.getInputStream());
io.setOutputStream(socket.getOutputStream());
connected=true;
}
}
catch(Exception e)
{
Console.WriteLine("target={0},port={1}",target,lport);
Console.WriteLine(e);
}
}
public override void run()
{
thread=Thread.currentThread();
Buffer buf=new Buffer(rmpsize);
Packet packet=new Packet(buf);
int i=0;
try
{
while(thread!=null && io!=null && io.ins!=null)
{
i=io.ins.Read(buf.buffer,
14,
buf.buffer.Length-14
-32 -20 // padding and mac
);
if(i<=0)
{
eof();
break;
}
packet.reset();
if(_close)break;
buf.putByte((byte)Session.SSH_MSG_CHANNEL_DATA);
buf.putInt(recipient);
buf.putInt(i);
buf.skip(i);
session.write(packet, this, i);
}
}
catch(Exception e)
{
//System.out.println(e);
}
//thread=null;
//eof();
disconnect();
}
internal override void getData(Buffer buf)
{
setRecipient(buf.getInt());
setRemoteWindowSize(buf.getInt());
setRemotePacketSize(buf.getInt());
byte[] addr=buf.getString();
int port=buf.getInt();
byte[] orgaddr=buf.getString();
int orgport=buf.getInt();
/*
System.out.println("addr: "+new String(addr));
System.out.println("port: "+port);
System.out.println("orgaddr: "+new String(orgaddr));
System.out.println("orgport: "+orgport);
*/
lock(pool)
{
for(int i=0; i<pool.size(); i++)
{
Object[] foo=(Object[])(pool.elementAt(i));
if(foo[0]!=session) continue;
if(((Integer)foo[1]).intValue()!=port) continue;
this.rport=port;
this.target=(String)foo[2];
if(foo[3]==null || (foo[3] is Object[])){ this.lport=-1; }
else{ this.lport=((Integer)foo[3]).intValue(); }
if(foo.Length>=5)
{
this.factory=((SocketFactory)foo[4]);
}
break;
}
if(target==null)
{
Console.WriteLine("??");
}
}
}
internal static Object[] getPort(Session session, int rport)
{
lock(pool)
{
for(int i=0; i<pool.size(); i++)
{
Object[] bar=(Object[])(pool.elementAt(i));
if(bar[0]!=session) continue;
if(((Integer)bar[1]).intValue()!=rport) continue;
return bar;
}
return null;
}
}
internal static String[] getPortForwarding(Session session)
{
java.util.Vector foo=new java.util.Vector();
lock(pool)
{
for(int i=0; i<pool.size(); i++)
{
Object[] bar=(Object[])(pool.elementAt(i));
if(bar[0]!=session) continue;
if(bar[3]==null){ foo.addElement(bar[1]+":"+bar[2]+":"); }
else{ foo.addElement(bar[1]+":"+bar[2]+":"+bar[3]); }
}
}
String[] bar2=new String[foo.size()];
for(int i=0; i<foo.size(); i++)
{
bar2[i]=(String)(foo.elementAt(i));
}
return bar2;
}
internal static void addPort(Session session, int port, String target, int lport, SocketFactory factory)
{
lock(pool)
{
if(getPort(session, port)!=null)
{
throw new JSchException("PortForwardingR: remote port "+port+" is already registered.");
}
Object[] foo=new Object[5];
foo[0]=session; foo[1]=new Integer(port);
foo[2]=target; foo[3]=new Integer(lport);
foo[4]=factory;
pool.addElement(foo);
}
}
internal static void addPort(Session session, int port, String daemon, Object[] arg)
{
lock(pool)
{
if(getPort(session, port)!=null)
{
throw new JSchException("PortForwardingR: remote port "+port+" is already registered.");
}
Object[] foo=new Object[4];
foo[0]=session; foo[1]=new Integer(port);
foo[2]=daemon; foo[3]=arg;
pool.addElement(foo);
}
}
internal static void delPort(ChannelForwardedTCPIP c)
{
delPort(c.session, c.rport);
}
internal static void delPort(Session session, int rport)
{
lock(pool)
{
Object[] foo=null;
for(int i=0; i<pool.size(); i++)
{
Object[] bar=(Object[])(pool.elementAt(i));
if(bar[0]!=session) continue;
if(((Integer)bar[1]).intValue()!=rport) continue;
foo=bar;
break;
}
if(foo==null)return;
pool.removeElement(foo);
}
Buffer buf=new Buffer(100); // ??
Packet packet=new Packet(buf);
try
{
// byte SSH_MSG_GLOBAL_REQUEST 80
// string "cancel-tcpip-forward"
// boolean want_reply
// string address_to_bind (e.g. "127.0.0.1")
// uint32 port number to bind
packet.reset();
buf.putByte((byte) 80/*SSH_MSG_GLOBAL_REQUEST*/);
buf.putString(new Str("cancel-tcpip-forward").getBytes());
buf.putByte((byte)0);
buf.putString(new Str("0.0.0.0").getBytes());
buf.putInt(rport);
session.write(packet);
}
catch(Exception e)
{
// throw new JSchException(e.toString());
}
}
internal static void delPort(Session session)
{
int[] rport=null;
int count=0;
lock(pool)
{
rport=new int[pool.size()];
for(int i=0; i<pool.size(); i++)
{
Object[] bar=(Object[])(pool.elementAt(i));
if(bar[0]==session)
{
rport[count++]=((Integer)bar[1]).intValue();
}
}
}
for(int i=0; i<count; i++)
{
delPort(session, rport[i]);
}
}
public int getRemotePort(){return rport;}
void setSocketFactory(SocketFactory factory)
{
this.factory=factory;
}
}
}

View file

@ -1,96 +0,0 @@
using System;
using Tamir.SharpSsh.java.lang;
using Str = Tamir.SharpSsh.java.String;
namespace Tamir.SharpSsh.jsch
{
/* -*-mode:java; c-basic-offset:2; -*- */
/*
Copyright (c) 2002,2003,2004 ymnk, JCraft,Inc. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the distribution.
3. The names of the authors may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
public class ChannelSession : Channel
{
private static byte[] _session=new Str("session").getBytes();
public ChannelSession():base()
{
type=_session;
io=new IO();
}
public override void run()
{
//System.out.println(this+":run >");
/*
if(thread!=null){ return; }
thread=Thread.currentThread();
*/
// Buffer buf=new Buffer();
Buffer buf=new Buffer(rmpsize);
Packet packet=new Packet(buf);
int i=-1;
try
{
while(isConnected() &&
thread!=null &&
io!=null &&
io.ins!=null)
{
i=io.ins.Read(buf.buffer,
14,
buf.buffer.Length-14
-32 -20 // padding and mac
);
if(i==0)continue;
if(i==-1)
{
eof();
break;
}
if(_close)break;
packet.reset();
buf.putByte((byte)Session.SSH_MSG_CHANNEL_DATA);
buf.putInt(recipient);
buf.putInt(i);
buf.skip(i);
session.write(packet, this, i);
}
}
catch(Exception e)
{
Console.WriteLine("# ChannelSession.run");
Console.WriteLine(e);
}
if(thread!=null)
{
//lock(thread){ System.Threading.Monitor.PulseAll(this);/*thread.notifyAll();*/ }
}
thread=null;
//System.out.println(this+":run <");
}
}
}

File diff suppressed because it is too large Load diff

View file

@ -1,157 +0,0 @@
//using System;
//using System.IO;
//
//namespace Tamir.SharpSsh.jsch
//{
// public class InputStreamGet : java.io.InputStream
// {
// bool closed=false;
// int rest_length=0;
// byte[] _data=new byte[1];
// ChannelSftp sftp;
// byte[] handle;
// long[] _offset;
// int[]_server_version;
// SftpProgressMonitor monitor;
//
// public InputStreamGet(
// ChannelSftp sftp,
// byte[] handle,
// long[] _offset,
// int[] _server_version,
// SftpProgressMonitor monitor)
// {
// this.sftp=sftp;
// this.handle=handle;
// this._offset=_offset;
// this._server_version=_server_version;
// this.monitor=monitor;
// }
//
// public override int ReadByte()
// {
// int i=read(_data, 0, 1);
// if (i==-1) { return -1; }
// else
// {
// return _data[0]&0xff;
// }
// }
// public override int read(byte[] d)
// {
// return Read(d, 0, d.Length);
// }
// public override int Read(byte[] d, int s, int len)
// {
// if(d==null){throw new NullReferenceException();}
// if(s<0 || len <0 || s+len>d.Length)
// {
// throw new ArgumentOutOfRangeException();
// }
// if(len==0){ return 0; }
//
// if(rest_length>0)
// {
// int foo=rest_length;
// if(foo>len) foo=len;
// int i=sftp.io.ins.read(d, s, foo);
// if(i<0)
// {
// throw new IOException("error");
// }
// rest_length-=i;
// return i;
// }
//
// if(sftp.buf.buffer.length-13<len)
// {
// len=sftp.buf.buffer.length-13;
// }
// if(sftp.server_version==0 && len>1024)
// {
// len=1024;
// }
//
// try{sftp.sendREAD(handle, offset, len);}
// catch(Exception e){ throw new IOException("error"); }
//
// sftp.buf.rewind();
// int i=io.ins.read(buf.buffer, 0, 13); // 4 + 1 + 4 + 4
// if(i!=13)
// {
// throw new IOException("error");
// }
//
// rest_length=sftp.buf.getInt();
// int type=sftp.buf.getByte();
// rest_length--;
// sftp.buf.getInt();
// rest_length-=4;
// if(type!=sftp.SSH_FXP_STATUS && type!=SSH_FXP_DATA)
// {
// throw new IOException("error");
// }
// if(type==sftp.SSH_FXP_STATUS)
// {
// i=buf.getInt();
// rest_length-=4;
// sftp.io.ins.read(sftp.buf.buffer, 13, rest_length);
// rest_length=0;
// if(i==SSH_FX_EOF)
// {
// close();
// return -1;
// }
// //throwStatusError(buf, i);
// throw new IOException("error");
// }
//
// i=buf.getInt();
// rest_length-=4;
// offset+=rest_length;
// int foo=i;
// if(foo>0)
// {
// int bar=rest_length;
// if(bar>len)
// {
// bar=len;
// }
// i=io.ins.read(d, s, bar);
// if(i<0)
// {
// return -1;
// }
// rest_length-=i;
//
// if(monitor!=null)
// {
// if(!monitor.count(i))
// {
// return -1;
// }
// }
// return i;
// }
// return 0; // ??
// }
// public override void Close()
// {
// if(closed)return;
// closed=true;
// /*
// while(rest_length>0){
// int foo=rest_length;
// if(foo>buf.buffer.length){
// foo=buf.buffer.length;
// }
// io.in.read(buf.buffer, 0, foo);
// rest_length-=foo;
// }
// */
// if(monitor!=null)monitor.end();
// try{sftp._sendCLOSE(handle);}
// catch(Exception e){throw new IOException("error");}
// }
// }
//}

View file

@ -1,116 +0,0 @@
using System;
using System.IO;
namespace Tamir.SharpSsh.jsch
{
internal class OutputStreamPut : java.io.OutputStream
{
ChannelSftp sftp;
byte[] handle;
long[] _offset;
SftpProgressMonitor monitor;
private bool init=true;
private int[] ackid=new int[1];
private int startid=0;
private int _ackid=0;
private int ackcount=0;
private ChannelSftp.Header header=new ChannelSftp.Header();
internal OutputStreamPut
(ChannelSftp sftp,
byte[] handle,
long[] _offset,
SftpProgressMonitor monitor):base()
{
this.sftp=sftp;
this.handle=handle;
this._offset=_offset;
this.monitor=monitor;
}
public override void Write(byte[] d, int s, int len)
{
if(init)
{
startid=sftp.seq;
_ackid=sftp.seq;
init=false;
}
try
{
int _len=len;
while(_len>0)
{
int sent=sftp.sendWRITE(handle, _offset[0], d, s, _len);
_offset[0]+=sent;
s+=sent;
_len-=sent;
if((sftp.seq-1)==startid ||
sftp.io.ins.available()>=1024)
{
while(sftp.io.ins.available()>0)
{
if(sftp.checkStatus(ackid, header))
{
_ackid=ackid[0];
if(startid>_ackid || _ackid>sftp.seq-1)
{
throw new SftpException(ChannelSftp.SSH_FX_FAILURE, "");
}
ackcount++;
}
else
{
break;
}
}
}
}
if(monitor!=null && !monitor.count(len))
{
close();
throw new IOException("canceled");
}
}
catch(IOException e){ throw e; }
catch(Exception e){ throw new IOException(e.ToString()); }
}
byte[] _data=new byte[1];
public void write(int foo)
{
_data[0]=(byte)foo;
Write(_data, 0, 1);
}
public override void Close()
{
if(!init)
{
try
{
int _ackcount=sftp.seq-startid;
while(_ackcount>ackcount)
{
if(!sftp.checkStatus(null, header))
{
break;
}
ackcount++;
}
}
catch(SftpException e)
{
throw new IOException(e.toString());
}
}
if(monitor!=null)monitor.end();
try{ sftp._sendCLOSE(handle, header); }
catch(IOException e){ throw e; }
catch(Exception e)
{
throw new IOException(e.ToString());
}
}
}
}

View file

@ -1,89 +0,0 @@
using System;
using Tamir.SharpSsh.java.lang;
namespace Tamir.SharpSsh.jsch
{
/* -*-mode:java; c-basic-offset:2; -*- */
/*
Copyright (c) 2002,2003,2004 ymnk, JCraft,Inc. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the distribution.
3. The names of the authors may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
public class ChannelShell : ChannelSession
{
internal bool xforwading=false;
internal bool pty=true;
public override void setXForwarding(bool foo){ xforwading=foo; }
public void setPty(bool foo){ pty=foo; }
public override void start()
{
try
{
Request request;
if(xforwading)
{
request=new RequestX11();
request.request(session, this);
}
if(pty)
{
request=new RequestPtyReq();
request.request(session, this);
}
request=new RequestShell();
request.request(session, this);
}
catch//(Exception e)
{
throw new JSchException("ChannelShell");
}
thread=new Thread(this);
thread.setName("Shell for "+session.host);
thread.start();
}
public override void init()
{
io.setInputStream(session.In);
io.setOutputStream(session.Out);
}
public void setPtySize(int col, int row, int wp, int hp)
{
//if(thread==null) return;
try
{
RequestWindowChange request=new RequestWindowChange();
request.setSize(col, row, wp, hp);
request.request(session, this);
}
catch(Exception e)
{
throw new JSchException("ChannelShell.setPtySize: "+e.ToString());
}
}
}
}

View file

@ -1,89 +0,0 @@
/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
/*
Copyright (c) 2005 ymnk, JCraft,Inc. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the distribution.
3. The names of the authors may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
using System;
using Tamir.SharpSsh.java.net;
using Tamir.SharpSsh.java.lang;
namespace Tamir.SharpSsh.jsch
{
public class ChannelSubsystem : ChannelSession
{
bool xforwading=false;
bool pty=false;
bool want_reply=true;
String subsystem="";
public override void setXForwarding(bool foo){ xforwading=true; }
public void setPty(bool foo){ pty=foo; }
public void setWantReply(bool foo){ want_reply=foo; }
public void setSubsystem(String foo){ subsystem=foo; }
public override void start()
{
try
{
Request request;
if(xforwading)
{
request=new RequestX11();
request.request(session, this);
}
if(pty)
{
request=new RequestPtyReq();
request.request(session, this);
}
request=new RequestSubsystem();
((RequestSubsystem)request).request(session, this, subsystem, want_reply);
}
catch(Exception e)
{
if(e is JSchException){ throw (JSchException)e; }
throw new JSchException("ChannelSubsystem");
}
Thread thread=new Thread(this);
thread.setName("Subsystem for "+session.host);
thread.start();
}
//public void finalize() throws Throwable{ super.finalize(); }
public override void init()
{
io.setInputStream(session.In);
io.setOutputStream(session.Out);
}
public void setErrStream(System.IO.Stream outs)
{
setExtOutputStream(outs);
}
public java.io.InputStream getErrStream()
{
return getExtInputStream();
}
}
}

View file

@ -1,257 +0,0 @@
using System;
using System.Net;
using System.Net.Sockets;
using Tamir.SharpSsh.java.lang;
namespace Tamir.SharpSsh.jsch
{
/* -*-mode:java; c-basic-offset:2; -*- */
/*
Copyright (c) 2002,2003,2004 ymnk, JCraft,Inc. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the distribution.
3. The names of the authors may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
internal class ChannelX11 : Channel
{
private const int LOCAL_WINDOW_SIZE_MAX=0x20000;
private const int LOCAL_MAXIMUM_PACKET_SIZE=0x4000;
internal static String host="127.0.0.1";
internal static int port=6000;
internal bool _init=true;
internal static byte[] cookie=null;
//static byte[] cookie_hex="0c281f065158632a427d3e074d79265d".getBytes();
internal static byte[] cookie_hex=null;
private static System.Collections.Hashtable faked_cookie_pool=new System.Collections.Hashtable();
private static System.Collections.Hashtable faked_cookie_hex_pool=new System.Collections.Hashtable();
internal static byte[] table={0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,
0x61,0x62,0x63,0x64,0x65,0x66};
internal static int revtable(byte foo)
{
for(int i=0; i<table.Length; i++)
{
if(table[i]==foo)return i;
}
return 0;
}
internal static void setCookie(String foo)
{
cookie_hex=Util.getBytes(foo);
cookie=new byte[16];
for(int i=0; i<16; i++)
{
cookie[i]=(byte)(((revtable(cookie_hex[i*2])<<4)&0xf0) |
((revtable(cookie_hex[i*2+1]))&0xf));
}
}
internal static void setHost(String foo){ host=foo; }
internal static void setPort(int foo){ port=foo; }
internal static byte[] getFakedCookie(Session session)
{
lock(faked_cookie_hex_pool)
{
byte[] foo=(byte[])faked_cookie_hex_pool[session];
if(foo==null)
{
Random random=Session.random;
foo=new byte[16];
lock(random)
{
random.fill(foo, 0, 16);
}
/*
System.out.print("faked_cookie: ");
for(int i=0; i<foo.length; i++){
System.out.print(Integer.toHexString(foo[i]&0xff)+":");
}
System.out.println("");
*/
faked_cookie_pool.Add(session, foo);
byte[] bar=new byte[32];
for(int i=0; i<16; i++)
{
bar[2*i]=table[(foo[i]>>4)&0xf];
bar[2*i+1]=table[(foo[i])&0xf];
}
faked_cookie_hex_pool.Add(session, bar);
foo=bar;
}
return foo;
}
}
Socket socket = null;
internal ChannelX11():base()
{
setLocalWindowSizeMax(LOCAL_WINDOW_SIZE_MAX);
setLocalWindowSize(LOCAL_WINDOW_SIZE_MAX);
setLocalPacketSize(LOCAL_MAXIMUM_PACKET_SIZE);
type=Util.getBytes("x11");
try
{
IPEndPoint ep = new IPEndPoint(Dns.GetHostByName(host).AddressList[0], port);
socket=new Socket(ep.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.NoDelay, 1);
socket.Connect(ep);
io=new IO();
NetworkStream ns = new NetworkStream( socket );
io.setInputStream(ns);
io.setOutputStream(ns);
}
catch(Exception e)
{
Console.WriteLine(e);
}
}
public override void run()
{
thread=Thread.currentThread();
Buffer buf=new Buffer(rmpsize);
Packet packet=new Packet(buf);
int i=0;
try
{
while(thread!=null)
{
i=io.ins.Read(buf.buffer,
14,
buf.buffer.Length-14
-16 -20 // padding and mac
);
if(i<=0)
{
eof();
break;
}
if(_close)break;
packet.reset();
buf.putByte((byte)Session.SSH_MSG_CHANNEL_DATA);
buf.putInt(recipient);
buf.putInt(i);
buf.skip(i);
session.write(packet, this, i);
}
}
catch
{
//System.out.println(e);
}
thread=null;
}
internal override void write(byte[] foo, int s, int l)
{
//if(eof_local)return;
if(_init)
{
int plen=(foo[s+6]&0xff)*256+(foo[s+7]&0xff);
int dlen=(foo[s+8]&0xff)*256+(foo[s+9]&0xff);
if((foo[s]&0xff)==0x42)
{
}
else if((foo[s]&0xff)==0x6c)
{
plen=(int)(((uint)plen>>8)&0xff)|((plen<<8)&0xff00);
dlen=(int)(((uint)dlen>>8)&0xff)|((dlen<<8)&0xff00);
}
else
{
// ??
}
byte[] bar=new byte[dlen];
Array.Copy(foo, s+12+plen+((-plen)&3), bar, 0, dlen);
byte[] faked_cookie=(byte[])faked_cookie_pool[session];
if(equals(bar, faked_cookie))
{
if(cookie!=null)
Array.Copy(cookie, 0, foo, s+12+plen+((-plen)&3), dlen);
}
else
{
Console.WriteLine("wrong cookie");
}
_init=false;
}
io.put(foo, s, l);
}
public override void disconnect()
{
close();
thread=null;
try
{
if(io!=null)
{
try
{
if(io.ins!=null)
io.ins.Close();
}
catch{}
try
{
if(io.outs!=null)
io.outs.Close();
}
catch{}
}
try
{
if(socket!=null)
socket.Close();
}
catch{}
}
catch(Exception e)
{
Console.WriteLine(e.StackTrace);
}
io=null;
Channel.del(this);
}
private static bool equals(byte[] foo, byte[] bar)
{
if(foo.Length!=bar.Length)return false;
for(int i=0; i<foo.Length; i++)
{
if(foo[i]!=bar[i])return false;
}
return true;
}
}
}

View file

@ -1,43 +0,0 @@
using System;
namespace Tamir.SharpSsh.jsch
{
/* -*-mode:java; c-basic-offset:2; -*- */
/*
Copyright (c) 2002,2003,2004 ymnk, JCraft,Inc. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the distribution.
3. The names of the authors may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
public abstract class Cipher
{
internal static int ENCRYPT_MODE=0;
internal static int DECRYPT_MODE=1;
public abstract int getIVSize();
public abstract int getBlockSize();
public abstract void init(int mode, byte[] key, byte[] iv);
public abstract void update(byte[] foo, int s1, int len, byte[] bar, int s2);
}
}

View file

@ -1,42 +0,0 @@
using System;
namespace Tamir.SharpSsh.jsch
{
/* -*-mode:java; c-basic-offset:2; -*- */
/*
Copyright (c) 2002,2003,2004 ymnk, JCraft,Inc. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the distribution.
3. The names of the authors may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
public abstract class Compression
{
public const int INFLATER=0;
public const int DEFLATER=1;
public abstract void init(int type, int level);
public abstract int compress(byte[] buf, int start, int len);
public abstract byte[] uncompress(byte[] buf, int start, int[] len);
}
}

View file

@ -1,43 +0,0 @@
using System;
namespace Tamir.SharpSsh.jsch
{
/* -*-mode:java; c-basic-offset:2; -*- */
/*
Copyright (c) 2002,2003,2004 ymnk, JCraft,Inc. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the distribution.
3. The names of the authors may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
public interface DH
{
void init();
void setP(byte[] p);
void setG(byte[] g);
byte[] getE();
void setF(byte[] f);
byte[] getK();
}
}

View file

@ -1,314 +0,0 @@
using System;
namespace Tamir.SharpSsh.jsch
{
/* -*-mode:java; c-basic-offset:2; -*- */
/*
Copyright (c) 2002,2003,2004 ymnk, JCraft,Inc. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the distribution.
3. The names of the authors may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
public class DHG1 : KeyExchange
{
internal static byte[] g=new byte[]{ 2 };
internal static byte[] p=new byte[]{
(byte)0x00,
(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF,
(byte)0xC9,(byte)0x0F,(byte)0xDA,(byte)0xA2,(byte)0x21,(byte)0x68,(byte)0xC2,(byte)0x34,
(byte)0xC4,(byte)0xC6,(byte)0x62,(byte)0x8B,(byte)0x80,(byte)0xDC,(byte)0x1C,(byte)0xD1,
(byte)0x29,(byte)0x02,(byte)0x4E,(byte)0x08,(byte)0x8A,(byte)0x67,(byte)0xCC,(byte)0x74,
(byte)0x02,(byte)0x0B,(byte)0xBE,(byte)0xA6,(byte)0x3B,(byte)0x13,(byte)0x9B,(byte)0x22,
(byte)0x51,(byte)0x4A,(byte)0x08,(byte)0x79,(byte)0x8E,(byte)0x34,(byte)0x04,(byte)0xDD,
(byte)0xEF,(byte)0x95,(byte)0x19,(byte)0xB3,(byte)0xCD,(byte)0x3A,(byte)0x43,(byte)0x1B,
(byte)0x30,(byte)0x2B,(byte)0x0A,(byte)0x6D,(byte)0xF2,(byte)0x5F,(byte)0x14,(byte)0x37,
(byte)0x4F,(byte)0xE1,(byte)0x35,(byte)0x6D,(byte)0x6D,(byte)0x51,(byte)0xC2,(byte)0x45,
(byte)0xE4,(byte)0x85,(byte)0xB5,(byte)0x76,(byte)0x62,(byte)0x5E,(byte)0x7E,(byte)0xC6,
(byte)0xF4,(byte)0x4C,(byte)0x42,(byte)0xE9,(byte)0xA6,(byte)0x37,(byte)0xED,(byte)0x6B,
(byte)0x0B,(byte)0xFF,(byte)0x5C,(byte)0xB6,(byte)0xF4,(byte)0x06,(byte)0xB7,(byte)0xED,
(byte)0xEE,(byte)0x38,(byte)0x6B,(byte)0xFB,(byte)0x5A,(byte)0x89,(byte)0x9F,(byte)0xA5,
(byte)0xAE,(byte)0x9F,(byte)0x24,(byte)0x11,(byte)0x7C,(byte)0x4B,(byte)0x1F,(byte)0xE6,
(byte)0x49,(byte)0x28,(byte)0x66,(byte)0x51,(byte)0xEC,(byte)0xE6,(byte)0x53,(byte)0x81,
(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF
};
internal const int SSH_MSG_KEXDH_INIT= 30;
internal const int SSH_MSG_KEXDH_REPLY= 31;
internal const int RSA=0;
internal const int DSS=1;
private int type=0;
private int state;
internal DH dh;
// HASH sha;
// byte[] K;
// byte[] H;
internal byte[] V_S;
internal byte[] V_C;
internal byte[] I_S;
internal byte[] I_C;
// byte[] K_S;
internal byte[] e;
private Buffer buf;
private Packet packet;
public override void init(Session session,
byte[] V_S, byte[] V_C, byte[] I_S, byte[] I_C)
{
this.session=session;
this.V_S=V_S;
this.V_C=V_C;
this.I_S=I_S;
this.I_C=I_C;
// sha=new SHA1();
// sha.init();
try
{
Type t=Type.GetType(session.getConfig("sha-1"));
sha=(HASH)(Activator.CreateInstance(t));
sha.init();
}
catch(Exception ee)
{
Console.WriteLine(ee);
}
buf=new Buffer();
packet=new Packet(buf);
try
{
Type t=Type.GetType(session.getConfig("dh"));
dh=(DH)(Activator.CreateInstance(t));
dh.init();
}
catch(Exception ee)
{
throw ee;
}
dh.setP(p);
dh.setG(g);
// The client responds with:
// byte SSH_MSG_KEXDH_INIT(30)
// mpint e <- g^x mod p
// x is a random number (1 < x < (p-1)/2)
e=dh.getE();
packet.reset();
buf.putByte((byte)SSH_MSG_KEXDH_INIT);
buf.putMPInt(e);
session.write(packet);
state=SSH_MSG_KEXDH_REPLY;
}
public override bool next(Buffer _buf)
{
int i,j;
bool result = false;
switch(state)
{
case SSH_MSG_KEXDH_REPLY:
// The server responds with:
// byte SSH_MSG_KEXDH_REPLY(31)
// string server public host key and certificates (K_S)
// mpint f
// string signature of H
j=_buf.getInt();
j=_buf.getByte();
j=_buf.getByte();
if(j!=31)
{
Console.WriteLine("type: must be 31 "+j);
result = false;
break;
}
K_S=_buf.getString();
// K_S is server_key_blob, which includes ....
// string ssh-dss
// impint p of dsa
// impint q of dsa
// impint g of dsa
// impint pub_key of dsa
//System.out.print("K_S: "); //dump(K_S, 0, K_S.length);
byte[] f=_buf.getMPInt();
byte[] sig_of_H=_buf.getString();
/*
for(int ii=0; ii<sig_of_H.length;ii++){
System.out.print(Integer.toHexString(sig_of_H[ii]&0xff));
System.out.print(": ");
}
Console.WriteLine("");
*/
dh.setF(f);
K=dh.getK();
//The hash H is computed as the HASH hash of the concatenation of the
//following:
// string V_C, the client's version string (CR and NL excluded)
// string V_S, the server's version string (CR and NL excluded)
// string I_C, the payload of the client's SSH_MSG_KEXINIT
// string I_S, the payload of the server's SSH_MSG_KEXINIT
// string K_S, the host key
// mpint e, exchange value sent by the client
// mpint f, exchange value sent by the server
// mpint K, the shared secret
// This value is called the exchange hash, and it is used to authenti-
// cate the key exchange.
buf.reset();
buf.putString(V_C); buf.putString(V_S);
buf.putString(I_C); buf.putString(I_S);
buf.putString(K_S);
buf.putMPInt(e); buf.putMPInt(f);
buf.putMPInt(K);
byte[] foo=new byte[buf.getLength()];
buf.getByte(foo);
sha.update(foo, 0, foo.Length);
H=sha.digest();
//System.out.print("H -> "); //dump(H, 0, H.length);
i=0;
j=0;
j=(int)((K_S[i++]<<24)&0xff000000)|((K_S[i++]<<16)&0x00ff0000)|
((K_S[i++]<<8)&0x0000ff00)|((K_S[i++])&0x000000ff);
String alg=Util.getString(K_S, i, j);
i+=j;
result=false;
if(alg.Equals("ssh-rsa"))
{
byte[] tmp;
byte[] ee;
byte[] n;
type=RSA;
j=(int)((K_S[i++]<<24)&0xff000000)|((K_S[i++]<<16)&0x00ff0000)|
((K_S[i++]<<8)&0x0000ff00)|((K_S[i++])&0x000000ff);
tmp=new byte[j]; Array.Copy(K_S, i, tmp, 0, j); i+=j;
ee=tmp;
j=(int)((K_S[i++]<<24)&0xff000000)|((K_S[i++]<<16)&0x00ff0000)|
((K_S[i++]<<8)&0x0000ff00)|((K_S[i++])&0x000000ff);
tmp=new byte[j]; Array.Copy(K_S, i, tmp, 0, j); i+=j;
n=tmp;
// SignatureRSA sig=new SignatureRSA();
// sig.init();
SignatureRSA sig=null;
try
{
Type t=Type.GetType(session.getConfig("signature.rsa"));
sig=(SignatureRSA)(Activator.CreateInstance(t));
sig.init();
}
catch(Exception eee)
{
Console.WriteLine(eee);
}
sig.setPubKey(ee, n);
sig.update(H);
result=sig.verify(sig_of_H);
//MainClass.dump(ee, n, sig_of_H, H);
}
else if(alg.Equals("ssh-dss"))
{
byte[] q=null;
byte[] tmp;
byte[] p;
byte[] g;
type=DSS;
j=(int)((K_S[i++]<<24)&0xff000000)|((K_S[i++]<<16)&0x00ff0000)|
((K_S[i++]<<8)&0x0000ff00)|((K_S[i++])&0x000000ff);
tmp=new byte[j]; Array.Copy(K_S, i, tmp, 0, j); i+=j;
p=tmp;
j=(int)((K_S[i++]<<24)&0xff000000)|((K_S[i++]<<16)&0x00ff0000)|
((K_S[i++]<<8)&0x0000ff00)|((K_S[i++])&0x000000ff);
tmp=new byte[j]; Array.Copy(K_S, i, tmp, 0, j); i+=j;
q=tmp;
j=(int)((K_S[i++]<<24)&0xff000000)|((K_S[i++]<<16)&0x00ff0000)|
((K_S[i++]<<8)&0x0000ff00)|((K_S[i++])&0x000000ff);
tmp=new byte[j]; Array.Copy(K_S, i, tmp, 0, j); i+=j;
g=tmp;
j=(int)((K_S[i++]<<24)&0xff000000)|((K_S[i++]<<16)&0x00ff0000)|
((K_S[i++]<<8)&0x0000ff00)|((K_S[i++])&0x000000ff);
tmp=new byte[j]; Array.Copy(K_S, i, tmp, 0, j); i+=j;
f=tmp;
// SignatureDSA sig=new SignatureDSA();
// sig.init();
SignatureDSA sig=null;
try
{
Type t=Type.GetType(session.getConfig("signature.dss"));
sig=(SignatureDSA)(Activator.CreateInstance(t));
sig.init();
}
catch(Exception ee)
{
Console.WriteLine(ee);
}
sig.setPubKey(f, p, q, g);
sig.update(H);
result=sig.verify(sig_of_H);
}
else
{
Console.WriteLine("unknow alg");
}
state=STATE_END;
break;
}
return result;
}
public override String getKeyType()
{
if(type==DSS) return "DSA";
return "RSA";
}
public override int getState(){return state; }
}
}

View file

@ -1,340 +0,0 @@
using System;
namespace Tamir.SharpSsh.jsch
{
/* -*-mode:java; c-basic-offset:2; -*- */
/*
Copyright (c) 2002,2003,2004 ymnk, JCraft,Inc. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the distribution.
3. The names of the authors may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
public class DHGEX : KeyExchange
{
internal const int SSH_MSG_KEX_DH_GEX_GROUP= 31;
internal const int SSH_MSG_KEX_DH_GEX_INIT= 32;
internal const int SSH_MSG_KEX_DH_GEX_REPLY= 33;
internal static int min=1024;
// static int min=512;
internal static int preferred=1024;
internal static int max=1024;
// static int preferred=1024;
// static int max=2000;
internal const int RSA=0;
internal const int DSS=1;
private int type=0;
private int state;
// com.jcraft.jsch.DH dh;
internal DH dh;
internal byte[] V_S;
internal byte[] V_C;
internal byte[] I_S;
internal byte[] I_C;
private Buffer buf;
private Packet packet;
private byte[] p;
private byte[] g;
private byte[] e;
//private byte[] f;
public override void init(Session session,
byte[] V_S, byte[] V_C, byte[] I_S, byte[] I_C)
{
this.session=session;
this.V_S=V_S;
this.V_C=V_C;
this.I_S=I_S;
this.I_C=I_C;
// sha=new SHA1();
// sha.init();
try
{
Type t=Type.GetType(session.getConfig("sha-1"));
sha=(HASH)(Activator.CreateInstance(t));
sha.init();
}
catch(Exception e)
{
Console.WriteLine(e);
}
buf=new Buffer();
packet=new Packet(buf);
try
{
Type t=Type.GetType(session.getConfig("dh"));
dh=(DH)(Activator.CreateInstance(t));
dh.init();
}
catch(Exception e)
{
throw e;
}
packet.reset();
buf.putByte((byte)0x22);
buf.putInt(min);
buf.putInt(preferred);
buf.putInt(max);
session.write(packet);
state=SSH_MSG_KEX_DH_GEX_GROUP;
}
public override bool next(Buffer _buf)
{
int i,j;
bool result=false;
switch(state)
{
case SSH_MSG_KEX_DH_GEX_GROUP:
// byte SSH_MSG_KEX_DH_GEX_GROUP(31)
// mpint p, safe prime
// mpint g, generator for subgroup in GF (p)
_buf.getInt();
_buf.getByte();
j=_buf.getByte();
if(j!=31)
{
Console.WriteLine("type: must be 31 "+j);
result = false;
}
p=_buf.getMPInt();
g=_buf.getMPInt();
/*
for(int iii=0; iii<p.length; iii++){
System.out.println("0x"+Integer.toHexString(p[iii]&0xff)+",");
}
System.out.println("");
for(int iii=0; iii<g.length; iii++){
System.out.println("0x"+Integer.toHexString(g[iii]&0xff)+",");
}
*/
dh.setP(p);
dh.setG(g);
// The client responds with:
// byte SSH_MSG_KEX_DH_GEX_INIT(32)
// mpint e <- g^x mod p
// x is a random number (1 < x < (p-1)/2)
e=dh.getE();
packet.reset();
buf.putByte((byte)0x20);
buf.putMPInt(e);
session.write(packet);
state=SSH_MSG_KEX_DH_GEX_REPLY;
result = true;
break;
case SSH_MSG_KEX_DH_GEX_REPLY:
// The server responds with:
// byte SSH_MSG_KEX_DH_GEX_REPLY(33)
// string server public host key and certificates (K_S)
// mpint f
// string signature of H
j=_buf.getInt();
j=_buf.getByte();
j=_buf.getByte();
if(j!=33)
{
Console.WriteLine("type: must be 33 "+j);
result = false;
}
K_S=_buf.getString();
// K_S is server_key_blob, which includes ....
// string ssh-dss
// impint p of dsa
// impint q of dsa
// impint g of dsa
// impint pub_key of dsa
//System.out.print("K_S: "); dump(K_S, 0, K_S.length);
byte[] f=_buf.getMPInt();
byte[] sig_of_H=_buf.getString();
dh.setF(f);
K=dh.getK();
//The hash H is computed as the HASH hash of the concatenation of the
//following:
// string V_C, the client's version string (CR and NL excluded)
// string V_S, the server's version string (CR and NL excluded)
// string I_C, the payload of the client's SSH_MSG_KEXINIT
// string I_S, the payload of the server's SSH_MSG_KEXINIT
// string K_S, the host key
// uint32 min, minimal size in bits of an acceptable group
// uint32 n, preferred size in bits of the group the server should send
// uint32 max, maximal size in bits of an acceptable group
// mpint p, safe prime
// mpint g, generator for subgroup
// mpint e, exchange value sent by the client
// mpint f, exchange value sent by the server
// mpint K, the shared secret
// This value is called the exchange hash, and it is used to authenti-
// cate the key exchange.
buf.reset();
buf.putString(V_C); buf.putString(V_S);
buf.putString(I_C); buf.putString(I_S);
buf.putString(K_S);
buf.putInt(min); buf.putInt(preferred); buf.putInt(max);
buf.putMPInt(p); buf.putMPInt(g); buf.putMPInt(e); buf.putMPInt(f);
buf.putMPInt(K);
byte[] foo=new byte[buf.getLength()];
buf.getByte(foo);
sha.update(foo, 0, foo.Length);
H=sha.digest();
// System.out.print("H -> "); dump(H, 0, H.length);
i=0;
j=0;
j=(int)((K_S[i++]<<24)&0xff000000)|((K_S[i++]<<16)&0x00ff0000)|
((K_S[i++]<<8)&0x0000ff00)|((K_S[i++])&0x000000ff);
String alg=Util.getString(K_S, i, j);
i+=j;
if(alg.Equals("ssh-rsa"))
{
byte[] tmp;
byte[] ee;
byte[] n;
type=RSA;
j=(int)((K_S[i++]<<24)&0xff000000)|((K_S[i++]<<16)&0x00ff0000)|
((K_S[i++]<<8)&0x0000ff00)|((K_S[i++])&0x000000ff);
tmp=new byte[j]; Array.Copy(K_S, i, tmp, 0, j); i+=j;
ee=tmp;
j=(int)((K_S[i++]<<24)&0xff000000)|((K_S[i++]<<16)&0x00ff0000)|
((K_S[i++]<<8)&0x0000ff00)|((K_S[i++])&0x000000ff);
tmp=new byte[j]; Array.Copy(K_S, i, tmp, 0, j); i+=j;
n=tmp;
// SignatureRSA sig=new SignatureRSA();
// sig.init();
SignatureRSA sig=null;
try
{
Type t=Type.GetType(session.getConfig("signature.rsa"));
sig=(SignatureRSA)(Activator.CreateInstance(t));
sig.init();
}
catch(Exception eee)
{
Console.WriteLine(eee);
}
sig.setPubKey(ee, n);
sig.update(H);
result=sig.verify(sig_of_H);
}
else if(alg.Equals("ssh-dss"))
{
byte[] q=null;
byte[] tmp;
type=DSS;
j=(int)((K_S[i++]<<24)&0xff000000)|((K_S[i++]<<16)&0x00ff0000)|
((K_S[i++]<<8)&0x0000ff00)|((K_S[i++])&0x000000ff);
tmp=new byte[j]; Array.Copy(K_S, i, tmp, 0, j); i+=j;
p=tmp;
j=(int)((K_S[i++]<<24)&0xff000000)|((K_S[i++]<<16)&0x00ff0000)|
((K_S[i++]<<8)&0x0000ff00)|((K_S[i++])&0x000000ff);
tmp=new byte[j]; Array.Copy(K_S, i, tmp, 0, j); i+=j;
q=tmp;
j=(int)((K_S[i++]<<24)&0xff000000)|((K_S[i++]<<16)&0x00ff0000)|
((K_S[i++]<<8)&0x0000ff00)|((K_S[i++])&0x000000ff);
tmp=new byte[j]; Array.Copy(K_S, i, tmp, 0, j); i+=j;
g=tmp;
j=(int)((K_S[i++]<<24)&0xff000000)|((K_S[i++]<<16)&0x00ff0000)|
((K_S[i++]<<8)&0x0000ff00)|((K_S[i++])&0x000000ff);
tmp=new byte[j]; Array.Copy(K_S, i, tmp, 0, j); i+=j;
f=tmp;
// SignatureDSA sig=new SignatureDSA();
// sig.init();
SignatureDSA sig=null;
try
{
Type t=Type.GetType(session.getConfig("signature.dss"));
sig=(SignatureDSA)(Activator.CreateInstance(t));
sig.init();
}
catch(Exception ee)
{
Console.WriteLine(ee);
}
sig.setPubKey(f, p, q, g);
sig.update(H);
result=sig.verify(sig_of_H);
}
else
{
Console.WriteLine("unknow alg");
}
state=STATE_END;
break;
}
return result;
}
public override String getKeyType()
{
if(type==DSS) return "DSA";
return "RSA";
}
public override int getState(){return state; }
}
}

View file

@ -1,11 +0,0 @@
using System;
using Tamir.SharpSsh.java.lang;
namespace Tamir.SharpSsh.jsch
{
public interface ForwardedTCPIPDaemon : Runnable
{
void setChannel(ChannelForwardedTCPIP channel);
void setArg(Object[] arg);
}
}

View file

@ -1,41 +0,0 @@
using System;
namespace Tamir.SharpSsh.jsch
{
/* -*-mode:java; c-basic-offset:2; -*- */
/*
Copyright (c) 2002,2003,2004 ymnk, JCraft,Inc. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the distribution.
3. The names of the authors may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
public abstract class HASH
{
public abstract void init();
public abstract int getBlockSize();
public abstract void update(byte[] foo, int start, int len);
public abstract byte[] digest();
}
}

View file

@ -1,74 +0,0 @@
using System;
namespace Tamir.SharpSsh.jsch
{
/* -*-mode:java; c-basic-offset:2; -*- */
/*
Copyright (c) 2002,2003,2004 ymnk, JCraft,Inc. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the distribution.
3. The names of the authors may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
public class HostKey{
private static byte[] sshdss= System.Text.Encoding.Default.GetBytes( "ssh-dss" );
private static byte[] sshrsa= System.Text.Encoding.Default.GetBytes( "ssh-rsa" );
public const int SSHDSS=0;
public const int SSHRSA=1;
public const int UNKNOWN=2;
internal String host;
internal int type;
internal byte[] key;
public HostKey(String host, byte[] key)
{
this.host=host; this.key=key;
if(key[8]=='d'){ this.type=SSHDSS; }
else if(key[8]=='r'){ this.type=SSHRSA; }
else { throw new JSchException("invalid key type");}
}
internal HostKey(String host, int type, byte[] key){
this.host=host; this.type=type; this.key=key;
}
public String getHost(){ return host; }
public String getType(){
if(type==SSHDSS){ return System.Text.Encoding.Default.GetString(sshdss); }
if(type==SSHRSA){ return System.Text.Encoding.Default.GetString(sshrsa);}
return "UNKNOWN";
}
public String getKey(){
return Convert.ToBase64String(key, 0, key.Length);
}
public String getFingerPrint(JSch jsch){
HASH hash=null;
try{
hash=(HASH)Activator.CreateInstance(Type.GetType(jsch.getConfig("md5")));
}
catch(Exception e){ Console.Error.WriteLine("getFingerPrint: "+e); }
return Util.getFingerPrint(hash, key);
}
}
}

View file

@ -1,48 +0,0 @@
/* -*-mode:java; c-basic-offset:2; -*- */
/*
Copyright (c) 2004 ymnk, JCraft,Inc. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the distribution.
3. The names of the authors may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
using System;
namespace Tamir.SharpSsh.jsch
{
public abstract class HostKeyRepository
{
internal const int OK=0;
internal const int NOT_INCLUDED=1;
internal const int CHANGED=2;
public abstract int check(String host, byte[] key);
public abstract void add(String host, byte[] key, UserInfo ui);
public abstract void remove(String host, String type);
public abstract void remove(String host, String type, byte[] key);
public abstract String getKnownHostsRepositoryID();
public abstract HostKey[] getHostKey();
public abstract HostKey[] getHostKey(String host, String type);
}
}

View file

@ -1,183 +0,0 @@
using System;
using System.IO;
using Tamir.SharpSsh.java.io;
namespace Tamir.SharpSsh.jsch
{
/* -*-mode:java; c-basic-offset:2; -*- */
/*
Copyright (c) 2002,2003,2004 ymnk, JCraft,Inc. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the distribution.
3. The names of the authors may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
public class IO
{
internal JStream ins;
internal JStream outs;
internal JStream outs_ext;
private bool in_dontclose=false;
private bool out_dontclose=false;
private bool outs_ext_dontclose=false;
public void setOutputStream(Stream outs)
{
if(outs!=null)
{
this.outs= new JStream(outs);
}
else
{
this.outs=null;
}
}
public void setOutputStream(Stream outs, bool dontclose)
{
this.out_dontclose=dontclose;
setOutputStream(outs);
}
public void setExtOutputStream(Stream outs)
{
if(outs!=null)
{
this.outs_ext=new JStream(outs);
}
else
{
this.outs_ext=null;
}
}
public void setExtOutputStream(Stream outs, bool dontclose)
{
this.outs_ext_dontclose=dontclose;
setExtOutputStream(outs);
}
public void setInputStream(Stream ins)
{
//ConsoleStream low buffer patch
if(ins!=null)
{
if(ins.GetType() == Type.GetType("System.IO.__ConsoleStream"))
{
ins = new Tamir.Streams.ProtectedConsoleStream(ins);
}
else if(ins.GetType() == Type.GetType("System.IO.FileStream"))
{
ins = new Tamir.Streams.ProtectedConsoleStream(ins);
}
this.ins=new JStream(ins);
}
else
{
this.ins=null;
}
}
public void setInputStream(Stream ins, bool dontclose)
{
this.in_dontclose=dontclose;
setInputStream(ins);
}
public void put(Packet p)
{
outs.Write(p.buffer.buffer, 0, p.buffer.index);
outs.Flush();
}
internal void put(byte[] array, int begin, int length)
{
outs.Write(array, begin, length);
outs.Flush();
}
internal void put_ext(byte[] array, int begin, int length)
{
outs_ext.Write(array, begin, length);
outs_ext.Flush();
}
internal int getByte()
{
int res = ins.ReadByte()&0xff;
return res;
}
internal void getByte(byte[] array)
{
getByte(array, 0, array.Length);
}
internal void getByte(byte[] array, int begin, int length)
{
do
{
int completed = ins.Read(array, begin, length);
if(completed<=0)
{
throw new IOException("End of IO Stream Read");
}
begin+=completed;
length-=completed;
}
while (length>0);
}
public void close()
{
try
{
if(ins!=null && !in_dontclose) ins.Close();
ins=null;
}
catch(Exception ee){}
try
{
if(outs!=null && !out_dontclose) outs.Close();
outs=null;
}
catch(Exception ee){}
try
{
if(outs_ext!=null && !outs_ext_dontclose) outs_ext.Close();
outs_ext=null;
}
catch(Exception ee){}
}
// public void finalize()
// {
// try
// {
// if(ins!=null) ins.Close();
// }
// catch{}
// try
// {
// if(outs!=null) outs.Close();
// }
// catch{}
// }
}
}

View file

@ -1,44 +0,0 @@
using System;
namespace Tamir.SharpSsh.jsch
{
/* -*-mode:java; c-basic-offset:2; -*- */
/*
Copyright (c) 2002,2003,2004 ymnk, JCraft,Inc. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the distribution.
3. The names of the authors may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
internal interface Identity
{
bool setPassphrase(String passphrase);
byte[] getPublicKeyBlob();
byte[] getSignature(Session session, byte[] data);
bool decrypt();
String getAlgName();
String getName();
bool isEncrypted();
}
}

View file

@ -1,949 +0,0 @@
using System;
using System.IO;
namespace Tamir.SharpSsh.jsch
{
/* -*-mode:java; c-basic-offset:2; -*- */
/*
Copyright (c) 2002,2003,2004 ymnk, JCraft,Inc. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the distribution.
3. The names of the authors may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
internal class IdentityFile : Identity
{
String identity;
byte[] key;
byte[] iv;
private JSch jsch;
private HASH hash;
private byte[] encoded_data;
private Cipher cipher;
// DSA
private byte[] P_array;
private byte[] Q_array;
private byte[] G_array;
private byte[] pub_array;
private byte[] prv_array;
// RSA
private byte[] n_array; // modulus
private byte[] e_array; // public exponent
private byte[] d_array; // private exponent
private byte[] p_array;
private byte[] q_array;
private byte[] dmp1_array;
private byte[] dmq1_array;
private byte[] iqmp_array;
// private String algname="ssh-dss";
private String algname="ssh-rsa";
private const int ERROR=0;
private const int RSA=1;
private const int DSS=2;
internal const int UNKNOWN=3;
private const int OPENSSH=0;
private const int FSECURE=1;
private const int PUTTY=2;
private int type=ERROR;
private int keytype=OPENSSH;
private byte[] publickeyblob=null;
private bool encrypted=true;
internal IdentityFile(String identity, JSch jsch)
{
this.identity=identity;
this.jsch=jsch;
try
{
Type c=Type.GetType(jsch.getConfig("3des-cbc"));
cipher=(Cipher)Activator.CreateInstance(c);
key=new byte[cipher.getBlockSize()]; // 24
iv=new byte[cipher.getIVSize()]; // 8
c=Type.GetType(jsch.getConfig("md5"));
hash=(HASH)(Activator.CreateInstance(c));
hash.init();
FileInfo file=new FileInfo(identity);
FileStream fis = File.OpenRead(identity);
byte[] buf=new byte[(int)(file.Length)];
int len=fis.Read(buf, 0, buf.Length);
fis.Close();
int i=0;
while(i<len)
{
if(buf[i]=='B'&& buf[i+1]=='E'&& buf[i+2]=='G'&& buf[i+3]=='I')
{
i+=6;
if(buf[i]=='D'&& buf[i+1]=='S'&& buf[i+2]=='A'){ type=DSS; }
else if(buf[i]=='R'&& buf[i+1]=='S'&& buf[i+2]=='A'){ type=RSA; }
else if(buf[i]=='S'&& buf[i+1]=='S'&& buf[i+2]=='H')
{ // FSecure
type=UNKNOWN;
keytype=FSECURE;
}
else
{
//System.out.println("invalid format: "+identity);
throw new JSchException("invaid privatekey: "+identity);
}
i+=3;
continue;
}
if(buf[i]=='C'&& buf[i+1]=='B'&& buf[i+2]=='C'&& buf[i+3]==',')
{
i+=4;
for(int ii=0; ii<iv.Length; ii++)
{
iv[ii]=(byte)(((a2b(buf[i++])<<4)&0xf0)+
(a2b(buf[i++])&0xf));
}
continue;
}
if(buf[i]==0x0d &&
i+1<buf.Length && buf[i+1]==0x0a)
{
i++;
continue;
}
if(buf[i]==0x0a && i+1<buf.Length)
{
if(buf[i+1]==0x0a){ i+=2; break; }
if(buf[i+1]==0x0d &&
i+2<buf.Length && buf[i+2]==0x0a)
{
i+=3; break;
}
bool inheader=false;
for(int j=i+1; j<buf.Length; j++)
{
if(buf[j]==0x0a) break;
//if(buf[j]==0x0d) break;
if(buf[j]==':'){inheader=true; break;}
}
if(!inheader)
{
i++;
encrypted=false; // no passphrase
break;
}
}
i++;
}
if(type==ERROR)
{
throw new JSchException("invaid privatekey: "+identity);
}
int start=i;
while(i<len)
{
if(buf[i]==0x0a)
{
bool xd=(buf[i-1]==0x0d);
Array.Copy(buf, i+1,
buf,
i-(xd ? 1 : 0),
len-i-1-(xd ? 1 : 0)
);
if(xd)len--;
len--;
continue;
}
if(buf[i]=='-'){ break; }
i++;
}
encoded_data=Util.fromBase64(buf, start, i-start);
if(encoded_data.Length>4 && // FSecure
encoded_data[0]==(byte)0x3f &&
encoded_data[1]==(byte)0x6f &&
encoded_data[2]==(byte)0xf9 &&
encoded_data[3]==(byte)0xeb)
{
Buffer _buf=new Buffer(encoded_data);
_buf.getInt(); // 0x3f6ff9be
_buf.getInt();
byte[]_type=_buf.getString();
//System.out.println("type: "+new String(_type));
byte[] _cipher=_buf.getString();
String s_cipher=System.Text.Encoding.Default.GetString(_cipher);
//System.out.println("cipher: "+cipher);
if(s_cipher.Equals("3des-cbc"))
{
_buf.getInt();
byte[] foo=new byte[encoded_data.Length-_buf.getOffSet()];
_buf.getByte(foo);
encoded_data=foo;
encrypted=true;
throw new JSchException("unknown privatekey format: "+identity);
}
else if(s_cipher.Equals("none"))
{
_buf.getInt();
//_buf.getInt();
encrypted=false;
byte[] foo=new byte[encoded_data.Length-_buf.getOffSet()];
_buf.getByte(foo);
encoded_data=foo;
}
}
try
{
file=new FileInfo(identity+".pub");
fis=File.OpenRead(identity+".pub");
buf=new byte[(int)(file.Length)];
len=fis.Read(buf, 0, buf.Length);
fis.Close();
}
catch
{
return;
}
if(buf.Length>4 && // FSecure's public key
buf[0]=='-' && buf[1]=='-' && buf[2]=='-' && buf[3]=='-')
{
i=0;
do{i++;}while(buf.Length>i && buf[i]!=0x0a);
if(buf.Length<=i) return;
while(true)
{
if(buf[i]==0x0a)
{
bool inheader=false;
for(int j=i+1; j<buf.Length; j++)
{
if(buf[j]==0x0a) break;
if(buf[j]==':'){inheader=true; break;}
}
if(!inheader)
{
i++;
break;
}
}
i++;
}
if(buf.Length<=i) return;
start=i;
while(i<len)
{
if(buf[i]==0x0a)
{
Array.Copy(buf, i+1, buf, i, len-i-1);
len--;
continue;
}
if(buf[i]=='-'){ break; }
i++;
}
publickeyblob=Util.fromBase64(buf, start, i-start);
if(type==UNKNOWN)
{
if(publickeyblob[8]=='d')
{
type=DSS;
}
else if(publickeyblob[8]=='r')
{
type=RSA;
}
}
}
else
{
if(buf[0]!='s'|| buf[1]!='s'|| buf[2]!='h'|| buf[3]!='-') return;
i=0;
while(i<len){ if(buf[i]==' ')break; i++;} i++;
if(i>=len) return;
start=i;
while(i<len){ if(buf[i]==' ')break; i++;}
publickeyblob=Util.fromBase64(buf, start, i-start);
}
}
catch(Exception e)
{
Console.WriteLine("Identity: "+e);
if(e is JSchException) throw (JSchException)e;
throw new JSchException(e.ToString());
}
}
public String getAlgName()
{
if(type==RSA) return "ssh-rsa";
return "ssh-dss";
}
public bool setPassphrase(String _passphrase)
{
/*
hash is MD5
h(0) <- hash(passphrase, iv);
h(n) <- hash(h(n-1), passphrase, iv);
key <- (h(0),...,h(n))[0,..,key.Length];
*/
try
{
if(encrypted)
{
if(_passphrase==null) return false;
byte[] passphrase= System.Text.Encoding.Default.GetBytes( _passphrase );
int hsize=hash.getBlockSize();
byte[] hn=new byte[key.Length/hsize*hsize+
(key.Length%hsize==0?0:hsize)];
byte[] tmp=null;
if(keytype==OPENSSH)
{
for(int index=0; index+hsize<=hn.Length;)
{
if(tmp!=null){ hash.update(tmp, 0, tmp.Length); }
hash.update(passphrase, 0, passphrase.Length);
hash.update(iv, 0, iv.Length);
tmp=hash.digest();
Array.Copy(tmp, 0, hn, index, tmp.Length);
index+=tmp.Length;
}
Array.Copy(hn, 0, key, 0, key.Length);
}
else if(keytype==FSECURE)
{
for(int index=0; index+hsize<=hn.Length;)
{
if(tmp!=null){ hash.update(tmp, 0, tmp.Length); }
hash.update(passphrase, 0, passphrase.Length);
tmp=hash.digest();
Array.Copy(tmp, 0, hn, index, tmp.Length);
index+=tmp.Length;
}
Array.Copy(hn, 0, key, 0, key.Length);
}
}
if(decrypt())
{
encrypted=false;
return true;
}
P_array=Q_array=G_array=pub_array=prv_array=null;
return false;
}
catch(Exception e)
{
if(e is JSchException) throw (JSchException)e;
throw new JSchException(e.ToString());
}
}
public byte[] getPublicKeyBlob()
{
if(publickeyblob!=null) return publickeyblob;
if(type==RSA) return getPublicKeyBlob_rsa();
return getPublicKeyBlob_dss();
}
byte[] getPublicKeyBlob_rsa()
{
if(e_array==null) return null;
Buffer buf=new Buffer("ssh-rsa".Length+4+
e_array.Length+4+
n_array.Length+4);
buf.putString( System.Text.Encoding.Default.GetBytes( "ssh-rsa" ) );
buf.putString(e_array);
buf.putString(n_array);
return buf.buffer;
}
byte[] getPublicKeyBlob_dss()
{
if(P_array==null) return null;
Buffer buf=new Buffer("ssh-dss".Length+4+
P_array.Length+4+
Q_array.Length+4+
G_array.Length+4+
pub_array.Length+4);
buf.putString(System.Text.Encoding.Default.GetBytes("ssh-dss"));
buf.putString(P_array);
buf.putString(Q_array);
buf.putString(G_array);
buf.putString(pub_array);
return buf.buffer;
}
public byte[] getSignature(Session session, byte[] data)
{
if(type==RSA) return getSignature_rsa(session, data);
return getSignature_dss(session, data);
}
byte[] getSignature_rsa(Session session, byte[] data)
{
try
{
Type t=Type.GetType(jsch.getConfig("signature.rsa"));
SignatureRSA rsa=(SignatureRSA)Activator.CreateInstance(t);
rsa.init();
rsa.setPrvKey(e_array, n_array, d_array, p_array, q_array, dmp1_array, dmq1_array, iqmp_array);
/*
byte[] goo=new byte[4];
goo[0]=(byte)(session.getSessionId().Length>>>24);
goo[1]=(byte)(session.getSessionId().Length>>>16);
goo[2]=(byte)(session.getSessionId().Length>>>8);
goo[3]=(byte)(session.getSessionId().Length);
rsa.update(goo);
rsa.update(session.getSessionId());
*/
rsa.update(data);
byte[] sig = rsa.sign();
Buffer buf=new Buffer("ssh-rsa".Length+4+
sig.Length+4);
buf.putString( System.Text.Encoding.Default.GetBytes( "ssh-rsa" ));
buf.putString(sig);
return buf.buffer;
}
catch(Exception e)
{
Console.WriteLine(e);
}
return null;
}
byte[] getSignature_dss(Session session, byte[] data)
{
/*
byte[] foo;
int i;
System.out.print("P ");
foo=P_array;
for(i=0; i<foo.Length; i++){
System.out.print(Integer.toHexString(foo[i]&0xff)+":");
}
System.out.println("");
System.out.print("Q ");
foo=Q_array;
for(i=0; i<foo.Length; i++){
System.out.print(Integer.toHexString(foo[i]&0xff)+":");
}
System.out.println("");
System.out.print("G ");
foo=G_array;
for(i=0; i<foo.Length; i++){
System.out.print(Integer.toHexString(foo[i]&0xff)+":");
}
System.out.println("");
*/
try
{
Type t=Type.GetType(jsch.getConfig("signature.dss"));
SignatureDSA dsa=(SignatureDSA)(Activator.CreateInstance(t));
dsa.init();
dsa.setPrvKey(prv_array, P_array, Q_array, G_array);
/*
byte[] goo=new byte[4];
goo[0]=(byte)(session.getSessionId().Length>>>24);
goo[1]=(byte)(session.getSessionId().Length>>>16);
goo[2]=(byte)(session.getSessionId().Length>>>8);
goo[3]=(byte)(session.getSessionId().Length);
dsa.update(goo);
dsa.update(session.getSessionId());
*/
dsa.update(data);
byte[] sig = dsa.sign();
Buffer buf=new Buffer("ssh-dss".Length+4+
sig.Length+4);
buf.putString( System.Text.Encoding.Default.GetBytes( "ssh-dss" ) );
buf.putString(sig);
return buf.buffer;
}
catch(Exception e)
{
Console.WriteLine("e "+e);
}
return null;
}
public bool decrypt()
{
if(type==RSA) return decrypt_rsa();
return decrypt_dss();
}
bool decrypt_rsa()
{
// byte[] p_array;
// byte[] q_array;
// byte[] dmp1_array;
// byte[] dmq1_array;
// byte[] iqmp_array;
try
{
byte[] plain;
if(encrypted)
{
if(keytype==OPENSSH)
{
cipher.init(Cipher.DECRYPT_MODE, key, iv);
plain=new byte[encoded_data.Length];
cipher.update(encoded_data, 0, encoded_data.Length, plain, 0);
}
else if(keytype==FSECURE)
{
for(int i=0; i<iv.Length; i++)iv[i]=0;
cipher.init(Cipher.DECRYPT_MODE, key, iv);
plain=new byte[encoded_data.Length];
cipher.update(encoded_data, 0, encoded_data.Length, plain, 0);
}
else
{
return false;
}
}
else
{
if(n_array!=null) return true;
plain=encoded_data;
}
if(keytype==FSECURE)
{ // FSecure
Buffer buf=new Buffer(plain);
int foo=buf.getInt();
if(plain.Length!=foo+4)
{
return false;
}
e_array=buf.getMPIntBits();
d_array=buf.getMPIntBits();
n_array=buf.getMPIntBits();
byte[] u_array=buf.getMPIntBits();
p_array=buf.getMPIntBits();
q_array=buf.getMPIntBits();
return true;
}
int index=0;
int Length=0;
if(plain[index]!=0x30)return false;
index++; // SEQUENCE
Length=plain[index++]&0xff;
if((Length&0x80)!=0)
{
int foo=Length&0x7f; Length=0;
while(foo-->0){ Length=(Length<<8)+(plain[index++]&0xff); }
}
if(plain[index]!=0x02)return false;
index++; // INTEGER
Length=plain[index++]&0xff;
if((Length&0x80)!=0)
{
int foo=Length&0x7f; Length=0;
while(foo-->0){ Length=(Length<<8)+(plain[index++]&0xff); }
}
index+=Length;
//System.out.println("int: len="+Length);
//System.out.print(Integer.toHexString(plain[index-1]&0xff)+":");
//System.out.println("");
index++;
Length=plain[index++]&0xff;
if((Length&0x80)!=0)
{
int foo=Length&0x7f; Length=0;
while(foo-->0){ Length=(Length<<8)+(plain[index++]&0xff); }
}
n_array=new byte[Length];
Array.Copy(plain, index, n_array, 0, Length);
index+=Length;
/*
System.out.println("int: N len="+Length);
for(int i=0; i<n_array.Length; i++){
System.out.print(Integer.toHexString(n_array[i]&0xff)+":");
}
System.out.println("");
*/
index++;
Length=plain[index++]&0xff;
if((Length&0x80)!=0)
{
int foo=Length&0x7f; Length=0;
while(foo-->0){ Length=(Length<<8)+(plain[index++]&0xff); }
}
e_array=new byte[Length];
Array.Copy(plain, index, e_array, 0, Length);
index+=Length;
/*
System.out.println("int: E len="+Length);
for(int i=0; i<e_array.Length; i++){
System.out.print(Integer.toHexString(e_array[i]&0xff)+":");
}
System.out.println("");
*/
index++;
Length=plain[index++]&0xff;
if((Length&0x80)!=0)
{
int foo=Length&0x7f; Length=0;
while(foo-->0){ Length=(Length<<8)+(plain[index++]&0xff); }
}
d_array=new byte[Length];
Array.Copy(plain, index, d_array, 0, Length);
index+=Length;
/*
System.out.println("int: D len="+Length);
for(int i=0; i<d_array.Length; i++){
System.out.print(Integer.toHexString(d_array[i]&0xff)+":");
}
System.out.println("");
*/
index++;
Length=plain[index++]&0xff;
if((Length&0x80)!=0)
{
int foo=Length&0x7f; Length=0;
while(foo-->0){ Length=(Length<<8)+(plain[index++]&0xff); }
}
p_array=new byte[Length];
Array.Copy(plain, index, p_array, 0, Length);
index+=Length;
/*
System.out.println("int: P len="+Length);
for(int i=0; i<p_array.Length; i++){
System.out.print(Integer.toHexString(p_array[i]&0xff)+":");
}
System.out.println("");
*/
index++;
Length=plain[index++]&0xff;
if((Length&0x80)!=0)
{
int foo=Length&0x7f; Length=0;
while(foo-->0){ Length=(Length<<8)+(plain[index++]&0xff); }
}
q_array=new byte[Length];
Array.Copy(plain, index, q_array, 0, Length);
index+=Length;
/*
System.out.println("int: q len="+Length);
for(int i=0; i<q_array.Length; i++){
System.out.print(Integer.toHexString(q_array[i]&0xff)+":");
}
System.out.println("");
*/
index++;
Length=plain[index++]&0xff;
if((Length&0x80)!=0)
{
int foo=Length&0x7f; Length=0;
while(foo-->0){ Length=(Length<<8)+(plain[index++]&0xff); }
}
dmp1_array=new byte[Length];
Array.Copy(plain, index, dmp1_array, 0, Length);
index+=Length;
/*
System.out.println("int: dmp1 len="+Length);
for(int i=0; i<dmp1_array.Length; i++){
System.out.print(Integer.toHexString(dmp1_array[i]&0xff)+":");
}
System.out.println("");
*/
index++;
Length=plain[index++]&0xff;
if((Length&0x80)!=0)
{
int foo=Length&0x7f; Length=0;
while(foo-->0){ Length=(Length<<8)+(plain[index++]&0xff); }
}
dmq1_array=new byte[Length];
Array.Copy(plain, index, dmq1_array, 0, Length);
index+=Length;
/*
System.out.println("int: dmq1 len="+Length);
for(int i=0; i<dmq1_array.Length; i++){
System.out.print(Integer.toHexString(dmq1_array[i]&0xff)+":");
}
System.out.println("");
*/
index++;
Length=plain[index++]&0xff;
if((Length&0x80)!=0)
{
int foo=Length&0x7f; Length=0;
while(foo-->0){ Length=(Length<<8)+(plain[index++]&0xff); }
}
iqmp_array=new byte[Length];
Array.Copy(plain, index, iqmp_array, 0, Length);
index+=Length;
/*
System.out.println("int: iqmp len="+Length);
for(int i=0; i<iqmp_array.Length; i++){
System.out.print(Integer.toHexString(iqmp_array[i]&0xff)+":");
}
System.out.println("");
*/
}
catch
{
//System.out.println(e);
return false;
}
return true;
}
bool decrypt_dss()
{
try
{
byte[] plain;
if(encrypted)
{
if(keytype==OPENSSH)
{
cipher.init(Cipher.DECRYPT_MODE, key, iv);
plain=new byte[encoded_data.Length];
cipher.update(encoded_data, 0, encoded_data.Length, plain, 0);
/*
for(int i=0; i<plain.Length; i++){
System.out.print(Integer.toHexString(plain[i]&0xff)+":");
}
System.out.println("");
*/
}
else if(keytype==FSECURE)
{
for(int i=0; i<iv.Length; i++)iv[i]=0;
cipher.init(Cipher.DECRYPT_MODE, key, iv);
plain=new byte[encoded_data.Length];
cipher.update(encoded_data, 0, encoded_data.Length, plain, 0);
}
else
{
return false;
}
}
else
{
if(P_array!=null) return true;
plain=encoded_data;
}
if(keytype==FSECURE)
{ // FSecure
Buffer buf=new Buffer(plain);
int foo=buf.getInt();
if(plain.Length!=foo+4)
{
return false;
}
P_array=buf.getMPIntBits();
G_array=buf.getMPIntBits();
Q_array=buf.getMPIntBits();
pub_array=buf.getMPIntBits();
prv_array=buf.getMPIntBits();
return true;
}
int index=0;
int Length=0;
if(plain[index]!=0x30)return false;
index++; // SEQUENCE
Length=plain[index++]&0xff;
if((Length&0x80)!=0)
{
int foo=Length&0x7f; Length=0;
while(foo-->0){ Length=(Length<<8)+(plain[index++]&0xff); }
}
if(plain[index]!=0x02)return false;
index++; // INTEGER
Length=plain[index++]&0xff;
if((Length&0x80)!=0)
{
int foo=Length&0x7f; Length=0;
while(foo-->0){ Length=(Length<<8)+(plain[index++]&0xff); }
}
index+=Length;
index++;
Length=plain[index++]&0xff;
if((Length&0x80)!=0)
{
int foo=Length&0x7f; Length=0;
while(foo-->0){ Length=(Length<<8)+(plain[index++]&0xff); }
}
P_array=new byte[Length];
Array.Copy(plain, index, P_array, 0, Length);
index+=Length;
index++;
Length=plain[index++]&0xff;
if((Length&0x80)!=0)
{
int foo=Length&0x7f; Length=0;
while(foo-->0){ Length=(Length<<8)+(plain[index++]&0xff); }
}
Q_array=new byte[Length];
Array.Copy(plain, index, Q_array, 0, Length);
index+=Length;
index++;
Length=plain[index++]&0xff;
if((Length&0x80)!=0)
{
int foo=Length&0x7f; Length=0;
while(foo-->0){ Length=(Length<<8)+(plain[index++]&0xff); }
}
G_array=new byte[Length];
Array.Copy(plain, index, G_array, 0, Length);
index+=Length;
index++;
Length=plain[index++]&0xff;
if((Length&0x80)!=0)
{
int foo=Length&0x7f; Length=0;
while(foo-->0){ Length=(Length<<8)+(plain[index++]&0xff); }
}
pub_array=new byte[Length];
Array.Copy(plain, index, pub_array, 0, Length);
index+=Length;
index++;
Length=plain[index++]&0xff;
if((Length&0x80)!=0)
{
int foo=Length&0x7f; Length=0;
while(foo-->0){ Length=(Length<<8)+(plain[index++]&0xff); }
}
prv_array=new byte[Length];
Array.Copy(plain, index, prv_array, 0, Length);
index+=Length;
}
catch
{
//System.out.println(e);
//e.printStackTrace();
return false;
}
return true;
}
public bool isEncrypted()
{
return encrypted;
}
public String getName(){return identity;}
private int writeSEQUENCE(byte[] buf, int index, int len)
{
buf[index++]=0x30;
index=writeLength(buf, index, len);
return index;
}
private int writeINTEGER(byte[] buf, int index, byte[] data)
{
buf[index++]=0x02;
index=writeLength(buf, index, data.Length);
Array.Copy(data, 0, buf, index, data.Length);
index+=data.Length;
return index;
}
private int countLength(int i_len)
{
uint len = (uint)i_len;
int i=1;
if(len<=0x7f) return i;
while(len>0)
{
len>>=8;
i++;
}
return i;
}
private int writeLength(byte[] data, int index, int i_len)
{
int len = (int)i_len;
int i=countLength(len)-1;
if(i==0)
{
data[index++]=(byte)len;
return index;
}
data[index++]=(byte)(0x80|i);
int j=index+i;
while(i>0)
{
data[index+i-1]=(byte)(len&0xff);
len>>=8;
i--;
}
return j;
}
private byte a2b(byte c)
{
if('0'<=c&&c<='9') return (byte)(c-'0');
if('a'<=c&&c<='z') return (byte)(c-'a'+10);
return (byte)(c-'A'+10);
}
private byte b2a(byte c)
{
if(0<=c&&c<=9) return (byte)(c+'0');
return (byte)(c-10+'A');
}
}
}

View file

@ -1,241 +0,0 @@
using System;
using System.IO;
namespace Tamir.SharpSsh.jsch
{
/* -*-mode:java; c-basic-offset:2; -*- */
/*
Copyright (c) 2002,2003,2004 ymnk, JCraft,Inc. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the distribution.
3. The names of the authors may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
public class JSch
{
static System.Collections.Hashtable config;
public static void Init()
{
config=new System.Collections.Hashtable();
// config.Add("kex", "diffie-hellman-group-exchange-sha1");
config.Add("kex", "diffie-hellman-group1-sha1,diffie-hellman-group-exchange-sha1");
config.Add("server_host_key", "ssh-rsa,ssh-dss");
//config.Add("server_host_key", "ssh-dss,ssh-rsa");
// config.Add("cipher.s2c", "3des-cbc,blowfish-cbc");
// config.Add("cipher.c2s", "3des-cbc,blowfish-cbc");
config.Add("cipher.s2c", "3des-cbc,aes128-cbc");
config.Add("cipher.c2s", "3des-cbc,aes128-cbc");
// config.Add("mac.s2c", "hmac-md5,hmac-sha1,hmac-sha1-96,hmac-md5-96");
// config.Add("mac.c2s", "hmac-md5,hmac-sha1,hmac-sha1-96,hmac-md5-96");
config.Add("mac.s2c", "hmac-md5,hmac-sha1");
config.Add("mac.c2s", "hmac-md5,hmac-sha1");
config.Add("compression.s2c", "none");
config.Add("compression.c2s", "none");
config.Add("lang.s2c", "");
config.Add("lang.c2s", "");
config.Add("diffie-hellman-group-exchange-sha1",
"Tamir.SharpSsh.jsch.DHGEX");
config.Add("diffie-hellman-group1-sha1",
"Tamir.SharpSsh.jsch.DHG1");
config.Add("dh", "Tamir.SharpSsh.jsch.jce.DH");
config.Add("3des-cbc", "Tamir.SharpSsh.jsch.jce.TripleDESCBC");
//config.Add("blowfish-cbc", "Tamir.SharpSsh.jsch.jce.BlowfishCBC");
config.Add("hmac-sha1", "Tamir.SharpSsh.jsch.jce.HMACSHA1");
config.Add("hmac-sha1-96", "Tamir.SharpSsh.jsch.jce.HMACSHA196");
config.Add("hmac-md5", "Tamir.SharpSsh.jsch.jce.HMACMD5");
config.Add("hmac-md5-96", "Tamir.SharpSsh.jsch.jce.HMACMD596");
config.Add("sha-1", "Tamir.SharpSsh.jsch.jce.SHA1");
config.Add("md5", "Tamir.SharpSsh.jsch.jce.MD5");
config.Add("signature.dss", "Tamir.SharpSsh.jsch.jce.SignatureDSA");
config.Add("signature.rsa", "Tamir.SharpSsh.jsch.jce.SignatureRSA");
config.Add("keypairgen.dsa", "Tamir.SharpSsh.jsch.jce.KeyPairGenDSA");
config.Add("keypairgen.rsa", "Tamir.SharpSsh.jsch.jce.KeyPairGenRSA");
config.Add("random", "Tamir.SharpSsh.jsch.jce.Random");
config.Add("aes128-cbc", "Tamir.SharpSsh.jsch.jce.AES128CBC");
//config.Add("zlib", "com.jcraft.jsch.jcraft.Compression");
config.Add("StrictHostKeyChecking", "ask");
}
internal Tamir.SharpSsh.java.util.Vector pool=new Tamir.SharpSsh.java.util.Vector();
internal Tamir.SharpSsh.java.util.Vector identities=new Tamir.SharpSsh.java.util.Vector();
//private KnownHosts known_hosts=null;
private HostKeyRepository known_hosts=null;
public JSch()
{
//known_hosts=new KnownHosts(this);
if (config==null)
Init();
}
public Session getSession(String username, String host) { return getSession(username, host, 22); }
public Session getSession(String username, String host, int port)
{
Session s=new Session(this);
s.setUserName(username);
s.setHost(host);
s.setPort(port);
pool.Add(s);
return s;
}
internal bool removeSession(Session session)
{
lock(pool)
{
return pool.remove(session);
}
}
public void setHostKeyRepository(HostKeyRepository foo)
{
known_hosts=foo;
}
public void setKnownHosts(String foo)
{
if(known_hosts==null) known_hosts=new KnownHosts(this);
if(known_hosts is KnownHosts)
{
lock(known_hosts)
{
((KnownHosts)known_hosts).setKnownHosts(foo);
}
}
}
public void setKnownHosts(StreamReader foo)
{
if(known_hosts==null) known_hosts=new KnownHosts(this);
if(known_hosts is KnownHosts)
{
lock(known_hosts)
{
((KnownHosts)known_hosts).setKnownHosts(foo);
}
}
}
/*
HostKeyRepository getKnownHosts(){
if(known_hosts==null) known_hosts=new KnownHosts(this);
return known_hosts;
}
*/
public HostKeyRepository getHostKeyRepository()
{
if(known_hosts==null) known_hosts=new KnownHosts(this);
return known_hosts;
}
/*
public HostKey[] getHostKey(){
if(known_hosts==null) return null;
return known_hosts.getHostKey();
}
public void removeHostKey(String foo, String type){
removeHostKey(foo, type, null);
}
public void removeHostKey(String foo, String type, byte[] key){
if(known_hosts==null) return;
known_hosts.remove(foo, type, key);
}
*/
public void addIdentity(String foo)
{
addIdentity(foo, (String)null);
}
public void addIdentity(String foo, String bar)
{
Identity identity=new IdentityFile(foo, this);
if(bar!=null) identity.setPassphrase(bar);
identities.Add(identity);
}
internal String getConfig(String foo){ return (String)(config[foo]); }
private System.Collections.ArrayList proxies;
void setProxy(String hosts, Proxy proxy)
{
String[] patterns=Util.split(hosts, ",");
if(proxies==null){proxies=new System.Collections.ArrayList();}
lock(proxies)
{
for(int i=0; i<patterns.Length; i++)
{
if(proxy==null)
{
proxies[0] = null;
proxies[0] = System.Text.Encoding.Default.GetBytes( patterns[i] );
}
else
{
proxies.Add( System.Text.Encoding.Default.GetBytes( patterns[i] ) );
proxies.Add(proxy);
}
}
}
}
internal Proxy getProxy(String host)
{
if(proxies==null)return null;
byte[] _host= System.Text.Encoding.Default.GetBytes( host );
lock(proxies)
{
for(int i=0; i<proxies.Count; i+=2)
{
if(Util.glob(((byte[])proxies[i]), _host))
{
return (Proxy)(proxies[i+1]);
}
}
}
return null;
}
internal void removeProxy()
{
proxies=null;
}
public static void setConfig(System.Collections.Hashtable foo)
{
lock(config)
{
System.Collections.IEnumerator e=foo.Keys.GetEnumerator();
while(e.MoveNext())
{
String key=(String)(e.Current);
config.Add(key, (String)(foo[key]));
}
}
}
}
}

View file

@ -1,21 +0,0 @@
using System;
namespace Tamir.SharpSsh.jsch
{
/// <summary>
/// Summary description for JSchException.
/// </summary>
public class JSchAuthCancelException : JSchException
{
public JSchAuthCancelException() : base()
{
//
// TODO: Add constructor logic here
//
}
public JSchAuthCancelException(string msg) : base (msg)
{
}
}
}

View file

@ -1,21 +0,0 @@
using System;
namespace Tamir.SharpSsh.jsch
{
/// <summary>
/// Summary description for JSchException.
/// </summary>
public class JSchException : java.Exception
{
public JSchException() : base()
{
//
// TODO: Add constructor logic here
//
}
public JSchException(string msg) : base (msg)
{
}
}
}

View file

@ -1,26 +0,0 @@
using System;
namespace Tamir.SharpSsh.jsch
{
/// <summary>
/// Summary description for JSchException.
/// </summary>
public class JSchPartialAuthException : JSchException
{
string methods;
public JSchPartialAuthException() : base()
{
methods = null;
}
public JSchPartialAuthException(string msg) : base (msg)
{
methods = msg;
}
public String getMethods()
{
return methods;
}
}
}

View file

@ -1,170 +0,0 @@
using System;
namespace Tamir.SharpSsh.jsch
{
/* -*-mode:java; c-basic-offset:2; -*- */
/*
Copyright (c) 2002,2003,2004 ymnk, JCraft,Inc. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the distribution.
3. The names of the authors may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
public abstract class KeyExchange
{
internal const int PROPOSAL_KEX_ALGS=0;
internal const int PROPOSAL_SERVER_HOST_KEY_ALGS=1;
internal const int PROPOSAL_ENC_ALGS_CTOS=2;
internal const int PROPOSAL_ENC_ALGS_STOC=3;
internal const int PROPOSAL_MAC_ALGS_CTOS=4;
internal const int PROPOSAL_MAC_ALGS_STOC=5;
internal const int PROPOSAL_COMP_ALGS_CTOS=6;
internal const int PROPOSAL_COMP_ALGS_STOC=7;
internal const int PROPOSAL_LANG_CTOS=8;
internal const int PROPOSAL_LANG_STOC=9;
internal const int PROPOSAL_MAX=10;
//static String kex_algs="diffie-hellman-group-exchange-sha1"+
// ",diffie-hellman-group1-sha1";
//static String kex="diffie-hellman-group-exchange-sha1";
internal static String kex="diffie-hellman-group1-sha1";
internal static String server_host_key="ssh-rsa,ssh-dss";
internal static String enc_c2s="blowfish-cbc";
internal static String enc_s2c="blowfish-cbc";
internal static String mac_c2s="hmac-md5"; // hmac-md5,hmac-sha1,hmac-ripemd160,
// hmac-sha1-96,hmac-md5-96
internal static String mac_s2c="hmac-md5";
//static String comp_c2s="none"; // zlib
//static String comp_s2c="none";
internal static String lang_c2s="";
internal static String lang_s2c="";
public const int STATE_END=0;
public Tamir.SharpSsh.java.String[] _guess=null;
protected Session session=null;
protected HASH sha=null;
protected byte[] K=null;
protected byte[] H=null;
protected byte[] K_S=null;
public abstract void init(Session session,
byte[] V_S, byte[] V_C, byte[] I_S, byte[] I_C);
public abstract bool next(Buffer buf);
public abstract String getKeyType();
public abstract int getState();
/*
void dump(byte[] foo){
for(int i=0; i<foo.length; i++){
if((foo[i]&0xf0)==0)System.out.print("0");
System.out.print(Integer.toHexString(foo[i]&0xff));
if(i%16==15){System.out.println(""); continue;}
if(i%2==1)System.out.print(" ");
}
}
*/
internal static Tamir.SharpSsh.java.String[] guess(byte[]I_S, byte[]I_C)
{
//System.out.println("guess: ");
Tamir.SharpSsh.java.String[] guess=new Tamir.SharpSsh.java.String[PROPOSAL_MAX];
Buffer sb=new Buffer(I_S); sb.setOffSet(17);
Buffer cb=new Buffer(I_C); cb.setOffSet(17);
for(int i=0; i<PROPOSAL_MAX; i++)
{
byte[] sp=sb.getString(); // server proposal
byte[] cp=cb.getString(); // client proposal
//System.out.println("server-proposal: |"+new String(sp)+"|");
//System.out.println("client-proposal: |"+new String(cp)+"|");
int j=0;
int k=0;
//System.out.println(new String(cp));
//loop(using BREAK instead):
while(j<cp.Length)
{
while(j<cp.Length && cp[j]!=',')j++;
if(k==j) return null;
String algorithm=Util.getString(cp, k, j-k);
//System.out.println("algorithm: "+algorithm);
int l=0;
int m=0;
while(l<sp.Length)
{
while(l<sp.Length && sp[l]!=',')l++;
if(m==l) return null;
//System.out.println(" "+new String(sp, m, l-m));
if(algorithm.Equals(Util.getString(sp, m, l-m)))
{
guess[i]=algorithm;
//System.out.println(" "+algorithm);
goto BREAK;
}
l++;
m=l;
}
j++;
k=j;
}
BREAK:
if(j==0)
{
guess[i]="";
}
else if(guess[i]==null)
{
//System.out.println(" fail");
return null;
}
}
// for(int i=0; i<PROPOSAL_MAX; i++){
// System.out.println("guess: ["+guess[i]+"]");
// }
return guess;
}
public String getFingerPrint()
{
HASH hash=null;
try
{
Type t=Type.GetType(session.getConfig("md5"));
hash=(HASH)(Activator.CreateInstance(t));
}
catch(Exception e){ Console.Error.WriteLine("getFingerPrint: "+e); }
return Util.getFingerPrint(hash, getHostKey());
}
internal byte[] getK(){ return K; }
internal byte[] getH(){ return H; }
internal HASH getHash(){ return sha; }
internal byte[] getHostKey(){ return K_S; }
}
}

View file

@ -1,738 +0,0 @@
using System;
using System.IO;
using System.Runtime.CompilerServices;
namespace Tamir.SharpSsh.jsch
{
/* -*-mode:java; c-basic-offset:2; -*- */
/*
Copyright (c) 2002,2003,2004 ymnk, JCraft,Inc. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the distribution.
3. The names of the authors may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
public abstract class KeyPair
{
public const int ERROR=0;
public const int DSA=1;
public const int RSA=2;
public const int UNKNOWN=3;
internal const int VENDOR_OPENSSH=0;
internal const int VENDOR_FSECURE=1;
internal int vendor=VENDOR_OPENSSH;
private static byte[] cr=Util.getBytes("\n");
public static KeyPair genKeyPair(JSch jsch, int type)
{
return genKeyPair(jsch, type, 1024);
}
public static KeyPair genKeyPair(JSch jsch, int type, int key_size)
{
KeyPair kpair=null;
if(type==DSA){ kpair=new KeyPairDSA(jsch); }
else if(type==RSA){ kpair=new KeyPairRSA(jsch); }
if(kpair!=null)
{
kpair.generate(key_size);
}
return kpair;
}
internal abstract void generate(int key_size);
internal abstract byte[] getBegin();
internal abstract byte[] getEnd();
public abstract int getKeySize();
internal JSch jsch=null;
private Cipher cipher;
private HASH hash;
private Random random;
private byte[] passphrase;
public KeyPair(JSch jsch)
{
this.jsch=jsch;
}
static byte[][] header={Util.getBytes( "Proc-Type: 4,ENCRYPTED"),
Util.getBytes("DEK-Info: DES-EDE3-CBC,")};
internal abstract byte[] getPrivateKey();
private void Write(Stream s, byte[] arr)
{
s.Write(arr, 0, arr.Length);
}
public void writePrivateKey(Stream outs)
{
byte[] plain=getPrivateKey();
byte[][] _iv=new byte[1][];
byte[] encoded=encrypt(plain, _iv);
byte[] iv=_iv[0];
byte[] prv=Util.toBase64(encoded, 0, encoded.Length);
try
{
Write(outs, getBegin()); Write(outs,cr);
if(passphrase!=null)
{
Write(outs, header[0]); Write(outs,cr);
Write(outs, header[1]);
for(int j=0; j<iv.Length; j++)
{
outs.WriteByte(b2a((byte)((iv[j]>>4)&0x0f)));
outs.WriteByte(b2a((byte)(iv[j]&0x0f)));
}
Write(outs,cr);
Write(outs,cr);
}
int i=0;
while(i<prv.Length)
{
if(i+64<prv.Length)
{
outs.Write(prv, i, 64);
Write(outs,cr);
i+=64;
continue;
}
outs.Write(prv, i, prv.Length-i);
Write(outs,cr);
break;
}
Write(outs, getEnd()); Write(outs,cr);
//outs.close();
}
catch(Exception e)
{
Console.WriteLine(e);
}
}
private static byte[] space=Util.getBytes(" ");
internal abstract byte[] getKeyTypeName();
public abstract int getKeyType();
public virtual byte[] getPublicKeyBlob(){ return publickeyblob; }
public void writePublicKey(Stream outs, String comment)
{
byte[] pubblob=getPublicKeyBlob();
byte[] pub=Util.toBase64(pubblob, 0, pubblob.Length);
try
{
Write(outs, getKeyTypeName()); Write(outs, space);
outs.Write(pub, 0, pub.Length); Write(outs, space);
Write(outs, Util.getBytes( comment));
Write(outs,cr);
}
catch(Exception e)
{
Console.WriteLine(e);
}
}
public void writePublicKey(String name, String comment)
{
FileStream fos=new FileStream(name,FileMode.OpenOrCreate);
writePublicKey(fos, comment);
fos.Close();
}
public void writeSECSHPublicKey(Stream outs, String comment)
{
byte[] pubblob=getPublicKeyBlob();
byte[] pub=Util.toBase64(pubblob, 0, pubblob.Length);
try
{
Write(outs, Util.getBytes( "---- BEGIN SSH2 PUBLIC KEY ----")); Write(outs, cr);
Write(outs, Util.getBytes("Comment: \""+comment+"\"")); Write(outs,cr);
int index=0;
while(index<pub.Length)
{
int len=70;
if((pub.Length-index)<len)len=pub.Length-index;
outs.Write(pub, index, len); Write(outs, cr);
index+=len;
}
Write(outs, Util.getBytes("---- END SSH2 PUBLIC KEY ----")); Write(outs,cr);
}
catch(Exception e)
{
Console.WriteLine(e);
}
}
public void writeSECSHPublicKey(String name, String comment)
{
FileStream fos=new FileStream(name, FileMode.OpenOrCreate);
writeSECSHPublicKey(fos, comment);
fos.Close();
}
public void writePrivateKey(String name)
{
FileStream fos=new FileStream(name, FileMode.OpenOrCreate);
writePrivateKey(fos);
fos.Close();
}
public String getFingerPrint()
{
if(hash==null) hash=genHash();
byte[] kblob=getPublicKeyBlob();
if(kblob==null) return null;
return getKeySize()+" "+Util.getFingerPrint(hash, kblob);
}
private byte[] encrypt(byte[] plain, byte[][] _iv)
{
if(passphrase==null) return plain;
if(cipher==null) cipher=genCipher();
byte[] iv=_iv[0]=new byte[cipher.getIVSize()];
if(random==null) random=genRandom();
random.fill(iv, 0, iv.Length);
byte[] key=genKey(passphrase, iv);
byte[] encoded=plain;
int bsize=cipher.getBlockSize();
if(encoded.Length%bsize!=0)
{
byte[] foo=new byte[(encoded.Length/bsize+1)*bsize];
Array.Copy(encoded, 0, foo, 0, encoded.Length);
encoded=foo;
}
try
{
cipher.init(Cipher.ENCRYPT_MODE, key, iv);
cipher.update(encoded, 0, encoded.Length, encoded, 0);
}
catch(Exception e)
{
Console.WriteLine(e);
}
return encoded;
}
internal abstract bool parse(byte[] data);
private byte[] decrypt(byte[] data, byte[] passphrase, byte[] iv)
{
/*
if(iv==null){ // FSecure
iv=new byte[8];
for(int i=0; i<iv.Length; i++)iv[i]=0;
}
*/
try
{
byte[] key=genKey(passphrase, iv);
cipher.init(Cipher.DECRYPT_MODE, key, iv);
byte[] plain=new byte[data.Length];
cipher.update(data, 0, data.Length, plain, 0);
return plain;
}
catch(Exception e)
{
Console.WriteLine(e);
}
return null;
}
internal int writeSEQUENCE(byte[] buf, int index, int len)
{
buf[index++]=0x30;
index=writeLength(buf, index, len);
return index;
}
internal int writeINTEGER(byte[] buf, int index, byte[] data)
{
buf[index++]=0x02;
index=writeLength(buf, index, data.Length);
Array.Copy(data, 0, buf, index, data.Length);
index+=data.Length;
return index;
}
internal int countLength(int len)
{
int i=1;
if(len<=0x7f) return i;
while(len>0)
{
len>>=8;
i++;
}
return i;
}
internal int writeLength(byte[] data, int index, int len)
{
int i=countLength(len)-1;
if(i==0)
{
data[index++]=(byte)len;
return index;
}
data[index++]=(byte)(0x80|i);
int j=index+i;
while(i>0)
{
data[index+i-1]=(byte)(len&0xff);
len>>=8;
i--;
}
return j;
}
private Random genRandom()
{
if(random==null)
{
try
{
Type t=Type.GetType(jsch.getConfig("random"));
random=(Random)Activator.CreateInstance(t);
}
catch(Exception e){ Console.Error.WriteLine("connect: random "+e); }
}
return random;
}
private HASH genHash()
{
try
{
Type t=Type.GetType(jsch.getConfig("md5"));
hash=(HASH)Activator.CreateInstance(t);
hash.init();
}
catch//(Exception e)
{
}
return hash;
}
private Cipher genCipher()
{
try
{
Type t;
t=Type.GetType(jsch.getConfig("3des-cbc"));
cipher=(Cipher)(Activator.CreateInstance(t));
}
catch//(Exception e)
{
}
return cipher;
}
/*
hash is MD5
h(0) <- hash(passphrase, iv);
h(n) <- hash(h(n-1), passphrase, iv);
key <- (h(0),...,h(n))[0,..,key.Length];
*/
[MethodImpl(MethodImplOptions.Synchronized)]
internal byte[] genKey(byte[] passphrase, byte[] iv)
{
if(cipher==null) cipher=genCipher();
if(hash==null) hash=genHash();
byte[] key=new byte[cipher.getBlockSize()];
int hsize=hash.getBlockSize();
byte[] hn=new byte[key.Length/hsize*hsize+
(key.Length%hsize==0?0:hsize)];
try
{
byte[] tmp=null;
if(vendor==VENDOR_OPENSSH)
{
for(int index=0; index+hsize<=hn.Length;)
{
if(tmp!=null){ hash.update(tmp, 0, tmp.Length); }
hash.update(passphrase, 0, passphrase.Length);
hash.update(iv, 0, iv.Length);
tmp=hash.digest();
Array.Copy(tmp, 0, hn, index, tmp.Length);
index+=tmp.Length;
}
Array.Copy(hn, 0, key, 0, key.Length);
}
else if(vendor==VENDOR_FSECURE)
{
for(int index=0; index+hsize<=hn.Length;)
{
if(tmp!=null){ hash.update(tmp, 0, tmp.Length); }
hash.update(passphrase, 0, passphrase.Length);
tmp=hash.digest();
Array.Copy(tmp, 0, hn, index, tmp.Length);
index+=tmp.Length;
}
Array.Copy(hn, 0, key, 0, key.Length);
}
}
catch(Exception e)
{
Console.WriteLine(e);
}
return key;
}
public void setPassphrase(String passphrase)
{
if(passphrase==null || passphrase.Length==0)
{
setPassphrase((byte[])null);
}
else
{
setPassphrase(Util.getBytes( passphrase ));
}
}
public void setPassphrase(byte[] passphrase)
{
if(passphrase!=null && passphrase.Length==0)
passphrase=null;
this.passphrase=passphrase;
}
private bool encrypted=false;
private byte[] data=null;
private byte[] iv=null;
private byte[] publickeyblob=null;
public bool isEncrypted(){ return encrypted; }
public bool decrypt(String _passphrase)
{
byte[] passphrase= Util.getBytes( _passphrase );
byte[] foo=decrypt(data, passphrase, iv);
if(parse(foo))
{
encrypted=false;
}
return !encrypted;
}
public static KeyPair load(JSch jsch, String prvkey)
{
String pubkey=prvkey+".pub";
// if(!new File(pubkey).exists())
if(!File.Exists(pubkey))
{
pubkey=null;
}
return load(jsch, prvkey, pubkey);
}
public static KeyPair load(JSch jsch, String prvkey, String pubkey)
{
byte[] iv=new byte[8]; // 8
bool encrypted=true;
byte[] data=null;
byte[] publickeyblob=null;
int type=ERROR;
int vendor=VENDOR_OPENSSH;
try
{
//File file=new File(prvkey);
FileStream fis=File.OpenRead(prvkey);
byte[] buf=new byte[(int)(fis.Length)];
int len=fis.Read(buf, 0, buf.Length);
fis.Close();
int i=0;
while(i<len)
{
if(buf[i]=='B'&& buf[i+1]=='E'&& buf[i+2]=='G'&& buf[i+3]=='I')
{
i+=6;
if(buf[i]=='D'&& buf[i+1]=='S'&& buf[i+2]=='A'){ type=DSA; }
else if(buf[i]=='R'&& buf[i+1]=='S'&& buf[i+2]=='A'){ type=RSA; }
else if(buf[i]=='S'&& buf[i+1]=='S'&& buf[i+2]=='H')
{ // FSecure
type=UNKNOWN;
vendor=VENDOR_FSECURE;
}
else
{
//System.outs.println("invalid format: "+identity);
throw new JSchException("invaid privatekey: "+prvkey);
}
i+=3;
continue;
}
if(buf[i]=='C'&& buf[i+1]=='B'&& buf[i+2]=='C'&& buf[i+3]==',')
{
i+=4;
for(int ii=0; ii<iv.Length; ii++)
{
iv[ii]=(byte)(((a2b(buf[i++])<<4)&0xf0)+(a2b(buf[i++])&0xf));
}
continue;
}
if(buf[i]==0x0d &&
i+1<buf.Length && buf[i+1]==0x0a)
{
i++;
continue;
}
if(buf[i]==0x0a && i+1<buf.Length)
{
if(buf[i+1]==0x0a){ i+=2; break; }
if(buf[i+1]==0x0d &&
i+2<buf.Length && buf[i+2]==0x0a)
{
i+=3; break;
}
bool inheader=false;
for(int j=i+1; j<buf.Length; j++)
{
if(buf[j]==0x0a) break;
//if(buf[j]==0x0d) break;
if(buf[j]==':'){inheader=true; break;}
}
if(!inheader)
{
i++;
encrypted=false; // no passphrase
break;
}
}
i++;
}
if(type==ERROR)
{
throw new JSchException("invaid privatekey: "+prvkey);
}
int start=i;
while(i<len)
{
if(buf[i]==0x0a)
{
bool xd=(buf[i-1]==0x0d);
Array.Copy(buf, i+1,
buf,
i-(xd ? 1 : 0),
len-i-1-(xd ? 1 : 0)
);
if(xd)len--;
len--;
continue;
}
if(buf[i]=='-'){ break; }
i++;
}
data=Util.fromBase64(buf, start, i-start);
if(data.Length>4 && // FSecure
data[0]==(byte)0x3f &&
data[1]==(byte)0x6f &&
data[2]==(byte)0xf9 &&
data[3]==(byte)0xeb)
{
Buffer _buf=new Buffer(data);
_buf.getInt(); // 0x3f6ff9be
_buf.getInt();
byte[]_type=_buf.getString();
//System.outs.println("type: "+new String(_type));
byte[] _cipher=_buf.getString();
String cipher=Util.getString(_cipher);
//System.outs.println("cipher: "+cipher);
if(cipher.Equals("3des-cbc"))
{
_buf.getInt();
byte[] foo=new byte[data.Length-_buf.getOffSet()];
_buf.getByte(foo);
data=foo;
encrypted=true;
throw new JSchException("unknown privatekey format: "+prvkey);
}
else if(cipher.Equals("none"))
{
_buf.getInt();
_buf.getInt();
encrypted=false;
byte[] foo=new byte[data.Length-_buf.getOffSet()];
_buf.getByte(foo);
data=foo;
}
}
if(pubkey!=null)
{
try
{
//file=new File(pubkey);
fis=File.OpenRead(pubkey);
buf=new byte[(int)(fis.Length)];
len=fis.Read(buf, 0, buf.Length);
fis.Close();
if(buf.Length>4 && // FSecure's public key
buf[0]=='-' && buf[1]=='-' && buf[2]=='-' && buf[3]=='-')
{
bool valid=true;
i=0;
do{i++;}while(buf.Length>i && buf[i]!=0x0a);
if(buf.Length<=i) {valid=false;}
while(valid)
{
if(buf[i]==0x0a)
{
bool inheader=false;
for(int j=i+1; j<buf.Length; j++)
{
if(buf[j]==0x0a) break;
if(buf[j]==':'){inheader=true; break;}
}
if(!inheader)
{
i++;
break;
}
}
i++;
}
if(buf.Length<=i){valid=false;}
start=i;
while(valid && i<len)
{
if(buf[i]==0x0a)
{
Array.Copy(buf, i+1, buf, i, len-i-1);
len--;
continue;
}
if(buf[i]=='-'){ break; }
i++;
}
if(valid)
{
publickeyblob=Util.fromBase64(buf, start, i-start);
if(type==UNKNOWN)
{
if(publickeyblob[8]=='d'){ type=DSA; }
else if(publickeyblob[8]=='r'){ type=RSA; }
}
}
}
else
{
if(buf[0]=='s'&& buf[1]=='s'&& buf[2]=='h' && buf[3]=='-')
{
i=0;
while(i<len){ if(buf[i]==' ')break; i++;} i++;
if(i<len)
{
start=i;
while(i<len){ if(buf[i]==' ')break; i++;}
publickeyblob=Util.fromBase64(buf, start, i-start);
}
}
}
}
catch//(Exception ee)
{
}
}
}
catch(Exception e)
{
if(e is JSchException) throw (JSchException)e;
throw new JSchException(e.ToString());
}
KeyPair kpair=null;
if(type==DSA){ kpair=new KeyPairDSA(jsch); }
else if(type==RSA){ kpair=new KeyPairRSA(jsch); }
if(kpair!=null)
{
kpair.encrypted=encrypted;
kpair.publickeyblob=publickeyblob;
kpair.vendor=vendor;
if(encrypted)
{
kpair.iv=iv;
kpair.data=data;
}
else
{
if(kpair.parse(data))
{
return kpair;
}
else
{
throw new JSchException("invaid privatekey: "+prvkey);
}
}
}
return kpair;
}
static private byte a2b(byte c)
{
if('0'<=c&&c<='9') return (byte)(c-'0');
return (byte)(c-'a'+10);
}
static private byte b2a(byte c)
{
if(0<=c&&c<=9) return (byte)(c+'0');
return (byte)(c-10+'A');
}
public virtual void dispose()
{
passphrase=null;
}
}
}

View file

@ -1,246 +0,0 @@
using System;
namespace Tamir.SharpSsh.jsch
{
/* -*-mode:java; c-basic-offset:2; -*- */
/*
Copyright (c) 2002,2003,2004 ymnk, JCraft,Inc. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the distribution.
3. The names of the authors may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
public class KeyPairDSA : KeyPair
{
private byte[] P_array;
private byte[] Q_array;
private byte[] G_array;
private byte[] pub_array;
private byte[] prv_array;
//private int key_size=0;
private int key_size=1024;
public KeyPairDSA(JSch jsch):base(jsch)
{
}
internal override void generate(int key_size)
{
this.key_size=key_size;
try
{
Type t=Type.GetType(jsch.getConfig("keypairgen.dsa"));
KeyPairGenDSA keypairgen=(KeyPairGenDSA)(Activator.CreateInstance(t));
keypairgen.init(key_size);
P_array=keypairgen.getP();
Q_array=keypairgen.getQ();
G_array=keypairgen.getG();
pub_array=keypairgen.getY();
prv_array=keypairgen.getX();
keypairgen=null;
}
catch(Exception e)
{
Console.Error.WriteLine("KeyPairDSA: "+e);
throw new JSchException(e.ToString());
}
}
private static byte[] begin= Util.getBytes( "-----BEGIN DSA PRIVATE KEY-----" );
private static byte[] end=Util.getBytes("-----END DSA PRIVATE KEY-----");
internal override byte[] getBegin(){ return begin; }
internal override byte[] getEnd(){ return end; }
internal override byte[] getPrivateKey()
{
int content=
1+countLength(1) + 1 + // INTEGER
1+countLength(P_array.Length) + P_array.Length + // INTEGER P
1+countLength(Q_array.Length) + Q_array.Length + // INTEGER Q
1+countLength(G_array.Length) + G_array.Length + // INTEGER G
1+countLength(pub_array.Length) + pub_array.Length + // INTEGER pub
1+countLength(prv_array.Length) + prv_array.Length; // INTEGER prv
int total=
1+countLength(content)+content; // SEQUENCE
byte[] plain=new byte[total];
int index=0;
index=writeSEQUENCE(plain, index, content);
index=writeINTEGER(plain, index, new byte[1]); // 0
index=writeINTEGER(plain, index, P_array);
index=writeINTEGER(plain, index, Q_array);
index=writeINTEGER(plain, index, G_array);
index=writeINTEGER(plain, index, pub_array);
index=writeINTEGER(plain, index, prv_array);
return plain;
}
internal override bool parse(byte[] plain)
{
try
{
if(vendor==VENDOR_FSECURE)
{
if(plain[0]!=0x30)
{ // FSecure
Buffer buf=new Buffer(plain);
buf.getInt();
P_array=buf.getMPIntBits();
G_array=buf.getMPIntBits();
Q_array=buf.getMPIntBits();
pub_array=buf.getMPIntBits();
prv_array=buf.getMPIntBits();
return true;
}
return false;
}
int index=0;
int Length=0;
if(plain[index]!=0x30)return false;
index++; // SEQUENCE
Length=plain[index++]&0xff;
if((Length&0x80)!=0)
{
int foo=Length&0x7f; Length=0;
while(foo-->0){ Length=(Length<<8)+(plain[index++]&0xff); }
}
if(plain[index]!=0x02)return false;
index++; // INTEGER
Length=plain[index++]&0xff;
if((Length&0x80)!=0)
{
int foo=Length&0x7f; Length=0;
while(foo-->0){ Length=(Length<<8)+(plain[index++]&0xff); }
}
index+=Length;
index++;
Length=plain[index++]&0xff;
if((Length&0x80)!=0)
{
int foo=Length&0x7f; Length=0;
while(foo-->0){ Length=(Length<<8)+(plain[index++]&0xff); }
}
P_array=new byte[Length];
Array.Copy(plain, index, P_array, 0, Length);
index+=Length;
index++;
Length=plain[index++]&0xff;
if((Length&0x80)!=0)
{
int foo=Length&0x7f; Length=0;
while(foo-->0){ Length=(Length<<8)+(plain[index++]&0xff); }
}
Q_array=new byte[Length];
Array.Copy(plain, index, Q_array, 0, Length);
index+=Length;
index++;
Length=plain[index++]&0xff;
if((Length&0x80)!=0)
{
int foo=Length&0x7f; Length=0;
while(foo-->0){ Length=(Length<<8)+(plain[index++]&0xff); }
}
G_array=new byte[Length];
Array.Copy(plain, index, G_array, 0, Length);
index+=Length;
index++;
Length=plain[index++]&0xff;
if((Length&0x80)!=0)
{
int foo=Length&0x7f; Length=0;
while(foo-->0){ Length=(Length<<8)+(plain[index++]&0xff); }
}
pub_array=new byte[Length];
Array.Copy(plain, index, pub_array, 0, Length);
index+=Length;
index++;
Length=plain[index++]&0xff;
if((Length&0x80)!=0)
{
int foo=Length&0x7f; Length=0;
while(foo-->0){ Length=(Length<<8)+(plain[index++]&0xff); }
}
prv_array=new byte[Length];
Array.Copy(plain, index, prv_array, 0, Length);
index+=Length;
}
catch//(Exception e)
{
//System.out.println(e);
//e.printStackTrace();
return false;
}
return true;
}
public override byte[] getPublicKeyBlob()
{
byte[] foo=base.getPublicKeyBlob();
if(foo!=null) return foo;
if(P_array==null) return null;
Buffer buf=new Buffer(sshdss.Length+4+
P_array.Length+4+
Q_array.Length+4+
G_array.Length+4+
pub_array.Length+4);
buf.putString(sshdss);
buf.putString(P_array);
buf.putString(Q_array);
buf.putString(G_array);
buf.putString(pub_array);
return buf.buffer;
}
private static byte[] sshdss= Util.getBytes( "ssh-dss" );
internal override byte[] getKeyTypeName(){return sshdss;}
public override int getKeyType(){return DSA;}
public override int getKeySize(){return key_size; }
public override void dispose()
{
base.dispose();
P_array=null;
Q_array=null;
G_array=null;
pub_array=null;
prv_array=null;
}
}
}

View file

@ -1,44 +0,0 @@
using System;
namespace Tamir.SharpSsh.jsch
{
/* -*-mode:java; c-basic-offset:2; -*- */
/*
Copyright (c) 2002,2003,2004 ymnk, JCraft,Inc. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the distribution.
3. The names of the authors may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
public interface KeyPairGenDSA
{
void init(int key_size);
byte[] getX();
byte[] getY();
byte[] getP();
byte[] getQ();
byte[] getG();
}
}

View file

@ -1,48 +0,0 @@
using System;
namespace Tamir.SharpSsh.jsch
{
/* -*-mode:java; c-basic-offset:2; -*- */
/*
Copyright (c) 2002,2003,2004 ymnk, JCraft,Inc. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the distribution.
3. The names of the authors may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
public interface KeyPairGenRSA
{
void init(int key_size);
byte[] getD();
byte[] getE();
byte[] getN();
byte[] getC();
byte[] getEP();
byte[] getEQ();
byte[] getP();
byte[] getQ();
}
}

View file

@ -1,352 +0,0 @@
using System;
namespace Tamir.SharpSsh.jsch
{
/* -*-mode:java; c-basic-offset:2; -*- */
/*
Copyright (c) 2002,2003,2004 ymnk, JCraft,Inc. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the distribution.
3. The names of the authors may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
public class KeyPairRSA : KeyPair
{
private byte[] prv_array;
private byte[] pub_array;
private byte[] n_array;
private byte[] p_array; // prime p
private byte[] q_array; // prime q
private byte[] ep_array; // prime exponent p
private byte[] eq_array; // prime exponent q
private byte[] c_array; // coefficient
//private int key_size=0;
private int key_size=1024;
public KeyPairRSA(JSch jsch):base(jsch)
{
}
internal override void generate(int key_size)
{
this.key_size=key_size;
try
{
Type t=Type.GetType(jsch.getConfig("keypairgen.rsa"));
KeyPairGenRSA keypairgen=(KeyPairGenRSA)(Activator.CreateInstance(t));
keypairgen.init(key_size);
pub_array=keypairgen.getE();
prv_array=keypairgen.getD();
n_array=keypairgen.getN();
p_array=keypairgen.getP();
q_array=keypairgen.getQ();
ep_array=keypairgen.getEP();
eq_array=keypairgen.getEQ();
c_array=keypairgen.getC();
keypairgen=null;
}
catch(Exception e)
{
Console.WriteLine("KeyPairRSA: "+e);
throw new JSchException(e.ToString());
}
}
private static byte[] begin= Util.getBytes( "-----BEGIN RSA PRIVATE KEY-----");
private static byte[] end=Util.getBytes("-----END RSA PRIVATE KEY-----");
internal override byte[] getBegin(){ return begin; }
internal override byte[] getEnd(){ return end; }
internal override byte[] getPrivateKey()
{
int content=
1+countLength(1) + 1 + // INTEGER
1+countLength(n_array.Length) + n_array.Length + // INTEGER N
1+countLength(pub_array.Length) + pub_array.Length + // INTEGER pub
1+countLength(prv_array.Length) + prv_array.Length+ // INTEGER prv
1+countLength(p_array.Length) + p_array.Length+ // INTEGER p
1+countLength(q_array.Length) + q_array.Length+ // INTEGER q
1+countLength(ep_array.Length) + ep_array.Length+ // INTEGER ep
1+countLength(eq_array.Length) + eq_array.Length+ // INTEGER eq
1+countLength(c_array.Length) + c_array.Length; // INTEGER c
int total=
1+countLength(content)+content; // SEQUENCE
byte[] plain=new byte[total];
int index=0;
index=writeSEQUENCE(plain, index, content);
index=writeINTEGER(plain, index, new byte[1]); // 0
index=writeINTEGER(plain, index, n_array);
index=writeINTEGER(plain, index, pub_array);
index=writeINTEGER(plain, index, prv_array);
index=writeINTEGER(plain, index, p_array);
index=writeINTEGER(plain, index, q_array);
index=writeINTEGER(plain, index, ep_array);
index=writeINTEGER(plain, index, eq_array);
index=writeINTEGER(plain, index, c_array);
return plain;
}
internal override bool parse(byte [] plain)
{
/*
byte[] p_array;
byte[] q_array;
byte[] dmp1_array;
byte[] dmq1_array;
byte[] iqmp_array;
*/
try
{
int index=0;
int Length=0;
if(vendor==VENDOR_FSECURE)
{
if(plain[index]!=0x30)
{ // FSecure
Buffer buf=new Buffer(plain);
pub_array=buf.getMPIntBits();
prv_array=buf.getMPIntBits();
n_array=buf.getMPIntBits();
byte[] u_array=buf.getMPIntBits();
p_array=buf.getMPIntBits();
q_array=buf.getMPIntBits();
return true;
}
return false;
}
index++; // SEQUENCE
Length=plain[index++]&0xff;
if((Length&0x80)!=0)
{
int foo=Length&0x7f; Length=0;
while(foo-->0){ Length=(Length<<8)+(plain[index++]&0xff); }
}
if(plain[index]!=0x02)return false;
index++; // INTEGER
Length=plain[index++]&0xff;
if((Length&0x80)!=0)
{
int foo=Length&0x7f; Length=0;
while(foo-->0){ Length=(Length<<8)+(plain[index++]&0xff); }
}
index+=Length;
//System.out.println("int: len="+Length);
//System.out.print(Integer.toHexString(plain[index-1]&0xff)+":");
//System.out.println("");
index++;
Length=plain[index++]&0xff;
if((Length&0x80)!=0)
{
int foo=Length&0x7f; Length=0;
while(foo-->0){ Length=(Length<<8)+(plain[index++]&0xff); }
}
n_array=new byte[Length];
Array.Copy(plain, index, n_array, 0, Length);
index+=Length;
/*
System.out.println("int: N len="+Length);
for(int i=0; i<n_array.Length; i++){
System.out.print(Integer.toHexString(n_array[i]&0xff)+":");
}
System.out.println("");
*/
index++;
Length=plain[index++]&0xff;
if((Length&0x80)!=0)
{
int foo=Length&0x7f; Length=0;
while(foo-->0){ Length=(Length<<8)+(plain[index++]&0xff); }
}
pub_array=new byte[Length];
Array.Copy(plain, index, pub_array, 0, Length);
index+=Length;
/*
System.out.println("int: E len="+Length);
for(int i=0; i<pub_array.Length; i++){
System.out.print(Integer.toHexString(pub_array[i]&0xff)+":");
}
System.out.println("");
*/
index++;
Length=plain[index++]&0xff;
if((Length&0x80)!=0)
{
int foo=Length&0x7f; Length=0;
while(foo-->0){ Length=(Length<<8)+(plain[index++]&0xff); }
}
prv_array=new byte[Length];
Array.Copy(plain, index, prv_array, 0, Length);
index+=Length;
/*
System.out.println("int: prv len="+Length);
for(int i=0; i<prv_array.Length; i++){
System.out.print(Integer.toHexString(prv_array[i]&0xff)+":");
}
System.out.println("");
*/
index++;
Length=plain[index++]&0xff;
if((Length&0x80)!=0)
{
int foo=Length&0x7f; Length=0;
while(foo-->0){ Length=(Length<<8)+(plain[index++]&0xff); }
}
p_array=new byte[Length];
Array.Copy(plain, index, p_array, 0, Length);
index+=Length;
/*
System.out.println("int: P len="+Length);
for(int i=0; i<p_array.Length; i++){
System.out.print(Integer.toHexString(p_array[i]&0xff)+":");
}
System.out.println("");
*/
index++;
Length=plain[index++]&0xff;
if((Length&0x80)!=0)
{
int foo=Length&0x7f; Length=0;
while(foo-->0){ Length=(Length<<8)+(plain[index++]&0xff); }
}
q_array=new byte[Length];
Array.Copy(plain, index, q_array, 0, Length);
index+=Length;
/*
System.out.println("int: q len="+Length);
for(int i=0; i<q_array.Length; i++){
System.out.print(Integer.toHexString(q_array[i]&0xff)+":");
}
System.out.println("");
*/
index++;
Length=plain[index++]&0xff;
if((Length&0x80)!=0)
{
int foo=Length&0x7f; Length=0;
while(foo-->0){ Length=(Length<<8)+(plain[index++]&0xff); }
}
ep_array=new byte[Length];
Array.Copy(plain, index, ep_array, 0, Length);
index+=Length;
/*
System.out.println("int: ep len="+Length);
for(int i=0; i<ep_array.Length; i++){
System.out.print(Integer.toHexString(ep_array[i]&0xff)+":");
}
System.out.println("");
*/
index++;
Length=plain[index++]&0xff;
if((Length&0x80)!=0)
{
int foo=Length&0x7f; Length=0;
while(foo-->0){ Length=(Length<<8)+(plain[index++]&0xff); }
}
eq_array=new byte[Length];
Array.Copy(plain, index, eq_array, 0, Length);
index+=Length;
/*
System.out.println("int: eq len="+Length);
for(int i=0; i<eq_array.Length; i++){
System.out.print(Integer.toHexString(eq_array[i]&0xff)+":");
}
System.out.println("");
*/
index++;
Length=plain[index++]&0xff;
if((Length&0x80)!=0)
{
int foo=Length&0x7f; Length=0;
while(foo-->0){ Length=(Length<<8)+(plain[index++]&0xff); }
}
c_array=new byte[Length];
Array.Copy(plain, index, c_array, 0, Length);
index+=Length;
/*
System.out.println("int: c len="+Length);
for(int i=0; i<c_array.Length; i++){
System.out.print(Integer.toHexString(c_array[i]&0xff)+":");
}
System.out.println("");
*/
}
catch//(Exception e)
{
//System.out.println(e);
return false;
}
return true;
}
public override byte[] getPublicKeyBlob()
{
byte[] foo=base.getPublicKeyBlob();
if(foo!=null) return foo;
if(pub_array==null) return null;
Buffer buf=new Buffer(sshrsa.Length+4+
pub_array.Length+4+
n_array.Length+4);
buf.putString(sshrsa);
buf.putString(pub_array);
buf.putString(n_array);
return buf.buffer;
}
private static byte[] sshrsa= Util.getBytes( "ssh-rsa" );
internal override byte[] getKeyTypeName(){return sshrsa;}
public override int getKeyType(){return RSA;}
public override int getKeySize(){return key_size; }
public override void dispose()
{
base.dispose();
pub_array=null;
prv_array=null;
n_array=null;
p_array=null;
q_array=null;
ep_array=null;
eq_array=null;
c_array=null;
}
}
}

View file

@ -1,523 +0,0 @@
using System;
using System.IO;
namespace Tamir.SharpSsh.jsch
{
/* -*-mode:java; c-basic-offset:2; -*- */
/*
Copyright (c) 2002,2003,2004 ymnk, JCraft,Inc. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the distribution.
3. The names of the authors may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
public class KnownHosts : HostKeyRepository
{
private const String _known_hosts="known_hosts";
/*
static final int OK=0;
static final int NOT_INCLUDED=1;
static final int CHANGED=2;
*/
/*
static final int SSHDSS=0;
static final int SSHRSA=1;
static final int UNKNOWN=2;
*/
private JSch jsch=null;
private String known_hosts=null;
private System.Collections.ArrayList pool=null;
internal KnownHosts(JSch jsch) : base()
{
this.jsch=jsch;
pool=new System.Collections.ArrayList();
}
internal void setKnownHosts(String foo)
{
try
{
known_hosts=foo;
FileStream fis=File.OpenRead(foo);
setKnownHosts( new StreamReader(fis) );
}
catch
{
}
}
internal void setKnownHosts(StreamReader foo)
{
pool.Clear();
System.Text.StringBuilder sb=new System.Text.StringBuilder();
byte i;
int j;
bool error=false;
try
{
StreamReader fis=foo;
String host;
String key=null;
int type;
byte[] buf=new byte[1024];
int bufl=0;
loop:
while(true)
{
bufl=0;
while(true)
{
j=fis.Read();
if(j==-1){ goto break_loop;}
if(j==0x0d){ continue; }
if(j==0x0a){ break; }
buf[bufl++]=(byte)j;
}
j=0;
while(j<bufl)
{
i=buf[j];
if(i==' '||i=='\t'){ j++; continue; }
if(i=='#')
{
addInvalidLine(System.Text.Encoding.Default.GetString(buf, 0, bufl));
goto loop;
}
break;
}
if(j>=bufl)
{
addInvalidLine(System.Text.Encoding.Default.GetString(buf, 0, bufl));
goto loop;
}
sb.Length = 0;
while(j<bufl)
{
i=buf[j++];
if(i==0x20 || i=='\t'){ break; }
sb.Append((char)i);
}
host=sb.ToString();
if(j>=bufl || host.Length==0)
{
addInvalidLine(System.Text.Encoding.Default.GetString(buf, 0, bufl));
goto loop;
}
sb.Length=0;
type=-1;
while(j<bufl)
{
i=buf[j++];
if(i==0x20 || i=='\t'){ break; }
sb.Append((char)i);
}
if(sb.ToString().Equals("ssh-dss")){ type=HostKey.SSHDSS; }
else if(sb.ToString().Equals("ssh-rsa")){ type=HostKey.SSHRSA; }
else { j=bufl; }
if(j>=bufl)
{
addInvalidLine(Util.getString(buf, 0, bufl));
goto loop;
}
sb.Length=0;
while(j<bufl)
{
i=buf[j++];
if(i==0x0d){ continue; }
if(i==0x0a){ break; }
sb.Append((char)i);
}
key=sb.ToString();
if(key.Length==0)
{
addInvalidLine(Util.getString(buf, 0, bufl));
goto loop;
}
//System.out.println(host);
//System.out.println("|"+key+"|");
HostKey hk = new HostKey(host, type,
Util.fromBase64(Util.getBytes(key), 0,
key.Length));
pool.Add(hk);
}
break_loop:
fis.Close();
if(error)
{
throw new JSchException("KnownHosts: invalid format");
}
}
catch(Exception e)
{
if(e is JSchException)
{
throw (JSchException)e;
}
throw new JSchException(e.ToString());
}
}
private void addInvalidLine(String line)
{
HostKey hk = new HostKey(line, HostKey.UNKNOWN, null);
pool.Add(hk);
}
String getKnownHostsFile(){ return known_hosts; }
public override String getKnownHostsRepositoryID(){ return known_hosts; }
public override int check(String host, byte[] key)
{
//String foo;
//byte[] bar;
HostKey hk;
int result=NOT_INCLUDED;
int type=getType(key);
for(int i=0; i<pool.Count; i++)
{
hk=(HostKey)(pool[i]);
if(isIncluded(hk.host, host) && hk.type==type)
{
if(Util.array_equals(hk.key, key))
{
//System.out.println("find!!");
return OK;
}
else
{
result=CHANGED;
}
}
}
//System.out.println("fail!!");
return result;
}
public override void add(String host, byte[] key, UserInfo userinfo)
{
HostKey hk;
int type=getType(key);
for(int i=0; i<pool.Count; i++)
{
hk=(HostKey)(pool[i]);
if(isIncluded(hk.host, host) && hk.type==type)
{
/*
if(Util.array_equals(hk.key, key)){ return; }
if(hk.host.equals(host)){
hk.key=key;
return;
}
else{
hk.host=deleteSubString(hk.host, host);
break;
}
*/
}
}
hk=new HostKey(host, type, key);
pool.Add(hk);
String bar=getKnownHostsRepositoryID();
if(userinfo!=null &&
bar!=null)
{
bool foo=true;
FileInfo goo=new FileInfo(bar);
if(!goo.Exists)
{
foo=false;
if(userinfo!=null)
{
foo=userinfo.promptYesNo(
bar+" does not exist.\n"+
"Are you sure you want to create it?"
);
DirectoryInfo dir =goo.Directory;
if(foo && dir!=null && !dir.Exists)
{
foo=userinfo.promptYesNo(
"The parent directory "+dir.Name+" does not exist.\n"+
"Are you sure you want to create it?"
);
if(foo)
{
try{dir.Create(); userinfo.showMessage(dir.Name+" has been succesfully created.\nPlease check its access permission.");}
catch
{
userinfo.showMessage(dir.Name+" has not been created.");
foo=false;
}
}
}
if(goo==null)foo=false;
}
}
if(foo)
{
try
{
sync(bar);
}
catch(Exception e){ Console.WriteLine("sync known_hosts: "+e); }
}
}
}
public override HostKey[] getHostKey()
{
return getHostKey(null, null);
}
public override HostKey[] getHostKey(String host, String type)
{
lock(pool)
{
int count=0;
for(int i=0; i<pool.Count; i++)
{
HostKey hk=(HostKey)pool[i];
if(hk.type==HostKey.UNKNOWN) continue;
if(host==null ||
(isIncluded(hk.host, host) &&
(type==null || hk.getType().Equals(type))))
{
count++;
}
}
if(count==0)return null;
HostKey[] foo=new HostKey[count];
int j=0;
for(int i=0; i<pool.Count; i++)
{
HostKey hk=(HostKey)pool[i];
if(hk.type==HostKey.UNKNOWN) continue;
if(host==null ||
(isIncluded(hk.host, host) &&
(type==null || hk.getType().Equals(type))))
{
foo[j++]=hk;
}
}
return foo;
}
}
public override void remove(String host, String type)
{
remove(host, type, null);
}
public override void remove(String host, String type, byte[] key)
{
bool _sync=false;
for(int i=0; i<pool.Count; i++)
{
HostKey hk=(HostKey)(pool[i]);
if(host==null ||
(hk.getHost().Equals(host) &&
(type==null || (hk.getType().Equals(type) &&
(key==null || Util.array_equals(key, hk.key))))))
{
pool.Remove(hk);
_sync=true;
}
}
if(_sync)
{
try{sync();}
catch{};
}
}
private void sync()
{
if(known_hosts!=null)
sync(known_hosts);
}
private void sync(String foo)
{
if(foo==null) return;
FileStream fos=File.OpenWrite(foo);
dump(fos);
fos.Close();
}
private static byte[] space= new byte[]{(byte)0x20};
private static byte[] cr= System.Text.Encoding.Default.GetBytes("\n");
void dump(FileStream outs)
{
//StreamWriter outs = new StreamWriter(fs);
try
{
HostKey hk;
for(int i=0; i<pool.Count; i++)
{
hk=(HostKey)(pool[i]);
//hk.dump(out);
String host=hk.getHost();
String type=hk.getType();
if(type.Equals("UNKNOWN"))
{
Write(outs, Util.getBytes(host));
Write(outs, cr);
continue;
}
Write(outs, Util.getBytes(host));
Write(outs, space);
Write(outs, Util.getBytes(type));
Write(outs, space);
Write(outs, Util.getBytes(hk.getKey()));
Write(outs, cr);
}
outs.Flush();
}
catch(Exception e)
{
Console.WriteLine(e);
}
}
private void Write(Stream s, byte[] buff)
{
s.Write(buff, 0, buff.Length);
}
private int getType(byte[] key)
{
if(key[8]=='d') return HostKey.SSHDSS;
if(key[8]=='r') return HostKey.SSHRSA;
return HostKey.UNKNOWN;
}
private String deleteSubString(String hosts, String host)
{
int i=0;
int hostlen=host.Length;
int hostslen=hosts.Length;
int j;
while(i<hostslen)
{
j=hosts.IndexOf(',', i);
if(j==-1) break;
if(!host.Equals(hosts.Substring(i, j)))
{
i=j+1;
continue;
}
return hosts.Substring(0, i)+hosts.Substring(j+1);
}
if(hosts.EndsWith(host) && hostslen-i==hostlen)
{
return hosts.Substring(0, (hostlen==hostslen) ? 0 :hostslen-hostlen-1);
}
return hosts;
}
private bool isIncluded(String hosts, String host)
{
int i=0;
int hostlen=host.Length;
int hostslen=hosts.Length;
int j;
while(i<hostslen)
{
j=hosts.IndexOf(',', i);
if(j==-1)
{
if(hostlen!=hostslen-i) return false;
return Util.regionMatches( hosts, true, i, host, 0, hostlen);
//return hosts.substring(i).equals(host);
}
if(hostlen==(j-i))
{
if(Util.regionMatches( hosts,true, i, host, 0, hostlen)) return true;
//if(hosts.substring(i, i+hostlen).equals(host)) return true;
}
i=j+1;
}
return false;
}
/*
private static boolean equals(byte[] foo, byte[] bar){
if(foo.length!=bar.length)return false;
for(int i=0; i<foo.length; i++){
if(foo[i]!=bar[i])return false;
}
return true;
}
*/
/*
private static final byte[] space={(byte)0x20};
private static final byte[] sshdss="ssh-dss".getBytes();
private static final byte[] sshrsa="ssh-rsa".getBytes();
private static final byte[] cr="\n".getBytes();
public class HostKey{
String host;
int type;
byte[] key;
HostKey(String host, int type, byte[] key){
this.host=host; this.type=type; this.key=key;
}
void dump(OutputStream out) throws IOException{
if(type==UNKNOWN){
out.write(host.getBytes());
out.write(cr);
return;
}
out.write(host.getBytes());
out.write(space);
if(type==HostKey.SSHDSS){ out.write(sshdss); }
else if(type==HostKey.SSHRSA){ out.write(sshrsa);}
out.write(space);
out.write(Util.toBase64(key, 0, key.length));
out.write(cr);
}
public String getHost(){ return host; }
public String getType(){
if(type==SSHDSS){ return new String(sshdss); }
if(type==SSHRSA){ return new String(sshrsa);}
return "UNKNOWN";
}
public String getKey(){
return new String(Util.toBase64(key, 0, key.length));
}
public String getFingerPrint(){
HASH hash=null;
try{
Class c=Class.forName(jsch.getConfig("md5"));
hash=(HASH)(c.newInstance());
}
catch(Exception e){ System.err.println("getFingerPrint: "+e); }
return Util.getFingerPrint(hash, key);
}
}
*/
}
}

View file

@ -1,44 +0,0 @@
using System;
namespace Tamir.SharpSsh.jsch
{
/* -*-mode:java; c-basic-offset:2; -*- */
/*
Copyright (c) 2002,2003,2004 ymnk, JCraft,Inc. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the distribution.
3. The names of the authors may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
public interface MAC
{
String getName();
int getBlockSize();
void init(byte[] key);
void update(byte[] foo, int start, int len);
void update(int foo);
byte[] doFinal();
}
}

View file

@ -1,138 +0,0 @@
using System;
namespace Tamir.SharpSsh.jsch
{
/* -*-mode:java; c-basic-offset:2; -*- */
/*
Copyright (c) 2002,2003,2004 ymnk, JCraft,Inc. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the distribution.
3. The names of the authors may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
public class Packet
{
private static Random random=null;
internal static void setRandom(Random foo){ random=foo;}
internal Buffer buffer;
internal byte[] tmp=new byte[4];
public Packet(Buffer buffer)
{
this.buffer=buffer;
}
public void reset()
{
buffer.index=5;
}
// internal void padding()
// {
// uint len=(uint)buffer.index;
// int pad=(int) ((-len)&7);
// if(pad<8)
// {
// pad+=8;
// }
// len=(uint)(len+pad-4);
// tmp[0]=(byte)(len>>24);
// tmp[1]=(byte)(len>>16);
// tmp[2]=(byte)(len>>8);
// tmp[3]=(byte)(len);
// Array.Copy(tmp, 0, buffer.buffer, 0, 4);
// buffer.buffer[4]=(byte)pad;
// lock(random)
// {
// random.fill(buffer.buffer, buffer.index, pad);
// }
// buffer.skip(pad);
// //buffer.putPad(pad);
// /*
// for(int i=0; i<buffer.index; i++){
// System.out.print(Integer.toHexString(buffer.buffer[i]&0xff)+":");
// }
// System.out.println("");
// */
// }
internal void padding(int bsize)
{
uint len=(uint)buffer.index;
int pad=(int)( (-len)&(bsize-1) );
if(pad<bsize)
{
pad+=bsize;
}
len=(uint)(len+pad-4);
tmp[0]=(byte)(len>>24);
tmp[1]=(byte)(len>>16);
tmp[2]=(byte)(len>>8);
tmp[3]=(byte)(len);
Array.Copy(tmp, 0, buffer.buffer, 0, 4);
buffer.buffer[4]=(byte)pad;
lock(random)
{
random.fill(buffer.buffer, buffer.index, pad);
}
buffer.skip(pad);
//buffer.putPad(pad);
/*
for(int i=0; i<buffer.index; i++){
System.out.print(Integer.toHexString(buffer.buffer[i]&0xff)+":");
}
System.out.println("");
*/
}
internal int shift(int len, int mac)
{
int s=len+5+9;
int pad=(-s)&7;
if(pad<8)pad+=8;
s+=pad;
s+=mac;
Array.Copy(buffer.buffer,
len+5+9,
buffer.buffer, s, buffer.index-5-9-len);
buffer.index=10;
buffer.putInt(len);
buffer.index=len+5+9;
return s;
}
internal void unshift(byte command, int recipient, int s, int len)
{
Array.Copy(buffer.buffer,
s,
buffer.buffer, 5+9, len);
buffer.buffer[5]=command;
buffer.index=6;
buffer.putInt(recipient);
buffer.putInt(len);
buffer.index=len+5+9;
}
}
}

View file

@ -1,214 +0,0 @@
using System;
using System.IO;
using System.Threading;
using Tamir.SharpSsh.java.net;
using Tamir.SharpSsh.java.lang;
using InetAddress = Tamir.SharpSsh.java.net.InetAddress;
using String = Tamir.SharpSsh.java.String;
namespace Tamir.SharpSsh.jsch
{
/* -*-mode:java; c-basic-offset:2; -*- */
/*
Copyright (c) 2002,2003,2004 ymnk, JCraft,Inc. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the distribution.
3. The names of the authors may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
class PortWatcher : Tamir.SharpSsh.java.lang.Runnable
{
private static Tamir.SharpSsh.java.util.Vector pool=new Tamir.SharpSsh.java.util.Vector();
internal Session session;
internal int lport;
internal int rport;
internal String host;
internal InetAddress boundaddress;
internal Runnable thread;
internal ServerSocket ss;
internal static String[] getPortForwarding(Session session)
{
java.util.Vector foo=new java.util.Vector();
lock(pool)
{
for(int i=0; i<pool.size(); i++)
{
PortWatcher p=(PortWatcher)(pool.elementAt(i));
if(p.session==session)
{
foo.addElement(p.lport+":"+p.host+":"+p.rport);
}
}
}
String[] bar=new String[foo.size()];
for(int i=0; i<foo.size(); i++)
{
bar[i]=(String)(foo.elementAt(i));
}
return bar;
}
internal static PortWatcher getPort(Session session, String address, int lport)
{
InetAddress addr;
try
{
addr=InetAddress.getByName(address);
}
catch(Exception uhe)
{
throw new JSchException("PortForwardingL: invalid address "+address+" specified.");
}
lock(pool)
{
for(int i=0; i<pool.size(); i++)
{
PortWatcher p=(PortWatcher)(pool.elementAt(i));
if(p.session==session && p.lport==lport)
{
if(p.boundaddress.isAnyLocalAddress() ||
p.boundaddress.equals(addr))
return p;
}
}
return null;
}
}
internal static PortWatcher addPort(Session session, String address, int lport, String host, int rport, ServerSocketFactory ssf)
{
if(getPort(session, address, lport)!=null)
{
throw new JSchException("PortForwardingL: local port "+ address+":"+lport+" is already registered.");
}
PortWatcher pw=new PortWatcher(session, address, lport, host, rport, ssf);
pool.addElement(pw);
return pw;
}
internal static void delPort(Session session, String address, int lport)
{
PortWatcher pw=getPort(session, address, lport);
if(pw==null)
{
throw new JSchException("PortForwardingL: local port "+address+":"+lport+" is not registered.");
}
pw.delete();
pool.removeElement(pw);
}
internal static void delPort(Session session)
{
lock(pool)
{
PortWatcher[] foo=new PortWatcher[pool.size()];
int count=0;
for(int i=0; i<pool.size(); i++)
{
PortWatcher p=(PortWatcher)(pool.elementAt(i));
if(p.session==session)
{
p.delete();
foo[count++]=p;
}
}
for(int i=0; i<count; i++)
{
PortWatcher p=foo[i];
pool.removeElement(p);
}
}
}
internal PortWatcher(Session session,
String address, int lport,
String host, int rport,
ServerSocketFactory factory)
{
this.session=session;
this.lport=lport;
this.host=host;
this.rport=rport;
try
{
boundaddress=InetAddress.getByName(address);
ss=(factory==null) ?
new ServerSocket(lport, 0, boundaddress) :
factory.createServerSocket(lport, 0, boundaddress);
}
catch(Exception e)
{
Console.WriteLine(e);
throw new JSchException("PortForwardingL: local port "+address+":"+lport+" cannot be bound.");
}
}
public void run()
{
Buffer buf=new Buffer(300); // ??
Packet packet=new Packet(buf);
thread=this;
try
{
while(thread!=null)
{
Socket socket=ss.accept();
socket.setTcpNoDelay(true);
Stream In=socket.getInputStream();
Stream Out=socket.getOutputStream();
ChannelDirectTCPIP channel=new ChannelDirectTCPIP();
channel.init();
channel.setInputStream(In);
channel.setOutputStream(Out);
session.addChannel(channel);
((ChannelDirectTCPIP)channel).setHost(host);
((ChannelDirectTCPIP)channel).setPort(rport);
((ChannelDirectTCPIP)channel).setOrgIPAddress(socket.getInetAddress().getHostAddress());
((ChannelDirectTCPIP)channel).setOrgPort(socket.getPort());
channel.connect();
if(channel.exitstatus!=-1)
{
}
}
}
catch(Exception e)
{
//System.out.println("! "+e);
}
delete();
}
internal void delete()
{
thread=null;
try
{
if(ss!=null)ss.close();
ss=null;
}
catch(Exception e)
{
}
}
}
}

View file

@ -1,43 +0,0 @@
using Tamir.SharpSsh.java;
using System.IO;
using Tamir.SharpSsh.java.net;
namespace Tamir.SharpSsh.jsch
{
/* -*-mode:java; c-basic-offset:2; -*- */
/*
Copyright (c) 2002,2003,2004 ymnk, JCraft,Inc. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the distribution.
3. The names of the authors may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
public interface Proxy
{
void connect(SocketFactory socket_factory, String host, int port, int timeout);
Stream getInputStream();
Stream getOutputStream();
Socket getSocket();
void close();
}
}

View file

@ -1,183 +0,0 @@
using Tamir.SharpSsh.java;
using Tamir.SharpSsh.java.io;
using Tamir.SharpSsh.java.util;
using Tamir.SharpSsh.java.net;
using Tamir.SharpSsh.java.lang;
using Tamir.SharpSsh.jsch;
using System.IO;
namespace Tamir.SharpSsh.jsch
{
public class ProxyHTTP : Proxy
{
private static int DEFAULTPORT=80;
private String proxy_host;
private int proxy_port;
private JStream ins;
private JStream outs;
private Socket socket;
private String user;
private String passwd;
public ProxyHTTP(String proxy_host)
{
int port=DEFAULTPORT;
String host=proxy_host;
if(proxy_host.indexOf(':')!=-1)
{
try
{
host=proxy_host.substring(0, proxy_host.indexOf(':'));
port=Integer.parseInt(proxy_host.substring(proxy_host.indexOf(':')+1));
}
catch(Exception e)
{
}
}
this.proxy_host=host;
this.proxy_port=port;
}
public ProxyHTTP(String proxy_host, int proxy_port)
{
this.proxy_host=proxy_host;
this.proxy_port=proxy_port;
}
public void setUserPasswd(String user, String passwd)
{
this.user=user;
this.passwd=passwd;
}
public void connect(SocketFactory socket_factory, String host, int port, int timeout)
{
try
{
if(socket_factory==null)
{
socket=Util.createSocket(proxy_host, proxy_port, timeout);
ins= new JStream(socket.getInputStream());
outs=new JStream(socket.getOutputStream());
}
else
{
socket=socket_factory.createSocket(proxy_host, proxy_port);
ins=new JStream(socket_factory.getInputStream(socket));
outs=new JStream(socket_factory.getOutputStream(socket));
}
if(timeout>0)
{
socket.setSoTimeout(timeout);
}
socket.setTcpNoDelay(true);
outs.write(new String("CONNECT "+host+":"+port+" HTTP/1.0\r\n").getBytes());
if(user!=null && passwd!=null)
{
byte[] _code=(user+":"+passwd).getBytes();
_code=Util.toBase64(_code, 0, _code.Length);
outs.write(new String("Proxy-Authorization: Basic ").getBytes());
outs.write(_code);
outs.write(new String("\r\n").getBytes());
}
outs.write(new String("\r\n").getBytes());
outs.flush();
int foo=0;
StringBuffer sb=new StringBuffer();
while(foo>=0)
{
foo=ins.read(); if(foo!=13){sb.append((char)foo); continue;}
foo=ins.read(); if(foo!=10){continue;}
break;
}
if(foo<0)
{
throw new System.IO.IOException();
}
String response=sb.toString();
String reason="Unknow reason";
int code=-1;
try
{
foo=response.indexOf(' ');
int bar=response.indexOf(' ', foo+1);
code=Integer.parseInt(response.substring(foo+1, bar));
reason=response.substring(bar+1);
}
catch(Exception e)
{
}
if(code!=200)
{
throw new System.IO.IOException("proxy error: "+reason);
}
/*
while(foo>=0){
foo=in.read(); if(foo!=13) continue;
foo=in.read(); if(foo!=10) continue;
foo=in.read(); if(foo!=13) continue;
foo=in.read(); if(foo!=10) continue;
break;
}
*/
int count=0;
while(true)
{
count=0;
while(foo>=0)
{
foo=ins.read(); if(foo!=13){count++; continue;}
foo=ins.read(); if(foo!=10){continue;}
break;
}
if(foo<0)
{
throw new System.IO.IOException();
}
if(count==0)break;
}
}
catch(RuntimeException e)
{
throw e;
}
catch(Exception e)
{
try{ if(socket!=null)socket.close(); }
catch(Exception eee)
{
}
String message="ProxyHTTP: "+e.toString();
throw e;
}
}
public Stream getInputStream(){ return ins.s; }
public Stream getOutputStream(){ return outs.s; }
public Socket getSocket(){ return socket; }
public void close()
{
try
{
if(ins!=null)ins.close();
if(outs!=null)outs.close();
if(socket!=null)socket.close();
}
catch(Exception e)
{
}
ins=null;
outs=null;
socket=null;
}
public static int getDefaultPort()
{
return DEFAULTPORT;
}
}
}

View file

@ -1,38 +0,0 @@
using System;
namespace Tamir.SharpSsh.jsch
{
/* -*-mode:java; c-basic-offset:2; -*- */
/*
Copyright (c) 2002,2003,2004 ymnk, JCraft,Inc. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the distribution.
3. The names of the authors may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
public interface Random
{
void fill(byte[] foo, int start, int len);
}
}

View file

@ -1,39 +0,0 @@
using System;
namespace Tamir.SharpSsh.jsch
{
/* -*-mode:java; c-basic-offset:2; -*- */
/*
Copyright (c) 2002,2003,2004 ymnk, JCraft,Inc. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the distribution.
3. The names of the authors may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
internal interface Request
{
bool waitForReply();
void request(Session session, Channel channel);
}
}

View file

@ -1,62 +0,0 @@
using System;
using Str = Tamir.SharpSsh.java.String;
namespace Tamir.SharpSsh.jsch
{
/* -*-mode:java; c-basic-offset:2; -*- */
/*
Copyright (c) 2002,2003,2004 ymnk, JCraft,Inc. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the distribution.
3. The names of the authors may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
internal class RequestExec : Request
{
private String command="";
internal RequestExec(String foo)
{
this.command=foo;
}
public void request(Session session, Channel channel)
{
Packet packet=session.packet;
Buffer buf=session.buf;
// send
// byte SSH_MSG_CHANNEL_REQUEST(98)
// uint32 recipient channel
// string request type // "exec"
// boolean want reply // 0
// string command
packet.reset();
buf.putByte((byte) Session.SSH_MSG_CHANNEL_REQUEST);
buf.putInt(channel.getRecipient());
buf.putString(new Str("exec").getBytes());
buf.putByte((byte)(waitForReply() ? 1 : 0));
buf.putString(new Str(command).getBytes());
session.write(packet);
}
public bool waitForReply(){ return false; }
}
}

View file

@ -1,60 +0,0 @@
using System;
namespace Tamir.SharpSsh.jsch
{
/* -*-mode:java; c-basic-offset:2; -*- */
/*
Copyright (c) 2002,2003,2004 ymnk, JCraft,Inc. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the distribution.
3. The names of the authors may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
class RequestPtyReq : Request
{
void setCode(String cookie)
{
}
public void request(Session session, Channel channel)
{
Buffer buf=new Buffer();
Packet packet=new Packet(buf);
packet.reset();
buf.putByte((byte) Session.SSH_MSG_CHANNEL_REQUEST);
buf.putInt(channel.getRecipient());
buf.putString(Util.getBytes("pty-req"));
buf.putByte((byte)(waitForReply() ? 1 : 0));
buf.putString(Util.getBytes("vt100"));
buf.putInt(80);
buf.putInt(24);
buf.putInt(640);
buf.putInt(480);
buf.putString(Util.getBytes(""));
session.write(packet);
}
public bool waitForReply(){ return false; }
}
}

View file

@ -1,73 +0,0 @@
using System;
namespace Tamir.SharpSsh.jsch
{
/* -*-mode:java; c-basic-offset:2; -*- */
/*
Copyright (c) 2002,2003,2004 ymnk, JCraft,Inc. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the distribution.
3. The names of the authors may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
public class RequestSftp : Request
{
public void request(Session session, Channel channel)
{
Buffer buf=new Buffer();
Packet packet=new Packet(buf);
bool reply=waitForReply();
if(reply)
{
channel.reply=-1;
}
packet.reset();
buf.putByte((byte)Session.SSH_MSG_CHANNEL_REQUEST);
buf.putInt(channel.getRecipient());
buf.putString(Util.getBytes("subsystem"));
buf.putByte((byte)(waitForReply() ? 1 : 0));
buf.putString(Util.getBytes("sftp"));
session.write(packet);
if(reply)
{
while(channel.reply==-1)
{
try{System.Threading.Thread.Sleep(10);}
catch//(Exception ee)
{
}
}
if(channel.reply==0)
{
throw new JSchException("failed to send sftp request");
}
}
}
public bool waitForReply(){ return true; }
}
}

View file

@ -1,56 +0,0 @@
using System;
namespace Tamir.SharpSsh.jsch
{
/* -*-mode:java; c-basic-offset:2; -*- */
/*
Copyright (c) 2002,2003,2004 ymnk, JCraft,Inc. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the distribution.
3. The names of the authors may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
class RequestShell : Request
{
public void request(Session session, Channel channel)
{
Buffer buf=new Buffer();
Packet packet=new Packet(buf);
// send
// byte SSH_MSG_CHANNEL_REQUEST(98)
// uint32 recipient channel
// string request type // "shell"
// boolean want reply // 0
packet.reset();
buf.putByte((byte) Session.SSH_MSG_CHANNEL_REQUEST);
buf.putInt(channel.getRecipient());
buf.putString(Util.getBytes("shell"));
buf.putByte((byte)(waitForReply() ? 1 : 0));
session.write(packet);
}
public bool waitForReply(){ return false; }
}
}

View file

@ -1,54 +0,0 @@
using System;
namespace Tamir.SharpSsh.jsch
{
/* -*-mode:java; c-basic-offset:2; -*- */
/*
Copyright (c) 2002,2003,2004 ymnk, JCraft,Inc. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the distribution.
3. The names of the authors may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
class RequestSignal : Request
{
String signal="KILL";
public void setSignal(String foo){ signal=foo; }
public void request(Session session, Channel channel)
{
Buffer buf=new Buffer();
Packet packet=new Packet(buf);
packet.reset();
buf.putByte((byte) Session.SSH_MSG_CHANNEL_REQUEST);
buf.putInt(channel.getRecipient());
buf.putString( Util.getBytes("signal"));
buf.putByte((byte)(waitForReply() ? 1 : 0));
buf.putString(Util.getBytes(signal));
session.write(packet);
}
public bool waitForReply(){ return false; }
}
}

View file

@ -1,83 +0,0 @@
using Tamir.SharpSsh.java;
using Tamir.SharpSsh.java.lang;
namespace Tamir.SharpSsh.jsch
{
/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
/*
Copyright (c) 2005 ymnk, JCraft,Inc. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the distribution.
3. The names of the authors may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
public class RequestSubsystem : Request
{
private bool want_reply=true;
private String subsystem=null;
public void request(Session session, Channel channel, String subsystem, bool want_reply)
{
this.subsystem=subsystem;
this.want_reply=want_reply;
this.request(session, channel);
}
public void request(Session session, Channel channel)
{
Buffer buf=new Buffer();
Packet packet=new Packet(buf);
bool reply=waitForReply();
if(reply)
{
channel.reply=-1;
}
packet.reset();
buf.putByte((byte)Session.SSH_MSG_CHANNEL_REQUEST);
buf.putInt(channel.getRecipient());
buf.putString( new String( "subsystem" ).getBytes());
buf.putByte((byte)(waitForReply() ? 1 : 0));
buf.putString(subsystem.getBytes());
session.write(packet);
if(reply)
{
while(channel.reply==-1)
{
try{Thread.sleep(10);}
catch//(System.Exception ee)
{
}
}
if(channel.reply==0)
{
throw new JSchException("failed to send subsystem request");
}
}
}
public bool waitForReply(){ return want_reply; }
}
}

View file

@ -1,74 +0,0 @@
using System;
namespace Tamir.SharpSsh.jsch
{
/* -*-mode:java; c-basic-offset:2; -*- */
/*
Copyright (c) 2002,2003,2004 ymnk, JCraft,Inc. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the distribution.
3. The names of the authors may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
public class RequestWindowChange : Request
{
internal int width_columns=80;
internal int height_rows=24;
internal int width_pixels=640;
internal int height_pixels=480;
public void setSize(int row, int col, int wp, int hp)
{
this.width_columns=row;
this.height_rows=col;
this.width_pixels=wp;
this.height_pixels=hp;
}
public void request(Session session, Channel channel)
{
Buffer buf=new Buffer();
Packet packet=new Packet(buf);
//byte SSH_MSG_CHANNEL_REQUEST
//uint32 recipient_channel
//string "window-change"
//boolean FALSE
//uint32 terminal width, columns
//uint32 terminal height, rows
//uint32 terminal width, pixels
//uint32 terminal height, pixels
packet.reset();
buf.putByte((byte) Session.SSH_MSG_CHANNEL_REQUEST);
buf.putInt(channel.getRecipient());
buf.putString(Util.getBytes("window-change"));
buf.putByte((byte)(waitForReply() ? 1 : 0));
buf.putInt(width_columns);
buf.putInt(height_rows);
buf.putInt(width_pixels);
buf.putInt(height_pixels);
session.write(packet);
}
public bool waitForReply(){ return false; }
}
}

Some files were not shown because too many files have changed in this diff Show more