Merge lp:~veger/ubuntu/quantal/jsch/fix-for-803492-v2 into lp:ubuntu/quantal/jsch
- Quantal (12.10)
- fix-for-803492-v2
- Merge into quantal
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 | ||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
James Page | Approve | ||
Ubuntu branches | Pending | ||
Review via email: mp+104706@code.launchpad.net |
Commit message
Description of the change
Changes from 0.1.42 to 0.1.48 can be found at: http://
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 : | # |
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
1 | === removed directory '.pc' | |||
2 | === removed file '.pc/.version' | |||
3 | --- .pc/.version 2010-06-27 23:17:34 +0000 | |||
4 | +++ .pc/.version 1970-01-01 00:00:00 +0000 | |||
5 | @@ -1,1 +0,0 @@ | |||
6 | 1 | 2 | ||
7 | 2 | 0 | ||
8 | === removed file '.pc/applied-patches' | |||
9 | --- .pc/applied-patches 2010-06-27 23:17:34 +0000 | |||
10 | +++ .pc/applied-patches 1970-01-01 00:00:00 +0000 | |||
11 | @@ -1,1 +0,0 @@ | |||
12 | 1 | jsch-build-xml.patch | ||
13 | 2 | 0 | ||
14 | === removed directory '.pc/jsch-build-xml.patch' | |||
15 | === removed file '.pc/jsch-build-xml.patch/build.xml' | |||
16 | --- .pc/jsch-build-xml.patch/build.xml 2010-06-27 23:17:34 +0000 | |||
17 | +++ .pc/jsch-build-xml.patch/build.xml 1970-01-01 00:00:00 +0000 | |||
18 | @@ -1,77 +0,0 @@ | |||
19 | 1 | <project name="Jsch" default="dist" basedir="."> | ||
20 | 2 | <description> | ||
21 | 3 | JSch is a pure Java implementation of SSH2. JSch allows you to connect to an | ||
22 | 4 | sshd server and use port forwarding, X11 forwarding, file transfer, etc., and | ||
23 | 5 | you can integrate its functionality into your own Java programs | ||
24 | 6 | </description> | ||
25 | 7 | <!-- set global properties for this build --> | ||
26 | 8 | <property name="version" location="0.1.40"/> | ||
27 | 9 | <property name="src" location="src"/> | ||
28 | 10 | <property name="exasrc" location="examples"/> | ||
29 | 11 | <property name="build" location="build"/> | ||
30 | 12 | <property name="exabuild" location="examples"/> | ||
31 | 13 | <property name="dist" location="dist"/> | ||
32 | 14 | <property name="javadoc" location="javadoc"/> | ||
33 | 15 | <property name="javac.debug" value="true"/> | ||
34 | 16 | <path id="project.cp"> | ||
35 | 17 | <pathelement location="${build}"/> | ||
36 | 18 | </path> | ||
37 | 19 | <target name="init"> | ||
38 | 20 | <!-- Create the time stamp --> | ||
39 | 21 | <tstamp/> | ||
40 | 22 | <!-- Create the build directory structure used by compile --> | ||
41 | 23 | <mkdir dir="${build}"/> | ||
42 | 24 | </target> | ||
43 | 25 | |||
44 | 26 | <target name="compile" depends="init" | ||
45 | 27 | description="compile the source " > | ||
46 | 28 | <!-- Compile the java code from ${src} into ${build} --> | ||
47 | 29 | <available property="jzlib.available" | ||
48 | 30 | classname="com.jcraft.jzlib.ZStream"/> | ||
49 | 31 | <javac srcdir="${src}" destdir="${build}" debug="${javac.debug}"> | ||
50 | 32 | <exclude name="com/jcraft/jsch/jcraft/Compression.java" | ||
51 | 33 | unless="jzlib.available"/> | ||
52 | 34 | </javac> | ||
53 | 35 | </target> | ||
54 | 36 | <target name="run" depends="compile"> | ||
55 | 37 | <java classname="Login" classpathref="project.cp"/> | ||
56 | 38 | </target> | ||
57 | 39 | <target name="dist" depends="compile" | ||
58 | 40 | description="generate the distribution" > | ||
59 | 41 | <!-- Create the distribution directory --> | ||
60 | 42 | <mkdir dir="${dist}/lib"/> | ||
61 | 43 | |||
62 | 44 | <!-- Put everything in ${build} into the MyProject-${DSTAMP}.jar file --> | ||
63 | 45 | <jar jarfile="${dist}/lib/jsch-${DSTAMP}.jar" basedir="${build}"/> | ||
64 | 46 | </target> | ||
65 | 47 | |||
66 | 48 | <target name="examples" | ||
67 | 49 | description="compiles the examples" | ||
68 | 50 | depends="compile"> | ||
69 | 51 | |||
70 | 52 | <path id="compile.classpath"> | ||
71 | 53 | <pathelement location="${build}" /> | ||
72 | 54 | </path> | ||
73 | 55 | |||
74 | 56 | <javac srcdir="${exasrc}" destdir="${exabuild}"> | ||
75 | 57 | <classpath refid="compile.classpath"/> | ||
76 | 58 | </javac> | ||
77 | 59 | |||
78 | 60 | </target> | ||
79 | 61 | |||
80 | 62 | <target name="clean" | ||
81 | 63 | description="clean up" > | ||
82 | 64 | <!-- Delete the ${build} and ${dist} directory trees --> | ||
83 | 65 | <delete dir="${build}"/> | ||
84 | 66 | <delete dir="${dist}"/> | ||
85 | 67 | <delete dir="${javadoc}"/> | ||
86 | 68 | </target> | ||
87 | 69 | |||
88 | 70 | <target name="javadoc"> | ||
89 | 71 | <javadoc sourcepath="${src}" | ||
90 | 72 | destdir="${javadoc}" | ||
91 | 73 | > | ||
92 | 74 | <packageset dir="${src}"/> | ||
93 | 75 | </javadoc> | ||
94 | 76 | </target> | ||
95 | 77 | </project> | ||
96 | 78 | 0 | ||
97 | === modified file 'ChangeLog' | |||
98 | --- ChangeLog 2010-06-27 23:17:34 +0000 | |||
99 | +++ ChangeLog 2012-05-04 10:23:17 +0000 | |||
100 | @@ -1,6 +1,99 @@ | |||
101 | 1 | ChangeLog of JSch | 1 | ChangeLog of JSch |
102 | 2 | ==================================================================== | 2 | ==================================================================== |
104 | 3 | Last modified: Tue Jul 14 02:29:29 UTC 2009 | 3 | Last modified: Fri Apr 20 06:44:50 UTC 2012 |
105 | 4 | |||
106 | 5 | |||
107 | 6 | Changes since version 0.1.47: | ||
108 | 7 | - change: the file transfer speed with ChannelSftp#get(String src) has been | ||
109 | 8 | improved; sending multiple requests at any one time. | ||
110 | 9 | - change: by the default, at most, 16 requests will be sent at any one time | ||
111 | 10 | in ChannelSftp. | ||
112 | 11 | - feature: added Session#{setIdentityRepository(),getIdentityRepository()} | ||
113 | 12 | |||
114 | 13 | |||
115 | 14 | Changes since version 0.1.46: | ||
116 | 15 | - bugfix: failed to initialize channels for the stream forwarding. FIXED | ||
117 | 16 | - change: Session#getHostKey() will return the given hostkey | ||
118 | 17 | even if session is not established. | ||
119 | 18 | - change: Logger will record additional messages about algorithm negotiations. | ||
120 | 19 | - feature: added ChannelSftp#ls(String path, LsEntrySelector selector) method. | ||
121 | 20 | - feature: added IdentityRepository#{getName(),getStatus()} methods. | ||
122 | 21 | |||
123 | 22 | |||
124 | 23 | Changes since version 0.1.45: | ||
125 | 24 | - bugfix: in the agent forwarding mode, "ssh-add -l" on the remote | ||
126 | 25 | will freeze. FIXED | ||
127 | 26 | - bugfix: requests should not be sent to the closed channel. FIXED | ||
128 | 27 | - bugfix: ChannelShell#setAgentForwarding(true) will cause | ||
129 | 28 | resource leaks. FIXED | ||
130 | 29 | - change: for the efficiency, channel opening will be delayed | ||
131 | 30 | in local port forwarding. | ||
132 | 31 | - change: added examples/Sudo.java to demonstrate sudo on exec channel. | ||
133 | 32 | - change: authentication trials will be failed at 6 failures by the default. | ||
134 | 33 | - change: updating copyright messages; 2011 -> 2012 | ||
135 | 34 | - feature: added JSch#setIdentityRepository(IdentityRepository irepo) to | ||
136 | 35 | integrate with jsch-agent-proxy. | ||
137 | 36 | |||
138 | 37 | |||
139 | 38 | Changes since version 0.1.44: | ||
140 | 39 | - bugfix: fields referred by multiple threads simultaneously should be | ||
141 | 40 | volatile. FIXED | ||
142 | 41 | - bugfix: use local window size offered by the remote in sftp put. | ||
143 | 42 | FIXED | ||
144 | 43 | - bugfix: SftpProgressMonitor#init was not invoked in sftp-put | ||
145 | 44 | for input-stream. FIXED | ||
146 | 45 | - bugfix: sftp protocol version 3, 4 and 5 should allow only | ||
147 | 46 | UTF-8 encoding. FIXED | ||
148 | 47 | - bugfix: Channel Subsystem had failed to set X forwarding flag. | ||
149 | 48 | FIXED | ||
150 | 49 | - bugfix: Channel X11 had leaked some resources. | ||
151 | 50 | FIXED | ||
152 | 51 | - bugfix: packet compression may break sessions | ||
153 | 52 | in some case(transferring deflated data). FIXED | ||
154 | 53 | - bugfix: failed to set dev-null for logger | ||
155 | 54 | FIXED | ||
156 | 55 | - bugfix: even in sftp protocol version 3 session, some sftpd sends data | ||
157 | 56 | packets defined in sftp protocol 6 ;-( working around it. FIXED | ||
158 | 57 | - bugfix: ChannelSftp file globbing logic had missed | ||
159 | 58 | the string "foo\\\*bar" as a pattern. FIXED | ||
160 | 59 | - bugfix: sequential accesses to ChannelSftp by multiple threads may | ||
161 | 60 | break its I/O channel. | ||
162 | 61 | https://bugs.eclipse.org/bugs/show_bug.cgi?id=359184 FIXED | ||
163 | 62 | - bugfix: KeyPair.load can not handle private keys cyphered with AES. FIXED | ||
164 | 63 | - change: to improve sftp-put performance, send multiple packet at one time. | ||
165 | 64 | - change: wait/notify will be used instead of sleep loop | ||
166 | 65 | in establishing channel connections. | ||
167 | 66 | - change: increasing local window size for sftp get. | ||
168 | 67 | - change: updating copyright messages; 2010 -> 2011 | ||
169 | 68 | - change: src/com -> src/main/java/com | ||
170 | 69 | - feature: key-exchange method "diffie-hellman-group14-sha1" | ||
171 | 70 | (RFC4253#section-8.2) | ||
172 | 71 | - feature: KeyPair#getPlulicKeyCommment() is added. | ||
173 | 72 | |||
174 | 73 | |||
175 | 74 | Changes since version 0.1.43: | ||
176 | 75 | - bugfix: hmac-md5-96 and hmac-sha1-96 are broken. FIXED. | ||
177 | 76 | - bugfix: working around OOME in parsing broken data from the remote. FIXED. | ||
178 | 77 | - bugfix: failed to send very long command for exec channels. FIXED. | ||
179 | 78 | - bugfix: in some case, failed to get the response | ||
180 | 79 | for remote port-forwarding request. FIXED. | ||
181 | 80 | - feature: support for private keys ciphered with aes192-cbc and aes128-cbc. | ||
182 | 81 | |||
183 | 82 | |||
184 | 83 | Changes since version 0.1.42: | ||
185 | 84 | - bugfix: the remote window size must be in unsigned int. FIXED. | ||
186 | 85 | - bugfix: support for EBCDIC environment. FIXED. | ||
187 | 86 | - bugfix: data may be written to the closed channel. FIXED. | ||
188 | 87 | - bugfix: NPE in closing channels. FIXED. | ||
189 | 88 | - bugfix: the private key file may include garbage data before its header. FIXED. | ||
190 | 89 | - bugfix: the session down may not be detected during the re-keying process. FIXED. | ||
191 | 90 | - change: try keyboard-interactive auth with the given password if UserInfo is not given. | ||
192 | 91 | - change: working around the wrong auth method list sent by some SSHD | ||
193 | 92 | in the partial auth success. | ||
194 | 93 | - change: working around the CPNI-957037 Plain-text Recovery Attack. | ||
195 | 94 | - change: in searching for [host]:non-default port in known_hosts, | ||
196 | 95 | host:22 should be also checked. | ||
197 | 96 | - change: updating copyright messages; 2009 -> 2010 | ||
198 | 4 | 97 | ||
199 | 5 | 98 | ||
200 | 6 | Changes since version 0.1.41: | 99 | Changes since version 0.1.41: |
201 | 7 | 100 | ||
202 | === modified file 'LICENSE.txt' | |||
203 | --- LICENSE.txt 2010-06-27 23:17:34 +0000 | |||
204 | +++ LICENSE.txt 2012-05-04 10:23:17 +0000 | |||
205 | @@ -2,7 +2,7 @@ | |||
206 | 2 | over to a BSD-style license. | 2 | over to a BSD-style license. |
207 | 3 | 3 | ||
208 | 4 | ------------------------------------------------------------------------------ | 4 | ------------------------------------------------------------------------------ |
210 | 5 | Copyright (c) 2002,2003,2004,2005,2006,2007,2008,2009 Atsuhiko Yamanaka, JCraft,Inc. | 5 | Copyright (c) 2002-2012 Atsuhiko Yamanaka, JCraft,Inc. |
211 | 6 | All rights reserved. | 6 | All rights reserved. |
212 | 7 | 7 | ||
213 | 8 | Redistribution and use in source and binary forms, with or without | 8 | Redistribution and use in source and binary forms, with or without |
214 | 9 | 9 | ||
215 | === modified file 'build.xml' | |||
216 | --- build.xml 2010-06-27 23:17:34 +0000 | |||
217 | +++ build.xml 2012-05-04 10:23:17 +0000 | |||
218 | @@ -5,14 +5,17 @@ | |||
219 | 5 | you can integrate its functionality into your own Java programs | 5 | you can integrate its functionality into your own Java programs |
220 | 6 | </description> | 6 | </description> |
221 | 7 | <!-- set global properties for this build --> | 7 | <!-- set global properties for this build --> |
224 | 8 | <property name="version" location="0.1.40"/> | 8 | <property name="version" value="0.1.48"/> |
225 | 9 | <property name="src" location="src"/> | 9 | <property name="src" location="src/main/java/"/> |
226 | 10 | <property name="exasrc" location="examples"/> | 10 | <property name="exasrc" location="examples"/> |
227 | 11 | <property name="build" location="build"/> | 11 | <property name="build" location="build"/> |
228 | 12 | <property name="exabuild" location="examples"/> | 12 | <property name="exabuild" location="examples"/> |
229 | 13 | <property name="dist" location="dist"/> | 13 | <property name="dist" location="dist"/> |
230 | 14 | <property name="javadoc" location="javadoc"/> | 14 | <property name="javadoc" location="javadoc"/> |
231 | 15 | <property name="javac.debug" value="true"/> | 15 | <property name="javac.debug" value="true"/> |
232 | 16 | <path id="lib.path.ref"> | ||
233 | 17 | <fileset dir="lib" includes="*.jar"/> | ||
234 | 18 | </path> | ||
235 | 16 | <path id="project.cp"> | 19 | <path id="project.cp"> |
236 | 17 | <pathelement location="${build}"/> | 20 | <pathelement location="${build}"/> |
237 | 18 | </path> | 21 | </path> |
238 | @@ -27,22 +30,39 @@ | |||
239 | 27 | description="compile the source " > | 30 | description="compile the source " > |
240 | 28 | <!-- Compile the java code from ${src} into ${build} --> | 31 | <!-- Compile the java code from ${src} into ${build} --> |
241 | 29 | <available property="jzlib.available" | 32 | <available property="jzlib.available" |
244 | 30 | classname="com.jcraft.jzlib.ZStream"/> | 33 | classname="com.jcraft.jzlib.ZStream"> |
245 | 31 | <javac srcdir="${src}" destdir="${build}" debug="${javac.debug}"> | 34 | <classpath refid="lib.path.ref"/> |
246 | 35 | </available> | ||
247 | 36 | <javac srcdir="${src}" | ||
248 | 37 | destdir="${build}" | ||
249 | 38 | target="1.4" | ||
250 | 39 | source="1.4" | ||
251 | 40 | debug="${javac.debug}"> | ||
252 | 41 | <classpath refid="lib.path.ref"/> | ||
253 | 32 | <exclude name="com/jcraft/jsch/jcraft/Compression.java" | 42 | <exclude name="com/jcraft/jsch/jcraft/Compression.java" |
254 | 33 | unless="jzlib.available"/> | 43 | unless="jzlib.available"/> |
255 | 34 | </javac> | 44 | </javac> |
256 | 35 | </target> | 45 | </target> |
257 | 36 | <target name="run" depends="compile"> | ||
258 | 37 | <java classname="Login" classpathref="project.cp"/> | ||
259 | 38 | </target> | ||
260 | 39 | <target name="dist" depends="compile" | 46 | <target name="dist" depends="compile" |
261 | 40 | description="generate the distribution" > | 47 | description="generate the distribution" > |
262 | 41 | <!-- Create the distribution directory --> | 48 | <!-- Create the distribution directory --> |
263 | 42 | <mkdir dir="${dist}/lib"/> | 49 | <mkdir dir="${dist}/lib"/> |
264 | 43 | 50 | ||
267 | 44 | <!-- Put everything in ${build} into the MyProject-${DSTAMP}.jar file --> | 51 | <!-- Put everything in ${build} into the MyProject-${version}.jar file --> |
268 | 45 | <jar jarfile="${dist}/lib/jsch.jar" basedir="${build}" manifest="debian/manifest.mf" /> | 52 | <jar jarfile="${dist}/lib/jsch-${version}.jar" basedir="${build}"> |
269 | 53 | <!-- | ||
270 | 54 | <manifest> | ||
271 | 55 | <attribute name="Bundle-ClassPath" value="."/> | ||
272 | 56 | <attribute name="Bundle-Vendor" value="JCraft, Inc."/> | ||
273 | 57 | <attribute name="Bundle-Name" value="com.jcraft.jsch"/> | ||
274 | 58 | <attribute name="Bundle-ManifestVersion" value="2"/> | ||
275 | 59 | <attribute name="Bundle-SymbolicName" value="com.jcraft.jsch"/> | ||
276 | 60 | <attribute name="Bundle-Version" value="${version}"/> | ||
277 | 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'/> | ||
278 | 62 | <attribute name="Import-Package" value="javax.crypto,javax.crypto.spec,javax.crypto.interfaces,org.ietf.jgss,com.jcraft.jzlib"/> | ||
279 | 63 | </manifest> | ||
280 | 64 | --> | ||
281 | 65 | </jar> | ||
282 | 46 | </target> | 66 | </target> |
283 | 47 | 67 | ||
284 | 48 | <target name="examples" | 68 | <target name="examples" |
285 | 49 | 69 | ||
286 | === modified file 'debian/changelog' | |||
287 | --- debian/changelog 2010-06-27 23:17:34 +0000 | |||
288 | +++ debian/changelog 2012-05-04 10:23:17 +0000 | |||
289 | @@ -1,3 +1,12 @@ | |||
290 | 1 | jsch (0.1.48-0ubuntu1) quantal; urgency=low | ||
291 | 2 | |||
292 | 3 | * New upstream release. | ||
293 | 4 | - Updated debian/pom.xml | ||
294 | 5 | - Refreshed jsch-build-xml.patch | ||
295 | 6 | * Bumped Standards-Version to 3.9.3 - no changes required. | ||
296 | 7 | |||
297 | 8 | -- Maarten Bezemer <maarten.bezemer@gmail.com> Fri, 04 May 2012 10:39:23 +0200 | ||
298 | 9 | |||
299 | 1 | jsch (0.1.42-2fakesync1) maverick; urgency=low | 10 | jsch (0.1.42-2fakesync1) maverick; urgency=low |
300 | 2 | 11 | ||
301 | 3 | * Fake sync due to mismatching orig tarball. | 12 | * Fake sync due to mismatching orig tarball. |
302 | 4 | 13 | ||
303 | === modified file 'debian/control' | |||
304 | --- debian/control 2010-06-27 23:17:34 +0000 | |||
305 | +++ debian/control 2012-05-04 10:23:17 +0000 | |||
306 | @@ -8,7 +8,7 @@ | |||
307 | 8 | Niels Thykier <niels@thykier.net> | 8 | Niels Thykier <niels@thykier.net> |
308 | 9 | Build-Depends: debhelper (>= 7), cdbs, default-jdk | 9 | Build-Depends: debhelper (>= 7), cdbs, default-jdk |
309 | 10 | Build-Depends-Indep: maven-repo-helper, ant (>= 1.6.5) | 10 | Build-Depends-Indep: maven-repo-helper, ant (>= 1.6.5) |
311 | 11 | Standards-Version: 3.8.4 | 11 | Standards-Version: 3.9.3 |
312 | 12 | Vcs-Svn: svn://svn.debian.org/svn/pkg-java/trunk/jsch | 12 | Vcs-Svn: svn://svn.debian.org/svn/pkg-java/trunk/jsch |
313 | 13 | Vcs-Browser: http://svn.debian.org/wsvn/pkg-java/trunk/jsch | 13 | Vcs-Browser: http://svn.debian.org/wsvn/pkg-java/trunk/jsch |
314 | 14 | Homepage: http://www.jcraft.com/jsch/ | 14 | Homepage: http://www.jcraft.com/jsch/ |
315 | 15 | 15 | ||
316 | === modified file 'debian/patches/jsch-build-xml.patch' | |||
317 | --- debian/patches/jsch-build-xml.patch 2010-06-27 23:17:34 +0000 | |||
318 | +++ debian/patches/jsch-build-xml.patch 2012-05-04 10:23:17 +0000 | |||
319 | @@ -7,9 +7,9 @@ | |||
320 | 7 | @@ -42,7 +42,7 @@ | 7 | @@ -42,7 +42,7 @@ |
321 | 8 | <mkdir dir="${dist}/lib"/> | 8 | <mkdir dir="${dist}/lib"/> |
322 | 9 | 9 | ||
329 | 10 | <!-- Put everything in ${build} into the MyProject-${DSTAMP}.jar file --> | 10 | <!-- Put everything in ${build} into the MyProject-${version}.jar file --> |
330 | 11 | - <jar jarfile="${dist}/lib/jsch-${DSTAMP}.jar" basedir="${build}"/> | 11 | - <jar jarfile="${dist}/lib/jsch-${version}.jar" basedir="${build}"> |
331 | 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"> |
332 | 13 | </target> | 13 | <!-- |
333 | 14 | 14 | <manifest> | |
334 | 15 | <target name="examples" | 15 | <attribute name="Bundle-ClassPath" value="."/> |
335 | 16 | 16 | ||
336 | === modified file 'debian/pom.xml' | |||
337 | --- debian/pom.xml 2009-09-22 20:01:52 +0000 | |||
338 | +++ debian/pom.xml 2012-05-04 10:23:17 +0000 | |||
339 | @@ -6,7 +6,7 @@ | |||
340 | 6 | <modelVersion>4.0.0</modelVersion> | 6 | <modelVersion>4.0.0</modelVersion> |
341 | 7 | <groupId>com.jcraft</groupId> | 7 | <groupId>com.jcraft</groupId> |
342 | 8 | <artifactId>jsch</artifactId> | 8 | <artifactId>jsch</artifactId> |
344 | 9 | <version>0.1.42</version> | 9 | <version>0.1.48</version> |
345 | 10 | <name>JSch</name> | 10 | <name>JSch</name> |
346 | 11 | 11 | ||
347 | 12 | <description>JSch is a pure Java implementation of SSH2</description> | 12 | <description>JSch is a pure Java implementation of SSH2</description> |
348 | 13 | 13 | ||
349 | === removed directory 'dist' | |||
350 | === removed directory 'dist/lib' | |||
351 | === modified file 'examples/AES.java' | |||
352 | --- examples/AES.java 2008-02-06 23:23:19 +0000 | |||
353 | +++ examples/AES.java 2012-05-04 10:23:17 +0000 | |||
354 | @@ -1,4 +1,8 @@ | |||
355 | 1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ | 1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ |
356 | 2 | /** | ||
357 | 3 | * This program will demonstrate how to use "aes128-cbc". | ||
358 | 4 | * | ||
359 | 5 | */ | ||
360 | 2 | import com.jcraft.jsch.*; | 6 | import com.jcraft.jsch.*; |
361 | 3 | import java.awt.*; | 7 | import java.awt.*; |
362 | 4 | import javax.swing.*; | 8 | import javax.swing.*; |
363 | 5 | 9 | ||
364 | === modified file 'examples/ChangePassphrase.java' | |||
365 | --- examples/ChangePassphrase.java 2007-09-09 20:32:32 +0000 | |||
366 | +++ examples/ChangePassphrase.java 2012-05-04 10:23:17 +0000 | |||
367 | @@ -1,4 +1,15 @@ | |||
368 | 1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ | 1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ |
369 | 2 | /** | ||
370 | 3 | * This program will demonstrate to change the passphrase for a | ||
371 | 4 | * private key file instead of creating a new private key. | ||
372 | 5 | * $ CLASSPATH=.:../build javac ChangePassphrase.java | ||
373 | 6 | * $ CLASSPATH=.:../build java ChangePassphrase private-key | ||
374 | 7 | * A passphrase will be prompted if the given private-key has been | ||
375 | 8 | * encrypted. After successfully loading the content of the | ||
376 | 9 | * private-key, the new passphrase will be prompted and the given | ||
377 | 10 | * private-key will be re-encrypted with that new passphrase. | ||
378 | 11 | * | ||
379 | 12 | */ | ||
380 | 2 | import com.jcraft.jsch.*; | 13 | import com.jcraft.jsch.*; |
381 | 3 | import javax.swing.*; | 14 | import javax.swing.*; |
382 | 4 | 15 | ||
383 | 5 | 16 | ||
384 | === modified file 'examples/Compression.java' | |||
385 | --- examples/Compression.java 2008-02-06 23:23:19 +0000 | |||
386 | +++ examples/Compression.java 2012-05-04 10:23:17 +0000 | |||
387 | @@ -1,4 +1,13 @@ | |||
388 | 1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ | 1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ |
389 | 2 | /** | ||
390 | 3 | * This program will demonstrate the packet compression. | ||
391 | 4 | * $ CLASSPATH=.:../build javac Compression.java | ||
392 | 5 | * $ CLASSPATH=.:../build java Compression | ||
393 | 6 | * You will be asked username, hostname and passwd. | ||
394 | 7 | * If everything works fine, you will get the shell prompt. | ||
395 | 8 | * In this program, all data from sshd server to jsch will be compressed. | ||
396 | 9 | * | ||
397 | 10 | */ | ||
398 | 2 | import com.jcraft.jsch.*; | 11 | import com.jcraft.jsch.*; |
399 | 3 | import java.awt.*; | 12 | import java.awt.*; |
400 | 4 | import javax.swing.*; | 13 | import javax.swing.*; |
401 | 5 | 14 | ||
402 | === modified file 'examples/Daemon.java' | |||
403 | --- examples/Daemon.java 2008-02-06 23:23:19 +0000 | |||
404 | +++ examples/Daemon.java 2012-05-04 10:23:17 +0000 | |||
405 | @@ -1,4 +1,9 @@ | |||
406 | 1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ | 1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ |
407 | 2 | /** | ||
408 | 3 | * This program will demonstrate how to provide a network service like | ||
409 | 4 | * inetd by using remote port-forwarding functionality. | ||
410 | 5 | * | ||
411 | 6 | */ | ||
412 | 2 | import com.jcraft.jsch.*; | 7 | import com.jcraft.jsch.*; |
413 | 3 | import java.io.*; | 8 | import java.io.*; |
414 | 4 | import java.awt.*; | 9 | import java.awt.*; |
415 | @@ -58,10 +63,10 @@ | |||
416 | 58 | } | 63 | } |
417 | 59 | public void setArg(Object[] arg){this.arg=arg;} | 64 | public void setArg(Object[] arg){this.arg=arg;} |
418 | 60 | public void run(){ | 65 | public void run(){ |
419 | 61 | System.out.println("remote port: "+channel.getRemotePort()); | ||
420 | 62 | System.out.println("remote host: "+channel.getSession().getHost()); | ||
421 | 63 | try{ | 66 | try{ |
422 | 64 | byte[] buf=new byte[1024]; | 67 | byte[] buf=new byte[1024]; |
423 | 68 | System.out.println("remote port: "+channel.getRemotePort()); | ||
424 | 69 | System.out.println("remote host: "+channel.getSession().getHost()); | ||
425 | 65 | while(true){ | 70 | while(true){ |
426 | 66 | int i=in.read(buf, 0, buf.length); | 71 | int i=in.read(buf, 0, buf.length); |
427 | 67 | if(i<=0)break; | 72 | if(i<=0)break; |
428 | @@ -70,6 +75,9 @@ | |||
429 | 70 | if(buf[0]=='.')break; | 75 | if(buf[0]=='.')break; |
430 | 71 | } | 76 | } |
431 | 72 | } | 77 | } |
432 | 78 | catch(JSchException e){ | ||
433 | 79 | System.out.println("session is down."); | ||
434 | 80 | } | ||
435 | 73 | catch(IOException e){ | 81 | catch(IOException e){ |
436 | 74 | } | 82 | } |
437 | 75 | } | 83 | } |
438 | 76 | 84 | ||
439 | === modified file 'examples/Exec.java' | |||
440 | --- examples/Exec.java 2008-02-06 23:23:19 +0000 | |||
441 | +++ examples/Exec.java 2012-05-04 10:23:17 +0000 | |||
442 | @@ -1,4 +1,13 @@ | |||
443 | 1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ | 1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ |
444 | 2 | /** | ||
445 | 3 | * This program will demonstrate remote exec. | ||
446 | 4 | * $ CLASSPATH=.:../build javac Exec.java | ||
447 | 5 | * $ CLASSPATH=.:../build java Exec | ||
448 | 6 | * You will be asked username, hostname, displayname, passwd and command. | ||
449 | 7 | * If everything works fine, given command will be invoked | ||
450 | 8 | * on the remote side and outputs will be printed out. | ||
451 | 9 | * | ||
452 | 10 | */ | ||
453 | 2 | import com.jcraft.jsch.*; | 11 | import com.jcraft.jsch.*; |
454 | 3 | import java.awt.*; | 12 | import java.awt.*; |
455 | 4 | import javax.swing.*; | 13 | import javax.swing.*; |
456 | 5 | 14 | ||
457 | === modified file 'examples/KeyGen.java' | |||
458 | --- examples/KeyGen.java 2007-09-09 20:32:32 +0000 | |||
459 | +++ examples/KeyGen.java 2012-05-04 10:23:17 +0000 | |||
460 | @@ -1,4 +1,16 @@ | |||
461 | 1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ | 1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ |
462 | 2 | /** | ||
463 | 3 | * This progam will demonstrate the DSA keypair generation. | ||
464 | 4 | * $ CLASSPATH=.:../build javac KeyGen.java | ||
465 | 5 | * $ CLASSPATH=.:../build java KeyGen rsa output_keyfile comment | ||
466 | 6 | * or | ||
467 | 7 | * $ CLASSPATH=.:../build java KeyGen dsa output_keyfile comment | ||
468 | 8 | * You will be asked a passphrase for output_keyfile. | ||
469 | 9 | * If everything works fine, you will get the DSA or RSA keypair, | ||
470 | 10 | * output_keyfile and output_keyfile+".pub". | ||
471 | 11 | * The private key and public key are in the OpenSSH format. | ||
472 | 12 | * | ||
473 | 13 | */ | ||
474 | 2 | import com.jcraft.jsch.*; | 14 | import com.jcraft.jsch.*; |
475 | 3 | import javax.swing.*; | 15 | import javax.swing.*; |
476 | 4 | 16 | ||
477 | 5 | 17 | ||
478 | === modified file 'examples/KnownHosts.java' | |||
479 | --- examples/KnownHosts.java 2008-02-06 23:23:19 +0000 | |||
480 | +++ examples/KnownHosts.java 2012-05-04 10:23:17 +0000 | |||
481 | @@ -1,4 +1,14 @@ | |||
482 | 1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ | 1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ |
483 | 2 | /** | ||
484 | 3 | * This program will demonstrate the 'known_hosts' file handling. | ||
485 | 4 | * $ CLASSPATH=.:../build javac KnownHosts.java | ||
486 | 5 | * $ CLASSPATH=.:../build java KnownHosts | ||
487 | 6 | * You will be asked username, hostname, a path for 'known_hosts' and passwd. | ||
488 | 7 | * If everything works fine, you will get the shell prompt. | ||
489 | 8 | * In current implementation, jsch only reads 'known_hosts' for checking | ||
490 | 9 | * and does not modify it. | ||
491 | 10 | * | ||
492 | 11 | */ | ||
493 | 2 | import com.jcraft.jsch.*; | 12 | import com.jcraft.jsch.*; |
494 | 3 | import java.awt.*; | 13 | import java.awt.*; |
495 | 4 | import javax.swing.*; | 14 | import javax.swing.*; |
496 | 5 | 15 | ||
497 | === modified file 'examples/Logger.java' | |||
498 | --- examples/Logger.java 2008-02-06 23:23:19 +0000 | |||
499 | +++ examples/Logger.java 2012-05-04 10:23:17 +0000 | |||
500 | @@ -1,4 +1,8 @@ | |||
501 | 1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ | 1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ |
502 | 2 | /** | ||
503 | 3 | * This program will demonstrate how to enable logging mechanism and | ||
504 | 4 | * get logging messages. | ||
505 | 5 | */ | ||
506 | 2 | import com.jcraft.jsch.*; | 6 | import com.jcraft.jsch.*; |
507 | 3 | import java.awt.*; | 7 | import java.awt.*; |
508 | 4 | import javax.swing.*; | 8 | import javax.swing.*; |
509 | 5 | 9 | ||
510 | === modified file 'examples/PortForwardingL.java' | |||
511 | --- examples/PortForwardingL.java 2008-02-06 23:23:19 +0000 | |||
512 | +++ examples/PortForwardingL.java 2012-05-04 10:23:17 +0000 | |||
513 | @@ -1,4 +1,15 @@ | |||
514 | 1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ | 1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ |
515 | 2 | /** | ||
516 | 3 | * This program will demonstrate the port forwarding like option -L of | ||
517 | 4 | * ssh command; the given port on the local host will be forwarded to | ||
518 | 5 | * the given remote host and port on the remote side. | ||
519 | 6 | * $ CLASSPATH=.:../build javac PortForwardingL.java | ||
520 | 7 | * $ CLASSPATH=.:../build java PortForwardingL | ||
521 | 8 | * You will be asked username, hostname, port:host:hostport and passwd. | ||
522 | 9 | * If everything works fine, you will get the shell prompt. | ||
523 | 10 | * Try the port on localhost. | ||
524 | 11 | * | ||
525 | 12 | */ | ||
526 | 2 | import com.jcraft.jsch.*; | 13 | import com.jcraft.jsch.*; |
527 | 3 | import java.awt.*; | 14 | import java.awt.*; |
528 | 4 | import javax.swing.*; | 15 | import javax.swing.*; |
529 | 5 | 16 | ||
530 | === modified file 'examples/PortForwardingR.java' | |||
531 | --- examples/PortForwardingR.java 2008-02-06 23:23:19 +0000 | |||
532 | +++ examples/PortForwardingR.java 2012-05-04 10:23:17 +0000 | |||
533 | @@ -1,4 +1,15 @@ | |||
534 | 1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ | 1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ |
535 | 2 | /** | ||
536 | 3 | * This program will demonstrate the port forwarding like option -R of | ||
537 | 4 | * ssh command; the given port on the remote host will be forwarded to | ||
538 | 5 | * the given host and port on the local side. | ||
539 | 6 | * $ CLASSPATH=.:../build javac PortForwardingR.java | ||
540 | 7 | * $ CLASSPATH=.:../build java PortForwardingR | ||
541 | 8 | * You will be asked username, hostname, port:host:hostport and passwd. | ||
542 | 9 | * If everything works fine, you will get the shell prompt. | ||
543 | 10 | * Try the port on remote host. | ||
544 | 11 | * | ||
545 | 12 | */ | ||
546 | 2 | import com.jcraft.jsch.*; | 13 | import com.jcraft.jsch.*; |
547 | 3 | import java.awt.*; | 14 | import java.awt.*; |
548 | 4 | import javax.swing.*; | 15 | import javax.swing.*; |
549 | 5 | 16 | ||
550 | === modified file 'examples/README' | |||
551 | --- examples/README 2007-09-09 20:32:32 +0000 | |||
552 | +++ examples/README 2012-05-04 10:23:17 +0000 | |||
553 | @@ -38,6 +38,13 @@ | |||
554 | 38 | You will be asked username, hostname, proxy-server and passwd. | 38 | You will be asked username, hostname, proxy-server and passwd. |
555 | 39 | If everything works fine, you will get the shell prompt. | 39 | If everything works fine, you will get the shell prompt. |
556 | 40 | 40 | ||
557 | 41 | - ViaSOCKS.java | ||
558 | 42 | This program will demonstrate the ssh session via SOCKS proxy. | ||
559 | 43 | $ CLASSPATH=.:../build javac ViaSOCKS.java | ||
560 | 44 | $ CLASSPATH=.:../build java ViaSOCKS | ||
561 | 45 | You will be asked username, hostname, proxy-server and passwd. | ||
562 | 46 | If everything works fine, you will get the shell prompt. | ||
563 | 47 | |||
564 | 41 | - PortForwardingR.java | 48 | - PortForwardingR.java |
565 | 42 | This program will demonstrate the port forwarding like option -R of | 49 | This program will demonstrate the port forwarding like option -R of |
566 | 43 | ssh command; the given port on the remote host will be forwarded to | 50 | ssh command; the given port on the remote host will be forwarded to |
567 | @@ -158,3 +165,12 @@ | |||
568 | 158 | - Logger.java | 165 | - Logger.java |
569 | 159 | This program will demonstrate how to enable logging mechanism and | 166 | This program will demonstrate how to enable logging mechanism and |
570 | 160 | get logging messages. | 167 | get logging messages. |
571 | 168 | |||
572 | 169 | - Subsystem.java | ||
573 | 170 | This program will demonstrate how to use the Subsystem channel. | ||
574 | 171 | |||
575 | 172 | - Sudo.java | ||
576 | 173 | This program will demonstrate how to exec 'sudo' on the remote. | ||
577 | 174 | |||
578 | 175 | - ScpToNoneCipher.java | ||
579 | 176 | This program will demonstrate how to enable none cipher. | ||
580 | 161 | 177 | ||
581 | === modified file 'examples/ScpFrom.java' | |||
582 | --- examples/ScpFrom.java 2007-09-09 20:32:32 +0000 | |||
583 | +++ examples/ScpFrom.java 2012-05-04 10:23:17 +0000 | |||
584 | @@ -1,4 +1,13 @@ | |||
585 | 1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ | 1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ |
586 | 2 | /** | ||
587 | 3 | * This program will demonstrate the file transfer from remote to local | ||
588 | 4 | * $ CLASSPATH=.:../build javac ScpFrom.java | ||
589 | 5 | * $ CLASSPATH=.:../build java ScpFrom user@remotehost:file1 file2 | ||
590 | 6 | * You will be asked passwd. | ||
591 | 7 | * If everything works fine, a file 'file1' on 'remotehost' will copied to | ||
592 | 8 | * local 'file1'. | ||
593 | 9 | * | ||
594 | 10 | */ | ||
595 | 2 | import com.jcraft.jsch.*; | 11 | import com.jcraft.jsch.*; |
596 | 3 | import java.awt.*; | 12 | import java.awt.*; |
597 | 4 | import javax.swing.*; | 13 | import javax.swing.*; |
598 | 5 | 14 | ||
599 | === modified file 'examples/ScpTo.java' | |||
600 | --- examples/ScpTo.java 2007-09-09 20:32:32 +0000 | |||
601 | +++ examples/ScpTo.java 2012-05-04 10:23:17 +0000 | |||
602 | @@ -1,4 +1,13 @@ | |||
603 | 1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ | 1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ |
604 | 2 | /** | ||
605 | 3 | * This program will demonstrate the file transfer from local to remote. | ||
606 | 4 | * $ CLASSPATH=.:../build javac ScpTo.java | ||
607 | 5 | * $ CLASSPATH=.:../build java ScpTo file1 user@remotehost:file2 | ||
608 | 6 | * You will be asked passwd. | ||
609 | 7 | * If everything works fine, a local file 'file1' will copied to | ||
610 | 8 | * 'file2' on 'remotehost'. | ||
611 | 9 | * | ||
612 | 10 | */ | ||
613 | 2 | import com.jcraft.jsch.*; | 11 | import com.jcraft.jsch.*; |
614 | 3 | import java.awt.*; | 12 | import java.awt.*; |
615 | 4 | import javax.swing.*; | 13 | import javax.swing.*; |
616 | @@ -28,9 +37,10 @@ | |||
617 | 28 | session.setUserInfo(ui); | 37 | session.setUserInfo(ui); |
618 | 29 | session.connect(); | 38 | session.connect(); |
619 | 30 | 39 | ||
620 | 40 | boolean ptimestamp = true; | ||
621 | 31 | 41 | ||
622 | 32 | // exec 'scp -t rfile' remotely | 42 | // exec 'scp -t rfile' remotely |
624 | 33 | String command="scp -p -t "+rfile; | 43 | String command="scp " + (ptimestamp ? "-p" :"") +" -t "+rfile; |
625 | 34 | Channel channel=session.openChannel("exec"); | 44 | Channel channel=session.openChannel("exec"); |
626 | 35 | ((ChannelExec)channel).setCommand(command); | 45 | ((ChannelExec)channel).setCommand(command); |
627 | 36 | 46 | ||
628 | @@ -44,8 +54,21 @@ | |||
629 | 44 | System.exit(0); | 54 | System.exit(0); |
630 | 45 | } | 55 | } |
631 | 46 | 56 | ||
632 | 57 | File _lfile = new File(lfile); | ||
633 | 58 | |||
634 | 59 | if(ptimestamp){ | ||
635 | 60 | command="T "+(_lfile.lastModified()/1000)+" 0"; | ||
636 | 61 | // The access time should be sent here, | ||
637 | 62 | // but it is not accessible with JavaAPI ;-< | ||
638 | 63 | command+=(" "+(_lfile.lastModified()/1000)+" 0\n"); | ||
639 | 64 | out.write(command.getBytes()); out.flush(); | ||
640 | 65 | if(checkAck(in)!=0){ | ||
641 | 66 | System.exit(0); | ||
642 | 67 | } | ||
643 | 68 | } | ||
644 | 69 | |||
645 | 47 | // send "C0644 filesize filename", where filename should not include '/' | 70 | // send "C0644 filesize filename", where filename should not include '/' |
647 | 48 | long filesize=(new File(lfile)).length(); | 71 | long filesize=_lfile.length(); |
648 | 49 | command="C0644 "+filesize+" "; | 72 | command="C0644 "+filesize+" "; |
649 | 50 | if(lfile.lastIndexOf('/')>0){ | 73 | if(lfile.lastIndexOf('/')>0){ |
650 | 51 | command+=lfile.substring(lfile.lastIndexOf('/')+1); | 74 | command+=lfile.substring(lfile.lastIndexOf('/')+1); |
651 | 52 | 75 | ||
652 | === modified file 'examples/ScpToNoneCipher.java' | |||
653 | --- examples/ScpToNoneCipher.java 2007-09-09 20:32:32 +0000 | |||
654 | +++ examples/ScpToNoneCipher.java 2012-05-04 10:23:17 +0000 | |||
655 | @@ -1,4 +1,8 @@ | |||
656 | 1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ | 1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ |
657 | 2 | /** | ||
658 | 3 | * This program will demonstrate how to enable none cipher. | ||
659 | 4 | * | ||
660 | 5 | */ | ||
661 | 2 | import com.jcraft.jsch.*; | 6 | import com.jcraft.jsch.*; |
662 | 3 | import java.awt.*; | 7 | import java.awt.*; |
663 | 4 | import javax.swing.*; | 8 | import javax.swing.*; |
664 | 5 | 9 | ||
665 | === modified file 'examples/Sftp.java' | |||
666 | --- examples/Sftp.java 2009-10-19 15:08:16 +0000 | |||
667 | +++ examples/Sftp.java 2012-05-04 10:23:17 +0000 | |||
668 | @@ -1,4 +1,15 @@ | |||
669 | 1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ | 1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ |
670 | 2 | /** | ||
671 | 3 | * This program will demonstrate the sftp protocol support. | ||
672 | 4 | * $ CLASSPATH=.:../build javac Sftp.java | ||
673 | 5 | * $ CLASSPATH=.:../build java Sftp | ||
674 | 6 | * You will be asked username, host and passwd. | ||
675 | 7 | * If everything works fine, you will get a prompt 'sftp>'. | ||
676 | 8 | * 'help' command will show available command. | ||
677 | 9 | * In current implementation, the destination path for 'get' and 'put' | ||
678 | 10 | * commands must be a file, not a directory. | ||
679 | 11 | * | ||
680 | 12 | */ | ||
681 | 2 | import com.jcraft.jsch.*; | 13 | import com.jcraft.jsch.*; |
682 | 3 | import java.awt.*; | 14 | import java.awt.*; |
683 | 4 | import javax.swing.*; | 15 | import javax.swing.*; |
684 | 5 | 16 | ||
685 | === modified file 'examples/Shell.java' | |||
686 | --- examples/Shell.java 2009-10-19 15:08:16 +0000 | |||
687 | +++ examples/Shell.java 2012-05-04 10:23:17 +0000 | |||
688 | @@ -1,4 +1,13 @@ | |||
689 | 1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ | 1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ |
690 | 2 | /** | ||
691 | 3 | * This program enables you to connect to sshd server and get the shell prompt. | ||
692 | 4 | * $ CLASSPATH=.:../build javac Shell.java | ||
693 | 5 | * $ CLASSPATH=.:../build java Shell | ||
694 | 6 | * You will be asked username, hostname and passwd. | ||
695 | 7 | * If everything works fine, you will get the shell prompt. Output will | ||
696 | 8 | * be ugly because of lacks of terminal-emulation, but you can issue commands. | ||
697 | 9 | * | ||
698 | 10 | */ | ||
699 | 2 | import com.jcraft.jsch.*; | 11 | import com.jcraft.jsch.*; |
700 | 3 | import java.awt.*; | 12 | import java.awt.*; |
701 | 4 | import javax.swing.*; | 13 | import javax.swing.*; |
702 | @@ -25,12 +34,36 @@ | |||
703 | 25 | 34 | ||
704 | 26 | Session session=jsch.getSession(user, host, 22); | 35 | Session session=jsch.getSession(user, host, 22); |
705 | 27 | 36 | ||
710 | 28 | //session.setPassword("your password"); | 37 | String passwd = JOptionPane.showInputDialog("Enter password"); |
711 | 29 | 38 | session.setPassword(passwd); | |
712 | 30 | // username and password will be given via UserInfo interface. | 39 | |
713 | 31 | UserInfo ui=new MyUserInfo(); | 40 | UserInfo ui = new MyUserInfo(){ |
714 | 41 | public void showMessage(String message){ | ||
715 | 42 | JOptionPane.showMessageDialog(null, message); | ||
716 | 43 | } | ||
717 | 44 | public boolean promptYesNo(String message){ | ||
718 | 45 | Object[] options={ "yes", "no" }; | ||
719 | 46 | int foo=JOptionPane.showOptionDialog(null, | ||
720 | 47 | message, | ||
721 | 48 | "Warning", | ||
722 | 49 | JOptionPane.DEFAULT_OPTION, | ||
723 | 50 | JOptionPane.WARNING_MESSAGE, | ||
724 | 51 | null, options, options[0]); | ||
725 | 52 | return foo==0; | ||
726 | 53 | } | ||
727 | 54 | |||
728 | 55 | // If password is not given before the invocation of Session#connect(), | ||
729 | 56 | // implement also following methods, | ||
730 | 57 | // * UserInfo#getPassword(), | ||
731 | 58 | // * UserInfo#promptPassword(String message) and | ||
732 | 59 | // * UIKeyboardInteractive#promptKeyboardInteractive() | ||
733 | 60 | |||
734 | 61 | }; | ||
735 | 62 | |||
736 | 32 | session.setUserInfo(ui); | 63 | session.setUserInfo(ui); |
737 | 33 | 64 | ||
738 | 65 | // It must not be recommended, but if you want to skip host-key check, | ||
739 | 66 | // invoke following, | ||
740 | 34 | // session.setConfig("StrictHostKeyChecking", "no"); | 67 | // session.setConfig("StrictHostKeyChecking", "no"); |
741 | 35 | 68 | ||
742 | 36 | //session.connect(); | 69 | //session.connect(); |
743 | @@ -71,97 +104,20 @@ | |||
744 | 71 | } | 104 | } |
745 | 72 | } | 105 | } |
746 | 73 | 106 | ||
763 | 74 | public static class MyUserInfo implements UserInfo, UIKeyboardInteractive{ | 107 | public static abstract class MyUserInfo |
764 | 75 | public String getPassword(){ return passwd; } | 108 | implements UserInfo, UIKeyboardInteractive{ |
765 | 76 | public boolean promptYesNo(String str){ | 109 | public String getPassword(){ return null; } |
766 | 77 | Object[] options={ "yes", "no" }; | 110 | public boolean promptYesNo(String str){ return false; } |
751 | 78 | int foo=JOptionPane.showOptionDialog(null, | ||
752 | 79 | str, | ||
753 | 80 | "Warning", | ||
754 | 81 | JOptionPane.DEFAULT_OPTION, | ||
755 | 82 | JOptionPane.WARNING_MESSAGE, | ||
756 | 83 | null, options, options[0]); | ||
757 | 84 | return foo==0; | ||
758 | 85 | } | ||
759 | 86 | |||
760 | 87 | String passwd; | ||
761 | 88 | JTextField passwordField=(JTextField)new JPasswordField(20); | ||
762 | 89 | |||
767 | 90 | public String getPassphrase(){ return null; } | 111 | public String getPassphrase(){ return null; } |
790 | 91 | public boolean promptPassphrase(String message){ return true; } | 112 | public boolean promptPassphrase(String message){ return false; } |
791 | 92 | public boolean promptPassword(String message){ | 113 | public boolean promptPassword(String message){ return false; } |
792 | 93 | Object[] ob={passwordField}; | 114 | public void showMessage(String message){ } |
771 | 94 | int result=JOptionPane.showConfirmDialog(null, ob, message, | ||
772 | 95 | JOptionPane.OK_CANCEL_OPTION); | ||
773 | 96 | if(result==JOptionPane.OK_OPTION){ | ||
774 | 97 | passwd=passwordField.getText(); | ||
775 | 98 | return true; | ||
776 | 99 | } | ||
777 | 100 | else{ | ||
778 | 101 | return false; | ||
779 | 102 | } | ||
780 | 103 | } | ||
781 | 104 | public void showMessage(String message){ | ||
782 | 105 | JOptionPane.showMessageDialog(null, message); | ||
783 | 106 | } | ||
784 | 107 | final GridBagConstraints gbc = | ||
785 | 108 | new GridBagConstraints(0,0,1,1,1,1, | ||
786 | 109 | GridBagConstraints.NORTHWEST, | ||
787 | 110 | GridBagConstraints.NONE, | ||
788 | 111 | new Insets(0,0,0,0),0,0); | ||
789 | 112 | private Container panel; | ||
793 | 113 | public String[] promptKeyboardInteractive(String destination, | 115 | public String[] promptKeyboardInteractive(String destination, |
794 | 114 | String name, | 116 | String name, |
795 | 115 | String instruction, | 117 | String instruction, |
796 | 116 | String[] prompt, | 118 | String[] prompt, |
797 | 117 | boolean[] echo){ | 119 | boolean[] echo){ |
843 | 118 | panel = new JPanel(); | 120 | return null; |
799 | 119 | panel.setLayout(new GridBagLayout()); | ||
800 | 120 | |||
801 | 121 | gbc.weightx = 1.0; | ||
802 | 122 | gbc.gridwidth = GridBagConstraints.REMAINDER; | ||
803 | 123 | gbc.gridx = 0; | ||
804 | 124 | panel.add(new JLabel(instruction), gbc); | ||
805 | 125 | gbc.gridy++; | ||
806 | 126 | |||
807 | 127 | gbc.gridwidth = GridBagConstraints.RELATIVE; | ||
808 | 128 | |||
809 | 129 | JTextField[] texts=new JTextField[prompt.length]; | ||
810 | 130 | for(int i=0; i<prompt.length; i++){ | ||
811 | 131 | gbc.fill = GridBagConstraints.NONE; | ||
812 | 132 | gbc.gridx = 0; | ||
813 | 133 | gbc.weightx = 1; | ||
814 | 134 | panel.add(new JLabel(prompt[i]),gbc); | ||
815 | 135 | |||
816 | 136 | gbc.gridx = 1; | ||
817 | 137 | gbc.fill = GridBagConstraints.HORIZONTAL; | ||
818 | 138 | gbc.weighty = 1; | ||
819 | 139 | if(echo[i]){ | ||
820 | 140 | texts[i]=new JTextField(20); | ||
821 | 141 | } | ||
822 | 142 | else{ | ||
823 | 143 | texts[i]=new JPasswordField(20); | ||
824 | 144 | } | ||
825 | 145 | panel.add(texts[i], gbc); | ||
826 | 146 | gbc.gridy++; | ||
827 | 147 | } | ||
828 | 148 | |||
829 | 149 | if(JOptionPane.showConfirmDialog(null, panel, | ||
830 | 150 | destination+": "+name, | ||
831 | 151 | JOptionPane.OK_CANCEL_OPTION, | ||
832 | 152 | JOptionPane.QUESTION_MESSAGE) | ||
833 | 153 | ==JOptionPane.OK_OPTION){ | ||
834 | 154 | String[] response=new String[prompt.length]; | ||
835 | 155 | for(int i=0; i<prompt.length; i++){ | ||
836 | 156 | response[i]=texts[i].getText(); | ||
837 | 157 | } | ||
838 | 158 | return response; | ||
839 | 159 | } | ||
840 | 160 | else{ | ||
841 | 161 | return null; // cancel | ||
842 | 162 | } | ||
844 | 163 | } | 121 | } |
845 | 164 | } | 122 | } |
846 | 165 | } | 123 | } |
847 | 166 | |||
848 | 167 | |||
849 | 168 | 124 | ||
850 | === modified file 'examples/StreamForwarding.java' | |||
851 | --- examples/StreamForwarding.java 2008-02-06 23:23:19 +0000 | |||
852 | +++ examples/StreamForwarding.java 2012-05-04 10:23:17 +0000 | |||
853 | @@ -1,4 +1,16 @@ | |||
854 | 1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ | 1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ |
855 | 2 | /** | ||
856 | 3 | * This program will demonstrate the stream forwarding. The given Java | ||
857 | 4 | * I/O streams will be forwared to the given remote host and port on | ||
858 | 5 | * the remote side. It is simmilar to the -L option of ssh command, | ||
859 | 6 | * but you don't have to assign and open a local tcp port. | ||
860 | 7 | * $ CLASSPATH=.:../build javac StreamForwarding.java | ||
861 | 8 | * $ CLASSPATH=.:../build java StreamForwarding | ||
862 | 9 | * You will be asked username, hostname, host:hostport and passwd. | ||
863 | 10 | * If everything works fine, System.in and System.out streams will be | ||
864 | 11 | * forwared to remote port and you can send messages from command line. | ||
865 | 12 | * | ||
866 | 13 | */ | ||
867 | 2 | import com.jcraft.jsch.*; | 14 | import com.jcraft.jsch.*; |
868 | 3 | import java.awt.*; | 15 | import java.awt.*; |
869 | 4 | import javax.swing.*; | 16 | import javax.swing.*; |
870 | 5 | 17 | ||
871 | === modified file 'examples/Subsystem.java' | |||
872 | --- examples/Subsystem.java 2008-02-06 23:23:19 +0000 | |||
873 | +++ examples/Subsystem.java 2012-05-04 10:23:17 +0000 | |||
874 | @@ -1,4 +1,8 @@ | |||
875 | 1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ | 1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ |
876 | 2 | /** | ||
877 | 3 | * This program will demonstrate how to use the Subsystem channel. | ||
878 | 4 | * | ||
879 | 5 | */ | ||
880 | 2 | import com.jcraft.jsch.*; | 6 | import com.jcraft.jsch.*; |
881 | 3 | import java.awt.*; | 7 | import java.awt.*; |
882 | 4 | import javax.swing.*; | 8 | import javax.swing.*; |
883 | 5 | 9 | ||
884 | === added file 'examples/Sudo.java' | |||
885 | --- examples/Sudo.java 1970-01-01 00:00:00 +0000 | |||
886 | +++ examples/Sudo.java 2012-05-04 10:23:17 +0000 | |||
887 | @@ -0,0 +1,184 @@ | |||
888 | 1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ | ||
889 | 2 | /** | ||
890 | 3 | * This program will demonstrate how to exec 'sudo' on the remote. | ||
891 | 4 | * | ||
892 | 5 | */ | ||
893 | 6 | import com.jcraft.jsch.*; | ||
894 | 7 | import java.awt.*; | ||
895 | 8 | import javax.swing.*; | ||
896 | 9 | import java.io.*; | ||
897 | 10 | |||
898 | 11 | public class Sudo{ | ||
899 | 12 | public static void main(String[] arg){ | ||
900 | 13 | try{ | ||
901 | 14 | JSch jsch=new JSch(); | ||
902 | 15 | |||
903 | 16 | String host=null; | ||
904 | 17 | if(arg.length>0){ | ||
905 | 18 | host=arg[0]; | ||
906 | 19 | } | ||
907 | 20 | else{ | ||
908 | 21 | host=JOptionPane.showInputDialog("Enter username@hostname", | ||
909 | 22 | System.getProperty("user.name")+ | ||
910 | 23 | "@localhost"); | ||
911 | 24 | } | ||
912 | 25 | String user=host.substring(0, host.indexOf('@')); | ||
913 | 26 | host=host.substring(host.indexOf('@')+1); | ||
914 | 27 | |||
915 | 28 | Session session=jsch.getSession(user, host, 22); | ||
916 | 29 | |||
917 | 30 | UserInfo ui=new MyUserInfo(); | ||
918 | 31 | session.setUserInfo(ui); | ||
919 | 32 | session.connect(); | ||
920 | 33 | |||
921 | 34 | String command=JOptionPane.showInputDialog("Enter command, execed with sudo", | ||
922 | 35 | "printenv SUDO_USER"); | ||
923 | 36 | |||
924 | 37 | String sudo_pass=null; | ||
925 | 38 | { | ||
926 | 39 | JTextField passwordField=(JTextField)new JPasswordField(8); | ||
927 | 40 | Object[] ob={passwordField}; | ||
928 | 41 | int result= | ||
929 | 42 | JOptionPane.showConfirmDialog(null, | ||
930 | 43 | ob, | ||
931 | 44 | "Enter password for sudo", | ||
932 | 45 | JOptionPane.OK_CANCEL_OPTION); | ||
933 | 46 | if(result!=JOptionPane.OK_OPTION){ | ||
934 | 47 | System.exit(-1); | ||
935 | 48 | } | ||
936 | 49 | sudo_pass=passwordField.getText(); | ||
937 | 50 | } | ||
938 | 51 | |||
939 | 52 | Channel channel=session.openChannel("exec"); | ||
940 | 53 | |||
941 | 54 | // man sudo | ||
942 | 55 | // -S The -S (stdin) option causes sudo to read the password from the | ||
943 | 56 | // standard input instead of the terminal device. | ||
944 | 57 | // -p The -p (prompt) option allows you to override the default | ||
945 | 58 | // password prompt and use a custom one. | ||
946 | 59 | ((ChannelExec)channel).setCommand("sudo -S -p '' "+command); | ||
947 | 60 | |||
948 | 61 | |||
949 | 62 | InputStream in=channel.getInputStream(); | ||
950 | 63 | OutputStream out=channel.getOutputStream(); | ||
951 | 64 | ((ChannelExec)channel).setErrStream(System.err); | ||
952 | 65 | |||
953 | 66 | channel.connect(); | ||
954 | 67 | |||
955 | 68 | out.write((sudo_pass+"\n").getBytes()); | ||
956 | 69 | out.flush(); | ||
957 | 70 | |||
958 | 71 | byte[] tmp=new byte[1024]; | ||
959 | 72 | while(true){ | ||
960 | 73 | while(in.available()>0){ | ||
961 | 74 | int i=in.read(tmp, 0, 1024); | ||
962 | 75 | if(i<0)break; | ||
963 | 76 | System.out.print(new String(tmp, 0, i)); | ||
964 | 77 | } | ||
965 | 78 | if(channel.isClosed()){ | ||
966 | 79 | System.out.println("exit-status: "+channel.getExitStatus()); | ||
967 | 80 | break; | ||
968 | 81 | } | ||
969 | 82 | try{Thread.sleep(1000);}catch(Exception ee){} | ||
970 | 83 | } | ||
971 | 84 | channel.disconnect(); | ||
972 | 85 | session.disconnect(); | ||
973 | 86 | } | ||
974 | 87 | catch(Exception e){ | ||
975 | 88 | System.out.println(e); | ||
976 | 89 | } | ||
977 | 90 | } | ||
978 | 91 | |||
979 | 92 | public static class MyUserInfo implements UserInfo, UIKeyboardInteractive{ | ||
980 | 93 | public String getPassword(){ return passwd; } | ||
981 | 94 | public boolean promptYesNo(String str){ | ||
982 | 95 | Object[] options={ "yes", "no" }; | ||
983 | 96 | int foo=JOptionPane.showOptionDialog(null, | ||
984 | 97 | str, | ||
985 | 98 | "Warning", | ||
986 | 99 | JOptionPane.DEFAULT_OPTION, | ||
987 | 100 | JOptionPane.WARNING_MESSAGE, | ||
988 | 101 | null, options, options[0]); | ||
989 | 102 | return foo==0; | ||
990 | 103 | } | ||
991 | 104 | |||
992 | 105 | String passwd; | ||
993 | 106 | JTextField passwordField=(JTextField)new JPasswordField(20); | ||
994 | 107 | |||
995 | 108 | public String getPassphrase(){ return null; } | ||
996 | 109 | public boolean promptPassphrase(String message){ return true; } | ||
997 | 110 | public boolean promptPassword(String message){ | ||
998 | 111 | Object[] ob={passwordField}; | ||
999 | 112 | int result= | ||
1000 | 113 | JOptionPane.showConfirmDialog(null, ob, message, | ||
1001 | 114 | JOptionPane.OK_CANCEL_OPTION); | ||
1002 | 115 | if(result==JOptionPane.OK_OPTION){ | ||
1003 | 116 | passwd=passwordField.getText(); | ||
1004 | 117 | return true; | ||
1005 | 118 | } | ||
1006 | 119 | else{ | ||
1007 | 120 | return false; | ||
1008 | 121 | } | ||
1009 | 122 | } | ||
1010 | 123 | public void showMessage(String message){ | ||
1011 | 124 | JOptionPane.showMessageDialog(null, message); | ||
1012 | 125 | } | ||
1013 | 126 | final GridBagConstraints gbc = | ||
1014 | 127 | new GridBagConstraints(0,0,1,1,1,1, | ||
1015 | 128 | GridBagConstraints.NORTHWEST, | ||
1016 | 129 | GridBagConstraints.NONE, | ||
1017 | 130 | new Insets(0,0,0,0),0,0); | ||
1018 | 131 | private Container panel; | ||
1019 | 132 | public String[] promptKeyboardInteractive(String destination, | ||
1020 | 133 | String name, | ||
1021 | 134 | String instruction, | ||
1022 | 135 | String[] prompt, | ||
1023 | 136 | boolean[] echo){ | ||
1024 | 137 | panel = new JPanel(); | ||
1025 | 138 | panel.setLayout(new GridBagLayout()); | ||
1026 | 139 | |||
1027 | 140 | gbc.weightx = 1.0; | ||
1028 | 141 | gbc.gridwidth = GridBagConstraints.REMAINDER; | ||
1029 | 142 | gbc.gridx = 0; | ||
1030 | 143 | panel.add(new JLabel(instruction), gbc); | ||
1031 | 144 | gbc.gridy++; | ||
1032 | 145 | |||
1033 | 146 | gbc.gridwidth = GridBagConstraints.RELATIVE; | ||
1034 | 147 | |||
1035 | 148 | JTextField[] texts=new JTextField[prompt.length]; | ||
1036 | 149 | for(int i=0; i<prompt.length; i++){ | ||
1037 | 150 | gbc.fill = GridBagConstraints.NONE; | ||
1038 | 151 | gbc.gridx = 0; | ||
1039 | 152 | gbc.weightx = 1; | ||
1040 | 153 | panel.add(new JLabel(prompt[i]),gbc); | ||
1041 | 154 | |||
1042 | 155 | gbc.gridx = 1; | ||
1043 | 156 | gbc.fill = GridBagConstraints.HORIZONTAL; | ||
1044 | 157 | gbc.weighty = 1; | ||
1045 | 158 | if(echo[i]){ | ||
1046 | 159 | texts[i]=new JTextField(20); | ||
1047 | 160 | } | ||
1048 | 161 | else{ | ||
1049 | 162 | texts[i]=new JPasswordField(20); | ||
1050 | 163 | } | ||
1051 | 164 | panel.add(texts[i], gbc); | ||
1052 | 165 | gbc.gridy++; | ||
1053 | 166 | } | ||
1054 | 167 | |||
1055 | 168 | if(JOptionPane.showConfirmDialog(null, panel, | ||
1056 | 169 | destination+": "+name, | ||
1057 | 170 | JOptionPane.OK_CANCEL_OPTION, | ||
1058 | 171 | JOptionPane.QUESTION_MESSAGE) | ||
1059 | 172 | ==JOptionPane.OK_OPTION){ | ||
1060 | 173 | String[] response=new String[prompt.length]; | ||
1061 | 174 | for(int i=0; i<prompt.length; i++){ | ||
1062 | 175 | response[i]=texts[i].getText(); | ||
1063 | 176 | } | ||
1064 | 177 | return response; | ||
1065 | 178 | } | ||
1066 | 179 | else{ | ||
1067 | 180 | return null; // cancel | ||
1068 | 181 | } | ||
1069 | 182 | } | ||
1070 | 183 | } | ||
1071 | 184 | } | ||
1072 | 0 | 185 | ||
1073 | === modified file 'examples/UserAuthKI.java' | |||
1074 | --- examples/UserAuthKI.java 2008-02-06 23:23:19 +0000 | |||
1075 | +++ examples/UserAuthKI.java 2012-05-04 10:23:17 +0000 | |||
1076 | @@ -1,4 +1,12 @@ | |||
1077 | 1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ | 1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ |
1078 | 2 | /** | ||
1079 | 3 | * This program will demonstrate the keyboard-interactive authentication. | ||
1080 | 4 | * $ CLASSPATH=.:../build javac UserAuthKI.java | ||
1081 | 5 | * $ CLASSPATH=.:../build java UserAuthKI | ||
1082 | 6 | * If the remote sshd supports keyboard-interactive authentication, | ||
1083 | 7 | * you will be prompted. | ||
1084 | 8 | * | ||
1085 | 9 | */ | ||
1086 | 2 | import com.jcraft.jsch.*; | 10 | import com.jcraft.jsch.*; |
1087 | 3 | import java.awt.*; | 11 | import java.awt.*; |
1088 | 4 | import javax.swing.*; | 12 | import javax.swing.*; |
1089 | 5 | 13 | ||
1090 | === modified file 'examples/UserAuthPubKey.java' | |||
1091 | --- examples/UserAuthPubKey.java 2008-02-06 23:23:19 +0000 | |||
1092 | +++ examples/UserAuthPubKey.java 2012-05-04 10:23:17 +0000 | |||
1093 | @@ -1,4 +1,12 @@ | |||
1094 | 1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ | 1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ |
1095 | 2 | /** | ||
1096 | 3 | * This program will demonstrate the user authentification by public key. | ||
1097 | 4 | * $ CLASSPATH=.:../build javac UserAuthPubKey.java | ||
1098 | 5 | * $ CLASSPATH=.:../build java UserAuthPubKey | ||
1099 | 6 | * You will be asked username, hostname, privatekey(id_dsa) and passphrase. | ||
1100 | 7 | * If everything works fine, you will get the shell prompt | ||
1101 | 8 | * | ||
1102 | 9 | */ | ||
1103 | 2 | import com.jcraft.jsch.*; | 10 | import com.jcraft.jsch.*; |
1104 | 3 | import java.awt.*; | 11 | import java.awt.*; |
1105 | 4 | import javax.swing.*; | 12 | import javax.swing.*; |
1106 | 5 | 13 | ||
1107 | === modified file 'examples/ViaHTTP.java' | |||
1108 | --- examples/ViaHTTP.java 2008-02-06 23:23:19 +0000 | |||
1109 | +++ examples/ViaHTTP.java 2012-05-04 10:23:17 +0000 | |||
1110 | @@ -1,4 +1,12 @@ | |||
1111 | 1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ | 1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ |
1112 | 2 | /** | ||
1113 | 3 | * This program will demonstrate the ssh session via HTTP proxy. | ||
1114 | 4 | * $ CLASSPATH=.:../build javac ViaHTTP.java | ||
1115 | 5 | * $ CLASSPATH=.:../build java ViaHTTP | ||
1116 | 6 | * You will be asked username, hostname, proxy-server and passwd. | ||
1117 | 7 | * If everything works fine, you will get the shell prompt. | ||
1118 | 8 | * | ||
1119 | 9 | */ | ||
1120 | 2 | import com.jcraft.jsch.*; | 10 | import com.jcraft.jsch.*; |
1121 | 3 | import java.awt.*; | 11 | import java.awt.*; |
1122 | 4 | import javax.swing.*; | 12 | import javax.swing.*; |
1123 | 5 | 13 | ||
1124 | === modified file 'examples/ViaSOCKS5.java' | |||
1125 | --- examples/ViaSOCKS5.java 2008-02-06 23:23:19 +0000 | |||
1126 | +++ examples/ViaSOCKS5.java 2012-05-04 10:23:17 +0000 | |||
1127 | @@ -1,4 +1,12 @@ | |||
1128 | 1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ | 1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ |
1129 | 2 | /** | ||
1130 | 3 | * This program will demonstrate the ssh session via SOCKS proxy. | ||
1131 | 4 | * $ CLASSPATH=.:../build javac ViaSOCKS.java | ||
1132 | 5 | * $ CLASSPATH=.:../build java ViaSOCKS | ||
1133 | 6 | * You will be asked username, hostname, proxy-server and passwd. | ||
1134 | 7 | * If everything works fine, you will get the shell prompt. | ||
1135 | 8 | * | ||
1136 | 9 | */ | ||
1137 | 2 | import com.jcraft.jsch.*; | 10 | import com.jcraft.jsch.*; |
1138 | 3 | import java.awt.*; | 11 | import java.awt.*; |
1139 | 4 | import javax.swing.*; | 12 | import javax.swing.*; |
1140 | 5 | 13 | ||
1141 | === modified file 'examples/X11Forwarding.java' | |||
1142 | --- examples/X11Forwarding.java 2008-02-06 23:23:19 +0000 | |||
1143 | +++ examples/X11Forwarding.java 2012-05-04 10:23:17 +0000 | |||
1144 | @@ -1,4 +1,14 @@ | |||
1145 | 1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ | 1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ |
1146 | 2 | /** | ||
1147 | 3 | * This program will demonstrate X11 forwarding. | ||
1148 | 4 | * $ CLASSPATH=.:../build javac X11Forwarding.java | ||
1149 | 5 | * $ CLASSPATH=.:../build java X11Forwarding | ||
1150 | 6 | * You will be asked username, hostname, displayname and passwd. | ||
1151 | 7 | * If your X server does not run at 127.0.0.1, please enter correct | ||
1152 | 8 | * displayname. If everything works fine, you will get the shell prompt. | ||
1153 | 9 | * Try X applications; for example, xlogo. | ||
1154 | 10 | * | ||
1155 | 11 | */ | ||
1156 | 2 | import com.jcraft.jsch.*; | 12 | import com.jcraft.jsch.*; |
1157 | 3 | import java.awt.*; | 13 | import java.awt.*; |
1158 | 4 | import javax.swing.*; | 14 | import javax.swing.*; |
1159 | 5 | 15 | ||
1160 | === added directory 'lib' | |||
1161 | === added directory 'src/main' | |||
1162 | === added directory 'src/main/java' | |||
1163 | === renamed directory 'src/com' => 'src/main/java/com' | |||
1164 | === modified file 'src/main/java/com/jcraft/jsch/Buffer.java' | |||
1165 | --- src/com/jcraft/jsch/Buffer.java 2010-06-27 23:17:34 +0000 | |||
1166 | +++ src/main/java/com/jcraft/jsch/Buffer.java 2012-05-04 10:23:17 +0000 | |||
1167 | @@ -1,6 +1,6 @@ | |||
1168 | 1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ | 1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ |
1169 | 2 | /* | 2 | /* |
1171 | 3 | Copyright (c) 2002-2009 ymnk, JCraft,Inc. All rights reserved. | 3 | Copyright (c) 2002-2012 ymnk, JCraft,Inc. All rights reserved. |
1172 | 4 | 4 | ||
1173 | 5 | Redistribution and use in source and binary forms, with or without | 5 | Redistribution and use in source and binary forms, with or without |
1174 | 6 | modification, are permitted provided that the following conditions are met: | 6 | modification, are permitted provided that the following conditions are met: |
1175 | @@ -123,6 +123,16 @@ | |||
1176 | 123 | foo = ((foo<<16)&0xffff0000) | (getShort()&0xffff); | 123 | foo = ((foo<<16)&0xffff0000) | (getShort()&0xffff); |
1177 | 124 | return foo; | 124 | return foo; |
1178 | 125 | } | 125 | } |
1179 | 126 | public long getUInt(){ | ||
1180 | 127 | long foo = 0L; | ||
1181 | 128 | long bar = 0L; | ||
1182 | 129 | foo = getByte(); | ||
1183 | 130 | foo = ((foo<<8)&0xff00)|(getByte()&0xff); | ||
1184 | 131 | bar = getByte(); | ||
1185 | 132 | bar = ((bar<<8)&0xff00)|(getByte()&0xff); | ||
1186 | 133 | foo = ((foo<<16)&0xffff0000) | (bar&0xffff); | ||
1187 | 134 | return foo; | ||
1188 | 135 | } | ||
1189 | 126 | int getShort() { | 136 | int getShort() { |
1190 | 127 | int foo = getByte(); | 137 | int foo = getByte(); |
1191 | 128 | foo = ((foo<<8)&0xff00)|(getByte()&0xff); | 138 | foo = ((foo<<8)&0xff00)|(getByte()&0xff); |
1192 | @@ -144,7 +154,12 @@ | |||
1193 | 144 | return foo; | 154 | return foo; |
1194 | 145 | } | 155 | } |
1195 | 146 | public byte[] getMPInt() { | 156 | public byte[] getMPInt() { |
1197 | 147 | int i=getInt(); | 157 | int i=getInt(); // uint32 |
1198 | 158 | if(i<0 || // bigger than 0x7fffffff | ||
1199 | 159 | i>8*1024){ | ||
1200 | 160 | // TODO: an exception should be thrown. | ||
1201 | 161 | i = 8*1024; // the session will be broken, but working around OOME. | ||
1202 | 162 | } | ||
1203 | 148 | byte[] foo=new byte[i]; | 163 | byte[] foo=new byte[i]; |
1204 | 149 | getByte(foo, 0, i); | 164 | getByte(foo, 0, i); |
1205 | 150 | return foo; | 165 | return foo; |
1206 | @@ -163,7 +178,12 @@ | |||
1207 | 163 | return foo; | 178 | return foo; |
1208 | 164 | } | 179 | } |
1209 | 165 | public byte[] getString() { | 180 | public byte[] getString() { |
1211 | 166 | int i=getInt(); | 181 | int i = getInt(); // uint32 |
1212 | 182 | if(i<0 || // bigger than 0x7fffffff | ||
1213 | 183 | i>256*1024){ | ||
1214 | 184 | // TODO: an exception should be thrown. | ||
1215 | 185 | i = 256*1024; // the session will be broken, but working around OOME. | ||
1216 | 186 | } | ||
1217 | 167 | byte[] foo=new byte[i]; | 187 | byte[] foo=new byte[i]; |
1218 | 168 | getByte(foo, 0, i); | 188 | getByte(foo, 0, i); |
1219 | 169 | return foo; | 189 | return foo; |
1220 | @@ -192,6 +212,14 @@ | |||
1221 | 192 | return buffer[5]; | 212 | return buffer[5]; |
1222 | 193 | } | 213 | } |
1223 | 194 | 214 | ||
1224 | 215 | void checkFreeSize(int n){ | ||
1225 | 216 | if(buffer.length<index+n){ | ||
1226 | 217 | byte[] tmp = new byte[buffer.length*2]; | ||
1227 | 218 | System.arraycopy(buffer, 0, tmp, 0, index); | ||
1228 | 219 | buffer = tmp; | ||
1229 | 220 | } | ||
1230 | 221 | } | ||
1231 | 222 | |||
1232 | 195 | /* | 223 | /* |
1233 | 196 | static String[] chars={ | 224 | static String[] chars={ |
1234 | 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" |
1235 | 198 | 226 | ||
1236 | === modified file 'src/main/java/com/jcraft/jsch/Channel.java' | |||
1237 | --- src/com/jcraft/jsch/Channel.java 2010-06-27 23:17:34 +0000 | |||
1238 | +++ src/main/java/com/jcraft/jsch/Channel.java 2012-05-04 10:23:17 +0000 | |||
1239 | @@ -1,6 +1,6 @@ | |||
1240 | 1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ | 1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ |
1241 | 2 | /* | 2 | /* |
1243 | 3 | Copyright (c) 2002-2009 ymnk, JCraft,Inc. All rights reserved. | 3 | Copyright (c) 2002-2012 ymnk, JCraft,Inc. All rights reserved. |
1244 | 4 | 4 | ||
1245 | 5 | Redistribution and use in source and binary forms, with or without | 5 | Redistribution and use in source and binary forms, with or without |
1246 | 6 | modification, are permitted provided that the following conditions are met: | 6 | modification, are permitted provided that the following conditions are met: |
1247 | @@ -95,30 +95,29 @@ | |||
1248 | 95 | } | 95 | } |
1249 | 96 | 96 | ||
1250 | 97 | int id; | 97 | int id; |
1258 | 98 | int recipient=-1; | 98 | volatile int recipient=-1; |
1259 | 99 | byte[] type="foo".getBytes(); | 99 | protected byte[] type=Util.str2byte("foo"); |
1260 | 100 | int lwsize_max=0x100000; | 100 | volatile int lwsize_max=0x100000; |
1261 | 101 | //int lwsize_max=0x20000; // 32*1024*4 | 101 | volatile int lwsize=lwsize_max; // local initial window size |
1262 | 102 | int lwsize=lwsize_max; // local initial window size | 102 | volatile int lmpsize=0x4000; // local maximum packet size |
1256 | 103 | int lmpsize=0x4000; // local maximum packet size | ||
1257 | 104 | //int lmpsize=0x8000; // local maximum packet size | ||
1263 | 105 | 103 | ||
1266 | 106 | int rwsize=0; // remote initial window size | 104 | volatile long rwsize=0; // remote initial window size |
1267 | 107 | int rmpsize=0; // remote maximum packet size | 105 | volatile int rmpsize=0; // remote maximum packet size |
1268 | 108 | 106 | ||
1269 | 109 | IO io=null; | 107 | IO io=null; |
1270 | 110 | Thread thread=null; | 108 | Thread thread=null; |
1271 | 111 | 109 | ||
1282 | 112 | boolean eof_local=false; | 110 | volatile boolean eof_local=false; |
1283 | 113 | boolean eof_remote=false; | 111 | volatile boolean eof_remote=false; |
1284 | 114 | 112 | ||
1285 | 115 | boolean close=false; | 113 | volatile boolean close=false; |
1286 | 116 | boolean connected=false; | 114 | volatile boolean connected=false; |
1287 | 117 | 115 | volatile boolean open_confirmation=false; | |
1288 | 118 | int exitstatus=-1; | 116 | |
1289 | 119 | 117 | volatile int exitstatus=-1; | |
1290 | 120 | int reply=0; | 118 | |
1291 | 121 | int connectTimeout=0; | 119 | volatile int reply=0; |
1292 | 120 | volatile int connectTimeout=0; | ||
1293 | 122 | 121 | ||
1294 | 123 | private Session session; | 122 | private Session session; |
1295 | 124 | 123 | ||
1296 | @@ -130,8 +129,10 @@ | |||
1297 | 130 | pool.addElement(this); | 129 | pool.addElement(this); |
1298 | 131 | } | 130 | } |
1299 | 132 | } | 131 | } |
1301 | 133 | void setRecipient(int foo){ | 132 | synchronized void setRecipient(int foo){ |
1302 | 134 | this.recipient=foo; | 133 | this.recipient=foo; |
1303 | 134 | if(notifyme>0) | ||
1304 | 135 | notifyAll(); | ||
1305 | 135 | } | 136 | } |
1306 | 136 | int getRecipient(){ | 137 | int getRecipient(){ |
1307 | 137 | return recipient; | 138 | return recipient; |
1308 | @@ -145,62 +146,14 @@ | |||
1309 | 145 | } | 146 | } |
1310 | 146 | 147 | ||
1311 | 147 | public void connect(int connectTimeout) throws JSchException{ | 148 | public void connect(int connectTimeout) throws JSchException{ |
1312 | 148 | Session _session=getSession(); | ||
1313 | 149 | if(!_session.isConnected()){ | ||
1314 | 150 | throw new JSchException("session is down"); | ||
1315 | 151 | } | ||
1316 | 152 | this.connectTimeout=connectTimeout; | 149 | this.connectTimeout=connectTimeout; |
1317 | 153 | try{ | 150 | try{ |
1364 | 154 | Buffer buf=new Buffer(100); | 151 | sendChannelOpen(); |
1319 | 155 | Packet packet=new Packet(buf); | ||
1320 | 156 | // send | ||
1321 | 157 | // byte SSH_MSG_CHANNEL_OPEN(90) | ||
1322 | 158 | // string channel type // | ||
1323 | 159 | // uint32 sender channel // 0 | ||
1324 | 160 | // uint32 initial window size // 0x100000(65536) | ||
1325 | 161 | // uint32 maxmum packet size // 0x4000(16384) | ||
1326 | 162 | packet.reset(); | ||
1327 | 163 | buf.putByte((byte)90); | ||
1328 | 164 | buf.putString(this.type); | ||
1329 | 165 | buf.putInt(this.id); | ||
1330 | 166 | buf.putInt(this.lwsize); | ||
1331 | 167 | buf.putInt(this.lmpsize); | ||
1332 | 168 | _session.write(packet); | ||
1333 | 169 | int retry=1000; | ||
1334 | 170 | long start=System.currentTimeMillis(); | ||
1335 | 171 | long timeout=connectTimeout; | ||
1336 | 172 | while(this.getRecipient()==-1 && | ||
1337 | 173 | _session.isConnected() && | ||
1338 | 174 | retry>0){ | ||
1339 | 175 | if(timeout>0L){ | ||
1340 | 176 | if((System.currentTimeMillis()-start)>timeout){ | ||
1341 | 177 | retry=0; | ||
1342 | 178 | continue; | ||
1343 | 179 | } | ||
1344 | 180 | } | ||
1345 | 181 | try{Thread.sleep(50);}catch(Exception ee){} | ||
1346 | 182 | retry--; | ||
1347 | 183 | } | ||
1348 | 184 | if(!_session.isConnected()){ | ||
1349 | 185 | throw new JSchException("session is down"); | ||
1350 | 186 | } | ||
1351 | 187 | if(retry==0){ | ||
1352 | 188 | throw new JSchException("channel is not opened."); | ||
1353 | 189 | } | ||
1354 | 190 | |||
1355 | 191 | /* | ||
1356 | 192 | * At the failure in opening the channel on the sshd, | ||
1357 | 193 | * 'SSH_MSG_CHANNEL_OPEN_FAILURE' will be sent from sshd and it will | ||
1358 | 194 | * be processed in Session#run(). | ||
1359 | 195 | */ | ||
1360 | 196 | if(this.isClosed()){ | ||
1361 | 197 | throw new JSchException("channel is not opened."); | ||
1362 | 198 | } | ||
1363 | 199 | connected=true; | ||
1365 | 200 | start(); | 152 | start(); |
1366 | 201 | } | 153 | } |
1367 | 202 | catch(Exception e){ | 154 | catch(Exception e){ |
1368 | 203 | connected=false; | 155 | connected=false; |
1369 | 156 | disconnect(); | ||
1370 | 204 | if(e instanceof JSchException) | 157 | if(e instanceof JSchException) |
1371 | 205 | throw (JSchException)e; | 158 | throw (JSchException)e; |
1372 | 206 | throw new JSchException(e.toString(), e); | 159 | throw new JSchException(e.toString(), e); |
1373 | @@ -216,7 +169,7 @@ | |||
1374 | 216 | 169 | ||
1375 | 217 | void getData(Buffer buf){ | 170 | void getData(Buffer buf){ |
1376 | 218 | setRecipient(buf.getInt()); | 171 | setRecipient(buf.getInt()); |
1378 | 219 | setRemoteWindowSize(buf.getInt()); | 172 | setRemoteWindowSize(buf.getUInt()); |
1379 | 220 | setRemotePacketSize(buf.getInt()); | 173 | setRemotePacketSize(buf.getInt()); |
1380 | 221 | } | 174 | } |
1381 | 222 | 175 | ||
1382 | @@ -274,7 +227,7 @@ | |||
1383 | 274 | packet=new Packet(buffer); | 227 | packet=new Packet(buffer); |
1384 | 275 | 228 | ||
1385 | 276 | byte[] _buf=buffer.buffer; | 229 | byte[] _buf=buffer.buffer; |
1387 | 277 | if(_buf.length-(14+0)-32-20<=0){ | 230 | if(_buf.length-(14+0)-Session.buffer_margin<=0){ |
1388 | 278 | buffer=null; | 231 | buffer=null; |
1389 | 279 | packet=null; | 232 | packet=null; |
1390 | 280 | throw new IOException("failed to initialize the channel."); | 233 | throw new IOException("failed to initialize the channel."); |
1391 | @@ -299,8 +252,8 @@ | |||
1392 | 299 | int _bufl=_buf.length; | 252 | int _bufl=_buf.length; |
1393 | 300 | while(l>0){ | 253 | while(l>0){ |
1394 | 301 | int _l=l; | 254 | int _l=l; |
1397 | 302 | if(l>_bufl-(14+dataLen)-32-20){ | 255 | if(l>_bufl-(14+dataLen)-Session.buffer_margin){ |
1398 | 303 | _l=_bufl-(14+dataLen)-32-20; | 256 | _l=_bufl-(14+dataLen)-Session.buffer_margin; |
1399 | 304 | } | 257 | } |
1400 | 305 | 258 | ||
1401 | 306 | if(_l<=0){ | 259 | if(_l<=0){ |
1402 | @@ -329,7 +282,10 @@ | |||
1403 | 329 | try{ | 282 | try{ |
1404 | 330 | int foo=dataLen; | 283 | int foo=dataLen; |
1405 | 331 | dataLen=0; | 284 | dataLen=0; |
1407 | 332 | getSession().write(packet, channel, foo); | 285 | synchronized(channel){ |
1408 | 286 | if(!channel.close) | ||
1409 | 287 | getSession().write(packet, channel, foo); | ||
1410 | 288 | } | ||
1411 | 333 | } | 289 | } |
1412 | 334 | catch(Exception e){ | 290 | catch(Exception e){ |
1413 | 335 | close(); | 291 | close(); |
1414 | @@ -371,11 +327,27 @@ | |||
1415 | 371 | super(out); | 327 | super(out); |
1416 | 372 | buffer=new byte[size]; | 328 | buffer=new byte[size]; |
1417 | 373 | } | 329 | } |
1418 | 330 | |||
1419 | 331 | /* | ||
1420 | 332 | * TODO: We should have our own Piped[I/O]Stream implementation. | ||
1421 | 333 | * Before accepting data, JDK's PipedInputStream will check the existence of | ||
1422 | 334 | * reader thread, and if it is not alive, the stream will be closed. | ||
1423 | 335 | * That behavior may cause the problem if multiple threads make access to it. | ||
1424 | 336 | */ | ||
1425 | 337 | public synchronized void updateReadSide() throws IOException { | ||
1426 | 338 | if(available() != 0){ // not empty | ||
1427 | 339 | return; | ||
1428 | 340 | } | ||
1429 | 341 | in = 0; | ||
1430 | 342 | out = 0; | ||
1431 | 343 | buffer[in++] = 0; | ||
1432 | 344 | read(); | ||
1433 | 345 | } | ||
1434 | 374 | } | 346 | } |
1435 | 375 | void setLocalWindowSizeMax(int foo){ this.lwsize_max=foo; } | 347 | void setLocalWindowSizeMax(int foo){ this.lwsize_max=foo; } |
1436 | 376 | void setLocalWindowSize(int foo){ this.lwsize=foo; } | 348 | void setLocalWindowSize(int foo){ this.lwsize=foo; } |
1437 | 377 | void setLocalPacketSize(int foo){ this.lmpsize=foo; } | 349 | void setLocalPacketSize(int foo){ this.lmpsize=foo; } |
1439 | 378 | synchronized void setRemoteWindowSize(int foo){ this.rwsize=foo; } | 350 | synchronized void setRemoteWindowSize(long foo){ this.rwsize=foo; } |
1440 | 379 | synchronized void addRemoteWindowSize(int foo){ | 351 | synchronized void addRemoteWindowSize(int foo){ |
1441 | 380 | this.rwsize+=foo; | 352 | this.rwsize+=foo; |
1442 | 381 | if(notifyme>0) | 353 | if(notifyme>0) |
1443 | @@ -409,18 +381,19 @@ | |||
1444 | 409 | } | 381 | } |
1445 | 410 | 382 | ||
1446 | 411 | void eof(){ | 383 | void eof(){ |
1447 | 412 | //System.err.println("EOF!!!! "+this); | ||
1448 | 413 | if(close)return; | ||
1449 | 414 | if(eof_local)return; | 384 | if(eof_local)return; |
1450 | 415 | eof_local=true; | 385 | eof_local=true; |
1452 | 416 | //close=eof; | 386 | |
1453 | 417 | try{ | 387 | try{ |
1454 | 418 | Buffer buf=new Buffer(100); | 388 | Buffer buf=new Buffer(100); |
1455 | 419 | Packet packet=new Packet(buf); | 389 | Packet packet=new Packet(buf); |
1456 | 420 | packet.reset(); | 390 | packet.reset(); |
1457 | 421 | buf.putByte((byte)Session.SSH_MSG_CHANNEL_EOF); | 391 | buf.putByte((byte)Session.SSH_MSG_CHANNEL_EOF); |
1458 | 422 | buf.putInt(getRecipient()); | 392 | buf.putInt(getRecipient()); |
1460 | 423 | getSession().write(packet); | 393 | synchronized(this){ |
1461 | 394 | if(!close) | ||
1462 | 395 | getSession().write(packet); | ||
1463 | 396 | } | ||
1464 | 424 | } | 397 | } |
1465 | 425 | catch(Exception e){ | 398 | catch(Exception e){ |
1466 | 426 | //System.err.println("Channel.eof"); | 399 | //System.err.println("Channel.eof"); |
1467 | @@ -468,10 +441,8 @@ | |||
1468 | 468 | */ | 441 | */ |
1469 | 469 | 442 | ||
1470 | 470 | void close(){ | 443 | void close(){ |
1471 | 471 | //System.err.println("close!!!!"); | ||
1472 | 472 | if(close)return; | 444 | if(close)return; |
1473 | 473 | close=true; | 445 | close=true; |
1474 | 474 | |||
1475 | 475 | eof_local=eof_remote=true; | 446 | eof_local=eof_remote=true; |
1476 | 476 | 447 | ||
1477 | 477 | try{ | 448 | try{ |
1478 | @@ -480,7 +451,9 @@ | |||
1479 | 480 | packet.reset(); | 451 | packet.reset(); |
1480 | 481 | buf.putByte((byte)Session.SSH_MSG_CHANNEL_CLOSE); | 452 | buf.putByte((byte)Session.SSH_MSG_CHANNEL_CLOSE); |
1481 | 482 | buf.putInt(getRecipient()); | 453 | buf.putInt(getRecipient()); |
1483 | 483 | getSession().write(packet); | 454 | synchronized(this){ |
1484 | 455 | getSession().write(packet); | ||
1485 | 456 | } | ||
1486 | 484 | } | 457 | } |
1487 | 485 | catch(Exception e){ | 458 | catch(Exception e){ |
1488 | 486 | //e.printStackTrace(); | 459 | //e.printStackTrace(); |
1489 | @@ -514,14 +487,15 @@ | |||
1490 | 514 | //System.err.println(this+":disconnect "+io+" "+connected); | 487 | //System.err.println(this+":disconnect "+io+" "+connected); |
1491 | 515 | //Thread.dumpStack(); | 488 | //Thread.dumpStack(); |
1492 | 516 | 489 | ||
1496 | 517 | synchronized(this){ | 490 | try{ |
1497 | 518 | if(!connected){ | 491 | |
1498 | 519 | return; | 492 | synchronized(this){ |
1499 | 493 | if(!connected){ | ||
1500 | 494 | return; | ||
1501 | 495 | } | ||
1502 | 496 | connected=false; | ||
1503 | 520 | } | 497 | } |
1504 | 521 | connected=false; | ||
1505 | 522 | } | ||
1506 | 523 | 498 | ||
1507 | 524 | try{ | ||
1508 | 525 | close(); | 499 | close(); |
1509 | 526 | 500 | ||
1510 | 527 | eof_remote=eof_local=true; | 501 | eof_remote=eof_local=true; |
1511 | @@ -628,11 +602,76 @@ | |||
1512 | 628 | buf.putByte((byte)SSH_MSG_CHANNEL_OPEN_FAILURE); | 602 | buf.putByte((byte)SSH_MSG_CHANNEL_OPEN_FAILURE); |
1513 | 629 | buf.putInt(getRecipient()); | 603 | buf.putInt(getRecipient()); |
1514 | 630 | buf.putInt(reasoncode); | 604 | buf.putInt(reasoncode); |
1517 | 631 | buf.putString("open failed".getBytes()); | 605 | buf.putString(Util.str2byte("open failed")); |
1518 | 632 | buf.putString("".getBytes()); | 606 | buf.putString(Util.empty); |
1519 | 633 | getSession().write(packet); | 607 | getSession().write(packet); |
1520 | 634 | } | 608 | } |
1521 | 635 | catch(Exception e){ | 609 | catch(Exception e){ |
1522 | 636 | } | 610 | } |
1523 | 637 | } | 611 | } |
1524 | 612 | |||
1525 | 613 | protected Packet genChannelOpenPacket(){ | ||
1526 | 614 | Buffer buf=new Buffer(100); | ||
1527 | 615 | Packet packet=new Packet(buf); | ||
1528 | 616 | // byte SSH_MSG_CHANNEL_OPEN(90) | ||
1529 | 617 | // string channel type // | ||
1530 | 618 | // uint32 sender channel // 0 | ||
1531 | 619 | // uint32 initial window size // 0x100000(65536) | ||
1532 | 620 | // uint32 maxmum packet size // 0x4000(16384) | ||
1533 | 621 | packet.reset(); | ||
1534 | 622 | buf.putByte((byte)90); | ||
1535 | 623 | buf.putString(this.type); | ||
1536 | 624 | buf.putInt(this.id); | ||
1537 | 625 | buf.putInt(this.lwsize); | ||
1538 | 626 | buf.putInt(this.lmpsize); | ||
1539 | 627 | return packet; | ||
1540 | 628 | } | ||
1541 | 629 | |||
1542 | 630 | protected void sendChannelOpen() throws Exception { | ||
1543 | 631 | Session _session=getSession(); | ||
1544 | 632 | if(!_session.isConnected()){ | ||
1545 | 633 | throw new JSchException("session is down"); | ||
1546 | 634 | } | ||
1547 | 635 | |||
1548 | 636 | Packet packet = genChannelOpenPacket(); | ||
1549 | 637 | _session.write(packet); | ||
1550 | 638 | |||
1551 | 639 | int retry=10; | ||
1552 | 640 | long start=System.currentTimeMillis(); | ||
1553 | 641 | long timeout=connectTimeout; | ||
1554 | 642 | if(timeout!=0L) retry = 1; | ||
1555 | 643 | synchronized(this){ | ||
1556 | 644 | while(this.getRecipient()==-1 && | ||
1557 | 645 | _session.isConnected() && | ||
1558 | 646 | retry>0){ | ||
1559 | 647 | if(timeout>0L){ | ||
1560 | 648 | if((System.currentTimeMillis()-start)>timeout){ | ||
1561 | 649 | retry=0; | ||
1562 | 650 | continue; | ||
1563 | 651 | } | ||
1564 | 652 | } | ||
1565 | 653 | try{ | ||
1566 | 654 | long t = timeout==0L ? 5000L : timeout; | ||
1567 | 655 | this.notifyme=1; | ||
1568 | 656 | wait(t); | ||
1569 | 657 | } | ||
1570 | 658 | catch(java.lang.InterruptedException e){ | ||
1571 | 659 | } | ||
1572 | 660 | finally{ | ||
1573 | 661 | this.notifyme=0; | ||
1574 | 662 | } | ||
1575 | 663 | retry--; | ||
1576 | 664 | } | ||
1577 | 665 | } | ||
1578 | 666 | if(!_session.isConnected()){ | ||
1579 | 667 | throw new JSchException("session is down"); | ||
1580 | 668 | } | ||
1581 | 669 | if(this.getRecipient()==-1){ // timeout | ||
1582 | 670 | throw new JSchException("channel is not opened."); | ||
1583 | 671 | } | ||
1584 | 672 | if(this.open_confirmation==false){ // SSH_MSG_CHANNEL_OPEN_FAILURE | ||
1585 | 673 | throw new JSchException("channel is not opened."); | ||
1586 | 674 | } | ||
1587 | 675 | connected=true; | ||
1588 | 676 | } | ||
1589 | 638 | } | 677 | } |
1590 | 639 | 678 | ||
1591 | === modified file 'src/main/java/com/jcraft/jsch/ChannelAgentForwarding.java' | |||
1592 | --- src/com/jcraft/jsch/ChannelAgentForwarding.java 2010-06-27 23:17:34 +0000 | |||
1593 | +++ src/main/java/com/jcraft/jsch/ChannelAgentForwarding.java 2012-05-04 10:23:17 +0000 | |||
1594 | @@ -1,6 +1,6 @@ | |||
1595 | 1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ | 1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ |
1596 | 2 | /* | 2 | /* |
1598 | 3 | Copyright (c) 2006-2009 ymnk, JCraft,Inc. All rights reserved. | 3 | Copyright (c) 2006-2012 ymnk, JCraft,Inc. All rights reserved. |
1599 | 4 | 4 | ||
1600 | 5 | Redistribution and use in source and binary forms, with or without | 5 | Redistribution and use in source and binary forms, with or without |
1601 | 6 | modification, are permitted provided that the following conditions are met: | 6 | modification, are permitted provided that the following conditions are met: |
1602 | @@ -37,14 +37,24 @@ | |||
1603 | 37 | static private final int LOCAL_WINDOW_SIZE_MAX=0x20000; | 37 | static private final int LOCAL_WINDOW_SIZE_MAX=0x20000; |
1604 | 38 | static private final int LOCAL_MAXIMUM_PACKET_SIZE=0x4000; | 38 | static private final int LOCAL_MAXIMUM_PACKET_SIZE=0x4000; |
1605 | 39 | 39 | ||
1614 | 40 | private final int SSH2_AGENTC_REQUEST_IDENTITIES=11; | 40 | private final byte SSH_AGENTC_REQUEST_RSA_IDENTITIES = 1; |
1615 | 41 | private final int SSH2_AGENT_IDENTITIES_ANSWER=12; | 41 | private final byte SSH_AGENT_RSA_IDENTITIES_ANSWER = 2; |
1616 | 42 | private final int SSH2_AGENTC_SIGN_REQUEST=13; | 42 | private final byte SSH_AGENTC_RSA_CHALLENGE = 3; |
1617 | 43 | private final int SSH2_AGENT_SIGN_RESPONSE=14; | 43 | private final byte SSH_AGENT_RSA_RESPONSE = 4; |
1618 | 44 | private final int SSH2_AGENTC_ADD_IDENTITY=17; | 44 | private final byte SSH_AGENT_FAILURE = 5; |
1619 | 45 | private final int SSH2_AGENTC_REMOVE_IDENTITY=18; | 45 | private final byte SSH_AGENT_SUCCESS = 6; |
1620 | 46 | private final int SSH2_AGENTC_REMOVE_ALL_IDENTITIES=19; | 46 | private final byte SSH_AGENTC_ADD_RSA_IDENTITY = 7; |
1621 | 47 | private final int SSH2_AGENT_FAILURE=30; | 47 | private final byte SSH_AGENTC_REMOVE_RSA_IDENTITY = 8; |
1622 | 48 | private final byte SSH_AGENTC_REMOVE_ALL_RSA_IDENTITIES = 9; | ||
1623 | 49 | |||
1624 | 50 | private final byte SSH2_AGENTC_REQUEST_IDENTITIES=11; | ||
1625 | 51 | private final byte SSH2_AGENT_IDENTITIES_ANSWER=12; | ||
1626 | 52 | private final byte SSH2_AGENTC_SIGN_REQUEST=13; | ||
1627 | 53 | private final byte SSH2_AGENT_SIGN_RESPONSE=14; | ||
1628 | 54 | private final byte SSH2_AGENTC_ADD_IDENTITY=17; | ||
1629 | 55 | private final byte SSH2_AGENTC_REMOVE_IDENTITY=18; | ||
1630 | 56 | private final byte SSH2_AGENTC_REMOVE_ALL_IDENTITIES=19; | ||
1631 | 57 | private final byte SSH2_AGENT_FAILURE=30; | ||
1632 | 48 | 58 | ||
1633 | 49 | boolean init=true; | 59 | boolean init=true; |
1634 | 50 | 60 | ||
1635 | @@ -60,7 +70,7 @@ | |||
1636 | 60 | setLocalWindowSize(LOCAL_WINDOW_SIZE_MAX); | 70 | setLocalWindowSize(LOCAL_WINDOW_SIZE_MAX); |
1637 | 61 | setLocalPacketSize(LOCAL_MAXIMUM_PACKET_SIZE); | 71 | setLocalPacketSize(LOCAL_MAXIMUM_PACKET_SIZE); |
1638 | 62 | 72 | ||
1640 | 63 | type="auth-agent@openssh.com".getBytes(); | 73 | type=Util.str2byte("auth-agent@openssh.com"); |
1641 | 64 | rbuf=new Buffer(); | 74 | rbuf=new Buffer(); |
1642 | 65 | rbuf.reset(); | 75 | rbuf.reset(); |
1643 | 66 | //wbuf=new Buffer(rmpsize); | 76 | //wbuf=new Buffer(rmpsize); |
1644 | @@ -111,12 +121,14 @@ | |||
1645 | 111 | throw new java.io.IOException(e.toString()); | 121 | throw new java.io.IOException(e.toString()); |
1646 | 112 | } | 122 | } |
1647 | 113 | 123 | ||
1649 | 114 | Vector identities=_session.jsch.identities; | 124 | IdentityRepository irepo = _session.getIdentityRepository(); |
1650 | 115 | UserInfo userinfo=_session.getUserInfo(); | 125 | UserInfo userinfo=_session.getUserInfo(); |
1651 | 116 | 126 | ||
1652 | 127 | mbuf.reset(); | ||
1653 | 128 | |||
1654 | 117 | if(typ==SSH2_AGENTC_REQUEST_IDENTITIES){ | 129 | if(typ==SSH2_AGENTC_REQUEST_IDENTITIES){ |
1657 | 118 | mbuf.reset(); | 130 | mbuf.putByte(SSH2_AGENT_IDENTITIES_ANSWER); |
1658 | 119 | mbuf.putByte((byte)SSH2_AGENT_IDENTITIES_ANSWER); | 131 | Vector identities = irepo.getIdentities(); |
1659 | 120 | synchronized(identities){ | 132 | synchronized(identities){ |
1660 | 121 | int count=0; | 133 | int count=0; |
1661 | 122 | for(int i=0; i<identities.size(); i++){ | 134 | for(int i=0; i<identities.size(); i++){ |
1662 | @@ -131,13 +143,13 @@ | |||
1663 | 131 | if(pubkeyblob==null) | 143 | if(pubkeyblob==null) |
1664 | 132 | continue; | 144 | continue; |
1665 | 133 | mbuf.putString(pubkeyblob); | 145 | mbuf.putString(pubkeyblob); |
1667 | 134 | mbuf.putString("".getBytes()); | 146 | mbuf.putString(Util.empty); |
1668 | 135 | } | 147 | } |
1669 | 136 | } | 148 | } |
1674 | 137 | byte[] bar=new byte[mbuf.getLength()]; | 149 | } |
1675 | 138 | mbuf.getByte(bar); | 150 | else if(typ==SSH_AGENTC_REQUEST_RSA_IDENTITIES) { |
1676 | 139 | 151 | mbuf.putByte(SSH_AGENT_RSA_IDENTITIES_ANSWER); | |
1677 | 140 | send(bar); | 152 | mbuf.putInt(0); |
1678 | 141 | } | 153 | } |
1679 | 142 | else if(typ==SSH2_AGENTC_SIGN_REQUEST){ | 154 | else if(typ==SSH2_AGENTC_SIGN_REQUEST){ |
1680 | 143 | byte[] blob=rbuf.getString(); | 155 | byte[] blob=rbuf.getString(); |
1681 | @@ -148,7 +160,8 @@ | |||
1682 | 148 | // datafellows = SSH_BUG_SIGBLOB; | 160 | // datafellows = SSH_BUG_SIGBLOB; |
1683 | 149 | // } | 161 | // } |
1684 | 150 | 162 | ||
1686 | 151 | Identity identity=null; | 163 | Vector identities = irepo.getIdentities(); |
1687 | 164 | Identity identity = null; | ||
1688 | 152 | synchronized(identities){ | 165 | synchronized(identities){ |
1689 | 153 | for(int i=0; i<identities.size(); i++){ | 166 | for(int i=0; i<identities.size(); i++){ |
1690 | 154 | Identity _identity=(Identity)(identities.elementAt(i)); | 167 | Identity _identity=(Identity)(identities.elementAt(i)); |
1691 | @@ -195,20 +208,41 @@ | |||
1692 | 195 | signature=identity.getSignature(data); | 208 | signature=identity.getSignature(data); |
1693 | 196 | } | 209 | } |
1694 | 197 | 210 | ||
1695 | 198 | mbuf.reset(); | ||
1696 | 199 | if(signature==null){ | 211 | if(signature==null){ |
1698 | 200 | mbuf.putByte((byte)SSH2_AGENT_FAILURE); | 212 | mbuf.putByte(SSH2_AGENT_FAILURE); |
1699 | 201 | } | 213 | } |
1700 | 202 | else{ | 214 | else{ |
1702 | 203 | mbuf.putByte((byte)SSH2_AGENT_SIGN_RESPONSE); | 215 | mbuf.putByte(SSH2_AGENT_SIGN_RESPONSE); |
1703 | 204 | mbuf.putString(signature); | 216 | mbuf.putString(signature); |
1704 | 205 | } | 217 | } |
1711 | 206 | 218 | } | |
1712 | 207 | byte[] bar=new byte[mbuf.getLength()]; | 219 | else if(typ==SSH2_AGENTC_REMOVE_IDENTITY){ |
1713 | 208 | mbuf.getByte(bar); | 220 | byte[] blob=rbuf.getString(); |
1714 | 209 | 221 | irepo.remove(blob); | |
1715 | 210 | send(bar); | 222 | mbuf.putByte(SSH_AGENT_SUCCESS); |
1716 | 211 | } | 223 | } |
1717 | 224 | else if(typ==SSH_AGENTC_REMOVE_ALL_RSA_IDENTITIES){ | ||
1718 | 225 | mbuf.putByte(SSH_AGENT_SUCCESS); | ||
1719 | 226 | } | ||
1720 | 227 | else if(typ==SSH2_AGENTC_REMOVE_ALL_IDENTITIES){ | ||
1721 | 228 | irepo.removeAll(); | ||
1722 | 229 | mbuf.putByte(SSH_AGENT_SUCCESS); | ||
1723 | 230 | } | ||
1724 | 231 | else if(typ==SSH2_AGENTC_ADD_IDENTITY){ | ||
1725 | 232 | int fooo = rbuf.getLength(); | ||
1726 | 233 | byte[] tmp = new byte[fooo]; | ||
1727 | 234 | rbuf.getByte(tmp); | ||
1728 | 235 | boolean result = irepo.add(tmp); | ||
1729 | 236 | mbuf.putByte(result ? SSH_AGENT_SUCCESS : SSH_AGENT_FAILURE); | ||
1730 | 237 | } | ||
1731 | 238 | else { | ||
1732 | 239 | rbuf.skip(rbuf.getLength()-1); | ||
1733 | 240 | mbuf.putByte(SSH_AGENT_FAILURE); | ||
1734 | 241 | } | ||
1735 | 242 | |||
1736 | 243 | byte[] response = new byte[mbuf.getLength()]; | ||
1737 | 244 | mbuf.getByte(response); | ||
1738 | 245 | send(response); | ||
1739 | 212 | } | 246 | } |
1740 | 213 | 247 | ||
1741 | 214 | private void send(byte[] message){ | 248 | private void send(byte[] message){ |
1742 | @@ -224,4 +258,9 @@ | |||
1743 | 224 | catch(Exception e){ | 258 | catch(Exception e){ |
1744 | 225 | } | 259 | } |
1745 | 226 | } | 260 | } |
1746 | 261 | |||
1747 | 262 | void eof_remote(){ | ||
1748 | 263 | super.eof_remote(); | ||
1749 | 264 | eof(); | ||
1750 | 265 | } | ||
1751 | 227 | } | 266 | } |
1752 | 228 | 267 | ||
1753 | === modified file 'src/main/java/com/jcraft/jsch/ChannelDirectTCPIP.java' | |||
1754 | --- src/com/jcraft/jsch/ChannelDirectTCPIP.java 2010-06-27 23:17:34 +0000 | |||
1755 | +++ src/main/java/com/jcraft/jsch/ChannelDirectTCPIP.java 2012-05-04 10:23:17 +0000 | |||
1756 | @@ -1,6 +1,6 @@ | |||
1757 | 1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ | 1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ |
1758 | 2 | /* | 2 | /* |
1760 | 3 | Copyright (c) 2002-2009 ymnk, JCraft,Inc. All rights reserved. | 3 | Copyright (c) 2002-2012 ymnk, JCraft,Inc. All rights reserved. |
1761 | 4 | 4 | ||
1762 | 5 | Redistribution and use in source and binary forms, with or without | 5 | Redistribution and use in source and binary forms, with or without |
1763 | 6 | modification, are permitted provided that the following conditions are met: | 6 | modification, are permitted provided that the following conditions are met: |
1764 | @@ -35,7 +35,7 @@ | |||
1765 | 35 | 35 | ||
1766 | 36 | static private final int LOCAL_WINDOW_SIZE_MAX=0x20000; | 36 | static private final int LOCAL_WINDOW_SIZE_MAX=0x20000; |
1767 | 37 | static private final int LOCAL_MAXIMUM_PACKET_SIZE=0x4000; | 37 | static private final int LOCAL_MAXIMUM_PACKET_SIZE=0x4000; |
1769 | 38 | 38 | static private final byte[] _type = Util.str2byte("direct-tcpip"); | |
1770 | 39 | String host; | 39 | String host; |
1771 | 40 | int port; | 40 | int port; |
1772 | 41 | 41 | ||
1773 | @@ -44,18 +44,14 @@ | |||
1774 | 44 | 44 | ||
1775 | 45 | ChannelDirectTCPIP(){ | 45 | ChannelDirectTCPIP(){ |
1776 | 46 | super(); | 46 | super(); |
1777 | 47 | type = _type; | ||
1778 | 47 | setLocalWindowSizeMax(LOCAL_WINDOW_SIZE_MAX); | 48 | setLocalWindowSizeMax(LOCAL_WINDOW_SIZE_MAX); |
1779 | 48 | setLocalWindowSize(LOCAL_WINDOW_SIZE_MAX); | 49 | setLocalWindowSize(LOCAL_WINDOW_SIZE_MAX); |
1780 | 49 | setLocalPacketSize(LOCAL_MAXIMUM_PACKET_SIZE); | 50 | setLocalPacketSize(LOCAL_MAXIMUM_PACKET_SIZE); |
1781 | 50 | } | 51 | } |
1782 | 51 | 52 | ||
1783 | 52 | void init (){ | 53 | void init (){ |
1790 | 53 | try{ | 54 | io=new IO(); |
1785 | 54 | io=new IO(); | ||
1786 | 55 | } | ||
1787 | 56 | catch(Exception e){ | ||
1788 | 57 | System.err.println(e); | ||
1789 | 58 | } | ||
1791 | 59 | } | 55 | } |
1792 | 60 | 56 | ||
1793 | 61 | public void connect() throws JSchException{ | 57 | public void connect() throws JSchException{ |
1794 | @@ -64,54 +60,6 @@ | |||
1795 | 64 | if(!_session.isConnected()){ | 60 | if(!_session.isConnected()){ |
1796 | 65 | throw new JSchException("session is down"); | 61 | throw new JSchException("session is down"); |
1797 | 66 | } | 62 | } |
1798 | 67 | Buffer buf=new Buffer(150); | ||
1799 | 68 | Packet packet=new Packet(buf); | ||
1800 | 69 | // send | ||
1801 | 70 | // byte SSH_MSG_CHANNEL_OPEN(90) | ||
1802 | 71 | // string channel type // | ||
1803 | 72 | // uint32 sender channel // 0 | ||
1804 | 73 | // uint32 initial window size // 0x100000(65536) | ||
1805 | 74 | // uint32 maxmum packet size // 0x4000(16384) | ||
1806 | 75 | |||
1807 | 76 | packet.reset(); | ||
1808 | 77 | buf.putByte((byte)90); | ||
1809 | 78 | buf.putString("direct-tcpip".getBytes()); | ||
1810 | 79 | buf.putInt(id); | ||
1811 | 80 | buf.putInt(lwsize); | ||
1812 | 81 | buf.putInt(lmpsize); | ||
1813 | 82 | buf.putString(host.getBytes()); | ||
1814 | 83 | buf.putInt(port); | ||
1815 | 84 | buf.putString(originator_IP_address.getBytes()); | ||
1816 | 85 | buf.putInt(originator_port); | ||
1817 | 86 | _session.write(packet); | ||
1818 | 87 | |||
1819 | 88 | int retry=1000; | ||
1820 | 89 | try{ | ||
1821 | 90 | while(this.getRecipient()==-1 && | ||
1822 | 91 | _session.isConnected() && | ||
1823 | 92 | retry>0 && | ||
1824 | 93 | !eof_remote){ | ||
1825 | 94 | //Thread.sleep(500); | ||
1826 | 95 | Thread.sleep(50); | ||
1827 | 96 | retry--; | ||
1828 | 97 | } | ||
1829 | 98 | } | ||
1830 | 99 | catch(Exception ee){ | ||
1831 | 100 | } | ||
1832 | 101 | if(!_session.isConnected()){ | ||
1833 | 102 | throw new JSchException("session is down"); | ||
1834 | 103 | } | ||
1835 | 104 | if(retry==0 || this.eof_remote){ | ||
1836 | 105 | throw new JSchException("channel is not opened."); | ||
1837 | 106 | } | ||
1838 | 107 | /* | ||
1839 | 108 | if(this.eof_remote){ // failed to open | ||
1840 | 109 | disconnect(); | ||
1841 | 110 | return; | ||
1842 | 111 | } | ||
1843 | 112 | */ | ||
1844 | 113 | |||
1845 | 114 | connected=true; | ||
1846 | 115 | 63 | ||
1847 | 116 | if(io.in!=null){ | 64 | if(io.in!=null){ |
1848 | 117 | thread=new Thread(this); | 65 | thread=new Thread(this); |
1849 | @@ -121,6 +69,9 @@ | |||
1850 | 121 | } | 69 | } |
1851 | 122 | thread.start(); | 70 | thread.start(); |
1852 | 123 | } | 71 | } |
1853 | 72 | else { | ||
1854 | 73 | sendChannelOpen(); | ||
1855 | 74 | } | ||
1856 | 124 | } | 75 | } |
1857 | 125 | catch(Exception e){ | 76 | catch(Exception e){ |
1858 | 126 | io.close(); | 77 | io.close(); |
1859 | @@ -134,12 +85,14 @@ | |||
1860 | 134 | 85 | ||
1861 | 135 | public void run(){ | 86 | public void run(){ |
1862 | 136 | 87 | ||
1863 | 137 | Buffer buf=new Buffer(rmpsize); | ||
1864 | 138 | Packet packet=new Packet(buf); | ||
1865 | 139 | int i=0; | ||
1866 | 140 | |||
1867 | 141 | try{ | 88 | try{ |
1868 | 89 | sendChannelOpen(); | ||
1869 | 90 | |||
1870 | 91 | Buffer buf=new Buffer(rmpsize); | ||
1871 | 92 | Packet packet=new Packet(buf); | ||
1872 | 142 | Session _session=getSession(); | 93 | Session _session=getSession(); |
1873 | 94 | int i=0; | ||
1874 | 95 | |||
1875 | 143 | while(isConnected() && | 96 | while(isConnected() && |
1876 | 144 | thread!=null && | 97 | thread!=null && |
1877 | 145 | io!=null && | 98 | io!=null && |
1878 | @@ -147,26 +100,27 @@ | |||
1879 | 147 | i=io.in.read(buf.buffer, | 100 | i=io.in.read(buf.buffer, |
1880 | 148 | 14, | 101 | 14, |
1881 | 149 | buf.buffer.length-14 | 102 | buf.buffer.length-14 |
1883 | 150 | -32 -20 // padding and mac | 103 | -Session.buffer_margin |
1884 | 151 | ); | 104 | ); |
1885 | 152 | |||
1886 | 153 | if(i<=0){ | 105 | if(i<=0){ |
1887 | 154 | eof(); | 106 | eof(); |
1888 | 155 | break; | 107 | break; |
1889 | 156 | } | 108 | } |
1890 | 157 | if(close)break; | ||
1891 | 158 | packet.reset(); | 109 | packet.reset(); |
1892 | 159 | buf.putByte((byte)Session.SSH_MSG_CHANNEL_DATA); | 110 | buf.putByte((byte)Session.SSH_MSG_CHANNEL_DATA); |
1893 | 160 | buf.putInt(recipient); | 111 | buf.putInt(recipient); |
1894 | 161 | buf.putInt(i); | 112 | buf.putInt(i); |
1895 | 162 | buf.skip(i); | 113 | buf.skip(i); |
1897 | 163 | _session.write(packet, this, i); | 114 | synchronized(this){ |
1898 | 115 | if(close) | ||
1899 | 116 | break; | ||
1900 | 117 | _session.write(packet, this, i); | ||
1901 | 118 | } | ||
1902 | 164 | } | 119 | } |
1903 | 165 | } | 120 | } |
1904 | 166 | catch(Exception e){ | 121 | catch(Exception e){ |
1905 | 167 | } | 122 | } |
1906 | 168 | disconnect(); | 123 | disconnect(); |
1907 | 169 | //System.err.println("connect end"); | ||
1908 | 170 | } | 124 | } |
1909 | 171 | 125 | ||
1910 | 172 | public void setInputStream(InputStream in){ | 126 | public void setInputStream(InputStream in){ |
1911 | @@ -180,4 +134,25 @@ | |||
1912 | 180 | public void setPort(int port){this.port=port;} | 134 | public void setPort(int port){this.port=port;} |
1913 | 181 | public void setOrgIPAddress(String foo){this.originator_IP_address=foo;} | 135 | public void setOrgIPAddress(String foo){this.originator_IP_address=foo;} |
1914 | 182 | public void setOrgPort(int foo){this.originator_port=foo;} | 136 | public void setOrgPort(int foo){this.originator_port=foo;} |
1915 | 137 | |||
1916 | 138 | protected Packet genChannelOpenPacket(){ | ||
1917 | 139 | Buffer buf = new Buffer(150); | ||
1918 | 140 | Packet packet = new Packet(buf); | ||
1919 | 141 | // byte SSH_MSG_CHANNEL_OPEN(90) | ||
1920 | 142 | // string channel type // | ||
1921 | 143 | // uint32 sender channel // 0 | ||
1922 | 144 | // uint32 initial window size // 0x100000(65536) | ||
1923 | 145 | // uint32 maxmum packet size // 0x4000(16384) | ||
1924 | 146 | packet.reset(); | ||
1925 | 147 | buf.putByte((byte)90); | ||
1926 | 148 | buf.putString(this.type); | ||
1927 | 149 | buf.putInt(id); | ||
1928 | 150 | buf.putInt(lwsize); | ||
1929 | 151 | buf.putInt(lmpsize); | ||
1930 | 152 | buf.putString(Util.str2byte(host)); | ||
1931 | 153 | buf.putInt(port); | ||
1932 | 154 | buf.putString(Util.str2byte(originator_IP_address)); | ||
1933 | 155 | buf.putInt(originator_port); | ||
1934 | 156 | return packet; | ||
1935 | 157 | } | ||
1936 | 183 | } | 158 | } |
1937 | 184 | 159 | ||
1938 | === modified file 'src/main/java/com/jcraft/jsch/ChannelExec.java' | |||
1939 | --- src/com/jcraft/jsch/ChannelExec.java 2010-06-27 23:17:34 +0000 | |||
1940 | +++ src/main/java/com/jcraft/jsch/ChannelExec.java 2012-05-04 10:23:17 +0000 | |||
1941 | @@ -1,6 +1,6 @@ | |||
1942 | 1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ | 1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ |
1943 | 2 | /* | 2 | /* |
1945 | 3 | Copyright (c) 2002-2009 ymnk, JCraft,Inc. All rights reserved. | 3 | Copyright (c) 2002-2012 ymnk, JCraft,Inc. All rights reserved. |
1946 | 4 | 4 | ||
1947 | 5 | Redistribution and use in source and binary forms, with or without | 5 | Redistribution and use in source and binary forms, with or without |
1948 | 6 | modification, are permitted provided that the following conditions are met: | 6 | modification, are permitted provided that the following conditions are met: |
1949 | @@ -60,7 +60,7 @@ | |||
1950 | 60 | } | 60 | } |
1951 | 61 | 61 | ||
1952 | 62 | public void setCommand(String command){ | 62 | public void setCommand(String command){ |
1954 | 63 | this.command=command.getBytes(); | 63 | this.command=Util.str2byte(command); |
1955 | 64 | } | 64 | } |
1956 | 65 | public void setCommand(byte[] command){ | 65 | public void setCommand(byte[] command){ |
1957 | 66 | this.command=command; | 66 | this.command=command; |
1958 | 67 | 67 | ||
1959 | === modified file 'src/main/java/com/jcraft/jsch/ChannelForwardedTCPIP.java' | |||
1960 | --- src/com/jcraft/jsch/ChannelForwardedTCPIP.java 2010-06-27 23:17:34 +0000 | |||
1961 | +++ src/main/java/com/jcraft/jsch/ChannelForwardedTCPIP.java 2012-05-04 10:23:17 +0000 | |||
1962 | @@ -1,6 +1,6 @@ | |||
1963 | 1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ | 1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ |
1964 | 2 | /* | 2 | /* |
1966 | 3 | Copyright (c) 2002-2009 ymnk, JCraft,Inc. All rights reserved. | 3 | Copyright (c) 2002-2012 ymnk, JCraft,Inc. All rights reserved. |
1967 | 4 | 4 | ||
1968 | 5 | Redistribution and use in source and binary forms, with or without | 5 | Redistribution and use in source and binary forms, with or without |
1969 | 6 | modification, are permitted provided that the following conditions are met: | 6 | modification, are permitted provided that the following conditions are met: |
1970 | @@ -97,25 +97,29 @@ | |||
1971 | 97 | Packet packet=new Packet(buf); | 97 | Packet packet=new Packet(buf); |
1972 | 98 | int i=0; | 98 | int i=0; |
1973 | 99 | try{ | 99 | try{ |
1974 | 100 | Session _session = getSession(); | ||
1975 | 100 | while(thread!=null && | 101 | while(thread!=null && |
1976 | 101 | io!=null && | 102 | io!=null && |
1977 | 102 | io.in!=null){ | 103 | io.in!=null){ |
1978 | 103 | i=io.in.read(buf.buffer, | 104 | i=io.in.read(buf.buffer, |
1979 | 104 | 14, | 105 | 14, |
1980 | 105 | buf.buffer.length-14 | 106 | buf.buffer.length-14 |
1982 | 106 | -32 -20 // padding and mac | 107 | -Session.buffer_margin |
1983 | 107 | ); | 108 | ); |
1984 | 108 | if(i<=0){ | 109 | if(i<=0){ |
1985 | 109 | eof(); | 110 | eof(); |
1986 | 110 | break; | 111 | break; |
1987 | 111 | } | 112 | } |
1988 | 112 | packet.reset(); | 113 | packet.reset(); |
1989 | 113 | if(close)break; | ||
1990 | 114 | buf.putByte((byte)Session.SSH_MSG_CHANNEL_DATA); | 114 | buf.putByte((byte)Session.SSH_MSG_CHANNEL_DATA); |
1991 | 115 | buf.putInt(recipient); | 115 | buf.putInt(recipient); |
1992 | 116 | buf.putInt(i); | 116 | buf.putInt(i); |
1993 | 117 | buf.skip(i); | 117 | buf.skip(i); |
1995 | 118 | getSession().write(packet, this, i); | 118 | synchronized(this){ |
1996 | 119 | if(close) | ||
1997 | 120 | break; | ||
1998 | 121 | _session.write(packet, this, i); | ||
1999 | 122 | } | ||
2000 | 119 | } | 123 | } |
2001 | 120 | } | 124 | } |
2002 | 121 | catch(Exception e){ | 125 | catch(Exception e){ |
2003 | @@ -128,7 +132,7 @@ | |||
2004 | 128 | 132 | ||
2005 | 129 | void getData(Buffer buf){ | 133 | void getData(Buffer buf){ |
2006 | 130 | setRecipient(buf.getInt()); | 134 | setRecipient(buf.getInt()); |
2008 | 131 | setRemoteWindowSize(buf.getInt()); | 135 | setRemoteWindowSize(buf.getUInt()); |
2009 | 132 | setRemotePacketSize(buf.getInt()); | 136 | setRemotePacketSize(buf.getInt()); |
2010 | 133 | byte[] addr=buf.getString(); | 137 | byte[] addr=buf.getString(); |
2011 | 134 | int port=buf.getInt(); | 138 | int port=buf.getInt(); |
2012 | @@ -136,9 +140,9 @@ | |||
2013 | 136 | int orgport=buf.getInt(); | 140 | int orgport=buf.getInt(); |
2014 | 137 | 141 | ||
2015 | 138 | /* | 142 | /* |
2017 | 139 | System.err.println("addr: "+new String(addr)); | 143 | System.err.println("addr: "+Util.byte2str(addr)); |
2018 | 140 | System.err.println("port: "+port); | 144 | System.err.println("port: "+port); |
2020 | 141 | System.err.println("orgaddr: "+new String(orgaddr)); | 145 | System.err.println("orgaddr: "+Util.byte2str(orgaddr)); |
2021 | 142 | System.err.println("orgport: "+orgport); | 146 | System.err.println("orgport: "+orgport); |
2022 | 143 | */ | 147 | */ |
2023 | 144 | 148 | ||
2024 | @@ -277,9 +281,9 @@ | |||
2025 | 277 | // uint32 port number to bind | 281 | // uint32 port number to bind |
2026 | 278 | packet.reset(); | 282 | packet.reset(); |
2027 | 279 | buf.putByte((byte) 80/*SSH_MSG_GLOBAL_REQUEST*/); | 283 | buf.putByte((byte) 80/*SSH_MSG_GLOBAL_REQUEST*/); |
2029 | 280 | buf.putString("cancel-tcpip-forward".getBytes()); | 284 | buf.putString(Util.str2byte("cancel-tcpip-forward")); |
2030 | 281 | buf.putByte((byte)0); | 285 | buf.putByte((byte)0); |
2032 | 282 | buf.putString(address_to_bind.getBytes()); | 286 | buf.putString(Util.str2byte(address_to_bind)); |
2033 | 283 | buf.putInt(rport); | 287 | buf.putInt(rport); |
2034 | 284 | session.write(packet); | 288 | session.write(packet); |
2035 | 285 | } | 289 | } |
2036 | 286 | 290 | ||
2037 | === modified file 'src/main/java/com/jcraft/jsch/ChannelSession.java' | |||
2038 | --- src/com/jcraft/jsch/ChannelSession.java 2010-06-27 23:17:34 +0000 | |||
2039 | +++ src/main/java/com/jcraft/jsch/ChannelSession.java 2012-05-04 10:23:17 +0000 | |||
2040 | @@ -1,6 +1,6 @@ | |||
2041 | 1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ | 1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ |
2042 | 2 | /* | 2 | /* |
2044 | 3 | Copyright (c) 2002-2009 ymnk, JCraft,Inc. All rights reserved. | 3 | Copyright (c) 2002-2012 ymnk, JCraft,Inc. All rights reserved. |
2045 | 4 | 4 | ||
2046 | 5 | Redistribution and use in source and binary forms, with or without | 5 | Redistribution and use in source and binary forms, with or without |
2047 | 6 | modification, are permitted provided that the following conditions are met: | 6 | modification, are permitted provided that the following conditions are met: |
2048 | @@ -32,7 +32,7 @@ | |||
2049 | 32 | import java.util.*; | 32 | import java.util.*; |
2050 | 33 | 33 | ||
2051 | 34 | class ChannelSession extends Channel{ | 34 | class ChannelSession extends Channel{ |
2053 | 35 | private static byte[] _session="session".getBytes(); | 35 | private static byte[] _session=Util.str2byte("session"); |
2054 | 36 | 36 | ||
2055 | 37 | protected boolean agent_forwarding=false; | 37 | protected boolean agent_forwarding=false; |
2056 | 38 | protected boolean xforwading=false; | 38 | protected boolean xforwading=false; |
2057 | @@ -94,7 +94,7 @@ | |||
2058 | 94 | * @see RFC4254 6.4 Environment Variable Passing | 94 | * @see RFC4254 6.4 Environment Variable Passing |
2059 | 95 | */ | 95 | */ |
2060 | 96 | public void setEnv(String name, String value){ | 96 | public void setEnv(String name, String value){ |
2062 | 97 | setEnv(name.getBytes(), value.getBytes()); | 97 | setEnv(Util.str2byte(name), Util.str2byte(value)); |
2063 | 98 | } | 98 | } |
2064 | 99 | 99 | ||
2065 | 100 | /** | 100 | /** |
2066 | @@ -226,7 +226,7 @@ | |||
2067 | 226 | 226 | ||
2068 | 227 | private byte[] toByteArray(Object o){ | 227 | private byte[] toByteArray(Object o){ |
2069 | 228 | if(o instanceof String){ | 228 | if(o instanceof String){ |
2071 | 229 | return ((String)o).getBytes(); | 229 | return Util.str2byte((String)o); |
2072 | 230 | } | 230 | } |
2073 | 231 | return (byte[])o; | 231 | return (byte[])o; |
2074 | 232 | } | 232 | } |
2075 | @@ -245,7 +245,7 @@ | |||
2076 | 245 | i=io.in.read(buf.buffer, | 245 | i=io.in.read(buf.buffer, |
2077 | 246 | 14, | 246 | 14, |
2078 | 247 | buf.buffer.length-14 | 247 | buf.buffer.length-14 |
2080 | 248 | -32 -20 // padding and mac | 248 | -Session.buffer_margin |
2081 | 249 | ); | 249 | ); |
2082 | 250 | if(i==0)continue; | 250 | if(i==0)continue; |
2083 | 251 | if(i==-1){ | 251 | if(i==-1){ |
2084 | @@ -266,8 +266,9 @@ | |||
2085 | 266 | //System.err.println("# ChannelExec.run"); | 266 | //System.err.println("# ChannelExec.run"); |
2086 | 267 | //e.printStackTrace(); | 267 | //e.printStackTrace(); |
2087 | 268 | } | 268 | } |
2090 | 269 | if(thread!=null){ | 269 | Thread _thread=thread; |
2091 | 270 | synchronized(thread){ thread.notifyAll(); } | 270 | if(_thread!=null){ |
2092 | 271 | synchronized(_thread){ _thread.notifyAll(); } | ||
2093 | 271 | } | 272 | } |
2094 | 272 | thread=null; | 273 | thread=null; |
2095 | 273 | //System.err.println(this+":run <"); | 274 | //System.err.println(this+":run <"); |
2096 | 274 | 275 | ||
2097 | === modified file 'src/main/java/com/jcraft/jsch/ChannelSftp.java' | |||
2098 | --- src/com/jcraft/jsch/ChannelSftp.java 2010-06-27 23:17:34 +0000 | |||
2099 | +++ src/main/java/com/jcraft/jsch/ChannelSftp.java 2012-05-04 10:23:17 +0000 | |||
2100 | @@ -1,6 +1,6 @@ | |||
2101 | 1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ | 1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ |
2102 | 2 | /* | 2 | /* |
2104 | 3 | Copyright (c) 2002-2009 ymnk, JCraft,Inc. All rights reserved. | 3 | Copyright (c) 2002-2012 ymnk, JCraft,Inc. All rights reserved. |
2105 | 4 | 4 | ||
2106 | 5 | Redistribution and use in source and binary forms, with or without | 5 | Redistribution and use in source and binary forms, with or without |
2107 | 6 | modification, are permitted provided that the following conditions are met: | 6 | modification, are permitted provided that the following conditions are met: |
2108 | @@ -35,6 +35,9 @@ | |||
2109 | 35 | 35 | ||
2110 | 36 | public class ChannelSftp extends ChannelSession{ | 36 | public class ChannelSftp extends ChannelSession{ |
2111 | 37 | 37 | ||
2112 | 38 | static private final int LOCAL_MAXIMUM_PACKET_SIZE=32*1024; | ||
2113 | 39 | static private final int LOCAL_WINDOW_SIZE_MAX=(64*LOCAL_MAXIMUM_PACKET_SIZE); | ||
2114 | 40 | |||
2115 | 38 | private static final byte SSH_FXP_INIT= 1; | 41 | private static final byte SSH_FXP_INIT= 1; |
2116 | 39 | private static final byte SSH_FXP_VERSION= 2; | 42 | private static final byte SSH_FXP_VERSION= 2; |
2117 | 40 | private static final byte SSH_FXP_OPEN= 3; | 43 | private static final byte SSH_FXP_OPEN= 3; |
2118 | @@ -131,8 +134,13 @@ | |||
2119 | 131 | private boolean interactive=false; | 134 | private boolean interactive=false; |
2120 | 132 | private int seq=1; | 135 | private int seq=1; |
2121 | 133 | private int[] ackid=new int[1]; | 136 | private int[] ackid=new int[1]; |
2122 | 137 | |||
2123 | 134 | private Buffer buf; | 138 | private Buffer buf; |
2125 | 135 | private Packet packet=new Packet(buf); | 139 | private Packet packet; |
2126 | 140 | |||
2127 | 141 | // The followings will be used in file uploading. | ||
2128 | 142 | private Buffer obuf; | ||
2129 | 143 | private Packet opacket; | ||
2130 | 136 | 144 | ||
2131 | 137 | private int client_version=3; | 145 | private int client_version=3; |
2132 | 138 | private int server_version=3; | 146 | private int server_version=3; |
2133 | @@ -169,6 +177,40 @@ | |||
2134 | 169 | private String fEncoding=UTF8; | 177 | private String fEncoding=UTF8; |
2135 | 170 | private boolean fEncoding_is_utf8=true; | 178 | private boolean fEncoding_is_utf8=true; |
2136 | 171 | 179 | ||
2137 | 180 | private RequestQueue rq = new RequestQueue(16); | ||
2138 | 181 | |||
2139 | 182 | /** | ||
2140 | 183 | * Specify how many requests may be sent at any one time. | ||
2141 | 184 | * Increasing this value may slightly improve file transfer speed but will | ||
2142 | 185 | * increase memory usage. The default is 16 requests. | ||
2143 | 186 | * | ||
2144 | 187 | * @param bulk_requests how many requests may be outstanding at any one time. | ||
2145 | 188 | */ | ||
2146 | 189 | public void setBulkRequests(int bulk_requests) throws JSchException { | ||
2147 | 190 | if(bulk_requests>0) | ||
2148 | 191 | rq = new RequestQueue(bulk_requests); | ||
2149 | 192 | else | ||
2150 | 193 | throw new JSchException("setBulkRequests: "+ | ||
2151 | 194 | bulk_requests+" must be greater than 0."); | ||
2152 | 195 | } | ||
2153 | 196 | |||
2154 | 197 | /** | ||
2155 | 198 | * This method will return the value how many requests may be | ||
2156 | 199 | * sent at any one time. | ||
2157 | 200 | * | ||
2158 | 201 | * @return how many requests may be sent at any one time. | ||
2159 | 202 | */ | ||
2160 | 203 | public int getBulkRequests(){ | ||
2161 | 204 | return rq.size(); | ||
2162 | 205 | } | ||
2163 | 206 | |||
2164 | 207 | ChannelSftp(){ | ||
2165 | 208 | super(); | ||
2166 | 209 | setLocalWindowSizeMax(LOCAL_WINDOW_SIZE_MAX); | ||
2167 | 210 | setLocalWindowSize(LOCAL_WINDOW_SIZE_MAX); | ||
2168 | 211 | setLocalPacketSize(LOCAL_MAXIMUM_PACKET_SIZE); | ||
2169 | 212 | } | ||
2170 | 213 | |||
2171 | 172 | void init(){ | 214 | void init(){ |
2172 | 173 | } | 215 | } |
2173 | 174 | 216 | ||
2174 | @@ -177,7 +219,7 @@ | |||
2175 | 177 | 219 | ||
2176 | 178 | PipedOutputStream pos=new PipedOutputStream(); | 220 | PipedOutputStream pos=new PipedOutputStream(); |
2177 | 179 | io.setOutputStream(pos); | 221 | io.setOutputStream(pos); |
2179 | 180 | PipedInputStream pis=new MyPipedInputStream(pos, 32*1024); | 222 | PipedInputStream pis=new MyPipedInputStream(pos, rmpsize); |
2180 | 181 | io.setInputStream(pis); | 223 | io.setInputStream(pis); |
2181 | 182 | 224 | ||
2182 | 183 | io_in=io.in; | 225 | io_in=io.in; |
2183 | @@ -189,15 +231,19 @@ | |||
2184 | 189 | Request request=new RequestSftp(); | 231 | Request request=new RequestSftp(); |
2185 | 190 | request.request(getSession(), this); | 232 | request.request(getSession(), this); |
2186 | 191 | 233 | ||
2188 | 192 | /* | 234 | /* |
2189 | 193 | System.err.println("lmpsize: "+lmpsize); | 235 | System.err.println("lmpsize: "+lmpsize); |
2190 | 194 | System.err.println("lwsize: "+lwsize); | 236 | System.err.println("lwsize: "+lwsize); |
2191 | 195 | System.err.println("rmpsize: "+rmpsize); | 237 | System.err.println("rmpsize: "+rmpsize); |
2192 | 196 | System.err.println("rwsize: "+rwsize); | 238 | System.err.println("rwsize: "+rwsize); |
2194 | 197 | */ | 239 | */ |
2195 | 198 | 240 | ||
2197 | 199 | buf=new Buffer(rmpsize); | 241 | buf=new Buffer(lmpsize); |
2198 | 200 | packet=new Packet(buf); | 242 | packet=new Packet(buf); |
2199 | 243 | |||
2200 | 244 | obuf=new Buffer(rmpsize); | ||
2201 | 245 | opacket=new Packet(obuf); | ||
2202 | 246 | |||
2203 | 201 | int i=0; | 247 | int i=0; |
2204 | 202 | int length; | 248 | int length; |
2205 | 203 | int type; | 249 | int type; |
2206 | @@ -228,8 +274,8 @@ | |||
2207 | 228 | length-=(4+extension_name.length); | 274 | length-=(4+extension_name.length); |
2208 | 229 | extension_data=buf.getString(); | 275 | extension_data=buf.getString(); |
2209 | 230 | length-=(4+extension_data.length); | 276 | length-=(4+extension_data.length); |
2212 | 231 | extensions.put(new String(extension_name), | 277 | extensions.put(Util.byte2str(extension_name), |
2213 | 232 | new String(extension_data)); | 278 | Util.byte2str(extension_data)); |
2214 | 233 | } | 279 | } |
2215 | 234 | } | 280 | } |
2216 | 235 | 281 | ||
2217 | @@ -261,8 +307,9 @@ | |||
2218 | 261 | 307 | ||
2219 | 262 | public void cd(String path) throws SftpException{ | 308 | public void cd(String path) throws SftpException{ |
2220 | 263 | try{ | 309 | try{ |
2221 | 310 | ((MyPipedInputStream)io_in).updateReadSide(); | ||
2222 | 311 | |||
2223 | 264 | path=remoteAbsolutePath(path); | 312 | path=remoteAbsolutePath(path); |
2224 | 265 | |||
2225 | 266 | path=isUnique(path); | 313 | path=isUnique(path); |
2226 | 267 | 314 | ||
2227 | 268 | byte[] str=_realpath(path); | 315 | byte[] str=_realpath(path); |
2228 | @@ -299,11 +346,12 @@ | |||
2229 | 299 | } | 346 | } |
2230 | 300 | public void put(String src, String dst, | 347 | public void put(String src, String dst, |
2231 | 301 | SftpProgressMonitor monitor, int mode) throws SftpException{ | 348 | SftpProgressMonitor monitor, int mode) throws SftpException{ |
2232 | 302 | src=localAbsolutePath(src); | ||
2233 | 303 | dst=remoteAbsolutePath(dst); | ||
2234 | 304 | 349 | ||
2235 | 305 | //System.err.println("src: "+src+", "+dst); | ||
2236 | 306 | try{ | 350 | try{ |
2237 | 351 | ((MyPipedInputStream)io_in).updateReadSide(); | ||
2238 | 352 | |||
2239 | 353 | src=localAbsolutePath(src); | ||
2240 | 354 | dst=remoteAbsolutePath(dst); | ||
2241 | 307 | 355 | ||
2242 | 308 | Vector v=glob_remote(dst); | 356 | Vector v=glob_remote(dst); |
2243 | 309 | int vsize=v.size(); | 357 | int vsize=v.size(); |
2244 | @@ -415,6 +463,8 @@ | |||
2245 | 415 | public void put(InputStream src, String dst, | 463 | public void put(InputStream src, String dst, |
2246 | 416 | SftpProgressMonitor monitor, int mode) throws SftpException{ | 464 | SftpProgressMonitor monitor, int mode) throws SftpException{ |
2247 | 417 | try{ | 465 | try{ |
2248 | 466 | ((MyPipedInputStream)io_in).updateReadSide(); | ||
2249 | 467 | |||
2250 | 418 | dst=remoteAbsolutePath(dst); | 468 | dst=remoteAbsolutePath(dst); |
2251 | 419 | 469 | ||
2252 | 420 | Vector v=glob_remote(dst); | 470 | Vector v=glob_remote(dst); |
2253 | @@ -436,6 +486,12 @@ | |||
2254 | 436 | throw new SftpException(SSH_FX_FAILURE, dst+" is a directory"); | 486 | throw new SftpException(SSH_FX_FAILURE, dst+" is a directory"); |
2255 | 437 | } | 487 | } |
2256 | 438 | 488 | ||
2257 | 489 | if(monitor!=null){ | ||
2258 | 490 | monitor.init(SftpProgressMonitor.PUT, | ||
2259 | 491 | "-", dst, | ||
2260 | 492 | SftpProgressMonitor.UNKNOWN_SIZE); | ||
2261 | 493 | } | ||
2262 | 494 | |||
2263 | 439 | _put(src, dst, monitor, mode); | 495 | _put(src, dst, monitor, mode); |
2264 | 440 | } | 496 | } |
2265 | 441 | catch(Exception e){ | 497 | catch(Exception e){ |
2266 | @@ -447,8 +503,10 @@ | |||
2267 | 447 | } | 503 | } |
2268 | 448 | 504 | ||
2269 | 449 | public void _put(InputStream src, String dst, | 505 | public void _put(InputStream src, String dst, |
2271 | 450 | SftpProgressMonitor monitor, int mode) throws SftpException{ | 506 | SftpProgressMonitor monitor, int mode) throws SftpException{ |
2272 | 451 | try{ | 507 | try{ |
2273 | 508 | ((MyPipedInputStream)io_in).updateReadSide(); | ||
2274 | 509 | |||
2275 | 452 | byte[] dstb=Util.str2byte(dst, fEncoding); | 510 | byte[] dstb=Util.str2byte(dst, fEncoding); |
2276 | 453 | long skip=0; | 511 | long skip=0; |
2277 | 454 | if(mode==RESUME || mode==APPEND){ | 512 | if(mode==RESUME || mode==APPEND){ |
2278 | @@ -489,10 +547,9 @@ | |||
2279 | 489 | 547 | ||
2280 | 490 | boolean dontcopy=true; | 548 | boolean dontcopy=true; |
2281 | 491 | 549 | ||
2286 | 492 | if(!dontcopy){ | 550 | if(!dontcopy){ // This case will not work anymore. |
2287 | 493 | data=new byte[buf.buffer.length | 551 | data=new byte[obuf.buffer.length |
2288 | 494 | -(5+13+21+handle.length | 552 | -(5+13+21+handle.length+Session.buffer_margin |
2285 | 495 | +32 +20 // padding and mac | ||
2289 | 496 | ) | 553 | ) |
2290 | 497 | ]; | 554 | ]; |
2291 | 498 | } | 555 | } |
2292 | @@ -503,23 +560,26 @@ | |||
2293 | 503 | } | 560 | } |
2294 | 504 | 561 | ||
2295 | 505 | int startid=seq; | 562 | int startid=seq; |
2296 | 506 | int _ackid=seq; | ||
2297 | 507 | int ackcount=0; | 563 | int ackcount=0; |
2298 | 564 | int _s=0; | ||
2299 | 565 | int _datalen=0; | ||
2300 | 566 | |||
2301 | 567 | if(!dontcopy){ // This case will not work anymore. | ||
2302 | 568 | _datalen=data.length; | ||
2303 | 569 | } | ||
2304 | 570 | else{ | ||
2305 | 571 | data=obuf.buffer; | ||
2306 | 572 | _s=5+13+21+handle.length; | ||
2307 | 573 | _datalen=obuf.buffer.length-_s-Session.buffer_margin; | ||
2308 | 574 | } | ||
2309 | 575 | |||
2310 | 576 | int bulk_requests = rq.size(); | ||
2311 | 577 | |||
2312 | 508 | while(true){ | 578 | while(true){ |
2313 | 509 | int nread=0; | 579 | int nread=0; |
2314 | 510 | int s=0; | ||
2315 | 511 | int datalen=0; | ||
2316 | 512 | int count=0; | 580 | int count=0; |
2327 | 513 | 581 | int s=_s; | |
2328 | 514 | if(!dontcopy){ | 582 | int datalen=_datalen; |
2319 | 515 | datalen=data.length-s; | ||
2320 | 516 | } | ||
2321 | 517 | else{ | ||
2322 | 518 | data=buf.buffer; | ||
2323 | 519 | s=5+13+21+handle.length; | ||
2324 | 520 | datalen=buf.buffer.length -s | ||
2325 | 521 | -32 -20; // padding and mac | ||
2326 | 522 | } | ||
2329 | 523 | 583 | ||
2330 | 524 | do{ | 584 | do{ |
2331 | 525 | nread=src.read(data, s, datalen); | 585 | nread=src.read(data, s, datalen); |
2332 | @@ -532,20 +592,19 @@ | |||
2333 | 532 | while(datalen>0 && nread>0); | 592 | while(datalen>0 && nread>0); |
2334 | 533 | if(count<=0)break; | 593 | if(count<=0)break; |
2335 | 534 | 594 | ||
2339 | 535 | int _i=count; | 595 | int foo=count; |
2340 | 536 | while(_i>0){ | 596 | while(foo>0){ |
2338 | 537 | _i-=sendWRITE(handle, offset, data, 0, _i); | ||
2341 | 538 | if((seq-1)==startid || | 597 | if((seq-1)==startid || |
2344 | 539 | io_in.available()>=1024){ | 598 | ((seq-startid)-ackcount)>=bulk_requests){ |
2345 | 540 | while(io_in.available()>0){ | 599 | while(((seq-startid)-ackcount)>=bulk_requests){ |
2346 | 600 | if(this.rwsize>=foo) break; | ||
2347 | 541 | if(checkStatus(ackid, header)){ | 601 | if(checkStatus(ackid, header)){ |
2349 | 542 | _ackid=ackid[0]; | 602 | int _ackid = ackid[0]; |
2350 | 543 | if(startid>_ackid || _ackid>seq-1){ | 603 | if(startid>_ackid || _ackid>seq-1){ |
2351 | 544 | if(_ackid==seq){ | 604 | if(_ackid==seq){ |
2352 | 545 | System.err.println("ack error: startid="+startid+" seq="+seq+" _ackid="+_ackid); | 605 | System.err.println("ack error: startid="+startid+" seq="+seq+" _ackid="+_ackid); |
2353 | 546 | } | 606 | } |
2354 | 547 | else{ | 607 | else{ |
2355 | 548 | //throw new SftpException(SSH_FX_FAILURE, "ack error:"); | ||
2356 | 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); |
2357 | 550 | } | 609 | } |
2358 | 551 | } | 610 | } |
2359 | @@ -556,6 +615,7 @@ | |||
2360 | 556 | } | 615 | } |
2361 | 557 | } | 616 | } |
2362 | 558 | } | 617 | } |
2363 | 618 | foo-=sendWRITE(handle, offset, data, 0, foo); | ||
2364 | 559 | } | 619 | } |
2365 | 560 | offset+=count; | 620 | offset+=count; |
2366 | 561 | if(monitor!=null && !monitor.count(count)){ | 621 | if(monitor!=null && !monitor.count(count)){ |
2367 | @@ -590,9 +650,10 @@ | |||
2368 | 590 | return put(dst, monitor, mode, 0); | 650 | return put(dst, monitor, mode, 0); |
2369 | 591 | } | 651 | } |
2370 | 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{ |
2371 | 593 | dst=remoteAbsolutePath(dst); | ||
2372 | 594 | try{ | 653 | try{ |
2373 | 654 | ((MyPipedInputStream)io_in).updateReadSide(); | ||
2374 | 595 | 655 | ||
2375 | 656 | dst=remoteAbsolutePath(dst); | ||
2376 | 596 | dst=isUnique(dst); | 657 | dst=isUnique(dst); |
2377 | 597 | 658 | ||
2378 | 598 | if(isRemoteDir(dst)){ | 659 | if(isRemoteDir(dst)){ |
2379 | @@ -757,10 +818,14 @@ | |||
2380 | 757 | SftpProgressMonitor monitor, int mode) throws SftpException{ | 818 | SftpProgressMonitor monitor, int mode) throws SftpException{ |
2381 | 758 | // System.out.println("get: "+src+" "+dst); | 819 | // System.out.println("get: "+src+" "+dst); |
2382 | 759 | 820 | ||
2386 | 760 | src=remoteAbsolutePath(src); | 821 | boolean _dstExist = false; |
2387 | 761 | dst=localAbsolutePath(dst); | 822 | String _dst=null; |
2385 | 762 | |||
2388 | 763 | try{ | 823 | try{ |
2389 | 824 | ((MyPipedInputStream)io_in).updateReadSide(); | ||
2390 | 825 | |||
2391 | 826 | src=remoteAbsolutePath(src); | ||
2392 | 827 | dst=localAbsolutePath(dst); | ||
2393 | 828 | |||
2394 | 764 | Vector v=glob_remote(src); | 829 | Vector v=glob_remote(src); |
2395 | 765 | int vsize=v.size(); | 830 | int vsize=v.size(); |
2396 | 766 | if(vsize==0){ | 831 | if(vsize==0){ |
2397 | @@ -789,7 +854,7 @@ | |||
2398 | 789 | "not supported to get directory "+_src); | 854 | "not supported to get directory "+_src); |
2399 | 790 | } | 855 | } |
2400 | 791 | 856 | ||
2402 | 792 | String _dst=null; | 857 | _dst=null; |
2403 | 793 | if(isDstDir){ | 858 | if(isDstDir){ |
2404 | 794 | int i=_src.lastIndexOf('/'); | 859 | int i=_src.lastIndexOf('/'); |
2405 | 795 | if(i==-1) dstsb.append(_src); | 860 | if(i==-1) dstsb.append(_src); |
2406 | @@ -801,9 +866,10 @@ | |||
2407 | 801 | _dst=dst; | 866 | _dst=dst; |
2408 | 802 | } | 867 | } |
2409 | 803 | 868 | ||
2410 | 869 | File _dstFile=new File(_dst); | ||
2411 | 804 | if(mode==RESUME){ | 870 | if(mode==RESUME){ |
2412 | 805 | long size_of_src=attr.getSize(); | 871 | long size_of_src=attr.getSize(); |
2414 | 806 | long size_of_dst=new File(_dst).length(); | 872 | long size_of_dst=_dstFile.length(); |
2415 | 807 | if(size_of_dst>size_of_src){ | 873 | if(size_of_dst>size_of_src){ |
2416 | 808 | throw new SftpException(SSH_FX_FAILURE, | 874 | throw new SftpException(SSH_FX_FAILURE, |
2417 | 809 | "failed to resume for "+_dst); | 875 | "failed to resume for "+_dst); |
2418 | @@ -816,11 +882,12 @@ | |||
2419 | 816 | if(monitor!=null){ | 882 | if(monitor!=null){ |
2420 | 817 | monitor.init(SftpProgressMonitor.GET, _src, _dst, attr.getSize()); | 883 | monitor.init(SftpProgressMonitor.GET, _src, _dst, attr.getSize()); |
2421 | 818 | if(mode==RESUME){ | 884 | if(mode==RESUME){ |
2423 | 819 | monitor.count(new File(_dst).length()); | 885 | monitor.count(_dstFile.length()); |
2424 | 820 | } | 886 | } |
2425 | 821 | } | 887 | } |
2426 | 822 | 888 | ||
2428 | 823 | FileOutputStream fos=null; | 889 | FileOutputStream fos=null; |
2429 | 890 | _dstExist = _dstFile.exists(); | ||
2430 | 824 | try{ | 891 | try{ |
2431 | 825 | if(mode==OVERWRITE){ | 892 | if(mode==OVERWRITE){ |
2432 | 826 | fos=new FileOutputStream(_dst); | 893 | fos=new FileOutputStream(_dst); |
2433 | @@ -839,6 +906,12 @@ | |||
2434 | 839 | } | 906 | } |
2435 | 840 | } | 907 | } |
2436 | 841 | catch(Exception e){ | 908 | catch(Exception e){ |
2437 | 909 | if(!_dstExist && _dst!=null){ | ||
2438 | 910 | File _dstFile = new File(_dst); | ||
2439 | 911 | if(_dstFile.exists() && _dstFile.length()==0){ | ||
2440 | 912 | _dstFile.delete(); | ||
2441 | 913 | } | ||
2442 | 914 | } | ||
2443 | 842 | if(e instanceof SftpException) throw (SftpException)e; | 915 | if(e instanceof SftpException) throw (SftpException)e; |
2444 | 843 | if(e instanceof Throwable) | 916 | if(e instanceof Throwable) |
2445 | 844 | throw new SftpException(SSH_FX_FAILURE, "", (Throwable)e); | 917 | throw new SftpException(SSH_FX_FAILURE, "", (Throwable)e); |
2446 | @@ -856,8 +929,9 @@ | |||
2447 | 856 | SftpProgressMonitor monitor, int mode, long skip) throws SftpException{ | 929 | SftpProgressMonitor monitor, int mode, long skip) throws SftpException{ |
2448 | 857 | //System.err.println("get: "+src+", "+dst); | 930 | //System.err.println("get: "+src+", "+dst); |
2449 | 858 | try{ | 931 | try{ |
2450 | 932 | ((MyPipedInputStream)io_in).updateReadSide(); | ||
2451 | 933 | |||
2452 | 859 | src=remoteAbsolutePath(src); | 934 | src=remoteAbsolutePath(src); |
2453 | 860 | |||
2454 | 861 | src=isUnique(src); | 935 | src=isUnique(src); |
2455 | 862 | 936 | ||
2456 | 863 | if(monitor!=null){ | 937 | if(monitor!=null){ |
2457 | @@ -908,18 +982,27 @@ | |||
2458 | 908 | offset+=skip; | 982 | offset+=skip; |
2459 | 909 | } | 983 | } |
2460 | 910 | 984 | ||
2462 | 911 | int request_len=0; | 985 | int request_max=1; |
2463 | 986 | rq.init(); | ||
2464 | 987 | long request_offset=offset; | ||
2465 | 988 | |||
2466 | 989 | int request_len = buf.buffer.length-13; | ||
2467 | 990 | if(server_version==0){ request_len=1024; } | ||
2468 | 991 | |||
2469 | 912 | loop: | 992 | loop: |
2470 | 913 | while(true){ | 993 | while(true){ |
2471 | 914 | 994 | ||
2475 | 915 | request_len=buf.buffer.length-13; | 995 | while(rq.count() < request_max){ |
2476 | 916 | if(server_version==0){ request_len=1024; } | 996 | sendREAD(handle, request_offset, request_len, rq); |
2477 | 917 | sendREAD(handle, offset, request_len); | 997 | request_offset += request_len; |
2478 | 998 | } | ||
2479 | 918 | 999 | ||
2480 | 919 | header=header(buf, header); | 1000 | header=header(buf, header); |
2481 | 920 | length=header.length; | 1001 | length=header.length; |
2482 | 921 | type=header.type; | 1002 | type=header.type; |
2483 | 922 | 1003 | ||
2484 | 1004 | RequestQueue.Request rr = rq.get(header.rid); | ||
2485 | 1005 | |||
2486 | 923 | if(type==SSH_FXP_STATUS){ | 1006 | if(type==SSH_FXP_STATUS){ |
2487 | 924 | fill(buf, length); | 1007 | fill(buf, length); |
2488 | 925 | int i=buf.getInt(); | 1008 | int i=buf.getInt(); |
2489 | @@ -935,19 +1018,31 @@ | |||
2490 | 935 | 1018 | ||
2491 | 936 | buf.rewind(); | 1019 | buf.rewind(); |
2492 | 937 | fill(buf.buffer, 0, 4); length-=4; | 1020 | fill(buf.buffer, 0, 4); length-=4; |
2496 | 938 | int i=buf.getInt(); // length of data | 1021 | int length_of_data = buf.getInt(); // length of data |
2497 | 939 | int foo=i; | 1022 | |
2498 | 940 | 1023 | /** | |
2499 | 1024 | Since sftp protocol version 6, "end-of-file" has been defined, | ||
2500 | 1025 | |||
2501 | 1026 | byte SSH_FXP_DATA | ||
2502 | 1027 | uint32 request-id | ||
2503 | 1028 | string data | ||
2504 | 1029 | bool end-of-file [optional] | ||
2505 | 1030 | |||
2506 | 1031 | but some sftpd server will send such a field in the sftp protocol 3 ;-( | ||
2507 | 1032 | */ | ||
2508 | 1033 | int optional_data = length - length_of_data; | ||
2509 | 1034 | |||
2510 | 1035 | int foo = length_of_data; | ||
2511 | 941 | while(foo>0){ | 1036 | while(foo>0){ |
2512 | 942 | int bar=foo; | 1037 | int bar=foo; |
2513 | 943 | if(bar>buf.buffer.length){ | 1038 | if(bar>buf.buffer.length){ |
2514 | 944 | bar=buf.buffer.length; | 1039 | bar=buf.buffer.length; |
2515 | 945 | } | 1040 | } |
2518 | 946 | i=io_in.read(buf.buffer, 0, bar); | 1041 | int data_len = io_in.read(buf.buffer, 0, bar); |
2519 | 947 | if(i<0){ | 1042 | if(data_len<0){ |
2520 | 948 | break loop; | 1043 | break loop; |
2521 | 949 | } | 1044 | } |
2523 | 950 | int data_len=i; | 1045 | |
2524 | 951 | dst.write(buf.buffer, 0, data_len); | 1046 | dst.write(buf.buffer, 0, data_len); |
2525 | 952 | 1047 | ||
2526 | 953 | offset+=data_len; | 1048 | offset+=data_len; |
2527 | @@ -955,12 +1050,9 @@ | |||
2528 | 955 | 1050 | ||
2529 | 956 | if(monitor!=null){ | 1051 | if(monitor!=null){ |
2530 | 957 | if(!monitor.count(data_len)){ | 1052 | if(!monitor.count(data_len)){ |
2537 | 958 | while(foo>0){ | 1053 | skip(foo); |
2538 | 959 | i=io_in.read(buf.buffer, | 1054 | if(optional_data>0){ |
2539 | 960 | 0, | 1055 | skip(optional_data); |
2534 | 961 | (buf.buffer.length<foo?buf.buffer.length:foo)); | ||
2535 | 962 | if(i<=0) break; | ||
2536 | 963 | foo-=i; | ||
2540 | 964 | } | 1056 | } |
2541 | 965 | break loop; | 1057 | break loop; |
2542 | 966 | } | 1058 | } |
2543 | @@ -968,10 +1060,27 @@ | |||
2544 | 968 | 1060 | ||
2545 | 969 | } | 1061 | } |
2546 | 970 | //System.err.println("length: "+length); // length should be 0 | 1062 | //System.err.println("length: "+length); // length should be 0 |
2547 | 1063 | |||
2548 | 1064 | if(optional_data>0){ | ||
2549 | 1065 | skip(optional_data); | ||
2550 | 1066 | } | ||
2551 | 1067 | |||
2552 | 1068 | if(length_of_data<rr.length){ // | ||
2553 | 1069 | rq.cancel(header, buf); | ||
2554 | 1070 | sendREAD(handle, rr.offset+length_of_data, (int)(rr.length-length_of_data), rq); | ||
2555 | 1071 | request_offset=rr.offset+rr.length; | ||
2556 | 1072 | } | ||
2557 | 1073 | |||
2558 | 1074 | if(request_max < rq.size()){ | ||
2559 | 1075 | request_max++; | ||
2560 | 1076 | } | ||
2561 | 971 | } | 1077 | } |
2562 | 972 | dst.flush(); | 1078 | dst.flush(); |
2563 | 973 | 1079 | ||
2564 | 974 | if(monitor!=null)monitor.end(); | 1080 | if(monitor!=null)monitor.end(); |
2565 | 1081 | |||
2566 | 1082 | rq.cancel(header, buf); | ||
2567 | 1083 | |||
2568 | 975 | _sendCLOSE(handle, header); | 1084 | _sendCLOSE(handle, header); |
2569 | 976 | } | 1085 | } |
2570 | 977 | catch(Exception e){ | 1086 | catch(Exception e){ |
2571 | @@ -982,6 +1091,69 @@ | |||
2572 | 982 | } | 1091 | } |
2573 | 983 | } | 1092 | } |
2574 | 984 | 1093 | ||
2575 | 1094 | |||
2576 | 1095 | private class RequestQueue { | ||
2577 | 1096 | class Request { | ||
2578 | 1097 | int id; | ||
2579 | 1098 | long offset; | ||
2580 | 1099 | long length; | ||
2581 | 1100 | } | ||
2582 | 1101 | |||
2583 | 1102 | Request[] rrq=null; | ||
2584 | 1103 | int head, count; | ||
2585 | 1104 | RequestQueue(int size){ | ||
2586 | 1105 | rrq = new Request[size]; | ||
2587 | 1106 | for(int i=0; i<rrq.length; i++){ | ||
2588 | 1107 | rrq[i]=new Request(); | ||
2589 | 1108 | } | ||
2590 | 1109 | init(); | ||
2591 | 1110 | } | ||
2592 | 1111 | |||
2593 | 1112 | void init(){ | ||
2594 | 1113 | head=count=0; | ||
2595 | 1114 | } | ||
2596 | 1115 | |||
2597 | 1116 | void add(int id, long offset, int length){ | ||
2598 | 1117 | if(count == 0) head = 0; | ||
2599 | 1118 | int tail = head + count; | ||
2600 | 1119 | if(tail>=rrq.length) tail -= rrq.length; | ||
2601 | 1120 | rrq[tail].id=id; | ||
2602 | 1121 | rrq[tail].offset=offset; | ||
2603 | 1122 | rrq[tail].length=length; | ||
2604 | 1123 | count++; | ||
2605 | 1124 | } | ||
2606 | 1125 | |||
2607 | 1126 | Request get(int id){ | ||
2608 | 1127 | count -= 1; | ||
2609 | 1128 | int i=head; | ||
2610 | 1129 | head++; | ||
2611 | 1130 | if(head==rrq.length) head=0; | ||
2612 | 1131 | if(rrq[i].id!=id){ | ||
2613 | 1132 | System.err.println("The request is not in order."); | ||
2614 | 1133 | } | ||
2615 | 1134 | rrq[i].id=0; | ||
2616 | 1135 | return rrq[i]; | ||
2617 | 1136 | } | ||
2618 | 1137 | |||
2619 | 1138 | int count() { | ||
2620 | 1139 | return count; | ||
2621 | 1140 | } | ||
2622 | 1141 | |||
2623 | 1142 | int size() { | ||
2624 | 1143 | return rrq.length; | ||
2625 | 1144 | } | ||
2626 | 1145 | |||
2627 | 1146 | void cancel(Header header, Buffer buf) throws IOException { | ||
2628 | 1147 | int _count = count; | ||
2629 | 1148 | for(int i=0; i<_count; i++){ | ||
2630 | 1149 | header=header(buf, header); | ||
2631 | 1150 | int length=header.length; | ||
2632 | 1151 | get(header.rid); | ||
2633 | 1152 | skip(length); | ||
2634 | 1153 | } | ||
2635 | 1154 | } | ||
2636 | 1155 | } | ||
2637 | 1156 | |||
2638 | 985 | public InputStream get(String src) throws SftpException{ | 1157 | public InputStream get(String src) throws SftpException{ |
2639 | 986 | return get(src, null, 0L); | 1158 | return get(src, null, 0L); |
2640 | 987 | } | 1159 | } |
2641 | @@ -1002,8 +1174,11 @@ | |||
2642 | 1002 | return get(src, monitor, 0L); | 1174 | return get(src, monitor, 0L); |
2643 | 1003 | } | 1175 | } |
2644 | 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{ |
2646 | 1005 | src=remoteAbsolutePath(src); | 1177 | |
2647 | 1006 | try{ | 1178 | try{ |
2648 | 1179 | ((MyPipedInputStream)io_in).updateReadSide(); | ||
2649 | 1180 | |||
2650 | 1181 | src=remoteAbsolutePath(src); | ||
2651 | 1007 | src=isUnique(src); | 1182 | src=isUnique(src); |
2652 | 1008 | 1183 | ||
2653 | 1009 | byte[] srcb=Util.str2byte(src, fEncoding); | 1184 | byte[] srcb=Util.str2byte(src, fEncoding); |
2654 | @@ -1032,6 +1207,8 @@ | |||
2655 | 1032 | 1207 | ||
2656 | 1033 | final byte[] handle=buf.getString(); // handle | 1208 | final byte[] handle=buf.getString(); // handle |
2657 | 1034 | 1209 | ||
2658 | 1210 | rq.init(); | ||
2659 | 1211 | |||
2660 | 1035 | java.io.InputStream in=new java.io.InputStream(){ | 1212 | java.io.InputStream in=new java.io.InputStream(){ |
2661 | 1036 | long offset=skip; | 1213 | long offset=skip; |
2662 | 1037 | boolean closed=false; | 1214 | boolean closed=false; |
2663 | @@ -1039,6 +1216,8 @@ | |||
2664 | 1039 | byte[] _data=new byte[1]; | 1216 | byte[] _data=new byte[1]; |
2665 | 1040 | byte[] rest_byte=new byte[1024]; | 1217 | byte[] rest_byte=new byte[1024]; |
2666 | 1041 | Header header=new Header(); | 1218 | Header header=new Header(); |
2667 | 1219 | int request_max=1; | ||
2668 | 1220 | long request_offset=offset; | ||
2669 | 1042 | 1221 | ||
2670 | 1043 | public int read() throws java.io.IOException{ | 1222 | public int read() throws java.io.IOException{ |
2671 | 1044 | if(closed)return -1; | 1223 | if(closed)return -1; |
2672 | @@ -1087,14 +1266,26 @@ | |||
2673 | 1087 | len=1024; | 1266 | len=1024; |
2674 | 1088 | } | 1267 | } |
2675 | 1089 | 1268 | ||
2678 | 1090 | try{sendREAD(handle, offset, len);} | 1269 | if(rq.count()==0) { |
2679 | 1091 | catch(Exception e){ throw new IOException("error"); } | 1270 | int request_len = buf.buffer.length-13; |
2680 | 1271 | if(server_version==0){ request_len=1024; } | ||
2681 | 1272 | |||
2682 | 1273 | while(rq.count() < request_max){ | ||
2683 | 1274 | try{ | ||
2684 | 1275 | sendREAD(handle, request_offset, request_len, rq); | ||
2685 | 1276 | } | ||
2686 | 1277 | catch(Exception e){ throw new IOException("error"); } | ||
2687 | 1278 | request_offset += request_len; | ||
2688 | 1279 | } | ||
2689 | 1280 | } | ||
2690 | 1092 | 1281 | ||
2691 | 1093 | header=header(buf, header); | 1282 | header=header(buf, header); |
2692 | 1094 | rest_length=header.length; | 1283 | rest_length=header.length; |
2693 | 1095 | int type=header.type; | 1284 | int type=header.type; |
2694 | 1096 | int id=header.rid; | 1285 | int id=header.rid; |
2695 | 1097 | 1286 | ||
2696 | 1287 | RequestQueue.Request rr = rq.get(header.rid); | ||
2697 | 1288 | |||
2698 | 1098 | if(type!=SSH_FXP_STATUS && type!=SSH_FXP_DATA){ | 1289 | if(type!=SSH_FXP_STATUS && type!=SSH_FXP_DATA){ |
2699 | 1099 | throw new IOException("error"); | 1290 | throw new IOException("error"); |
2700 | 1100 | } | 1291 | } |
2701 | @@ -1109,29 +1300,43 @@ | |||
2702 | 1109 | //throwStatusError(buf, i); | 1300 | //throwStatusError(buf, i); |
2703 | 1110 | throw new IOException("error"); | 1301 | throw new IOException("error"); |
2704 | 1111 | } | 1302 | } |
2705 | 1303 | |||
2706 | 1112 | buf.rewind(); | 1304 | buf.rewind(); |
2707 | 1113 | fill(buf.buffer, 0, 4); | 1305 | fill(buf.buffer, 0, 4); |
2712 | 1114 | int i=buf.getInt(); rest_length-=4; | 1306 | int length_of_data = buf.getInt(); rest_length-=4; |
2713 | 1115 | 1307 | ||
2714 | 1116 | offset+=rest_length; | 1308 | /** |
2715 | 1117 | int foo=i; | 1309 | Since sftp protocol version 6, "end-of-file" has been defined, |
2716 | 1310 | |||
2717 | 1311 | byte SSH_FXP_DATA | ||
2718 | 1312 | uint32 request-id | ||
2719 | 1313 | string data | ||
2720 | 1314 | bool end-of-file [optional] | ||
2721 | 1315 | |||
2722 | 1316 | but some sftpd server will send such a field in the sftp protocol 3 ;-( | ||
2723 | 1317 | */ | ||
2724 | 1318 | int optional_data = rest_length - length_of_data; | ||
2725 | 1319 | |||
2726 | 1320 | offset += length_of_data; | ||
2727 | 1321 | int foo = length_of_data; | ||
2728 | 1118 | if(foo>0){ | 1322 | if(foo>0){ |
2730 | 1119 | int bar=rest_length; | 1323 | int bar=foo; |
2731 | 1120 | if(bar>len){ | 1324 | if(bar>len){ |
2732 | 1121 | bar=len; | 1325 | bar=len; |
2733 | 1122 | } | 1326 | } |
2735 | 1123 | i=io_in.read(d, s, bar); | 1327 | int i=io_in.read(d, s, bar); |
2736 | 1124 | if(i<0){ | 1328 | if(i<0){ |
2737 | 1125 | return -1; | 1329 | return -1; |
2738 | 1126 | } | 1330 | } |
2740 | 1127 | rest_length-=i; | 1331 | foo-=i; |
2741 | 1332 | rest_length=foo; | ||
2742 | 1128 | 1333 | ||
2746 | 1129 | if(rest_length>0){ | 1334 | if(foo>0){ |
2747 | 1130 | if(rest_byte.length<rest_length){ | 1335 | if(rest_byte.length<foo){ |
2748 | 1131 | rest_byte=new byte[rest_length]; | 1336 | rest_byte=new byte[foo]; |
2749 | 1132 | } | 1337 | } |
2750 | 1133 | int _s=0; | 1338 | int _s=0; |
2752 | 1134 | int _len=rest_length; | 1339 | int _len=foo; |
2753 | 1135 | int j; | 1340 | int j; |
2754 | 1136 | while(_len>0){ | 1341 | while(_len>0){ |
2755 | 1137 | j=io_in.read(rest_byte, _s, _len); | 1342 | j=io_in.read(rest_byte, _s, _len); |
2756 | @@ -1141,6 +1346,25 @@ | |||
2757 | 1141 | } | 1346 | } |
2758 | 1142 | } | 1347 | } |
2759 | 1143 | 1348 | ||
2760 | 1349 | if(optional_data>0){ | ||
2761 | 1350 | io_in.skip(optional_data); | ||
2762 | 1351 | } | ||
2763 | 1352 | |||
2764 | 1353 | if(length_of_data<rr.length){ // | ||
2765 | 1354 | rq.cancel(header, buf); | ||
2766 | 1355 | try { | ||
2767 | 1356 | sendREAD(handle, | ||
2768 | 1357 | rr.offset+length_of_data, | ||
2769 | 1358 | (int)(rr.length-length_of_data), rq); | ||
2770 | 1359 | } | ||
2771 | 1360 | catch(Exception e){ throw new IOException("error"); } | ||
2772 | 1361 | request_offset=rr.offset+rr.length; | ||
2773 | 1362 | } | ||
2774 | 1363 | |||
2775 | 1364 | if(request_max < rq.size()){ | ||
2776 | 1365 | request_max++; | ||
2777 | 1366 | } | ||
2778 | 1367 | |||
2779 | 1144 | if(monitor!=null){ | 1368 | if(monitor!=null){ |
2780 | 1145 | if(!monitor.count(i)){ | 1369 | if(!monitor.count(i)){ |
2781 | 1146 | close(); | 1370 | close(); |
2782 | @@ -1156,6 +1380,7 @@ | |||
2783 | 1156 | if(closed)return; | 1380 | if(closed)return; |
2784 | 1157 | closed=true; | 1381 | closed=true; |
2785 | 1158 | if(monitor!=null)monitor.end(); | 1382 | if(monitor!=null)monitor.end(); |
2786 | 1383 | rq.cancel(header, buf); | ||
2787 | 1159 | try{_sendCLOSE(handle, header);} | 1384 | try{_sendCLOSE(handle, header);} |
2788 | 1160 | catch(Exception e){throw new IOException("error");} | 1385 | catch(Exception e){throw new IOException("error");} |
2789 | 1161 | } | 1386 | } |
2790 | @@ -1171,8 +1396,32 @@ | |||
2791 | 1171 | } | 1396 | } |
2792 | 1172 | 1397 | ||
2793 | 1173 | public java.util.Vector ls(String path) throws SftpException{ | 1398 | public java.util.Vector ls(String path) throws SftpException{ |
2794 | 1399 | final java.util.Vector v = new Vector(); | ||
2795 | 1400 | LsEntrySelector selector = new LsEntrySelector(){ | ||
2796 | 1401 | public int select(LsEntry entry){ | ||
2797 | 1402 | v.addElement(entry); | ||
2798 | 1403 | return CONTINUE; | ||
2799 | 1404 | } | ||
2800 | 1405 | }; | ||
2801 | 1406 | ls(path, selector); | ||
2802 | 1407 | return v; | ||
2803 | 1408 | } | ||
2804 | 1409 | |||
2805 | 1410 | /** | ||
2806 | 1411 | * List files specified by the remote <code>path</code>. | ||
2807 | 1412 | * Each files and directories will be passed to | ||
2808 | 1413 | * <code>LsEntrySelector#select(LsEntry)</code> method, and if that method | ||
2809 | 1414 | * returns <code>LsEntrySelector#BREAK</code>, the operation will be | ||
2810 | 1415 | * canceled immediately. | ||
2811 | 1416 | * | ||
2812 | 1417 | * @see #LsEntrySelector | ||
2813 | 1418 | * @since 0.1.47 | ||
2814 | 1419 | */ | ||
2815 | 1420 | public void ls(String path, LsEntrySelector selector) throws SftpException{ | ||
2816 | 1174 | //System.out.println("ls: "+path); | 1421 | //System.out.println("ls: "+path); |
2817 | 1175 | try{ | 1422 | try{ |
2818 | 1423 | ((MyPipedInputStream)io_in).updateReadSide(); | ||
2819 | 1424 | |||
2820 | 1176 | path=remoteAbsolutePath(path); | 1425 | path=remoteAbsolutePath(path); |
2821 | 1177 | byte[] pattern=null; | 1426 | byte[] pattern=null; |
2822 | 1178 | java.util.Vector v=new java.util.Vector(); | 1427 | java.util.Vector v=new java.util.Vector(); |
2823 | @@ -1237,9 +1486,11 @@ | |||
2824 | 1237 | throwStatusError(buf, i); | 1486 | throwStatusError(buf, i); |
2825 | 1238 | } | 1487 | } |
2826 | 1239 | 1488 | ||
2827 | 1489 | int cancel = LsEntrySelector.CONTINUE; | ||
2828 | 1240 | byte[] handle=buf.getString(); // handle | 1490 | byte[] handle=buf.getString(); // handle |
2829 | 1241 | 1491 | ||
2831 | 1242 | while(true){ | 1492 | while(cancel==LsEntrySelector.CONTINUE){ |
2832 | 1493 | |||
2833 | 1243 | sendREADDIR(handle); | 1494 | sendREADDIR(handle); |
2834 | 1244 | 1495 | ||
2835 | 1245 | header=header(buf, header); | 1496 | header=header(buf, header); |
2836 | @@ -1281,6 +1532,11 @@ | |||
2837 | 1281 | } | 1532 | } |
2838 | 1282 | SftpATTRS attrs=SftpATTRS.getATTR(buf); | 1533 | SftpATTRS attrs=SftpATTRS.getATTR(buf); |
2839 | 1283 | 1534 | ||
2840 | 1535 | if(cancel==LsEntrySelector.BREAK){ | ||
2841 | 1536 | count--; | ||
2842 | 1537 | continue; | ||
2843 | 1538 | } | ||
2844 | 1539 | |||
2845 | 1284 | boolean find=false; | 1540 | boolean find=false; |
2846 | 1285 | String f=null; | 1541 | String f=null; |
2847 | 1286 | if(pattern==null){ | 1542 | if(pattern==null){ |
2848 | @@ -1311,7 +1567,8 @@ | |||
2849 | 1311 | else{ | 1567 | else{ |
2850 | 1312 | l=Util.byte2str(longname, fEncoding); | 1568 | l=Util.byte2str(longname, fEncoding); |
2851 | 1313 | } | 1569 | } |
2853 | 1314 | v.addElement(new LsEntry(f, l, attrs)); | 1570 | |
2854 | 1571 | cancel = selector.select(new LsEntry(f, l, attrs)); | ||
2855 | 1315 | } | 1572 | } |
2856 | 1316 | 1573 | ||
2857 | 1317 | count--; | 1574 | count--; |
2858 | @@ -1336,7 +1593,6 @@ | |||
2859 | 1336 | } | 1593 | } |
2860 | 1337 | */ | 1594 | */ |
2861 | 1338 | 1595 | ||
2862 | 1339 | return v; | ||
2863 | 1340 | } | 1596 | } |
2864 | 1341 | catch(Exception e){ | 1597 | catch(Exception e){ |
2865 | 1342 | if(e instanceof SftpException) throw (SftpException)e; | 1598 | if(e instanceof SftpException) throw (SftpException)e; |
2866 | @@ -1345,14 +1601,16 @@ | |||
2867 | 1345 | throw new SftpException(SSH_FX_FAILURE, ""); | 1601 | throw new SftpException(SSH_FX_FAILURE, ""); |
2868 | 1346 | } | 1602 | } |
2869 | 1347 | } | 1603 | } |
2870 | 1604 | |||
2871 | 1348 | public String readlink(String path) throws SftpException{ | 1605 | public String readlink(String path) throws SftpException{ |
2872 | 1349 | try{ | 1606 | try{ |
2873 | 1350 | |||
2874 | 1351 | if(server_version<3){ | 1607 | if(server_version<3){ |
2875 | 1352 | throw new SftpException(SSH_FX_OP_UNSUPPORTED, | 1608 | throw new SftpException(SSH_FX_OP_UNSUPPORTED, |
2876 | 1353 | "The remote sshd is too old to support symlink operation."); | 1609 | "The remote sshd is too old to support symlink operation."); |
2877 | 1354 | } | 1610 | } |
2878 | 1355 | 1611 | ||
2879 | 1612 | ((MyPipedInputStream)io_in).updateReadSide(); | ||
2880 | 1613 | |||
2881 | 1356 | path=remoteAbsolutePath(path); | 1614 | path=remoteAbsolutePath(path); |
2882 | 1357 | 1615 | ||
2883 | 1358 | path=isUnique(path); | 1616 | path=isUnique(path); |
2884 | @@ -1400,6 +1658,8 @@ | |||
2885 | 1400 | } | 1658 | } |
2886 | 1401 | 1659 | ||
2887 | 1402 | try{ | 1660 | try{ |
2888 | 1661 | ((MyPipedInputStream)io_in).updateReadSide(); | ||
2889 | 1662 | |||
2890 | 1403 | oldpath=remoteAbsolutePath(oldpath); | 1663 | oldpath=remoteAbsolutePath(oldpath); |
2891 | 1404 | newpath=remoteAbsolutePath(newpath); | 1664 | newpath=remoteAbsolutePath(newpath); |
2892 | 1405 | 1665 | ||
2893 | @@ -1443,6 +1703,8 @@ | |||
2894 | 1443 | } | 1703 | } |
2895 | 1444 | 1704 | ||
2896 | 1445 | try{ | 1705 | try{ |
2897 | 1706 | ((MyPipedInputStream)io_in).updateReadSide(); | ||
2898 | 1707 | |||
2899 | 1446 | oldpath=remoteAbsolutePath(oldpath); | 1708 | oldpath=remoteAbsolutePath(oldpath); |
2900 | 1447 | newpath=remoteAbsolutePath(newpath); | 1709 | newpath=remoteAbsolutePath(newpath); |
2901 | 1448 | 1710 | ||
2902 | @@ -1489,6 +1751,8 @@ | |||
2903 | 1489 | } | 1751 | } |
2904 | 1490 | public void rm(String path) throws SftpException{ | 1752 | public void rm(String path) throws SftpException{ |
2905 | 1491 | try{ | 1753 | try{ |
2906 | 1754 | ((MyPipedInputStream)io_in).updateReadSide(); | ||
2907 | 1755 | |||
2908 | 1492 | path=remoteAbsolutePath(path); | 1756 | path=remoteAbsolutePath(path); |
2909 | 1493 | 1757 | ||
2910 | 1494 | Vector v=glob_remote(path); | 1758 | Vector v=glob_remote(path); |
2911 | @@ -1546,6 +1810,8 @@ | |||
2912 | 1546 | 1810 | ||
2913 | 1547 | public void chgrp(int gid, String path) throws SftpException{ | 1811 | public void chgrp(int gid, String path) throws SftpException{ |
2914 | 1548 | try{ | 1812 | try{ |
2915 | 1813 | ((MyPipedInputStream)io_in).updateReadSide(); | ||
2916 | 1814 | |||
2917 | 1549 | path=remoteAbsolutePath(path); | 1815 | path=remoteAbsolutePath(path); |
2918 | 1550 | 1816 | ||
2919 | 1551 | Vector v=glob_remote(path); | 1817 | Vector v=glob_remote(path); |
2920 | @@ -1570,6 +1836,8 @@ | |||
2921 | 1570 | 1836 | ||
2922 | 1571 | public void chown(int uid, String path) throws SftpException{ | 1837 | public void chown(int uid, String path) throws SftpException{ |
2923 | 1572 | try{ | 1838 | try{ |
2924 | 1839 | ((MyPipedInputStream)io_in).updateReadSide(); | ||
2925 | 1840 | |||
2926 | 1573 | path=remoteAbsolutePath(path); | 1841 | path=remoteAbsolutePath(path); |
2927 | 1574 | 1842 | ||
2928 | 1575 | Vector v=glob_remote(path); | 1843 | Vector v=glob_remote(path); |
2929 | @@ -1594,6 +1862,8 @@ | |||
2930 | 1594 | 1862 | ||
2931 | 1595 | public void chmod(int permissions, String path) throws SftpException{ | 1863 | public void chmod(int permissions, String path) throws SftpException{ |
2932 | 1596 | try{ | 1864 | try{ |
2933 | 1865 | ((MyPipedInputStream)io_in).updateReadSide(); | ||
2934 | 1866 | |||
2935 | 1597 | path=remoteAbsolutePath(path); | 1867 | path=remoteAbsolutePath(path); |
2936 | 1598 | 1868 | ||
2937 | 1599 | Vector v=glob_remote(path); | 1869 | Vector v=glob_remote(path); |
2938 | @@ -1618,6 +1888,8 @@ | |||
2939 | 1618 | 1888 | ||
2940 | 1619 | public void setMtime(String path, int mtime) throws SftpException{ | 1889 | public void setMtime(String path, int mtime) throws SftpException{ |
2941 | 1620 | try{ | 1890 | try{ |
2942 | 1891 | ((MyPipedInputStream)io_in).updateReadSide(); | ||
2943 | 1892 | |||
2944 | 1621 | path=remoteAbsolutePath(path); | 1893 | path=remoteAbsolutePath(path); |
2945 | 1622 | 1894 | ||
2946 | 1623 | Vector v=glob_remote(path); | 1895 | Vector v=glob_remote(path); |
2947 | @@ -1642,6 +1914,8 @@ | |||
2948 | 1642 | 1914 | ||
2949 | 1643 | public void rmdir(String path) throws SftpException{ | 1915 | public void rmdir(String path) throws SftpException{ |
2950 | 1644 | try{ | 1916 | try{ |
2951 | 1917 | ((MyPipedInputStream)io_in).updateReadSide(); | ||
2952 | 1918 | |||
2953 | 1645 | path=remoteAbsolutePath(path); | 1919 | path=remoteAbsolutePath(path); |
2954 | 1646 | 1920 | ||
2955 | 1647 | Vector v=glob_remote(path); | 1921 | Vector v=glob_remote(path); |
2956 | @@ -1679,6 +1953,8 @@ | |||
2957 | 1679 | 1953 | ||
2958 | 1680 | public void mkdir(String path) throws SftpException{ | 1954 | public void mkdir(String path) throws SftpException{ |
2959 | 1681 | try{ | 1955 | try{ |
2960 | 1956 | ((MyPipedInputStream)io_in).updateReadSide(); | ||
2961 | 1957 | |||
2962 | 1682 | path=remoteAbsolutePath(path); | 1958 | path=remoteAbsolutePath(path); |
2963 | 1683 | 1959 | ||
2964 | 1684 | sendMKDIR(Util.str2byte(path, fEncoding), null); | 1960 | sendMKDIR(Util.str2byte(path, fEncoding), null); |
2965 | @@ -1708,8 +1984,9 @@ | |||
2966 | 1708 | 1984 | ||
2967 | 1709 | public SftpATTRS stat(String path) throws SftpException{ | 1985 | public SftpATTRS stat(String path) throws SftpException{ |
2968 | 1710 | try{ | 1986 | try{ |
2969 | 1987 | ((MyPipedInputStream)io_in).updateReadSide(); | ||
2970 | 1988 | |||
2971 | 1711 | path=remoteAbsolutePath(path); | 1989 | path=remoteAbsolutePath(path); |
2972 | 1712 | |||
2973 | 1713 | path=isUnique(path); | 1990 | path=isUnique(path); |
2974 | 1714 | 1991 | ||
2975 | 1715 | return _stat(path); | 1992 | return _stat(path); |
2976 | @@ -1760,8 +2037,9 @@ | |||
2977 | 1760 | 2037 | ||
2978 | 1761 | public SftpATTRS lstat(String path) throws SftpException{ | 2038 | public SftpATTRS lstat(String path) throws SftpException{ |
2979 | 1762 | try{ | 2039 | try{ |
2980 | 2040 | ((MyPipedInputStream)io_in).updateReadSide(); | ||
2981 | 2041 | |||
2982 | 1763 | path=remoteAbsolutePath(path); | 2042 | path=remoteAbsolutePath(path); |
2983 | 1764 | |||
2984 | 1765 | path=isUnique(path); | 2043 | path=isUnique(path); |
2985 | 1766 | 2044 | ||
2986 | 1767 | return _lstat(path); | 2045 | return _lstat(path); |
2987 | @@ -1836,6 +2114,8 @@ | |||
2988 | 1836 | 2114 | ||
2989 | 1837 | public void setStat(String path, SftpATTRS attr) throws SftpException{ | 2115 | public void setStat(String path, SftpATTRS attr) throws SftpException{ |
2990 | 1838 | try{ | 2116 | try{ |
2991 | 2117 | ((MyPipedInputStream)io_in).updateReadSide(); | ||
2992 | 2118 | |||
2993 | 1839 | path=remoteAbsolutePath(path); | 2119 | path=remoteAbsolutePath(path); |
2994 | 1840 | 2120 | ||
2995 | 1841 | Vector v=glob_remote(path); | 2121 | Vector v=glob_remote(path); |
2996 | @@ -1885,6 +2165,8 @@ | |||
2997 | 1885 | public String getHome() throws SftpException { | 2165 | public String getHome() throws SftpException { |
2998 | 1886 | if(home==null){ | 2166 | if(home==null){ |
2999 | 1887 | try{ | 2167 | try{ |
3000 | 2168 | ((MyPipedInputStream)io_in).updateReadSide(); | ||
3001 | 2169 | |||
3002 | 1888 | byte[] _home=_realpath(""); | 2170 | byte[] _home=_realpath(""); |
3003 | 1889 | home=Util.byte2str(_home, fEncoding); | 2171 | home=Util.byte2str(_home, fEncoding); |
3004 | 1890 | } | 2172 | } |
3005 | @@ -2040,32 +2322,31 @@ | |||
3006 | 2040 | private int sendWRITE(byte[] handle, long offset, | 2322 | private int sendWRITE(byte[] handle, long offset, |
3007 | 2041 | byte[] data, int start, int length) throws Exception{ | 2323 | byte[] data, int start, int length) throws Exception{ |
3008 | 2042 | int _length=length; | 2324 | int _length=length; |
3017 | 2043 | packet.reset(); | 2325 | opacket.reset(); |
3018 | 2044 | if(buf.buffer.length<buf.index+13+21+handle.length+length | 2326 | if(obuf.buffer.length<obuf.index+13+21+handle.length+length+Session.buffer_margin){ |
3019 | 2045 | +32 +20 // padding and mac | 2327 | _length=obuf.buffer.length-(obuf.index+13+21+handle.length+Session.buffer_margin); |
3020 | 2046 | ){ | 2328 | // System.err.println("_length="+_length+" length="+length); |
3013 | 2047 | _length=buf.buffer.length-(buf.index+13+21+handle.length | ||
3014 | 2048 | +32 +20 // padding and mac | ||
3015 | 2049 | ); | ||
3016 | 2050 | //System.err.println("_length="+_length+" length="+length); | ||
3021 | 2051 | } | 2329 | } |
3022 | 2052 | 2330 | ||
3029 | 2053 | putHEAD(SSH_FXP_WRITE, 21+handle.length+_length); // 14 | 2331 | putHEAD(obuf, SSH_FXP_WRITE, 21+handle.length+_length); // 14 |
3030 | 2054 | buf.putInt(seq++); // 4 | 2332 | obuf.putInt(seq++); // 4 |
3031 | 2055 | buf.putString(handle); // 4+handle.length | 2333 | obuf.putString(handle); // 4+handle.length |
3032 | 2056 | buf.putLong(offset); // 8 | 2334 | obuf.putLong(offset); // 8 |
3033 | 2057 | if(buf.buffer!=data){ | 2335 | if(obuf.buffer!=data){ |
3034 | 2058 | buf.putString(data, start, _length); // 4+_length | 2336 | obuf.putString(data, start, _length); // 4+_length |
3035 | 2059 | } | 2337 | } |
3036 | 2060 | else{ | 2338 | else{ |
3039 | 2061 | buf.putInt(_length); | 2339 | obuf.putInt(_length); |
3040 | 2062 | buf.skip(_length); | 2340 | obuf.skip(_length); |
3041 | 2063 | } | 2341 | } |
3043 | 2064 | getSession().write(packet, this, 21+handle.length+_length+4); | 2342 | getSession().write(opacket, this, 21+handle.length+_length+4); |
3044 | 2065 | return _length; | 2343 | return _length; |
3045 | 2066 | } | 2344 | } |
3046 | 2067 | |||
3047 | 2068 | private void sendREAD(byte[] handle, long offset, int length) throws Exception{ | 2345 | private void sendREAD(byte[] handle, long offset, int length) throws Exception{ |
3048 | 2346 | sendREAD(handle, offset, length, null); | ||
3049 | 2347 | } | ||
3050 | 2348 | private void sendREAD(byte[] handle, long offset, int length, | ||
3051 | 2349 | RequestQueue rrq) throws Exception{ | ||
3052 | 2069 | packet.reset(); | 2350 | packet.reset(); |
3053 | 2070 | putHEAD(SSH_FXP_READ, 21+handle.length); | 2351 | putHEAD(SSH_FXP_READ, 21+handle.length); |
3054 | 2071 | buf.putInt(seq++); | 2352 | buf.putInt(seq++); |
3055 | @@ -2073,9 +2354,12 @@ | |||
3056 | 2073 | buf.putLong(offset); | 2354 | buf.putLong(offset); |
3057 | 2074 | buf.putInt(length); | 2355 | buf.putInt(length); |
3058 | 2075 | getSession().write(packet, this, 21+handle.length+4); | 2356 | getSession().write(packet, this, 21+handle.length+4); |
3059 | 2357 | if(rrq!=null){ | ||
3060 | 2358 | rrq.add(seq-1, offset, length); | ||
3061 | 2359 | } | ||
3062 | 2076 | } | 2360 | } |
3063 | 2077 | 2361 | ||
3065 | 2078 | private void putHEAD(byte type, int length) throws Exception{ | 2362 | private void putHEAD(Buffer buf, byte type, int length) throws Exception{ |
3066 | 2079 | buf.putByte((byte)Session.SSH_MSG_CHANNEL_DATA); | 2363 | buf.putByte((byte)Session.SSH_MSG_CHANNEL_DATA); |
3067 | 2080 | buf.putInt(recipient); | 2364 | buf.putInt(recipient); |
3068 | 2081 | buf.putInt(length+4); | 2365 | buf.putInt(length+4); |
3069 | @@ -2083,8 +2367,11 @@ | |||
3070 | 2083 | buf.putByte(type); | 2367 | buf.putByte(type); |
3071 | 2084 | } | 2368 | } |
3072 | 2085 | 2369 | ||
3073 | 2370 | private void putHEAD(byte type, int length) throws Exception{ | ||
3074 | 2371 | putHEAD(buf, type, length); | ||
3075 | 2372 | } | ||
3076 | 2373 | |||
3077 | 2086 | private Vector glob_remote(String _path) throws Exception{ | 2374 | private Vector glob_remote(String _path) throws Exception{ |
3078 | 2087 | |||
3079 | 2088 | Vector v=new Vector(); | 2375 | Vector v=new Vector(); |
3080 | 2089 | int i=0; | 2376 | int i=0; |
3081 | 2090 | 2377 | ||
3082 | @@ -2104,7 +2391,7 @@ | |||
3083 | 2104 | boolean pattern_has_wildcard=isPattern(_pattern, _pattern_utf8); | 2391 | boolean pattern_has_wildcard=isPattern(_pattern, _pattern_utf8); |
3084 | 2105 | 2392 | ||
3085 | 2106 | if(!pattern_has_wildcard){ | 2393 | if(!pattern_has_wildcard){ |
3087 | 2107 | if(dir.length()!=1) // not equal to "/" | 2394 | if(!dir.equals("/")) |
3088 | 2108 | dir+="/"; | 2395 | dir+="/"; |
3089 | 2109 | v.addElement(dir+Util.unquote(_pattern)); | 2396 | v.addElement(dir+Util.unquote(_pattern)); |
3090 | 2110 | return v; | 2397 | return v; |
3091 | @@ -2202,23 +2489,16 @@ | |||
3092 | 2202 | } | 2489 | } |
3093 | 2203 | 2490 | ||
3094 | 2204 | private boolean isPattern(byte[] path){ | 2491 | private boolean isPattern(byte[] path){ |
3109 | 2205 | int i=path.length-1; | 2492 | int length=path.length; |
3110 | 2206 | while(i>=0){ | 2493 | int i=0; |
3111 | 2207 | if(path[i]=='*' || path[i]=='?'){ | 2494 | while(i<length){ |
3112 | 2208 | if(i>0 && path[i-1]=='\\'){ | 2495 | if(path[i]=='*' || path[i]=='?') |
3113 | 2209 | i--; | 2496 | return true; |
3114 | 2210 | if(i>0 && path[i-1]=='\\'){ // \\* or \\? | 2497 | if(path[i]=='\\' && (i+1)<length) |
3115 | 2211 | break; | 2498 | i++; |
3116 | 2212 | } | 2499 | i++; |
3103 | 2213 | } | ||
3104 | 2214 | else{ | ||
3105 | 2215 | break; | ||
3106 | 2216 | } | ||
3107 | 2217 | } | ||
3108 | 2218 | i--; | ||
3117 | 2219 | } | 2500 | } |
3120 | 2220 | // System.err.println("isPattern: ["+(new String(path))+"] "+(!(i<0))); | 2501 | return false; |
3119 | 2221 | return !(i<0); | ||
3121 | 2222 | } | 2502 | } |
3122 | 2223 | 2503 | ||
3123 | 2224 | private Vector glob_local(String _path) throws Exception{ | 2504 | private Vector glob_local(String _path) throws Exception{ |
3124 | @@ -2358,6 +2638,7 @@ | |||
3125 | 2358 | private String remoteAbsolutePath(String path) throws SftpException{ | 2638 | private String remoteAbsolutePath(String path) throws SftpException{ |
3126 | 2359 | if(path.charAt(0)=='/') return path; | 2639 | if(path.charAt(0)=='/') return path; |
3127 | 2360 | String cwd=getCwd(); | 2640 | String cwd=getCwd(); |
3128 | 2641 | // if(cwd.equals(getHome())) return path; | ||
3129 | 2361 | if(cwd.endsWith("/")) return cwd+path; | 2642 | if(cwd.endsWith("/")) return cwd+path; |
3130 | 2362 | return cwd+"/"+path; | 2643 | return cwd+"/"+path; |
3131 | 2363 | } | 2644 | } |
3132 | @@ -2391,9 +2672,9 @@ | |||
3133 | 2391 | 2672 | ||
3134 | 2392 | public void setFilenameEncoding(String encoding) throws SftpException{ | 2673 | public void setFilenameEncoding(String encoding) throws SftpException{ |
3135 | 2393 | int sversion=getServerVersion(); | 2674 | int sversion=getServerVersion(); |
3137 | 2394 | if(sversion > 3 && | 2675 | if(3 <= sversion && sversion <= 5 && |
3138 | 2395 | !encoding.equals(UTF8)){ | 2676 | !encoding.equals(UTF8)){ |
3140 | 2396 | throw new SftpException(SSH_FX_FAILURE, | 2677 | throw new SftpException(SSH_FX_FAILURE, |
3141 | 2397 | "The encoding can not be changed for this sftp server."); | 2678 | "The encoding can not be changed for this sftp server."); |
3142 | 2398 | } | 2679 | } |
3143 | 2399 | if(encoding.equals(UTF8)){ | 2680 | if(encoding.equals(UTF8)){ |
3144 | @@ -2445,4 +2726,26 @@ | |||
3145 | 2445 | throw new ClassCastException("a decendent of LsEntry must be given."); | 2726 | throw new ClassCastException("a decendent of LsEntry must be given."); |
3146 | 2446 | } | 2727 | } |
3147 | 2447 | } | 2728 | } |
3148 | 2729 | |||
3149 | 2730 | /** | ||
3150 | 2731 | * This interface will be passed as an arugment for <code>ls</code> method. | ||
3151 | 2732 | * | ||
3152 | 2733 | * @see #LsEntry | ||
3153 | 2734 | * @see #ls(String, LsEntrySelector) | ||
3154 | 2735 | * @since 0.1.47 | ||
3155 | 2736 | */ | ||
3156 | 2737 | public interface LsEntrySelector { | ||
3157 | 2738 | public final int CONTINUE = 0; | ||
3158 | 2739 | public final int BREAK = 1; | ||
3159 | 2740 | |||
3160 | 2741 | /** | ||
3161 | 2742 | * <p> The <code>select</code> method will be invoked in <code>ls</code> | ||
3162 | 2743 | * method for each file entry. If this method returns BREAK, | ||
3163 | 2744 | * <code>ls</code> will be canceled. | ||
3164 | 2745 | * | ||
3165 | 2746 | * @param entry one of entry from ls | ||
3166 | 2747 | * @return if BREAK is returned, the 'ls' operation will be canceled. | ||
3167 | 2748 | */ | ||
3168 | 2749 | public int select(LsEntry entry); | ||
3169 | 2750 | } | ||
3170 | 2448 | } | 2751 | } |
3171 | 2449 | 2752 | ||
3172 | === modified file 'src/main/java/com/jcraft/jsch/ChannelShell.java' | |||
3173 | --- src/com/jcraft/jsch/ChannelShell.java 2010-06-27 23:17:34 +0000 | |||
3174 | +++ src/main/java/com/jcraft/jsch/ChannelShell.java 2012-05-04 10:23:17 +0000 | |||
3175 | @@ -1,6 +1,6 @@ | |||
3176 | 1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ | 1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ |
3177 | 2 | /* | 2 | /* |
3179 | 3 | Copyright (c) 2002-2009 ymnk, JCraft,Inc. All rights reserved. | 3 | Copyright (c) 2002-2012 ymnk, JCraft,Inc. All rights reserved. |
3180 | 4 | 4 | ||
3181 | 5 | Redistribution and use in source and binary forms, with or without | 5 | Redistribution and use in source and binary forms, with or without |
3182 | 6 | modification, are permitted provided that the following conditions are met: | 6 | modification, are permitted provided that the following conditions are met: |
3183 | 7 | 7 | ||
3184 | === modified file 'src/main/java/com/jcraft/jsch/ChannelSubsystem.java' | |||
3185 | --- src/com/jcraft/jsch/ChannelSubsystem.java 2010-06-27 23:17:34 +0000 | |||
3186 | +++ src/main/java/com/jcraft/jsch/ChannelSubsystem.java 2012-05-04 10:23:17 +0000 | |||
3187 | @@ -1,6 +1,6 @@ | |||
3188 | 1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ | 1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ |
3189 | 2 | /* | 2 | /* |
3191 | 3 | Copyright (c) 2005-2009 ymnk, JCraft,Inc. All rights reserved. | 3 | Copyright (c) 2005-2012 ymnk, JCraft,Inc. All rights reserved. |
3192 | 4 | 4 | ||
3193 | 5 | Redistribution and use in source and binary forms, with or without | 5 | Redistribution and use in source and binary forms, with or without |
3194 | 6 | modification, are permitted provided that the following conditions are met: | 6 | modification, are permitted provided that the following conditions are met: |
3195 | @@ -34,7 +34,7 @@ | |||
3196 | 34 | boolean pty=false; | 34 | boolean pty=false; |
3197 | 35 | boolean want_reply=true; | 35 | boolean want_reply=true; |
3198 | 36 | String subsystem=""; | 36 | String subsystem=""; |
3200 | 37 | public void setXForwarding(boolean foo){ xforwading=true; } | 37 | public void setXForwarding(boolean foo){ xforwading=foo; } |
3201 | 38 | public void setPty(boolean foo){ pty=foo; } | 38 | public void setPty(boolean foo){ pty=foo; } |
3202 | 39 | public void setWantReply(boolean foo){ want_reply=foo; } | 39 | public void setWantReply(boolean foo){ want_reply=foo; } |
3203 | 40 | public void setSubsystem(String foo){ subsystem=foo; } | 40 | public void setSubsystem(String foo){ subsystem=foo; } |
3204 | 41 | 41 | ||
3205 | === modified file 'src/main/java/com/jcraft/jsch/ChannelX11.java' | |||
3206 | --- src/com/jcraft/jsch/ChannelX11.java 2010-06-27 23:17:34 +0000 | |||
3207 | +++ src/main/java/com/jcraft/jsch/ChannelX11.java 2012-05-04 10:23:17 +0000 | |||
3208 | @@ -1,6 +1,6 @@ | |||
3209 | 1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ | 1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ |
3210 | 2 | /* | 2 | /* |
3212 | 3 | Copyright (c) 2002-2009 ymnk, JCraft,Inc. All rights reserved. | 3 | Copyright (c) 2002-2012 ymnk, JCraft,Inc. All rights reserved. |
3213 | 4 | 4 | ||
3214 | 5 | Redistribution and use in source and binary forms, with or without | 5 | Redistribution and use in source and binary forms, with or without |
3215 | 6 | modification, are permitted provided that the following conditions are met: | 6 | modification, are permitted provided that the following conditions are met: |
3216 | @@ -61,7 +61,7 @@ | |||
3217 | 61 | return 0; | 61 | return 0; |
3218 | 62 | } | 62 | } |
3219 | 63 | static void setCookie(String foo){ | 63 | static void setCookie(String foo){ |
3221 | 64 | cookie_hex=foo.getBytes(); | 64 | cookie_hex=Util.str2byte(foo); |
3222 | 65 | cookie=new byte[16]; | 65 | cookie=new byte[16]; |
3223 | 66 | for(int i=0; i<16; i++){ | 66 | for(int i=0; i<16; i++){ |
3224 | 67 | cookie[i]=(byte)(((revtable(cookie_hex[i*2])<<4)&0xf0) | | 67 | cookie[i]=(byte)(((revtable(cookie_hex[i*2])<<4)&0xf0) | |
3225 | @@ -99,6 +99,13 @@ | |||
3226 | 99 | } | 99 | } |
3227 | 100 | } | 100 | } |
3228 | 101 | 101 | ||
3229 | 102 | static void removeFakedCookie(Session session){ | ||
3230 | 103 | synchronized(faked_cookie_hex_pool){ | ||
3231 | 104 | faked_cookie_hex_pool.remove(session); | ||
3232 | 105 | faked_cookie_pool.remove(session); | ||
3233 | 106 | } | ||
3234 | 107 | } | ||
3235 | 108 | |||
3236 | 102 | ChannelX11(){ | 109 | ChannelX11(){ |
3237 | 103 | super(); | 110 | super(); |
3238 | 104 | 111 | ||
3239 | @@ -106,7 +113,7 @@ | |||
3240 | 106 | setLocalWindowSize(LOCAL_WINDOW_SIZE_MAX); | 113 | setLocalWindowSize(LOCAL_WINDOW_SIZE_MAX); |
3241 | 107 | setLocalPacketSize(LOCAL_MAXIMUM_PACKET_SIZE); | 114 | setLocalPacketSize(LOCAL_MAXIMUM_PACKET_SIZE); |
3242 | 108 | 115 | ||
3244 | 109 | type="x11".getBytes(); | 116 | type=Util.str2byte("x11"); |
3245 | 110 | 117 | ||
3246 | 111 | connected=true; | 118 | connected=true; |
3247 | 112 | /* | 119 | /* |
3248 | @@ -150,9 +157,7 @@ | |||
3249 | 150 | io.in!=null){ | 157 | io.in!=null){ |
3250 | 151 | i=io.in.read(buf.buffer, | 158 | i=io.in.read(buf.buffer, |
3251 | 152 | 14, | 159 | 14, |
3255 | 153 | buf.buffer.length-14 | 160 | buf.buffer.length-14-Session.buffer_margin); |
3253 | 154 | -32 -20 // padding and mac | ||
3254 | 155 | ); | ||
3256 | 156 | if(i<=0){ | 161 | if(i<=0){ |
3257 | 157 | eof(); | 162 | eof(); |
3258 | 158 | break; | 163 | break; |
3259 | 159 | 164 | ||
3260 | === modified file 'src/main/java/com/jcraft/jsch/Cipher.java' | |||
3261 | --- src/com/jcraft/jsch/Cipher.java 2010-06-27 23:17:34 +0000 | |||
3262 | +++ src/main/java/com/jcraft/jsch/Cipher.java 2012-05-04 10:23:17 +0000 | |||
3263 | @@ -1,6 +1,6 @@ | |||
3264 | 1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ | 1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ |
3265 | 2 | /* | 2 | /* |
3267 | 3 | Copyright (c) 2002-2009 ymnk, JCraft,Inc. All rights reserved. | 3 | Copyright (c) 2002-2012 ymnk, JCraft,Inc. All rights reserved. |
3268 | 4 | 4 | ||
3269 | 5 | Redistribution and use in source and binary forms, with or without | 5 | Redistribution and use in source and binary forms, with or without |
3270 | 6 | modification, are permitted provided that the following conditions are met: | 6 | modification, are permitted provided that the following conditions are met: |
3271 | @@ -36,4 +36,5 @@ | |||
3272 | 36 | int getBlockSize(); | 36 | int getBlockSize(); |
3273 | 37 | void init(int mode, byte[] key, byte[] iv) throws Exception; | 37 | void init(int mode, byte[] key, byte[] iv) throws Exception; |
3274 | 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; |
3275 | 39 | boolean isCBC(); | ||
3276 | 39 | } | 40 | } |
3277 | 40 | 41 | ||
3278 | === modified file 'src/main/java/com/jcraft/jsch/CipherNone.java' | |||
3279 | --- src/com/jcraft/jsch/CipherNone.java 2010-06-27 23:17:34 +0000 | |||
3280 | +++ src/main/java/com/jcraft/jsch/CipherNone.java 2012-05-04 10:23:17 +0000 | |||
3281 | @@ -1,6 +1,6 @@ | |||
3282 | 1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ | 1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ |
3283 | 2 | /* | 2 | /* |
3285 | 3 | Copyright (c) 2002-2009 ymnk, JCraft,Inc. All rights reserved. | 3 | Copyright (c) 2002-2012 ymnk, JCraft,Inc. All rights reserved. |
3286 | 4 | 4 | ||
3287 | 5 | Redistribution and use in source and binary forms, with or without | 5 | Redistribution and use in source and binary forms, with or without |
3288 | 6 | modification, are permitted provided that the following conditions are met: | 6 | modification, are permitted provided that the following conditions are met: |
3289 | @@ -38,4 +38,5 @@ | |||
3290 | 38 | } | 38 | } |
3291 | 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{ |
3292 | 40 | } | 40 | } |
3293 | 41 | public boolean isCBC(){return false; } | ||
3294 | 41 | } | 42 | } |
3295 | 42 | 43 | ||
3296 | === modified file 'src/main/java/com/jcraft/jsch/Compression.java' | |||
3297 | --- src/com/jcraft/jsch/Compression.java 2010-06-27 23:17:34 +0000 | |||
3298 | +++ src/main/java/com/jcraft/jsch/Compression.java 2012-05-04 10:23:17 +0000 | |||
3299 | @@ -1,6 +1,6 @@ | |||
3300 | 1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ | 1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ |
3301 | 2 | /* | 2 | /* |
3303 | 3 | Copyright (c) 2002-2009 ymnk, JCraft,Inc. All rights reserved. | 3 | Copyright (c) 2002-2012 ymnk, JCraft,Inc. All rights reserved. |
3304 | 4 | 4 | ||
3305 | 5 | Redistribution and use in source and binary forms, with or without | 5 | Redistribution and use in source and binary forms, with or without |
3306 | 6 | modification, are permitted provided that the following conditions are met: | 6 | modification, are permitted provided that the following conditions are met: |
3307 | @@ -33,6 +33,6 @@ | |||
3308 | 33 | static public final int INFLATER=0; | 33 | static public final int INFLATER=0; |
3309 | 34 | static public final int DEFLATER=1; | 34 | static public final int DEFLATER=1; |
3310 | 35 | void init(int type, int level); | 35 | void init(int type, int level); |
3312 | 36 | int compress(byte[] buf, int start, int len); | 36 | byte[] compress(byte[] buf, int start, int[] len); |
3313 | 37 | byte[] uncompress(byte[] buf, int start, int[] len); | 37 | byte[] uncompress(byte[] buf, int start, int[] len); |
3314 | 38 | } | 38 | } |
3315 | 39 | 39 | ||
3316 | === modified file 'src/main/java/com/jcraft/jsch/DH.java' | |||
3317 | --- src/com/jcraft/jsch/DH.java 2010-06-27 23:17:34 +0000 | |||
3318 | +++ src/main/java/com/jcraft/jsch/DH.java 2012-05-04 10:23:17 +0000 | |||
3319 | @@ -1,6 +1,6 @@ | |||
3320 | 1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ | 1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ |
3321 | 2 | /* | 2 | /* |
3323 | 3 | Copyright (c) 2002-2009 ymnk, JCraft,Inc. All rights reserved. | 3 | Copyright (c) 2002-2012 ymnk, JCraft,Inc. All rights reserved. |
3324 | 4 | 4 | ||
3325 | 5 | Redistribution and use in source and binary forms, with or without | 5 | Redistribution and use in source and binary forms, with or without |
3326 | 6 | modification, are permitted provided that the following conditions are met: | 6 | modification, are permitted provided that the following conditions are met: |
3327 | 7 | 7 | ||
3328 | === modified file 'src/main/java/com/jcraft/jsch/DHG1.java' | |||
3329 | --- src/com/jcraft/jsch/DHG1.java 2010-06-27 23:17:34 +0000 | |||
3330 | +++ src/main/java/com/jcraft/jsch/DHG1.java 2012-05-04 10:23:17 +0000 | |||
3331 | @@ -1,6 +1,6 @@ | |||
3332 | 1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ | 1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ |
3333 | 2 | /* | 2 | /* |
3335 | 3 | Copyright (c) 2002-2009 ymnk, JCraft,Inc. All rights reserved. | 3 | Copyright (c) 2002-2012 ymnk, JCraft,Inc. All rights reserved. |
3336 | 4 | 4 | ||
3337 | 5 | Redistribution and use in source and binary forms, with or without | 5 | Redistribution and use in source and binary forms, with or without |
3338 | 6 | modification, are permitted provided that the following conditions are met: | 6 | modification, are permitted provided that the following conditions are met: |
3339 | @@ -203,7 +203,7 @@ | |||
3340 | 203 | j=0; | 203 | j=0; |
3341 | 204 | j=((K_S[i++]<<24)&0xff000000)|((K_S[i++]<<16)&0x00ff0000)| | 204 | j=((K_S[i++]<<24)&0xff000000)|((K_S[i++]<<16)&0x00ff0000)| |
3342 | 205 | ((K_S[i++]<<8)&0x0000ff00)|((K_S[i++])&0x000000ff); | 205 | ((K_S[i++]<<8)&0x0000ff00)|((K_S[i++])&0x000000ff); |
3344 | 206 | String alg=new String(K_S, i, j); | 206 | String alg=Util.byte2str(K_S, i, j); |
3345 | 207 | i+=j; | 207 | i+=j; |
3346 | 208 | 208 | ||
3347 | 209 | boolean result=false; | 209 | boolean result=false; |
3348 | 210 | 210 | ||
3349 | === added file 'src/main/java/com/jcraft/jsch/DHG14.java' | |||
3350 | --- src/main/java/com/jcraft/jsch/DHG14.java 1970-01-01 00:00:00 +0000 | |||
3351 | +++ src/main/java/com/jcraft/jsch/DHG14.java 2012-05-04 10:23:17 +0000 | |||
3352 | @@ -0,0 +1,310 @@ | |||
3353 | 1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ | ||
3354 | 2 | /* | ||
3355 | 3 | Copyright (c) 2002-2012 ymnk, JCraft,Inc. All rights reserved. | ||
3356 | 4 | |||
3357 | 5 | Redistribution and use in source and binary forms, with or without | ||
3358 | 6 | modification, are permitted provided that the following conditions are met: | ||
3359 | 7 | |||
3360 | 8 | 1. Redistributions of source code must retain the above copyright notice, | ||
3361 | 9 | this list of conditions and the following disclaimer. | ||
3362 | 10 | |||
3363 | 11 | 2. Redistributions in binary form must reproduce the above copyright | ||
3364 | 12 | notice, this list of conditions and the following disclaimer in | ||
3365 | 13 | the documentation and/or other materials provided with the distribution. | ||
3366 | 14 | |||
3367 | 15 | 3. The names of the authors may not be used to endorse or promote products | ||
3368 | 16 | derived from this software without specific prior written permission. | ||
3369 | 17 | |||
3370 | 18 | THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, | ||
3371 | 19 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND | ||
3372 | 20 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT, | ||
3373 | 21 | INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
3374 | 22 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
3375 | 23 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, | ||
3376 | 24 | OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | ||
3377 | 25 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | ||
3378 | 26 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, | ||
3379 | 27 | EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
3380 | 28 | */ | ||
3381 | 29 | |||
3382 | 30 | package com.jcraft.jsch; | ||
3383 | 31 | |||
3384 | 32 | public class DHG14 extends KeyExchange{ | ||
3385 | 33 | |||
3386 | 34 | static final byte[] g={ 2 }; | ||
3387 | 35 | static final byte[] p={ | ||
3388 | 36 | (byte)0x00, | ||
3389 | 37 | (byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF, | ||
3390 | 38 | (byte)0xC9,(byte)0x0F,(byte)0xDA,(byte)0xA2,(byte)0x21,(byte)0x68,(byte)0xC2,(byte)0x34, | ||
3391 | 39 | (byte)0xC4,(byte)0xC6,(byte)0x62,(byte)0x8B,(byte)0x80,(byte)0xDC,(byte)0x1C,(byte)0xD1, | ||
3392 | 40 | (byte)0x29,(byte)0x02,(byte)0x4E,(byte)0x08,(byte)0x8A,(byte)0x67,(byte)0xCC,(byte)0x74, | ||
3393 | 41 | (byte)0x02,(byte)0x0B,(byte)0xBE,(byte)0xA6,(byte)0x3B,(byte)0x13,(byte)0x9B,(byte)0x22, | ||
3394 | 42 | (byte)0x51,(byte)0x4A,(byte)0x08,(byte)0x79,(byte)0x8E,(byte)0x34,(byte)0x04,(byte)0xDD, | ||
3395 | 43 | (byte)0xEF,(byte)0x95,(byte)0x19,(byte)0xB3,(byte)0xCD,(byte)0x3A,(byte)0x43,(byte)0x1B, | ||
3396 | 44 | (byte)0x30,(byte)0x2B,(byte)0x0A,(byte)0x6D,(byte)0xF2,(byte)0x5F,(byte)0x14,(byte)0x37, | ||
3397 | 45 | (byte)0x4F,(byte)0xE1,(byte)0x35,(byte)0x6D,(byte)0x6D,(byte)0x51,(byte)0xC2,(byte)0x45, | ||
3398 | 46 | (byte)0xE4,(byte)0x85,(byte)0xB5,(byte)0x76,(byte)0x62,(byte)0x5E,(byte)0x7E,(byte)0xC6, | ||
3399 | 47 | (byte)0xF4,(byte)0x4C,(byte)0x42,(byte)0xE9,(byte)0xA6,(byte)0x37,(byte)0xED,(byte)0x6B, | ||
3400 | 48 | (byte)0x0B,(byte)0xFF,(byte)0x5C,(byte)0xB6,(byte)0xF4,(byte)0x06,(byte)0xB7,(byte)0xED, | ||
3401 | 49 | (byte)0xEE,(byte)0x38,(byte)0x6B,(byte)0xFB,(byte)0x5A,(byte)0x89,(byte)0x9F,(byte)0xA5, | ||
3402 | 50 | (byte)0xAE,(byte)0x9F,(byte)0x24,(byte)0x11,(byte)0x7C,(byte)0x4B,(byte)0x1F,(byte)0xE6, | ||
3403 | 51 | (byte)0x49,(byte)0x28,(byte)0x66,(byte)0x51,(byte)0xEC,(byte)0xE4,(byte)0x5B,(byte)0x3D, | ||
3404 | 52 | (byte)0xC2,(byte)0x00,(byte)0x7C,(byte)0xB8,(byte)0xA1,(byte)0x63,(byte)0xBF,(byte)0x05, | ||
3405 | 53 | (byte)0x98,(byte)0xDA,(byte)0x48,(byte)0x36,(byte)0x1C,(byte)0x55,(byte)0xD3,(byte)0x9A, | ||
3406 | 54 | (byte)0x69,(byte)0x16,(byte)0x3F,(byte)0xA8,(byte)0xFD,(byte)0x24,(byte)0xCF,(byte)0x5F, | ||
3407 | 55 | (byte)0x83,(byte)0x65,(byte)0x5D,(byte)0x23,(byte)0xDC,(byte)0xA3,(byte)0xAD,(byte)0x96, | ||
3408 | 56 | (byte)0x1C,(byte)0x62,(byte)0xF3,(byte)0x56,(byte)0x20,(byte)0x85,(byte)0x52,(byte)0xBB, | ||
3409 | 57 | (byte)0x9E,(byte)0xD5,(byte)0x29,(byte)0x07,(byte)0x70,(byte)0x96,(byte)0x96,(byte)0x6D, | ||
3410 | 58 | (byte)0x67,(byte)0x0C,(byte)0x35,(byte)0x4E,(byte)0x4A,(byte)0xBC,(byte)0x98,(byte)0x04, | ||
3411 | 59 | (byte)0xF1,(byte)0x74,(byte)0x6C,(byte)0x08,(byte)0xCA,(byte)0x18,(byte)0x21,(byte)0x7C, | ||
3412 | 60 | (byte)0x32,(byte)0x90,(byte)0x5E,(byte)0x46,(byte)0x2E,(byte)0x36,(byte)0xCE,(byte)0x3B, | ||
3413 | 61 | (byte)0xE3,(byte)0x9E,(byte)0x77,(byte)0x2C,(byte)0x18,(byte)0x0E,(byte)0x86,(byte)0x03, | ||
3414 | 62 | (byte)0x9B,(byte)0x27,(byte)0x83,(byte)0xA2,(byte)0xEC,(byte)0x07,(byte)0xA2,(byte)0x8F, | ||
3415 | 63 | (byte)0xB5,(byte)0xC5,(byte)0x5D,(byte)0xF0,(byte)0x6F,(byte)0x4C,(byte)0x52,(byte)0xC9, | ||
3416 | 64 | (byte)0xDE,(byte)0x2B,(byte)0xCB,(byte)0xF6,(byte)0x95,(byte)0x58,(byte)0x17,(byte)0x18, | ||
3417 | 65 | (byte)0x39,(byte)0x95,(byte)0x49,(byte)0x7C,(byte)0xEA,(byte)0x95,(byte)0x6A,(byte)0xE5, | ||
3418 | 66 | (byte)0x15,(byte)0xD2,(byte)0x26,(byte)0x18,(byte)0x98,(byte)0xFA,(byte)0x05,(byte)0x10, | ||
3419 | 67 | (byte)0x15,(byte)0x72,(byte)0x8E,(byte)0x5A,(byte)0x8A,(byte)0xAC,(byte)0xAA,(byte)0x68, | ||
3420 | 68 | (byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF | ||
3421 | 69 | }; | ||
3422 | 70 | |||
3423 | 71 | private static final int SSH_MSG_KEXDH_INIT= 30; | ||
3424 | 72 | private static final int SSH_MSG_KEXDH_REPLY= 31; | ||
3425 | 73 | |||
3426 | 74 | static final int RSA=0; | ||
3427 | 75 | static final int DSS=1; | ||
3428 | 76 | private int type=0; | ||
3429 | 77 | |||
3430 | 78 | private int state; | ||
3431 | 79 | |||
3432 | 80 | DH dh; | ||
3433 | 81 | |||
3434 | 82 | byte[] V_S; | ||
3435 | 83 | byte[] V_C; | ||
3436 | 84 | byte[] I_S; | ||
3437 | 85 | byte[] I_C; | ||
3438 | 86 | |||
3439 | 87 | byte[] e; | ||
3440 | 88 | |||
3441 | 89 | private Buffer buf; | ||
3442 | 90 | private Packet packet; | ||
3443 | 91 | |||
3444 | 92 | public void init(Session session, | ||
3445 | 93 | byte[] V_S, byte[] V_C, byte[] I_S, byte[] I_C) throws Exception{ | ||
3446 | 94 | this.session=session; | ||
3447 | 95 | this.V_S=V_S; | ||
3448 | 96 | this.V_C=V_C; | ||
3449 | 97 | this.I_S=I_S; | ||
3450 | 98 | this.I_C=I_C; | ||
3451 | 99 | |||
3452 | 100 | try{ | ||
3453 | 101 | Class c=Class.forName(session.getConfig("sha-1")); | ||
3454 | 102 | sha=(HASH)(c.newInstance()); | ||
3455 | 103 | sha.init(); | ||
3456 | 104 | } | ||
3457 | 105 | catch(Exception e){ | ||
3458 | 106 | System.err.println(e); | ||
3459 | 107 | } | ||
3460 | 108 | |||
3461 | 109 | buf=new Buffer(); | ||
3462 | 110 | packet=new Packet(buf); | ||
3463 | 111 | |||
3464 | 112 | try{ | ||
3465 | 113 | Class c=Class.forName(session.getConfig("dh")); | ||
3466 | 114 | dh=(DH)(c.newInstance()); | ||
3467 | 115 | dh.init(); | ||
3468 | 116 | } | ||
3469 | 117 | catch(Exception e){ | ||
3470 | 118 | //System.err.println(e); | ||
3471 | 119 | throw e; | ||
3472 | 120 | } | ||
3473 | 121 | |||
3474 | 122 | dh.setP(p); | ||
3475 | 123 | dh.setG(g); | ||
3476 | 124 | // The client responds with: | ||
3477 | 125 | // byte SSH_MSG_KEXDH_INIT(30) | ||
3478 | 126 | // mpint e <- g^x mod p | ||
3479 | 127 | // x is a random number (1 < x < (p-1)/2) | ||
3480 | 128 | |||
3481 | 129 | e=dh.getE(); | ||
3482 | 130 | packet.reset(); | ||
3483 | 131 | buf.putByte((byte)SSH_MSG_KEXDH_INIT); | ||
3484 | 132 | buf.putMPInt(e); | ||
3485 | 133 | |||
3486 | 134 | if(V_S==null){ // This is a really ugly hack for Session.checkKexes ;-( | ||
3487 | 135 | return; | ||
3488 | 136 | } | ||
3489 | 137 | |||
3490 | 138 | session.write(packet); | ||
3491 | 139 | |||
3492 | 140 | if(JSch.getLogger().isEnabled(Logger.INFO)){ | ||
3493 | 141 | JSch.getLogger().log(Logger.INFO, | ||
3494 | 142 | "SSH_MSG_KEXDH_INIT sent"); | ||
3495 | 143 | JSch.getLogger().log(Logger.INFO, | ||
3496 | 144 | "expecting SSH_MSG_KEXDH_REPLY"); | ||
3497 | 145 | } | ||
3498 | 146 | |||
3499 | 147 | state=SSH_MSG_KEXDH_REPLY; | ||
3500 | 148 | } | ||
3501 | 149 | |||
3502 | 150 | public boolean next(Buffer _buf) throws Exception{ | ||
3503 | 151 | int i,j; | ||
3504 | 152 | |||
3505 | 153 | switch(state){ | ||
3506 | 154 | case SSH_MSG_KEXDH_REPLY: | ||
3507 | 155 | // The server responds with: | ||
3508 | 156 | // byte SSH_MSG_KEXDH_REPLY(31) | ||
3509 | 157 | // string server public host key and certificates (K_S) | ||
3510 | 158 | // mpint f | ||
3511 | 159 | // string signature of H | ||
3512 | 160 | j=_buf.getInt(); | ||
3513 | 161 | j=_buf.getByte(); | ||
3514 | 162 | j=_buf.getByte(); | ||
3515 | 163 | if(j!=31){ | ||
3516 | 164 | System.err.println("type: must be 31 "+j); | ||
3517 | 165 | return false; | ||
3518 | 166 | } | ||
3519 | 167 | |||
3520 | 168 | K_S=_buf.getString(); | ||
3521 | 169 | // K_S is server_key_blob, which includes .... | ||
3522 | 170 | // string ssh-dss | ||
3523 | 171 | // impint p of dsa | ||
3524 | 172 | // impint q of dsa | ||
3525 | 173 | // impint g of dsa | ||
3526 | 174 | // impint pub_key of dsa | ||
3527 | 175 | //System.err.print("K_S: "); //dump(K_S, 0, K_S.length); | ||
3528 | 176 | byte[] f=_buf.getMPInt(); | ||
3529 | 177 | byte[] sig_of_H=_buf.getString(); | ||
3530 | 178 | |||
3531 | 179 | dh.setF(f); | ||
3532 | 180 | K=dh.getK(); | ||
3533 | 181 | |||
3534 | 182 | //The hash H is computed as the HASH hash of the concatenation of the | ||
3535 | 183 | //following: | ||
3536 | 184 | // string V_C, the client's version string (CR and NL excluded) | ||
3537 | 185 | // string V_S, the server's version string (CR and NL excluded) | ||
3538 | 186 | // string I_C, the payload of the client's SSH_MSG_KEXINIT | ||
3539 | 187 | // string I_S, the payload of the server's SSH_MSG_KEXINIT | ||
3540 | 188 | // string K_S, the host key | ||
3541 | 189 | // mpint e, exchange value sent by the client | ||
3542 | 190 | // mpint f, exchange value sent by the server | ||
3543 | 191 | // mpint K, the shared secret | ||
3544 | 192 | // This value is called the exchange hash, and it is used to authenti- | ||
3545 | 193 | // cate the key exchange. | ||
3546 | 194 | buf.reset(); | ||
3547 | 195 | buf.putString(V_C); buf.putString(V_S); | ||
3548 | 196 | buf.putString(I_C); buf.putString(I_S); | ||
3549 | 197 | buf.putString(K_S); | ||
3550 | 198 | buf.putMPInt(e); buf.putMPInt(f); | ||
3551 | 199 | buf.putMPInt(K); | ||
3552 | 200 | byte[] foo=new byte[buf.getLength()]; | ||
3553 | 201 | buf.getByte(foo); | ||
3554 | 202 | sha.update(foo, 0, foo.length); | ||
3555 | 203 | H=sha.digest(); | ||
3556 | 204 | //System.err.print("H -> "); //dump(H, 0, H.length); | ||
3557 | 205 | |||
3558 | 206 | i=0; | ||
3559 | 207 | j=0; | ||
3560 | 208 | j=((K_S[i++]<<24)&0xff000000)|((K_S[i++]<<16)&0x00ff0000)| | ||
3561 | 209 | ((K_S[i++]<<8)&0x0000ff00)|((K_S[i++])&0x000000ff); | ||
3562 | 210 | String alg=Util.byte2str(K_S, i, j); | ||
3563 | 211 | i+=j; | ||
3564 | 212 | |||
3565 | 213 | boolean result=false; | ||
3566 | 214 | |||
3567 | 215 | if(alg.equals("ssh-rsa")){ | ||
3568 | 216 | byte[] tmp; | ||
3569 | 217 | byte[] ee; | ||
3570 | 218 | byte[] n; | ||
3571 | 219 | |||
3572 | 220 | type=RSA; | ||
3573 | 221 | |||
3574 | 222 | j=((K_S[i++]<<24)&0xff000000)|((K_S[i++]<<16)&0x00ff0000)| | ||
3575 | 223 | ((K_S[i++]<<8)&0x0000ff00)|((K_S[i++])&0x000000ff); | ||
3576 | 224 | tmp=new byte[j]; System.arraycopy(K_S, i, tmp, 0, j); i+=j; | ||
3577 | 225 | ee=tmp; | ||
3578 | 226 | j=((K_S[i++]<<24)&0xff000000)|((K_S[i++]<<16)&0x00ff0000)| | ||
3579 | 227 | ((K_S[i++]<<8)&0x0000ff00)|((K_S[i++])&0x000000ff); | ||
3580 | 228 | tmp=new byte[j]; System.arraycopy(K_S, i, tmp, 0, j); i+=j; | ||
3581 | 229 | n=tmp; | ||
3582 | 230 | |||
3583 | 231 | SignatureRSA sig=null; | ||
3584 | 232 | try{ | ||
3585 | 233 | Class c=Class.forName(session.getConfig("signature.rsa")); | ||
3586 | 234 | sig=(SignatureRSA)(c.newInstance()); | ||
3587 | 235 | sig.init(); | ||
3588 | 236 | } | ||
3589 | 237 | catch(Exception e){ | ||
3590 | 238 | System.err.println(e); | ||
3591 | 239 | } | ||
3592 | 240 | |||
3593 | 241 | sig.setPubKey(ee, n); | ||
3594 | 242 | sig.update(H); | ||
3595 | 243 | result=sig.verify(sig_of_H); | ||
3596 | 244 | |||
3597 | 245 | if(JSch.getLogger().isEnabled(Logger.INFO)){ | ||
3598 | 246 | JSch.getLogger().log(Logger.INFO, | ||
3599 | 247 | "ssh_rsa_verify: signature "+result); | ||
3600 | 248 | } | ||
3601 | 249 | |||
3602 | 250 | } | ||
3603 | 251 | else if(alg.equals("ssh-dss")){ | ||
3604 | 252 | byte[] q=null; | ||
3605 | 253 | byte[] tmp; | ||
3606 | 254 | byte[] p; | ||
3607 | 255 | byte[] g; | ||
3608 | 256 | |||
3609 | 257 | type=DSS; | ||
3610 | 258 | |||
3611 | 259 | j=((K_S[i++]<<24)&0xff000000)|((K_S[i++]<<16)&0x00ff0000)| | ||
3612 | 260 | ((K_S[i++]<<8)&0x0000ff00)|((K_S[i++])&0x000000ff); | ||
3613 | 261 | tmp=new byte[j]; System.arraycopy(K_S, i, tmp, 0, j); i+=j; | ||
3614 | 262 | p=tmp; | ||
3615 | 263 | j=((K_S[i++]<<24)&0xff000000)|((K_S[i++]<<16)&0x00ff0000)| | ||
3616 | 264 | ((K_S[i++]<<8)&0x0000ff00)|((K_S[i++])&0x000000ff); | ||
3617 | 265 | tmp=new byte[j]; System.arraycopy(K_S, i, tmp, 0, j); i+=j; | ||
3618 | 266 | q=tmp; | ||
3619 | 267 | j=((K_S[i++]<<24)&0xff000000)|((K_S[i++]<<16)&0x00ff0000)| | ||
3620 | 268 | ((K_S[i++]<<8)&0x0000ff00)|((K_S[i++])&0x000000ff); | ||
3621 | 269 | tmp=new byte[j]; System.arraycopy(K_S, i, tmp, 0, j); i+=j; | ||
3622 | 270 | g=tmp; | ||
3623 | 271 | j=((K_S[i++]<<24)&0xff000000)|((K_S[i++]<<16)&0x00ff0000)| | ||
3624 | 272 | ((K_S[i++]<<8)&0x0000ff00)|((K_S[i++])&0x000000ff); | ||
3625 | 273 | tmp=new byte[j]; System.arraycopy(K_S, i, tmp, 0, j); i+=j; | ||
3626 | 274 | f=tmp; | ||
3627 | 275 | |||
3628 | 276 | SignatureDSA sig=null; | ||
3629 | 277 | try{ | ||
3630 | 278 | Class c=Class.forName(session.getConfig("signature.dss")); | ||
3631 | 279 | sig=(SignatureDSA)(c.newInstance()); | ||
3632 | 280 | sig.init(); | ||
3633 | 281 | } | ||
3634 | 282 | catch(Exception e){ | ||
3635 | 283 | System.err.println(e); | ||
3636 | 284 | } | ||
3637 | 285 | sig.setPubKey(f, p, q, g); | ||
3638 | 286 | sig.update(H); | ||
3639 | 287 | result=sig.verify(sig_of_H); | ||
3640 | 288 | |||
3641 | 289 | if(JSch.getLogger().isEnabled(Logger.INFO)){ | ||
3642 | 290 | JSch.getLogger().log(Logger.INFO, | ||
3643 | 291 | "ssh_dss_verify: signature "+result); | ||
3644 | 292 | } | ||
3645 | 293 | |||
3646 | 294 | } | ||
3647 | 295 | else{ | ||
3648 | 296 | System.err.println("unknown alg"); | ||
3649 | 297 | } | ||
3650 | 298 | state=STATE_END; | ||
3651 | 299 | return result; | ||
3652 | 300 | } | ||
3653 | 301 | return false; | ||
3654 | 302 | } | ||
3655 | 303 | |||
3656 | 304 | public String getKeyType(){ | ||
3657 | 305 | if(type==DSS) return "DSA"; | ||
3658 | 306 | return "RSA"; | ||
3659 | 307 | } | ||
3660 | 308 | |||
3661 | 309 | public int getState(){return state; } | ||
3662 | 310 | } | ||
3663 | 0 | 311 | ||
3664 | === modified file 'src/main/java/com/jcraft/jsch/DHGEX.java' | |||
3665 | --- src/com/jcraft/jsch/DHGEX.java 2010-06-27 23:17:34 +0000 | |||
3666 | +++ src/main/java/com/jcraft/jsch/DHGEX.java 2012-05-04 10:23:17 +0000 | |||
3667 | @@ -1,6 +1,6 @@ | |||
3668 | 1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ | 1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ |
3669 | 2 | /* | 2 | /* |
3671 | 3 | Copyright (c) 2002-2009 ymnk, JCraft,Inc. All rights reserved. | 3 | Copyright (c) 2002-2012 ymnk, JCraft,Inc. All rights reserved. |
3672 | 4 | 4 | ||
3673 | 5 | Redistribution and use in source and binary forms, with or without | 5 | Redistribution and use in source and binary forms, with or without |
3674 | 6 | modification, are permitted provided that the following conditions are met: | 6 | modification, are permitted provided that the following conditions are met: |
3675 | @@ -233,7 +233,7 @@ | |||
3676 | 233 | j=0; | 233 | j=0; |
3677 | 234 | j=((K_S[i++]<<24)&0xff000000)|((K_S[i++]<<16)&0x00ff0000)| | 234 | j=((K_S[i++]<<24)&0xff000000)|((K_S[i++]<<16)&0x00ff0000)| |
3678 | 235 | ((K_S[i++]<<8)&0x0000ff00)|((K_S[i++])&0x000000ff); | 235 | ((K_S[i++]<<8)&0x0000ff00)|((K_S[i++])&0x000000ff); |
3680 | 236 | String alg=new String(K_S, i, j); | 236 | String alg=Util.byte2str(K_S, i, j); |
3681 | 237 | i+=j; | 237 | i+=j; |
3682 | 238 | 238 | ||
3683 | 239 | boolean result=false; | 239 | boolean result=false; |
3684 | 240 | 240 | ||
3685 | === modified file 'src/main/java/com/jcraft/jsch/ForwardedTCPIPDaemon.java' | |||
3686 | --- src/com/jcraft/jsch/ForwardedTCPIPDaemon.java 2010-06-27 23:17:34 +0000 | |||
3687 | +++ src/main/java/com/jcraft/jsch/ForwardedTCPIPDaemon.java 2012-05-04 10:23:17 +0000 | |||
3688 | @@ -1,6 +1,6 @@ | |||
3689 | 1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ | 1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ |
3690 | 2 | /* | 2 | /* |
3692 | 3 | Copyright (c) 2002-2009 ymnk, JCraft,Inc. All rights reserved. | 3 | Copyright (c) 2002-2012 ymnk, JCraft,Inc. All rights reserved. |
3693 | 4 | 4 | ||
3694 | 5 | Redistribution and use in source and binary forms, with or without | 5 | Redistribution and use in source and binary forms, with or without |
3695 | 6 | modification, are permitted provided that the following conditions are met: | 6 | modification, are permitted provided that the following conditions are met: |
3696 | 7 | 7 | ||
3697 | === modified file 'src/main/java/com/jcraft/jsch/GSSContext.java' | |||
3698 | --- src/com/jcraft/jsch/GSSContext.java 2010-06-27 23:17:34 +0000 | |||
3699 | +++ src/main/java/com/jcraft/jsch/GSSContext.java 2012-05-04 10:23:17 +0000 | |||
3700 | @@ -1,6 +1,6 @@ | |||
3701 | 1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ | 1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ |
3702 | 2 | /* | 2 | /* |
3704 | 3 | Copyright (c) 2004-2009 ymnk, JCraft,Inc. All rights reserved. | 3 | Copyright (c) 2004-2012 ymnk, JCraft,Inc. All rights reserved. |
3705 | 4 | 4 | ||
3706 | 5 | Redistribution and use in source and binary forms, with or without | 5 | Redistribution and use in source and binary forms, with or without |
3707 | 6 | modification, are permitted provided that the following conditions are met: | 6 | modification, are permitted provided that the following conditions are met: |
3708 | 7 | 7 | ||
3709 | === modified file 'src/main/java/com/jcraft/jsch/HASH.java' | |||
3710 | --- src/com/jcraft/jsch/HASH.java 2010-06-27 23:17:34 +0000 | |||
3711 | +++ src/main/java/com/jcraft/jsch/HASH.java 2012-05-04 10:23:17 +0000 | |||
3712 | @@ -1,6 +1,6 @@ | |||
3713 | 1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ | 1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ |
3714 | 2 | /* | 2 | /* |
3716 | 3 | Copyright (c) 2002-2009 ymnk, JCraft,Inc. All rights reserved. | 3 | Copyright (c) 2002-2012 ymnk, JCraft,Inc. All rights reserved. |
3717 | 4 | 4 | ||
3718 | 5 | Redistribution and use in source and binary forms, with or without | 5 | Redistribution and use in source and binary forms, with or without |
3719 | 6 | modification, are permitted provided that the following conditions are met: | 6 | modification, are permitted provided that the following conditions are met: |
3720 | 7 | 7 | ||
3721 | === modified file 'src/main/java/com/jcraft/jsch/HostKey.java' | |||
3722 | --- src/com/jcraft/jsch/HostKey.java 2010-06-27 23:17:34 +0000 | |||
3723 | +++ src/main/java/com/jcraft/jsch/HostKey.java 2012-05-04 10:23:17 +0000 | |||
3724 | @@ -1,6 +1,6 @@ | |||
3725 | 1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ | 1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ |
3726 | 2 | /* | 2 | /* |
3728 | 3 | Copyright (c) 2002-2009 ymnk, JCraft,Inc. All rights reserved. | 3 | Copyright (c) 2002-2012 ymnk, JCraft,Inc. All rights reserved. |
3729 | 4 | 4 | ||
3730 | 5 | Redistribution and use in source and binary forms, with or without | 5 | Redistribution and use in source and binary forms, with or without |
3731 | 6 | modification, are permitted provided that the following conditions are met: | 6 | modification, are permitted provided that the following conditions are met: |
3732 | @@ -30,8 +30,8 @@ | |||
3733 | 30 | package com.jcraft.jsch; | 30 | package com.jcraft.jsch; |
3734 | 31 | 31 | ||
3735 | 32 | public class HostKey{ | 32 | public class HostKey{ |
3738 | 33 | private static final byte[] sshdss="ssh-dss".getBytes(); | 33 | private static final byte[] sshdss=Util.str2byte("ssh-dss"); |
3739 | 34 | private static final byte[] sshrsa="ssh-rsa".getBytes(); | 34 | private static final byte[] sshrsa=Util.str2byte("ssh-rsa"); |
3740 | 35 | 35 | ||
3741 | 36 | protected static final int GUESS=0; | 36 | protected static final int GUESS=0; |
3742 | 37 | public static final int SSHDSS=1; | 37 | public static final int SSHDSS=1; |
3743 | @@ -61,12 +61,12 @@ | |||
3744 | 61 | 61 | ||
3745 | 62 | public String getHost(){ return host; } | 62 | public String getHost(){ return host; } |
3746 | 63 | public String getType(){ | 63 | public String getType(){ |
3749 | 64 | if(type==SSHDSS){ return new String(sshdss); } | 64 | if(type==SSHDSS){ return Util.byte2str(sshdss); } |
3750 | 65 | if(type==SSHRSA){ return new String(sshrsa);} | 65 | if(type==SSHRSA){ return Util.byte2str(sshrsa);} |
3751 | 66 | return "UNKNOWN"; | 66 | return "UNKNOWN"; |
3752 | 67 | } | 67 | } |
3753 | 68 | public String getKey(){ | 68 | public String getKey(){ |
3755 | 69 | return new String(Util.toBase64(key, 0, key.length)); | 69 | return Util.byte2str(Util.toBase64(key, 0, key.length)); |
3756 | 70 | } | 70 | } |
3757 | 71 | public String getFingerPrint(JSch jsch){ | 71 | public String getFingerPrint(JSch jsch){ |
3758 | 72 | HASH hash=null; | 72 | HASH hash=null; |
3759 | 73 | 73 | ||
3760 | === modified file 'src/main/java/com/jcraft/jsch/HostKeyRepository.java' | |||
3761 | --- src/com/jcraft/jsch/HostKeyRepository.java 2010-06-27 23:17:34 +0000 | |||
3762 | +++ src/main/java/com/jcraft/jsch/HostKeyRepository.java 2012-05-04 10:23:17 +0000 | |||
3763 | @@ -1,6 +1,6 @@ | |||
3764 | 1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ | 1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ |
3765 | 2 | /* | 2 | /* |
3767 | 3 | Copyright (c) 2004-2009 ymnk, JCraft,Inc. All rights reserved. | 3 | Copyright (c) 2004-2012 ymnk, JCraft,Inc. All rights reserved. |
3768 | 4 | 4 | ||
3769 | 5 | Redistribution and use in source and binary forms, with or without | 5 | Redistribution and use in source and binary forms, with or without |
3770 | 6 | modification, are permitted provided that the following conditions are met: | 6 | modification, are permitted provided that the following conditions are met: |
3771 | 7 | 7 | ||
3772 | === modified file 'src/main/java/com/jcraft/jsch/IO.java' | |||
3773 | --- src/com/jcraft/jsch/IO.java 2010-06-27 23:17:34 +0000 | |||
3774 | +++ src/main/java/com/jcraft/jsch/IO.java 2012-05-04 10:23:17 +0000 | |||
3775 | @@ -1,6 +1,6 @@ | |||
3776 | 1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ | 1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ |
3777 | 2 | /* | 2 | /* |
3779 | 3 | Copyright (c) 2002-2009 ymnk, JCraft,Inc. All rights reserved. | 3 | Copyright (c) 2002-2012 ymnk, JCraft,Inc. All rights reserved. |
3780 | 4 | 4 | ||
3781 | 5 | Redistribution and use in source and binary forms, with or without | 5 | Redistribution and use in source and binary forms, with or without |
3782 | 6 | modification, are permitted provided that the following conditions are met: | 6 | modification, are permitted provided that the following conditions are met: |
3783 | 7 | 7 | ||
3784 | === modified file 'src/main/java/com/jcraft/jsch/Identity.java' | |||
3785 | --- src/com/jcraft/jsch/Identity.java 2010-06-27 23:17:34 +0000 | |||
3786 | +++ src/main/java/com/jcraft/jsch/Identity.java 2012-05-04 10:23:17 +0000 | |||
3787 | @@ -1,6 +1,6 @@ | |||
3788 | 1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ | 1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ |
3789 | 2 | /* | 2 | /* |
3791 | 3 | Copyright (c) 2002-2009 ymnk, JCraft,Inc. All rights reserved. | 3 | Copyright (c) 2002-2012 ymnk, JCraft,Inc. All rights reserved. |
3792 | 4 | 4 | ||
3793 | 5 | Redistribution and use in source and binary forms, with or without | 5 | Redistribution and use in source and binary forms, with or without |
3794 | 6 | modification, are permitted provided that the following conditions are met: | 6 | modification, are permitted provided that the following conditions are met: |
3795 | 7 | 7 | ||
3796 | === modified file 'src/main/java/com/jcraft/jsch/IdentityFile.java' | |||
3797 | --- src/com/jcraft/jsch/IdentityFile.java 2010-06-27 23:17:34 +0000 | |||
3798 | +++ src/main/java/com/jcraft/jsch/IdentityFile.java 2012-05-04 10:23:17 +0000 | |||
3799 | @@ -1,6 +1,6 @@ | |||
3800 | 1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ | 1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ |
3801 | 2 | /* | 2 | /* |
3803 | 3 | Copyright (c) 2002-2009 ymnk, JCraft,Inc. All rights reserved. | 3 | Copyright (c) 2002-2012 ymnk, JCraft,Inc. All rights reserved. |
3804 | 4 | 4 | ||
3805 | 5 | Redistribution and use in source and binary forms, with or without | 5 | Redistribution and use in source and binary forms, with or without |
3806 | 6 | modification, are permitted provided that the following conditions are met: | 6 | modification, are permitted provided that the following conditions are met: |
3807 | @@ -142,6 +142,47 @@ | |||
3808 | 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{ |
3809 | 143 | this.identity=name; | 143 | this.identity=name; |
3810 | 144 | this.jsch=jsch; | 144 | this.jsch=jsch; |
3811 | 145 | |||
3812 | 146 | // prvkey from "ssh-add" command on the remote. | ||
3813 | 147 | if(pubkey==null && | ||
3814 | 148 | prvkey!=null && | ||
3815 | 149 | (prvkey.length>11 && | ||
3816 | 150 | prvkey[0]==0 && prvkey[1]==0 && prvkey[2]==0 && prvkey[3]==7)){ | ||
3817 | 151 | |||
3818 | 152 | Buffer buf=new Buffer(prvkey); | ||
3819 | 153 | String _type = new String(buf.getString()); // ssh-rsa | ||
3820 | 154 | |||
3821 | 155 | if(_type.equals("ssh-rsa")){ | ||
3822 | 156 | type=RSA; | ||
3823 | 157 | n_array=buf.getString(); | ||
3824 | 158 | e_array=buf.getString(); | ||
3825 | 159 | d_array=buf.getString(); | ||
3826 | 160 | buf.getString(); | ||
3827 | 161 | buf.getString(); | ||
3828 | 162 | buf.getString(); | ||
3829 | 163 | this.identity += new String(buf.getString()); | ||
3830 | 164 | } | ||
3831 | 165 | else if(_type.equals("ssh-dss")){ | ||
3832 | 166 | type=DSS; | ||
3833 | 167 | P_array=buf.getString(); | ||
3834 | 168 | Q_array=buf.getString(); | ||
3835 | 169 | G_array=buf.getString(); | ||
3836 | 170 | pub_array=buf.getString(); | ||
3837 | 171 | prv_array=buf.getString(); | ||
3838 | 172 | this.identity += new String(buf.getString()); | ||
3839 | 173 | } | ||
3840 | 174 | else{ | ||
3841 | 175 | throw new JSchException("privatekey: invalid key "+new String(prvkey, 4, 7)); | ||
3842 | 176 | } | ||
3843 | 177 | encoded_data=prvkey; | ||
3844 | 178 | encrypted=false; | ||
3845 | 179 | keytype=OPENSSH; | ||
3846 | 180 | return; | ||
3847 | 181 | } | ||
3848 | 182 | |||
3849 | 183 | /* TODO: IdentityFile should use KeyPair. | ||
3850 | 184 | * The following logic exists also in KeyPair. It is redundant. | ||
3851 | 185 | */ | ||
3852 | 145 | try{ | 186 | try{ |
3853 | 146 | Class c; | 187 | Class c; |
3854 | 147 | c=Class.forName((String)jsch.getConfig("3des-cbc")); | 188 | c=Class.forName((String)jsch.getConfig("3des-cbc")); |
3855 | @@ -156,8 +197,18 @@ | |||
3856 | 156 | int len=buf.length; | 197 | int len=buf.length; |
3857 | 157 | 198 | ||
3858 | 158 | int i=0; | 199 | int i=0; |
3861 | 159 | while(i<len){ | 200 | |
3862 | 160 | if(buf[i]=='B'&& buf[i+1]=='E'&& buf[i+2]=='G'&& buf[i+3]=='I'){ | 201 | while(i<len){ |
3863 | 202 | if(buf[i] == '-' && i+4<len && | ||
3864 | 203 | buf[i+1] == '-' && buf[i+2] == '-' && | ||
3865 | 204 | buf[i+3] == '-' && buf[i+4] == '-'){ | ||
3866 | 205 | break; | ||
3867 | 206 | } | ||
3868 | 207 | i++; | ||
3869 | 208 | } | ||
3870 | 209 | |||
3871 | 210 | while(i<len){ | ||
3872 | 211 | if(buf[i]=='B'&& i+3<len && buf[i+1]=='E'&& buf[i+2]=='G'&& buf[i+3]=='I'){ | ||
3873 | 161 | i+=6; | 212 | i+=6; |
3874 | 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; } |
3875 | 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; } |
3876 | @@ -172,7 +223,7 @@ | |||
3877 | 172 | i+=3; | 223 | i+=3; |
3878 | 173 | continue; | 224 | continue; |
3879 | 174 | } | 225 | } |
3881 | 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]=='-' && |
3882 | 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]=='-'){ |
3883 | 177 | i+=8; | 228 | i+=8; |
3884 | 178 | if(Session.checkCipher((String)jsch.getConfig("aes256-cbc"))){ | 229 | if(Session.checkCipher((String)jsch.getConfig("aes256-cbc"))){ |
3885 | @@ -186,7 +237,35 @@ | |||
3886 | 186 | } | 237 | } |
3887 | 187 | continue; | 238 | continue; |
3888 | 188 | } | 239 | } |
3890 | 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]=='-' && |
3891 | 241 | buf[i+4]=='1'&& buf[i+5]=='9'&& buf[i+6]=='2'&& buf[i+7]=='-'){ | ||
3892 | 242 | i+=8; | ||
3893 | 243 | if(Session.checkCipher((String)jsch.getConfig("aes192-cbc"))){ | ||
3894 | 244 | c=Class.forName((String)jsch.getConfig("aes192-cbc")); | ||
3895 | 245 | cipher=(Cipher)(c.newInstance()); | ||
3896 | 246 | key=new byte[cipher.getBlockSize()]; | ||
3897 | 247 | iv=new byte[cipher.getIVSize()]; | ||
3898 | 248 | } | ||
3899 | 249 | else{ | ||
3900 | 250 | throw new JSchException("privatekey: aes192-cbc is not available "+identity); | ||
3901 | 251 | } | ||
3902 | 252 | continue; | ||
3903 | 253 | } | ||
3904 | 254 | if(buf[i]=='A'&& i+7<len && buf[i+1]=='E'&& buf[i+2]=='S'&& buf[i+3]=='-' && | ||
3905 | 255 | buf[i+4]=='1'&& buf[i+5]=='2'&& buf[i+6]=='8'&& buf[i+7]=='-'){ | ||
3906 | 256 | i+=8; | ||
3907 | 257 | if(Session.checkCipher((String)jsch.getConfig("aes128-cbc"))){ | ||
3908 | 258 | c=Class.forName((String)jsch.getConfig("aes128-cbc")); | ||
3909 | 259 | cipher=(Cipher)(c.newInstance()); | ||
3910 | 260 | key=new byte[cipher.getBlockSize()]; | ||
3911 | 261 | iv=new byte[cipher.getIVSize()]; | ||
3912 | 262 | } | ||
3913 | 263 | else{ | ||
3914 | 264 | throw new JSchException("privatekey: aes128-cbc is not available "+identity); | ||
3915 | 265 | } | ||
3916 | 266 | continue; | ||
3917 | 267 | } | ||
3918 | 268 | if(buf[i]=='C'&& i+3<len && buf[i+1]=='B'&& buf[i+2]=='C'&& buf[i+3]==','){ | ||
3919 | 190 | i+=4; | 269 | i+=4; |
3920 | 191 | for(int ii=0; ii<iv.length; ii++){ | 270 | for(int ii=0; ii<iv.length; ii++){ |
3921 | 192 | iv[ii]=(byte)(((a2b(buf[i++])<<4)&0xf0)+ | 271 | iv[ii]=(byte)(((a2b(buf[i++])<<4)&0xf0)+ |
3922 | @@ -194,19 +273,18 @@ | |||
3923 | 194 | } | 273 | } |
3924 | 195 | continue; | 274 | continue; |
3925 | 196 | } | 275 | } |
3928 | 197 | if(buf[i]==0x0d && | 276 | if(buf[i]==0x0d && i+1<len && buf[i+1]==0x0a){ |
3927 | 198 | i+1<buf.length && buf[i+1]==0x0a){ | ||
3929 | 199 | i++; | 277 | i++; |
3930 | 200 | continue; | 278 | continue; |
3931 | 201 | } | 279 | } |
3933 | 202 | if(buf[i]==0x0a && i+1<buf.length){ | 280 | if(buf[i]==0x0a && i+1<len){ |
3934 | 203 | if(buf[i+1]==0x0a){ i+=2; break; } | 281 | if(buf[i+1]==0x0a){ i+=2; break; } |
3935 | 204 | if(buf[i+1]==0x0d && | 282 | if(buf[i+1]==0x0d && |
3937 | 205 | i+2<buf.length && buf[i+2]==0x0a){ | 283 | i+2<len && buf[i+2]==0x0a){ |
3938 | 206 | i+=3; break; | 284 | i+=3; break; |
3939 | 207 | } | 285 | } |
3940 | 208 | boolean inheader=false; | 286 | boolean inheader=false; |
3942 | 209 | for(int j=i+1; j<buf.length; j++){ | 287 | for(int j=i+1; j<len; j++){ |
3943 | 210 | if(buf[j]==0x0a) break; | 288 | if(buf[j]==0x0a) break; |
3944 | 211 | //if(buf[j]==0x0d) break; | 289 | //if(buf[j]==0x0d) break; |
3945 | 212 | if(buf[j]==':'){inheader=true; break;} | 290 | if(buf[j]==':'){inheader=true; break;} |
3946 | @@ -254,7 +332,7 @@ | |||
3947 | 254 | byte[]_type=_buf.getString(); | 332 | byte[]_type=_buf.getString(); |
3948 | 255 | //System.err.println("type: "+new String(_type)); | 333 | //System.err.println("type: "+new String(_type)); |
3949 | 256 | byte[] _cipher=_buf.getString(); | 334 | byte[] _cipher=_buf.getString(); |
3951 | 257 | String cipher=new String(_cipher); | 335 | String cipher=Util.byte2str(_cipher); |
3952 | 258 | //System.err.println("cipher: "+cipher); | 336 | //System.err.println("cipher: "+cipher); |
3953 | 259 | if(cipher.equals("3des-cbc")){ | 337 | if(cipher.equals("3des-cbc")){ |
3954 | 260 | _buf.getInt(); | 338 | _buf.getInt(); |
3955 | @@ -421,7 +499,7 @@ | |||
3956 | 421 | Buffer buf=new Buffer("ssh-rsa".length()+4+ | 499 | Buffer buf=new Buffer("ssh-rsa".length()+4+ |
3957 | 422 | e_array.length+4+ | 500 | e_array.length+4+ |
3958 | 423 | n_array.length+4); | 501 | n_array.length+4); |
3960 | 424 | buf.putString("ssh-rsa".getBytes()); | 502 | buf.putString(Util.str2byte("ssh-rsa")); |
3961 | 425 | buf.putString(e_array); | 503 | buf.putString(e_array); |
3962 | 426 | buf.putString(n_array); | 504 | buf.putString(n_array); |
3963 | 427 | return buf.buffer; | 505 | return buf.buffer; |
3964 | @@ -434,7 +512,7 @@ | |||
3965 | 434 | Q_array.length+4+ | 512 | Q_array.length+4+ |
3966 | 435 | G_array.length+4+ | 513 | G_array.length+4+ |
3967 | 436 | pub_array.length+4); | 514 | pub_array.length+4); |
3969 | 437 | buf.putString("ssh-dss".getBytes()); | 515 | buf.putString(Util.str2byte("ssh-dss")); |
3970 | 438 | buf.putString(P_array); | 516 | buf.putString(P_array); |
3971 | 439 | buf.putString(Q_array); | 517 | buf.putString(Q_array); |
3972 | 440 | buf.putString(G_array); | 518 | buf.putString(G_array); |
3973 | @@ -459,7 +537,7 @@ | |||
3974 | 459 | byte[] sig = rsa.sign(); | 537 | byte[] sig = rsa.sign(); |
3975 | 460 | Buffer buf=new Buffer("ssh-rsa".length()+4+ | 538 | Buffer buf=new Buffer("ssh-rsa".length()+4+ |
3976 | 461 | sig.length+4); | 539 | sig.length+4); |
3978 | 462 | buf.putString("ssh-rsa".getBytes()); | 540 | buf.putString(Util.str2byte("ssh-rsa")); |
3979 | 463 | buf.putString(sig); | 541 | buf.putString(sig); |
3980 | 464 | return buf.buffer; | 542 | return buf.buffer; |
3981 | 465 | } | 543 | } |
3982 | @@ -502,7 +580,7 @@ | |||
3983 | 502 | byte[] sig = dsa.sign(); | 580 | byte[] sig = dsa.sign(); |
3984 | 503 | Buffer buf=new Buffer("ssh-dss".length()+4+ | 581 | Buffer buf=new Buffer("ssh-dss".length()+4+ |
3985 | 504 | sig.length+4); | 582 | sig.length+4); |
3987 | 505 | buf.putString("ssh-dss".getBytes()); | 583 | buf.putString(Util.str2byte("ssh-dss")); |
3988 | 506 | buf.putString(sig); | 584 | buf.putString(sig); |
3989 | 507 | return buf.buffer; | 585 | return buf.buffer; |
3990 | 508 | } | 586 | } |
3991 | 509 | 587 | ||
3992 | === added file 'src/main/java/com/jcraft/jsch/IdentityRepository.java' | |||
3993 | --- src/main/java/com/jcraft/jsch/IdentityRepository.java 1970-01-01 00:00:00 +0000 | |||
3994 | +++ src/main/java/com/jcraft/jsch/IdentityRepository.java 2012-05-04 10:23:17 +0000 | |||
3995 | @@ -0,0 +1,44 @@ | |||
3996 | 1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ | ||
3997 | 2 | /* | ||
3998 | 3 | Copyright (c) 2012 ymnk, JCraft,Inc. All rights reserved. | ||
3999 | 4 | |||
4000 | 5 | Redistribution and use in source and binary forms, with or without | ||
4001 | 6 | modification, are permitted provided that the following conditions are met: | ||
4002 | 7 | |||
4003 | 8 | 1. Redistributions of source code must retain the above copyright notice, | ||
4004 | 9 | this list of conditions and the following disclaimer. | ||
4005 | 10 | |||
4006 | 11 | 2. Redistributions in binary form must reproduce the above copyright | ||
4007 | 12 | notice, this list of conditions and the following disclaimer in | ||
4008 | 13 | the documentation and/or other materials provided with the distribution. | ||
4009 | 14 | |||
4010 | 15 | 3. The names of the authors may not be used to endorse or promote products | ||
4011 | 16 | derived from this software without specific prior written permission. | ||
4012 | 17 | |||
4013 | 18 | THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, | ||
4014 | 19 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND | ||
4015 | 20 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT, | ||
4016 | 21 | INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
4017 | 22 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
4018 | 23 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, | ||
4019 | 24 | OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | ||
4020 | 25 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | ||
4021 | 26 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, | ||
4022 | 27 | EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
4023 | 28 | */ | ||
4024 | 29 | |||
4025 | 30 | package com.jcraft.jsch; | ||
4026 | 31 | |||
4027 | 32 | import java.util.Vector; | ||
4028 | 33 | |||
4029 | 34 | public interface IdentityRepository { | ||
4030 | 35 | public static final int UNAVAILABLE=0; | ||
4031 | 36 | public static final int NOTRUNNING=1; | ||
4032 | 37 | public static final int RUNNING=2; | ||
4033 | 38 | public String getName(); | ||
4034 | 39 | public int getStatus(); | ||
4035 | 40 | public Vector getIdentities(); | ||
4036 | 41 | public boolean add(byte[] identity); | ||
4037 | 42 | public boolean remove(byte[] blob); | ||
4038 | 43 | public void removeAll(); | ||
4039 | 44 | } | ||
4040 | 0 | 45 | ||
4041 | === modified file 'src/main/java/com/jcraft/jsch/JSch.java' | |||
4042 | --- src/com/jcraft/jsch/JSch.java 2010-06-27 23:17:34 +0000 | |||
4043 | +++ src/main/java/com/jcraft/jsch/JSch.java 2012-05-04 10:23:17 +0000 | |||
4044 | @@ -1,6 +1,6 @@ | |||
4045 | 1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ | 1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ |
4046 | 2 | /* | 2 | /* |
4048 | 3 | Copyright (c) 2002-2009 ymnk, JCraft,Inc. All rights reserved. | 3 | Copyright (c) 2002-2012 ymnk, JCraft,Inc. All rights reserved. |
4049 | 4 | 4 | ||
4050 | 5 | Redistribution and use in source and binary forms, with or without | 5 | Redistribution and use in source and binary forms, with or without |
4051 | 6 | modification, are permitted provided that the following conditions are met: | 6 | modification, are permitted provided that the following conditions are met: |
4052 | @@ -33,12 +33,15 @@ | |||
4053 | 33 | import java.util.Vector; | 33 | import java.util.Vector; |
4054 | 34 | 34 | ||
4055 | 35 | public class JSch{ | 35 | public class JSch{ |
4056 | 36 | /** | ||
4057 | 37 | * The version number. | ||
4058 | 38 | */ | ||
4059 | 39 | public static final String VERSION = "0.1.48"; | ||
4060 | 40 | |||
4061 | 36 | static java.util.Hashtable config=new java.util.Hashtable(); | 41 | static java.util.Hashtable config=new java.util.Hashtable(); |
4062 | 37 | static{ | 42 | static{ |
4065 | 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"); |
4064 | 39 | config.put("kex", "diffie-hellman-group1-sha1,diffie-hellman-group-exchange-sha1"); | ||
4066 | 40 | config.put("server_host_key", "ssh-rsa,ssh-dss"); | 44 | config.put("server_host_key", "ssh-rsa,ssh-dss"); |
4067 | 41 | // config.put("server_host_key", "ssh-dss,ssh-rsa"); | ||
4068 | 42 | 45 | ||
4069 | 43 | config.put("cipher.s2c", | 46 | config.put("cipher.s2c", |
4070 | 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"); |
4071 | @@ -48,9 +51,7 @@ | |||
4072 | 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"); |
4073 | 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"); |
4074 | 50 | config.put("compression.s2c", "none"); | 53 | config.put("compression.s2c", "none"); |
4075 | 51 | // config.put("compression.s2c", "zlib@openssh.com,zlib,none"); | ||
4076 | 52 | config.put("compression.c2s", "none"); | 54 | config.put("compression.c2s", "none"); |
4077 | 53 | // config.put("compression.c2s", "zlib@openssh.com,zlib,none"); | ||
4078 | 54 | 55 | ||
4079 | 55 | config.put("lang.s2c", ""); | 56 | config.put("lang.s2c", ""); |
4080 | 56 | config.put("lang.c2s", ""); | 57 | config.put("lang.c2s", ""); |
4081 | @@ -61,6 +62,8 @@ | |||
4082 | 61 | "com.jcraft.jsch.DHGEX"); | 62 | "com.jcraft.jsch.DHGEX"); |
4083 | 62 | config.put("diffie-hellman-group1-sha1", | 63 | config.put("diffie-hellman-group1-sha1", |
4084 | 63 | "com.jcraft.jsch.DHG1"); | 64 | "com.jcraft.jsch.DHG1"); |
4085 | 65 | config.put("diffie-hellman-group14-sha1", | ||
4086 | 66 | "com.jcraft.jsch.DHG14"); | ||
4087 | 64 | 67 | ||
4088 | 65 | config.put("dh", "com.jcraft.jsch.jce.DH"); | 68 | config.put("dh", "com.jcraft.jsch.jce.DH"); |
4089 | 66 | config.put("3des-cbc", "com.jcraft.jsch.jce.TripleDESCBC"); | 69 | config.put("3des-cbc", "com.jcraft.jsch.jce.TripleDESCBC"); |
4090 | @@ -103,13 +106,44 @@ | |||
4091 | 103 | 106 | ||
4092 | 104 | config.put("StrictHostKeyChecking", "ask"); | 107 | config.put("StrictHostKeyChecking", "ask"); |
4093 | 105 | config.put("HashKnownHosts", "no"); | 108 | config.put("HashKnownHosts", "no"); |
4095 | 106 | //config.put("HashKnownHosts", "yes"); | 109 | |
4096 | 107 | config.put("PreferredAuthentications", "gssapi-with-mic,publickey,keyboard-interactive,password"); | 110 | config.put("PreferredAuthentications", "gssapi-with-mic,publickey,keyboard-interactive,password"); |
4097 | 108 | 111 | ||
4098 | 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"); |
4102 | 110 | } | 113 | config.put("CheckKexes", "diffie-hellman-group14-sha1"); |
4103 | 111 | java.util.Vector pool=new java.util.Vector(); | 114 | |
4104 | 112 | java.util.Vector identities=new java.util.Vector(); | 115 | config.put("MaxAuthTries", "6"); |
4105 | 116 | } | ||
4106 | 117 | |||
4107 | 118 | private java.util.Vector sessionPool = new java.util.Vector(); | ||
4108 | 119 | |||
4109 | 120 | private IdentityRepository defaultIdentityRepository = | ||
4110 | 121 | new LocalIdentityRepository(this); | ||
4111 | 122 | |||
4112 | 123 | private IdentityRepository identityRepository = defaultIdentityRepository; | ||
4113 | 124 | |||
4114 | 125 | /** | ||
4115 | 126 | * Sets the <code>identityRepository</code>, which will be referred | ||
4116 | 127 | * in the public key authentication. | ||
4117 | 128 | * | ||
4118 | 129 | * @param identityRepository if <code>null</code> is given, | ||
4119 | 130 | * the default repository, which usually refers to ~/.ssh/, will be used. | ||
4120 | 131 | * | ||
4121 | 132 | * @see #getIdentityRepository() | ||
4122 | 133 | */ | ||
4123 | 134 | public synchronized void setIdentityRepository(IdentityRepository identityRepository){ | ||
4124 | 135 | if(identityRepository == null){ | ||
4125 | 136 | this.identityRepository = defaultIdentityRepository; | ||
4126 | 137 | } | ||
4127 | 138 | else{ | ||
4128 | 139 | this.identityRepository = identityRepository; | ||
4129 | 140 | } | ||
4130 | 141 | } | ||
4131 | 142 | |||
4132 | 143 | synchronized IdentityRepository getIdentityRepository(){ | ||
4133 | 144 | return this.identityRepository; | ||
4134 | 145 | } | ||
4135 | 146 | |||
4136 | 113 | private HostKeyRepository known_hosts=null; | 147 | private HostKeyRepository known_hosts=null; |
4137 | 114 | 148 | ||
4138 | 115 | private static final Logger DEVNULL=new Logger(){ | 149 | private static final Logger DEVNULL=new Logger(){ |
4139 | @@ -134,7 +168,47 @@ | |||
4140 | 134 | 168 | ||
4141 | 135 | } | 169 | } |
4142 | 136 | 170 | ||
4144 | 137 | public Session getSession(String username, String host) throws JSchException { return getSession(username, host, 22); } | 171 | /** |
4145 | 172 | * Instantiates the <code>Session</code> object with | ||
4146 | 173 | * <code>username</code> and <code>host</code>. | ||
4147 | 174 | * The TCP port 22 will be used in making the connection. | ||
4148 | 175 | * Note that the TCP connection must not be established | ||
4149 | 176 | * until Session#connect(). | ||
4150 | 177 | * | ||
4151 | 178 | * @param username user name | ||
4152 | 179 | * @param host hostname | ||
4153 | 180 | * | ||
4154 | 181 | * @throws JSchException | ||
4155 | 182 | * if <code>username</code> or <code>host</code> are invalid. | ||
4156 | 183 | * | ||
4157 | 184 | * @return the instance of <code>Session</code> class. | ||
4158 | 185 | * | ||
4159 | 186 | * @see #getSession(String username, String host, int port) | ||
4160 | 187 | * @see com.jcraft.jsch.Session | ||
4161 | 188 | */ | ||
4162 | 189 | public Session getSession(String username, String host) | ||
4163 | 190 | throws JSchException { | ||
4164 | 191 | return getSession(username, host, 22); | ||
4165 | 192 | } | ||
4166 | 193 | |||
4167 | 194 | /** | ||
4168 | 195 | * Instantiates the <code>Session</code> object with given | ||
4169 | 196 | * <code>username</code>, <code>host</code> and <code>port</code>. | ||
4170 | 197 | * Note that the TCP connection must not be established | ||
4171 | 198 | * until Session#connect(). | ||
4172 | 199 | * | ||
4173 | 200 | * @param username user name | ||
4174 | 201 | * @param host hostname | ||
4175 | 202 | * @param post port number | ||
4176 | 203 | * | ||
4177 | 204 | * @throws JSchException | ||
4178 | 205 | * if <code>username</code> or <code>host</code> are invalid. | ||
4179 | 206 | * | ||
4180 | 207 | * @return the instance of <code>Session</code> class. | ||
4181 | 208 | * | ||
4182 | 209 | * @see #getSession(String username, String host, int port) | ||
4183 | 210 | * @see com.jcraft.jsch.Session | ||
4184 | 211 | */ | ||
4185 | 138 | public Session getSession(String username, String host, int port) throws JSchException { | 212 | public Session getSession(String username, String host, int port) throws JSchException { |
4186 | 139 | if(username==null){ | 213 | if(username==null){ |
4187 | 140 | throw new JSchException("username must not be null."); | 214 | throw new JSchException("username must not be null."); |
4188 | @@ -146,25 +220,44 @@ | |||
4189 | 146 | s.setUserName(username); | 220 | s.setUserName(username); |
4190 | 147 | s.setHost(host); | 221 | s.setHost(host); |
4191 | 148 | s.setPort(port); | 222 | s.setPort(port); |
4192 | 149 | //pool.addElement(s); | ||
4193 | 150 | return s; | 223 | return s; |
4194 | 151 | } | 224 | } |
4195 | 152 | 225 | ||
4196 | 153 | protected void addSession(Session session){ | 226 | protected void addSession(Session session){ |
4199 | 154 | synchronized(pool){ | 227 | synchronized(sessionPool){ |
4200 | 155 | pool.addElement(session); | 228 | sessionPool.addElement(session); |
4201 | 156 | } | 229 | } |
4202 | 157 | } | 230 | } |
4203 | 158 | 231 | ||
4204 | 159 | protected boolean removeSession(Session session){ | 232 | protected boolean removeSession(Session session){ |
4207 | 160 | synchronized(pool){ | 233 | synchronized(sessionPool){ |
4208 | 161 | return pool.remove(session); | 234 | return sessionPool.remove(session); |
4209 | 162 | } | 235 | } |
4210 | 163 | } | 236 | } |
4211 | 237 | |||
4212 | 238 | /** | ||
4213 | 239 | * Sets the hostkey repository. | ||
4214 | 240 | * | ||
4215 | 241 | * @param hkrepo | ||
4216 | 242 | * | ||
4217 | 243 | * @see com.jcraft.jsch.HostKeyRepository | ||
4218 | 244 | * @see com.jcraft.jsch.KnownHosts | ||
4219 | 245 | */ | ||
4220 | 164 | public void setHostKeyRepository(HostKeyRepository hkrepo){ | 246 | public void setHostKeyRepository(HostKeyRepository hkrepo){ |
4221 | 165 | known_hosts=hkrepo; | 247 | known_hosts=hkrepo; |
4222 | 166 | } | 248 | } |
4223 | 167 | 249 | ||
4224 | 250 | /** | ||
4225 | 251 | * Sets the instance of <code>KnownHosts</code>, which refers | ||
4226 | 252 | * to <code>filename</code>. | ||
4227 | 253 | * | ||
4228 | 254 | * @param filename filename of known_hosts file. | ||
4229 | 255 | * | ||
4230 | 256 | * @throws JSchException | ||
4231 | 257 | * if the given filename is invalid. | ||
4232 | 258 | * | ||
4233 | 259 | * @see com.jcraft.jsch.KnownHosts | ||
4234 | 260 | */ | ||
4235 | 168 | public void setKnownHosts(String filename) throws JSchException{ | 261 | public void setKnownHosts(String filename) throws JSchException{ |
4236 | 169 | if(known_hosts==null) known_hosts=new KnownHosts(this); | 262 | if(known_hosts==null) known_hosts=new KnownHosts(this); |
4237 | 170 | if(known_hosts instanceof KnownHosts){ | 263 | if(known_hosts instanceof KnownHosts){ |
4238 | @@ -174,6 +267,17 @@ | |||
4239 | 174 | } | 267 | } |
4240 | 175 | } | 268 | } |
4241 | 176 | 269 | ||
4242 | 270 | /** | ||
4243 | 271 | * Sets the instance of <code>KnownHosts</code> generated with | ||
4244 | 272 | * <code>stream</code>. | ||
4245 | 273 | * | ||
4246 | 274 | * @param stream the instance of InputStream from known_hosts file. | ||
4247 | 275 | * | ||
4248 | 276 | * @throws JSchException | ||
4249 | 277 | * if an I/O error occurs. | ||
4250 | 278 | * | ||
4251 | 279 | * @see com.jcraft.jsch.KnownHosts | ||
4252 | 280 | */ | ||
4253 | 177 | public void setKnownHosts(InputStream stream) throws JSchException{ | 281 | public void setKnownHosts(InputStream stream) throws JSchException{ |
4254 | 178 | if(known_hosts==null) known_hosts=new KnownHosts(this); | 282 | if(known_hosts==null) known_hosts=new KnownHosts(this); |
4255 | 179 | if(known_hosts instanceof KnownHosts){ | 283 | if(known_hosts instanceof KnownHosts){ |
4256 | @@ -183,15 +287,47 @@ | |||
4257 | 183 | } | 287 | } |
4258 | 184 | } | 288 | } |
4259 | 185 | 289 | ||
4260 | 290 | /** | ||
4261 | 291 | * Returns the current hostkey repository. | ||
4262 | 292 | * By the default, this method will the instance of <code>KnownHosts</code>. | ||
4263 | 293 | * | ||
4264 | 294 | * @return current hostkey repository. | ||
4265 | 295 | * | ||
4266 | 296 | * @see com.jcraft.jsch.HostKeyRepository | ||
4267 | 297 | * @see com.jcraft.jsch.KnownHosts | ||
4268 | 298 | */ | ||
4269 | 186 | public HostKeyRepository getHostKeyRepository(){ | 299 | public HostKeyRepository getHostKeyRepository(){ |
4270 | 187 | if(known_hosts==null) known_hosts=new KnownHosts(this); | 300 | if(known_hosts==null) known_hosts=new KnownHosts(this); |
4271 | 188 | return known_hosts; | 301 | return known_hosts; |
4272 | 189 | } | 302 | } |
4273 | 190 | 303 | ||
4274 | 304 | /** | ||
4275 | 305 | * Sets the private key, which will be referred in | ||
4276 | 306 | * the public key authentication. | ||
4277 | 307 | * | ||
4278 | 308 | * @param prvkey filename of the private key. | ||
4279 | 309 | * | ||
4280 | 310 | * @throws JSchException if <code>prvkey</code> is invalid. | ||
4281 | 311 | * | ||
4282 | 312 | * @see #addIdentity(String prvkey, String passphrase) | ||
4283 | 313 | */ | ||
4284 | 191 | public void addIdentity(String prvkey) throws JSchException{ | 314 | public void addIdentity(String prvkey) throws JSchException{ |
4285 | 192 | addIdentity(prvkey, (byte[])null); | 315 | addIdentity(prvkey, (byte[])null); |
4286 | 193 | } | 316 | } |
4287 | 194 | 317 | ||
4288 | 318 | /** | ||
4289 | 319 | * Sets the private key, which will be referred in | ||
4290 | 320 | * the public key authentication. | ||
4291 | 321 | * Before registering it into identityRepository, | ||
4292 | 322 | * it will be deciphered with <code>passphrase</code>. | ||
4293 | 323 | * | ||
4294 | 324 | * @param prvkey filename of the private key. | ||
4295 | 325 | * @param passphrase passphrase for <code>prvkey</code>. | ||
4296 | 326 | * | ||
4297 | 327 | * @throws JSchException if <code>passphrase</code> is not right. | ||
4298 | 328 | * | ||
4299 | 329 | * @see #addIdentity(String prvkey, byte[] passphrase) | ||
4300 | 330 | */ | ||
4301 | 195 | public void addIdentity(String prvkey, String passphrase) throws JSchException{ | 331 | public void addIdentity(String prvkey, String passphrase) throws JSchException{ |
4302 | 196 | byte[] _passphrase=null; | 332 | byte[] _passphrase=null; |
4303 | 197 | if(passphrase!=null){ | 333 | if(passphrase!=null){ |
4304 | @@ -202,20 +338,70 @@ | |||
4305 | 202 | Util.bzero(_passphrase); | 338 | Util.bzero(_passphrase); |
4306 | 203 | } | 339 | } |
4307 | 204 | 340 | ||
4308 | 341 | /** | ||
4309 | 342 | * Sets the private key, which will be referred in | ||
4310 | 343 | * the public key authentication. | ||
4311 | 344 | * Before registering it into identityRepository, | ||
4312 | 345 | * it will be deciphered with <code>passphrase</code>. | ||
4313 | 346 | * | ||
4314 | 347 | * @param prvkey filename of the private key. | ||
4315 | 348 | * @param passphrase passphrase for <code>prvkey</code>. | ||
4316 | 349 | * | ||
4317 | 350 | * @throws JSchException if <code>passphrase</code> is not right. | ||
4318 | 351 | * | ||
4319 | 352 | * @see #addIdentity(String prvkey, String pubkey, byte[] passphrase) | ||
4320 | 353 | */ | ||
4321 | 205 | public void addIdentity(String prvkey, byte[] passphrase) throws JSchException{ | 354 | public void addIdentity(String prvkey, byte[] passphrase) throws JSchException{ |
4322 | 206 | Identity identity=IdentityFile.newInstance(prvkey, null, this); | 355 | Identity identity=IdentityFile.newInstance(prvkey, null, this); |
4323 | 207 | addIdentity(identity, passphrase); | 356 | addIdentity(identity, passphrase); |
4324 | 208 | } | 357 | } |
4325 | 358 | |||
4326 | 359 | /** | ||
4327 | 360 | * Sets the private key, which will be referred in | ||
4328 | 361 | * the public key authentication. | ||
4329 | 362 | * Before registering it into identityRepository, | ||
4330 | 363 | * it will be deciphered with <code>passphrase</code>. | ||
4331 | 364 | * | ||
4332 | 365 | * @param prvkey filename of the private key. | ||
4333 | 366 | * @param pubkey filename of the public key. | ||
4334 | 367 | * @param passphrase passphrase for <code>prvkey</code>. | ||
4335 | 368 | * | ||
4336 | 369 | * @throws JSchException if <code>passphrase</code> is not right. | ||
4337 | 370 | */ | ||
4338 | 209 | public void addIdentity(String prvkey, String pubkey, byte[] passphrase) throws JSchException{ | 371 | public void addIdentity(String prvkey, String pubkey, byte[] passphrase) throws JSchException{ |
4339 | 210 | Identity identity=IdentityFile.newInstance(prvkey, pubkey, this); | 372 | Identity identity=IdentityFile.newInstance(prvkey, pubkey, this); |
4340 | 211 | addIdentity(identity, passphrase); | 373 | addIdentity(identity, passphrase); |
4341 | 212 | } | 374 | } |
4342 | 213 | 375 | ||
4343 | 376 | /** | ||
4344 | 377 | * Sets the private key, which will be referred in | ||
4345 | 378 | * the public key authentication. | ||
4346 | 379 | * Before registering it into identityRepository, | ||
4347 | 380 | * it will be deciphered with <code>passphrase</code>. | ||
4348 | 381 | * | ||
4349 | 382 | * @param name name of the identity to be used to | ||
4350 | 383 | retrieve it in the identityRepository. | ||
4351 | 384 | * @param prvkey private key in byte array. | ||
4352 | 385 | * @param pubkey public key in byte array. | ||
4353 | 386 | * @param passphrase passphrase for <code>prvkey</code>. | ||
4354 | 387 | * | ||
4355 | 388 | */ | ||
4356 | 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{ |
4357 | 215 | Identity identity=IdentityFile.newInstance(name, prvkey, pubkey, this); | 390 | Identity identity=IdentityFile.newInstance(name, prvkey, pubkey, this); |
4358 | 216 | addIdentity(identity, passphrase); | 391 | addIdentity(identity, passphrase); |
4359 | 217 | } | 392 | } |
4360 | 218 | 393 | ||
4361 | 394 | /** | ||
4362 | 395 | * Sets the private key, which will be referred in | ||
4363 | 396 | * the public key authentication. | ||
4364 | 397 | * Before registering it into identityRepository, | ||
4365 | 398 | * it will be deciphered with <code>passphrase</code>. | ||
4366 | 399 | * | ||
4367 | 400 | * @param identity private key. | ||
4368 | 401 | * @param passphrase passphrase for <code>identity</code>. | ||
4369 | 402 | * | ||
4370 | 403 | * @throws JSchException if <code>passphrase</code> is not right. | ||
4371 | 404 | */ | ||
4372 | 219 | public void addIdentity(Identity identity, byte[] passphrase) throws JSchException{ | 405 | public void addIdentity(Identity identity, byte[] passphrase) throws JSchException{ |
4373 | 220 | if(passphrase!=null){ | 406 | if(passphrase!=null){ |
4374 | 221 | try{ | 407 | try{ |
4375 | @@ -228,53 +414,83 @@ | |||
4376 | 228 | Util.bzero(passphrase); | 414 | Util.bzero(passphrase); |
4377 | 229 | } | 415 | } |
4378 | 230 | } | 416 | } |
4383 | 231 | synchronized(identities){ | 417 | |
4384 | 232 | if(!identities.contains(identity)){ | 418 | if(identityRepository instanceof LocalIdentityRepository){ |
4385 | 233 | identities.addElement(identity); | 419 | ((LocalIdentityRepository)identityRepository).add(identity); |
4386 | 234 | } | 420 | } |
4387 | 421 | else { | ||
4388 | 422 | // TODO | ||
4389 | 235 | } | 423 | } |
4390 | 236 | } | 424 | } |
4391 | 237 | 425 | ||
4392 | 426 | /** | ||
4393 | 427 | * @deprecated use #removeIdentity(Identity identity) | ||
4394 | 428 | */ | ||
4395 | 238 | public void removeIdentity(String name) throws JSchException{ | 429 | public void removeIdentity(String name) throws JSchException{ |
4405 | 239 | synchronized(identities){ | 430 | Vector identities = identityRepository.getIdentities(); |
4406 | 240 | for(int i=0; i<identities.size(); i++){ | 431 | for(int i=0; i<identities.size(); i++){ |
4407 | 241 | Identity identity=(Identity)(identities.elementAt(i)); | 432 | Identity identity=(Identity)(identities.elementAt(i)); |
4408 | 242 | if(!identity.getName().equals(name)) | 433 | if(!identity.getName().equals(name)) |
4409 | 243 | continue; | 434 | continue; |
4410 | 244 | identities.removeElement(identity); | 435 | identityRepository.remove(identity.getPublicKeyBlob()); |
4411 | 245 | identity.clear(); | 436 | break; |
4403 | 246 | break; | ||
4404 | 247 | } | ||
4412 | 248 | } | 437 | } |
4413 | 249 | } | 438 | } |
4414 | 250 | 439 | ||
4415 | 440 | /** | ||
4416 | 441 | * Removes the identity from identityRepository. | ||
4417 | 442 | * | ||
4418 | 443 | * @param identity the indentity to be removed. | ||
4419 | 444 | * | ||
4420 | 445 | * @throws JSchException if <code>identity</code> is invalid. | ||
4421 | 446 | */ | ||
4422 | 447 | public void removeIdentity(Identity identity) throws JSchException{ | ||
4423 | 448 | identityRepository.remove(identity.getPublicKeyBlob()); | ||
4424 | 449 | } | ||
4425 | 450 | |||
4426 | 451 | /** | ||
4427 | 452 | * Lists names of identities included in the identityRepository. | ||
4428 | 453 | * | ||
4429 | 454 | * @return names of identities | ||
4430 | 455 | * | ||
4431 | 456 | * @throws JSchException if identityReposory has problems. | ||
4432 | 457 | */ | ||
4433 | 251 | public Vector getIdentityNames() throws JSchException{ | 458 | public Vector getIdentityNames() throws JSchException{ |
4434 | 252 | Vector foo=new Vector(); | 459 | Vector foo=new Vector(); |
4440 | 253 | synchronized(identities){ | 460 | Vector identities = identityRepository.getIdentities(); |
4441 | 254 | for(int i=0; i<identities.size(); i++){ | 461 | for(int i=0; i<identities.size(); i++){ |
4442 | 255 | Identity identity=(Identity)(identities.elementAt(i)); | 462 | Identity identity=(Identity)(identities.elementAt(i)); |
4443 | 256 | foo.addElement(identity.getName()); | 463 | foo.addElement(identity.getName()); |
4439 | 257 | } | ||
4444 | 258 | } | 464 | } |
4445 | 259 | return foo; | 465 | return foo; |
4446 | 260 | } | 466 | } |
4447 | 261 | 467 | ||
4448 | 468 | /** | ||
4449 | 469 | * Removes all identities from identityRepository. | ||
4450 | 470 | * | ||
4451 | 471 | * @throws JSchException if identityReposory has problems. | ||
4452 | 472 | */ | ||
4453 | 262 | public void removeAllIdentity() throws JSchException{ | 473 | public void removeAllIdentity() throws JSchException{ |
4461 | 263 | synchronized(identities){ | 474 | identityRepository.removeAll(); |
4455 | 264 | Vector foo=getIdentityNames(); | ||
4456 | 265 | for(int i=0; i<foo.size(); i++){ | ||
4457 | 266 | String name=((String)foo.elementAt(i)); | ||
4458 | 267 | removeIdentity(name); | ||
4459 | 268 | } | ||
4460 | 269 | } | ||
4462 | 270 | } | 475 | } |
4463 | 271 | 476 | ||
4464 | 477 | /** | ||
4465 | 478 | * Returns the config value for the specified key. | ||
4466 | 479 | * | ||
4467 | 480 | * @param key key for the configuration. | ||
4468 | 481 | * @return config value | ||
4469 | 482 | */ | ||
4470 | 272 | public static String getConfig(String key){ | 483 | public static String getConfig(String key){ |
4471 | 273 | synchronized(config){ | 484 | synchronized(config){ |
4472 | 274 | return (String)(config.get(key)); | 485 | return (String)(config.get(key)); |
4473 | 275 | } | 486 | } |
4474 | 276 | } | 487 | } |
4475 | 277 | 488 | ||
4476 | 489 | /** | ||
4477 | 490 | * Sets or Overrides the configuration. | ||
4478 | 491 | * | ||
4479 | 492 | * @param newconf configurations | ||
4480 | 493 | */ | ||
4481 | 278 | public static void setConfig(java.util.Hashtable newconf){ | 494 | public static void setConfig(java.util.Hashtable newconf){ |
4482 | 279 | synchronized(config){ | 495 | synchronized(config){ |
4483 | 280 | for(java.util.Enumeration e=newconf.keys() ; e.hasMoreElements() ;) { | 496 | for(java.util.Enumeration e=newconf.keys() ; e.hasMoreElements() ;) { |
4484 | @@ -284,14 +500,28 @@ | |||
4485 | 284 | } | 500 | } |
4486 | 285 | } | 501 | } |
4487 | 286 | 502 | ||
4488 | 503 | /** | ||
4489 | 504 | * Sets or Overrides the configuration. | ||
4490 | 505 | * | ||
4491 | 506 | * @param key key for the configuration | ||
4492 | 507 | * @param value value for the configuration | ||
4493 | 508 | */ | ||
4494 | 287 | public static void setConfig(String key, String value){ | 509 | public static void setConfig(String key, String value){ |
4495 | 288 | config.put(key, value); | 510 | config.put(key, value); |
4496 | 289 | } | 511 | } |
4497 | 290 | 512 | ||
4498 | 513 | /** | ||
4499 | 514 | * Sets the logger | ||
4500 | 515 | * | ||
4501 | 516 | * @param logger logger | ||
4502 | 517 | * | ||
4503 | 518 | * @see com.jcraft.jsch.Logger | ||
4504 | 519 | */ | ||
4505 | 291 | public static void setLogger(Logger logger){ | 520 | public static void setLogger(Logger logger){ |
4507 | 292 | if(logger==null) JSch.logger=DEVNULL; | 521 | if(logger==null) logger=DEVNULL; |
4508 | 293 | JSch.logger=logger; | 522 | JSch.logger=logger; |
4509 | 294 | } | 523 | } |
4510 | 524 | |||
4511 | 295 | static Logger getLogger(){ | 525 | static Logger getLogger(){ |
4512 | 296 | return logger; | 526 | return logger; |
4513 | 297 | } | 527 | } |
4514 | 298 | 528 | ||
4515 | === modified file 'src/main/java/com/jcraft/jsch/JSchAuthCancelException.java' | |||
4516 | --- src/com/jcraft/jsch/JSchAuthCancelException.java 2010-06-27 23:17:34 +0000 | |||
4517 | +++ src/main/java/com/jcraft/jsch/JSchAuthCancelException.java 2012-05-04 10:23:17 +0000 | |||
4518 | @@ -1,6 +1,6 @@ | |||
4519 | 1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ | 1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ |
4520 | 2 | /* | 2 | /* |
4522 | 3 | Copyright (c) 2002-2009 ymnk, JCraft,Inc. All rights reserved. | 3 | Copyright (c) 2002-2012 ymnk, JCraft,Inc. All rights reserved. |
4523 | 4 | 4 | ||
4524 | 5 | Redistribution and use in source and binary forms, with or without | 5 | Redistribution and use in source and binary forms, with or without |
4525 | 6 | modification, are permitted provided that the following conditions are met: | 6 | modification, are permitted provided that the following conditions are met: |
4526 | 7 | 7 | ||
4527 | === modified file 'src/main/java/com/jcraft/jsch/JSchException.java' | |||
4528 | --- src/com/jcraft/jsch/JSchException.java 2010-06-27 23:17:34 +0000 | |||
4529 | +++ src/main/java/com/jcraft/jsch/JSchException.java 2012-05-04 10:23:17 +0000 | |||
4530 | @@ -1,6 +1,6 @@ | |||
4531 | 1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ | 1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ |
4532 | 2 | /* | 2 | /* |
4534 | 3 | Copyright (c) 2002-2009 ymnk, JCraft,Inc. All rights reserved. | 3 | Copyright (c) 2002-2012 ymnk, JCraft,Inc. All rights reserved. |
4535 | 4 | 4 | ||
4536 | 5 | Redistribution and use in source and binary forms, with or without | 5 | Redistribution and use in source and binary forms, with or without |
4537 | 6 | modification, are permitted provided that the following conditions are met: | 6 | modification, are permitted provided that the following conditions are met: |
4538 | 7 | 7 | ||
4539 | === modified file 'src/main/java/com/jcraft/jsch/JSchPartialAuthException.java' | |||
4540 | --- src/com/jcraft/jsch/JSchPartialAuthException.java 2010-06-27 23:17:34 +0000 | |||
4541 | +++ src/main/java/com/jcraft/jsch/JSchPartialAuthException.java 2012-05-04 10:23:17 +0000 | |||
4542 | @@ -1,6 +1,6 @@ | |||
4543 | 1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ | 1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ |
4544 | 2 | /* | 2 | /* |
4546 | 3 | Copyright (c) 2002-2009 ymnk, JCraft,Inc. All rights reserved. | 3 | Copyright (c) 2002-2012 ymnk, JCraft,Inc. All rights reserved. |
4547 | 4 | 4 | ||
4548 | 5 | Redistribution and use in source and binary forms, with or without | 5 | Redistribution and use in source and binary forms, with or without |
4549 | 6 | modification, are permitted provided that the following conditions are met: | 6 | modification, are permitted provided that the following conditions are met: |
4550 | 7 | 7 | ||
4551 | === modified file 'src/main/java/com/jcraft/jsch/KeyExchange.java' | |||
4552 | --- src/com/jcraft/jsch/KeyExchange.java 2010-06-27 23:17:34 +0000 | |||
4553 | +++ src/main/java/com/jcraft/jsch/KeyExchange.java 2012-05-04 10:23:17 +0000 | |||
4554 | @@ -1,6 +1,6 @@ | |||
4555 | 1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ | 1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ |
4556 | 2 | /* | 2 | /* |
4558 | 3 | Copyright (c) 2002-2009 ymnk, JCraft,Inc. All rights reserved. | 3 | Copyright (c) 2002-2012 ymnk, JCraft,Inc. All rights reserved. |
4559 | 4 | 4 | ||
4560 | 5 | Redistribution and use in source and binary forms, with or without | 5 | Redistribution and use in source and binary forms, with or without |
4561 | 6 | modification, are permitted provided that the following conditions are met: | 6 | modification, are permitted provided that the following conditions are met: |
4562 | @@ -85,36 +85,41 @@ | |||
4563 | 85 | */ | 85 | */ |
4564 | 86 | 86 | ||
4565 | 87 | protected static String[] guess(byte[]I_S, byte[]I_C){ | 87 | protected static String[] guess(byte[]I_S, byte[]I_C){ |
4566 | 88 | //System.err.println("guess: "); | ||
4567 | 89 | String[] guess=new String[PROPOSAL_MAX]; | 88 | String[] guess=new String[PROPOSAL_MAX]; |
4568 | 90 | Buffer sb=new Buffer(I_S); sb.setOffSet(17); | 89 | Buffer sb=new Buffer(I_S); sb.setOffSet(17); |
4569 | 91 | Buffer cb=new Buffer(I_C); cb.setOffSet(17); | 90 | Buffer cb=new Buffer(I_C); cb.setOffSet(17); |
4570 | 92 | 91 | ||
4571 | 92 | if(JSch.getLogger().isEnabled(Logger.INFO)){ | ||
4572 | 93 | for(int i=0; i<PROPOSAL_MAX; i++){ | ||
4573 | 94 | JSch.getLogger().log(Logger.INFO, | ||
4574 | 95 | "kex: server: "+Util.byte2str(sb.getString())); | ||
4575 | 96 | } | ||
4576 | 97 | for(int i=0; i<PROPOSAL_MAX; i++){ | ||
4577 | 98 | JSch.getLogger().log(Logger.INFO, | ||
4578 | 99 | "kex: client: "+Util.byte2str(cb.getString())); | ||
4579 | 100 | } | ||
4580 | 101 | sb.setOffSet(17); | ||
4581 | 102 | cb.setOffSet(17); | ||
4582 | 103 | } | ||
4583 | 104 | |||
4584 | 93 | for(int i=0; i<PROPOSAL_MAX; i++){ | 105 | for(int i=0; i<PROPOSAL_MAX; i++){ |
4585 | 94 | byte[] sp=sb.getString(); // server proposal | 106 | byte[] sp=sb.getString(); // server proposal |
4586 | 95 | byte[] cp=cb.getString(); // client proposal | 107 | byte[] cp=cb.getString(); // client proposal |
4587 | 96 | |||
4588 | 97 | //System.err.println("server-proposal: |"+new String(sp)+"|"); | ||
4589 | 98 | //System.err.println("client-proposal: |"+new String(cp)+"|"); | ||
4590 | 99 | |||
4591 | 100 | int j=0; | 108 | int j=0; |
4592 | 101 | int k=0; | 109 | int k=0; |
4594 | 102 | //System.err.println(new String(cp)); | 110 | |
4595 | 103 | loop: | 111 | loop: |
4596 | 104 | while(j<cp.length){ | 112 | while(j<cp.length){ |
4597 | 105 | while(j<cp.length && cp[j]!=',')j++; | 113 | while(j<cp.length && cp[j]!=',')j++; |
4598 | 106 | if(k==j) return null; | 114 | if(k==j) return null; |
4601 | 107 | String algorithm=new String(cp, k, j-k); | 115 | String algorithm=Util.byte2str(cp, k, j-k); |
4600 | 108 | //System.err.println("algorithm: "+algorithm); | ||
4602 | 109 | int l=0; | 116 | int l=0; |
4603 | 110 | int m=0; | 117 | int m=0; |
4604 | 111 | while(l<sp.length){ | 118 | while(l<sp.length){ |
4605 | 112 | while(l<sp.length && sp[l]!=',')l++; | 119 | while(l<sp.length && sp[l]!=',')l++; |
4606 | 113 | if(m==l) return null; | 120 | if(m==l) return null; |
4609 | 114 | //System.err.println(" "+new String(sp, m, l-m)); | 121 | if(algorithm.equals(Util.byte2str(sp, m, l-m))){ |
4608 | 115 | if(algorithm.equals(new String(sp, m, l-m))){ | ||
4610 | 116 | guess[i]=algorithm; | 122 | guess[i]=algorithm; |
4611 | 117 | //System.err.println(" "+algorithm); | ||
4612 | 118 | break loop; | 123 | break loop; |
4613 | 119 | } | 124 | } |
4614 | 120 | l++; | 125 | l++; |
4615 | @@ -127,7 +132,6 @@ | |||
4616 | 127 | guess[i]=""; | 132 | guess[i]=""; |
4617 | 128 | } | 133 | } |
4618 | 129 | else if(guess[i]==null){ | 134 | else if(guess[i]==null){ |
4619 | 130 | //System.err.println(" fail"); | ||
4620 | 131 | return null; | 135 | return null; |
4621 | 132 | } | 136 | } |
4622 | 133 | } | 137 | } |
4623 | @@ -145,10 +149,6 @@ | |||
4624 | 145 | " "+guess[PROPOSAL_COMP_ALGS_CTOS]); | 149 | " "+guess[PROPOSAL_COMP_ALGS_CTOS]); |
4625 | 146 | } | 150 | } |
4626 | 147 | 151 | ||
4627 | 148 | // for(int i=0; i<PROPOSAL_MAX; i++){ | ||
4628 | 149 | // System.err.println("guess: ["+guess[i]+"]"); | ||
4629 | 150 | // } | ||
4630 | 151 | |||
4631 | 152 | return guess; | 152 | return guess; |
4632 | 153 | } | 153 | } |
4633 | 154 | 154 | ||
4634 | 155 | 155 | ||
4635 | === modified file 'src/main/java/com/jcraft/jsch/KeyPair.java' | |||
4636 | --- src/com/jcraft/jsch/KeyPair.java 2010-06-27 23:17:34 +0000 | |||
4637 | +++ src/main/java/com/jcraft/jsch/KeyPair.java 2012-05-04 10:23:17 +0000 | |||
4638 | @@ -1,6 +1,6 @@ | |||
4639 | 1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ | 1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ |
4640 | 2 | /* | 2 | /* |
4642 | 3 | Copyright (c) 2002-2009 ymnk, JCraft,Inc. All rights reserved. | 3 | Copyright (c) 2002-2012 ymnk, JCraft,Inc. All rights reserved. |
4643 | 4 | 4 | ||
4644 | 5 | Redistribution and use in source and binary forms, with or without | 5 | Redistribution and use in source and binary forms, with or without |
4645 | 6 | modification, are permitted provided that the following conditions are met: | 6 | modification, are permitted provided that the following conditions are met: |
4646 | @@ -43,7 +43,7 @@ | |||
4647 | 43 | static final int VENDOR_FSECURE=1; | 43 | static final int VENDOR_FSECURE=1; |
4648 | 44 | int vendor=VENDOR_OPENSSH; | 44 | int vendor=VENDOR_OPENSSH; |
4649 | 45 | 45 | ||
4651 | 46 | private static final byte[] cr="\n".getBytes(); | 46 | private static final byte[] cr=Util.str2byte("\n"); |
4652 | 47 | 47 | ||
4653 | 48 | public static KeyPair genKeyPair(JSch jsch, int type) throws JSchException{ | 48 | public static KeyPair genKeyPair(JSch jsch, int type) throws JSchException{ |
4654 | 49 | return genKeyPair(jsch, type, 1024); | 49 | return genKeyPair(jsch, type, 1024); |
4655 | @@ -64,6 +64,11 @@ | |||
4656 | 64 | abstract byte[] getEnd(); | 64 | abstract byte[] getEnd(); |
4657 | 65 | abstract int getKeySize(); | 65 | abstract int getKeySize(); |
4658 | 66 | 66 | ||
4659 | 67 | public String getPublicKeyComment(){ | ||
4660 | 68 | return publicKeyComment; | ||
4661 | 69 | } | ||
4662 | 70 | private String publicKeyComment = ""; | ||
4663 | 71 | |||
4664 | 67 | JSch jsch=null; | 72 | JSch jsch=null; |
4665 | 68 | private Cipher cipher; | 73 | private Cipher cipher; |
4666 | 69 | private HASH hash; | 74 | private HASH hash; |
4667 | @@ -75,8 +80,8 @@ | |||
4668 | 75 | this.jsch=jsch; | 80 | this.jsch=jsch; |
4669 | 76 | } | 81 | } |
4670 | 77 | 82 | ||
4673 | 78 | static byte[][] header={"Proc-Type: 4,ENCRYPTED".getBytes(), | 83 | static byte[][] header={Util.str2byte("Proc-Type: 4,ENCRYPTED"), |
4674 | 79 | "DEK-Info: DES-EDE3-CBC,".getBytes()}; | 84 | Util.str2byte("DEK-Info: DES-EDE3-CBC,")}; |
4675 | 80 | 85 | ||
4676 | 81 | abstract byte[] getPrivateKey(); | 86 | abstract byte[] getPrivateKey(); |
4677 | 82 | 87 | ||
4678 | @@ -120,7 +125,7 @@ | |||
4679 | 120 | } | 125 | } |
4680 | 121 | } | 126 | } |
4681 | 122 | 127 | ||
4683 | 123 | private static byte[] space=" ".getBytes(); | 128 | private static byte[] space=Util.str2byte(" "); |
4684 | 124 | 129 | ||
4685 | 125 | abstract byte[] getKeyTypeName(); | 130 | abstract byte[] getKeyTypeName(); |
4686 | 126 | public abstract int getKeyType(); | 131 | public abstract int getKeyType(); |
4687 | @@ -133,7 +138,7 @@ | |||
4688 | 133 | try{ | 138 | try{ |
4689 | 134 | out.write(getKeyTypeName()); out.write(space); | 139 | out.write(getKeyTypeName()); out.write(space); |
4690 | 135 | out.write(pub, 0, pub.length); out.write(space); | 140 | out.write(pub, 0, pub.length); out.write(space); |
4692 | 136 | out.write(comment.getBytes()); | 141 | out.write(Util.str2byte(comment)); |
4693 | 137 | out.write(cr); | 142 | out.write(cr); |
4694 | 138 | } | 143 | } |
4695 | 139 | catch(Exception e){ | 144 | catch(Exception e){ |
4696 | @@ -150,8 +155,8 @@ | |||
4697 | 150 | byte[] pubblob=getPublicKeyBlob(); | 155 | byte[] pubblob=getPublicKeyBlob(); |
4698 | 151 | byte[] pub=Util.toBase64(pubblob, 0, pubblob.length); | 156 | byte[] pub=Util.toBase64(pubblob, 0, pubblob.length); |
4699 | 152 | try{ | 157 | try{ |
4702 | 153 | out.write("---- BEGIN SSH2 PUBLIC KEY ----".getBytes()); out.write(cr); | 158 | out.write(Util.str2byte("---- BEGIN SSH2 PUBLIC KEY ----")); out.write(cr); |
4703 | 154 | out.write(("Comment: \""+comment+"\"").getBytes()); out.write(cr); | 159 | out.write(Util.str2byte("Comment: \""+comment+"\"")); out.write(cr); |
4704 | 155 | int index=0; | 160 | int index=0; |
4705 | 156 | while(index<pub.length){ | 161 | while(index<pub.length){ |
4706 | 157 | int len=70; | 162 | int len=70; |
4707 | @@ -159,7 +164,7 @@ | |||
4708 | 159 | out.write(pub, index, len); out.write(cr); | 164 | out.write(pub, index, len); out.write(cr); |
4709 | 160 | index+=len; | 165 | index+=len; |
4710 | 161 | } | 166 | } |
4712 | 162 | out.write("---- END SSH2 PUBLIC KEY ----".getBytes()); out.write(cr); | 167 | out.write(Util.str2byte("---- END SSH2 PUBLIC KEY ----")); out.write(cr); |
4713 | 163 | } | 168 | } |
4714 | 164 | catch(Exception e){ | 169 | catch(Exception e){ |
4715 | 165 | } | 170 | } |
4716 | @@ -335,7 +340,7 @@ | |||
4717 | 335 | for(int index=0; index+hsize<=hn.length;){ | 340 | for(int index=0; index+hsize<=hn.length;){ |
4718 | 336 | if(tmp!=null){ hash.update(tmp, 0, tmp.length); } | 341 | if(tmp!=null){ hash.update(tmp, 0, tmp.length); } |
4719 | 337 | hash.update(passphrase, 0, passphrase.length); | 342 | hash.update(passphrase, 0, passphrase.length); |
4721 | 338 | hash.update(iv, 0, iv.length); | 343 | hash.update(iv, 0, iv.length > 8 ? 8: iv.length); |
4722 | 339 | tmp=hash.digest(); | 344 | tmp=hash.digest(); |
4723 | 340 | System.arraycopy(tmp, 0, hn, index, tmp.length); | 345 | System.arraycopy(tmp, 0, hn, index, tmp.length); |
4724 | 341 | index+=tmp.length; | 346 | index+=tmp.length; |
4725 | @@ -420,6 +425,8 @@ | |||
4726 | 420 | 425 | ||
4727 | 421 | int type=ERROR; | 426 | int type=ERROR; |
4728 | 422 | int vendor=VENDOR_OPENSSH; | 427 | int vendor=VENDOR_OPENSSH; |
4729 | 428 | String publicKeyComment = ""; | ||
4730 | 429 | Cipher cipher=null; | ||
4731 | 423 | 430 | ||
4732 | 424 | try{ | 431 | try{ |
4733 | 425 | File file=new File(prvkey); | 432 | File file=new File(prvkey); |
4734 | @@ -437,7 +444,16 @@ | |||
4735 | 437 | int i=0; | 444 | int i=0; |
4736 | 438 | 445 | ||
4737 | 439 | while(i<len){ | 446 | while(i<len){ |
4739 | 440 | if(buf[i]=='B'&& buf[i+1]=='E'&& buf[i+2]=='G'&& buf[i+3]=='I'){ | 447 | if(buf[i] == '-' && i+4<len && |
4740 | 448 | buf[i+1] == '-' && buf[i+2] == '-' && | ||
4741 | 449 | buf[i+3] == '-' && buf[i+4] == '-'){ | ||
4742 | 450 | break; | ||
4743 | 451 | } | ||
4744 | 452 | i++; | ||
4745 | 453 | } | ||
4746 | 454 | |||
4747 | 455 | while(i<len){ | ||
4748 | 456 | if(buf[i]=='B'&& i+3<len && buf[i+1]=='E'&& buf[i+2]=='G'&& buf[i+3]=='I'){ | ||
4749 | 441 | i+=6; | 457 | i+=6; |
4750 | 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; } |
4751 | 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; } |
4752 | @@ -446,21 +462,61 @@ | |||
4753 | 446 | vendor=VENDOR_FSECURE; | 462 | vendor=VENDOR_FSECURE; |
4754 | 447 | } | 463 | } |
4755 | 448 | else{ | 464 | else{ |
4756 | 449 | //System.err.println("invalid format: "+identity); | ||
4757 | 450 | throw new JSchException("invalid privatekey: "+prvkey); | 465 | throw new JSchException("invalid privatekey: "+prvkey); |
4758 | 451 | } | 466 | } |
4759 | 452 | i+=3; | 467 | i+=3; |
4760 | 453 | continue; | 468 | continue; |
4761 | 454 | } | 469 | } |
4763 | 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]=='-' && |
4764 | 471 | buf[i+4]=='2'&& buf[i+5]=='5'&& buf[i+6]=='6'&& buf[i+7]=='-'){ | ||
4765 | 472 | i+=8; | ||
4766 | 473 | if(Session.checkCipher((String)jsch.getConfig("aes256-cbc"))){ | ||
4767 | 474 | Class c=Class.forName((String)jsch.getConfig("aes256-cbc")); | ||
4768 | 475 | cipher=(Cipher)(c.newInstance()); | ||
4769 | 476 | // key=new byte[cipher.getBlockSize()]; | ||
4770 | 477 | iv=new byte[cipher.getIVSize()]; | ||
4771 | 478 | } | ||
4772 | 479 | else{ | ||
4773 | 480 | throw new JSchException("privatekey: aes256-cbc is not available "+prvkey); | ||
4774 | 481 | } | ||
4775 | 482 | continue; | ||
4776 | 483 | } | ||
4777 | 484 | if(buf[i]=='A'&& i+7<len && buf[i+1]=='E'&& buf[i+2]=='S'&& buf[i+3]=='-' && | ||
4778 | 485 | buf[i+4]=='1'&& buf[i+5]=='9'&& buf[i+6]=='2'&& buf[i+7]=='-'){ | ||
4779 | 486 | i+=8; | ||
4780 | 487 | if(Session.checkCipher((String)jsch.getConfig("aes192-cbc"))){ | ||
4781 | 488 | Class c=Class.forName((String)jsch.getConfig("aes192-cbc")); | ||
4782 | 489 | cipher=(Cipher)(c.newInstance()); | ||
4783 | 490 | // key=new byte[cipher.getBlockSize()]; | ||
4784 | 491 | iv=new byte[cipher.getIVSize()]; | ||
4785 | 492 | } | ||
4786 | 493 | else{ | ||
4787 | 494 | throw new JSchException("privatekey: aes192-cbc is not available "+prvkey); | ||
4788 | 495 | } | ||
4789 | 496 | continue; | ||
4790 | 497 | } | ||
4791 | 498 | if(buf[i]=='A'&& i+7<len && buf[i+1]=='E'&& buf[i+2]=='S'&& buf[i+3]=='-' && | ||
4792 | 499 | buf[i+4]=='1'&& buf[i+5]=='2'&& buf[i+6]=='8'&& buf[i+7]=='-'){ | ||
4793 | 500 | i+=8; | ||
4794 | 501 | if(Session.checkCipher((String)jsch.getConfig("aes128-cbc"))){ | ||
4795 | 502 | Class c=Class.forName((String)jsch.getConfig("aes128-cbc")); | ||
4796 | 503 | cipher=(Cipher)(c.newInstance()); | ||
4797 | 504 | // key=new byte[cipher.getBlockSize()]; | ||
4798 | 505 | iv=new byte[cipher.getIVSize()]; | ||
4799 | 506 | } | ||
4800 | 507 | else{ | ||
4801 | 508 | throw new JSchException("privatekey: aes128-cbc is not available "+prvkey); | ||
4802 | 509 | } | ||
4803 | 510 | continue; | ||
4804 | 511 | } | ||
4805 | 512 | if(buf[i]=='C'&& i+3<len && buf[i+1]=='B'&& buf[i+2]=='C'&& buf[i+3]==','){ | ||
4806 | 456 | i+=4; | 513 | i+=4; |
4807 | 457 | for(int ii=0; ii<iv.length; ii++){ | 514 | for(int ii=0; ii<iv.length; ii++){ |
4808 | 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)); |
4809 | 459 | } | 516 | } |
4810 | 460 | continue; | 517 | continue; |
4811 | 461 | } | 518 | } |
4814 | 462 | if(buf[i]==0x0d && | 519 | if(buf[i]==0x0d && i+1<buf.length && buf[i+1]==0x0a){ |
4813 | 463 | i+1<buf.length && buf[i+1]==0x0a){ | ||
4815 | 464 | i++; | 520 | i++; |
4816 | 465 | continue; | 521 | continue; |
4817 | 466 | } | 522 | } |
4818 | @@ -518,10 +574,9 @@ | |||
4819 | 518 | _buf.getInt(); | 574 | _buf.getInt(); |
4820 | 519 | byte[]_type=_buf.getString(); | 575 | byte[]_type=_buf.getString(); |
4821 | 520 | //System.err.println("type: "+new String(_type)); | 576 | //System.err.println("type: "+new String(_type)); |
4826 | 521 | byte[] _cipher=_buf.getString(); | 577 | String _cipher=Util.byte2str(_buf.getString()); |
4827 | 522 | String cipher=new String(_cipher); | 578 | //System.err.println("cipher: "+_cipher); |
4828 | 523 | //System.err.println("cipher: "+cipher); | 579 | if(_cipher.equals("3des-cbc")){ |
4825 | 524 | if(cipher.equals("3des-cbc")){ | ||
4829 | 525 | _buf.getInt(); | 580 | _buf.getInt(); |
4830 | 526 | byte[] foo=new byte[data.length-_buf.getOffSet()]; | 581 | byte[] foo=new byte[data.length-_buf.getOffSet()]; |
4831 | 527 | _buf.getByte(foo); | 582 | _buf.getByte(foo); |
4832 | @@ -529,7 +584,7 @@ | |||
4833 | 529 | encrypted=true; | 584 | encrypted=true; |
4834 | 530 | throw new JSchException("unknown privatekey format: "+prvkey); | 585 | throw new JSchException("unknown privatekey format: "+prvkey); |
4835 | 531 | } | 586 | } |
4837 | 532 | else if(cipher.equals("none")){ | 587 | else if(_cipher.equals("none")){ |
4838 | 533 | _buf.getInt(); | 588 | _buf.getInt(); |
4839 | 534 | _buf.getInt(); | 589 | _buf.getInt(); |
4840 | 535 | 590 | ||
4841 | @@ -606,6 +661,13 @@ | |||
4842 | 606 | while(i<len){ if(buf[i]==' ')break; i++;} | 661 | while(i<len){ if(buf[i]==' ')break; i++;} |
4843 | 607 | publickeyblob=Util.fromBase64(buf, start, i-start); | 662 | publickeyblob=Util.fromBase64(buf, start, i-start); |
4844 | 608 | } | 663 | } |
4845 | 664 | if(i++<len){ | ||
4846 | 665 | int s=i; | ||
4847 | 666 | while(i<len){ if(buf[i]=='\n')break; i++;} | ||
4848 | 667 | if(i<len){ | ||
4849 | 668 | publicKeyComment = new String(buf, s, i-s); | ||
4850 | 669 | } | ||
4851 | 670 | } | ||
4852 | 609 | } | 671 | } |
4853 | 610 | } | 672 | } |
4854 | 611 | } | 673 | } |
4855 | @@ -628,6 +690,8 @@ | |||
4856 | 628 | kpair.encrypted=encrypted; | 690 | kpair.encrypted=encrypted; |
4857 | 629 | kpair.publickeyblob=publickeyblob; | 691 | kpair.publickeyblob=publickeyblob; |
4858 | 630 | kpair.vendor=vendor; | 692 | kpair.vendor=vendor; |
4859 | 693 | kpair.publicKeyComment=publicKeyComment; | ||
4860 | 694 | kpair.cipher=cipher; | ||
4861 | 631 | 695 | ||
4862 | 632 | if(encrypted){ | 696 | if(encrypted){ |
4863 | 633 | kpair.iv=iv; | 697 | kpair.iv=iv; |
4864 | 634 | 698 | ||
4865 | === modified file 'src/main/java/com/jcraft/jsch/KeyPairDSA.java' | |||
4866 | --- src/com/jcraft/jsch/KeyPairDSA.java 2010-06-27 23:17:34 +0000 | |||
4867 | +++ src/main/java/com/jcraft/jsch/KeyPairDSA.java 2012-05-04 10:23:17 +0000 | |||
4868 | @@ -1,6 +1,6 @@ | |||
4869 | 1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ | 1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ |
4870 | 2 | /* | 2 | /* |
4872 | 3 | Copyright (c) 2002-2009 ymnk, JCraft,Inc. All rights reserved. | 3 | Copyright (c) 2002-2012 ymnk, JCraft,Inc. All rights reserved. |
4873 | 4 | 4 | ||
4874 | 5 | Redistribution and use in source and binary forms, with or without | 5 | Redistribution and use in source and binary forms, with or without |
4875 | 6 | modification, are permitted provided that the following conditions are met: | 6 | modification, are permitted provided that the following conditions are met: |
4876 | @@ -65,8 +65,8 @@ | |||
4877 | 65 | } | 65 | } |
4878 | 66 | } | 66 | } |
4879 | 67 | 67 | ||
4882 | 68 | private static final byte[] begin="-----BEGIN DSA PRIVATE KEY-----".getBytes(); | 68 | private static final byte[] begin=Util.str2byte("-----BEGIN DSA PRIVATE KEY-----"); |
4883 | 69 | private static final byte[] end="-----END DSA PRIVATE KEY-----".getBytes(); | 69 | private static final byte[] end=Util.str2byte("-----END DSA PRIVATE KEY-----"); |
4884 | 70 | 70 | ||
4885 | 71 | byte[] getBegin(){ return begin; } | 71 | byte[] getBegin(){ return begin; } |
4886 | 72 | byte[] getEnd(){ return end; } | 72 | byte[] getEnd(){ return end; } |
4887 | @@ -209,7 +209,7 @@ | |||
4888 | 209 | return buf.buffer; | 209 | return buf.buffer; |
4889 | 210 | } | 210 | } |
4890 | 211 | 211 | ||
4892 | 212 | private static final byte[] sshdss="ssh-dss".getBytes(); | 212 | private static final byte[] sshdss=Util.str2byte("ssh-dss"); |
4893 | 213 | byte[] getKeyTypeName(){return sshdss;} | 213 | byte[] getKeyTypeName(){return sshdss;} |
4894 | 214 | public int getKeyType(){return DSA;} | 214 | public int getKeyType(){return DSA;} |
4895 | 215 | 215 | ||
4896 | 216 | 216 | ||
4897 | === modified file 'src/main/java/com/jcraft/jsch/KeyPairGenDSA.java' | |||
4898 | --- src/com/jcraft/jsch/KeyPairGenDSA.java 2010-06-27 23:17:34 +0000 | |||
4899 | +++ src/main/java/com/jcraft/jsch/KeyPairGenDSA.java 2012-05-04 10:23:17 +0000 | |||
4900 | @@ -1,6 +1,6 @@ | |||
4901 | 1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ | 1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ |
4902 | 2 | /* | 2 | /* |
4904 | 3 | Copyright (c) 2002-2009 ymnk, JCraft,Inc. All rights reserved. | 3 | Copyright (c) 2002-2012 ymnk, JCraft,Inc. All rights reserved. |
4905 | 4 | 4 | ||
4906 | 5 | Redistribution and use in source and binary forms, with or without | 5 | Redistribution and use in source and binary forms, with or without |
4907 | 6 | modification, are permitted provided that the following conditions are met: | 6 | modification, are permitted provided that the following conditions are met: |
4908 | 7 | 7 | ||
4909 | === modified file 'src/main/java/com/jcraft/jsch/KeyPairGenRSA.java' | |||
4910 | --- src/com/jcraft/jsch/KeyPairGenRSA.java 2010-06-27 23:17:34 +0000 | |||
4911 | +++ src/main/java/com/jcraft/jsch/KeyPairGenRSA.java 2012-05-04 10:23:17 +0000 | |||
4912 | @@ -1,6 +1,6 @@ | |||
4913 | 1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ | 1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ |
4914 | 2 | /* | 2 | /* |
4916 | 3 | Copyright (c) 2002-2009 ymnk, JCraft,Inc. All rights reserved. | 3 | Copyright (c) 2002-2012 ymnk, JCraft,Inc. All rights reserved. |
4917 | 4 | 4 | ||
4918 | 5 | Redistribution and use in source and binary forms, with or without | 5 | Redistribution and use in source and binary forms, with or without |
4919 | 6 | modification, are permitted provided that the following conditions are met: | 6 | modification, are permitted provided that the following conditions are met: |
4920 | 7 | 7 | ||
4921 | === modified file 'src/main/java/com/jcraft/jsch/KeyPairRSA.java' | |||
4922 | --- src/com/jcraft/jsch/KeyPairRSA.java 2010-06-27 23:17:34 +0000 | |||
4923 | +++ src/main/java/com/jcraft/jsch/KeyPairRSA.java 2012-05-04 10:23:17 +0000 | |||
4924 | @@ -1,6 +1,6 @@ | |||
4925 | 1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ | 1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ |
4926 | 2 | /* | 2 | /* |
4928 | 3 | Copyright (c) 2002-2009 ymnk, JCraft,Inc. All rights reserved. | 3 | Copyright (c) 2002-2012 ymnk, JCraft,Inc. All rights reserved. |
4929 | 4 | 4 | ||
4930 | 5 | Redistribution and use in source and binary forms, with or without | 5 | Redistribution and use in source and binary forms, with or without |
4931 | 6 | modification, are permitted provided that the following conditions are met: | 6 | modification, are permitted provided that the following conditions are met: |
4932 | @@ -73,8 +73,8 @@ | |||
4933 | 73 | } | 73 | } |
4934 | 74 | } | 74 | } |
4935 | 75 | 75 | ||
4938 | 76 | private static final byte[] begin="-----BEGIN RSA PRIVATE KEY-----".getBytes(); | 76 | private static final byte[] begin=Util.str2byte("-----BEGIN RSA PRIVATE KEY-----"); |
4939 | 77 | private static final byte[] end="-----END RSA PRIVATE KEY-----".getBytes(); | 77 | private static final byte[] end=Util.str2byte("-----END RSA PRIVATE KEY-----"); |
4940 | 78 | 78 | ||
4941 | 79 | byte[] getBegin(){ return begin; } | 79 | byte[] getBegin(){ return begin; } |
4942 | 80 | byte[] getEnd(){ return end; } | 80 | byte[] getEnd(){ return end; } |
4943 | @@ -308,7 +308,7 @@ | |||
4944 | 308 | return buf.buffer; | 308 | return buf.buffer; |
4945 | 309 | } | 309 | } |
4946 | 310 | 310 | ||
4948 | 311 | private static final byte[] sshrsa="ssh-rsa".getBytes(); | 311 | private static final byte[] sshrsa=Util.str2byte("ssh-rsa"); |
4949 | 312 | byte[] getKeyTypeName(){return sshrsa;} | 312 | byte[] getKeyTypeName(){return sshrsa;} |
4950 | 313 | public int getKeyType(){return RSA;} | 313 | public int getKeyType(){return RSA;} |
4951 | 314 | 314 | ||
4952 | 315 | 315 | ||
4953 | === modified file 'src/main/java/com/jcraft/jsch/KnownHosts.java' | |||
4954 | --- src/com/jcraft/jsch/KnownHosts.java 2010-06-27 23:17:34 +0000 | |||
4955 | +++ src/main/java/com/jcraft/jsch/KnownHosts.java 2012-05-04 10:23:17 +0000 | |||
4956 | @@ -1,6 +1,6 @@ | |||
4957 | 1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ | 1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ |
4958 | 2 | /* | 2 | /* |
4960 | 3 | Copyright (c) 2002-2009 ymnk, JCraft,Inc. All rights reserved. | 3 | Copyright (c) 2002-2012 ymnk, JCraft,Inc. All rights reserved. |
4961 | 4 | 4 | ||
4962 | 5 | Redistribution and use in source and binary forms, with or without | 5 | Redistribution and use in source and binary forms, with or without |
4963 | 6 | modification, are permitted provided that the following conditions are met: | 6 | modification, are permitted provided that the following conditions are met: |
4964 | @@ -100,13 +100,13 @@ | |||
4965 | 100 | i=buf[j]; | 100 | i=buf[j]; |
4966 | 101 | if(i==' '||i=='\t'){ j++; continue; } | 101 | if(i==' '||i=='\t'){ j++; continue; } |
4967 | 102 | if(i=='#'){ | 102 | if(i=='#'){ |
4969 | 103 | addInvalidLine(new String(buf, 0, bufl)); | 103 | addInvalidLine(Util.byte2str(buf, 0, bufl)); |
4970 | 104 | continue loop; | 104 | continue loop; |
4971 | 105 | } | 105 | } |
4972 | 106 | break; | 106 | break; |
4973 | 107 | } | 107 | } |
4974 | 108 | if(j>=bufl){ | 108 | if(j>=bufl){ |
4976 | 109 | addInvalidLine(new String(buf, 0, bufl)); | 109 | addInvalidLine(Util.byte2str(buf, 0, bufl)); |
4977 | 110 | continue loop; | 110 | continue loop; |
4978 | 111 | } | 111 | } |
4979 | 112 | 112 | ||
4980 | @@ -118,7 +118,7 @@ | |||
4981 | 118 | } | 118 | } |
4982 | 119 | host=sb.toString(); | 119 | host=sb.toString(); |
4983 | 120 | if(j>=bufl || host.length()==0){ | 120 | if(j>=bufl || host.length()==0){ |
4985 | 121 | addInvalidLine(new String(buf, 0, bufl)); | 121 | addInvalidLine(Util.byte2str(buf, 0, bufl)); |
4986 | 122 | continue loop; | 122 | continue loop; |
4987 | 123 | } | 123 | } |
4988 | 124 | 124 | ||
4989 | @@ -133,7 +133,7 @@ | |||
4990 | 133 | else if(sb.toString().equals("ssh-rsa")){ type=HostKey.SSHRSA; } | 133 | else if(sb.toString().equals("ssh-rsa")){ type=HostKey.SSHRSA; } |
4991 | 134 | else { j=bufl; } | 134 | else { j=bufl; } |
4992 | 135 | if(j>=bufl){ | 135 | if(j>=bufl){ |
4994 | 136 | addInvalidLine(new String(buf, 0, bufl)); | 136 | addInvalidLine(Util.byte2str(buf, 0, bufl)); |
4995 | 137 | continue loop; | 137 | continue loop; |
4996 | 138 | } | 138 | } |
4997 | 139 | 139 | ||
4998 | @@ -146,7 +146,7 @@ | |||
4999 | 146 | } | 146 | } |
5000 | 147 | key=sb.toString(); | 147 | key=sb.toString(); |
The diff has been truncated for viewing.
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