main
Jörg Prante 2 months ago
parent a905b0559a
commit f9c77330f6

@ -0,0 +1,4 @@
dependencies {
testImplementation testLibs.testcontainers
testImplementation testLibs.testcontainers.junit.jupiter
}

@ -0,0 +1,35 @@
/*
* Copyright (c) 2011 ymnk, JCraft,Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted
* provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions
* and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other materials provided with
* the distribution.
*
* 3. The names of the authors may not be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL JCRAFT, INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.jcraft.jsch;
public interface AgentConnector {
String getName();
boolean isAvailable();
void query(Buffer buffer) throws AgentProxyException;
}

@ -0,0 +1,80 @@
/*
* Copyright (c) 2011 ymnk, JCraft,Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted
* provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions
* and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other materials provided with
* the distribution.
*
* 3. The names of the authors may not be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL JCRAFT, INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.jcraft.jsch;
class AgentIdentity implements Identity {
private AgentProxy agent;
private byte[] blob;
private String comment;
private String algname;
AgentIdentity(AgentProxy agent, byte[] blob, String comment) {
this.agent = agent;
this.blob = blob;
this.comment = comment;
algname = Util.byte2str((new Buffer(blob)).getString());
}
@Override
public boolean setPassphrase(byte[] passphrase) throws JSchException {
return true;
}
@Override
public byte[] getPublicKeyBlob() {
return blob;
}
@Override
public byte[] getSignature(byte[] data) {
return agent.sign(blob, data, null);
}
@Override
public byte[] getSignature(byte[] data, String alg) {
return agent.sign(blob, data, alg);
}
@Override
public String getAlgName() {
return algname;
}
@Override
public String getName() {
return comment;
}
@Override
public boolean isEncrypted() {
return false;
}
@Override
public void clear() {}
}

@ -0,0 +1,72 @@
/*
* Copyright (c) 2011 ymnk, JCraft,Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted
* provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions
* and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other materials provided with
* the distribution.
*
* 3. The names of the authors may not be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL JCRAFT, INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.jcraft.jsch;
import java.util.Vector;
public class AgentIdentityRepository implements IdentityRepository {
private AgentProxy agent;
public AgentIdentityRepository(AgentConnector connector) {
this.agent = new AgentProxy(connector);
}
@Override
public Vector<Identity> getIdentities() {
return agent.getIdentities();
}
@Override
public boolean add(byte[] identity) {
return agent.addIdentity(identity);
}
@Override
public boolean remove(byte[] blob) {
return agent.removeIdentity(blob);
}
@Override
public void removeAll() {
agent.removeAllIdentities();
}
@Override
public String getName() {
return agent.getConnector().getName();
}
@Override
public int getStatus() {
if (agent.getConnector().isAvailable()) {
return RUNNING;
} else {
return NOTRUNNING;
}
}
}

@ -0,0 +1,246 @@
/*
* Copyright (c) 2012 ymnk, JCraft,Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted
* provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions
* and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other materials provided with
* the distribution.
*
* 3. The names of the authors may not be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL JCRAFT, INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.jcraft.jsch;
import java.util.Vector;
class AgentProxy {
private static final byte SSH_AGENTC_REQUEST_RSA_IDENTITIES = 1;
private static final byte SSH_AGENT_RSA_IDENTITIES_ANSWER = 2;
private static final byte SSH_AGENTC_RSA_CHALLENGE = 3;
private static final byte SSH_AGENT_RSA_RESPONSE = 4;
private static final byte SSH_AGENT_FAILURE = 5;
private static final byte SSH_AGENT_SUCCESS = 6;
private static final byte SSH_AGENTC_ADD_RSA_IDENTITY = 7;
private static final byte SSH_AGENTC_REMOVE_RSA_IDENTITY = 8;
private static final byte SSH_AGENTC_REMOVE_ALL_RSA_IDENTITIES = 9;
private static final byte SSH2_AGENTC_REQUEST_IDENTITIES = 11;
private static final byte SSH2_AGENT_IDENTITIES_ANSWER = 12;
private static final byte SSH2_AGENTC_SIGN_REQUEST = 13;
private static final byte SSH2_AGENT_SIGN_RESPONSE = 14;
private static final byte SSH2_AGENTC_ADD_IDENTITY = 17;
private static final byte SSH2_AGENTC_REMOVE_IDENTITY = 18;
private static final byte SSH2_AGENTC_REMOVE_ALL_IDENTITIES = 19;
private static final byte SSH_AGENTC_ADD_SMARTCARD_KEY = 20;
private static final byte SSH_AGENTC_REMOVE_SMARTCARD_KEY = 21;
private static final byte SSH_AGENTC_LOCK = 22;
private static final byte SSH_AGENTC_UNLOCK = 23;
private static final byte SSH_AGENTC_ADD_RSA_ID_CONSTRAINED = 24;
private static final byte SSH2_AGENTC_ADD_ID_CONSTRAINED = 25;
private static final byte SSH_AGENTC_ADD_SMARTCARD_KEY_CONSTRAINED = 26;
private static final byte SSH_AGENT_CONSTRAIN_LIFETIME = 1;
private static final byte SSH_AGENT_CONSTRAIN_CONFIRM = 2;
private static final byte SSH2_AGENT_FAILURE = 30;
private static final byte SSH_COM_AGENT2_FAILURE = 102;
// private static final byte SSH_AGENT_OLD_SIGNATURE = 0x1;
private static final int SSH_AGENT_RSA_SHA2_256 = 0x2;
private static final int SSH_AGENT_RSA_SHA2_512 = 0x4;
private static final int MAX_AGENT_IDENTITIES = 2048;
private final byte[] buf = new byte[1024];
private final Buffer buffer = new Buffer(buf);
private AgentConnector connector;
AgentProxy(AgentConnector connector) {
this.connector = connector;
}
synchronized Vector<Identity> getIdentities() {
Vector<Identity> identities = new Vector<>();
int required_size = 1 + 4;
buffer.reset();
buffer.checkFreeSize(required_size);
buffer.putInt(required_size - 4);
buffer.putByte(SSH2_AGENTC_REQUEST_IDENTITIES);
try {
connector.query(buffer);
} catch (AgentProxyException e) {
buffer.rewind();
buffer.putByte(SSH_AGENT_FAILURE);
return identities;
}
int rcode = buffer.getByte();
// System.out.println(rcode == SSH2_AGENT_IDENTITIES_ANSWER);
if (rcode != SSH2_AGENT_IDENTITIES_ANSWER) {
return identities;
}
int count = buffer.getInt();
// System.out.println(count);
if (count <= 0 || count > MAX_AGENT_IDENTITIES) {
return identities;
}
for (int i = 0; i < count; i++) {
byte[] blob = buffer.getString();
String comment = Util.byte2str(buffer.getString());
identities.add(new AgentIdentity(this, blob, comment));
}
return identities;
}
synchronized byte[] sign(byte[] blob, byte[] data, String alg) {
int flags = 0x0;
if (alg != null) {
if (alg.equals("rsa-sha2-256")) {
flags = SSH_AGENT_RSA_SHA2_256;
} else if (alg.equals("rsa-sha2-512")) {
flags = SSH_AGENT_RSA_SHA2_512;
}
}
int required_size = 1 + 4 * 4 + blob.length + data.length;
buffer.reset();
buffer.checkFreeSize(required_size);
buffer.putInt(required_size - 4);
buffer.putByte(SSH2_AGENTC_SIGN_REQUEST);
buffer.putString(blob);
buffer.putString(data);
buffer.putInt(flags);
try {
connector.query(buffer);
} catch (AgentProxyException e) {
buffer.rewind();
buffer.putByte(SSH_AGENT_FAILURE);
}
int rcode = buffer.getByte();
// System.out.println(rcode == SSH2_AGENT_SIGN_RESPONSE);
if (rcode != SSH2_AGENT_SIGN_RESPONSE) {
return null;
}
return buffer.getString();
}
synchronized boolean removeIdentity(byte[] blob) {
int required_size = 1 + 4 * 2 + blob.length;
buffer.reset();
buffer.checkFreeSize(required_size);
buffer.putInt(required_size - 4);
buffer.putByte(SSH2_AGENTC_REMOVE_IDENTITY);
buffer.putString(blob);
try {
connector.query(buffer);
} catch (AgentProxyException e) {
buffer.rewind();
buffer.putByte(SSH_AGENT_FAILURE);
}
int rcode = buffer.getByte();
// System.out.println(rcode == SSH_AGENT_SUCCESS);
return rcode == SSH_AGENT_SUCCESS;
}
synchronized void removeAllIdentities() {
int required_size = 1 + 4;
buffer.reset();
buffer.checkFreeSize(required_size);
buffer.putInt(required_size - 4);
buffer.putByte(SSH2_AGENTC_REMOVE_ALL_IDENTITIES);
try {
connector.query(buffer);
} catch (AgentProxyException e) {
buffer.rewind();
buffer.putByte(SSH_AGENT_FAILURE);
}
// int rcode = buffer.getByte();
// System.out.println(rcode == SSH_AGENT_SUCCESS);
}
synchronized boolean addIdentity(byte[] identity) {
int required_size = 1 + 4 + identity.length;
buffer.reset();
buffer.checkFreeSize(required_size);
buffer.putInt(required_size - 4);
buffer.putByte(SSH2_AGENTC_ADD_IDENTITY);
buffer.putByte(identity);
try {
connector.query(buffer);
} catch (AgentProxyException e) {
buffer.rewind();
buffer.putByte(SSH_AGENT_FAILURE);
}
int rcode = buffer.getByte();
// System.out.println(rcode == SSH_AGENT_SUCCESS);
return rcode == SSH_AGENT_SUCCESS;
}
synchronized boolean isRunning() {
int required_size = 1 + 4;
buffer.reset();
buffer.checkFreeSize(required_size);
buffer.putInt(required_size - 4);
buffer.putByte(SSH2_AGENTC_REQUEST_IDENTITIES);
try {
connector.query(buffer);
} catch (AgentProxyException e) {
return false;
}
int rcode = buffer.getByte();
// System.out.println(rcode == SSH2_AGENT_IDENTITIES_ANSWER);
return rcode == SSH2_AGENT_IDENTITIES_ANSWER;
}
synchronized AgentConnector getConnector() {
return connector;
}
}

@ -0,0 +1,39 @@
/*
* Copyright (c) 2011 ymnk, JCraft,Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted
* provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions
* and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other materials provided with
* the distribution.
*
* 3. The names of the authors may not be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL JCRAFT, INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.jcraft.jsch;
public class AgentProxyException extends Exception {
private static final long serialVersionUID = -1L;
public AgentProxyException(String message) {
super(message);
}
public AgentProxyException(String message, Throwable e) {
super(message, e);
}
}

@ -0,0 +1,38 @@
/*
* Copyright (c) 2013-2018 ymnk, JCraft,Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted
* provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions
* and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other materials provided with
* the distribution.
*
* 3. The names of the authors may not be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL JCRAFT, INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.jcraft.jsch;
public interface Argon2 extends KDF {
public static final int ARGON2D = 0;
public static final int ARGON2I = 1;
public static final int ARGON2ID = 2;
public static final int V10 = 0x10;
public static final int V13 = 0x13;
void init(byte[] salt, int iteration, int type, byte[] additional, byte[] secret, int memory,
int parallelism, int version) throws Exception;
}

@ -0,0 +1,31 @@
/*
* Copyright (c) 2013-2018 ymnk, JCraft,Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted
* provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions
* and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other materials provided with
* the distribution.
*
* 3. The names of the authors may not be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL JCRAFT, INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.jcraft.jsch;
public interface BCrypt extends KDF {
void init(byte[] salt, int iteration) throws Exception;
}

@ -0,0 +1,303 @@
/*
* Copyright (c) 2002-2018 ymnk, JCraft,Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted
* provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions
* and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other materials provided with
* the distribution.
*
* 3. The names of the authors may not be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL JCRAFT, INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.jcraft.jsch;
public class Buffer {
final byte[] tmp = new byte[4];
byte[] buffer;
int index;
int s;
public Buffer(int size) {
buffer = new byte[size];
index = 0;
s = 0;
}
public Buffer(byte[] buffer) {
this.buffer = buffer;
index = 0;
s = 0;
}
public Buffer() {
this(1024 * 10 * 2);
}
public void putByte(byte foo) {
buffer[index++] = foo;
}
public void putByte(byte[] foo) {
putByte(foo, 0, foo.length);
}
public void putByte(byte[] foo, int begin, int length) {
System.arraycopy(foo, begin, buffer, index, length);
index += length;
}
public void putString(byte[] foo) {
putString(foo, 0, foo.length);
}
public void putString(byte[] foo, int begin, int length) {
putInt(length);
putByte(foo, begin, length);
}
public void putInt(int val) {
tmp[0] = (byte) (val >>> 24);
tmp[1] = (byte) (val >>> 16);
tmp[2] = (byte) (val >>> 8);
tmp[3] = (byte) (val);
System.arraycopy(tmp, 0, buffer, index, 4);
index += 4;
}
public void putLong(long val) {
tmp[0] = (byte) (val >>> 56);
tmp[1] = (byte) (val >>> 48);
tmp[2] = (byte) (val >>> 40);
tmp[3] = (byte) (val >>> 32);
System.arraycopy(tmp, 0, buffer, index, 4);
tmp[0] = (byte) (val >>> 24);
tmp[1] = (byte) (val >>> 16);
tmp[2] = (byte) (val >>> 8);
tmp[3] = (byte) (val);
System.arraycopy(tmp, 0, buffer, index + 4, 4);
index += 8;
}
void skip(int n) {
index += n;
}
void putPad(int n) {
while (n > 0) {
buffer[index++] = (byte) 0;
n--;
}
}
public void putMPInt(byte[] foo) {
int i = foo.length;
if ((foo[0] & 0x80) != 0) {
i++;
putInt(i);
putByte((byte) 0);
} else {
putInt(i);
}
putByte(foo);
}
public int getLength() {
return index - s;
}
public int getOffSet() {
return s;
}
public void setOffSet(int s) {
this.s = s;
}
public long getLong() {
long foo = getInt() & 0xffffffffL;
foo = ((foo << 32)) | (getInt() & 0xffffffffL);
return foo;
}
public int getInt() {
int foo = getShort();
foo = ((foo << 16) & 0xffff0000) | (getShort() & 0xffff);
return foo;
}
public long getUInt() {
long foo = 0L;
long bar = 0L;
foo = getByte();
foo = ((foo << 8) & 0xff00) | (getByte() & 0xff);
bar = getByte();
bar = ((bar << 8) & 0xff00) | (getByte() & 0xff);
foo = ((foo << 16) & 0xffff0000) | (bar & 0xffff);
return foo;
}
int getShort() {
int foo = getByte();
foo = ((foo << 8) & 0xff00) | (getByte() & 0xff);
return foo;
}
public int getByte() {
return (buffer[s++] & 0xff);
}
public void getByte(byte[] foo) {
getByte(foo, 0, foo.length);
}
void getByte(byte[] foo, int start, int len) {
System.arraycopy(buffer, s, foo, start, len);
s += len;
}
public int getByte(int len) {
int foo = s;
s += len;
return foo;
}
public byte[] getMPInt() {
int i = getInt(); // uint32
if (i < 0 || // bigger than 0x7fffffff
i > 8 * 1024) {
// TODO: an exception should be thrown.
i = 8 * 1024; // the session will be broken, but working around OOME.
}
byte[] foo = new byte[i];
getByte(foo, 0, i);
return foo;
}
public byte[] getMPIntBits() {
int bits = getInt();
int bytes = (bits + 7) / 8;
byte[] foo = new byte[bytes];
getByte(foo, 0, bytes);
if ((foo[0] & 0x80) != 0) {
byte[] bar = new byte[foo.length + 1];
bar[0] = 0; // ??
System.arraycopy(foo, 0, bar, 1, foo.length);
foo = bar;
}
return foo;
}
public byte[] getString() {
int i = getInt(); // uint32
if (i < 0 || // bigger than 0x7fffffff
i > 256 * 1024) {
// TODO: an exception should be thrown.
i = 256 * 1024; // the session will be broken, but working around OOME.
}
byte[] foo = new byte[i];
getByte(foo, 0, i);
return foo;
}
byte[] getString(int[] start, int[] len) {
int i = getInt();
start[0] = getByte(i);
len[0] = i;
return buffer;
}
public void reset() {
index = 0;
s = 0;
}
public void shift() {
if (s == 0)
return;
System.arraycopy(buffer, s, buffer, 0, index - s);
index = index - s;
s = 0;
}
void rewind() {
s = 0;
}
byte getCommand() {
return buffer[5];
}
// Hardcode this since we can't use dynamic Session value
private static final int buffer_margin = 32 + // maximum padding length
64 + // maximum mac length
32; // margin for deflater; deflater may inflate data
void checkFreeSize(int n) {
int size = index + n + buffer_margin;
if (buffer.length < size) {
int i = buffer.length * 2;
if (i < size)
i = size;
byte[] tmp = new byte[i];
System.arraycopy(buffer, 0, tmp, 0, index);
buffer = tmp;
}
}
byte[][] getBytes(int n, String msg) throws JSchException {
byte[][] tmp = new byte[n][];
for (int i = 0; i < n; i++) {
int j = getInt();
if (getLength() < j) {
throw new JSchException(msg);
}
tmp[i] = new byte[j];
getByte(tmp[i]);
}
return tmp;
}
/*
* static Buffer fromBytes(byte[]... args){ int length = args.length*4; for(int i = 0; i <
* args.length; i++){ length += args[i].length; } Buffer buf = new Buffer(length); for(int i = 0;
* i < args.length; i++){ buf.putString(args[i]); } return buf; }
*/
static Buffer fromBytes(byte[][] args) {
int length = args.length * 4;
for (int i = 0; i < args.length; i++) {
length += args[i].length;
}
Buffer buf = new Buffer(length);
for (int i = 0; i < args.length; i++) {
buf.putString(args[i]);
}
return buf;
}
/*
* static String[] chars={ "0","1","2","3","4","5","6","7","8","9", "a","b","c","d","e","f" };
* static void dump_buffer(){ int foo; for(int i=0; i<tmp_buffer_index; i++){
* foo=tmp_buffer[i]&0xff; System.err.print(chars[(foo>>>4)&0xf]);
* System.err.print(chars[foo&0xf]); if(i%16==15){ System.err.println(""); continue; } if(i>0 &&
* i%2==1){ System.err.print(" "); } } System.err.println(""); } static void dump(byte[] b){
* dump(b, 0, b.length); } static void dump(byte[] b, int s, int l){ for(int i=s; i<s+l; i++){
* System.err.print(Integer.toHexString(b[i]&0xff)+":"); } System.err.println(""); }
*/
}

@ -0,0 +1,842 @@
/*
* Copyright (c) 2002-2018 ymnk, JCraft,Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted
* provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions
* and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other materials provided with
* the distribution.
*
* 3. The names of the authors may not be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL JCRAFT, INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.jcraft.jsch;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PipedInputStream;
import java.io.PipedOutputStream;
import java.util.Vector;
public abstract class Channel {
static final int SSH_MSG_CHANNEL_OPEN_CONFIRMATION = 91;
static final int SSH_MSG_CHANNEL_OPEN_FAILURE = 92;
static final int SSH_MSG_CHANNEL_WINDOW_ADJUST = 93;
static final int SSH_OPEN_ADMINISTRATIVELY_PROHIBITED = 1;
static final int SSH_OPEN_CONNECT_FAILED = 2;
static final int SSH_OPEN_UNKNOWN_CHANNEL_TYPE = 3;
static final int SSH_OPEN_RESOURCE_SHORTAGE = 4;
static int index = 0;
private static Vector<Channel> pool = new Vector<>();
static Channel getChannel(String type, Session session) {
Channel ret = null;
if (type.equals("session")) {
ret = new ChannelSession();
}
if (type.equals("shell")) {
ret = new ChannelShell();
}
if (type.equals("exec")) {
ret = new ChannelExec();
}
if (type.equals("x11")) {
ret = new ChannelX11();
}
if (type.equals("auth-agent@openssh.com")) {
ret = new ChannelAgentForwarding();
}
if (type.equals("direct-tcpip")) {
ret = new ChannelDirectTCPIP();
}
if (type.equals("forwarded-tcpip")) {
ret = new ChannelForwardedTCPIP();
}
if (type.equals("sftp")) {
ChannelSftp sftp = new ChannelSftp();
boolean useWriteFlushWorkaround =
session.getConfig("use_sftp_write_flush_workaround").equals("yes");
sftp.setUseWriteFlushWorkaround(useWriteFlushWorkaround);
ret = sftp;
}
if (type.equals("subsystem")) {
ret = new ChannelSubsystem();
}
if (type.equals("direct-streamlocal@openssh.com")) {
ret = new ChannelDirectStreamLocal();
}
if (ret == null) {
return null;
}
ret.setSession(session);
return ret;
}
static Channel getChannel(int id, Session session) {
synchronized (pool) {
for (int i = 0; i < pool.size(); i++) {
Channel c = pool.elementAt(i);
if (c.id == id && c.session == session)
return c;
}
}
return null;
}
static void del(Channel c) {
synchronized (pool) {
pool.removeElement(c);
}
}
int id;
volatile int recipient = -1;
protected byte[] type = Util.str2byte("foo");
volatile int lwsize_max = 0x100000;
volatile int lwsize = lwsize_max; // local initial window size
volatile int lmpsize = 0x4000; // local maximum packet size
volatile long rwsize = 0; // remote initial window size
volatile int rmpsize = 0; // remote maximum packet size
IO io = null;
Thread thread = null;
volatile boolean eof_local = false;
volatile boolean eof_remote = false;
volatile boolean close = false;
volatile boolean connected = false;
volatile boolean open_confirmation = false;
volatile int exitstatus = -1;
volatile int reply = 0;
volatile int connectTimeout = 0;
protected Session session;
int notifyme = 0;
Channel() {
synchronized (pool) {
id = index++;
pool.addElement(this);
}
}
synchronized void setRecipient(int foo) {
this.recipient = foo;
if (notifyme > 0)
notifyAll();
}
int getRecipient() {
return recipient;
}
void init() throws JSchException {}
public void connect() throws JSchException {
connect(0);
}
public void connect(int connectTimeout) throws JSchException {
this.connectTimeout = connectTimeout;
try {
sendChannelOpen();
start();
} catch (Exception e) {
connected = false;
disconnect();
if (e instanceof JSchException)
throw (JSchException) e;
throw new JSchException(e.toString(), e);
}
}
public void setXForwarding(boolean foo) {}
public void start() throws JSchException {}
public boolean isEOF() {
return eof_remote;
}
void getData(Buffer buf) {
setRecipient(buf.getInt());
setRemoteWindowSize(buf.getUInt());
setRemotePacketSize(buf.getInt());
}
public void setInputStream(InputStream in) {
io.setInputStream(in, false);
}
public void setInputStream(InputStream in, boolean dontclose) {
io.setInputStream(in, dontclose);
}
public void setOutputStream(OutputStream out) {
io.setOutputStream(out, false);
}
public void setOutputStream(OutputStream out, boolean dontclose) {
io.setOutputStream(out, dontclose);
}
public void setExtOutputStream(OutputStream out) {
io.setExtOutputStream(out, false);
}
public void setExtOutputStream(OutputStream out, boolean dontclose) {
io.setExtOutputStream(out, dontclose);
}
public InputStream getInputStream() throws IOException {
Session _session = this.session;
if (_session != null && isConnected() && _session.getLogger().isEnabled(Logger.WARN)) {
_session.getLogger().log(Logger.WARN, "getInputStream() should be called before connect()");
}
int max_input_buffer_size = 32 * 1024;
try {
max_input_buffer_size = Integer.parseInt(getSession().getConfig("max_input_buffer_size"));
} catch (Exception e) {
}
PipedInputStream in = new MyPipedInputStream(32 * 1024, // this value should be customizable.
max_input_buffer_size);
boolean resizable = 32 * 1024 < max_input_buffer_size;
io.setOutputStream(new PassiveOutputStream(in, resizable), false);
return in;
}
public InputStream getExtInputStream() throws IOException {
Session _session = this.session;
if (_session != null && isConnected() && _session.getLogger().isEnabled(Logger.WARN)) {
_session.getLogger().log(Logger.WARN,
"getExtInputStream() should be called before connect()");
}
int max_input_buffer_size = 32 * 1024;
try {
max_input_buffer_size = Integer.parseInt(getSession().getConfig("max_input_buffer_size"));
} catch (Exception e) {
}
PipedInputStream in = new MyPipedInputStream(32 * 1024, // this value should be customizable.
max_input_buffer_size);
boolean resizable = 32 * 1024 < max_input_buffer_size;
io.setExtOutputStream(new PassiveOutputStream(in, resizable), false);
return in;
}
public OutputStream getOutputStream() throws IOException {
final Channel channel = this;
OutputStream out = new OutputStream() {
private int dataLen = 0;
private Buffer buffer = null;
private Packet packet = null;
private boolean closed = false;
private synchronized void init() throws IOException {
buffer = new Buffer(rmpsize);
packet = new Packet(buffer);
byte[] _buf = buffer.buffer;
try {
if (_buf.length - (14 + 0) - getSession().getBufferMargin() <= 0) {
buffer = null;
packet = null;
throw new IOException("failed to initialize the channel.");
}
} catch (JSchException e) {
throw new IOException("failed to initialize the channel.", e);
}
}
byte[] b = new byte[1];
@Override
public void write(int w) throws IOException {
b[0] = (byte) w;
write(b, 0, 1);
}
@Override
public void write(byte[] buf, int s, int l) throws IOException {
if (packet == null) {
init();
}
if (closed) {
throw new IOException("Already closed");
}
byte[] _buf = buffer.buffer;
int _bufl = _buf.length;
try {
while (l > 0) {
int _l = l;
int buffer_margin = getSession().getBufferMargin();
if (l > _bufl - (14 + dataLen) - buffer_margin) {
_l = _bufl - (14 + dataLen) - buffer_margin;
}
if (_l <= 0) {
flush();
continue;
}
System.arraycopy(buf, s, _buf, 14 + dataLen, _l);
dataLen += _l;
s += _l;
l -= _l;
}
} catch (JSchException e) {
throw new IOException(e.toString(), e);
}
}
@Override
public void flush() throws IOException {
if (closed) {
throw new IOException("Already closed");
}
if (dataLen == 0)
return;
packet.reset();
buffer.putByte((byte) Session.SSH_MSG_CHANNEL_DATA);
buffer.putInt(recipient);
buffer.putInt(dataLen);
buffer.skip(dataLen);
try {
int foo = dataLen;
dataLen = 0;
synchronized (channel) {
if (!channel.close)
getSession().write(packet, channel, foo);
}
} catch (Exception e) {
close();
throw new IOException(e.toString(), e);
}
}
@Override
public void close() throws IOException {
if (packet == null) {
try {
init();
} catch (IOException e) {
// close should be finished silently.
return;
}
}
if (closed) {
return;
}
if (dataLen > 0) {
flush();
}
channel.eof();
closed = true;
}
};
return out;
}
static class MyPipedInputStream extends PipedInputStream {
private int BUFFER_SIZE = 1024;
private int max_buffer_size = BUFFER_SIZE;
MyPipedInputStream() throws IOException {
super();
}
MyPipedInputStream(int size) throws IOException {
super();
buffer = new byte[size];
BUFFER_SIZE = size;
max_buffer_size = size;
}
MyPipedInputStream(int size, int max_buffer_size) throws IOException {
this(size);
this.max_buffer_size = max_buffer_size;
}
MyPipedInputStream(PipedOutputStream out) throws IOException {
super(out);
}
MyPipedInputStream(PipedOutputStream out, int size) throws IOException {
super(out);
buffer = new byte[size];
BUFFER_SIZE = size;
}
/*
* TODO: We should have our own Piped[I/O]Stream implementation. Before accepting data, JDK's
* PipedInputStream will check the existence of reader thread, and if it is not alive, the
* stream will be closed. That behavior may cause the problem if multiple threads make access to
* it.
*/
public synchronized void updateReadSide() throws IOException {
if (available() != 0) { // not empty
return;
}
in = 0;
out = 0;
buffer[in++] = 0;
read();
}
private int freeSpace() {
int size = 0;
if (out < in) {
size = buffer.length - in;
} else if (in < out) {
if (in == -1)
size = buffer.length;
else
size = out - in;
}
return size;
}
synchronized void checkSpace(int len) throws IOException {
int size = freeSpace();
if (size < len) {
int datasize = buffer.length - size;
int foo = buffer.length;
while ((foo - datasize) < len) {
foo *= 2;
}
if (foo > max_buffer_size) {
foo = max_buffer_size;
}
if ((foo - datasize) < len)
return;
byte[] tmp = new byte[foo];
if (out < in) {
System.arraycopy(buffer, 0, tmp, 0, buffer.length);
} else if (in < out) {
if (in == -1) {
} else {
System.arraycopy(buffer, 0, tmp, 0, in);
System.arraycopy(buffer, out, tmp, tmp.length - (buffer.length - out),
(buffer.length - out));
out = tmp.length - (buffer.length - out);
}
} else if (in == out) {
System.arraycopy(buffer, 0, tmp, 0, buffer.length);
in = buffer.length;
}
buffer = tmp;
} else if (buffer.length == size && size > BUFFER_SIZE) {
int i = size / 2;
if (i < BUFFER_SIZE)
i = BUFFER_SIZE;
byte[] tmp = new byte[i];
buffer = tmp;
}
}
}
void setLocalWindowSizeMax(int foo) {
this.lwsize_max = foo;
}
void setLocalWindowSize(int foo) {
this.lwsize = foo;
}
void setLocalPacketSize(int foo) {
this.lmpsize = foo;
}
synchronized void setRemoteWindowSize(long foo) {
this.rwsize = foo;
}
synchronized void addRemoteWindowSize(long foo) {
this.rwsize += foo;
if (notifyme > 0)
notifyAll();
}
void setRemotePacketSize(int foo) {
this.rmpsize = foo;
}
abstract void run();
void write(byte[] foo) throws IOException {
write(foo, 0, foo.length);
}
void write(byte[] foo, int s, int l) throws IOException {
try {
io.put(foo, s, l);
} catch (NullPointerException e) {
}
}
void write_ext(byte[] foo, int s, int l) throws IOException {
try {
io.put_ext(foo, s, l);
} catch (NullPointerException e) {
}
}
void eof_remote() {
eof_remote = true;
try {
io.out_close();
} catch (NullPointerException e) {
}
}
void eof() {
if (eof_local)
return;
eof_local = true;
int i = getRecipient();
if (i == -1)
return;
try {
Buffer buf = new Buffer(100);
Packet packet = new Packet(buf);
packet.reset();
buf.putByte((byte) Session.SSH_MSG_CHANNEL_EOF);
buf.putInt(i);
synchronized (this) {
if (!close)
getSession().write(packet);
}
} catch (Exception e) {
// System.err.println("Channel.eof");
// e.printStackTrace();
}
/*
* if(!isConnected()){ disconnect(); }
*/
}
/*
* http://www1.ietf.org/internet-drafts/draft-ietf-secsh-connect-24.txt
*
* 5.3 Closing a Channel When a party will no longer send more data to a channel, it SHOULD send
* SSH_MSG_CHANNEL_EOF.
*
* byte SSH_MSG_CHANNEL_EOF uint32 recipient_channel
*
* No explicit response is sent to this message. However, the application may send EOF to whatever
* is at the other end of the channel. Note that the channel remains open after this message, and
* more data may still be sent in the other direction. This message does not consume window space
* and can be sent even if no window space is available.
*
* When either party wishes to terminate the channel, it sends SSH_MSG_CHANNEL_CLOSE. Upon
* receiving this message, a party MUST send back a SSH_MSG_CHANNEL_CLOSE unless it has already
* sent this message for the channel. The channel is considered closed for a party when it has
* both sent and received SSH_MSG_CHANNEL_CLOSE, and the party may then reuse the channel number.
* A party MAY send SSH_MSG_CHANNEL_CLOSE without having sent or received SSH_MSG_CHANNEL_EOF.
*
* byte SSH_MSG_CHANNEL_CLOSE uint32 recipient_channel
*
* This message does not consume window space and can be sent even if no window space is
* available.
*
* It is recommended that any data sent before this message is delivered to the actual
* destination, if possible.
*/
void close() {
if (close)
return;
close = true;
eof_local = eof_remote = true;
int i = getRecipient();
if (i == -1)
return;
try {
Buffer buf = new Buffer(100);
Packet packet = new Packet(buf);
packet.reset();
buf.putByte((byte) Session.SSH_MSG_CHANNEL_CLOSE);
buf.putInt(i);
synchronized (this) {
getSession().write(packet);
}
} catch (Exception e) {
// e.printStackTrace();
}
}
public boolean isClosed() {
return close;
}
static void disconnect(Session session) {
Channel[] channels = null;
int count = 0;
synchronized (pool) {
channels = new Channel[pool.size()];
for (int i = 0; i < pool.size(); i++) {
try {
Channel c = pool.elementAt(i);
if (c.session == session) {
channels[count++] = c;
}
} catch (Exception e) {
}
}
}
for (int i = 0; i < count; i++) {
channels[i].disconnect();
}
}
public void disconnect() {
// System.err.println(this+":disconnect "+io+" "+connected);
// Thread.dumpStack();
try {
synchronized (this) {
if (!connected) {
return;
}
connected = false;
}
close();
eof_remote = eof_local = true;
thread = null;
try {
if (io != null) {
io.close();
}
} catch (Exception e) {
// e.printStackTrace();
}
// io=null;
} finally {
Channel.del(this);
}
}
public boolean isConnected() {
Session _session = this.session;
if (_session != null) {
return _session.isConnected() && connected;
}
return false;
}
public void sendSignal(String signal) throws Exception {
RequestSignal request = new RequestSignal();
request.setSignal(signal);
request.request(getSession(), this);
}
// public String toString(){
// return "Channel: type="+new
// String(type)+",id="+id+",recipient="+recipient+",window_size="+window_size+",packet_size="+packet_size;
// }
/*
* class OutputThread extends Thread{ Channel c; OutputThread(Channel c){ this.c=c;} public void
* run(){c.output_thread();} }
*/
static class PassiveInputStream extends MyPipedInputStream {
PipedOutputStream os;
PassiveInputStream(PipedOutputStream out, int size) throws IOException {
super(out, size);
this.os = out;
}
PassiveInputStream(PipedOutputStream out) throws IOException {
super(out);
this.os = out;
}
@Override
public void close() throws IOException {
if (this.os != null) {
this.os.close();
}
this.os = null;
}
}
static class PassiveOutputStream extends PipedOutputStream {
private MyPipedInputStream _sink = null;
PassiveOutputStream(PipedInputStream in, boolean resizable_buffer) throws IOException {
super(in);
if (resizable_buffer && (in instanceof MyPipedInputStream)) {
this._sink = (MyPipedInputStream) in;
}
}
@Override
public void write(int b) throws IOException {
if (_sink != null) {
_sink.checkSpace(1);
}
super.write(b);
}
@Override
public void write(byte[] b, int off, int len) throws IOException {
if (_sink != null) {
_sink.checkSpace(len);
}
super.write(b, off, len);
}
}
void setExitStatus(int status) {
exitstatus = status;
}
public int getExitStatus() {
return exitstatus;
}
void setSession(Session session) {
this.session = session;
}
public Session getSession() throws JSchException {
Session _session = session;
if (_session == null) {
throw new JSchException("session is not available");
}
return _session;
}
public int getId() {
return id;
}
protected void sendOpenConfirmation() throws Exception {
Buffer buf = new Buffer(200);
Packet packet = new Packet(buf);
packet.reset();
buf.putByte((byte) SSH_MSG_CHANNEL_OPEN_CONFIRMATION);
buf.putInt(getRecipient());
buf.putInt(id);
buf.putInt(lwsize);
buf.putInt(lmpsize);
getSession().write(packet);
}
protected void sendOpenFailure(int reasoncode) {
try {
Buffer buf = new Buffer(200);
Packet packet = new Packet(buf);
packet.reset();
buf.putByte((byte) SSH_MSG_CHANNEL_OPEN_FAILURE);
buf.putInt(getRecipient());
buf.putInt(reasoncode);
buf.putString(Util.str2byte("open failed"));
buf.putString(Util.empty);
getSession().write(packet);
} catch (Exception e) {
}
}
protected Packet genChannelOpenPacket() {
Buffer buf = new Buffer(200);
Packet packet = new Packet(buf);
// byte SSH_MSG_CHANNEL_OPEN(90)
// string channel type //
// uint32 sender channel // 0
// uint32 initial window size // 0x100000(65536)
// uint32 maxmum packet size // 0x4000(16384)
packet.reset();
buf.putByte((byte) 90);
buf.putString(this.type);
buf.putInt(this.id);
buf.putInt(this.lwsize);
buf.putInt(this.lmpsize);
return packet;
}
protected void sendChannelOpen() throws Exception {
Session _session = getSession();
if (!_session.isConnected()) {
throw new JSchException("session is down");
}
Packet packet = genChannelOpenPacket();
_session.write(packet);
int retry = 2000;
long start = System.currentTimeMillis();
long timeout = connectTimeout;
if (timeout != 0L)
retry = 1;
synchronized (this) {
while (this.getRecipient() == -1 && _session.isConnected() && retry > 0) {
if (timeout > 0L) {
if ((System.currentTimeMillis() - start) > timeout) {
retry = 0;
continue;
}
}
try {
long t = timeout == 0L ? 10L : timeout;
this.notifyme = 1;
wait(t);
} catch (InterruptedException e) {
} finally {
this.notifyme = 0;
}
retry--;
}
}
if (!_session.isConnected()) {
throw new JSchException("session is down");
}
if (this.getRecipient() == -1) { // timeout
throw new JSchException("channel is not opened.");
}
if (this.open_confirmation == false) { // SSH_MSG_CHANNEL_OPEN_FAILURE
throw new JSchException("channel is not opened.");
}
connected = true;
}
}

@ -0,0 +1,268 @@
/*
* Copyright (c) 2006-2018 ymnk, JCraft,Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted
* provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions
* and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other materials provided with
* the distribution.
*
* 3. The names of the authors may not be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL JCRAFT, INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.jcraft.jsch;
import java.io.IOException;
import java.util.Vector;
class ChannelAgentForwarding extends Channel {
private static final int LOCAL_WINDOW_SIZE_MAX = 0x20000;
private static final int LOCAL_MAXIMUM_PACKET_SIZE = 0x4000;
private static final byte SSH_AGENTC_REQUEST_RSA_IDENTITIES = 1;
private static final byte SSH_AGENT_RSA_IDENTITIES_ANSWER = 2;
private static final byte SSH_AGENTC_RSA_CHALLENGE = 3;
private static final byte SSH_AGENT_RSA_RESPONSE = 4;
private static final byte SSH_AGENT_FAILURE = 5;
private static final byte SSH_AGENT_SUCCESS = 6;
private static final byte SSH_AGENTC_ADD_RSA_IDENTITY = 7;
private static final byte SSH_AGENTC_REMOVE_RSA_IDENTITY = 8;
private static final byte SSH_AGENTC_REMOVE_ALL_RSA_IDENTITIES = 9;
private static final byte SSH2_AGENTC_REQUEST_IDENTITIES = 11;
private static final byte SSH2_AGENT_IDENTITIES_ANSWER = 12;
private static final byte SSH2_AGENTC_SIGN_REQUEST = 13;
private static final byte SSH2_AGENT_SIGN_RESPONSE = 14;
private static final byte SSH2_AGENTC_ADD_IDENTITY = 17;
private static final byte SSH2_AGENTC_REMOVE_IDENTITY = 18;
private static final byte SSH2_AGENTC_REMOVE_ALL_IDENTITIES = 19;
private static final byte SSH2_AGENT_FAILURE = 30;
// static private final int SSH_AGENT_OLD_SIGNATURE=0x1;
private static final int SSH_AGENT_RSA_SHA2_256 = 0x2;
private static final int SSH_AGENT_RSA_SHA2_512 = 0x4;
private Buffer rbuf = null;
private Buffer wbuf = null;
private Packet packet = null;
private Buffer mbuf = null;
ChannelAgentForwarding() {
super();
lwsize_max = LOCAL_WINDOW_SIZE_MAX;
lwsize = LOCAL_WINDOW_SIZE_MAX;
lmpsize = LOCAL_MAXIMUM_PACKET_SIZE;
type = Util.str2byte("auth-agent@openssh.com");
rbuf = new Buffer();
rbuf.reset();
// wbuf=new Buffer(rmpsize);
// packet=new Packet(wbuf);
mbuf = new Buffer();
connected = true;
}
@Override
void run() {
try {
sendOpenConfirmation();
} catch (Exception e) {
close = true;
disconnect();
}
}
@Override
void write(byte[] foo, int s, int l) throws IOException {
if (packet == null) {
wbuf = new Buffer(rmpsize);
packet = new Packet(wbuf);
}
rbuf.shift();
if (rbuf.buffer.length < rbuf.index + l) {
byte[] newbuf = new byte[rbuf.s + l];
System.arraycopy(rbuf.buffer, 0, newbuf, 0, rbuf.buffer.length);
rbuf.buffer = newbuf;
}
rbuf.putByte(foo, s, l);
int mlen = rbuf.getInt();
if (mlen > rbuf.getLength()) {
rbuf.s -= 4;
return;
}
int typ = rbuf.getByte();
Session _session = null;
try {
_session = getSession();
} catch (JSchException e) {
throw new IOException(e.toString(), e);
}
IdentityRepository irepo = _session.getIdentityRepository();
UserInfo userinfo = _session.getUserInfo();
mbuf.reset();
if (typ == SSH2_AGENTC_REQUEST_IDENTITIES) {
mbuf.putByte(SSH2_AGENT_IDENTITIES_ANSWER);
Vector<Identity> identities = irepo.getIdentities();
synchronized (identities) {
int count = 0;
for (int i = 0; i < identities.size(); i++) {
Identity identity = identities.elementAt(i);
if (identity.getPublicKeyBlob() != null)
count++;
}
mbuf.putInt(count);
for (int i = 0; i < identities.size(); i++) {
Identity identity = identities.elementAt(i);
byte[] pubkeyblob = identity.getPublicKeyBlob();
if (pubkeyblob == null)
continue;
mbuf.putString(pubkeyblob);
mbuf.putString(Util.empty);
}
}
} else if (typ == SSH_AGENTC_REQUEST_RSA_IDENTITIES) {
mbuf.putByte(SSH_AGENT_RSA_IDENTITIES_ANSWER);
mbuf.putInt(0);
} else if (typ == SSH2_AGENTC_SIGN_REQUEST) {
byte[] blob = rbuf.getString();
byte[] data = rbuf.getString();
int flags = rbuf.getInt();
// if((flags & SSH_AGENT_OLD_SIGNATURE)!=0){ // old OpenSSH 2.0, 2.1
// datafellows = SSH_BUG_SIGBLOB;
// }
Vector<Identity> identities = irepo.getIdentities();
Identity identity = null;
synchronized (identities) {
for (int i = 0; i < identities.size(); i++) {
Identity _identity = identities.elementAt(i);
if (_identity.getPublicKeyBlob() == null)
continue;
if (!Util.array_equals(blob, _identity.getPublicKeyBlob())) {
continue;
}
if (_identity.isEncrypted()) {
if (userinfo == null)
continue;
while (_identity.isEncrypted()) {
if (!userinfo.promptPassphrase("Passphrase for " + _identity.getName())) {
break;
}
String _passphrase = userinfo.getPassphrase();
if (_passphrase == null) {
break;
}
byte[] passphrase = Util.str2byte(_passphrase);
try {
if (_identity.setPassphrase(passphrase)) {
break;
}
} catch (JSchException e) {
break;
}
}
}
if (!_identity.isEncrypted()) {
identity = _identity;
break;
}
}
}
byte[] signature = null;
if (identity != null) {
Buffer kbuf = new Buffer(blob);
String keytype = Util.byte2str(kbuf.getString());
if (keytype.equals("ssh-rsa")) {
if ((flags & SSH_AGENT_RSA_SHA2_256) != 0) {
signature = identity.getSignature(data, "rsa-sha2-256");
} else if ((flags & SSH_AGENT_RSA_SHA2_512) != 0) {
signature = identity.getSignature(data, "rsa-sha2-512");
} else {
signature = identity.getSignature(data, "ssh-rsa");
}
} else {
signature = identity.getSignature(data);
}
}
if (signature == null) {
mbuf.putByte(SSH2_AGENT_FAILURE);
} else {
mbuf.putByte(SSH2_AGENT_SIGN_RESPONSE);
mbuf.putString(signature);
}
} else if (typ == SSH2_AGENTC_REMOVE_IDENTITY) {
byte[] blob = rbuf.getString();
irepo.remove(blob);
mbuf.putByte(SSH_AGENT_SUCCESS);
} else if (typ == SSH_AGENTC_REMOVE_ALL_RSA_IDENTITIES) {
mbuf.putByte(SSH_AGENT_SUCCESS);
} else if (typ == SSH2_AGENTC_REMOVE_ALL_IDENTITIES) {
irepo.removeAll();
mbuf.putByte(SSH_AGENT_SUCCESS);
} else if (typ == SSH2_AGENTC_ADD_IDENTITY) {
int fooo = rbuf.getLength();
byte[] tmp = new byte[fooo];
rbuf.getByte(tmp);
boolean result = irepo.add(tmp);
mbuf.putByte(result ? SSH_AGENT_SUCCESS : SSH_AGENT_FAILURE);
} else {
rbuf.skip(rbuf.getLength() - 1);
mbuf.putByte(SSH_AGENT_FAILURE);
}
byte[] response = new byte[mbuf.getLength()];
mbuf.getByte(response);
send(response);
}
private void send(byte[] message) {
packet.reset();
wbuf.putByte((byte) Session.SSH_MSG_CHANNEL_DATA);
wbuf.putInt(recipient);
wbuf.putInt(4 + message.length);
wbuf.putString(message);
try {
getSession().write(packet, this, 4 + message.length);
} catch (Exception e) {
}
}
@Override
void eof_remote() {
super.eof_remote();
eof();
}
}

@ -0,0 +1,65 @@
package com.jcraft.jsch;
import static com.jcraft.jsch.Session.SSH_MSG_CHANNEL_OPEN;
/**
* Extension of {@link ChannelDirectTCPIP} to support socket forwarding.
*
* <p>
* https://raw.githubusercontent.com/openssh/openssh-portable/master/PROTOCOL
*/
public class ChannelDirectStreamLocal extends ChannelDirectTCPIP {
private static final int LOCAL_WINDOW_SIZE_MAX = 0x20000;
private static final int LOCAL_MAXIMUM_PACKET_SIZE = 0x4000;
private static final byte[] _type = Util.str2byte("direct-streamlocal@openssh.com");
private String socketPath;
ChannelDirectStreamLocal() {
super();
type = _type;
lwsize_max = LOCAL_WINDOW_SIZE_MAX;
lwsize = LOCAL_WINDOW_SIZE_MAX;
lmpsize = LOCAL_MAXIMUM_PACKET_SIZE;
}
@Override
protected Packet genChannelOpenPacket() {
if (socketPath == null) {
session.getLogger().log(Logger.FATAL, "socketPath must be set");
throw new RuntimeException("socketPath must be set");
}
/*
* Similar to direct-tcpip, direct-streamlocal is sent by the client to request that the server
* make a connection to a Unix domain socket.
*
* byte SSH_MSG_CHANNEL_OPEN string "direct-streamlocal@openssh.com" uint32 sender channel
* uint32 initial window size uint32 maximum packet size string socket path string reserved
* uint32 reserved
*/
Buffer buf = new Buffer(50 + socketPath.length() + session.getBufferMargin());
Packet packet = new Packet(buf);
packet.reset();
buf.putByte((byte) SSH_MSG_CHANNEL_OPEN);
buf.putString(this.type);
buf.putInt(id);
buf.putInt(lwsize);
buf.putInt(lmpsize);
buf.putString(Util.str2byte(socketPath));
buf.putString(Util.str2byte(originator_IP_address));
buf.putInt(originator_port);
return packet;
}
public String getSocketPath() {
return socketPath;
}
public void setSocketPath(String socketPath) {
this.socketPath = socketPath;
}
}

@ -0,0 +1,175 @@
/*
* Copyright (c) 2002-2018 ymnk, JCraft,Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted
* provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions
* and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other materials provided with
* the distribution.
*
* 3. The names of the authors may not be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL JCRAFT, INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.jcraft.jsch;
import java.io.InputStream;
import java.io.OutputStream;
public class ChannelDirectTCPIP extends Channel {
private static final int LOCAL_WINDOW_SIZE_MAX = 0x20000;
private static final int LOCAL_MAXIMUM_PACKET_SIZE = 0x4000;
private static final byte[] _type = Util.str2byte("direct-tcpip");
String host;
int port;
String originator_IP_address = "127.0.0.1";
int originator_port = 0;
ChannelDirectTCPIP() {
super();
type = _type;
lwsize_max = LOCAL_WINDOW_SIZE_MAX;
lwsize = LOCAL_WINDOW_SIZE_MAX;
lmpsize = LOCAL_MAXIMUM_PACKET_SIZE;
}
@Override
void init() {
io = new IO();
}
@Override
public void connect(int connectTimeout) throws JSchException {
this.connectTimeout = connectTimeout;
try {
Session _session = getSession();
if (!_session.isConnected()) {
throw new JSchException("session is down");
}
if (io.in != null) {
thread = new Thread(this::run);
thread.setName("DirectTCPIP thread " + _session.getHost());
if (_session.daemon_thread) {
thread.setDaemon(_session.daemon_thread);
}
thread.start();
} else {
sendChannelOpen();
}
} catch (Exception e) {
io.close();
io = null;
Channel.del(this);
if (e instanceof JSchException) {
throw (JSchException) e;
}
}
}
@Override
void run() {
try {
sendChannelOpen();
Buffer buf = new Buffer(rmpsize);
Packet packet = new Packet(buf);
Session _session = getSession();
int i = 0;
while (isConnected() && thread != null && io != null && io.in != null) {
i = io.in.read(buf.buffer, 14, buf.buffer.length - 14 - _session.getBufferMargin());
if (i <= 0) {
eof();
break;
}
packet.reset();
buf.putByte((byte) Session.SSH_MSG_CHANNEL_DATA);
buf.putInt(recipient);
buf.putInt(i);
buf.skip(i);
synchronized (this) {
if (close)
break;
_session.write(packet, this, i);
}
}
} catch (Exception e) {
// Whenever an exception is thrown by sendChannelOpen(),
// 'connected' is false.
if (!connected) {
connected = true;
}
disconnect();
return;
}
eof();
disconnect();
}
@Override
public void setInputStream(InputStream in) {
io.setInputStream(in);
}
@Override
public void setOutputStream(OutputStream out) {
io.setOutputStream(out);
}
public void setHost(String host) {
this.host = host;
}
public void setPort(int port) {
this.port = port;
}
public void setOrgIPAddress(String foo) {
this.originator_IP_address = foo;
}
public void setOrgPort(int foo) {
this.originator_port = foo;
}
@Override
protected Packet genChannelOpenPacket() {
Buffer buf = new Buffer(50 + // 6 + 4*8 + 12
host.length() + originator_IP_address.length() + session.getBufferMargin());
Packet packet = new Packet(buf);
// byte SSH_MSG_CHANNEL_OPEN(90)
// string channel type //
// uint32 sender channel // 0
// uint32 initial window size // 0x100000(65536)
// uint32 maxmum packet size // 0x4000(16384)
packet.reset();
buf.putByte((byte) 90);
buf.putString(this.type);
buf.putInt(id);
buf.putInt(lwsize);
buf.putInt(lmpsize);
buf.putString(Util.str2byte(host));
buf.putInt(port);
buf.putString(Util.str2byte(originator_IP_address));
buf.putInt(originator_port);
return packet;
}
}

@ -0,0 +1,85 @@
/*
* Copyright (c) 2002-2018 ymnk, JCraft,Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted
* provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions
* and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other materials provided with
* the distribution.
*
* 3. The names of the authors may not be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL JCRAFT, INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.jcraft.jsch;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
public class ChannelExec extends ChannelSession {
byte[] command = new byte[0];
@Override
public void start() throws JSchException {
Session _session = getSession();
try {
sendRequests();
Request request = new RequestExec(command);
request.request(_session, this);
} catch (Exception e) {
if (e instanceof JSchException)
throw (JSchException) e;
throw new JSchException("ChannelExec", e);
}
if (io.in != null) {
thread = new Thread(this::run);
thread.setName("Exec thread " + _session.getHost());
if (_session.daemon_thread) {
thread.setDaemon(_session.daemon_thread);
}
thread.start();
}
}
public void setCommand(String command) {
this.command = Util.str2byte(command);
}
public void setCommand(byte[] command) {
this.command = command;
}
@Override
void init() throws JSchException {
io.setInputStream(getSession().in);
io.setOutputStream(getSession().out);
}
public void setErrStream(OutputStream out) {
setExtOutputStream(out);
}
public void setErrStream(OutputStream out, boolean dontclose) {
setExtOutputStream(out, dontclose);
}
public InputStream getErrStream() throws IOException {
return getExtInputStream();
}
}

@ -0,0 +1,334 @@
/*
* Copyright (c) 2002-2018 ymnk, JCraft,Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted
* provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions
* and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other materials provided with
* the distribution.
*
* 3. The names of the authors may not be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL JCRAFT, INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.jcraft.jsch;
import java.io.PipedOutputStream;
import java.net.Socket;
import java.util.Vector;
public class ChannelForwardedTCPIP extends Channel {
private static Vector<Config> pool = new Vector<>();
private static final int LOCAL_WINDOW_SIZE_MAX = 0x20000;
// static private final int LOCAL_WINDOW_SIZE_MAX=0x100000;
private static final int LOCAL_MAXIMUM_PACKET_SIZE = 0x4000;
private static final int TIMEOUT = 10 * 1000;
private Socket socket = null;
private ForwardedTCPIPDaemon daemon = null;
private Config config = null;
ChannelForwardedTCPIP() {
super();
lwsize_max = LOCAL_WINDOW_SIZE_MAX;
lwsize = LOCAL_WINDOW_SIZE_MAX;
lmpsize = LOCAL_MAXIMUM_PACKET_SIZE;
io = new IO();
connected = true;
}
@Override
public void run() {
try {
if (config instanceof ConfigDaemon) {
ConfigDaemon _config = (ConfigDaemon) config;
Class<? extends ForwardedTCPIPDaemon> c =
Class.forName(_config.target).asSubclass(ForwardedTCPIPDaemon.class);
daemon = c.getDeclaredConstructor().newInstance();
PipedOutputStream out = new PipedOutputStream();
io.setInputStream(new PassiveInputStream(out, 32 * 1024), false);
daemon.setChannel(this, getInputStream(), out);
daemon.setArg(_config.arg);
new Thread(daemon).start();
} else {
ConfigLHost _config = (ConfigLHost) config;
socket =
(_config.factory == null) ? Util.createSocket(_config.target, _config.lport, TIMEOUT)
: _config.factory.createSocket(_config.target, _config.lport);
socket.setTcpNoDelay(true);
io.setInputStream(socket.getInputStream());
io.setOutputStream(socket.getOutputStream());
}
sendOpenConfirmation();
} catch (Exception e) {
sendOpenFailure(SSH_OPEN_ADMINISTRATIVELY_PROHIBITED);
close = true;
disconnect();
return;
}
thread = Thread.currentThread();
Buffer buf = new Buffer(rmpsize);
Packet packet = new Packet(buf);
int i = 0;
try {
Session _session = getSession();
while (thread != null && io != null && io.in != null) {
i = io.in.read(buf.buffer, 14, buf.buffer.length - 14 - _session.getBufferMargin());
if (i <= 0) {
eof();
break;
}
packet.reset();
buf.putByte((byte) Session.SSH_MSG_CHANNEL_DATA);
buf.putInt(recipient);
buf.putInt(i);
buf.skip(i);
synchronized (this) {
if (close)
break;
_session.write(packet, this, i);
}
}
} catch (Exception e) {
// System.err.println(e);
}
// thread=null;
// eof();
disconnect();
}
@Override
void getData(Buffer buf) {
setRecipient(buf.getInt());
setRemoteWindowSize(buf.getUInt());
setRemotePacketSize(buf.getInt());
byte[] addr = buf.getString();
int port = buf.getInt();
byte[] orgaddr = buf.getString();
int orgport = buf.getInt();
/*
* System.err.println("addr: "+Util.byte2str(addr)); System.err.println("port: "+port);
* System.err.println("orgaddr: "+Util.byte2str(orgaddr));
* System.err.println("orgport: "+orgport);
*/
Session _session = null;
try {
_session = getSession();
} catch (JSchException e) {
// session has been already down.
}
this.config = getPort(_session, Util.byte2str(addr), port);
if (this.config == null)
this.config = getPort(_session, null, port);
if (this.config == null) {
if (_session.getLogger().isEnabled(Logger.ERROR)) {
_session.getLogger().log(Logger.ERROR,
"ChannelForwardedTCPIP: " + Util.byte2str(addr) + ":" + port + " is not registered.");
}
}
}
private static Config getPort(Session session, String address_to_bind, int rport) {
synchronized (pool) {
for (int i = 0; i < pool.size(); i++) {
Config bar = pool.elementAt(i);
if (bar.session != session)
continue;
if (bar.rport != rport) {
if (bar.rport != 0 || bar.allocated_rport != rport)
continue;
}
if (address_to_bind != null && !bar.address_to_bind.equals(address_to_bind))
continue;
return bar;
}
return null;
}
}
static String[] getPortForwarding(Session session) {
Vector<String> foo = new Vector<>();
synchronized (pool) {
for (int i = 0; i < pool.size(); i++) {
Config config = pool.elementAt(i);
if (config.session == session) {
if (config instanceof ConfigDaemon)
foo.addElement(config.allocated_rport + ":" + config.target + ":");
else
foo.addElement(
config.allocated_rport + ":" + config.target + ":" + ((ConfigLHost) config).lport);
}
}
}
String[] bar = new String[foo.size()];
for (int i = 0; i < foo.size(); i++) {
bar[i] = foo.elementAt(i);
}
return bar;
}
static String normalize(String address) {
if (address == null) {
return "localhost";
} else if (address.length() == 0 || address.equals("*")) {
return "";
} else {
return address;
}
}
static void addPort(Session session, String _address_to_bind, int port, int allocated_port,
String target, int lport, SocketFactory factory) throws JSchException {
String address_to_bind = normalize(_address_to_bind);
synchronized (pool) {
if (getPort(session, address_to_bind, port) != null) {
throw new JSchException("PortForwardingR: remote port " + port + " is already registered.");
}
ConfigLHost config = new ConfigLHost();
config.session = session;
config.rport = port;
config.allocated_rport = allocated_port;
config.target = target;
config.lport = lport;
config.address_to_bind = address_to_bind;
config.factory = factory;
pool.addElement(config);
}
}
static void addPort(Session session, String _address_to_bind, int port, int allocated_port,
String daemon, Object[] arg) throws JSchException {
String address_to_bind = normalize(_address_to_bind);
synchronized (pool) {
if (getPort(session, address_to_bind, port) != null) {
throw new JSchException("PortForwardingR: remote port " + port + " is already registered.");
}
ConfigDaemon config = new ConfigDaemon();
config.session = session;
config.rport = port;
config.allocated_rport = port;
config.target = daemon;
config.arg = arg;
config.address_to_bind = address_to_bind;
pool.addElement(config);
}
}
static void delPort(ChannelForwardedTCPIP c) {
Session _session = null;
try {
_session = c.getSession();
} catch (JSchException e) {
// session has been already down.
}
if (_session != null && c.config != null)
delPort(_session, c.config.rport);
}
static void delPort(Session session, int rport) {
delPort(session, null, rport);
}
static void delPort(Session session, String address_to_bind, int rport) {
synchronized (pool) {
Config foo = getPort(session, normalize(address_to_bind), rport);
if (foo == null)
foo = getPort(session, null, rport);
if (foo == null)
return;
pool.removeElement(foo);
if (address_to_bind == null) {
address_to_bind = foo.address_to_bind;
}
if (address_to_bind == null) {
address_to_bind = "0.0.0.0";
}
}
Buffer buf = new Buffer(200); // ??
Packet packet = new Packet(buf);
try {
// byte SSH_MSG_GLOBAL_REQUEST 80
// string "cancel-tcpip-forward"
// boolean want_reply
// string address_to_bind (e.g. "127.0.0.1")
// uint32 port number to bind
packet.reset();
buf.putByte((byte) 80 /* SSH_MSG_GLOBAL_REQUEST */);
buf.putString(Util.str2byte("cancel-tcpip-forward"));
buf.putByte((byte) 0);
buf.putString(Util.str2byte(address_to_bind));
buf.putInt(rport);
session.write(packet);
} catch (Exception e) {
// throw new JSchException(e.toString(), e);
}
}
static void delPort(Session session) {
int[] rport = null;
int count = 0;
synchronized (pool) {
rport = new int[pool.size()];
for (int i = 0; i < pool.size(); i++) {
Config config = pool.elementAt(i);
if (config.session == session) {
rport[count++] = config.rport; // ((Integer)bar[1]).intValue();
}
}
}
for (int i = 0; i < count; i++) {
delPort(session, rport[i]);
}
}
public int getRemotePort() {
return (config != null ? config.rport : 0);
}
private void setSocketFactory(SocketFactory factory) {
if (config != null && (config instanceof ConfigLHost))
((ConfigLHost) config).factory = factory;
}
abstract static class Config {
Session session;
int rport;
int allocated_rport;
String address_to_bind;
String target;
}
static class ConfigDaemon extends Config {
Object[] arg;
}
static class ConfigLHost extends Config {
int lport;
SocketFactory factory;
}
}

@ -0,0 +1,265 @@
/*
* Copyright (c) 2002-2018 ymnk, JCraft,Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted
* provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions
* and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other materials provided with
* the distribution.
*
* 3. The names of the authors may not be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL JCRAFT, INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.jcraft.jsch;
import java.util.Enumeration;
import java.util.Hashtable;
class ChannelSession extends Channel {
private static byte[] _session = Util.str2byte("session");
protected boolean agent_forwarding = false;
protected boolean xforwading = false;
protected Hashtable<byte[], byte[]> env = null;
protected boolean pty = false;
protected String ttype = "vt100";
protected int tcol = 80;
protected int trow = 24;
protected int twp = 640;
protected int thp = 480;
protected byte[] terminal_mode = null;
ChannelSession() {
super();
type = _session;
io = new IO();
}
/**
* Enable the agent forwarding.
*
* @param enable
*/
public void setAgentForwarding(boolean enable) {
agent_forwarding = enable;
}
/**
* Enable the X11 forwarding. Refer to RFC4254 6.3.1. Requesting X11 Forwarding.
*
* @param enable
*/
@Override
public void setXForwarding(boolean enable) {
xforwading = enable;
}
/**
* @deprecated Use #setEnv(String, String) or #setEnv(byte[], byte[]) instead.
* @see #setEnv(String, String)
* @see #setEnv(byte[], byte[])
*/
@Deprecated
public void setEnv(Hashtable<byte[], byte[]> env) {
synchronized (this) {
this.env = env;
}
}
/**
* Set the environment variable. If <code>name</code> and <code>value</code> are needed to be
* passed to the remote in your favorite encoding, use {@link #setEnv(byte[], byte[])}. Refer to
* RFC4254 6.4 Environment Variable Passing.
*
* @param name A name for environment variable.
* @param value A value for environment variable.
*/
public void setEnv(String name, String value) {
setEnv(Util.str2byte(name), Util.str2byte(value));
}
/**
* Set the environment variable. Refer to RFC4254 6.4 Environment Variable Passing.
*
* @param name A name of environment variable.
* @param value A value of environment variable.
* @see #setEnv(String, String)
*/
public void setEnv(byte[] name, byte[] value) {
synchronized (this) {
getEnv().put(name, value);
}
}
private Hashtable<byte[], byte[]> getEnv() {
if (env == null)
env = new Hashtable<>();
return env;
}
/**
* Allocate a Pseudo-Terminal. Refer to RFC4254 6.2. Requesting a Pseudo-Terminal.
*
* @param enable
*/
public void setPty(boolean enable) {
pty = enable;
}
/**
* Set the terminal mode.
*
* @param terminal_mode
*/
public void setTerminalMode(byte[] terminal_mode) {
this.terminal_mode = terminal_mode;
}
/**
* Change the window dimension interactively. Refer to RFC4254 6.7. Window Dimension Change
* Message.
*
* @param col terminal width, columns
* @param row terminal height, rows
* @param wp terminal width, pixels
* @param hp terminal height, pixels
*/
public void setPtySize(int col, int row, int wp, int hp) {
setPtyType(this.ttype, col, row, wp, hp);
if (!pty || !isConnected()) {
return;
}
try {
RequestWindowChange request = new RequestWindowChange();
request.setSize(col, row, wp, hp);
request.request(getSession(), this);
} catch (Exception e) {
// System.err.println("ChannelSessio.setPtySize: "+e);
}
}
/**
* Set the terminal type. This method is not effective after Channel#connect().
*
* @param ttype terminal type(for example, "vt100")
* @see #setPtyType(String, int, int, int, int)
*/
public void setPtyType(String ttype) {
setPtyType(ttype, 80, 24, 640, 480);
}
/**
* Set the terminal type. This method is not effective after Channel#connect().
*
* @param ttype terminal type(for example, "vt100")
* @param col terminal width, columns
* @param row terminal height, rows
* @param wp terminal width, pixels
* @param hp terminal height, pixels
*/
public void setPtyType(String ttype, int col, int row, int wp, int hp) {
this.ttype = ttype;
this.tcol = col;
this.trow = row;
this.twp = wp;
this.thp = hp;
}
protected void sendRequests() throws Exception {
Session _session = getSession();
Request request;
if (agent_forwarding) {
request = new RequestAgentForwarding();
request.request(_session, this);
}
if (xforwading) {
request = new RequestX11();
request.request(_session, this);
}
if (pty) {
request = new RequestPtyReq();
((RequestPtyReq) request).setTType(ttype);
((RequestPtyReq) request).setTSize(tcol, trow, twp, thp);
if (terminal_mode != null) {
((RequestPtyReq) request).setTerminalMode(terminal_mode);
}
request.request(_session, this);
}
if (env != null) {
for (Enumeration<byte[]> _env = env.keys(); _env.hasMoreElements();) {
byte[] name = _env.nextElement();
byte[] value = env.get(name);
request = new RequestEnv();
((RequestEnv) request).setEnv(toByteArray(name), toByteArray(value));
request.request(_session, this);
}
}
}
private byte[] toByteArray(Object o) {
if (o instanceof String) {
return Util.str2byte((String) o);
}
return (byte[]) o;
}
@Override
void run() {
// System.err.println(this+":run >");
Buffer buf = new Buffer(rmpsize);
Packet packet = new Packet(buf);
int i = -1;
try {
Session _session = getSession();
while (isConnected() && thread != null && io != null && io.in != null) {
i = io.in.read(buf.buffer, 14, buf.buffer.length - 14 - _session.getBufferMargin());
if (i == 0)
continue;
if (i == -1) {
eof();
break;
}
if (close)
break;
// System.out.println("write: "+i);
packet.reset();
buf.putByte((byte) Session.SSH_MSG_CHANNEL_DATA);
buf.putInt(recipient);
buf.putInt(i);
buf.skip(i);
_session.write(packet, this, i);
}
} catch (Exception e) {
// System.err.println("# ChannelExec.run");
// e.printStackTrace();
}
Thread _thread = thread;
if (_thread != null) {
synchronized (_thread) {
_thread.notifyAll();
}
}
thread = null;
// System.err.println(this+":run <");
}
}

File diff suppressed because it is too large Load Diff

@ -0,0 +1,65 @@
/*
* Copyright (c) 2002-2018 ymnk, JCraft,Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted
* provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions
* and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other materials provided with
* the distribution.
*
* 3. The names of the authors may not be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL JCRAFT, INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.jcraft.jsch;
public class ChannelShell extends ChannelSession {
ChannelShell() {
super();
pty = true;
}
@Override
public void start() throws JSchException {
Session _session = getSession();
try {
sendRequests();
Request request = new RequestShell();
request.request(_session, this);
} catch (Exception e) {
if (e instanceof JSchException)
throw (JSchException) e;
throw new JSchException("ChannelShell", e);
}
if (io.in != null) {
thread = new Thread(this::run);
thread.setName("Shell for " + _session.host);
if (_session.daemon_thread) {
thread.setDaemon(_session.daemon_thread);
}
thread.start();
}
}
@Override
void init() throws JSchException {
io.setInputStream(getSession().in);
io.setOutputStream(getSession().out);
}
}

@ -0,0 +1,89 @@
/*
* Copyright (c) 2005-2018 ymnk, JCraft,Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted
* provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions
* and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other materials provided with
* the distribution.
*
* 3. The names of the authors may not be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL JCRAFT, INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.jcraft.jsch;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
public class ChannelSubsystem extends ChannelSession {
boolean want_reply = true;
String subsystem = "";
public void setWantReply(boolean foo) {
want_reply = foo;
}
public void setSubsystem(String foo) {
subsystem = foo;
}
@Override
public void start() throws JSchException {
Session _session = getSession();
try {
Request request;
if (xforwading) {
request = new RequestX11();
request.request(_session, this);
}
if (pty) {
request = new RequestPtyReq();
request.request(_session, this);
}
request = new RequestSubsystem();
((RequestSubsystem) request).request(_session, this, subsystem, want_reply);
} catch (Exception e) {
if (e instanceof JSchException) {
throw (JSchException) e;
}
throw new JSchException("ChannelSubsystem", e);
}
if (io.in != null) {
thread = new Thread(this::run);
thread.setName("Subsystem for " + _session.host);
if (_session.daemon_thread) {
thread.setDaemon(_session.daemon_thread);
}
thread.start();
}
}
@Override
void init() throws JSchException {
io.setInputStream(getSession().in);
io.setOutputStream(getSession().out);
}
public void setErrStream(OutputStream out) {
setExtOutputStream(out);
}
public InputStream getErrStream() throws IOException {
return getExtInputStream();
}
}

@ -0,0 +1,262 @@
/*
* Copyright (c) 2002-2018 ymnk, JCraft,Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted
* provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions
* and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other materials provided with
* the distribution.
*
* 3. The names of the authors may not be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL JCRAFT, INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.jcraft.jsch;
import java.io.IOException;
import java.net.Socket;
import java.util.Hashtable;
class ChannelX11 extends Channel {
private static final int LOCAL_WINDOW_SIZE_MAX = 0x20000;
private static final int LOCAL_MAXIMUM_PACKET_SIZE = 0x4000;
private static final int TIMEOUT = 10 * 1000;
private static String host = "127.0.0.1";
private static int port = 6000;
private boolean init = true;
static byte[] cookie = null;
private static byte[] cookie_hex = null;
private static Hashtable<Session, byte[]> faked_cookie_pool = new Hashtable<>();
private static Hashtable<Session, byte[]> faked_cookie_hex_pool = new Hashtable<>();
private static byte[] table = {0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x61,
0x62, 0x63, 0x64, 0x65, 0x66};
private Socket socket = null;
static int revtable(byte foo) {
for (int i = 0; i < table.length; i++) {
if (table[i] == foo)
return i;
}
return 0;
}
static void setCookie(String foo) {
cookie_hex = Util.str2byte(foo);
cookie = new byte[16];
for (int i = 0; i < 16; i++) {
cookie[i] = (byte) (((revtable(cookie_hex[i * 2]) << 4) & 0xf0)
| ((revtable(cookie_hex[i * 2 + 1])) & 0xf));
}
}
static void setHost(String foo) {
host = foo;
}
static void setPort(int foo) {
port = foo;
}
static byte[] getFakedCookie(Session session) {
synchronized (faked_cookie_hex_pool) {
byte[] foo = faked_cookie_hex_pool.get(session);
if (foo == null) {
Random random = Session.random;
foo = new byte[16];
synchronized (random) {
random.fill(foo, 0, 16);
}
/*
* System.err.print("faked_cookie: "); for(int i=0; i<foo.length; i++){
* System.err.print(Integer.toHexString(foo[i]&0xff)+":"); } System.err.println("");
*/
faked_cookie_pool.put(session, foo);
byte[] bar = new byte[32];
for (int i = 0; i < 16; i++) {
bar[2 * i] = table[(foo[i] >>> 4) & 0xf];
bar[2 * i + 1] = table[(foo[i]) & 0xf];
}
faked_cookie_hex_pool.put(session, bar);
foo = bar;
}
return foo;
}
}
static void removeFakedCookie(Session session) {
synchronized (faked_cookie_hex_pool) {
faked_cookie_hex_pool.remove(session);
faked_cookie_pool.remove(session);
}
}
ChannelX11() {
super();
lwsize_max = LOCAL_WINDOW_SIZE_MAX;
lwsize = LOCAL_WINDOW_SIZE_MAX;
lmpsize = LOCAL_MAXIMUM_PACKET_SIZE;
type = Util.str2byte("x11");
connected = true;
/*
* try{ socket=Util.createSocket(host, port, TIMEOUT); socket.setTcpNoDelay(true); io=new IO();
* io.setInputStream(socket.getInputStream()); io.setOutputStream(socket.getOutputStream()); }
* catch(Exception e){ //System.err.println(e); }
*/
}
@Override
void run() {
try {
socket = Util.createSocket(host, port, TIMEOUT);
socket.setTcpNoDelay(true);
io = new IO();
io.setInputStream(socket.getInputStream());
io.setOutputStream(socket.getOutputStream());
sendOpenConfirmation();
} catch (Exception e) {
sendOpenFailure(SSH_OPEN_ADMINISTRATIVELY_PROHIBITED);
close = true;
disconnect();
return;
}
thread = Thread.currentThread();
Buffer buf = new Buffer(rmpsize);
Packet packet = new Packet(buf);
int i = 0;
try {
Session _session = getSession();
while (thread != null && io != null && io.in != null) {
i = io.in.read(buf.buffer, 14, buf.buffer.length - 14 - _session.getBufferMargin());
if (i <= 0) {
eof();
break;
}
if (close)
break;
packet.reset();
buf.putByte((byte) Session.SSH_MSG_CHANNEL_DATA);
buf.putInt(recipient);
buf.putInt(i);
buf.skip(i);
_session.write(packet, this, i);
}
} catch (Exception e) {
// System.err.println(e);
}
disconnect();
}
private byte[] cache = new byte[0];
private byte[] addCache(byte[] foo, int s, int l) {
byte[] bar = new byte[cache.length + l];
System.arraycopy(foo, s, bar, cache.length, l);
if (cache.length > 0)
System.arraycopy(cache, 0, bar, 0, cache.length);
cache = bar;
return cache;
}
@Override
void write(byte[] foo, int s, int l) throws IOException {
// if(eof_local)return;
if (init) {
Session _session = null;
try {
_session = getSession();
} catch (JSchException e) {
throw new IOException(e.toString(), e);
}
foo = addCache(foo, s, l);
s = 0;
l = foo.length;
if (l < 9)
return;
int plen = (foo[s + 6] & 0xff) * 256 + (foo[s + 7] & 0xff);
int dlen = (foo[s + 8] & 0xff) * 256 + (foo[s + 9] & 0xff);
if ((foo[s] & 0xff) == 0x42) {
} else if ((foo[s] & 0xff) == 0x6c) {
plen = ((plen >>> 8) & 0xff) | ((plen << 8) & 0xff00);
dlen = ((dlen >>> 8) & 0xff) | ((dlen << 8) & 0xff00);
} else {
// ??
}
if (l < 12 + plen + ((-plen) & 3) + dlen)
return;
byte[] bar = new byte[dlen];
System.arraycopy(foo, s + 12 + plen + ((-plen) & 3), bar, 0, dlen);
byte[] faked_cookie = null;
synchronized (faked_cookie_pool) {
faked_cookie = faked_cookie_pool.get(_session);
}
/*
* System.err.print("faked_cookie: "); for(int i=0; i<faked_cookie.length; i++){
* System.err.print(Integer.toHexString(faked_cookie[i]&0xff)+":"); } System.err.println("");
* System.err.print("bar: "); for(int i=0; i<bar.length; i++){
* System.err.print(Integer.toHexString(bar[i]&0xff)+":"); } System.err.println("");
*/
if (equals(bar, faked_cookie)) {
if (cookie != null)
System.arraycopy(cookie, 0, foo, s + 12 + plen + ((-plen) & 3), dlen);
} else {
// System.err.println("wrong cookie");
thread = null;
eof();
io.close();
disconnect();
}
init = false;
io.put(foo, s, l);
cache = null;
return;
}
io.put(foo, s, l);
}
private static boolean equals(byte[] foo, byte[] bar) {
if (foo.length != bar.length)
return false;
for (int i = 0; i < foo.length; i++) {
if (foo[i] != bar[i])
return false;
}
return true;
}
}

@ -0,0 +1,60 @@
/*
* Copyright (c) 2002-2018 ymnk, JCraft,Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted
* provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions
* and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other materials provided with
* the distribution.
*
* 3. The names of the authors may not be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL JCRAFT, INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.jcraft.jsch;
public interface Cipher {
static int ENCRYPT_MODE = 0;
static int DECRYPT_MODE = 1;
int getIVSize();
int getBlockSize();
default int getTagSize() {
return 0;
}
void init(int mode, byte[] key, byte[] iv) throws Exception;
default void update(int foo) throws Exception {}
void update(byte[] foo, int s1, int len, byte[] bar, int s2) throws Exception;
default void updateAAD(byte[] foo, int s1, int len) throws Exception {}
default void doFinal(byte[] foo, int s1, int len, byte[] bar, int s2) throws Exception {}
boolean isCBC();
default boolean isAEAD() {
return false;
}
default boolean isChaCha20() {
return false;
}
}

@ -0,0 +1,53 @@
/*
* Copyright (c) 2002-2018 ymnk, JCraft,Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted
* provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions
* and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other materials provided with
* the distribution.
*
* 3. The names of the authors may not be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL JCRAFT, INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.jcraft.jsch;
class CipherNone implements Cipher {
private static final int ivsize = 8;
private static final int bsize = 16;
@Override
public int getIVSize() {
return ivsize;
}
@Override
public int getBlockSize() {
return bsize;
}
@Override
public void init(int mode, byte[] key, byte[] iv) throws Exception {}
@Override
public void update(byte[] foo, int s1, int len, byte[] bar, int s2) throws Exception {}
@Override
public boolean isCBC() {
return false;
}
}

@ -0,0 +1,44 @@
/*
* Copyright (c) 2002-2018 ymnk, JCraft,Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted
* provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions
* and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other materials provided with
* the distribution.
*
* 3. The names of the authors may not be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL JCRAFT, INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.jcraft.jsch;
public interface Compression {
public static final int INFLATER = 0;
public static final int DEFLATER = 1;
default void init(int type, int level, Session session) {
init(type, level);
}
default void end() {}
void init(int type, int level);
byte[] compress(byte[] buf, int start, int[] len);
byte[] uncompress(byte[] buf, int start, int[] len);
}

@ -0,0 +1,78 @@
/*
* Copyright (c) 2013-2018 ymnk, JCraft,Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted
* provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions
* and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other materials provided with
* the distribution.
*
* 3. The names of the authors may not be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL JCRAFT, INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.jcraft.jsch;
public interface ConfigRepository {
public Config getConfig(String host);
public interface Config {
public String getHostname();
public String getUser();
public int getPort();
public String getValue(String key);
public String[] getValues(String key);
}
static final Config defaultConfig = new Config() {
@Override
public String getHostname() {
return null;
}
@Override
public String getUser() {
return null;
}
@Override
public int getPort() {
return -1;
}
@Override
public String getValue(String key) {
return null;
}
@Override
public String[] getValues(String key) {
return null;
}
};
static final ConfigRepository nullConfig = new ConfigRepository() {
@Override
public Config getConfig(String host) {
return defaultConfig;
}
};
}

@ -0,0 +1,45 @@
/*
* Copyright (c) 2002-2018 ymnk, JCraft,Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted
* provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions
* and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other materials provided with
* the distribution.
*
* 3. The names of the authors may not be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL JCRAFT, INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.jcraft.jsch;
public interface DH {
void init() throws Exception;
void setP(byte[] p);
void setG(byte[] g);
byte[] getE() throws Exception;
void setF(byte[] f);
byte[] getK() throws Exception;
// checkRange() will check if e and f are in [1,p-1]
// as defined at https://tools.ietf.org/html/rfc4253#section-8
void checkRange() throws Exception;
}

@ -0,0 +1,35 @@
/*
* Copyright (c) 2015-2018 ymnk, JCraft,Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted
* provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions
* and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other materials provided with
* the distribution.
*
* 3. The names of the authors may not be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL JCRAFT, INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.jcraft.jsch;
class DH25519 extends DHXEC {
public DH25519() {
sha_name = "sha-256";
curve_name = "X25519";
key_len = 32;
}
}

@ -0,0 +1,38 @@
/*
* Copyright (c) 2015-2018 ymnk, JCraft,Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted
* provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions
* and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other materials provided with
* the distribution.
*
* 3. The names of the authors may not be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL JCRAFT, INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.jcraft.jsch;
class DH25519SNTRUP761 extends DHXECKEM {
public DH25519SNTRUP761() {
kem_name = "sntrup761";
sha_name = "sha-512";
curve_name = "X25519";
kem_pubkey_len = 1158;
kem_encap_len = 1039;
xec_key_len = 32;
}
}

@ -0,0 +1,35 @@
/*
* Copyright (c) 2015-2018 ymnk, JCraft,Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted
* provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions
* and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other materials provided with
* the distribution.
*
* 3. The names of the authors may not be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL JCRAFT, INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.jcraft.jsch;
class DH448 extends DHXEC {
public DH448() {
sha_name = "sha-512";
curve_name = "X448";
key_len = 56;
}
}

@ -0,0 +1,34 @@
/*
* Copyright (c) 2015-2018 ymnk, JCraft,Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted
* provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions
* and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other materials provided with
* the distribution.
*
* 3. The names of the authors may not be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL JCRAFT, INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.jcraft.jsch;
class DHEC256 extends DHECN {
public DHEC256() {
sha_name = "sha-256";
key_size = 256;
}
}

@ -0,0 +1,34 @@
/*
* Copyright (c) 2015-2018 ymnk, JCraft,Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted
* provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions
* and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other materials provided with
* the distribution.
*
* 3. The names of the authors may not be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL JCRAFT, INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.jcraft.jsch;
class DHEC384 extends DHECN {
public DHEC384() {
sha_name = "sha-384";
key_size = 384;
}
}

@ -0,0 +1,34 @@
/*
* Copyright (c) 2015-2018 ymnk, JCraft,Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted
* provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions
* and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other materials provided with
* the distribution.
*
* 3. The names of the authors may not be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL JCRAFT, INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.jcraft.jsch;
class DHEC521 extends DHECN {
public DHEC521() {
sha_name = "sha-512";
key_size = 521;
}
}

@ -0,0 +1,187 @@
/*
* Copyright (c) 2015-2018 ymnk, JCraft,Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted
* provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions
* and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other materials provided with
* the distribution.
*
* 3. The names of the authors may not be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL JCRAFT, INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.jcraft.jsch;
abstract class DHECN extends KeyExchange {
private static final int SSH_MSG_KEX_ECDH_INIT = 30;
private static final int SSH_MSG_KEX_ECDH_REPLY = 31;
private int state;
byte[] Q_C;
byte[] V_S;
byte[] V_C;
byte[] I_S;
byte[] I_C;
byte[] e;
private Buffer buf;
private Packet packet;
private ECDH ecdh;
protected String sha_name;
protected int key_size;
@Override
public void init(Session session, byte[] V_S, byte[] V_C, byte[] I_S, byte[] I_C)
throws Exception {
this.V_S = V_S;
this.V_C = V_C;
this.I_S = I_S;
this.I_C = I_C;
try {
Class<? extends HASH> c = Class.forName(session.getConfig(sha_name)).asSubclass(HASH.class);
sha = c.getDeclaredConstructor().newInstance();
sha.init();
} catch (Exception e) {
throw new JSchException(e.toString(), e);
}
buf = new Buffer();
packet = new Packet(buf);
packet.reset();
buf.putByte((byte) SSH_MSG_KEX_ECDH_INIT);
try {
Class<? extends ECDH> c =
Class.forName(session.getConfig("ecdh-sha2-nistp")).asSubclass(ECDH.class);
ecdh = c.getDeclaredConstructor().newInstance();
ecdh.init(key_size);
Q_C = ecdh.getQ();
buf.putString(Q_C);
} catch (Exception e) {
throw new JSchException(e.toString(), e);
}
if (V_S == null) { // This is a really ugly hack for Session.checkKexes ;-(
return;
}
session.write(packet);
if (session.getLogger().isEnabled(Logger.INFO)) {
session.getLogger().log(Logger.INFO, "SSH_MSG_KEX_ECDH_INIT sent");
session.getLogger().log(Logger.INFO, "expecting SSH_MSG_KEX_ECDH_REPLY");
}
state = SSH_MSG_KEX_ECDH_REPLY;
}
@Override
public boolean next(Buffer _buf) throws Exception {
int i, j;
switch (state) {
case SSH_MSG_KEX_ECDH_REPLY:
// The server responds with:
// byte SSH_MSG_KEX_ECDH_REPLY
// string K_S, server's public host key
// string Q_S, server's ephemeral public key octet string
// string the signature on the exchange hash
j = _buf.getInt();
j = _buf.getByte();
j = _buf.getByte();
if (j != SSH_MSG_KEX_ECDH_REPLY) {
if (session.getLogger().isEnabled(Logger.ERROR)) {
session.getLogger().log(Logger.ERROR, "type: must be SSH_MSG_KEX_ECDH_REPLY " + j);
}
return false;
}
K_S = _buf.getString();
byte[] Q_S = _buf.getString();
byte[][] r_s = KeyPairECDSA.fromPoint(Q_S);
// RFC 5656,
// 4. ECDH Key Exchange
// All elliptic curve public keys MUST be validated after they are
// received. An example of a validation algorithm can be found in
// Section 3.2.2 of [SEC1]. If a key fails validation,
// the key exchange MUST fail.
if (!ecdh.validate(r_s[0], r_s[1])) {
return false;
}
K = encodeAsMPInt(normalize(ecdh.getSecret(r_s[0], r_s[1])));
byte[] sig_of_H = _buf.getString();
// The hash H is computed as the HASH hash of the concatenation of the
// following:
// string V_C, client's identification string (CR and LF excluded)
// string V_S, server's identification string (CR and LF excluded)
// string I_C, payload of the client's SSH_MSG_KEXINIT
// string I_S, payload of the server's SSH_MSG_KEXINIT
// string K_S, server's public host key
// string Q_C, client's ephemeral public key octet string
// string Q_S, server's ephemeral public key octet string
// mpint K, shared secret
// This value is called the exchange hash, and it is used to authenti-
// cate the key exchange.
buf.reset();
buf.putString(V_C);
buf.putString(V_S);
buf.putString(I_C);
buf.putString(I_S);
buf.putString(K_S);
buf.putString(Q_C);
buf.putString(Q_S);
byte[] foo = new byte[buf.getLength()];
buf.getByte(foo);
sha.update(foo, 0, foo.length);
sha.update(K, 0, K.length);
H = sha.digest();
i = 0;
j = 0;
j = ((K_S[i++] << 24) & 0xff000000) | ((K_S[i++] << 16) & 0x00ff0000)
| ((K_S[i++] << 8) & 0x0000ff00) | ((K_S[i++]) & 0x000000ff);
String alg = Util.byte2str(K_S, i, j);
i += j;
boolean result = verify(alg, K_S, i, sig_of_H);
state = STATE_END;
return result;
}
return false;
}
@Override
public int getState() {
return state;
}
}

@ -0,0 +1,66 @@
/*
* Copyright (c) 2002-2018 ymnk, JCraft,Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted
* provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions
* and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other materials provided with
* the distribution.
*
* 3. The names of the authors may not be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL JCRAFT, INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.jcraft.jsch;
class DHG1 extends DHGN {
static final byte[] g = {2};
static final byte[] p = {(byte) 0x00, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
(byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xC9, (byte) 0x0F, (byte) 0xDA,
(byte) 0xA2, (byte) 0x21, (byte) 0x68, (byte) 0xC2, (byte) 0x34, (byte) 0xC4, (byte) 0xC6,
(byte) 0x62, (byte) 0x8B, (byte) 0x80, (byte) 0xDC, (byte) 0x1C, (byte) 0xD1, (byte) 0x29,
(byte) 0x02, (byte) 0x4E, (byte) 0x08, (byte) 0x8A, (byte) 0x67, (byte) 0xCC, (byte) 0x74,
(byte) 0x02, (byte) 0x0B, (byte) 0xBE, (byte) 0xA6, (byte) 0x3B, (byte) 0x13, (byte) 0x9B,
(byte) 0x22, (byte) 0x51, (byte) 0x4A, (byte) 0x08, (byte) 0x79, (byte) 0x8E, (byte) 0x34,
(byte) 0x04, (byte) 0xDD, (byte) 0xEF, (byte) 0x95, (byte) 0x19, (byte) 0xB3, (byte) 0xCD,
(byte) 0x3A, (byte) 0x43, (byte) 0x1B, (byte) 0x30, (byte) 0x2B, (byte) 0x0A, (byte) 0x6D,
(byte) 0xF2, (byte) 0x5F, (byte) 0x14, (byte) 0x37, (byte) 0x4F, (byte) 0xE1, (byte) 0x35,
(byte) 0x6D, (byte) 0x6D, (byte) 0x51, (byte) 0xC2, (byte) 0x45, (byte) 0xE4, (byte) 0x85,
(byte) 0xB5, (byte) 0x76, (byte) 0x62, (byte) 0x5E, (byte) 0x7E, (byte) 0xC6, (byte) 0xF4,
(byte) 0x4C, (byte) 0x42, (byte) 0xE9, (byte) 0xA6, (byte) 0x37, (byte) 0xED, (byte) 0x6B,
(byte) 0x0B, (byte) 0xFF, (byte) 0x5C, (byte) 0xB6, (byte) 0xF4, (byte) 0x06, (byte) 0xB7,
(byte) 0xED, (byte) 0xEE, (byte) 0x38, (byte) 0x6B, (byte) 0xFB, (byte) 0x5A, (byte) 0x89,
(byte) 0x9F, (byte) 0xA5, (byte) 0xAE, (byte) 0x9F, (byte) 0x24, (byte) 0x11, (byte) 0x7C,
(byte) 0x4B, (byte) 0x1F, (byte) 0xE6, (byte) 0x49, (byte) 0x28, (byte) 0x66, (byte) 0x51,
(byte) 0xEC, (byte) 0xE6, (byte) 0x53, (byte) 0x81, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
(byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF};
@Override
byte[] G() {
return g;
}
@Override
byte[] P() {
return p;
}
@Override
String sha_name() {
return "sha-1";
}
}

@ -0,0 +1,35 @@
/*
* Copyright (c) 2002-2018 ymnk, JCraft,Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted
* provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions
* and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other materials provided with
* the distribution.
*
* 3. The names of the authors may not be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL JCRAFT, INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.jcraft.jsch;
class DHG14 extends DHG14N {
@Override
String sha_name() {
return "sha-1";
}
}

@ -0,0 +1,35 @@
/*
* Copyright (c) 2002-2018 ymnk, JCraft,Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted
* provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions
* and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other materials provided with
* the distribution.
*
* 3. The names of the authors may not be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL JCRAFT, INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.jcraft.jsch;
class DHG14224 extends DHG14N {
@Override
String sha_name() {
return "sha-224";
}
}

@ -0,0 +1,35 @@
/*
* Copyright (c) 2002-2018 ymnk, JCraft,Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted
* provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions
* and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other materials provided with
* the distribution.
*
* 3. The names of the authors may not be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL JCRAFT, INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.jcraft.jsch;
class DHG14256 extends DHG14N {
@Override
String sha_name() {
return "sha-256";
}
}

@ -0,0 +1,79 @@
/*
* Copyright (c) 2002-2018 ymnk, JCraft,Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted
* provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions
* and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other materials provided with
* the distribution.
*
* 3. The names of the authors may not be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL JCRAFT, INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.jcraft.jsch;
abstract class DHG14N extends DHGN {
static final byte[] g = {2};
static final byte[] p = {(byte) 0x00, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
(byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xC9, (byte) 0x0F, (byte) 0xDA,
(byte) 0xA2, (byte) 0x21, (byte) 0x68, (byte) 0xC2, (byte) 0x34, (byte) 0xC4, (byte) 0xC6,
(byte) 0x62, (byte) 0x8B, (byte) 0x80, (byte) 0xDC, (byte) 0x1C, (byte) 0xD1, (byte) 0x29,
(byte) 0x02, (byte) 0x4E, (byte) 0x08, (byte) 0x8A, (byte) 0x67, (byte) 0xCC, (byte) 0x74,
(byte) 0x02, (byte) 0x0B, (byte) 0xBE, (byte) 0xA6, (byte) 0x3B, (byte) 0x13, (byte) 0x9B,
(byte) 0x22, (byte) 0x51, (byte) 0x4A, (byte) 0x08, (byte) 0x79, (byte) 0x8E, (byte) 0x34,
(byte) 0x04, (byte) 0xDD, (byte) 0xEF, (byte) 0x95, (byte) 0x19, (byte) 0xB3, (byte) 0xCD,
(byte) 0x3A, (byte) 0x43, (byte) 0x1B, (byte) 0x30, (byte) 0x2B, (byte) 0x0A, (byte) 0x6D,
(byte) 0xF2, (byte) 0x5F, (byte) 0x14, (byte) 0x37, (byte) 0x4F, (byte) 0xE1, (byte) 0x35,
(byte) 0x6D, (byte) 0x6D, (byte) 0x51, (byte) 0xC2, (byte) 0x45, (byte) 0xE4, (byte) 0x85,
(byte) 0xB5, (byte) 0x76, (byte) 0x62, (byte) 0x5E, (byte) 0x7E, (byte) 0xC6, (byte) 0xF4,
(byte) 0x4C, (byte) 0x42, (byte) 0xE9, (byte) 0xA6, (byte) 0x37, (byte) 0xED, (byte) 0x6B,
(byte) 0x0B, (byte) 0xFF, (byte) 0x5C, (byte) 0xB6, (byte) 0xF4, (byte) 0x06, (byte) 0xB7,
(byte) 0xED, (byte) 0xEE, (byte) 0x38, (byte) 0x6B, (byte) 0xFB, (byte) 0x5A, (byte) 0x89,
(byte) 0x9F, (byte) 0xA5, (byte) 0xAE, (byte) 0x9F, (byte) 0x24, (byte) 0x11, (byte) 0x7C,
(byte) 0x4B, (byte) 0x1F, (byte) 0xE6, (byte) 0x49, (byte) 0x28, (byte) 0x66, (byte) 0x51,
(byte) 0xEC, (byte) 0xE4, (byte) 0x5B, (byte) 0x3D, (byte) 0xC2, (byte) 0x00, (byte) 0x7C,
(byte) 0xB8, (byte) 0xA1, (byte) 0x63, (byte) 0xBF, (byte) 0x05, (byte) 0x98, (byte) 0xDA,
(byte) 0x48, (byte) 0x36, (byte) 0x1C, (byte) 0x55, (byte) 0xD3, (byte) 0x9A, (byte) 0x69,
(byte) 0x16, (byte) 0x3F, (byte) 0xA8, (byte) 0xFD, (byte) 0x24, (byte) 0xCF, (byte) 0x5F,
(byte) 0x83, (byte) 0x65, (byte) 0x5D, (byte) 0x23, (byte) 0xDC, (byte) 0xA3, (byte) 0xAD,
(byte) 0x96, (byte) 0x1C, (byte) 0x62, (byte) 0xF3, (byte) 0x56, (byte) 0x20, (byte) 0x85,
(byte) 0x52, (byte) 0xBB, (byte) 0x9E, (byte) 0xD5, (byte) 0x29, (byte) 0x07, (byte) 0x70,
(byte) 0x96, (byte) 0x96, (byte) 0x6D, (byte) 0x67, (byte) 0x0C, (byte) 0x35, (byte) 0x4E,
(byte) 0x4A, (byte) 0xBC, (byte) 0x98, (byte) 0x04, (byte) 0xF1, (byte) 0x74, (byte) 0x6C,
(byte) 0x08, (byte) 0xCA, (byte) 0x18, (byte) 0x21, (byte) 0x7C, (byte) 0x32, (byte) 0x90,
(byte) 0x5E, (byte) 0x46, (byte) 0x2E, (byte) 0x36, (byte) 0xCE, (byte) 0x3B, (byte) 0xE3,
(byte) 0x9E, (byte) 0x77, (byte) 0x2C, (byte) 0x18, (byte) 0x0E, (byte) 0x86, (byte) 0x03,
(byte) 0x9B, (byte) 0x27, (byte) 0x83, (byte) 0xA2, (byte) 0xEC, (byte) 0x07, (byte) 0xA2,
(byte) 0x8F, (byte) 0xB5, (byte) 0xC5, (byte) 0x5D, (byte) 0xF0, (byte) 0x6F, (byte) 0x4C,
(byte) 0x52, (byte) 0xC9, (byte) 0xDE, (byte) 0x2B, (byte) 0xCB, (byte) 0xF6, (byte) 0x95,
(byte) 0x58, (byte) 0x17, (byte) 0x18, (byte) 0x39, (byte) 0x95, (byte) 0x49, (byte) 0x7C,
(byte) 0xEA, (byte) 0x95, (byte) 0x6A, (byte) 0xE5, (byte) 0x15, (byte) 0xD2, (byte) 0x26,
(byte) 0x18, (byte) 0x98, (byte) 0xFA, (byte) 0x05, (byte) 0x10, (byte) 0x15, (byte) 0x72,
(byte) 0x8E, (byte) 0x5A, (byte) 0x8A, (byte) 0xAC, (byte) 0xAA, (byte) 0x68, (byte) 0xFF,
(byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF};
@Override
byte[] G() {
return g;
}
@Override
byte[] P() {
return p;
}
}

@ -0,0 +1,35 @@
/*
* Copyright (c) 2002-2018 ymnk, JCraft,Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted
* provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions
* and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other materials provided with
* the distribution.
*
* 3. The names of the authors may not be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL JCRAFT, INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.jcraft.jsch;
class DHG15 extends DHG15N {
@Override
String sha_name() {
return "sha-512";
}
}

@ -0,0 +1,35 @@
/*
* Copyright (c) 2002-2018 ymnk, JCraft,Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted
* provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions
* and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other materials provided with
* the distribution.
*
* 3. The names of the authors may not be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL JCRAFT, INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.jcraft.jsch;
class DHG15256 extends DHG15N {
@Override
String sha_name() {
return "sha-256";
}
}

@ -0,0 +1,35 @@
/*
* Copyright (c) 2002-2018 ymnk, JCraft,Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted
* provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions
* and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other materials provided with
* the distribution.
*
* 3. The names of the authors may not be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL JCRAFT, INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.jcraft.jsch;
class DHG15384 extends DHG15N {
@Override
String sha_name() {
return "sha-384";
}
}

@ -0,0 +1,98 @@
/*
* Copyright (c) 2002-2018 ymnk, JCraft,Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted
* provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions
* and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other materials provided with
* the distribution.
*
* 3. The names of the authors may not be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL JCRAFT, INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.jcraft.jsch;
abstract class DHG15N extends DHGN {
static final byte[] g = {2};
static final byte[] p = {(byte) 0x00, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
(byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xC9, (byte) 0x0F, (byte) 0xDA,
(byte) 0xA2, (byte) 0x21, (byte) 0x68, (byte) 0xC2, (byte) 0x34, (byte) 0xC4, (byte) 0xC6,
(byte) 0x62, (byte) 0x8B, (byte) 0x80, (byte) 0xDC, (byte) 0x1C, (byte) 0xD1, (byte) 0x29,
(byte) 0x02, (byte) 0x4E, (byte) 0x08, (byte) 0x8A, (byte) 0x67, (byte) 0xCC, (byte) 0x74,
(byte) 0x02, (byte) 0x0B, (byte) 0xBE, (byte) 0xA6, (byte) 0x3B, (byte) 0x13, (byte) 0x9B,
(byte) 0x22, (byte) 0x51, (byte) 0x4A, (byte) 0x08, (byte) 0x79, (byte) 0x8E, (byte) 0x34,
(byte) 0x04, (byte) 0xDD, (byte) 0xEF, (byte) 0x95, (byte) 0x19, (byte) 0xB3, (byte) 0xCD,
(byte) 0x3A, (byte) 0x43, (byte) 0x1B, (byte) 0x30, (byte) 0x2B, (byte) 0x0A, (byte) 0x6D,
(byte) 0xF2, (byte) 0x5F, (byte) 0x14, (byte) 0x37, (byte) 0x4F, (byte) 0xE1, (byte) 0x35,
(byte) 0x6D, (byte) 0x6D, (byte) 0x51, (byte) 0xC2, (byte) 0x45, (byte) 0xE4, (byte) 0x85,
(byte) 0xB5, (byte) 0x76, (byte) 0x62, (byte) 0x5E, (byte) 0x7E, (byte) 0xC6, (byte) 0xF4,
(byte) 0x4C, (byte) 0x42, (byte) 0xE9, (byte) 0xA6, (byte) 0x37, (byte) 0xED, (byte) 0x6B,
(byte) 0x0B, (byte) 0xFF, (byte) 0x5C, (byte) 0xB6, (byte) 0xF4, (byte) 0x06, (byte) 0xB7,
(byte) 0xED, (byte) 0xEE, (byte) 0x38, (byte) 0x6B, (byte) 0xFB, (byte) 0x5A, (byte) 0x89,
(byte) 0x9F, (byte) 0xA5, (byte) 0xAE, (byte) 0x9F, (byte) 0x24, (byte) 0x11, (byte) 0x7C,
(byte) 0x4B, (byte) 0x1F, (byte) 0xE6, (byte) 0x49, (byte) 0x28, (byte) 0x66, (byte) 0x51,
(byte) 0xEC, (byte) 0xE4, (byte) 0x5B, (byte) 0x3D, (byte) 0xC2, (byte) 0x00, (byte) 0x7C,
(byte) 0xB8, (byte) 0xA1, (byte) 0x63, (byte) 0xBF, (byte) 0x05, (byte) 0x98, (byte) 0xDA,
(byte) 0x48, (byte) 0x36, (byte) 0x1C, (byte) 0x55, (byte) 0xD3, (byte) 0x9A, (byte) 0x69,
(byte) 0x16, (byte) 0x3F, (byte) 0xA8, (byte) 0xFD, (byte) 0x24, (byte) 0xCF, (byte) 0x5F,
(byte) 0x83, (byte) 0x65, (byte) 0x5D, (byte) 0x23, (byte) 0xDC, (byte) 0xA3, (byte) 0xAD,
(byte) 0x96, (byte) 0x1C, (byte) 0x62, (byte) 0xF3, (byte) 0x56, (byte) 0x20, (byte) 0x85,
(byte) 0x52, (byte) 0xBB, (byte) 0x9E, (byte) 0xD5, (byte) 0x29, (byte) 0x07, (byte) 0x70,
(byte) 0x96, (byte) 0x96, (byte) 0x6D, (byte) 0x67, (byte) 0x0C, (byte) 0x35, (byte) 0x4E,
(byte) 0x4A, (byte) 0xBC, (byte) 0x98, (byte) 0x04, (byte) 0xF1, (byte) 0x74, (byte) 0x6C,
(byte) 0x08, (byte) 0xCA, (byte) 0x18, (byte) 0x21, (byte) 0x7C, (byte) 0x32, (byte) 0x90,
(byte) 0x5E, (byte) 0x46, (byte) 0x2E, (byte) 0x36, (byte) 0xCE, (byte) 0x3B, (byte) 0xE3,
(byte) 0x9E, (byte) 0x77, (byte) 0x2C, (byte) 0x18, (byte) 0x0E, (byte) 0x86, (byte) 0x03,
(byte) 0x9B, (byte) 0x27, (byte) 0x83, (byte) 0xA2, (byte) 0xEC, (byte) 0x07, (byte) 0xA2,
(byte) 0x8F, (byte) 0xB5, (byte) 0xC5, (byte) 0x5D, (byte) 0xF0, (byte) 0x6F, (byte) 0x4C,
(byte) 0x52, (byte) 0xC9, (byte) 0xDE, (byte) 0x2B, (byte) 0xCB, (byte) 0xF6, (byte) 0x95,
(byte) 0x58, (byte) 0x17, (byte) 0x18, (byte) 0x39, (byte) 0x95, (byte) 0x49, (byte) 0x7C,
(byte) 0xEA, (byte) 0x95, (byte) 0x6A, (byte) 0xE5, (byte) 0x15, (byte) 0xD2, (byte) 0x26,
(byte) 0x18, (byte) 0x98, (byte) 0xFA, (byte) 0x05, (byte) 0x10, (byte) 0x15, (byte) 0x72,
(byte) 0x8E, (byte) 0x5A, (byte) 0x8A, (byte) 0xAA, (byte) 0xC4, (byte) 0x2D, (byte) 0xAD,
(byte) 0x33, (byte) 0x17, (byte) 0x0D, (byte) 0x04, (byte) 0x50, (byte) 0x7A, (byte) 0x33,
(byte) 0xA8, (byte) 0x55, (byte) 0x21, (byte) 0xAB, (byte) 0xDF, (byte) 0x1C, (byte) 0xBA,
(byte) 0x64, (byte) 0xEC, (byte) 0xFB, (byte) 0x85, (byte) 0x04, (byte) 0x58, (byte) 0xDB,
(byte) 0xEF, (byte) 0x0A, (byte) 0x8A, (byte) 0xEA, (byte) 0x71, (byte) 0x57, (byte) 0x5D,
(byte) 0x06, (byte) 0x0C, (byte) 0x7D, (byte) 0xB3, (byte) 0x97, (byte) 0x0F, (byte) 0x85,
(byte) 0xA6, (byte) 0xE1, (byte) 0xE4, (byte) 0xC7, (byte) 0xAB, (byte) 0xF5, (byte) 0xAE,
(byte) 0x8C, (byte) 0xDB, (byte) 0x09, (byte) 0x33, (byte) 0xD7, (byte) 0x1E, (byte) 0x8C,
(byte) 0x94, (byte) 0xE0, (byte) 0x4A, (byte) 0x25, (byte) 0x61, (byte) 0x9D, (byte) 0xCE,
(byte) 0xE3, (byte) 0xD2, (byte) 0x26, (byte) 0x1A, (byte) 0xD2, (byte) 0xEE, (byte) 0x6B,
(byte) 0xF1, (byte) 0x2F, (byte) 0xFA, (byte) 0x06, (byte) 0xD9, (byte) 0x8A, (byte) 0x08,
(byte) 0x64, (byte) 0xD8, (byte) 0x76, (byte) 0x02, (byte) 0x73, (byte) 0x3E, (byte) 0xC8,
(byte) 0x6A, (byte) 0x64, (byte) 0x52, (byte) 0x1F, (byte) 0x2B, (byte) 0x18, (byte) 0x17,
(byte) 0x7B, (byte) 0x20, (byte) 0x0C, (byte) 0xBB, (byte) 0xE1, (byte) 0x17, (byte) 0x57,
(byte) 0x7A, (byte) 0x61, (byte) 0x5D, (byte) 0x6C, (byte) 0x77, (byte) 0x09, (byte) 0x88,
(byte) 0xC0, (byte) 0xBA, (byte) 0xD9, (byte) 0x46, (byte) 0xE2, (byte) 0x08, (byte) 0xE2,
(byte) 0x4F, (byte) 0xA0, (byte) 0x74, (byte) 0xE5, (byte) 0xAB, (byte) 0x31, (byte) 0x43,
(byte) 0xDB, (byte) 0x5B, (byte) 0xFC, (byte) 0xE0, (byte) 0xFD, (byte) 0x10, (byte) 0x8E,
(byte) 0x4B, (byte) 0x82, (byte) 0xD1, (byte) 0x20, (byte) 0xA9, (byte) 0x3A, (byte) 0xD2,
(byte) 0xCA, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
(byte) 0xFF, (byte) 0xFF};
@Override
byte[] G() {
return g;
}
@Override
byte[] P() {
return p;
}
}

@ -0,0 +1,35 @@
/*
* Copyright (c) 2002-2018 ymnk, JCraft,Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted
* provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions
* and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other materials provided with
* the distribution.
*
* 3. The names of the authors may not be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL JCRAFT, INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.jcraft.jsch;
class DHG16 extends DHG16N {
@Override
String sha_name() {
return "sha-512";
}
}

@ -0,0 +1,35 @@
/*
* Copyright (c) 2002-2018 ymnk, JCraft,Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted
* provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions
* and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other materials provided with
* the distribution.
*
* 3. The names of the authors may not be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL JCRAFT, INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.jcraft.jsch;
class DHG16384 extends DHG16N {
@Override
String sha_name() {
return "sha-384";
}
}

@ -0,0 +1,116 @@
/*
* Copyright (c) 2002-2018 ymnk, JCraft,Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted
* provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions
* and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other materials provided with
* the distribution.
*
* 3. The names of the authors may not be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL JCRAFT, INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.jcraft.jsch;
abstract class DHG16N extends DHGN {
static final byte[] g = {2};
static final byte[] p = {(byte) 0x00, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
(byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xC9, (byte) 0x0F, (byte) 0xDA,
(byte) 0xA2, (byte) 0x21, (byte) 0x68, (byte) 0xC2, (byte) 0x34, (byte) 0xC4, (byte) 0xC6,
(byte) 0x62, (byte) 0x8B, (byte) 0x80, (byte) 0xDC, (byte) 0x1C, (byte) 0xD1, (byte) 0x29,
(byte) 0x02, (byte) 0x4E, (byte) 0x08, (byte) 0x8A, (byte) 0x67, (byte) 0xCC, (byte) 0x74,
(byte) 0x02, (byte) 0x0B, (byte) 0xBE, (byte) 0xA6, (byte) 0x3B, (byte) 0x13, (byte) 0x9B,
(byte) 0x22, (byte) 0x51, (byte) 0x4A, (byte) 0x08, (byte) 0x79, (byte) 0x8E, (byte) 0x34,
(byte) 0x04, (byte) 0xDD, (byte) 0xEF, (byte) 0x95, (byte) 0x19, (byte) 0xB3, (byte) 0xCD,
(byte) 0x3A, (byte) 0x43, (byte) 0x1B, (byte) 0x30, (byte) 0x2B, (byte) 0x0A, (byte) 0x6D,
(byte) 0xF2, (byte) 0x5F, (byte) 0x14, (byte) 0x37, (byte) 0x4F, (byte) 0xE1, (byte) 0x35,
(byte) 0x6D, (byte) 0x6D, (byte) 0x51, (byte) 0xC2, (byte) 0x45, (byte) 0xE4, (byte) 0x85,
(byte) 0xB5, (byte) 0x76, (byte) 0x62, (byte) 0x5E, (byte) 0x7E, (byte) 0xC6, (byte) 0xF4,
(byte) 0x4C, (byte) 0x42, (byte) 0xE9, (byte) 0xA6, (byte) 0x37, (byte) 0xED, (byte) 0x6B,
(byte) 0x0B, (byte) 0xFF, (byte) 0x5C, (byte) 0xB6, (byte) 0xF4, (byte) 0x06, (byte) 0xB7,
(byte) 0xED, (byte) 0xEE, (byte) 0x38, (byte) 0x6B, (byte) 0xFB, (byte) 0x5A, (byte) 0x89,
(byte) 0x9F, (byte) 0xA5, (byte) 0xAE, (byte) 0x9F, (byte) 0x24, (byte) 0x11, (byte) 0x7C,
(byte) 0x4B, (byte) 0x1F, (byte) 0xE6, (byte) 0x49, (byte) 0x28, (byte) 0x66, (byte) 0x51,
(byte) 0xEC, (byte) 0xE4, (byte) 0x5B, (byte) 0x3D, (byte) 0xC2, (byte) 0x00, (byte) 0x7C,
(byte) 0xB8, (byte) 0xA1, (byte) 0x63, (byte) 0xBF, (byte) 0x05, (byte) 0x98, (byte) 0xDA,
(byte) 0x48, (byte) 0x36, (byte) 0x1C, (byte) 0x55, (byte) 0xD3, (byte) 0x9A, (byte) 0x69,
(byte) 0x16, (byte) 0x3F, (byte) 0xA8, (byte) 0xFD, (byte) 0x24, (byte) 0xCF, (byte) 0x5F,
(byte) 0x83, (byte) 0x65, (byte) 0x5D, (byte) 0x23, (byte) 0xDC, (byte) 0xA3, (byte) 0xAD,
(byte) 0x96, (byte) 0x1C, (byte) 0x62, (byte) 0xF3, (byte) 0x56, (byte) 0x20, (byte) 0x85,
(byte) 0x52, (byte) 0xBB, (byte) 0x9E, (byte) 0xD5, (byte) 0x29, (byte) 0x07, (byte) 0x70,
(byte) 0x96, (byte) 0x96, (byte) 0x6D, (byte) 0x67, (byte) 0x0C, (byte) 0x35, (byte) 0x4E,
(byte) 0x4A, (byte) 0xBC, (byte) 0x98, (byte) 0x04, (byte) 0xF1, (byte) 0x74, (byte) 0x6C,
(byte) 0x08, (byte) 0xCA, (byte) 0x18, (byte) 0x21, (byte) 0x7C, (byte) 0x32, (byte) 0x90,
(byte) 0x5E, (byte) 0x46, (byte) 0x2E, (byte) 0x36, (byte) 0xCE, (byte) 0x3B, (byte) 0xE3,
(byte) 0x9E, (byte) 0x77, (byte) 0x2C, (byte) 0x18, (byte) 0x0E, (byte) 0x86, (byte) 0x03,
(byte) 0x9B, (byte) 0x27, (byte) 0x83, (byte) 0xA2, (byte) 0xEC, (byte) 0x07, (byte) 0xA2,
(byte) 0x8F, (byte) 0xB5, (byte) 0xC5, (byte) 0x5D, (byte) 0xF0, (byte) 0x6F, (byte) 0x4C,
(byte) 0x52, (byte) 0xC9, (byte) 0xDE, (byte) 0x2B, (byte) 0xCB, (byte) 0xF6, (byte) 0x95,
(byte) 0x58, (byte) 0x17, (byte) 0x18, (byte) 0x39, (byte) 0x95, (byte) 0x49, (byte) 0x7C,
(byte) 0xEA, (byte) 0x95, (byte) 0x6A, (byte) 0xE5, (byte) 0x15, (byte) 0xD2, (byte) 0x26,
(byte) 0x18, (byte) 0x98, (byte) 0xFA, (byte) 0x05, (byte) 0x10, (byte) 0x15, (byte) 0x72,
(byte) 0x8E, (byte) 0x5A, (byte) 0x8A, (byte) 0xAA, (byte) 0xC4, (byte) 0x2D, (byte) 0xAD,
(byte) 0x33, (byte) 0x17, (byte) 0x0D, (byte) 0x04, (byte) 0x50, (byte) 0x7A, (byte) 0x33,
(byte) 0xA8, (byte) 0x55, (byte) 0x21, (byte) 0xAB, (byte) 0xDF, (byte) 0x1C, (byte) 0xBA,
(byte) 0x64, (byte) 0xEC, (byte) 0xFB, (byte) 0x85, (byte) 0x04, (byte) 0x58, (byte) 0xDB,
(byte) 0xEF, (byte) 0x0A, (byte) 0x8A, (byte) 0xEA, (byte) 0x71, (byte) 0x57, (byte) 0x5D,
(byte) 0x06, (byte) 0x0C, (byte) 0x7D, (byte) 0xB3, (byte) 0x97, (byte) 0x0F, (byte) 0x85,
(byte) 0xA6, (byte) 0xE1, (byte) 0xE4, (byte) 0xC7, (byte) 0xAB, (byte) 0xF5, (byte) 0xAE,
(byte) 0x8C, (byte) 0xDB, (byte) 0x09, (byte) 0x33, (byte) 0xD7, (byte) 0x1E, (byte) 0x8C,
(byte) 0x94, (byte) 0xE0, (byte) 0x4A, (byte) 0x25, (byte) 0x61, (byte) 0x9D, (byte) 0xCE,
(byte) 0xE3, (byte) 0xD2, (byte) 0x26, (byte) 0x1A, (byte) 0xD2, (byte) 0xEE, (byte) 0x6B,
(byte) 0xF1, (byte) 0x2F, (byte) 0xFA, (byte) 0x06, (byte) 0xD9, (byte) 0x8A, (byte) 0x08,
(byte) 0x64, (byte) 0xD8, (byte) 0x76, (byte) 0x02, (byte) 0x73, (byte) 0x3E, (byte) 0xC8,
(byte) 0x6A, (byte) 0x64, (byte) 0x52, (byte) 0x1F, (byte) 0x2B, (byte) 0x18, (byte) 0x17,
(byte) 0x7B, (byte) 0x20, (byte) 0x0C, (byte) 0xBB, (byte) 0xE1, (byte) 0x17, (byte) 0x57,
(byte) 0x7A, (byte) 0x61, (byte) 0x5D, (byte) 0x6C, (byte) 0x77, (byte) 0x09, (byte) 0x88,
(byte) 0xC0, (byte) 0xBA, (byte) 0xD9, (byte) 0x46, (byte) 0xE2, (byte) 0x08, (byte) 0xE2,
(byte) 0x4F, (byte) 0xA0, (byte) 0x74, (byte) 0xE5, (byte) 0xAB, (byte) 0x31, (byte) 0x43,
(byte) 0xDB, (byte) 0x5B, (byte) 0xFC, (byte) 0xE0, (byte) 0xFD, (byte) 0x10, (byte) 0x8E,
(byte) 0x4B, (byte) 0x82, (byte) 0xD1, (byte) 0x20, (byte) 0xA9, (byte) 0x21, (byte) 0x08,
(byte) 0x01, (byte) 0x1A, (byte) 0x72, (byte) 0x3C, (byte) 0x12, (byte) 0xA7, (byte) 0x87,
(byte) 0xE6, (byte) 0xD7, (byte) 0x88, (byte) 0x71, (byte) 0x9A, (byte) 0x10, (byte) 0xBD,
(byte) 0xBA, (byte) 0x5B, (byte) 0x26, (byte) 0x99, (byte) 0xC3, (byte) 0x27, (byte) 0x18,
(byte) 0x6A, (byte) 0xF4, (byte) 0xE2, (byte) 0x3C, (byte) 0x1A, (byte) 0x94, (byte) 0x68,
(byte) 0x34, (byte) 0xB6, (byte) 0x15, (byte) 0x0B, (byte) 0xDA, (byte) 0x25, (byte) 0x83,
(byte) 0xE9, (byte) 0xCA, (byte) 0x2A, (byte) 0xD4, (byte) 0x4C, (byte) 0xE8, (byte) 0xDB,
(byte) 0xBB, (byte) 0xC2, (byte) 0xDB, (byte) 0x04, (byte) 0xDE, (byte) 0x8E, (byte) 0xF9,
(byte) 0x2E, (byte) 0x8E, (byte) 0xFC, (byte) 0x14, (byte) 0x1F, (byte) 0xBE, (byte) 0xCA,
(byte) 0xA6, (byte) 0x28, (byte) 0x7C, (byte) 0x59, (byte) 0x47, (byte) 0x4E, (byte) 0x6B,
(byte) 0xC0, (byte) 0x5D, (byte) 0x99, (byte) 0xB2, (byte) 0x96, (byte) 0x4F, (byte) 0xA0,
(byte) 0x90, (byte) 0xC3, (byte) 0xA2, (byte) 0x23, (byte) 0x3B, (byte) 0xA1, (byte) 0x86,
(byte) 0x51, (byte) 0x5B, (byte) 0xE7, (byte) 0xED, (byte) 0x1F, (byte) 0x61, (byte) 0x29,
(byte) 0x70, (byte) 0xCE, (byte) 0xE2, (byte) 0xD7, (byte) 0xAF, (byte) 0xB8, (byte) 0x1B,
(byte) 0xDD, (byte) 0x76, (byte) 0x21, (byte) 0x70, (byte) 0x48, (byte) 0x1C, (byte) 0xD0,
(byte) 0x06, (byte) 0x91, (byte) 0x27, (byte) 0xD5, (byte) 0xB0, (byte) 0x5A, (byte) 0xA9,
(byte) 0x93, (byte) 0xB4, (byte) 0xEA, (byte) 0x98, (byte) 0x8D, (byte) 0x8F, (byte) 0xDD,
(byte) 0xC1, (byte) 0x86, (byte) 0xFF, (byte) 0xB7, (byte) 0xDC, (byte) 0x90, (byte) 0xA6,
(byte) 0xC0, (byte) 0x8F, (byte) 0x4D, (byte) 0xF4, (byte) 0x35, (byte) 0xC9, (byte) 0x34,
(byte) 0x06, (byte) 0x31, (byte) 0x99, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
(byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF};
@Override
byte[] G() {
return g;
}
@Override
byte[] P() {
return p;
}
}

@ -0,0 +1,158 @@
/*
* Copyright (c) 2002-2018 ymnk, JCraft,Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted
* provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions
* and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other materials provided with
* the distribution.
*
* 3. The names of the authors may not be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL JCRAFT, INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.jcraft.jsch;
class DHG17 extends DHGN {
static final byte[] g = {2};
static final byte[] p =
{(byte) 0x00, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
(byte) 0xFF, (byte) 0xFF, (byte) 0xC9, (byte) 0x0F, (byte) 0xDA, (byte) 0xA2, (byte) 0x21,
(byte) 0x68, (byte) 0xC2, (byte) 0x34, (byte) 0xC4, (byte) 0xC6, (byte) 0x62, (byte) 0x8B,
(byte) 0x80, (byte) 0xDC, (byte) 0x1C, (byte) 0xD1, (byte) 0x29, (byte) 0x02, (byte) 0x4E,
(byte) 0x08, (byte) 0x8A, (byte) 0x67, (byte) 0xCC, (byte) 0x74, (byte) 0x02, (byte) 0x0B,
(byte) 0xBE, (byte) 0xA6, (byte) 0x3B, (byte) 0x13, (byte) 0x9B, (byte) 0x22, (byte) 0x51,
(byte) 0x4A, (byte) 0x08, (byte) 0x79, (byte) 0x8E, (byte) 0x34, (byte) 0x04, (byte) 0xDD,
(byte) 0xEF, (byte) 0x95, (byte) 0x19, (byte) 0xB3, (byte) 0xCD, (byte) 0x3A, (byte) 0x43,
(byte) 0x1B, (byte) 0x30, (byte) 0x2B, (byte) 0x0A, (byte) 0x6D, (byte) 0xF2, (byte) 0x5F,
(byte) 0x14, (byte) 0x37, (byte) 0x4F, (byte) 0xE1, (byte) 0x35, (byte) 0x6D, (byte) 0x6D,
(byte) 0x51, (byte) 0xC2, (byte) 0x45, (byte) 0xE4, (byte) 0x85, (byte) 0xB5, (byte) 0x76,
(byte) 0x62, (byte) 0x5E, (byte) 0x7E, (byte) 0xC6, (byte) 0xF4, (byte) 0x4C, (byte) 0x42,
(byte) 0xE9, (byte) 0xA6, (byte) 0x37, (byte) 0xED, (byte) 0x6B, (byte) 0x0B, (byte) 0xFF,
(byte) 0x5C, (byte) 0xB6, (byte) 0xF4, (byte) 0x06, (byte) 0xB7, (byte) 0xED, (byte) 0xEE,
(byte) 0x38, (byte) 0x6B, (byte) 0xFB, (byte) 0x5A, (byte) 0x89, (byte) 0x9F, (byte) 0xA5,
(byte) 0xAE, (byte) 0x9F, (byte) 0x24, (byte) 0x11, (byte) 0x7C, (byte) 0x4B, (byte) 0x1F,
(byte) 0xE6, (byte) 0x49, (byte) 0x28, (byte) 0x66, (byte) 0x51, (byte) 0xEC, (byte) 0xE4,
(byte) 0x5B, (byte) 0x3D, (byte) 0xC2, (byte) 0x00, (byte) 0x7C, (byte) 0xB8, (byte) 0xA1,
(byte) 0x63, (byte) 0xBF, (byte) 0x05, (byte) 0x98, (byte) 0xDA, (byte) 0x48, (byte) 0x36,
(byte) 0x1C, (byte) 0x55, (byte) 0xD3, (byte) 0x9A, (byte) 0x69, (byte) 0x16, (byte) 0x3F,
(byte) 0xA8, (byte) 0xFD, (byte) 0x24, (byte) 0xCF, (byte) 0x5F, (byte) 0x83, (byte) 0x65,
(byte) 0x5D, (byte) 0x23, (byte) 0xDC, (byte) 0xA3, (byte) 0xAD, (byte) 0x96, (byte) 0x1C,
(byte) 0x62, (byte) 0xF3, (byte) 0x56, (byte) 0x20, (byte) 0x85, (byte) 0x52, (byte) 0xBB,
(byte) 0x9E, (byte) 0xD5, (byte) 0x29, (byte) 0x07, (byte) 0x70, (byte) 0x96, (byte) 0x96,
(byte) 0x6D, (byte) 0x67, (byte) 0x0C, (byte) 0x35, (byte) 0x4E, (byte) 0x4A, (byte) 0xBC,
(byte) 0x98, (byte) 0x04, (byte) 0xF1, (byte) 0x74, (byte) 0x6C, (byte) 0x08, (byte) 0xCA,
(byte) 0x18, (byte) 0x21, (byte) 0x7C, (byte) 0x32, (byte) 0x90, (byte) 0x5E, (byte) 0x46,
(byte) 0x2E, (byte) 0x36, (byte) 0xCE, (byte) 0x3B, (byte) 0xE3, (byte) 0x9E, (byte) 0x77,
(byte) 0x2C, (byte) 0x18, (byte) 0x0E, (byte) 0x86, (byte) 0x03, (byte) 0x9B, (byte) 0x27,
(byte) 0x83, (byte) 0xA2, (byte) 0xEC, (byte) 0x07, (byte) 0xA2, (byte) 0x8F, (byte) 0xB5,
(byte) 0xC5, (byte) 0x5D, (byte) 0xF0, (byte) 0x6F, (byte) 0x4C, (byte) 0x52, (byte) 0xC9,
(byte) 0xDE, (byte) 0x2B, (byte) 0xCB, (byte) 0xF6, (byte) 0x95, (byte) 0x58, (byte) 0x17,
(byte) 0x18, (byte) 0x39, (byte) 0x95, (byte) 0x49, (byte) 0x7C, (byte) 0xEA, (byte) 0x95,
(byte) 0x6A, (byte) 0xE5, (byte) 0x15, (byte) 0xD2, (byte) 0x26, (byte) 0x18, (byte) 0x98,
(byte) 0xFA, (byte) 0x05, (byte) 0x10, (byte) 0x15, (byte) 0x72, (byte) 0x8E, (byte) 0x5A,
(byte) 0x8A, (byte) 0xAA, (byte) 0xC4, (byte) 0x2D, (byte) 0xAD, (byte) 0x33, (byte) 0x17,
(byte) 0x0D, (byte) 0x04, (byte) 0x50, (byte) 0x7A, (byte) 0x33, (byte) 0xA8, (byte) 0x55,
(byte) 0x21, (byte) 0xAB, (byte) 0xDF, (byte) 0x1C, (byte) 0xBA, (byte) 0x64, (byte) 0xEC,
(byte) 0xFB, (byte) 0x85, (byte) 0x04, (byte) 0x58, (byte) 0xDB, (byte) 0xEF, (byte) 0x0A,
(byte) 0x8A, (byte) 0xEA, (byte) 0x71, (byte) 0x57, (byte) 0x5D, (byte) 0x06, (byte) 0x0C,
(byte) 0x7D, (byte) 0xB3, (byte) 0x97, (byte) 0x0F, (byte) 0x85, (byte) 0xA6, (byte) 0xE1,
(byte) 0xE4, (byte) 0xC7, (byte) 0xAB, (byte) 0xF5, (byte) 0xAE, (byte) 0x8C, (byte) 0xDB,
(byte) 0x09, (byte) 0x33, (byte) 0xD7, (byte) 0x1E, (byte) 0x8C, (byte) 0x94, (byte) 0xE0,
(byte) 0x4A, (byte) 0x25, (byte) 0x61, (byte) 0x9D, (byte) 0xCE, (byte) 0xE3, (byte) 0xD2,
(byte) 0x26, (byte) 0x1A, (byte) 0xD2, (byte) 0xEE, (byte) 0x6B, (byte) 0xF1, (byte) 0x2F,
(byte) 0xFA, (byte) 0x06, (byte) 0xD9, (byte) 0x8A, (byte) 0x08, (byte) 0x64, (byte) 0xD8,
(byte) 0x76, (byte) 0x02, (byte) 0x73, (byte) 0x3E, (byte) 0xC8, (byte) 0x6A, (byte) 0x64,
(byte) 0x52, (byte) 0x1F, (byte) 0x2B, (byte) 0x18, (byte) 0x17, (byte) 0x7B, (byte) 0x20,
(byte) 0x0C, (byte) 0xBB, (byte) 0xE1, (byte) 0x17, (byte) 0x57, (byte) 0x7A, (byte) 0x61,
(byte) 0x5D, (byte) 0x6C, (byte) 0x77, (byte) 0x09, (byte) 0x88, (byte) 0xC0, (byte) 0xBA,
(byte) 0xD9, (byte) 0x46, (byte) 0xE2, (byte) 0x08, (byte) 0xE2, (byte) 0x4F, (byte) 0xA0,
(byte) 0x74, (byte) 0xE5, (byte) 0xAB, (byte) 0x31, (byte) 0x43, (byte) 0xDB, (byte) 0x5B,
(byte) 0xFC, (byte) 0xE0, (byte) 0xFD, (byte) 0x10, (byte) 0x8E, (byte) 0x4B, (byte) 0x82,
(byte) 0xD1, (byte) 0x20, (byte) 0xA9, (byte) 0x21, (byte) 0x08, (byte) 0x01, (byte) 0x1A,
(byte) 0x72, (byte) 0x3C, (byte) 0x12, (byte) 0xA7, (byte) 0x87, (byte) 0xE6, (byte) 0xD7,
(byte) 0x88, (byte) 0x71, (byte) 0x9A, (byte) 0x10, (byte) 0xBD, (byte) 0xBA, (byte) 0x5B,
(byte) 0x26, (byte) 0x99, (byte) 0xC3, (byte) 0x27, (byte) 0x18, (byte) 0x6A, (byte) 0xF4,
(byte) 0xE2, (byte) 0x3C, (byte) 0x1A, (byte) 0x94, (byte) 0x68, (byte) 0x34, (byte) 0xB6,
(byte) 0x15, (byte) 0x0B, (byte) 0xDA, (byte) 0x25, (byte) 0x83, (byte) 0xE9, (byte) 0xCA,
(byte) 0x2A, (byte) 0xD4, (byte) 0x4C, (byte) 0xE8, (byte) 0xDB, (byte) 0xBB, (byte) 0xC2,
(byte) 0xDB, (byte) 0x04, (byte) 0xDE, (byte) 0x8E, (byte) 0xF9, (byte) 0x2E, (byte) 0x8E,
(byte) 0xFC, (byte) 0x14, (byte) 0x1F, (byte) 0xBE, (byte) 0xCA, (byte) 0xA6, (byte) 0x28,
(byte) 0x7C, (byte) 0x59, (byte) 0x47, (byte) 0x4E, (byte) 0x6B, (byte) 0xC0, (byte) 0x5D,
(byte) 0x99, (byte) 0xB2, (byte) 0x96, (byte) 0x4F, (byte) 0xA0, (byte) 0x90, (byte) 0xC3,
(byte) 0xA2, (byte) 0x23, (byte) 0x3B, (byte) 0xA1, (byte) 0x86, (byte) 0x51, (byte) 0x5B,
(byte) 0xE7, (byte) 0xED, (byte) 0x1F, (byte) 0x61, (byte) 0x29, (byte) 0x70, (byte) 0xCE,
(byte) 0xE2, (byte) 0xD7, (byte) 0xAF, (byte) 0xB8, (byte) 0x1B, (byte) 0xDD, (byte) 0x76,
(byte) 0x21, (byte) 0x70, (byte) 0x48, (byte) 0x1C, (byte) 0xD0, (byte) 0x06, (byte) 0x91,
(byte) 0x27, (byte) 0xD5, (byte) 0xB0, (byte) 0x5A, (byte) 0xA9, (byte) 0x93, (byte) 0xB4,
(byte) 0xEA, (byte) 0x98, (byte) 0x8D, (byte) 0x8F, (byte) 0xDD, (byte) 0xC1, (byte) 0x86,
(byte) 0xFF, (byte) 0xB7, (byte) 0xDC, (byte) 0x90, (byte) 0xA6, (byte) 0xC0, (byte) 0x8F,
(byte) 0x4D, (byte) 0xF4, (byte) 0x35, (byte) 0xC9, (byte) 0x34, (byte) 0x02, (byte) 0x84,
(byte) 0x92, (byte) 0x36, (byte) 0xC3, (byte) 0xFA, (byte) 0xB4, (byte) 0xD2, (byte) 0x7C,
(byte) 0x70, (byte) 0x26, (byte) 0xC1, (byte) 0xD4, (byte) 0xDC, (byte) 0xB2, (byte) 0x60,
(byte) 0x26, (byte) 0x46, (byte) 0xDE, (byte) 0xC9, (byte) 0x75, (byte) 0x1E, (byte) 0x76,
(byte) 0x3D, (byte) 0xBA, (byte) 0x37, (byte) 0xBD, (byte) 0xF8, (byte) 0xFF, (byte) 0x94,
(byte) 0x06, (byte) 0xAD, (byte) 0x9E, (byte) 0x53, (byte) 0x0E, (byte) 0xE5, (byte) 0xDB,
(byte) 0x38, (byte) 0x2F, (byte) 0x41, (byte) 0x30, (byte) 0x01, (byte) 0xAE, (byte) 0xB0,
(byte) 0x6A, (byte) 0x53, (byte) 0xED, (byte) 0x90, (byte) 0x27, (byte) 0xD8, (byte) 0x31,
(byte) 0x17, (byte) 0x97, (byte) 0x27, (byte) 0xB0, (byte) 0x86, (byte) 0x5A, (byte) 0x89,
(byte) 0x18, (byte) 0xDA, (byte) 0x3E, (byte) 0xDB, (byte) 0xEB, (byte) 0xCF, (byte) 0x9B,
(byte) 0x14, (byte) 0xED, (byte) 0x44, (byte) 0xCE, (byte) 0x6C, (byte) 0xBA, (byte) 0xCE,
(byte) 0xD4, (byte) 0xBB, (byte) 0x1B, (byte) 0xDB, (byte) 0x7F, (byte) 0x14, (byte) 0x47,
(byte) 0xE6, (byte) 0xCC, (byte) 0x25, (byte) 0x4B, (byte) 0x33, (byte) 0x20, (byte) 0x51,
(byte) 0x51, (byte) 0x2B, (byte) 0xD7, (byte) 0xAF, (byte) 0x42, (byte) 0x6F, (byte) 0xB8,
(byte) 0xF4, (byte) 0x01, (byte) 0x37, (byte) 0x8C, (byte) 0xD2, (byte) 0xBF, (byte) 0x59,
(byte) 0x83, (byte) 0xCA, (byte) 0x01, (byte) 0xC6, (byte) 0x4B, (byte) 0x92, (byte) 0xEC,
(byte) 0xF0, (byte) 0x32, (byte) 0xEA, (byte) 0x15, (byte) 0xD1, (byte) 0x72, (byte) 0x1D,
(byte) 0x03, (byte) 0xF4, (byte) 0x82, (byte) 0xD7, (byte) 0xCE, (byte) 0x6E, (byte) 0x74,
(byte) 0xFE, (byte) 0xF6, (byte) 0xD5, (byte) 0x5E, (byte) 0x70, (byte) 0x2F, (byte) 0x46,
(byte) 0x98, (byte) 0x0C, (byte) 0x82, (byte) 0xB5, (byte) 0xA8, (byte) 0x40, (byte) 0x31,
(byte) 0x90, (byte) 0x0B, (byte) 0x1C, (byte) 0x9E, (byte) 0x59, (byte) 0xE7, (byte) 0xC9,
(byte) 0x7F, (byte) 0xBE, (byte) 0xC7, (byte) 0xE8, (byte) 0xF3, (byte) 0x23, (byte) 0xA9,
(byte) 0x7A, (byte) 0x7E, (byte) 0x36, (byte) 0xCC, (byte) 0x88, (byte) 0xBE, (byte) 0x0F,
(byte) 0x1D, (byte) 0x45, (byte) 0xB7, (byte) 0xFF, (byte) 0x58, (byte) 0x5A, (byte) 0xC5,
(byte) 0x4B, (byte) 0xD4, (byte) 0x07, (byte) 0xB2, (byte) 0x2B, (byte) 0x41, (byte) 0x54,
(byte) 0xAA, (byte) 0xCC, (byte) 0x8F, (byte) 0x6D, (byte) 0x7E, (byte) 0xBF, (byte) 0x48,
(byte) 0xE1, (byte) 0xD8, (byte) 0x14, (byte) 0xCC, (byte) 0x5E, (byte) 0xD2, (byte) 0x0F,
(byte) 0x80, (byte) 0x37, (byte) 0xE0, (byte) 0xA7, (byte) 0x97, (byte) 0x15, (byte) 0xEE,
(byte) 0xF2, (byte) 0x9B, (byte) 0xE3, (byte) 0x28, (byte) 0x06, (byte) 0xA1, (byte) 0xD5,
(byte) 0x8B, (byte) 0xB7, (byte) 0xC5, (byte) 0xDA, (byte) 0x76, (byte) 0xF5, (byte) 0x50,
(byte) 0xAA, (byte) 0x3D, (byte) 0x8A, (byte) 0x1F, (byte) 0xBF, (byte) 0xF0, (byte) 0xEB,
(byte) 0x19, (byte) 0xCC, (byte) 0xB1, (byte) 0xA3, (byte) 0x13, (byte) 0xD5, (byte) 0x5C,
(byte) 0xDA, (byte) 0x56, (byte) 0xC9, (byte) 0xEC, (byte) 0x2E, (byte) 0xF2, (byte) 0x96,
(byte) 0x32, (byte) 0x38, (byte) 0x7F, (byte) 0xE8, (byte) 0xD7, (byte) 0x6E, (byte) 0x3C,
(byte) 0x04, (byte) 0x68, (byte) 0x04, (byte) 0x3E, (byte) 0x8F, (byte) 0x66, (byte) 0x3F,
(byte) 0x48, (byte) 0x60, (byte) 0xEE, (byte) 0x12, (byte) 0xBF, (byte) 0x2D, (byte) 0x5B,
(byte) 0x0B, (byte) 0x74, (byte) 0x74, (byte) 0xD6, (byte) 0xE6, (byte) 0x94, (byte) 0xF9,
(byte) 0x1E, (byte) 0x6D, (byte) 0xCC, (byte) 0x40, (byte) 0x24, (byte) 0xFF, (byte) 0xFF,
(byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,};
@Override
byte[] G() {
return g;
}
@Override
byte[] P() {
return p;
}
@Override
String sha_name() {
return "sha-512";
}
}

@ -0,0 +1,194 @@
/*
* Copyright (c) 2002-2018 ymnk, JCraft,Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted
* provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions
* and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other materials provided with
* the distribution.
*
* 3. The names of the authors may not be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL JCRAFT, INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.jcraft.jsch;
class DHG18 extends DHGN {
static final byte[] g = {2};
static final byte[] p = {(byte) 0x00, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
(byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xC9, (byte) 0x0F, (byte) 0xDA,
(byte) 0xA2, (byte) 0x21, (byte) 0x68, (byte) 0xC2, (byte) 0x34, (byte) 0xC4, (byte) 0xC6,
(byte) 0x62, (byte) 0x8B, (byte) 0x80, (byte) 0xDC, (byte) 0x1C, (byte) 0xD1, (byte) 0x29,
(byte) 0x02, (byte) 0x4E, (byte) 0x08, (byte) 0x8A, (byte) 0x67, (byte) 0xCC, (byte) 0x74,
(byte) 0x02, (byte) 0x0B, (byte) 0xBE, (byte) 0xA6, (byte) 0x3B, (byte) 0x13, (byte) 0x9B,
(byte) 0x22, (byte) 0x51, (byte) 0x4A, (byte) 0x08, (byte) 0x79, (byte) 0x8E, (byte) 0x34,
(byte) 0x04, (byte) 0xDD, (byte) 0xEF, (byte) 0x95, (byte) 0x19, (byte) 0xB3, (byte) 0xCD,
(byte) 0x3A, (byte) 0x43, (byte) 0x1B, (byte) 0x30, (byte) 0x2B, (byte) 0x0A, (byte) 0x6D,
(byte) 0xF2, (byte) 0x5F, (byte) 0x14, (byte) 0x37, (byte) 0x4F, (byte) 0xE1, (byte) 0x35,
(byte) 0x6D, (byte) 0x6D, (byte) 0x51, (byte) 0xC2, (byte) 0x45, (byte) 0xE4, (byte) 0x85,
(byte) 0xB5, (byte) 0x76, (byte) 0x62, (byte) 0x5E, (byte) 0x7E, (byte) 0xC6, (byte) 0xF4,
(byte) 0x4C, (byte) 0x42, (byte) 0xE9, (byte) 0xA6, (byte) 0x37, (byte) 0xED, (byte) 0x6B,
(byte) 0x0B, (byte) 0xFF, (byte) 0x5C, (byte) 0xB6, (byte) 0xF4, (byte) 0x06, (byte) 0xB7,
(byte) 0xED, (byte) 0xEE, (byte) 0x38, (byte) 0x6B, (byte) 0xFB, (byte) 0x5A, (byte) 0x89,
(byte) 0x9F, (byte) 0xA5, (byte) 0xAE, (byte) 0x9F, (byte) 0x24, (byte) 0x11, (byte) 0x7C,
(byte) 0x4B, (byte) 0x1F, (byte) 0xE6, (byte) 0x49, (byte) 0x28, (byte) 0x66, (byte) 0x51,
(byte) 0xEC, (byte) 0xE4, (byte) 0x5B, (byte) 0x3D, (byte) 0xC2, (byte) 0x00, (byte) 0x7C,
(byte) 0xB8, (byte) 0xA1, (byte) 0x63, (byte) 0xBF, (byte) 0x05, (byte) 0x98, (byte) 0xDA,
(byte) 0x48, (byte) 0x36, (byte) 0x1C, (byte) 0x55, (byte) 0xD3, (byte) 0x9A, (byte) 0x69,
(byte) 0x16, (byte) 0x3F, (byte) 0xA8, (byte) 0xFD, (byte) 0x24, (byte) 0xCF, (byte) 0x5F,
(byte) 0x83, (byte) 0x65, (byte) 0x5D, (byte) 0x23, (byte) 0xDC, (byte) 0xA3, (byte) 0xAD,
(byte) 0x96, (byte) 0x1C, (byte) 0x62, (byte) 0xF3, (byte) 0x56, (byte) 0x20, (byte) 0x85,
(byte) 0x52, (byte) 0xBB, (byte) 0x9E, (byte) 0xD5, (byte) 0x29, (byte) 0x07, (byte) 0x70,
(byte) 0x96, (byte) 0x96, (byte) 0x6D, (byte) 0x67, (byte) 0x0C, (byte) 0x35, (byte) 0x4E,
(byte) 0x4A, (byte) 0xBC, (byte) 0x98, (byte) 0x04, (byte) 0xF1, (byte) 0x74, (byte) 0x6C,
(byte) 0x08, (byte) 0xCA, (byte) 0x18, (byte) 0x21, (byte) 0x7C, (byte) 0x32, (byte) 0x90,
(byte) 0x5E, (byte) 0x46, (byte) 0x2E, (byte) 0x36, (byte) 0xCE, (byte) 0x3B, (byte) 0xE3,
(byte) 0x9E, (byte) 0x77, (byte) 0x2C, (byte) 0x18, (byte) 0x0E, (byte) 0x86, (byte) 0x03,
(byte) 0x9B, (byte) 0x27, (byte) 0x83, (byte) 0xA2, (byte) 0xEC, (byte) 0x07, (byte) 0xA2,
(byte) 0x8F, (byte) 0xB5, (byte) 0xC5, (byte) 0x5D, (byte) 0xF0, (byte) 0x6F, (byte) 0x4C,
(byte) 0x52, (byte) 0xC9, (byte) 0xDE, (byte) 0x2B, (byte) 0xCB, (byte) 0xF6, (byte) 0x95,
(byte) 0x58, (byte) 0x17, (byte) 0x18, (byte) 0x39, (byte) 0x95, (byte) 0x49, (byte) 0x7C,
(byte) 0xEA, (byte) 0x95, (byte) 0x6A, (byte) 0xE5, (byte) 0x15, (byte) 0xD2, (byte) 0x26,
(byte) 0x18, (byte) 0x98, (byte) 0xFA, (byte) 0x05, (byte) 0x10, (byte) 0x15, (byte) 0x72,
(byte) 0x8E, (byte) 0x5A, (byte) 0x8A, (byte) 0xAA, (byte) 0xC4, (byte) 0x2D, (byte) 0xAD,
(byte) 0x33, (byte) 0x17, (byte) 0x0D, (byte) 0x04, (byte) 0x50, (byte) 0x7A, (byte) 0x33,
(byte) 0xA8, (byte) 0x55, (byte) 0x21, (byte) 0xAB, (byte) 0xDF, (byte) 0x1C, (byte) 0xBA,
(byte) 0x64, (byte) 0xEC, (byte) 0xFB, (byte) 0x85, (byte) 0x04, (byte) 0x58, (byte) 0xDB,
(byte) 0xEF, (byte) 0x0A, (byte) 0x8A, (byte) 0xEA, (byte) 0x71, (byte) 0x57, (byte) 0x5D,
(byte) 0x06, (byte) 0x0C, (byte) 0x7D, (byte) 0xB3, (byte) 0x97, (byte) 0x0F, (byte) 0x85,
(byte) 0xA6, (byte) 0xE1, (byte) 0xE4, (byte) 0xC7, (byte) 0xAB, (byte) 0xF5, (byte) 0xAE,
(byte) 0x8C, (byte) 0xDB, (byte) 0x09, (byte) 0x33, (byte) 0xD7, (byte) 0x1E, (byte) 0x8C,
(byte) 0x94, (byte) 0xE0, (byte) 0x4A, (byte) 0x25, (byte) 0x61, (byte) 0x9D, (byte) 0xCE,
(byte) 0xE3, (byte) 0xD2, (byte) 0x26, (byte) 0x1A, (byte) 0xD2, (byte) 0xEE, (byte) 0x6B,
(byte) 0xF1, (byte) 0x2F, (byte) 0xFA, (byte) 0x06, (byte) 0xD9, (byte) 0x8A, (byte) 0x08,
(byte) 0x64, (byte) 0xD8, (byte) 0x76, (byte) 0x02, (byte) 0x73, (byte) 0x3E, (byte) 0xC8,
(byte) 0x6A, (byte) 0x64, (byte) 0x52, (byte) 0x1F, (byte) 0x2B, (byte) 0x18, (byte) 0x17,
(byte) 0x7B, (byte) 0x20, (byte) 0x0C, (byte) 0xBB, (byte) 0xE1, (byte) 0x17, (byte) 0x57,
(byte) 0x7A, (byte) 0x61, (byte) 0x5D, (byte) 0x6C, (byte) 0x77, (byte) 0x09, (byte) 0x88,
(byte) 0xC0, (byte) 0xBA, (byte) 0xD9, (byte) 0x46, (byte) 0xE2, (byte) 0x08, (byte) 0xE2,
(byte) 0x4F, (byte) 0xA0, (byte) 0x74, (byte) 0xE5, (byte) 0xAB, (byte) 0x31, (byte) 0x43,
(byte) 0xDB, (byte) 0x5B, (byte) 0xFC, (byte) 0xE0, (byte) 0xFD, (byte) 0x10, (byte) 0x8E,
(byte) 0x4B, (byte) 0x82, (byte) 0xD1, (byte) 0x20, (byte) 0xA9, (byte) 0x21, (byte) 0x08,
(byte) 0x01, (byte) 0x1A, (byte) 0x72, (byte) 0x3C, (byte) 0x12, (byte) 0xA7, (byte) 0x87,
(byte) 0xE6, (byte) 0xD7, (byte) 0x88, (byte) 0x71, (byte) 0x9A, (byte) 0x10, (byte) 0xBD,
(byte) 0xBA, (byte) 0x5B, (byte) 0x26, (byte) 0x99, (byte) 0xC3, (byte) 0x27, (byte) 0x18,
(byte) 0x6A, (byte) 0xF4, (byte) 0xE2, (byte) 0x3C, (byte) 0x1A, (byte) 0x94, (byte) 0x68,
(byte) 0x34, (byte) 0xB6, (byte) 0x15, (byte) 0x0B, (byte) 0xDA, (byte) 0x25, (byte) 0x83,
(byte) 0xE9, (byte) 0xCA, (byte) 0x2A, (byte) 0xD4, (byte) 0x4C, (byte) 0xE8, (byte) 0xDB,
(byte) 0xBB, (byte) 0xC2, (byte) 0xDB, (byte) 0x04, (byte) 0xDE, (byte) 0x8E, (byte) 0xF9,
(byte) 0x2E, (byte) 0x8E, (byte) 0xFC, (byte) 0x14, (byte) 0x1F, (byte) 0xBE, (byte) 0xCA,
(byte) 0xA6, (byte) 0x28, (byte) 0x7C, (byte) 0x59, (byte) 0x47, (byte) 0x4E, (byte) 0x6B,
(byte) 0xC0, (byte) 0x5D, (byte) 0x99, (byte) 0xB2, (byte) 0x96, (byte) 0x4F, (byte) 0xA0,
(byte) 0x90, (byte) 0xC3, (byte) 0xA2, (byte) 0x23, (byte) 0x3B, (byte) 0xA1, (byte) 0x86,
(byte) 0x51, (byte) 0x5B, (byte) 0xE7, (byte) 0xED, (byte) 0x1F, (byte) 0x61, (byte) 0x29,
(byte) 0x70, (byte) 0xCE, (byte) 0xE2, (byte) 0xD7, (byte) 0xAF, (byte) 0xB8, (byte) 0x1B,
(byte) 0xDD, (byte) 0x76, (byte) 0x21, (byte) 0x70, (byte) 0x48, (byte) 0x1C, (byte) 0xD0,
(byte) 0x06, (byte) 0x91, (byte) 0x27, (byte) 0xD5, (byte) 0xB0, (byte) 0x5A, (byte) 0xA9,
(byte) 0x93, (byte) 0xB4, (byte) 0xEA, (byte) 0x98, (byte) 0x8D, (byte) 0x8F, (byte) 0xDD,
(byte) 0xC1, (byte) 0x86, (byte) 0xFF, (byte) 0xB7, (byte) 0xDC, (byte) 0x90, (byte) 0xA6,
(byte) 0xC0, (byte) 0x8F, (byte) 0x4D, (byte) 0xF4, (byte) 0x35, (byte) 0xC9, (byte) 0x34,
(byte) 0x02, (byte) 0x84, (byte) 0x92, (byte) 0x36, (byte) 0xC3, (byte) 0xFA, (byte) 0xB4,
(byte) 0xD2, (byte) 0x7C, (byte) 0x70, (byte) 0x26, (byte) 0xC1, (byte) 0xD4, (byte) 0xDC,
(byte) 0xB2, (byte) 0x60, (byte) 0x26, (byte) 0x46, (byte) 0xDE, (byte) 0xC9, (byte) 0x75,
(byte) 0x1E, (byte) 0x76, (byte) 0x3D, (byte) 0xBA, (byte) 0x37, (byte) 0xBD, (byte) 0xF8,
(byte) 0xFF, (byte) 0x94, (byte) 0x06, (byte) 0xAD, (byte) 0x9E, (byte) 0x53, (byte) 0x0E,
(byte) 0xE5, (byte) 0xDB, (byte) 0x38, (byte) 0x2F, (byte) 0x41, (byte) 0x30, (byte) 0x01,
(byte) 0xAE, (byte) 0xB0, (byte) 0x6A, (byte) 0x53, (byte) 0xED, (byte) 0x90, (byte) 0x27,
(byte) 0xD8, (byte) 0x31, (byte) 0x17, (byte) 0x97, (byte) 0x27, (byte) 0xB0, (byte) 0x86,
(byte) 0x5A, (byte) 0x89, (byte) 0x18, (byte) 0xDA, (byte) 0x3E, (byte) 0xDB, (byte) 0xEB,
(byte) 0xCF, (byte) 0x9B, (byte) 0x14, (byte) 0xED, (byte) 0x44, (byte) 0xCE, (byte) 0x6C,
(byte) 0xBA, (byte) 0xCE, (byte) 0xD4, (byte) 0xBB, (byte) 0x1B, (byte) 0xDB, (byte) 0x7F,
(byte) 0x14, (byte) 0x47, (byte) 0xE6, (byte) 0xCC, (byte) 0x25, (byte) 0x4B, (byte) 0x33,
(byte) 0x20, (byte) 0x51, (byte) 0x51, (byte) 0x2B, (byte) 0xD7, (byte) 0xAF, (byte) 0x42,
(byte) 0x6F, (byte) 0xB8, (byte) 0xF4, (byte) 0x01, (byte) 0x37, (byte) 0x8C, (byte) 0xD2,
(byte) 0xBF, (byte) 0x59, (byte) 0x83, (byte) 0xCA, (byte) 0x01, (byte) 0xC6, (byte) 0x4B,
(byte) 0x92, (byte) 0xEC, (byte) 0xF0, (byte) 0x32, (byte) 0xEA, (byte) 0x15, (byte) 0xD1,
(byte) 0x72, (byte) 0x1D, (byte) 0x03, (byte) 0xF4, (byte) 0x82, (byte) 0xD7, (byte) 0xCE,
(byte) 0x6E, (byte) 0x74, (byte) 0xFE, (byte) 0xF6, (byte) 0xD5, (byte) 0x5E, (byte) 0x70,
(byte) 0x2F, (byte) 0x46, (byte) 0x98, (byte) 0x0C, (byte) 0x82, (byte) 0xB5, (byte) 0xA8,
(byte) 0x40, (byte) 0x31, (byte) 0x90, (byte) 0x0B, (byte) 0x1C, (byte) 0x9E, (byte) 0x59,
(byte) 0xE7, (byte) 0xC9, (byte) 0x7F, (byte) 0xBE, (byte) 0xC7, (byte) 0xE8, (byte) 0xF3,
(byte) 0x23, (byte) 0xA9, (byte) 0x7A, (byte) 0x7E, (byte) 0x36, (byte) 0xCC, (byte) 0x88,
(byte) 0xBE, (byte) 0x0F, (byte) 0x1D, (byte) 0x45, (byte) 0xB7, (byte) 0xFF, (byte) 0x58,
(byte) 0x5A, (byte) 0xC5, (byte) 0x4B, (byte) 0xD4, (byte) 0x07, (byte) 0xB2, (byte) 0x2B,
(byte) 0x41, (byte) 0x54, (byte) 0xAA, (byte) 0xCC, (byte) 0x8F, (byte) 0x6D, (byte) 0x7E,
(byte) 0xBF, (byte) 0x48, (byte) 0xE1, (byte) 0xD8, (byte) 0x14, (byte) 0xCC, (byte) 0x5E,
(byte) 0xD2, (byte) 0x0F, (byte) 0x80, (byte) 0x37, (byte) 0xE0, (byte) 0xA7, (byte) 0x97,
(byte) 0x15, (byte) 0xEE, (byte) 0xF2, (byte) 0x9B, (byte) 0xE3, (byte) 0x28, (byte) 0x06,
(byte) 0xA1, (byte) 0xD5, (byte) 0x8B, (byte) 0xB7, (byte) 0xC5, (byte) 0xDA, (byte) 0x76,
(byte) 0xF5, (byte) 0x50, (byte) 0xAA, (byte) 0x3D, (byte) 0x8A, (byte) 0x1F, (byte) 0xBF,
(byte) 0xF0, (byte) 0xEB, (byte) 0x19, (byte) 0xCC, (byte) 0xB1, (byte) 0xA3, (byte) 0x13,
(byte) 0xD5, (byte) 0x5C, (byte) 0xDA, (byte) 0x56, (byte) 0xC9, (byte) 0xEC, (byte) 0x2E,
(byte) 0xF2, (byte) 0x96, (byte) 0x32, (byte) 0x38, (byte) 0x7F, (byte) 0xE8, (byte) 0xD7,
(byte) 0x6E, (byte) 0x3C, (byte) 0x04, (byte) 0x68, (byte) 0x04, (byte) 0x3E, (byte) 0x8F,
(byte) 0x66, (byte) 0x3F, (byte) 0x48, (byte) 0x60, (byte) 0xEE, (byte) 0x12, (byte) 0xBF,
(byte) 0x2D, (byte) 0x5B, (byte) 0x0B, (byte) 0x74, (byte) 0x74, (byte) 0xD6, (byte) 0xE6,
(byte) 0x94, (byte) 0xF9, (byte) 0x1E, (byte) 0x6D, (byte) 0xBE, (byte) 0x11, (byte) 0x59,
(byte) 0x74, (byte) 0xA3, (byte) 0x92, (byte) 0x6F, (byte) 0x12, (byte) 0xFE, (byte) 0xE5,
(byte) 0xE4, (byte) 0x38, (byte) 0x77, (byte) 0x7C, (byte) 0xB6, (byte) 0xA9, (byte) 0x32,
(byte) 0xDF, (byte) 0x8C, (byte) 0xD8, (byte) 0xBE, (byte) 0xC4, (byte) 0xD0, (byte) 0x73,
(byte) 0xB9, (byte) 0x31, (byte) 0xBA, (byte) 0x3B, (byte) 0xC8, (byte) 0x32, (byte) 0xB6,
(byte) 0x8D, (byte) 0x9D, (byte) 0xD3, (byte) 0x00, (byte) 0x74, (byte) 0x1F, (byte) 0xA7,
(byte) 0xBF, (byte) 0x8A, (byte) 0xFC, (byte) 0x47, (byte) 0xED, (byte) 0x25, (byte) 0x76,
(byte) 0xF6, (byte) 0x93, (byte) 0x6B, (byte) 0xA4, (byte) 0x24, (byte) 0x66, (byte) 0x3A,
(byte) 0xAB, (byte) 0x63, (byte) 0x9C, (byte) 0x5A, (byte) 0xE4, (byte) 0xF5, (byte) 0x68,
(byte) 0x34, (byte) 0x23, (byte) 0xB4, (byte) 0x74, (byte) 0x2B, (byte) 0xF1, (byte) 0xC9,
(byte) 0x78, (byte) 0x23, (byte) 0x8F, (byte) 0x16, (byte) 0xCB, (byte) 0xE3, (byte) 0x9D,
(byte) 0x65, (byte) 0x2D, (byte) 0xE3, (byte) 0xFD, (byte) 0xB8, (byte) 0xBE, (byte) 0xFC,
(byte) 0x84, (byte) 0x8A, (byte) 0xD9, (byte) 0x22, (byte) 0x22, (byte) 0x2E, (byte) 0x04,
(byte) 0xA4, (byte) 0x03, (byte) 0x7C, (byte) 0x07, (byte) 0x13, (byte) 0xEB, (byte) 0x57,
(byte) 0xA8, (byte) 0x1A, (byte) 0x23, (byte) 0xF0, (byte) 0xC7, (byte) 0x34, (byte) 0x73,
(byte) 0xFC, (byte) 0x64, (byte) 0x6C, (byte) 0xEA, (byte) 0x30, (byte) 0x6B, (byte) 0x4B,
(byte) 0xCB, (byte) 0xC8, (byte) 0x86, (byte) 0x2F, (byte) 0x83, (byte) 0x85, (byte) 0xDD,
(byte) 0xFA, (byte) 0x9D, (byte) 0x4B, (byte) 0x7F, (byte) 0xA2, (byte) 0xC0, (byte) 0x87,
(byte) 0xE8, (byte) 0x79, (byte) 0x68, (byte) 0x33, (byte) 0x03, (byte) 0xED, (byte) 0x5B,
(byte) 0xDD, (byte) 0x3A, (byte) 0x06, (byte) 0x2B, (byte) 0x3C, (byte) 0xF5, (byte) 0xB3,
(byte) 0xA2, (byte) 0x78, (byte) 0xA6, (byte) 0x6D, (byte) 0x2A, (byte) 0x13, (byte) 0xF8,
(byte) 0x3F, (byte) 0x44, (byte) 0xF8, (byte) 0x2D, (byte) 0xDF, (byte) 0x31, (byte) 0x0E,
(byte) 0xE0, (byte) 0x74, (byte) 0xAB, (byte) 0x6A, (byte) 0x36, (byte) 0x45, (byte) 0x97,
(byte) 0xE8, (byte) 0x99, (byte) 0xA0, (byte) 0x25, (byte) 0x5D, (byte) 0xC1, (byte) 0x64,
(byte) 0xF3, (byte) 0x1C, (byte) 0xC5, (byte) 0x08, (byte) 0x46, (byte) 0x85, (byte) 0x1D,
(byte) 0xF9, (byte) 0xAB, (byte) 0x48, (byte) 0x19, (byte) 0x5D, (byte) 0xED, (byte) 0x7E,
(byte) 0xA1, (byte) 0xB1, (byte) 0xD5, (byte) 0x10, (byte) 0xBD, (byte) 0x7E, (byte) 0xE7,
(byte) 0x4D, (byte) 0x73, (byte) 0xFA, (byte) 0xF3, (byte) 0x6B, (byte) 0xC3, (byte) 0x1E,
(byte) 0xCF, (byte) 0xA2, (byte) 0x68, (byte) 0x35, (byte) 0x90, (byte) 0x46, (byte) 0xF4,
(byte) 0xEB, (byte) 0x87, (byte) 0x9F, (byte) 0x92, (byte) 0x40, (byte) 0x09, (byte) 0x43,
(byte) 0x8B, (byte) 0x48, (byte) 0x1C, (byte) 0x6C, (byte) 0xD7, (byte) 0x88, (byte) 0x9A,
(byte) 0x00, (byte) 0x2E, (byte) 0xD5, (byte) 0xEE, (byte) 0x38, (byte) 0x2B, (byte) 0xC9,
(byte) 0x19, (byte) 0x0D, (byte) 0xA6, (byte) 0xFC, (byte) 0x02, (byte) 0x6E, (byte) 0x47,
(byte) 0x95, (byte) 0x58, (byte) 0xE4, (byte) 0x47, (byte) 0x56, (byte) 0x77, (byte) 0xE9,
(byte) 0xAA, (byte) 0x9E, (byte) 0x30, (byte) 0x50, (byte) 0xE2, (byte) 0x76, (byte) 0x56,
(byte) 0x94, (byte) 0xDF, (byte) 0xC8, (byte) 0x1F, (byte) 0x56, (byte) 0xE8, (byte) 0x80,
(byte) 0xB9, (byte) 0x6E, (byte) 0x71, (byte) 0x60, (byte) 0xC9, (byte) 0x80, (byte) 0xDD,
(byte) 0x98, (byte) 0xED, (byte) 0xD3, (byte) 0xDF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
(byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF};
@Override
byte[] G() {
return g;
}
@Override
byte[] P() {
return p;
}
@Override
String sha_name() {
return "sha-512";
}
}

@ -0,0 +1,246 @@
/*
* Copyright (c) 2002-2018 ymnk, JCraft,Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted
* provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions
* and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other materials provided with
* the distribution.
*
* 3. The names of the authors may not be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL JCRAFT, INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.jcraft.jsch;
import java.math.BigInteger;
abstract class DHGEX extends KeyExchange {
private static final int SSH_MSG_KEX_DH_GEX_GROUP = 31;
private static final int SSH_MSG_KEX_DH_GEX_INIT = 32;
private static final int SSH_MSG_KEX_DH_GEX_REPLY = 33;
private static final int SSH_MSG_KEX_DH_GEX_REQUEST = 34;
int min;
int preferred;
int max;
private int state;
DH dh;
byte[] V_S;
byte[] V_C;
byte[] I_S;
byte[] I_C;
private Buffer buf;
private Packet packet;
private byte[] p;
private byte[] g;
private byte[] e;
protected String hash;
@Override
public void init(Session session, byte[] V_S, byte[] V_C, byte[] I_S, byte[] I_C)
throws Exception {
this.V_S = V_S;
this.V_C = V_C;
this.I_S = I_S;
this.I_C = I_C;
try {
Class<? extends HASH> c = Class.forName(session.getConfig(hash)).asSubclass(HASH.class);
sha = c.getDeclaredConstructor().newInstance();
sha.init();
} catch (Exception e) {
throw new JSchException(e.toString(), e);
}
buf = new Buffer();
packet = new Packet(buf);
try {
Class<? extends DH> c = Class.forName(session.getConfig("dh")).asSubclass(DH.class);
min = Integer.parseInt(session.getConfig("dhgex_min"));
max = Integer.parseInt(session.getConfig("dhgex_max"));
preferred = Integer.parseInt(session.getConfig("dhgex_preferred"));
if (min <= 0 || max <= 0 || preferred <= 0 || preferred < min || preferred > max) {
throw new JSchException(
"Invalid DHGEX sizes: min=" + min + " max=" + max + " preferred=" + preferred);
}
dh = c.getDeclaredConstructor().newInstance();
dh.init();
} catch (Exception e) {
throw new JSchException(e.toString(), e);
}
packet.reset();
buf.putByte((byte) SSH_MSG_KEX_DH_GEX_REQUEST);
buf.putInt(min);
buf.putInt(preferred);
buf.putInt(max);
session.write(packet);
if (session.getLogger().isEnabled(Logger.INFO)) {
session.getLogger().log(Logger.INFO,
"SSH_MSG_KEX_DH_GEX_REQUEST(" + min + "<" + preferred + "<" + max + ") sent");
session.getLogger().log(Logger.INFO, "expecting SSH_MSG_KEX_DH_GEX_GROUP");
}
state = SSH_MSG_KEX_DH_GEX_GROUP;
}
@Override
public boolean next(Buffer _buf) throws Exception {
int i, j;
switch (state) {
case SSH_MSG_KEX_DH_GEX_GROUP:
// byte SSH_MSG_KEX_DH_GEX_GROUP(31)
// mpint p, safe prime
// mpint g, generator for subgroup in GF (p)
_buf.getInt();
_buf.getByte();
j = _buf.getByte();
if (j != SSH_MSG_KEX_DH_GEX_GROUP) {
if (session.getLogger().isEnabled(Logger.ERROR)) {
session.getLogger().log(Logger.ERROR, "type: must be SSH_MSG_KEX_DH_GEX_GROUP " + j);
}
return false;
}
p = _buf.getMPInt();
g = _buf.getMPInt();
int bits = new BigInteger(1, p).bitLength();
if (bits < min || bits > max) {
return false;
}
dh.setP(p);
dh.setG(g);
// The client responds with:
// byte SSH_MSG_KEX_DH_GEX_INIT(32)
// mpint e <- g^x mod p
// x is a random number (1 < x < (p-1)/2)
e = dh.getE();
packet.reset();
buf.putByte((byte) SSH_MSG_KEX_DH_GEX_INIT);
buf.putMPInt(e);
session.write(packet);
if (session.getLogger().isEnabled(Logger.INFO)) {
session.getLogger().log(Logger.INFO, "SSH_MSG_KEX_DH_GEX_INIT sent");
session.getLogger().log(Logger.INFO, "expecting SSH_MSG_KEX_DH_GEX_REPLY");
}
state = SSH_MSG_KEX_DH_GEX_REPLY;
return true;
// break;
case SSH_MSG_KEX_DH_GEX_REPLY:
// The server responds with:
// byte SSH_MSG_KEX_DH_GEX_REPLY(33)
// string server public host key and certificates (K_S)
// mpint f
// string signature of H
j = _buf.getInt();
j = _buf.getByte();
j = _buf.getByte();
if (j != SSH_MSG_KEX_DH_GEX_REPLY) {
if (session.getLogger().isEnabled(Logger.ERROR)) {
session.getLogger().log(Logger.ERROR, "type: must be SSH_MSG_KEX_DH_GEX_REPLY " + j);
}
return false;
}
K_S = _buf.getString();
byte[] f = _buf.getMPInt();
byte[] sig_of_H = _buf.getString();
dh.setF(f);
dh.checkRange();
K = encodeAsMPInt(normalize(dh.getK()));
// The hash H is computed as the HASH hash of the concatenation of the
// following:
// string V_C, the client's version string (CR and NL excluded)
// string V_S, the server's version string (CR and NL excluded)
// string I_C, the payload of the client's SSH_MSG_KEXINIT
// string I_S, the payload of the server's SSH_MSG_KEXINIT
// string K_S, the host key
// uint32 min, minimal size in bits of an acceptable group
// uint32 n, preferred size in bits of the group the server should send
// uint32 max, maximal size in bits of an acceptable group
// mpint p, safe prime
// mpint g, generator for subgroup
// mpint e, exchange value sent by the client
// mpint f, exchange value sent by the server
// mpint K, the shared secret
// This value is called the exchange hash, and it is used to authenti-
// cate the key exchange.
buf.reset();
buf.putString(V_C);
buf.putString(V_S);
buf.putString(I_C);
buf.putString(I_S);
buf.putString(K_S);
buf.putInt(min);
buf.putInt(preferred);
buf.putInt(max);
buf.putMPInt(p);
buf.putMPInt(g);
buf.putMPInt(e);
buf.putMPInt(f);
byte[] foo = new byte[buf.getLength()];
buf.getByte(foo);
sha.update(foo, 0, foo.length);
sha.update(K, 0, K.length);
H = sha.digest();
// System.err.print("H -> "); dump(H, 0, H.length);
i = 0;
j = 0;
j = ((K_S[i++] << 24) & 0xff000000) | ((K_S[i++] << 16) & 0x00ff0000)
| ((K_S[i++] << 8) & 0x0000ff00) | ((K_S[i++]) & 0x000000ff);
String alg = Util.byte2str(K_S, i, j);
i += j;
boolean result = verify(alg, K_S, i, sig_of_H);
state = STATE_END;
return result;
}
return false;
}
@Override
public int getState() {
return state;
}
}

@ -0,0 +1,33 @@
/*
* Copyright (c) 2002-2018 ymnk, JCraft,Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted
* provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions
* and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other materials provided with
* the distribution.
*
* 3. The names of the authors may not be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL JCRAFT, INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.jcraft.jsch;
class DHGEX1 extends DHGEX {
DHGEX1() {
hash = "sha-1";
}
}

@ -0,0 +1,33 @@
/*
* Copyright (c) 2002-2018 ymnk, JCraft,Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted
* provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions
* and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other materials provided with
* the distribution.
*
* 3. The names of the authors may not be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL JCRAFT, INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.jcraft.jsch;
class DHGEX224 extends DHGEX {
DHGEX224() {
hash = "sha-224";
}
}

@ -0,0 +1,33 @@
/*
* Copyright (c) 2002-2018 ymnk, JCraft,Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted
* provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions
* and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other materials provided with
* the distribution.
*
* 3. The names of the authors may not be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL JCRAFT, INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.jcraft.jsch;
class DHGEX256 extends DHGEX {
DHGEX256() {
hash = "sha-256";
}
}

@ -0,0 +1,33 @@
/*
* Copyright (c) 2002-2018 ymnk, JCraft,Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted
* provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions
* and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other materials provided with
* the distribution.
*
* 3. The names of the authors may not be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL JCRAFT, INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.jcraft.jsch;
class DHGEX384 extends DHGEX {
DHGEX384() {
hash = "sha-384";
}
}

@ -0,0 +1,33 @@
/*
* Copyright (c) 2002-2018 ymnk, JCraft,Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted
* provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions
* and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other materials provided with
* the distribution.
*
* 3. The names of the authors may not be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL JCRAFT, INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.jcraft.jsch;
class DHGEX512 extends DHGEX {
DHGEX512() {
hash = "sha-512";
}
}

@ -0,0 +1,186 @@
/*
* Copyright (c) 2002-2018 ymnk, JCraft,Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted
* provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions
* and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other materials provided with
* the distribution.
*
* 3. The names of the authors may not be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL JCRAFT, INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.jcraft.jsch;
abstract class DHGN extends KeyExchange {
private static final int SSH_MSG_KEXDH_INIT = 30;
private static final int SSH_MSG_KEXDH_REPLY = 31;
private int state;
DH dh;
byte[] V_S;
byte[] V_C;
byte[] I_S;
byte[] I_C;
byte[] e;
private Buffer buf;
private Packet packet;
abstract byte[] G();
abstract byte[] P();
abstract String sha_name();
@Override
public void init(Session session, byte[] V_S, byte[] V_C, byte[] I_S, byte[] I_C)
throws Exception {
this.V_S = V_S;
this.V_C = V_C;
this.I_S = I_S;
this.I_C = I_C;
try {
Class<? extends HASH> c = Class.forName(session.getConfig(sha_name())).asSubclass(HASH.class);
sha = c.getDeclaredConstructor().newInstance();
sha.init();
} catch (Exception e) {
throw new JSchException(e.toString(), e);
}
buf = new Buffer();
packet = new Packet(buf);
try {
Class<? extends DH> c = Class.forName(session.getConfig("dh")).asSubclass(DH.class);
dh = c.getDeclaredConstructor().newInstance();
dh.init();
} catch (Exception e) {
throw new JSchException(e.toString(), e);
}
dh.setP(P());
dh.setG(G());
// The client responds with:
// byte SSH_MSG_KEXDH_INIT(30)
// mpint e <- g^x mod p
// x is a random number (1 < x < (p-1)/2)
e = dh.getE();
packet.reset();
buf.putByte((byte) SSH_MSG_KEXDH_INIT);
buf.putMPInt(e);
if (V_S == null) { // This is a really ugly hack for Session.checkKexes ;-(
return;
}
session.write(packet);
if (session.getLogger().isEnabled(Logger.INFO)) {
session.getLogger().log(Logger.INFO, "SSH_MSG_KEXDH_INIT sent");
session.getLogger().log(Logger.INFO, "expecting SSH_MSG_KEXDH_REPLY");
}
state = SSH_MSG_KEXDH_REPLY;
}
@Override
public boolean next(Buffer _buf) throws Exception {
int i, j;
switch (state) {
case SSH_MSG_KEXDH_REPLY:
// The server responds with:
// byte SSH_MSG_KEXDH_REPLY(31)
// string server public host key and certificates (K_S)
// mpint f
// string signature of H
j = _buf.getInt();
j = _buf.getByte();
j = _buf.getByte();
if (j != SSH_MSG_KEXDH_REPLY) {
if (session.getLogger().isEnabled(Logger.ERROR)) {
session.getLogger().log(Logger.ERROR, "type: must be SSH_MSG_KEXDH_REPLY " + j);
}
return false;
}
K_S = _buf.getString();
byte[] f = _buf.getMPInt();
byte[] sig_of_H = _buf.getString();
dh.setF(f);
dh.checkRange();
K = encodeAsMPInt(normalize(dh.getK()));
// The hash H is computed as the HASH hash of the concatenation of the
// following:
// string V_C, the client's version string (CR and NL excluded)
// string V_S, the server's version string (CR and NL excluded)
// string I_C, the payload of the client's SSH_MSG_KEXINIT
// string I_S, the payload of the server's SSH_MSG_KEXINIT
// string K_S, the host key
// mpint e, exchange value sent by the client
// mpint f, exchange value sent by the server
// mpint K, the shared secret
// This value is called the exchange hash, and it is used to authenti-
// cate the key exchange.
buf.reset();
buf.putString(V_C);
buf.putString(V_S);
buf.putString(I_C);
buf.putString(I_S);
buf.putString(K_S);
buf.putMPInt(e);
buf.putMPInt(f);
byte[] foo = new byte[buf.getLength()];
buf.getByte(foo);
sha.update(foo, 0, foo.length);
sha.update(K, 0, K.length);
H = sha.digest();
// System.err.print("H -> "); //dump(H, 0, H.length);
i = 0;
j = 0;
j = ((K_S[i++] << 24) & 0xff000000) | ((K_S[i++] << 16) & 0x00ff0000)
| ((K_S[i++] << 8) & 0x0000ff00) | ((K_S[i++]) & 0x000000ff);
String alg = Util.byte2str(K_S, i, j);
i += j;
boolean result = verify(alg, K_S, i, sig_of_H);
state = STATE_END;
return result;
}
return false;
}
@Override
public int getState() {
return state;
}
}

@ -0,0 +1,199 @@
/*
* Copyright (c) 2015-2018 ymnk, JCraft,Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted
* provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions
* and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other materials provided with
* the distribution.
*
* 3. The names of the authors may not be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL JCRAFT, INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.jcraft.jsch;
abstract class DHXEC extends KeyExchange {
private static final int SSH_MSG_KEX_ECDH_INIT = 30;
private static final int SSH_MSG_KEX_ECDH_REPLY = 31;
private int state;
byte[] Q_C;
byte[] V_S;
byte[] V_C;
byte[] I_S;
byte[] I_C;
byte[] e;
private Buffer buf;
private Packet packet;
private XDH xdh;
protected String sha_name;
protected String curve_name;
protected int key_len;
@Override
public void init(Session session, byte[] V_S, byte[] V_C, byte[] I_S, byte[] I_C)
throws Exception {
this.V_S = V_S;
this.V_C = V_C;
this.I_S = I_S;
this.I_C = I_C;
try {
Class<? extends HASH> c = Class.forName(session.getConfig(sha_name)).asSubclass(HASH.class);
sha = c.getDeclaredConstructor().newInstance();
sha.init();
} catch (Exception e) {
throw new JSchException(e.toString(), e);
}
buf = new Buffer();
packet = new Packet(buf);
packet.reset();
buf.putByte((byte) SSH_MSG_KEX_ECDH_INIT);
try {
Class<? extends XDH> c = Class.forName(session.getConfig("xdh")).asSubclass(XDH.class);
xdh = c.getDeclaredConstructor().newInstance();
xdh.init(curve_name, key_len);
Q_C = xdh.getQ();
buf.putString(Q_C);
} catch (Exception | NoClassDefFoundError e) {
throw new JSchException(e.toString(), e);
}
if (V_S == null) { // This is a really ugly hack for Session.checkKexes ;-(
return;
}
session.write(packet);
if (session.getLogger().isEnabled(Logger.INFO)) {
session.getLogger().log(Logger.INFO, "SSH_MSG_KEX_ECDH_INIT sent");
session.getLogger().log(Logger.INFO, "expecting SSH_MSG_KEX_ECDH_REPLY");
}
state = SSH_MSG_KEX_ECDH_REPLY;
}
@Override
public boolean next(Buffer _buf) throws Exception {
int i, j;
switch (state) {
case SSH_MSG_KEX_ECDH_REPLY:
// The server responds with:
// byte SSH_MSG_KEX_ECDH_REPLY
// string K_S, server's public host key
// string Q_S, server's ephemeral public key octet string
// string the signature on the exchange hash
j = _buf.getInt();
j = _buf.getByte();
j = _buf.getByte();
if (j != SSH_MSG_KEX_ECDH_REPLY) {
if (session.getLogger().isEnabled(Logger.ERROR)) {
session.getLogger().log(Logger.ERROR, "type: must be SSH_MSG_KEX_ECDH_REPLY " + j);
}
return false;
}
K_S = _buf.getString();
byte[] Q_S = _buf.getString();
// RFC 5656,
// 4. ECDH Key Exchange
// All elliptic curve public keys MUST be validated after they are
// received. An example of a validation algorithm can be found in
// Section 3.2.2 of [SEC1]. If a key fails validation,
// the key exchange MUST fail.
if (!xdh.validate(Q_S)) {
return false;
}
K = encodeAsMPInt(normalize(xdh.getSecret(Q_S)));
byte[] sig_of_H = _buf.getString();
// The hash H is computed as the HASH hash of the concatenation of the
// following:
// string V_C, client's identification string (CR and LF excluded)
// string V_S, server's identification string (CR and LF excluded)
// string I_C, payload of the client's SSH_MSG_KEXINIT
// string I_S, payload of the server's SSH_MSG_KEXINIT
// string K_S, server's public host key
// string Q_C, client's ephemeral public key octet string
// string Q_S, server's ephemeral public key octet string
// mpint K, shared secret
// This value is called the exchange hash, and it is used to authenti-
// cate the key exchange.
// RFC 8731,
// 3.1. Shared Secret Encoding
// The shared secret, K, is defined in [RFC4253] and [RFC5656] as an
// integer encoded as a multiple precision integer (mpint).
// Curve25519/448 outputs a binary string X, which is the 32- or 56-byte
// point obtained by scalar multiplication of the other side's public
// key and the local private key scalar. The 32 or 56 bytes of X are
// converted into K by interpreting the octets as an unsigned fixed-
// length integer encoded in network byte order.
//
// The mpint K is then encoded using the process described in Section 5
// of [RFC4251], and the resulting bytes are fed as described in
// [RFC4253] to the key exchange method's hash function to generate
// encryption keys.
buf.reset();
buf.putString(V_C);
buf.putString(V_S);
buf.putString(I_C);
buf.putString(I_S);
buf.putString(K_S);
buf.putString(Q_C);
buf.putString(Q_S);
byte[] foo = new byte[buf.getLength()];
buf.getByte(foo);
sha.update(foo, 0, foo.length);
sha.update(K, 0, K.length);
H = sha.digest();
i = 0;
j = 0;
j = ((K_S[i++] << 24) & 0xff000000) | ((K_S[i++] << 16) & 0x00ff0000)
| ((K_S[i++] << 8) & 0x0000ff00) | ((K_S[i++]) & 0x000000ff);
String alg = Util.byte2str(K_S, i, j);
i += j;
boolean result = verify(alg, K_S, i, sig_of_H);
state = STATE_END;
return result;
}
return false;
}
@Override
public int getState() {
return state;
}
}

@ -0,0 +1,229 @@
/*
* Copyright (c) 2015-2018 ymnk, JCraft,Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted
* provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions
* and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other materials provided with
* the distribution.
*
* 3. The names of the authors may not be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL JCRAFT, INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.jcraft.jsch;
abstract class DHXECKEM extends KeyExchange {
private static final int SSH_MSG_KEX_ECDH_INIT = 30;
private static final int SSH_MSG_KEX_ECDH_REPLY = 31;
private int state;
byte[] Q_C;
byte[] V_S;
byte[] V_C;
byte[] I_S;
byte[] I_C;
byte[] e;
private Buffer buf;
private Packet packet;
private KEM kem;
private XDH xdh;
protected String kem_name;
protected String sha_name;
protected String curve_name;
protected int kem_pubkey_len;
protected int kem_encap_len;
protected int xec_key_len;
@Override
public void init(Session session, byte[] V_S, byte[] V_C, byte[] I_S, byte[] I_C)
throws Exception {
this.V_S = V_S;
this.V_C = V_C;
this.I_S = I_S;
this.I_C = I_C;
try {
Class<? extends HASH> c = Class.forName(session.getConfig(sha_name)).asSubclass(HASH.class);
sha = c.getDeclaredConstructor().newInstance();
sha.init();
} catch (Exception e) {
throw new JSchException(e.toString(), e);
}
buf = new Buffer();
packet = new Packet(buf);
packet.reset();
// command + string len + Q_C len
buf.checkFreeSize(1 + 4 + kem_pubkey_len + xec_key_len);
buf.putByte((byte) SSH_MSG_KEX_ECDH_INIT);
try {
Class<? extends KEM> k = Class.forName(session.getConfig(kem_name)).asSubclass(KEM.class);
kem = k.getDeclaredConstructor().newInstance();
kem.init();
Class<? extends XDH> c = Class.forName(session.getConfig("xdh")).asSubclass(XDH.class);
xdh = c.getDeclaredConstructor().newInstance();
xdh.init(curve_name, xec_key_len);
byte[] kem_public_key_C = kem.getPublicKey();
byte[] xec_public_key_C = xdh.getQ();
Q_C = new byte[kem_pubkey_len + xec_key_len];
System.arraycopy(kem_public_key_C, 0, Q_C, 0, kem_pubkey_len);
System.arraycopy(xec_public_key_C, 0, Q_C, kem_pubkey_len, xec_key_len);
buf.putString(Q_C);
} catch (Exception | NoClassDefFoundError e) {
throw new JSchException(e.toString(), e);
}
if (V_S == null) { // This is a really ugly hack for Session.checkKexes ;-(
return;
}
session.write(packet);
if (session.getLogger().isEnabled(Logger.INFO)) {
session.getLogger().log(Logger.INFO, "SSH_MSG_KEX_ECDH_INIT sent");
session.getLogger().log(Logger.INFO, "expecting SSH_MSG_KEX_ECDH_REPLY");
}
state = SSH_MSG_KEX_ECDH_REPLY;
}
@Override
public boolean next(Buffer _buf) throws Exception {
int i, j;
switch (state) {
case SSH_MSG_KEX_ECDH_REPLY:
// The server responds with:
// byte SSH_MSG_KEX_ECDH_REPLY
// string K_S, server's public host key
// string Q_S, server's ephemeral public key octet string
// string the signature on the exchange hash
j = _buf.getInt();
j = _buf.getByte();
j = _buf.getByte();
if (j != SSH_MSG_KEX_ECDH_REPLY) {
if (session.getLogger().isEnabled(Logger.ERROR)) {
session.getLogger().log(Logger.ERROR, "type: must be SSH_MSG_KEX_ECDH_REPLY " + j);
}
return false;
}
K_S = _buf.getString();
byte[] Q_S = _buf.getString();
if (Q_S.length != kem_encap_len + xec_key_len) {
return false;
}
byte[] encapsulation = new byte[kem_encap_len];
byte[] xec_public_key_S = new byte[xec_key_len];
System.arraycopy(Q_S, 0, encapsulation, 0, kem_encap_len);
System.arraycopy(Q_S, kem_encap_len, xec_public_key_S, 0, xec_key_len);
// RFC 5656,
// 4. ECDH Key Exchange
// All elliptic curve public keys MUST be validated after they are
// received. An example of a validation algorithm can be found in
// Section 3.2.2 of [SEC1]. If a key fails validation,
// the key exchange MUST fail.
if (!xdh.validate(xec_public_key_S)) {
return false;
}
byte[] tmp = null;
try {
tmp = kem.decapsulate(encapsulation);
sha.update(tmp, 0, tmp.length);
} finally {
Util.bzero(tmp);
}
try {
tmp = normalize(xdh.getSecret(xec_public_key_S));
sha.update(tmp, 0, tmp.length);
} finally {
Util.bzero(tmp);
}
K = encodeAsString(sha.digest());
byte[] sig_of_H = _buf.getString();
// The hash H is computed as the HASH hash of the concatenation of the
// following:
// string V_C, client's identification string (CR and LF excluded)
// string V_S, server's identification string (CR and LF excluded)
// string I_C, payload of the client's SSH_MSG_KEXINIT
// string I_S, payload of the server's SSH_MSG_KEXINIT
// string K_S, server's public host key
// string Q_C, client's ephemeral public key octet string
// string Q_S, server's ephemeral public key octet string
// string K, shared secret
// draft-josefsson-ntruprime-ssh-02,
// 3. Key Exchange Method: sntrup761x25519-sha512
// ...
// The SSH_MSG_KEX_ECDH_REPLY's signature value is computed as described
// in [RFC5656] with the following changes. Instead of encoding the
// shared secret K as 'mpint', it MUST be encoded as 'string'. The
// shared secret K value MUST be the 64-byte output octet string of the
// SHA-512 hash computed with the input as the 32-byte octet string key
// output from the key encapsulation mechanism of sntrup761 concatenated
// with the 32-byte octet string of X25519(a, X25519(b, 9)) = X25519(b,
// X25519(a, 9)).
buf.reset();
buf.putString(V_C);
buf.putString(V_S);
buf.putString(I_C);
buf.putString(I_S);
buf.putString(K_S);
buf.putString(Q_C);
buf.putString(Q_S);
byte[] foo = new byte[buf.getLength()];
buf.getByte(foo);
sha.update(foo, 0, foo.length);
sha.update(K, 0, K.length);
H = sha.digest();
i = 0;
j = 0;
j = ((K_S[i++] << 24) & 0xff000000) | ((K_S[i++] << 16) & 0x00ff0000)
| ((K_S[i++] << 8) & 0x0000ff00) | ((K_S[i++]) & 0x000000ff);
String alg = Util.byte2str(K_S, i, j);
i += j;
boolean result = verify(alg, K_S, i, sig_of_H);
state = STATE_END;
return result;
}
return false;
}
@Override
public int getState() {
return state;
}
}

@ -0,0 +1,37 @@
/*
* Copyright (c) 2015-2018 ymnk, JCraft,Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted
* provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions
* and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other materials provided with
* the distribution.
*
* 3. The names of the authors may not be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL JCRAFT, INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.jcraft.jsch;
public interface ECDH {
void init(int size) throws Exception;
byte[] getSecret(byte[] r, byte[] s) throws Exception;
byte[] getQ() throws Exception;
boolean validate(byte[] r, byte[] s) throws Exception;
}

@ -0,0 +1,36 @@
/*
* Copyright (c) 2002-2018 ymnk, JCraft,Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted
* provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions
* and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other materials provided with
* the distribution.
*
* 3. The names of the authors may not be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL JCRAFT, INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.jcraft.jsch;
import java.io.InputStream;
import java.io.OutputStream;
public interface ForwardedTCPIPDaemon extends Runnable {
void setChannel(ChannelForwardedTCPIP channel, InputStream in, OutputStream out);
void setArg(Object[] arg);
}

@ -0,0 +1,39 @@
/*
* Copyright (c) 2004-2018 ymnk, JCraft,Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted
* provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions
* and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other materials provided with
* the distribution.
*
* 3. The names of the authors may not be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL JCRAFT, INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.jcraft.jsch;
public interface GSSContext {
public void create(String user, String host) throws JSchException;
public boolean isEstablished();
public byte[] init(byte[] token, int s, int l) throws JSchException;
public byte[] getMIC(byte[] message, int s, int l);
public void dispose();
}

@ -0,0 +1,41 @@
/*
* Copyright (c) 2002-2018 ymnk, JCraft,Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted
* provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions
* and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other materials provided with
* the distribution.
*
* 3. The names of the authors may not be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL JCRAFT, INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.jcraft.jsch;
public interface HASH {
void init() throws Exception;
int getBlockSize();
void update(byte[] foo, int start, int len) throws Exception;
byte[] digest() throws Exception;
default String name() {
return "";
}
}

@ -0,0 +1,167 @@
/*
* Copyright (c) 2002-2018 ymnk, JCraft,Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted
* provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions
* and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other materials provided with
* the distribution.
*
* 3. The names of the authors may not be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL JCRAFT, INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.jcraft.jsch;
import java.util.Locale;
public class HostKey {
private static final byte[][] names =
{Util.str2byte("ssh-dss"), Util.str2byte("ssh-rsa"), Util.str2byte("ecdsa-sha2-nistp256"),
Util.str2byte("ecdsa-sha2-nistp384"), Util.str2byte("ecdsa-sha2-nistp521"),
Util.str2byte("ssh-ed25519"), Util.str2byte("ssh-ed448")};
public static final int UNKNOWN = -1;
public static final int GUESS = 0;
public static final int SSHDSS = 1;
public static final int SSHRSA = 2;
public static final int ECDSA256 = 3;
public static final int ECDSA384 = 4;
public static final int ECDSA521 = 5;
public static final int ED25519 = 6;
public static final int ED448 = 7;
protected String marker;
protected String host;
protected int type;
protected byte[] key;
protected String comment;
public HostKey(String host, byte[] key) throws JSchException {
this(host, GUESS, key);
}
public HostKey(String host, int type, byte[] key) throws JSchException {
this(host, type, key, null);
}
public HostKey(String host, int type, byte[] key, String comment) throws JSchException {
this("", host, type, key, comment);
}
public HostKey(String marker, String host, int type, byte[] key, String comment)
throws JSchException {
this.marker = marker;
this.host = host;
if (type == GUESS) {
if (key[8] == 'd') {
this.type = SSHDSS;
} else if (key[8] == 'r') {
this.type = SSHRSA;
} else if (key[8] == 'e' && key[10] == '2') {
this.type = ED25519;
} else if (key[8] == 'e' && key[10] == '4') {
this.type = ED448;
} else if (key[8] == 'a' && key[20] == '2') {
this.type = ECDSA256;
} else if (key[8] == 'a' && key[20] == '3') {
this.type = ECDSA384;
} else if (key[8] == 'a' && key[20] == '5') {
this.type = ECDSA521;
} else {
throw new JSchException("invalid key type");
}
} else {
this.type = type;
}
this.key = key;
this.comment = comment;
}
public String getHost() {
return host;
}
public String getType() {
if (type == SSHDSS || type == SSHRSA || type == ED25519 || type == ED448 || type == ECDSA256
|| type == ECDSA384 || type == ECDSA521) {
return Util.byte2str(names[type - 1]);
}
return "UNKNOWN";
}
protected static int name2type(String name) {
for (int i = 0; i < names.length; i++) {
if (Util.byte2str(names[i]).equals(name)) {
return i + 1;
}
}
return UNKNOWN;
}
public String getKey() {
return Util.byte2str(Util.toBase64(key, 0, key.length, true));
}
public String getFingerPrint(JSch jsch) {
HASH hash = null;
try {
String _c = JSch.getConfig("FingerprintHash").toLowerCase(Locale.ROOT);
Class<? extends HASH> c = Class.forName(JSch.getConfig(_c)).asSubclass(HASH.class);
hash = c.getDeclaredConstructor().newInstance();
} catch (Exception e) {
if (jsch.getInstanceLogger().isEnabled(Logger.ERROR)) {
jsch.getInstanceLogger().log(Logger.ERROR, "getFingerPrint: " + e.getMessage(), e);
}
}
return Util.getFingerPrint(hash, key, false, true);
}
public String getComment() {
return comment;
}
public String getMarker() {
return marker;
}
boolean isMatched(String _host) {
return isIncluded(_host);
}
private boolean isIncluded(String _host) {
int i = 0;
String hosts = this.host;
int hostslen = hosts.length();
int hostlen = _host.length();
int j;
while (i < hostslen) {
j = hosts.indexOf(',', i);
if (j == -1) {
if (hostlen != hostslen - i)
return false;
return hosts.regionMatches(true, i, _host, 0, hostlen);
}
if (hostlen == (j - i)) {
if (hosts.regionMatches(true, i, _host, 0, hostlen))
return true;
}
i = j + 1;
}
return false;
}
}

@ -0,0 +1,89 @@
/*
* Copyright (c) 2004-2018 ymnk, JCraft,Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted
* provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions
* and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other materials provided with
* the distribution.
*
* 3. The names of the authors may not be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL JCRAFT, INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.jcraft.jsch;
public interface HostKeyRepository {
final int OK = 0;
final int NOT_INCLUDED = 1;
final int CHANGED = 2;
/**
* Checks if <code>host</code> is included with the <code>key</code>.
*
* @return #NOT_INCLUDED, #OK or #CHANGED
* @see #NOT_INCLUDED
* @see #OK
* @see #CHANGED
*/
int check(String host, byte[] key);
/**
* Adds a host key <code>hostkey</code>
*
* @param hostkey a host key to be added
* @param ui a user interface for showing messages or promping inputs.
* @see UserInfo
*/
void add(HostKey hostkey, UserInfo ui);
/**
* Removes a host key if there exists mached key with <code>host</code>, <code>type</code>.
*
* @see #remove(String host, String type, byte[] key)
*/
void remove(String host, String type);
/**
* Removes a host key if there exists a matched key with <code>host</code>, <code>type</code> and
* <code>key</code>.
*/
void remove(String host, String type, byte[] key);
/**
* Returns id of this repository.
*
* @return identity in String
*/
String getKnownHostsRepositoryID();
/**
* Retuns a list for host keys managed in this repository.
*
* @see #getHostKey(String host, String type)
*/
HostKey[] getHostKey();
/**
* Retuns a list for host keys managed in this repository.
*
* @param host a hostname used in searching host keys. If <code>null</code> is given, every host
* key will be listed.
* @param type a key type used in searching host keys, and it should be "ssh-dss" or "ssh-rsa". If
* <code>null</code> is given, a key type type will not be ignored.
*/
HostKey[] getHostKey(String host, String type);
}

@ -0,0 +1,136 @@
/*
* Copyright (c) 2002-2018 ymnk, JCraft,Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted
* provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions
* and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other materials provided with
* the distribution.
*
* 3. The names of the authors may not be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL JCRAFT, INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.jcraft.jsch;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.SocketException;
class IO {
InputStream in;
OutputStream out;
OutputStream out_ext;
private boolean in_dontclose = false;
private boolean out_dontclose = false;
private boolean out_ext_dontclose = false;
void setOutputStream(OutputStream out) {
this.out = out;
}
void setOutputStream(OutputStream out, boolean dontclose) {
this.out_dontclose = dontclose;
setOutputStream(out);
}
void setExtOutputStream(OutputStream out) {
this.out_ext = out;
}
void setExtOutputStream(OutputStream out, boolean dontclose) {
this.out_ext_dontclose = dontclose;
setExtOutputStream(out);
}
void setInputStream(InputStream in) {
this.in = in;
}
void setInputStream(InputStream in, boolean dontclose) {
this.in_dontclose = dontclose;
setInputStream(in);
}
void put(Packet p) throws IOException, SocketException {
out.write(p.buffer.buffer, 0, p.buffer.index);
out.flush();
}
void put(byte[] array, int begin, int length) throws IOException {
out.write(array, begin, length);
out.flush();
}
void put_ext(byte[] array, int begin, int length) throws IOException {
out_ext.write(array, begin, length);
out_ext.flush();
}
int getByte() throws IOException {
return in.read();
}
void getByte(byte[] array) throws IOException {
getByte(array, 0, array.length);
}
void getByte(byte[] array, int begin, int length) throws IOException {
do {
int completed = in.read(array, begin, length);
if (completed < 0) {
throw new IOException("End of IO Stream Read");
}
begin += completed;
length -= completed;
} while (length > 0);
}
void out_close() {
try {
if (out != null && !out_dontclose)
out.close();
out = null;
} catch (Exception ee) {
}
}
void close() {
try {
if (in != null && !in_dontclose)
in.close();
in = null;
} catch (Exception ee) {
}
out_close();
try {
if (out_ext != null && !out_ext_dontclose)
out_ext.close();
out_ext = null;
} catch (Exception ee) {
}
}
/*
* void finalize() throws Throwable{ try{ if(in!=null) in.close(); } catch(Exception ee){} try{
* if(out!=null) out.close(); } catch(Exception ee){} try{ if(out_ext!=null) out_ext.close(); }
* catch(Exception ee){} }
*/
}

@ -0,0 +1,122 @@
/*
* Copyright (c) 2002-2018 ymnk, JCraft,Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted
* provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions
* and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other materials provided with
* the distribution.
*
* 3. The names of the authors may not be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL JCRAFT, INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.jcraft.jsch;
public interface Identity {
/**
* Decrypts this identity with the specified pass-phrase.
*
* @param passphrase the pass-phrase for this identity.
* @return <code>true</code> if the decryption is succeeded or this identity is not cyphered.
*/
public boolean setPassphrase(byte[] passphrase) throws JSchException;
/**
* Returns the public-key blob.
*
* @return the public-key blob
*/
public byte[] getPublicKeyBlob();
/**
* Signs on data with this identity, and returns the result.
*
* <p>
* <em>IMPORTANT NOTE:</em> <br>
* The {@link #getSignature(byte[], String)} method should be overridden to ensure {@code ssh-rsa}
* type public keys function with the {@code rsa-sha2-256} or {@code rsa-sha2-512} signature
* algorithms.
*
* @param data data to be signed
* @return the signature
* @see #getSignature(byte[], String)
*/
public byte[] getSignature(byte[] data);
/**
* Signs on data with this identity, and returns the result.
*
* <p>
* <em>IMPORTANT NOTE:</em> <br>
* The default implementation of this method simply calls {@link #getSignature(byte[])}, which
* will fail with {@code ssh-rsa} type public keys when utilized with the {@code rsa-sha2-256} or
* {@code rsa-sha2-512} signature algorithms: <br>
* it exists only to maintain backwards compatibility of this interface.
*
* <p>
* This default method should be overridden by implementations to ensure the {@code rsa-sha2-256}
* and {@code rsa-sha2-512} signature algorithms function correctly.
*
* @param data data to be signed
* @param alg signature algorithm to use
* @return the signature
* @since 0.1.57
* @see #getSignature(byte[])
*/
public default byte[] getSignature(byte[] data, String alg) {
return getSignature(data);
}
/**
* This method is deprecated and the default implmentation of this method will throw an
* {@link UnsupportedOperationException}.
*
* @deprecated The decryption should be done automatically in {@link #setPassphrase(byte[])}
* @return <code>true</code> if the decryption is succeeded or this identity is not cyphered.
* @see #setPassphrase(byte[])
*/
@Deprecated
public default boolean decrypt() {
throw new UnsupportedOperationException("not implemented");
}
/**
* Returns the name of the key algorithm.
*
* @return the name of the key algorithm
*/
public String getAlgName();
/**
* Returns the name of this identity. It will be useful to identify this object in the
* {@link IdentityRepository}.
*
* @return the name of this identity
*/
public String getName();
/**
* Returns <code>true</code> if this identity is cyphered.
*
* @return <code>true</code> if this identity is cyphered.
*/
public boolean isEncrypted();
/** Disposes internally allocated data, like byte array for the private key. */
public void clear();
}

@ -0,0 +1,141 @@
/*
* Copyright (c) 2002-2018 ymnk, JCraft,Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted
* provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions
* and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other materials provided with
* the distribution.
*
* 3. The names of the authors may not be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL JCRAFT, INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.jcraft.jsch;
class IdentityFile implements Identity {
private KeyPair kpair;
private String identity;
static IdentityFile newInstance(String prvfile, String pubfile, JSch.InstanceLogger instLogger)
throws JSchException {
KeyPair kpair = KeyPair.load(instLogger, prvfile, pubfile);
return new IdentityFile(prvfile, kpair);
}
static IdentityFile newInstance(String name, byte[] prvkey, byte[] pubkey,
JSch.InstanceLogger instLogger) throws JSchException {
KeyPair kpair = KeyPair.load(instLogger, prvkey, pubkey);
return new IdentityFile(name, kpair);
}
private IdentityFile(String name, KeyPair kpair) {
this.identity = name;
this.kpair = kpair;
}
/**
* Decrypts this identity with the specified pass-phrase.
*
* @param passphrase the pass-phrase for this identity.
* @return <code>true</code> if the decryption is succeeded or this identity is not cyphered.
*/
@Override
public boolean setPassphrase(byte[] passphrase) throws JSchException {
return kpair.decrypt(passphrase);
}
/**
* Returns the public-key blob.
*
* @return the public-key blob
*/
@Override
public byte[] getPublicKeyBlob() {
return kpair.getPublicKeyBlob();
}
/**
* Signs on data with this identity, and returns the result.
*
* @param data data to be signed
* @return the signature
*/
@Override
public byte[] getSignature(byte[] data) {
return kpair.getSignature(data);
}
/**
* Signs on data with this identity, and returns the result.
*
* @param data data to be signed
* @param alg signature algorithm to use
* @return the signature
*/
@Override
public byte[] getSignature(byte[] data, String alg) {
return kpair.getSignature(data, alg);
}
/**
* Returns the name of the key algorithm.
*
* @return the name of the key algorithm
*/
@Override
public String getAlgName() {
return kpair.getKeyTypeString();
}
/**
* Returns the name of this identity. It will be useful to identify this object in the
* {@link IdentityRepository}.
*
* @return the name of this identity
*/
@Override
public String getName() {
return identity;
}
/**
* Returns <code>true</code> if this identity is cyphered.
*
* @return <code>true</code> if this identity is cyphered.
*/
@Override
public boolean isEncrypted() {
return kpair.isEncrypted();
}
/** Disposes internally allocated data, like byte array for the private key. */
@Override
public void clear() {
kpair.dispose();
kpair = null;
}
/**
* Returns an instance of {@link KeyPair} used in this {@link Identity}.
*
* @return an instance of {@link KeyPair} used in this {@link Identity}.
*/
public KeyPair getKeyPair() {
return kpair;
}
}

@ -0,0 +1,47 @@
/*
* Copyright (c) 2012-2018 ymnk, JCraft,Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted
* provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions
* and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other materials provided with
* the distribution.
*
* 3. The names of the authors may not be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL JCRAFT, INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.jcraft.jsch;
import java.util.Vector;
public interface IdentityRepository {
public static final int UNAVAILABLE = 0;
public static final int NOTRUNNING = 1;
public static final int RUNNING = 2;
public String getName();
public int getStatus();
public Vector<Identity> getIdentities();
public boolean add(byte[] identity);
public boolean remove(byte[] blob);
public void removeAll();
}

@ -0,0 +1,111 @@
/*
* Copyright (c) 2012-2018 ymnk, JCraft,Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted
* provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions
* and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other materials provided with
* the distribution.
*
* 3. The names of the authors may not be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL JCRAFT, INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.jcraft.jsch;
import java.util.Vector;
/**
* JSch will accept ciphered keys, but some implementations of IdentityRepository can not. For
* example, IdentityRepository for ssh-agent and pageant only accept plain keys. The following class
* has been introduced to cache ciphered keys for them, and pass them whenever they are de-ciphered.
*/
class IdentityRepositoryWrapper implements IdentityRepository {
private IdentityRepository ir;
private Vector<Identity> cache = new Vector<>();
private boolean keep_in_cache = false;
IdentityRepositoryWrapper(IdentityRepository ir) {
this(ir, false);
}
IdentityRepositoryWrapper(IdentityRepository ir, boolean keep_in_cache) {
this.ir = ir;
this.keep_in_cache = keep_in_cache;
}
@Override
public String getName() {
return ir.getName();
}
@Override
public int getStatus() {
return ir.getStatus();
}
@Override
public boolean add(byte[] identity) {
return ir.add(identity);
}
@Override
public boolean remove(byte[] blob) {
return ir.remove(blob);
}
@Override
public void removeAll() {
cache.removeAllElements();
ir.removeAll();
}
@Override
public Vector<Identity> getIdentities() {
Vector<Identity> result = new Vector<>();
for (int i = 0; i < cache.size(); i++) {
Identity identity = cache.elementAt(i);
result.add(identity);
}
Vector<Identity> tmp = ir.getIdentities();
for (int i = 0; i < tmp.size(); i++) {
result.add(tmp.elementAt(i));
}
return result;
}
void add(Identity identity) {
if (!keep_in_cache && !identity.isEncrypted() && (identity instanceof IdentityFile)) {
try {
ir.add(((IdentityFile) identity).getKeyPair().forSSHAgent());
} catch (JSchException e) {
// an exception will not be thrown.
}
} else
cache.addElement(identity);
}
void check() {
if (cache.size() > 0) {
Object[] identities = cache.toArray();
for (int i = 0; i < identities.length; i++) {
Identity identity = (Identity) (identities[i]);
cache.removeElement(identity);
add(identity);
}
}
}
}

@ -0,0 +1,694 @@
/*
* Copyright (c) 2002-2018 ymnk, JCraft,Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted
* provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions
* and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other materials provided with
* the distribution.
*
* 3. The names of the authors may not be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL JCRAFT, INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.jcraft.jsch;
import java.io.InputStream;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Vector;
public class JSch {
/** The version number. */
public static final String VERSION = Version.getVersion();
static Hashtable<String, String> config = new Hashtable<>();
static {
config.put("kex", Util.getSystemProperty("jsch.kex",
"curve25519-sha256,curve25519-sha256@libssh.org,ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hellman-group16-sha512,diffie-hellman-group18-sha512,diffie-hellman-group14-sha256"));
config.put("server_host_key", Util.getSystemProperty("jsch.server_host_key",
"ssh-ed25519,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521,rsa-sha2-512,rsa-sha2-256"));
config.put("prefer_known_host_key_types",
Util.getSystemProperty("jsch.prefer_known_host_key_types", "yes"));
config.put("enable_strict_kex", Util.getSystemProperty("jsch.enable_strict_kex", "yes"));
config.put("require_strict_kex", Util.getSystemProperty("jsch.require_strict_kex", "no"));
config.put("enable_server_sig_algs",
Util.getSystemProperty("jsch.enable_server_sig_algs", "yes"));
config.put("enable_ext_info_in_auth",
Util.getSystemProperty("jsch.enable_ext_info_in_auth", "yes"));
config.put("cipher.s2c", Util.getSystemProperty("jsch.cipher",
"aes128-ctr,aes192-ctr,aes256-ctr,aes128-gcm@openssh.com,aes256-gcm@openssh.com"));
config.put("cipher.c2s", Util.getSystemProperty("jsch.cipher",
"aes128-ctr,aes192-ctr,aes256-ctr,aes128-gcm@openssh.com,aes256-gcm@openssh.com"));
config.put("mac.s2c", Util.getSystemProperty("jsch.mac",
"hmac-sha2-256-etm@openssh.com,hmac-sha2-512-etm@openssh.com,hmac-sha1-etm@openssh.com,hmac-sha2-256,hmac-sha2-512,hmac-sha1"));
config.put("mac.c2s", Util.getSystemProperty("jsch.mac",
"hmac-sha2-256-etm@openssh.com,hmac-sha2-512-etm@openssh.com,hmac-sha1-etm@openssh.com,hmac-sha2-256,hmac-sha2-512,hmac-sha1"));
config.put("compression.s2c", Util.getSystemProperty("jsch.compression", "none"));
config.put("compression.c2s", Util.getSystemProperty("jsch.compression", "none"));
config.put("lang.s2c", Util.getSystemProperty("jsch.lang", ""));
config.put("lang.c2s", Util.getSystemProperty("jsch.lang", ""));
config.put("dhgex_min", Util.getSystemProperty("jsch.dhgex_min", "2048"));
config.put("dhgex_max", Util.getSystemProperty("jsch.dhgex_max", "8192"));
config.put("dhgex_preferred", Util.getSystemProperty("jsch.dhgex_preferred", "3072"));
config.put("compression_level", Util.getSystemProperty("jsch.compression_level", "6"));
config.put("diffie-hellman-group-exchange-sha1", "com.jcraft.jsch.DHGEX1");
config.put("diffie-hellman-group1-sha1", "com.jcraft.jsch.DHG1");
config.put("diffie-hellman-group14-sha1", "com.jcraft.jsch.DHG14");
config.put("diffie-hellman-group-exchange-sha256", "com.jcraft.jsch.DHGEX256");
config.put("diffie-hellman-group-exchange-sha224@ssh.com", "com.jcraft.jsch.DHGEX224");
config.put("diffie-hellman-group-exchange-sha384@ssh.com", "com.jcraft.jsch.DHGEX384");
config.put("diffie-hellman-group-exchange-sha512@ssh.com", "com.jcraft.jsch.DHGEX512");
config.put("diffie-hellman-group14-sha256", "com.jcraft.jsch.DHG14256");
config.put("diffie-hellman-group15-sha512", "com.jcraft.jsch.DHG15");
config.put("diffie-hellman-group16-sha512", "com.jcraft.jsch.DHG16");
config.put("diffie-hellman-group17-sha512", "com.jcraft.jsch.DHG17");
config.put("diffie-hellman-group18-sha512", "com.jcraft.jsch.DHG18");
config.put("diffie-hellman-group14-sha256@ssh.com", "com.jcraft.jsch.DHG14256");
config.put("diffie-hellman-group14-sha224@ssh.com", "com.jcraft.jsch.DHG14224");
config.put("diffie-hellman-group15-sha256@ssh.com", "com.jcraft.jsch.DHG15256");
config.put("diffie-hellman-group15-sha384@ssh.com", "com.jcraft.jsch.DHG15384");
config.put("diffie-hellman-group16-sha512@ssh.com", "com.jcraft.jsch.DHG16");
config.put("diffie-hellman-group16-sha384@ssh.com", "com.jcraft.jsch.DHG16384");
config.put("diffie-hellman-group18-sha512@ssh.com", "com.jcraft.jsch.DHG18");
config.put("ecdsa-sha2-nistp256", "com.jcraft.jsch.jce.SignatureECDSA256");
config.put("ecdsa-sha2-nistp384", "com.jcraft.jsch.jce.SignatureECDSA384");
config.put("ecdsa-sha2-nistp521", "com.jcraft.jsch.jce.SignatureECDSA521");
config.put("ecdh-sha2-nistp256", "com.jcraft.jsch.DHEC256");
config.put("ecdh-sha2-nistp384", "com.jcraft.jsch.DHEC384");
config.put("ecdh-sha2-nistp521", "com.jcraft.jsch.DHEC521");
config.put("ecdh-sha2-nistp", "com.jcraft.jsch.jce.ECDHN");
config.put("curve25519-sha256", "com.jcraft.jsch.DH25519");
config.put("curve25519-sha256@libssh.org", "com.jcraft.jsch.DH25519");
config.put("curve448-sha512", "com.jcraft.jsch.DH448");
config.put("sntrup761x25519-sha512@openssh.com", "com.jcraft.jsch.DH25519SNTRUP761");
config.put("sntrup761", "com.jcraft.jsch.bc.SNTRUP761");
config.put("dh", "com.jcraft.jsch.jce.DH");
config.put("3des-cbc", "com.jcraft.jsch.jce.TripleDESCBC");
config.put("blowfish-cbc", "com.jcraft.jsch.jce.BlowfishCBC");
config.put("hmac-sha1", "com.jcraft.jsch.jce.HMACSHA1");
config.put("hmac-sha1-96", "com.jcraft.jsch.jce.HMACSHA196");
config.put("hmac-sha2-256", "com.jcraft.jsch.jce.HMACSHA256");
config.put("hmac-sha2-512", "com.jcraft.jsch.jce.HMACSHA512");
config.put("hmac-md5", "com.jcraft.jsch.jce.HMACMD5");
config.put("hmac-md5-96", "com.jcraft.jsch.jce.HMACMD596");
config.put("hmac-sha1-etm@openssh.com", "com.jcraft.jsch.jce.HMACSHA1ETM");
config.put("hmac-sha1-96-etm@openssh.com", "com.jcraft.jsch.jce.HMACSHA196ETM");
config.put("hmac-sha2-256-etm@openssh.com", "com.jcraft.jsch.jce.HMACSHA256ETM");
config.put("hmac-sha2-512-etm@openssh.com", "com.jcraft.jsch.jce.HMACSHA512ETM");
config.put("hmac-md5-etm@openssh.com", "com.jcraft.jsch.jce.HMACMD5ETM");
config.put("hmac-md5-96-etm@openssh.com", "com.jcraft.jsch.jce.HMACMD596ETM");
config.put("hmac-sha256-2@ssh.com", "com.jcraft.jsch.jce.HMACSHA2562SSHCOM");
config.put("hmac-sha224@ssh.com", "com.jcraft.jsch.jce.HMACSHA224SSHCOM");
config.put("hmac-sha256@ssh.com", "com.jcraft.jsch.jce.HMACSHA256SSHCOM");
config.put("hmac-sha384@ssh.com", "com.jcraft.jsch.jce.HMACSHA384SSHCOM");
config.put("hmac-sha512@ssh.com", "com.jcraft.jsch.jce.HMACSHA512SSHCOM");
config.put("sha-1", "com.jcraft.jsch.jce.SHA1");
config.put("sha-224", "com.jcraft.jsch.jce.SHA224");
config.put("sha-256", "com.jcraft.jsch.jce.SHA256");
config.put("sha-384", "com.jcraft.jsch.jce.SHA384");
config.put("sha-512", "com.jcraft.jsch.jce.SHA512");
config.put("md5", "com.jcraft.jsch.jce.MD5");
config.put("sha1", "com.jcraft.jsch.jce.SHA1");
config.put("sha224", "com.jcraft.jsch.jce.SHA224");
config.put("sha256", "com.jcraft.jsch.jce.SHA256");
config.put("sha384", "com.jcraft.jsch.jce.SHA384");
config.put("sha512", "com.jcraft.jsch.jce.SHA512");
config.put("signature.dss", "com.jcraft.jsch.jce.SignatureDSA");
config.put("ssh-rsa", "com.jcraft.jsch.jce.SignatureRSA");
config.put("rsa-sha2-256", "com.jcraft.jsch.jce.SignatureRSASHA256");
config.put("rsa-sha2-512", "com.jcraft.jsch.jce.SignatureRSASHA512");
config.put("ssh-rsa-sha224@ssh.com", "com.jcraft.jsch.jce.SignatureRSASHA224SSHCOM");
config.put("ssh-rsa-sha256@ssh.com", "com.jcraft.jsch.jce.SignatureRSASHA256SSHCOM");
config.put("ssh-rsa-sha384@ssh.com", "com.jcraft.jsch.jce.SignatureRSASHA384SSHCOM");
config.put("ssh-rsa-sha512@ssh.com", "com.jcraft.jsch.jce.SignatureRSASHA512SSHCOM");
config.put("keypairgen.dsa", "com.jcraft.jsch.jce.KeyPairGenDSA");
config.put("keypairgen.rsa", "com.jcraft.jsch.jce.KeyPairGenRSA");
config.put("keypairgen.ecdsa", "com.jcraft.jsch.jce.KeyPairGenECDSA");
config.put("random", "com.jcraft.jsch.jce.Random");
config.put("hmac-ripemd160", "com.jcraft.jsch.bc.HMACRIPEMD160");
config.put("hmac-ripemd160@openssh.com", "com.jcraft.jsch.bc.HMACRIPEMD160OpenSSH");
config.put("hmac-ripemd160-etm@openssh.com", "com.jcraft.jsch.bc.HMACRIPEMD160ETM");
config.put("none", "com.jcraft.jsch.CipherNone");
config.put("aes128-gcm@openssh.com", "com.jcraft.jsch.jce.AES128GCM");
config.put("aes256-gcm@openssh.com", "com.jcraft.jsch.jce.AES256GCM");
config.put("aes128-cbc", "com.jcraft.jsch.jce.AES128CBC");
config.put("aes192-cbc", "com.jcraft.jsch.jce.AES192CBC");
config.put("aes256-cbc", "com.jcraft.jsch.jce.AES256CBC");
config.put("rijndael-cbc@lysator.liu.se", "com.jcraft.jsch.jce.AES256CBC");
config.put("chacha20-poly1305@openssh.com", "com.jcraft.jsch.bc.ChaCha20Poly1305");
config.put("cast128-cbc", "com.jcraft.jsch.bc.CAST128CBC");
config.put("cast128-ctr", "com.jcraft.jsch.bc.CAST128CTR");
config.put("twofish128-cbc", "com.jcraft.jsch.bc.Twofish128CBC");
config.put("twofish192-cbc", "com.jcraft.jsch.bc.Twofish192CBC");
config.put("twofish256-cbc", "com.jcraft.jsch.bc.Twofish256CBC");
config.put("twofish-cbc", "com.jcraft.jsch.bc.Twofish256CBC");
config.put("twofish128-ctr", "com.jcraft.jsch.bc.Twofish128CTR");
config.put("twofish192-ctr", "com.jcraft.jsch.bc.Twofish192CTR");
config.put("twofish256-ctr", "com.jcraft.jsch.bc.Twofish256CTR");
config.put("seed-cbc@ssh.com", "com.jcraft.jsch.bc.SEEDCBC");
config.put("aes128-ctr", "com.jcraft.jsch.jce.AES128CTR");
config.put("aes192-ctr", "com.jcraft.jsch.jce.AES192CTR");
config.put("aes256-ctr", "com.jcraft.jsch.jce.AES256CTR");
config.put("3des-ctr", "com.jcraft.jsch.jce.TripleDESCTR");
config.put("blowfish-ctr", "com.jcraft.jsch.jce.BlowfishCTR");
config.put("arcfour", "com.jcraft.jsch.jce.ARCFOUR");
config.put("arcfour128", "com.jcraft.jsch.jce.ARCFOUR128");
config.put("arcfour256", "com.jcraft.jsch.jce.ARCFOUR256");
config.put("userauth.none", "com.jcraft.jsch.UserAuthNone");
config.put("userauth.password", "com.jcraft.jsch.UserAuthPassword");
config.put("userauth.keyboard-interactive", "com.jcraft.jsch.UserAuthKeyboardInteractive");
config.put("userauth.publickey", "com.jcraft.jsch.UserAuthPublicKey");
config.put("userauth.gssapi-with-mic", "com.jcraft.jsch.UserAuthGSSAPIWithMIC");
config.put("gssapi-with-mic.krb5", "com.jcraft.jsch.jgss.GSSContextKrb5");
config.put("zlib", "com.jcraft.jsch.jzlib.Compression");
config.put("zlib@openssh.com", "com.jcraft.jsch.jzlib.Compression");
config.put("pbkdf", "com.jcraft.jsch.jce.PBKDF");
config.put("pbkdf2-hmac-sha1", "com.jcraft.jsch.jce.PBKDF2HMACSHA1");
config.put("pbkdf2-hmac-sha224", "com.jcraft.jsch.jce.PBKDF2HMACSHA224");
config.put("pbkdf2-hmac-sha256", "com.jcraft.jsch.jce.PBKDF2HMACSHA256");
config.put("pbkdf2-hmac-sha384", "com.jcraft.jsch.jce.PBKDF2HMACSHA384");
config.put("pbkdf2-hmac-sha512", "com.jcraft.jsch.jce.PBKDF2HMACSHA512");
config.put("pbkdf2-hmac-sha512-224", "com.jcraft.jsch.jce.PBKDF2HMACSHA512224");
config.put("pbkdf2-hmac-sha512-256", "com.jcraft.jsch.jce.PBKDF2HMACSHA512256");
config.put("bcrypt", "com.jcraft.jsch.jbcrypt.JBCrypt");
config.put("argon2", "com.jcraft.jsch.bc.Argon2");
config.put("scrypt", "com.jcraft.jsch.bc.SCrypt");
if (JavaVersion.getVersion() >= 11) {
config.put("xdh", "com.jcraft.jsch.jce.XDH");
} else {
config.put("xdh", "com.jcraft.jsch.bc.XDH");
}
if (JavaVersion.getVersion() >= 15) {
config.put("keypairgen.eddsa", "com.jcraft.jsch.jce.KeyPairGenEdDSA");
config.put("ssh-ed25519", "com.jcraft.jsch.jce.SignatureEd25519");
config.put("ssh-ed448", "com.jcraft.jsch.jce.SignatureEd448");
} else {
config.put("keypairgen.eddsa", "com.jcraft.jsch.bc.KeyPairGenEdDSA");
config.put("ssh-ed25519", "com.jcraft.jsch.bc.SignatureEd25519");
config.put("ssh-ed448", "com.jcraft.jsch.bc.SignatureEd448");
}
config.put("keypairgen_fromprivate.eddsa", "com.jcraft.jsch.bc.KeyPairGenEdDSA");
config.put("StrictHostKeyChecking", "ask");
config.put("HashKnownHosts", "no");
config.put("PreferredAuthentications", Util.getSystemProperty("jsch.preferred_authentications",
"gssapi-with-mic,publickey,keyboard-interactive,password"));
config.put("PubkeyAcceptedAlgorithms", Util.getSystemProperty("jsch.client_pubkey",
"ssh-ed25519,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521,rsa-sha2-512,rsa-sha2-256"));
config.put("enable_pubkey_auth_query",
Util.getSystemProperty("jsch.enable_pubkey_auth_query", "yes"));
config.put("try_additional_pubkey_algorithms",
Util.getSystemProperty("jsch.try_additional_pubkey_algorithms", "yes"));
config.put("enable_auth_none", Util.getSystemProperty("jsch.enable_auth_none", "yes"));
config.put("use_sftp_write_flush_workaround",
Util.getSystemProperty("jsch.use_sftp_write_flush_workaround", "yes"));
config.put("CheckCiphers",
Util.getSystemProperty("jsch.check_ciphers", "chacha20-poly1305@openssh.com"));
config.put("CheckMacs", Util.getSystemProperty("jsch.check_macs", ""));
config.put("CheckKexes", Util.getSystemProperty("jsch.check_kexes",
"sntrup761x25519-sha512@openssh.com,curve25519-sha256,curve25519-sha256@libssh.org,curve448-sha512"));
config.put("CheckSignatures",
Util.getSystemProperty("jsch.check_signatures", "ssh-ed25519,ssh-ed448"));
config.put("FingerprintHash", Util.getSystemProperty("jsch.fingerprint_hash", "sha256"));
config.put("MaxAuthTries", Util.getSystemProperty("jsch.max_auth_tries", "6"));
config.put("ClearAllForwardings", "no");
}
final InstanceLogger instLogger = new InstanceLogger();
private Vector<Session> sessionPool = new Vector<>();
private IdentityRepository defaultIdentityRepository = new LocalIdentityRepository(instLogger);
private IdentityRepository identityRepository = defaultIdentityRepository;
private ConfigRepository configRepository = null;
/**
* Sets the <code>identityRepository</code>, which will be referred in the public key
* authentication.
*
* @param identityRepository if <code>null</code> is given, the default repository, which usually
* refers to ~/.ssh/, will be used.
* @see #getIdentityRepository()
*/
public synchronized void setIdentityRepository(IdentityRepository identityRepository) {
if (identityRepository == null) {
this.identityRepository = defaultIdentityRepository;
} else {
this.identityRepository = identityRepository;
}
}
public synchronized IdentityRepository getIdentityRepository() {
return this.identityRepository;
}
public ConfigRepository getConfigRepository() {
return this.configRepository;
}
public void setConfigRepository(ConfigRepository configRepository) {
this.configRepository = configRepository;
}
private HostKeyRepository known_hosts = null;
static final Logger DEVNULL = new Logger() {
@Override
public boolean isEnabled(int level) {
return false;
}
@Override
public void log(int level, String message) {}
};
static Logger logger = DEVNULL;
public JSch() {}
/**
* Instantiates the <code>Session</code> object with <code>host</code>. The user name and port
* number will be retrieved from ConfigRepository. If user name is not given, the system property
* "user.name" will be referred.
*
* @param host hostname
* @throws JSchException if <code>username</code> or <code>host</code> are invalid.
* @return the instance of <code>Session</code> class.
* @see #getSession(String username, String host, int port)
* @see Session
* @see ConfigRepository
*/
public Session getSession(String host) throws JSchException {
return getSession(null, host, 22);
}
/**
* Instantiates the <code>Session</code> object with <code>username</code> and <code>host</code>.
* The TCP port 22 will be used in making the connection. Note that the TCP connection must not be
* established until Session#connect().
*
* @param username user name
* @param host hostname
* @throws JSchException if <code>username</code> or <code>host</code> are invalid.
* @return the instance of <code>Session</code> class.
* @see #getSession(String username, String host, int port)
* @see Session
*/
public Session getSession(String username, String host) throws JSchException {
return getSession(username, host, 22);
}
/**
* Instantiates the <code>Session</code> object with given <code>username</code>,
* <code>host</code> and <code>port</code>. Note that the TCP connection must not be established
* until Session#connect().
*
* @param username user name
* @param host hostname
* @param port port number
* @throws JSchException if <code>username</code> or <code>host</code> are invalid.
* @return the instance of <code>Session</code> class.
* @see #getSession(String username, String host, int port)
* @see Session
*/
public Session getSession(String username, String host, int port) throws JSchException {
if (host == null) {
throw new JSchException("host must not be null.");
}
Session s = new Session(this, username, host, port);
return s;
}
protected void addSession(Session session) {
synchronized (sessionPool) {
sessionPool.addElement(session);
}
}
protected boolean removeSession(Session session) {
synchronized (sessionPool) {
return sessionPool.remove(session);
}
}
/**
* Sets the hostkey repository.
*
* @param hkrepo
* @see HostKeyRepository
* @see KnownHosts
*/
public void setHostKeyRepository(HostKeyRepository hkrepo) {
known_hosts = hkrepo;
}
/**
* Sets the instance of <code>KnownHosts</code>, which refers to <code>filename</code>.
*
* @param filename filename of known_hosts file.
* @throws JSchException if the given filename is invalid.
* @see KnownHosts
*/
public void setKnownHosts(String filename) throws JSchException {
if (known_hosts == null)
known_hosts = new KnownHosts(this);
if (known_hosts instanceof KnownHosts) {
synchronized (known_hosts) {
((KnownHosts) known_hosts).setKnownHosts(filename);
}
}
}
/**
* Sets the instance of <code>KnownHosts</code> generated with <code>stream</code>.
*
* @param stream the instance of InputStream from known_hosts file.
* @throws JSchException if an I/O error occurs.
* @see KnownHosts
*/
public void setKnownHosts(InputStream stream) throws JSchException {
if (known_hosts == null)
known_hosts = new KnownHosts(this);
if (known_hosts instanceof KnownHosts) {
synchronized (known_hosts) {
((KnownHosts) known_hosts).setKnownHosts(stream);
}
}
}
/**
* Returns the current hostkey repository. By the default, this method will the instance of
* <code>KnownHosts</code>.
*
* @return current hostkey repository.
* @see HostKeyRepository
* @see KnownHosts
*/
public HostKeyRepository getHostKeyRepository() {
if (known_hosts == null)
known_hosts = new KnownHosts(this);
return known_hosts;
}
/**
* Sets the private key, which will be referred in the public key authentication.
*
* @param prvkey filename of the private key.
* @throws JSchException if <code>prvkey</code> is invalid.
* @see #addIdentity(String prvkey, String passphrase)
*/
public void addIdentity(String prvkey) throws JSchException {
addIdentity(prvkey, (byte[]) null);
}
/**
* Sets the private key, which will be referred in the public key authentication. Before
* registering it into identityRepository, it will be deciphered with <code>passphrase</code>.
*
* @param prvkey filename of the private key.
* @param passphrase passphrase for <code>prvkey</code>.
* @throws JSchException if <code>passphrase</code> is not right.
* @see #addIdentity(String prvkey, byte[] passphrase)
*/
public void addIdentity(String prvkey, String passphrase) throws JSchException {
byte[] _passphrase = null;
if (passphrase != null) {
_passphrase = Util.str2byte(passphrase);
}
addIdentity(prvkey, _passphrase);
if (_passphrase != null)
Util.bzero(_passphrase);
}
/**
* Sets the private key, which will be referred in the public key authentication. Before
* registering it into identityRepository, it will be deciphered with <code>passphrase</code>.
*
* @param prvkey filename of the private key.
* @param passphrase passphrase for <code>prvkey</code>.
* @throws JSchException if <code>passphrase</code> is not right.
* @see #addIdentity(String prvkey, String pubkey, byte[] passphrase)
*/
public void addIdentity(String prvkey, byte[] passphrase) throws JSchException {
Identity identity = IdentityFile.newInstance(prvkey, null, instLogger);
addIdentity(identity, passphrase);
}
/**
* Sets the private key, which will be referred in the public key authentication. Before
* registering it into identityRepository, it will be deciphered with <code>passphrase</code>.
*
* @param prvkey filename of the private key.
* @param pubkey filename of the public key.
* @param passphrase passphrase for <code>prvkey</code>.
* @throws JSchException if <code>passphrase</code> is not right.
*/
public void addIdentity(String prvkey, String pubkey, byte[] passphrase) throws JSchException {
Identity identity = IdentityFile.newInstance(prvkey, pubkey, instLogger);
addIdentity(identity, passphrase);
}
/**
* Sets the private key, which will be referred in the public key authentication. Before
* registering it into identityRepository, it will be deciphered with <code>passphrase</code>.
*
* @param name name of the identity to be used to retrieve it in the identityRepository.
* @param prvkey private key in byte array.
* @param pubkey public key in byte array.
* @param passphrase passphrase for <code>prvkey</code>.
*/
public void addIdentity(String name, byte[] prvkey, byte[] pubkey, byte[] passphrase)
throws JSchException {
Identity identity = IdentityFile.newInstance(name, prvkey, pubkey, instLogger);
addIdentity(identity, passphrase);
}
/**
* Sets the private key, which will be referred in the public key authentication. Before
* registering it into identityRepository, it will be deciphered with <code>passphrase</code>.
*
* @param identity private key.
* @param passphrase passphrase for <code>identity</code>.
* @throws JSchException if <code>passphrase</code> is not right.
*/
public void addIdentity(Identity identity, byte[] passphrase) throws JSchException {
if (passphrase != null) {
try {
byte[] goo = new byte[passphrase.length];
System.arraycopy(passphrase, 0, goo, 0, passphrase.length);
passphrase = goo;
identity.setPassphrase(passphrase);
} finally {
Util.bzero(passphrase);
}
}
if (identityRepository instanceof LocalIdentityRepository) {
((LocalIdentityRepository) identityRepository).add(identity);
} else if (identity instanceof IdentityFile && !identity.isEncrypted()) {
identityRepository.add(((IdentityFile) identity).getKeyPair().forSSHAgent());
} else {
synchronized (this) {
if (!(identityRepository instanceof IdentityRepositoryWrapper)) {
setIdentityRepository(new IdentityRepositoryWrapper(identityRepository));
}
}
((IdentityRepositoryWrapper) identityRepository).add(identity);
}
}
/**
* @deprecated use #removeIdentity(Identity identity)
*/
@Deprecated
public void removeIdentity(String name) throws JSchException {
Vector<Identity> identities = identityRepository.getIdentities();
for (int i = 0; i < identities.size(); i++) {
Identity identity = identities.elementAt(i);
if (!identity.getName().equals(name))
continue;
if (identityRepository instanceof LocalIdentityRepository) {
((LocalIdentityRepository) identityRepository).remove(identity);
} else
identityRepository.remove(identity.getPublicKeyBlob());
}
}
/**
* Removes the identity from identityRepository.
*
* @param identity the indentity to be removed.
* @throws JSchException if <code>identity</code> is invalid.
*/
public void removeIdentity(Identity identity) throws JSchException {
identityRepository.remove(identity.getPublicKeyBlob());
}
/**
* Lists names of identities included in the identityRepository.
*
* @return names of identities
* @throws JSchException if identityReposory has problems.
*/
public Vector<String> getIdentityNames() throws JSchException {
Vector<String> foo = new Vector<>();
Vector<Identity> identities = identityRepository.getIdentities();
for (int i = 0; i < identities.size(); i++) {
Identity identity = identities.elementAt(i);
foo.addElement(identity.getName());
}
return foo;
}
/**
* Removes all identities from identityRepository.
*
* @throws JSchException if identityReposory has problems.
*/
public void removeAllIdentity() throws JSchException {
identityRepository.removeAll();
}
/**
* Returns the config value for the specified key.
*
* @param key key for the configuration.
* @return config value
*/
public static String getConfig(String key) {
synchronized (config) {
if (key.equals("PubkeyAcceptedKeyTypes")) {
key = "PubkeyAcceptedAlgorithms";
}
return config.get(key);
}
}
/**
* Sets or Overrides the configuration.
*
* @param newconf configurations
*/
public static void setConfig(Hashtable<String, String> newconf) {
synchronized (config) {
for (Enumeration<String> e = newconf.keys(); e.hasMoreElements();) {
String newkey = e.nextElement();
String key =
(newkey.equals("PubkeyAcceptedKeyTypes") ? "PubkeyAcceptedAlgorithms" : newkey);
config.put(key, newconf.get(newkey));
}
}
}
/**
* Sets or Overrides the configuration.
*
* @param key key for the configuration
* @param value value for the configuration
*/
public static void setConfig(String key, String value) {
if (key.equals("PubkeyAcceptedKeyTypes")) {
config.put("PubkeyAcceptedAlgorithms", value);
} else {
config.put(key, value);
}
}
/**
* Sets the logger
*
* @param logger logger or <code>null</code> if no logging should take place
* @see Logger
*/
public static void setLogger(Logger logger) {
if (logger == null)
logger = DEVNULL;
JSch.logger = logger;
}
/**
* Returns a logger to be used for this particular instance of JSch
*
* @return The logger that is used by this instance. If no particular logger has been set, the
* statically set logger is returned.
*/
public Logger getInstanceLogger() {
return instLogger.getLogger();
}
/**
* Sets a logger to be used for this particular instance of JSch
*
* @param logger The logger to be used or <code>null</code> if the statically set logger should be
* used
*/
public void setInstanceLogger(Logger logger) {
instLogger.setLogger(logger);
}
/**
* Returns the statically set logger, i.e. the logger being used by all JSch instances without
* explicitly set logger.
*
* @return The logger
*/
public static Logger getLogger() {
return logger;
}
static class InstanceLogger {
private Logger logger;
private InstanceLogger() {}
Logger getLogger() {
if (logger == null) {
return JSch.logger;
}
return logger;
}
void setLogger(Logger logger) {
this.logger = logger;
}
}
}

@ -0,0 +1,71 @@
package com.jcraft.jsch;
import java.util.Locale;
/**
* Extension of {@link JSchException} to indicate when a connection fails during algorithm
* negotiation.
*/
public class JSchAlgoNegoFailException extends JSchException {
private static final long serialVersionUID = -1L;
private final String algorithmName;
private final String jschProposal;
private final String serverProposal;
JSchAlgoNegoFailException(int algorithmIndex, String jschProposal, String serverProposal) {
super(failString(algorithmIndex, jschProposal, serverProposal));
algorithmName = algorithmNameFromIndex(algorithmIndex);
this.jschProposal = jschProposal;
this.serverProposal = serverProposal;
}
/** Get the algorithm name. */
public String getAlgorithmName() {
return algorithmName;
}
/** Get the JSch algorithm proposal. */
public String getJSchProposal() {
return jschProposal;
}
/** Get the server algorithm proposal. */
public String getServerProposal() {
return serverProposal;
}
private static String failString(int algorithmIndex, String jschProposal, String serverProposal) {
return String.format(Locale.ROOT,
"Algorithm negotiation fail: algorithmName=\"%s\" jschProposal=\"%s\" serverProposal=\"%s\"",
algorithmNameFromIndex(algorithmIndex), jschProposal, serverProposal);
}
private static String algorithmNameFromIndex(int algorithmIndex) {
switch (algorithmIndex) {
case KeyExchange.PROPOSAL_KEX_ALGS:
return "kex";
case KeyExchange.PROPOSAL_SERVER_HOST_KEY_ALGS:
return "server_host_key";
case KeyExchange.PROPOSAL_ENC_ALGS_CTOS:
return "cipher.c2s";
case KeyExchange.PROPOSAL_ENC_ALGS_STOC:
return "cipher.s2c";
case KeyExchange.PROPOSAL_MAC_ALGS_CTOS:
return "mac.c2s";
case KeyExchange.PROPOSAL_MAC_ALGS_STOC:
return "mac.s2c";
case KeyExchange.PROPOSAL_COMP_ALGS_CTOS:
return "compression.c2s";
case KeyExchange.PROPOSAL_COMP_ALGS_STOC:
return "compression.s2c";
case KeyExchange.PROPOSAL_LANG_CTOS:
return "lang.c2s";
case KeyExchange.PROPOSAL_LANG_STOC:
return "lang.s2c";
default:
return "";
}
}
}

@ -0,0 +1,45 @@
/*
* Copyright (c) 2002-2018 ymnk, JCraft,Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted
* provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions
* and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other materials provided with
* the distribution.
*
* 3. The names of the authors may not be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL JCRAFT, INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.jcraft.jsch;
class JSchAuthCancelException extends JSchException {
private static final long serialVersionUID = -1L;
String method;
JSchAuthCancelException() {
super();
}
JSchAuthCancelException(String s) {
super(s);
this.method = s;
}
public String getMethod() {
return method;
}
}

@ -0,0 +1,39 @@
/*
* Copyright (c) 2002-2018 ymnk, JCraft,Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted
* provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions
* and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other materials provided with
* the distribution.
*
* 3. The names of the authors may not be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL JCRAFT, INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.jcraft.jsch;
public class JSchChangedHostKeyException extends JSchHostKeyException {
private static final long serialVersionUID = -1L;
JSchChangedHostKeyException() {
super();
}
JSchChangedHostKeyException(String s) {
super(s);
}
}

@ -0,0 +1,43 @@
/*
* Copyright (c) 2002-2018 ymnk, JCraft,Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted
* provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions
* and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other materials provided with
* the distribution.
*
* 3. The names of the authors may not be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL JCRAFT, INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.jcraft.jsch;
public class JSchException extends Exception {
private static final long serialVersionUID = -1L;
public JSchException() {
super();
}
public JSchException(String s) {
super(s);
}
public JSchException(String s, Throwable e) {
super(s, e);
}
}

@ -0,0 +1,39 @@
/*
* Copyright (c) 2002-2018 ymnk, JCraft,Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted
* provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions
* and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other materials provided with
* the distribution.
*
* 3. The names of the authors may not be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL JCRAFT, INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.jcraft.jsch;
public abstract class JSchHostKeyException extends JSchException {
private static final long serialVersionUID = -1L;
JSchHostKeyException() {
super();
}
JSchHostKeyException(String s) {
super(s);
}
}

@ -0,0 +1,45 @@
/*
* Copyright (c) 2002-2018 ymnk, JCraft,Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted
* provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions
* and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other materials provided with
* the distribution.
*
* 3. The names of the authors may not be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL JCRAFT, INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.jcraft.jsch;
class JSchPartialAuthException extends JSchException {
private static final long serialVersionUID = -1L;
String methods;
public JSchPartialAuthException() {
super();
}
public JSchPartialAuthException(String s) {
super(s);
this.methods = s;
}
public String getMethods() {
return methods;
}
}

@ -0,0 +1,39 @@
/*
* Copyright (c) 2002-2018 ymnk, JCraft,Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted
* provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions
* and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other materials provided with
* the distribution.
*
* 3. The names of the authors may not be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL JCRAFT, INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.jcraft.jsch;
public class JSchProxyException extends JSchException {
private static final long serialVersionUID = -1L;
public JSchProxyException(String s) {
super(s);
}
public JSchProxyException(String s, Throwable e) {
super(s, e);
}
}

@ -0,0 +1,39 @@
/*
* Copyright (c) 2002-2018 ymnk, JCraft,Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted
* provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions
* and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other materials provided with
* the distribution.
*
* 3. The names of the authors may not be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL JCRAFT, INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.jcraft.jsch;
public class JSchRevokedHostKeyException extends JSchHostKeyException {
private static final long serialVersionUID = -1L;
JSchRevokedHostKeyException() {
super();
}
JSchRevokedHostKeyException(String s) {
super(s);
}
}

@ -0,0 +1,55 @@
/*
* Copyright (c) 2002-2018 ymnk, JCraft,Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted
* provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions
* and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other materials provided with
* the distribution.
*
* 3. The names of the authors may not be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL JCRAFT, INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.jcraft.jsch;
public class JSchSessionDisconnectException extends JSchException {
private static final long serialVersionUID = -1L;
// RFC 4253 11.1.
private final int reasonCode; // RFC 4250 4.2.2.
private final String description;
private final String languageTag;
JSchSessionDisconnectException(String s, int reasonCode, String description, String languageTag) {
super(s);
this.reasonCode = reasonCode;
this.description = description;
this.languageTag = languageTag;
}
public int getReasonCode() {
return reasonCode;
}
public String getDescription() {
return description;
}
public String getLanguageTag() {
return languageTag;
}
}

@ -0,0 +1,39 @@
/*
* Copyright (c) 2002-2018 ymnk, JCraft,Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted
* provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions
* and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other materials provided with
* the distribution.
*
* 3. The names of the authors may not be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL JCRAFT, INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.jcraft.jsch;
public class JSchStrictKexException extends JSchException {
private static final long serialVersionUID = -1L;
JSchStrictKexException() {
super();
}
JSchStrictKexException(String s) {
super(s);
}
}

@ -0,0 +1,39 @@
/*
* Copyright (c) 2002-2018 ymnk, JCraft,Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted
* provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions
* and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other materials provided with
* the distribution.
*
* 3. The names of the authors may not be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL JCRAFT, INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.jcraft.jsch;
public class JSchUnknownHostKeyException extends JSchHostKeyException {
private static final long serialVersionUID = -1L;
JSchUnknownHostKeyException() {
super();
}
JSchUnknownHostKeyException(String s) {
super(s);
}
}

@ -0,0 +1,8 @@
package com.jcraft.jsch;
final class JavaVersion {
static int getVersion() {
return Runtime.version().feature();
}
}

@ -0,0 +1,46 @@
package com.jcraft.jsch;
import java.lang.System.Logger;
import java.lang.System.Logger.Level;
public class JplLogger implements com.jcraft.jsch.Logger {
private static final Logger logger = System.getLogger(JSch.class.getName());
public JplLogger() {}
@Override
public boolean isEnabled(int level) {
return logger.isLoggable(getLevel(level));
}
@Override
public void log(int level, String message) {
logger.log(getLevel(level), message);
}
@Override
public void log(int level, String message, Throwable cause) {
if (cause == null) {
logger.log(getLevel(level), message);
return;
}
logger.log(getLevel(level), message, cause);
}
private static Level getLevel(int level) {
switch (level) {
case com.jcraft.jsch.Logger.DEBUG:
return Level.DEBUG;
case com.jcraft.jsch.Logger.INFO:
return Level.INFO;
case com.jcraft.jsch.Logger.WARN:
return Level.WARNING;
case com.jcraft.jsch.Logger.ERROR:
case com.jcraft.jsch.Logger.FATAL:
return Level.ERROR;
default:
return Level.TRACE;
}
}
}

@ -0,0 +1,46 @@
package com.jcraft.jsch;
import java.util.logging.Level;
import java.util.logging.Logger;
public class JulLogger implements com.jcraft.jsch.Logger {
private static final Logger logger = Logger.getLogger(JSch.class.getName());
public JulLogger() {}
@Override
public boolean isEnabled(int level) {
return logger.isLoggable(getLevel(level));
}
@Override
public void log(int level, String message) {
log(level, message, null);
}
@Override
public void log(int level, String message, Throwable cause) {
if (cause == null) {
logger.log(getLevel(level), message);
return;
}
logger.log(getLevel(level), message, cause);
}
static Level getLevel(int level) {
switch (level) {
case com.jcraft.jsch.Logger.DEBUG:
return Level.FINE;
case com.jcraft.jsch.Logger.INFO:
return Level.INFO;
case com.jcraft.jsch.Logger.WARN:
return Level.WARNING;
case com.jcraft.jsch.Logger.ERROR:
case com.jcraft.jsch.Logger.FATAL:
return Level.SEVERE;
default:
return Level.FINER;
}
}
}

@ -0,0 +1,31 @@
/*
* Copyright (c) 2013-2018 ymnk, JCraft,Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted
* provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions
* and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other materials provided with
* the distribution.
*
* 3. The names of the authors may not be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL JCRAFT, INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.jcraft.jsch;
public interface KDF {
byte[] getKey(byte[] pass, int size);
}

@ -0,0 +1,35 @@
/*
* Copyright (c) 2015-2018 ymnk, JCraft,Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted
* provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions
* and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other materials provided with
* the distribution.
*
* 3. The names of the authors may not be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL JCRAFT, INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.jcraft.jsch;
public interface KEM {
void init() throws Exception;
byte[] getPublicKey() throws Exception;
byte[] decapsulate(byte[] encapsulation) throws Exception;
}

@ -0,0 +1,502 @@
/*
* Copyright (c) 2002-2018 ymnk, JCraft,Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted
* provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions
* and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other materials provided with
* the distribution.
*
* 3. The names of the authors may not be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL JCRAFT, INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.jcraft.jsch;
import java.util.Locale;
public abstract class KeyExchange {
static final int PROPOSAL_KEX_ALGS = 0;
static final int PROPOSAL_SERVER_HOST_KEY_ALGS = 1;
static final int PROPOSAL_ENC_ALGS_CTOS = 2;
static final int PROPOSAL_ENC_ALGS_STOC = 3;
static final int PROPOSAL_MAC_ALGS_CTOS = 4;
static final int PROPOSAL_MAC_ALGS_STOC = 5;
static final int PROPOSAL_COMP_ALGS_CTOS = 6;
static final int PROPOSAL_COMP_ALGS_STOC = 7;
static final int PROPOSAL_LANG_CTOS = 8;
static final int PROPOSAL_LANG_STOC = 9;
static final int PROPOSAL_MAX = 10;
static final String[] PROPOSAL_NAMES =
{"KEX algorithms", "host key algorithms", "ciphers c2s", "ciphers s2c", "MACs c2s",
"MACs s2c", "compression c2s", "compression s2c", "languages c2s", "languages s2c"};
// static String kex_algs="diffie-hellman-group-exchange-sha1"+
// ",diffie-hellman-group1-sha1";
// static String kex="diffie-hellman-group-exchange-sha1";
static String kex = "diffie-hellman-group1-sha1";
static String server_host_key = "ssh-rsa,ssh-dss";
static String enc_c2s = "blowfish-cbc";
static String enc_s2c = "blowfish-cbc";
static String mac_c2s = "hmac-md5"; // hmac-md5,hmac-sha1,hmac-ripemd160,
// hmac-sha1-96,hmac-md5-96
static String mac_s2c = "hmac-md5";
// static String comp_c2s="none"; // zlib
// static String comp_s2c="none";
static String lang_c2s = "";
static String lang_s2c = "";
public static final int STATE_END = 0;
protected Session session = null;
protected HASH sha = null;
protected byte[] K = null;
protected byte[] H = null;
protected byte[] K_S = null;
public abstract void init(Session session, byte[] V_S, byte[] V_C, byte[] I_S, byte[] I_C)
throws Exception;
void doInit(Session session, byte[] V_S, byte[] V_C, byte[] I_S, byte[] I_C) throws Exception {
this.session = session;
init(session, V_S, V_C, I_S, I_C);
}
public abstract boolean next(Buffer buf) throws Exception;
public abstract int getState();
protected final int RSA = 0;
protected final int DSS = 1;
protected final int ECDSA = 2;
protected final int EDDSA = 3;
private int type = 0;
private String key_alg_name = "";
public String getKeyType() {
if (type == DSS)
return "DSA";
if (type == RSA)
return "RSA";
if (type == EDDSA)
return "EDDSA";
return "ECDSA";
}
public String getKeyAlgorithName() {
return key_alg_name;
}
protected static String[] guess(Session session, byte[] I_S, byte[] I_C) throws Exception {
String[] guess = new String[PROPOSAL_MAX];
Buffer sb = new Buffer(I_S);
sb.setOffSet(17);
Buffer cb = new Buffer(I_C);
cb.setOffSet(17);
if (session.getLogger().isEnabled(Logger.INFO)) {
for (int i = 0; i < PROPOSAL_MAX; i++) {
session.getLogger().log(Logger.INFO,
"server proposal: " + PROPOSAL_NAMES[i] + ": " + Util.byte2str(sb.getString()));
}
for (int i = 0; i < PROPOSAL_MAX; i++) {
session.getLogger().log(Logger.INFO,
"client proposal: " + PROPOSAL_NAMES[i] + ": " + Util.byte2str(cb.getString()));
}
sb.setOffSet(17);
cb.setOffSet(17);
}
for (int i = 0; i < PROPOSAL_MAX; i++) {
byte[] sp = sb.getString(); // server proposal
byte[] cp = cb.getString(); // client proposal
int j = 0;
int k = 0;
loop: while (j < cp.length) {
while (j < cp.length && cp[j] != ',')
j++;
if (k == j)
throw new JSchAlgoNegoFailException(i, Util.byte2str(cp), Util.byte2str(sp));
String algorithm = Util.byte2str(cp, k, j - k);
int l = 0;
int m = 0;
while (l < sp.length) {
while (l < sp.length && sp[l] != ',')
l++;
if (m == l)
throw new JSchAlgoNegoFailException(i, Util.byte2str(cp), Util.byte2str(sp));
if (algorithm.equals(Util.byte2str(sp, m, l - m))) {
guess[i] = algorithm;
break loop;
}
l++;
m = l;
}
j++;
k = j;
}
if (j == 0) {
guess[i] = "";
} else if (guess[i] == null) {
throw new JSchAlgoNegoFailException(i, Util.byte2str(cp), Util.byte2str(sp));
}
}
boolean _s2cAEAD = false;
boolean _c2sAEAD = false;
try {
Class<? extends Cipher> _s2cclazz =
Class.forName(session.getConfig(guess[PROPOSAL_ENC_ALGS_STOC])).asSubclass(Cipher.class);
Cipher _s2ccipher = _s2cclazz.getDeclaredConstructor().newInstance();
_s2cAEAD = _s2ccipher.isAEAD();
if (_s2cAEAD) {
guess[PROPOSAL_MAC_ALGS_STOC] = null;
}
Class<? extends Cipher> _c2sclazz =
Class.forName(session.getConfig(guess[PROPOSAL_ENC_ALGS_CTOS])).asSubclass(Cipher.class);
Cipher _c2scipher = _c2sclazz.getDeclaredConstructor().newInstance();
_c2sAEAD = _c2scipher.isAEAD();
if (_c2sAEAD) {
guess[PROPOSAL_MAC_ALGS_CTOS] = null;
}
} catch (Exception | NoClassDefFoundError e) {
throw new JSchException(e.toString(), e);
}
if (session.getLogger().isEnabled(Logger.INFO)) {
session.getLogger().log(Logger.INFO, "kex: algorithm: " + guess[PROPOSAL_KEX_ALGS]);
session.getLogger().log(Logger.INFO,
"kex: host key algorithm: " + guess[PROPOSAL_SERVER_HOST_KEY_ALGS]);
session.getLogger().log(Logger.INFO,
"kex: server->client" + " cipher: " + guess[PROPOSAL_ENC_ALGS_STOC] + " MAC: "
+ (_s2cAEAD ? ("<implicit>") : (guess[PROPOSAL_MAC_ALGS_STOC])) + " compression: "
+ guess[PROPOSAL_COMP_ALGS_STOC]);
session.getLogger().log(Logger.INFO,
"kex: client->server" + " cipher: " + guess[PROPOSAL_ENC_ALGS_CTOS] + " MAC: "
+ (_c2sAEAD ? ("<implicit>") : (guess[PROPOSAL_MAC_ALGS_CTOS])) + " compression: "
+ guess[PROPOSAL_COMP_ALGS_CTOS]);
}
return guess;
}
public String getFingerPrint() {
HASH hash = null;
try {
String _c = session.getConfig("FingerprintHash").toLowerCase(Locale.ROOT);
Class<? extends HASH> c = Class.forName(session.getConfig(_c)).asSubclass(HASH.class);
hash = c.getDeclaredConstructor().newInstance();
} catch (Exception e) {
if (session.getLogger().isEnabled(Logger.ERROR)) {
session.getLogger().log(Logger.ERROR, "getFingerPrint: " + e.getMessage(), e);
}
}
return Util.getFingerPrint(hash, getHostKey(), true, false);
}
byte[] getK() {
return K;
}
void clearK() {
Util.bzero(K);
K = null;
}
byte[] getH() {
return H;
}
HASH getHash() {
return sha;
}
byte[] getHostKey() {
return K_S;
}
/*
* It seems JCE included in Oracle's Java7u6(and later) has suddenly changed its behavior. The
* secrete generated by KeyAgreement#generateSecret() may start with 0, even if it is a positive
* value. See https://bugs.openjdk.org/browse/JDK-7146728.
*/
protected byte[] normalize(byte[] secret) {
// This should be a timing safe version of the following:
// if (secret.length > 1 && secret[0] == 0 && (secret[1] & 0x80) == 0) {
// byte[] tmp = new byte[secret.length - 1];
// System.arraycopy(secret, 1, tmp, 0, tmp.length);
// Util.bzero(secret);
// return normalize(tmp);
// } else {
// return secret;
// }
int len = secret.length;
if (len < 2) {
return secret;
}
// secret[0] == 0
int a = 0;
int s0 = secret[0] & 0xff;
for (int i = 0; i < 8; i++) {
int j = s0 >>> i;
j &= 0x1;
a |= j;
}
a ^= 0x1;
// (secret[1..n] & 0x80) == 0 && secret[1..n] != 0
int offset = 0;
for (int i = 1; i < len; i++) {
int j = secret[i] & 0x80;
j >>>= 7;
j ^= 0x1;
a &= j;
offset += a;
j = secret[i] & 0x7f;
for (int k = 0; k < 7; k++) {
int l = j >>> k;
l &= 0x1;
l ^= 0x1;
a &= l;
}
}
len -= offset;
// Try to remain timing safe by performing an allocation + copy for leading bytes removed
byte[] foo = new byte[len];
byte[] bar = new byte[offset];
System.arraycopy(secret, 0, bar, 0, offset);
System.arraycopy(secret, offset, foo, 0, len);
Util.bzero(secret);
return foo;
}
protected boolean verify(String alg, byte[] K_S, int index, byte[] sig_of_H) throws Exception {
int i, j;
i = index;
boolean result = false;
if (alg.equals("ssh-rsa")) {
byte[] tmp;
byte[] ee;
byte[] n;
type = RSA;
key_alg_name = alg;
j = ((K_S[i++] << 24) & 0xff000000) | ((K_S[i++] << 16) & 0x00ff0000)
| ((K_S[i++] << 8) & 0x0000ff00) | ((K_S[i++]) & 0x000000ff);
tmp = new byte[j];
System.arraycopy(K_S, i, tmp, 0, j);
i += j;
ee = tmp;
j = ((K_S[i++] << 24) & 0xff000000) | ((K_S[i++] << 16) & 0x00ff0000)
| ((K_S[i++] << 8) & 0x0000ff00) | ((K_S[i++]) & 0x000000ff);
tmp = new byte[j];
System.arraycopy(K_S, i, tmp, 0, j);
i += j;
n = tmp;
SignatureRSA sig = null;
Buffer buf = new Buffer(sig_of_H);
String foo = Util.byte2str(buf.getString());
try {
Class<? extends SignatureRSA> c =
Class.forName(session.getConfig(foo)).asSubclass(SignatureRSA.class);
sig = c.getDeclaredConstructor().newInstance();
sig.init();
} catch (Exception e) {
throw new JSchException(e.toString(), e);
}
sig.setPubKey(ee, n);
sig.update(H);
result = sig.verify(sig_of_H);
if (session.getLogger().isEnabled(Logger.INFO)) {
session.getLogger().log(Logger.INFO, "ssh_rsa_verify: " + foo + " signature " + result);
}
} else if (alg.equals("ssh-dss")) {
byte[] q = null;
byte[] tmp;
byte[] p;
byte[] g;
byte[] f;
type = DSS;
key_alg_name = alg;
j = ((K_S[i++] << 24) & 0xff000000) | ((K_S[i++] << 16) & 0x00ff0000)
| ((K_S[i++] << 8) & 0x0000ff00) | ((K_S[i++]) & 0x000000ff);
tmp = new byte[j];
System.arraycopy(K_S, i, tmp, 0, j);
i += j;
p = tmp;
j = ((K_S[i++] << 24) & 0xff000000) | ((K_S[i++] << 16) & 0x00ff0000)
| ((K_S[i++] << 8) & 0x0000ff00) | ((K_S[i++]) & 0x000000ff);
tmp = new byte[j];
System.arraycopy(K_S, i, tmp, 0, j);
i += j;
q = tmp;
j = ((K_S[i++] << 24) & 0xff000000) | ((K_S[i++] << 16) & 0x00ff0000)
| ((K_S[i++] << 8) & 0x0000ff00) | ((K_S[i++]) & 0x000000ff);
tmp = new byte[j];
System.arraycopy(K_S, i, tmp, 0, j);
i += j;
g = tmp;
j = ((K_S[i++] << 24) & 0xff000000) | ((K_S[i++] << 16) & 0x00ff0000)
| ((K_S[i++] << 8) & 0x0000ff00) | ((K_S[i++]) & 0x000000ff);
tmp = new byte[j];
System.arraycopy(K_S, i, tmp, 0, j);
i += j;
f = tmp;
SignatureDSA sig = null;
try {
Class<? extends SignatureDSA> c =
Class.forName(session.getConfig("signature.dss")).asSubclass(SignatureDSA.class);
sig = c.getDeclaredConstructor().newInstance();
sig.init();
} catch (Exception e) {
throw new JSchException(e.toString(), e);
}
sig.setPubKey(f, p, q, g);
sig.update(H);
result = sig.verify(sig_of_H);
if (session.getLogger().isEnabled(Logger.INFO)) {
session.getLogger().log(Logger.INFO, "ssh_dss_verify: signature " + result);
}
} else if (alg.equals("ecdsa-sha2-nistp256") || alg.equals("ecdsa-sha2-nistp384")
|| alg.equals("ecdsa-sha2-nistp521")) {
byte[] tmp;
byte[] r;
byte[] s;
// RFC 5656,
type = ECDSA;
key_alg_name = alg;
j = ((K_S[i++] << 24) & 0xff000000) | ((K_S[i++] << 16) & 0x00ff0000)
| ((K_S[i++] << 8) & 0x0000ff00) | ((K_S[i++]) & 0x000000ff);
tmp = new byte[j];
System.arraycopy(K_S, i, tmp, 0, j);
i += j;
j = ((K_S[i++] << 24) & 0xff000000) | ((K_S[i++] << 16) & 0x00ff0000)
| ((K_S[i++] << 8) & 0x0000ff00) | ((K_S[i++]) & 0x000000ff);
i++;
tmp = new byte[(j - 1) / 2];
System.arraycopy(K_S, i, tmp, 0, tmp.length);
i += (j - 1) / 2;
r = tmp;
tmp = new byte[(j - 1) / 2];
System.arraycopy(K_S, i, tmp, 0, tmp.length);
i += (j - 1) / 2;
s = tmp;
SignatureECDSA sig = null;
try {
Class<? extends SignatureECDSA> c =
Class.forName(session.getConfig(alg)).asSubclass(SignatureECDSA.class);
sig = c.getDeclaredConstructor().newInstance();
sig.init();
} catch (Exception e) {
throw new JSchException(e.toString(), e);
}
sig.setPubKey(r, s);
sig.update(H);
result = sig.verify(sig_of_H);
if (session.getLogger().isEnabled(Logger.INFO)) {
session.getLogger().log(Logger.INFO, "ssh_ecdsa_verify: " + alg + " signature " + result);
}
} else if (alg.equals("ssh-ed25519") || alg.equals("ssh-ed448")) {
byte[] tmp;
// RFC 8709,
type = EDDSA;
key_alg_name = alg;
j = ((K_S[i++] << 24) & 0xff000000) | ((K_S[i++] << 16) & 0x00ff0000)
| ((K_S[i++] << 8) & 0x0000ff00) | ((K_S[i++]) & 0x000000ff);
tmp = new byte[j];
System.arraycopy(K_S, i, tmp, 0, j);
i += j;
SignatureEdDSA sig = null;
try {
Class<? extends SignatureEdDSA> c =
Class.forName(session.getConfig(alg)).asSubclass(SignatureEdDSA.class);
sig = c.getDeclaredConstructor().newInstance();
sig.init();
} catch (Exception | NoClassDefFoundError e) {
throw new JSchException(e.toString(), e);
}
sig.setPubKey(tmp);
sig.update(H);
result = sig.verify(sig_of_H);
if (session.getLogger().isEnabled(Logger.INFO)) {
session.getLogger().log(Logger.INFO, "ssh_eddsa_verify: " + alg + " signature " + result);
}
} else {
if (session.getLogger().isEnabled(Logger.ERROR)) {
session.getLogger().log(Logger.ERROR, "unknown alg: " + alg);
}
}
return result;
}
protected byte[] encodeAsMPInt(byte[] raw) {
int i = (raw[0] & 0x80) >>> 7;
int len = raw.length + i;
byte[] foo = new byte[len + 4];
// Try to remain timing safe by performing an extra allocation when i == 0
byte[] bar = new byte[i ^ 0x1];
foo[0] = (byte) (len >>> 24);
foo[1] = (byte) (len >>> 16);
foo[2] = (byte) (len >>> 8);
foo[3] = (byte) (len);
System.arraycopy(raw, 0, foo, 4 + i, len - i);
Util.bzero(raw);
return foo;
}
protected byte[] encodeAsString(byte[] raw) {
int len = raw.length;
byte[] foo = new byte[len + 4];
foo[0] = (byte) (len >>> 24);
foo[1] = (byte) (len >>> 16);
foo[2] = (byte) (len >>> 8);
foo[3] = (byte) (len);
System.arraycopy(raw, 0, foo, 4, len);
Util.bzero(raw);
return foo;
}
}

File diff suppressed because it is too large Load Diff

@ -0,0 +1,406 @@
/*
* Copyright (c) 2002-2018 ymnk, JCraft,Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted
* provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions
* and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other materials provided with
* the distribution.
*
* 3. The names of the authors may not be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL JCRAFT, INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.jcraft.jsch;
import java.math.BigInteger;
class KeyPairDSA extends KeyPair {
private byte[] P_array;
private byte[] Q_array;
private byte[] G_array;
private byte[] pub_array;
private byte[] prv_array;
// private int key_size=0;
private int key_size = 1024;
KeyPairDSA(JSch.InstanceLogger instLogger) {
this(instLogger, null, null, null, null, null);
}
KeyPairDSA(JSch.InstanceLogger instLogger, byte[] P_array, byte[] Q_array, byte[] G_array,
byte[] pub_array, byte[] prv_array) {
super(instLogger);
this.P_array = P_array;
this.Q_array = Q_array;
this.G_array = G_array;
this.pub_array = pub_array;
this.prv_array = prv_array;
if (P_array != null)
key_size = (new BigInteger(P_array)).bitLength();
}
@Override
void generate(int key_size) throws JSchException {
this.key_size = key_size;
try {
Class<? extends KeyPairGenDSA> c =
Class.forName(JSch.getConfig("keypairgen.dsa")).asSubclass(KeyPairGenDSA.class);
KeyPairGenDSA keypairgen = c.getDeclaredConstructor().newInstance();
keypairgen.init(key_size);
P_array = keypairgen.getP();
Q_array = keypairgen.getQ();
G_array = keypairgen.getG();
pub_array = keypairgen.getY();
prv_array = keypairgen.getX();
keypairgen = null;
} catch (Exception e) {
throw new JSchException(e.toString(), e);
}
}
private static final byte[] begin = Util.str2byte("-----BEGIN DSA PRIVATE KEY-----");
private static final byte[] end = Util.str2byte("-----END DSA PRIVATE KEY-----");
@Override
byte[] getBegin() {
return begin;
}
@Override
byte[] getEnd() {
return end;
}
@Override
byte[] getPrivateKey() {
int content = 1 + countLength(1) + 1 + // INTEGER
1 + countLength(P_array.length) + P_array.length + // INTEGER P
1 + countLength(Q_array.length) + Q_array.length + // INTEGER Q
1 + countLength(G_array.length) + G_array.length + // INTEGER G
1 + countLength(pub_array.length) + pub_array.length + // INTEGER pub
1 + countLength(prv_array.length) + prv_array.length; // INTEGER prv
int total = 1 + countLength(content) + content; // SEQUENCE
byte[] plain = new byte[total];
int index = 0;
index = writeSEQUENCE(plain, index, content);
index = writeINTEGER(plain, index, new byte[1]); // 0
index = writeINTEGER(plain, index, P_array);
index = writeINTEGER(plain, index, Q_array);
index = writeINTEGER(plain, index, G_array);
index = writeINTEGER(plain, index, pub_array);
index = writeINTEGER(plain, index, prv_array);
return plain;
}
@Override
boolean parse(byte[] plain) {
try {
if (vendor == VENDOR_FSECURE) {
if (plain[0] != 0x30) { // FSecure
Buffer buf = new Buffer(plain);
buf.getInt();
P_array = buf.getMPIntBits();
G_array = buf.getMPIntBits();
Q_array = buf.getMPIntBits();
pub_array = buf.getMPIntBits();
prv_array = buf.getMPIntBits();
if (P_array != null)
key_size = (new BigInteger(P_array)).bitLength();
return true;
}
return false;
} else if (vendor == VENDOR_PUTTY || vendor == VENDOR_PUTTY_V3) {
Buffer buf = new Buffer(plain);
buf.skip(plain.length);
try {
byte[][] tmp = buf.getBytes(1, "");
prv_array = tmp[0];
} catch (JSchException e) {
if (instLogger.getLogger().isEnabled(Logger.ERROR)) {
instLogger.getLogger().log(Logger.ERROR, "failed to parse key", e);
}
return false;
}
return true;
}
// OPENSSH Key v1 Format
else if (vendor == VENDOR_OPENSSH_V1) {
final Buffer prvKEyBuffer = new Buffer(plain);
int checkInt1 = prvKEyBuffer.getInt(); // uint32 checkint1
int checkInt2 = prvKEyBuffer.getInt(); // uint32 checkint2
if (checkInt1 != checkInt2) {
throw new JSchException("check failed");
}
// The private key section contains both the public key and the private key
String keyType = Util.byte2str(prvKEyBuffer.getString()); // string keytype
P_array = prvKEyBuffer.getMPInt();
Q_array = prvKEyBuffer.getMPInt();
G_array = prvKEyBuffer.getMPInt();
pub_array = prvKEyBuffer.getMPInt();
prv_array = prvKEyBuffer.getMPInt();
publicKeyComment = Util.byte2str(prvKEyBuffer.getString());
// if(P_array!=null) key_size = (new BigInteger(P_array)).bitLength();
return true;
}
int index = 0;
int length = 0;
if (plain[index] != 0x30)
return false;
index++; // SEQUENCE
length = plain[index++] & 0xff;
if ((length & 0x80) != 0) {
int foo = length & 0x7f;
length = 0;
while (foo-- > 0) {
length = (length << 8) + (plain[index++] & 0xff);
}
}
if (plain[index] != 0x02)
return false;
index++; // INTEGER
length = plain[index++] & 0xff;
if ((length & 0x80) != 0) {
int foo = length & 0x7f;
length = 0;
while (foo-- > 0) {
length = (length << 8) + (plain[index++] & 0xff);
}
}
index += length;
index++;
length = plain[index++] & 0xff;
if ((length & 0x80) != 0) {
int foo = length & 0x7f;
length = 0;
while (foo-- > 0) {
length = (length << 8) + (plain[index++] & 0xff);
}
}
P_array = new byte[length];
System.arraycopy(plain, index, P_array, 0, length);
index += length;
index++;
length = plain[index++] & 0xff;
if ((length & 0x80) != 0) {
int foo = length & 0x7f;
length = 0;
while (foo-- > 0) {
length = (length << 8) + (plain[index++] & 0xff);
}
}
Q_array = new byte[length];
System.arraycopy(plain, index, Q_array, 0, length);
index += length;
index++;
length = plain[index++] & 0xff;
if ((length & 0x80) != 0) {
int foo = length & 0x7f;
length = 0;
while (foo-- > 0) {
length = (length << 8) + (plain[index++] & 0xff);
}
}
G_array = new byte[length];
System.arraycopy(plain, index, G_array, 0, length);
index += length;
index++;
length = plain[index++] & 0xff;
if ((length & 0x80) != 0) {
int foo = length & 0x7f;
length = 0;
while (foo-- > 0) {
length = (length << 8) + (plain[index++] & 0xff);
}
}
pub_array = new byte[length];
System.arraycopy(plain, index, pub_array, 0, length);
index += length;
index++;
length = plain[index++] & 0xff;
if ((length & 0x80) != 0) {
int foo = length & 0x7f;
length = 0;
while (foo-- > 0) {
length = (length << 8) + (plain[index++] & 0xff);
}
}
prv_array = new byte[length];
System.arraycopy(plain, index, prv_array, 0, length);
index += length;
if (P_array != null)
key_size = (new BigInteger(P_array)).bitLength();
} catch (Exception e) {
if (instLogger.getLogger().isEnabled(Logger.ERROR)) {
instLogger.getLogger().log(Logger.ERROR, "failed to parse key", e);
}
return false;
}
return true;
}
@Override
public byte[] getPublicKeyBlob() {
byte[] foo = super.getPublicKeyBlob();
if (foo != null)
return foo;
if (P_array == null)
return null;
byte[][] tmp = new byte[5][];
tmp[0] = sshdss;
tmp[1] = P_array;
tmp[2] = Q_array;
tmp[3] = G_array;
tmp[4] = pub_array;
return Buffer.fromBytes(tmp).buffer;
}
private static final byte[] sshdss = Util.str2byte("ssh-dss");
@Override
byte[] getKeyTypeName() {
return sshdss;
}
@Override
public int getKeyType() {
return DSA;
}
@Override
public int getKeySize() {
return key_size;
}
@Override
public byte[] getSignature(byte[] data) {
try {
Class<? extends SignatureDSA> c =
Class.forName(JSch.getConfig("signature.dss")).asSubclass(SignatureDSA.class);
SignatureDSA dsa = c.getDeclaredConstructor().newInstance();
dsa.init();
dsa.setPrvKey(prv_array, P_array, Q_array, G_array);
dsa.update(data);
byte[] sig = dsa.sign();
byte[][] tmp = new byte[2][];
tmp[0] = sshdss;
tmp[1] = sig;
return Buffer.fromBytes(tmp).buffer;
} catch (Exception e) {
if (instLogger.getLogger().isEnabled(Logger.ERROR)) {
instLogger.getLogger().log(Logger.ERROR, "failed to generate signature", e);
}
}
return null;
}
@Override
public byte[] getSignature(byte[] data, String alg) {
return getSignature(data);
}
@Override
public Signature getVerifier() {
try {
Class<? extends SignatureDSA> c =
Class.forName(JSch.getConfig("signature.dss")).asSubclass(SignatureDSA.class);
SignatureDSA dsa = c.getDeclaredConstructor().newInstance();
dsa.init();
if (pub_array == null && P_array == null && getPublicKeyBlob() != null) {
Buffer buf = new Buffer(getPublicKeyBlob());
buf.getString();
P_array = buf.getString();
Q_array = buf.getString();
G_array = buf.getString();
pub_array = buf.getString();
}
dsa.setPubKey(pub_array, P_array, Q_array, G_array);
return dsa;
} catch (Exception e) {
if (instLogger.getLogger().isEnabled(Logger.ERROR)) {
instLogger.getLogger().log(Logger.ERROR, "failed to create verifier", e);
}
}
return null;
}
@Override
public Signature getVerifier(String alg) {
return getVerifier();
}
static KeyPair fromSSHAgent(JSch.InstanceLogger instLogger, Buffer buf) throws JSchException {
byte[][] tmp = buf.getBytes(7, "invalid key format");
byte[] P_array = tmp[1];
byte[] Q_array = tmp[2];
byte[] G_array = tmp[3];
byte[] pub_array = tmp[4];
byte[] prv_array = tmp[5];
KeyPairDSA kpair = new KeyPairDSA(instLogger, P_array, Q_array, G_array, pub_array, prv_array);
kpair.publicKeyComment = Util.byte2str(tmp[6]);
kpair.vendor = VENDOR_OPENSSH;
return kpair;
}
@Override
public byte[] forSSHAgent() throws JSchException {
if (isEncrypted()) {
throw new JSchException("key is encrypted.");
}
Buffer buf = new Buffer();
buf.putString(sshdss);
buf.putString(P_array);
buf.putString(Q_array);
buf.putString(G_array);
buf.putString(pub_array);
buf.putString(prv_array);
buf.putString(Util.str2byte(publicKeyComment));
byte[] result = new byte[buf.getLength()];
buf.getByte(result, 0, result.length);
return result;
}
@Override
public void dispose() {
super.dispose();
Util.bzero(prv_array);
}
}

@ -0,0 +1,470 @@
/*
* Copyright (c) 2015-2018 ymnk, JCraft,Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted
* provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions
* and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other materials provided with
* the distribution.
*
* 3. The names of the authors may not be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL JCRAFT, INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.jcraft.jsch;
import java.util.Arrays;
class KeyPairECDSA extends KeyPair {
private static byte[][] oids = {{(byte) 0x06, (byte) 0x08, (byte) 0x2a, (byte) 0x86, (byte) 0x48, // 256
(byte) 0xce, (byte) 0x3d, (byte) 0x03, (byte) 0x01, (byte) 0x07},
{(byte) 0x06, (byte) 0x05, (byte) 0x2b, (byte) 0x81, (byte) 0x04, // 384
(byte) 0x00, (byte) 0x22},
{(byte) 0x06, (byte) 0x05, (byte) 0x2b, (byte) 0x81, (byte) 0x04, // 521
(byte) 0x00, (byte) 0x23},};
private static String[] names = {"nistp256", "nistp384", "nistp521"};
private byte[] name = Util.str2byte(names[0]);
private byte[] r_array;
private byte[] s_array;
private byte[] prv_array;
private int key_size = 256;
KeyPairECDSA(JSch.InstanceLogger instLogger) {
this(instLogger, null, null, null, null);
}
KeyPairECDSA(JSch.InstanceLogger instLogger, byte[] pubkey) {
this(instLogger, null, null, null, null);
if (pubkey != null) {
byte[] name = new byte[8];
System.arraycopy(pubkey, 11, name, 0, 8);
if (Util.array_equals(name, Util.str2byte("nistp384"))) {
key_size = 384;
this.name = name;
}
if (Util.array_equals(name, Util.str2byte("nistp521"))) {
key_size = 521;
this.name = name;
}
}
}
KeyPairECDSA(JSch.InstanceLogger instLogger, byte[] name, byte[] r_array, byte[] s_array,
byte[] prv_array) {
super(instLogger);
if (name != null)
this.name = name;
this.r_array = r_array;
this.s_array = s_array;
this.prv_array = prv_array;
if (prv_array != null)
key_size = prv_array.length >= 64 ? 521 : (prv_array.length >= 48 ? 384 : 256);
}
@Override
void generate(int key_size) throws JSchException {
this.key_size = key_size;
try {
Class<? extends KeyPairGenECDSA> c =
Class.forName(JSch.getConfig("keypairgen.ecdsa")).asSubclass(KeyPairGenECDSA.class);
KeyPairGenECDSA keypairgen = c.getDeclaredConstructor().newInstance();
keypairgen.init(key_size);
prv_array = keypairgen.getD();
r_array = keypairgen.getR();
s_array = keypairgen.getS();
name = Util.str2byte(names[prv_array.length >= 64 ? 2 : (prv_array.length >= 48 ? 1 : 0)]);
keypairgen = null;
} catch (Exception e) {
throw new JSchException(e.toString(), e);
}
}
private static final byte[] begin = Util.str2byte("-----BEGIN EC PRIVATE KEY-----");
private static final byte[] end = Util.str2byte("-----END EC PRIVATE KEY-----");
@Override
byte[] getBegin() {
return begin;
}
@Override
byte[] getEnd() {
return end;
}
@Override
byte[] getPrivateKey() {
byte[] tmp = new byte[1];
tmp[0] = 1;
byte[] oid = oids[(r_array.length >= 64) ? 2 : ((r_array.length >= 48) ? 1 : 0)];
byte[] point = toPoint(r_array, s_array);
int bar = ((point.length + 1) & 0x80) == 0 ? 3 : 4;
byte[] foo = new byte[point.length + bar];
System.arraycopy(point, 0, foo, bar, point.length);
foo[0] = 0x03; // BITSTRING
if (bar == 3) {
foo[1] = (byte) (point.length + 1);
} else {
foo[1] = (byte) 0x81;
foo[2] = (byte) (point.length + 1);
}
point = foo;
int content = 1 + countLength(tmp.length) + tmp.length + 1 + countLength(prv_array.length)
+ prv_array.length + 1 + countLength(oid.length) + oid.length + 1
+ countLength(point.length) + point.length;
int total = 1 + countLength(content) + content; // SEQUENCE
byte[] plain = new byte[total];
int index = 0;
index = writeSEQUENCE(plain, index, content);
index = writeINTEGER(plain, index, tmp);
index = writeOCTETSTRING(plain, index, prv_array);
index = writeDATA(plain, (byte) 0xa0, index, oid);
index = writeDATA(plain, (byte) 0xa1, index, point);
return plain;
}
@Override
boolean parse(byte[] plain) {
try {
if (vendor == VENDOR_FSECURE) {
/*
* if(plain[0]!=0x30){ // FSecure return true; } return false;
*/
return false;
} else if (vendor == VENDOR_PUTTY || vendor == VENDOR_PUTTY_V3) {
Buffer buf = new Buffer(plain);
buf.skip(plain.length);
try {
byte[][] tmp = buf.getBytes(1, "");
prv_array = tmp[0];
key_size = prv_array.length >= 64 ? 521 : (prv_array.length >= 48 ? 384 : 256);
} catch (JSchException e) {
if (instLogger.getLogger().isEnabled(Logger.ERROR)) {
instLogger.getLogger().log(Logger.ERROR, "failed to parse key", e);
}
return false;
}
return true;
}
// OPENSSH Key v1 Format
if (vendor == VENDOR_OPENSSH_V1) {
final Buffer prvKeyBuffer = new Buffer(plain);
int checkInt1 = prvKeyBuffer.getInt(); // uint32 checkint1
int checkInt2 = prvKeyBuffer.getInt(); // uint32 checkint2
if (checkInt1 != checkInt2) {
throw new JSchException("check failed");
}
String keyType = Util.byte2str(prvKeyBuffer.getString()); // string keytype
name = prvKeyBuffer.getString();
if (!Arrays.asList(names).contains(Util.byte2str(name))) {
throw new IllegalArgumentException("unknown curve name " + Util.byte2str(name));
}
final int keyLen = prvKeyBuffer.getInt();
final int x04 = prvKeyBuffer.getByte(); // in case of x04 it is uncompressed
// https://tools.ietf.org/html/rfc5480#page-7
final byte[] x = new byte[(keyLen - 1) / 2];
final byte[] y = new byte[(keyLen - 1) / 2];
prvKeyBuffer.getByte(x);
prvKeyBuffer.getByte(y);
prv_array = prvKeyBuffer.getString();
publicKeyComment = Util.byte2str(prvKeyBuffer.getString());
r_array = x;
s_array = y;
key_size = x.length >= 64 ? 521 : (x.length >= 48 ? 384 : 256);
return true;
}
int index = 0;
int length = 0;
if (plain[index] != 0x30)
return false;
index++; // SEQUENCE
length = plain[index++] & 0xff;
if ((length & 0x80) != 0) {
int foo = length & 0x7f;
length = 0;
while (foo-- > 0) {
length = (length << 8) + (plain[index++] & 0xff);
}
}
if (plain[index] != 0x02)
return false;
index++; // INTEGER
length = plain[index++] & 0xff;
if ((length & 0x80) != 0) {
int foo = length & 0x7f;
length = 0;
while (foo-- > 0) {
length = (length << 8) + (plain[index++] & 0xff);
}
}
index += length;
index++; // 0x04
length = plain[index++] & 0xff;
if ((length & 0x80) != 0) {
int foo = length & 0x7f;
length = 0;
while (foo-- > 0) {
length = (length << 8) + (plain[index++] & 0xff);
}
}
prv_array = new byte[length];
System.arraycopy(plain, index, prv_array, 0, length);
index += length;
index++; // 0xa0
length = plain[index++] & 0xff;
if ((length & 0x80) != 0) {
int foo = length & 0x7f;
length = 0;
while (foo-- > 0) {
length = (length << 8) + (plain[index++] & 0xff);
}
}
byte[] oid_array = new byte[length];
System.arraycopy(plain, index, oid_array, 0, length);
index += length;
for (int i = 0; i < oids.length; i++) {
if (Util.array_equals(oids[i], oid_array)) {
name = Util.str2byte(names[i]);
break;
}
}
index++; // 0xa1
length = plain[index++] & 0xff;
if ((length & 0x80) != 0) {
int foo = length & 0x7f;
length = 0;
while (foo-- > 0) {
length = (length << 8) + (plain[index++] & 0xff);
}
}
byte[] Q_array = new byte[length];
System.arraycopy(plain, index, Q_array, 0, length);
index += length;
byte[][] tmp = fromPoint(Q_array);
r_array = tmp[0];
s_array = tmp[1];
if (prv_array != null)
key_size = prv_array.length >= 64 ? 521 : (prv_array.length >= 48 ? 384 : 256);
} catch (Exception e) {
if (instLogger.getLogger().isEnabled(Logger.ERROR)) {
instLogger.getLogger().log(Logger.ERROR, "failed to parse key", e);
}
return false;
}
return true;
}
@Override
public byte[] getPublicKeyBlob() {
byte[] foo = super.getPublicKeyBlob();
if (foo != null)
return foo;
if (r_array == null)
return null;
byte[][] tmp = new byte[3][];
tmp[0] = Util.str2byte("ecdsa-sha2-" + Util.byte2str(name));
tmp[1] = name;
tmp[2] = new byte[1 + r_array.length + s_array.length];
tmp[2][0] = 4; // POINT_CONVERSION_UNCOMPRESSED
System.arraycopy(r_array, 0, tmp[2], 1, r_array.length);
System.arraycopy(s_array, 0, tmp[2], 1 + r_array.length, s_array.length);
return Buffer.fromBytes(tmp).buffer;
}
@Override
byte[] getKeyTypeName() {
return Util.str2byte("ecdsa-sha2-" + Util.byte2str(name));
}
@Override
public int getKeyType() {
return ECDSA;
}
@Override
public int getKeySize() {
return key_size;
}
@Override
public byte[] getSignature(byte[] data) {
try {
Class<? extends SignatureECDSA> c =
Class.forName(JSch.getConfig("ecdsa-sha2-" + Util.byte2str(name)))
.asSubclass(SignatureECDSA.class);
SignatureECDSA ecdsa = c.getDeclaredConstructor().newInstance();
ecdsa.init();
ecdsa.setPrvKey(prv_array);
ecdsa.update(data);
byte[] sig = ecdsa.sign();
byte[][] tmp = new byte[2][];
tmp[0] = Util.str2byte("ecdsa-sha2-" + Util.byte2str(name));
tmp[1] = sig;
return Buffer.fromBytes(tmp).buffer;
} catch (Exception e) {
if (instLogger.getLogger().isEnabled(Logger.ERROR)) {
instLogger.getLogger().log(Logger.ERROR, "failed to generate signature", e);
}
}
return null;
}
@Override
public byte[] getSignature(byte[] data, String al) {
return getSignature(data);
}
@Override
public Signature getVerifier() {
try {
Class<? extends SignatureECDSA> c =
Class.forName(JSch.getConfig("ecdsa-sha2-" + Util.byte2str(name)))
.asSubclass(SignatureECDSA.class);
final SignatureECDSA ecdsa = c.getDeclaredConstructor().newInstance();
ecdsa.init();
if (r_array == null && s_array == null && getPublicKeyBlob() != null) {
Buffer buf = new Buffer(getPublicKeyBlob());
buf.getString(); // ecdsa-sha2-nistp256
buf.getString(); // nistp256
byte[][] tmp = fromPoint(buf.getString());
r_array = tmp[0];
s_array = tmp[1];
}
ecdsa.setPubKey(r_array, s_array);
return ecdsa;
} catch (Exception e) {
if (instLogger.getLogger().isEnabled(Logger.ERROR)) {
instLogger.getLogger().log(Logger.ERROR, "failed to create verifier", e);
}
}
return null;
}
@Override
public Signature getVerifier(String alg) {
return getVerifier();
}
static KeyPair fromSSHAgent(JSch.InstanceLogger instLogger, Buffer buf) throws JSchException {
byte[][] tmp = buf.getBytes(5, "invalid key format");
byte[] name = tmp[1]; // nistp256
byte[][] foo = fromPoint(tmp[2]);
byte[] r_array = foo[0];
byte[] s_array = foo[1];
byte[] prv_array = tmp[3];
KeyPairECDSA kpair = new KeyPairECDSA(instLogger, name, r_array, s_array, prv_array);
kpair.publicKeyComment = Util.byte2str(tmp[4]);
kpair.vendor = VENDOR_OPENSSH;
return kpair;
}
@Override
public byte[] forSSHAgent() throws JSchException {
if (isEncrypted()) {
throw new JSchException("key is encrypted.");
}
Buffer buf = new Buffer();
buf.putString(Util.str2byte("ecdsa-sha2-" + Util.byte2str(name)));
buf.putString(name);
buf.putString(toPoint(r_array, s_array));
buf.putString(prv_array);
buf.putString(Util.str2byte(publicKeyComment));
byte[] result = new byte[buf.getLength()];
buf.getByte(result, 0, result.length);
return result;
}
static byte[] toPoint(byte[] r_array, byte[] s_array) {
byte[] tmp = new byte[1 + r_array.length + s_array.length];
tmp[0] = 0x04;
System.arraycopy(r_array, 0, tmp, 1, r_array.length);
System.arraycopy(s_array, 0, tmp, 1 + r_array.length, s_array.length);
return tmp;
}
static byte[][] fromPoint(byte[] point) {
int i = 0;
while (point[i] != 4)
i++;
i++;
byte[][] tmp = new byte[2][];
byte[] r_array = new byte[(point.length - i) / 2];
byte[] s_array = new byte[(point.length - i) / 2];
// point[0] == 0x04 == POINT_CONVERSION_UNCOMPRESSED
System.arraycopy(point, i, r_array, 0, r_array.length);
System.arraycopy(point, i + r_array.length, s_array, 0, s_array.length);
tmp[0] = r_array;
tmp[1] = s_array;
return tmp;
}
@Override
public void dispose() {
super.dispose();
Util.bzero(prv_array);
}
}

@ -0,0 +1,74 @@
/*
* Copyright (c) 2002-2018 ymnk, JCraft,Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted
* provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions
* and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other materials provided with
* the distribution.
*
* 3. The names of the authors may not be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL JCRAFT, INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.jcraft.jsch;
import java.util.Arrays;
class KeyPairEd25519 extends KeyPairEdDSA {
private static int keySize = 32;
KeyPairEd25519(JSch.InstanceLogger instLogger) {
this(instLogger, null, null);
}
KeyPairEd25519(JSch.InstanceLogger instLogger, byte[] pub_array, byte[] prv_array) {
super(instLogger, pub_array, prv_array);
}
@Override
public int getKeyType() {
return ED25519;
}
@Override
public int getKeySize() {
return keySize;
}
@Override
String getSshName() {
return "ssh-ed25519";
}
@Override
String getJceName() {
return "Ed25519";
}
static KeyPair fromSSHAgent(JSch.InstanceLogger instLogger, Buffer buf) throws JSchException {
byte[][] tmp = buf.getBytes(4, "invalid key format");
byte[] pub_array = tmp[1];
byte[] prv_array = Arrays.copyOf(tmp[2], keySize);
KeyPairEd25519 kpair = new KeyPairEd25519(instLogger, pub_array, prv_array);
kpair.publicKeyComment = Util.byte2str(tmp[3]);
kpair.vendor = VENDOR_OPENSSH;
return kpair;
}
}

@ -0,0 +1,74 @@
/*
* Copyright (c) 2002-2018 ymnk, JCraft,Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted
* provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions
* and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other materials provided with
* the distribution.
*
* 3. The names of the authors may not be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL JCRAFT, INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.jcraft.jsch;
import java.util.Arrays;
class KeyPairEd448 extends KeyPairEdDSA {
private static int keySize = 57;
KeyPairEd448(JSch.InstanceLogger instLogger) {
this(instLogger, null, null);
}
KeyPairEd448(JSch.InstanceLogger instLogger, byte[] pub_array, byte[] prv_array) {
super(instLogger, pub_array, prv_array);
}
@Override
public int getKeyType() {
return ED448;
}
@Override
public int getKeySize() {
return keySize;
}
@Override
String getSshName() {
return "ssh-ed448";
}
@Override
String getJceName() {
return "Ed448";
}
static KeyPair fromSSHAgent(JSch.InstanceLogger instLogger, Buffer buf) throws JSchException {
byte[][] tmp = buf.getBytes(4, "invalid key format");
byte[] pub_array = tmp[1];
byte[] prv_array = Arrays.copyOf(tmp[2], keySize);
KeyPairEd448 kpair = new KeyPairEd448(instLogger, pub_array, prv_array);
kpair.publicKeyComment = Util.byte2str(tmp[3]);
kpair.vendor = VENDOR_OPENSSH;
return kpair;
}
}

@ -0,0 +1,241 @@
/*
* Copyright (c) 2002-2018 ymnk, JCraft,Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted
* provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions
* and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other materials provided with
* the distribution.
*
* 3. The names of the authors may not be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL JCRAFT, INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.jcraft.jsch;
import java.util.Arrays;
abstract class KeyPairEdDSA extends KeyPair {
private byte[] pub_array;
private byte[] prv_array;
KeyPairEdDSA(JSch.InstanceLogger instLogger, byte[] pub_array, byte[] prv_array) {
super(instLogger);
this.pub_array = pub_array;
this.prv_array = prv_array;
}
abstract String getSshName();
abstract String getJceName();
@Override
void generate(int key_size) throws JSchException {
try {
Class<? extends KeyPairGenEdDSA> c =
Class.forName(JSch.getConfig("keypairgen.eddsa")).asSubclass(KeyPairGenEdDSA.class);
KeyPairGenEdDSA keypairgen = c.getDeclaredConstructor().newInstance();
keypairgen.init(getJceName(), getKeySize());
pub_array = keypairgen.getPub();
prv_array = keypairgen.getPrv();
keypairgen = null;
} catch (Exception | NoClassDefFoundError e) {
throw new JSchException(e.toString(), e);
}
}
// These methods appear to be for writing keys to a file.
// And since writing VENDOR_OPENSSH_V1 isn't supported yet, have these methods fail.
@Override
byte[] getBegin() {
throw new UnsupportedOperationException();
}
@Override
byte[] getEnd() {
throw new UnsupportedOperationException();
}
@Override
byte[] getPrivateKey() {
throw new UnsupportedOperationException();
}
@Override
boolean parse(byte[] plain) {
if (vendor == VENDOR_PUTTY || vendor == VENDOR_PUTTY_V3) {
Buffer buf = new Buffer(plain);
buf.skip(plain.length);
try {
byte[][] tmp = buf.getBytes(1, "");
prv_array = tmp[0];
} catch (JSchException e) {
if (instLogger.getLogger().isEnabled(Logger.ERROR)) {
instLogger.getLogger().log(Logger.ERROR, "failed to parse key", e);
}
return false;
}
return true;
} else if (vendor == VENDOR_OPENSSH_V1) {
try {
// OPENSSH Key v1 Format
final Buffer buf = new Buffer(plain);
int checkInt1 = buf.getInt(); // uint32 checkint1
int checkInt2 = buf.getInt(); // uint32 checkint2
if (checkInt1 != checkInt2) {
throw new JSchException("check failed");
}
String keyType = Util.byte2str(buf.getString()); // string keytype
pub_array = buf.getString(); // public key
// OpenSSH stores private key in first half of string and duplicate copy of public key in
// second half of string
byte[] tmp = buf.getString(); // secret key (private key + public key)
prv_array = Arrays.copyOf(tmp, getKeySize());
publicKeyComment = Util.byte2str(buf.getString());
return true;
} catch (Exception e) {
if (instLogger.getLogger().isEnabled(Logger.ERROR)) {
instLogger.getLogger().log(Logger.ERROR, "failed to parse key", e);
}
return false;
}
} else if (vendor == VENDOR_PKCS8) {
try {
Class<? extends KeyPairGenEdDSA> c =
Class.forName(JSch.getConfig("keypairgen_fromprivate.eddsa"))
.asSubclass(KeyPairGenEdDSA.class);
KeyPairGenEdDSA keypairgen = c.getDeclaredConstructor().newInstance();
keypairgen.init(getJceName(), plain);
pub_array = keypairgen.getPub();
prv_array = keypairgen.getPrv();
return true;
} catch (Exception | NoClassDefFoundError e) {
if (instLogger.getLogger().isEnabled(Logger.ERROR)) {
instLogger.getLogger().log(Logger.ERROR, "failed to parse key", e);
}
return false;
}
} else {
if (instLogger.getLogger().isEnabled(Logger.ERROR)) {
instLogger.getLogger().log(Logger.ERROR, "failed to parse key");
}
return false;
}
}
@Override
public byte[] getPublicKeyBlob() {
byte[] foo = super.getPublicKeyBlob();
if (foo != null)
return foo;
if (pub_array == null)
return null;
byte[][] tmp = new byte[2][];
tmp[0] = getKeyTypeName();
tmp[1] = pub_array;
return Buffer.fromBytes(tmp).buffer;
}
@Override
byte[] getKeyTypeName() {
return Util.str2byte(getSshName());
}
@Override
public byte[] getSignature(byte[] data) {
return getSignature(data, getSshName());
}
@Override
public byte[] getSignature(byte[] data, String alg) {
try {
Class<? extends SignatureEdDSA> c =
Class.forName(JSch.getConfig(alg)).asSubclass(SignatureEdDSA.class);
SignatureEdDSA eddsa = c.getDeclaredConstructor().newInstance();
eddsa.init();
eddsa.setPrvKey(prv_array);
eddsa.update(data);
byte[] sig = eddsa.sign();
byte[][] tmp = new byte[2][];
tmp[0] = Util.str2byte(alg);
tmp[1] = sig;
return Buffer.fromBytes(tmp).buffer;
} catch (Exception | NoClassDefFoundError e) {
if (instLogger.getLogger().isEnabled(Logger.ERROR)) {
instLogger.getLogger().log(Logger.ERROR, "failed to generate signature", e);
}
}
return null;
}
@Override
public Signature getVerifier() {
return getVerifier(getSshName());
}
@Override
public Signature getVerifier(String alg) {
try {
Class<? extends SignatureEdDSA> c =
Class.forName(JSch.getConfig(alg)).asSubclass(SignatureEdDSA.class);
SignatureEdDSA eddsa = c.getDeclaredConstructor().newInstance();
eddsa.init();
if (pub_array == null && getPublicKeyBlob() != null) {
Buffer buf = new Buffer(getPublicKeyBlob());
buf.getString();
pub_array = buf.getString();
}
eddsa.setPubKey(pub_array);
return eddsa;
} catch (Exception | NoClassDefFoundError e) {
if (instLogger.getLogger().isEnabled(Logger.ERROR)) {
instLogger.getLogger().log(Logger.ERROR, "failed to create verifier", e);
}
}
return null;
}
@Override
public byte[] forSSHAgent() throws JSchException {
if (isEncrypted()) {
throw new JSchException("key is encrypted.");
}
Buffer buf = new Buffer();
buf.putString(getKeyTypeName());
buf.putString(pub_array);
byte[] tmp = new byte[prv_array.length + pub_array.length];
System.arraycopy(prv_array, 0, tmp, 0, prv_array.length);
System.arraycopy(pub_array, 0, tmp, prv_array.length, pub_array.length);
buf.putString(tmp);
buf.putString(Util.str2byte(publicKeyComment));
byte[] result = new byte[buf.getLength()];
buf.getByte(result, 0, result.length);
return result;
}
@Override
public void dispose() {
super.dispose();
Util.bzero(prv_array);
}
}

@ -0,0 +1,41 @@
/*
* Copyright (c) 2002-2018 ymnk, JCraft,Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted
* provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions
* and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other materials provided with
* the distribution.
*
* 3. The names of the authors may not be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL JCRAFT, INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.jcraft.jsch;
public interface KeyPairGenDSA {
void init(int key_size) throws Exception;
byte[] getX();
byte[] getY();
byte[] getP();
byte[] getQ();
byte[] getG();
}

@ -0,0 +1,37 @@
/*
* Copyright (c) 2015-2018 ymnk, JCraft,Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted
* provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions
* and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other materials provided with
* the distribution.
*
* 3. The names of the authors may not be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL JCRAFT, INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.jcraft.jsch;
public interface KeyPairGenECDSA {
void init(int key_size) throws Exception;
byte[] getD();
byte[] getR();
byte[] getS();
}

@ -0,0 +1,39 @@
/*
* Copyright (c) 2002-2018 ymnk, JCraft,Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted
* provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions
* and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other materials provided with
* the distribution.
*
* 3. The names of the authors may not be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL JCRAFT, INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.jcraft.jsch;
public interface KeyPairGenEdDSA {
void init(String name, int keylen) throws Exception;
byte[] getPub();
byte[] getPrv();
default void init(String name, byte[] prv) throws Exception {
throw new UnsupportedOperationException();
}
}

@ -0,0 +1,47 @@
/*
* Copyright (c) 2002-2018 ymnk, JCraft,Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted
* provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions
* and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other materials provided with
* the distribution.
*
* 3. The names of the authors may not be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL JCRAFT, INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.jcraft.jsch;
public interface KeyPairGenRSA {
void init(int key_size) throws Exception;
byte[] getD();
byte[] getE();
byte[] getN();
byte[] getC();
byte[] getEP();
byte[] getEQ();
byte[] getP();
byte[] getQ();
}

@ -0,0 +1,873 @@
/*
* Copyright (c) 2013-2018 ymnk, JCraft,Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted
* provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions
* and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other materials provided with
* the distribution.
*
* 3. The names of the authors may not be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL JCRAFT, INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.jcraft.jsch;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;
class KeyPairPKCS8 extends KeyPair {
private static final byte[] rsaEncryption = {(byte) 0x2a, (byte) 0x86, (byte) 0x48, (byte) 0x86,
(byte) 0xf7, (byte) 0x0d, (byte) 0x01, (byte) 0x01, (byte) 0x01};
private static final byte[] dsaEncryption =
{(byte) 0x2a, (byte) 0x86, (byte) 0x48, (byte) 0xce, (byte) 0x38, (byte) 0x04, (byte) 0x01};
private static final byte[] ecPublicKey =
{(byte) 0x2a, (byte) 0x86, (byte) 0x48, (byte) 0xce, (byte) 0x3d, (byte) 0x02, (byte) 0x01};
private static final byte[] ed25519 = {(byte) 0x2b, (byte) 0x65, (byte) 0x70};
private static final byte[] ed448 = {(byte) 0x2b, (byte) 0x65, (byte) 0x71};
private static final byte[] secp256r1 = {(byte) 0x2a, (byte) 0x86, (byte) 0x48, (byte) 0xce,
(byte) 0x3d, (byte) 0x03, (byte) 0x01, (byte) 0x07};
private static final byte[] secp384r1 =
{(byte) 0x2b, (byte) 0x81, (byte) 0x04, (byte) 0x00, (byte) 0x22};
private static final byte[] secp521r1 =
{(byte) 0x2b, (byte) 0x81, (byte) 0x04, (byte) 0x00, (byte) 0x23};
private static final byte[] pbes2 = {(byte) 0x2a, (byte) 0x86, (byte) 0x48, (byte) 0x86,
(byte) 0xf7, (byte) 0x0d, (byte) 0x01, (byte) 0x05, (byte) 0x0d};
private static final byte[] pbkdf2 = {(byte) 0x2a, (byte) 0x86, (byte) 0x48, (byte) 0x86,
(byte) 0xf7, (byte) 0x0d, (byte) 0x01, (byte) 0x05, (byte) 0x0c};
private static final byte[] scrypt = {(byte) 0x2b, (byte) 0x06, (byte) 0x01, (byte) 0x04,
(byte) 0x01, (byte) 0xda, (byte) 0x47, (byte) 0x04, (byte) 0x0b};
private static final byte[] hmacWithSha1 = {(byte) 0x2a, (byte) 0x86, (byte) 0x48, (byte) 0x86,
(byte) 0xf7, (byte) 0x0d, (byte) 0x02, (byte) 0x07};
private static final byte[] hmacWithSha224 = {(byte) 0x2a, (byte) 0x86, (byte) 0x48, (byte) 0x86,
(byte) 0xf7, (byte) 0x0d, (byte) 0x02, (byte) 0x08};
private static final byte[] hmacWithSha256 = {(byte) 0x2a, (byte) 0x86, (byte) 0x48, (byte) 0x86,
(byte) 0xf7, (byte) 0x0d, (byte) 0x02, (byte) 0x09};
private static final byte[] hmacWithSha384 = {(byte) 0x2a, (byte) 0x86, (byte) 0x48, (byte) 0x86,
(byte) 0xf7, (byte) 0x0d, (byte) 0x02, (byte) 0x0a};
private static final byte[] hmacWithSha512 = {(byte) 0x2a, (byte) 0x86, (byte) 0x48, (byte) 0x86,
(byte) 0xf7, (byte) 0x0d, (byte) 0x02, (byte) 0x0b};
private static final byte[] hmacWithSha512224 = {(byte) 0x2a, (byte) 0x86, (byte) 0x48,
(byte) 0x86, (byte) 0xf7, (byte) 0x0d, (byte) 0x02, (byte) 0x0c};
private static final byte[] hmacWithSha512256 = {(byte) 0x2a, (byte) 0x86, (byte) 0x48,
(byte) 0x86, (byte) 0xf7, (byte) 0x0d, (byte) 0x02, (byte) 0x0d};
private static final byte[] aes128cbc = {(byte) 0x60, (byte) 0x86, (byte) 0x48, (byte) 0x01,
(byte) 0x65, (byte) 0x03, (byte) 0x04, (byte) 0x01, (byte) 0x02};
private static final byte[] aes192cbc = {(byte) 0x60, (byte) 0x86, (byte) 0x48, (byte) 0x01,
(byte) 0x65, (byte) 0x03, (byte) 0x04, (byte) 0x01, (byte) 0x16};
private static final byte[] aes256cbc = {(byte) 0x60, (byte) 0x86, (byte) 0x48, (byte) 0x01,
(byte) 0x65, (byte) 0x03, (byte) 0x04, (byte) 0x01, (byte) 0x2a};
private static final byte[] descbc =
{(byte) 0x2b, (byte) 0x0e, (byte) 0x03, (byte) 0x02, (byte) 0x07};
private static final byte[] des3cbc = {(byte) 0x2a, (byte) 0x86, (byte) 0x48, (byte) 0x86,
(byte) 0xf7, (byte) 0x0d, (byte) 0x03, (byte) 0x07};
private static final byte[] rc2cbc = {(byte) 0x2a, (byte) 0x86, (byte) 0x48, (byte) 0x86,
(byte) 0xf7, (byte) 0x0d, (byte) 0x03, (byte) 0x02};
private static final byte[] rc5cbc = {(byte) 0x2a, (byte) 0x86, (byte) 0x48, (byte) 0x86,
(byte) 0xf7, (byte) 0x0d, (byte) 0x03, (byte) 0x09};
private static final byte[] pbeWithMD2AndDESCBC = {(byte) 0x2a, (byte) 0x86, (byte) 0x48,
(byte) 0x86, (byte) 0xf7, (byte) 0x0d, (byte) 0x01, (byte) 0x05, (byte) 0x01};
private static final byte[] pbeWithMD2AndRC2CBC = {(byte) 0x2a, (byte) 0x86, (byte) 0x48,
(byte) 0x86, (byte) 0xf7, (byte) 0x0d, (byte) 0x01, (byte) 0x05, (byte) 0x04};
private static final byte[] pbeWithMD5AndDESCBC = {(byte) 0x2a, (byte) 0x86, (byte) 0x48,
(byte) 0x86, (byte) 0xf7, (byte) 0x0d, (byte) 0x01, (byte) 0x05, (byte) 0x03};
private static final byte[] pbeWithMD5AndRC2CBC = {(byte) 0x2a, (byte) 0x86, (byte) 0x48,
(byte) 0x86, (byte) 0xf7, (byte) 0x0d, (byte) 0x01, (byte) 0x05, (byte) 0x06};
private static final byte[] pbeWithSHA1AndDESCBC = {(byte) 0x2a, (byte) 0x86, (byte) 0x48,
(byte) 0x86, (byte) 0xf7, (byte) 0x0d, (byte) 0x01, (byte) 0x05, (byte) 0x0a};
private static final byte[] pbeWithSHA1AndRC2CBC = {(byte) 0x2a, (byte) 0x86, (byte) 0x48,
(byte) 0x86, (byte) 0xf7, (byte) 0x0d, (byte) 0x01, (byte) 0x05, (byte) 0x0b};
private KeyPair kpair = null;
KeyPairPKCS8(JSch.InstanceLogger instLogger) {
super(instLogger);
}
@Override
void generate(int key_size) throws JSchException {}
private static final byte[] begin = Util.str2byte("-----BEGIN DSA PRIVATE KEY-----");
private static final byte[] end = Util.str2byte("-----END DSA PRIVATE KEY-----");
@Override
byte[] getBegin() {
return begin;
}
@Override
byte[] getEnd() {
return end;
}
@Override
byte[] getPrivateKey() {
return null;
}
@Override
boolean parse(byte[] plain) {
/*
* from RFC5208 PrivateKeyInfo ::= SEQUENCE { version Version, privateKeyAlgorithm
* PrivateKeyAlgorithmIdentifier, privateKey PrivateKey, attributes [0] IMPLICIT Attributes
* OPTIONAL } Version ::= INTEGER PrivateKeyAlgorithmIdentifier ::= AlgorithmIdentifier
* PrivateKey ::= OCTET STRING Attributes ::= SET OF Attribute }
*/
byte[] _data = null;
byte[] prv_array = null;
byte[] _plain = null;
KeyPair _key = null;
try {
ASN1[] contents;
ASN1 asn1 = new ASN1(plain);
if (!asn1.isSEQUENCE()) {
throw new ASN1Exception();
}
contents = asn1.getContents();
if (contents.length < 3 || contents.length > 4) {
throw new ASN1Exception();
}
if (!contents[0].isINTEGER()) {
throw new ASN1Exception();
}
if (!contents[1].isSEQUENCE()) {
throw new ASN1Exception();
}
if (!contents[2].isOCTETSTRING()) {
throw new ASN1Exception();
}
// attributes [0] IMPLICIT Attributes OPTIONAL
if (contents.length > 3 && !contents[3].isCONTEXTCONSTRUCTED(0)) {
throw new ASN1Exception();
}
int version = parseASN1IntegerAsInt(contents[0].getContent());
if (version != 0) {
throw new ASN1Exception();
}
ASN1 privateKeyAlgorithm = contents[1];
ASN1 privateKey = contents[2];
contents = privateKeyAlgorithm.getContents();
if (contents.length == 0) {
throw new ASN1Exception();
}
if (!contents[0].isOBJECT()) {
throw new ASN1Exception();
}
byte[] privateKeyAlgorithmID = contents[0].getContent();
_data = privateKey.getContent();
KeyPair _kpair = null;
if (Util.array_equals(privateKeyAlgorithmID, rsaEncryption)) {
if (contents.length != 2) {
throw new ASN1Exception();
}
if (!contents[1].isNULL()) {
throw new ASN1Exception();
}
_kpair = new KeyPairRSA(instLogger);
_kpair.copy(this);
if (_kpair.parse(_data)) {
kpair = _kpair;
return true;
} else {
throw new JSchException("failed to parse RSA");
}
} else if (Util.array_equals(privateKeyAlgorithmID, dsaEncryption)) {
List<byte[]> values = new ArrayList<>(3);
if (contents.length > 1 && contents[1].isSEQUENCE()) {
contents = contents[1].getContents();
if (contents.length != 3) {
throw new ASN1Exception();
}
if (!contents[0].isINTEGER()) {
throw new ASN1Exception();
}
if (!contents[1].isINTEGER()) {
throw new ASN1Exception();
}
if (!contents[2].isINTEGER()) {
throw new ASN1Exception();
}
values.add(contents[0].getContent());
values.add(contents[1].getContent());
values.add(contents[2].getContent());
}
asn1 = new ASN1(_data);
if (values.size() == 0) { // embedded DSA parameters format
/*
* SEQUENCE SEQUENCE INTEGER // P_array INTEGER // Q_array INTEGER // G_array INTEGER //
* prv_array
*/
if (!asn1.isSEQUENCE()) {
throw new ASN1Exception();
}
contents = asn1.getContents();
if (contents.length != 2) {
throw new ASN1Exception();
}
if (!contents[0].isSEQUENCE()) {
throw new ASN1Exception();
}
if (!contents[1].isINTEGER()) {
throw new ASN1Exception();
}
prv_array = contents[1].getContent();
contents = contents[0].getContents();
if (contents.length != 3) {
throw new ASN1Exception();
}
if (!contents[0].isINTEGER()) {
throw new ASN1Exception();
}
if (!contents[1].isINTEGER()) {
throw new ASN1Exception();
}
if (!contents[2].isINTEGER()) {
throw new ASN1Exception();
}
values.add(contents[0].getContent());
values.add(contents[1].getContent());
values.add(contents[2].getContent());
} else {
/*
* INTEGER // prv_array
*/
if (!asn1.isINTEGER()) {
throw new ASN1Exception();
}
prv_array = asn1.getContent();
}
byte[] P_array = values.get(0);
byte[] Q_array = values.get(1);
byte[] G_array = values.get(2);
// Y = g^X mode p
byte[] pub_array = (new BigInteger(G_array))
.modPow(new BigInteger(prv_array), new BigInteger(P_array)).toByteArray();
_key = new KeyPairDSA(instLogger, P_array, Q_array, G_array, pub_array, prv_array);
_plain = _key.getPrivateKey();
_kpair = new KeyPairDSA(instLogger);
_kpair.copy(this);
if (_kpair.parse(_plain)) {
kpair = _kpair;
return true;
} else {
throw new JSchException("failed to parse DSA");
}
} else if (Util.array_equals(privateKeyAlgorithmID, ecPublicKey)) {
if (contents.length != 2) {
throw new ASN1Exception();
}
if (!contents[1].isOBJECT()) {
throw new ASN1Exception();
}
byte[] namedCurve = contents[1].getContent();
byte[] name;
if (!Util.array_equals(namedCurve, secp256r1)) {
name = Util.str2byte("nistp256");
} else if (!Util.array_equals(namedCurve, secp384r1)) {
name = Util.str2byte("nistp384");
} else if (!Util.array_equals(namedCurve, secp521r1)) {
name = Util.str2byte("nistp521");
} else {
throw new JSchException("unsupported named curve oid: " + Util.toHex(namedCurve));
}
ASN1 ecPrivateKey = new ASN1(_data);
if (!ecPrivateKey.isSEQUENCE()) {
throw new ASN1Exception();
}
// ECPrivateKey ::= SEQUENCE {
// version INTEGER { ecPrivkeyVer1(1) } (ecPrivkeyVer1),
// privateKey OCTET STRING,
// parameters [0] ECParameters {{ NamedCurve }} OPTIONAL,
// publicKey [1] BIT STRING OPTIONAL
// }
contents = ecPrivateKey.getContents();
if (contents.length < 3 || contents.length > 4) {
throw new ASN1Exception();
}
if (!contents[0].isINTEGER()) {
throw new ASN1Exception();
}
if (!contents[1].isOCTETSTRING()) {
throw new ASN1Exception();
}
version = parseASN1IntegerAsInt(contents[0].getContent());
if (version != 1) {
throw new ASN1Exception();
}
prv_array = contents[1].getContent();
// publicKey is required here since there is no other way to derive it.
ASN1 publicKey;
if (contents.length == 3) {
publicKey = contents[2];
} else {
publicKey = contents[3];
// parameters [0] ECParameters {{ NamedCurve }} OPTIONAL
if (!contents[2].isCONTEXTCONSTRUCTED(0)) {
throw new ASN1Exception();
}
// NamedCurve isn't required here since it is already known.
// But if it is included, they should be the same...
ASN1[] goo = contents[2].getContents();
if (goo.length != 1) {
throw new ASN1Exception();
}
if (!goo[0].isOBJECT()) {
throw new ASN1Exception();
}
if (!Util.array_equals(goo[0].getContent(), namedCurve)) {
throw new ASN1Exception();
}
}
// publicKey [1] BIT STRING OPTIONAL
if (!publicKey.isCONTEXTCONSTRUCTED(1)) {
throw new ASN1Exception();
}
contents = publicKey.getContents();
if (contents.length != 1) {
throw new ASN1Exception();
}
if (!contents[0].isBITSTRING()) {
throw new ASN1Exception();
}
byte[] Q_array = contents[0].getContent();
byte[][] tmp = KeyPairECDSA.fromPoint(Q_array);
byte[] r_array = tmp[0];
byte[] s_array = tmp[1];
_key = new KeyPairECDSA(instLogger, name, r_array, s_array, prv_array);
_plain = _key.getPrivateKey();
_kpair = new KeyPairECDSA(instLogger);
_kpair.copy(this);
if (_kpair.parse(_plain)) {
kpair = _kpair;
return true;
} else {
throw new JSchException("failed to parse ECDSA");
}
} else if (Util.array_equals(privateKeyAlgorithmID, ed25519)
|| Util.array_equals(privateKeyAlgorithmID, ed448)) {
if (contents.length != 1) {
throw new ASN1Exception();
}
ASN1 curvePrivateKey = new ASN1(_data);
if (!curvePrivateKey.isOCTETSTRING()) {
throw new ASN1Exception();
}
prv_array = curvePrivateKey.getContent();
if (Util.array_equals(privateKeyAlgorithmID, ed25519)) {
_kpair = new KeyPairEd25519(instLogger);
} else {
_kpair = new KeyPairEd448(instLogger);
}
_kpair.copy(this);
if (_kpair.parse(prv_array)) {
kpair = _kpair;
return true;
} else {
throw new JSchException("failed to parse EdDSA");
}
} else {
throw new JSchException(
"unsupported privateKeyAlgorithm oid: " + Util.toHex(privateKeyAlgorithmID));
}
} catch (ASN1Exception e) {
if (instLogger.getLogger().isEnabled(Logger.ERROR)) {
instLogger.getLogger().log(Logger.ERROR, "PKCS8: failed to parse key: ASN1 parsing error",
e);
}
return false;
} catch (Exception e) {
if (instLogger.getLogger().isEnabled(Logger.ERROR)) {
instLogger.getLogger().log(Logger.ERROR, "PKCS8: failed to parse key: " + e.getMessage(),
e);
}
return false;
} finally {
Util.bzero(_data);
Util.bzero(prv_array);
Util.bzero(_plain);
if (_key != null) {
_key.dispose();
}
}
}
@Override
public byte[] getPublicKeyBlob() {
if (kpair != null) {
return kpair.getPublicKeyBlob();
} else {
return super.getPublicKeyBlob();
}
}
@Override
byte[] getKeyTypeName() {
if (kpair != null) {
return kpair.getKeyTypeName();
} else {
return new byte[0];
}
}
@Override
public int getKeyType() {
if (kpair != null) {
return kpair.getKeyType();
} else {
return UNKNOWN;
}
}
@Override
public int getKeySize() {
return kpair.getKeySize();
}
@Override
public byte[] getSignature(byte[] data) {
return kpair.getSignature(data);
}
@Override
public byte[] getSignature(byte[] data, String alg) {
return kpair.getSignature(data, alg);
}
@Override
public Signature getVerifier() {
return kpair.getVerifier();
}
@Override
public Signature getVerifier(String alg) {
return kpair.getVerifier(alg);
}
@Override
public byte[] forSSHAgent() throws JSchException {
return kpair.forSSHAgent();
}
@Override
public boolean decrypt(byte[] _passphrase) {
if (!isEncrypted()) {
return true;
}
if (_passphrase == null) {
return !isEncrypted();
}
/*
* SEQUENCE SEQUENCE OBJECT :PBES2 SEQUENCE SEQUENCE OBJECT :PBKDF2 SEQUENCE OCTET STRING [HEX
* DUMP]:E4E24ADC9C00BD4D INTEGER :0800 SEQUENCE OBJECT :aes-128-cbc OCTET STRING [HEX
* DUMP]:5B66E6B3BF03944C92317BC370CC3AD0 OCTET STRING [HEX DUMP]:
*
* or
*
* SEQUENCE SEQUENCE OBJECT :PBES2 SEQUENCE SEQUENCE OBJECT :PBKDF2 SEQUENCE OCTET STRING [HEX
* DUMP]:E4E24ADC9C00BD4D INTEGER :0800 SEQUENCE OBJECT :hmacWithSHA256 NULL SEQUENCE OBJECT
* :aes-128-cbc OCTET STRING [HEX DUMP]:5B66E6B3BF03944C92317BC370CC3AD0 OCTET STRING [HEX
* DUMP]:
*
* or
*
* SEQUENCE SEQUENCE OBJECT :pbeWithMD5AndDES-CBC SEQUENCE OCTET STRING [HEX
* DUMP]:DBF75ECB69E3C0FC INTEGER :0800 OCTET STRING [HEX DUMP]
*/
byte[] _data = null;
byte[] key = null;
byte[] plain = null;
try {
ASN1[] contents;
ASN1 asn1 = new ASN1(data);
if (!asn1.isSEQUENCE()) {
throw new ASN1Exception();
}
contents = asn1.getContents();
if (contents.length != 2) {
throw new ASN1Exception();
}
if (!contents[0].isSEQUENCE()) {
throw new ASN1Exception();
}
if (!contents[1].isOCTETSTRING()) {
throw new ASN1Exception();
}
_data = contents[1].getContent();
ASN1 pbes = contents[0];
contents = pbes.getContents();
if (contents.length != 2) {
throw new ASN1Exception();
}
if (!contents[0].isOBJECT()) {
throw new ASN1Exception();
}
if (!contents[1].isSEQUENCE()) {
throw new ASN1Exception();
}
byte[] pbesid = contents[0].getContent();
ASN1 pbesparam = contents[1];
String kdfname;
KDF kdfinst;
byte[] encryptfuncid;
ASN1 encryptparams;
if (Util.array_equals(pbesid, pbes2)) {
contents = pbesparam.getContents();
if (contents.length != 2) {
throw new ASN1Exception();
}
ASN1 kdf = contents[0];
ASN1 encryptfunc = contents[1];
if (!kdf.isSEQUENCE()) {
throw new ASN1Exception();
}
if (!encryptfunc.isSEQUENCE()) {
throw new ASN1Exception();
}
contents = encryptfunc.getContents();
if (contents.length != 2) {
throw new ASN1Exception();
}
if (!contents[0].isOBJECT()) {
throw new ASN1Exception();
}
encryptfuncid = contents[0].getContent();
encryptparams = contents[1];
contents = kdf.getContents();
if (contents.length != 2) {
throw new ASN1Exception();
}
if (!contents[0].isOBJECT()) {
throw new ASN1Exception();
}
if (!contents[1].isSEQUENCE()) {
throw new ASN1Exception();
}
byte[] kdfid = contents[0].getContent();
if (Util.array_equals(kdfid, pbkdf2)) {
ASN1 pbkdf2func = contents[1];
if (!pbkdf2func.isSEQUENCE()) {
throw new ASN1Exception();
}
ASN1 prf = null;
contents = pbkdf2func.getContents();
if (contents.length < 2 || contents.length > 4) {
throw new ASN1Exception();
}
if (!contents[0].isOCTETSTRING()) {
throw new ASN1Exception();
}
if (!contents[1].isINTEGER()) {
throw new ASN1Exception();
}
if (contents.length == 4) {
if (!contents[2].isINTEGER()) {
throw new ASN1Exception();
}
if (!contents[3].isSEQUENCE()) {
throw new ASN1Exception();
}
prf = contents[3];
} else if (contents.length == 3) {
if (contents[2].isSEQUENCE()) {
prf = contents[2];
} else if (!contents[2].isINTEGER()) {
throw new ASN1Exception();
}
}
byte[] prfid = null;
byte[] salt = contents[0].getContent();
int iterations = parseASN1IntegerAsInt(contents[1].getContent());
if (prf != null) {
contents = prf.getContents();
if (contents.length != 2) {
throw new ASN1Exception();
}
if (!contents[0].isOBJECT()) {
throw new ASN1Exception();
}
if (!contents[1].isNULL()) {
throw new ASN1Exception();
}
prfid = contents[0].getContent();
}
kdfname = getPBKDF2Name(prfid);
PBKDF2 pbkdf2kdf = getPBKDF2(kdfname);
pbkdf2kdf.init(salt, iterations);
kdfinst = pbkdf2kdf;
} else if (Util.array_equals(kdfid, scrypt)) {
contents = contents[1].getContents();
if (contents.length < 4 || contents.length > 5) {
throw new ASN1Exception();
}
if (!contents[0].isOCTETSTRING()) {
throw new ASN1Exception();
}
if (!contents[1].isINTEGER()) {
throw new ASN1Exception();
}
if (!contents[2].isINTEGER()) {
throw new ASN1Exception();
}
if (!contents[3].isINTEGER()) {
throw new ASN1Exception();
}
if (contents.length > 4 && !contents[4].isINTEGER()) {
throw new ASN1Exception();
}
byte[] salt = contents[0].getContent();
int cost = parseASN1IntegerAsInt(contents[1].getContent());
int blocksize = parseASN1IntegerAsInt(contents[2].getContent());
int parallel = parseASN1IntegerAsInt(contents[3].getContent());
kdfname = "scrypt";
SCrypt scryptkdf = getSCrypt();
scryptkdf.init(salt, cost, blocksize, parallel);
kdfinst = scryptkdf;
} else {
throw new JSchException("unsupported kdf oid: " + Util.toHex(kdfid));
}
} else {
String message;
if (Util.array_equals(pbesid, pbeWithMD2AndDESCBC)) {
message = "pbeWithMD2AndDES-CBC unsupported";
} else if (Util.array_equals(pbesid, pbeWithMD2AndRC2CBC)) {
message = "pbeWithMD2AndRC2-CBC unsupported";
} else if (Util.array_equals(pbesid, pbeWithMD5AndDESCBC)) {
message = "pbeWithMD5AndDES-CBC unsupported";
} else if (Util.array_equals(pbesid, pbeWithMD5AndRC2CBC)) {
message = "pbeWithMD5AndRC2-CBC unsupported";
} else if (Util.array_equals(pbesid, pbeWithSHA1AndDESCBC)) {
message = "pbeWithSHA1AndDES-CBC unsupported";
} else if (Util.array_equals(pbesid, pbeWithSHA1AndRC2CBC)) {
message = "pbeWithSHA1AndRC2-CBC unsupported";
} else {
message = "unsupported encryption oid: " + Util.toHex(pbesid);
}
throw new JSchException(message);
}
byte[][] ivp = new byte[1][];
Cipher cipher = getCipher(encryptfuncid, encryptparams, ivp);
byte[] iv = ivp[0];
key = kdfinst.getKey(_passphrase, cipher.getBlockSize());
if (key == null) {
throw new JSchException("failed to generate key from KDF " + kdfname);
}
cipher.init(Cipher.DECRYPT_MODE, key, iv);
plain = new byte[_data.length];
cipher.update(_data, 0, _data.length, plain, 0);
if (parse(plain)) {
encrypted = false;
Util.bzero(data);
return true;
} else {
throw new JSchException("failed to parse decrypted key");
}
} catch (ASN1Exception e) {
if (instLogger.getLogger().isEnabled(Logger.ERROR)) {
instLogger.getLogger().log(Logger.ERROR, "PKCS8: failed to decrypt key: ASN1 parsing error",
e);
}
return false;
} catch (Exception e) {
if (instLogger.getLogger().isEnabled(Logger.ERROR)) {
instLogger.getLogger().log(Logger.ERROR, "PKCS8: failed to decrypt key: " + e.getMessage(),
e);
}
return false;
} finally {
Util.bzero(_data);
Util.bzero(key);
Util.bzero(plain);
}
}
static String getPBKDF2Name(byte[] id) throws JSchException {
String name = null;
if (id == null || Util.array_equals(id, hmacWithSha1)) {
name = "pbkdf2-hmac-sha1";
} else if (Util.array_equals(id, hmacWithSha224)) {
name = "pbkdf2-hmac-sha224";
} else if (Util.array_equals(id, hmacWithSha256)) {
name = "pbkdf2-hmac-sha256";
} else if (Util.array_equals(id, hmacWithSha384)) {
name = "pbkdf2-hmac-sha384";
} else if (Util.array_equals(id, hmacWithSha512)) {
name = "pbkdf2-hmac-sha512";
} else if (Util.array_equals(id, hmacWithSha512224)) {
name = "pbkdf2-hmac-sha512-224";
} else if (Util.array_equals(id, hmacWithSha512256)) {
name = "pbkdf2-hmac-sha512-256";
}
if (name == null) {
throw new JSchException("unsupported pbkdf2 function oid: " + Util.toHex(id));
}
return name;
}
static PBKDF2 getPBKDF2(String name) throws JSchException {
try {
Class<? extends PBKDF2> c = Class.forName(JSch.getConfig(name)).asSubclass(PBKDF2.class);
return c.getDeclaredConstructor().newInstance();
} catch (Exception e) {
throw new JSchException(name + " is not supported", e);
}
}
static SCrypt getSCrypt() throws JSchException {
try {
Class<? extends SCrypt> c = Class.forName(JSch.getConfig("scrypt")).asSubclass(SCrypt.class);
return c.getDeclaredConstructor().newInstance();
} catch (Exception e) {
throw new JSchException("scrypt is not supported", e);
}
}
static Cipher getCipher(byte[] id, ASN1 encryptparams, byte[][] ivp) throws Exception {
String name = null;
if (Util.array_equals(id, aes128cbc)) {
name = "aes128-cbc";
} else if (Util.array_equals(id, aes192cbc)) {
name = "aes192-cbc";
} else if (Util.array_equals(id, aes256cbc)) {
name = "aes256-cbc";
} else if (Util.array_equals(id, descbc)) {
throw new JSchException("unsupported cipher function: des-cbc");
} else if (Util.array_equals(id, des3cbc)) {
throw new JSchException("unsupported cipher function: 3des-cbc");
} else if (Util.array_equals(id, rc2cbc)) {
throw new JSchException("unsupported cipher function: rc2-cbc");
} else if (Util.array_equals(id, rc5cbc)) {
throw new JSchException("unsupported cipher function: rc5-cbc");
}
if (name == null) {
throw new JSchException("unsupported cipher function oid: " + Util.toHex(id));
}
if (!encryptparams.isOCTETSTRING()) {
throw new ASN1Exception();
}
ivp[0] = encryptparams.getContent();
try {
Class<? extends Cipher> c = Class.forName(JSch.getConfig(name)).asSubclass(Cipher.class);
return c.getDeclaredConstructor().newInstance();
} catch (Exception e) {
throw new JSchException(name + " is not supported", e);
}
}
static int parseASN1IntegerAsInt(byte[] content) {
BigInteger b = new BigInteger(content);
// https://github.com/mwiede/jsch/issues/392 not using intValueExact() because of Android
// incompatibility.
if (b.bitLength() <= 31) {
return b.intValue();
} else {
throw new ArithmeticException("BigInteger out of int range");
}
}
}

@ -0,0 +1,506 @@
/*
* Copyright (c) 2002-2018 ymnk, JCraft,Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted
* provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions
* and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other materials provided with
* the distribution.
*
* 3. The names of the authors may not be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL JCRAFT, INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.jcraft.jsch;
import java.math.BigInteger;
class KeyPairRSA extends KeyPair {
private byte[] n_array; // modulus p multiply q
private byte[] pub_array; // e
private byte[] prv_array; // d e^-1 mod (p-1)(q-1)
private byte[] p_array; // prime p
private byte[] q_array; // prime q
private byte[] ep_array; // prime exponent p dmp1 == prv mod (p-1)
private byte[] eq_array; // prime exponent q dmq1 == prv mod (q-1)
private byte[] c_array; // coefficient iqmp == modinv(q, p) == q^-1 mod p
private int key_size = 1024;
KeyPairRSA(JSch.InstanceLogger instLogger) {
this(instLogger, null, null, null);
}
KeyPairRSA(JSch.InstanceLogger instLogger, byte[] n_array, byte[] pub_array, byte[] prv_array) {
super(instLogger);
this.n_array = n_array;
this.pub_array = pub_array;
this.prv_array = prv_array;
if (n_array != null) {
key_size = (new BigInteger(n_array)).bitLength();
}
}
@Override
void generate(int key_size) throws JSchException {
this.key_size = key_size;
try {
Class<? extends KeyPairGenRSA> c =
Class.forName(JSch.getConfig("keypairgen.rsa")).asSubclass(KeyPairGenRSA.class);
KeyPairGenRSA keypairgen = c.getDeclaredConstructor().newInstance();
keypairgen.init(key_size);
pub_array = keypairgen.getE();
prv_array = keypairgen.getD();
n_array = keypairgen.getN();
p_array = keypairgen.getP();
q_array = keypairgen.getQ();
ep_array = keypairgen.getEP();
eq_array = keypairgen.getEQ();
c_array = keypairgen.getC();
keypairgen = null;
} catch (Exception e) {
throw new JSchException(e.toString(), e);
}
}
private static final byte[] begin = Util.str2byte("-----BEGIN RSA PRIVATE KEY-----");
private static final byte[] end = Util.str2byte("-----END RSA PRIVATE KEY-----");
@Override
byte[] getBegin() {
return begin;
}
@Override
byte[] getEnd() {
return end;
}
@Override
byte[] getPrivateKey() {
int content = 1 + countLength(1) + 1 + // INTEGER
1 + countLength(n_array.length) + n_array.length + // INTEGER N
1 + countLength(pub_array.length) + pub_array.length + // INTEGER pub
1 + countLength(prv_array.length) + prv_array.length + // INTEGER prv
1 + countLength(p_array.length) + p_array.length + // INTEGER p
1 + countLength(q_array.length) + q_array.length + // INTEGER q
1 + countLength(ep_array.length) + ep_array.length + // INTEGER ep
1 + countLength(eq_array.length) + eq_array.length + // INTEGER eq
1 + countLength(c_array.length) + c_array.length; // INTEGER c
int total = 1 + countLength(content) + content; // SEQUENCE
byte[] plain = new byte[total];
int index = 0;
index = writeSEQUENCE(plain, index, content);
index = writeINTEGER(plain, index, new byte[1]); // 0
index = writeINTEGER(plain, index, n_array);
index = writeINTEGER(plain, index, pub_array);
index = writeINTEGER(plain, index, prv_array);
index = writeINTEGER(plain, index, p_array);
index = writeINTEGER(plain, index, q_array);
index = writeINTEGER(plain, index, ep_array);
index = writeINTEGER(plain, index, eq_array);
index = writeINTEGER(plain, index, c_array);
return plain;
}
@Override
boolean parse(byte[] plain) {
try {
int index = 0;
int length = 0;
if (vendor == VENDOR_PUTTY || vendor == VENDOR_PUTTY_V3) {
Buffer buf = new Buffer(plain);
buf.skip(plain.length);
try {
byte[][] tmp = buf.getBytes(4, "");
prv_array = tmp[0];
p_array = tmp[1];
q_array = tmp[2];
c_array = tmp[3];
} catch (JSchException e) {
if (instLogger.getLogger().isEnabled(Logger.ERROR)) {
instLogger.getLogger().log(Logger.ERROR, "failed to parse key", e);
}
return false;
}
getEPArray();
getEQArray();
return true;
}
if (vendor == VENDOR_FSECURE) {
if (plain[index] != 0x30) { // FSecure
Buffer buf = new Buffer(plain);
pub_array = buf.getMPIntBits();
prv_array = buf.getMPIntBits();
n_array = buf.getMPIntBits();
byte[] u_array = buf.getMPIntBits();
p_array = buf.getMPIntBits();
q_array = buf.getMPIntBits();
if (n_array != null) {
key_size = (new BigInteger(n_array)).bitLength();
}
getEPArray();
getEQArray();
getCArray();
return true;
}
if (instLogger.getLogger().isEnabled(Logger.ERROR)) {
instLogger.getLogger().log(Logger.ERROR, "failed to parse key");
}
return false;
}
// OPENSSH Key v1 Format
if (vendor == VENDOR_OPENSSH_V1) {
final Buffer prvKEyBuffer = new Buffer(plain);
int checkInt1 = prvKEyBuffer.getInt(); // uint32 checkint1
int checkInt2 = prvKEyBuffer.getInt(); // uint32 checkint2
if (checkInt1 != checkInt2) {
throw new JSchException("check failed");
}
String keyType = Util.byte2str(prvKEyBuffer.getString()); // string keytype
n_array = prvKEyBuffer.getMPInt(); // Modulus
pub_array = prvKEyBuffer.getMPInt(); // Public Exponent
prv_array = prvKEyBuffer.getMPInt(); // Private Exponent
c_array = prvKEyBuffer.getMPInt(); // iqmp (q^-1 mod p)
p_array = prvKEyBuffer.getMPInt(); // p (Prime 1)
q_array = prvKEyBuffer.getMPInt(); // q (Prime 2)
if (n_array != null) {
key_size = (new BigInteger(n_array)).bitLength();
}
publicKeyComment = Util.byte2str(prvKEyBuffer.getString());
getEPArray();
getEQArray();
return true;
}
/*
* Key must be in the following ASN.1 DER encoding, RSAPrivateKey ::= SEQUENCE { version
* Version, modulus INTEGER, -- n publicExponent INTEGER, -- e privateExponent INTEGER, -- d
* prime1 INTEGER, -- p prime2 INTEGER, -- q exponent1 INTEGER, -- d mod (p-1) exponent2
* INTEGER, -- d mod (q-1) coefficient INTEGER, -- (inverse of q) mod p otherPrimeInfos
* OtherPrimeInfos OPTIONAL }
*/
index++; // SEQUENCE
length = plain[index++] & 0xff;
if ((length & 0x80) != 0) {
int foo = length & 0x7f;
length = 0;
while (foo-- > 0) {
length = (length << 8) + (plain[index++] & 0xff);
}
}
if (plain[index] != 0x02)
return false;
index++; // INTEGER
length = plain[index++] & 0xff;
if ((length & 0x80) != 0) {
int foo = length & 0x7f;
length = 0;
while (foo-- > 0) {
length = (length << 8) + (plain[index++] & 0xff);
}
}
index += length;
index++;
length = plain[index++] & 0xff;
if ((length & 0x80) != 0) {
int foo = length & 0x7f;
length = 0;
while (foo-- > 0) {
length = (length << 8) + (plain[index++] & 0xff);
}
}
n_array = new byte[length];
System.arraycopy(plain, index, n_array, 0, length);
index += length;
index++;
length = plain[index++] & 0xff;
if ((length & 0x80) != 0) {
int foo = length & 0x7f;
length = 0;
while (foo-- > 0) {
length = (length << 8) + (plain[index++] & 0xff);
}
}
pub_array = new byte[length];
System.arraycopy(plain, index, pub_array, 0, length);
index += length;
index++;
length = plain[index++] & 0xff;
if ((length & 0x80) != 0) {
int foo = length & 0x7f;
length = 0;
while (foo-- > 0) {
length = (length << 8) + (plain[index++] & 0xff);
}
}
prv_array = new byte[length];
System.arraycopy(plain, index, prv_array, 0, length);
index += length;
index++;
length = plain[index++] & 0xff;
if ((length & 0x80) != 0) {
int foo = length & 0x7f;
length = 0;
while (foo-- > 0) {
length = (length << 8) + (plain[index++] & 0xff);
}
}
p_array = new byte[length];
System.arraycopy(plain, index, p_array, 0, length);
index += length;
index++;
length = plain[index++] & 0xff;
if ((length & 0x80) != 0) {
int foo = length & 0x7f;
length = 0;
while (foo-- > 0) {
length = (length << 8) + (plain[index++] & 0xff);
}
}
q_array = new byte[length];
System.arraycopy(plain, index, q_array, 0, length);
index += length;
index++;
length = plain[index++] & 0xff;
if ((length & 0x80) != 0) {
int foo = length & 0x7f;
length = 0;
while (foo-- > 0) {
length = (length << 8) + (plain[index++] & 0xff);
}
}
ep_array = new byte[length];
System.arraycopy(plain, index, ep_array, 0, length);
index += length;
index++;
length = plain[index++] & 0xff;
if ((length & 0x80) != 0) {
int foo = length & 0x7f;
length = 0;
while (foo-- > 0) {
length = (length << 8) + (plain[index++] & 0xff);
}
}
eq_array = new byte[length];
System.arraycopy(plain, index, eq_array, 0, length);
index += length;
index++;
length = plain[index++] & 0xff;
if ((length & 0x80) != 0) {
int foo = length & 0x7f;
length = 0;
while (foo-- > 0) {
length = (length << 8) + (plain[index++] & 0xff);
}
}
c_array = new byte[length];
System.arraycopy(plain, index, c_array, 0, length);
index += length;
if (n_array != null) {
key_size = (new BigInteger(n_array)).bitLength();
}
} catch (Exception e) {
if (instLogger.getLogger().isEnabled(Logger.ERROR)) {
instLogger.getLogger().log(Logger.ERROR, "failed to parse key", e);
}
return false;
}
return true;
}
@Override
public byte[] getPublicKeyBlob() {
byte[] foo = super.getPublicKeyBlob();
if (foo != null)
return foo;
if (pub_array == null)
return null;
byte[][] tmp = new byte[3][];
tmp[0] = sshrsa;
tmp[1] = pub_array;
tmp[2] = n_array;
return Buffer.fromBytes(tmp).buffer;
}
private static final byte[] sshrsa = Util.str2byte("ssh-rsa");
@Override
byte[] getKeyTypeName() {
return sshrsa;
}
@Override
public int getKeyType() {
return RSA;
}
@Override
public int getKeySize() {
return key_size;
}
@Override
public byte[] getSignature(byte[] data) {
return getSignature(data, "ssh-rsa");
}
@Override
public byte[] getSignature(byte[] data, String alg) {
try {
Class<? extends SignatureRSA> c =
Class.forName(JSch.getConfig(alg)).asSubclass(SignatureRSA.class);
SignatureRSA rsa = c.getDeclaredConstructor().newInstance();
rsa.init();
rsa.setPrvKey(prv_array, n_array);
rsa.update(data);
byte[] sig = rsa.sign();
byte[][] tmp = new byte[2][];
tmp[0] = Util.str2byte(alg);
tmp[1] = sig;
return Buffer.fromBytes(tmp).buffer;
} catch (Exception e) {
if (instLogger.getLogger().isEnabled(Logger.ERROR)) {
instLogger.getLogger().log(Logger.ERROR, "failed to generate signature", e);
}
}
return null;
}
@Override
public Signature getVerifier() {
return getVerifier("ssh-rsa");
}
@Override
public Signature getVerifier(String alg) {
try {
Class<? extends SignatureRSA> c =
Class.forName(JSch.getConfig(alg)).asSubclass(SignatureRSA.class);
SignatureRSA rsa = c.getDeclaredConstructor().newInstance();
rsa.init();
if (pub_array == null && n_array == null && getPublicKeyBlob() != null) {
Buffer buf = new Buffer(getPublicKeyBlob());
buf.getString();
pub_array = buf.getString();
n_array = buf.getString();
}
rsa.setPubKey(pub_array, n_array);
return rsa;
} catch (Exception e) {
if (instLogger.getLogger().isEnabled(Logger.ERROR)) {
instLogger.getLogger().log(Logger.ERROR, "failed to create verifier", e);
}
}
return null;
}
static KeyPair fromSSHAgent(JSch.InstanceLogger instLogger, Buffer buf) throws JSchException {
byte[][] tmp = buf.getBytes(8, "invalid key format");
byte[] n_array = tmp[1];
byte[] pub_array = tmp[2];
byte[] prv_array = tmp[3];
KeyPairRSA kpair = new KeyPairRSA(instLogger, n_array, pub_array, prv_array);
kpair.c_array = tmp[4]; // iqmp
kpair.p_array = tmp[5];
kpair.q_array = tmp[6];
kpair.publicKeyComment = Util.byte2str(tmp[7]);
kpair.vendor = VENDOR_OPENSSH;
return kpair;
}
@Override
public byte[] forSSHAgent() throws JSchException {
if (isEncrypted()) {
throw new JSchException("key is encrypted.");
}
Buffer buf = new Buffer();
buf.putString(sshrsa);
buf.putString(n_array);
buf.putString(pub_array);
buf.putString(prv_array);
buf.putString(getCArray());
buf.putString(p_array);
buf.putString(q_array);
buf.putString(Util.str2byte(publicKeyComment));
byte[] result = new byte[buf.getLength()];
buf.getByte(result, 0, result.length);
return result;
}
private byte[] getEPArray() {
if (ep_array == null) {
ep_array = (new BigInteger(prv_array)).mod(new BigInteger(p_array).subtract(BigInteger.ONE))
.toByteArray();
}
return ep_array;
}
private byte[] getEQArray() {
if (eq_array == null) {
eq_array = (new BigInteger(prv_array)).mod(new BigInteger(q_array).subtract(BigInteger.ONE))
.toByteArray();
}
return eq_array;
}
private byte[] getCArray() {
if (c_array == null) {
c_array = (new BigInteger(q_array)).modInverse(new BigInteger(p_array)).toByteArray();
}
return c_array;
}
@Override
public void dispose() {
super.dispose();
Util.bzero(prv_array);
}
}

@ -0,0 +1,648 @@
/*
* Copyright (c) 2002-2018 ymnk, JCraft,Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted
* provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions
* and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other materials provided with
* the distribution.
*
* 3. The names of the authors may not be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL JCRAFT, INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.jcraft.jsch;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Vector;
class KnownHosts implements HostKeyRepository {
private JSch jsch = null;
private String known_hosts = null;
private Vector<HostKey> pool = null;
MAC hmacsha1;
KnownHosts(JSch jsch) {
super();
this.jsch = jsch;
getHMACSHA1();
pool = new Vector<>();
}
void setKnownHosts(String filename) throws JSchException {
try {
known_hosts = filename;
InputStream fis = new FileInputStream(Util.checkTilde(filename));
setKnownHosts(fis);
} catch (FileNotFoundException e) {
// The non-existing file should be allowed.
}
}
void setKnownHosts(InputStream input) throws JSchException {
pool.removeAllElements();
StringBuilder sb = new StringBuilder();
byte i;
int j;
boolean error = false;
try (InputStream fis = input) {
String host;
String key = null;
int type;
byte[] buf = new byte[1024];
int bufl = 0;
loop: while (true) {
bufl = 0;
while (true) {
j = fis.read();
if (j == -1) {
if (bufl == 0) {
break loop;
}
break;
}
if (j == 0x0d) {
continue;
}
if (j == 0x0a) {
break;
}
if (buf.length <= bufl) {
if (bufl > 1024 * 10)
break; // too long...
byte[] newbuf = new byte[buf.length * 2];
System.arraycopy(buf, 0, newbuf, 0, buf.length);
buf = newbuf;
}
buf[bufl++] = (byte) j;
}
j = 0;
while (j < bufl) {
i = buf[j];
if (i == ' ' || i == '\t') {
j++;
continue;
}
if (i == '#') {
addInvalidLine(Util.byte2str(buf, 0, bufl));
continue loop;
}
break;
}
if (j >= bufl) {
addInvalidLine(Util.byte2str(buf, 0, bufl));
continue loop;
}
sb.setLength(0);
while (j < bufl) {
i = buf[j++];
if (i == 0x20 || i == '\t') {
break;
}
sb.append((char) i);
}
host = sb.toString();
if (j >= bufl || host.length() == 0) {
addInvalidLine(Util.byte2str(buf, 0, bufl));
continue loop;
}
while (j < bufl) {
i = buf[j];
if (i == ' ' || i == '\t') {
j++;
continue;
}
break;
}
String marker = "";
if (host.charAt(0) == '@') {
marker = host;
sb.setLength(0);
while (j < bufl) {
i = buf[j++];
if (i == 0x20 || i == '\t') {
break;
}
sb.append((char) i);
}
host = sb.toString();
if (j >= bufl || host.length() == 0) {
addInvalidLine(Util.byte2str(buf, 0, bufl));
continue loop;
}
while (j < bufl) {
i = buf[j];
if (i == ' ' || i == '\t') {
j++;
continue;
}
break;
}
}
sb.setLength(0);
type = -1;
while (j < bufl) {
i = buf[j++];
if (i == 0x20 || i == '\t') {
break;
}
sb.append((char) i);
}
String tmp = sb.toString();
if (HostKey.name2type(tmp) != HostKey.UNKNOWN) {
type = HostKey.name2type(tmp);
} else {
j = bufl;
}
if (j >= bufl) {
addInvalidLine(Util.byte2str(buf, 0, bufl));
continue loop;
}
while (j < bufl) {
i = buf[j];
if (i == ' ' || i == '\t') {
j++;
continue;
}
break;
}
sb.setLength(0);
while (j < bufl) {
i = buf[j++];
if (i == 0x0d) {
continue;
}
if (i == 0x0a) {
break;
}
if (i == 0x20 || i == '\t') {
break;
}
sb.append((char) i);
}
key = sb.toString();
if (key.length() == 0) {
addInvalidLine(Util.byte2str(buf, 0, bufl));
continue loop;
}
while (j < bufl) {
i = buf[j];
if (i == ' ' || i == '\t') {
j++;
continue;
}
break;
}
/**
* "man sshd" has following descriptions, Note that the lines in these files are typically
* hundreds of characters long, and you definitely don't want to type in the host keys by
* hand. Rather, generate them by a script, ssh-keyscan(1) or by taking
* /usr/local/etc/ssh_host_key.pub and adding the host names at the front. This means that a
* comment is allowed to appear at the end of each key entry.
*/
String comment = null;
if (j < bufl) {
sb.setLength(0);
while (j < bufl) {
i = buf[j++];
if (i == 0x0d) {
continue;
}
if (i == 0x0a) {
break;
}
sb.append((char) i);
}
comment = sb.toString();
}
// System.err.println(host);
// System.err.println("|"+key+"|");
HostKey hk = null;
hk = new HashedHostKey(marker, host, type,
Util.fromBase64(Util.str2byte(key), 0, key.length()), comment);
pool.addElement(hk);
}
if (error) {
throw new JSchException("KnownHosts: invalid format");
}
} catch (Exception e) {
if (e instanceof JSchException)
throw (JSchException) e;
throw new JSchException(e.toString(), e);
}
}
private void addInvalidLine(String line) throws JSchException {
HostKey hk = new HostKey(line, HostKey.UNKNOWN, null);
pool.addElement(hk);
}
String getKnownHostsFile() {
return known_hosts;
}
@Override
public String getKnownHostsRepositoryID() {
return known_hosts;
}
@Override
public int check(String host, byte[] key) {
int result = NOT_INCLUDED;
if (host == null) {
return result;
}
HostKey hk = null;
try {
hk = new HostKey(host, HostKey.GUESS, key);
} catch (Exception e) { // unsupported key
jsch.getInstanceLogger().log(Logger.DEBUG,
"exception while trying to read key while checking host '" + host + "'", e);
return result;
}
synchronized (pool) {
for (int i = 0; i < pool.size(); i++) {
HostKey _hk = pool.elementAt(i);
if (_hk.isMatched(host) && _hk.type == hk.type) {
if (Util.array_equals(_hk.key, key)) {
return OK;
}
result = CHANGED;
}
}
}
if (result == NOT_INCLUDED && host.startsWith("[") && host.indexOf("]:") > 1) {
return check(host.substring(1, host.indexOf("]:")), key);
}
return result;
}
@Override
public void add(HostKey hostkey, UserInfo userinfo) {
int type = hostkey.type;
String host = hostkey.getHost();
// byte[] key=hostkey.key;
HostKey hk = null;
synchronized (pool) {
for (int i = 0; i < pool.size(); i++) {
hk = pool.elementAt(i);
if (hk.isMatched(host) && hk.type == type) {
/*
* if(Util.array_equals(hk.key, key)){ return; } if(hk.host.equals(host)){ hk.key=key;
* return; } else{ hk.host=deleteSubString(hk.host, host); break; }
*/
}
}
}
hk = hostkey;
pool.addElement(hk);
syncKnownHostsFile(userinfo);
}
void syncKnownHostsFile(UserInfo userinfo) {
String khFilename = getKnownHostsRepositoryID();
if (khFilename == null) {
return;
}
boolean doSync = true;
File goo = new File(Util.checkTilde(khFilename));
if (!goo.exists()) {
doSync = false;
if (userinfo != null) {
doSync = userinfo
.promptYesNo(khFilename + " does not exist.\n" + "Are you sure you want to create it?");
goo = goo.getParentFile();
if (doSync && goo != null && !goo.exists()) {
doSync = userinfo.promptYesNo("The parent directory " + goo + " does not exist.\n"
+ "Are you sure you want to create it?");
if (doSync) {
if (!goo.mkdirs()) {
userinfo.showMessage(goo + " has not been created.");
doSync = false;
} else {
userinfo.showMessage(
goo + " has been succesfully created.\nPlease check its access permission.");
}
}
}
if (goo == null)
doSync = false;
}
}
if (!doSync) {
return;
}
try {
sync(khFilename);
} catch (Exception e) {
jsch.getInstanceLogger().log(Logger.ERROR, "unable to sync known host file " + goo.getPath(),
e);
}
}
@Override
public HostKey[] getHostKey() {
return getHostKey(null, (String) null);
}
@Override
public HostKey[] getHostKey(String host, String type) {
synchronized (pool) {
List<HostKey> v = new ArrayList<>();
for (int i = 0; i < pool.size(); i++) {
HostKey hk = pool.elementAt(i);
if (hk.type == HostKey.UNKNOWN)
continue;
if (host == null || (hk.isMatched(host) && (type == null || hk.getType().equals(type)))) {
v.add(hk);
}
}
HostKey[] foo = new HostKey[v.size()];
for (int i = 0; i < v.size(); i++) {
foo[i] = v.get(i);
}
if (host != null && host.startsWith("[") && host.indexOf("]:") > 1) {
HostKey[] tmp = getHostKey(host.substring(1, host.indexOf("]:")), type);
if (tmp.length > 0) {
HostKey[] bar = new HostKey[foo.length + tmp.length];
System.arraycopy(foo, 0, bar, 0, foo.length);
System.arraycopy(tmp, 0, bar, foo.length, tmp.length);
foo = bar;
}
}
return foo;
}
}
@Override
public void remove(String host, String type) {
remove(host, type, null);
}
@Override
public void remove(String host, String type, byte[] key) {
boolean sync = false;
synchronized (pool) {
for (int i = 0; i < pool.size(); i++) {
HostKey hk = pool.elementAt(i);
if (host == null || (hk.isMatched(host) && (type == null
|| (hk.getType().equals(type) && (key == null || Util.array_equals(key, hk.key)))))) {
String hosts = hk.getHost();
if (host == null || hosts.equals(host)
|| ((hk instanceof HashedHostKey) && ((HashedHostKey) hk).isHashed())) {
pool.removeElement(hk);
i--;
} else {
hk.host = deleteSubString(hosts, host);
}
sync = true;
}
}
}
if (sync) {
try {
sync();
} catch (Exception e) {
} ;
}
}
void sync() throws IOException {
if (known_hosts != null)
sync(known_hosts);
}
synchronized void sync(String foo) throws IOException {
if (foo == null)
return;
try (FileOutputStream fos = new FileOutputStream(Util.checkTilde(foo))) {
dump(fos);
}
}
private static final byte[] space = {(byte) 0x20};
private static final byte[] lf = Util.str2byte("\n");
void dump(OutputStream out) {
try {
HostKey hk;
synchronized (pool) {
for (int i = 0; i < pool.size(); i++) {
hk = pool.elementAt(i);
dumpHostKey(out, hk);
}
}
} catch (Exception e) {
jsch.getInstanceLogger().log(Logger.ERROR, "unable to dump known hosts", e);
}
}
void dumpHostKey(OutputStream out, HostKey hk) throws IOException {
String marker = hk.getMarker();
String host = hk.getHost();
String type = hk.getType();
String comment = hk.getComment();
if (type.equals("UNKNOWN")) {
out.write(Util.str2byte(host));
out.write(lf);
return;
}
if (marker.length() != 0) {
out.write(Util.str2byte(marker));
out.write(space);
}
out.write(Util.str2byte(host));
out.write(space);
out.write(Util.str2byte(type));
out.write(space);
out.write(Util.str2byte(hk.getKey()));
if (comment != null) {
out.write(space);
out.write(Util.str2byte(comment));
}
out.write(lf);
}
String deleteSubString(String hosts, String host) {
int i = 0;
int hostlen = host.length();
int hostslen = hosts.length();
int j;
while (i < hostslen) {
j = hosts.indexOf(',', i);
if (j == -1)
break;
if (!host.equals(hosts.substring(i, j))) {
i = j + 1;
continue;
}
return hosts.substring(0, i) + hosts.substring(j + 1);
}
if (hosts.endsWith(host) && hostslen - i == hostlen) {
return hosts.substring(0, (hostlen == hostslen) ? 0 : hostslen - hostlen - 1);
}
return hosts;
}
MAC getHMACSHA1() throws IllegalArgumentException {
if (hmacsha1 == null) {
hmacsha1 = createHMAC(JSch.getConfig("hmac-sha1"));
}
return hmacsha1;
}
MAC createHMAC(String hmacClassname) throws IllegalArgumentException {
try {
Class<? extends MAC> c = Class.forName(hmacClassname).asSubclass(MAC.class);
return c.getDeclaredConstructor().newInstance();
} catch (Exception e) {
jsch.getInstanceLogger().log(Logger.ERROR,
"unable to instantiate HMAC-class " + hmacClassname, e);
throw new IllegalArgumentException("instantiation of " + hmacClassname + " lead to an error",
e);
}
}
HostKey createHashedHostKey(String host, byte[] key) throws JSchException {
HashedHostKey hhk = new HashedHostKey(host, key);
hhk.hash();
return hhk;
}
class HashedHostKey extends HostKey {
private static final String HASH_MAGIC = "|1|";
private static final String HASH_DELIM = "|";
private boolean hashed = false;
byte[] salt = null;
byte[] hash = null;
HashedHostKey(String host, byte[] key) throws JSchException {
this(host, GUESS, key);
}
HashedHostKey(String host, int type, byte[] key) throws JSchException {
this("", host, type, key, null);
}
HashedHostKey(String marker, String host, int type, byte[] key, String comment)
throws JSchException {
super(marker, host, type, key, comment);
if (this.host.startsWith(HASH_MAGIC)
&& this.host.substring(HASH_MAGIC.length()).indexOf(HASH_DELIM) > 0) {
String data = this.host.substring(HASH_MAGIC.length());
String _salt = data.substring(0, data.indexOf(HASH_DELIM));
String _hash = data.substring(data.indexOf(HASH_DELIM) + 1);
salt = Util.fromBase64(Util.str2byte(_salt), 0, _salt.length());
hash = Util.fromBase64(Util.str2byte(_hash), 0, _hash.length());
int blockSize = hmacsha1.getBlockSize();
if (salt.length != blockSize || hash.length != blockSize) {
salt = null;
hash = null;
return;
}
hashed = true;
}
}
@Override
boolean isMatched(String _host) {
if (!hashed) {
return super.isMatched(_host);
}
try {
synchronized (hmacsha1) {
hmacsha1.init(salt);
byte[] foo = Util.str2byte(_host);
hmacsha1.update(foo, 0, foo.length);
byte[] bar = new byte[hmacsha1.getBlockSize()];
hmacsha1.doFinal(bar, 0);
return Util.array_equals(hash, bar);
}
} catch (Exception e) {
jsch.getInstanceLogger().log(Logger.ERROR,
"an error occurred while trying to check hash for host " + _host, e);
}
return false;
}
boolean isHashed() {
return hashed;
}
void hash() {
if (hashed)
return;
if (salt == null) {
Random random = Session.random;
synchronized (random) {
salt = new byte[hmacsha1.getBlockSize()];
random.fill(salt, 0, salt.length);
}
}
try {
synchronized (hmacsha1) {
hmacsha1.init(salt);
byte[] foo = Util.str2byte(host);
hmacsha1.update(foo, 0, foo.length);
hash = new byte[hmacsha1.getBlockSize()];
hmacsha1.doFinal(hash, 0);
}
} catch (Exception e) {
jsch.getInstanceLogger().log(Logger.ERROR,
"an error occurred while trying to calculate the hash for host " + host, e);
salt = null;
hash = null;
return;
}
host = HASH_MAGIC + Util.byte2str(Util.toBase64(salt, 0, salt.length, true)) + HASH_DELIM
+ Util.byte2str(Util.toBase64(hash, 0, hash.length, true));
hashed = true;
}
}
}

@ -0,0 +1,152 @@
/*
* Copyright (c) 2012-2018 ymnk, JCraft,Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted
* provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions
* and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other materials provided with
* the distribution.
*
* 3. The names of the authors may not be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL JCRAFT, INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.jcraft.jsch;
import java.util.Vector;
class LocalIdentityRepository implements IdentityRepository {
private static final String name = "Local Identity Repository";
private Vector<Identity> identities = new Vector<>();
private JSch.InstanceLogger instLogger;
LocalIdentityRepository(JSch.InstanceLogger instLogger) {
this.instLogger = instLogger;
}
@Override
public String getName() {
return name;
}
@Override
public int getStatus() {
return RUNNING;
}
@Override
public synchronized Vector<Identity> getIdentities() {
removeDupulicates();
Vector<Identity> v = new Vector<>();
for (int i = 0; i < identities.size(); i++) {
v.addElement(identities.elementAt(i));
}
return v;
}
public synchronized void add(Identity identity) {
if (!identities.contains(identity)) {
byte[] blob1 = identity.getPublicKeyBlob();
if (blob1 == null) {
identities.addElement(identity);
return;
}
for (int i = 0; i < identities.size(); i++) {
byte[] blob2 = identities.elementAt(i).getPublicKeyBlob();
if (blob2 != null && Util.array_equals(blob1, blob2)) {
if (!identity.isEncrypted() && identities.elementAt(i).isEncrypted()) {
remove(blob2);
} else {
return;
}
}
}
identities.addElement(identity);
}
}
@Override
public synchronized boolean add(byte[] identity) {
try {
Identity _identity = IdentityFile.newInstance("from remote:", identity, null, instLogger);
add(_identity);
return true;
} catch (JSchException e) {
return false;
}
}
synchronized void remove(Identity identity) {
if (identities.contains(identity)) {
identities.removeElement(identity);
identity.clear();
} else {
remove(identity.getPublicKeyBlob());
}
}
@Override
public synchronized boolean remove(byte[] blob) {
if (blob == null)
return false;
for (int i = 0; i < identities.size(); i++) {
Identity _identity = identities.elementAt(i);
byte[] _blob = _identity.getPublicKeyBlob();
if (_blob == null || !Util.array_equals(blob, _blob))
continue;
identities.removeElement(_identity);
_identity.clear();
return true;
}
return false;
}
@Override
public synchronized void removeAll() {
for (int i = 0; i < identities.size(); i++) {
Identity identity = identities.elementAt(i);
identity.clear();
}
identities.removeAllElements();
}
private void removeDupulicates() {
Vector<byte[]> v = new Vector<>();
int len = identities.size();
if (len == 0)
return;
for (int i = 0; i < len; i++) {
Identity foo = identities.elementAt(i);
byte[] foo_blob = foo.getPublicKeyBlob();
if (foo_blob == null)
continue;
for (int j = i + 1; j < len; j++) {
Identity bar = identities.elementAt(j);
byte[] bar_blob = bar.getPublicKeyBlob();
if (bar_blob == null)
continue;
if (Util.array_equals(foo_blob, bar_blob) && foo.isEncrypted() == bar.isEncrypted()) {
v.addElement(foo_blob);
break;
}
}
}
for (int i = 0; i < v.size(); i++) {
remove(v.elementAt(i));
}
}
}

@ -0,0 +1,64 @@
/*
* Copyright (c) 2006-2018 ymnk, JCraft,Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted
* provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions
* and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other materials provided with
* the distribution.
*
* 3. The names of the authors may not be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL JCRAFT, INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.jcraft.jsch;
import java.io.PrintWriter;
import java.io.StringWriter;
public interface Logger {
public final int DEBUG = 0;
public final int INFO = 1;
public final int WARN = 2;
public final int ERROR = 3;
public final int FATAL = 4;
public boolean isEnabled(int level);
public void log(int level, String message);
public default void log(int level, String message, Throwable cause) {
if (!isEnabled(level)) {
return;
}
if (cause != null) {
StringWriter sw = new StringWriter();
try (PrintWriter pw = new PrintWriter(sw, true)) {
cause.printStackTrace(pw);
}
message += System.lineSeparator() + sw.toString();
}
log(level, message);
}
/*
* public final Logger SIMPLE_LOGGER=new Logger(){ public boolean isEnabled(int level){return
* true;} public void log(int level, String message){System.err.println(message);} }; final Logger
* DEVNULL=new Logger(){ public boolean isEnabled(int level){return false;} public void log(int
* level, String message){} };
*/
}

@ -0,0 +1,45 @@
/*
* Copyright (c) 2002-2018 ymnk, JCraft,Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted
* provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions
* and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other materials provided with
* the distribution.
*
* 3. The names of the authors may not be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL JCRAFT, INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.jcraft.jsch;
public interface MAC {
String getName();
int getBlockSize();
void init(byte[] key) throws Exception;
void update(byte[] foo, int start, int len);
void update(int foo);
void doFinal(byte[] buf, int offset);
default boolean isEtM() {
return false;
}
}

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save