Skip to content

Commit

Permalink
Import of JSch release archive from SourceForge.net - version jsch-0.…
Browse files Browse the repository at this point in the history
…1.44
  • Loading branch information
Roberto Tyley committed Feb 21, 2011
1 parent 9ce0a51 commit 96b0558
Show file tree
Hide file tree
Showing 9 changed files with 93 additions and 21 deletions.
11 changes: 10 additions & 1 deletion ChangeLog
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
ChangeLog of JSch
====================================================================
Last modified: Fri Jul 16 08:06:27 UTC 2010
Last modified: Tue Nov 2 11:59:57 JST 2010


Changes since version 0.1.43:
- bugfix: hmac-md5-96 and hmac-sha1-96 are broken. FIXED.
- bugfix: working around OOME in parsing broken data from the remote. FIXED.
- bugfix: failed to send very long command for exec channels. FIXED.
- bugfix: in some case, failed to get the response
for remote port-forwarding request. FIXED.
- feature: support for private keys ciphered with aes192-cbc and aes128-cbc.


Changes since version 0.1.42:
Expand Down
7 changes: 5 additions & 2 deletions examples/Daemon.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ public void setChannel(ChannelForwardedTCPIP c, InputStream in, OutputStream out
}
public void setArg(Object[] arg){this.arg=arg;}
public void run(){
System.out.println("remote port: "+channel.getRemotePort());
System.out.println("remote host: "+channel.getSession().getHost());
try{
byte[] buf=new byte[1024];
System.out.println("remote port: "+channel.getRemotePort());
System.out.println("remote host: "+channel.getSession().getHost());
while(true){
int i=in.read(buf, 0, buf.length);
if(i<=0)break;
Expand All @@ -70,6 +70,9 @@ public void run(){
if(buf[0]=='.')break;
}
}
catch(JSchException e){
System.out.println("session is down.");
}
catch(IOException e){
}
}
Expand Down
23 changes: 17 additions & 6 deletions src/com/jcraft/jsch/Buffer.java
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,12 @@ public int getByte(int len) {
return foo;
}
public byte[] getMPInt() {
int i=getInt();
int i=getInt(); // uint32
if(i<0 || // bigger than 0x7fffffff
i>8*1024){
// TODO: an exception should be thrown.
i = 8*1024; // the session will be broken, but working around OOME.
}
byte[] foo=new byte[i];
getByte(foo, 0, i);
return foo;
Expand All @@ -174,13 +179,11 @@ public byte[] getMPIntBits() {
}
public byte[] getString() {
int i = getInt(); // uint32
/*
if(i<0 || // bigger than 0x7fffffff
s+i>index){
//throw new java.io.IOException("invalid string length: "+(((long)i)&0xffffffffL));
i = index-s; // the session will be broken, but working around OOME.
i>256*1024){
// TODO: an exception should be thrown.
i = 256*1024; // the session will be broken, but working around OOME.
}
*/
byte[] foo=new byte[i];
getByte(foo, 0, i);
return foo;
Expand Down Expand Up @@ -209,6 +212,14 @@ byte getCommand(){
return buffer[5];
}

void checkFreeSize(int n){
if(buffer.length<index+n){
byte[] tmp = new byte[buffer.length*2];
System.arraycopy(buffer, 0, tmp, 0, index);
buffer = tmp;
}
}

/*
static String[] chars={
"0","1","2","3","4","5","6","7","8","9", "a","b","c","d","e","f"
Expand Down
16 changes: 13 additions & 3 deletions src/com/jcraft/jsch/ChannelSftp.java
Original file line number Diff line number Diff line change
Expand Up @@ -759,6 +759,8 @@ public void get(String src, String dst,
src=remoteAbsolutePath(src);
dst=localAbsolutePath(dst);

boolean _dstExist = false;
String _dst=null;
try{
Vector v=glob_remote(src);
int vsize=v.size();
Expand Down Expand Up @@ -788,7 +790,7 @@ else if(vsize>1){
"not supported to get directory "+_src);
}

String _dst=null;
_dst=null;
if(isDstDir){
int i=_src.lastIndexOf('/');
if(i==-1) dstsb.append(_src);
Expand All @@ -800,9 +802,10 @@ else if(vsize>1){
_dst=dst;
}

File _dstFile=new File(_dst);
if(mode==RESUME){
long size_of_src=attr.getSize();
long size_of_dst=new File(_dst).length();
long size_of_dst=_dstFile.length();
if(size_of_dst>size_of_src){
throw new SftpException(SSH_FX_FAILURE,
"failed to resume for "+_dst);
Expand All @@ -815,11 +818,12 @@ else if(vsize>1){
if(monitor!=null){
monitor.init(SftpProgressMonitor.GET, _src, _dst, attr.getSize());
if(mode==RESUME){
monitor.count(new File(_dst).length());
monitor.count(_dstFile.length());
}
}

FileOutputStream fos=null;
_dstExist = _dstFile.exists();
try{
if(mode==OVERWRITE){
fos=new FileOutputStream(_dst);
Expand All @@ -838,6 +842,12 @@ else if(vsize>1){
}
}
catch(Exception e){
if(!_dstExist && _dst!=null){
File _dstFile = new File(_dst);
if(_dstFile.exists() && _dstFile.length()==0){
_dstFile.delete();
}
}
if(e instanceof SftpException) throw (SftpException)e;
if(e instanceof Throwable)
throw new SftpException(SSH_FX_FAILURE, "", (Throwable)e);
Expand Down
28 changes: 28 additions & 0 deletions src/com/jcraft/jsch/IdentityFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,34 @@ else if(buf[i]=='S'&& buf[i+1]=='S'&& buf[i+2]=='H'){ // FSecure
}
continue;
}
if(buf[i]=='A'&& i+7<len && buf[i+1]=='E'&& buf[i+2]=='S'&& buf[i+3]=='-' &&
buf[i+4]=='1'&& buf[i+5]=='9'&& buf[i+6]=='2'&& buf[i+7]=='-'){
i+=8;
if(Session.checkCipher((String)jsch.getConfig("aes192-cbc"))){
c=Class.forName((String)jsch.getConfig("aes192-cbc"));
cipher=(Cipher)(c.newInstance());
key=new byte[cipher.getBlockSize()];
iv=new byte[cipher.getIVSize()];
}
else{
throw new JSchException("privatekey: aes192-cbc is not available "+identity);
}
continue;
}
if(buf[i]=='A'&& i+7<len && buf[i+1]=='E'&& buf[i+2]=='S'&& buf[i+3]=='-' &&
buf[i+4]=='1'&& buf[i+5]=='2'&& buf[i+6]=='8'&& buf[i+7]=='-'){
i+=8;
if(Session.checkCipher((String)jsch.getConfig("aes128-cbc"))){
c=Class.forName((String)jsch.getConfig("aes128-cbc"));
cipher=(Cipher)(c.newInstance());
key=new byte[cipher.getBlockSize()];
iv=new byte[cipher.getIVSize()];
}
else{
throw new JSchException("privatekey: aes128-cbc is not available "+identity);
}
continue;
}
if(buf[i]=='C'&& i+3<len && buf[i+1]=='B'&& buf[i+2]=='C'&& buf[i+3]==','){
i+=4;
for(int ii=0; ii<iv.length; ii++){
Expand Down
1 change: 1 addition & 0 deletions src/com/jcraft/jsch/RequestExec.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public void request(Session session, Channel channel) throws Exception{
buf.putInt(channel.getRecipient());
buf.putString(Util.str2byte("exec"));
buf.putByte((byte)(waitForReply() ? 1 : 0));
buf.checkFreeSize(4+command.length);
buf.putString(command);
write(packet);
}
Expand Down
24 changes: 17 additions & 7 deletions src/com/jcraft/jsch/Session.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
import java.net.*;

public class Session implements Runnable{
static private final String version="JSCH-0.1.43";
static private final String version="JSCH-0.1.44";

// http://ietf.org/internet-drafts/draft-ietf-secsh-assignednumbers-01.txt
static final int SSH_MSG_DISCONNECT= 1;
Expand Down Expand Up @@ -1247,6 +1247,10 @@ public void run(){
stimeout++;
continue;
}
else if(in_kex && stimeout<serverAliveCountMax){
stimeout++;
continue;
}
throw ee;
}

Expand Down Expand Up @@ -1673,6 +1677,8 @@ private void setPortForwarding(String bind_address, int rport) throws JSchExcept

String address_to_bind=ChannelForwardedTCPIP.normalize(bind_address);

grr.setThread(Thread.currentThread());

try{
// byte SSH_MSG_GLOBAL_REQUEST 80
// string "tcpip-forward"
Expand All @@ -1682,25 +1688,29 @@ private void setPortForwarding(String bind_address, int rport) throws JSchExcept
packet.reset();
buf.putByte((byte) SSH_MSG_GLOBAL_REQUEST);
buf.putString(Util.str2byte("tcpip-forward"));
// buf.putByte((byte)0);
buf.putByte((byte)1);
buf.putString(Util.str2byte(address_to_bind));
buf.putInt(rport);
write(packet);
}
catch(Exception e){
grr.setThread(null);
if(e instanceof Throwable)
throw new JSchException(e.toString(), (Throwable)e);
throw new JSchException(e.toString());
}

grr.setThread(Thread.currentThread());
try{ Thread.sleep(10000);}
catch(Exception e){
int count = 0;
int reply = grr.getReply();
while(count < 10 && reply == -1){
try{ Thread.sleep(1000); }
catch(Exception e){
}
count++;
reply = grr.getReply();
}
int reply=grr.getReply();
grr.setThread(null);
if(reply==0){
if(reply != 1){
throw new JSchException("remote port forwarding failed for listen port "+rport);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/com/jcraft/jsch/jce/HMACMD596.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public void doFinal(byte[] buf, int offset){
}
catch(ShortBufferException e){
}
System.arraycopy(_buf16, 0, buf, 0, 12);
System.arraycopy(_buf16, 0, buf, offset, 12);
}

public String getName(){
Expand Down
2 changes: 1 addition & 1 deletion src/com/jcraft/jsch/jce/HMACSHA196.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public void doFinal(byte[] buf, int offset){
}
catch(ShortBufferException e){
}
System.arraycopy(_buf20, 0, buf, 0, 12);
System.arraycopy(_buf20, 0, buf, offset, 12);
}

public String getName(){
Expand Down

0 comments on commit 96b0558

Please sign in to comment.