Merge lp:~veger/ubuntu/quantal/jsch/fix-for-803492-v2 into lp:ubuntu/quantal/jsch

Proposed by Maarten Bezemer
Status: Merged
Merge reported by: James Page
Merged at revision: not available
Proposed branch: lp:~veger/ubuntu/quantal/jsch/fix-for-803492-v2
Merge into: lp:ubuntu/quantal/jsch
Diff against target: 7636 lines (+2809/-994)
141 files modified
.pc/.version (+0/-1)
.pc/applied-patches (+0/-1)
.pc/jsch-build-xml.patch/build.xml (+0/-77)
ChangeLog (+94/-1)
LICENSE.txt (+1/-1)
build.xml (+29/-9)
debian/changelog (+9/-0)
debian/control (+1/-1)
debian/patches/jsch-build-xml.patch (+6/-6)
debian/pom.xml (+1/-1)
examples/AES.java (+4/-0)
examples/ChangePassphrase.java (+11/-0)
examples/Compression.java (+9/-0)
examples/Daemon.java (+10/-2)
examples/Exec.java (+9/-0)
examples/KeyGen.java (+12/-0)
examples/KnownHosts.java (+10/-0)
examples/Logger.java (+4/-0)
examples/PortForwardingL.java (+11/-0)
examples/PortForwardingR.java (+11/-0)
examples/README (+16/-0)
examples/ScpFrom.java (+9/-0)
examples/ScpTo.java (+25/-2)
examples/ScpToNoneCipher.java (+4/-0)
examples/Sftp.java (+11/-0)
examples/Shell.java (+45/-89)
examples/StreamForwarding.java (+12/-0)
examples/Subsystem.java (+4/-0)
examples/Sudo.java (+184/-0)
examples/UserAuthKI.java (+8/-0)
examples/UserAuthPubKey.java (+8/-0)
examples/ViaHTTP.java (+8/-0)
examples/ViaSOCKS5.java (+8/-0)
examples/X11Forwarding.java (+10/-0)
src/main/java/com/jcraft/jsch/Buffer.java (+31/-3)
src/main/java/com/jcraft/jsch/Channel.java (+131/-92)
src/main/java/com/jcraft/jsch/ChannelAgentForwarding.java (+67/-28)
src/main/java/com/jcraft/jsch/ChannelDirectTCPIP.java (+40/-65)
src/main/java/com/jcraft/jsch/ChannelExec.java (+2/-2)
src/main/java/com/jcraft/jsch/ChannelForwardedTCPIP.java (+13/-9)
src/main/java/com/jcraft/jsch/ChannelSession.java (+8/-7)
src/main/java/com/jcraft/jsch/ChannelSftp.java (+424/-121)
src/main/java/com/jcraft/jsch/ChannelShell.java (+1/-1)
src/main/java/com/jcraft/jsch/ChannelSubsystem.java (+2/-2)
src/main/java/com/jcraft/jsch/ChannelX11.java (+11/-6)
src/main/java/com/jcraft/jsch/Cipher.java (+2/-1)
src/main/java/com/jcraft/jsch/CipherNone.java (+2/-1)
src/main/java/com/jcraft/jsch/Compression.java (+2/-2)
src/main/java/com/jcraft/jsch/DH.java (+1/-1)
src/main/java/com/jcraft/jsch/DHG1.java (+2/-2)
src/main/java/com/jcraft/jsch/DHG14.java (+310/-0)
src/main/java/com/jcraft/jsch/DHGEX.java (+2/-2)
src/main/java/com/jcraft/jsch/ForwardedTCPIPDaemon.java (+1/-1)
src/main/java/com/jcraft/jsch/GSSContext.java (+1/-1)
src/main/java/com/jcraft/jsch/HASH.java (+1/-1)
src/main/java/com/jcraft/jsch/HostKey.java (+6/-6)
src/main/java/com/jcraft/jsch/HostKeyRepository.java (+1/-1)
src/main/java/com/jcraft/jsch/IO.java (+1/-1)
src/main/java/com/jcraft/jsch/Identity.java (+1/-1)
src/main/java/com/jcraft/jsch/IdentityFile.java (+93/-15)
src/main/java/com/jcraft/jsch/IdentityRepository.java (+44/-0)
src/main/java/com/jcraft/jsch/JSch.java (+272/-42)
src/main/java/com/jcraft/jsch/JSchAuthCancelException.java (+1/-1)
src/main/java/com/jcraft/jsch/JSchException.java (+1/-1)
src/main/java/com/jcraft/jsch/JSchPartialAuthException.java (+1/-1)
src/main/java/com/jcraft/jsch/KeyExchange.java (+17/-17)
src/main/java/com/jcraft/jsch/KeyPair.java (+84/-20)
src/main/java/com/jcraft/jsch/KeyPairDSA.java (+4/-4)
src/main/java/com/jcraft/jsch/KeyPairGenDSA.java (+1/-1)
src/main/java/com/jcraft/jsch/KeyPairGenRSA.java (+1/-1)
src/main/java/com/jcraft/jsch/KeyPairRSA.java (+4/-4)
src/main/java/com/jcraft/jsch/KnownHosts.java (+37/-31)
src/main/java/com/jcraft/jsch/LocalIdentityRepository.java (+99/-0)
src/main/java/com/jcraft/jsch/Logger.java (+1/-1)
src/main/java/com/jcraft/jsch/MAC.java (+1/-1)
src/main/java/com/jcraft/jsch/Packet.java (+5/-4)
src/main/java/com/jcraft/jsch/PortWatcher.java (+1/-1)
src/main/java/com/jcraft/jsch/Proxy.java (+1/-1)
src/main/java/com/jcraft/jsch/ProxyHTTP.java (+6/-6)
src/main/java/com/jcraft/jsch/ProxySOCKS4.java (+2/-2)
src/main/java/com/jcraft/jsch/ProxySOCKS5.java (+4/-4)
src/main/java/com/jcraft/jsch/Random.java (+1/-1)
src/main/java/com/jcraft/jsch/Request.java (+1/-1)
src/main/java/com/jcraft/jsch/RequestAgentForwarding.java (+2/-2)
src/main/java/com/jcraft/jsch/RequestEnv.java (+2/-2)
src/main/java/com/jcraft/jsch/RequestExec.java (+3/-2)
src/main/java/com/jcraft/jsch/RequestPtyReq.java (+4/-4)
src/main/java/com/jcraft/jsch/RequestSftp.java (+3/-3)
src/main/java/com/jcraft/jsch/RequestShell.java (+2/-2)
src/main/java/com/jcraft/jsch/RequestSignal.java (+3/-3)
src/main/java/com/jcraft/jsch/RequestSubsystem.java (+3/-3)
src/main/java/com/jcraft/jsch/RequestWindowChange.java (+2/-2)
src/main/java/com/jcraft/jsch/RequestX11.java (+4/-4)
src/main/java/com/jcraft/jsch/ServerSocketFactory.java (+1/-1)
src/main/java/com/jcraft/jsch/Session.java (+278/-101)
src/main/java/com/jcraft/jsch/SftpATTRS.java (+5/-5)
src/main/java/com/jcraft/jsch/SftpException.java (+1/-1)
src/main/java/com/jcraft/jsch/SftpProgressMonitor.java (+2/-1)
src/main/java/com/jcraft/jsch/SignatureDSA.java (+1/-1)
src/main/java/com/jcraft/jsch/SignatureRSA.java (+1/-1)
src/main/java/com/jcraft/jsch/SocketFactory.java (+1/-1)
src/main/java/com/jcraft/jsch/UIKeyboardInteractive.java (+1/-1)
src/main/java/com/jcraft/jsch/UserAuth.java (+1/-1)
src/main/java/com/jcraft/jsch/UserAuthGSSAPIWithMIC.java (+6/-6)
src/main/java/com/jcraft/jsch/UserAuthKeyboardInteractive.java (+28/-30)
src/main/java/com/jcraft/jsch/UserAuthNone.java (+6/-12)
src/main/java/com/jcraft/jsch/UserAuthPassword.java (+14/-8)
src/main/java/com/jcraft/jsch/UserAuthPublicKey.java (+17/-19)
src/main/java/com/jcraft/jsch/UserInfo.java (+1/-1)
src/main/java/com/jcraft/jsch/Util.java (+19/-9)
src/main/java/com/jcraft/jsch/jce/AES128CBC.java (+3/-1)
src/main/java/com/jcraft/jsch/jce/AES128CTR.java (+3/-1)
src/main/java/com/jcraft/jsch/jce/AES192CBC.java (+2/-1)
src/main/java/com/jcraft/jsch/jce/AES192CTR.java (+2/-1)
src/main/java/com/jcraft/jsch/jce/AES256CBC.java (+2/-1)
src/main/java/com/jcraft/jsch/jce/AES256CTR.java (+2/-1)
src/main/java/com/jcraft/jsch/jce/ARCFOUR.java (+2/-1)
src/main/java/com/jcraft/jsch/jce/ARCFOUR128.java (+2/-1)
src/main/java/com/jcraft/jsch/jce/ARCFOUR256.java (+2/-1)
src/main/java/com/jcraft/jsch/jce/BlowfishCBC.java (+2/-1)
src/main/java/com/jcraft/jsch/jce/DH.java (+1/-1)
src/main/java/com/jcraft/jsch/jce/HMACMD5.java (+1/-1)
src/main/java/com/jcraft/jsch/jce/HMACMD596.java (+2/-2)
src/main/java/com/jcraft/jsch/jce/HMACSHA1.java (+1/-1)
src/main/java/com/jcraft/jsch/jce/HMACSHA196.java (+2/-2)
src/main/java/com/jcraft/jsch/jce/KeyPairGenDSA.java (+1/-1)
src/main/java/com/jcraft/jsch/jce/KeyPairGenRSA.java (+1/-1)
src/main/java/com/jcraft/jsch/jce/MD5.java (+1/-1)
src/main/java/com/jcraft/jsch/jce/Random.java (+1/-1)
src/main/java/com/jcraft/jsch/jce/SHA1.java (+1/-1)
src/main/java/com/jcraft/jsch/jce/SignatureDSA.java (+1/-1)
src/main/java/com/jcraft/jsch/jce/SignatureRSA.java (+1/-1)
src/main/java/com/jcraft/jsch/jce/TripleDESCBC.java (+2/-1)
src/main/java/com/jcraft/jsch/jce/TripleDESCTR.java (+2/-1)
src/main/java/com/jcraft/jsch/jcraft/Compression.java (+23/-28)
src/main/java/com/jcraft/jsch/jcraft/HMAC.java (+1/-1)
src/main/java/com/jcraft/jsch/jcraft/HMACMD5.java (+1/-1)
src/main/java/com/jcraft/jsch/jcraft/HMACMD596.java (+1/-1)
src/main/java/com/jcraft/jsch/jcraft/HMACSHA1.java (+1/-1)
src/main/java/com/jcraft/jsch/jcraft/HMACSHA196.java (+1/-1)
src/main/java/com/jcraft/jsch/jgss/GSSContextKrb5.java (+1/-1)
To merge this branch: bzr merge lp:~veger/ubuntu/quantal/jsch/fix-for-803492-v2
Reviewer Review Type Date Requested Status
James Page Approve
Ubuntu branches Pending
Review via email: mp+104706@code.launchpad.net

Description of the change

Changes from 0.1.42 to 0.1.48 can be found at: http://www.jcraft.com/jsch/ChangeLog

To post a comment you must log in.
11. By Maarten Bezemer

Reverted removal (and refreshed) jsch-build-xml.patch as it still is required

Revision history for this message
James Page (james-page) wrote :

Hi Maarten

Thanks for preparing this update; I have two bits of feedback

1) The Merge proposal looks a little odd (removal of files in the .pc directory) because you have not applied all patched and added the .pc directory. This is a little counter intuitive but makes it easier to review

2) d/manifest.mf needed an update as well for the new version.

I've fixed both of these issues and uploaded - thanks for your contribution!

Cheers

James

review: Approve
Revision history for this message
James Page (james-page) wrote :

Oh - I missed this last point as well - you should really reference the bug report in the changelog entry with a (LP: #xxxxx) reference - that way the bug report gets closed as well.

I obviously still need more coffee...

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== removed directory '.pc'
=== removed file '.pc/.version'
--- .pc/.version 2010-06-27 23:17:34 +0000
+++ .pc/.version 1970-01-01 00:00:00 +0000
@@ -1,1 +0,0 @@
12
20
=== removed file '.pc/applied-patches'
--- .pc/applied-patches 2010-06-27 23:17:34 +0000
+++ .pc/applied-patches 1970-01-01 00:00:00 +0000
@@ -1,1 +0,0 @@
1jsch-build-xml.patch
20
=== removed directory '.pc/jsch-build-xml.patch'
=== removed file '.pc/jsch-build-xml.patch/build.xml'
--- .pc/jsch-build-xml.patch/build.xml 2010-06-27 23:17:34 +0000
+++ .pc/jsch-build-xml.patch/build.xml 1970-01-01 00:00:00 +0000
@@ -1,77 +0,0 @@
1<project name="Jsch" default="dist" basedir=".">
2 <description>
3JSch is a pure Java implementation of SSH2. JSch allows you to connect to an
4sshd server and use port forwarding, X11 forwarding, file transfer, etc., and
5you can integrate its functionality into your own Java programs
6 </description>
7 <!-- set global properties for this build -->
8 <property name="version" location="0.1.40"/>
9 <property name="src" location="src"/>
10 <property name="exasrc" location="examples"/>
11 <property name="build" location="build"/>
12 <property name="exabuild" location="examples"/>
13 <property name="dist" location="dist"/>
14 <property name="javadoc" location="javadoc"/>
15 <property name="javac.debug" value="true"/>
16 <path id="project.cp">
17 <pathelement location="${build}"/>
18 </path>
19 <target name="init">
20 <!-- Create the time stamp -->
21 <tstamp/>
22 <!-- Create the build directory structure used by compile -->
23 <mkdir dir="${build}"/>
24 </target>
25
26 <target name="compile" depends="init"
27 description="compile the source " >
28 <!-- Compile the java code from ${src} into ${build} -->
29 <available property="jzlib.available"
30 classname="com.jcraft.jzlib.ZStream"/>
31 <javac srcdir="${src}" destdir="${build}" debug="${javac.debug}">
32 <exclude name="com/jcraft/jsch/jcraft/Compression.java"
33 unless="jzlib.available"/>
34 </javac>
35 </target>
36 <target name="run" depends="compile">
37 <java classname="Login" classpathref="project.cp"/>
38 </target>
39 <target name="dist" depends="compile"
40 description="generate the distribution" >
41 <!-- Create the distribution directory -->
42 <mkdir dir="${dist}/lib"/>
43
44 <!-- Put everything in ${build} into the MyProject-${DSTAMP}.jar file -->
45 <jar jarfile="${dist}/lib/jsch-${DSTAMP}.jar" basedir="${build}"/>
46 </target>
47
48 <target name="examples"
49 description="compiles the examples"
50 depends="compile">
51
52 <path id="compile.classpath">
53 <pathelement location="${build}" />
54 </path>
55
56 <javac srcdir="${exasrc}" destdir="${exabuild}">
57 <classpath refid="compile.classpath"/>
58 </javac>
59
60 </target>
61
62 <target name="clean"
63 description="clean up" >
64 <!-- Delete the ${build} and ${dist} directory trees -->
65 <delete dir="${build}"/>
66 <delete dir="${dist}"/>
67 <delete dir="${javadoc}"/>
68 </target>
69
70 <target name="javadoc">
71 <javadoc sourcepath="${src}"
72 destdir="${javadoc}"
73 >
74 <packageset dir="${src}"/>
75 </javadoc>
76 </target>
77</project>
780
=== modified file 'ChangeLog'
--- ChangeLog 2010-06-27 23:17:34 +0000
+++ ChangeLog 2012-05-04 10:23:17 +0000
@@ -1,6 +1,99 @@
1ChangeLog of JSch1ChangeLog of JSch
2====================================================================2====================================================================
3Last modified: Tue Jul 14 02:29:29 UTC 20093Last modified: Fri Apr 20 06:44:50 UTC 2012
4
5
6Changes since version 0.1.47:
7- change: the file transfer speed with ChannelSftp#get(String src) has been
8 improved; sending multiple requests at any one time.
9- change: by the default, at most, 16 requests will be sent at any one time
10 in ChannelSftp.
11- feature: added Session#{setIdentityRepository(),getIdentityRepository()}
12
13
14Changes since version 0.1.46:
15- bugfix: failed to initialize channels for the stream forwarding. FIXED
16- change: Session#getHostKey() will return the given hostkey
17 even if session is not established.
18- change: Logger will record additional messages about algorithm negotiations.
19- feature: added ChannelSftp#ls(String path, LsEntrySelector selector) method.
20- feature: added IdentityRepository#{getName(),getStatus()} methods.
21
22
23Changes since version 0.1.45:
24- bugfix: in the agent forwarding mode, "ssh-add -l" on the remote
25 will freeze. FIXED
26- bugfix: requests should not be sent to the closed channel. FIXED
27- bugfix: ChannelShell#setAgentForwarding(true) will cause
28 resource leaks. FIXED
29- change: for the efficiency, channel opening will be delayed
30 in local port forwarding.
31- change: added examples/Sudo.java to demonstrate sudo on exec channel.
32- change: authentication trials will be failed at 6 failures by the default.
33- change: updating copyright messages; 2011 -> 2012
34- feature: added JSch#setIdentityRepository(IdentityRepository irepo) to
35 integrate with jsch-agent-proxy.
36
37
38Changes since version 0.1.44:
39- bugfix: fields referred by multiple threads simultaneously should be
40 volatile. FIXED
41- bugfix: use local window size offered by the remote in sftp put.
42 FIXED
43- bugfix: SftpProgressMonitor#init was not invoked in sftp-put
44 for input-stream. FIXED
45- bugfix: sftp protocol version 3, 4 and 5 should allow only
46 UTF-8 encoding. FIXED
47- bugfix: Channel Subsystem had failed to set X forwarding flag.
48 FIXED
49- bugfix: Channel X11 had leaked some resources.
50 FIXED
51- bugfix: packet compression may break sessions
52 in some case(transferring deflated data). FIXED
53- bugfix: failed to set dev-null for logger
54 FIXED
55- bugfix: even in sftp protocol version 3 session, some sftpd sends data
56 packets defined in sftp protocol 6 ;-( working around it. FIXED
57- bugfix: ChannelSftp file globbing logic had missed
58 the string "foo\\\*bar" as a pattern. FIXED
59- bugfix: sequential accesses to ChannelSftp by multiple threads may
60 break its I/O channel.
61 https://bugs.eclipse.org/bugs/show_bug.cgi?id=359184 FIXED
62- bugfix: KeyPair.load can not handle private keys cyphered with AES. FIXED
63- change: to improve sftp-put performance, send multiple packet at one time.
64- change: wait/notify will be used instead of sleep loop
65 in establishing channel connections.
66- change: increasing local window size for sftp get.
67- change: updating copyright messages; 2010 -> 2011
68- change: src/com -> src/main/java/com
69- feature: key-exchange method "diffie-hellman-group14-sha1"
70 (RFC4253#section-8.2)
71- feature: KeyPair#getPlulicKeyCommment() is added.
72
73
74Changes since version 0.1.43:
75- bugfix: hmac-md5-96 and hmac-sha1-96 are broken. FIXED.
76- bugfix: working around OOME in parsing broken data from the remote. FIXED.
77- bugfix: failed to send very long command for exec channels. FIXED.
78- bugfix: in some case, failed to get the response
79 for remote port-forwarding request. FIXED.
80- feature: support for private keys ciphered with aes192-cbc and aes128-cbc.
81
82
83Changes since version 0.1.42:
84- bugfix: the remote window size must be in unsigned int. FIXED.
85- bugfix: support for EBCDIC environment. FIXED.
86- bugfix: data may be written to the closed channel. FIXED.
87- bugfix: NPE in closing channels. FIXED.
88- bugfix: the private key file may include garbage data before its header. FIXED.
89- bugfix: the session down may not be detected during the re-keying process. FIXED.
90- change: try keyboard-interactive auth with the given password if UserInfo is not given.
91- change: working around the wrong auth method list sent by some SSHD
92 in the partial auth success.
93- change: working around the CPNI-957037 Plain-text Recovery Attack.
94- change: in searching for [host]:non-default port in known_hosts,
95 host:22 should be also checked.
96- change: updating copyright messages; 2009 -> 2010
497
5 98
6Changes since version 0.1.41:99Changes since version 0.1.41:
7100
=== modified file 'LICENSE.txt'
--- LICENSE.txt 2010-06-27 23:17:34 +0000
+++ LICENSE.txt 2012-05-04 10:23:17 +0000
@@ -2,7 +2,7 @@
2over to a BSD-style license. 2over to a BSD-style license.
33
4------------------------------------------------------------------------------4------------------------------------------------------------------------------
5Copyright (c) 2002,2003,2004,2005,2006,2007,2008,2009 Atsuhiko Yamanaka, JCraft,Inc. 5Copyright (c) 2002-2012 Atsuhiko Yamanaka, JCraft,Inc.
6All rights reserved.6All rights reserved.
77
8Redistribution and use in source and binary forms, with or without8Redistribution and use in source and binary forms, with or without
99
=== modified file 'build.xml'
--- build.xml 2010-06-27 23:17:34 +0000
+++ build.xml 2012-05-04 10:23:17 +0000
@@ -5,14 +5,17 @@
5you can integrate its functionality into your own Java programs5you can integrate its functionality into your own Java programs
6 </description>6 </description>
7 <!-- set global properties for this build -->7 <!-- set global properties for this build -->
8 <property name="version" location="0.1.40"/>8 <property name="version" value="0.1.48"/>
9 <property name="src" location="src"/>9 <property name="src" location="src/main/java/"/>
10 <property name="exasrc" location="examples"/>10 <property name="exasrc" location="examples"/>
11 <property name="build" location="build"/>11 <property name="build" location="build"/>
12 <property name="exabuild" location="examples"/>12 <property name="exabuild" location="examples"/>
13 <property name="dist" location="dist"/>13 <property name="dist" location="dist"/>
14 <property name="javadoc" location="javadoc"/>14 <property name="javadoc" location="javadoc"/>
15 <property name="javac.debug" value="true"/>15 <property name="javac.debug" value="true"/>
16 <path id="lib.path.ref">
17 <fileset dir="lib" includes="*.jar"/>
18 </path>
16 <path id="project.cp">19 <path id="project.cp">
17 <pathelement location="${build}"/>20 <pathelement location="${build}"/>
18 </path>21 </path>
@@ -27,22 +30,39 @@
27 description="compile the source " >30 description="compile the source " >
28 <!-- Compile the java code from ${src} into ${build} -->31 <!-- Compile the java code from ${src} into ${build} -->
29 <available property="jzlib.available"32 <available property="jzlib.available"
30 classname="com.jcraft.jzlib.ZStream"/>33 classname="com.jcraft.jzlib.ZStream">
31 <javac srcdir="${src}" destdir="${build}" debug="${javac.debug}">34 <classpath refid="lib.path.ref"/>
35 </available>
36 <javac srcdir="${src}"
37 destdir="${build}"
38 target="1.4"
39 source="1.4"
40 debug="${javac.debug}">
41 <classpath refid="lib.path.ref"/>
32 <exclude name="com/jcraft/jsch/jcraft/Compression.java"42 <exclude name="com/jcraft/jsch/jcraft/Compression.java"
33 unless="jzlib.available"/>43 unless="jzlib.available"/>
34 </javac>44 </javac>
35 </target>45 </target>
36 <target name="run" depends="compile">
37 <java classname="Login" classpathref="project.cp"/>
38 </target>
39 <target name="dist" depends="compile"46 <target name="dist" depends="compile"
40 description="generate the distribution" >47 description="generate the distribution" >
41 <!-- Create the distribution directory -->48 <!-- Create the distribution directory -->
42 <mkdir dir="${dist}/lib"/>49 <mkdir dir="${dist}/lib"/>
4350
44 <!-- Put everything in ${build} into the MyProject-${DSTAMP}.jar file -->51 <!-- Put everything in ${build} into the MyProject-${version}.jar file -->
45 <jar jarfile="${dist}/lib/jsch.jar" basedir="${build}" manifest="debian/manifest.mf" />52 <jar jarfile="${dist}/lib/jsch-${version}.jar" basedir="${build}">
53 <!--
54 <manifest>
55 <attribute name="Bundle-ClassPath" value="."/>
56 <attribute name="Bundle-Vendor" value="JCraft, Inc."/>
57 <attribute name="Bundle-Name" value="com.jcraft.jsch"/>
58 <attribute name="Bundle-ManifestVersion" value="2"/>
59 <attribute name="Bundle-SymbolicName" value="com.jcraft.jsch"/>
60 <attribute name="Bundle-Version" value="${version}"/>
61 <attribute name="Export-Package" value='com.jcraft.jsch;version="${version}",com.jcraft.jsch.jce;version="${version}";x-internal:=true,com.jcraft.jsch.jcraft;version="${version}";x-internal:=true,com.jcraft.jsch.jgss;version="${version}";x-internal:=true'/>
62 <attribute name="Import-Package" value="javax.crypto,javax.crypto.spec,javax.crypto.interfaces,org.ietf.jgss,com.jcraft.jzlib"/>
63 </manifest>
64 -->
65 </jar>
46 </target>66 </target>
4767
48 <target name="examples"68 <target name="examples"
4969
=== modified file 'debian/changelog'
--- debian/changelog 2010-06-27 23:17:34 +0000
+++ debian/changelog 2012-05-04 10:23:17 +0000
@@ -1,3 +1,12 @@
1jsch (0.1.48-0ubuntu1) quantal; urgency=low
2
3 * New upstream release.
4 - Updated debian/pom.xml
5 - Refreshed jsch-build-xml.patch
6 * Bumped Standards-Version to 3.9.3 - no changes required.
7
8 -- Maarten Bezemer <maarten.bezemer@gmail.com> Fri, 04 May 2012 10:39:23 +0200
9
1jsch (0.1.42-2fakesync1) maverick; urgency=low10jsch (0.1.42-2fakesync1) maverick; urgency=low
211
3 * Fake sync due to mismatching orig tarball.12 * Fake sync due to mismatching orig tarball.
413
=== modified file 'debian/control'
--- debian/control 2010-06-27 23:17:34 +0000
+++ debian/control 2012-05-04 10:23:17 +0000
@@ -8,7 +8,7 @@
8 Niels Thykier <niels@thykier.net>8 Niels Thykier <niels@thykier.net>
9Build-Depends: debhelper (>= 7), cdbs, default-jdk9Build-Depends: debhelper (>= 7), cdbs, default-jdk
10Build-Depends-Indep: maven-repo-helper, ant (>= 1.6.5)10Build-Depends-Indep: maven-repo-helper, ant (>= 1.6.5)
11Standards-Version: 3.8.411Standards-Version: 3.9.3
12Vcs-Svn: svn://svn.debian.org/svn/pkg-java/trunk/jsch12Vcs-Svn: svn://svn.debian.org/svn/pkg-java/trunk/jsch
13Vcs-Browser: http://svn.debian.org/wsvn/pkg-java/trunk/jsch13Vcs-Browser: http://svn.debian.org/wsvn/pkg-java/trunk/jsch
14Homepage: http://www.jcraft.com/jsch/14Homepage: http://www.jcraft.com/jsch/
1515
=== modified file 'debian/patches/jsch-build-xml.patch'
--- debian/patches/jsch-build-xml.patch 2010-06-27 23:17:34 +0000
+++ debian/patches/jsch-build-xml.patch 2012-05-04 10:23:17 +0000
@@ -7,9 +7,9 @@
7@@ -42,7 +42,7 @@7@@ -42,7 +42,7 @@
8 <mkdir dir="${dist}/lib"/>8 <mkdir dir="${dist}/lib"/>
9 9
10 <!-- Put everything in ${build} into the MyProject-${DSTAMP}.jar file -->10 <!-- Put everything in ${build} into the MyProject-${version}.jar file -->
11- <jar jarfile="${dist}/lib/jsch-${DSTAMP}.jar" basedir="${build}"/>11- <jar jarfile="${dist}/lib/jsch-${version}.jar" basedir="${build}">
12+ <jar jarfile="${dist}/lib/jsch.jar" basedir="${build}" manifest="debian/manifest.mf" />12+ <jar jarfile="${dist}/lib/jsch.jar" basedir="${build}" manifest="debian/manifest.mf">
13 </target>13 <!--
14 14 <manifest>
15 <target name="examples"15 <attribute name="Bundle-ClassPath" value="."/>
1616
=== modified file 'debian/pom.xml'
--- debian/pom.xml 2009-09-22 20:01:52 +0000
+++ debian/pom.xml 2012-05-04 10:23:17 +0000
@@ -6,7 +6,7 @@
6 <modelVersion>4.0.0</modelVersion>6 <modelVersion>4.0.0</modelVersion>
7 <groupId>com.jcraft</groupId>7 <groupId>com.jcraft</groupId>
8 <artifactId>jsch</artifactId>8 <artifactId>jsch</artifactId>
9 <version>0.1.42</version>9 <version>0.1.48</version>
10 <name>JSch</name>10 <name>JSch</name>
1111
12 <description>JSch is a pure Java implementation of SSH2</description>12 <description>JSch is a pure Java implementation of SSH2</description>
1313
=== removed directory 'dist'
=== removed directory 'dist/lib'
=== modified file 'examples/AES.java'
--- examples/AES.java 2008-02-06 23:23:19 +0000
+++ examples/AES.java 2012-05-04 10:23:17 +0000
@@ -1,4 +1,8 @@
1/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */1/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
2/**
3 * This program will demonstrate how to use "aes128-cbc".
4 *
5 */
2import com.jcraft.jsch.*;6import com.jcraft.jsch.*;
3import java.awt.*;7import java.awt.*;
4import javax.swing.*;8import javax.swing.*;
59
=== modified file 'examples/ChangePassphrase.java'
--- examples/ChangePassphrase.java 2007-09-09 20:32:32 +0000
+++ examples/ChangePassphrase.java 2012-05-04 10:23:17 +0000
@@ -1,4 +1,15 @@
1/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */1/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
2/**
3 * This program will demonstrate to change the passphrase for a
4 * private key file instead of creating a new private key.
5 * $ CLASSPATH=.:../build javac ChangePassphrase.java
6 * $ CLASSPATH=.:../build java ChangePassphrase private-key
7 * A passphrase will be prompted if the given private-key has been
8 * encrypted. After successfully loading the content of the
9 * private-key, the new passphrase will be prompted and the given
10 * private-key will be re-encrypted with that new passphrase.
11 *
12 */
2import com.jcraft.jsch.*;13import com.jcraft.jsch.*;
3import javax.swing.*;14import javax.swing.*;
415
516
=== modified file 'examples/Compression.java'
--- examples/Compression.java 2008-02-06 23:23:19 +0000
+++ examples/Compression.java 2012-05-04 10:23:17 +0000
@@ -1,4 +1,13 @@
1/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */1/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
2/**
3 * This program will demonstrate the packet compression.
4 * $ CLASSPATH=.:../build javac Compression.java
5 * $ CLASSPATH=.:../build java Compression
6 * You will be asked username, hostname and passwd.
7 * If everything works fine, you will get the shell prompt.
8 * In this program, all data from sshd server to jsch will be compressed.
9 *
10 */
2import com.jcraft.jsch.*;11import com.jcraft.jsch.*;
3import java.awt.*;12import java.awt.*;
4import javax.swing.*;13import javax.swing.*;
514
=== modified file 'examples/Daemon.java'
--- examples/Daemon.java 2008-02-06 23:23:19 +0000
+++ examples/Daemon.java 2012-05-04 10:23:17 +0000
@@ -1,4 +1,9 @@
1/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */1/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
2/**
3 * This program will demonstrate how to provide a network service like
4 * inetd by using remote port-forwarding functionality.
5 *
6 */
2import com.jcraft.jsch.*;7import com.jcraft.jsch.*;
3import java.io.*;8import java.io.*;
4import java.awt.*;9import java.awt.*;
@@ -58,10 +63,10 @@
58 }63 }
59 public void setArg(Object[] arg){this.arg=arg;}64 public void setArg(Object[] arg){this.arg=arg;}
60 public void run(){65 public void run(){
61 System.out.println("remote port: "+channel.getRemotePort());
62 System.out.println("remote host: "+channel.getSession().getHost());
63 try{66 try{
64 byte[] buf=new byte[1024];67 byte[] buf=new byte[1024];
68 System.out.println("remote port: "+channel.getRemotePort());
69 System.out.println("remote host: "+channel.getSession().getHost());
65 while(true){70 while(true){
66 int i=in.read(buf, 0, buf.length);71 int i=in.read(buf, 0, buf.length);
67 if(i<=0)break;72 if(i<=0)break;
@@ -70,6 +75,9 @@
70 if(buf[0]=='.')break;75 if(buf[0]=='.')break;
71 }76 }
72 }77 }
78 catch(JSchException e){
79 System.out.println("session is down.");
80 }
73 catch(IOException e){81 catch(IOException e){
74 }82 }
75 }83 }
7684
=== modified file 'examples/Exec.java'
--- examples/Exec.java 2008-02-06 23:23:19 +0000
+++ examples/Exec.java 2012-05-04 10:23:17 +0000
@@ -1,4 +1,13 @@
1/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */1/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
2/**
3 * This program will demonstrate remote exec.
4 * $ CLASSPATH=.:../build javac Exec.java
5 * $ CLASSPATH=.:../build java Exec
6 * You will be asked username, hostname, displayname, passwd and command.
7 * If everything works fine, given command will be invoked
8 * on the remote side and outputs will be printed out.
9 *
10 */
2import com.jcraft.jsch.*;11import com.jcraft.jsch.*;
3import java.awt.*;12import java.awt.*;
4import javax.swing.*;13import javax.swing.*;
514
=== modified file 'examples/KeyGen.java'
--- examples/KeyGen.java 2007-09-09 20:32:32 +0000
+++ examples/KeyGen.java 2012-05-04 10:23:17 +0000
@@ -1,4 +1,16 @@
1/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */1/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
2/**
3 * This progam will demonstrate the DSA keypair generation.
4 * $ CLASSPATH=.:../build javac KeyGen.java
5 * $ CLASSPATH=.:../build java KeyGen rsa output_keyfile comment
6 * or
7 * $ CLASSPATH=.:../build java KeyGen dsa output_keyfile comment
8 * You will be asked a passphrase for output_keyfile.
9 * If everything works fine, you will get the DSA or RSA keypair,
10 * output_keyfile and output_keyfile+".pub".
11 * The private key and public key are in the OpenSSH format.
12 *
13 */
2import com.jcraft.jsch.*;14import com.jcraft.jsch.*;
3import javax.swing.*;15import javax.swing.*;
416
517
=== modified file 'examples/KnownHosts.java'
--- examples/KnownHosts.java 2008-02-06 23:23:19 +0000
+++ examples/KnownHosts.java 2012-05-04 10:23:17 +0000
@@ -1,4 +1,14 @@
1/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */1/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
2/**
3 * This program will demonstrate the 'known_hosts' file handling.
4 * $ CLASSPATH=.:../build javac KnownHosts.java
5 * $ CLASSPATH=.:../build java KnownHosts
6 * You will be asked username, hostname, a path for 'known_hosts' and passwd.
7 * If everything works fine, you will get the shell prompt.
8 * In current implementation, jsch only reads 'known_hosts' for checking
9 * and does not modify it.
10 *
11 */
2import com.jcraft.jsch.*;12import com.jcraft.jsch.*;
3import java.awt.*;13import java.awt.*;
4import javax.swing.*;14import javax.swing.*;
515
=== modified file 'examples/Logger.java'
--- examples/Logger.java 2008-02-06 23:23:19 +0000
+++ examples/Logger.java 2012-05-04 10:23:17 +0000
@@ -1,4 +1,8 @@
1/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */1/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
2/**
3 * This program will demonstrate how to enable logging mechanism and
4 * get logging messages.
5 */
2import com.jcraft.jsch.*;6import com.jcraft.jsch.*;
3import java.awt.*;7import java.awt.*;
4import javax.swing.*;8import javax.swing.*;
59
=== modified file 'examples/PortForwardingL.java'
--- examples/PortForwardingL.java 2008-02-06 23:23:19 +0000
+++ examples/PortForwardingL.java 2012-05-04 10:23:17 +0000
@@ -1,4 +1,15 @@
1/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */1/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
2/**
3 * This program will demonstrate the port forwarding like option -L of
4 * ssh command; the given port on the local host will be forwarded to
5 * the given remote host and port on the remote side.
6 * $ CLASSPATH=.:../build javac PortForwardingL.java
7 * $ CLASSPATH=.:../build java PortForwardingL
8 * You will be asked username, hostname, port:host:hostport and passwd.
9 * If everything works fine, you will get the shell prompt.
10 * Try the port on localhost.
11 *
12 */
2import com.jcraft.jsch.*;13import com.jcraft.jsch.*;
3import java.awt.*;14import java.awt.*;
4import javax.swing.*;15import javax.swing.*;
516
=== modified file 'examples/PortForwardingR.java'
--- examples/PortForwardingR.java 2008-02-06 23:23:19 +0000
+++ examples/PortForwardingR.java 2012-05-04 10:23:17 +0000
@@ -1,4 +1,15 @@
1/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */1/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
2/**
3 * This program will demonstrate the port forwarding like option -R of
4 * ssh command; the given port on the remote host will be forwarded to
5 * the given host and port on the local side.
6 * $ CLASSPATH=.:../build javac PortForwardingR.java
7 * $ CLASSPATH=.:../build java PortForwardingR
8 * You will be asked username, hostname, port:host:hostport and passwd.
9 * If everything works fine, you will get the shell prompt.
10 * Try the port on remote host.
11 *
12 */
2import com.jcraft.jsch.*;13import com.jcraft.jsch.*;
3import java.awt.*;14import java.awt.*;
4import javax.swing.*;15import javax.swing.*;
516
=== modified file 'examples/README'
--- examples/README 2007-09-09 20:32:32 +0000
+++ examples/README 2012-05-04 10:23:17 +0000
@@ -38,6 +38,13 @@
38 You will be asked username, hostname, proxy-server and passwd. 38 You will be asked username, hostname, proxy-server and passwd.
39 If everything works fine, you will get the shell prompt.39 If everything works fine, you will get the shell prompt.
4040
41- ViaSOCKS.java
42 This program will demonstrate the ssh session via SOCKS proxy.
43 $ CLASSPATH=.:../build javac ViaSOCKS.java
44 $ CLASSPATH=.:../build java ViaSOCKS
45 You will be asked username, hostname, proxy-server and passwd.
46 If everything works fine, you will get the shell prompt.
47
41- PortForwardingR.java48- PortForwardingR.java
42 This program will demonstrate the port forwarding like option -R of49 This program will demonstrate the port forwarding like option -R of
43 ssh command; the given port on the remote host will be forwarded to50 ssh command; the given port on the remote host will be forwarded to
@@ -158,3 +165,12 @@
158- Logger.java165- Logger.java
159 This program will demonstrate how to enable logging mechanism and166 This program will demonstrate how to enable logging mechanism and
160 get logging messages.167 get logging messages.
168
169- Subsystem.java
170 This program will demonstrate how to use the Subsystem channel.
171
172- Sudo.java
173 This program will demonstrate how to exec 'sudo' on the remote.
174
175- ScpToNoneCipher.java
176 This program will demonstrate how to enable none cipher.
161177
=== modified file 'examples/ScpFrom.java'
--- examples/ScpFrom.java 2007-09-09 20:32:32 +0000
+++ examples/ScpFrom.java 2012-05-04 10:23:17 +0000
@@ -1,4 +1,13 @@
1/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */1/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
2/**
3 * This program will demonstrate the file transfer from remote to local
4 * $ CLASSPATH=.:../build javac ScpFrom.java
5 * $ CLASSPATH=.:../build java ScpFrom user@remotehost:file1 file2
6 * You will be asked passwd.
7 * If everything works fine, a file 'file1' on 'remotehost' will copied to
8 * local 'file1'.
9 *
10 */
2import com.jcraft.jsch.*;11import com.jcraft.jsch.*;
3import java.awt.*;12import java.awt.*;
4import javax.swing.*;13import javax.swing.*;
514
=== modified file 'examples/ScpTo.java'
--- examples/ScpTo.java 2007-09-09 20:32:32 +0000
+++ examples/ScpTo.java 2012-05-04 10:23:17 +0000
@@ -1,4 +1,13 @@
1/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */1/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
2/**
3 * This program will demonstrate the file transfer from local to remote.
4 * $ CLASSPATH=.:../build javac ScpTo.java
5 * $ CLASSPATH=.:../build java ScpTo file1 user@remotehost:file2
6 * You will be asked passwd.
7 * If everything works fine, a local file 'file1' will copied to
8 * 'file2' on 'remotehost'.
9 *
10 */
2import com.jcraft.jsch.*;11import com.jcraft.jsch.*;
3import java.awt.*;12import java.awt.*;
4import javax.swing.*;13import javax.swing.*;
@@ -28,9 +37,10 @@
28 session.setUserInfo(ui);37 session.setUserInfo(ui);
29 session.connect();38 session.connect();
3039
40 boolean ptimestamp = true;
3141
32 // exec 'scp -t rfile' remotely42 // exec 'scp -t rfile' remotely
33 String command="scp -p -t "+rfile;43 String command="scp " + (ptimestamp ? "-p" :"") +" -t "+rfile;
34 Channel channel=session.openChannel("exec");44 Channel channel=session.openChannel("exec");
35 ((ChannelExec)channel).setCommand(command);45 ((ChannelExec)channel).setCommand(command);
3646
@@ -44,8 +54,21 @@
44 System.exit(0);54 System.exit(0);
45 }55 }
4656
57 File _lfile = new File(lfile);
58
59 if(ptimestamp){
60 command="T "+(_lfile.lastModified()/1000)+" 0";
61 // The access time should be sent here,
62 // but it is not accessible with JavaAPI ;-<
63 command+=(" "+(_lfile.lastModified()/1000)+" 0\n");
64 out.write(command.getBytes()); out.flush();
65 if(checkAck(in)!=0){
66 System.exit(0);
67 }
68 }
69
47 // send "C0644 filesize filename", where filename should not include '/'70 // send "C0644 filesize filename", where filename should not include '/'
48 long filesize=(new File(lfile)).length();71 long filesize=_lfile.length();
49 command="C0644 "+filesize+" ";72 command="C0644 "+filesize+" ";
50 if(lfile.lastIndexOf('/')>0){73 if(lfile.lastIndexOf('/')>0){
51 command+=lfile.substring(lfile.lastIndexOf('/')+1);74 command+=lfile.substring(lfile.lastIndexOf('/')+1);
5275
=== modified file 'examples/ScpToNoneCipher.java'
--- examples/ScpToNoneCipher.java 2007-09-09 20:32:32 +0000
+++ examples/ScpToNoneCipher.java 2012-05-04 10:23:17 +0000
@@ -1,4 +1,8 @@
1/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */1/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
2/**
3 * This program will demonstrate how to enable none cipher.
4 *
5 */
2import com.jcraft.jsch.*;6import com.jcraft.jsch.*;
3import java.awt.*;7import java.awt.*;
4import javax.swing.*;8import javax.swing.*;
59
=== modified file 'examples/Sftp.java'
--- examples/Sftp.java 2009-10-19 15:08:16 +0000
+++ examples/Sftp.java 2012-05-04 10:23:17 +0000
@@ -1,4 +1,15 @@
1/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */1/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
2/**
3 * This program will demonstrate the sftp protocol support.
4 * $ CLASSPATH=.:../build javac Sftp.java
5 * $ CLASSPATH=.:../build java Sftp
6 * You will be asked username, host and passwd.
7 * If everything works fine, you will get a prompt 'sftp>'.
8 * 'help' command will show available command.
9 * In current implementation, the destination path for 'get' and 'put'
10 * commands must be a file, not a directory.
11 *
12 */
2import com.jcraft.jsch.*;13import com.jcraft.jsch.*;
3import java.awt.*;14import java.awt.*;
4import javax.swing.*;15import javax.swing.*;
516
=== modified file 'examples/Shell.java'
--- examples/Shell.java 2009-10-19 15:08:16 +0000
+++ examples/Shell.java 2012-05-04 10:23:17 +0000
@@ -1,4 +1,13 @@
1/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */1/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
2/**
3 * This program enables you to connect to sshd server and get the shell prompt.
4 * $ CLASSPATH=.:../build javac Shell.java
5 * $ CLASSPATH=.:../build java Shell
6 * You will be asked username, hostname and passwd.
7 * If everything works fine, you will get the shell prompt. Output will
8 * be ugly because of lacks of terminal-emulation, but you can issue commands.
9 *
10 */
2import com.jcraft.jsch.*;11import com.jcraft.jsch.*;
3import java.awt.*;12import java.awt.*;
4import javax.swing.*;13import javax.swing.*;
@@ -25,12 +34,36 @@
2534
26 Session session=jsch.getSession(user, host, 22);35 Session session=jsch.getSession(user, host, 22);
2736
28 //session.setPassword("your password");37 String passwd = JOptionPane.showInputDialog("Enter password");
2938 session.setPassword(passwd);
30 // username and password will be given via UserInfo interface.39
31 UserInfo ui=new MyUserInfo();40 UserInfo ui = new MyUserInfo(){
41 public void showMessage(String message){
42 JOptionPane.showMessageDialog(null, message);
43 }
44 public boolean promptYesNo(String message){
45 Object[] options={ "yes", "no" };
46 int foo=JOptionPane.showOptionDialog(null,
47 message,
48 "Warning",
49 JOptionPane.DEFAULT_OPTION,
50 JOptionPane.WARNING_MESSAGE,
51 null, options, options[0]);
52 return foo==0;
53 }
54
55 // If password is not given before the invocation of Session#connect(),
56 // implement also following methods,
57 // * UserInfo#getPassword(),
58 // * UserInfo#promptPassword(String message) and
59 // * UIKeyboardInteractive#promptKeyboardInteractive()
60
61 };
62
32 session.setUserInfo(ui);63 session.setUserInfo(ui);
3364
65 // It must not be recommended, but if you want to skip host-key check,
66 // invoke following,
34 // session.setConfig("StrictHostKeyChecking", "no");67 // session.setConfig("StrictHostKeyChecking", "no");
3568
36 //session.connect();69 //session.connect();
@@ -71,97 +104,20 @@
71 }104 }
72 }105 }
73106
74 public static class MyUserInfo implements UserInfo, UIKeyboardInteractive{107 public static abstract class MyUserInfo
75 public String getPassword(){ return passwd; }108 implements UserInfo, UIKeyboardInteractive{
76 public boolean promptYesNo(String str){109 public String getPassword(){ return null; }
77 Object[] options={ "yes", "no" };110 public boolean promptYesNo(String str){ return false; }
78 int foo=JOptionPane.showOptionDialog(null,
79 str,
80 "Warning",
81 JOptionPane.DEFAULT_OPTION,
82 JOptionPane.WARNING_MESSAGE,
83 null, options, options[0]);
84 return foo==0;
85 }
86
87 String passwd;
88 JTextField passwordField=(JTextField)new JPasswordField(20);
89
90 public String getPassphrase(){ return null; }111 public String getPassphrase(){ return null; }
91 public boolean promptPassphrase(String message){ return true; }112 public boolean promptPassphrase(String message){ return false; }
92 public boolean promptPassword(String message){113 public boolean promptPassword(String message){ return false; }
93 Object[] ob={passwordField}; 114 public void showMessage(String message){ }
94 int result=JOptionPane.showConfirmDialog(null, ob, message,
95 JOptionPane.OK_CANCEL_OPTION);
96 if(result==JOptionPane.OK_OPTION){
97 passwd=passwordField.getText();
98 return true;
99 }
100 else{
101 return false;
102 }
103 }
104 public void showMessage(String message){
105 JOptionPane.showMessageDialog(null, message);
106 }
107 final GridBagConstraints gbc =
108 new GridBagConstraints(0,0,1,1,1,1,
109 GridBagConstraints.NORTHWEST,
110 GridBagConstraints.NONE,
111 new Insets(0,0,0,0),0,0);
112 private Container panel;
113 public String[] promptKeyboardInteractive(String destination,115 public String[] promptKeyboardInteractive(String destination,
114 String name,116 String name,
115 String instruction,117 String instruction,
116 String[] prompt,118 String[] prompt,
117 boolean[] echo){119 boolean[] echo){
118 panel = new JPanel();120 return null;
119 panel.setLayout(new GridBagLayout());
120
121 gbc.weightx = 1.0;
122 gbc.gridwidth = GridBagConstraints.REMAINDER;
123 gbc.gridx = 0;
124 panel.add(new JLabel(instruction), gbc);
125 gbc.gridy++;
126
127 gbc.gridwidth = GridBagConstraints.RELATIVE;
128
129 JTextField[] texts=new JTextField[prompt.length];
130 for(int i=0; i<prompt.length; i++){
131 gbc.fill = GridBagConstraints.NONE;
132 gbc.gridx = 0;
133 gbc.weightx = 1;
134 panel.add(new JLabel(prompt[i]),gbc);
135
136 gbc.gridx = 1;
137 gbc.fill = GridBagConstraints.HORIZONTAL;
138 gbc.weighty = 1;
139 if(echo[i]){
140 texts[i]=new JTextField(20);
141 }
142 else{
143 texts[i]=new JPasswordField(20);
144 }
145 panel.add(texts[i], gbc);
146 gbc.gridy++;
147 }
148
149 if(JOptionPane.showConfirmDialog(null, panel,
150 destination+": "+name,
151 JOptionPane.OK_CANCEL_OPTION,
152 JOptionPane.QUESTION_MESSAGE)
153 ==JOptionPane.OK_OPTION){
154 String[] response=new String[prompt.length];
155 for(int i=0; i<prompt.length; i++){
156 response[i]=texts[i].getText();
157 }
158 return response;
159 }
160 else{
161 return null; // cancel
162 }
163 }121 }
164 }122 }
165}123}
166
167
168124
=== modified file 'examples/StreamForwarding.java'
--- examples/StreamForwarding.java 2008-02-06 23:23:19 +0000
+++ examples/StreamForwarding.java 2012-05-04 10:23:17 +0000
@@ -1,4 +1,16 @@
1/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */1/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
2/**
3 * This program will demonstrate the stream forwarding. The given Java
4 * I/O streams will be forwared to the given remote host and port on
5 * the remote side. It is simmilar to the -L option of ssh command,
6 * but you don't have to assign and open a local tcp port.
7 * $ CLASSPATH=.:../build javac StreamForwarding.java
8 * $ CLASSPATH=.:../build java StreamForwarding
9 * You will be asked username, hostname, host:hostport and passwd.
10 * If everything works fine, System.in and System.out streams will be
11 * forwared to remote port and you can send messages from command line.
12 *
13 */
2import com.jcraft.jsch.*;14import com.jcraft.jsch.*;
3import java.awt.*;15import java.awt.*;
4import javax.swing.*;16import javax.swing.*;
517
=== modified file 'examples/Subsystem.java'
--- examples/Subsystem.java 2008-02-06 23:23:19 +0000
+++ examples/Subsystem.java 2012-05-04 10:23:17 +0000
@@ -1,4 +1,8 @@
1/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */1/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
2/**
3 * This program will demonstrate how to use the Subsystem channel.
4 *
5 */
2import com.jcraft.jsch.*;6import com.jcraft.jsch.*;
3import java.awt.*;7import java.awt.*;
4import javax.swing.*;8import javax.swing.*;
59
=== added file 'examples/Sudo.java'
--- examples/Sudo.java 1970-01-01 00:00:00 +0000
+++ examples/Sudo.java 2012-05-04 10:23:17 +0000
@@ -0,0 +1,184 @@
1/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
2/**
3 * This program will demonstrate how to exec 'sudo' on the remote.
4 *
5 */
6import com.jcraft.jsch.*;
7import java.awt.*;
8import javax.swing.*;
9import java.io.*;
10
11public class Sudo{
12 public static void main(String[] arg){
13 try{
14 JSch jsch=new JSch();
15
16 String host=null;
17 if(arg.length>0){
18 host=arg[0];
19 }
20 else{
21 host=JOptionPane.showInputDialog("Enter username@hostname",
22 System.getProperty("user.name")+
23 "@localhost");
24 }
25 String user=host.substring(0, host.indexOf('@'));
26 host=host.substring(host.indexOf('@')+1);
27
28 Session session=jsch.getSession(user, host, 22);
29
30 UserInfo ui=new MyUserInfo();
31 session.setUserInfo(ui);
32 session.connect();
33
34 String command=JOptionPane.showInputDialog("Enter command, execed with sudo",
35 "printenv SUDO_USER");
36
37 String sudo_pass=null;
38 {
39 JTextField passwordField=(JTextField)new JPasswordField(8);
40 Object[] ob={passwordField};
41 int result=
42 JOptionPane.showConfirmDialog(null,
43 ob,
44 "Enter password for sudo",
45 JOptionPane.OK_CANCEL_OPTION);
46 if(result!=JOptionPane.OK_OPTION){
47 System.exit(-1);
48 }
49 sudo_pass=passwordField.getText();
50 }
51
52 Channel channel=session.openChannel("exec");
53
54 // man sudo
55 // -S The -S (stdin) option causes sudo to read the password from the
56 // standard input instead of the terminal device.
57 // -p The -p (prompt) option allows you to override the default
58 // password prompt and use a custom one.
59 ((ChannelExec)channel).setCommand("sudo -S -p '' "+command);
60
61
62 InputStream in=channel.getInputStream();
63 OutputStream out=channel.getOutputStream();
64 ((ChannelExec)channel).setErrStream(System.err);
65
66 channel.connect();
67
68 out.write((sudo_pass+"\n").getBytes());
69 out.flush();
70
71 byte[] tmp=new byte[1024];
72 while(true){
73 while(in.available()>0){
74 int i=in.read(tmp, 0, 1024);
75 if(i<0)break;
76 System.out.print(new String(tmp, 0, i));
77 }
78 if(channel.isClosed()){
79 System.out.println("exit-status: "+channel.getExitStatus());
80 break;
81 }
82 try{Thread.sleep(1000);}catch(Exception ee){}
83 }
84 channel.disconnect();
85 session.disconnect();
86 }
87 catch(Exception e){
88 System.out.println(e);
89 }
90 }
91
92 public static class MyUserInfo implements UserInfo, UIKeyboardInteractive{
93 public String getPassword(){ return passwd; }
94 public boolean promptYesNo(String str){
95 Object[] options={ "yes", "no" };
96 int foo=JOptionPane.showOptionDialog(null,
97 str,
98 "Warning",
99 JOptionPane.DEFAULT_OPTION,
100 JOptionPane.WARNING_MESSAGE,
101 null, options, options[0]);
102 return foo==0;
103 }
104
105 String passwd;
106 JTextField passwordField=(JTextField)new JPasswordField(20);
107
108 public String getPassphrase(){ return null; }
109 public boolean promptPassphrase(String message){ return true; }
110 public boolean promptPassword(String message){
111 Object[] ob={passwordField};
112 int result=
113 JOptionPane.showConfirmDialog(null, ob, message,
114 JOptionPane.OK_CANCEL_OPTION);
115 if(result==JOptionPane.OK_OPTION){
116 passwd=passwordField.getText();
117 return true;
118 }
119 else{
120 return false;
121 }
122 }
123 public void showMessage(String message){
124 JOptionPane.showMessageDialog(null, message);
125 }
126 final GridBagConstraints gbc =
127 new GridBagConstraints(0,0,1,1,1,1,
128 GridBagConstraints.NORTHWEST,
129 GridBagConstraints.NONE,
130 new Insets(0,0,0,0),0,0);
131 private Container panel;
132 public String[] promptKeyboardInteractive(String destination,
133 String name,
134 String instruction,
135 String[] prompt,
136 boolean[] echo){
137 panel = new JPanel();
138 panel.setLayout(new GridBagLayout());
139
140 gbc.weightx = 1.0;
141 gbc.gridwidth = GridBagConstraints.REMAINDER;
142 gbc.gridx = 0;
143 panel.add(new JLabel(instruction), gbc);
144 gbc.gridy++;
145
146 gbc.gridwidth = GridBagConstraints.RELATIVE;
147
148 JTextField[] texts=new JTextField[prompt.length];
149 for(int i=0; i<prompt.length; i++){
150 gbc.fill = GridBagConstraints.NONE;
151 gbc.gridx = 0;
152 gbc.weightx = 1;
153 panel.add(new JLabel(prompt[i]),gbc);
154
155 gbc.gridx = 1;
156 gbc.fill = GridBagConstraints.HORIZONTAL;
157 gbc.weighty = 1;
158 if(echo[i]){
159 texts[i]=new JTextField(20);
160 }
161 else{
162 texts[i]=new JPasswordField(20);
163 }
164 panel.add(texts[i], gbc);
165 gbc.gridy++;
166 }
167
168 if(JOptionPane.showConfirmDialog(null, panel,
169 destination+": "+name,
170 JOptionPane.OK_CANCEL_OPTION,
171 JOptionPane.QUESTION_MESSAGE)
172 ==JOptionPane.OK_OPTION){
173 String[] response=new String[prompt.length];
174 for(int i=0; i<prompt.length; i++){
175 response[i]=texts[i].getText();
176 }
177 return response;
178 }
179 else{
180 return null; // cancel
181 }
182 }
183 }
184}
0185
=== modified file 'examples/UserAuthKI.java'
--- examples/UserAuthKI.java 2008-02-06 23:23:19 +0000
+++ examples/UserAuthKI.java 2012-05-04 10:23:17 +0000
@@ -1,4 +1,12 @@
1/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */1/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
2/**
3 * This program will demonstrate the keyboard-interactive authentication.
4 * $ CLASSPATH=.:../build javac UserAuthKI.java
5 * $ CLASSPATH=.:../build java UserAuthKI
6 * If the remote sshd supports keyboard-interactive authentication,
7 * you will be prompted.
8 *
9 */
2import com.jcraft.jsch.*;10import com.jcraft.jsch.*;
3import java.awt.*;11import java.awt.*;
4import javax.swing.*;12import javax.swing.*;
513
=== modified file 'examples/UserAuthPubKey.java'
--- examples/UserAuthPubKey.java 2008-02-06 23:23:19 +0000
+++ examples/UserAuthPubKey.java 2012-05-04 10:23:17 +0000
@@ -1,4 +1,12 @@
1/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */1/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
2/**
3 * This program will demonstrate the user authentification by public key.
4 * $ CLASSPATH=.:../build javac UserAuthPubKey.java
5 * $ CLASSPATH=.:../build java UserAuthPubKey
6 * You will be asked username, hostname, privatekey(id_dsa) and passphrase.
7 * If everything works fine, you will get the shell prompt
8 *
9 */
2import com.jcraft.jsch.*;10import com.jcraft.jsch.*;
3import java.awt.*;11import java.awt.*;
4import javax.swing.*;12import javax.swing.*;
513
=== modified file 'examples/ViaHTTP.java'
--- examples/ViaHTTP.java 2008-02-06 23:23:19 +0000
+++ examples/ViaHTTP.java 2012-05-04 10:23:17 +0000
@@ -1,4 +1,12 @@
1/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */1/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
2/**
3 * This program will demonstrate the ssh session via HTTP proxy.
4 * $ CLASSPATH=.:../build javac ViaHTTP.java
5 * $ CLASSPATH=.:../build java ViaHTTP
6 * You will be asked username, hostname, proxy-server and passwd.
7 * If everything works fine, you will get the shell prompt.
8 *
9 */
2import com.jcraft.jsch.*;10import com.jcraft.jsch.*;
3import java.awt.*;11import java.awt.*;
4import javax.swing.*;12import javax.swing.*;
513
=== modified file 'examples/ViaSOCKS5.java'
--- examples/ViaSOCKS5.java 2008-02-06 23:23:19 +0000
+++ examples/ViaSOCKS5.java 2012-05-04 10:23:17 +0000
@@ -1,4 +1,12 @@
1/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */1/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
2/**
3 * This program will demonstrate the ssh session via SOCKS proxy.
4 * $ CLASSPATH=.:../build javac ViaSOCKS.java
5 * $ CLASSPATH=.:../build java ViaSOCKS
6 * You will be asked username, hostname, proxy-server and passwd.
7 * If everything works fine, you will get the shell prompt.
8 *
9 */
2import com.jcraft.jsch.*;10import com.jcraft.jsch.*;
3import java.awt.*;11import java.awt.*;
4import javax.swing.*;12import javax.swing.*;
513
=== modified file 'examples/X11Forwarding.java'
--- examples/X11Forwarding.java 2008-02-06 23:23:19 +0000
+++ examples/X11Forwarding.java 2012-05-04 10:23:17 +0000
@@ -1,4 +1,14 @@
1/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */1/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
2/**
3 * This program will demonstrate X11 forwarding.
4 * $ CLASSPATH=.:../build javac X11Forwarding.java
5 * $ CLASSPATH=.:../build java X11Forwarding
6 * You will be asked username, hostname, displayname and passwd.
7 * If your X server does not run at 127.0.0.1, please enter correct
8 * displayname. If everything works fine, you will get the shell prompt.
9 * Try X applications; for example, xlogo.
10 *
11 */
2import com.jcraft.jsch.*;12import com.jcraft.jsch.*;
3import java.awt.*;13import java.awt.*;
4import javax.swing.*;14import javax.swing.*;
515
=== added directory 'lib'
=== added directory 'src/main'
=== added directory 'src/main/java'
=== renamed directory 'src/com' => 'src/main/java/com'
=== modified file 'src/main/java/com/jcraft/jsch/Buffer.java'
--- src/com/jcraft/jsch/Buffer.java 2010-06-27 23:17:34 +0000
+++ src/main/java/com/jcraft/jsch/Buffer.java 2012-05-04 10:23:17 +0000
@@ -1,6 +1,6 @@
1/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */1/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
2/*2/*
3Copyright (c) 2002-2009 ymnk, JCraft,Inc. All rights reserved.3Copyright (c) 2002-2012 ymnk, JCraft,Inc. All rights reserved.
44
5Redistribution and use in source and binary forms, with or without5Redistribution and use in source and binary forms, with or without
6modification, are permitted provided that the following conditions are met:6modification, are permitted provided that the following conditions are met:
@@ -123,6 +123,16 @@
123 foo = ((foo<<16)&0xffff0000) | (getShort()&0xffff);123 foo = ((foo<<16)&0xffff0000) | (getShort()&0xffff);
124 return foo;124 return foo;
125 }125 }
126 public long getUInt(){
127 long foo = 0L;
128 long bar = 0L;
129 foo = getByte();
130 foo = ((foo<<8)&0xff00)|(getByte()&0xff);
131 bar = getByte();
132 bar = ((bar<<8)&0xff00)|(getByte()&0xff);
133 foo = ((foo<<16)&0xffff0000) | (bar&0xffff);
134 return foo;
135 }
126 int getShort() {136 int getShort() {
127 int foo = getByte();137 int foo = getByte();
128 foo = ((foo<<8)&0xff00)|(getByte()&0xff);138 foo = ((foo<<8)&0xff00)|(getByte()&0xff);
@@ -144,7 +154,12 @@
144 return foo;154 return foo;
145 }155 }
146 public byte[] getMPInt() {156 public byte[] getMPInt() {
147 int i=getInt();157 int i=getInt(); // uint32
158 if(i<0 || // bigger than 0x7fffffff
159 i>8*1024){
160 // TODO: an exception should be thrown.
161 i = 8*1024; // the session will be broken, but working around OOME.
162 }
148 byte[] foo=new byte[i];163 byte[] foo=new byte[i];
149 getByte(foo, 0, i);164 getByte(foo, 0, i);
150 return foo;165 return foo;
@@ -163,7 +178,12 @@
163 return foo;178 return foo;
164 }179 }
165 public byte[] getString() {180 public byte[] getString() {
166 int i=getInt();181 int i = getInt(); // uint32
182 if(i<0 || // bigger than 0x7fffffff
183 i>256*1024){
184 // TODO: an exception should be thrown.
185 i = 256*1024; // the session will be broken, but working around OOME.
186 }
167 byte[] foo=new byte[i];187 byte[] foo=new byte[i];
168 getByte(foo, 0, i);188 getByte(foo, 0, i);
169 return foo;189 return foo;
@@ -192,6 +212,14 @@
192 return buffer[5];212 return buffer[5];
193 }213 }
194214
215 void checkFreeSize(int n){
216 if(buffer.length<index+n){
217 byte[] tmp = new byte[buffer.length*2];
218 System.arraycopy(buffer, 0, tmp, 0, index);
219 buffer = tmp;
220 }
221 }
222
195/*223/*
196 static String[] chars={224 static String[] chars={
197 "0","1","2","3","4","5","6","7","8","9", "a","b","c","d","e","f"225 "0","1","2","3","4","5","6","7","8","9", "a","b","c","d","e","f"
198226
=== modified file 'src/main/java/com/jcraft/jsch/Channel.java'
--- src/com/jcraft/jsch/Channel.java 2010-06-27 23:17:34 +0000
+++ src/main/java/com/jcraft/jsch/Channel.java 2012-05-04 10:23:17 +0000
@@ -1,6 +1,6 @@
1/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */1/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
2/*2/*
3Copyright (c) 2002-2009 ymnk, JCraft,Inc. All rights reserved.3Copyright (c) 2002-2012 ymnk, JCraft,Inc. All rights reserved.
44
5Redistribution and use in source and binary forms, with or without5Redistribution and use in source and binary forms, with or without
6modification, are permitted provided that the following conditions are met:6modification, are permitted provided that the following conditions are met:
@@ -95,30 +95,29 @@
95 }95 }
9696
97 int id;97 int id;
98 int recipient=-1;98 volatile int recipient=-1;
99 byte[] type="foo".getBytes();99 protected byte[] type=Util.str2byte("foo");
100 int lwsize_max=0x100000;100 volatile int lwsize_max=0x100000;
101//int lwsize_max=0x20000; // 32*1024*4101 volatile int lwsize=lwsize_max; // local initial window size
102 int lwsize=lwsize_max; // local initial window size102 volatile int lmpsize=0x4000; // local maximum packet size
103 int lmpsize=0x4000; // local maximum packet size
104//int lmpsize=0x8000; // local maximum packet size
105103
106 int rwsize=0; // remote initial window size104 volatile long rwsize=0; // remote initial window size
107 int rmpsize=0; // remote maximum packet size105 volatile int rmpsize=0; // remote maximum packet size
108106
109 IO io=null; 107 IO io=null;
110 Thread thread=null;108 Thread thread=null;
111109
112 boolean eof_local=false;110 volatile boolean eof_local=false;
113 boolean eof_remote=false;111 volatile boolean eof_remote=false;
114112
115 boolean close=false;113 volatile boolean close=false;
116 boolean connected=false;114 volatile boolean connected=false;
117115 volatile boolean open_confirmation=false;
118 int exitstatus=-1;116
119117 volatile int exitstatus=-1;
120 int reply=0; 118
121 int connectTimeout=0;119 volatile int reply=0;
120 volatile int connectTimeout=0;
122121
123 private Session session;122 private Session session;
124123
@@ -130,8 +129,10 @@
130 pool.addElement(this);129 pool.addElement(this);
131 }130 }
132 }131 }
133 void setRecipient(int foo){132 synchronized void setRecipient(int foo){
134 this.recipient=foo;133 this.recipient=foo;
134 if(notifyme>0)
135 notifyAll();
135 }136 }
136 int getRecipient(){137 int getRecipient(){
137 return recipient;138 return recipient;
@@ -145,62 +146,14 @@
145 }146 }
146147
147 public void connect(int connectTimeout) throws JSchException{148 public void connect(int connectTimeout) throws JSchException{
148 Session _session=getSession();
149 if(!_session.isConnected()){
150 throw new JSchException("session is down");
151 }
152 this.connectTimeout=connectTimeout;149 this.connectTimeout=connectTimeout;
153 try{150 try{
154 Buffer buf=new Buffer(100);151 sendChannelOpen();
155 Packet packet=new Packet(buf);
156 // send
157 // byte SSH_MSG_CHANNEL_OPEN(90)
158 // string channel type //
159 // uint32 sender channel // 0
160 // uint32 initial window size // 0x100000(65536)
161 // uint32 maxmum packet size // 0x4000(16384)
162 packet.reset();
163 buf.putByte((byte)90);
164 buf.putString(this.type);
165 buf.putInt(this.id);
166 buf.putInt(this.lwsize);
167 buf.putInt(this.lmpsize);
168 _session.write(packet);
169 int retry=1000;
170 long start=System.currentTimeMillis();
171 long timeout=connectTimeout;
172 while(this.getRecipient()==-1 &&
173 _session.isConnected() &&
174 retry>0){
175 if(timeout>0L){
176 if((System.currentTimeMillis()-start)>timeout){
177 retry=0;
178 continue;
179 }
180 }
181 try{Thread.sleep(50);}catch(Exception ee){}
182 retry--;
183 }
184 if(!_session.isConnected()){
185 throw new JSchException("session is down");
186 }
187 if(retry==0){
188 throw new JSchException("channel is not opened.");
189 }
190
191 /*
192 * At the failure in opening the channel on the sshd,
193 * 'SSH_MSG_CHANNEL_OPEN_FAILURE' will be sent from sshd and it will
194 * be processed in Session#run().
195 */
196 if(this.isClosed()){
197 throw new JSchException("channel is not opened.");
198 }
199 connected=true;
200 start();152 start();
201 }153 }
202 catch(Exception e){154 catch(Exception e){
203 connected=false;155 connected=false;
156 disconnect();
204 if(e instanceof JSchException) 157 if(e instanceof JSchException)
205 throw (JSchException)e;158 throw (JSchException)e;
206 throw new JSchException(e.toString(), e);159 throw new JSchException(e.toString(), e);
@@ -216,7 +169,7 @@
216169
217 void getData(Buffer buf){170 void getData(Buffer buf){
218 setRecipient(buf.getInt());171 setRecipient(buf.getInt());
219 setRemoteWindowSize(buf.getInt());172 setRemoteWindowSize(buf.getUInt());
220 setRemotePacketSize(buf.getInt());173 setRemotePacketSize(buf.getInt());
221 }174 }
222175
@@ -274,7 +227,7 @@
274 packet=new Packet(buffer);227 packet=new Packet(buffer);
275228
276 byte[] _buf=buffer.buffer;229 byte[] _buf=buffer.buffer;
277 if(_buf.length-(14+0)-32-20<=0){230 if(_buf.length-(14+0)-Session.buffer_margin<=0){
278 buffer=null;231 buffer=null;
279 packet=null;232 packet=null;
280 throw new IOException("failed to initialize the channel.");233 throw new IOException("failed to initialize the channel.");
@@ -299,8 +252,8 @@
299 int _bufl=_buf.length;252 int _bufl=_buf.length;
300 while(l>0){253 while(l>0){
301 int _l=l;254 int _l=l;
302 if(l>_bufl-(14+dataLen)-32-20){255 if(l>_bufl-(14+dataLen)-Session.buffer_margin){
303 _l=_bufl-(14+dataLen)-32-20;256 _l=_bufl-(14+dataLen)-Session.buffer_margin;
304 }257 }
305258
306 if(_l<=0){259 if(_l<=0){
@@ -329,7 +282,10 @@
329 try{282 try{
330 int foo=dataLen;283 int foo=dataLen;
331 dataLen=0;284 dataLen=0;
332 getSession().write(packet, channel, foo);285 synchronized(channel){
286 if(!channel.close)
287 getSession().write(packet, channel, foo);
288 }
333 }289 }
334 catch(Exception e){290 catch(Exception e){
335 close();291 close();
@@ -371,11 +327,27 @@
371 super(out);327 super(out);
372 buffer=new byte[size];328 buffer=new byte[size];
373 }329 }
330
331 /*
332 * TODO: We should have our own Piped[I/O]Stream implementation.
333 * Before accepting data, JDK's PipedInputStream will check the existence of
334 * reader thread, and if it is not alive, the stream will be closed.
335 * That behavior may cause the problem if multiple threads make access to it.
336 */
337 public synchronized void updateReadSide() throws IOException {
338 if(available() != 0){ // not empty
339 return;
340 }
341 in = 0;
342 out = 0;
343 buffer[in++] = 0;
344 read();
345 }
374 }346 }
375 void setLocalWindowSizeMax(int foo){ this.lwsize_max=foo; }347 void setLocalWindowSizeMax(int foo){ this.lwsize_max=foo; }
376 void setLocalWindowSize(int foo){ this.lwsize=foo; }348 void setLocalWindowSize(int foo){ this.lwsize=foo; }
377 void setLocalPacketSize(int foo){ this.lmpsize=foo; }349 void setLocalPacketSize(int foo){ this.lmpsize=foo; }
378 synchronized void setRemoteWindowSize(int foo){ this.rwsize=foo; }350 synchronized void setRemoteWindowSize(long foo){ this.rwsize=foo; }
379 synchronized void addRemoteWindowSize(int foo){ 351 synchronized void addRemoteWindowSize(int foo){
380 this.rwsize+=foo; 352 this.rwsize+=foo;
381 if(notifyme>0)353 if(notifyme>0)
@@ -409,18 +381,19 @@
409 }381 }
410382
411 void eof(){383 void eof(){
412 //System.err.println("EOF!!!! "+this);
413 if(close)return;
414 if(eof_local)return;384 if(eof_local)return;
415 eof_local=true;385 eof_local=true;
416 //close=eof;386
417 try{387 try{
418 Buffer buf=new Buffer(100);388 Buffer buf=new Buffer(100);
419 Packet packet=new Packet(buf);389 Packet packet=new Packet(buf);
420 packet.reset();390 packet.reset();
421 buf.putByte((byte)Session.SSH_MSG_CHANNEL_EOF);391 buf.putByte((byte)Session.SSH_MSG_CHANNEL_EOF);
422 buf.putInt(getRecipient());392 buf.putInt(getRecipient());
423 getSession().write(packet);393 synchronized(this){
394 if(!close)
395 getSession().write(packet);
396 }
424 }397 }
425 catch(Exception e){398 catch(Exception e){
426 //System.err.println("Channel.eof");399 //System.err.println("Channel.eof");
@@ -468,10 +441,8 @@
468 */441 */
469442
470 void close(){443 void close(){
471 //System.err.println("close!!!!");
472 if(close)return;444 if(close)return;
473 close=true;445 close=true;
474
475 eof_local=eof_remote=true;446 eof_local=eof_remote=true;
476447
477 try{448 try{
@@ -480,7 +451,9 @@
480 packet.reset();451 packet.reset();
481 buf.putByte((byte)Session.SSH_MSG_CHANNEL_CLOSE);452 buf.putByte((byte)Session.SSH_MSG_CHANNEL_CLOSE);
482 buf.putInt(getRecipient());453 buf.putInt(getRecipient());
483 getSession().write(packet);454 synchronized(this){
455 getSession().write(packet);
456 }
484 }457 }
485 catch(Exception e){458 catch(Exception e){
486 //e.printStackTrace();459 //e.printStackTrace();
@@ -514,14 +487,15 @@
514 //System.err.println(this+":disconnect "+io+" "+connected);487 //System.err.println(this+":disconnect "+io+" "+connected);
515 //Thread.dumpStack();488 //Thread.dumpStack();
516489
517 synchronized(this){490 try{
518 if(!connected){491
519 return;492 synchronized(this){
493 if(!connected){
494 return;
495 }
496 connected=false;
520 }497 }
521 connected=false;
522 }
523498
524 try{
525 close();499 close();
526500
527 eof_remote=eof_local=true;501 eof_remote=eof_local=true;
@@ -628,11 +602,76 @@
628 buf.putByte((byte)SSH_MSG_CHANNEL_OPEN_FAILURE);602 buf.putByte((byte)SSH_MSG_CHANNEL_OPEN_FAILURE);
629 buf.putInt(getRecipient());603 buf.putInt(getRecipient());
630 buf.putInt(reasoncode);604 buf.putInt(reasoncode);
631 buf.putString("open failed".getBytes());605 buf.putString(Util.str2byte("open failed"));
632 buf.putString("".getBytes());606 buf.putString(Util.empty);
633 getSession().write(packet);607 getSession().write(packet);
634 }608 }
635 catch(Exception e){609 catch(Exception e){
636 }610 }
637 }611 }
612
613 protected Packet genChannelOpenPacket(){
614 Buffer buf=new Buffer(100);
615 Packet packet=new Packet(buf);
616 // byte SSH_MSG_CHANNEL_OPEN(90)
617 // string channel type //
618 // uint32 sender channel // 0
619 // uint32 initial window size // 0x100000(65536)
620 // uint32 maxmum packet size // 0x4000(16384)
621 packet.reset();
622 buf.putByte((byte)90);
623 buf.putString(this.type);
624 buf.putInt(this.id);
625 buf.putInt(this.lwsize);
626 buf.putInt(this.lmpsize);
627 return packet;
628 }
629
630 protected void sendChannelOpen() throws Exception {
631 Session _session=getSession();
632 if(!_session.isConnected()){
633 throw new JSchException("session is down");
634 }
635
636 Packet packet = genChannelOpenPacket();
637 _session.write(packet);
638
639 int retry=10;
640 long start=System.currentTimeMillis();
641 long timeout=connectTimeout;
642 if(timeout!=0L) retry = 1;
643 synchronized(this){
644 while(this.getRecipient()==-1 &&
645 _session.isConnected() &&
646 retry>0){
647 if(timeout>0L){
648 if((System.currentTimeMillis()-start)>timeout){
649 retry=0;
650 continue;
651 }
652 }
653 try{
654 long t = timeout==0L ? 5000L : timeout;
655 this.notifyme=1;
656 wait(t);
657 }
658 catch(java.lang.InterruptedException e){
659 }
660 finally{
661 this.notifyme=0;
662 }
663 retry--;
664 }
665 }
666 if(!_session.isConnected()){
667 throw new JSchException("session is down");
668 }
669 if(this.getRecipient()==-1){ // timeout
670 throw new JSchException("channel is not opened.");
671 }
672 if(this.open_confirmation==false){ // SSH_MSG_CHANNEL_OPEN_FAILURE
673 throw new JSchException("channel is not opened.");
674 }
675 connected=true;
676 }
638}677}
639678
=== modified file 'src/main/java/com/jcraft/jsch/ChannelAgentForwarding.java'
--- src/com/jcraft/jsch/ChannelAgentForwarding.java 2010-06-27 23:17:34 +0000
+++ src/main/java/com/jcraft/jsch/ChannelAgentForwarding.java 2012-05-04 10:23:17 +0000
@@ -1,6 +1,6 @@
1/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */1/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
2/*2/*
3Copyright (c) 2006-2009 ymnk, JCraft,Inc. All rights reserved.3Copyright (c) 2006-2012 ymnk, JCraft,Inc. All rights reserved.
44
5Redistribution and use in source and binary forms, with or without5Redistribution and use in source and binary forms, with or without
6modification, are permitted provided that the following conditions are met:6modification, are permitted provided that the following conditions are met:
@@ -37,14 +37,24 @@
37 static private final int LOCAL_WINDOW_SIZE_MAX=0x20000;37 static private final int LOCAL_WINDOW_SIZE_MAX=0x20000;
38 static private final int LOCAL_MAXIMUM_PACKET_SIZE=0x4000;38 static private final int LOCAL_MAXIMUM_PACKET_SIZE=0x4000;
3939
40 private final int SSH2_AGENTC_REQUEST_IDENTITIES=11;40 private final byte SSH_AGENTC_REQUEST_RSA_IDENTITIES = 1;
41 private final int SSH2_AGENT_IDENTITIES_ANSWER=12;41 private final byte SSH_AGENT_RSA_IDENTITIES_ANSWER = 2;
42 private final int SSH2_AGENTC_SIGN_REQUEST=13;42 private final byte SSH_AGENTC_RSA_CHALLENGE = 3;
43 private final int SSH2_AGENT_SIGN_RESPONSE=14;43 private final byte SSH_AGENT_RSA_RESPONSE = 4;
44 private final int SSH2_AGENTC_ADD_IDENTITY=17;44 private final byte SSH_AGENT_FAILURE = 5;
45 private final int SSH2_AGENTC_REMOVE_IDENTITY=18;45 private final byte SSH_AGENT_SUCCESS = 6;
46 private final int SSH2_AGENTC_REMOVE_ALL_IDENTITIES=19;46 private final byte SSH_AGENTC_ADD_RSA_IDENTITY = 7;
47 private final int SSH2_AGENT_FAILURE=30;47 private final byte SSH_AGENTC_REMOVE_RSA_IDENTITY = 8;
48 private final byte SSH_AGENTC_REMOVE_ALL_RSA_IDENTITIES = 9;
49
50 private final byte SSH2_AGENTC_REQUEST_IDENTITIES=11;
51 private final byte SSH2_AGENT_IDENTITIES_ANSWER=12;
52 private final byte SSH2_AGENTC_SIGN_REQUEST=13;
53 private final byte SSH2_AGENT_SIGN_RESPONSE=14;
54 private final byte SSH2_AGENTC_ADD_IDENTITY=17;
55 private final byte SSH2_AGENTC_REMOVE_IDENTITY=18;
56 private final byte SSH2_AGENTC_REMOVE_ALL_IDENTITIES=19;
57 private final byte SSH2_AGENT_FAILURE=30;
4858
49 boolean init=true;59 boolean init=true;
5060
@@ -60,7 +70,7 @@
60 setLocalWindowSize(LOCAL_WINDOW_SIZE_MAX);70 setLocalWindowSize(LOCAL_WINDOW_SIZE_MAX);
61 setLocalPacketSize(LOCAL_MAXIMUM_PACKET_SIZE);71 setLocalPacketSize(LOCAL_MAXIMUM_PACKET_SIZE);
6272
63 type="auth-agent@openssh.com".getBytes();73 type=Util.str2byte("auth-agent@openssh.com");
64 rbuf=new Buffer();74 rbuf=new Buffer();
65 rbuf.reset();75 rbuf.reset();
66 //wbuf=new Buffer(rmpsize);76 //wbuf=new Buffer(rmpsize);
@@ -111,12 +121,14 @@
111 throw new java.io.IOException(e.toString());121 throw new java.io.IOException(e.toString());
112 }122 }
113123
114 Vector identities=_session.jsch.identities;124 IdentityRepository irepo = _session.getIdentityRepository();
115 UserInfo userinfo=_session.getUserInfo();125 UserInfo userinfo=_session.getUserInfo();
116126
127 mbuf.reset();
128
117 if(typ==SSH2_AGENTC_REQUEST_IDENTITIES){ 129 if(typ==SSH2_AGENTC_REQUEST_IDENTITIES){
118 mbuf.reset();130 mbuf.putByte(SSH2_AGENT_IDENTITIES_ANSWER);
119 mbuf.putByte((byte)SSH2_AGENT_IDENTITIES_ANSWER);131 Vector identities = irepo.getIdentities();
120 synchronized(identities){132 synchronized(identities){
121 int count=0;133 int count=0;
122 for(int i=0; i<identities.size(); i++){134 for(int i=0; i<identities.size(); i++){
@@ -131,13 +143,13 @@
131 if(pubkeyblob==null)143 if(pubkeyblob==null)
132 continue;144 continue;
133 mbuf.putString(pubkeyblob);145 mbuf.putString(pubkeyblob);
134 mbuf.putString("".getBytes());146 mbuf.putString(Util.empty);
135 }147 }
136 }148 }
137 byte[] bar=new byte[mbuf.getLength()];149 }
138 mbuf.getByte(bar);150 else if(typ==SSH_AGENTC_REQUEST_RSA_IDENTITIES) {
139151 mbuf.putByte(SSH_AGENT_RSA_IDENTITIES_ANSWER);
140 send(bar);152 mbuf.putInt(0);
141 }153 }
142 else if(typ==SSH2_AGENTC_SIGN_REQUEST){154 else if(typ==SSH2_AGENTC_SIGN_REQUEST){
143 byte[] blob=rbuf.getString();155 byte[] blob=rbuf.getString();
@@ -148,7 +160,8 @@
148// datafellows = SSH_BUG_SIGBLOB;160// datafellows = SSH_BUG_SIGBLOB;
149// }161// }
150162
151 Identity identity=null;163 Vector identities = irepo.getIdentities();
164 Identity identity = null;
152 synchronized(identities){165 synchronized(identities){
153 for(int i=0; i<identities.size(); i++){166 for(int i=0; i<identities.size(); i++){
154 Identity _identity=(Identity)(identities.elementAt(i));167 Identity _identity=(Identity)(identities.elementAt(i));
@@ -195,20 +208,41 @@
195 signature=identity.getSignature(data);208 signature=identity.getSignature(data);
196 }209 }
197210
198 mbuf.reset();
199 if(signature==null){211 if(signature==null){
200 mbuf.putByte((byte)SSH2_AGENT_FAILURE);212 mbuf.putByte(SSH2_AGENT_FAILURE);
201 }213 }
202 else{214 else{
203 mbuf.putByte((byte)SSH2_AGENT_SIGN_RESPONSE);215 mbuf.putByte(SSH2_AGENT_SIGN_RESPONSE);
204 mbuf.putString(signature);216 mbuf.putString(signature);
205 }217 }
206218 }
207 byte[] bar=new byte[mbuf.getLength()];219 else if(typ==SSH2_AGENTC_REMOVE_IDENTITY){
208 mbuf.getByte(bar);220 byte[] blob=rbuf.getString();
209221 irepo.remove(blob);
210 send(bar);222 mbuf.putByte(SSH_AGENT_SUCCESS);
211 }223 }
224 else if(typ==SSH_AGENTC_REMOVE_ALL_RSA_IDENTITIES){
225 mbuf.putByte(SSH_AGENT_SUCCESS);
226 }
227 else if(typ==SSH2_AGENTC_REMOVE_ALL_IDENTITIES){
228 irepo.removeAll();
229 mbuf.putByte(SSH_AGENT_SUCCESS);
230 }
231 else if(typ==SSH2_AGENTC_ADD_IDENTITY){
232 int fooo = rbuf.getLength();
233 byte[] tmp = new byte[fooo];
234 rbuf.getByte(tmp);
235 boolean result = irepo.add(tmp);
236 mbuf.putByte(result ? SSH_AGENT_SUCCESS : SSH_AGENT_FAILURE);
237 }
238 else {
239 rbuf.skip(rbuf.getLength()-1);
240 mbuf.putByte(SSH_AGENT_FAILURE);
241 }
242
243 byte[] response = new byte[mbuf.getLength()];
244 mbuf.getByte(response);
245 send(response);
212 }246 }
213247
214 private void send(byte[] message){248 private void send(byte[] message){
@@ -224,4 +258,9 @@
224 catch(Exception e){258 catch(Exception e){
225 }259 }
226 }260 }
261
262 void eof_remote(){
263 super.eof_remote();
264 eof();
265 }
227}266}
228267
=== modified file 'src/main/java/com/jcraft/jsch/ChannelDirectTCPIP.java'
--- src/com/jcraft/jsch/ChannelDirectTCPIP.java 2010-06-27 23:17:34 +0000
+++ src/main/java/com/jcraft/jsch/ChannelDirectTCPIP.java 2012-05-04 10:23:17 +0000
@@ -1,6 +1,6 @@
1/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */1/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
2/*2/*
3Copyright (c) 2002-2009 ymnk, JCraft,Inc. All rights reserved.3Copyright (c) 2002-2012 ymnk, JCraft,Inc. All rights reserved.
44
5Redistribution and use in source and binary forms, with or without5Redistribution and use in source and binary forms, with or without
6modification, are permitted provided that the following conditions are met:6modification, are permitted provided that the following conditions are met:
@@ -35,7 +35,7 @@
3535
36 static private final int LOCAL_WINDOW_SIZE_MAX=0x20000;36 static private final int LOCAL_WINDOW_SIZE_MAX=0x20000;
37 static private final int LOCAL_MAXIMUM_PACKET_SIZE=0x4000;37 static private final int LOCAL_MAXIMUM_PACKET_SIZE=0x4000;
3838 static private final byte[] _type = Util.str2byte("direct-tcpip");
39 String host;39 String host;
40 int port;40 int port;
4141
@@ -44,18 +44,14 @@
4444
45 ChannelDirectTCPIP(){45 ChannelDirectTCPIP(){
46 super();46 super();
47 type = _type;
47 setLocalWindowSizeMax(LOCAL_WINDOW_SIZE_MAX);48 setLocalWindowSizeMax(LOCAL_WINDOW_SIZE_MAX);
48 setLocalWindowSize(LOCAL_WINDOW_SIZE_MAX);49 setLocalWindowSize(LOCAL_WINDOW_SIZE_MAX);
49 setLocalPacketSize(LOCAL_MAXIMUM_PACKET_SIZE);50 setLocalPacketSize(LOCAL_MAXIMUM_PACKET_SIZE);
50 }51 }
5152
52 void init (){53 void init (){
53 try{ 54 io=new IO();
54 io=new IO();
55 }
56 catch(Exception e){
57 System.err.println(e);
58 }
59 }55 }
6056
61 public void connect() throws JSchException{57 public void connect() throws JSchException{
@@ -64,54 +60,6 @@
64 if(!_session.isConnected()){60 if(!_session.isConnected()){
65 throw new JSchException("session is down");61 throw new JSchException("session is down");
66 }62 }
67 Buffer buf=new Buffer(150);
68 Packet packet=new Packet(buf);
69 // send
70 // byte SSH_MSG_CHANNEL_OPEN(90)
71 // string channel type //
72 // uint32 sender channel // 0
73 // uint32 initial window size // 0x100000(65536)
74 // uint32 maxmum packet size // 0x4000(16384)
75
76 packet.reset();
77 buf.putByte((byte)90);
78 buf.putString("direct-tcpip".getBytes());
79 buf.putInt(id);
80 buf.putInt(lwsize);
81 buf.putInt(lmpsize);
82 buf.putString(host.getBytes());
83 buf.putInt(port);
84 buf.putString(originator_IP_address.getBytes());
85 buf.putInt(originator_port);
86 _session.write(packet);
87
88 int retry=1000;
89 try{
90 while(this.getRecipient()==-1 &&
91 _session.isConnected() &&
92 retry>0 &&
93 !eof_remote){
94 //Thread.sleep(500);
95 Thread.sleep(50);
96 retry--;
97 }
98 }
99 catch(Exception ee){
100 }
101 if(!_session.isConnected()){
102 throw new JSchException("session is down");
103 }
104 if(retry==0 || this.eof_remote){
105 throw new JSchException("channel is not opened.");
106 }
107 /*
108 if(this.eof_remote){ // failed to open
109 disconnect();
110 return;
111 }
112 */
113
114 connected=true;
11563
116 if(io.in!=null){64 if(io.in!=null){
117 thread=new Thread(this);65 thread=new Thread(this);
@@ -121,6 +69,9 @@
121 }69 }
122 thread.start();70 thread.start();
123 }71 }
72 else {
73 sendChannelOpen();
74 }
124 }75 }
125 catch(Exception e){76 catch(Exception e){
126 io.close();77 io.close();
@@ -134,12 +85,14 @@
13485
135 public void run(){86 public void run(){
13687
137 Buffer buf=new Buffer(rmpsize);
138 Packet packet=new Packet(buf);
139 int i=0;
140
141 try{88 try{
89 sendChannelOpen();
90
91 Buffer buf=new Buffer(rmpsize);
92 Packet packet=new Packet(buf);
142 Session _session=getSession();93 Session _session=getSession();
94 int i=0;
95
143 while(isConnected() &&96 while(isConnected() &&
144 thread!=null && 97 thread!=null &&
145 io!=null && 98 io!=null &&
@@ -147,26 +100,27 @@
147 i=io.in.read(buf.buffer, 100 i=io.in.read(buf.buffer,
148 14, 101 14,
149 buf.buffer.length-14102 buf.buffer.length-14
150 -32 -20 // padding and mac103 -Session.buffer_margin
151 );104 );
152
153 if(i<=0){105 if(i<=0){
154 eof();106 eof();
155 break;107 break;
156 }108 }
157 if(close)break;
158 packet.reset();109 packet.reset();
159 buf.putByte((byte)Session.SSH_MSG_CHANNEL_DATA);110 buf.putByte((byte)Session.SSH_MSG_CHANNEL_DATA);
160 buf.putInt(recipient);111 buf.putInt(recipient);
161 buf.putInt(i);112 buf.putInt(i);
162 buf.skip(i);113 buf.skip(i);
163 _session.write(packet, this, i);114 synchronized(this){
115 if(close)
116 break;
117 _session.write(packet, this, i);
118 }
164 }119 }
165 }120 }
166 catch(Exception e){121 catch(Exception e){
167 }122 }
168 disconnect();123 disconnect();
169 //System.err.println("connect end");
170 }124 }
171125
172 public void setInputStream(InputStream in){126 public void setInputStream(InputStream in){
@@ -180,4 +134,25 @@
180 public void setPort(int port){this.port=port;}134 public void setPort(int port){this.port=port;}
181 public void setOrgIPAddress(String foo){this.originator_IP_address=foo;}135 public void setOrgIPAddress(String foo){this.originator_IP_address=foo;}
182 public void setOrgPort(int foo){this.originator_port=foo;}136 public void setOrgPort(int foo){this.originator_port=foo;}
137
138 protected Packet genChannelOpenPacket(){
139 Buffer buf = new Buffer(150);
140 Packet packet = new Packet(buf);
141 // byte SSH_MSG_CHANNEL_OPEN(90)
142 // string channel type //
143 // uint32 sender channel // 0
144 // uint32 initial window size // 0x100000(65536)
145 // uint32 maxmum packet size // 0x4000(16384)
146 packet.reset();
147 buf.putByte((byte)90);
148 buf.putString(this.type);
149 buf.putInt(id);
150 buf.putInt(lwsize);
151 buf.putInt(lmpsize);
152 buf.putString(Util.str2byte(host));
153 buf.putInt(port);
154 buf.putString(Util.str2byte(originator_IP_address));
155 buf.putInt(originator_port);
156 return packet;
157 }
183}158}
184159
=== modified file 'src/main/java/com/jcraft/jsch/ChannelExec.java'
--- src/com/jcraft/jsch/ChannelExec.java 2010-06-27 23:17:34 +0000
+++ src/main/java/com/jcraft/jsch/ChannelExec.java 2012-05-04 10:23:17 +0000
@@ -1,6 +1,6 @@
1/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */1/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
2/*2/*
3Copyright (c) 2002-2009 ymnk, JCraft,Inc. All rights reserved.3Copyright (c) 2002-2012 ymnk, JCraft,Inc. All rights reserved.
44
5Redistribution and use in source and binary forms, with or without5Redistribution and use in source and binary forms, with or without
6modification, are permitted provided that the following conditions are met:6modification, are permitted provided that the following conditions are met:
@@ -60,7 +60,7 @@
60 }60 }
6161
62 public void setCommand(String command){ 62 public void setCommand(String command){
63 this.command=command.getBytes();63 this.command=Util.str2byte(command);
64 }64 }
65 public void setCommand(byte[] command){ 65 public void setCommand(byte[] command){
66 this.command=command;66 this.command=command;
6767
=== modified file 'src/main/java/com/jcraft/jsch/ChannelForwardedTCPIP.java'
--- src/com/jcraft/jsch/ChannelForwardedTCPIP.java 2010-06-27 23:17:34 +0000
+++ src/main/java/com/jcraft/jsch/ChannelForwardedTCPIP.java 2012-05-04 10:23:17 +0000
@@ -1,6 +1,6 @@
1/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */1/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
2/*2/*
3Copyright (c) 2002-2009 ymnk, JCraft,Inc. All rights reserved.3Copyright (c) 2002-2012 ymnk, JCraft,Inc. All rights reserved.
44
5Redistribution and use in source and binary forms, with or without5Redistribution and use in source and binary forms, with or without
6modification, are permitted provided that the following conditions are met:6modification, are permitted provided that the following conditions are met:
@@ -97,25 +97,29 @@
97 Packet packet=new Packet(buf);97 Packet packet=new Packet(buf);
98 int i=0;98 int i=0;
99 try{99 try{
100 Session _session = getSession();
100 while(thread!=null && 101 while(thread!=null &&
101 io!=null && 102 io!=null &&
102 io.in!=null){103 io.in!=null){
103 i=io.in.read(buf.buffer, 104 i=io.in.read(buf.buffer,
104 14, 105 14,
105 buf.buffer.length-14106 buf.buffer.length-14
106 -32 -20 // padding and mac107 -Session.buffer_margin
107 );108 );
108 if(i<=0){109 if(i<=0){
109 eof();110 eof();
110 break;111 break;
111 }112 }
112 packet.reset();113 packet.reset();
113 if(close)break;
114 buf.putByte((byte)Session.SSH_MSG_CHANNEL_DATA);114 buf.putByte((byte)Session.SSH_MSG_CHANNEL_DATA);
115 buf.putInt(recipient);115 buf.putInt(recipient);
116 buf.putInt(i);116 buf.putInt(i);
117 buf.skip(i);117 buf.skip(i);
118 getSession().write(packet, this, i);118 synchronized(this){
119 if(close)
120 break;
121 _session.write(packet, this, i);
122 }
119 }123 }
120 }124 }
121 catch(Exception e){125 catch(Exception e){
@@ -128,7 +132,7 @@
128132
129 void getData(Buffer buf){133 void getData(Buffer buf){
130 setRecipient(buf.getInt());134 setRecipient(buf.getInt());
131 setRemoteWindowSize(buf.getInt());135 setRemoteWindowSize(buf.getUInt());
132 setRemotePacketSize(buf.getInt());136 setRemotePacketSize(buf.getInt());
133 byte[] addr=buf.getString();137 byte[] addr=buf.getString();
134 int port=buf.getInt();138 int port=buf.getInt();
@@ -136,9 +140,9 @@
136 int orgport=buf.getInt();140 int orgport=buf.getInt();
137141
138 /*142 /*
139 System.err.println("addr: "+new String(addr));143 System.err.println("addr: "+Util.byte2str(addr));
140 System.err.println("port: "+port);144 System.err.println("port: "+port);
141 System.err.println("orgaddr: "+new String(orgaddr));145 System.err.println("orgaddr: "+Util.byte2str(orgaddr));
142 System.err.println("orgport: "+orgport);146 System.err.println("orgport: "+orgport);
143 */147 */
144148
@@ -277,9 +281,9 @@
277 // uint32 port number to bind281 // uint32 port number to bind
278 packet.reset();282 packet.reset();
279 buf.putByte((byte) 80/*SSH_MSG_GLOBAL_REQUEST*/);283 buf.putByte((byte) 80/*SSH_MSG_GLOBAL_REQUEST*/);
280 buf.putString("cancel-tcpip-forward".getBytes());284 buf.putString(Util.str2byte("cancel-tcpip-forward"));
281 buf.putByte((byte)0);285 buf.putByte((byte)0);
282 buf.putString(address_to_bind.getBytes());286 buf.putString(Util.str2byte(address_to_bind));
283 buf.putInt(rport);287 buf.putInt(rport);
284 session.write(packet);288 session.write(packet);
285 }289 }
286290
=== modified file 'src/main/java/com/jcraft/jsch/ChannelSession.java'
--- src/com/jcraft/jsch/ChannelSession.java 2010-06-27 23:17:34 +0000
+++ src/main/java/com/jcraft/jsch/ChannelSession.java 2012-05-04 10:23:17 +0000
@@ -1,6 +1,6 @@
1/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */1/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
2/*2/*
3Copyright (c) 2002-2009 ymnk, JCraft,Inc. All rights reserved.3Copyright (c) 2002-2012 ymnk, JCraft,Inc. All rights reserved.
44
5Redistribution and use in source and binary forms, with or without5Redistribution and use in source and binary forms, with or without
6modification, are permitted provided that the following conditions are met:6modification, are permitted provided that the following conditions are met:
@@ -32,7 +32,7 @@
32import java.util.*;32import java.util.*;
3333
34class ChannelSession extends Channel{34class ChannelSession extends Channel{
35 private static byte[] _session="session".getBytes();35 private static byte[] _session=Util.str2byte("session");
3636
37 protected boolean agent_forwarding=false;37 protected boolean agent_forwarding=false;
38 protected boolean xforwading=false;38 protected boolean xforwading=false;
@@ -94,7 +94,7 @@
94 * @see RFC4254 6.4 Environment Variable Passing94 * @see RFC4254 6.4 Environment Variable Passing
95 */95 */
96 public void setEnv(String name, String value){96 public void setEnv(String name, String value){
97 setEnv(name.getBytes(), value.getBytes());97 setEnv(Util.str2byte(name), Util.str2byte(value));
98 }98 }
9999
100 /**100 /**
@@ -226,7 +226,7 @@
226226
227 private byte[] toByteArray(Object o){227 private byte[] toByteArray(Object o){
228 if(o instanceof String){228 if(o instanceof String){
229 return ((String)o).getBytes();229 return Util.str2byte((String)o);
230 }230 }
231 return (byte[])o;231 return (byte[])o;
232 }232 }
@@ -245,7 +245,7 @@
245 i=io.in.read(buf.buffer, 245 i=io.in.read(buf.buffer,
246 14, 246 14,
247 buf.buffer.length-14247 buf.buffer.length-14
248 -32 -20 // padding and mac248 -Session.buffer_margin
249 );249 );
250 if(i==0)continue;250 if(i==0)continue;
251 if(i==-1){251 if(i==-1){
@@ -266,8 +266,9 @@
266 //System.err.println("# ChannelExec.run");266 //System.err.println("# ChannelExec.run");
267 //e.printStackTrace();267 //e.printStackTrace();
268 }268 }
269 if(thread!=null){269 Thread _thread=thread;
270 synchronized(thread){ thread.notifyAll(); }270 if(_thread!=null){
271 synchronized(_thread){ _thread.notifyAll(); }
271 }272 }
272 thread=null;273 thread=null;
273 //System.err.println(this+":run <");274 //System.err.println(this+":run <");
274275
=== modified file 'src/main/java/com/jcraft/jsch/ChannelSftp.java'
--- src/com/jcraft/jsch/ChannelSftp.java 2010-06-27 23:17:34 +0000
+++ src/main/java/com/jcraft/jsch/ChannelSftp.java 2012-05-04 10:23:17 +0000
@@ -1,6 +1,6 @@
1/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */1/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
2/*2/*
3Copyright (c) 2002-2009 ymnk, JCraft,Inc. All rights reserved.3Copyright (c) 2002-2012 ymnk, JCraft,Inc. All rights reserved.
44
5Redistribution and use in source and binary forms, with or without5Redistribution and use in source and binary forms, with or without
6modification, are permitted provided that the following conditions are met:6modification, are permitted provided that the following conditions are met:
@@ -35,6 +35,9 @@
3535
36public class ChannelSftp extends ChannelSession{36public class ChannelSftp extends ChannelSession{
3737
38 static private final int LOCAL_MAXIMUM_PACKET_SIZE=32*1024;
39 static private final int LOCAL_WINDOW_SIZE_MAX=(64*LOCAL_MAXIMUM_PACKET_SIZE);
40
38 private static final byte SSH_FXP_INIT= 1;41 private static final byte SSH_FXP_INIT= 1;
39 private static final byte SSH_FXP_VERSION= 2;42 private static final byte SSH_FXP_VERSION= 2;
40 private static final byte SSH_FXP_OPEN= 3;43 private static final byte SSH_FXP_OPEN= 3;
@@ -131,8 +134,13 @@
131 private boolean interactive=false;134 private boolean interactive=false;
132 private int seq=1;135 private int seq=1;
133 private int[] ackid=new int[1];136 private int[] ackid=new int[1];
137
134 private Buffer buf;138 private Buffer buf;
135 private Packet packet=new Packet(buf);139 private Packet packet;
140
141 // The followings will be used in file uploading.
142 private Buffer obuf;
143 private Packet opacket;
136144
137 private int client_version=3;145 private int client_version=3;
138 private int server_version=3;146 private int server_version=3;
@@ -169,6 +177,40 @@
169 private String fEncoding=UTF8;177 private String fEncoding=UTF8;
170 private boolean fEncoding_is_utf8=true;178 private boolean fEncoding_is_utf8=true;
171179
180 private RequestQueue rq = new RequestQueue(16);
181
182 /**
183 * Specify how many requests may be sent at any one time.
184 * Increasing this value may slightly improve file transfer speed but will
185 * increase memory usage. The default is 16 requests.
186 *
187 * @param bulk_requests how many requests may be outstanding at any one time.
188 */
189 public void setBulkRequests(int bulk_requests) throws JSchException {
190 if(bulk_requests>0)
191 rq = new RequestQueue(bulk_requests);
192 else
193 throw new JSchException("setBulkRequests: "+
194 bulk_requests+" must be greater than 0.");
195 }
196
197 /**
198 * This method will return the value how many requests may be
199 * sent at any one time.
200 *
201 * @return how many requests may be sent at any one time.
202 */
203 public int getBulkRequests(){
204 return rq.size();
205 }
206
207 ChannelSftp(){
208 super();
209 setLocalWindowSizeMax(LOCAL_WINDOW_SIZE_MAX);
210 setLocalWindowSize(LOCAL_WINDOW_SIZE_MAX);
211 setLocalPacketSize(LOCAL_MAXIMUM_PACKET_SIZE);
212 }
213
172 void init(){214 void init(){
173 }215 }
174216
@@ -177,7 +219,7 @@
177219
178 PipedOutputStream pos=new PipedOutputStream();220 PipedOutputStream pos=new PipedOutputStream();
179 io.setOutputStream(pos);221 io.setOutputStream(pos);
180 PipedInputStream pis=new MyPipedInputStream(pos, 32*1024);222 PipedInputStream pis=new MyPipedInputStream(pos, rmpsize);
181 io.setInputStream(pis);223 io.setInputStream(pis);
182224
183 io_in=io.in;225 io_in=io.in;
@@ -189,15 +231,19 @@
189 Request request=new RequestSftp();231 Request request=new RequestSftp();
190 request.request(getSession(), this);232 request.request(getSession(), this);
191233
192/*234 /*
193 System.err.println("lmpsize: "+lmpsize);235 System.err.println("lmpsize: "+lmpsize);
194 System.err.println("lwsize: "+lwsize);236 System.err.println("lwsize: "+lwsize);
195 System.err.println("rmpsize: "+rmpsize);237 System.err.println("rmpsize: "+rmpsize);
196 System.err.println("rwsize: "+rwsize);238 System.err.println("rwsize: "+rwsize);
197*/239 */
198240
199 buf=new Buffer(rmpsize);241 buf=new Buffer(lmpsize);
200 packet=new Packet(buf);242 packet=new Packet(buf);
243
244 obuf=new Buffer(rmpsize);
245 opacket=new Packet(obuf);
246
201 int i=0;247 int i=0;
202 int length;248 int length;
203 int type;249 int type;
@@ -228,8 +274,8 @@
228 length-=(4+extension_name.length);274 length-=(4+extension_name.length);
229 extension_data=buf.getString();275 extension_data=buf.getString();
230 length-=(4+extension_data.length);276 length-=(4+extension_data.length);
231 extensions.put(new String(extension_name),277 extensions.put(Util.byte2str(extension_name),
232 new String(extension_data));278 Util.byte2str(extension_data));
233 }279 }
234 }280 }
235281
@@ -261,8 +307,9 @@
261307
262 public void cd(String path) throws SftpException{308 public void cd(String path) throws SftpException{
263 try{309 try{
310 ((MyPipedInputStream)io_in).updateReadSide();
311
264 path=remoteAbsolutePath(path);312 path=remoteAbsolutePath(path);
265
266 path=isUnique(path);313 path=isUnique(path);
267314
268 byte[] str=_realpath(path);315 byte[] str=_realpath(path);
@@ -299,11 +346,12 @@
299 }346 }
300 public void put(String src, String dst, 347 public void put(String src, String dst,
301 SftpProgressMonitor monitor, int mode) throws SftpException{348 SftpProgressMonitor monitor, int mode) throws SftpException{
302 src=localAbsolutePath(src);
303 dst=remoteAbsolutePath(dst);
304349
305 //System.err.println("src: "+src+", "+dst);
306 try{350 try{
351 ((MyPipedInputStream)io_in).updateReadSide();
352
353 src=localAbsolutePath(src);
354 dst=remoteAbsolutePath(dst);
307355
308 Vector v=glob_remote(dst);356 Vector v=glob_remote(dst);
309 int vsize=v.size();357 int vsize=v.size();
@@ -415,6 +463,8 @@
415 public void put(InputStream src, String dst, 463 public void put(InputStream src, String dst,
416 SftpProgressMonitor monitor, int mode) throws SftpException{464 SftpProgressMonitor monitor, int mode) throws SftpException{
417 try{465 try{
466 ((MyPipedInputStream)io_in).updateReadSide();
467
418 dst=remoteAbsolutePath(dst);468 dst=remoteAbsolutePath(dst);
419469
420 Vector v=glob_remote(dst);470 Vector v=glob_remote(dst);
@@ -436,6 +486,12 @@
436 throw new SftpException(SSH_FX_FAILURE, dst+" is a directory");486 throw new SftpException(SSH_FX_FAILURE, dst+" is a directory");
437 }487 }
438488
489 if(monitor!=null){
490 monitor.init(SftpProgressMonitor.PUT,
491 "-", dst,
492 SftpProgressMonitor.UNKNOWN_SIZE);
493 }
494
439 _put(src, dst, monitor, mode);495 _put(src, dst, monitor, mode);
440 }496 }
441 catch(Exception e){497 catch(Exception e){
@@ -447,8 +503,10 @@
447 }503 }
448504
449 public void _put(InputStream src, String dst, 505 public void _put(InputStream src, String dst,
450 SftpProgressMonitor monitor, int mode) throws SftpException{506 SftpProgressMonitor monitor, int mode) throws SftpException{
451 try{507 try{
508 ((MyPipedInputStream)io_in).updateReadSide();
509
452 byte[] dstb=Util.str2byte(dst, fEncoding);510 byte[] dstb=Util.str2byte(dst, fEncoding);
453 long skip=0;511 long skip=0;
454 if(mode==RESUME || mode==APPEND){512 if(mode==RESUME || mode==APPEND){
@@ -489,10 +547,9 @@
489547
490 boolean dontcopy=true;548 boolean dontcopy=true;
491549
492 if(!dontcopy){550 if(!dontcopy){ // This case will not work anymore.
493 data=new byte[buf.buffer.length551 data=new byte[obuf.buffer.length
494 -(5+13+21+handle.length552 -(5+13+21+handle.length+Session.buffer_margin
495 +32 +20 // padding and mac
496 )553 )
497 ];554 ];
498 }555 }
@@ -503,23 +560,26 @@
503 }560 }
504561
505 int startid=seq;562 int startid=seq;
506 int _ackid=seq;
507 int ackcount=0;563 int ackcount=0;
564 int _s=0;
565 int _datalen=0;
566
567 if(!dontcopy){ // This case will not work anymore.
568 _datalen=data.length;
569 }
570 else{
571 data=obuf.buffer;
572 _s=5+13+21+handle.length;
573 _datalen=obuf.buffer.length-_s-Session.buffer_margin;
574 }
575
576 int bulk_requests = rq.size();
577
508 while(true){578 while(true){
509 int nread=0;579 int nread=0;
510 int s=0;
511 int datalen=0;
512 int count=0;580 int count=0;
513581 int s=_s;
514 if(!dontcopy){582 int datalen=_datalen;
515 datalen=data.length-s;
516 }
517 else{
518 data=buf.buffer;
519 s=5+13+21+handle.length;
520 datalen=buf.buffer.length -s
521 -32 -20; // padding and mac
522 }
523583
524 do{584 do{
525 nread=src.read(data, s, datalen);585 nread=src.read(data, s, datalen);
@@ -532,20 +592,19 @@
532 while(datalen>0 && nread>0); 592 while(datalen>0 && nread>0);
533 if(count<=0)break;593 if(count<=0)break;
534594
535 int _i=count;595 int foo=count;
536 while(_i>0){596 while(foo>0){
537 _i-=sendWRITE(handle, offset, data, 0, _i);
538 if((seq-1)==startid ||597 if((seq-1)==startid ||
539 io_in.available()>=1024){598 ((seq-startid)-ackcount)>=bulk_requests){
540 while(io_in.available()>0){599 while(((seq-startid)-ackcount)>=bulk_requests){
600 if(this.rwsize>=foo) break;
541 if(checkStatus(ackid, header)){601 if(checkStatus(ackid, header)){
542 _ackid=ackid[0];602 int _ackid = ackid[0];
543 if(startid>_ackid || _ackid>seq-1){603 if(startid>_ackid || _ackid>seq-1){
544 if(_ackid==seq){604 if(_ackid==seq){
545 System.err.println("ack error: startid="+startid+" seq="+seq+" _ackid="+_ackid);605 System.err.println("ack error: startid="+startid+" seq="+seq+" _ackid="+_ackid);
546 } 606 }
547 else{607 else{
548 //throw new SftpException(SSH_FX_FAILURE, "ack error:");
549 throw new SftpException(SSH_FX_FAILURE, "ack error: startid="+startid+" seq="+seq+" _ackid="+_ackid);608 throw new SftpException(SSH_FX_FAILURE, "ack error: startid="+startid+" seq="+seq+" _ackid="+_ackid);
550 }609 }
551 }610 }
@@ -556,6 +615,7 @@
556 }615 }
557 }616 }
558 }617 }
618 foo-=sendWRITE(handle, offset, data, 0, foo);
559 }619 }
560 offset+=count;620 offset+=count;
561 if(monitor!=null && !monitor.count(count)){621 if(monitor!=null && !monitor.count(count)){
@@ -590,9 +650,10 @@
590 return put(dst, monitor, mode, 0);650 return put(dst, monitor, mode, 0);
591 }651 }
592 public OutputStream put(String dst, final SftpProgressMonitor monitor, final int mode, long offset) throws SftpException{652 public OutputStream put(String dst, final SftpProgressMonitor monitor, final int mode, long offset) throws SftpException{
593 dst=remoteAbsolutePath(dst);
594 try{653 try{
654 ((MyPipedInputStream)io_in).updateReadSide();
595655
656 dst=remoteAbsolutePath(dst);
596 dst=isUnique(dst);657 dst=isUnique(dst);
597658
598 if(isRemoteDir(dst)){659 if(isRemoteDir(dst)){
@@ -757,10 +818,14 @@
757 SftpProgressMonitor monitor, int mode) throws SftpException{818 SftpProgressMonitor monitor, int mode) throws SftpException{
758 // System.out.println("get: "+src+" "+dst);819 // System.out.println("get: "+src+" "+dst);
759820
760 src=remoteAbsolutePath(src);821 boolean _dstExist = false;
761 dst=localAbsolutePath(dst);822 String _dst=null;
762
763 try{823 try{
824 ((MyPipedInputStream)io_in).updateReadSide();
825
826 src=remoteAbsolutePath(src);
827 dst=localAbsolutePath(dst);
828
764 Vector v=glob_remote(src);829 Vector v=glob_remote(src);
765 int vsize=v.size();830 int vsize=v.size();
766 if(vsize==0){831 if(vsize==0){
@@ -789,7 +854,7 @@
789 "not supported to get directory "+_src);854 "not supported to get directory "+_src);
790 } 855 }
791856
792 String _dst=null;857 _dst=null;
793 if(isDstDir){858 if(isDstDir){
794 int i=_src.lastIndexOf('/');859 int i=_src.lastIndexOf('/');
795 if(i==-1) dstsb.append(_src);860 if(i==-1) dstsb.append(_src);
@@ -801,9 +866,10 @@
801 _dst=dst;866 _dst=dst;
802 }867 }
803868
869 File _dstFile=new File(_dst);
804 if(mode==RESUME){870 if(mode==RESUME){
805 long size_of_src=attr.getSize();871 long size_of_src=attr.getSize();
806 long size_of_dst=new File(_dst).length();872 long size_of_dst=_dstFile.length();
807 if(size_of_dst>size_of_src){873 if(size_of_dst>size_of_src){
808 throw new SftpException(SSH_FX_FAILURE, 874 throw new SftpException(SSH_FX_FAILURE,
809 "failed to resume for "+_dst);875 "failed to resume for "+_dst);
@@ -816,11 +882,12 @@
816 if(monitor!=null){882 if(monitor!=null){
817 monitor.init(SftpProgressMonitor.GET, _src, _dst, attr.getSize());883 monitor.init(SftpProgressMonitor.GET, _src, _dst, attr.getSize());
818 if(mode==RESUME){884 if(mode==RESUME){
819 monitor.count(new File(_dst).length());885 monitor.count(_dstFile.length());
820 }886 }
821 }887 }
822888
823 FileOutputStream fos=null;889 FileOutputStream fos=null;
890 _dstExist = _dstFile.exists();
824 try{891 try{
825 if(mode==OVERWRITE){892 if(mode==OVERWRITE){
826 fos=new FileOutputStream(_dst);893 fos=new FileOutputStream(_dst);
@@ -839,6 +906,12 @@
839 }906 }
840 }907 }
841 catch(Exception e){908 catch(Exception e){
909 if(!_dstExist && _dst!=null){
910 File _dstFile = new File(_dst);
911 if(_dstFile.exists() && _dstFile.length()==0){
912 _dstFile.delete();
913 }
914 }
842 if(e instanceof SftpException) throw (SftpException)e;915 if(e instanceof SftpException) throw (SftpException)e;
843 if(e instanceof Throwable)916 if(e instanceof Throwable)
844 throw new SftpException(SSH_FX_FAILURE, "", (Throwable)e);917 throw new SftpException(SSH_FX_FAILURE, "", (Throwable)e);
@@ -856,8 +929,9 @@
856 SftpProgressMonitor monitor, int mode, long skip) throws SftpException{929 SftpProgressMonitor monitor, int mode, long skip) throws SftpException{
857//System.err.println("get: "+src+", "+dst);930//System.err.println("get: "+src+", "+dst);
858 try{931 try{
932 ((MyPipedInputStream)io_in).updateReadSide();
933
859 src=remoteAbsolutePath(src);934 src=remoteAbsolutePath(src);
860
861 src=isUnique(src);935 src=isUnique(src);
862936
863 if(monitor!=null){937 if(monitor!=null){
@@ -908,18 +982,27 @@
908 offset+=skip;982 offset+=skip;
909 }983 }
910984
911 int request_len=0;985 int request_max=1;
986 rq.init();
987 long request_offset=offset;
988
989 int request_len = buf.buffer.length-13;
990 if(server_version==0){ request_len=1024; }
991
912 loop:992 loop:
913 while(true){993 while(true){
914994
915 request_len=buf.buffer.length-13;995 while(rq.count() < request_max){
916 if(server_version==0){ request_len=1024; }996 sendREAD(handle, request_offset, request_len, rq);
917 sendREAD(handle, offset, request_len);997 request_offset += request_len;
998 }
918999
919 header=header(buf, header);1000 header=header(buf, header);
920 length=header.length;1001 length=header.length;
921 type=header.type;1002 type=header.type;
9221003
1004 RequestQueue.Request rr = rq.get(header.rid);
1005
923 if(type==SSH_FXP_STATUS){1006 if(type==SSH_FXP_STATUS){
924 fill(buf, length);1007 fill(buf, length);
925 int i=buf.getInt(); 1008 int i=buf.getInt();
@@ -935,19 +1018,31 @@
9351018
936 buf.rewind();1019 buf.rewind();
937 fill(buf.buffer, 0, 4); length-=4;1020 fill(buf.buffer, 0, 4); length-=4;
938 int i=buf.getInt(); // length of data 1021 int length_of_data = buf.getInt(); // length of data
939 int foo=i;1022
9401023 /**
1024 Since sftp protocol version 6, "end-of-file" has been defined,
1025
1026 byte SSH_FXP_DATA
1027 uint32 request-id
1028 string data
1029 bool end-of-file [optional]
1030
1031 but some sftpd server will send such a field in the sftp protocol 3 ;-(
1032 */
1033 int optional_data = length - length_of_data;
1034
1035 int foo = length_of_data;
941 while(foo>0){1036 while(foo>0){
942 int bar=foo;1037 int bar=foo;
943 if(bar>buf.buffer.length){1038 if(bar>buf.buffer.length){
944 bar=buf.buffer.length;1039 bar=buf.buffer.length;
945 }1040 }
946 i=io_in.read(buf.buffer, 0, bar);1041 int data_len = io_in.read(buf.buffer, 0, bar);
947 if(i<0){1042 if(data_len<0){
948 break loop;1043 break loop;
949 }1044 }
950 int data_len=i;1045
951 dst.write(buf.buffer, 0, data_len);1046 dst.write(buf.buffer, 0, data_len);
9521047
953 offset+=data_len;1048 offset+=data_len;
@@ -955,12 +1050,9 @@
9551050
956 if(monitor!=null){1051 if(monitor!=null){
957 if(!monitor.count(data_len)){1052 if(!monitor.count(data_len)){
958 while(foo>0){1053 skip(foo);
959 i=io_in.read(buf.buffer, 1054 if(optional_data>0){
960 0, 1055 skip(optional_data);
961 (buf.buffer.length<foo?buf.buffer.length:foo));
962 if(i<=0) break;
963 foo-=i;
964 }1056 }
965 break loop;1057 break loop;
966 }1058 }
@@ -968,10 +1060,27 @@
9681060
969 }1061 }
970 //System.err.println("length: "+length); // length should be 01062 //System.err.println("length: "+length); // length should be 0
1063
1064 if(optional_data>0){
1065 skip(optional_data);
1066 }
1067
1068 if(length_of_data<rr.length){ //
1069 rq.cancel(header, buf);
1070 sendREAD(handle, rr.offset+length_of_data, (int)(rr.length-length_of_data), rq);
1071 request_offset=rr.offset+rr.length;
1072 }
1073
1074 if(request_max < rq.size()){
1075 request_max++;
1076 }
971 }1077 }
972 dst.flush();1078 dst.flush();
9731079
974 if(monitor!=null)monitor.end();1080 if(monitor!=null)monitor.end();
1081
1082 rq.cancel(header, buf);
1083
975 _sendCLOSE(handle, header);1084 _sendCLOSE(handle, header);
976 }1085 }
977 catch(Exception e){1086 catch(Exception e){
@@ -982,6 +1091,69 @@
982 }1091 }
983 }1092 }
9841093
1094
1095 private class RequestQueue {
1096 class Request {
1097 int id;
1098 long offset;
1099 long length;
1100 }
1101
1102 Request[] rrq=null;
1103 int head, count;
1104 RequestQueue(int size){
1105 rrq = new Request[size];
1106 for(int i=0; i<rrq.length; i++){
1107 rrq[i]=new Request();
1108 }
1109 init();
1110 }
1111
1112 void init(){
1113 head=count=0;
1114 }
1115
1116 void add(int id, long offset, int length){
1117 if(count == 0) head = 0;
1118 int tail = head + count;
1119 if(tail>=rrq.length) tail -= rrq.length;
1120 rrq[tail].id=id;
1121 rrq[tail].offset=offset;
1122 rrq[tail].length=length;
1123 count++;
1124 }
1125
1126 Request get(int id){
1127 count -= 1;
1128 int i=head;
1129 head++;
1130 if(head==rrq.length) head=0;
1131 if(rrq[i].id!=id){
1132 System.err.println("The request is not in order.");
1133 }
1134 rrq[i].id=0;
1135 return rrq[i];
1136 }
1137
1138 int count() {
1139 return count;
1140 }
1141
1142 int size() {
1143 return rrq.length;
1144 }
1145
1146 void cancel(Header header, Buffer buf) throws IOException {
1147 int _count = count;
1148 for(int i=0; i<_count; i++){
1149 header=header(buf, header);
1150 int length=header.length;
1151 get(header.rid);
1152 skip(length);
1153 }
1154 }
1155 }
1156
985 public InputStream get(String src) throws SftpException{1157 public InputStream get(String src) throws SftpException{
986 return get(src, null, 0L);1158 return get(src, null, 0L);
987 }1159 }
@@ -1002,8 +1174,11 @@
1002 return get(src, monitor, 0L);1174 return get(src, monitor, 0L);
1003 }1175 }
1004 public InputStream get(String src, final SftpProgressMonitor monitor, final long skip) throws SftpException{1176 public InputStream get(String src, final SftpProgressMonitor monitor, final long skip) throws SftpException{
1005 src=remoteAbsolutePath(src);1177
1006 try{1178 try{
1179 ((MyPipedInputStream)io_in).updateReadSide();
1180
1181 src=remoteAbsolutePath(src);
1007 src=isUnique(src);1182 src=isUnique(src);
10081183
1009 byte[] srcb=Util.str2byte(src, fEncoding);1184 byte[] srcb=Util.str2byte(src, fEncoding);
@@ -1032,6 +1207,8 @@
10321207
1033 final byte[] handle=buf.getString(); // handle1208 final byte[] handle=buf.getString(); // handle
10341209
1210 rq.init();
1211
1035 java.io.InputStream in=new java.io.InputStream(){1212 java.io.InputStream in=new java.io.InputStream(){
1036 long offset=skip;1213 long offset=skip;
1037 boolean closed=false;1214 boolean closed=false;
@@ -1039,6 +1216,8 @@
1039 byte[] _data=new byte[1];1216 byte[] _data=new byte[1];
1040 byte[] rest_byte=new byte[1024];1217 byte[] rest_byte=new byte[1024];
1041 Header header=new Header();1218 Header header=new Header();
1219 int request_max=1;
1220 long request_offset=offset;
10421221
1043 public int read() throws java.io.IOException{1222 public int read() throws java.io.IOException{
1044 if(closed)return -1;1223 if(closed)return -1;
@@ -1087,14 +1266,26 @@
1087 len=1024; 1266 len=1024;
1088 }1267 }
10891268
1090 try{sendREAD(handle, offset, len);}1269 if(rq.count()==0) {
1091 catch(Exception e){ throw new IOException("error"); }1270 int request_len = buf.buffer.length-13;
1271 if(server_version==0){ request_len=1024; }
1272
1273 while(rq.count() < request_max){
1274 try{
1275 sendREAD(handle, request_offset, request_len, rq);
1276 }
1277 catch(Exception e){ throw new IOException("error"); }
1278 request_offset += request_len;
1279 }
1280 }
10921281
1093 header=header(buf, header);1282 header=header(buf, header);
1094 rest_length=header.length;1283 rest_length=header.length;
1095 int type=header.type;1284 int type=header.type;
1096 int id=header.rid;1285 int id=header.rid;
10971286
1287 RequestQueue.Request rr = rq.get(header.rid);
1288
1098 if(type!=SSH_FXP_STATUS && type!=SSH_FXP_DATA){ 1289 if(type!=SSH_FXP_STATUS && type!=SSH_FXP_DATA){
1099 throw new IOException("error");1290 throw new IOException("error");
1100 }1291 }
@@ -1109,29 +1300,43 @@
1109 //throwStatusError(buf, i);1300 //throwStatusError(buf, i);
1110 throw new IOException("error");1301 throw new IOException("error");
1111 }1302 }
1303
1112 buf.rewind();1304 buf.rewind();
1113 fill(buf.buffer, 0, 4);1305 fill(buf.buffer, 0, 4);
1114 int i=buf.getInt(); rest_length-=4;1306 int length_of_data = buf.getInt(); rest_length-=4;
11151307
1116 offset+=rest_length;1308 /**
1117 int foo=i;1309 Since sftp protocol version 6, "end-of-file" has been defined,
1310
1311 byte SSH_FXP_DATA
1312 uint32 request-id
1313 string data
1314 bool end-of-file [optional]
1315
1316 but some sftpd server will send such a field in the sftp protocol 3 ;-(
1317 */
1318 int optional_data = rest_length - length_of_data;
1319
1320 offset += length_of_data;
1321 int foo = length_of_data;
1118 if(foo>0){1322 if(foo>0){
1119 int bar=rest_length;1323 int bar=foo;
1120 if(bar>len){1324 if(bar>len){
1121 bar=len;1325 bar=len;
1122 }1326 }
1123 i=io_in.read(d, s, bar);1327 int i=io_in.read(d, s, bar);
1124 if(i<0){1328 if(i<0){
1125 return -1;1329 return -1;
1126 }1330 }
1127 rest_length-=i;1331 foo-=i;
1332 rest_length=foo;
11281333
1129 if(rest_length>0){1334 if(foo>0){
1130 if(rest_byte.length<rest_length){1335 if(rest_byte.length<foo){
1131 rest_byte=new byte[rest_length];1336 rest_byte=new byte[foo];
1132 }1337 }
1133 int _s=0;1338 int _s=0;
1134 int _len=rest_length;1339 int _len=foo;
1135 int j;1340 int j;
1136 while(_len>0){1341 while(_len>0){
1137 j=io_in.read(rest_byte, _s, _len);1342 j=io_in.read(rest_byte, _s, _len);
@@ -1141,6 +1346,25 @@
1141 }1346 }
1142 }1347 }
11431348
1349 if(optional_data>0){
1350 io_in.skip(optional_data);
1351 }
1352
1353 if(length_of_data<rr.length){ //
1354 rq.cancel(header, buf);
1355 try {
1356 sendREAD(handle,
1357 rr.offset+length_of_data,
1358 (int)(rr.length-length_of_data), rq);
1359 }
1360 catch(Exception e){ throw new IOException("error"); }
1361 request_offset=rr.offset+rr.length;
1362 }
1363
1364 if(request_max < rq.size()){
1365 request_max++;
1366 }
1367
1144 if(monitor!=null){1368 if(monitor!=null){
1145 if(!monitor.count(i)){1369 if(!monitor.count(i)){
1146 close();1370 close();
@@ -1156,6 +1380,7 @@
1156 if(closed)return;1380 if(closed)return;
1157 closed=true;1381 closed=true;
1158 if(monitor!=null)monitor.end();1382 if(monitor!=null)monitor.end();
1383 rq.cancel(header, buf);
1159 try{_sendCLOSE(handle, header);}1384 try{_sendCLOSE(handle, header);}
1160 catch(Exception e){throw new IOException("error");}1385 catch(Exception e){throw new IOException("error");}
1161 }1386 }
@@ -1171,8 +1396,32 @@
1171 }1396 }
11721397
1173 public java.util.Vector ls(String path) throws SftpException{1398 public java.util.Vector ls(String path) throws SftpException{
1399 final java.util.Vector v = new Vector();
1400 LsEntrySelector selector = new LsEntrySelector(){
1401 public int select(LsEntry entry){
1402 v.addElement(entry);
1403 return CONTINUE;
1404 }
1405 };
1406 ls(path, selector);
1407 return v;
1408 }
1409
1410 /**
1411 * List files specified by the remote <code>path</code>.
1412 * Each files and directories will be passed to
1413 * <code>LsEntrySelector#select(LsEntry)</code> method, and if that method
1414 * returns <code>LsEntrySelector#BREAK</code>, the operation will be
1415 * canceled immediately.
1416 *
1417 * @see #LsEntrySelector
1418 * @since 0.1.47
1419 */
1420 public void ls(String path, LsEntrySelector selector) throws SftpException{
1174 //System.out.println("ls: "+path);1421 //System.out.println("ls: "+path);
1175 try{1422 try{
1423 ((MyPipedInputStream)io_in).updateReadSide();
1424
1176 path=remoteAbsolutePath(path);1425 path=remoteAbsolutePath(path);
1177 byte[] pattern=null;1426 byte[] pattern=null;
1178 java.util.Vector v=new java.util.Vector();1427 java.util.Vector v=new java.util.Vector();
@@ -1237,9 +1486,11 @@
1237 throwStatusError(buf, i);1486 throwStatusError(buf, i);
1238 }1487 }
12391488
1489 int cancel = LsEntrySelector.CONTINUE;
1240 byte[] handle=buf.getString(); // handle1490 byte[] handle=buf.getString(); // handle
12411491
1242 while(true){1492 while(cancel==LsEntrySelector.CONTINUE){
1493
1243 sendREADDIR(handle);1494 sendREADDIR(handle);
12441495
1245 header=header(buf, header);1496 header=header(buf, header);
@@ -1281,6 +1532,11 @@
1281 }1532 }
1282 SftpATTRS attrs=SftpATTRS.getATTR(buf);1533 SftpATTRS attrs=SftpATTRS.getATTR(buf);
12831534
1535 if(cancel==LsEntrySelector.BREAK){
1536 count--;
1537 continue;
1538 }
1539
1284 boolean find=false;1540 boolean find=false;
1285 String f=null;1541 String f=null;
1286 if(pattern==null){1542 if(pattern==null){
@@ -1311,7 +1567,8 @@
1311 else{1567 else{
1312 l=Util.byte2str(longname, fEncoding);1568 l=Util.byte2str(longname, fEncoding);
1313 }1569 }
1314 v.addElement(new LsEntry(f, l, attrs));1570
1571 cancel = selector.select(new LsEntry(f, l, attrs));
1315 }1572 }
13161573
1317 count--; 1574 count--;
@@ -1336,7 +1593,6 @@
1336 }1593 }
1337 */1594 */
13381595
1339 return v;
1340 }1596 }
1341 catch(Exception e){1597 catch(Exception e){
1342 if(e instanceof SftpException) throw (SftpException)e;1598 if(e instanceof SftpException) throw (SftpException)e;
@@ -1345,14 +1601,16 @@
1345 throw new SftpException(SSH_FX_FAILURE, "");1601 throw new SftpException(SSH_FX_FAILURE, "");
1346 }1602 }
1347 }1603 }
1604
1348 public String readlink(String path) throws SftpException{1605 public String readlink(String path) throws SftpException{
1349 try{1606 try{
1350
1351 if(server_version<3){1607 if(server_version<3){
1352 throw new SftpException(SSH_FX_OP_UNSUPPORTED, 1608 throw new SftpException(SSH_FX_OP_UNSUPPORTED,
1353 "The remote sshd is too old to support symlink operation.");1609 "The remote sshd is too old to support symlink operation.");
1354 }1610 }
13551611
1612 ((MyPipedInputStream)io_in).updateReadSide();
1613
1356 path=remoteAbsolutePath(path);1614 path=remoteAbsolutePath(path);
13571615
1358 path=isUnique(path);1616 path=isUnique(path);
@@ -1400,6 +1658,8 @@
1400 }1658 }
14011659
1402 try{1660 try{
1661 ((MyPipedInputStream)io_in).updateReadSide();
1662
1403 oldpath=remoteAbsolutePath(oldpath);1663 oldpath=remoteAbsolutePath(oldpath);
1404 newpath=remoteAbsolutePath(newpath);1664 newpath=remoteAbsolutePath(newpath);
14051665
@@ -1443,6 +1703,8 @@
1443 }1703 }
14441704
1445 try{1705 try{
1706 ((MyPipedInputStream)io_in).updateReadSide();
1707
1446 oldpath=remoteAbsolutePath(oldpath);1708 oldpath=remoteAbsolutePath(oldpath);
1447 newpath=remoteAbsolutePath(newpath);1709 newpath=remoteAbsolutePath(newpath);
14481710
@@ -1489,6 +1751,8 @@
1489 }1751 }
1490 public void rm(String path) throws SftpException{1752 public void rm(String path) throws SftpException{
1491 try{1753 try{
1754 ((MyPipedInputStream)io_in).updateReadSide();
1755
1492 path=remoteAbsolutePath(path);1756 path=remoteAbsolutePath(path);
14931757
1494 Vector v=glob_remote(path);1758 Vector v=glob_remote(path);
@@ -1546,6 +1810,8 @@
15461810
1547 public void chgrp(int gid, String path) throws SftpException{1811 public void chgrp(int gid, String path) throws SftpException{
1548 try{1812 try{
1813 ((MyPipedInputStream)io_in).updateReadSide();
1814
1549 path=remoteAbsolutePath(path);1815 path=remoteAbsolutePath(path);
15501816
1551 Vector v=glob_remote(path);1817 Vector v=glob_remote(path);
@@ -1570,6 +1836,8 @@
15701836
1571 public void chown(int uid, String path) throws SftpException{1837 public void chown(int uid, String path) throws SftpException{
1572 try{1838 try{
1839 ((MyPipedInputStream)io_in).updateReadSide();
1840
1573 path=remoteAbsolutePath(path);1841 path=remoteAbsolutePath(path);
15741842
1575 Vector v=glob_remote(path);1843 Vector v=glob_remote(path);
@@ -1594,6 +1862,8 @@
15941862
1595 public void chmod(int permissions, String path) throws SftpException{1863 public void chmod(int permissions, String path) throws SftpException{
1596 try{1864 try{
1865 ((MyPipedInputStream)io_in).updateReadSide();
1866
1597 path=remoteAbsolutePath(path);1867 path=remoteAbsolutePath(path);
15981868
1599 Vector v=glob_remote(path);1869 Vector v=glob_remote(path);
@@ -1618,6 +1888,8 @@
16181888
1619 public void setMtime(String path, int mtime) throws SftpException{1889 public void setMtime(String path, int mtime) throws SftpException{
1620 try{1890 try{
1891 ((MyPipedInputStream)io_in).updateReadSide();
1892
1621 path=remoteAbsolutePath(path);1893 path=remoteAbsolutePath(path);
16221894
1623 Vector v=glob_remote(path);1895 Vector v=glob_remote(path);
@@ -1642,6 +1914,8 @@
16421914
1643 public void rmdir(String path) throws SftpException{1915 public void rmdir(String path) throws SftpException{
1644 try{1916 try{
1917 ((MyPipedInputStream)io_in).updateReadSide();
1918
1645 path=remoteAbsolutePath(path);1919 path=remoteAbsolutePath(path);
16461920
1647 Vector v=glob_remote(path);1921 Vector v=glob_remote(path);
@@ -1679,6 +1953,8 @@
16791953
1680 public void mkdir(String path) throws SftpException{1954 public void mkdir(String path) throws SftpException{
1681 try{1955 try{
1956 ((MyPipedInputStream)io_in).updateReadSide();
1957
1682 path=remoteAbsolutePath(path);1958 path=remoteAbsolutePath(path);
16831959
1684 sendMKDIR(Util.str2byte(path, fEncoding), null);1960 sendMKDIR(Util.str2byte(path, fEncoding), null);
@@ -1708,8 +1984,9 @@
17081984
1709 public SftpATTRS stat(String path) throws SftpException{1985 public SftpATTRS stat(String path) throws SftpException{
1710 try{1986 try{
1987 ((MyPipedInputStream)io_in).updateReadSide();
1988
1711 path=remoteAbsolutePath(path);1989 path=remoteAbsolutePath(path);
1712
1713 path=isUnique(path);1990 path=isUnique(path);
17141991
1715 return _stat(path);1992 return _stat(path);
@@ -1760,8 +2037,9 @@
17602037
1761 public SftpATTRS lstat(String path) throws SftpException{2038 public SftpATTRS lstat(String path) throws SftpException{
1762 try{2039 try{
2040 ((MyPipedInputStream)io_in).updateReadSide();
2041
1763 path=remoteAbsolutePath(path);2042 path=remoteAbsolutePath(path);
1764
1765 path=isUnique(path);2043 path=isUnique(path);
17662044
1767 return _lstat(path);2045 return _lstat(path);
@@ -1836,6 +2114,8 @@
18362114
1837 public void setStat(String path, SftpATTRS attr) throws SftpException{2115 public void setStat(String path, SftpATTRS attr) throws SftpException{
1838 try{2116 try{
2117 ((MyPipedInputStream)io_in).updateReadSide();
2118
1839 path=remoteAbsolutePath(path);2119 path=remoteAbsolutePath(path);
18402120
1841 Vector v=glob_remote(path);2121 Vector v=glob_remote(path);
@@ -1885,6 +2165,8 @@
1885 public String getHome() throws SftpException {2165 public String getHome() throws SftpException {
1886 if(home==null){2166 if(home==null){
1887 try{2167 try{
2168 ((MyPipedInputStream)io_in).updateReadSide();
2169
1888 byte[] _home=_realpath("");2170 byte[] _home=_realpath("");
1889 home=Util.byte2str(_home, fEncoding);2171 home=Util.byte2str(_home, fEncoding);
1890 }2172 }
@@ -2040,32 +2322,31 @@
2040 private int sendWRITE(byte[] handle, long offset, 2322 private int sendWRITE(byte[] handle, long offset,
2041 byte[] data, int start, int length) throws Exception{2323 byte[] data, int start, int length) throws Exception{
2042 int _length=length;2324 int _length=length;
2043 packet.reset();2325 opacket.reset();
2044 if(buf.buffer.length<buf.index+13+21+handle.length+length2326 if(obuf.buffer.length<obuf.index+13+21+handle.length+length+Session.buffer_margin){
2045 +32 +20 // padding and mac2327 _length=obuf.buffer.length-(obuf.index+13+21+handle.length+Session.buffer_margin);
2046){2328 // System.err.println("_length="+_length+" length="+length);
2047 _length=buf.buffer.length-(buf.index+13+21+handle.length
2048 +32 +20 // padding and mac
2049);
2050 //System.err.println("_length="+_length+" length="+length);
2051 }2329 }
20522330
2053 putHEAD(SSH_FXP_WRITE, 21+handle.length+_length); // 142331 putHEAD(obuf, SSH_FXP_WRITE, 21+handle.length+_length); // 14
2054 buf.putInt(seq++); // 42332 obuf.putInt(seq++); // 4
2055 buf.putString(handle); // 4+handle.length2333 obuf.putString(handle); // 4+handle.length
2056 buf.putLong(offset); // 82334 obuf.putLong(offset); // 8
2057 if(buf.buffer!=data){2335 if(obuf.buffer!=data){
2058 buf.putString(data, start, _length); // 4+_length2336 obuf.putString(data, start, _length); // 4+_length
2059 }2337 }
2060 else{2338 else{
2061 buf.putInt(_length);2339 obuf.putInt(_length);
2062 buf.skip(_length);2340 obuf.skip(_length);
2063 }2341 }
2064 getSession().write(packet, this, 21+handle.length+_length+4);2342 getSession().write(opacket, this, 21+handle.length+_length+4);
2065 return _length;2343 return _length;
2066 }2344 }
2067
2068 private void sendREAD(byte[] handle, long offset, int length) throws Exception{2345 private void sendREAD(byte[] handle, long offset, int length) throws Exception{
2346 sendREAD(handle, offset, length, null);
2347 }
2348 private void sendREAD(byte[] handle, long offset, int length,
2349 RequestQueue rrq) throws Exception{
2069 packet.reset();2350 packet.reset();
2070 putHEAD(SSH_FXP_READ, 21+handle.length);2351 putHEAD(SSH_FXP_READ, 21+handle.length);
2071 buf.putInt(seq++);2352 buf.putInt(seq++);
@@ -2073,9 +2354,12 @@
2073 buf.putLong(offset);2354 buf.putLong(offset);
2074 buf.putInt(length);2355 buf.putInt(length);
2075 getSession().write(packet, this, 21+handle.length+4);2356 getSession().write(packet, this, 21+handle.length+4);
2357 if(rrq!=null){
2358 rrq.add(seq-1, offset, length);
2359 }
2076 }2360 }
20772361
2078 private void putHEAD(byte type, int length) throws Exception{2362 private void putHEAD(Buffer buf, byte type, int length) throws Exception{
2079 buf.putByte((byte)Session.SSH_MSG_CHANNEL_DATA);2363 buf.putByte((byte)Session.SSH_MSG_CHANNEL_DATA);
2080 buf.putInt(recipient);2364 buf.putInt(recipient);
2081 buf.putInt(length+4);2365 buf.putInt(length+4);
@@ -2083,8 +2367,11 @@
2083 buf.putByte(type);2367 buf.putByte(type);
2084 }2368 }
20852369
2370 private void putHEAD(byte type, int length) throws Exception{
2371 putHEAD(buf, type, length);
2372 }
2373
2086 private Vector glob_remote(String _path) throws Exception{2374 private Vector glob_remote(String _path) throws Exception{
2087
2088 Vector v=new Vector();2375 Vector v=new Vector();
2089 int i=0;2376 int i=0;
20902377
@@ -2104,7 +2391,7 @@
2104 boolean pattern_has_wildcard=isPattern(_pattern, _pattern_utf8);2391 boolean pattern_has_wildcard=isPattern(_pattern, _pattern_utf8);
21052392
2106 if(!pattern_has_wildcard){2393 if(!pattern_has_wildcard){
2107 if(dir.length()!=1) // not equal to "/"2394 if(!dir.equals("/"))
2108 dir+="/";2395 dir+="/";
2109 v.addElement(dir+Util.unquote(_pattern));2396 v.addElement(dir+Util.unquote(_pattern));
2110 return v;2397 return v;
@@ -2202,23 +2489,16 @@
2202 }2489 }
22032490
2204 private boolean isPattern(byte[] path){2491 private boolean isPattern(byte[] path){
2205 int i=path.length-1;2492 int length=path.length;
2206 while(i>=0){2493 int i=0;
2207 if(path[i]=='*' || path[i]=='?'){2494 while(i<length){
2208 if(i>0 && path[i-1]=='\\'){2495 if(path[i]=='*' || path[i]=='?')
2209 i--;2496 return true;
2210 if(i>0 && path[i-1]=='\\'){ // \\* or \\?2497 if(path[i]=='\\' && (i+1)<length)
2211 break;2498 i++;
2212 }2499 i++;
2213 }
2214 else{
2215 break;
2216 }
2217 }
2218 i--;
2219 }2500 }
2220 // System.err.println("isPattern: ["+(new String(path))+"] "+(!(i<0)));2501 return false;
2221 return !(i<0);
2222 }2502 }
22232503
2224 private Vector glob_local(String _path) throws Exception{2504 private Vector glob_local(String _path) throws Exception{
@@ -2358,6 +2638,7 @@
2358 private String remoteAbsolutePath(String path) throws SftpException{2638 private String remoteAbsolutePath(String path) throws SftpException{
2359 if(path.charAt(0)=='/') return path;2639 if(path.charAt(0)=='/') return path;
2360 String cwd=getCwd();2640 String cwd=getCwd();
2641// if(cwd.equals(getHome())) return path;
2361 if(cwd.endsWith("/")) return cwd+path;2642 if(cwd.endsWith("/")) return cwd+path;
2362 return cwd+"/"+path;2643 return cwd+"/"+path;
2363 }2644 }
@@ -2391,9 +2672,9 @@
23912672
2392 public void setFilenameEncoding(String encoding) throws SftpException{2673 public void setFilenameEncoding(String encoding) throws SftpException{
2393 int sversion=getServerVersion();2674 int sversion=getServerVersion();
2394 if(sversion > 3 && 2675 if(3 <= sversion && sversion <= 5 &&
2395 !encoding.equals(UTF8)){2676 !encoding.equals(UTF8)){
2396 throw new SftpException(SSH_FX_FAILURE, 2677 throw new SftpException(SSH_FX_FAILURE,
2397 "The encoding can not be changed for this sftp server.");2678 "The encoding can not be changed for this sftp server.");
2398 }2679 }
2399 if(encoding.equals(UTF8)){2680 if(encoding.equals(UTF8)){
@@ -2445,4 +2726,26 @@
2445 throw new ClassCastException("a decendent of LsEntry must be given.");2726 throw new ClassCastException("a decendent of LsEntry must be given.");
2446 }2727 }
2447 }2728 }
2729
2730 /**
2731 * This interface will be passed as an arugment for <code>ls</code> method.
2732 *
2733 * @see #LsEntry
2734 * @see #ls(String, LsEntrySelector)
2735 * @since 0.1.47
2736 */
2737 public interface LsEntrySelector {
2738 public final int CONTINUE = 0;
2739 public final int BREAK = 1;
2740
2741 /**
2742 * <p> The <code>select</code> method will be invoked in <code>ls</code>
2743 * method for each file entry. If this method returns BREAK,
2744 * <code>ls</code> will be canceled.
2745 *
2746 * @param entry one of entry from ls
2747 * @return if BREAK is returned, the 'ls' operation will be canceled.
2748 */
2749 public int select(LsEntry entry);
2750 }
2448}2751}
24492752
=== modified file 'src/main/java/com/jcraft/jsch/ChannelShell.java'
--- src/com/jcraft/jsch/ChannelShell.java 2010-06-27 23:17:34 +0000
+++ src/main/java/com/jcraft/jsch/ChannelShell.java 2012-05-04 10:23:17 +0000
@@ -1,6 +1,6 @@
1/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */1/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
2/*2/*
3Copyright (c) 2002-2009 ymnk, JCraft,Inc. All rights reserved.3Copyright (c) 2002-2012 ymnk, JCraft,Inc. All rights reserved.
44
5Redistribution and use in source and binary forms, with or without5Redistribution and use in source and binary forms, with or without
6modification, are permitted provided that the following conditions are met:6modification, are permitted provided that the following conditions are met:
77
=== modified file 'src/main/java/com/jcraft/jsch/ChannelSubsystem.java'
--- src/com/jcraft/jsch/ChannelSubsystem.java 2010-06-27 23:17:34 +0000
+++ src/main/java/com/jcraft/jsch/ChannelSubsystem.java 2012-05-04 10:23:17 +0000
@@ -1,6 +1,6 @@
1/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */1/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
2/*2/*
3Copyright (c) 2005-2009 ymnk, JCraft,Inc. All rights reserved.3Copyright (c) 2005-2012 ymnk, JCraft,Inc. All rights reserved.
44
5Redistribution and use in source and binary forms, with or without5Redistribution and use in source and binary forms, with or without
6modification, are permitted provided that the following conditions are met:6modification, are permitted provided that the following conditions are met:
@@ -34,7 +34,7 @@
34 boolean pty=false;34 boolean pty=false;
35 boolean want_reply=true;35 boolean want_reply=true;
36 String subsystem="";36 String subsystem="";
37 public void setXForwarding(boolean foo){ xforwading=true; }37 public void setXForwarding(boolean foo){ xforwading=foo; }
38 public void setPty(boolean foo){ pty=foo; }38 public void setPty(boolean foo){ pty=foo; }
39 public void setWantReply(boolean foo){ want_reply=foo; }39 public void setWantReply(boolean foo){ want_reply=foo; }
40 public void setSubsystem(String foo){ subsystem=foo; }40 public void setSubsystem(String foo){ subsystem=foo; }
4141
=== modified file 'src/main/java/com/jcraft/jsch/ChannelX11.java'
--- src/com/jcraft/jsch/ChannelX11.java 2010-06-27 23:17:34 +0000
+++ src/main/java/com/jcraft/jsch/ChannelX11.java 2012-05-04 10:23:17 +0000
@@ -1,6 +1,6 @@
1/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */1/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
2/*2/*
3Copyright (c) 2002-2009 ymnk, JCraft,Inc. All rights reserved.3Copyright (c) 2002-2012 ymnk, JCraft,Inc. All rights reserved.
44
5Redistribution and use in source and binary forms, with or without5Redistribution and use in source and binary forms, with or without
6modification, are permitted provided that the following conditions are met:6modification, are permitted provided that the following conditions are met:
@@ -61,7 +61,7 @@
61 return 0;61 return 0;
62 }62 }
63 static void setCookie(String foo){63 static void setCookie(String foo){
64 cookie_hex=foo.getBytes(); 64 cookie_hex=Util.str2byte(foo);
65 cookie=new byte[16];65 cookie=new byte[16];
66 for(int i=0; i<16; i++){66 for(int i=0; i<16; i++){
67 cookie[i]=(byte)(((revtable(cookie_hex[i*2])<<4)&0xf0) |67 cookie[i]=(byte)(((revtable(cookie_hex[i*2])<<4)&0xf0) |
@@ -99,6 +99,13 @@
99 }99 }
100 }100 }
101101
102 static void removeFakedCookie(Session session){
103 synchronized(faked_cookie_hex_pool){
104 faked_cookie_hex_pool.remove(session);
105 faked_cookie_pool.remove(session);
106 }
107 }
108
102 ChannelX11(){109 ChannelX11(){
103 super();110 super();
104111
@@ -106,7 +113,7 @@
106 setLocalWindowSize(LOCAL_WINDOW_SIZE_MAX);113 setLocalWindowSize(LOCAL_WINDOW_SIZE_MAX);
107 setLocalPacketSize(LOCAL_MAXIMUM_PACKET_SIZE);114 setLocalPacketSize(LOCAL_MAXIMUM_PACKET_SIZE);
108115
109 type="x11".getBytes();116 type=Util.str2byte("x11");
110117
111 connected=true;118 connected=true;
112 /*119 /*
@@ -150,9 +157,7 @@
150 io.in!=null){157 io.in!=null){
151 i=io.in.read(buf.buffer, 158 i=io.in.read(buf.buffer,
152 14, 159 14,
153 buf.buffer.length-14160 buf.buffer.length-14-Session.buffer_margin);
154 -32 -20 // padding and mac
155 );
156 if(i<=0){161 if(i<=0){
157 eof();162 eof();
158 break;163 break;
159164
=== modified file 'src/main/java/com/jcraft/jsch/Cipher.java'
--- src/com/jcraft/jsch/Cipher.java 2010-06-27 23:17:34 +0000
+++ src/main/java/com/jcraft/jsch/Cipher.java 2012-05-04 10:23:17 +0000
@@ -1,6 +1,6 @@
1/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */1/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
2/*2/*
3Copyright (c) 2002-2009 ymnk, JCraft,Inc. All rights reserved.3Copyright (c) 2002-2012 ymnk, JCraft,Inc. All rights reserved.
44
5Redistribution and use in source and binary forms, with or without5Redistribution and use in source and binary forms, with or without
6modification, are permitted provided that the following conditions are met:6modification, are permitted provided that the following conditions are met:
@@ -36,4 +36,5 @@
36 int getBlockSize(); 36 int getBlockSize();
37 void init(int mode, byte[] key, byte[] iv) throws Exception; 37 void init(int mode, byte[] key, byte[] iv) throws Exception;
38 void update(byte[] foo, int s1, int len, byte[] bar, int s2) throws Exception;38 void update(byte[] foo, int s1, int len, byte[] bar, int s2) throws Exception;
39 boolean isCBC();
39}40}
4041
=== modified file 'src/main/java/com/jcraft/jsch/CipherNone.java'
--- src/com/jcraft/jsch/CipherNone.java 2010-06-27 23:17:34 +0000
+++ src/main/java/com/jcraft/jsch/CipherNone.java 2012-05-04 10:23:17 +0000
@@ -1,6 +1,6 @@
1/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */1/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
2/*2/*
3Copyright (c) 2002-2009 ymnk, JCraft,Inc. All rights reserved.3Copyright (c) 2002-2012 ymnk, JCraft,Inc. All rights reserved.
44
5Redistribution and use in source and binary forms, with or without5Redistribution and use in source and binary forms, with or without
6modification, are permitted provided that the following conditions are met:6modification, are permitted provided that the following conditions are met:
@@ -38,4 +38,5 @@
38 }38 }
39 public void update(byte[] foo, int s1, int len, byte[] bar, int s2) throws Exception{39 public void update(byte[] foo, int s1, int len, byte[] bar, int s2) throws Exception{
40 }40 }
41 public boolean isCBC(){return false; }
41}42}
4243
=== modified file 'src/main/java/com/jcraft/jsch/Compression.java'
--- src/com/jcraft/jsch/Compression.java 2010-06-27 23:17:34 +0000
+++ src/main/java/com/jcraft/jsch/Compression.java 2012-05-04 10:23:17 +0000
@@ -1,6 +1,6 @@
1/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */1/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
2/*2/*
3Copyright (c) 2002-2009 ymnk, JCraft,Inc. All rights reserved.3Copyright (c) 2002-2012 ymnk, JCraft,Inc. All rights reserved.
44
5Redistribution and use in source and binary forms, with or without5Redistribution and use in source and binary forms, with or without
6modification, are permitted provided that the following conditions are met:6modification, are permitted provided that the following conditions are met:
@@ -33,6 +33,6 @@
33 static public final int INFLATER=0;33 static public final int INFLATER=0;
34 static public final int DEFLATER=1;34 static public final int DEFLATER=1;
35 void init(int type, int level);35 void init(int type, int level);
36 int compress(byte[] buf, int start, int len);36 byte[] compress(byte[] buf, int start, int[] len);
37 byte[] uncompress(byte[] buf, int start, int[] len);37 byte[] uncompress(byte[] buf, int start, int[] len);
38}38}
3939
=== modified file 'src/main/java/com/jcraft/jsch/DH.java'
--- src/com/jcraft/jsch/DH.java 2010-06-27 23:17:34 +0000
+++ src/main/java/com/jcraft/jsch/DH.java 2012-05-04 10:23:17 +0000
@@ -1,6 +1,6 @@
1/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */1/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
2/*2/*
3Copyright (c) 2002-2009 ymnk, JCraft,Inc. All rights reserved.3Copyright (c) 2002-2012 ymnk, JCraft,Inc. All rights reserved.
44
5Redistribution and use in source and binary forms, with or without5Redistribution and use in source and binary forms, with or without
6modification, are permitted provided that the following conditions are met:6modification, are permitted provided that the following conditions are met:
77
=== modified file 'src/main/java/com/jcraft/jsch/DHG1.java'
--- src/com/jcraft/jsch/DHG1.java 2010-06-27 23:17:34 +0000
+++ src/main/java/com/jcraft/jsch/DHG1.java 2012-05-04 10:23:17 +0000
@@ -1,6 +1,6 @@
1/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */1/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
2/*2/*
3Copyright (c) 2002-2009 ymnk, JCraft,Inc. All rights reserved.3Copyright (c) 2002-2012 ymnk, JCraft,Inc. All rights reserved.
44
5Redistribution and use in source and binary forms, with or without5Redistribution and use in source and binary forms, with or without
6modification, are permitted provided that the following conditions are met:6modification, are permitted provided that the following conditions are met:
@@ -203,7 +203,7 @@
203 j=0;203 j=0;
204 j=((K_S[i++]<<24)&0xff000000)|((K_S[i++]<<16)&0x00ff0000)|204 j=((K_S[i++]<<24)&0xff000000)|((K_S[i++]<<16)&0x00ff0000)|
205 ((K_S[i++]<<8)&0x0000ff00)|((K_S[i++])&0x000000ff);205 ((K_S[i++]<<8)&0x0000ff00)|((K_S[i++])&0x000000ff);
206 String alg=new String(K_S, i, j);206 String alg=Util.byte2str(K_S, i, j);
207 i+=j;207 i+=j;
208208
209 boolean result=false;209 boolean result=false;
210210
=== added file 'src/main/java/com/jcraft/jsch/DHG14.java'
--- src/main/java/com/jcraft/jsch/DHG14.java 1970-01-01 00:00:00 +0000
+++ src/main/java/com/jcraft/jsch/DHG14.java 2012-05-04 10:23:17 +0000
@@ -0,0 +1,310 @@
1/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
2/*
3Copyright (c) 2002-2012 ymnk, JCraft,Inc. All rights reserved.
4
5Redistribution and use in source and binary forms, with or without
6modification, are permitted provided that the following conditions are met:
7
8 1. Redistributions of source code must retain the above copyright notice,
9 this list of conditions and the following disclaimer.
10
11 2. Redistributions in binary form must reproduce the above copyright
12 notice, this list of conditions and the following disclaimer in
13 the documentation and/or other materials provided with the distribution.
14
15 3. The names of the authors may not be used to endorse or promote products
16 derived from this software without specific prior written permission.
17
18THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
19INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
20FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
21INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
22INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
24OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
25LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
26NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
27EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28*/
29
30package com.jcraft.jsch;
31
32public class DHG14 extends KeyExchange{
33
34 static final byte[] g={ 2 };
35 static final byte[] p={
36(byte)0x00,
37(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF,
38(byte)0xC9,(byte)0x0F,(byte)0xDA,(byte)0xA2,(byte)0x21,(byte)0x68,(byte)0xC2,(byte)0x34,
39(byte)0xC4,(byte)0xC6,(byte)0x62,(byte)0x8B,(byte)0x80,(byte)0xDC,(byte)0x1C,(byte)0xD1,
40(byte)0x29,(byte)0x02,(byte)0x4E,(byte)0x08,(byte)0x8A,(byte)0x67,(byte)0xCC,(byte)0x74,
41(byte)0x02,(byte)0x0B,(byte)0xBE,(byte)0xA6,(byte)0x3B,(byte)0x13,(byte)0x9B,(byte)0x22,
42(byte)0x51,(byte)0x4A,(byte)0x08,(byte)0x79,(byte)0x8E,(byte)0x34,(byte)0x04,(byte)0xDD,
43(byte)0xEF,(byte)0x95,(byte)0x19,(byte)0xB3,(byte)0xCD,(byte)0x3A,(byte)0x43,(byte)0x1B,
44(byte)0x30,(byte)0x2B,(byte)0x0A,(byte)0x6D,(byte)0xF2,(byte)0x5F,(byte)0x14,(byte)0x37,
45(byte)0x4F,(byte)0xE1,(byte)0x35,(byte)0x6D,(byte)0x6D,(byte)0x51,(byte)0xC2,(byte)0x45,
46(byte)0xE4,(byte)0x85,(byte)0xB5,(byte)0x76,(byte)0x62,(byte)0x5E,(byte)0x7E,(byte)0xC6,
47(byte)0xF4,(byte)0x4C,(byte)0x42,(byte)0xE9,(byte)0xA6,(byte)0x37,(byte)0xED,(byte)0x6B,
48(byte)0x0B,(byte)0xFF,(byte)0x5C,(byte)0xB6,(byte)0xF4,(byte)0x06,(byte)0xB7,(byte)0xED,
49(byte)0xEE,(byte)0x38,(byte)0x6B,(byte)0xFB,(byte)0x5A,(byte)0x89,(byte)0x9F,(byte)0xA5,
50(byte)0xAE,(byte)0x9F,(byte)0x24,(byte)0x11,(byte)0x7C,(byte)0x4B,(byte)0x1F,(byte)0xE6,
51(byte)0x49,(byte)0x28,(byte)0x66,(byte)0x51,(byte)0xEC,(byte)0xE4,(byte)0x5B,(byte)0x3D,
52(byte)0xC2,(byte)0x00,(byte)0x7C,(byte)0xB8,(byte)0xA1,(byte)0x63,(byte)0xBF,(byte)0x05,
53(byte)0x98,(byte)0xDA,(byte)0x48,(byte)0x36,(byte)0x1C,(byte)0x55,(byte)0xD3,(byte)0x9A,
54(byte)0x69,(byte)0x16,(byte)0x3F,(byte)0xA8,(byte)0xFD,(byte)0x24,(byte)0xCF,(byte)0x5F,
55(byte)0x83,(byte)0x65,(byte)0x5D,(byte)0x23,(byte)0xDC,(byte)0xA3,(byte)0xAD,(byte)0x96,
56(byte)0x1C,(byte)0x62,(byte)0xF3,(byte)0x56,(byte)0x20,(byte)0x85,(byte)0x52,(byte)0xBB,
57(byte)0x9E,(byte)0xD5,(byte)0x29,(byte)0x07,(byte)0x70,(byte)0x96,(byte)0x96,(byte)0x6D,
58(byte)0x67,(byte)0x0C,(byte)0x35,(byte)0x4E,(byte)0x4A,(byte)0xBC,(byte)0x98,(byte)0x04,
59(byte)0xF1,(byte)0x74,(byte)0x6C,(byte)0x08,(byte)0xCA,(byte)0x18,(byte)0x21,(byte)0x7C,
60(byte)0x32,(byte)0x90,(byte)0x5E,(byte)0x46,(byte)0x2E,(byte)0x36,(byte)0xCE,(byte)0x3B,
61(byte)0xE3,(byte)0x9E,(byte)0x77,(byte)0x2C,(byte)0x18,(byte)0x0E,(byte)0x86,(byte)0x03,
62(byte)0x9B,(byte)0x27,(byte)0x83,(byte)0xA2,(byte)0xEC,(byte)0x07,(byte)0xA2,(byte)0x8F,
63(byte)0xB5,(byte)0xC5,(byte)0x5D,(byte)0xF0,(byte)0x6F,(byte)0x4C,(byte)0x52,(byte)0xC9,
64(byte)0xDE,(byte)0x2B,(byte)0xCB,(byte)0xF6,(byte)0x95,(byte)0x58,(byte)0x17,(byte)0x18,
65(byte)0x39,(byte)0x95,(byte)0x49,(byte)0x7C,(byte)0xEA,(byte)0x95,(byte)0x6A,(byte)0xE5,
66(byte)0x15,(byte)0xD2,(byte)0x26,(byte)0x18,(byte)0x98,(byte)0xFA,(byte)0x05,(byte)0x10,
67(byte)0x15,(byte)0x72,(byte)0x8E,(byte)0x5A,(byte)0x8A,(byte)0xAC,(byte)0xAA,(byte)0x68,
68(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF
69};
70
71 private static final int SSH_MSG_KEXDH_INIT= 30;
72 private static final int SSH_MSG_KEXDH_REPLY= 31;
73
74 static final int RSA=0;
75 static final int DSS=1;
76 private int type=0;
77
78 private int state;
79
80 DH dh;
81
82 byte[] V_S;
83 byte[] V_C;
84 byte[] I_S;
85 byte[] I_C;
86
87 byte[] e;
88
89 private Buffer buf;
90 private Packet packet;
91
92 public void init(Session session,
93 byte[] V_S, byte[] V_C, byte[] I_S, byte[] I_C) throws Exception{
94 this.session=session;
95 this.V_S=V_S;
96 this.V_C=V_C;
97 this.I_S=I_S;
98 this.I_C=I_C;
99
100 try{
101 Class c=Class.forName(session.getConfig("sha-1"));
102 sha=(HASH)(c.newInstance());
103 sha.init();
104 }
105 catch(Exception e){
106 System.err.println(e);
107 }
108
109 buf=new Buffer();
110 packet=new Packet(buf);
111
112 try{
113 Class c=Class.forName(session.getConfig("dh"));
114 dh=(DH)(c.newInstance());
115 dh.init();
116 }
117 catch(Exception e){
118 //System.err.println(e);
119 throw e;
120 }
121
122 dh.setP(p);
123 dh.setG(g);
124 // The client responds with:
125 // byte SSH_MSG_KEXDH_INIT(30)
126 // mpint e <- g^x mod p
127 // x is a random number (1 < x < (p-1)/2)
128
129 e=dh.getE();
130 packet.reset();
131 buf.putByte((byte)SSH_MSG_KEXDH_INIT);
132 buf.putMPInt(e);
133
134 if(V_S==null){ // This is a really ugly hack for Session.checkKexes ;-(
135 return;
136 }
137
138 session.write(packet);
139
140 if(JSch.getLogger().isEnabled(Logger.INFO)){
141 JSch.getLogger().log(Logger.INFO,
142 "SSH_MSG_KEXDH_INIT sent");
143 JSch.getLogger().log(Logger.INFO,
144 "expecting SSH_MSG_KEXDH_REPLY");
145 }
146
147 state=SSH_MSG_KEXDH_REPLY;
148 }
149
150 public boolean next(Buffer _buf) throws Exception{
151 int i,j;
152
153 switch(state){
154 case SSH_MSG_KEXDH_REPLY:
155 // The server responds with:
156 // byte SSH_MSG_KEXDH_REPLY(31)
157 // string server public host key and certificates (K_S)
158 // mpint f
159 // string signature of H
160 j=_buf.getInt();
161 j=_buf.getByte();
162 j=_buf.getByte();
163 if(j!=31){
164 System.err.println("type: must be 31 "+j);
165 return false;
166 }
167
168 K_S=_buf.getString();
169 // K_S is server_key_blob, which includes ....
170 // string ssh-dss
171 // impint p of dsa
172 // impint q of dsa
173 // impint g of dsa
174 // impint pub_key of dsa
175 //System.err.print("K_S: "); //dump(K_S, 0, K_S.length);
176 byte[] f=_buf.getMPInt();
177 byte[] sig_of_H=_buf.getString();
178
179 dh.setF(f);
180 K=dh.getK();
181
182 //The hash H is computed as the HASH hash of the concatenation of the
183 //following:
184 // string V_C, the client's version string (CR and NL excluded)
185 // string V_S, the server's version string (CR and NL excluded)
186 // string I_C, the payload of the client's SSH_MSG_KEXINIT
187 // string I_S, the payload of the server's SSH_MSG_KEXINIT
188 // string K_S, the host key
189 // mpint e, exchange value sent by the client
190 // mpint f, exchange value sent by the server
191 // mpint K, the shared secret
192 // This value is called the exchange hash, and it is used to authenti-
193 // cate the key exchange.
194 buf.reset();
195 buf.putString(V_C); buf.putString(V_S);
196 buf.putString(I_C); buf.putString(I_S);
197 buf.putString(K_S);
198 buf.putMPInt(e); buf.putMPInt(f);
199 buf.putMPInt(K);
200 byte[] foo=new byte[buf.getLength()];
201 buf.getByte(foo);
202 sha.update(foo, 0, foo.length);
203 H=sha.digest();
204 //System.err.print("H -> "); //dump(H, 0, H.length);
205
206 i=0;
207 j=0;
208 j=((K_S[i++]<<24)&0xff000000)|((K_S[i++]<<16)&0x00ff0000)|
209 ((K_S[i++]<<8)&0x0000ff00)|((K_S[i++])&0x000000ff);
210 String alg=Util.byte2str(K_S, i, j);
211 i+=j;
212
213 boolean result=false;
214
215 if(alg.equals("ssh-rsa")){
216 byte[] tmp;
217 byte[] ee;
218 byte[] n;
219
220 type=RSA;
221
222 j=((K_S[i++]<<24)&0xff000000)|((K_S[i++]<<16)&0x00ff0000)|
223 ((K_S[i++]<<8)&0x0000ff00)|((K_S[i++])&0x000000ff);
224 tmp=new byte[j]; System.arraycopy(K_S, i, tmp, 0, j); i+=j;
225 ee=tmp;
226 j=((K_S[i++]<<24)&0xff000000)|((K_S[i++]<<16)&0x00ff0000)|
227 ((K_S[i++]<<8)&0x0000ff00)|((K_S[i++])&0x000000ff);
228 tmp=new byte[j]; System.arraycopy(K_S, i, tmp, 0, j); i+=j;
229 n=tmp;
230
231 SignatureRSA sig=null;
232 try{
233 Class c=Class.forName(session.getConfig("signature.rsa"));
234 sig=(SignatureRSA)(c.newInstance());
235 sig.init();
236 }
237 catch(Exception e){
238 System.err.println(e);
239 }
240
241 sig.setPubKey(ee, n);
242 sig.update(H);
243 result=sig.verify(sig_of_H);
244
245 if(JSch.getLogger().isEnabled(Logger.INFO)){
246 JSch.getLogger().log(Logger.INFO,
247 "ssh_rsa_verify: signature "+result);
248 }
249
250 }
251 else if(alg.equals("ssh-dss")){
252 byte[] q=null;
253 byte[] tmp;
254 byte[] p;
255 byte[] g;
256
257 type=DSS;
258
259 j=((K_S[i++]<<24)&0xff000000)|((K_S[i++]<<16)&0x00ff0000)|
260 ((K_S[i++]<<8)&0x0000ff00)|((K_S[i++])&0x000000ff);
261 tmp=new byte[j]; System.arraycopy(K_S, i, tmp, 0, j); i+=j;
262 p=tmp;
263 j=((K_S[i++]<<24)&0xff000000)|((K_S[i++]<<16)&0x00ff0000)|
264 ((K_S[i++]<<8)&0x0000ff00)|((K_S[i++])&0x000000ff);
265 tmp=new byte[j]; System.arraycopy(K_S, i, tmp, 0, j); i+=j;
266 q=tmp;
267 j=((K_S[i++]<<24)&0xff000000)|((K_S[i++]<<16)&0x00ff0000)|
268 ((K_S[i++]<<8)&0x0000ff00)|((K_S[i++])&0x000000ff);
269 tmp=new byte[j]; System.arraycopy(K_S, i, tmp, 0, j); i+=j;
270 g=tmp;
271 j=((K_S[i++]<<24)&0xff000000)|((K_S[i++]<<16)&0x00ff0000)|
272 ((K_S[i++]<<8)&0x0000ff00)|((K_S[i++])&0x000000ff);
273 tmp=new byte[j]; System.arraycopy(K_S, i, tmp, 0, j); i+=j;
274 f=tmp;
275
276 SignatureDSA sig=null;
277 try{
278 Class c=Class.forName(session.getConfig("signature.dss"));
279 sig=(SignatureDSA)(c.newInstance());
280 sig.init();
281 }
282 catch(Exception e){
283 System.err.println(e);
284 }
285 sig.setPubKey(f, p, q, g);
286 sig.update(H);
287 result=sig.verify(sig_of_H);
288
289 if(JSch.getLogger().isEnabled(Logger.INFO)){
290 JSch.getLogger().log(Logger.INFO,
291 "ssh_dss_verify: signature "+result);
292 }
293
294 }
295 else{
296 System.err.println("unknown alg");
297 }
298 state=STATE_END;
299 return result;
300 }
301 return false;
302 }
303
304 public String getKeyType(){
305 if(type==DSS) return "DSA";
306 return "RSA";
307 }
308
309 public int getState(){return state; }
310}
0311
=== modified file 'src/main/java/com/jcraft/jsch/DHGEX.java'
--- src/com/jcraft/jsch/DHGEX.java 2010-06-27 23:17:34 +0000
+++ src/main/java/com/jcraft/jsch/DHGEX.java 2012-05-04 10:23:17 +0000
@@ -1,6 +1,6 @@
1/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */1/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
2/*2/*
3Copyright (c) 2002-2009 ymnk, JCraft,Inc. All rights reserved.3Copyright (c) 2002-2012 ymnk, JCraft,Inc. All rights reserved.
44
5Redistribution and use in source and binary forms, with or without5Redistribution and use in source and binary forms, with or without
6modification, are permitted provided that the following conditions are met:6modification, are permitted provided that the following conditions are met:
@@ -233,7 +233,7 @@
233 j=0;233 j=0;
234 j=((K_S[i++]<<24)&0xff000000)|((K_S[i++]<<16)&0x00ff0000)|234 j=((K_S[i++]<<24)&0xff000000)|((K_S[i++]<<16)&0x00ff0000)|
235 ((K_S[i++]<<8)&0x0000ff00)|((K_S[i++])&0x000000ff);235 ((K_S[i++]<<8)&0x0000ff00)|((K_S[i++])&0x000000ff);
236 String alg=new String(K_S, i, j);236 String alg=Util.byte2str(K_S, i, j);
237 i+=j;237 i+=j;
238238
239 boolean result=false;239 boolean result=false;
240240
=== modified file 'src/main/java/com/jcraft/jsch/ForwardedTCPIPDaemon.java'
--- src/com/jcraft/jsch/ForwardedTCPIPDaemon.java 2010-06-27 23:17:34 +0000
+++ src/main/java/com/jcraft/jsch/ForwardedTCPIPDaemon.java 2012-05-04 10:23:17 +0000
@@ -1,6 +1,6 @@
1/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */1/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
2/*2/*
3Copyright (c) 2002-2009 ymnk, JCraft,Inc. All rights reserved.3Copyright (c) 2002-2012 ymnk, JCraft,Inc. All rights reserved.
44
5Redistribution and use in source and binary forms, with or without5Redistribution and use in source and binary forms, with or without
6modification, are permitted provided that the following conditions are met:6modification, are permitted provided that the following conditions are met:
77
=== modified file 'src/main/java/com/jcraft/jsch/GSSContext.java'
--- src/com/jcraft/jsch/GSSContext.java 2010-06-27 23:17:34 +0000
+++ src/main/java/com/jcraft/jsch/GSSContext.java 2012-05-04 10:23:17 +0000
@@ -1,6 +1,6 @@
1/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */1/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
2/*2/*
3Copyright (c) 2004-2009 ymnk, JCraft,Inc. All rights reserved.3Copyright (c) 2004-2012 ymnk, JCraft,Inc. All rights reserved.
44
5Redistribution and use in source and binary forms, with or without5Redistribution and use in source and binary forms, with or without
6modification, are permitted provided that the following conditions are met:6modification, are permitted provided that the following conditions are met:
77
=== modified file 'src/main/java/com/jcraft/jsch/HASH.java'
--- src/com/jcraft/jsch/HASH.java 2010-06-27 23:17:34 +0000
+++ src/main/java/com/jcraft/jsch/HASH.java 2012-05-04 10:23:17 +0000
@@ -1,6 +1,6 @@
1/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */1/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
2/*2/*
3Copyright (c) 2002-2009 ymnk, JCraft,Inc. All rights reserved.3Copyright (c) 2002-2012 ymnk, JCraft,Inc. All rights reserved.
44
5Redistribution and use in source and binary forms, with or without5Redistribution and use in source and binary forms, with or without
6modification, are permitted provided that the following conditions are met:6modification, are permitted provided that the following conditions are met:
77
=== modified file 'src/main/java/com/jcraft/jsch/HostKey.java'
--- src/com/jcraft/jsch/HostKey.java 2010-06-27 23:17:34 +0000
+++ src/main/java/com/jcraft/jsch/HostKey.java 2012-05-04 10:23:17 +0000
@@ -1,6 +1,6 @@
1/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */1/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
2/*2/*
3Copyright (c) 2002-2009 ymnk, JCraft,Inc. All rights reserved.3Copyright (c) 2002-2012 ymnk, JCraft,Inc. All rights reserved.
44
5Redistribution and use in source and binary forms, with or without5Redistribution and use in source and binary forms, with or without
6modification, are permitted provided that the following conditions are met:6modification, are permitted provided that the following conditions are met:
@@ -30,8 +30,8 @@
30package com.jcraft.jsch;30package com.jcraft.jsch;
3131
32public class HostKey{32public class HostKey{
33 private static final byte[] sshdss="ssh-dss".getBytes();33 private static final byte[] sshdss=Util.str2byte("ssh-dss");
34 private static final byte[] sshrsa="ssh-rsa".getBytes();34 private static final byte[] sshrsa=Util.str2byte("ssh-rsa");
3535
36 protected static final int GUESS=0;36 protected static final int GUESS=0;
37 public static final int SSHDSS=1;37 public static final int SSHDSS=1;
@@ -61,12 +61,12 @@
6161
62 public String getHost(){ return host; }62 public String getHost(){ return host; }
63 public String getType(){63 public String getType(){
64 if(type==SSHDSS){ return new String(sshdss); }64 if(type==SSHDSS){ return Util.byte2str(sshdss); }
65 if(type==SSHRSA){ return new String(sshrsa);}65 if(type==SSHRSA){ return Util.byte2str(sshrsa);}
66 return "UNKNOWN";66 return "UNKNOWN";
67 }67 }
68 public String getKey(){68 public String getKey(){
69 return new String(Util.toBase64(key, 0, key.length));69 return Util.byte2str(Util.toBase64(key, 0, key.length));
70 }70 }
71 public String getFingerPrint(JSch jsch){71 public String getFingerPrint(JSch jsch){
72 HASH hash=null;72 HASH hash=null;
7373
=== modified file 'src/main/java/com/jcraft/jsch/HostKeyRepository.java'
--- src/com/jcraft/jsch/HostKeyRepository.java 2010-06-27 23:17:34 +0000
+++ src/main/java/com/jcraft/jsch/HostKeyRepository.java 2012-05-04 10:23:17 +0000
@@ -1,6 +1,6 @@
1/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */1/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
2/*2/*
3Copyright (c) 2004-2009 ymnk, JCraft,Inc. All rights reserved.3Copyright (c) 2004-2012 ymnk, JCraft,Inc. All rights reserved.
44
5Redistribution and use in source and binary forms, with or without5Redistribution and use in source and binary forms, with or without
6modification, are permitted provided that the following conditions are met:6modification, are permitted provided that the following conditions are met:
77
=== modified file 'src/main/java/com/jcraft/jsch/IO.java'
--- src/com/jcraft/jsch/IO.java 2010-06-27 23:17:34 +0000
+++ src/main/java/com/jcraft/jsch/IO.java 2012-05-04 10:23:17 +0000
@@ -1,6 +1,6 @@
1/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */1/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
2/*2/*
3Copyright (c) 2002-2009 ymnk, JCraft,Inc. All rights reserved.3Copyright (c) 2002-2012 ymnk, JCraft,Inc. All rights reserved.
44
5Redistribution and use in source and binary forms, with or without5Redistribution and use in source and binary forms, with or without
6modification, are permitted provided that the following conditions are met:6modification, are permitted provided that the following conditions are met:
77
=== modified file 'src/main/java/com/jcraft/jsch/Identity.java'
--- src/com/jcraft/jsch/Identity.java 2010-06-27 23:17:34 +0000
+++ src/main/java/com/jcraft/jsch/Identity.java 2012-05-04 10:23:17 +0000
@@ -1,6 +1,6 @@
1/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */1/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
2/*2/*
3Copyright (c) 2002-2009 ymnk, JCraft,Inc. All rights reserved.3Copyright (c) 2002-2012 ymnk, JCraft,Inc. All rights reserved.
44
5Redistribution and use in source and binary forms, with or without5Redistribution and use in source and binary forms, with or without
6modification, are permitted provided that the following conditions are met:6modification, are permitted provided that the following conditions are met:
77
=== modified file 'src/main/java/com/jcraft/jsch/IdentityFile.java'
--- src/com/jcraft/jsch/IdentityFile.java 2010-06-27 23:17:34 +0000
+++ src/main/java/com/jcraft/jsch/IdentityFile.java 2012-05-04 10:23:17 +0000
@@ -1,6 +1,6 @@
1/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */1/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
2/*2/*
3Copyright (c) 2002-2009 ymnk, JCraft,Inc. All rights reserved.3Copyright (c) 2002-2012 ymnk, JCraft,Inc. All rights reserved.
44
5Redistribution and use in source and binary forms, with or without5Redistribution and use in source and binary forms, with or without
6modification, are permitted provided that the following conditions are met:6modification, are permitted provided that the following conditions are met:
@@ -142,6 +142,47 @@
142 private IdentityFile(String name, byte[] prvkey, byte[] pubkey, JSch jsch) throws JSchException{142 private IdentityFile(String name, byte[] prvkey, byte[] pubkey, JSch jsch) throws JSchException{
143 this.identity=name;143 this.identity=name;
144 this.jsch=jsch;144 this.jsch=jsch;
145
146 // prvkey from "ssh-add" command on the remote.
147 if(pubkey==null &&
148 prvkey!=null &&
149 (prvkey.length>11 &&
150 prvkey[0]==0 && prvkey[1]==0 && prvkey[2]==0 && prvkey[3]==7)){
151
152 Buffer buf=new Buffer(prvkey);
153 String _type = new String(buf.getString()); // ssh-rsa
154
155 if(_type.equals("ssh-rsa")){
156 type=RSA;
157 n_array=buf.getString();
158 e_array=buf.getString();
159 d_array=buf.getString();
160 buf.getString();
161 buf.getString();
162 buf.getString();
163 this.identity += new String(buf.getString());
164 }
165 else if(_type.equals("ssh-dss")){
166 type=DSS;
167 P_array=buf.getString();
168 Q_array=buf.getString();
169 G_array=buf.getString();
170 pub_array=buf.getString();
171 prv_array=buf.getString();
172 this.identity += new String(buf.getString());
173 }
174 else{
175 throw new JSchException("privatekey: invalid key "+new String(prvkey, 4, 7));
176 }
177 encoded_data=prvkey;
178 encrypted=false;
179 keytype=OPENSSH;
180 return;
181 }
182
183 /* TODO: IdentityFile should use KeyPair.
184 * The following logic exists also in KeyPair. It is redundant.
185 */
145 try{186 try{
146 Class c;187 Class c;
147 c=Class.forName((String)jsch.getConfig("3des-cbc"));188 c=Class.forName((String)jsch.getConfig("3des-cbc"));
@@ -156,8 +197,18 @@
156 int len=buf.length;197 int len=buf.length;
157198
158 int i=0;199 int i=0;
159 while(i<len){200
160 if(buf[i]=='B'&& buf[i+1]=='E'&& buf[i+2]=='G'&& buf[i+3]=='I'){201 while(i<len){
202 if(buf[i] == '-' && i+4<len &&
203 buf[i+1] == '-' && buf[i+2] == '-' &&
204 buf[i+3] == '-' && buf[i+4] == '-'){
205 break;
206 }
207 i++;
208 }
209
210 while(i<len){
211 if(buf[i]=='B'&& i+3<len && buf[i+1]=='E'&& buf[i+2]=='G'&& buf[i+3]=='I'){
161 i+=6; 212 i+=6;
162 if(buf[i]=='D'&& buf[i+1]=='S'&& buf[i+2]=='A'){ type=DSS; }213 if(buf[i]=='D'&& buf[i+1]=='S'&& buf[i+2]=='A'){ type=DSS; }
163 else if(buf[i]=='R'&& buf[i+1]=='S'&& buf[i+2]=='A'){ type=RSA; }214 else if(buf[i]=='R'&& buf[i+1]=='S'&& buf[i+2]=='A'){ type=RSA; }
@@ -172,7 +223,7 @@
172 i+=3;223 i+=3;
173 continue;224 continue;
174 }225 }
175 if(buf[i]=='A'&& buf[i+1]=='E'&& buf[i+2]=='S'&& buf[i+3]=='-' && 226 if(buf[i]=='A'&& i+7<len && buf[i+1]=='E'&& buf[i+2]=='S'&& buf[i+3]=='-' &&
176 buf[i+4]=='2'&& buf[i+5]=='5'&& buf[i+6]=='6'&& buf[i+7]=='-'){227 buf[i+4]=='2'&& buf[i+5]=='5'&& buf[i+6]=='6'&& buf[i+7]=='-'){
177 i+=8;228 i+=8;
178 if(Session.checkCipher((String)jsch.getConfig("aes256-cbc"))){229 if(Session.checkCipher((String)jsch.getConfig("aes256-cbc"))){
@@ -186,7 +237,35 @@
186 }237 }
187 continue;238 continue;
188 }239 }
189 if(buf[i]=='C'&& buf[i+1]=='B'&& buf[i+2]=='C'&& buf[i+3]==','){240 if(buf[i]=='A'&& i+7<len && buf[i+1]=='E'&& buf[i+2]=='S'&& buf[i+3]=='-' &&
241 buf[i+4]=='1'&& buf[i+5]=='9'&& buf[i+6]=='2'&& buf[i+7]=='-'){
242 i+=8;
243 if(Session.checkCipher((String)jsch.getConfig("aes192-cbc"))){
244 c=Class.forName((String)jsch.getConfig("aes192-cbc"));
245 cipher=(Cipher)(c.newInstance());
246 key=new byte[cipher.getBlockSize()];
247 iv=new byte[cipher.getIVSize()];
248 }
249 else{
250 throw new JSchException("privatekey: aes192-cbc is not available "+identity);
251 }
252 continue;
253 }
254 if(buf[i]=='A'&& i+7<len && buf[i+1]=='E'&& buf[i+2]=='S'&& buf[i+3]=='-' &&
255 buf[i+4]=='1'&& buf[i+5]=='2'&& buf[i+6]=='8'&& buf[i+7]=='-'){
256 i+=8;
257 if(Session.checkCipher((String)jsch.getConfig("aes128-cbc"))){
258 c=Class.forName((String)jsch.getConfig("aes128-cbc"));
259 cipher=(Cipher)(c.newInstance());
260 key=new byte[cipher.getBlockSize()];
261 iv=new byte[cipher.getIVSize()];
262 }
263 else{
264 throw new JSchException("privatekey: aes128-cbc is not available "+identity);
265 }
266 continue;
267 }
268 if(buf[i]=='C'&& i+3<len && buf[i+1]=='B'&& buf[i+2]=='C'&& buf[i+3]==','){
190 i+=4;269 i+=4;
191 for(int ii=0; ii<iv.length; ii++){270 for(int ii=0; ii<iv.length; ii++){
192 iv[ii]=(byte)(((a2b(buf[i++])<<4)&0xf0)+271 iv[ii]=(byte)(((a2b(buf[i++])<<4)&0xf0)+
@@ -194,19 +273,18 @@
194 }273 }
195 continue;274 continue;
196 }275 }
197 if(buf[i]==0x0d &&276 if(buf[i]==0x0d && i+1<len && buf[i+1]==0x0a){
198 i+1<buf.length && buf[i+1]==0x0a){
199 i++;277 i++;
200 continue;278 continue;
201 }279 }
202 if(buf[i]==0x0a && i+1<buf.length){280 if(buf[i]==0x0a && i+1<len){
203 if(buf[i+1]==0x0a){ i+=2; break; }281 if(buf[i+1]==0x0a){ i+=2; break; }
204 if(buf[i+1]==0x0d &&282 if(buf[i+1]==0x0d &&
205 i+2<buf.length && buf[i+2]==0x0a){283 i+2<len && buf[i+2]==0x0a){
206 i+=3; break;284 i+=3; break;
207 }285 }
208 boolean inheader=false;286 boolean inheader=false;
209 for(int j=i+1; j<buf.length; j++){287 for(int j=i+1; j<len; j++){
210 if(buf[j]==0x0a) break;288 if(buf[j]==0x0a) break;
211 //if(buf[j]==0x0d) break;289 //if(buf[j]==0x0d) break;
212 if(buf[j]==':'){inheader=true; break;}290 if(buf[j]==':'){inheader=true; break;}
@@ -254,7 +332,7 @@
254 byte[]_type=_buf.getString();332 byte[]_type=_buf.getString();
255 //System.err.println("type: "+new String(_type)); 333 //System.err.println("type: "+new String(_type));
256 byte[] _cipher=_buf.getString();334 byte[] _cipher=_buf.getString();
257 String cipher=new String(_cipher);335 String cipher=Util.byte2str(_cipher);
258 //System.err.println("cipher: "+cipher); 336 //System.err.println("cipher: "+cipher);
259 if(cipher.equals("3des-cbc")){337 if(cipher.equals("3des-cbc")){
260 _buf.getInt();338 _buf.getInt();
@@ -421,7 +499,7 @@
421 Buffer buf=new Buffer("ssh-rsa".length()+4+499 Buffer buf=new Buffer("ssh-rsa".length()+4+
422 e_array.length+4+ 500 e_array.length+4+
423 n_array.length+4);501 n_array.length+4);
424 buf.putString("ssh-rsa".getBytes());502 buf.putString(Util.str2byte("ssh-rsa"));
425 buf.putString(e_array);503 buf.putString(e_array);
426 buf.putString(n_array);504 buf.putString(n_array);
427 return buf.buffer;505 return buf.buffer;
@@ -434,7 +512,7 @@
434 Q_array.length+4+ 512 Q_array.length+4+
435 G_array.length+4+ 513 G_array.length+4+
436 pub_array.length+4);514 pub_array.length+4);
437 buf.putString("ssh-dss".getBytes());515 buf.putString(Util.str2byte("ssh-dss"));
438 buf.putString(P_array);516 buf.putString(P_array);
439 buf.putString(Q_array);517 buf.putString(Q_array);
440 buf.putString(G_array);518 buf.putString(G_array);
@@ -459,7 +537,7 @@
459 byte[] sig = rsa.sign();537 byte[] sig = rsa.sign();
460 Buffer buf=new Buffer("ssh-rsa".length()+4+538 Buffer buf=new Buffer("ssh-rsa".length()+4+
461 sig.length+4);539 sig.length+4);
462 buf.putString("ssh-rsa".getBytes());540 buf.putString(Util.str2byte("ssh-rsa"));
463 buf.putString(sig);541 buf.putString(sig);
464 return buf.buffer;542 return buf.buffer;
465 }543 }
@@ -502,7 +580,7 @@
502 byte[] sig = dsa.sign();580 byte[] sig = dsa.sign();
503 Buffer buf=new Buffer("ssh-dss".length()+4+581 Buffer buf=new Buffer("ssh-dss".length()+4+
504 sig.length+4);582 sig.length+4);
505 buf.putString("ssh-dss".getBytes());583 buf.putString(Util.str2byte("ssh-dss"));
506 buf.putString(sig);584 buf.putString(sig);
507 return buf.buffer;585 return buf.buffer;
508 }586 }
509587
=== added file 'src/main/java/com/jcraft/jsch/IdentityRepository.java'
--- src/main/java/com/jcraft/jsch/IdentityRepository.java 1970-01-01 00:00:00 +0000
+++ src/main/java/com/jcraft/jsch/IdentityRepository.java 2012-05-04 10:23:17 +0000
@@ -0,0 +1,44 @@
1/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
2/*
3Copyright (c) 2012 ymnk, JCraft,Inc. All rights reserved.
4
5Redistribution and use in source and binary forms, with or without
6modification, are permitted provided that the following conditions are met:
7
8 1. Redistributions of source code must retain the above copyright notice,
9 this list of conditions and the following disclaimer.
10
11 2. Redistributions in binary form must reproduce the above copyright
12 notice, this list of conditions and the following disclaimer in
13 the documentation and/or other materials provided with the distribution.
14
15 3. The names of the authors may not be used to endorse or promote products
16 derived from this software without specific prior written permission.
17
18THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
19INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
20FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
21INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
22INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
24OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
25LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
26NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
27EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28*/
29
30package com.jcraft.jsch;
31
32import java.util.Vector;
33
34public interface IdentityRepository {
35 public static final int UNAVAILABLE=0;
36 public static final int NOTRUNNING=1;
37 public static final int RUNNING=2;
38 public String getName();
39 public int getStatus();
40 public Vector getIdentities();
41 public boolean add(byte[] identity);
42 public boolean remove(byte[] blob);
43 public void removeAll();
44}
045
=== modified file 'src/main/java/com/jcraft/jsch/JSch.java'
--- src/com/jcraft/jsch/JSch.java 2010-06-27 23:17:34 +0000
+++ src/main/java/com/jcraft/jsch/JSch.java 2012-05-04 10:23:17 +0000
@@ -1,6 +1,6 @@
1/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */1/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
2/*2/*
3Copyright (c) 2002-2009 ymnk, JCraft,Inc. All rights reserved.3Copyright (c) 2002-2012 ymnk, JCraft,Inc. All rights reserved.
44
5Redistribution and use in source and binary forms, with or without5Redistribution and use in source and binary forms, with or without
6modification, are permitted provided that the following conditions are met:6modification, are permitted provided that the following conditions are met:
@@ -33,12 +33,15 @@
33import java.util.Vector;33import java.util.Vector;
3434
35public class JSch{35public class JSch{
36 /**
37 * The version number.
38 */
39 public static final String VERSION = "0.1.48";
40
36 static java.util.Hashtable config=new java.util.Hashtable();41 static java.util.Hashtable config=new java.util.Hashtable();
37 static{42 static{
38// config.put("kex", "diffie-hellman-group-exchange-sha1");43 config.put("kex", "diffie-hellman-group1-sha1,diffie-hellman-group14-sha1,diffie-hellman-group-exchange-sha1");
39 config.put("kex", "diffie-hellman-group1-sha1,diffie-hellman-group-exchange-sha1");
40 config.put("server_host_key", "ssh-rsa,ssh-dss");44 config.put("server_host_key", "ssh-rsa,ssh-dss");
41// config.put("server_host_key", "ssh-dss,ssh-rsa");
4245
43 config.put("cipher.s2c", 46 config.put("cipher.s2c",
44 "aes128-ctr,aes128-cbc,3des-ctr,3des-cbc,blowfish-cbc,aes192-cbc,aes256-cbc");47 "aes128-ctr,aes128-cbc,3des-ctr,3des-cbc,blowfish-cbc,aes192-cbc,aes256-cbc");
@@ -48,9 +51,7 @@
48 config.put("mac.s2c", "hmac-md5,hmac-sha1,hmac-sha1-96,hmac-md5-96");51 config.put("mac.s2c", "hmac-md5,hmac-sha1,hmac-sha1-96,hmac-md5-96");
49 config.put("mac.c2s", "hmac-md5,hmac-sha1,hmac-sha1-96,hmac-md5-96");52 config.put("mac.c2s", "hmac-md5,hmac-sha1,hmac-sha1-96,hmac-md5-96");
50 config.put("compression.s2c", "none");53 config.put("compression.s2c", "none");
51 // config.put("compression.s2c", "zlib@openssh.com,zlib,none");
52 config.put("compression.c2s", "none");54 config.put("compression.c2s", "none");
53 // config.put("compression.c2s", "zlib@openssh.com,zlib,none");
5455
55 config.put("lang.s2c", "");56 config.put("lang.s2c", "");
56 config.put("lang.c2s", "");57 config.put("lang.c2s", "");
@@ -61,6 +62,8 @@
61 "com.jcraft.jsch.DHGEX");62 "com.jcraft.jsch.DHGEX");
62 config.put("diffie-hellman-group1-sha1", 63 config.put("diffie-hellman-group1-sha1",
63 "com.jcraft.jsch.DHG1");64 "com.jcraft.jsch.DHG1");
65 config.put("diffie-hellman-group14-sha1",
66 "com.jcraft.jsch.DHG14");
6467
65 config.put("dh", "com.jcraft.jsch.jce.DH");68 config.put("dh", "com.jcraft.jsch.jce.DH");
66 config.put("3des-cbc", "com.jcraft.jsch.jce.TripleDESCBC");69 config.put("3des-cbc", "com.jcraft.jsch.jce.TripleDESCBC");
@@ -103,13 +106,44 @@
103106
104 config.put("StrictHostKeyChecking", "ask");107 config.put("StrictHostKeyChecking", "ask");
105 config.put("HashKnownHosts", "no");108 config.put("HashKnownHosts", "no");
106 //config.put("HashKnownHosts", "yes");109
107 config.put("PreferredAuthentications", "gssapi-with-mic,publickey,keyboard-interactive,password");110 config.put("PreferredAuthentications", "gssapi-with-mic,publickey,keyboard-interactive,password");
108111
109 config.put("CheckCiphers", "aes256-ctr,aes192-ctr,aes128-ctr,aes256-cbc,aes192-cbc,aes128-cbc,3des-ctr,arcfour,arcfour128,arcfour256");112 config.put("CheckCiphers", "aes256-ctr,aes192-ctr,aes128-ctr,aes256-cbc,aes192-cbc,aes128-cbc,3des-ctr,arcfour,arcfour128,arcfour256");
110 }113 config.put("CheckKexes", "diffie-hellman-group14-sha1");
111 java.util.Vector pool=new java.util.Vector();114
112 java.util.Vector identities=new java.util.Vector();115 config.put("MaxAuthTries", "6");
116 }
117
118 private java.util.Vector sessionPool = new java.util.Vector();
119
120 private IdentityRepository defaultIdentityRepository =
121 new LocalIdentityRepository(this);
122
123 private IdentityRepository identityRepository = defaultIdentityRepository;
124
125 /**
126 * Sets the <code>identityRepository</code>, which will be referred
127 * in the public key authentication.
128 *
129 * @param identityRepository if <code>null</code> is given,
130 * the default repository, which usually refers to ~/.ssh/, will be used.
131 *
132 * @see #getIdentityRepository()
133 */
134 public synchronized void setIdentityRepository(IdentityRepository identityRepository){
135 if(identityRepository == null){
136 this.identityRepository = defaultIdentityRepository;
137 }
138 else{
139 this.identityRepository = identityRepository;
140 }
141 }
142
143 synchronized IdentityRepository getIdentityRepository(){
144 return this.identityRepository;
145 }
146
113 private HostKeyRepository known_hosts=null;147 private HostKeyRepository known_hosts=null;
114148
115 private static final Logger DEVNULL=new Logger(){149 private static final Logger DEVNULL=new Logger(){
@@ -134,7 +168,47 @@
134168
135 }169 }
136170
137 public Session getSession(String username, String host) throws JSchException { return getSession(username, host, 22); }171 /**
172 * Instantiates the <code>Session</code> object with
173 * <code>username</code> and <code>host</code>.
174 * The TCP port 22 will be used in making the connection.
175 * Note that the TCP connection must not be established
176 * until Session#connect().
177 *
178 * @param username user name
179 * @param host hostname
180 *
181 * @throws JSchException
182 * if <code>username</code> or <code>host</code> are invalid.
183 *
184 * @return the instance of <code>Session</code> class.
185 *
186 * @see #getSession(String username, String host, int port)
187 * @see com.jcraft.jsch.Session
188 */
189 public Session getSession(String username, String host)
190 throws JSchException {
191 return getSession(username, host, 22);
192 }
193
194 /**
195 * Instantiates the <code>Session</code> object with given
196 * <code>username</code>, <code>host</code> and <code>port</code>.
197 * Note that the TCP connection must not be established
198 * until Session#connect().
199 *
200 * @param username user name
201 * @param host hostname
202 * @param post port number
203 *
204 * @throws JSchException
205 * if <code>username</code> or <code>host</code> are invalid.
206 *
207 * @return the instance of <code>Session</code> class.
208 *
209 * @see #getSession(String username, String host, int port)
210 * @see com.jcraft.jsch.Session
211 */
138 public Session getSession(String username, String host, int port) throws JSchException {212 public Session getSession(String username, String host, int port) throws JSchException {
139 if(username==null){213 if(username==null){
140 throw new JSchException("username must not be null.");214 throw new JSchException("username must not be null.");
@@ -146,25 +220,44 @@
146 s.setUserName(username);220 s.setUserName(username);
147 s.setHost(host);221 s.setHost(host);
148 s.setPort(port);222 s.setPort(port);
149 //pool.addElement(s);
150 return s;223 return s;
151 }224 }
152225
153 protected void addSession(Session session){226 protected void addSession(Session session){
154 synchronized(pool){227 synchronized(sessionPool){
155 pool.addElement(session);228 sessionPool.addElement(session);
156 }229 }
157 }230 }
158231
159 protected boolean removeSession(Session session){232 protected boolean removeSession(Session session){
160 synchronized(pool){233 synchronized(sessionPool){
161 return pool.remove(session);234 return sessionPool.remove(session);
162 }235 }
163 }236 }
237
238 /**
239 * Sets the hostkey repository.
240 *
241 * @param hkrepo
242 *
243 * @see com.jcraft.jsch.HostKeyRepository
244 * @see com.jcraft.jsch.KnownHosts
245 */
164 public void setHostKeyRepository(HostKeyRepository hkrepo){246 public void setHostKeyRepository(HostKeyRepository hkrepo){
165 known_hosts=hkrepo;247 known_hosts=hkrepo;
166 }248 }
167249
250 /**
251 * Sets the instance of <code>KnownHosts</code>, which refers
252 * to <code>filename</code>.
253 *
254 * @param filename filename of known_hosts file.
255 *
256 * @throws JSchException
257 * if the given filename is invalid.
258 *
259 * @see com.jcraft.jsch.KnownHosts
260 */
168 public void setKnownHosts(String filename) throws JSchException{261 public void setKnownHosts(String filename) throws JSchException{
169 if(known_hosts==null) known_hosts=new KnownHosts(this);262 if(known_hosts==null) known_hosts=new KnownHosts(this);
170 if(known_hosts instanceof KnownHosts){263 if(known_hosts instanceof KnownHosts){
@@ -174,6 +267,17 @@
174 }267 }
175 }268 }
176269
270 /**
271 * Sets the instance of <code>KnownHosts</code> generated with
272 * <code>stream</code>.
273 *
274 * @param stream the instance of InputStream from known_hosts file.
275 *
276 * @throws JSchException
277 * if an I/O error occurs.
278 *
279 * @see com.jcraft.jsch.KnownHosts
280 */
177 public void setKnownHosts(InputStream stream) throws JSchException{ 281 public void setKnownHosts(InputStream stream) throws JSchException{
178 if(known_hosts==null) known_hosts=new KnownHosts(this);282 if(known_hosts==null) known_hosts=new KnownHosts(this);
179 if(known_hosts instanceof KnownHosts){283 if(known_hosts instanceof KnownHosts){
@@ -183,15 +287,47 @@
183 }287 }
184 }288 }
185289
290 /**
291 * Returns the current hostkey repository.
292 * By the default, this method will the instance of <code>KnownHosts</code>.
293 *
294 * @return current hostkey repository.
295 *
296 * @see com.jcraft.jsch.HostKeyRepository
297 * @see com.jcraft.jsch.KnownHosts
298 */
186 public HostKeyRepository getHostKeyRepository(){ 299 public HostKeyRepository getHostKeyRepository(){
187 if(known_hosts==null) known_hosts=new KnownHosts(this);300 if(known_hosts==null) known_hosts=new KnownHosts(this);
188 return known_hosts; 301 return known_hosts;
189 }302 }
190303
304 /**
305 * Sets the private key, which will be referred in
306 * the public key authentication.
307 *
308 * @param prvkey filename of the private key.
309 *
310 * @throws JSchException if <code>prvkey</code> is invalid.
311 *
312 * @see #addIdentity(String prvkey, String passphrase)
313 */
191 public void addIdentity(String prvkey) throws JSchException{314 public void addIdentity(String prvkey) throws JSchException{
192 addIdentity(prvkey, (byte[])null);315 addIdentity(prvkey, (byte[])null);
193 }316 }
194317
318 /**
319 * Sets the private key, which will be referred in
320 * the public key authentication.
321 * Before registering it into identityRepository,
322 * it will be deciphered with <code>passphrase</code>.
323 *
324 * @param prvkey filename of the private key.
325 * @param passphrase passphrase for <code>prvkey</code>.
326 *
327 * @throws JSchException if <code>passphrase</code> is not right.
328 *
329 * @see #addIdentity(String prvkey, byte[] passphrase)
330 */
195 public void addIdentity(String prvkey, String passphrase) throws JSchException{331 public void addIdentity(String prvkey, String passphrase) throws JSchException{
196 byte[] _passphrase=null;332 byte[] _passphrase=null;
197 if(passphrase!=null){333 if(passphrase!=null){
@@ -202,20 +338,70 @@
202 Util.bzero(_passphrase);338 Util.bzero(_passphrase);
203 }339 }
204340
341 /**
342 * Sets the private key, which will be referred in
343 * the public key authentication.
344 * Before registering it into identityRepository,
345 * it will be deciphered with <code>passphrase</code>.
346 *
347 * @param prvkey filename of the private key.
348 * @param passphrase passphrase for <code>prvkey</code>.
349 *
350 * @throws JSchException if <code>passphrase</code> is not right.
351 *
352 * @see #addIdentity(String prvkey, String pubkey, byte[] passphrase)
353 */
205 public void addIdentity(String prvkey, byte[] passphrase) throws JSchException{354 public void addIdentity(String prvkey, byte[] passphrase) throws JSchException{
206 Identity identity=IdentityFile.newInstance(prvkey, null, this);355 Identity identity=IdentityFile.newInstance(prvkey, null, this);
207 addIdentity(identity, passphrase);356 addIdentity(identity, passphrase);
208 }357 }
358
359 /**
360 * Sets the private key, which will be referred in
361 * the public key authentication.
362 * Before registering it into identityRepository,
363 * it will be deciphered with <code>passphrase</code>.
364 *
365 * @param prvkey filename of the private key.
366 * @param pubkey filename of the public key.
367 * @param passphrase passphrase for <code>prvkey</code>.
368 *
369 * @throws JSchException if <code>passphrase</code> is not right.
370 */
209 public void addIdentity(String prvkey, String pubkey, byte[] passphrase) throws JSchException{371 public void addIdentity(String prvkey, String pubkey, byte[] passphrase) throws JSchException{
210 Identity identity=IdentityFile.newInstance(prvkey, pubkey, this);372 Identity identity=IdentityFile.newInstance(prvkey, pubkey, this);
211 addIdentity(identity, passphrase);373 addIdentity(identity, passphrase);
212 }374 }
213375
376 /**
377 * Sets the private key, which will be referred in
378 * the public key authentication.
379 * Before registering it into identityRepository,
380 * it will be deciphered with <code>passphrase</code>.
381 *
382 * @param name name of the identity to be used to
383 retrieve it in the identityRepository.
384 * @param prvkey private key in byte array.
385 * @param pubkey public key in byte array.
386 * @param passphrase passphrase for <code>prvkey</code>.
387 *
388 */
214 public void addIdentity(String name, byte[]prvkey, byte[]pubkey, byte[] passphrase) throws JSchException{389 public void addIdentity(String name, byte[]prvkey, byte[]pubkey, byte[] passphrase) throws JSchException{
215 Identity identity=IdentityFile.newInstance(name, prvkey, pubkey, this);390 Identity identity=IdentityFile.newInstance(name, prvkey, pubkey, this);
216 addIdentity(identity, passphrase);391 addIdentity(identity, passphrase);
217 }392 }
218393
394 /**
395 * Sets the private key, which will be referred in
396 * the public key authentication.
397 * Before registering it into identityRepository,
398 * it will be deciphered with <code>passphrase</code>.
399 *
400 * @param identity private key.
401 * @param passphrase passphrase for <code>identity</code>.
402 *
403 * @throws JSchException if <code>passphrase</code> is not right.
404 */
219 public void addIdentity(Identity identity, byte[] passphrase) throws JSchException{405 public void addIdentity(Identity identity, byte[] passphrase) throws JSchException{
220 if(passphrase!=null){406 if(passphrase!=null){
221 try{ 407 try{
@@ -228,53 +414,83 @@
228 Util.bzero(passphrase);414 Util.bzero(passphrase);
229 }415 }
230 }416 }
231 synchronized(identities){417
232 if(!identities.contains(identity)){418 if(identityRepository instanceof LocalIdentityRepository){
233 identities.addElement(identity);419 ((LocalIdentityRepository)identityRepository).add(identity);
234 }420 }
421 else {
422 // TODO
235 }423 }
236 }424 }
237425
426 /**
427 * @deprecated use #removeIdentity(Identity identity)
428 */
238 public void removeIdentity(String name) throws JSchException{429 public void removeIdentity(String name) throws JSchException{
239 synchronized(identities){430 Vector identities = identityRepository.getIdentities();
240 for(int i=0; i<identities.size(); i++){431 for(int i=0; i<identities.size(); i++){
241 Identity identity=(Identity)(identities.elementAt(i));432 Identity identity=(Identity)(identities.elementAt(i));
242 if(!identity.getName().equals(name))433 if(!identity.getName().equals(name))
243 continue;434 continue;
244 identities.removeElement(identity);435 identityRepository.remove(identity.getPublicKeyBlob());
245 identity.clear();436 break;
246 break;
247 }
248 }437 }
249 }438 }
250439
440 /**
441 * Removes the identity from identityRepository.
442 *
443 * @param identity the indentity to be removed.
444 *
445 * @throws JSchException if <code>identity</code> is invalid.
446 */
447 public void removeIdentity(Identity identity) throws JSchException{
448 identityRepository.remove(identity.getPublicKeyBlob());
449 }
450
451 /**
452 * Lists names of identities included in the identityRepository.
453 *
454 * @return names of identities
455 *
456 * @throws JSchException if identityReposory has problems.
457 */
251 public Vector getIdentityNames() throws JSchException{458 public Vector getIdentityNames() throws JSchException{
252 Vector foo=new Vector();459 Vector foo=new Vector();
253 synchronized(identities){460 Vector identities = identityRepository.getIdentities();
254 for(int i=0; i<identities.size(); i++){461 for(int i=0; i<identities.size(); i++){
255 Identity identity=(Identity)(identities.elementAt(i));462 Identity identity=(Identity)(identities.elementAt(i));
256 foo.addElement(identity.getName());463 foo.addElement(identity.getName());
257 }
258 }464 }
259 return foo;465 return foo;
260 }466 }
261467
468 /**
469 * Removes all identities from identityRepository.
470 *
471 * @throws JSchException if identityReposory has problems.
472 */
262 public void removeAllIdentity() throws JSchException{473 public void removeAllIdentity() throws JSchException{
263 synchronized(identities){474 identityRepository.removeAll();
264 Vector foo=getIdentityNames();
265 for(int i=0; i<foo.size(); i++){
266 String name=((String)foo.elementAt(i));
267 removeIdentity(name);
268 }
269 }
270 }475 }
271476
477 /**
478 * Returns the config value for the specified key.
479 *
480 * @param key key for the configuration.
481 * @return config value
482 */
272 public static String getConfig(String key){ 483 public static String getConfig(String key){
273 synchronized(config){484 synchronized(config){
274 return (String)(config.get(key));485 return (String)(config.get(key));
275 } 486 }
276 }487 }
277488
489 /**
490 * Sets or Overrides the configuration.
491 *
492 * @param newconf configurations
493 */
278 public static void setConfig(java.util.Hashtable newconf){494 public static void setConfig(java.util.Hashtable newconf){
279 synchronized(config){495 synchronized(config){
280 for(java.util.Enumeration e=newconf.keys() ; e.hasMoreElements() ;) {496 for(java.util.Enumeration e=newconf.keys() ; e.hasMoreElements() ;) {
@@ -284,14 +500,28 @@
284 }500 }
285 }501 }
286502
503 /**
504 * Sets or Overrides the configuration.
505 *
506 * @param key key for the configuration
507 * @param value value for the configuration
508 */
287 public static void setConfig(String key, String value){509 public static void setConfig(String key, String value){
288 config.put(key, value);510 config.put(key, value);
289 }511 }
290512
513 /**
514 * Sets the logger
515 *
516 * @param logger logger
517 *
518 * @see com.jcraft.jsch.Logger
519 */
291 public static void setLogger(Logger logger){520 public static void setLogger(Logger logger){
292 if(logger==null) JSch.logger=DEVNULL;521 if(logger==null) logger=DEVNULL;
293 JSch.logger=logger;522 JSch.logger=logger;
294 }523 }
524
295 static Logger getLogger(){525 static Logger getLogger(){
296 return logger;526 return logger;
297 }527 }
298528
=== modified file 'src/main/java/com/jcraft/jsch/JSchAuthCancelException.java'
--- src/com/jcraft/jsch/JSchAuthCancelException.java 2010-06-27 23:17:34 +0000
+++ src/main/java/com/jcraft/jsch/JSchAuthCancelException.java 2012-05-04 10:23:17 +0000
@@ -1,6 +1,6 @@
1/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */1/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
2/*2/*
3Copyright (c) 2002-2009 ymnk, JCraft,Inc. All rights reserved.3Copyright (c) 2002-2012 ymnk, JCraft,Inc. All rights reserved.
44
5Redistribution and use in source and binary forms, with or without5Redistribution and use in source and binary forms, with or without
6modification, are permitted provided that the following conditions are met:6modification, are permitted provided that the following conditions are met:
77
=== modified file 'src/main/java/com/jcraft/jsch/JSchException.java'
--- src/com/jcraft/jsch/JSchException.java 2010-06-27 23:17:34 +0000
+++ src/main/java/com/jcraft/jsch/JSchException.java 2012-05-04 10:23:17 +0000
@@ -1,6 +1,6 @@
1/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */1/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
2/*2/*
3Copyright (c) 2002-2009 ymnk, JCraft,Inc. All rights reserved.3Copyright (c) 2002-2012 ymnk, JCraft,Inc. All rights reserved.
44
5Redistribution and use in source and binary forms, with or without5Redistribution and use in source and binary forms, with or without
6modification, are permitted provided that the following conditions are met:6modification, are permitted provided that the following conditions are met:
77
=== modified file 'src/main/java/com/jcraft/jsch/JSchPartialAuthException.java'
--- src/com/jcraft/jsch/JSchPartialAuthException.java 2010-06-27 23:17:34 +0000
+++ src/main/java/com/jcraft/jsch/JSchPartialAuthException.java 2012-05-04 10:23:17 +0000
@@ -1,6 +1,6 @@
1/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */1/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
2/*2/*
3Copyright (c) 2002-2009 ymnk, JCraft,Inc. All rights reserved.3Copyright (c) 2002-2012 ymnk, JCraft,Inc. All rights reserved.
44
5Redistribution and use in source and binary forms, with or without5Redistribution and use in source and binary forms, with or without
6modification, are permitted provided that the following conditions are met:6modification, are permitted provided that the following conditions are met:
77
=== modified file 'src/main/java/com/jcraft/jsch/KeyExchange.java'
--- src/com/jcraft/jsch/KeyExchange.java 2010-06-27 23:17:34 +0000
+++ src/main/java/com/jcraft/jsch/KeyExchange.java 2012-05-04 10:23:17 +0000
@@ -1,6 +1,6 @@
1/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */1/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
2/*2/*
3Copyright (c) 2002-2009 ymnk, JCraft,Inc. All rights reserved.3Copyright (c) 2002-2012 ymnk, JCraft,Inc. All rights reserved.
44
5Redistribution and use in source and binary forms, with or without5Redistribution and use in source and binary forms, with or without
6modification, are permitted provided that the following conditions are met:6modification, are permitted provided that the following conditions are met:
@@ -85,36 +85,41 @@
85 */85 */
8686
87 protected static String[] guess(byte[]I_S, byte[]I_C){87 protected static String[] guess(byte[]I_S, byte[]I_C){
88//System.err.println("guess: ");
89 String[] guess=new String[PROPOSAL_MAX];88 String[] guess=new String[PROPOSAL_MAX];
90 Buffer sb=new Buffer(I_S); sb.setOffSet(17);89 Buffer sb=new Buffer(I_S); sb.setOffSet(17);
91 Buffer cb=new Buffer(I_C); cb.setOffSet(17);90 Buffer cb=new Buffer(I_C); cb.setOffSet(17);
9291
92 if(JSch.getLogger().isEnabled(Logger.INFO)){
93 for(int i=0; i<PROPOSAL_MAX; i++){
94 JSch.getLogger().log(Logger.INFO,
95 "kex: server: "+Util.byte2str(sb.getString()));
96 }
97 for(int i=0; i<PROPOSAL_MAX; i++){
98 JSch.getLogger().log(Logger.INFO,
99 "kex: client: "+Util.byte2str(cb.getString()));
100 }
101 sb.setOffSet(17);
102 cb.setOffSet(17);
103 }
104
93 for(int i=0; i<PROPOSAL_MAX; i++){105 for(int i=0; i<PROPOSAL_MAX; i++){
94 byte[] sp=sb.getString(); // server proposal106 byte[] sp=sb.getString(); // server proposal
95 byte[] cp=cb.getString(); // client proposal107 byte[] cp=cb.getString(); // client proposal
96
97//System.err.println("server-proposal: |"+new String(sp)+"|");
98//System.err.println("client-proposal: |"+new String(cp)+"|");
99
100 int j=0;108 int j=0;
101 int k=0;109 int k=0;
102//System.err.println(new String(cp));110
103 loop:111 loop:
104 while(j<cp.length){112 while(j<cp.length){
105 while(j<cp.length && cp[j]!=',')j++; 113 while(j<cp.length && cp[j]!=',')j++;
106 if(k==j) return null;114 if(k==j) return null;
107 String algorithm=new String(cp, k, j-k);115 String algorithm=Util.byte2str(cp, k, j-k);
108//System.err.println("algorithm: "+algorithm);
109 int l=0;116 int l=0;
110 int m=0;117 int m=0;
111 while(l<sp.length){118 while(l<sp.length){
112 while(l<sp.length && sp[l]!=',')l++; 119 while(l<sp.length && sp[l]!=',')l++;
113 if(m==l) return null;120 if(m==l) return null;
114//System.err.println(" "+new String(sp, m, l-m));121 if(algorithm.equals(Util.byte2str(sp, m, l-m))){
115 if(algorithm.equals(new String(sp, m, l-m))){
116 guess[i]=algorithm;122 guess[i]=algorithm;
117//System.err.println(" "+algorithm);
118 break loop;123 break loop;
119 }124 }
120 l++;125 l++;
@@ -127,7 +132,6 @@
127 guess[i]="";132 guess[i]="";
128 }133 }
129 else if(guess[i]==null){134 else if(guess[i]==null){
130//System.err.println(" fail");
131 return null;135 return null;
132 }136 }
133 }137 }
@@ -145,10 +149,6 @@
145 " "+guess[PROPOSAL_COMP_ALGS_CTOS]);149 " "+guess[PROPOSAL_COMP_ALGS_CTOS]);
146 }150 }
147151
148// for(int i=0; i<PROPOSAL_MAX; i++){
149// System.err.println("guess: ["+guess[i]+"]");
150// }
151
152 return guess;152 return guess;
153 }153 }
154154
155155
=== modified file 'src/main/java/com/jcraft/jsch/KeyPair.java'
--- src/com/jcraft/jsch/KeyPair.java 2010-06-27 23:17:34 +0000
+++ src/main/java/com/jcraft/jsch/KeyPair.java 2012-05-04 10:23:17 +0000
@@ -1,6 +1,6 @@
1/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */1/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
2/*2/*
3Copyright (c) 2002-2009 ymnk, JCraft,Inc. All rights reserved.3Copyright (c) 2002-2012 ymnk, JCraft,Inc. All rights reserved.
44
5Redistribution and use in source and binary forms, with or without5Redistribution and use in source and binary forms, with or without
6modification, are permitted provided that the following conditions are met:6modification, are permitted provided that the following conditions are met:
@@ -43,7 +43,7 @@
43 static final int VENDOR_FSECURE=1;43 static final int VENDOR_FSECURE=1;
44 int vendor=VENDOR_OPENSSH;44 int vendor=VENDOR_OPENSSH;
4545
46 private static final byte[] cr="\n".getBytes();46 private static final byte[] cr=Util.str2byte("\n");
4747
48 public static KeyPair genKeyPair(JSch jsch, int type) throws JSchException{48 public static KeyPair genKeyPair(JSch jsch, int type) throws JSchException{
49 return genKeyPair(jsch, type, 1024);49 return genKeyPair(jsch, type, 1024);
@@ -64,6 +64,11 @@
64 abstract byte[] getEnd();64 abstract byte[] getEnd();
65 abstract int getKeySize();65 abstract int getKeySize();
6666
67 public String getPublicKeyComment(){
68 return publicKeyComment;
69 }
70 private String publicKeyComment = "";
71
67 JSch jsch=null;72 JSch jsch=null;
68 private Cipher cipher;73 private Cipher cipher;
69 private HASH hash;74 private HASH hash;
@@ -75,8 +80,8 @@
75 this.jsch=jsch;80 this.jsch=jsch;
76 }81 }
7782
78 static byte[][] header={"Proc-Type: 4,ENCRYPTED".getBytes(),83 static byte[][] header={Util.str2byte("Proc-Type: 4,ENCRYPTED"),
79 "DEK-Info: DES-EDE3-CBC,".getBytes()};84 Util.str2byte("DEK-Info: DES-EDE3-CBC,")};
8085
81 abstract byte[] getPrivateKey();86 abstract byte[] getPrivateKey();
8287
@@ -120,7 +125,7 @@
120 }125 }
121 }126 }
122127
123 private static byte[] space=" ".getBytes();128 private static byte[] space=Util.str2byte(" ");
124129
125 abstract byte[] getKeyTypeName();130 abstract byte[] getKeyTypeName();
126 public abstract int getKeyType();131 public abstract int getKeyType();
@@ -133,7 +138,7 @@
133 try{138 try{
134 out.write(getKeyTypeName()); out.write(space);139 out.write(getKeyTypeName()); out.write(space);
135 out.write(pub, 0, pub.length); out.write(space);140 out.write(pub, 0, pub.length); out.write(space);
136 out.write(comment.getBytes());141 out.write(Util.str2byte(comment));
137 out.write(cr);142 out.write(cr);
138 }143 }
139 catch(Exception e){144 catch(Exception e){
@@ -150,8 +155,8 @@
150 byte[] pubblob=getPublicKeyBlob();155 byte[] pubblob=getPublicKeyBlob();
151 byte[] pub=Util.toBase64(pubblob, 0, pubblob.length);156 byte[] pub=Util.toBase64(pubblob, 0, pubblob.length);
152 try{157 try{
153 out.write("---- BEGIN SSH2 PUBLIC KEY ----".getBytes()); out.write(cr);158 out.write(Util.str2byte("---- BEGIN SSH2 PUBLIC KEY ----")); out.write(cr);
154 out.write(("Comment: \""+comment+"\"").getBytes()); out.write(cr);159 out.write(Util.str2byte("Comment: \""+comment+"\"")); out.write(cr);
155 int index=0;160 int index=0;
156 while(index<pub.length){161 while(index<pub.length){
157 int len=70;162 int len=70;
@@ -159,7 +164,7 @@
159 out.write(pub, index, len); out.write(cr);164 out.write(pub, index, len); out.write(cr);
160 index+=len;165 index+=len;
161 }166 }
162 out.write("---- END SSH2 PUBLIC KEY ----".getBytes()); out.write(cr);167 out.write(Util.str2byte("---- END SSH2 PUBLIC KEY ----")); out.write(cr);
163 }168 }
164 catch(Exception e){169 catch(Exception e){
165 }170 }
@@ -335,7 +340,7 @@
335 for(int index=0; index+hsize<=hn.length;){340 for(int index=0; index+hsize<=hn.length;){
336 if(tmp!=null){ hash.update(tmp, 0, tmp.length); }341 if(tmp!=null){ hash.update(tmp, 0, tmp.length); }
337 hash.update(passphrase, 0, passphrase.length);342 hash.update(passphrase, 0, passphrase.length);
338 hash.update(iv, 0, iv.length);343 hash.update(iv, 0, iv.length > 8 ? 8: iv.length);
339 tmp=hash.digest();344 tmp=hash.digest();
340 System.arraycopy(tmp, 0, hn, index, tmp.length);345 System.arraycopy(tmp, 0, hn, index, tmp.length);
341 index+=tmp.length;346 index+=tmp.length;
@@ -420,6 +425,8 @@
420425
421 int type=ERROR;426 int type=ERROR;
422 int vendor=VENDOR_OPENSSH;427 int vendor=VENDOR_OPENSSH;
428 String publicKeyComment = "";
429 Cipher cipher=null;
423430
424 try{431 try{
425 File file=new File(prvkey);432 File file=new File(prvkey);
@@ -437,7 +444,16 @@
437 int i=0;444 int i=0;
438445
439 while(i<len){446 while(i<len){
440 if(buf[i]=='B'&& buf[i+1]=='E'&& buf[i+2]=='G'&& buf[i+3]=='I'){447 if(buf[i] == '-' && i+4<len &&
448 buf[i+1] == '-' && buf[i+2] == '-' &&
449 buf[i+3] == '-' && buf[i+4] == '-'){
450 break;
451 }
452 i++;
453 }
454
455 while(i<len){
456 if(buf[i]=='B'&& i+3<len && buf[i+1]=='E'&& buf[i+2]=='G'&& buf[i+3]=='I'){
441 i+=6; 457 i+=6;
442 if(buf[i]=='D'&& buf[i+1]=='S'&& buf[i+2]=='A'){ type=DSA; }458 if(buf[i]=='D'&& buf[i+1]=='S'&& buf[i+2]=='A'){ type=DSA; }
443 else if(buf[i]=='R'&& buf[i+1]=='S'&& buf[i+2]=='A'){ type=RSA; }459 else if(buf[i]=='R'&& buf[i+1]=='S'&& buf[i+2]=='A'){ type=RSA; }
@@ -446,21 +462,61 @@
446 vendor=VENDOR_FSECURE;462 vendor=VENDOR_FSECURE;
447 }463 }
448 else{464 else{
449 //System.err.println("invalid format: "+identity);
450 throw new JSchException("invalid privatekey: "+prvkey);465 throw new JSchException("invalid privatekey: "+prvkey);
451 }466 }
452 i+=3;467 i+=3;
453 continue;468 continue;
454 }469 }
455 if(buf[i]=='C'&& buf[i+1]=='B'&& buf[i+2]=='C'&& buf[i+3]==','){470 if(buf[i]=='A'&& i+7<len && buf[i+1]=='E'&& buf[i+2]=='S'&& buf[i+3]=='-' &&
471 buf[i+4]=='2'&& buf[i+5]=='5'&& buf[i+6]=='6'&& buf[i+7]=='-'){
472 i+=8;
473 if(Session.checkCipher((String)jsch.getConfig("aes256-cbc"))){
474 Class c=Class.forName((String)jsch.getConfig("aes256-cbc"));
475 cipher=(Cipher)(c.newInstance());
476 // key=new byte[cipher.getBlockSize()];
477 iv=new byte[cipher.getIVSize()];
478 }
479 else{
480 throw new JSchException("privatekey: aes256-cbc is not available "+prvkey);
481 }
482 continue;
483 }
484 if(buf[i]=='A'&& i+7<len && buf[i+1]=='E'&& buf[i+2]=='S'&& buf[i+3]=='-' &&
485 buf[i+4]=='1'&& buf[i+5]=='9'&& buf[i+6]=='2'&& buf[i+7]=='-'){
486 i+=8;
487 if(Session.checkCipher((String)jsch.getConfig("aes192-cbc"))){
488 Class c=Class.forName((String)jsch.getConfig("aes192-cbc"));
489 cipher=(Cipher)(c.newInstance());
490 // key=new byte[cipher.getBlockSize()];
491 iv=new byte[cipher.getIVSize()];
492 }
493 else{
494 throw new JSchException("privatekey: aes192-cbc is not available "+prvkey);
495 }
496 continue;
497 }
498 if(buf[i]=='A'&& i+7<len && buf[i+1]=='E'&& buf[i+2]=='S'&& buf[i+3]=='-' &&
499 buf[i+4]=='1'&& buf[i+5]=='2'&& buf[i+6]=='8'&& buf[i+7]=='-'){
500 i+=8;
501 if(Session.checkCipher((String)jsch.getConfig("aes128-cbc"))){
502 Class c=Class.forName((String)jsch.getConfig("aes128-cbc"));
503 cipher=(Cipher)(c.newInstance());
504 // key=new byte[cipher.getBlockSize()];
505 iv=new byte[cipher.getIVSize()];
506 }
507 else{
508 throw new JSchException("privatekey: aes128-cbc is not available "+prvkey);
509 }
510 continue;
511 }
512 if(buf[i]=='C'&& i+3<len && buf[i+1]=='B'&& buf[i+2]=='C'&& buf[i+3]==','){
456 i+=4;513 i+=4;
457 for(int ii=0; ii<iv.length; ii++){514 for(int ii=0; ii<iv.length; ii++){
458 iv[ii]=(byte)(((a2b(buf[i++])<<4)&0xf0)+(a2b(buf[i++])&0xf));515 iv[ii]=(byte)(((a2b(buf[i++])<<4)&0xf0)+(a2b(buf[i++])&0xf));
459 }516 }
460 continue;517 continue;
461 }518 }
462 if(buf[i]==0x0d &&519 if(buf[i]==0x0d && i+1<buf.length && buf[i+1]==0x0a){
463 i+1<buf.length && buf[i+1]==0x0a){
464 i++;520 i++;
465 continue;521 continue;
466 }522 }
@@ -518,10 +574,9 @@
518 _buf.getInt();574 _buf.getInt();
519 byte[]_type=_buf.getString();575 byte[]_type=_buf.getString();
520 //System.err.println("type: "+new String(_type)); 576 //System.err.println("type: "+new String(_type));
521 byte[] _cipher=_buf.getString();577 String _cipher=Util.byte2str(_buf.getString());
522 String cipher=new String(_cipher);578 //System.err.println("cipher: "+_cipher);
523 //System.err.println("cipher: "+cipher); 579 if(_cipher.equals("3des-cbc")){
524 if(cipher.equals("3des-cbc")){
525 _buf.getInt();580 _buf.getInt();
526 byte[] foo=new byte[data.length-_buf.getOffSet()];581 byte[] foo=new byte[data.length-_buf.getOffSet()];
527 _buf.getByte(foo);582 _buf.getByte(foo);
@@ -529,7 +584,7 @@
529 encrypted=true;584 encrypted=true;
530 throw new JSchException("unknown privatekey format: "+prvkey);585 throw new JSchException("unknown privatekey format: "+prvkey);
531 }586 }
532 else if(cipher.equals("none")){587 else if(_cipher.equals("none")){
533 _buf.getInt();588 _buf.getInt();
534 _buf.getInt();589 _buf.getInt();
535590
@@ -606,6 +661,13 @@
606 while(i<len){ if(buf[i]==' ')break; i++;}661 while(i<len){ if(buf[i]==' ')break; i++;}
607 publickeyblob=Util.fromBase64(buf, start, i-start);662 publickeyblob=Util.fromBase64(buf, start, i-start);
608 }663 }
664 if(i++<len){
665 int s=i;
666 while(i<len){ if(buf[i]=='\n')break; i++;}
667 if(i<len){
668 publicKeyComment = new String(buf, s, i-s);
669 }
670 }
609 }671 }
610 }672 }
611 }673 }
@@ -628,6 +690,8 @@
628 kpair.encrypted=encrypted;690 kpair.encrypted=encrypted;
629 kpair.publickeyblob=publickeyblob;691 kpair.publickeyblob=publickeyblob;
630 kpair.vendor=vendor;692 kpair.vendor=vendor;
693 kpair.publicKeyComment=publicKeyComment;
694 kpair.cipher=cipher;
631695
632 if(encrypted){696 if(encrypted){
633 kpair.iv=iv;697 kpair.iv=iv;
634698
=== modified file 'src/main/java/com/jcraft/jsch/KeyPairDSA.java'
--- src/com/jcraft/jsch/KeyPairDSA.java 2010-06-27 23:17:34 +0000
+++ src/main/java/com/jcraft/jsch/KeyPairDSA.java 2012-05-04 10:23:17 +0000
@@ -1,6 +1,6 @@
1/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */1/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
2/*2/*
3Copyright (c) 2002-2009 ymnk, JCraft,Inc. All rights reserved.3Copyright (c) 2002-2012 ymnk, JCraft,Inc. All rights reserved.
44
5Redistribution and use in source and binary forms, with or without5Redistribution and use in source and binary forms, with or without
6modification, are permitted provided that the following conditions are met:6modification, are permitted provided that the following conditions are met:
@@ -65,8 +65,8 @@
65 }65 }
66 }66 }
6767
68 private static final byte[] begin="-----BEGIN DSA PRIVATE KEY-----".getBytes();68 private static final byte[] begin=Util.str2byte("-----BEGIN DSA PRIVATE KEY-----");
69 private static final byte[] end="-----END DSA PRIVATE KEY-----".getBytes();69 private static final byte[] end=Util.str2byte("-----END DSA PRIVATE KEY-----");
7070
71 byte[] getBegin(){ return begin; }71 byte[] getBegin(){ return begin; }
72 byte[] getEnd(){ return end; }72 byte[] getEnd(){ return end; }
@@ -209,7 +209,7 @@
209 return buf.buffer;209 return buf.buffer;
210 }210 }
211211
212 private static final byte[] sshdss="ssh-dss".getBytes();212 private static final byte[] sshdss=Util.str2byte("ssh-dss");
213 byte[] getKeyTypeName(){return sshdss;}213 byte[] getKeyTypeName(){return sshdss;}
214 public int getKeyType(){return DSA;}214 public int getKeyType(){return DSA;}
215215
216216
=== modified file 'src/main/java/com/jcraft/jsch/KeyPairGenDSA.java'
--- src/com/jcraft/jsch/KeyPairGenDSA.java 2010-06-27 23:17:34 +0000
+++ src/main/java/com/jcraft/jsch/KeyPairGenDSA.java 2012-05-04 10:23:17 +0000
@@ -1,6 +1,6 @@
1/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */1/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
2/*2/*
3Copyright (c) 2002-2009 ymnk, JCraft,Inc. All rights reserved.3Copyright (c) 2002-2012 ymnk, JCraft,Inc. All rights reserved.
44
5Redistribution and use in source and binary forms, with or without5Redistribution and use in source and binary forms, with or without
6modification, are permitted provided that the following conditions are met:6modification, are permitted provided that the following conditions are met:
77
=== modified file 'src/main/java/com/jcraft/jsch/KeyPairGenRSA.java'
--- src/com/jcraft/jsch/KeyPairGenRSA.java 2010-06-27 23:17:34 +0000
+++ src/main/java/com/jcraft/jsch/KeyPairGenRSA.java 2012-05-04 10:23:17 +0000
@@ -1,6 +1,6 @@
1/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */1/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
2/*2/*
3Copyright (c) 2002-2009 ymnk, JCraft,Inc. All rights reserved.3Copyright (c) 2002-2012 ymnk, JCraft,Inc. All rights reserved.
44
5Redistribution and use in source and binary forms, with or without5Redistribution and use in source and binary forms, with or without
6modification, are permitted provided that the following conditions are met:6modification, are permitted provided that the following conditions are met:
77
=== modified file 'src/main/java/com/jcraft/jsch/KeyPairRSA.java'
--- src/com/jcraft/jsch/KeyPairRSA.java 2010-06-27 23:17:34 +0000
+++ src/main/java/com/jcraft/jsch/KeyPairRSA.java 2012-05-04 10:23:17 +0000
@@ -1,6 +1,6 @@
1/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */1/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
2/*2/*
3Copyright (c) 2002-2009 ymnk, JCraft,Inc. All rights reserved.3Copyright (c) 2002-2012 ymnk, JCraft,Inc. All rights reserved.
44
5Redistribution and use in source and binary forms, with or without5Redistribution and use in source and binary forms, with or without
6modification, are permitted provided that the following conditions are met:6modification, are permitted provided that the following conditions are met:
@@ -73,8 +73,8 @@
73 }73 }
74 }74 }
7575
76 private static final byte[] begin="-----BEGIN RSA PRIVATE KEY-----".getBytes();76 private static final byte[] begin=Util.str2byte("-----BEGIN RSA PRIVATE KEY-----");
77 private static final byte[] end="-----END RSA PRIVATE KEY-----".getBytes();77 private static final byte[] end=Util.str2byte("-----END RSA PRIVATE KEY-----");
7878
79 byte[] getBegin(){ return begin; }79 byte[] getBegin(){ return begin; }
80 byte[] getEnd(){ return end; }80 byte[] getEnd(){ return end; }
@@ -308,7 +308,7 @@
308 return buf.buffer;308 return buf.buffer;
309 }309 }
310310
311 private static final byte[] sshrsa="ssh-rsa".getBytes();311 private static final byte[] sshrsa=Util.str2byte("ssh-rsa");
312 byte[] getKeyTypeName(){return sshrsa;}312 byte[] getKeyTypeName(){return sshrsa;}
313 public int getKeyType(){return RSA;}313 public int getKeyType(){return RSA;}
314314
315315
=== modified file 'src/main/java/com/jcraft/jsch/KnownHosts.java'
--- src/com/jcraft/jsch/KnownHosts.java 2010-06-27 23:17:34 +0000
+++ src/main/java/com/jcraft/jsch/KnownHosts.java 2012-05-04 10:23:17 +0000
@@ -1,6 +1,6 @@
1/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */1/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
2/*2/*
3Copyright (c) 2002-2009 ymnk, JCraft,Inc. All rights reserved.3Copyright (c) 2002-2012 ymnk, JCraft,Inc. All rights reserved.
44
5Redistribution and use in source and binary forms, with or without5Redistribution and use in source and binary forms, with or without
6modification, are permitted provided that the following conditions are met:6modification, are permitted provided that the following conditions are met:
@@ -100,13 +100,13 @@
100 i=buf[j];100 i=buf[j];
101 if(i==' '||i=='\t'){ j++; continue; }101 if(i==' '||i=='\t'){ j++; continue; }
102 if(i=='#'){102 if(i=='#'){
103 addInvalidLine(new String(buf, 0, bufl));103 addInvalidLine(Util.byte2str(buf, 0, bufl));
104 continue loop;104 continue loop;
105 }105 }
106 break;106 break;
107 }107 }
108 if(j>=bufl){ 108 if(j>=bufl){
109 addInvalidLine(new String(buf, 0, bufl));109 addInvalidLine(Util.byte2str(buf, 0, bufl));
110 continue loop; 110 continue loop;
111 }111 }
112112
@@ -118,7 +118,7 @@
118 }118 }
119 host=sb.toString();119 host=sb.toString();
120 if(j>=bufl || host.length()==0){120 if(j>=bufl || host.length()==0){
121 addInvalidLine(new String(buf, 0, bufl));121 addInvalidLine(Util.byte2str(buf, 0, bufl));
122 continue loop; 122 continue loop;
123 }123 }
124124
@@ -133,7 +133,7 @@
133 else if(sb.toString().equals("ssh-rsa")){ type=HostKey.SSHRSA; }133 else if(sb.toString().equals("ssh-rsa")){ type=HostKey.SSHRSA; }
134 else { j=bufl; }134 else { j=bufl; }
135 if(j>=bufl){135 if(j>=bufl){
136 addInvalidLine(new String(buf, 0, bufl));136 addInvalidLine(Util.byte2str(buf, 0, bufl));
137 continue loop; 137 continue loop;
138 }138 }
139139
@@ -146,7 +146,7 @@
146 }146 }
147 key=sb.toString();147 key=sb.toString();
The diff has been truncated for viewing.

Subscribers

People subscribed via source and target branches