├── .gitignore
├── ChangeLog
├── LICENSE.txt
├── README
├── build.bat
├── build.sh
├── build.xml
├── examples
├── AES.java
├── ChangePassphrase.java
├── Compression.java
├── Daemon.java
├── Exec.java
├── KeyGen.java
├── KnownHosts.java
├── Logger.java
├── OpenSSHConfig.java
├── PortForwardingL.java
├── PortForwardingR.java
├── README
├── ScpFrom.java
├── ScpTo.java
├── ScpToNoneCipher.java
├── Sftp.java
├── Shell.java
├── StreamForwarding.java
├── Subsystem.java
├── Sudo.java
├── UserAuthKI.java
├── UserAuthPubKey.java
├── ViaHTTP.java
├── ViaSOCKS5.java
└── X11Forwarding.java
├── pom.xml
├── simpleclasses.list
├── src
└── main
│ └── java
│ └── com
│ └── jcraft
│ └── jsch
│ ├── Buffer.java
│ ├── Channel.java
│ ├── ChannelAgentForwarding.java
│ ├── ChannelDirectTCPIP.java
│ ├── ChannelExec.java
│ ├── ChannelForwardedTCPIP.java
│ ├── ChannelSession.java
│ ├── ChannelSftp.java
│ ├── ChannelShell.java
│ ├── ChannelSubsystem.java
│ ├── ChannelX11.java
│ ├── Cipher.java
│ ├── CipherNone.java
│ ├── Compression.java
│ ├── ConfigRepository.java
│ ├── DH.java
│ ├── DHEC256.java
│ ├── DHEC384.java
│ ├── DHEC521.java
│ ├── DHECN.java
│ ├── DHG1.java
│ ├── DHG14.java
│ ├── DHGEX.java
│ ├── DHGEX256.java
│ ├── ECDH.java
│ ├── ForwardedTCPIPDaemon.java
│ ├── GSSContext.java
│ ├── HASH.java
│ ├── HostKey.java
│ ├── HostKeyRepository.java
│ ├── IO.java
│ ├── Identity.java
│ ├── IdentityFile.java
│ ├── IdentityRepository.java
│ ├── JSch.java
│ ├── JSchAuthCancelException.java
│ ├── JSchException.java
│ ├── JSchPartialAuthException.java
│ ├── KeyExchange.java
│ ├── KeyPair.java
│ ├── KeyPairDSA.java
│ ├── KeyPairECDSA.java
│ ├── KeyPairGenDSA.java
│ ├── KeyPairGenECDSA.java
│ ├── KeyPairGenRSA.java
│ ├── KeyPairPKCS8.java
│ ├── KeyPairRSA.java
│ ├── KnownHosts.java
│ ├── LocalIdentityRepository.java
│ ├── Logger.java
│ ├── MAC.java
│ ├── OpenSSHConfig.java
│ ├── PBKDF.java
│ ├── Packet.java
│ ├── PortWatcher.java
│ ├── Proxy.java
│ ├── ProxyHTTP.java
│ ├── ProxySOCKS4.java
│ ├── ProxySOCKS5.java
│ ├── Random.java
│ ├── Request.java
│ ├── RequestAgentForwarding.java
│ ├── RequestEnv.java
│ ├── RequestExec.java
│ ├── RequestPtyReq.java
│ ├── RequestSftp.java
│ ├── RequestShell.java
│ ├── RequestSignal.java
│ ├── RequestSubsystem.java
│ ├── RequestWindowChange.java
│ ├── RequestX11.java
│ ├── ServerSocketFactory.java
│ ├── Session.java
│ ├── SftpATTRS.java
│ ├── SftpException.java
│ ├── SftpProgressMonitor.java
│ ├── SftpStatVFS.java
│ ├── Signature.java
│ ├── SignatureDSA.java
│ ├── SignatureECDSA.java
│ ├── SignatureRSA.java
│ ├── SocketFactory.java
│ ├── UIKeyboardInteractive.java
│ ├── UserAuth.java
│ ├── UserAuthGSSAPIWithMIC.java
│ ├── UserAuthKeyboardInteractive.java
│ ├── UserAuthNone.java
│ ├── UserAuthPassword.java
│ ├── UserAuthPublicKey.java
│ ├── UserInfo.java
│ ├── Util.java
│ ├── jce
│ ├── AES128CBC.java
│ ├── AES128CTR.java
│ ├── AES192CBC.java
│ ├── AES192CTR.java
│ ├── AES256CBC.java
│ ├── AES256CTR.java
│ ├── ARCFOUR.java
│ ├── ARCFOUR128.java
│ ├── ARCFOUR256.java
│ ├── BlowfishCBC.java
│ ├── DH.java
│ ├── ECDH256.java
│ ├── ECDH384.java
│ ├── ECDH521.java
│ ├── ECDHN.java
│ ├── HMAC.java
│ ├── HMACMD5.java
│ ├── HMACMD596.java
│ ├── HMACSHA1.java
│ ├── HMACSHA196.java
│ ├── HMACSHA256.java
│ ├── HMACSHA512.java
│ ├── KeyPairGenDSA.java
│ ├── KeyPairGenECDSA.java
│ ├── KeyPairGenRSA.java
│ ├── MD5.java
│ ├── PBKDF.java
│ ├── Random.java
│ ├── SHA1.java
│ ├── SHA256.java
│ ├── SHA384.java
│ ├── SHA512.java
│ ├── SignatureDSA.java
│ ├── SignatureECDSA.java
│ ├── SignatureRSA.java
│ ├── TripleDESCBC.java
│ └── TripleDESCTR.java
│ ├── jcraft
│ ├── Compression.java
│ ├── HMAC.java
│ ├── HMACMD5.java
│ ├── HMACMD596.java
│ ├── HMACSHA1.java
│ └── HMACSHA196.java
│ ├── jgss
│ └── GSSContextKrb5.java
│ └── package-info.java
└── tools
└── bin
├── ant
├── ant.bat
├── antRun
├── antRun.bat
├── lcp.bat
├── runant.pl
└── runant.py
/.gitignore:
--------------------------------------------------------------------------------
1 | *.class
2 | /javadoc
3 | /simple.javadoc
4 | build/
5 | dist/
6 |
7 | *~
8 | semantic.cache
9 |
10 |
--------------------------------------------------------------------------------
/LICENSE.txt:
--------------------------------------------------------------------------------
1 | JSch 0.0.* was released under the GNU LGPL license. Later, we have switched
2 | over to a BSD-style license.
3 |
4 | ------------------------------------------------------------------------------
5 | Copyright (c) 2002-2015 Atsuhiko Yamanaka, JCraft,Inc.
6 | All rights reserved.
7 |
8 | Redistribution and use in source and binary forms, with or without
9 | modification, are permitted provided that the following conditions are met:
10 |
11 | 1. Redistributions of source code must retain the above copyright notice,
12 | this list of conditions and the following disclaimer.
13 |
14 | 2. Redistributions in binary form must reproduce the above copyright
15 | notice, this list of conditions and the following disclaimer in
16 | the documentation and/or other materials provided with the distribution.
17 |
18 | 3. The names of the authors may not be used to endorse or promote products
19 | derived from this software without specific prior written permission.
20 |
21 | THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
22 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
23 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
24 | INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
25 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
27 | OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30 | EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 |
--------------------------------------------------------------------------------
/build.bat:
--------------------------------------------------------------------------------
1 | @echo off
2 |
3 | echo.
4 | echo JSch Build System
5 | echo -----------------
6 |
7 | set OLD_ANT_HOME=%ANT_HOME%
8 | set ANT_HOME=tools
9 |
10 | set OLD_CLASSPATH=%CLASSPATH%
11 |
12 | %ANT_HOME%\bin\ant.bat -emacs %1 %2 %3 %4 %5 %6 %7 %8
13 | goto cleanup
14 |
15 | :cleanup
16 | set ANT_HOME=%OLD_ANT_HOME%
17 | set CLASSPATH=%OLD_CLASSPATH%
18 |
--------------------------------------------------------------------------------
/build.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | echo
4 | echo "JSch Build System"
5 | echo "-----------------"
6 |
7 | export OLD_ANT_HOME=$ANT_HOME
8 | ANT_HOME=./tools
9 |
10 | export OLD_CLASSPATH=$CLASSPATH
11 |
12 |
13 |
14 | export CLASSPATH
15 |
16 | chmod u+x ${ANT_HOME}/bin/antRun
17 | chmod u+x ${ANT_HOME}/bin/ant
18 |
19 | export PROPOSAL=""
20 |
21 |
22 | ${ANT_HOME}/bin/ant -emacs $@
23 |
24 | export CLASSPATH=$OLD_CLASSPATH
25 | export ANT_HOME=$OLD_ANT_HOME
26 |
--------------------------------------------------------------------------------
/examples/ChangePassphrase.java:
--------------------------------------------------------------------------------
1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
2 | /**
3 | * This program will demonstrate to change the passphrase for a
4 | * private key file instead of creating a new private key.
5 | * $ CLASSPATH=.:../build javac ChangePassphrase.java
6 | * $ CLASSPATH=.:../build java ChangePassphrase private-key
7 | * A passphrase will be prompted if the given private-key has been
8 | * encrypted. After successfully loading the content of the
9 | * private-key, the new passphrase will be prompted and the given
10 | * private-key will be re-encrypted with that new passphrase.
11 | *
12 | */
13 | import com.jcraft.jsch.*;
14 | import javax.swing.*;
15 |
16 | class ChangePassphrase{
17 | public static void main(String[] arg){
18 | if(arg.length!=1){
19 | System.err.println("usage: java ChangePassphrase private_key");
20 | System.exit(-1);
21 | }
22 |
23 | JSch jsch=new JSch();
24 |
25 | String pkey=arg[0];
26 |
27 | try{
28 | KeyPair kpair=KeyPair.load(jsch, pkey);
29 |
30 | System.out.println(pkey+" has "+(kpair.isEncrypted()?"been ":"not been ")+"encrypted");
31 |
32 | String passphrase="";
33 | while(kpair.isEncrypted()){
34 | JTextField passphraseField=(JTextField)new JPasswordField(20);
35 | Object[] ob={passphraseField};
36 | int result=JOptionPane.showConfirmDialog(null, ob,
37 | "Enter passphrase for "+pkey,
38 | JOptionPane.OK_CANCEL_OPTION);
39 | if(result!=JOptionPane.OK_OPTION){
40 | System.exit(-1);
41 | }
42 | passphrase=passphraseField.getText();
43 | if(!kpair.decrypt(passphrase)){
44 | System.out.println("failed to decrypt "+pkey);
45 | }
46 | else{
47 | System.out.println(pkey+" is decrypted.");
48 | }
49 | }
50 |
51 | passphrase="";
52 |
53 | JTextField passphraseField=(JTextField)new JPasswordField(20);
54 | Object[] ob={passphraseField};
55 | int result=JOptionPane.showConfirmDialog(null, ob,
56 | "Enter new passphrase for "+pkey+
57 | " (empty for no passphrase)",
58 | JOptionPane.OK_CANCEL_OPTION);
59 | if(result!=JOptionPane.OK_OPTION){
60 | System.exit(-1);
61 | }
62 | passphrase=passphraseField.getText();
63 |
64 | kpair.setPassphrase(passphrase);
65 | kpair.writePrivateKey(pkey);
66 | kpair.dispose();
67 | }
68 | catch(Exception e){
69 | System.out.println(e);
70 | }
71 | System.exit(0);
72 | }
73 | }
74 |
--------------------------------------------------------------------------------
/examples/KeyGen.java:
--------------------------------------------------------------------------------
1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
2 | /**
3 | * This progam will demonstrate the DSA keypair generation.
4 | * $ CLASSPATH=.:../build javac KeyGen.java
5 | * $ CLASSPATH=.:../build java KeyGen rsa output_keyfile comment
6 | * or
7 | * $ CLASSPATH=.:../build java KeyGen dsa output_keyfile comment
8 | * You will be asked a passphrase for output_keyfile.
9 | * If everything works fine, you will get the DSA or RSA keypair,
10 | * output_keyfile and output_keyfile+".pub".
11 | * The private key and public key are in the OpenSSH format.
12 | *
13 | */
14 | import com.jcraft.jsch.*;
15 | import javax.swing.*;
16 |
17 | class KeyGen{
18 | public static void main(String[] arg){
19 | int key_size = 1024;
20 | if(arg.length<3){
21 | System.err.println(
22 | "usage: java KeyGen rsa output_keyfile comment\n"+
23 | " java KeyGen dsa output_keyfile comment\n"+
24 | " java KeyGen ecdsa-sha2-256 output_keyfile comment\n"+
25 | " java KeyGen ecdsa-sha2-384 output_keyfile comment\n"+
26 | " java KeyGen ecdsa-sha2-521 output_keyfile comment");
27 | System.exit(-1);
28 | }
29 | String _type=arg[0];
30 | int type=0;
31 | if(_type.equals("rsa")){type=KeyPair.RSA;}
32 | else if(_type.equals("dsa")){type=KeyPair.DSA;}
33 | else if(_type.equals("ecdsa-sha2-nistp256")){
34 | type=KeyPair.ECDSA;
35 | key_size=256;
36 | }
37 | else if(_type.equals("ecdsa-sha2-nistp384")){
38 | type=KeyPair.ECDSA;
39 | key_size=384;
40 | }
41 | else if(_type.equals("ecdsa-sha2-nistp521")){
42 | type=KeyPair.ECDSA;
43 | key_size=521;
44 | }
45 | else {
46 | System.err.println(
47 | "usage: java KeyGen rsa output_keyfile comment\n"+
48 | " java KeyGen dsa output_keyfile comment\n"+
49 | " java KeyGen ecdsa-sha2-256 output_keyfile comment\n"+
50 | " java KeyGen ecdsa-sha2-384 output_keyfile comment\n"+
51 | " java KeyGen ecdsa-sha2-521 output_keyfile comment");
52 | System.exit(-1);
53 | }
54 | String filename=arg[1];
55 | String comment=arg[2];
56 |
57 | JSch jsch=new JSch();
58 |
59 | String passphrase="";
60 | JTextField passphraseField=(JTextField)new JPasswordField(20);
61 | Object[] ob={passphraseField};
62 | int result=
63 | JOptionPane.showConfirmDialog(null, ob, "Enter passphrase (empty for no passphrase)",
64 | JOptionPane.OK_CANCEL_OPTION);
65 | if(result==JOptionPane.OK_OPTION){
66 | passphrase=passphraseField.getText();
67 | }
68 |
69 | try{
70 | KeyPair kpair=KeyPair.genKeyPair(jsch, type, key_size);
71 | kpair.setPassphrase(passphrase);
72 | kpair.writePrivateKey(filename);
73 | kpair.writePublicKey(filename+".pub", comment);
74 | System.out.println("Finger print: "+kpair.getFingerPrint());
75 | kpair.dispose();
76 | }
77 | catch(Exception e){
78 | System.out.println(e);
79 | }
80 | System.exit(0);
81 | }
82 | }
83 |
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
39 | * {@link Session#openChannel session.openChannel} ("shell") 40 | *41 | * @see RFC 4254, 42 | * section 6.5. Starting a Shell or a Command 43 | */ 44 | public class ChannelShell extends ChannelSession{ 45 | 46 | ChannelShell(){ 47 | super(); 48 | pty=true; 49 | } 50 | 51 | // javadoc is copied from superclass -- P.E. 52 | public void start() throws JSchException{ 53 | Session _session=getSession(); 54 | try{ 55 | sendRequests(); 56 | 57 | Request request=new RequestShell(); 58 | request.request(_session, this); 59 | } 60 | catch(Exception e){ 61 | if(e instanceof JSchException) throw (JSchException)e; 62 | if(e instanceof Throwable) 63 | throw new JSchException("ChannelShell", (Throwable)e); 64 | throw new JSchException("ChannelShell"); 65 | } 66 | 67 | if(io.in!=null){ 68 | thread=new Thread(this); 69 | thread.setName("Shell for "+_session.host); 70 | if(_session.daemon_thread){ 71 | thread.setDaemon(_session.daemon_thread); 72 | } 73 | thread.start(); 74 | } 75 | } 76 | 77 | void init() throws JSchException { 78 | io.setInputStream(getSession().in); 79 | io.setOutputStream(getSession().out); 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /src/main/java/com/jcraft/jsch/CipherNone.java: -------------------------------------------------------------------------------- 1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ 2 | /* 3 | Copyright (c) 2002-2016 ymnk, JCraft,Inc. All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | 1. Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | 11 | 2. Redistributions in binary form must reproduce the above copyright 12 | notice, this list of conditions and the following disclaimer in 13 | the documentation and/or other materials provided with the distribution. 14 | 15 | 3. The names of the authors may not be used to endorse or promote products 16 | derived from this software without specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, 19 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 20 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT, 21 | INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT, 22 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 24 | OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 25 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 26 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 27 | EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | package com.jcraft.jsch; 31 | 32 | /** 33 | * Usually not to be used by applications. 34 | * An implementation of the Cipher {@code none}, i.e. unencrypted transport. 35 | * This is used during key-exchange until the first real Cipher can be used. 36 | * 37 | *
38 | * The "none" algorithm specifies that no encryption is to be done. 39 | * Note that this method provides no confidentiality protection, and it 40 | * is NOT RECOMMENDED. Some functionality (e.g., password 41 | * authentication) may be disabled for security reasons if this cipher 42 | * is chosen. 43 | *44 | * 45 | * The implementation here consists mainly of no-ops. 46 | * 47 | * @see RFC 4253, 48 | * section 6.3 Encryption 49 | * @see RFC 2410, 50 | * The NULL Encryption Algorithm and Its Use With IPsec 51 | */ 52 | public class CipherNone implements Cipher{ 53 | private static final int ivsize=8; 54 | private static final int bsize=16; 55 | public int getIVSize(){return ivsize;} 56 | public int getBlockSize(){return bsize;} 57 | public void init(int mode, byte[] key, byte[] iv) throws Exception{ 58 | } 59 | public void update(byte[] foo, int s1, int len, byte[] bar, int s2) throws Exception{ 60 | } 61 | public boolean isCBC(){return false; } 62 | } 63 | -------------------------------------------------------------------------------- /src/main/java/com/jcraft/jsch/DHEC256.java: -------------------------------------------------------------------------------- 1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ 2 | /* 3 | Copyright (c) 2015-2016 ymnk, JCraft,Inc. All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | 1. Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | 11 | 2. Redistributions in binary form must reproduce the above copyright 12 | notice, this list of conditions and the following disclaimer in 13 | the documentation and/or other materials provided with the distribution. 14 | 15 | 3. The names of the authors may not be used to endorse or promote products 16 | derived from this software without specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, 19 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 20 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT, 21 | INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT, 22 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 24 | OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 25 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 26 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 27 | EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | package com.jcraft.jsch; 31 | 32 | public class DHEC256 extends DHECN { 33 | public DHEC256(){ 34 | sha_name="sha-256"; 35 | key_size=256; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/com/jcraft/jsch/DHEC384.java: -------------------------------------------------------------------------------- 1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ 2 | /* 3 | Copyright (c) 2015-2016 ymnk, JCraft,Inc. All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | 1. Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | 11 | 2. Redistributions in binary form must reproduce the above copyright 12 | notice, this list of conditions and the following disclaimer in 13 | the documentation and/or other materials provided with the distribution. 14 | 15 | 3. The names of the authors may not be used to endorse or promote products 16 | derived from this software without specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, 19 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 20 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT, 21 | INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT, 22 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 24 | OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 25 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 26 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 27 | EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | package com.jcraft.jsch; 31 | 32 | public class DHEC384 extends DHECN { 33 | public DHEC384(){ 34 | sha_name="sha-384"; 35 | key_size=384; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/com/jcraft/jsch/DHEC521.java: -------------------------------------------------------------------------------- 1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ 2 | /* 3 | Copyright (c) 2015-2016 ymnk, JCraft,Inc. All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | 1. Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | 11 | 2. Redistributions in binary form must reproduce the above copyright 12 | notice, this list of conditions and the following disclaimer in 13 | the documentation and/or other materials provided with the distribution. 14 | 15 | 3. The names of the authors may not be used to endorse or promote products 16 | derived from this software without specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, 19 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 20 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT, 21 | INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT, 22 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 24 | OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 25 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 26 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 27 | EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | package com.jcraft.jsch; 31 | 32 | public class DHEC521 extends DHECN { 33 | public DHEC521(){ 34 | sha_name="sha-512"; 35 | key_size=521; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/com/jcraft/jsch/DHGEX256.java: -------------------------------------------------------------------------------- 1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ 2 | /* 3 | Copyright (c) 2002-2016 ymnk, JCraft,Inc. All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | 1. Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | 11 | 2. Redistributions in binary form must reproduce the above copyright 12 | notice, this list of conditions and the following disclaimer in 13 | the documentation and/or other materials provided with the distribution. 14 | 15 | 3. The names of the authors may not be used to endorse or promote products 16 | derived from this software without specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, 19 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 20 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT, 21 | INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT, 22 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 24 | OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 25 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 26 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 27 | EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | package com.jcraft.jsch; 31 | 32 | public class DHGEX256 extends DHGEX { 33 | DHGEX256(){ 34 | hash="sha-256"; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/com/jcraft/jsch/ECDH.java: -------------------------------------------------------------------------------- 1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ 2 | /* 3 | Copyright (c) 2015-2016 ymnk, JCraft,Inc. All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | 1. Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | 11 | 2. Redistributions in binary form must reproduce the above copyright 12 | notice, this list of conditions and the following disclaimer in 13 | the documentation and/or other materials provided with the distribution. 14 | 15 | 3. The names of the authors may not be used to endorse or promote products 16 | derived from this software without specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, 19 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 20 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT, 21 | INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT, 22 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 24 | OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 25 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 26 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 27 | EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | package com.jcraft.jsch; 31 | 32 | 33 | /** 34 | * Usually not to be used by applications. 35 | * An interface with the mathematical operations needed for the Elliptic Curve Diffie Hellman key exchanges. 36 | * Might be implemented to provide optimized operations for some curve. 37 | * Its implementation class name needs to be given to {@link Jsch#setConfig Jsch.setConfig("ecdh-sha2-nistp")}.} 38 | * @since 0.1.52 39 | */ 40 | public interface ECDH { 41 | 42 | /** 43 | * Initializes this instance for key pairs of a specific size. 44 | */ 45 | void init(int size) throws Exception; 46 | 47 | /** 48 | * calculates and returns the shared secret for this key exchange. 49 | * @param r the x coordinate of the remote partner's point, encoded as a byte[]. 50 | * @param s the y coordinate of the remote partner's point, encoded as a byte[]. 51 | * @return the shared secret, in the form of a byte[]. 52 | * @throws Exception if anything goes wrong. 53 | */ 54 | byte[] getSecret(byte[] r, byte[] s) throws Exception; 55 | 56 | /** 57 | * Retrieves the public key (i.e. an elliptic curve point) to be sent to the remote side. 58 | * @return the point, encoded as a byte[]. 59 | * @throws Exception if anything goes wrong. 60 | */ 61 | byte[] getQ() throws Exception; 62 | 63 | /** 64 | * Validates a public key (i.e. an elliptic curve point) sent by the remote side. 65 | * @param r the x coordinate of the point, encoded as a byte[]. 66 | * @param s the y coordinate of the point, encoded as a byte[]. 67 | * @return true if the given point is actually on the curve, false otherwise. 68 | * @throws Exception if anything goes wrong. 69 | */ 70 | boolean validate(byte[] r, byte[] s) throws Exception; 71 | } 72 | -------------------------------------------------------------------------------- /src/main/java/com/jcraft/jsch/HASH.java: -------------------------------------------------------------------------------- 1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ 2 | /* 3 | Copyright (c) 2002-2016 ymnk, JCraft,Inc. All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | 1. Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | 11 | 2. Redistributions in binary form must reproduce the above copyright 12 | notice, this list of conditions and the following disclaimer in 13 | the documentation and/or other materials provided with the distribution. 14 | 15 | 3. The names of the authors may not be used to endorse or promote products 16 | derived from this software without specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, 19 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 20 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT, 21 | INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT, 22 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 24 | OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 25 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 26 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 27 | EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | package com.jcraft.jsch; 31 | 32 | /** 33 | * Usually not to be used by applications. 34 | * The interface for a (cryptographic) Hash algorithm. 35 | *
36 | * This is a slimmed-down version of {@link java.security.MessageDigest}. 37 | *
38 | *39 | * Several parts of the library will look up the implementation class to 40 | * use in the {@linkplain JSch#setConfig configuration} and then instantiate 41 | * it using the no-argument constructor. The used algorithm names are only 42 | * "md5" and "sha-1", for now. 43 | *
44 | *45 | * The library includes default implementations of MD5 and SHA-1 based 46 | * on Java's MessageDigest. 47 | *
48 | */ 49 | public interface HASH{ 50 | /** 51 | * initializes the algorithm for new input data. 52 | * This will be called before the first call to {@link #update}. 53 | */ 54 | void init() throws Exception; 55 | 56 | /** 57 | * returns the size of the hash which will be produced from input. 58 | * This usually will be a constant function, like 16 for MD5 and 59 | * 20 for SHA1. 60 | * @return the length of the produced hash, in bytes. 61 | * @see java.security.MessageDigest#getDigestLength MessageDigest.getDigestLength() 62 | */ 63 | int getBlockSize(); 64 | 65 | /** 66 | * Updates the algorithm with new data. 67 | * The data will not be changed, only our internal state. 68 | * @param foo an array containing new data to hash. 69 | * @param start the index of the start of the data in {@code foo}. 70 | * @param len the length of the new added data. 71 | * @see java.security.MessageDigest#update(byte[], start, len) MessageDigest.update() 72 | */ 73 | void update(byte[] foo, int start, int len) throws Exception; 74 | 75 | /** 76 | * calculates and returns the digest for all the data 77 | * hashed up so far. 78 | * @return an array containing the hash. This will have length 79 | * {@link #getBlockSize}. 80 | * @see java.security.MessageDigest#digest() MessageDigest.digest() 81 | */ 82 | byte[] digest() throws Exception; 83 | } 84 | -------------------------------------------------------------------------------- /src/main/java/com/jcraft/jsch/JSchAuthCancelException.java: -------------------------------------------------------------------------------- 1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ 2 | /* 3 | Copyright (c) 2002-2016 ymnk, JCraft,Inc. All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | 1. Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | 11 | 2. Redistributions in binary form must reproduce the above copyright 12 | notice, this list of conditions and the following disclaimer in 13 | the documentation and/or other materials provided with the distribution. 14 | 15 | 3. The names of the authors may not be used to endorse or promote products 16 | derived from this software without specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, 19 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 20 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT, 21 | INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT, 22 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 24 | OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 25 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 26 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 27 | EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | package com.jcraft.jsch; 31 | 32 | class JSchAuthCancelException extends JSchException{ 33 | //private static final long serialVersionUID=3204965907117900987L; 34 | String method; 35 | JSchAuthCancelException () { 36 | super(); 37 | } 38 | JSchAuthCancelException (String s) { 39 | super(s); 40 | this.method=s; 41 | } 42 | public String getMethod(){ 43 | return method; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/com/jcraft/jsch/JSchException.java: -------------------------------------------------------------------------------- 1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ 2 | /* 3 | Copyright (c) 2002-2016 ymnk, JCraft,Inc. All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | 1. Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | 11 | 2. Redistributions in binary form must reproduce the above copyright 12 | notice, this list of conditions and the following disclaimer in 13 | the documentation and/or other materials provided with the distribution. 14 | 15 | 3. The names of the authors may not be used to endorse or promote products 16 | derived from this software without specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, 19 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 20 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT, 21 | INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT, 22 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 24 | OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 25 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 26 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 27 | EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | package com.jcraft.jsch; 31 | 32 | /** 33 | * Will be thrown if anything goes wrong with the SSH protocol. 34 | */ 35 | public class JSchException extends Exception{ 36 | // we reimplement the 'cause'/getCause mechanism 37 | // because we want to be usable with pre-1.4 38 | // JREs, too. (I suppose.) -- P.E. 39 | 40 | //private static final long serialVersionUID=-1319309923966731989L; 41 | private Throwable cause=null; 42 | /** 43 | * Creates a JSchException without message. 44 | */ 45 | public JSchException () { 46 | super(); 47 | } 48 | 49 | /** 50 | * Creates a JSchException with message. 51 | */ 52 | public JSchException (String s) { 53 | super(s); 54 | } 55 | 56 | /** 57 | * Creates a JSchException with message and cause 58 | * @param s the message to be shown to the user. 59 | * @param e a nested Throwable, which indicates the cause of this Exception. 60 | */ 61 | public JSchException (String s, Throwable e) { 62 | super(s); 63 | this.cause=e; 64 | } 65 | 66 | /** 67 | * retrieves the cause. 68 | */ 69 | public Throwable getCause(){ 70 | return this.cause; 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /src/main/java/com/jcraft/jsch/JSchPartialAuthException.java: -------------------------------------------------------------------------------- 1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ 2 | /* 3 | Copyright (c) 2002-2016 ymnk, JCraft,Inc. All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | 1. Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | 11 | 2. Redistributions in binary form must reproduce the above copyright 12 | notice, this list of conditions and the following disclaimer in 13 | the documentation and/or other materials provided with the distribution. 14 | 15 | 3. The names of the authors may not be used to endorse or promote products 16 | derived from this software without specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, 19 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 20 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT, 21 | INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT, 22 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 24 | OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 25 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 26 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 27 | EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | package com.jcraft.jsch; 31 | 32 | class JSchPartialAuthException extends JSchException{ 33 | //private static final long serialVersionUID=-378849862323360367L; 34 | String methods; 35 | public JSchPartialAuthException () { 36 | super(); 37 | } 38 | public JSchPartialAuthException (String s) { 39 | super(s); 40 | this.methods=s; 41 | } 42 | public String getMethods(){ 43 | return methods; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/com/jcraft/jsch/KeyPairGenDSA.java: -------------------------------------------------------------------------------- 1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ 2 | /* 3 | Copyright (c) 2002-2016 ymnk, JCraft,Inc. All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | 1. Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | 11 | 2. Redistributions in binary form must reproduce the above copyright 12 | notice, this list of conditions and the following disclaimer in 13 | the documentation and/or other materials provided with the distribution. 14 | 15 | 3. The names of the authors may not be used to endorse or promote products 16 | derived from this software without specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, 19 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 20 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT, 21 | INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT, 22 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 24 | OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 25 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 26 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 27 | EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | package com.jcraft.jsch; 31 | 32 | /** 33 | * Usually not to be used by applications. 34 | * A generator for a DSA key pair. 35 | *36 | * The library contains a default implementation of this class, based on 37 | * the JCE classes available in Java SE from 1.4. 38 | *
39 | *40 | * The actual implementation class is chosen by the configuration option 41 | * {@code "keypairgen.dsa"}, and then instantiated using the no-argument 42 | * constructor. The library uses each instance only for one key generation. 43 | *
44 | *45 | * This object will create a DSA key pair, consisting of a public key 46 | * ({@link #getP p}, {@link #getQ q}, {@link #getG g}, {@link #getY y}) 47 | * and a private key {@link #getX x}.
48 | *49 | * Here {@code q} is a 160-bit prime (when using SHA-1), 50 | * {@code p} a prime of the given key size such that 51 | * {@code p-1} is a multiple of {@code q}, {@code g} is a generator of a 52 | * multiplicative subgroup of order {@code q} of {@code (Z/pZ)^*}. 53 | * {@code p}, {@code q} and {@code g} are called 54 | * community parameters and can be shared by many keys (some 55 | * implementations may have precalculated ones). 56 | *
57 | *58 | * {@code x} is a random number with {@code 0 < x < q}, and 59 | * {@code y = g^x mod p} - these two numbers are key pair specific, and 60 | * {@code x} must be preserved secretely. 61 | *
62 | */ 63 | public interface KeyPairGenDSA { 64 | /** 65 | * Generates a key pair. 66 | * The other methods can then be called to retrieve 67 | * the key components. 68 | * @param key_size the number of bits of the key to be produced. 69 | */ 70 | void init(int key_size) throws Exception; 71 | 72 | /** 73 | * The secret key {@code x}. 74 | */ 75 | byte[] getX(); 76 | /** 77 | * The public key {@code y = g^x mod p}. 78 | */ 79 | byte[] getY(); 80 | 81 | /** 82 | * The modulus {@code p}, a prime. 83 | */ 84 | byte[] getP(); 85 | 86 | /** 87 | * The order {@code q} of the subgroup of (Z/pZ)^* generated by {@code g}, 88 | * also prime. 89 | */ 90 | byte[] getQ(); 91 | 92 | /** 93 | * The generator {@code g} of the subgroup. 94 | */ 95 | byte[] getG(); 96 | } 97 | -------------------------------------------------------------------------------- /src/main/java/com/jcraft/jsch/KeyPairGenECDSA.java: -------------------------------------------------------------------------------- 1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ 2 | /* 3 | Copyright (c) 2015-2016 ymnk, JCraft,Inc. All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | 1. Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | 11 | 2. Redistributions in binary form must reproduce the above copyright 12 | notice, this list of conditions and the following disclaimer in 13 | the documentation and/or other materials provided with the distribution. 14 | 15 | 3. The names of the authors may not be used to endorse or promote products 16 | derived from this software without specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, 19 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 20 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT, 21 | INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT, 22 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 24 | OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 25 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 26 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 27 | EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | package com.jcraft.jsch; 31 | 32 | /** 33 | * Usually not to be used by applications. 34 | * A generator for a ECDSA key pair. 35 | *36 | * The library contains a default implementation of this class, based on 37 | * the JCE classes available in Java SE from 1.4. 38 | *
39 | *40 | * The actually used implementation class is chosen by the configuration option 41 | * {@code "keypairgen.ecdsa"}, and then instantiated using the no-argument 42 | * constructor. The library uses each instance only for one key generation. 43 | *
44 | * @since 0.1.52 45 | */ 46 | public interface KeyPairGenECDSA{ 47 | void init(int key_size) throws Exception; 48 | byte[] getD(); 49 | byte[] getR(); 50 | byte[] getS(); 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/com/jcraft/jsch/PBKDF.java: -------------------------------------------------------------------------------- 1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ 2 | /* 3 | Copyright (c) 2013-2016 ymnk, JCraft,Inc. All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | 1. Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | 11 | 2. Redistributions in binary form must reproduce the above copyright 12 | notice, this list of conditions and the following disclaimer in 13 | the documentation and/or other materials provided with the distribution. 14 | 15 | 3. The names of the authors may not be used to endorse or promote products 16 | derived from this software without specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, 19 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 20 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT, 21 | INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT, 22 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 24 | OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 25 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 26 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 27 | EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | package com.jcraft.jsch; 31 | 32 | /** 33 | * The PBKDF2 algorithm for password-based key derivation. 34 | * The library contains an implementation based on javax.crypto, 35 | * but applications could provide their own alternatives. 36 | * The actually used implementation's class name is given by the configuration 37 | * {@code pbkdf}. 38 | * @since 0.1.51 39 | */ 40 | public interface PBKDF { 41 | /** 42 | * Derives a key from a password and a salt. 43 | * @param pass the password. 44 | * @param salt the salt. 45 | * @param iteration the iteration count. 46 | * @param size the desired output size. 47 | * @return the derived key, as a byte[]. 48 | */ 49 | byte[] getKey(byte[] pass, byte[] salt, int iteration, int size); 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/com/jcraft/jsch/Random.java: -------------------------------------------------------------------------------- 1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ 2 | /* 3 | Copyright (c) 2002-2016 ymnk, JCraft,Inc. All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | 1. Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | 11 | 2. Redistributions in binary form must reproduce the above copyright 12 | notice, this list of conditions and the following disclaimer in 13 | the documentation and/or other materials provided with the distribution. 14 | 15 | 3. The names of the authors may not be used to endorse or promote products 16 | derived from this software without specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, 19 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 20 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT, 21 | INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT, 22 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 24 | OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 25 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 26 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 27 | EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | package com.jcraft.jsch; 31 | 32 | /** 33 | * A random number generator. 34 | *35 | * The library used an object (or in fact, multiple ones in different places) 36 | * implementing this interface to generate random numbers. These are used for 37 | * several purposes: 38 | *
45 | * The library will choose the implementation class by the configuration 46 | * option {@code random}, and instantiate it using the no-argument 47 | * constructor. 48 | *
49 | *50 | * The library includes a default implementation, based on a 51 | * {@link java.security.SecureRandom new SecureRandom()}. 52 | *
53 | *54 | * An application might implement this interface to provide an alternative 55 | * random number generator, maybe based on some hardware device. 56 | *
57 | */ 58 | public interface Random{ 59 | 60 | /** 61 | * Fills a segment of a byte array with random bits. 62 | * @param foo the array to put the random data into. 63 | * @param start the position in the array from where on the random data 64 | * should be put. 65 | * @param len the length of the segment to be filled with random data, 66 | * in bytes. There will be {@code 8 * len} random bits generated. 67 | */ 68 | void fill(byte[] foo, int start, int len); 69 | } 70 | -------------------------------------------------------------------------------- /src/main/java/com/jcraft/jsch/Request.java: -------------------------------------------------------------------------------- 1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ 2 | /* 3 | Copyright (c) 2002-2016 ymnk, JCraft,Inc. All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | 1. Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | 11 | 2. Redistributions in binary form must reproduce the above copyright 12 | notice, this list of conditions and the following disclaimer in 13 | the documentation and/or other materials provided with the distribution. 14 | 15 | 3. The names of the authors may not be used to endorse or promote products 16 | derived from this software without specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, 19 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 20 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT, 21 | INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT, 22 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 24 | OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 25 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 26 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 27 | EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | package com.jcraft.jsch; 31 | 32 | /** 33 | * This abstract base class represents a 34 | * channel-specific request (SSH_MSG_CHANNEL_REQUEST) to be sent 35 | * to the remote side. 36 | * 37 | * These request classes are used only internally, and should not be public. 38 | */ 39 | abstract class Request{ 40 | private boolean reply=false; 41 | private Session session=null; 42 | private Channel channel=null; 43 | void request(Session session, Channel channel) throws Exception{ 44 | this.session=session; 45 | this.channel=channel; 46 | if(channel.connectTimeout>0){ 47 | setReply(true); 48 | } 49 | } 50 | boolean waitForReply(){ return reply; } 51 | void setReply(boolean reply){ this.reply=reply; } 52 | void write(Packet packet) throws Exception{ 53 | if(reply){ 54 | channel.reply=-1; 55 | } 56 | session.write(packet); 57 | if(reply){ 58 | long start=System.currentTimeMillis(); 59 | long timeout=channel.connectTimeout; 60 | while(channel.isConnected() && channel.reply==-1){ 61 | try{Thread.sleep(10);} 62 | catch(Exception ee){ 63 | } 64 | if(timeout>0L && 65 | (System.currentTimeMillis()-start)>timeout){ 66 | channel.reply=0; 67 | throw new JSchException("channel request: timeout"); 68 | } 69 | } 70 | 71 | if(channel.reply==0){ 72 | throw new JSchException("failed to send channel request"); 73 | } 74 | } 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /src/main/java/com/jcraft/jsch/RequestAgentForwarding.java: -------------------------------------------------------------------------------- 1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ 2 | /* 3 | Copyright (c) 2006-2016 ymnk, JCraft,Inc. All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | 1. Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | 11 | 2. Redistributions in binary form must reproduce the above copyright 12 | notice, this list of conditions and the following disclaimer in 13 | the documentation and/or other materials provided with the distribution. 14 | 15 | 3. The names of the authors may not be used to endorse or promote products 16 | derived from this software without specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, 19 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 20 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT, 21 | INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT, 22 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 24 | OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 25 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 26 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 27 | EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | package com.jcraft.jsch; 31 | 32 | /** 33 | * A request to enable forwarding of SSH authentication agent 34 | * requests. 35 | */ 36 | class RequestAgentForwarding extends Request{ 37 | public void request(Session session, Channel channel) throws Exception{ 38 | super.request(session, channel); 39 | 40 | setReply(false); 41 | 42 | Buffer buf=new Buffer(); 43 | Packet packet=new Packet(buf); 44 | 45 | // byte SSH_MSG_CHANNEL_REQUEST(98) 46 | // uint32 recipient channel 47 | // string request type // "auth-agent-req@openssh.com" 48 | // boolean want reply // 0 49 | packet.reset(); 50 | buf.putByte((byte) Session.SSH_MSG_CHANNEL_REQUEST); 51 | buf.putInt(channel.getRecipient()); 52 | buf.putString(Util.str2byte("auth-agent-req@openssh.com")); 53 | buf.putByte((byte)(waitForReply() ? 1 : 0)); 54 | write(packet); 55 | session.agent_forwarding=true; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/main/java/com/jcraft/jsch/RequestEnv.java: -------------------------------------------------------------------------------- 1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ 2 | /* 3 | Copyright (c) 2002-2016 ymnk, JCraft,Inc. All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | 1. Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | 11 | 2. Redistributions in binary form must reproduce the above copyright 12 | notice, this list of conditions and the following disclaimer in 13 | the documentation and/or other materials provided with the distribution. 14 | 15 | 3. The names of the authors may not be used to endorse or promote products 16 | derived from this software without specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, 19 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 20 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT, 21 | INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT, 22 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 24 | OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 25 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 26 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 27 | EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | package com.jcraft.jsch; 31 | 32 | class RequestEnv extends Request{ 33 | byte[] name=new byte[0]; 34 | byte[] value=new byte[0]; 35 | void setEnv(byte[] name, byte[] value){ 36 | this.name=name; 37 | this.value=value; 38 | } 39 | public void request(Session session, Channel channel) throws Exception{ 40 | super.request(session, channel); 41 | 42 | Buffer buf=new Buffer(); 43 | Packet packet=new Packet(buf); 44 | 45 | packet.reset(); 46 | buf.putByte((byte) Session.SSH_MSG_CHANNEL_REQUEST); 47 | buf.putInt(channel.getRecipient()); 48 | buf.putString(Util.str2byte("env")); 49 | buf.putByte((byte)(waitForReply() ? 1 : 0)); 50 | buf.putString(name); 51 | buf.putString(value); 52 | write(packet); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/com/jcraft/jsch/RequestExec.java: -------------------------------------------------------------------------------- 1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ 2 | /* 3 | Copyright (c) 2002-2016 ymnk, JCraft,Inc. All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | 1. Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | 11 | 2. Redistributions in binary form must reproduce the above copyright 12 | notice, this list of conditions and the following disclaimer in 13 | the documentation and/or other materials provided with the distribution. 14 | 15 | 3. The names of the authors may not be used to endorse or promote products 16 | derived from this software without specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, 19 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 20 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT, 21 | INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT, 22 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 24 | OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 25 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 26 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 27 | EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | package com.jcraft.jsch; 31 | 32 | class RequestExec extends Request{ 33 | private byte[] command=new byte[0]; 34 | RequestExec(byte[] command){ 35 | this.command=command; 36 | } 37 | public void request(Session session, Channel channel) throws Exception{ 38 | super.request(session, channel); 39 | 40 | Buffer buf=new Buffer(); 41 | Packet packet=new Packet(buf); 42 | 43 | // send 44 | // byte SSH_MSG_CHANNEL_REQUEST(98) 45 | // uint32 recipient channel 46 | // string request type // "exec" 47 | // boolean want reply // 0 48 | // string command 49 | packet.reset(); 50 | buf.putByte((byte) Session.SSH_MSG_CHANNEL_REQUEST); 51 | buf.putInt(channel.getRecipient()); 52 | buf.putString(Util.str2byte("exec")); 53 | buf.putByte((byte)(waitForReply() ? 1 : 0)); 54 | buf.checkFreeSize(4+command.length); 55 | buf.putString(command); 56 | write(packet); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/main/java/com/jcraft/jsch/RequestPtyReq.java: -------------------------------------------------------------------------------- 1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ 2 | /* 3 | Copyright (c) 2002-2016 ymnk, JCraft,Inc. All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | 1. Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | 11 | 2. Redistributions in binary form must reproduce the above copyright 12 | notice, this list of conditions and the following disclaimer in 13 | the documentation and/or other materials provided with the distribution. 14 | 15 | 3. The names of the authors may not be used to endorse or promote products 16 | derived from this software without specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, 19 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 20 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT, 21 | INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT, 22 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 24 | OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 25 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 26 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 27 | EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | package com.jcraft.jsch; 31 | 32 | class RequestPtyReq extends Request{ 33 | private String ttype="vt100"; 34 | private int tcol=80; 35 | private int trow=24; 36 | private int twp=640; 37 | private int thp=480; 38 | 39 | private byte[] terminal_mode=Util.empty; 40 | 41 | void setCode(String cookie){ 42 | } 43 | 44 | void setTType(String ttype){ 45 | this.ttype=ttype; 46 | } 47 | 48 | void setTerminalMode(byte[] terminal_mode){ 49 | this.terminal_mode=terminal_mode; 50 | } 51 | 52 | void setTSize(int tcol, int trow, int twp, int thp){ 53 | this.tcol=tcol; 54 | this.trow=trow; 55 | this.twp=twp; 56 | this.thp=thp; 57 | } 58 | 59 | public void request(Session session, Channel channel) throws Exception{ 60 | super.request(session, channel); 61 | 62 | Buffer buf=new Buffer(); 63 | Packet packet=new Packet(buf); 64 | 65 | packet.reset(); 66 | buf.putByte((byte) Session.SSH_MSG_CHANNEL_REQUEST); 67 | buf.putInt(channel.getRecipient()); 68 | buf.putString(Util.str2byte("pty-req")); 69 | buf.putByte((byte)(waitForReply() ? 1 : 0)); 70 | buf.putString(Util.str2byte(ttype)); 71 | buf.putInt(tcol); 72 | buf.putInt(trow); 73 | buf.putInt(twp); 74 | buf.putInt(thp); 75 | buf.putString(terminal_mode); 76 | write(packet); 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /src/main/java/com/jcraft/jsch/RequestSftp.java: -------------------------------------------------------------------------------- 1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ 2 | /* 3 | Copyright (c) 2002-2016 ymnk, JCraft,Inc. All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | 1. Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | 11 | 2. Redistributions in binary form must reproduce the above copyright 12 | notice, this list of conditions and the following disclaimer in 13 | the documentation and/or other materials provided with the distribution. 14 | 15 | 3. The names of the authors may not be used to endorse or promote products 16 | derived from this software without specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, 19 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 20 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT, 21 | INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT, 22 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 24 | OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 25 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 26 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 27 | EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | package com.jcraft.jsch; 31 | 32 | /** 33 | * Usually not to be used by applications. 34 | * A request to start the sftp subsystem in a channel. 35 | * 36 | * There is no reason this class is public. 37 | * 38 | * @see RFC 4254, section 6.5 39 | * @see Internet draft "SSH File Transfer" (version 13, expired 2007) 40 | * @see ChannelSftp 41 | */ 42 | public class RequestSftp extends Request{ 43 | RequestSftp(){ 44 | setReply(true); 45 | } 46 | public void request(Session session, Channel channel) throws Exception{ 47 | super.request(session, channel); 48 | 49 | Buffer buf=new Buffer(); 50 | Packet packet=new Packet(buf); 51 | packet.reset(); 52 | buf.putByte((byte)Session.SSH_MSG_CHANNEL_REQUEST); 53 | buf.putInt(channel.getRecipient()); 54 | buf.putString(Util.str2byte("subsystem")); 55 | buf.putByte((byte)(waitForReply() ? 1 : 0)); 56 | buf.putString(Util.str2byte("sftp")); 57 | write(packet); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/main/java/com/jcraft/jsch/RequestShell.java: -------------------------------------------------------------------------------- 1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ 2 | /* 3 | Copyright (c) 2002-2016 ymnk, JCraft,Inc. All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | 1. Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | 11 | 2. Redistributions in binary form must reproduce the above copyright 12 | notice, this list of conditions and the following disclaimer in 13 | the documentation and/or other materials provided with the distribution. 14 | 15 | 3. The names of the authors may not be used to endorse or promote products 16 | derived from this software without specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, 19 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 20 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT, 21 | INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT, 22 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 24 | OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 25 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 26 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 27 | EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | package com.jcraft.jsch; 31 | 32 | class RequestShell extends Request{ 33 | public void request(Session session, Channel channel) throws Exception{ 34 | super.request(session, channel); 35 | 36 | Buffer buf=new Buffer(); 37 | Packet packet=new Packet(buf); 38 | 39 | // send 40 | // byte SSH_MSG_CHANNEL_REQUEST(98) 41 | // uint32 recipient channel 42 | // string request type // "shell" 43 | // boolean want reply // 0 44 | packet.reset(); 45 | buf.putByte((byte) Session.SSH_MSG_CHANNEL_REQUEST); 46 | buf.putInt(channel.getRecipient()); 47 | buf.putString(Util.str2byte("shell")); 48 | buf.putByte((byte)(waitForReply() ? 1 : 0)); 49 | write(packet); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/com/jcraft/jsch/RequestSignal.java: -------------------------------------------------------------------------------- 1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ 2 | /* 3 | Copyright (c) 2002-2016 ymnk, JCraft,Inc. All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | 1. Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | 11 | 2. Redistributions in binary form must reproduce the above copyright 12 | notice, this list of conditions and the following disclaimer in 13 | the documentation and/or other materials provided with the distribution. 14 | 15 | 3. The names of the authors may not be used to endorse or promote products 16 | derived from this software without specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, 19 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 20 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT, 21 | INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT, 22 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 24 | OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 25 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 26 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 27 | EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | package com.jcraft.jsch; 31 | 32 | class RequestSignal extends Request{ 33 | private String signal="KILL"; 34 | public void setSignal(String foo){ signal=foo; } 35 | public void request(Session session, Channel channel) throws Exception{ 36 | super.request(session, channel); 37 | 38 | Buffer buf=new Buffer(); 39 | Packet packet=new Packet(buf); 40 | 41 | packet.reset(); 42 | buf.putByte((byte) Session.SSH_MSG_CHANNEL_REQUEST); 43 | buf.putInt(channel.getRecipient()); 44 | buf.putString(Util.str2byte("signal")); 45 | buf.putByte((byte)(waitForReply() ? 1 : 0)); 46 | buf.putString(Util.str2byte(signal)); 47 | write(packet); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/com/jcraft/jsch/RequestSubsystem.java: -------------------------------------------------------------------------------- 1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ 2 | /* 3 | Copyright (c) 2005-2016 ymnk, JCraft,Inc. All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | 1. Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | 11 | 2. Redistributions in binary form must reproduce the above copyright 12 | notice, this list of conditions and the following disclaimer in 13 | the documentation and/or other materials provided with the distribution. 14 | 15 | 3. The names of the authors may not be used to endorse or promote products 16 | derived from this software without specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, 19 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 20 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT, 21 | INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT, 22 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 24 | OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 25 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 26 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 27 | EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | package com.jcraft.jsch; 31 | 32 | /** 33 | * Usually not to be used by applications. 34 | * A request for the start of a subsystem in a channel. 35 | * 36 | * There is no reason this class is public. 37 | * @see RFC 4254, section 6.5 38 | * @see ChannelSubsystem 39 | */ 40 | public class RequestSubsystem extends Request{ 41 | private String subsystem=null; 42 | public void request(Session session, Channel channel, String subsystem, boolean want_reply) throws Exception{ 43 | setReply(want_reply); 44 | this.subsystem=subsystem; 45 | this.request(session, channel); 46 | } 47 | public void request(Session session, Channel channel) throws Exception{ 48 | super.request(session, channel); 49 | 50 | Buffer buf=new Buffer(); 51 | Packet packet=new Packet(buf); 52 | 53 | packet.reset(); 54 | buf.putByte((byte)Session.SSH_MSG_CHANNEL_REQUEST); 55 | buf.putInt(channel.getRecipient()); 56 | buf.putString(Util.str2byte("subsystem")); 57 | buf.putByte((byte)(waitForReply() ? 1 : 0)); 58 | buf.putString(Util.str2byte(subsystem)); 59 | write(packet); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/main/java/com/jcraft/jsch/RequestWindowChange.java: -------------------------------------------------------------------------------- 1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ 2 | /* 3 | Copyright (c) 2002-2016 ymnk, JCraft,Inc. All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | 1. Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | 11 | 2. Redistributions in binary form must reproduce the above copyright 12 | notice, this list of conditions and the following disclaimer in 13 | the documentation and/or other materials provided with the distribution. 14 | 15 | 3. The names of the authors may not be used to endorse or promote products 16 | derived from this software without specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, 19 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 20 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT, 21 | INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT, 22 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 24 | OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 25 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 26 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 27 | EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | package com.jcraft.jsch; 31 | 32 | class RequestWindowChange extends Request{ 33 | int width_columns=80; 34 | int height_rows=24; 35 | int width_pixels=640; 36 | int height_pixels=480; 37 | void setSize(int col, int row, int wp, int hp){ 38 | this.width_columns=col; 39 | this.height_rows=row; 40 | this.width_pixels=wp; 41 | this.height_pixels=hp; 42 | } 43 | public void request(Session session, Channel channel) throws Exception{ 44 | super.request(session, channel); 45 | 46 | Buffer buf=new Buffer(); 47 | Packet packet=new Packet(buf); 48 | 49 | //byte SSH_MSG_CHANNEL_REQUEST 50 | //uint32 recipient_channel 51 | //string "window-change" 52 | //boolean FALSE 53 | //uint32 terminal width, columns 54 | //uint32 terminal height, rows 55 | //uint32 terminal width, pixels 56 | //uint32 terminal height, pixels 57 | packet.reset(); 58 | buf.putByte((byte) Session.SSH_MSG_CHANNEL_REQUEST); 59 | buf.putInt(channel.getRecipient()); 60 | buf.putString(Util.str2byte("window-change")); 61 | buf.putByte((byte)(waitForReply() ? 1 : 0)); 62 | buf.putInt(width_columns); 63 | buf.putInt(height_rows); 64 | buf.putInt(width_pixels); 65 | buf.putInt(height_pixels); 66 | write(packet); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/main/java/com/jcraft/jsch/RequestX11.java: -------------------------------------------------------------------------------- 1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ 2 | /* 3 | Copyright (c) 2002-2016 ymnk, JCraft,Inc. All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | 1. Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | 11 | 2. Redistributions in binary form must reproduce the above copyright 12 | notice, this list of conditions and the following disclaimer in 13 | the documentation and/or other materials provided with the distribution. 14 | 15 | 3. The names of the authors may not be used to endorse or promote products 16 | derived from this software without specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, 19 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 20 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT, 21 | INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT, 22 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 24 | OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 25 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 26 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 27 | EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | package com.jcraft.jsch; 31 | 32 | /** 33 | * A request to forward X11 connections 34 | * to remote programs connected to a channel. 35 | * 36 | * We use the "MIT-MAGIC_COOKIE-1" authentication protocol. 37 | */ 38 | class RequestX11 extends Request{ 39 | public void setCookie(String cookie){ 40 | ChannelX11.cookie=Util.str2byte(cookie); 41 | } 42 | public void request(Session session, Channel channel) throws Exception{ 43 | super.request(session, channel); 44 | 45 | Buffer buf=new Buffer(); 46 | Packet packet=new Packet(buf); 47 | 48 | // byte SSH_MSG_CHANNEL_REQUEST(98) 49 | // uint32 recipient channel 50 | // string request type // "x11-req" 51 | // boolean want reply // 0 52 | // boolean single connection 53 | // string x11 authentication protocol // "MIT-MAGIC-COOKIE-1". 54 | // string x11 authentication cookie 55 | // uint32 x11 screen number 56 | packet.reset(); 57 | buf.putByte((byte) Session.SSH_MSG_CHANNEL_REQUEST); 58 | buf.putInt(channel.getRecipient()); 59 | buf.putString(Util.str2byte("x11-req")); 60 | buf.putByte((byte)(waitForReply() ? 1 : 0)); 61 | buf.putByte((byte)0); 62 | buf.putString(Util.str2byte("MIT-MAGIC-COOKIE-1")); 63 | buf.putString(ChannelX11.getFakedCookie(session)); 64 | buf.putInt(0); 65 | write(packet); 66 | 67 | session.x11_forwarding=true; 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /src/main/java/com/jcraft/jsch/ServerSocketFactory.java: -------------------------------------------------------------------------------- 1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ 2 | /* 3 | Copyright (c) 2002-2016 ymnk, JCraft,Inc. All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | 1. Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | 11 | 2. Redistributions in binary form must reproduce the above copyright 12 | notice, this list of conditions and the following disclaimer in 13 | the documentation and/or other materials provided with the distribution. 14 | 15 | 3. The names of the authors may not be used to endorse or promote products 16 | derived from this software without specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, 19 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 20 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT, 21 | INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT, 22 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 24 | OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 25 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 26 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 27 | EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | package com.jcraft.jsch; 31 | 32 | import java.net.*; 33 | import java.io.*; 34 | 35 | /** 36 | * A factory for ServerSockets. This interface works similarly to 37 | * {@link javax.net.ServerSocketFactory}, but does not depend on 38 | * the 1.4 Java version. 39 | *40 | * An application may want to implement this interface to have control 41 | * over the server socket creation for local port forwardings, for example 42 | * to configure the server socket (or the Sockets it creates) before use. 43 | *
44 | * 45 | * @see SocketFactory 46 | * @see Session#setPortForwardingL(String, int, String, int, 47 | * ServerSocketFactory) 48 | */ 49 | public interface ServerSocketFactory{ 50 | 51 | /** 52 | * Creates a ServerSocket. 53 | * @param port the port to listen on. 54 | * @param backlog the number of not-yet accepted connections which 55 | * may be waiting at the same time before new ones will be rejected. 56 | * @param bindAddr the local network interface the socket will be 57 | * listening on. If {@code null}, listen on all local addresses. 58 | * @throws IOException if some network error occured, like the port 59 | * was already in use. 60 | */ 61 | public ServerSocket createServerSocket(int port, int backlog, 62 | InetAddress bindAddr) throws IOException; 63 | } 64 | -------------------------------------------------------------------------------- /src/main/java/com/jcraft/jsch/SftpProgressMonitor.java: -------------------------------------------------------------------------------- 1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ 2 | /* 3 | Copyright (c) 2002-2016 ymnk, JCraft,Inc. All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | 1. Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | 11 | 2. Redistributions in binary form must reproduce the above copyright 12 | notice, this list of conditions and the following disclaimer in 13 | the documentation and/or other materials provided with the distribution. 14 | 15 | 3. The names of the authors may not be used to endorse or promote products 16 | derived from this software without specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, 19 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 20 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT, 21 | INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT, 22 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 24 | OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 25 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 26 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 27 | EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | package com.jcraft.jsch; 31 | 32 | /** 33 | * A callback to get information about the progress of a file 34 | * transfer operation. 35 | *36 | * An application will implement this interface to get information 37 | * about a running file transfer, and maybe show it to the user. 38 | * For example, it might wrap an {@link javax.swing.ProgressMonitor}. 39 | *
40 | *41 | * Additionally, this interface enables the application to stop the 42 | * transfer by returning {@code false} from the {@link #count count} method. 43 | *
44 | *45 | * Several of the {@link ChannelSftp}'s {@code put} and {@code get} methods 46 | * take an object of this type, and will call its methods as defined here. 47 | *
48 | * 49 | * @see ChannelSftp 50 | */ 51 | public interface SftpProgressMonitor{ 52 | 53 | /** 54 | * Direction constant for upload. 55 | */ 56 | public static final int PUT=0; 57 | 58 | /** 59 | * Direction constant for download. 60 | */ 61 | public static final int GET=1; 62 | public static final long UNKNOWN_SIZE = -1L; 63 | 64 | /** 65 | * Will be called when a new operation starts. 66 | * @param op a code indicating the direction of transfer, 67 | * one of {@link #PUT} and {@link #GET} 68 | * @param dest the destination file name. 69 | * @param max the final count (i.e. length of file to transfer). 70 | */ 71 | void init(int op, String src, String dest, long max); 72 | 73 | /** 74 | * Will be called periodically as more data is transfered. 75 | * @param count the number of bytes transferred so far 76 | * @return true if the transfer should go on, 77 | * false if the transfer should be cancelled. 78 | */ 79 | boolean count(long count); 80 | 81 | /** 82 | * Will be called when the transfer ended, either because all the data 83 | * was transferred, or because the transfer was cancelled. 84 | */ 85 | void end(); 86 | } 87 | -------------------------------------------------------------------------------- /src/main/java/com/jcraft/jsch/Signature.java: -------------------------------------------------------------------------------- 1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ 2 | /* 3 | Copyright (c) 2012-2016 ymnk, JCraft,Inc. All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | 1. Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | 11 | 2. Redistributions in binary form must reproduce the above copyright 12 | notice, this list of conditions and the following disclaimer in 13 | the documentation and/or other materials provided with the distribution. 14 | 15 | 3. The names of the authors may not be used to endorse or promote products 16 | derived from this software without specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, 19 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 20 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT, 21 | INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT, 22 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 24 | OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 25 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 26 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 27 | EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | package com.jcraft.jsch; 31 | 32 | /** 33 | * Usually not to be used by applications. 34 | * A generic signature algorithm, with key and some state of 35 | * an ongoing signing or verification algorithm. 36 | * (Methods for providing the key are given in the subinterfaces 37 | * {@link SignatureDSA}, {@link SignatureECDSA}, {@link SignatureRSA}, 38 | * which also have some more documentation.) 39 | * @since 0.1.49 40 | */ 41 | public interface Signature{ 42 | /** 43 | * Initializes the signature object. (This can only do initialization 44 | * which do not depend on whether signing or checking is done.) 45 | */ 46 | void init() throws Exception; 47 | /** 48 | * adds some more data to be signed/verified. 49 | * @param H the array containing the data to be signed/verified. 50 | */ 51 | void update(byte[] H) throws Exception; 52 | /** 53 | * Verifies that the given signature is a correct signature. 54 | * @param sig an array containing the signature for the data 55 | * given by {@link #update}. 56 | * @return true if the signature is correct, 57 | * false if the signature is not correct. 58 | */ 59 | boolean verify(byte[] sig) throws Exception; 60 | /** 61 | * Signs the data given so far to the {@link #update} method. 62 | * @return a signature for the data. 63 | */ 64 | byte[] sign() throws Exception; 65 | } 66 | -------------------------------------------------------------------------------- /src/main/java/com/jcraft/jsch/SignatureDSA.java: -------------------------------------------------------------------------------- 1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ 2 | /* 3 | Copyright (c) 2002-2016 ymnk, JCraft,Inc. All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | 1. Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | 11 | 2. Redistributions in binary form must reproduce the above copyright 12 | notice, this list of conditions and the following disclaimer in 13 | the documentation and/or other materials provided with the distribution. 14 | 15 | 3. The names of the authors may not be used to endorse or promote products 16 | derived from this software without specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, 19 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 20 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT, 21 | INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT, 22 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 24 | OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 25 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 26 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 27 | EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | package com.jcraft.jsch; 31 | 32 | /** 33 | * Usually not to be used by applications. 34 | * A DSA signing or signature checking algorithm. 35 | *36 | * This interface is a slimmed down and specialized (on DSA) version 37 | * of {@link java.security.Signature}. 38 | *
39 | *40 | * It will be used by the library to check the server's signature 41 | * during key exchange, and to prove our own possession of the 42 | * private key for public-key authentication in the default {@link Identity} 43 | * implementation. 44 | *
45 | *46 | * The library will choose the implementation class by the configuration 47 | * option {@code signature.dsa}, and instantiate it using the no-argument 48 | * constructor. For signature checking, the usage would look like this: 49 | *
50 | *51 | * sig = class.newInstance(); 52 | * sig.init(); 53 | * sig.setPubKey(y, p, q, g); 54 | * sig.update(H); // maybe more than once 55 | * boolean ok = sig.verify(sig_of_H); 56 | *57 | *
For signing, the usage would look like this:
58 | *59 | * sig = class.newInstance(); 60 | * sig.init(); 61 | * sig.setPrvKey(x, p, q, g); 62 | * sig.update(H); // maybe more than once 63 | * byte[] sig_of_H = sig.sign(); 64 | *65 | *
66 | * The library contains a default implementation based on 67 | * {@link java.security.Signature}. 68 | *
69 | * @see SignatureRSA 70 | */ 71 | public interface SignatureDSA extends Signature { 72 | /** 73 | * Sets the public key and prepares this signature object 74 | * for signature verifying. 75 | * @param y the public key {@code y = g^x mod p}. 76 | * @param p the big prime 77 | * @param q the small prime 78 | * @param g the generator 79 | * @see KeyPairGenDSA 80 | */ 81 | void setPubKey(byte[] y, byte[] p, byte[] q, byte[] g) throws Exception; 82 | 83 | /** 84 | * Sets the private key and prepares this signature object 85 | * for signing. 86 | * @param x the private key 87 | * @param p the big prime 88 | * @param q the small prime 89 | * @param g the generator 90 | * @see KeyPairGenDSA 91 | */ 92 | void setPrvKey(byte[] x, byte[] p, byte[] q, byte[] g) throws Exception; 93 | } 94 | -------------------------------------------------------------------------------- /src/main/java/com/jcraft/jsch/SignatureECDSA.java: -------------------------------------------------------------------------------- 1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ 2 | /* 3 | Copyright (c) 2015-2016 ymnk, JCraft,Inc. All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | 1. Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | 11 | 2. Redistributions in binary form must reproduce the above copyright 12 | notice, this list of conditions and the following disclaimer in 13 | the documentation and/or other materials provided with the distribution. 14 | 15 | 3. The names of the authors may not be used to endorse or promote products 16 | derived from this software without specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, 19 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 20 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT, 21 | INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT, 22 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 24 | OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 25 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 26 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 27 | EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | package com.jcraft.jsch; 31 | 32 | /** 33 | * Usually not to be used by applications. 34 | * A generic ECDSA signature algorithm, allowing signing (using a private key) 35 | * or signature verification (using a public key). Each implementation works 36 | * with one specific curve. 37 | *38 | * This interface is a slimmed down and specialized (on RSA) version 39 | * of {@link java.security.Signature}. 40 | *
41 | *42 | * It will be used by the library to check the server's signature 43 | * during key exchange, and to prove our own possession of the 44 | * private key for public-key authentication in the default {@link Identity} 45 | * implementation. 46 | *
47 | *48 | * The library will choose the implementation class by the configuration 49 | * option {@code signature.ecdsa}, and instantiate it using the no-argument 50 | * constructor. For signature checking, the usage would look like this: 51 | *
52 | *53 | * sig = class.newInstance(); 54 | * sig.init(); 55 | * sig.setPubKey(r, s); 56 | * sig.update(H); // maybe more than once 57 | * boolean ok = sig.verify(sig_of_H); 58 | *59 | *
For signing, the usage would look like this:
60 | *61 | * sig = class.newInstance(); 62 | * sig.init(); 63 | * sig.setPrvKey(prvKey); 64 | * sig.update(H); // maybe more than once 65 | * byte[] sig_of_H = sig.sign(); 66 | *67 | *
68 | * The library contains a default implementation based on 69 | * {@link java.security.Signature}. 70 | *
71 | * @see SignatureDSA 72 | * @since 0.1.52 73 | */ 74 | public interface SignatureECDSA extends Signature { 75 | 76 | /** 77 | * Sets the public key to be used for signature verification. 78 | * @param r the x-coordinate of the public key point. 79 | * @param s the y-coordinate of the public key point. 80 | * @throws Exception if something goes wrong. 81 | */ 82 | void setPubKey(byte[] r, byte[] s) throws Exception; 83 | 84 | /** 85 | * Sets the private key to be used for signing. 86 | * @param s the private key (exponent), encoded as a byte[]. 87 | * @throws Exception if something goes wrong. 88 | */ 89 | void setPrvKey(byte[] s) throws Exception; 90 | } 91 | -------------------------------------------------------------------------------- /src/main/java/com/jcraft/jsch/SignatureRSA.java: -------------------------------------------------------------------------------- 1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ 2 | /* 3 | Copyright (c) 2002-2016 ymnk, JCraft,Inc. All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | 1. Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | 11 | 2. Redistributions in binary form must reproduce the above copyright 12 | notice, this list of conditions and the following disclaimer in 13 | the documentation and/or other materials provided with the distribution. 14 | 15 | 3. The names of the authors may not be used to endorse or promote products 16 | derived from this software without specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, 19 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 20 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT, 21 | INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT, 22 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 24 | OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 25 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 26 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 27 | EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | package com.jcraft.jsch; 31 | 32 | /** 33 | * Usually not to be used by applications. 34 | * An RSA signing or signature checking algorithm. 35 | *36 | * This interface is a slimmed down and specialized (on RSA) version 37 | * of {@link java.security.Signature}. 38 | *
39 | *40 | * It will be used by the library to check the server's signature 41 | * during key exchange, and to prove our own possession of the 42 | * private key for public-key authentication in the default {@link Identity} 43 | * implementation. 44 | *
45 | *46 | * The library will choose the implementation class by the configuration 47 | * option {@code signature.dsa}, and instantiate it using the no-argument 48 | * constructor. For signature checking, the usage would look like this: 49 | *
50 | *51 | * sig = class.newInstance(); 52 | * sig.init(); 53 | * sig.setPubKey(e, n); 54 | * sig.update(H); // maybe more than once 55 | * boolean ok = sig.verify(sig_of_H); 56 | *57 | *
For signing, the usage would look like this:
58 | *59 | * sig = class.newInstance(); 60 | * sig.init(); 61 | * sig.setPrvKey(d, n); 62 | * sig.update(H); // maybe more than once 63 | * byte[] sig_of_H = sig.sign(); 64 | *65 | *
66 | * The library contains a default implementation based on 67 | * {@link java.security.Signature}. 68 | *
69 | * @see SignatureDSA 70 | */ 71 | public interface SignatureRSA extends Signature { 72 | 73 | /** 74 | * Sets the public key and prepares this signature object 75 | * for signature verifying. 76 | * @param e the public exponent. 77 | * @param n the modulus. 78 | */ 79 | void setPubKey(byte[] e, byte[] n) throws Exception; 80 | 81 | /** 82 | * Sets the private key and prepares this signature object 83 | * for signing. 84 | * @param d the private exponent. 85 | * @param n the modulus. 86 | */ 87 | void setPrvKey(byte[] d, byte[] n) throws Exception; 88 | } 89 | -------------------------------------------------------------------------------- /src/main/java/com/jcraft/jsch/SocketFactory.java: -------------------------------------------------------------------------------- 1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ 2 | /* 3 | Copyright (c) 2002-2016 ymnk, JCraft,Inc. All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | 1. Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | 11 | 2. Redistributions in binary form must reproduce the above copyright 12 | notice, this list of conditions and the following disclaimer in 13 | the documentation and/or other materials provided with the distribution. 14 | 15 | 3. The names of the authors may not be used to endorse or promote products 16 | derived from this software without specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, 19 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 20 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT, 21 | INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT, 22 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 24 | OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 25 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 26 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 27 | EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | package com.jcraft.jsch; 31 | 32 | import java.net.*; 33 | import java.io.*; 34 | 35 | /** 36 | * A factory for (client) sockets. 37 | * This works similar to {@link javax.net.SocketFactory}, but with the 38 | * ability to replace/wrap the Streams without having to subclass 39 | * {@link Socket} (and it works with before JDK 1.4, too). 40 | * 41 | *42 | * An application may pass an implementation of this interface to 43 | * the Session to control the creation of outgoing Sockets for 44 | * port forwardings (to other hosts/ports on the local side) or for 45 | * the main connection to the remote host. 46 | *
47 | * @see ServerSocketFactory 48 | * @see Session#setSocketFactory 49 | * @see Session#setPortForwardingR(String, int, String, int, SocketFactory) 50 | */ 51 | public interface SocketFactory{ 52 | 53 | /** 54 | * Creates a Socket connected to a given host/port. 55 | * @param host the destination host name. 56 | * @param port the destination port number. 57 | */ 58 | public Socket createSocket(String host, int port)throws IOException, 59 | UnknownHostException; 60 | 61 | /** 62 | * Creates an InputStream for a Socket. 63 | * The canonical implementation would simply do 64 | * {@code return socket.getInputStream()}, 65 | * but advanced implementations may wrap the stream. 66 | * @param socket a socket created with {@link #createSocket}. 67 | * @return an InputStream reading from the socket. 68 | */ 69 | public InputStream getInputStream(Socket socket)throws IOException; 70 | 71 | /** 72 | * Creates an OutputStream for a Socket. 73 | * The canonical implementation would simply do 74 | * {@code return socket.getOutputStream()}, 75 | * but advanced implementations may wrap the stream. 76 | * @param socket a socket created with {@link #createSocket}. 77 | * @return an OutputStream writing to the socket. 78 | */ 79 | public OutputStream getOutputStream(Socket socket)throws IOException; 80 | } 81 | -------------------------------------------------------------------------------- /src/main/java/com/jcraft/jsch/UIKeyboardInteractive.java: -------------------------------------------------------------------------------- 1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ 2 | /* 3 | Copyright (c) 2002-2016 ymnk, JCraft,Inc. All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | 1. Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | 11 | 2. Redistributions in binary form must reproduce the above copyright 12 | notice, this list of conditions and the following disclaimer in 13 | the documentation and/or other materials provided with the distribution. 14 | 15 | 3. The names of the authors may not be used to endorse or promote products 16 | derived from this software without specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, 19 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 20 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT, 21 | INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT, 22 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 24 | OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 25 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 26 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 27 | EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | package com.jcraft.jsch; 31 | 32 | 33 | /** 34 | * Provides a way to prompt the user for {@code keyboard-interactive} 35 | * authentication. 36 | * This interface will be implemented by applications in 37 | * {@link UserInfo} implementations to support {@code keyboard-interactive} 38 | * authentication as defined in RFC 4256. 39 | *40 | * Additionally, it is used in case of password-based authorization when the 41 | * server requests a password change. 42 | *
43 | *44 | * Most of the examples include an implementation of this 45 | * interface based on Swings {@link javax.swing.JOptionPane}. 46 | *
47 | * 48 | * @see RFC 4256: 49 | * Generic Message Exchange Authentication for 50 | * the Secure Shell Protocol (SSH) 51 | */ 52 | public interface UIKeyboardInteractive{ 53 | 54 | /** 55 | * Retrieves answers from the user to a number of questions. 56 | * 57 | * 58 | * @param destination identifies the user/host pair where we want to login. 59 | * (This was not sent by the remote side). 60 | * @param name the name of the request (could be shown in the 61 | * window title). This may be empty. 62 | * @param instruction an instruction string to be shown to the user. 63 | * This may be empty, and may contain new-lines. 64 | * @param prompt a list of prompt strings. 65 | * @param echo for each prompt string, whether to show the 66 | * texts typed in ({@code true}) or to mask them ({@code false}). 67 | * This array will have the same length as {@code prompt}. 68 | * 69 | * @return the answers as given by the user. This must be an array of 70 | * same length as {@code prompt}, if the user confirmed. 71 | * If the user cancels the input, the return value should be 72 | * {@code null}. 73 | * 74 | * @see RFC 4256, 75 | * 3.2. Information Requests 76 | * @see RFC 4256, 77 | * 3.3. User Interface 78 | */ 79 | String[] promptKeyboardInteractive(String destination, 80 | String name, 81 | String instruction, 82 | String[] prompt, 83 | boolean[] echo); 84 | } 85 | -------------------------------------------------------------------------------- /src/main/java/com/jcraft/jsch/UserAuth.java: -------------------------------------------------------------------------------- 1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ 2 | /* 3 | Copyright (c) 2002-2016 ymnk, JCraft,Inc. All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | 1. Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | 11 | 2. Redistributions in binary form must reproduce the above copyright 12 | notice, this list of conditions and the following disclaimer in 13 | the documentation and/or other materials provided with the distribution. 14 | 15 | 3. The names of the authors may not be used to endorse or promote products 16 | derived from this software without specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, 19 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 20 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT, 21 | INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT, 22 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 24 | OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 25 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 26 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 27 | EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | package com.jcraft.jsch; 31 | 32 | 33 | /** 34 | * Usually not to be used by applications. 35 | * The base class for all User authentication methods supported 36 | * by this SSH implementation. 37 | * 38 | * The actual method will be negiotiated between client and server, 39 | * and then we'll look up the implementation class by the configuration 40 | * option with the choosen method as a name. 41 | */ 42 | public abstract class UserAuth{ 43 | protected static final int SSH_MSG_USERAUTH_REQUEST= 50; 44 | protected static final int SSH_MSG_USERAUTH_FAILURE= 51; 45 | protected static final int SSH_MSG_USERAUTH_SUCCESS= 52; 46 | protected static final int SSH_MSG_USERAUTH_BANNER= 53; 47 | protected static final int SSH_MSG_USERAUTH_INFO_REQUEST= 60; 48 | protected static final int SSH_MSG_USERAUTH_INFO_RESPONSE= 61; 49 | protected static final int SSH_MSG_USERAUTH_PK_OK= 60; 50 | 51 | protected UserInfo userinfo; 52 | protected Packet packet; 53 | protected Buffer buf; 54 | protected String username; 55 | 56 | /** 57 | * Will be called by the Session to do the authentication. 58 | * Subclasses will override this method and do the actual 59 | * authentication, using the session's read/write methods. 60 | *61 | * This implementation fills the protected variables {@link #username}, 62 | * {@link #packet}, {@link #buf} and {@link #userinfo} and returns 63 | * {@code true}. Subclasses will usually call {@code super.start(session)} 64 | * as first statement in the implementation. 65 | *
66 | * @return true if the authentication was successful, else false. 67 | * @throws JSchPartialAuthException if the authentication was partially 68 | * successful, i.e. not yet sufficient to login, but enough to continue 69 | * with more methods. 70 | */ 71 | public boolean start(Session session) throws Exception{ 72 | this.userinfo=session.getUserInfo(); 73 | this.packet=session.packet; 74 | this.buf=packet.getBuffer(); 75 | this.username=session.getUserName(); 76 | return true; 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /src/main/java/com/jcraft/jsch/jce/AES128CBC.java: -------------------------------------------------------------------------------- 1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ 2 | /* 3 | Copyright (c) 2005-2016 ymnk, JCraft,Inc. All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | 1. Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | 11 | 2. Redistributions in binary form must reproduce the above copyright 12 | notice, this list of conditions and the following disclaimer in 13 | the documentation and/or other materials provided with the distribution. 14 | 15 | 3. The names of the authors may not be used to endorse or promote products 16 | derived from this software without specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, 19 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 20 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT, 21 | INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT, 22 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 24 | OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 25 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 26 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 27 | EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | package com.jcraft.jsch.jce; 31 | 32 | import com.jcraft.jsch.Cipher; 33 | import javax.crypto.spec.*; 34 | 35 | public class AES128CBC implements Cipher{ 36 | private static final int ivsize=16; 37 | private static final int bsize=16; 38 | private javax.crypto.Cipher cipher; 39 | public int getIVSize(){return ivsize;} 40 | public int getBlockSize(){return bsize;} 41 | public void init(int mode, byte[] key, byte[] iv) throws Exception{ 42 | String pad="NoPadding"; 43 | byte[] tmp; 44 | if(iv.length>ivsize){ 45 | tmp=new byte[ivsize]; 46 | System.arraycopy(iv, 0, tmp, 0, tmp.length); 47 | iv=tmp; 48 | } 49 | if(key.length>bsize){ 50 | tmp=new byte[bsize]; 51 | System.arraycopy(key, 0, tmp, 0, tmp.length); 52 | key=tmp; 53 | } 54 | 55 | try{ 56 | SecretKeySpec keyspec=new SecretKeySpec(key, "AES"); 57 | cipher=javax.crypto.Cipher.getInstance("AES/CBC/"+pad); 58 | synchronized(javax.crypto.Cipher.class){ 59 | cipher.init((mode==ENCRYPT_MODE? 60 | javax.crypto.Cipher.ENCRYPT_MODE: 61 | javax.crypto.Cipher.DECRYPT_MODE), 62 | keyspec, new IvParameterSpec(iv)); 63 | } 64 | } 65 | catch(Exception e){ 66 | cipher=null; 67 | throw e; 68 | } 69 | } 70 | public void update(byte[] foo, int s1, int len, byte[] bar, int s2) throws Exception{ 71 | cipher.update(foo, s1, len, bar, s2); 72 | } 73 | 74 | public boolean isCBC(){return true; } 75 | } 76 | -------------------------------------------------------------------------------- /src/main/java/com/jcraft/jsch/jce/AES128CTR.java: -------------------------------------------------------------------------------- 1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ 2 | /* 3 | Copyright (c) 2008-2016 ymnk, JCraft,Inc. All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | 1. Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | 11 | 2. Redistributions in binary form must reproduce the above copyright 12 | notice, this list of conditions and the following disclaimer in 13 | the documentation and/or other materials provided with the distribution. 14 | 15 | 3. The names of the authors may not be used to endorse or promote products 16 | derived from this software without specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, 19 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 20 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT, 21 | INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT, 22 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 24 | OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 25 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 26 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 27 | EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | package com.jcraft.jsch.jce; 31 | 32 | import com.jcraft.jsch.Cipher; 33 | import javax.crypto.spec.*; 34 | 35 | public class AES128CTR implements Cipher{ 36 | private static final int ivsize=16; 37 | private static final int bsize=16; 38 | private javax.crypto.Cipher cipher; 39 | public int getIVSize(){return ivsize;} 40 | public int getBlockSize(){return bsize;} 41 | public void init(int mode, byte[] key, byte[] iv) throws Exception{ 42 | String pad="NoPadding"; 43 | byte[] tmp; 44 | if(iv.length>ivsize){ 45 | tmp=new byte[ivsize]; 46 | System.arraycopy(iv, 0, tmp, 0, tmp.length); 47 | iv=tmp; 48 | } 49 | if(key.length>bsize){ 50 | tmp=new byte[bsize]; 51 | System.arraycopy(key, 0, tmp, 0, tmp.length); 52 | key=tmp; 53 | } 54 | 55 | try{ 56 | SecretKeySpec keyspec=new SecretKeySpec(key, "AES"); 57 | cipher=javax.crypto.Cipher.getInstance("AES/CTR/"+pad); 58 | synchronized(javax.crypto.Cipher.class){ 59 | cipher.init((mode==ENCRYPT_MODE? 60 | javax.crypto.Cipher.ENCRYPT_MODE: 61 | javax.crypto.Cipher.DECRYPT_MODE), 62 | keyspec, new IvParameterSpec(iv)); 63 | } 64 | } 65 | catch(Exception e){ 66 | cipher=null; 67 | throw e; 68 | } 69 | } 70 | public void update(byte[] foo, int s1, int len, byte[] bar, int s2) throws Exception{ 71 | cipher.update(foo, s1, len, bar, s2); 72 | } 73 | 74 | public boolean isCBC(){return false; } 75 | } 76 | -------------------------------------------------------------------------------- /src/main/java/com/jcraft/jsch/jce/AES192CBC.java: -------------------------------------------------------------------------------- 1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ 2 | /* 3 | Copyright (c) 2005-2016 ymnk, JCraft,Inc. All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | 1. Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | 11 | 2. Redistributions in binary form must reproduce the above copyright 12 | notice, this list of conditions and the following disclaimer in 13 | the documentation and/or other materials provided with the distribution. 14 | 15 | 3. The names of the authors may not be used to endorse or promote products 16 | derived from this software without specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, 19 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 20 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT, 21 | INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT, 22 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 24 | OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 25 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 26 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 27 | EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | package com.jcraft.jsch.jce; 31 | 32 | import com.jcraft.jsch.Cipher; 33 | import javax.crypto.spec.*; 34 | 35 | public class AES192CBC implements Cipher{ 36 | private static final int ivsize=16; 37 | private static final int bsize=24; 38 | private javax.crypto.Cipher cipher; 39 | public int getIVSize(){return ivsize;} 40 | public int getBlockSize(){return bsize;} 41 | public void init(int mode, byte[] key, byte[] iv) throws Exception{ 42 | String pad="NoPadding"; 43 | byte[] tmp; 44 | if(iv.length>ivsize){ 45 | tmp=new byte[ivsize]; 46 | System.arraycopy(iv, 0, tmp, 0, tmp.length); 47 | iv=tmp; 48 | } 49 | if(key.length>bsize){ 50 | tmp=new byte[bsize]; 51 | System.arraycopy(key, 0, tmp, 0, tmp.length); 52 | key=tmp; 53 | } 54 | try{ 55 | SecretKeySpec keyspec=new SecretKeySpec(key, "AES"); 56 | cipher=javax.crypto.Cipher.getInstance("AES/CBC/"+pad); 57 | synchronized(javax.crypto.Cipher.class){ 58 | cipher.init((mode==ENCRYPT_MODE? 59 | javax.crypto.Cipher.ENCRYPT_MODE: 60 | javax.crypto.Cipher.DECRYPT_MODE), 61 | keyspec, new IvParameterSpec(iv)); 62 | } 63 | } 64 | catch(Exception e){ 65 | cipher=null; 66 | throw e; 67 | } 68 | } 69 | public void update(byte[] foo, int s1, int len, byte[] bar, int s2) throws Exception{ 70 | cipher.update(foo, s1, len, bar, s2); 71 | } 72 | public boolean isCBC(){return true; } 73 | } 74 | -------------------------------------------------------------------------------- /src/main/java/com/jcraft/jsch/jce/AES192CTR.java: -------------------------------------------------------------------------------- 1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ 2 | /* 3 | Copyright (c) 2008-2016 ymnk, JCraft,Inc. All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | 1. Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | 11 | 2. Redistributions in binary form must reproduce the above copyright 12 | notice, this list of conditions and the following disclaimer in 13 | the documentation and/or other materials provided with the distribution. 14 | 15 | 3. The names of the authors may not be used to endorse or promote products 16 | derived from this software without specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, 19 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 20 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT, 21 | INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT, 22 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 24 | OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 25 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 26 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 27 | EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | package com.jcraft.jsch.jce; 31 | 32 | import com.jcraft.jsch.Cipher; 33 | import javax.crypto.spec.*; 34 | 35 | public class AES192CTR implements Cipher{ 36 | private static final int ivsize=16; 37 | private static final int bsize=24; 38 | private javax.crypto.Cipher cipher; 39 | public int getIVSize(){return ivsize;} 40 | public int getBlockSize(){return bsize;} 41 | public void init(int mode, byte[] key, byte[] iv) throws Exception{ 42 | String pad="NoPadding"; 43 | byte[] tmp; 44 | if(iv.length>ivsize){ 45 | tmp=new byte[ivsize]; 46 | System.arraycopy(iv, 0, tmp, 0, tmp.length); 47 | iv=tmp; 48 | } 49 | if(key.length>bsize){ 50 | tmp=new byte[bsize]; 51 | System.arraycopy(key, 0, tmp, 0, tmp.length); 52 | key=tmp; 53 | } 54 | try{ 55 | SecretKeySpec keyspec=new SecretKeySpec(key, "AES"); 56 | cipher=javax.crypto.Cipher.getInstance("AES/CTR/"+pad); 57 | synchronized(javax.crypto.Cipher.class){ 58 | cipher.init((mode==ENCRYPT_MODE? 59 | javax.crypto.Cipher.ENCRYPT_MODE: 60 | javax.crypto.Cipher.DECRYPT_MODE), 61 | keyspec, new IvParameterSpec(iv)); 62 | } 63 | } 64 | catch(Exception e){ 65 | cipher=null; 66 | throw e; 67 | } 68 | } 69 | public void update(byte[] foo, int s1, int len, byte[] bar, int s2) throws Exception{ 70 | cipher.update(foo, s1, len, bar, s2); 71 | } 72 | public boolean isCBC(){return false; } 73 | } 74 | -------------------------------------------------------------------------------- /src/main/java/com/jcraft/jsch/jce/AES256CBC.java: -------------------------------------------------------------------------------- 1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ 2 | /* 3 | Copyright (c) 2005-2016 ymnk, JCraft,Inc. All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | 1. Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | 11 | 2. Redistributions in binary form must reproduce the above copyright 12 | notice, this list of conditions and the following disclaimer in 13 | the documentation and/or other materials provided with the distribution. 14 | 15 | 3. The names of the authors may not be used to endorse or promote products 16 | derived from this software without specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, 19 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 20 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT, 21 | INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT, 22 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 24 | OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 25 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 26 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 27 | EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | package com.jcraft.jsch.jce; 31 | 32 | import com.jcraft.jsch.Cipher; 33 | import javax.crypto.spec.*; 34 | 35 | public class AES256CBC implements Cipher{ 36 | private static final int ivsize=16; 37 | private static final int bsize=32; 38 | private javax.crypto.Cipher cipher; 39 | public int getIVSize(){return ivsize;} 40 | public int getBlockSize(){return bsize;} 41 | public void init(int mode, byte[] key, byte[] iv) throws Exception{ 42 | String pad="NoPadding"; 43 | byte[] tmp; 44 | if(iv.length>ivsize){ 45 | tmp=new byte[ivsize]; 46 | System.arraycopy(iv, 0, tmp, 0, tmp.length); 47 | iv=tmp; 48 | } 49 | if(key.length>bsize){ 50 | tmp=new byte[bsize]; 51 | System.arraycopy(key, 0, tmp, 0, tmp.length); 52 | key=tmp; 53 | } 54 | try{ 55 | SecretKeySpec keyspec=new SecretKeySpec(key, "AES"); 56 | cipher=javax.crypto.Cipher.getInstance("AES/CBC/"+pad); 57 | synchronized(javax.crypto.Cipher.class){ 58 | cipher.init((mode==ENCRYPT_MODE? 59 | javax.crypto.Cipher.ENCRYPT_MODE: 60 | javax.crypto.Cipher.DECRYPT_MODE), 61 | keyspec, new IvParameterSpec(iv)); 62 | } 63 | } 64 | catch(Exception e){ 65 | cipher=null; 66 | throw e; 67 | } 68 | } 69 | public void update(byte[] foo, int s1, int len, byte[] bar, int s2) throws Exception{ 70 | cipher.update(foo, s1, len, bar, s2); 71 | } 72 | public boolean isCBC(){return true; } 73 | } 74 | -------------------------------------------------------------------------------- /src/main/java/com/jcraft/jsch/jce/AES256CTR.java: -------------------------------------------------------------------------------- 1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ 2 | /* 3 | Copyright (c) 2008-2016 ymnk, JCraft,Inc. All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | 1. Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | 11 | 2. Redistributions in binary form must reproduce the above copyright 12 | notice, this list of conditions and the following disclaimer in 13 | the documentation and/or other materials provided with the distribution. 14 | 15 | 3. The names of the authors may not be used to endorse or promote products 16 | derived from this software without specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, 19 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 20 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT, 21 | INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT, 22 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 24 | OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 25 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 26 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 27 | EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | package com.jcraft.jsch.jce; 31 | 32 | import com.jcraft.jsch.Cipher; 33 | import javax.crypto.spec.*; 34 | 35 | public class AES256CTR implements Cipher{ 36 | private static final int ivsize=16; 37 | private static final int bsize=32; 38 | private javax.crypto.Cipher cipher; 39 | public int getIVSize(){return ivsize;} 40 | public int getBlockSize(){return bsize;} 41 | public void init(int mode, byte[] key, byte[] iv) throws Exception{ 42 | String pad="NoPadding"; 43 | byte[] tmp; 44 | if(iv.length>ivsize){ 45 | tmp=new byte[ivsize]; 46 | System.arraycopy(iv, 0, tmp, 0, tmp.length); 47 | iv=tmp; 48 | } 49 | if(key.length>bsize){ 50 | tmp=new byte[bsize]; 51 | System.arraycopy(key, 0, tmp, 0, tmp.length); 52 | key=tmp; 53 | } 54 | try{ 55 | SecretKeySpec keyspec=new SecretKeySpec(key, "AES"); 56 | cipher=javax.crypto.Cipher.getInstance("AES/CTR/"+pad); 57 | synchronized(javax.crypto.Cipher.class){ 58 | cipher.init((mode==ENCRYPT_MODE? 59 | javax.crypto.Cipher.ENCRYPT_MODE: 60 | javax.crypto.Cipher.DECRYPT_MODE), 61 | keyspec, new IvParameterSpec(iv)); 62 | } 63 | } 64 | catch(Exception e){ 65 | cipher=null; 66 | throw e; 67 | } 68 | } 69 | public void update(byte[] foo, int s1, int len, byte[] bar, int s2) throws Exception{ 70 | cipher.update(foo, s1, len, bar, s2); 71 | } 72 | public boolean isCBC(){return false; } 73 | } 74 | -------------------------------------------------------------------------------- /src/main/java/com/jcraft/jsch/jce/ARCFOUR.java: -------------------------------------------------------------------------------- 1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ 2 | /* 3 | Copyright (c) 2008-2016 ymnk, JCraft,Inc. All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | 1. Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | 11 | 2. Redistributions in binary form must reproduce the above copyright 12 | notice, this list of conditions and the following disclaimer in 13 | the documentation and/or other materials provided with the distribution. 14 | 15 | 3. The names of the authors may not be used to endorse or promote products 16 | derived from this software without specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, 19 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 20 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT, 21 | INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT, 22 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 24 | OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 25 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 26 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 27 | EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | package com.jcraft.jsch.jce; 31 | 32 | import com.jcraft.jsch.Cipher; 33 | import javax.crypto.*; 34 | import javax.crypto.spec.*; 35 | 36 | public class ARCFOUR implements Cipher{ 37 | private static final int ivsize=8; 38 | private static final int bsize=16; 39 | private javax.crypto.Cipher cipher; 40 | public int getIVSize(){return ivsize;} 41 | public int getBlockSize(){return bsize;} 42 | public void init(int mode, byte[] key, byte[] iv) throws Exception{ 43 | String pad="NoPadding"; 44 | byte[] tmp; 45 | if(key.length>bsize){ 46 | tmp=new byte[bsize]; 47 | System.arraycopy(key, 0, tmp, 0, tmp.length); 48 | key=tmp; 49 | } 50 | 51 | try{ 52 | cipher=javax.crypto.Cipher.getInstance("RC4"); 53 | SecretKeySpec _key = new SecretKeySpec(key, "RC4"); 54 | synchronized(javax.crypto.Cipher.class){ 55 | cipher.init((mode==ENCRYPT_MODE? 56 | javax.crypto.Cipher.ENCRYPT_MODE: 57 | javax.crypto.Cipher.DECRYPT_MODE), 58 | _key); 59 | } 60 | } 61 | catch(Exception e){ 62 | cipher=null; 63 | throw e; 64 | } 65 | } 66 | public void update(byte[] foo, int s1, int len, byte[] bar, int s2) throws Exception{ 67 | cipher.update(foo, s1, len, bar, s2); 68 | } 69 | public boolean isCBC(){return false; } 70 | } 71 | -------------------------------------------------------------------------------- /src/main/java/com/jcraft/jsch/jce/ARCFOUR128.java: -------------------------------------------------------------------------------- 1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ 2 | /* 3 | Copyright (c) 2008-2016 ymnk, JCraft,Inc. All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | 1. Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | 11 | 2. Redistributions in binary form must reproduce the above copyright 12 | notice, this list of conditions and the following disclaimer in 13 | the documentation and/or other materials provided with the distribution. 14 | 15 | 3. The names of the authors may not be used to endorse or promote products 16 | derived from this software without specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, 19 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 20 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT, 21 | INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT, 22 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 24 | OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 25 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 26 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 27 | EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | package com.jcraft.jsch.jce; 31 | 32 | import com.jcraft.jsch.Cipher; 33 | import javax.crypto.*; 34 | import javax.crypto.spec.*; 35 | 36 | public class ARCFOUR128 implements Cipher{ 37 | private static final int ivsize=8; 38 | private static final int bsize=16; 39 | private static final int skip=1536; 40 | private javax.crypto.Cipher cipher; 41 | public int getIVSize(){return ivsize;} 42 | public int getBlockSize(){return bsize;} 43 | public void init(int mode, byte[] key, byte[] iv) throws Exception{ 44 | byte[] tmp; 45 | if(key.length>bsize){ 46 | tmp=new byte[bsize]; 47 | System.arraycopy(key, 0, tmp, 0, tmp.length); 48 | key=tmp; 49 | } 50 | try{ 51 | cipher=javax.crypto.Cipher.getInstance("RC4"); 52 | SecretKeySpec _key = new SecretKeySpec(key, "RC4"); 53 | synchronized(javax.crypto.Cipher.class){ 54 | cipher.init((mode==ENCRYPT_MODE? 55 | javax.crypto.Cipher.ENCRYPT_MODE: 56 | javax.crypto.Cipher.DECRYPT_MODE), 57 | _key); 58 | } 59 | byte[] foo=new byte[1]; 60 | for(int i=0; iHere is an overview about the most important ones:
7 | *28 | * Most other classes are either for internal use (see next paragraph) 29 | * or for special uses, and not necessary for a normal application. 30 | *
31 | * 32 | *The string Usually not to be used by applications. 33 | * at the beginning of a class or interface description means 34 | * that this type is used internally by the library, and normally 35 | * there is no need for an application to directly use 36 | * (or implement/extend) this type. It may be needed if you need to 37 | * extend functionality, then you normally will also have to change some 38 | * {@linkplain com.jcraft.jsch.JSch#setConfig configuration options}. 39 | *
40 | */ 41 | package com.jcraft.jsch; -------------------------------------------------------------------------------- /tools/bin/ant: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | 3 | if [ -f $HOME/.antrc ] ; then 4 | . $HOME/.antrc 5 | fi 6 | 7 | # OS specific support. $var _must_ be set to either true or false. 8 | cygwin=false; 9 | darwin=false; 10 | case "`uname`" in 11 | CYGWIN*) cygwin=true ;; 12 | Darwin*) darwin=true ;; 13 | esac 14 | 15 | if [ -z "$ANT_HOME" ] ; then 16 | # try to find ANT 17 | if [ -d /opt/ant ] ; then 18 | ANT_HOME=/opt/ant 19 | fi 20 | 21 | if [ -d ${HOME}/opt/ant ] ; then 22 | ANT_HOME=${HOME}/opt/ant 23 | fi 24 | 25 | ## resolve links - $0 may be a link to ant's home 26 | PRG=$0 27 | progname=`basename $0` 28 | 29 | while [ -h "$PRG" ] ; do 30 | ls=`ls -ld "$PRG"` 31 | link=`expr "$ls" : '.*-> \(.*\)$'` 32 | if expr "$link" : '.*/.*' > /dev/null; then 33 | PRG="$link" 34 | else 35 | PRG="`dirname $PRG`/$link" 36 | fi 37 | done 38 | 39 | ANT_HOME=`dirname "$PRG"`/.. 40 | 41 | fi 42 | 43 | # For Cygwin, ensure paths are in UNIX format before anything is touched 44 | if $cygwin ; then 45 | [ -n "$ANT_HOME" ] && 46 | ANT_HOME=`cygpath --unix "$ANT_HOME"` 47 | [ -n "$JAVA_HOME" ] && 48 | JAVA_HOME=`cygpath --unix "$JAVA_HOME"` 49 | [ -n "$CLASSPATH" ] && 50 | CLASSPATH=`cygpath --path --unix "$CLASSPATH"` 51 | fi 52 | 53 | if [ -z "$JAVACMD" ] ; then 54 | if [ -n "$JAVA_HOME" ] ; then 55 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 56 | # IBM's JDK on AIX uses strange locations for the executables 57 | JAVACMD=$JAVA_HOME/jre/sh/java 58 | else 59 | JAVACMD=$JAVA_HOME/bin/java 60 | fi 61 | else 62 | JAVACMD=java 63 | fi 64 | fi 65 | 66 | if [ ! -x "$JAVACMD" ] ; then 67 | echo "Error: JAVA_HOME is not defined correctly." 68 | echo " We cannot execute $JAVACMD" 69 | exit 70 | fi 71 | 72 | if [ -n "$CLASSPATH" ] ; then 73 | LOCALCLASSPATH=$CLASSPATH 74 | fi 75 | 76 | # add in the dependency .jar files 77 | DIRLIBS=${ANT_HOME}/lib/*.jar 78 | for i in ${DIRLIBS} 79 | do 80 | # if the directory is empty, then it will return the input string 81 | # this is stupid, so case for it 82 | if [ "$i" != "${DIRLIBS}" ] ; then 83 | if [ -z "$LOCALCLASSPATH" ] ; then 84 | LOCALCLASSPATH=$i 85 | else 86 | LOCALCLASSPATH="$i":$LOCALCLASSPATH 87 | fi 88 | fi 89 | done 90 | 91 | if [ -n "$JAVA_HOME" ] ; then 92 | if [ -f "$JAVA_HOME/lib/tools.jar" ] ; then 93 | LOCALCLASSPATH=$LOCALCLASSPATH:$JAVA_HOME/lib/tools.jar 94 | fi 95 | 96 | if [ -f "$JAVA_HOME/lib/classes.zip" ] ; then 97 | LOCALCLASSPATH=$LOCALCLASSPATH:$JAVA_HOME/lib/classes.zip 98 | fi 99 | 100 | # OSX hack to make Ant work with jikes 101 | if $darwin ; then 102 | OSXHACK="/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Classes" 103 | if [ -d ${OSXHACK} ] ; then 104 | for i in ${OSXHACK}/*.jar 105 | do 106 | JIKESPATH=$JIKESPATH:$i 107 | done 108 | fi 109 | fi 110 | 111 | else 112 | echo "Warning: JAVA_HOME environment variable is not set." 113 | echo " If build fails because sun.* classes could not be found" 114 | echo " you will need to set the JAVA_HOME environment variable" 115 | echo " to the installation directory of java." 116 | fi 117 | 118 | # supply JIKESPATH to Ant as jikes.class.path 119 | if [ -n "$JIKESPATH" ] ; then 120 | if [ -n "$ANT_OPTS" ] ; then 121 | ANT_OPTS="$ANT_OPTS -Djikes.class.path=$JIKESPATH" 122 | else 123 | ANT_OPTS=-Djikes.class.path=$JIKESPATH 124 | fi 125 | fi 126 | 127 | # For Cygwin, switch paths to Windows format before running java 128 | if $cygwin; then 129 | ANT_HOME=`cygpath --path --windows "$ANT_HOME"` 130 | JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` 131 | LOCALCLASSPATH=`cygpath --path --windows "$LOCALCLASSPATH"` 132 | fi 133 | 134 | $JAVACMD -classpath "$LOCALCLASSPATH" -Dant.home="${ANT_HOME}" $ANT_OPTS org.apache.tools.ant.Main "$@" 135 | -------------------------------------------------------------------------------- /tools/bin/ant.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | if exist "%HOME%\antrc_pre.bat" call "%HOME%\antrc_pre.bat" 4 | 5 | if not "%OS%"=="Windows_NT" goto win9xStart 6 | :winNTStart 7 | @setlocal 8 | 9 | rem %~dp0 is name of current script under NT 10 | set DEFAULT_ANT_HOME=%~dp0 11 | 12 | rem : operator works similar to make : operator 13 | set DEFAULT_ANT_HOME=%DEFAULT_ANT_HOME%\.. 14 | 15 | if "%ANT_HOME%"=="" set ANT_HOME=%DEFAULT_ANT_HOME% 16 | set DEFAULT_ANT_HOME= 17 | 18 | rem Need to check if we are using the 4NT shell... 19 | if "%eval[2+2]" == "4" goto setup4NT 20 | 21 | rem On NT/2K grab all arguments at once 22 | set ANT_CMD_LINE_ARGS=%* 23 | goto doneStart 24 | 25 | :setup4NT 26 | set ANT_CMD_LINE_ARGS=%$ 27 | goto doneStart 28 | 29 | :win9xStart 30 | rem Slurp the command line arguments. This loop allows for an unlimited number of 31 | rem agruments (up to the command line limit, anyway). 32 | 33 | set ANT_CMD_LINE_ARGS= 34 | 35 | :setupArgs 36 | if %1a==a goto doneStart 37 | set ANT_CMD_LINE_ARGS=%ANT_CMD_LINE_ARGS% %1 38 | shift 39 | goto setupArgs 40 | 41 | :doneStart 42 | rem This label provides a place for the argument list loop to break out 43 | rem and for NT handling to skip to. 44 | 45 | rem find ANT_HOME 46 | if not "%ANT_HOME%"=="" goto checkJava 47 | 48 | rem check for ant in Program Files on system drive 49 | if not exist "%SystemDrive%\Program Files\ant" goto checkSystemDrive 50 | set ANT_HOME=%SystemDrive%\Program Files\ant 51 | goto checkJava 52 | 53 | :checkSystemDrive 54 | rem check for ant in root directory of system drive 55 | if not exist %SystemDrive%\ant\nul goto checkCDrive 56 | set ANT_HOME=%SystemDrive%\ant 57 | goto checkJava 58 | 59 | :checkCDrive 60 | rem check for ant in C:\ant for Win9X users 61 | if not exist C:\ant\nul goto noAntHome 62 | set ANT_HOME=C:\ant 63 | goto checkJava 64 | 65 | :noAntHome 66 | echo ANT_HOME is not set and ant could not be located. Please set ANT_HOME. 67 | goto end 68 | 69 | :checkJava 70 | set _JAVACMD=%JAVACMD% 71 | set LOCALCLASSPATH=%CLASSPATH% 72 | for %%i in ("%ANT_HOME%\lib\*.jar") do call "%ANT_HOME%\bin\lcp.bat" %%i 73 | 74 | if "%JAVA_HOME%" == "" goto noJavaHome 75 | if "%_JAVACMD%" == "" set _JAVACMD=%JAVA_HOME%\bin\java 76 | if exist "%JAVA_HOME%\lib\tools.jar" call "%ANT_HOME%\bin\lcp.bat" %JAVA_HOME%\lib\tools.jar 77 | if exist "%JAVA_HOME%\lib\classes.zip" call "%ANT_HOME%\bin\lcp.bat" %JAVA_HOME%\lib\classes.zip 78 | goto checkJikes 79 | 80 | :noJavaHome 81 | if "%_JAVACMD%" == "" set _JAVACMD=java 82 | echo. 83 | echo Warning: JAVA_HOME environment variable is not set. 84 | echo If build fails because sun.* classes could not be found 85 | echo you will need to set the JAVA_HOME environment variable 86 | echo to the installation directory of java. 87 | echo. 88 | 89 | :checkJikes 90 | if not "%JIKESPATH%" == "" goto runAntWithJikes 91 | 92 | :runAnt 93 | "%_JAVACMD%" -classpath "%LOCALCLASSPATH%" -Dant.home="%ANT_HOME%" %ANT_OPTS% org.apache.tools.ant.Main %ANT_CMD_LINE_ARGS% 94 | goto end 95 | 96 | :runAntWithJikes 97 | "%_JAVACMD%" -classpath "%LOCALCLASSPATH%" -Dant.home="%ANT_HOME%" -Djikes.class.path="%JIKESPATH%" %ANT_OPTS% org.apache.tools.ant.Main %ANT_CMD_LINE_ARGS% 98 | 99 | :end 100 | set LOCALCLASSPATH= 101 | set _JAVACMD= 102 | set ANT_CMD_LINE_ARGS= 103 | 104 | if not "%OS%"=="Windows_NT" goto mainEnd 105 | :winNTend 106 | @endlocal 107 | 108 | :mainEnd 109 | if exist "%HOME%\antrc_post.bat" call "%HOME%\antrc_post.bat" 110 | 111 | -------------------------------------------------------------------------------- /tools/bin/antRun: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | 3 | # Args: DIR command 4 | cd "$1" 5 | CMD="$2" 6 | shift 7 | shift 8 | 9 | exec $CMD "$@" 10 | -------------------------------------------------------------------------------- /tools/bin/antRun.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | rem Change drive and directory to %1 (Win9X only for NT/2K use "cd /d") 4 | cd %1 5 | %1\ 6 | set ANT_RUN_CMD=%2 7 | shift 8 | shift 9 | 10 | set PARAMS= 11 | :loop 12 | if ""%1 == "" goto runCommand 13 | set PARAMS=%PARAMS% %1 14 | shift 15 | goto loop 16 | 17 | :runCommand 18 | rem echo %ANT_RUN_CMD% %PARAMS% 19 | %ANT_RUN_CMD% %PARAMS% 20 | 21 | -------------------------------------------------------------------------------- /tools/bin/lcp.bat: -------------------------------------------------------------------------------- 1 | set _CLASSPATHCOMPONENT=%1 2 | :argCheck 3 | if %2a==a goto gotAllArgs 4 | shift 5 | set _CLASSPATHCOMPONENT=%_CLASSPATHCOMPONENT% %1 6 | goto argCheck 7 | :gotAllArgs 8 | set LOCALCLASSPATH=%_CLASSPATHCOMPONENT%;%LOCALCLASSPATH% 9 | 10 | -------------------------------------------------------------------------------- /tools/bin/runant.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | """ 3 | 4 | runant.py 5 | 6 | This script is a translation of the runant.pl written by Steve Loughran. 7 | It runs ant with/out arguments, it should be quite portable (thanks to 8 | the python os library) 9 | This script has been tested with Python2.0/Win2K 10 | 11 | created: 2001-04-11 12 | author: Pierre Dittgen pierre.dittgen@criltelecom.com 13 | 14 | Assumptions: 15 | 16 | - the "java" executable/script is on the command path 17 | - ANT_HOME has been set 18 | """ 19 | import os, os.path, string, sys 20 | 21 | # Change it to 1 to get extra debug information 22 | debug = 0 23 | 24 | ####################################################################### 25 | # 26 | # check to make sure environment is setup 27 | # 28 | if not os.environ.has_key('ANT_HOME'): 29 | print '\n\nANT_HOME *MUST* be set!\n\n' 30 | sys.exit(1) 31 | else: 32 | ANT_HOME = os.environ['ANT_HOME'] 33 | 34 | if not os.environ.has_key('JAVACMD'): 35 | JAVACMD = 'java' 36 | else: 37 | JAVACMD = os.environ['JAVACMD'] 38 | 39 | # Sets the separator char for CLASSPATH 40 | SEPARATOR = ':' 41 | if os.name == 'dos' or os.name == 'nt': 42 | SEPARATOR = ';' 43 | 44 | # Build up standard classpath 45 | localpath = '' 46 | if os.environ.has_key('CLASSPATH'): 47 | localpath = os.environ['CLASSPATH'] 48 | else: 49 | if debug: 50 | print 'Warning: no initial classpath\n' 51 | 52 | # Add jar files 53 | LIBDIR = os.path.join(ANT_HOME, 'lib') 54 | jarfiles = [] 55 | for file in os.listdir(LIBDIR): 56 | if file[-4:] == '.jar': 57 | jarfiles.append(os.path.join(LIBDIR,file)) 58 | if debug: 59 | print 'Jar files:' 60 | for jar in jarfiles: 61 | print jar 62 | localpath = localpath + SEPARATOR + string.join(jarfiles, SEPARATOR) 63 | 64 | # If JAVA_HOME is defined, look for tools.jar & classes.zip 65 | # and add to classpath 66 | if os.environ.has_key('JAVA_HOME') and os.environ['JAVA_HOME'] != '': 67 | JAVA_HOME = os.environ['JAVA_HOME'] 68 | TOOLS = os.path.join(JAVA_HOME, os.path.join('lib', 'tools.jar')) 69 | if os.path.exists(TOOLS): 70 | localpath = localpath + SEPARATOR + TOOLS 71 | CLASSES = os.path.join(JAVA_HOME, os.path.join('lib', 'classes.zip')) 72 | if os.path.exists(CLASSES): 73 | localpath = localpath + SEPARATOR + CLASSES 74 | else: 75 | print '\n\nWarning: JAVA_HOME environment variable is not set.\n', \ 76 | 'If the build fails because sun.* classes could not be found\n', \ 77 | 'you will need to set the JAVA_HOME environment variable\n', \ 78 | 'to the installation directory of java\n' 79 | 80 | # Jikes 81 | ANT_OPTS = [] 82 | if os.environ.has_key('ANT_OPTS'): 83 | ANT_OPTS = string.split(os.environ['ANT_OPTS']) 84 | if os.environ.has_key('JIKESPATH'): 85 | ANT_OPTS.append('-Djikes.class.path=' + os.environ['JIKESPATH']) 86 | 87 | # Builds the commandline 88 | cmdline = '%s -classpath %s -Dant.home=%s %s org.apache.tools.ant.Main %s' \ 89 | % (JAVACMD, localpath, ANT_HOME, string.join(ANT_OPTS,' '), \ 90 | string.join(sys.argv[1:], ' ')) 91 | 92 | if debug: 93 | print '\n%s\n\n' % (cmdline) 94 | 95 | # Run the biniou! 96 | os.system(cmdline) 97 | --------------------------------------------------------------------------------