jsch-0.1.50/ 0000755 0000000 0000000 00000000000 12142542040 011214 5 ustar root root jsch-0.1.50/build.xml 0000644 0000000 0000000 00000006701 12075556672 013066 0 ustar root root
JSch is a pure Java implementation of SSH2. JSch allows you to connect to an
sshd server and use port forwarding, X11 forwarding, file transfer, etc., and
you can integrate its functionality into your own Java programs
jsch-0.1.50/README 0000644 0000000 0000000 00000020467 11126530356 012115 0 ustar root root
JSch
Java Secure Channel
by ymnk@jcraft.com, JCraft,Inc.
http://www.jcraft.com/jsch/
Last modified: Wed Nov 1 14:43:31 UTC 2006
Description
===========
JSch is a pure Java implementation of SSH2. JSch allows you to
connect to an sshd server and use port forwarding, X11 forwarding,
file transfer, etc., and you can integrate its functionality
into your own Java programs. JSch is licensed under BSD style license.
Documentation
=============
* README files all over the source tree have info related to the stuff
in the directories.
* ChangeLog: what changed from the previous version?
Directories & Files in the Source Tree
======================================
* src/com/ has source trees of JSch
* example/ has some samples, which demonstrate the usages.
* tools/ has scripts for Ant.
Why JSch?
==========
Our intension in developing this stuff is to enable users of our pure
java X servers, WiredX(http://wiredx.net/) and WeirdX, to enjoy secure X
sessions. Our efforts have mostly targeted the SSH2 protocol in relation
to X Window System and X11 forwarding. Of course, we are also interested in
adding other functionality - port forward, file transfer, terminal emulation, etc.
Features
========
* JSch is in pure Java, but it depends on JavaTM Cryptography
Extension (JCE). JSch is know to work with:
o J2SE 1.4.0 or later (no additional libraries required).
o J2SE 1.3 and Sun's JCE reference implementation that can be
obtained at http://java.sun.com/products/jce/
o J2SE 1.2.2 and later and Bouncycastle's JCE implementation that
can be obtained at http://www.bouncycastle.org/
* SSH2 protocol support.
* Key exchange: diffie-hellman-group-exchange-sha1, diffie-hellman-group1-sha1
* Cipher: blowfish-cbc,3des-cbc,aes128-cbc,aes192-cbc,aes256-cbc
3des-ctr,aes128-ctr,aes192-ctr,aes256-ctc,
arcfour,arcfour128,arcfour256
* MAC: hmac-md5,hmac-md5-96,hmac-sha1,hmac-sha1-96
* Host key type: ssh-dss, ssh-rsa
* Userauth: password
* Userauth: publickey(DSA,RSA)
* Userauth: keyboard-interactive
* Userauth: gssapi-with-mic
* X11 forwarding.
* xauth spoofing.
* connection through HTTP proxy.
* connection through SOCKS5, SOCKS4 proxy.
* port forwarding.
* stream forwarding.
* signal sending.
The unofficial patch for sshd of openssh will be find in the thread
http://marc.theaimsgroup.com/?l=openssh-unix-dev&m=104295745607575&w=2
* envrironment variable passing.
* remote exec.
* generating DSA and RSA key pairs.
* SSH File Transfer Protocol(version 0, 1, 2, 3)
* partial authentication
* packet compression: zlib, zlib@openssh.com
JZlib(http://www.jcraft.com/jzlib/) has been used.
* hashed known_hosts file.
* NONE Cipher switching.
http://www.psc.edu/networking/projects/hpn-ssh/none.php
* JSch is licensed under BSD style license(refer to LICENSE.txt).
How To Try
==========
This archive does not include java byte code, so please compile
the source code by your self.
$ cd jsch-?.?.?/src
$ javac com/jcraft/jsch/*java com/jcraft/jsch/jce/*java com/jcraft/jzlib/*.java
'/examples/' directory has included some samples to demonstrate what
JSch can do. Please refer to '/examples/README' file.
AES cipher
==========
JSch supports aes128-cbc,aes192-cbc,aes256-cbc,aes128-ctr,aes192-ctr,
aes256-ctr but you require AES support in your J2SE to choose some of them.
If you are using Sun's J2SE, J2SE 1.4.2 or later is required.
And then, J2SE 1.4.2(or later) does not support aes256 by the default,
because of 'import control restrictions of some countries'.
We have confirmed that by applying
"Java Cryptography Extension (JCE)
Unlimited Strength Jurisdiction Policy Files 1.4.2"
on
http://java.sun.com/j2se/1.4.2/download.html#docs
we can enjoy 'aes256-cbc,aes256-ctr'.
Stream Forwarding
=================
JSch has a unique functionality, Stream Forwarding.
Stream Forwarding allows you to plug Java I/O streams directly into a remote TCP
port without assigning and opening a local TCP port.
In port forwarding, as with the -L option of ssh command, you have to assign
and open a local TCP port and that port is also accessible by crackers
on localhost. In some case, that local TCP port may be plugged to a
secret port via SSH session.
A sample program, /example/StreamForwarding.java , demonstrates
this functionality.
Generating Authentication Keys
==============================
JSch allows you to generate DSA and RSA key pairs, which are in OpenSSH format.
Please refer to 'examples/KeyGen.java'.
Packet Compression
==================
According to the draft from IETF sesch working group, the packet
compression can be applied to each data stream directions; from sshd
server to ssh client and from ssh client to sshd server. So, jsch
allows you to choose which data stream direction will be compressed or not.
For example, in X11 forwarding session, the packet compression for data
stream from sshd to ssh client will save the network traffic, but
usually the traffic from ssh client to sshd is light, so by omitting
the compression for this direction, you may be able to save some CPU time.
Please refer to a sample program 'examples/Compression.java'.
Property
========
By setting properties, you can control the behavior of jsch.
Here is an example of enabling the packet compression,
Session session=jsch.getSession(user, host, 22);
java.util.Properties config=new java.util.Properties();
config.put("compression.s2c", "zlib,none");
config.put("compression.c2s", "zlib,none");
session.setConfig(config);
session.connect();
Current release has supported following properties,
* compression.s2c: zlib, none
default: none
Specifies whether to use compression for the data stream
from sshd to jsch. If "zlib,none" is given and the remote sshd does
not allow the packet compression, compression will not be done.
* compression.c2s: zlib, none
default: none
Specifies whether to use compression for the data stream
from jsch to sshd.
* StrictHostKeyChecking: ask | yes | no
default: ask
If this property is set to ``yes'', jsch will never automatically add
host keys to the $HOME/.ssh/known_hosts file, and refuses to connect
to hosts whose host key has changed. This property forces the user
to manually add all new hosts. If this property is set to ``no'',
jsch will automatically add new host keys to the user known hosts
files. If this property is set to ``ask'', new host keys will be
added to the user known host files only after the user has confirmed
that is what they really want to do, and jsch will refuse to connect
to hosts whose host key has changed.
TODO
====
* re-implementation with java.nio.
* replacing cipher, hash by JCE with pure Java code.
* SSH File Transfer Protocol version 4.
* error handling.
Copyrights & Disclaimers
========================
JSch is copyrighted by ymnk, JCraft,Inc. and is licensed through BSD style license.
Read the LICENSE.txt file for the complete license.
Credits and Acknowledgments
============================
JSch has been developed by ymnk@jcraft.com and it can not be hacked
without several help.
* First of all, we want to thank JCE team at Sun Microsystems.
For long time, we had planed to implement SSH2 in pure Java,
but we had hesitated to do because tons of work must be done for
implementing ciphers, hashes, etc., from the scratch.
Thanks to newly added functionalities to J2SE 1.4.0, we could
start this project.
* We appreciate the OpenSSH project.
The options '-ddd' of sshd, '---vvv' of ssh and the compile options
'-DPACKET_DEBUG', '-DDEBUG_KEXDH' and '-DDEBUG_KEX' were very
useful in debugging JSch.
* We appreciate IETF sesch working group and SSH Communications Security Corp.
Without the standardization of the protocol, we could not get the
chance to implement JSch.
* We appreciate Seigo Haruyama(http://www.unixuser.org/~haruyama/),
who are interpreting drafts of SSH2 protocol in Japanese.
His works were very useful for us to understand the technical terms
in our native language.
* We also appreciate SourceForge.net's awesome service to the
Open Source Community.
If you have any comments, suggestions and questions, write us
at jsch@jcraft.com
``SSH is a registered trademark and Secure Shell is a trademark of
SSH Communications Security Corp (www.ssh.com)''.
jsch-0.1.50/examples/ 0000755 0000000 0000000 00000000000 12142516550 013041 5 ustar root root jsch-0.1.50/examples/README 0000644 0000000 0000000 00000016334 11743601376 013737 0 ustar root root
README of example directory
====================================================================
Last modified: Wed Oct 16 13:53:12 UTC 2002
This directory contains some examples, which demonstrate how to use JSch
- Shell.java
This program enables you to connect to sshd server and get the shell prompt.
$ CLASSPATH=.:../build javac Shell.java
$ CLASSPATH=.:../build java Shell
You will be asked username, hostname and passwd.
If everything works fine, you will get the shell prompt. Output will
be ugly because of lacks of terminal-emulation, but you can issue commands.
- X11Forwarding.java
This program will demonstrate X11 forwarding.
$ CLASSPATH=.:../build javac X11Forwarding.java
$ CLASSPATH=.:../build java X11Forwarding
You will be asked username, hostname, displayname and passwd.
If your X server does not run at 127.0.0.1, please enter correct
displayname. If everything works fine, you will get the shell prompt.
Try X applications; for example, xlogo.
- Exec.java
This program will demonstrate remote exec.
$ CLASSPATH=.:../build javac Exec.java
$ CLASSPATH=.:../build java Exec
You will be asked username, hostname, displayname, passwd and command.
If everything works fine, given command will be invoked
on the remote side and outputs will be printed out.
- ViaHTTP.java
This program will demonstrate the ssh session via HTTP proxy.
$ CLASSPATH=.:../build javac ViaHTTP.java
$ CLASSPATH=.:../build java ViaHTTP
You will be asked username, hostname, proxy-server and passwd.
If everything works fine, you will get the shell prompt.
- ViaSOCKS.java
This program will demonstrate the ssh session via SOCKS proxy.
$ CLASSPATH=.:../build javac ViaSOCKS.java
$ CLASSPATH=.:../build java ViaSOCKS
You will be asked username, hostname, proxy-server and passwd.
If everything works fine, you will get the shell prompt.
- PortForwardingR.java
This program will demonstrate the port forwarding like option -R of
ssh command; the given port on the remote host will be forwarded to
the given host and port on the local side.
$ CLASSPATH=.:../build javac PortForwardingR.java
$ CLASSPATH=.:../build java PortForwardingR
You will be asked username, hostname, port:host:hostport and passwd.
If everything works fine, you will get the shell prompt.
Try the port on remote host.
- PortForwardingL.java
This program will demonstrate the port forwarding like option -L of
ssh command; the given port on the local host will be forwarded to
the given remote host and port on the remote side.
$ CLASSPATH=.:../build javac PortForwardingL.java
$ CLASSPATH=.:../build java PortForwardingL
You will be asked username, hostname, port:host:hostport and passwd.
If everything works fine, you will get the shell prompt.
Try the port on localhost.
- StreamForwarding.java
This program will demonstrate the stream forwarding. The given Java
I/O streams will be forwared to the given remote host and port on
the remote side. It is simmilar to the -L option of ssh command,
but you don't have to assign and open a local tcp port.
$ CLASSPATH=.:../build javac StreamForwarding.java
$ CLASSPATH=.:../build java StreamForwarding
You will be asked username, hostname, host:hostport and passwd.
If everything works fine, System.in and System.out streams will be
forwared to remote port and you can send messages from command line.
- UserAuthPubKey.java
This program will demonstrate the user authentification by public key.
$ CLASSPATH=.:../build javac UserAuthPubKey.java
$ CLASSPATH=.:../build java UserAuthPubKey
You will be asked username, hostname, privatekey(id_dsa) and passphrase.
If everything works fine, you will get the shell prompt
- Compression.java
This program will demonstrate the packet compression.
$ CLASSPATH=.:../build javac Compression.java
$ CLASSPATH=.:../build java Compression
You will be asked username, hostname and passwd.
If everything works fine, you will get the shell prompt.
In this program, all data from sshd server to jsch will be
compressed.
- ScpTo.java
This program will demonstrate the file transfer from local to remote.
$ CLASSPATH=.:../build javac ScpTo.java
$ CLASSPATH=.:../build java ScpTo file1 user@remotehost:file2
You will be asked passwd.
If everything works fine, a local file 'file1' will copied to
'file2' on 'remotehost'.
- ScpFrom.java
This program will demonstrate the file transfer from remote to local
$ CLASSPATH=.:../build javac ScpFrom.java
$ CLASSPATH=.:../build java ScpFrom user@remotehost:file1 file2
You will be asked passwd.
If everything works fine, a file 'file1' on 'remotehost' will copied to
local 'file1'.
- Sftp.java
This program will demonstrate the sftp protocol support.
$ CLASSPATH=.:../build javac Sftp.java
$ CLASSPATH=.:../build java Sftp
You will be asked username, host and passwd.
If everything works fine, you will get a prompt 'sftp>'.
'help' command will show available command.
In current implementation, the destination path for 'get' and 'put'
commands must be a file, not a directory.
- KnownHosts.java
This program will demonstrate the 'known_hosts' file handling.
$ CLASSPATH=.:../build javac KnownHosts.java
$ CLASSPATH=.:../build java KnownHosts
You will be asked username, hostname, a path for 'known_hosts' and passwd.
If everything works fine, you will get the shell prompt.
In current implementation, jsch only reads 'known_hosts' for checking
and does not modify it.
- UserAuthKI.java
This program will demonstrate the keyboard-interactive authentication.
$ CLASSPATH=.:../build javac UserAuthKI.java
$ CLASSPATH=.:../build java UserAuthKI
If the remote sshd supports keyboard-interactive authentication,
you will be prompted.
- KeyGen.java
This progam will demonstrate the DSA keypair generation.
$ CLASSPATH=.:../build javac KeyGen.java
$ CLASSPATH=.:../build java KeyGen rsa output_keyfile comment
or
$ CLASSPATH=.:../build java KeyGen dsa output_keyfile comment
You will be asked a passphrase for output_keyfile.
If everything works fine, you will get the DSA or RSA keypair,
output_keyfile and output_keyfile+".pub".
The private key and public key are in the OpenSSH format.
- ChangePassphrase.java
This program will demonstrate to change the passphrase for a
private key file instead of creating a new private key.
$ CLASSPATH=.:../build javac ChangePassphrase.java
$ CLASSPATH=.:../build java ChangePassphrase private-key
A passphrase will be prompted if the given private-key has been
encrypted. After successfully loading the content of the
private-key, the new passphrase will be prompted and the given
private-key will be re-encrypted with that new passphrase.
- AES.java
This program will demonstrate how to use "aes128-cbc".
- Daemon.java
This program will demonstrate how to provide a network service like
inetd by using remote port-forwarding functionality.
- Logger.java
This program will demonstrate how to enable logging mechanism and
get logging messages.
- Subsystem.java
This program will demonstrate how to use the Subsystem channel.
- Sudo.java
This program will demonstrate how to exec 'sudo' on the remote.
- ScpToNoneCipher.java
This program will demonstrate how to enable none cipher.
jsch-0.1.50/examples/X11Forwarding.java 0000644 0000000 0000000 00000011503 11743364322 016304 0 ustar root root /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
/**
* This program will demonstrate X11 forwarding.
* $ CLASSPATH=.:../build javac X11Forwarding.java
* $ CLASSPATH=.:../build java X11Forwarding
* You will be asked username, hostname, displayname and passwd.
* If your X server does not run at 127.0.0.1, please enter correct
* displayname. If everything works fine, you will get the shell prompt.
* Try X applications; for example, xlogo.
*
*/
import com.jcraft.jsch.*;
import java.awt.*;
import javax.swing.*;
public class X11Forwarding{
public static void main(String[] arg){
String xhost="127.0.0.1";
int xport=0;
try{
JSch jsch=new JSch();
String host=null;
if(arg.length>0){
host=arg[0];
}
else{
host=JOptionPane.showInputDialog("Enter username@hostname",
System.getProperty("user.name")+
"@localhost");
}
String user=host.substring(0, host.indexOf('@'));
host=host.substring(host.indexOf('@')+1);
Session session=jsch.getSession(user, host, 22);
String display=JOptionPane.showInputDialog("Please enter display name",
xhost+":"+xport);
xhost=display.substring(0, display.indexOf(':'));
xport=Integer.parseInt(display.substring(display.indexOf(':')+1));
session.setX11Host(xhost);
session.setX11Port(xport+6000);
// username and password will be given via UserInfo interface.
UserInfo ui=new MyUserInfo();
session.setUserInfo(ui);
session.connect();
Channel channel=session.openChannel("shell");
channel.setXForwarding(true);
channel.setInputStream(System.in);
channel.setOutputStream(System.out);
channel.connect();
}
catch(Exception e){
System.out.println(e);
}
}
public static class MyUserInfo implements UserInfo, UIKeyboardInteractive{
public String getPassword(){ return passwd; }
public boolean promptYesNo(String str){
Object[] options={ "yes", "no" };
int foo=JOptionPane.showOptionDialog(null,
str,
"Warning",
JOptionPane.DEFAULT_OPTION,
JOptionPane.WARNING_MESSAGE,
null, options, options[0]);
return foo==0;
}
String passwd;
JTextField passwordField=(JTextField)new JPasswordField(20);
public String getPassphrase(){ return null; }
public boolean promptPassphrase(String message){ return true; }
public boolean promptPassword(String message){
Object[] ob={passwordField};
int result=
JOptionPane.showConfirmDialog(null, ob, message,
JOptionPane.OK_CANCEL_OPTION);
if(result==JOptionPane.OK_OPTION){
passwd=passwordField.getText();
return true;
}
else{ return false; }
}
public void showMessage(String message){
JOptionPane.showMessageDialog(null, message);
}
final GridBagConstraints gbc =
new GridBagConstraints(0,0,1,1,1,1,
GridBagConstraints.NORTHWEST,
GridBagConstraints.NONE,
new Insets(0,0,0,0),0,0);
private Container panel;
public String[] promptKeyboardInteractive(String destination,
String name,
String instruction,
String[] prompt,
boolean[] echo){
panel = new JPanel();
panel.setLayout(new GridBagLayout());
gbc.weightx = 1.0;
gbc.gridwidth = GridBagConstraints.REMAINDER;
gbc.gridx = 0;
panel.add(new JLabel(instruction), gbc);
gbc.gridy++;
gbc.gridwidth = GridBagConstraints.RELATIVE;
JTextField[] texts=new JTextField[prompt.length];
for(int i=0; i